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