Mbed OS Reference
Loading...
Searching...
No Matches
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 "ppp_opts.h"
35#if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
36
37#ifndef PPPOL2TP_H
38#define PPPOL2TP_H
39
40#include "ppp.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/* Timeout */
47#define PPPOL2TP_CONTROL_TIMEOUT (5*1000) /* base for quick timeout calculation */
48#define PPPOL2TP_SLOW_RETRY (60*1000) /* persistent retry interval */
49
50#define PPPOL2TP_MAXSCCRQ 4 /* retry SCCRQ four times (quickly) */
51#define PPPOL2TP_MAXICRQ 4 /* retry IRCQ four times */
52#define PPPOL2TP_MAXICCN 4 /* retry ICCN four times */
53
54/* L2TP header flags */
55#define PPPOL2TP_HEADERFLAG_CONTROL 0x8000
56#define PPPOL2TP_HEADERFLAG_LENGTH 0x4000
57#define PPPOL2TP_HEADERFLAG_SEQUENCE 0x0800
58#define PPPOL2TP_HEADERFLAG_OFFSET 0x0200
59#define PPPOL2TP_HEADERFLAG_PRIORITY 0x0100
60#define PPPOL2TP_HEADERFLAG_VERSION 0x0002
61
62/* Mandatory bits for control: Control, Length, Sequence, Version 2 */
63#define PPPOL2TP_HEADERFLAG_CONTROL_MANDATORY (PPPOL2TP_HEADERFLAG_CONTROL|PPPOL2TP_HEADERFLAG_LENGTH|PPPOL2TP_HEADERFLAG_SEQUENCE|PPPOL2TP_HEADERFLAG_VERSION)
64/* Forbidden bits for control: Offset, Priority */
65#define PPPOL2TP_HEADERFLAG_CONTROL_FORBIDDEN (PPPOL2TP_HEADERFLAG_OFFSET|PPPOL2TP_HEADERFLAG_PRIORITY)
66
67/* Mandatory bits for data: Version 2 */
68#define PPPOL2TP_HEADERFLAG_DATA_MANDATORY (PPPOL2TP_HEADERFLAG_VERSION)
69
70/* AVP (Attribute Value Pair) header */
71#define PPPOL2TP_AVPHEADERFLAG_MANDATORY 0x8000
72#define PPPOL2TP_AVPHEADERFLAG_HIDDEN 0x4000
73#define PPPOL2TP_AVPHEADERFLAG_LENGTHMASK 0x03ff
74
75/* -- AVP - Message type */
76#define PPPOL2TP_AVPTYPE_MESSAGE 0 /* Message type */
77
78/* Control Connection Management */
79#define PPPOL2TP_MESSAGETYPE_SCCRQ 1 /* Start Control Connection Request */
80#define PPPOL2TP_MESSAGETYPE_SCCRP 2 /* Start Control Connection Reply */
81#define PPPOL2TP_MESSAGETYPE_SCCCN 3 /* Start Control Connection Connected */
82#define PPPOL2TP_MESSAGETYPE_STOPCCN 4 /* Stop Control Connection Notification */
83#define PPPOL2TP_MESSAGETYPE_HELLO 6 /* Hello */
84/* Call Management */
85#define PPPOL2TP_MESSAGETYPE_OCRQ 7 /* Outgoing Call Request */
86#define PPPOL2TP_MESSAGETYPE_OCRP 8 /* Outgoing Call Reply */
87#define PPPOL2TP_MESSAGETYPE_OCCN 9 /* Outgoing Call Connected */
88#define PPPOL2TP_MESSAGETYPE_ICRQ 10 /* Incoming Call Request */
89#define PPPOL2TP_MESSAGETYPE_ICRP 11 /* Incoming Call Reply */
90#define PPPOL2TP_MESSAGETYPE_ICCN 12 /* Incoming Call Connected */
91#define PPPOL2TP_MESSAGETYPE_CDN 14 /* Call Disconnect Notify */
92/* Error reporting */
93#define PPPOL2TP_MESSAGETYPE_WEN 15 /* WAN Error Notify */
94/* PPP Session Control */
95#define PPPOL2TP_MESSAGETYPE_SLI 16 /* Set Link Info */
96
97/* -- AVP - Result code */
98#define PPPOL2TP_AVPTYPE_RESULTCODE 1 /* Result code */
99#define PPPOL2TP_RESULTCODE 1 /* General request to clear control connection */
100
101/* -- AVP - Protocol version (!= L2TP Header version) */
102#define PPPOL2TP_AVPTYPE_VERSION 2
103#define PPPOL2TP_VERSION 0x0100 /* L2TP Protocol version 1, revision 0 */
104
105/* -- AVP - Framing capabilities */
106#define PPPOL2TP_AVPTYPE_FRAMINGCAPABILITIES 3 /* Bearer capabilities */
107#define PPPOL2TP_FRAMINGCAPABILITIES 0x00000003 /* Async + Sync framing */
108
109/* -- AVP - Bearer capabilities */
110#define PPPOL2TP_AVPTYPE_BEARERCAPABILITIES 4 /* Bearer capabilities */
111#define PPPOL2TP_BEARERCAPABILITIES 0x00000003 /* Analog + Digital Access */
112
113/* -- AVP - Tie breaker */
114#define PPPOL2TP_AVPTYPE_TIEBREAKER 5
115
116/* -- AVP - Host name */
117#define PPPOL2TP_AVPTYPE_HOSTNAME 7 /* Host name */
118#define PPPOL2TP_HOSTNAME "ppp" /* FIXME: make it configurable */
119
120/* -- AVP - Vendor name */
121#define PPPOL2TP_AVPTYPE_VENDORNAME 8 /* Vendor name */
122#define PPPOL2TP_VENDORNAME "ppp" /* FIXME: make it configurable */
123
124/* -- AVP - Assign tunnel ID */
125#define PPPOL2TP_AVPTYPE_TUNNELID 9 /* Assign Tunnel ID */
126
127/* -- AVP - Receive window size */
128#define PPPOL2TP_AVPTYPE_RECEIVEWINDOWSIZE 10 /* Receive window size */
129#define PPPOL2TP_RECEIVEWINDOWSIZE 8 /* FIXME: make it configurable */
130
131/* -- AVP - Challenge */
132#define PPPOL2TP_AVPTYPE_CHALLENGE 11 /* Challenge */
133
134/* -- AVP - Cause code */
135#define PPPOL2TP_AVPTYPE_CAUSECODE 12 /* Cause code*/
136
137/* -- AVP - Challenge response */
138#define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE 13 /* Challenge response */
139#define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE_SIZE 16
140
141/* -- AVP - Assign session ID */
142#define PPPOL2TP_AVPTYPE_SESSIONID 14 /* Assign Session ID */
143
144/* -- AVP - Call serial number */
145#define PPPOL2TP_AVPTYPE_CALLSERIALNUMBER 15 /* Call Serial Number */
146
147/* -- AVP - Framing type */
148#define PPPOL2TP_AVPTYPE_FRAMINGTYPE 19 /* Framing Type */
149#define PPPOL2TP_FRAMINGTYPE 0x00000001 /* Sync framing */
150
151/* -- AVP - TX Connect Speed */
152#define PPPOL2TP_AVPTYPE_TXCONNECTSPEED 24 /* TX Connect Speed */
153#define PPPOL2TP_TXCONNECTSPEED 100000000 /* Connect speed: 100 Mbits/s */
154
155/* L2TP Session state */
156#define PPPOL2TP_STATE_INITIAL 0
157#define PPPOL2TP_STATE_SCCRQ_SENT 1
158#define PPPOL2TP_STATE_ICRQ_SENT 2
159#define PPPOL2TP_STATE_ICCN_SENT 3
160#define PPPOL2TP_STATE_DATA 4
161
162#define PPPOL2TP_OUTPUT_DATA_HEADER_LEN 6 /* Our data header len */
163
164/*
165 * PPPoL2TP interface control block.
166 */
167typedef struct pppol2tp_pcb_s pppol2tp_pcb;
168struct pppol2tp_pcb_s {
169 ppp_pcb *ppp; /* PPP PCB */
170 u8_t phase; /* L2TP phase */
171 struct udp_pcb *udp; /* UDP L2TP Socket */
172 struct netif *netif; /* Output interface, used as a default route */
173 ip_addr_t remote_ip; /* LNS IP Address */
174 u16_t remote_port; /* LNS port */
175#if PPPOL2TP_AUTH_SUPPORT
176 const u8_t *secret; /* Secret string */
177 u8_t secret_len; /* Secret string length */
178 u8_t secret_rv[16]; /* Random vector */
179 u8_t challenge_hash[16]; /* Challenge response */
180 u8_t send_challenge; /* Boolean whether the next sent packet should contains a challenge response */
181#endif /* PPPOL2TP_AUTH_SUPPORT */
182
183 u16_t tunnel_port; /* Tunnel port */
184 u16_t our_ns; /* NS to peer */
185 u16_t peer_nr; /* NR from peer */
186 u16_t peer_ns; /* Expected NS from peer */
187 u16_t source_tunnel_id; /* Tunnel ID assigned by peer */
188 u16_t remote_tunnel_id; /* Tunnel ID assigned to peer */
189 u16_t source_session_id; /* Session ID assigned by peer */
190 u16_t remote_session_id; /* Session ID assigned to peer */
191
192 u8_t sccrq_retried; /* number of SCCRQ retries already done */
193 u8_t icrq_retried; /* number of ICRQ retries already done */
194 u8_t iccn_retried; /* number of ICCN retries already done */
195};
196
197
198/* Create a new L2TP session. */
199ppp_pcb *pppol2tp_create(struct netif *pppif,
200 struct netif *netif, const ip_addr_t *ipaddr, u16_t port,
201 const u8_t *secret, u8_t secret_len,
202 ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif /* PPPOL2TP_H */
209#endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */
IP address structure for passing IP addresses by value.
Definition: nsapi_types.h:247