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