Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
pppol2tp.h
00001 /** 00002 * @file 00003 * Network Point to Point Protocol over Layer 2 Tunneling Protocol header file. 00004 * 00005 */ 00006 00007 /* 00008 * Redistribution and use in source and binary forms, with or without modification, 00009 * are permitted provided that the following conditions are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright notice, 00014 * this list of conditions and the following disclaimer in the documentation 00015 * and/or other materials provided with the distribution. 00016 * 3. The name of the author may not be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00020 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00021 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00022 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00024 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00027 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00028 * OF SUCH DAMAGE. 00029 * 00030 * This file is part of the lwIP TCP/IP stack. 00031 * 00032 */ 00033 00034 #include "ppp_opts.h" 00035 #if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ 00036 00037 #ifndef PPPOL2TP_H 00038 #define PPPOL2TP_H 00039 00040 #include "ppp.h" 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 /* Timeout */ 00047 #define PPPOL2TP_CONTROL_TIMEOUT (5*1000) /* base for quick timeout calculation */ 00048 #define PPPOL2TP_SLOW_RETRY (60*1000) /* persistent retry interval */ 00049 00050 #define PPPOL2TP_MAXSCCRQ 4 /* retry SCCRQ four times (quickly) */ 00051 #define PPPOL2TP_MAXICRQ 4 /* retry IRCQ four times */ 00052 #define PPPOL2TP_MAXICCN 4 /* retry ICCN four times */ 00053 00054 /* L2TP header flags */ 00055 #define PPPOL2TP_HEADERFLAG_CONTROL 0x8000 00056 #define PPPOL2TP_HEADERFLAG_LENGTH 0x4000 00057 #define PPPOL2TP_HEADERFLAG_SEQUENCE 0x0800 00058 #define PPPOL2TP_HEADERFLAG_OFFSET 0x0200 00059 #define PPPOL2TP_HEADERFLAG_PRIORITY 0x0100 00060 #define PPPOL2TP_HEADERFLAG_VERSION 0x0002 00061 00062 /* Mandatory bits for control: Control, Length, Sequence, Version 2 */ 00063 #define PPPOL2TP_HEADERFLAG_CONTROL_MANDATORY (PPPOL2TP_HEADERFLAG_CONTROL|PPPOL2TP_HEADERFLAG_LENGTH|PPPOL2TP_HEADERFLAG_SEQUENCE|PPPOL2TP_HEADERFLAG_VERSION) 00064 /* Forbidden bits for control: Offset, Priority */ 00065 #define PPPOL2TP_HEADERFLAG_CONTROL_FORBIDDEN (PPPOL2TP_HEADERFLAG_OFFSET|PPPOL2TP_HEADERFLAG_PRIORITY) 00066 00067 /* Mandatory bits for data: Version 2 */ 00068 #define PPPOL2TP_HEADERFLAG_DATA_MANDATORY (PPPOL2TP_HEADERFLAG_VERSION) 00069 00070 /* AVP (Attribute Value Pair) header */ 00071 #define PPPOL2TP_AVPHEADERFLAG_MANDATORY 0x8000 00072 #define PPPOL2TP_AVPHEADERFLAG_HIDDEN 0x4000 00073 #define PPPOL2TP_AVPHEADERFLAG_LENGTHMASK 0x03ff 00074 00075 /* -- AVP - Message type */ 00076 #define PPPOL2TP_AVPTYPE_MESSAGE 0 /* Message type */ 00077 00078 /* Control Connection Management */ 00079 #define PPPOL2TP_MESSAGETYPE_SCCRQ 1 /* Start Control Connection Request */ 00080 #define PPPOL2TP_MESSAGETYPE_SCCRP 2 /* Start Control Connection Reply */ 00081 #define PPPOL2TP_MESSAGETYPE_SCCCN 3 /* Start Control Connection Connected */ 00082 #define PPPOL2TP_MESSAGETYPE_STOPCCN 4 /* Stop Control Connection Notification */ 00083 #define PPPOL2TP_MESSAGETYPE_HELLO 6 /* Hello */ 00084 /* Call Management */ 00085 #define PPPOL2TP_MESSAGETYPE_OCRQ 7 /* Outgoing Call Request */ 00086 #define PPPOL2TP_MESSAGETYPE_OCRP 8 /* Outgoing Call Reply */ 00087 #define PPPOL2TP_MESSAGETYPE_OCCN 9 /* Outgoing Call Connected */ 00088 #define PPPOL2TP_MESSAGETYPE_ICRQ 10 /* Incoming Call Request */ 00089 #define PPPOL2TP_MESSAGETYPE_ICRP 11 /* Incoming Call Reply */ 00090 #define PPPOL2TP_MESSAGETYPE_ICCN 12 /* Incoming Call Connected */ 00091 #define PPPOL2TP_MESSAGETYPE_CDN 14 /* Call Disconnect Notify */ 00092 /* Error reporting */ 00093 #define PPPOL2TP_MESSAGETYPE_WEN 15 /* WAN Error Notify */ 00094 /* PPP Session Control */ 00095 #define PPPOL2TP_MESSAGETYPE_SLI 16 /* Set Link Info */ 00096 00097 /* -- AVP - Result code */ 00098 #define PPPOL2TP_AVPTYPE_RESULTCODE 1 /* Result code */ 00099 #define PPPOL2TP_RESULTCODE 1 /* General request to clear control connection */ 00100 00101 /* -- AVP - Protocol version (!= L2TP Header version) */ 00102 #define PPPOL2TP_AVPTYPE_VERSION 2 00103 #define PPPOL2TP_VERSION 0x0100 /* L2TP Protocol version 1, revision 0 */ 00104 00105 /* -- AVP - Framing capabilities */ 00106 #define PPPOL2TP_AVPTYPE_FRAMINGCAPABILITIES 3 /* Bearer capabilities */ 00107 #define PPPOL2TP_FRAMINGCAPABILITIES 0x00000003 /* Async + Sync framing */ 00108 00109 /* -- AVP - Bearer capabilities */ 00110 #define PPPOL2TP_AVPTYPE_BEARERCAPABILITIES 4 /* Bearer capabilities */ 00111 #define PPPOL2TP_BEARERCAPABILITIES 0x00000003 /* Analog + Digital Access */ 00112 00113 /* -- AVP - Tie breaker */ 00114 #define PPPOL2TP_AVPTYPE_TIEBREAKER 5 00115 00116 /* -- AVP - Host name */ 00117 #define PPPOL2TP_AVPTYPE_HOSTNAME 7 /* Host name */ 00118 #define PPPOL2TP_HOSTNAME "ppp" /* FIXME: make it configurable */ 00119 00120 /* -- AVP - Vendor name */ 00121 #define PPPOL2TP_AVPTYPE_VENDORNAME 8 /* Vendor name */ 00122 #define PPPOL2TP_VENDORNAME "ppp" /* FIXME: make it configurable */ 00123 00124 /* -- AVP - Assign tunnel ID */ 00125 #define PPPOL2TP_AVPTYPE_TUNNELID 9 /* Assign Tunnel ID */ 00126 00127 /* -- AVP - Receive window size */ 00128 #define PPPOL2TP_AVPTYPE_RECEIVEWINDOWSIZE 10 /* Receive window size */ 00129 #define PPPOL2TP_RECEIVEWINDOWSIZE 8 /* FIXME: make it configurable */ 00130 00131 /* -- AVP - Challenge */ 00132 #define PPPOL2TP_AVPTYPE_CHALLENGE 11 /* Challenge */ 00133 00134 /* -- AVP - Cause code */ 00135 #define PPPOL2TP_AVPTYPE_CAUSECODE 12 /* Cause code*/ 00136 00137 /* -- AVP - Challenge response */ 00138 #define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE 13 /* Challenge response */ 00139 #define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE_SIZE 16 00140 00141 /* -- AVP - Assign session ID */ 00142 #define PPPOL2TP_AVPTYPE_SESSIONID 14 /* Assign Session ID */ 00143 00144 /* -- AVP - Call serial number */ 00145 #define PPPOL2TP_AVPTYPE_CALLSERIALNUMBER 15 /* Call Serial Number */ 00146 00147 /* -- AVP - Framing type */ 00148 #define PPPOL2TP_AVPTYPE_FRAMINGTYPE 19 /* Framing Type */ 00149 #define PPPOL2TP_FRAMINGTYPE 0x00000001 /* Sync framing */ 00150 00151 /* -- AVP - TX Connect Speed */ 00152 #define PPPOL2TP_AVPTYPE_TXCONNECTSPEED 24 /* TX Connect Speed */ 00153 #define PPPOL2TP_TXCONNECTSPEED 100000000 /* Connect speed: 100 Mbits/s */ 00154 00155 /* L2TP Session state */ 00156 #define PPPOL2TP_STATE_INITIAL 0 00157 #define PPPOL2TP_STATE_SCCRQ_SENT 1 00158 #define PPPOL2TP_STATE_ICRQ_SENT 2 00159 #define PPPOL2TP_STATE_ICCN_SENT 3 00160 #define PPPOL2TP_STATE_DATA 4 00161 00162 #define PPPOL2TP_OUTPUT_DATA_HEADER_LEN 6 /* Our data header len */ 00163 00164 /* 00165 * PPPoL2TP interface control block. 00166 */ 00167 typedef struct pppol2tp_pcb_s pppol2tp_pcb; 00168 struct pppol2tp_pcb_s { 00169 ppp_pcb *ppp; /* PPP PCB */ 00170 u8_t phase; /* L2TP phase */ 00171 struct udp_pcb *udp; /* UDP L2TP Socket */ 00172 struct netif *netif; /* Output interface, used as a default route */ 00173 ip_addr_t remote_ip; /* LNS IP Address */ 00174 u16_t remote_port; /* LNS port */ 00175 #if PPPOL2TP_AUTH_SUPPORT 00176 const u8_t *secret; /* Secret string */ 00177 u8_t secret_len; /* Secret string length */ 00178 u8_t secret_rv[16]; /* Random vector */ 00179 u8_t challenge_hash[16]; /* Challenge response */ 00180 u8_t send_challenge; /* Boolean whether the next sent packet should contains a challenge response */ 00181 #endif /* PPPOL2TP_AUTH_SUPPORT */ 00182 00183 u16_t tunnel_port; /* Tunnel port */ 00184 u16_t our_ns; /* NS to peer */ 00185 u16_t peer_nr; /* NR from peer */ 00186 u16_t peer_ns; /* Expected NS from peer */ 00187 u16_t source_tunnel_id; /* Tunnel ID assigned by peer */ 00188 u16_t remote_tunnel_id; /* Tunnel ID assigned to peer */ 00189 u16_t source_session_id; /* Session ID assigned by peer */ 00190 u16_t remote_session_id; /* Session ID assigned to peer */ 00191 00192 u8_t sccrq_retried; /* number of SCCRQ retries already done */ 00193 u8_t icrq_retried; /* number of ICRQ retries already done */ 00194 u8_t iccn_retried; /* number of ICCN retries already done */ 00195 }; 00196 00197 00198 /* Create a new L2TP session. */ 00199 ppp_pcb *pppol2tp_create(struct netif *pppif, 00200 struct netif *netif, const ip_addr_t *ipaddr, u16_t port, 00201 const u8_t *secret, u8_t secret_len, 00202 ppp_link_status_cb_fn link_status_cb, void *ctx_cb); 00203 00204 #ifdef __cplusplus 00205 } 00206 #endif 00207 00208 #endif /* PPPOL2TP_H */ 00209 #endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */
Generated on Tue Jul 12 2022 13:54:43 by
