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.
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 "netif/ppp/ppp_opts.h" 00035 #if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 00036 00037 #ifndef PPPOL2TP_H 00038 #define PPPOL2TP_H 00039 00040 #include "ppp.h" 00041 00042 /* Timeout */ 00043 #define PPPOL2TP_CONTROL_TIMEOUT (5*1000) /* base for quick timeout calculation */ 00044 #define PPPOL2TP_SLOW_RETRY (60*1000) /* persistent retry interval */ 00045 00046 #define PPPOL2TP_MAXSCCRQ 4 /* retry SCCRQ four times (quickly) */ 00047 #define PPPOL2TP_MAXICRQ 4 /* retry IRCQ four times */ 00048 #define PPPOL2TP_MAXICCN 4 /* retry ICCN four times */ 00049 00050 /* L2TP header flags */ 00051 #define PPPOL2TP_HEADERFLAG_CONTROL 0x8000 00052 #define PPPOL2TP_HEADERFLAG_LENGTH 0x4000 00053 #define PPPOL2TP_HEADERFLAG_SEQUENCE 0x0800 00054 #define PPPOL2TP_HEADERFLAG_OFFSET 0x0200 00055 #define PPPOL2TP_HEADERFLAG_PRIORITY 0x0100 00056 #define PPPOL2TP_HEADERFLAG_VERSION 0x0002 00057 00058 /* Mandatory bits for control: Control, Length, Sequence, Version 2 */ 00059 #define PPPOL2TP_HEADERFLAG_CONTROL_MANDATORY (PPPOL2TP_HEADERFLAG_CONTROL|PPPOL2TP_HEADERFLAG_LENGTH|PPPOL2TP_HEADERFLAG_SEQUENCE|PPPOL2TP_HEADERFLAG_VERSION) 00060 /* Forbidden bits for control: Offset, Priority */ 00061 #define PPPOL2TP_HEADERFLAG_CONTROL_FORBIDDEN (PPPOL2TP_HEADERFLAG_OFFSET|PPPOL2TP_HEADERFLAG_PRIORITY) 00062 00063 /* Mandatory bits for data: Version 2 */ 00064 #define PPPOL2TP_HEADERFLAG_DATA_MANDATORY (PPPOL2TP_HEADERFLAG_VERSION) 00065 00066 /* AVP (Attribute Value Pair) header */ 00067 #define PPPOL2TP_AVPHEADERFLAG_MANDATORY 0x8000 00068 #define PPPOL2TP_AVPHEADERFLAG_HIDDEN 0x4000 00069 #define PPPOL2TP_AVPHEADERFLAG_LENGTHMASK 0x03ff 00070 00071 /* -- AVP - Message type */ 00072 #define PPPOL2TP_AVPTYPE_MESSAGE 0 /* Message type */ 00073 00074 /* Control Connection Management */ 00075 #define PPPOL2TP_MESSAGETYPE_SCCRQ 1 /* Start Control Connection Request */ 00076 #define PPPOL2TP_MESSAGETYPE_SCCRP 2 /* Start Control Connection Reply */ 00077 #define PPPOL2TP_MESSAGETYPE_SCCCN 3 /* Start Control Connection Connected */ 00078 #define PPPOL2TP_MESSAGETYPE_STOPCCN 4 /* Stop Control Connection Notification */ 00079 #define PPPOL2TP_MESSAGETYPE_HELLO 6 /* Hello */ 00080 /* Call Management */ 00081 #define PPPOL2TP_MESSAGETYPE_OCRQ 7 /* Outgoing Call Request */ 00082 #define PPPOL2TP_MESSAGETYPE_OCRP 8 /* Outgoing Call Reply */ 00083 #define PPPOL2TP_MESSAGETYPE_OCCN 9 /* Outgoing Call Connected */ 00084 #define PPPOL2TP_MESSAGETYPE_ICRQ 10 /* Incoming Call Request */ 00085 #define PPPOL2TP_MESSAGETYPE_ICRP 11 /* Incoming Call Reply */ 00086 #define PPPOL2TP_MESSAGETYPE_ICCN 12 /* Incoming Call Connected */ 00087 #define PPPOL2TP_MESSAGETYPE_CDN 14 /* Call Disconnect Notify */ 00088 /* Error reporting */ 00089 #define PPPOL2TP_MESSAGETYPE_WEN 15 /* WAN Error Notify */ 00090 /* PPP Session Control */ 00091 #define PPPOL2TP_MESSAGETYPE_SLI 16 /* Set Link Info */ 00092 00093 /* -- AVP - Result code */ 00094 #define PPPOL2TP_AVPTYPE_RESULTCODE 1 /* Result code */ 00095 #define PPPOL2TP_RESULTCODE 1 /* General request to clear control connection */ 00096 00097 /* -- AVP - Protocol version (!= L2TP Header version) */ 00098 #define PPPOL2TP_AVPTYPE_VERSION 2 00099 #define PPPOL2TP_VERSION 0x0100 /* L2TP Protocol version 1, revision 0 */ 00100 00101 /* -- AVP - Framing capabilities */ 00102 #define PPPOL2TP_AVPTYPE_FRAMINGCAPABILITIES 3 /* Bearer capabilities */ 00103 #define PPPOL2TP_FRAMINGCAPABILITIES 0x00000003 /* Async + Sync framing */ 00104 00105 /* -- AVP - Bearer capabilities */ 00106 #define PPPOL2TP_AVPTYPE_BEARERCAPABILITIES 4 /* Bearer capabilities */ 00107 #define PPPOL2TP_BEARERCAPABILITIES 0x00000003 /* Analog + Digital Access */ 00108 00109 /* -- AVP - Tie breaker */ 00110 #define PPPOL2TP_AVPTYPE_TIEBREAKER 5 00111 00112 /* -- AVP - Host name */ 00113 #define PPPOL2TP_AVPTYPE_HOSTNAME 7 /* Host name */ 00114 #define PPPOL2TP_HOSTNAME "lwIP" /* FIXME: make it configurable */ 00115 00116 /* -- AVP - Vendor name */ 00117 #define PPPOL2TP_AVPTYPE_VENDORNAME 8 /* Vendor name */ 00118 #define PPPOL2TP_VENDORNAME "lwIP" /* FIXME: make it configurable */ 00119 00120 /* -- AVP - Assign tunnel ID */ 00121 #define PPPOL2TP_AVPTYPE_TUNNELID 9 /* Assign Tunnel ID */ 00122 00123 /* -- AVP - Receive window size */ 00124 #define PPPOL2TP_AVPTYPE_RECEIVEWINDOWSIZE 10 /* Receive window size */ 00125 #define PPPOL2TP_RECEIVEWINDOWSIZE 8 /* FIXME: make it configurable */ 00126 00127 /* -- AVP - Challenge */ 00128 #define PPPOL2TP_AVPTYPE_CHALLENGE 11 /* Challenge */ 00129 00130 /* -- AVP - Cause code */ 00131 #define PPPOL2TP_AVPTYPE_CAUSECODE 12 /* Cause code*/ 00132 00133 /* -- AVP - Challenge response */ 00134 #define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE 13 /* Challenge response */ 00135 #define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE_SIZE 16 00136 00137 /* -- AVP - Assign session ID */ 00138 #define PPPOL2TP_AVPTYPE_SESSIONID 14 /* Assign Session ID */ 00139 00140 /* -- AVP - Call serial number */ 00141 #define PPPOL2TP_AVPTYPE_CALLSERIALNUMBER 15 /* Call Serial Number */ 00142 00143 /* -- AVP - Framing type */ 00144 #define PPPOL2TP_AVPTYPE_FRAMINGTYPE 19 /* Framing Type */ 00145 #define PPPOL2TP_FRAMINGTYPE 0x00000001 /* Sync framing */ 00146 00147 /* -- AVP - TX Connect Speed */ 00148 #define PPPOL2TP_AVPTYPE_TXCONNECTSPEED 24 /* TX Connect Speed */ 00149 #define PPPOL2TP_TXCONNECTSPEED 100000000 /* Connect speed: 100 Mbits/s */ 00150 00151 /* L2TP Session state */ 00152 #define PPPOL2TP_STATE_INITIAL 0 00153 #define PPPOL2TP_STATE_SCCRQ_SENT 1 00154 #define PPPOL2TP_STATE_ICRQ_SENT 2 00155 #define PPPOL2TP_STATE_ICCN_SENT 3 00156 #define PPPOL2TP_STATE_DATA 4 00157 00158 #define PPPOL2TP_OUTPUT_DATA_HEADER_LEN 6 /* Our data header len */ 00159 00160 /* 00161 * PPPoL2TP interface control block. 00162 */ 00163 typedef struct pppol2tp_pcb_s pppol2tp_pcb; 00164 struct pppol2tp_pcb_s { 00165 ppp_pcb *ppp; /* PPP PCB */ 00166 u8_t phase; /* L2TP phase */ 00167 struct udp_pcb *udp; /* UDP L2TP Socket */ 00168 struct netif *netif; /* Output interface, used as a default route */ 00169 ip_addr_t remote_ip; /* LNS IP Address */ 00170 u16_t remote_port; /* LNS port */ 00171 #if PPPOL2TP_AUTH_SUPPORT 00172 const u8_t *secret; /* Secret string */ 00173 u8_t secret_len; /* Secret string length */ 00174 u8_t secret_rv[16]; /* Random vector */ 00175 u8_t challenge_hash[16]; /* Challenge response */ 00176 u8_t send_challenge; /* Boolean whether the next sent packet should contains a challenge response */ 00177 #endif /* PPPOL2TP_AUTH_SUPPORT */ 00178 00179 u16_t tunnel_port; /* Tunnel port */ 00180 u16_t our_ns; /* NS to peer */ 00181 u16_t peer_nr; /* NR from peer */ 00182 u16_t peer_ns; /* NS from peer */ 00183 u16_t source_tunnel_id; /* Tunnel ID assigned by peer */ 00184 u16_t remote_tunnel_id; /* Tunnel ID assigned to peer */ 00185 u16_t source_session_id; /* Session ID assigned by peer */ 00186 u16_t remote_session_id; /* Session ID assigned to peer */ 00187 00188 u8_t sccrq_retried; /* number of SCCRQ retries already done */ 00189 u8_t icrq_retried; /* number of ICRQ retries already done */ 00190 u8_t iccn_retried; /* number of ICCN retries already done */ 00191 }; 00192 00193 00194 /* Create a new L2TP session. */ 00195 ppp_pcb *pppol2tp_create(struct netif *pppif, 00196 struct netif *netif, const ip_addr_t *ipaddr, u16_t port, 00197 const u8_t *secret, u8_t secret_len, 00198 ppp_link_status_cb_fn link_status_cb, void *ctx_cb); 00199 00200 #endif /* PPPOL2TP_H */ 00201 #endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */
Generated on Tue Jul 12 2022 12:22:17 by
