xref: /openbmc/linux/drivers/net/ppp/ppp_mppe.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2224cf5adSJeff Kirsher #define MPPE_PAD                4      /* MPPE growth per frame */
3224cf5adSJeff Kirsher #define MPPE_MAX_KEY_LEN       16      /* largest key length (128-bit) */
4224cf5adSJeff Kirsher 
5224cf5adSJeff Kirsher /* option bits for ccp_options.mppe */
6224cf5adSJeff Kirsher #define MPPE_OPT_40            0x01    /* 40 bit */
7224cf5adSJeff Kirsher #define MPPE_OPT_128           0x02    /* 128 bit */
8224cf5adSJeff Kirsher #define MPPE_OPT_STATEFUL      0x04    /* stateful mode */
9224cf5adSJeff Kirsher /* unsupported opts */
10224cf5adSJeff Kirsher #define MPPE_OPT_56            0x08    /* 56 bit */
11224cf5adSJeff Kirsher #define MPPE_OPT_MPPC          0x10    /* MPPC compression */
12224cf5adSJeff Kirsher #define MPPE_OPT_D             0x20    /* Unknown */
13224cf5adSJeff Kirsher #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
14224cf5adSJeff Kirsher #define MPPE_OPT_UNKNOWN       0x40    /* Bits !defined in RFC 3078 were set */
15224cf5adSJeff Kirsher 
16224cf5adSJeff Kirsher /*
17224cf5adSJeff Kirsher  * This is not nice ... the alternative is a bitfield struct though.
18224cf5adSJeff Kirsher  * And unfortunately, we cannot share the same bits for the option
19224cf5adSJeff Kirsher  * names above since C and H are the same bit.  We could do a u_int32
20224cf5adSJeff Kirsher  * but then we have to do a htonl() all the time and/or we still need
21224cf5adSJeff Kirsher  * to know which octet is which.
22224cf5adSJeff Kirsher  */
23224cf5adSJeff Kirsher #define MPPE_C_BIT             0x01    /* MPPC */
24224cf5adSJeff Kirsher #define MPPE_D_BIT             0x10    /* Obsolete, usage unknown */
25224cf5adSJeff Kirsher #define MPPE_L_BIT             0x20    /* 40-bit */
26224cf5adSJeff Kirsher #define MPPE_S_BIT             0x40    /* 128-bit */
27224cf5adSJeff Kirsher #define MPPE_M_BIT             0x80    /* 56-bit, not supported */
28224cf5adSJeff Kirsher #define MPPE_H_BIT             0x01    /* Stateless (in a different byte) */
29224cf5adSJeff Kirsher 
30224cf5adSJeff Kirsher /* Does not include H bit; used for least significant octet only. */
31224cf5adSJeff Kirsher #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
32224cf5adSJeff Kirsher 
33224cf5adSJeff Kirsher /* Build a CI from mppe opts (see RFC 3078) */
34224cf5adSJeff Kirsher #define MPPE_OPTS_TO_CI(opts, ci)              \
35224cf5adSJeff Kirsher     do {                                       \
36224cf5adSJeff Kirsher        u_char *ptr = ci; /* u_char[4] */       \
37224cf5adSJeff Kirsher                                                \
38224cf5adSJeff Kirsher        /* H bit */                             \
39224cf5adSJeff Kirsher        if (opts & MPPE_OPT_STATEFUL)           \
40224cf5adSJeff Kirsher            *ptr++ = 0x0;                       \
41224cf5adSJeff Kirsher        else                                    \
42224cf5adSJeff Kirsher            *ptr++ = MPPE_H_BIT;                \
43224cf5adSJeff Kirsher        *ptr++ = 0;                             \
44224cf5adSJeff Kirsher        *ptr++ = 0;                             \
45224cf5adSJeff Kirsher                                                \
46224cf5adSJeff Kirsher        /* S,L bits */                          \
47224cf5adSJeff Kirsher        *ptr = 0;                               \
48224cf5adSJeff Kirsher        if (opts & MPPE_OPT_128)                \
49224cf5adSJeff Kirsher            *ptr |= MPPE_S_BIT;                 \
50224cf5adSJeff Kirsher        if (opts & MPPE_OPT_40)                 \
51224cf5adSJeff Kirsher            *ptr |= MPPE_L_BIT;                 \
52224cf5adSJeff Kirsher        /* M,D,C bits not supported */          \
53224cf5adSJeff Kirsher     } while (/* CONSTCOND */ 0)
54224cf5adSJeff Kirsher 
55224cf5adSJeff Kirsher /* The reverse of the above */
56224cf5adSJeff Kirsher #define MPPE_CI_TO_OPTS(ci, opts)              \
57224cf5adSJeff Kirsher     do {                                       \
58224cf5adSJeff Kirsher        u_char *ptr = ci; /* u_char[4] */       \
59224cf5adSJeff Kirsher                                                \
60224cf5adSJeff Kirsher        opts = 0;                               \
61224cf5adSJeff Kirsher                                                \
62224cf5adSJeff Kirsher        /* H bit */                             \
63224cf5adSJeff Kirsher        if (!(ptr[0] & MPPE_H_BIT))             \
64224cf5adSJeff Kirsher            opts |= MPPE_OPT_STATEFUL;          \
65224cf5adSJeff Kirsher                                                \
66224cf5adSJeff Kirsher        /* S,L bits */                          \
67224cf5adSJeff Kirsher        if (ptr[3] & MPPE_S_BIT)                \
68224cf5adSJeff Kirsher            opts |= MPPE_OPT_128;               \
69224cf5adSJeff Kirsher        if (ptr[3] & MPPE_L_BIT)                \
70224cf5adSJeff Kirsher            opts |= MPPE_OPT_40;                \
71224cf5adSJeff Kirsher                                                \
72224cf5adSJeff Kirsher        /* M,D,C bits */                        \
73224cf5adSJeff Kirsher        if (ptr[3] & MPPE_M_BIT)                \
74224cf5adSJeff Kirsher            opts |= MPPE_OPT_56;                \
75224cf5adSJeff Kirsher        if (ptr[3] & MPPE_D_BIT)                \
76224cf5adSJeff Kirsher            opts |= MPPE_OPT_D;                 \
77224cf5adSJeff Kirsher        if (ptr[3] & MPPE_C_BIT)                \
78224cf5adSJeff Kirsher            opts |= MPPE_OPT_MPPC;              \
79224cf5adSJeff Kirsher                                                \
80224cf5adSJeff Kirsher        /* Other bits */                        \
81224cf5adSJeff Kirsher        if (ptr[0] & ~MPPE_H_BIT)               \
82224cf5adSJeff Kirsher            opts |= MPPE_OPT_UNKNOWN;           \
83224cf5adSJeff Kirsher        if (ptr[1] || ptr[2])                   \
84224cf5adSJeff Kirsher            opts |= MPPE_OPT_UNKNOWN;           \
85224cf5adSJeff Kirsher        if (ptr[3] & ~MPPE_ALL_BITS)            \
86224cf5adSJeff Kirsher            opts |= MPPE_OPT_UNKNOWN;           \
87224cf5adSJeff Kirsher     } while (/* CONSTCOND */ 0)
88