xref: /minix3/minix/lib/liblwip/dist/src/include/netif/ppp/pppol2tp.h (revision 5d5fbe79c1b60734f34c69330aec5496644e8651)
1*5d5fbe79SDavid van Moolenbroek /**
2*5d5fbe79SDavid van Moolenbroek  * @file
3*5d5fbe79SDavid van Moolenbroek  * Network Point to Point Protocol over Layer 2 Tunneling Protocol header file.
4*5d5fbe79SDavid van Moolenbroek  *
5*5d5fbe79SDavid van Moolenbroek  */
6*5d5fbe79SDavid van Moolenbroek 
7*5d5fbe79SDavid van Moolenbroek /*
8*5d5fbe79SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without modification,
9*5d5fbe79SDavid van Moolenbroek  * are permitted provided that the following conditions are met:
10*5d5fbe79SDavid van Moolenbroek  *
11*5d5fbe79SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright notice,
12*5d5fbe79SDavid van Moolenbroek  *    this list of conditions and the following disclaimer.
13*5d5fbe79SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce the above copyright notice,
14*5d5fbe79SDavid van Moolenbroek  *    this list of conditions and the following disclaimer in the documentation
15*5d5fbe79SDavid van Moolenbroek  *    and/or other materials provided with the distribution.
16*5d5fbe79SDavid van Moolenbroek  * 3. The name of the author may not be used to endorse or promote products
17*5d5fbe79SDavid van Moolenbroek  *    derived from this software without specific prior written permission.
18*5d5fbe79SDavid van Moolenbroek  *
19*5d5fbe79SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20*5d5fbe79SDavid van Moolenbroek  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21*5d5fbe79SDavid van Moolenbroek  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22*5d5fbe79SDavid van Moolenbroek  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23*5d5fbe79SDavid van Moolenbroek  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24*5d5fbe79SDavid van Moolenbroek  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*5d5fbe79SDavid van Moolenbroek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*5d5fbe79SDavid van Moolenbroek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27*5d5fbe79SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28*5d5fbe79SDavid van Moolenbroek  * OF SUCH DAMAGE.
29*5d5fbe79SDavid van Moolenbroek  *
30*5d5fbe79SDavid van Moolenbroek  * This file is part of the lwIP TCP/IP stack.
31*5d5fbe79SDavid van Moolenbroek  *
32*5d5fbe79SDavid van Moolenbroek  */
33*5d5fbe79SDavid van Moolenbroek 
34*5d5fbe79SDavid van Moolenbroek #include "netif/ppp/ppp_opts.h"
35*5d5fbe79SDavid van Moolenbroek #if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in lwipopts.h */
36*5d5fbe79SDavid van Moolenbroek 
37*5d5fbe79SDavid van Moolenbroek #ifndef PPPOL2TP_H
38*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_H
39*5d5fbe79SDavid van Moolenbroek 
40*5d5fbe79SDavid van Moolenbroek #include "ppp.h"
41*5d5fbe79SDavid van Moolenbroek 
42*5d5fbe79SDavid van Moolenbroek /* Timeout */
43*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_CONTROL_TIMEOUT         (5*1000)  /* base for quick timeout calculation */
44*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_SLOW_RETRY              (60*1000) /* persistent retry interval */
45*5d5fbe79SDavid van Moolenbroek 
46*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MAXSCCRQ                4         /* retry SCCRQ four times (quickly) */
47*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MAXICRQ                 4         /* retry IRCQ four times */
48*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MAXICCN                 4         /* retry ICCN four times */
49*5d5fbe79SDavid van Moolenbroek 
50*5d5fbe79SDavid van Moolenbroek /* L2TP header flags */
51*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_CONTROL      0x8000
52*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_LENGTH       0x4000
53*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_SEQUENCE     0x0800
54*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_OFFSET       0x0200
55*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_PRIORITY     0x0100
56*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_VERSION      0x0002
57*5d5fbe79SDavid van Moolenbroek 
58*5d5fbe79SDavid van Moolenbroek /* Mandatory bits for control: Control, Length, Sequence, Version 2 */
59*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_CONTROL_MANDATORY     (PPPOL2TP_HEADERFLAG_CONTROL|PPPOL2TP_HEADERFLAG_LENGTH|PPPOL2TP_HEADERFLAG_SEQUENCE|PPPOL2TP_HEADERFLAG_VERSION)
60*5d5fbe79SDavid van Moolenbroek /* Forbidden bits for control: Offset, Priority */
61*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_CONTROL_FORBIDDEN     (PPPOL2TP_HEADERFLAG_OFFSET|PPPOL2TP_HEADERFLAG_PRIORITY)
62*5d5fbe79SDavid van Moolenbroek 
63*5d5fbe79SDavid van Moolenbroek /* Mandatory bits for data: Version 2 */
64*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HEADERFLAG_DATA_MANDATORY        (PPPOL2TP_HEADERFLAG_VERSION)
65*5d5fbe79SDavid van Moolenbroek 
66*5d5fbe79SDavid van Moolenbroek /* AVP (Attribute Value Pair) header */
67*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPHEADERFLAG_MANDATORY  0x8000
68*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPHEADERFLAG_HIDDEN     0x4000
69*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPHEADERFLAG_LENGTHMASK 0x03ff
70*5d5fbe79SDavid van Moolenbroek 
71*5d5fbe79SDavid van Moolenbroek /* -- AVP - Message type */
72*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_MESSAGE      0 /* Message type */
73*5d5fbe79SDavid van Moolenbroek 
74*5d5fbe79SDavid van Moolenbroek /* Control Connection Management */
75*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_SCCRQ    1 /* Start Control Connection Request */
76*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_SCCRP    2 /* Start Control Connection Reply */
77*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_SCCCN    3 /* Start Control Connection Connected */
78*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_STOPCCN  4 /* Stop Control Connection Notification */
79*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_HELLO    6 /* Hello */
80*5d5fbe79SDavid van Moolenbroek /* Call Management */
81*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_OCRQ     7 /* Outgoing Call Request */
82*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_OCRP     8 /* Outgoing Call Reply */
83*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_OCCN     9 /* Outgoing Call Connected */
84*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_ICRQ    10 /* Incoming Call Request */
85*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_ICRP    11 /* Incoming Call Reply */
86*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_ICCN    12 /* Incoming Call Connected */
87*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_CDN     14 /* Call Disconnect Notify */
88*5d5fbe79SDavid van Moolenbroek /* Error reporting */
89*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_WEN     15 /* WAN Error Notify */
90*5d5fbe79SDavid van Moolenbroek /* PPP Session Control */
91*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_MESSAGETYPE_SLI     16 /* Set Link Info */
92*5d5fbe79SDavid van Moolenbroek 
93*5d5fbe79SDavid van Moolenbroek /* -- AVP - Result code */
94*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_RESULTCODE   1 /* Result code */
95*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_RESULTCODE           1 /* General request to clear control connection */
96*5d5fbe79SDavid van Moolenbroek 
97*5d5fbe79SDavid van Moolenbroek /* -- AVP - Protocol version (!= L2TP Header version) */
98*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_VERSION      2
99*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_VERSION         0x0100 /* L2TP Protocol version 1, revision 0 */
100*5d5fbe79SDavid van Moolenbroek 
101*5d5fbe79SDavid van Moolenbroek /* -- AVP - Framing capabilities */
102*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_FRAMINGCAPABILITIES           3 /* Bearer capabilities */
103*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_FRAMINGCAPABILITIES          0x00000003 /* Async + Sync framing */
104*5d5fbe79SDavid van Moolenbroek 
105*5d5fbe79SDavid van Moolenbroek /* -- AVP - Bearer capabilities */
106*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_BEARERCAPABILITIES           4 /* Bearer capabilities */
107*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_BEARERCAPABILITIES          0x00000003 /* Analog + Digital Access */
108*5d5fbe79SDavid van Moolenbroek 
109*5d5fbe79SDavid van Moolenbroek /* -- AVP - Tie breaker */
110*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_TIEBREAKER   5
111*5d5fbe79SDavid van Moolenbroek 
112*5d5fbe79SDavid van Moolenbroek /* -- AVP - Host name */
113*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_HOSTNAME     7 /* Host name */
114*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_HOSTNAME        "lwIP" /* FIXME: make it configurable */
115*5d5fbe79SDavid van Moolenbroek 
116*5d5fbe79SDavid van Moolenbroek /* -- AVP - Vendor name */
117*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_VENDORNAME   8 /* Vendor name */
118*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_VENDORNAME      "lwIP" /* FIXME: make it configurable */
119*5d5fbe79SDavid van Moolenbroek 
120*5d5fbe79SDavid van Moolenbroek /* -- AVP - Assign tunnel ID */
121*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_TUNNELID     9 /* Assign Tunnel ID */
122*5d5fbe79SDavid van Moolenbroek 
123*5d5fbe79SDavid van Moolenbroek /* -- AVP - Receive window size */
124*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_RECEIVEWINDOWSIZE  10 /* Receive window size */
125*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_RECEIVEWINDOWSIZE           8 /* FIXME: make it configurable */
126*5d5fbe79SDavid van Moolenbroek 
127*5d5fbe79SDavid van Moolenbroek /* -- AVP - Challenge */
128*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_CHALLENGE   11 /* Challenge */
129*5d5fbe79SDavid van Moolenbroek 
130*5d5fbe79SDavid van Moolenbroek /* -- AVP - Cause code */
131*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_CAUSECODE   12 /* Cause code*/
132*5d5fbe79SDavid van Moolenbroek 
133*5d5fbe79SDavid van Moolenbroek /* -- AVP - Challenge response */
134*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE   13 /* Challenge response */
135*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE_SIZE  16
136*5d5fbe79SDavid van Moolenbroek 
137*5d5fbe79SDavid van Moolenbroek /* -- AVP - Assign session ID */
138*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_SESSIONID   14 /* Assign Session ID */
139*5d5fbe79SDavid van Moolenbroek 
140*5d5fbe79SDavid van Moolenbroek /* -- AVP - Call serial number */
141*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_CALLSERIALNUMBER   15 /* Call Serial Number */
142*5d5fbe79SDavid van Moolenbroek 
143*5d5fbe79SDavid van Moolenbroek /* -- AVP - Framing type */
144*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_FRAMINGTYPE         19 /* Framing Type */
145*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_FRAMINGTYPE         0x00000001 /* Sync framing */
146*5d5fbe79SDavid van Moolenbroek 
147*5d5fbe79SDavid van Moolenbroek /* -- AVP - TX Connect Speed */
148*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_AVPTYPE_TXCONNECTSPEED      24 /* TX Connect Speed */
149*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_TXCONNECTSPEED       100000000 /* Connect speed: 100 Mbits/s */
150*5d5fbe79SDavid van Moolenbroek 
151*5d5fbe79SDavid van Moolenbroek /* L2TP Session state */
152*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_STATE_INITIAL     0
153*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_STATE_SCCRQ_SENT  1
154*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_STATE_ICRQ_SENT   2
155*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_STATE_ICCN_SENT   3
156*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_STATE_DATA        4
157*5d5fbe79SDavid van Moolenbroek 
158*5d5fbe79SDavid van Moolenbroek #define PPPOL2TP_OUTPUT_DATA_HEADER_LEN   6 /* Our data header len */
159*5d5fbe79SDavid van Moolenbroek 
160*5d5fbe79SDavid van Moolenbroek /*
161*5d5fbe79SDavid van Moolenbroek  * PPPoL2TP interface control block.
162*5d5fbe79SDavid van Moolenbroek  */
163*5d5fbe79SDavid van Moolenbroek typedef struct pppol2tp_pcb_s pppol2tp_pcb;
164*5d5fbe79SDavid van Moolenbroek struct pppol2tp_pcb_s {
165*5d5fbe79SDavid van Moolenbroek   ppp_pcb *ppp;                /* PPP PCB */
166*5d5fbe79SDavid van Moolenbroek   u8_t phase;                  /* L2TP phase */
167*5d5fbe79SDavid van Moolenbroek   struct udp_pcb *udp;         /* UDP L2TP Socket */
168*5d5fbe79SDavid van Moolenbroek   struct netif *netif;         /* Output interface, used as a default route */
169*5d5fbe79SDavid van Moolenbroek   ip_addr_t remote_ip;         /* LNS IP Address */
170*5d5fbe79SDavid van Moolenbroek   u16_t remote_port;           /* LNS port */
171*5d5fbe79SDavid van Moolenbroek #if PPPOL2TP_AUTH_SUPPORT
172*5d5fbe79SDavid van Moolenbroek   const u8_t *secret;          /* Secret string */
173*5d5fbe79SDavid van Moolenbroek   u8_t secret_len;             /* Secret string length */
174*5d5fbe79SDavid van Moolenbroek   u8_t secret_rv[16];          /* Random vector */
175*5d5fbe79SDavid van Moolenbroek   u8_t challenge_hash[16];     /* Challenge response */
176*5d5fbe79SDavid van Moolenbroek   u8_t send_challenge;         /* Boolean whether the next sent packet should contains a challenge response */
177*5d5fbe79SDavid van Moolenbroek #endif /* PPPOL2TP_AUTH_SUPPORT */
178*5d5fbe79SDavid van Moolenbroek 
179*5d5fbe79SDavid van Moolenbroek   u16_t tunnel_port;           /* Tunnel port */
180*5d5fbe79SDavid van Moolenbroek   u16_t our_ns;                /* NS to peer */
181*5d5fbe79SDavid van Moolenbroek   u16_t peer_nr;               /* NR from peer */
182*5d5fbe79SDavid van Moolenbroek   u16_t peer_ns;               /* NS from peer */
183*5d5fbe79SDavid van Moolenbroek   u16_t source_tunnel_id;      /* Tunnel ID assigned by peer */
184*5d5fbe79SDavid van Moolenbroek   u16_t remote_tunnel_id;      /* Tunnel ID assigned to peer */
185*5d5fbe79SDavid van Moolenbroek   u16_t source_session_id;     /* Session ID assigned by peer */
186*5d5fbe79SDavid van Moolenbroek   u16_t remote_session_id;     /* Session ID assigned to peer */
187*5d5fbe79SDavid van Moolenbroek 
188*5d5fbe79SDavid van Moolenbroek   u8_t sccrq_retried;          /* number of SCCRQ retries already done */
189*5d5fbe79SDavid van Moolenbroek   u8_t icrq_retried;           /* number of ICRQ retries already done */
190*5d5fbe79SDavid van Moolenbroek   u8_t iccn_retried;           /* number of ICCN retries already done */
191*5d5fbe79SDavid van Moolenbroek };
192*5d5fbe79SDavid van Moolenbroek 
193*5d5fbe79SDavid van Moolenbroek 
194*5d5fbe79SDavid van Moolenbroek /* Create a new L2TP session. */
195*5d5fbe79SDavid van Moolenbroek ppp_pcb *pppol2tp_create(struct netif *pppif,
196*5d5fbe79SDavid van Moolenbroek        struct netif *netif, const ip_addr_t *ipaddr, u16_t port,
197*5d5fbe79SDavid van Moolenbroek        const u8_t *secret, u8_t secret_len,
198*5d5fbe79SDavid van Moolenbroek        ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
199*5d5fbe79SDavid van Moolenbroek 
200*5d5fbe79SDavid van Moolenbroek #endif /* PPPOL2TP_H */
201*5d5fbe79SDavid van Moolenbroek #endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */
202