EthernetNetIf Compatibility.
Dependents: XBeeWiFi_SPI_example
Fork of NetServicesSource by
lwip/netif/ppp/ppp.c@0:632c9925f013, 2010-06-11 (annotated)
- Committer:
- donatien
- Date:
- Fri Jun 11 16:05:15 2010 +0000
- Revision:
- 0:632c9925f013
- Child:
- 4:fd826cad83c0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:632c9925f013 | 1 | /***************************************************************************** |
donatien | 0:632c9925f013 | 2 | * ppp.c - Network Point to Point Protocol program file. |
donatien | 0:632c9925f013 | 3 | * |
donatien | 0:632c9925f013 | 4 | * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. |
donatien | 0:632c9925f013 | 5 | * portions Copyright (c) 1997 by Global Election Systems Inc. |
donatien | 0:632c9925f013 | 6 | * |
donatien | 0:632c9925f013 | 7 | * The authors hereby grant permission to use, copy, modify, distribute, |
donatien | 0:632c9925f013 | 8 | * and license this software and its documentation for any purpose, provided |
donatien | 0:632c9925f013 | 9 | * that existing copyright notices are retained in all copies and that this |
donatien | 0:632c9925f013 | 10 | * notice and the following disclaimer are included verbatim in any |
donatien | 0:632c9925f013 | 11 | * distributions. No written agreement, license, or royalty fee is required |
donatien | 0:632c9925f013 | 12 | * for any of the authorized uses. |
donatien | 0:632c9925f013 | 13 | * |
donatien | 0:632c9925f013 | 14 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR |
donatien | 0:632c9925f013 | 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
donatien | 0:632c9925f013 | 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
donatien | 0:632c9925f013 | 17 | * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
donatien | 0:632c9925f013 | 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
donatien | 0:632c9925f013 | 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
donatien | 0:632c9925f013 | 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
donatien | 0:632c9925f013 | 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
donatien | 0:632c9925f013 | 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
donatien | 0:632c9925f013 | 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
donatien | 0:632c9925f013 | 24 | * |
donatien | 0:632c9925f013 | 25 | ****************************************************************************** |
donatien | 0:632c9925f013 | 26 | * REVISION HISTORY |
donatien | 0:632c9925f013 | 27 | * |
donatien | 0:632c9925f013 | 28 | * 03-01-01 Marc Boucher <marc@mbsi.ca> |
donatien | 0:632c9925f013 | 29 | * Ported to lwIP. |
donatien | 0:632c9925f013 | 30 | * 97-11-05 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. |
donatien | 0:632c9925f013 | 31 | * Original. |
donatien | 0:632c9925f013 | 32 | *****************************************************************************/ |
donatien | 0:632c9925f013 | 33 | |
donatien | 0:632c9925f013 | 34 | /* |
donatien | 0:632c9925f013 | 35 | * ppp_defs.h - PPP definitions. |
donatien | 0:632c9925f013 | 36 | * |
donatien | 0:632c9925f013 | 37 | * if_pppvar.h - private structures and declarations for PPP. |
donatien | 0:632c9925f013 | 38 | * |
donatien | 0:632c9925f013 | 39 | * Copyright (c) 1994 The Australian National University. |
donatien | 0:632c9925f013 | 40 | * All rights reserved. |
donatien | 0:632c9925f013 | 41 | * |
donatien | 0:632c9925f013 | 42 | * Permission to use, copy, modify, and distribute this software and its |
donatien | 0:632c9925f013 | 43 | * documentation is hereby granted, provided that the above copyright |
donatien | 0:632c9925f013 | 44 | * notice appears in all copies. This software is provided without any |
donatien | 0:632c9925f013 | 45 | * warranty, express or implied. The Australian National University |
donatien | 0:632c9925f013 | 46 | * makes no representations about the suitability of this software for |
donatien | 0:632c9925f013 | 47 | * any purpose. |
donatien | 0:632c9925f013 | 48 | * |
donatien | 0:632c9925f013 | 49 | * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY |
donatien | 0:632c9925f013 | 50 | * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
donatien | 0:632c9925f013 | 51 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF |
donatien | 0:632c9925f013 | 52 | * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY |
donatien | 0:632c9925f013 | 53 | * OF SUCH DAMAGE. |
donatien | 0:632c9925f013 | 54 | * |
donatien | 0:632c9925f013 | 55 | * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
donatien | 0:632c9925f013 | 56 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
donatien | 0:632c9925f013 | 57 | * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
donatien | 0:632c9925f013 | 58 | * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO |
donatien | 0:632c9925f013 | 59 | * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, |
donatien | 0:632c9925f013 | 60 | * OR MODIFICATIONS. |
donatien | 0:632c9925f013 | 61 | */ |
donatien | 0:632c9925f013 | 62 | |
donatien | 0:632c9925f013 | 63 | /* |
donatien | 0:632c9925f013 | 64 | * if_ppp.h - Point-to-Point Protocol definitions. |
donatien | 0:632c9925f013 | 65 | * |
donatien | 0:632c9925f013 | 66 | * Copyright (c) 1989 Carnegie Mellon University. |
donatien | 0:632c9925f013 | 67 | * All rights reserved. |
donatien | 0:632c9925f013 | 68 | * |
donatien | 0:632c9925f013 | 69 | * Redistribution and use in source and binary forms are permitted |
donatien | 0:632c9925f013 | 70 | * provided that the above copyright notice and this paragraph are |
donatien | 0:632c9925f013 | 71 | * duplicated in all such forms and that any documentation, |
donatien | 0:632c9925f013 | 72 | * advertising materials, and other materials related to such |
donatien | 0:632c9925f013 | 73 | * distribution and use acknowledge that the software was developed |
donatien | 0:632c9925f013 | 74 | * by Carnegie Mellon University. The name of the |
donatien | 0:632c9925f013 | 75 | * University may not be used to endorse or promote products derived |
donatien | 0:632c9925f013 | 76 | * from this software without specific prior written permission. |
donatien | 0:632c9925f013 | 77 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
donatien | 0:632c9925f013 | 78 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
donatien | 0:632c9925f013 | 79 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
donatien | 0:632c9925f013 | 80 | */ |
donatien | 0:632c9925f013 | 81 | |
donatien | 0:632c9925f013 | 82 | #include "lwip/opt.h" |
donatien | 0:632c9925f013 | 83 | |
donatien | 0:632c9925f013 | 84 | #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ |
donatien | 0:632c9925f013 | 85 | |
donatien | 0:632c9925f013 | 86 | #include "lwip/ip.h" /* for ip_input() */ |
donatien | 0:632c9925f013 | 87 | |
donatien | 0:632c9925f013 | 88 | #include "ppp.h" |
donatien | 0:632c9925f013 | 89 | #include "pppdebug.h" |
donatien | 0:632c9925f013 | 90 | |
donatien | 0:632c9925f013 | 91 | #include "randm.h" |
donatien | 0:632c9925f013 | 92 | #include "fsm.h" |
donatien | 0:632c9925f013 | 93 | #if PAP_SUPPORT |
donatien | 0:632c9925f013 | 94 | #include "pap.h" |
donatien | 0:632c9925f013 | 95 | #endif /* PAP_SUPPORT */ |
donatien | 0:632c9925f013 | 96 | #if CHAP_SUPPORT |
donatien | 0:632c9925f013 | 97 | #include "chap.h" |
donatien | 0:632c9925f013 | 98 | #endif /* CHAP_SUPPORT */ |
donatien | 0:632c9925f013 | 99 | #include "ipcp.h" |
donatien | 0:632c9925f013 | 100 | #include "lcp.h" |
donatien | 0:632c9925f013 | 101 | #include "magic.h" |
donatien | 0:632c9925f013 | 102 | #include "auth.h" |
donatien | 0:632c9925f013 | 103 | #if VJ_SUPPORT |
donatien | 0:632c9925f013 | 104 | #include "vj.h" |
donatien | 0:632c9925f013 | 105 | #endif /* VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 106 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 107 | #include "netif/ppp_oe.h" |
donatien | 0:632c9925f013 | 108 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 109 | |
donatien | 0:632c9925f013 | 110 | #include "lwip/tcpip.h" |
donatien | 0:632c9925f013 | 111 | #include "lwip/api.h" |
donatien | 0:632c9925f013 | 112 | #include "lwip/snmp.h" |
donatien | 0:632c9925f013 | 113 | |
donatien | 0:632c9925f013 | 114 | #include <string.h> |
donatien | 0:632c9925f013 | 115 | |
donatien | 0:632c9925f013 | 116 | /*************************/ |
donatien | 0:632c9925f013 | 117 | /*** LOCAL DEFINITIONS ***/ |
donatien | 0:632c9925f013 | 118 | /*************************/ |
donatien | 0:632c9925f013 | 119 | |
donatien | 0:632c9925f013 | 120 | /** PPP_INPROC_MULTITHREADED==1 call pppInput using tcpip_callback(). |
donatien | 0:632c9925f013 | 121 | * Set this to 0 if pppInProc is called inside tcpip_thread or with NO_SYS==1. |
donatien | 0:632c9925f013 | 122 | * Default is 1 for NO_SYS==0 (multithreaded) and 0 for NO_SYS==1 (single-threaded). |
donatien | 0:632c9925f013 | 123 | */ |
donatien | 0:632c9925f013 | 124 | #ifndef PPP_INPROC_MULTITHREADED |
donatien | 0:632c9925f013 | 125 | #define PPP_INPROC_MULTITHREADED (NO_SYS==0) |
donatien | 0:632c9925f013 | 126 | #endif |
donatien | 0:632c9925f013 | 127 | |
donatien | 0:632c9925f013 | 128 | /** PPP_INPROC_OWNTHREAD==1: start a dedicated RX thread per PPP session. |
donatien | 0:632c9925f013 | 129 | * Default is 0: call pppos_input() for received raw characters, charcater |
donatien | 0:632c9925f013 | 130 | * reception is up to the port */ |
donatien | 0:632c9925f013 | 131 | #ifndef PPP_INPROC_OWNTHREAD |
donatien | 0:632c9925f013 | 132 | #define PPP_INPROC_OWNTHREAD PPP_INPROC_MULTITHREADED |
donatien | 0:632c9925f013 | 133 | #endif |
donatien | 0:632c9925f013 | 134 | |
donatien | 0:632c9925f013 | 135 | #if PPP_INPROC_OWNTHREAD && !PPP_INPROC_MULTITHREADED |
donatien | 0:632c9925f013 | 136 | #error "PPP_INPROC_OWNTHREAD needs PPP_INPROC_MULTITHREADED==1" |
donatien | 0:632c9925f013 | 137 | #endif |
donatien | 0:632c9925f013 | 138 | |
donatien | 0:632c9925f013 | 139 | /* |
donatien | 0:632c9925f013 | 140 | * The basic PPP frame. |
donatien | 0:632c9925f013 | 141 | */ |
donatien | 0:632c9925f013 | 142 | #define PPP_ADDRESS(p) (((u_char *)(p))[0]) |
donatien | 0:632c9925f013 | 143 | #define PPP_CONTROL(p) (((u_char *)(p))[1]) |
donatien | 0:632c9925f013 | 144 | #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3]) |
donatien | 0:632c9925f013 | 145 | |
donatien | 0:632c9925f013 | 146 | /* PPP packet parser states. Current state indicates operation yet to be |
donatien | 0:632c9925f013 | 147 | * completed. */ |
donatien | 0:632c9925f013 | 148 | typedef enum { |
donatien | 0:632c9925f013 | 149 | PDIDLE = 0, /* Idle state - waiting. */ |
donatien | 0:632c9925f013 | 150 | PDSTART, /* Process start flag. */ |
donatien | 0:632c9925f013 | 151 | PDADDRESS, /* Process address field. */ |
donatien | 0:632c9925f013 | 152 | PDCONTROL, /* Process control field. */ |
donatien | 0:632c9925f013 | 153 | PDPROTOCOL1, /* Process protocol field 1. */ |
donatien | 0:632c9925f013 | 154 | PDPROTOCOL2, /* Process protocol field 2. */ |
donatien | 0:632c9925f013 | 155 | PDDATA /* Process data byte. */ |
donatien | 0:632c9925f013 | 156 | } PPPDevStates; |
donatien | 0:632c9925f013 | 157 | |
donatien | 0:632c9925f013 | 158 | #define ESCAPE_P(accm, c) ((accm)[(c) >> 3] & pppACCMMask[c & 0x07]) |
donatien | 0:632c9925f013 | 159 | |
donatien | 0:632c9925f013 | 160 | /************************/ |
donatien | 0:632c9925f013 | 161 | /*** LOCAL DATA TYPES ***/ |
donatien | 0:632c9925f013 | 162 | /************************/ |
donatien | 0:632c9925f013 | 163 | |
donatien | 0:632c9925f013 | 164 | /** RX buffer size: this may be configured smaller! */ |
donatien | 0:632c9925f013 | 165 | #ifndef PPPOS_RX_BUFSIZE |
donatien | 0:632c9925f013 | 166 | #define PPPOS_RX_BUFSIZE (PPP_MRU + PPP_HDRLEN) |
donatien | 0:632c9925f013 | 167 | #endif |
donatien | 0:632c9925f013 | 168 | |
donatien | 0:632c9925f013 | 169 | typedef struct PPPControlRx_s { |
donatien | 0:632c9925f013 | 170 | /** unit number / ppp descriptor */ |
donatien | 0:632c9925f013 | 171 | int pd; |
donatien | 0:632c9925f013 | 172 | /** the rx file descriptor */ |
donatien | 0:632c9925f013 | 173 | sio_fd_t fd; |
donatien | 0:632c9925f013 | 174 | /** receive buffer - encoded data is stored here */ |
donatien | 0:632c9925f013 | 175 | u_char rxbuf[PPPOS_RX_BUFSIZE]; |
donatien | 0:632c9925f013 | 176 | |
donatien | 0:632c9925f013 | 177 | /* The input packet. */ |
donatien | 0:632c9925f013 | 178 | struct pbuf *inHead, *inTail; |
donatien | 0:632c9925f013 | 179 | |
donatien | 0:632c9925f013 | 180 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 181 | u16_t inProtocol; /* The input protocol code. */ |
donatien | 0:632c9925f013 | 182 | u16_t inFCS; /* Input Frame Check Sequence value. */ |
donatien | 0:632c9925f013 | 183 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 184 | PPPDevStates inState; /* The input process state. */ |
donatien | 0:632c9925f013 | 185 | char inEscaped; /* Escape next character. */ |
donatien | 0:632c9925f013 | 186 | ext_accm inACCM; /* Async-Ctl-Char-Map for input. */ |
donatien | 0:632c9925f013 | 187 | } PPPControlRx; |
donatien | 0:632c9925f013 | 188 | |
donatien | 0:632c9925f013 | 189 | /* |
donatien | 0:632c9925f013 | 190 | * PPP interface control block. |
donatien | 0:632c9925f013 | 191 | */ |
donatien | 0:632c9925f013 | 192 | typedef struct PPPControl_s { |
donatien | 0:632c9925f013 | 193 | PPPControlRx rx; |
donatien | 0:632c9925f013 | 194 | char openFlag; /* True when in use. */ |
donatien | 0:632c9925f013 | 195 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 196 | struct netif *ethif; |
donatien | 0:632c9925f013 | 197 | struct pppoe_softc *pppoe_sc; |
donatien | 0:632c9925f013 | 198 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 199 | int if_up; /* True when the interface is up. */ |
donatien | 0:632c9925f013 | 200 | int errCode; /* Code indicating why interface is down. */ |
donatien | 0:632c9925f013 | 201 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 202 | sio_fd_t fd; /* File device ID of port. */ |
donatien | 0:632c9925f013 | 203 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 204 | u16_t mtu; /* Peer's mru */ |
donatien | 0:632c9925f013 | 205 | int pcomp; /* Does peer accept protocol compression? */ |
donatien | 0:632c9925f013 | 206 | int accomp; /* Does peer accept addr/ctl compression? */ |
donatien | 0:632c9925f013 | 207 | u_long lastXMit; /* Time of last transmission. */ |
donatien | 0:632c9925f013 | 208 | ext_accm outACCM; /* Async-Ctl-Char-Map for output. */ |
donatien | 0:632c9925f013 | 209 | #if PPPOS_SUPPORT && VJ_SUPPORT |
donatien | 0:632c9925f013 | 210 | int vjEnabled; /* Flag indicating VJ compression enabled. */ |
donatien | 0:632c9925f013 | 211 | struct vjcompress vjComp; /* Van Jacobson compression header. */ |
donatien | 0:632c9925f013 | 212 | #endif /* PPPOS_SUPPORT && VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 213 | |
donatien | 0:632c9925f013 | 214 | struct netif netif; |
donatien | 0:632c9925f013 | 215 | |
donatien | 0:632c9925f013 | 216 | struct ppp_addrs addrs; |
donatien | 0:632c9925f013 | 217 | |
donatien | 0:632c9925f013 | 218 | void (*linkStatusCB)(void *ctx, int errCode, void *arg); |
donatien | 0:632c9925f013 | 219 | void *linkStatusCtx; |
donatien | 0:632c9925f013 | 220 | |
donatien | 0:632c9925f013 | 221 | } PPPControl; |
donatien | 0:632c9925f013 | 222 | |
donatien | 0:632c9925f013 | 223 | |
donatien | 0:632c9925f013 | 224 | /* |
donatien | 0:632c9925f013 | 225 | * Ioctl definitions. |
donatien | 0:632c9925f013 | 226 | */ |
donatien | 0:632c9925f013 | 227 | |
donatien | 0:632c9925f013 | 228 | struct npioctl { |
donatien | 0:632c9925f013 | 229 | int protocol; /* PPP procotol, e.g. PPP_IP */ |
donatien | 0:632c9925f013 | 230 | enum NPmode mode; |
donatien | 0:632c9925f013 | 231 | }; |
donatien | 0:632c9925f013 | 232 | |
donatien | 0:632c9925f013 | 233 | |
donatien | 0:632c9925f013 | 234 | |
donatien | 0:632c9925f013 | 235 | /***********************************/ |
donatien | 0:632c9925f013 | 236 | /*** LOCAL FUNCTION DECLARATIONS ***/ |
donatien | 0:632c9925f013 | 237 | /***********************************/ |
donatien | 0:632c9925f013 | 238 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 239 | #if PPP_INPROC_OWNTHREAD |
donatien | 0:632c9925f013 | 240 | static void pppInputThread(void *arg); |
donatien | 0:632c9925f013 | 241 | #endif /* PPP_INPROC_OWNTHREAD */ |
donatien | 0:632c9925f013 | 242 | static void pppDrop(PPPControlRx *pcrx); |
donatien | 0:632c9925f013 | 243 | static void pppInProc(PPPControlRx *pcrx, u_char *s, int l); |
donatien | 0:632c9925f013 | 244 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 245 | |
donatien | 0:632c9925f013 | 246 | |
donatien | 0:632c9925f013 | 247 | /******************************/ |
donatien | 0:632c9925f013 | 248 | /*** PUBLIC DATA STRUCTURES ***/ |
donatien | 0:632c9925f013 | 249 | /******************************/ |
donatien | 0:632c9925f013 | 250 | u_long subnetMask; |
donatien | 0:632c9925f013 | 251 | |
donatien | 0:632c9925f013 | 252 | static PPPControl pppControl[NUM_PPP] MEM_POSITION; /* The PPP interface control blocks. */ |
donatien | 0:632c9925f013 | 253 | |
donatien | 0:632c9925f013 | 254 | /* |
donatien | 0:632c9925f013 | 255 | * PPP Data Link Layer "protocol" table. |
donatien | 0:632c9925f013 | 256 | * One entry per supported protocol. |
donatien | 0:632c9925f013 | 257 | * The last entry must be NULL. |
donatien | 0:632c9925f013 | 258 | */ |
donatien | 0:632c9925f013 | 259 | struct protent *ppp_protocols[] = { |
donatien | 0:632c9925f013 | 260 | &lcp_protent, |
donatien | 0:632c9925f013 | 261 | #if PAP_SUPPORT |
donatien | 0:632c9925f013 | 262 | &pap_protent, |
donatien | 0:632c9925f013 | 263 | #endif /* PAP_SUPPORT */ |
donatien | 0:632c9925f013 | 264 | #if CHAP_SUPPORT |
donatien | 0:632c9925f013 | 265 | &chap_protent, |
donatien | 0:632c9925f013 | 266 | #endif /* CHAP_SUPPORT */ |
donatien | 0:632c9925f013 | 267 | #if CBCP_SUPPORT |
donatien | 0:632c9925f013 | 268 | &cbcp_protent, |
donatien | 0:632c9925f013 | 269 | #endif /* CBCP_SUPPORT */ |
donatien | 0:632c9925f013 | 270 | &ipcp_protent, |
donatien | 0:632c9925f013 | 271 | #if CCP_SUPPORT |
donatien | 0:632c9925f013 | 272 | &ccp_protent, |
donatien | 0:632c9925f013 | 273 | #endif /* CCP_SUPPORT */ |
donatien | 0:632c9925f013 | 274 | NULL |
donatien | 0:632c9925f013 | 275 | }; |
donatien | 0:632c9925f013 | 276 | |
donatien | 0:632c9925f013 | 277 | |
donatien | 0:632c9925f013 | 278 | /* |
donatien | 0:632c9925f013 | 279 | * Buffers for outgoing packets. This must be accessed only from the appropriate |
donatien | 0:632c9925f013 | 280 | * PPP task so that it doesn't need to be protected to avoid collisions. |
donatien | 0:632c9925f013 | 281 | */ |
donatien | 0:632c9925f013 | 282 | u_char outpacket_buf[NUM_PPP][PPP_MRU+PPP_HDRLEN] MEM_POSITION; |
donatien | 0:632c9925f013 | 283 | |
donatien | 0:632c9925f013 | 284 | |
donatien | 0:632c9925f013 | 285 | /*****************************/ |
donatien | 0:632c9925f013 | 286 | /*** LOCAL DATA STRUCTURES ***/ |
donatien | 0:632c9925f013 | 287 | /*****************************/ |
donatien | 0:632c9925f013 | 288 | |
donatien | 0:632c9925f013 | 289 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 290 | /* |
donatien | 0:632c9925f013 | 291 | * FCS lookup table as calculated by genfcstab. |
donatien | 0:632c9925f013 | 292 | * @todo: smaller, slower implementation for lower memory footprint? |
donatien | 0:632c9925f013 | 293 | */ |
donatien | 0:632c9925f013 | 294 | static const u_short fcstab[256] = { |
donatien | 0:632c9925f013 | 295 | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, |
donatien | 0:632c9925f013 | 296 | 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, |
donatien | 0:632c9925f013 | 297 | 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, |
donatien | 0:632c9925f013 | 298 | 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, |
donatien | 0:632c9925f013 | 299 | 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, |
donatien | 0:632c9925f013 | 300 | 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, |
donatien | 0:632c9925f013 | 301 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, |
donatien | 0:632c9925f013 | 302 | 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, |
donatien | 0:632c9925f013 | 303 | 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, |
donatien | 0:632c9925f013 | 304 | 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, |
donatien | 0:632c9925f013 | 305 | 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, |
donatien | 0:632c9925f013 | 306 | 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, |
donatien | 0:632c9925f013 | 307 | 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, |
donatien | 0:632c9925f013 | 308 | 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, |
donatien | 0:632c9925f013 | 309 | 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, |
donatien | 0:632c9925f013 | 310 | 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, |
donatien | 0:632c9925f013 | 311 | 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, |
donatien | 0:632c9925f013 | 312 | 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, |
donatien | 0:632c9925f013 | 313 | 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, |
donatien | 0:632c9925f013 | 314 | 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, |
donatien | 0:632c9925f013 | 315 | 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, |
donatien | 0:632c9925f013 | 316 | 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, |
donatien | 0:632c9925f013 | 317 | 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, |
donatien | 0:632c9925f013 | 318 | 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, |
donatien | 0:632c9925f013 | 319 | 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, |
donatien | 0:632c9925f013 | 320 | 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, |
donatien | 0:632c9925f013 | 321 | 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, |
donatien | 0:632c9925f013 | 322 | 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, |
donatien | 0:632c9925f013 | 323 | 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, |
donatien | 0:632c9925f013 | 324 | 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, |
donatien | 0:632c9925f013 | 325 | 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, |
donatien | 0:632c9925f013 | 326 | 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 |
donatien | 0:632c9925f013 | 327 | }; |
donatien | 0:632c9925f013 | 328 | |
donatien | 0:632c9925f013 | 329 | /* PPP's Asynchronous-Control-Character-Map. The mask array is used |
donatien | 0:632c9925f013 | 330 | * to select the specific bit for a character. */ |
donatien | 0:632c9925f013 | 331 | static u_char pppACCMMask[] = { |
donatien | 0:632c9925f013 | 332 | 0x01, |
donatien | 0:632c9925f013 | 333 | 0x02, |
donatien | 0:632c9925f013 | 334 | 0x04, |
donatien | 0:632c9925f013 | 335 | 0x08, |
donatien | 0:632c9925f013 | 336 | 0x10, |
donatien | 0:632c9925f013 | 337 | 0x20, |
donatien | 0:632c9925f013 | 338 | 0x40, |
donatien | 0:632c9925f013 | 339 | 0x80 |
donatien | 0:632c9925f013 | 340 | }; |
donatien | 0:632c9925f013 | 341 | |
donatien | 0:632c9925f013 | 342 | /** Wake up the task blocked in reading from serial line (if any) */ |
donatien | 0:632c9925f013 | 343 | static void |
donatien | 0:632c9925f013 | 344 | pppRecvWakeup(int pd) |
donatien | 0:632c9925f013 | 345 | { |
donatien | 0:632c9925f013 | 346 | PPPDEBUG(LOG_DEBUG, ("pppRecvWakeup: unit %d\n", pd)); |
donatien | 0:632c9925f013 | 347 | sio_read_abort(pppControl[pd].fd); |
donatien | 0:632c9925f013 | 348 | } |
donatien | 0:632c9925f013 | 349 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 350 | |
donatien | 0:632c9925f013 | 351 | void |
donatien | 0:632c9925f013 | 352 | pppLinkTerminated(int pd) |
donatien | 0:632c9925f013 | 353 | { |
donatien | 0:632c9925f013 | 354 | PPPDEBUG(LOG_DEBUG, ("pppLinkTerminated: unit %d\n", pd)); |
donatien | 0:632c9925f013 | 355 | |
donatien | 0:632c9925f013 | 356 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 357 | if (pppControl[pd].ethif) { |
donatien | 0:632c9925f013 | 358 | pppoe_disconnect(pppControl[pd].pppoe_sc); |
donatien | 0:632c9925f013 | 359 | } else |
donatien | 0:632c9925f013 | 360 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 361 | { |
donatien | 0:632c9925f013 | 362 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 363 | PPPControl* pc; |
donatien | 0:632c9925f013 | 364 | pppRecvWakeup(pd); |
donatien | 0:632c9925f013 | 365 | pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 366 | pppDrop(&pc->rx); /* bug fix #17726 */ |
donatien | 0:632c9925f013 | 367 | |
donatien | 0:632c9925f013 | 368 | PPPDEBUG(LOG_DEBUG, ("pppLinkTerminated: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); |
donatien | 0:632c9925f013 | 369 | if (pc->linkStatusCB) { |
donatien | 0:632c9925f013 | 370 | pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL, NULL); |
donatien | 0:632c9925f013 | 371 | } |
donatien | 0:632c9925f013 | 372 | |
donatien | 0:632c9925f013 | 373 | pc->openFlag = 0;/**/ |
donatien | 0:632c9925f013 | 374 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 375 | } |
donatien | 0:632c9925f013 | 376 | PPPDEBUG(LOG_DEBUG, ("pppLinkTerminated: finished.\n")); |
donatien | 0:632c9925f013 | 377 | } |
donatien | 0:632c9925f013 | 378 | |
donatien | 0:632c9925f013 | 379 | void |
donatien | 0:632c9925f013 | 380 | pppLinkDown(int pd) |
donatien | 0:632c9925f013 | 381 | { |
donatien | 0:632c9925f013 | 382 | PPPDEBUG(LOG_DEBUG, ("pppLinkDown: unit %d\n", pd)); |
donatien | 0:632c9925f013 | 383 | |
donatien | 0:632c9925f013 | 384 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 385 | if (pppControl[pd].ethif) { |
donatien | 0:632c9925f013 | 386 | pppoe_disconnect(pppControl[pd].pppoe_sc); |
donatien | 0:632c9925f013 | 387 | } else |
donatien | 0:632c9925f013 | 388 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 389 | { |
donatien | 0:632c9925f013 | 390 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 391 | pppRecvWakeup(pd); |
donatien | 0:632c9925f013 | 392 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 393 | } |
donatien | 0:632c9925f013 | 394 | } |
donatien | 0:632c9925f013 | 395 | |
donatien | 0:632c9925f013 | 396 | /** Initiate LCP open request */ |
donatien | 0:632c9925f013 | 397 | static void |
donatien | 0:632c9925f013 | 398 | pppStart(int pd) |
donatien | 0:632c9925f013 | 399 | { |
donatien | 0:632c9925f013 | 400 | PPPDEBUG(LOG_DEBUG, ("pppStart: unit %d\n", pd)); |
donatien | 0:632c9925f013 | 401 | lcp_lowerup(pd); |
donatien | 0:632c9925f013 | 402 | lcp_open(pd); /* Start protocol */ |
donatien | 0:632c9925f013 | 403 | PPPDEBUG(LOG_DEBUG, ("pppStart: finished\n")); |
donatien | 0:632c9925f013 | 404 | } |
donatien | 0:632c9925f013 | 405 | |
donatien | 0:632c9925f013 | 406 | /** LCP close request */ |
donatien | 0:632c9925f013 | 407 | static void |
donatien | 0:632c9925f013 | 408 | pppStop(int pd) |
donatien | 0:632c9925f013 | 409 | { |
donatien | 0:632c9925f013 | 410 | PPPDEBUG(LOG_DEBUG, ("pppStop: unit %d\n", pd)); |
donatien | 0:632c9925f013 | 411 | lcp_close(pd, "User request"); |
donatien | 0:632c9925f013 | 412 | } |
donatien | 0:632c9925f013 | 413 | |
donatien | 0:632c9925f013 | 414 | /** Called when carrier/link is lost */ |
donatien | 0:632c9925f013 | 415 | static void |
donatien | 0:632c9925f013 | 416 | pppHup(int pd) |
donatien | 0:632c9925f013 | 417 | { |
donatien | 0:632c9925f013 | 418 | PPPDEBUG(LOG_DEBUG, ("pppHupCB: unit %d\n", pd)); |
donatien | 0:632c9925f013 | 419 | lcp_lowerdown(pd); |
donatien | 0:632c9925f013 | 420 | link_terminated(pd); |
donatien | 0:632c9925f013 | 421 | } |
donatien | 0:632c9925f013 | 422 | |
donatien | 0:632c9925f013 | 423 | /***********************************/ |
donatien | 0:632c9925f013 | 424 | /*** PUBLIC FUNCTION DEFINITIONS ***/ |
donatien | 0:632c9925f013 | 425 | /***********************************/ |
donatien | 0:632c9925f013 | 426 | /* Initialize the PPP subsystem. */ |
donatien | 0:632c9925f013 | 427 | |
donatien | 0:632c9925f013 | 428 | struct ppp_settings ppp_settings; |
donatien | 0:632c9925f013 | 429 | |
donatien | 0:632c9925f013 | 430 | void |
donatien | 0:632c9925f013 | 431 | pppInit(void) |
donatien | 0:632c9925f013 | 432 | { |
donatien | 0:632c9925f013 | 433 | struct protent *protp; |
donatien | 0:632c9925f013 | 434 | int i, j; |
donatien | 0:632c9925f013 | 435 | |
donatien | 0:632c9925f013 | 436 | memset(&ppp_settings, 0, sizeof(ppp_settings)); |
donatien | 0:632c9925f013 | 437 | ppp_settings.usepeerdns = 1; |
donatien | 0:632c9925f013 | 438 | pppSetAuth(PPPAUTHTYPE_NONE, NULL, NULL); |
donatien | 0:632c9925f013 | 439 | |
donatien | 0:632c9925f013 | 440 | magicInit(); |
donatien | 0:632c9925f013 | 441 | |
donatien | 0:632c9925f013 | 442 | subnetMask = htonl(0xffffff00); |
donatien | 0:632c9925f013 | 443 | |
donatien | 0:632c9925f013 | 444 | for (i = 0; i < NUM_PPP; i++) { |
donatien | 0:632c9925f013 | 445 | /* Initialize each protocol to the standard option set. */ |
donatien | 0:632c9925f013 | 446 | for (j = 0; (protp = ppp_protocols[j]) != NULL; ++j) { |
donatien | 0:632c9925f013 | 447 | (*protp->init)(i); |
donatien | 0:632c9925f013 | 448 | } |
donatien | 0:632c9925f013 | 449 | } |
donatien | 0:632c9925f013 | 450 | |
donatien | 0:632c9925f013 | 451 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 452 | pppoe_init(); |
donatien | 0:632c9925f013 | 453 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 454 | } |
donatien | 0:632c9925f013 | 455 | |
donatien | 0:632c9925f013 | 456 | void |
donatien | 0:632c9925f013 | 457 | pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd) |
donatien | 0:632c9925f013 | 458 | { |
donatien | 0:632c9925f013 | 459 | switch(authType) { |
donatien | 0:632c9925f013 | 460 | case PPPAUTHTYPE_NONE: |
donatien | 0:632c9925f013 | 461 | default: |
donatien | 0:632c9925f013 | 462 | #ifdef LWIP_PPP_STRICT_PAP_REJECT |
donatien | 0:632c9925f013 | 463 | ppp_settings.refuse_pap = 1; |
donatien | 0:632c9925f013 | 464 | #else /* LWIP_PPP_STRICT_PAP_REJECT */ |
donatien | 0:632c9925f013 | 465 | /* some providers request pap and accept an empty login/pw */ |
donatien | 0:632c9925f013 | 466 | ppp_settings.refuse_pap = 0; |
donatien | 0:632c9925f013 | 467 | #endif /* LWIP_PPP_STRICT_PAP_REJECT */ |
donatien | 0:632c9925f013 | 468 | ppp_settings.refuse_chap = 1; |
donatien | 0:632c9925f013 | 469 | break; |
donatien | 0:632c9925f013 | 470 | |
donatien | 0:632c9925f013 | 471 | case PPPAUTHTYPE_ANY: |
donatien | 0:632c9925f013 | 472 | /* Warning: Using PPPAUTHTYPE_ANY might have security consequences. |
donatien | 0:632c9925f013 | 473 | * RFC 1994 says: |
donatien | 0:632c9925f013 | 474 | * |
donatien | 0:632c9925f013 | 475 | * In practice, within or associated with each PPP server, there is a |
donatien | 0:632c9925f013 | 476 | * database which associates "user" names with authentication |
donatien | 0:632c9925f013 | 477 | * information ("secrets"). It is not anticipated that a particular |
donatien | 0:632c9925f013 | 478 | * named user would be authenticated by multiple methods. This would |
donatien | 0:632c9925f013 | 479 | * make the user vulnerable to attacks which negotiate the least secure |
donatien | 0:632c9925f013 | 480 | * method from among a set (such as PAP rather than CHAP). If the same |
donatien | 0:632c9925f013 | 481 | * secret was used, PAP would reveal the secret to be used later with |
donatien | 0:632c9925f013 | 482 | * CHAP. |
donatien | 0:632c9925f013 | 483 | * |
donatien | 0:632c9925f013 | 484 | * Instead, for each user name there should be an indication of exactly |
donatien | 0:632c9925f013 | 485 | * one method used to authenticate that user name. If a user needs to |
donatien | 0:632c9925f013 | 486 | * make use of different authentication methods under different |
donatien | 0:632c9925f013 | 487 | * circumstances, then distinct user names SHOULD be employed, each of |
donatien | 0:632c9925f013 | 488 | * which identifies exactly one authentication method. |
donatien | 0:632c9925f013 | 489 | * |
donatien | 0:632c9925f013 | 490 | */ |
donatien | 0:632c9925f013 | 491 | ppp_settings.refuse_pap = 0; |
donatien | 0:632c9925f013 | 492 | ppp_settings.refuse_chap = 0; |
donatien | 0:632c9925f013 | 493 | break; |
donatien | 0:632c9925f013 | 494 | |
donatien | 0:632c9925f013 | 495 | case PPPAUTHTYPE_PAP: |
donatien | 0:632c9925f013 | 496 | ppp_settings.refuse_pap = 0; |
donatien | 0:632c9925f013 | 497 | ppp_settings.refuse_chap = 1; |
donatien | 0:632c9925f013 | 498 | break; |
donatien | 0:632c9925f013 | 499 | |
donatien | 0:632c9925f013 | 500 | case PPPAUTHTYPE_CHAP: |
donatien | 0:632c9925f013 | 501 | ppp_settings.refuse_pap = 1; |
donatien | 0:632c9925f013 | 502 | ppp_settings.refuse_chap = 0; |
donatien | 0:632c9925f013 | 503 | break; |
donatien | 0:632c9925f013 | 504 | } |
donatien | 0:632c9925f013 | 505 | |
donatien | 0:632c9925f013 | 506 | if(user) { |
donatien | 0:632c9925f013 | 507 | strncpy(ppp_settings.user, user, sizeof(ppp_settings.user)-1); |
donatien | 0:632c9925f013 | 508 | ppp_settings.user[sizeof(ppp_settings.user)-1] = '\0'; |
donatien | 0:632c9925f013 | 509 | } else { |
donatien | 0:632c9925f013 | 510 | ppp_settings.user[0] = '\0'; |
donatien | 0:632c9925f013 | 511 | } |
donatien | 0:632c9925f013 | 512 | |
donatien | 0:632c9925f013 | 513 | if(passwd) { |
donatien | 0:632c9925f013 | 514 | strncpy(ppp_settings.passwd, passwd, sizeof(ppp_settings.passwd)-1); |
donatien | 0:632c9925f013 | 515 | ppp_settings.passwd[sizeof(ppp_settings.passwd)-1] = '\0'; |
donatien | 0:632c9925f013 | 516 | } else { |
donatien | 0:632c9925f013 | 517 | ppp_settings.passwd[0] = '\0'; |
donatien | 0:632c9925f013 | 518 | } |
donatien | 0:632c9925f013 | 519 | } |
donatien | 0:632c9925f013 | 520 | |
donatien | 0:632c9925f013 | 521 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 522 | /** Open a new PPP connection using the given I/O device. |
donatien | 0:632c9925f013 | 523 | * This initializes the PPP control block but does not |
donatien | 0:632c9925f013 | 524 | * attempt to negotiate the LCP session. If this port |
donatien | 0:632c9925f013 | 525 | * connects to a modem, the modem connection must be |
donatien | 0:632c9925f013 | 526 | * established before calling this. |
donatien | 0:632c9925f013 | 527 | * Return a new PPP connection descriptor on success or |
donatien | 0:632c9925f013 | 528 | * an error code (negative) on failure. |
donatien | 0:632c9925f013 | 529 | * |
donatien | 0:632c9925f013 | 530 | * pppOpen() is directly defined to this function. |
donatien | 0:632c9925f013 | 531 | */ |
donatien | 0:632c9925f013 | 532 | int |
donatien | 0:632c9925f013 | 533 | pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx) |
donatien | 0:632c9925f013 | 534 | { |
donatien | 0:632c9925f013 | 535 | PPPControl *pc; |
donatien | 0:632c9925f013 | 536 | int pd; |
donatien | 0:632c9925f013 | 537 | |
donatien | 0:632c9925f013 | 538 | if (linkStatusCB == NULL) { |
donatien | 0:632c9925f013 | 539 | /* PPP is single-threaded: without a callback, |
donatien | 0:632c9925f013 | 540 | * there is no way to know when the link is up. */ |
donatien | 0:632c9925f013 | 541 | return PPPERR_PARAM; |
donatien | 0:632c9925f013 | 542 | } |
donatien | 0:632c9925f013 | 543 | |
donatien | 0:632c9925f013 | 544 | /* Find a free PPP session descriptor. */ |
donatien | 0:632c9925f013 | 545 | for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++); |
donatien | 0:632c9925f013 | 546 | |
donatien | 0:632c9925f013 | 547 | if (pd >= NUM_PPP) { |
donatien | 0:632c9925f013 | 548 | pd = PPPERR_OPEN; |
donatien | 0:632c9925f013 | 549 | } else { |
donatien | 0:632c9925f013 | 550 | pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 551 | /* @todo: is this correct or do I overwrite something? */ |
donatien | 0:632c9925f013 | 552 | memset(pc, 0, sizeof(PPPControl)); |
donatien | 0:632c9925f013 | 553 | pc->rx.pd = pd; |
donatien | 0:632c9925f013 | 554 | pc->rx.fd = fd; |
donatien | 0:632c9925f013 | 555 | |
donatien | 0:632c9925f013 | 556 | pc->openFlag = 1; |
donatien | 0:632c9925f013 | 557 | pc->fd = fd; |
donatien | 0:632c9925f013 | 558 | |
donatien | 0:632c9925f013 | 559 | #if VJ_SUPPORT |
donatien | 0:632c9925f013 | 560 | vj_compress_init(&pc->vjComp); |
donatien | 0:632c9925f013 | 561 | #endif /* VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 562 | |
donatien | 0:632c9925f013 | 563 | /* |
donatien | 0:632c9925f013 | 564 | * Default the in and out accm so that escape and flag characters |
donatien | 0:632c9925f013 | 565 | * are always escaped. |
donatien | 0:632c9925f013 | 566 | */ |
donatien | 0:632c9925f013 | 567 | pc->rx.inACCM[15] = 0x60; /* no need to protect since RX is not running */ |
donatien | 0:632c9925f013 | 568 | pc->outACCM[15] = 0x60; |
donatien | 0:632c9925f013 | 569 | |
donatien | 0:632c9925f013 | 570 | pc->linkStatusCB = linkStatusCB; |
donatien | 0:632c9925f013 | 571 | pc->linkStatusCtx = linkStatusCtx; |
donatien | 0:632c9925f013 | 572 | |
donatien | 0:632c9925f013 | 573 | /* |
donatien | 0:632c9925f013 | 574 | * Start the connection and handle incoming events (packet or timeout). |
donatien | 0:632c9925f013 | 575 | */ |
donatien | 0:632c9925f013 | 576 | PPPDEBUG(LOG_INFO, ("pppOverSerialOpen: unit %d: Connecting\n", pd)); |
donatien | 0:632c9925f013 | 577 | pppStart(pd); |
donatien | 0:632c9925f013 | 578 | #if PPP_INPROC_OWNTHREAD |
donatien | 0:632c9925f013 | 579 | sys_thread_new(PPP_THREAD_NAME, pppInputThread, (void*)&pc->rx, PPP_THREAD_STACKSIZE, PPP_THREAD_PRIO); |
donatien | 0:632c9925f013 | 580 | #endif |
donatien | 0:632c9925f013 | 581 | } |
donatien | 0:632c9925f013 | 582 | |
donatien | 0:632c9925f013 | 583 | return pd; |
donatien | 0:632c9925f013 | 584 | } |
donatien | 0:632c9925f013 | 585 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 586 | |
donatien | 0:632c9925f013 | 587 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 588 | static void pppOverEthernetLinkStatusCB(int pd, int up); |
donatien | 0:632c9925f013 | 589 | |
donatien | 0:632c9925f013 | 590 | void |
donatien | 0:632c9925f013 | 591 | pppOverEthernetClose(int pd) |
donatien | 0:632c9925f013 | 592 | { |
donatien | 0:632c9925f013 | 593 | PPPControl* pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 594 | |
donatien | 0:632c9925f013 | 595 | /* *TJL* There's no lcp_deinit */ |
donatien | 0:632c9925f013 | 596 | lcp_close(pd, NULL); |
donatien | 0:632c9925f013 | 597 | |
donatien | 0:632c9925f013 | 598 | pppoe_destroy(&pc->netif); |
donatien | 0:632c9925f013 | 599 | } |
donatien | 0:632c9925f013 | 600 | |
donatien | 0:632c9925f013 | 601 | int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const char *concentrator_name, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx) |
donatien | 0:632c9925f013 | 602 | { |
donatien | 0:632c9925f013 | 603 | PPPControl *pc; |
donatien | 0:632c9925f013 | 604 | int pd; |
donatien | 0:632c9925f013 | 605 | |
donatien | 0:632c9925f013 | 606 | LWIP_UNUSED_ARG(service_name); |
donatien | 0:632c9925f013 | 607 | LWIP_UNUSED_ARG(concentrator_name); |
donatien | 0:632c9925f013 | 608 | |
donatien | 0:632c9925f013 | 609 | if (linkStatusCB == NULL) { |
donatien | 0:632c9925f013 | 610 | /* PPP is single-threaded: without a callback, |
donatien | 0:632c9925f013 | 611 | * there is no way to know when the link is up. */ |
donatien | 0:632c9925f013 | 612 | return PPPERR_PARAM; |
donatien | 0:632c9925f013 | 613 | } |
donatien | 0:632c9925f013 | 614 | |
donatien | 0:632c9925f013 | 615 | /* Find a free PPP session descriptor. Critical region? */ |
donatien | 0:632c9925f013 | 616 | for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++); |
donatien | 0:632c9925f013 | 617 | if (pd >= NUM_PPP) { |
donatien | 0:632c9925f013 | 618 | pd = PPPERR_OPEN; |
donatien | 0:632c9925f013 | 619 | } else { |
donatien | 0:632c9925f013 | 620 | pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 621 | memset(pc, 0, sizeof(PPPControl)); |
donatien | 0:632c9925f013 | 622 | pc->openFlag = 1; |
donatien | 0:632c9925f013 | 623 | pc->ethif = ethif; |
donatien | 0:632c9925f013 | 624 | |
donatien | 0:632c9925f013 | 625 | pc->linkStatusCB = linkStatusCB; |
donatien | 0:632c9925f013 | 626 | pc->linkStatusCtx = linkStatusCtx; |
donatien | 0:632c9925f013 | 627 | |
donatien | 0:632c9925f013 | 628 | lcp_wantoptions[pd].mru = PPPOE_MAXMTU; |
donatien | 0:632c9925f013 | 629 | lcp_wantoptions[pd].neg_asyncmap = 0; |
donatien | 0:632c9925f013 | 630 | lcp_wantoptions[pd].neg_pcompression = 0; |
donatien | 0:632c9925f013 | 631 | lcp_wantoptions[pd].neg_accompression = 0; |
donatien | 0:632c9925f013 | 632 | |
donatien | 0:632c9925f013 | 633 | lcp_allowoptions[pd].mru = PPPOE_MAXMTU; |
donatien | 0:632c9925f013 | 634 | lcp_allowoptions[pd].neg_asyncmap = 0; |
donatien | 0:632c9925f013 | 635 | lcp_allowoptions[pd].neg_pcompression = 0; |
donatien | 0:632c9925f013 | 636 | lcp_allowoptions[pd].neg_accompression = 0; |
donatien | 0:632c9925f013 | 637 | |
donatien | 0:632c9925f013 | 638 | if(pppoe_create(ethif, pd, pppOverEthernetLinkStatusCB, &pc->pppoe_sc) != ERR_OK) { |
donatien | 0:632c9925f013 | 639 | pc->openFlag = 0; |
donatien | 0:632c9925f013 | 640 | return PPPERR_OPEN; |
donatien | 0:632c9925f013 | 641 | } |
donatien | 0:632c9925f013 | 642 | |
donatien | 0:632c9925f013 | 643 | pppoe_connect(pc->pppoe_sc); |
donatien | 0:632c9925f013 | 644 | } |
donatien | 0:632c9925f013 | 645 | |
donatien | 0:632c9925f013 | 646 | return pd; |
donatien | 0:632c9925f013 | 647 | } |
donatien | 0:632c9925f013 | 648 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 649 | |
donatien | 0:632c9925f013 | 650 | |
donatien | 0:632c9925f013 | 651 | /* Close a PPP connection and release the descriptor. |
donatien | 0:632c9925f013 | 652 | * Any outstanding packets in the queues are dropped. |
donatien | 0:632c9925f013 | 653 | * Return 0 on success, an error code on failure. */ |
donatien | 0:632c9925f013 | 654 | int |
donatien | 0:632c9925f013 | 655 | pppClose(int pd) |
donatien | 0:632c9925f013 | 656 | { |
donatien | 0:632c9925f013 | 657 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 658 | int st = 0; |
donatien | 0:632c9925f013 | 659 | |
donatien | 0:632c9925f013 | 660 | PPPDEBUG(LOG_DEBUG, ("pppClose() called\n")); |
donatien | 0:632c9925f013 | 661 | |
donatien | 0:632c9925f013 | 662 | /* Disconnect */ |
donatien | 0:632c9925f013 | 663 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 664 | if(pc->ethif) { |
donatien | 0:632c9925f013 | 665 | PPPDEBUG(LOG_DEBUG, ("pppClose: unit %d kill_link -> pppStop\n", pd)); |
donatien | 0:632c9925f013 | 666 | pc->errCode = PPPERR_USER; |
donatien | 0:632c9925f013 | 667 | /* This will leave us at PHASE_DEAD. */ |
donatien | 0:632c9925f013 | 668 | pppStop(pd); |
donatien | 0:632c9925f013 | 669 | } else |
donatien | 0:632c9925f013 | 670 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 671 | { |
donatien | 0:632c9925f013 | 672 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 673 | PPPDEBUG(LOG_DEBUG, ("pppClose: unit %d kill_link -> pppStop\n", pd)); |
donatien | 0:632c9925f013 | 674 | pc->errCode = PPPERR_USER; |
donatien | 0:632c9925f013 | 675 | /* This will leave us at PHASE_DEAD. */ |
donatien | 0:632c9925f013 | 676 | pppStop(pd); |
donatien | 0:632c9925f013 | 677 | pppRecvWakeup(pd); |
donatien | 0:632c9925f013 | 678 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 679 | } |
donatien | 0:632c9925f013 | 680 | |
donatien | 0:632c9925f013 | 681 | return st; |
donatien | 0:632c9925f013 | 682 | } |
donatien | 0:632c9925f013 | 683 | |
donatien | 0:632c9925f013 | 684 | /* This function is called when carrier is lost on the PPP channel. */ |
donatien | 0:632c9925f013 | 685 | void |
donatien | 0:632c9925f013 | 686 | pppSigHUP(int pd) |
donatien | 0:632c9925f013 | 687 | { |
donatien | 0:632c9925f013 | 688 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 689 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 690 | if(pc->ethif) { |
donatien | 0:632c9925f013 | 691 | PPPDEBUG(LOG_DEBUG, ("pppSigHUP: unit %d sig_hup -> pppHupCB\n", pd)); |
donatien | 0:632c9925f013 | 692 | pppHup(pd); |
donatien | 0:632c9925f013 | 693 | } else |
donatien | 0:632c9925f013 | 694 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 695 | { |
donatien | 0:632c9925f013 | 696 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 697 | PPPDEBUG(LOG_DEBUG, ("pppSigHUP: unit %d sig_hup -> pppHupCB\n", pd)); |
donatien | 0:632c9925f013 | 698 | pppHup(pd); |
donatien | 0:632c9925f013 | 699 | pppRecvWakeup(pd); |
donatien | 0:632c9925f013 | 700 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 701 | } |
donatien | 0:632c9925f013 | 702 | } |
donatien | 0:632c9925f013 | 703 | |
donatien | 0:632c9925f013 | 704 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 705 | static void |
donatien | 0:632c9925f013 | 706 | nPut(PPPControl *pc, struct pbuf *nb) |
donatien | 0:632c9925f013 | 707 | { |
donatien | 0:632c9925f013 | 708 | struct pbuf *b; |
donatien | 0:632c9925f013 | 709 | int c = 0; |
donatien | 0:632c9925f013 | 710 | |
donatien | 0:632c9925f013 | 711 | for(b = nb; b != NULL; b = b->next) { |
donatien | 0:632c9925f013 | 712 | if((c = sio_write(pc->fd, (u8_t*)b->payload, b->len)) != b->len) { |
donatien | 0:632c9925f013 | 713 | PPPDEBUG(LOG_WARNING, |
donatien | 0:632c9925f013 | 714 | ("PPP nPut: incomplete sio_write(fd:%d, len:%d, c: 0x%"X8_F") c = %d\n", (size_t)pc->fd, b->len, c, c)); |
donatien | 0:632c9925f013 | 715 | LINK_STATS_INC(link.err); |
donatien | 0:632c9925f013 | 716 | pc->lastXMit = 0; /* prepend PPP_FLAG to next packet */ |
donatien | 0:632c9925f013 | 717 | snmp_inc_ifoutdiscards(&pc->netif); |
donatien | 0:632c9925f013 | 718 | pbuf_free(nb); |
donatien | 0:632c9925f013 | 719 | return; |
donatien | 0:632c9925f013 | 720 | } |
donatien | 0:632c9925f013 | 721 | } |
donatien | 0:632c9925f013 | 722 | |
donatien | 0:632c9925f013 | 723 | snmp_add_ifoutoctets(&pc->netif, nb->tot_len); |
donatien | 0:632c9925f013 | 724 | snmp_inc_ifoutucastpkts(&pc->netif); |
donatien | 0:632c9925f013 | 725 | pbuf_free(nb); |
donatien | 0:632c9925f013 | 726 | LINK_STATS_INC(link.xmit); |
donatien | 0:632c9925f013 | 727 | } |
donatien | 0:632c9925f013 | 728 | |
donatien | 0:632c9925f013 | 729 | /* |
donatien | 0:632c9925f013 | 730 | * pppAppend - append given character to end of given pbuf. If outACCM |
donatien | 0:632c9925f013 | 731 | * is not NULL and the character needs to be escaped, do so. |
donatien | 0:632c9925f013 | 732 | * If pbuf is full, append another. |
donatien | 0:632c9925f013 | 733 | * Return the current pbuf. |
donatien | 0:632c9925f013 | 734 | */ |
donatien | 0:632c9925f013 | 735 | static struct pbuf * |
donatien | 0:632c9925f013 | 736 | pppAppend(u_char c, struct pbuf *nb, ext_accm *outACCM) |
donatien | 0:632c9925f013 | 737 | { |
donatien | 0:632c9925f013 | 738 | struct pbuf *tb = nb; |
donatien | 0:632c9925f013 | 739 | |
donatien | 0:632c9925f013 | 740 | /* Make sure there is room for the character and an escape code. |
donatien | 0:632c9925f013 | 741 | * Sure we don't quite fill the buffer if the character doesn't |
donatien | 0:632c9925f013 | 742 | * get escaped but is one character worth complicating this? */ |
donatien | 0:632c9925f013 | 743 | /* Note: We assume no packet header. */ |
donatien | 0:632c9925f013 | 744 | if (nb && (PBUF_POOL_BUFSIZE - nb->len) < 2) { |
donatien | 0:632c9925f013 | 745 | tb = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); |
donatien | 0:632c9925f013 | 746 | if (tb) { |
donatien | 0:632c9925f013 | 747 | nb->next = tb; |
donatien | 0:632c9925f013 | 748 | } else { |
donatien | 0:632c9925f013 | 749 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 750 | } |
donatien | 0:632c9925f013 | 751 | nb = tb; |
donatien | 0:632c9925f013 | 752 | } |
donatien | 0:632c9925f013 | 753 | |
donatien | 0:632c9925f013 | 754 | if (nb) { |
donatien | 0:632c9925f013 | 755 | if (outACCM && ESCAPE_P(*outACCM, c)) { |
donatien | 0:632c9925f013 | 756 | *((u_char*)nb->payload + nb->len++) = PPP_ESCAPE; |
donatien | 0:632c9925f013 | 757 | *((u_char*)nb->payload + nb->len++) = c ^ PPP_TRANS; |
donatien | 0:632c9925f013 | 758 | } else { |
donatien | 0:632c9925f013 | 759 | *((u_char*)nb->payload + nb->len++) = c; |
donatien | 0:632c9925f013 | 760 | } |
donatien | 0:632c9925f013 | 761 | } |
donatien | 0:632c9925f013 | 762 | |
donatien | 0:632c9925f013 | 763 | return tb; |
donatien | 0:632c9925f013 | 764 | } |
donatien | 0:632c9925f013 | 765 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 766 | |
donatien | 0:632c9925f013 | 767 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 768 | static err_t |
donatien | 0:632c9925f013 | 769 | pppnetifOutputOverEthernet(int pd, struct pbuf *p) |
donatien | 0:632c9925f013 | 770 | { |
donatien | 0:632c9925f013 | 771 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 772 | struct pbuf *pb; |
donatien | 0:632c9925f013 | 773 | u_short protocol = PPP_IP; |
donatien | 0:632c9925f013 | 774 | int i=0; |
donatien | 0:632c9925f013 | 775 | u16_t tot_len; |
donatien | 0:632c9925f013 | 776 | |
donatien | 0:632c9925f013 | 777 | /* @todo: try to use pbuf_header() here! */ |
donatien | 0:632c9925f013 | 778 | pb = pbuf_alloc(PBUF_LINK, PPPOE_HDRLEN + sizeof(protocol), PBUF_RAM); |
donatien | 0:632c9925f013 | 779 | if(!pb) { |
donatien | 0:632c9925f013 | 780 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 781 | LINK_STATS_INC(link.proterr); |
donatien | 0:632c9925f013 | 782 | snmp_inc_ifoutdiscards(&pc->netif); |
donatien | 0:632c9925f013 | 783 | return ERR_MEM; |
donatien | 0:632c9925f013 | 784 | } |
donatien | 0:632c9925f013 | 785 | |
donatien | 0:632c9925f013 | 786 | pbuf_header(pb, -(s16_t)PPPOE_HDRLEN); |
donatien | 0:632c9925f013 | 787 | |
donatien | 0:632c9925f013 | 788 | pc->lastXMit = sys_jiffies(); |
donatien | 0:632c9925f013 | 789 | |
donatien | 0:632c9925f013 | 790 | if (!pc->pcomp || protocol > 0xFF) { |
donatien | 0:632c9925f013 | 791 | *((u_char*)pb->payload + i++) = (protocol >> 8) & 0xFF; |
donatien | 0:632c9925f013 | 792 | } |
donatien | 0:632c9925f013 | 793 | *((u_char*)pb->payload + i) = protocol & 0xFF; |
donatien | 0:632c9925f013 | 794 | |
donatien | 0:632c9925f013 | 795 | pbuf_chain(pb, p); |
donatien | 0:632c9925f013 | 796 | tot_len = pb->tot_len; |
donatien | 0:632c9925f013 | 797 | |
donatien | 0:632c9925f013 | 798 | if(pppoe_xmit(pc->pppoe_sc, pb) != ERR_OK) { |
donatien | 0:632c9925f013 | 799 | LINK_STATS_INC(link.err); |
donatien | 0:632c9925f013 | 800 | snmp_inc_ifoutdiscards(&pc->netif); |
donatien | 0:632c9925f013 | 801 | return PPPERR_DEVICE; |
donatien | 0:632c9925f013 | 802 | } |
donatien | 0:632c9925f013 | 803 | |
donatien | 0:632c9925f013 | 804 | snmp_add_ifoutoctets(&pc->netif, tot_len); |
donatien | 0:632c9925f013 | 805 | snmp_inc_ifoutucastpkts(&pc->netif); |
donatien | 0:632c9925f013 | 806 | LINK_STATS_INC(link.xmit); |
donatien | 0:632c9925f013 | 807 | return ERR_OK; |
donatien | 0:632c9925f013 | 808 | } |
donatien | 0:632c9925f013 | 809 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 810 | |
donatien | 0:632c9925f013 | 811 | /* Send a packet on the given connection. */ |
donatien | 0:632c9925f013 | 812 | static err_t |
donatien | 0:632c9925f013 | 813 | pppnetifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr) |
donatien | 0:632c9925f013 | 814 | { |
donatien | 0:632c9925f013 | 815 | int pd = (int)(size_t)netif->state; |
donatien | 0:632c9925f013 | 816 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 817 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 818 | u_short protocol = PPP_IP; |
donatien | 0:632c9925f013 | 819 | u_int fcsOut = PPP_INITFCS; |
donatien | 0:632c9925f013 | 820 | struct pbuf *headMB = NULL, *tailMB = NULL, *p; |
donatien | 0:632c9925f013 | 821 | u_char c; |
donatien | 0:632c9925f013 | 822 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 823 | |
donatien | 0:632c9925f013 | 824 | LWIP_UNUSED_ARG(ipaddr); |
donatien | 0:632c9925f013 | 825 | |
donatien | 0:632c9925f013 | 826 | /* Validate parameters. */ |
donatien | 0:632c9925f013 | 827 | /* We let any protocol value go through - it can't hurt us |
donatien | 0:632c9925f013 | 828 | * and the peer will just drop it if it's not accepting it. */ |
donatien | 0:632c9925f013 | 829 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag || !pb) { |
donatien | 0:632c9925f013 | 830 | PPPDEBUG(LOG_WARNING, ("pppnetifOutput[%d]: bad parms prot=%d pb=%p\n", |
donatien | 0:632c9925f013 | 831 | pd, PPP_IP, pb)); |
donatien | 0:632c9925f013 | 832 | LINK_STATS_INC(link.opterr); |
donatien | 0:632c9925f013 | 833 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 834 | snmp_inc_ifoutdiscards(netif); |
donatien | 0:632c9925f013 | 835 | return ERR_ARG; |
donatien | 0:632c9925f013 | 836 | } |
donatien | 0:632c9925f013 | 837 | |
donatien | 0:632c9925f013 | 838 | /* Check that the link is up. */ |
donatien | 0:632c9925f013 | 839 | if (lcp_phase[pd] == PHASE_DEAD) { |
donatien | 0:632c9925f013 | 840 | PPPDEBUG(LOG_ERR, ("pppnetifOutput[%d]: link not up\n", pd)); |
donatien | 0:632c9925f013 | 841 | LINK_STATS_INC(link.rterr); |
donatien | 0:632c9925f013 | 842 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 843 | snmp_inc_ifoutdiscards(netif); |
donatien | 0:632c9925f013 | 844 | return ERR_RTE; |
donatien | 0:632c9925f013 | 845 | } |
donatien | 0:632c9925f013 | 846 | |
donatien | 0:632c9925f013 | 847 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 848 | if(pc->ethif) { |
donatien | 0:632c9925f013 | 849 | return pppnetifOutputOverEthernet(pd, pb); |
donatien | 0:632c9925f013 | 850 | } |
donatien | 0:632c9925f013 | 851 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 852 | |
donatien | 0:632c9925f013 | 853 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 854 | /* Grab an output buffer. */ |
donatien | 0:632c9925f013 | 855 | headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); |
donatien | 0:632c9925f013 | 856 | if (headMB == NULL) { |
donatien | 0:632c9925f013 | 857 | PPPDEBUG(LOG_WARNING, ("pppnetifOutput[%d]: first alloc fail\n", pd)); |
donatien | 0:632c9925f013 | 858 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 859 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 860 | snmp_inc_ifoutdiscards(netif); |
donatien | 0:632c9925f013 | 861 | return ERR_MEM; |
donatien | 0:632c9925f013 | 862 | } |
donatien | 0:632c9925f013 | 863 | |
donatien | 0:632c9925f013 | 864 | #if VJ_SUPPORT |
donatien | 0:632c9925f013 | 865 | /* |
donatien | 0:632c9925f013 | 866 | * Attempt Van Jacobson header compression if VJ is configured and |
donatien | 0:632c9925f013 | 867 | * this is an IP packet. |
donatien | 0:632c9925f013 | 868 | */ |
donatien | 0:632c9925f013 | 869 | if (protocol == PPP_IP && pc->vjEnabled) { |
donatien | 0:632c9925f013 | 870 | switch (vj_compress_tcp(&pc->vjComp, pb)) { |
donatien | 0:632c9925f013 | 871 | case TYPE_IP: |
donatien | 0:632c9925f013 | 872 | /* No change... |
donatien | 0:632c9925f013 | 873 | protocol = PPP_IP_PROTOCOL; */ |
donatien | 0:632c9925f013 | 874 | break; |
donatien | 0:632c9925f013 | 875 | case TYPE_COMPRESSED_TCP: |
donatien | 0:632c9925f013 | 876 | protocol = PPP_VJC_COMP; |
donatien | 0:632c9925f013 | 877 | break; |
donatien | 0:632c9925f013 | 878 | case TYPE_UNCOMPRESSED_TCP: |
donatien | 0:632c9925f013 | 879 | protocol = PPP_VJC_UNCOMP; |
donatien | 0:632c9925f013 | 880 | break; |
donatien | 0:632c9925f013 | 881 | default: |
donatien | 0:632c9925f013 | 882 | PPPDEBUG(LOG_WARNING, ("pppnetifOutput[%d]: bad IP packet\n", pd)); |
donatien | 0:632c9925f013 | 883 | LINK_STATS_INC(link.proterr); |
donatien | 0:632c9925f013 | 884 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 885 | snmp_inc_ifoutdiscards(netif); |
donatien | 0:632c9925f013 | 886 | pbuf_free(headMB); |
donatien | 0:632c9925f013 | 887 | return ERR_VAL; |
donatien | 0:632c9925f013 | 888 | } |
donatien | 0:632c9925f013 | 889 | } |
donatien | 0:632c9925f013 | 890 | #endif /* VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 891 | |
donatien | 0:632c9925f013 | 892 | tailMB = headMB; |
donatien | 0:632c9925f013 | 893 | |
donatien | 0:632c9925f013 | 894 | /* Build the PPP header. */ |
donatien | 0:632c9925f013 | 895 | if ((sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG) { |
donatien | 0:632c9925f013 | 896 | tailMB = pppAppend(PPP_FLAG, tailMB, NULL); |
donatien | 0:632c9925f013 | 897 | } |
donatien | 0:632c9925f013 | 898 | |
donatien | 0:632c9925f013 | 899 | pc->lastXMit = sys_jiffies(); |
donatien | 0:632c9925f013 | 900 | if (!pc->accomp) { |
donatien | 0:632c9925f013 | 901 | fcsOut = PPP_FCS(fcsOut, PPP_ALLSTATIONS); |
donatien | 0:632c9925f013 | 902 | tailMB = pppAppend(PPP_ALLSTATIONS, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 903 | fcsOut = PPP_FCS(fcsOut, PPP_UI); |
donatien | 0:632c9925f013 | 904 | tailMB = pppAppend(PPP_UI, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 905 | } |
donatien | 0:632c9925f013 | 906 | if (!pc->pcomp || protocol > 0xFF) { |
donatien | 0:632c9925f013 | 907 | c = (protocol >> 8) & 0xFF; |
donatien | 0:632c9925f013 | 908 | fcsOut = PPP_FCS(fcsOut, c); |
donatien | 0:632c9925f013 | 909 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 910 | } |
donatien | 0:632c9925f013 | 911 | c = protocol & 0xFF; |
donatien | 0:632c9925f013 | 912 | fcsOut = PPP_FCS(fcsOut, c); |
donatien | 0:632c9925f013 | 913 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 914 | |
donatien | 0:632c9925f013 | 915 | /* Load packet. */ |
donatien | 0:632c9925f013 | 916 | for(p = pb; p; p = p->next) { |
donatien | 0:632c9925f013 | 917 | int n; |
donatien | 0:632c9925f013 | 918 | u_char *sPtr; |
donatien | 0:632c9925f013 | 919 | |
donatien | 0:632c9925f013 | 920 | sPtr = (u_char*)p->payload; |
donatien | 0:632c9925f013 | 921 | n = p->len; |
donatien | 0:632c9925f013 | 922 | while (n-- > 0) { |
donatien | 0:632c9925f013 | 923 | c = *sPtr++; |
donatien | 0:632c9925f013 | 924 | |
donatien | 0:632c9925f013 | 925 | /* Update FCS before checking for special characters. */ |
donatien | 0:632c9925f013 | 926 | fcsOut = PPP_FCS(fcsOut, c); |
donatien | 0:632c9925f013 | 927 | |
donatien | 0:632c9925f013 | 928 | /* Copy to output buffer escaping special characters. */ |
donatien | 0:632c9925f013 | 929 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 930 | } |
donatien | 0:632c9925f013 | 931 | } |
donatien | 0:632c9925f013 | 932 | |
donatien | 0:632c9925f013 | 933 | /* Add FCS and trailing flag. */ |
donatien | 0:632c9925f013 | 934 | c = ~fcsOut & 0xFF; |
donatien | 0:632c9925f013 | 935 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 936 | c = (~fcsOut >> 8) & 0xFF; |
donatien | 0:632c9925f013 | 937 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 938 | tailMB = pppAppend(PPP_FLAG, tailMB, NULL); |
donatien | 0:632c9925f013 | 939 | |
donatien | 0:632c9925f013 | 940 | /* If we failed to complete the packet, throw it away. */ |
donatien | 0:632c9925f013 | 941 | if (!tailMB) { |
donatien | 0:632c9925f013 | 942 | PPPDEBUG(LOG_WARNING, |
donatien | 0:632c9925f013 | 943 | ("pppnetifOutput[%d]: Alloc err - dropping proto=%d\n", |
donatien | 0:632c9925f013 | 944 | pd, protocol)); |
donatien | 0:632c9925f013 | 945 | pbuf_free(headMB); |
donatien | 0:632c9925f013 | 946 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 947 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 948 | snmp_inc_ifoutdiscards(netif); |
donatien | 0:632c9925f013 | 949 | return ERR_MEM; |
donatien | 0:632c9925f013 | 950 | } |
donatien | 0:632c9925f013 | 951 | |
donatien | 0:632c9925f013 | 952 | /* Send it. */ |
donatien | 0:632c9925f013 | 953 | PPPDEBUG(LOG_INFO, ("pppnetifOutput[%d]: proto=0x%"X16_F"\n", pd, protocol)); |
donatien | 0:632c9925f013 | 954 | |
donatien | 0:632c9925f013 | 955 | nPut(pc, headMB); |
donatien | 0:632c9925f013 | 956 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 957 | |
donatien | 0:632c9925f013 | 958 | return ERR_OK; |
donatien | 0:632c9925f013 | 959 | } |
donatien | 0:632c9925f013 | 960 | |
donatien | 0:632c9925f013 | 961 | /* Get and set parameters for the given connection. |
donatien | 0:632c9925f013 | 962 | * Return 0 on success, an error code on failure. */ |
donatien | 0:632c9925f013 | 963 | int |
donatien | 0:632c9925f013 | 964 | pppIOCtl(int pd, int cmd, void *arg) |
donatien | 0:632c9925f013 | 965 | { |
donatien | 0:632c9925f013 | 966 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 967 | int st = 0; |
donatien | 0:632c9925f013 | 968 | |
donatien | 0:632c9925f013 | 969 | if (pd < 0 || pd >= NUM_PPP) { |
donatien | 0:632c9925f013 | 970 | st = PPPERR_PARAM; |
donatien | 0:632c9925f013 | 971 | } else { |
donatien | 0:632c9925f013 | 972 | switch(cmd) { |
donatien | 0:632c9925f013 | 973 | case PPPCTLG_UPSTATUS: /* Get the PPP up status. */ |
donatien | 0:632c9925f013 | 974 | if (arg) { |
donatien | 0:632c9925f013 | 975 | *(int *)arg = (int)(pc->if_up); |
donatien | 0:632c9925f013 | 976 | } else { |
donatien | 0:632c9925f013 | 977 | st = PPPERR_PARAM; |
donatien | 0:632c9925f013 | 978 | } |
donatien | 0:632c9925f013 | 979 | break; |
donatien | 0:632c9925f013 | 980 | case PPPCTLS_ERRCODE: /* Set the PPP error code. */ |
donatien | 0:632c9925f013 | 981 | if (arg) { |
donatien | 0:632c9925f013 | 982 | pc->errCode = *(int *)arg; |
donatien | 0:632c9925f013 | 983 | } else { |
donatien | 0:632c9925f013 | 984 | st = PPPERR_PARAM; |
donatien | 0:632c9925f013 | 985 | } |
donatien | 0:632c9925f013 | 986 | break; |
donatien | 0:632c9925f013 | 987 | case PPPCTLG_ERRCODE: /* Get the PPP error code. */ |
donatien | 0:632c9925f013 | 988 | if (arg) { |
donatien | 0:632c9925f013 | 989 | *(int *)arg = (int)(pc->errCode); |
donatien | 0:632c9925f013 | 990 | } else { |
donatien | 0:632c9925f013 | 991 | st = PPPERR_PARAM; |
donatien | 0:632c9925f013 | 992 | } |
donatien | 0:632c9925f013 | 993 | break; |
donatien | 0:632c9925f013 | 994 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 995 | case PPPCTLG_FD: /* Get the fd associated with the ppp */ |
donatien | 0:632c9925f013 | 996 | if (arg) { |
donatien | 0:632c9925f013 | 997 | *(sio_fd_t *)arg = pc->fd; |
donatien | 0:632c9925f013 | 998 | } else { |
donatien | 0:632c9925f013 | 999 | st = PPPERR_PARAM; |
donatien | 0:632c9925f013 | 1000 | } |
donatien | 0:632c9925f013 | 1001 | break; |
donatien | 0:632c9925f013 | 1002 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 1003 | default: |
donatien | 0:632c9925f013 | 1004 | st = PPPERR_PARAM; |
donatien | 0:632c9925f013 | 1005 | break; |
donatien | 0:632c9925f013 | 1006 | } |
donatien | 0:632c9925f013 | 1007 | } |
donatien | 0:632c9925f013 | 1008 | |
donatien | 0:632c9925f013 | 1009 | return st; |
donatien | 0:632c9925f013 | 1010 | } |
donatien | 0:632c9925f013 | 1011 | |
donatien | 0:632c9925f013 | 1012 | /* |
donatien | 0:632c9925f013 | 1013 | * Return the Maximum Transmission Unit for the given PPP connection. |
donatien | 0:632c9925f013 | 1014 | */ |
donatien | 0:632c9925f013 | 1015 | u_short |
donatien | 0:632c9925f013 | 1016 | pppMTU(int pd) |
donatien | 0:632c9925f013 | 1017 | { |
donatien | 0:632c9925f013 | 1018 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1019 | u_short st; |
donatien | 0:632c9925f013 | 1020 | |
donatien | 0:632c9925f013 | 1021 | /* Validate parameters. */ |
donatien | 0:632c9925f013 | 1022 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { |
donatien | 0:632c9925f013 | 1023 | st = 0; |
donatien | 0:632c9925f013 | 1024 | } else { |
donatien | 0:632c9925f013 | 1025 | st = pc->mtu; |
donatien | 0:632c9925f013 | 1026 | } |
donatien | 0:632c9925f013 | 1027 | |
donatien | 0:632c9925f013 | 1028 | return st; |
donatien | 0:632c9925f013 | 1029 | } |
donatien | 0:632c9925f013 | 1030 | |
donatien | 0:632c9925f013 | 1031 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 1032 | int |
donatien | 0:632c9925f013 | 1033 | pppWriteOverEthernet(int pd, const u_char *s, int n) |
donatien | 0:632c9925f013 | 1034 | { |
donatien | 0:632c9925f013 | 1035 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1036 | struct pbuf *pb; |
donatien | 0:632c9925f013 | 1037 | |
donatien | 0:632c9925f013 | 1038 | /* skip address & flags */ |
donatien | 0:632c9925f013 | 1039 | s += 2; |
donatien | 0:632c9925f013 | 1040 | n -= 2; |
donatien | 0:632c9925f013 | 1041 | |
donatien | 0:632c9925f013 | 1042 | LWIP_ASSERT("PPPOE_HDRLEN + n <= 0xffff", PPPOE_HDRLEN + n <= 0xffff); |
donatien | 0:632c9925f013 | 1043 | pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HDRLEN + n), PBUF_RAM); |
donatien | 0:632c9925f013 | 1044 | if(!pb) { |
donatien | 0:632c9925f013 | 1045 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 1046 | LINK_STATS_INC(link.proterr); |
donatien | 0:632c9925f013 | 1047 | snmp_inc_ifoutdiscards(&pc->netif); |
donatien | 0:632c9925f013 | 1048 | return PPPERR_ALLOC; |
donatien | 0:632c9925f013 | 1049 | } |
donatien | 0:632c9925f013 | 1050 | |
donatien | 0:632c9925f013 | 1051 | pbuf_header(pb, -(s16_t)PPPOE_HDRLEN); |
donatien | 0:632c9925f013 | 1052 | |
donatien | 0:632c9925f013 | 1053 | pc->lastXMit = sys_jiffies(); |
donatien | 0:632c9925f013 | 1054 | |
donatien | 0:632c9925f013 | 1055 | MEMCPY(pb->payload, s, n); |
donatien | 0:632c9925f013 | 1056 | |
donatien | 0:632c9925f013 | 1057 | if(pppoe_xmit(pc->pppoe_sc, pb) != ERR_OK) { |
donatien | 0:632c9925f013 | 1058 | LINK_STATS_INC(link.err); |
donatien | 0:632c9925f013 | 1059 | snmp_inc_ifoutdiscards(&pc->netif); |
donatien | 0:632c9925f013 | 1060 | return PPPERR_DEVICE; |
donatien | 0:632c9925f013 | 1061 | } |
donatien | 0:632c9925f013 | 1062 | |
donatien | 0:632c9925f013 | 1063 | snmp_add_ifoutoctets(&pc->netif, (u16_t)n); |
donatien | 0:632c9925f013 | 1064 | snmp_inc_ifoutucastpkts(&pc->netif); |
donatien | 0:632c9925f013 | 1065 | LINK_STATS_INC(link.xmit); |
donatien | 0:632c9925f013 | 1066 | return PPPERR_NONE; |
donatien | 0:632c9925f013 | 1067 | } |
donatien | 0:632c9925f013 | 1068 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 1069 | |
donatien | 0:632c9925f013 | 1070 | /* |
donatien | 0:632c9925f013 | 1071 | * Write n characters to a ppp link. |
donatien | 0:632c9925f013 | 1072 | * RETURN: >= 0 Number of characters written |
donatien | 0:632c9925f013 | 1073 | * -1 Failed to write to device |
donatien | 0:632c9925f013 | 1074 | */ |
donatien | 0:632c9925f013 | 1075 | int |
donatien | 0:632c9925f013 | 1076 | pppWrite(int pd, const u_char *s, int n) |
donatien | 0:632c9925f013 | 1077 | { |
donatien | 0:632c9925f013 | 1078 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1079 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 1080 | u_char c; |
donatien | 0:632c9925f013 | 1081 | u_int fcsOut; |
donatien | 0:632c9925f013 | 1082 | struct pbuf *headMB, *tailMB; |
donatien | 0:632c9925f013 | 1083 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 1084 | |
donatien | 0:632c9925f013 | 1085 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 1086 | if(pc->ethif) { |
donatien | 0:632c9925f013 | 1087 | return pppWriteOverEthernet(pd, s, n); |
donatien | 0:632c9925f013 | 1088 | } |
donatien | 0:632c9925f013 | 1089 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 1090 | |
donatien | 0:632c9925f013 | 1091 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 1092 | headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); |
donatien | 0:632c9925f013 | 1093 | if (headMB == NULL) { |
donatien | 0:632c9925f013 | 1094 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 1095 | LINK_STATS_INC(link.proterr); |
donatien | 0:632c9925f013 | 1096 | snmp_inc_ifoutdiscards(&pc->netif); |
donatien | 0:632c9925f013 | 1097 | return PPPERR_ALLOC; |
donatien | 0:632c9925f013 | 1098 | } |
donatien | 0:632c9925f013 | 1099 | |
donatien | 0:632c9925f013 | 1100 | tailMB = headMB; |
donatien | 0:632c9925f013 | 1101 | |
donatien | 0:632c9925f013 | 1102 | /* If the link has been idle, we'll send a fresh flag character to |
donatien | 0:632c9925f013 | 1103 | * flush any noise. */ |
donatien | 0:632c9925f013 | 1104 | if ((sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG) { |
donatien | 0:632c9925f013 | 1105 | tailMB = pppAppend(PPP_FLAG, tailMB, NULL); |
donatien | 0:632c9925f013 | 1106 | } |
donatien | 0:632c9925f013 | 1107 | pc->lastXMit = sys_jiffies(); |
donatien | 0:632c9925f013 | 1108 | |
donatien | 0:632c9925f013 | 1109 | fcsOut = PPP_INITFCS; |
donatien | 0:632c9925f013 | 1110 | /* Load output buffer. */ |
donatien | 0:632c9925f013 | 1111 | while (n-- > 0) { |
donatien | 0:632c9925f013 | 1112 | c = *s++; |
donatien | 0:632c9925f013 | 1113 | |
donatien | 0:632c9925f013 | 1114 | /* Update FCS before checking for special characters. */ |
donatien | 0:632c9925f013 | 1115 | fcsOut = PPP_FCS(fcsOut, c); |
donatien | 0:632c9925f013 | 1116 | |
donatien | 0:632c9925f013 | 1117 | /* Copy to output buffer escaping special characters. */ |
donatien | 0:632c9925f013 | 1118 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 1119 | } |
donatien | 0:632c9925f013 | 1120 | |
donatien | 0:632c9925f013 | 1121 | /* Add FCS and trailing flag. */ |
donatien | 0:632c9925f013 | 1122 | c = ~fcsOut & 0xFF; |
donatien | 0:632c9925f013 | 1123 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 1124 | c = (~fcsOut >> 8) & 0xFF; |
donatien | 0:632c9925f013 | 1125 | tailMB = pppAppend(c, tailMB, &pc->outACCM); |
donatien | 0:632c9925f013 | 1126 | tailMB = pppAppend(PPP_FLAG, tailMB, NULL); |
donatien | 0:632c9925f013 | 1127 | |
donatien | 0:632c9925f013 | 1128 | /* If we failed to complete the packet, throw it away. |
donatien | 0:632c9925f013 | 1129 | * Otherwise send it. */ |
donatien | 0:632c9925f013 | 1130 | if (!tailMB) { |
donatien | 0:632c9925f013 | 1131 | PPPDEBUG(LOG_WARNING, |
donatien | 0:632c9925f013 | 1132 | ("pppWrite[%d]: Alloc err - dropping pbuf len=%d\n", pd, headMB->len)); |
donatien | 0:632c9925f013 | 1133 | /*"pppWrite[%d]: Alloc err - dropping %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */ |
donatien | 0:632c9925f013 | 1134 | pbuf_free(headMB); |
donatien | 0:632c9925f013 | 1135 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 1136 | LINK_STATS_INC(link.proterr); |
donatien | 0:632c9925f013 | 1137 | snmp_inc_ifoutdiscards(&pc->netif); |
donatien | 0:632c9925f013 | 1138 | return PPPERR_ALLOC; |
donatien | 0:632c9925f013 | 1139 | } |
donatien | 0:632c9925f013 | 1140 | |
donatien | 0:632c9925f013 | 1141 | PPPDEBUG(LOG_INFO, ("pppWrite[%d]: len=%d\n", pd, headMB->len)); |
donatien | 0:632c9925f013 | 1142 | /* "pppWrite[%d]: %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */ |
donatien | 0:632c9925f013 | 1143 | nPut(pc, headMB); |
donatien | 0:632c9925f013 | 1144 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 1145 | |
donatien | 0:632c9925f013 | 1146 | return PPPERR_NONE; |
donatien | 0:632c9925f013 | 1147 | } |
donatien | 0:632c9925f013 | 1148 | |
donatien | 0:632c9925f013 | 1149 | /* |
donatien | 0:632c9925f013 | 1150 | * ppp_send_config - configure the transmit characteristics of |
donatien | 0:632c9925f013 | 1151 | * the ppp interface. |
donatien | 0:632c9925f013 | 1152 | */ |
donatien | 0:632c9925f013 | 1153 | void |
donatien | 0:632c9925f013 | 1154 | ppp_send_config( int unit, u16_t mtu, u32_t asyncmap, int pcomp, int accomp) |
donatien | 0:632c9925f013 | 1155 | { |
donatien | 0:632c9925f013 | 1156 | PPPControl *pc = &pppControl[unit]; |
donatien | 0:632c9925f013 | 1157 | int i; |
donatien | 0:632c9925f013 | 1158 | |
donatien | 0:632c9925f013 | 1159 | pc->mtu = mtu; |
donatien | 0:632c9925f013 | 1160 | pc->pcomp = pcomp; |
donatien | 0:632c9925f013 | 1161 | pc->accomp = accomp; |
donatien | 0:632c9925f013 | 1162 | |
donatien | 0:632c9925f013 | 1163 | /* Load the ACCM bits for the 32 control codes. */ |
donatien | 0:632c9925f013 | 1164 | for (i = 0; i < 32/8; i++) { |
donatien | 0:632c9925f013 | 1165 | pc->outACCM[i] = (u_char)((asyncmap >> (8 * i)) & 0xFF); |
donatien | 0:632c9925f013 | 1166 | } |
donatien | 0:632c9925f013 | 1167 | PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]: outACCM=%X %X %X %X\n", |
donatien | 0:632c9925f013 | 1168 | unit, |
donatien | 0:632c9925f013 | 1169 | pc->outACCM[0], pc->outACCM[1], pc->outACCM[2], pc->outACCM[3])); |
donatien | 0:632c9925f013 | 1170 | } |
donatien | 0:632c9925f013 | 1171 | |
donatien | 0:632c9925f013 | 1172 | |
donatien | 0:632c9925f013 | 1173 | /* |
donatien | 0:632c9925f013 | 1174 | * ppp_set_xaccm - set the extended transmit ACCM for the interface. |
donatien | 0:632c9925f013 | 1175 | */ |
donatien | 0:632c9925f013 | 1176 | void |
donatien | 0:632c9925f013 | 1177 | ppp_set_xaccm(int unit, ext_accm *accm) |
donatien | 0:632c9925f013 | 1178 | { |
donatien | 0:632c9925f013 | 1179 | SMEMCPY(pppControl[unit].outACCM, accm, sizeof(ext_accm)); |
donatien | 0:632c9925f013 | 1180 | PPPDEBUG(LOG_INFO, ("ppp_set_xaccm[%d]: outACCM=%X %X %X %X\n", |
donatien | 0:632c9925f013 | 1181 | unit, |
donatien | 0:632c9925f013 | 1182 | pppControl[unit].outACCM[0], |
donatien | 0:632c9925f013 | 1183 | pppControl[unit].outACCM[1], |
donatien | 0:632c9925f013 | 1184 | pppControl[unit].outACCM[2], |
donatien | 0:632c9925f013 | 1185 | pppControl[unit].outACCM[3])); |
donatien | 0:632c9925f013 | 1186 | } |
donatien | 0:632c9925f013 | 1187 | |
donatien | 0:632c9925f013 | 1188 | |
donatien | 0:632c9925f013 | 1189 | /* |
donatien | 0:632c9925f013 | 1190 | * ppp_recv_config - configure the receive-side characteristics of |
donatien | 0:632c9925f013 | 1191 | * the ppp interface. |
donatien | 0:632c9925f013 | 1192 | */ |
donatien | 0:632c9925f013 | 1193 | void |
donatien | 0:632c9925f013 | 1194 | ppp_recv_config( int unit, int mru, u32_t asyncmap, int pcomp, int accomp) |
donatien | 0:632c9925f013 | 1195 | { |
donatien | 0:632c9925f013 | 1196 | PPPControl *pc = &pppControl[unit]; |
donatien | 0:632c9925f013 | 1197 | int i; |
donatien | 0:632c9925f013 | 1198 | SYS_ARCH_DECL_PROTECT(lev); |
donatien | 0:632c9925f013 | 1199 | |
donatien | 0:632c9925f013 | 1200 | LWIP_UNUSED_ARG(accomp); |
donatien | 0:632c9925f013 | 1201 | LWIP_UNUSED_ARG(pcomp); |
donatien | 0:632c9925f013 | 1202 | LWIP_UNUSED_ARG(mru); |
donatien | 0:632c9925f013 | 1203 | |
donatien | 0:632c9925f013 | 1204 | /* Load the ACCM bits for the 32 control codes. */ |
donatien | 0:632c9925f013 | 1205 | SYS_ARCH_PROTECT(lev); |
donatien | 0:632c9925f013 | 1206 | for (i = 0; i < 32 / 8; i++) { |
donatien | 0:632c9925f013 | 1207 | /* @todo: does this work? ext_accm has been modified from pppd! */ |
donatien | 0:632c9925f013 | 1208 | pc->rx.inACCM[i] = (u_char)(asyncmap >> (i * 8)); |
donatien | 0:632c9925f013 | 1209 | } |
donatien | 0:632c9925f013 | 1210 | SYS_ARCH_UNPROTECT(lev); |
donatien | 0:632c9925f013 | 1211 | PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]: inACCM=%X %X %X %X\n", |
donatien | 0:632c9925f013 | 1212 | unit, |
donatien | 0:632c9925f013 | 1213 | pc->rx.inACCM[0], pc->rx.inACCM[1], pc->rx.inACCM[2], pc->rx.inACCM[3])); |
donatien | 0:632c9925f013 | 1214 | } |
donatien | 0:632c9925f013 | 1215 | |
donatien | 0:632c9925f013 | 1216 | #if 0 |
donatien | 0:632c9925f013 | 1217 | /* |
donatien | 0:632c9925f013 | 1218 | * ccp_test - ask kernel whether a given compression method |
donatien | 0:632c9925f013 | 1219 | * is acceptable for use. Returns 1 if the method and parameters |
donatien | 0:632c9925f013 | 1220 | * are OK, 0 if the method is known but the parameters are not OK |
donatien | 0:632c9925f013 | 1221 | * (e.g. code size should be reduced), or -1 if the method is unknown. |
donatien | 0:632c9925f013 | 1222 | */ |
donatien | 0:632c9925f013 | 1223 | int |
donatien | 0:632c9925f013 | 1224 | ccp_test( int unit, int opt_len, int for_transmit, u_char *opt_ptr) |
donatien | 0:632c9925f013 | 1225 | { |
donatien | 0:632c9925f013 | 1226 | return 0; /* XXX Currently no compression. */ |
donatien | 0:632c9925f013 | 1227 | } |
donatien | 0:632c9925f013 | 1228 | |
donatien | 0:632c9925f013 | 1229 | /* |
donatien | 0:632c9925f013 | 1230 | * ccp_flags_set - inform kernel about the current state of CCP. |
donatien | 0:632c9925f013 | 1231 | */ |
donatien | 0:632c9925f013 | 1232 | void |
donatien | 0:632c9925f013 | 1233 | ccp_flags_set(int unit, int isopen, int isup) |
donatien | 0:632c9925f013 | 1234 | { |
donatien | 0:632c9925f013 | 1235 | /* XXX */ |
donatien | 0:632c9925f013 | 1236 | } |
donatien | 0:632c9925f013 | 1237 | |
donatien | 0:632c9925f013 | 1238 | /* |
donatien | 0:632c9925f013 | 1239 | * ccp_fatal_error - returns 1 if decompression was disabled as a |
donatien | 0:632c9925f013 | 1240 | * result of an error detected after decompression of a packet, |
donatien | 0:632c9925f013 | 1241 | * 0 otherwise. This is necessary because of patent nonsense. |
donatien | 0:632c9925f013 | 1242 | */ |
donatien | 0:632c9925f013 | 1243 | int |
donatien | 0:632c9925f013 | 1244 | ccp_fatal_error(int unit) |
donatien | 0:632c9925f013 | 1245 | { |
donatien | 0:632c9925f013 | 1246 | /* XXX */ |
donatien | 0:632c9925f013 | 1247 | return 0; |
donatien | 0:632c9925f013 | 1248 | } |
donatien | 0:632c9925f013 | 1249 | #endif |
donatien | 0:632c9925f013 | 1250 | |
donatien | 0:632c9925f013 | 1251 | /* |
donatien | 0:632c9925f013 | 1252 | * get_idle_time - return how long the link has been idle. |
donatien | 0:632c9925f013 | 1253 | */ |
donatien | 0:632c9925f013 | 1254 | int |
donatien | 0:632c9925f013 | 1255 | get_idle_time(int u, struct ppp_idle *ip) |
donatien | 0:632c9925f013 | 1256 | { |
donatien | 0:632c9925f013 | 1257 | /* XXX */ |
donatien | 0:632c9925f013 | 1258 | LWIP_UNUSED_ARG(u); |
donatien | 0:632c9925f013 | 1259 | LWIP_UNUSED_ARG(ip); |
donatien | 0:632c9925f013 | 1260 | |
donatien | 0:632c9925f013 | 1261 | return 0; |
donatien | 0:632c9925f013 | 1262 | } |
donatien | 0:632c9925f013 | 1263 | |
donatien | 0:632c9925f013 | 1264 | |
donatien | 0:632c9925f013 | 1265 | /* |
donatien | 0:632c9925f013 | 1266 | * Return user specified netmask, modified by any mask we might determine |
donatien | 0:632c9925f013 | 1267 | * for address `addr' (in network byte order). |
donatien | 0:632c9925f013 | 1268 | * Here we scan through the system's list of interfaces, looking for |
donatien | 0:632c9925f013 | 1269 | * any non-point-to-point interfaces which might appear to be on the same |
donatien | 0:632c9925f013 | 1270 | * network as `addr'. If we find any, we OR in their netmask to the |
donatien | 0:632c9925f013 | 1271 | * user-specified netmask. |
donatien | 0:632c9925f013 | 1272 | */ |
donatien | 0:632c9925f013 | 1273 | u32_t |
donatien | 0:632c9925f013 | 1274 | GetMask(u32_t addr) |
donatien | 0:632c9925f013 | 1275 | { |
donatien | 0:632c9925f013 | 1276 | u32_t mask, nmask; |
donatien | 0:632c9925f013 | 1277 | |
donatien | 0:632c9925f013 | 1278 | htonl(addr); |
donatien | 0:632c9925f013 | 1279 | if (IP_CLASSA(addr)) { /* determine network mask for address class */ |
donatien | 0:632c9925f013 | 1280 | nmask = IP_CLASSA_NET; |
donatien | 0:632c9925f013 | 1281 | } else if (IP_CLASSB(addr)) { |
donatien | 0:632c9925f013 | 1282 | nmask = IP_CLASSB_NET; |
donatien | 0:632c9925f013 | 1283 | } else { |
donatien | 0:632c9925f013 | 1284 | nmask = IP_CLASSC_NET; |
donatien | 0:632c9925f013 | 1285 | } |
donatien | 0:632c9925f013 | 1286 | |
donatien | 0:632c9925f013 | 1287 | /* class D nets are disallowed by bad_ip_adrs */ |
donatien | 0:632c9925f013 | 1288 | mask = subnetMask | htonl(nmask); |
donatien | 0:632c9925f013 | 1289 | |
donatien | 0:632c9925f013 | 1290 | /* XXX |
donatien | 0:632c9925f013 | 1291 | * Scan through the system's network interfaces. |
donatien | 0:632c9925f013 | 1292 | * Get each netmask and OR them into our mask. |
donatien | 0:632c9925f013 | 1293 | */ |
donatien | 0:632c9925f013 | 1294 | |
donatien | 0:632c9925f013 | 1295 | return mask; |
donatien | 0:632c9925f013 | 1296 | } |
donatien | 0:632c9925f013 | 1297 | |
donatien | 0:632c9925f013 | 1298 | /* |
donatien | 0:632c9925f013 | 1299 | * sifvjcomp - config tcp header compression |
donatien | 0:632c9925f013 | 1300 | */ |
donatien | 0:632c9925f013 | 1301 | int |
donatien | 0:632c9925f013 | 1302 | sifvjcomp(int pd, int vjcomp, u8_t cidcomp, u8_t maxcid) |
donatien | 0:632c9925f013 | 1303 | { |
donatien | 0:632c9925f013 | 1304 | #if PPPOS_SUPPORT && VJ_SUPPORT |
donatien | 0:632c9925f013 | 1305 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1306 | |
donatien | 0:632c9925f013 | 1307 | pc->vjEnabled = vjcomp; |
donatien | 0:632c9925f013 | 1308 | pc->vjComp.compressSlot = cidcomp; |
donatien | 0:632c9925f013 | 1309 | pc->vjComp.maxSlotIndex = maxcid; |
donatien | 0:632c9925f013 | 1310 | PPPDEBUG(LOG_INFO, ("sifvjcomp: VJ compress enable=%d slot=%d max slot=%d\n", |
donatien | 0:632c9925f013 | 1311 | vjcomp, cidcomp, maxcid)); |
donatien | 0:632c9925f013 | 1312 | #else /* PPPOS_SUPPORT && VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 1313 | LWIP_UNUSED_ARG(pd); |
donatien | 0:632c9925f013 | 1314 | LWIP_UNUSED_ARG(vjcomp); |
donatien | 0:632c9925f013 | 1315 | LWIP_UNUSED_ARG(cidcomp); |
donatien | 0:632c9925f013 | 1316 | LWIP_UNUSED_ARG(maxcid); |
donatien | 0:632c9925f013 | 1317 | #endif /* PPPOS_SUPPORT && VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 1318 | |
donatien | 0:632c9925f013 | 1319 | return 0; |
donatien | 0:632c9925f013 | 1320 | } |
donatien | 0:632c9925f013 | 1321 | |
donatien | 0:632c9925f013 | 1322 | /* |
donatien | 0:632c9925f013 | 1323 | * pppnetifNetifInit - netif init callback |
donatien | 0:632c9925f013 | 1324 | */ |
donatien | 0:632c9925f013 | 1325 | static err_t |
donatien | 0:632c9925f013 | 1326 | pppnetifNetifInit(struct netif *netif) |
donatien | 0:632c9925f013 | 1327 | { |
donatien | 0:632c9925f013 | 1328 | netif->name[0] = 'p'; |
donatien | 0:632c9925f013 | 1329 | netif->name[1] = 'p'; |
donatien | 0:632c9925f013 | 1330 | netif->output = pppnetifOutput; |
donatien | 0:632c9925f013 | 1331 | netif->mtu = pppMTU((int)(size_t)netif->state); |
donatien | 0:632c9925f013 | 1332 | netif->flags = NETIF_FLAG_POINTTOPOINT | NETIF_FLAG_LINK_UP; |
donatien | 0:632c9925f013 | 1333 | #if LWIP_NETIF_HOSTNAME |
donatien | 0:632c9925f013 | 1334 | /* @todo: Initialize interface hostname */ |
donatien | 0:632c9925f013 | 1335 | /* netif_set_hostname(netif, "lwip"); */ |
donatien | 0:632c9925f013 | 1336 | #endif /* LWIP_NETIF_HOSTNAME */ |
donatien | 0:632c9925f013 | 1337 | return ERR_OK; |
donatien | 0:632c9925f013 | 1338 | } |
donatien | 0:632c9925f013 | 1339 | |
donatien | 0:632c9925f013 | 1340 | |
donatien | 0:632c9925f013 | 1341 | /* |
donatien | 0:632c9925f013 | 1342 | * sifup - Config the interface up and enable IP packets to pass. |
donatien | 0:632c9925f013 | 1343 | */ |
donatien | 0:632c9925f013 | 1344 | int |
donatien | 0:632c9925f013 | 1345 | sifup(int pd) |
donatien | 0:632c9925f013 | 1346 | { |
donatien | 0:632c9925f013 | 1347 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1348 | int st = 1; |
donatien | 0:632c9925f013 | 1349 | |
donatien | 0:632c9925f013 | 1350 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { |
donatien | 0:632c9925f013 | 1351 | st = 0; |
donatien | 0:632c9925f013 | 1352 | PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd)); |
donatien | 0:632c9925f013 | 1353 | } else { |
donatien | 0:632c9925f013 | 1354 | netif_remove(&pc->netif); |
donatien | 0:632c9925f013 | 1355 | if (netif_add(&pc->netif, &pc->addrs.our_ipaddr, &pc->addrs.netmask, |
donatien | 0:632c9925f013 | 1356 | &pc->addrs.his_ipaddr, (void *)(size_t)pd, pppnetifNetifInit, ip_input)) { |
donatien | 0:632c9925f013 | 1357 | netif_set_up(&pc->netif); |
donatien | 0:632c9925f013 | 1358 | pc->if_up = 1; |
donatien | 0:632c9925f013 | 1359 | pc->errCode = PPPERR_NONE; |
donatien | 0:632c9925f013 | 1360 | |
donatien | 0:632c9925f013 | 1361 | PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); |
donatien | 0:632c9925f013 | 1362 | if (pc->linkStatusCB) { |
donatien | 0:632c9925f013 | 1363 | pc->linkStatusCB(pc->linkStatusCtx, pc->errCode, &pc->addrs); |
donatien | 0:632c9925f013 | 1364 | } |
donatien | 0:632c9925f013 | 1365 | } else { |
donatien | 0:632c9925f013 | 1366 | st = 0; |
donatien | 0:632c9925f013 | 1367 | PPPDEBUG(LOG_ERR, ("sifup[%d]: netif_add failed\n", pd)); |
donatien | 0:632c9925f013 | 1368 | } |
donatien | 0:632c9925f013 | 1369 | } |
donatien | 0:632c9925f013 | 1370 | |
donatien | 0:632c9925f013 | 1371 | return st; |
donatien | 0:632c9925f013 | 1372 | } |
donatien | 0:632c9925f013 | 1373 | |
donatien | 0:632c9925f013 | 1374 | /* |
donatien | 0:632c9925f013 | 1375 | * sifnpmode - Set the mode for handling packets for a given NP. |
donatien | 0:632c9925f013 | 1376 | */ |
donatien | 0:632c9925f013 | 1377 | int |
donatien | 0:632c9925f013 | 1378 | sifnpmode(int u, int proto, enum NPmode mode) |
donatien | 0:632c9925f013 | 1379 | { |
donatien | 0:632c9925f013 | 1380 | LWIP_UNUSED_ARG(u); |
donatien | 0:632c9925f013 | 1381 | LWIP_UNUSED_ARG(proto); |
donatien | 0:632c9925f013 | 1382 | LWIP_UNUSED_ARG(mode); |
donatien | 0:632c9925f013 | 1383 | return 0; |
donatien | 0:632c9925f013 | 1384 | } |
donatien | 0:632c9925f013 | 1385 | |
donatien | 0:632c9925f013 | 1386 | /* |
donatien | 0:632c9925f013 | 1387 | * sifdown - Config the interface down and disable IP. |
donatien | 0:632c9925f013 | 1388 | */ |
donatien | 0:632c9925f013 | 1389 | int |
donatien | 0:632c9925f013 | 1390 | sifdown(int pd) |
donatien | 0:632c9925f013 | 1391 | { |
donatien | 0:632c9925f013 | 1392 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1393 | int st = 1; |
donatien | 0:632c9925f013 | 1394 | |
donatien | 0:632c9925f013 | 1395 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { |
donatien | 0:632c9925f013 | 1396 | st = 0; |
donatien | 0:632c9925f013 | 1397 | PPPDEBUG(LOG_WARNING, ("sifdown[%d]: bad parms\n", pd)); |
donatien | 0:632c9925f013 | 1398 | } else { |
donatien | 0:632c9925f013 | 1399 | pc->if_up = 0; |
donatien | 0:632c9925f013 | 1400 | /* make sure the netif status callback is called */ |
donatien | 0:632c9925f013 | 1401 | netif_set_down(&pc->netif); |
donatien | 0:632c9925f013 | 1402 | netif_remove(&pc->netif); |
donatien | 0:632c9925f013 | 1403 | PPPDEBUG(LOG_DEBUG, ("sifdown: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); |
donatien | 0:632c9925f013 | 1404 | if (pc->linkStatusCB) { |
donatien | 0:632c9925f013 | 1405 | pc->linkStatusCB(pc->linkStatusCtx, PPPERR_CONNECT, NULL); |
donatien | 0:632c9925f013 | 1406 | } |
donatien | 0:632c9925f013 | 1407 | } |
donatien | 0:632c9925f013 | 1408 | return st; |
donatien | 0:632c9925f013 | 1409 | } |
donatien | 0:632c9925f013 | 1410 | |
donatien | 0:632c9925f013 | 1411 | /** |
donatien | 0:632c9925f013 | 1412 | * sifaddr - Config the interface IP addresses and netmask. |
donatien | 0:632c9925f013 | 1413 | * @param pd Interface unit ??? |
donatien | 0:632c9925f013 | 1414 | * @param o Our IP address ??? |
donatien | 0:632c9925f013 | 1415 | * @param h His IP address ??? |
donatien | 0:632c9925f013 | 1416 | * @param m IP subnet mask ??? |
donatien | 0:632c9925f013 | 1417 | * @param ns1 Primary DNS |
donatien | 0:632c9925f013 | 1418 | * @param ns2 Secondary DNS |
donatien | 0:632c9925f013 | 1419 | */ |
donatien | 0:632c9925f013 | 1420 | int |
donatien | 0:632c9925f013 | 1421 | sifaddr( int pd, u32_t o, u32_t h, u32_t m, u32_t ns1, u32_t ns2) |
donatien | 0:632c9925f013 | 1422 | { |
donatien | 0:632c9925f013 | 1423 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1424 | int st = 1; |
donatien | 0:632c9925f013 | 1425 | |
donatien | 0:632c9925f013 | 1426 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { |
donatien | 0:632c9925f013 | 1427 | st = 0; |
donatien | 0:632c9925f013 | 1428 | PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd)); |
donatien | 0:632c9925f013 | 1429 | } else { |
donatien | 0:632c9925f013 | 1430 | SMEMCPY(&pc->addrs.our_ipaddr, &o, sizeof(o)); |
donatien | 0:632c9925f013 | 1431 | SMEMCPY(&pc->addrs.his_ipaddr, &h, sizeof(h)); |
donatien | 0:632c9925f013 | 1432 | SMEMCPY(&pc->addrs.netmask, &m, sizeof(m)); |
donatien | 0:632c9925f013 | 1433 | SMEMCPY(&pc->addrs.dns1, &ns1, sizeof(ns1)); |
donatien | 0:632c9925f013 | 1434 | SMEMCPY(&pc->addrs.dns2, &ns2, sizeof(ns2)); |
donatien | 0:632c9925f013 | 1435 | } |
donatien | 0:632c9925f013 | 1436 | return st; |
donatien | 0:632c9925f013 | 1437 | } |
donatien | 0:632c9925f013 | 1438 | |
donatien | 0:632c9925f013 | 1439 | /** |
donatien | 0:632c9925f013 | 1440 | * cifaddr - Clear the interface IP addresses, and delete routes |
donatien | 0:632c9925f013 | 1441 | * through the interface if possible. |
donatien | 0:632c9925f013 | 1442 | * @param pd Interface unit ??? |
donatien | 0:632c9925f013 | 1443 | * @param o Our IP address ??? |
donatien | 0:632c9925f013 | 1444 | * @param h IP broadcast address ??? |
donatien | 0:632c9925f013 | 1445 | */ |
donatien | 0:632c9925f013 | 1446 | int |
donatien | 0:632c9925f013 | 1447 | cifaddr( int pd, u32_t o, u32_t h) |
donatien | 0:632c9925f013 | 1448 | { |
donatien | 0:632c9925f013 | 1449 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1450 | int st = 1; |
donatien | 0:632c9925f013 | 1451 | |
donatien | 0:632c9925f013 | 1452 | LWIP_UNUSED_ARG(o); |
donatien | 0:632c9925f013 | 1453 | LWIP_UNUSED_ARG(h); |
donatien | 0:632c9925f013 | 1454 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { |
donatien | 0:632c9925f013 | 1455 | st = 0; |
donatien | 0:632c9925f013 | 1456 | PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd)); |
donatien | 0:632c9925f013 | 1457 | } else { |
donatien | 0:632c9925f013 | 1458 | IP4_ADDR(&pc->addrs.our_ipaddr, 0,0,0,0); |
donatien | 0:632c9925f013 | 1459 | IP4_ADDR(&pc->addrs.his_ipaddr, 0,0,0,0); |
donatien | 0:632c9925f013 | 1460 | IP4_ADDR(&pc->addrs.netmask, 255,255,255,0); |
donatien | 0:632c9925f013 | 1461 | IP4_ADDR(&pc->addrs.dns1, 0,0,0,0); |
donatien | 0:632c9925f013 | 1462 | IP4_ADDR(&pc->addrs.dns2, 0,0,0,0); |
donatien | 0:632c9925f013 | 1463 | } |
donatien | 0:632c9925f013 | 1464 | return st; |
donatien | 0:632c9925f013 | 1465 | } |
donatien | 0:632c9925f013 | 1466 | |
donatien | 0:632c9925f013 | 1467 | /* |
donatien | 0:632c9925f013 | 1468 | * sifdefaultroute - assign a default route through the address given. |
donatien | 0:632c9925f013 | 1469 | */ |
donatien | 0:632c9925f013 | 1470 | int |
donatien | 0:632c9925f013 | 1471 | sifdefaultroute(int pd, u32_t l, u32_t g) |
donatien | 0:632c9925f013 | 1472 | { |
donatien | 0:632c9925f013 | 1473 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1474 | int st = 1; |
donatien | 0:632c9925f013 | 1475 | |
donatien | 0:632c9925f013 | 1476 | LWIP_UNUSED_ARG(l); |
donatien | 0:632c9925f013 | 1477 | LWIP_UNUSED_ARG(g); |
donatien | 0:632c9925f013 | 1478 | |
donatien | 0:632c9925f013 | 1479 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { |
donatien | 0:632c9925f013 | 1480 | st = 0; |
donatien | 0:632c9925f013 | 1481 | PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd)); |
donatien | 0:632c9925f013 | 1482 | } else { |
donatien | 0:632c9925f013 | 1483 | netif_set_default(&pc->netif); |
donatien | 0:632c9925f013 | 1484 | } |
donatien | 0:632c9925f013 | 1485 | |
donatien | 0:632c9925f013 | 1486 | /* TODO: check how PPP handled the netMask, previously not set by ipSetDefault */ |
donatien | 0:632c9925f013 | 1487 | |
donatien | 0:632c9925f013 | 1488 | return st; |
donatien | 0:632c9925f013 | 1489 | } |
donatien | 0:632c9925f013 | 1490 | |
donatien | 0:632c9925f013 | 1491 | /* |
donatien | 0:632c9925f013 | 1492 | * cifdefaultroute - delete a default route through the address given. |
donatien | 0:632c9925f013 | 1493 | */ |
donatien | 0:632c9925f013 | 1494 | int |
donatien | 0:632c9925f013 | 1495 | cifdefaultroute(int pd, u32_t l, u32_t g) |
donatien | 0:632c9925f013 | 1496 | { |
donatien | 0:632c9925f013 | 1497 | PPPControl *pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1498 | int st = 1; |
donatien | 0:632c9925f013 | 1499 | |
donatien | 0:632c9925f013 | 1500 | LWIP_UNUSED_ARG(l); |
donatien | 0:632c9925f013 | 1501 | LWIP_UNUSED_ARG(g); |
donatien | 0:632c9925f013 | 1502 | |
donatien | 0:632c9925f013 | 1503 | if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { |
donatien | 0:632c9925f013 | 1504 | st = 0; |
donatien | 0:632c9925f013 | 1505 | PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd)); |
donatien | 0:632c9925f013 | 1506 | } else { |
donatien | 0:632c9925f013 | 1507 | netif_set_default(NULL); |
donatien | 0:632c9925f013 | 1508 | } |
donatien | 0:632c9925f013 | 1509 | |
donatien | 0:632c9925f013 | 1510 | return st; |
donatien | 0:632c9925f013 | 1511 | } |
donatien | 0:632c9925f013 | 1512 | |
donatien | 0:632c9925f013 | 1513 | /**********************************/ |
donatien | 0:632c9925f013 | 1514 | /*** LOCAL FUNCTION DEFINITIONS ***/ |
donatien | 0:632c9925f013 | 1515 | /**********************************/ |
donatien | 0:632c9925f013 | 1516 | |
donatien | 0:632c9925f013 | 1517 | #if PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD |
donatien | 0:632c9925f013 | 1518 | /* The main PPP process function. This implements the state machine according |
donatien | 0:632c9925f013 | 1519 | * to section 4 of RFC 1661: The Point-To-Point Protocol. */ |
donatien | 0:632c9925f013 | 1520 | static void |
donatien | 0:632c9925f013 | 1521 | pppInputThread(void *arg) |
donatien | 0:632c9925f013 | 1522 | { |
donatien | 0:632c9925f013 | 1523 | int count; |
donatien | 0:632c9925f013 | 1524 | PPPControlRx *pcrx = arg; |
donatien | 0:632c9925f013 | 1525 | |
donatien | 0:632c9925f013 | 1526 | while (lcp_phase[pcrx->pd] != PHASE_DEAD) { |
donatien | 0:632c9925f013 | 1527 | count = sio_read(pcrx->fd, pcrx->rxbuf, PPPOS_RX_BUFSIZE); |
donatien | 0:632c9925f013 | 1528 | if(count > 0) { |
donatien | 0:632c9925f013 | 1529 | pppInProc(pcrx, pcrx->rxbuf, count); |
donatien | 0:632c9925f013 | 1530 | } else { |
donatien | 0:632c9925f013 | 1531 | /* nothing received, give other tasks a chance to run */ |
donatien | 0:632c9925f013 | 1532 | sys_msleep(1); |
donatien | 0:632c9925f013 | 1533 | } |
donatien | 0:632c9925f013 | 1534 | } |
donatien | 0:632c9925f013 | 1535 | } |
donatien | 0:632c9925f013 | 1536 | #endif /* PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD */ |
donatien | 0:632c9925f013 | 1537 | |
donatien | 0:632c9925f013 | 1538 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 1539 | |
donatien | 0:632c9925f013 | 1540 | void |
donatien | 0:632c9925f013 | 1541 | pppOverEthernetInitFailed(int pd) |
donatien | 0:632c9925f013 | 1542 | { |
donatien | 0:632c9925f013 | 1543 | PPPControl* pc; |
donatien | 0:632c9925f013 | 1544 | |
donatien | 0:632c9925f013 | 1545 | pppHup(pd); |
donatien | 0:632c9925f013 | 1546 | pppStop(pd); |
donatien | 0:632c9925f013 | 1547 | |
donatien | 0:632c9925f013 | 1548 | pc = &pppControl[pd]; |
donatien | 0:632c9925f013 | 1549 | pppoe_destroy(&pc->netif); |
donatien | 0:632c9925f013 | 1550 | pc->openFlag = 0; |
donatien | 0:632c9925f013 | 1551 | |
donatien | 0:632c9925f013 | 1552 | if(pc->linkStatusCB) { |
donatien | 0:632c9925f013 | 1553 | pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL, NULL); |
donatien | 0:632c9925f013 | 1554 | } |
donatien | 0:632c9925f013 | 1555 | } |
donatien | 0:632c9925f013 | 1556 | |
donatien | 0:632c9925f013 | 1557 | static void |
donatien | 0:632c9925f013 | 1558 | pppOverEthernetLinkStatusCB(int pd, int up) |
donatien | 0:632c9925f013 | 1559 | { |
donatien | 0:632c9925f013 | 1560 | if(up) { |
donatien | 0:632c9925f013 | 1561 | PPPDEBUG(LOG_INFO, ("pppOverEthernetLinkStatusCB: unit %d: Connecting\n", pd)); |
donatien | 0:632c9925f013 | 1562 | pppStart(pd); |
donatien | 0:632c9925f013 | 1563 | } else { |
donatien | 0:632c9925f013 | 1564 | pppOverEthernetInitFailed(pd); |
donatien | 0:632c9925f013 | 1565 | } |
donatien | 0:632c9925f013 | 1566 | } |
donatien | 0:632c9925f013 | 1567 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 1568 | |
donatien | 0:632c9925f013 | 1569 | struct pbuf * |
donatien | 0:632c9925f013 | 1570 | pppSingleBuf(struct pbuf *p) |
donatien | 0:632c9925f013 | 1571 | { |
donatien | 0:632c9925f013 | 1572 | struct pbuf *q, *b; |
donatien | 0:632c9925f013 | 1573 | u_char *pl; |
donatien | 0:632c9925f013 | 1574 | |
donatien | 0:632c9925f013 | 1575 | if(p->tot_len == p->len) { |
donatien | 0:632c9925f013 | 1576 | return p; |
donatien | 0:632c9925f013 | 1577 | } |
donatien | 0:632c9925f013 | 1578 | |
donatien | 0:632c9925f013 | 1579 | q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); |
donatien | 0:632c9925f013 | 1580 | if(!q) { |
donatien | 0:632c9925f013 | 1581 | PPPDEBUG(LOG_ERR, |
donatien | 0:632c9925f013 | 1582 | ("pppSingleBuf: unable to alloc new buf (%d)\n", p->tot_len)); |
donatien | 0:632c9925f013 | 1583 | return p; /* live dangerously */ |
donatien | 0:632c9925f013 | 1584 | } |
donatien | 0:632c9925f013 | 1585 | |
donatien | 0:632c9925f013 | 1586 | for(b = p, pl = (u_char*) q->payload; b != NULL; b = b->next) { |
donatien | 0:632c9925f013 | 1587 | MEMCPY(pl, b->payload, b->len); |
donatien | 0:632c9925f013 | 1588 | pl += b->len; |
donatien | 0:632c9925f013 | 1589 | } |
donatien | 0:632c9925f013 | 1590 | |
donatien | 0:632c9925f013 | 1591 | pbuf_free(p); |
donatien | 0:632c9925f013 | 1592 | |
donatien | 0:632c9925f013 | 1593 | return q; |
donatien | 0:632c9925f013 | 1594 | } |
donatien | 0:632c9925f013 | 1595 | |
donatien | 0:632c9925f013 | 1596 | struct pppInputHeader { |
donatien | 0:632c9925f013 | 1597 | int unit; |
donatien | 0:632c9925f013 | 1598 | u16_t proto; |
donatien | 0:632c9925f013 | 1599 | }; |
donatien | 0:632c9925f013 | 1600 | |
donatien | 0:632c9925f013 | 1601 | /* |
donatien | 0:632c9925f013 | 1602 | * Pass the processed input packet to the appropriate handler. |
donatien | 0:632c9925f013 | 1603 | * This function and all handlers run in the context of the tcpip_thread |
donatien | 0:632c9925f013 | 1604 | */ |
donatien | 0:632c9925f013 | 1605 | static void |
donatien | 0:632c9925f013 | 1606 | pppInput(void *arg) |
donatien | 0:632c9925f013 | 1607 | { |
donatien | 0:632c9925f013 | 1608 | struct pbuf *nb = (struct pbuf *)arg; |
donatien | 0:632c9925f013 | 1609 | u16_t protocol; |
donatien | 0:632c9925f013 | 1610 | int pd; |
donatien | 0:632c9925f013 | 1611 | |
donatien | 0:632c9925f013 | 1612 | pd = ((struct pppInputHeader *)nb->payload)->unit; |
donatien | 0:632c9925f013 | 1613 | protocol = ((struct pppInputHeader *)nb->payload)->proto; |
donatien | 0:632c9925f013 | 1614 | |
donatien | 0:632c9925f013 | 1615 | if(pbuf_header(nb, -(int)sizeof(struct pppInputHeader))) { |
donatien | 0:632c9925f013 | 1616 | LWIP_ASSERT("pbuf_header failed\n", 0); |
donatien | 0:632c9925f013 | 1617 | goto drop; |
donatien | 0:632c9925f013 | 1618 | } |
donatien | 0:632c9925f013 | 1619 | |
donatien | 0:632c9925f013 | 1620 | LINK_STATS_INC(link.recv); |
donatien | 0:632c9925f013 | 1621 | snmp_inc_ifinucastpkts(&pppControl[pd].netif); |
donatien | 0:632c9925f013 | 1622 | snmp_add_ifinoctets(&pppControl[pd].netif, nb->tot_len); |
donatien | 0:632c9925f013 | 1623 | |
donatien | 0:632c9925f013 | 1624 | /* |
donatien | 0:632c9925f013 | 1625 | * Toss all non-LCP packets unless LCP is OPEN. |
donatien | 0:632c9925f013 | 1626 | * Until we get past the authentication phase, toss all packets |
donatien | 0:632c9925f013 | 1627 | * except LCP, LQR and authentication packets. |
donatien | 0:632c9925f013 | 1628 | */ |
donatien | 0:632c9925f013 | 1629 | if((lcp_phase[pd] <= PHASE_AUTHENTICATE) && (protocol != PPP_LCP)) { |
donatien | 0:632c9925f013 | 1630 | if(!((protocol == PPP_LQR) || (protocol == PPP_PAP) || (protocol == PPP_CHAP)) || |
donatien | 0:632c9925f013 | 1631 | (lcp_phase[pd] != PHASE_AUTHENTICATE)) { |
donatien | 0:632c9925f013 | 1632 | PPPDEBUG(LOG_INFO, ("pppInput: discarding proto 0x%"X16_F" in phase %d\n", protocol, lcp_phase[pd])); |
donatien | 0:632c9925f013 | 1633 | goto drop; |
donatien | 0:632c9925f013 | 1634 | } |
donatien | 0:632c9925f013 | 1635 | } |
donatien | 0:632c9925f013 | 1636 | |
donatien | 0:632c9925f013 | 1637 | switch(protocol) { |
donatien | 0:632c9925f013 | 1638 | case PPP_VJC_COMP: /* VJ compressed TCP */ |
donatien | 0:632c9925f013 | 1639 | #if PPPOS_SUPPORT && VJ_SUPPORT |
donatien | 0:632c9925f013 | 1640 | PPPDEBUG(LOG_INFO, ("pppInput[%d]: vj_comp in pbuf len=%d\n", pd, nb->len)); |
donatien | 0:632c9925f013 | 1641 | /* |
donatien | 0:632c9925f013 | 1642 | * Clip off the VJ header and prepend the rebuilt TCP/IP header and |
donatien | 0:632c9925f013 | 1643 | * pass the result to IP. |
donatien | 0:632c9925f013 | 1644 | */ |
donatien | 0:632c9925f013 | 1645 | if ((vj_uncompress_tcp(&nb, &pppControl[pd].vjComp) >= 0) && (pppControl[pd].netif.input)) { |
donatien | 0:632c9925f013 | 1646 | pppControl[pd].netif.input(nb, &pppControl[pd].netif); |
donatien | 0:632c9925f013 | 1647 | return; |
donatien | 0:632c9925f013 | 1648 | } |
donatien | 0:632c9925f013 | 1649 | /* Something's wrong so drop it. */ |
donatien | 0:632c9925f013 | 1650 | PPPDEBUG(LOG_WARNING, ("pppInput[%d]: Dropping VJ compressed\n", pd)); |
donatien | 0:632c9925f013 | 1651 | #else /* PPPOS_SUPPORT && VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 1652 | /* No handler for this protocol so drop the packet. */ |
donatien | 0:632c9925f013 | 1653 | PPPDEBUG(LOG_INFO, ("pppInput[%d]: drop VJ Comp in %d:%s\n", pd, nb->len, nb->payload)); |
donatien | 0:632c9925f013 | 1654 | #endif /* PPPOS_SUPPORT && VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 1655 | break; |
donatien | 0:632c9925f013 | 1656 | |
donatien | 0:632c9925f013 | 1657 | case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */ |
donatien | 0:632c9925f013 | 1658 | #if PPPOS_SUPPORT && VJ_SUPPORT |
donatien | 0:632c9925f013 | 1659 | PPPDEBUG(LOG_INFO, ("pppInput[%d]: vj_un in pbuf len=%d\n", pd, nb->len)); |
donatien | 0:632c9925f013 | 1660 | /* |
donatien | 0:632c9925f013 | 1661 | * Process the TCP/IP header for VJ header compression and then pass |
donatien | 0:632c9925f013 | 1662 | * the packet to IP. |
donatien | 0:632c9925f013 | 1663 | */ |
donatien | 0:632c9925f013 | 1664 | if ((vj_uncompress_uncomp(nb, &pppControl[pd].vjComp) >= 0) && pppControl[pd].netif.input) { |
donatien | 0:632c9925f013 | 1665 | pppControl[pd].netif.input(nb, &pppControl[pd].netif); |
donatien | 0:632c9925f013 | 1666 | return; |
donatien | 0:632c9925f013 | 1667 | } |
donatien | 0:632c9925f013 | 1668 | /* Something's wrong so drop it. */ |
donatien | 0:632c9925f013 | 1669 | PPPDEBUG(LOG_WARNING, ("pppInput[%d]: Dropping VJ uncompressed\n", pd)); |
donatien | 0:632c9925f013 | 1670 | #else /* PPPOS_SUPPORT && VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 1671 | /* No handler for this protocol so drop the packet. */ |
donatien | 0:632c9925f013 | 1672 | PPPDEBUG((LOG_INFO, |
donatien | 0:632c9925f013 | 1673 | "pppInput[%d]: drop VJ UnComp in %d:.*H\n", |
donatien | 0:632c9925f013 | 1674 | pd, nb->len, LWIP_MIN(nb->len * 2, 40), nb->payload)); |
donatien | 0:632c9925f013 | 1675 | #endif /* PPPOS_SUPPORT && VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 1676 | break; |
donatien | 0:632c9925f013 | 1677 | |
donatien | 0:632c9925f013 | 1678 | case PPP_IP: /* Internet Protocol */ |
donatien | 0:632c9925f013 | 1679 | PPPDEBUG(LOG_INFO, ("pppInput[%d]: ip in pbuf len=%d\n", pd, nb->len)); |
donatien | 0:632c9925f013 | 1680 | if (pppControl[pd].netif.input) { |
donatien | 0:632c9925f013 | 1681 | pppControl[pd].netif.input(nb, &pppControl[pd].netif); |
donatien | 0:632c9925f013 | 1682 | return; |
donatien | 0:632c9925f013 | 1683 | } |
donatien | 0:632c9925f013 | 1684 | break; |
donatien | 0:632c9925f013 | 1685 | |
donatien | 0:632c9925f013 | 1686 | default: { |
donatien | 0:632c9925f013 | 1687 | struct protent *protp; |
donatien | 0:632c9925f013 | 1688 | int i; |
donatien | 0:632c9925f013 | 1689 | |
donatien | 0:632c9925f013 | 1690 | /* |
donatien | 0:632c9925f013 | 1691 | * Upcall the proper protocol input routine. |
donatien | 0:632c9925f013 | 1692 | */ |
donatien | 0:632c9925f013 | 1693 | for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) { |
donatien | 0:632c9925f013 | 1694 | if (protp->protocol == protocol && protp->enabled_flag) { |
donatien | 0:632c9925f013 | 1695 | PPPDEBUG(LOG_INFO, ("pppInput[%d]: %s len=%d\n", pd, protp->name, nb->len)); |
donatien | 0:632c9925f013 | 1696 | nb = pppSingleBuf(nb); |
donatien | 0:632c9925f013 | 1697 | (*protp->input)(pd, (u_char*)nb->payload, nb->len); |
donatien | 0:632c9925f013 | 1698 | PPPDEBUG(LOG_DETAIL, ("pppInput[%d]: packet processed\n", pd)); |
donatien | 0:632c9925f013 | 1699 | goto out; |
donatien | 0:632c9925f013 | 1700 | } |
donatien | 0:632c9925f013 | 1701 | } |
donatien | 0:632c9925f013 | 1702 | |
donatien | 0:632c9925f013 | 1703 | /* No handler for this protocol so reject the packet. */ |
donatien | 0:632c9925f013 | 1704 | PPPDEBUG(LOG_INFO, ("pppInput[%d]: rejecting unsupported proto 0x%"X16_F" len=%d\n", pd, protocol, nb->len)); |
donatien | 0:632c9925f013 | 1705 | if (pbuf_header(nb, sizeof(protocol))) { |
donatien | 0:632c9925f013 | 1706 | LWIP_ASSERT("pbuf_header failed\n", 0); |
donatien | 0:632c9925f013 | 1707 | goto drop; |
donatien | 0:632c9925f013 | 1708 | } |
donatien | 0:632c9925f013 | 1709 | #if BYTE_ORDER == LITTLE_ENDIAN |
donatien | 0:632c9925f013 | 1710 | protocol = htons(protocol); |
donatien | 0:632c9925f013 | 1711 | SMEMCPY(nb->payload, &protocol, sizeof(protocol)); |
donatien | 0:632c9925f013 | 1712 | #endif /* BYTE_ORDER == LITTLE_ENDIAN */ |
donatien | 0:632c9925f013 | 1713 | lcp_sprotrej(pd, (u_char*) nb->payload, nb->len); |
donatien | 0:632c9925f013 | 1714 | } |
donatien | 0:632c9925f013 | 1715 | break; |
donatien | 0:632c9925f013 | 1716 | } |
donatien | 0:632c9925f013 | 1717 | |
donatien | 0:632c9925f013 | 1718 | drop: |
donatien | 0:632c9925f013 | 1719 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 1720 | snmp_inc_ifindiscards(&pppControl[pd].netif); |
donatien | 0:632c9925f013 | 1721 | |
donatien | 0:632c9925f013 | 1722 | out: |
donatien | 0:632c9925f013 | 1723 | pbuf_free(nb); |
donatien | 0:632c9925f013 | 1724 | return; |
donatien | 0:632c9925f013 | 1725 | } |
donatien | 0:632c9925f013 | 1726 | |
donatien | 0:632c9925f013 | 1727 | #if PPPOS_SUPPORT |
donatien | 0:632c9925f013 | 1728 | /* |
donatien | 0:632c9925f013 | 1729 | * Drop the input packet. |
donatien | 0:632c9925f013 | 1730 | */ |
donatien | 0:632c9925f013 | 1731 | static void |
donatien | 0:632c9925f013 | 1732 | pppDrop(PPPControlRx *pcrx) |
donatien | 0:632c9925f013 | 1733 | { |
donatien | 0:632c9925f013 | 1734 | if (pcrx->inHead != NULL) { |
donatien | 0:632c9925f013 | 1735 | #if 0 |
donatien | 0:632c9925f013 | 1736 | PPPDEBUG(LOG_INFO, ("pppDrop: %d:%.*H\n", pcrx->inHead->len, min(60, pcrx->inHead->len * 2), pcrx->inHead->payload)); |
donatien | 0:632c9925f013 | 1737 | #endif |
donatien | 0:632c9925f013 | 1738 | PPPDEBUG(LOG_INFO, ("pppDrop: pbuf len=%d, addr %p\n", pcrx->inHead->len, (void*)pcrx->inHead)); |
donatien | 0:632c9925f013 | 1739 | if (pcrx->inTail && (pcrx->inTail != pcrx->inHead)) { |
donatien | 0:632c9925f013 | 1740 | pbuf_free(pcrx->inTail); |
donatien | 0:632c9925f013 | 1741 | } |
donatien | 0:632c9925f013 | 1742 | pbuf_free(pcrx->inHead); |
donatien | 0:632c9925f013 | 1743 | pcrx->inHead = NULL; |
donatien | 0:632c9925f013 | 1744 | pcrx->inTail = NULL; |
donatien | 0:632c9925f013 | 1745 | } |
donatien | 0:632c9925f013 | 1746 | #if VJ_SUPPORT |
donatien | 0:632c9925f013 | 1747 | vj_uncompress_err(&pppControl[pcrx->pd].vjComp); |
donatien | 0:632c9925f013 | 1748 | #endif /* VJ_SUPPORT */ |
donatien | 0:632c9925f013 | 1749 | |
donatien | 0:632c9925f013 | 1750 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 1751 | snmp_inc_ifindiscards(&pppControl[pcrx->pd].netif); |
donatien | 0:632c9925f013 | 1752 | } |
donatien | 0:632c9925f013 | 1753 | |
donatien | 0:632c9925f013 | 1754 | /** Pass received raw characters to PPPoS to be decoded. This function is |
donatien | 0:632c9925f013 | 1755 | * thread-safe and can be called from a dedicated RX-thread or from a main-loop. |
donatien | 0:632c9925f013 | 1756 | * |
donatien | 0:632c9925f013 | 1757 | * @param pd PPP descriptor index, returned by pppOpen() |
donatien | 0:632c9925f013 | 1758 | * @param data received data |
donatien | 0:632c9925f013 | 1759 | * @param len length of received data |
donatien | 0:632c9925f013 | 1760 | */ |
donatien | 0:632c9925f013 | 1761 | void |
donatien | 0:632c9925f013 | 1762 | pppos_input(int pd, u_char* data, int len) |
donatien | 0:632c9925f013 | 1763 | { |
donatien | 0:632c9925f013 | 1764 | pppInProc(&pppControl[pd].rx, data, len); |
donatien | 0:632c9925f013 | 1765 | } |
donatien | 0:632c9925f013 | 1766 | |
donatien | 0:632c9925f013 | 1767 | /** |
donatien | 0:632c9925f013 | 1768 | * Process a received octet string. |
donatien | 0:632c9925f013 | 1769 | */ |
donatien | 0:632c9925f013 | 1770 | static void |
donatien | 0:632c9925f013 | 1771 | pppInProc(PPPControlRx *pcrx, u_char *s, int l) |
donatien | 0:632c9925f013 | 1772 | { |
donatien | 0:632c9925f013 | 1773 | struct pbuf *nextNBuf; |
donatien | 0:632c9925f013 | 1774 | u_char curChar; |
donatien | 0:632c9925f013 | 1775 | u_char escaped; |
donatien | 0:632c9925f013 | 1776 | SYS_ARCH_DECL_PROTECT(lev); |
donatien | 0:632c9925f013 | 1777 | |
donatien | 0:632c9925f013 | 1778 | PPPDEBUG(LOG_DEBUG, ("pppInProc[%d]: got %d bytes\n", pcrx->pd, l)); |
donatien | 0:632c9925f013 | 1779 | while (l-- > 0) { |
donatien | 0:632c9925f013 | 1780 | curChar = *s++; |
donatien | 0:632c9925f013 | 1781 | |
donatien | 0:632c9925f013 | 1782 | SYS_ARCH_PROTECT(lev); |
donatien | 0:632c9925f013 | 1783 | escaped = ESCAPE_P(pcrx->inACCM, curChar); |
donatien | 0:632c9925f013 | 1784 | SYS_ARCH_UNPROTECT(lev); |
donatien | 0:632c9925f013 | 1785 | /* Handle special characters. */ |
donatien | 0:632c9925f013 | 1786 | if (escaped) { |
donatien | 0:632c9925f013 | 1787 | /* Check for escape sequences. */ |
donatien | 0:632c9925f013 | 1788 | /* XXX Note that this does not handle an escaped 0x5d character which |
donatien | 0:632c9925f013 | 1789 | * would appear as an escape character. Since this is an ASCII ']' |
donatien | 0:632c9925f013 | 1790 | * and there is no reason that I know of to escape it, I won't complicate |
donatien | 0:632c9925f013 | 1791 | * the code to handle this case. GLL */ |
donatien | 0:632c9925f013 | 1792 | if (curChar == PPP_ESCAPE) { |
donatien | 0:632c9925f013 | 1793 | pcrx->inEscaped = 1; |
donatien | 0:632c9925f013 | 1794 | /* Check for the flag character. */ |
donatien | 0:632c9925f013 | 1795 | } else if (curChar == PPP_FLAG) { |
donatien | 0:632c9925f013 | 1796 | /* If this is just an extra flag character, ignore it. */ |
donatien | 0:632c9925f013 | 1797 | if (pcrx->inState <= PDADDRESS) { |
donatien | 0:632c9925f013 | 1798 | /* ignore it */; |
donatien | 0:632c9925f013 | 1799 | /* If we haven't received the packet header, drop what has come in. */ |
donatien | 0:632c9925f013 | 1800 | } else if (pcrx->inState < PDDATA) { |
donatien | 0:632c9925f013 | 1801 | PPPDEBUG(LOG_WARNING, |
donatien | 0:632c9925f013 | 1802 | ("pppInProc[%d]: Dropping incomplete packet %d\n", |
donatien | 0:632c9925f013 | 1803 | pcrx->pd, pcrx->inState)); |
donatien | 0:632c9925f013 | 1804 | LINK_STATS_INC(link.lenerr); |
donatien | 0:632c9925f013 | 1805 | pppDrop(pcrx); |
donatien | 0:632c9925f013 | 1806 | /* If the fcs is invalid, drop the packet. */ |
donatien | 0:632c9925f013 | 1807 | } else if (pcrx->inFCS != PPP_GOODFCS) { |
donatien | 0:632c9925f013 | 1808 | PPPDEBUG(LOG_INFO, |
donatien | 0:632c9925f013 | 1809 | ("pppInProc[%d]: Dropping bad fcs 0x%"X16_F" proto=0x%"X16_F"\n", |
donatien | 0:632c9925f013 | 1810 | pcrx->pd, pcrx->inFCS, pcrx->inProtocol)); |
donatien | 0:632c9925f013 | 1811 | /* Note: If you get lots of these, check for UART frame errors or try different baud rate */ |
donatien | 0:632c9925f013 | 1812 | LINK_STATS_INC(link.chkerr); |
donatien | 0:632c9925f013 | 1813 | pppDrop(pcrx); |
donatien | 0:632c9925f013 | 1814 | /* Otherwise it's a good packet so pass it on. */ |
donatien | 0:632c9925f013 | 1815 | } else { |
donatien | 0:632c9925f013 | 1816 | /* Trim off the checksum. */ |
donatien | 0:632c9925f013 | 1817 | if(pcrx->inTail->len >= 2) { |
donatien | 0:632c9925f013 | 1818 | pcrx->inTail->len -= 2; |
donatien | 0:632c9925f013 | 1819 | |
donatien | 0:632c9925f013 | 1820 | pcrx->inTail->tot_len = pcrx->inTail->len; |
donatien | 0:632c9925f013 | 1821 | if (pcrx->inTail != pcrx->inHead) { |
donatien | 0:632c9925f013 | 1822 | pbuf_cat(pcrx->inHead, pcrx->inTail); |
donatien | 0:632c9925f013 | 1823 | } |
donatien | 0:632c9925f013 | 1824 | } else { |
donatien | 0:632c9925f013 | 1825 | pcrx->inTail->tot_len = pcrx->inTail->len; |
donatien | 0:632c9925f013 | 1826 | if (pcrx->inTail != pcrx->inHead) { |
donatien | 0:632c9925f013 | 1827 | pbuf_cat(pcrx->inHead, pcrx->inTail); |
donatien | 0:632c9925f013 | 1828 | } |
donatien | 0:632c9925f013 | 1829 | |
donatien | 0:632c9925f013 | 1830 | pbuf_realloc(pcrx->inHead, pcrx->inHead->tot_len - 2); |
donatien | 0:632c9925f013 | 1831 | } |
donatien | 0:632c9925f013 | 1832 | |
donatien | 0:632c9925f013 | 1833 | /* Dispatch the packet thereby consuming it. */ |
donatien | 0:632c9925f013 | 1834 | #if PPP_INPROC_MULTITHREADED |
donatien | 0:632c9925f013 | 1835 | if(tcpip_callback_with_block(pppInput, pcrx->inHead, 0) != ERR_OK) { |
donatien | 0:632c9925f013 | 1836 | PPPDEBUG(LOG_ERR, ("pppInProc[%d]: tcpip_callback() failed, dropping packet\n", pcrx->pd)); |
donatien | 0:632c9925f013 | 1837 | pbuf_free(pcrx->inHead); |
donatien | 0:632c9925f013 | 1838 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 1839 | snmp_inc_ifindiscards(&pppControl[pcrx->pd].netif); |
donatien | 0:632c9925f013 | 1840 | } |
donatien | 0:632c9925f013 | 1841 | #else /* PPP_INPROC_MULTITHREADED */ |
donatien | 0:632c9925f013 | 1842 | pppInput(pcrx->inHead); |
donatien | 0:632c9925f013 | 1843 | #endif /* PPP_INPROC_MULTITHREADED */ |
donatien | 0:632c9925f013 | 1844 | pcrx->inHead = NULL; |
donatien | 0:632c9925f013 | 1845 | pcrx->inTail = NULL; |
donatien | 0:632c9925f013 | 1846 | } |
donatien | 0:632c9925f013 | 1847 | |
donatien | 0:632c9925f013 | 1848 | /* Prepare for a new packet. */ |
donatien | 0:632c9925f013 | 1849 | pcrx->inFCS = PPP_INITFCS; |
donatien | 0:632c9925f013 | 1850 | pcrx->inState = PDADDRESS; |
donatien | 0:632c9925f013 | 1851 | pcrx->inEscaped = 0; |
donatien | 0:632c9925f013 | 1852 | /* Other characters are usually control characters that may have |
donatien | 0:632c9925f013 | 1853 | * been inserted by the physical layer so here we just drop them. */ |
donatien | 0:632c9925f013 | 1854 | } else { |
donatien | 0:632c9925f013 | 1855 | PPPDEBUG(LOG_WARNING, |
donatien | 0:632c9925f013 | 1856 | ("pppInProc[%d]: Dropping ACCM char <%d>\n", pcrx->pd, curChar)); |
donatien | 0:632c9925f013 | 1857 | } |
donatien | 0:632c9925f013 | 1858 | /* Process other characters. */ |
donatien | 0:632c9925f013 | 1859 | } else { |
donatien | 0:632c9925f013 | 1860 | /* Unencode escaped characters. */ |
donatien | 0:632c9925f013 | 1861 | if (pcrx->inEscaped) { |
donatien | 0:632c9925f013 | 1862 | pcrx->inEscaped = 0; |
donatien | 0:632c9925f013 | 1863 | curChar ^= PPP_TRANS; |
donatien | 0:632c9925f013 | 1864 | } |
donatien | 0:632c9925f013 | 1865 | |
donatien | 0:632c9925f013 | 1866 | /* Process character relative to current state. */ |
donatien | 0:632c9925f013 | 1867 | switch(pcrx->inState) { |
donatien | 0:632c9925f013 | 1868 | case PDIDLE: /* Idle state - waiting. */ |
donatien | 0:632c9925f013 | 1869 | /* Drop the character if it's not 0xff |
donatien | 0:632c9925f013 | 1870 | * we would have processed a flag character above. */ |
donatien | 0:632c9925f013 | 1871 | if (curChar != PPP_ALLSTATIONS) { |
donatien | 0:632c9925f013 | 1872 | break; |
donatien | 0:632c9925f013 | 1873 | } |
donatien | 0:632c9925f013 | 1874 | |
donatien | 0:632c9925f013 | 1875 | /* Fall through */ |
donatien | 0:632c9925f013 | 1876 | case PDSTART: /* Process start flag. */ |
donatien | 0:632c9925f013 | 1877 | /* Prepare for a new packet. */ |
donatien | 0:632c9925f013 | 1878 | pcrx->inFCS = PPP_INITFCS; |
donatien | 0:632c9925f013 | 1879 | |
donatien | 0:632c9925f013 | 1880 | /* Fall through */ |
donatien | 0:632c9925f013 | 1881 | case PDADDRESS: /* Process address field. */ |
donatien | 0:632c9925f013 | 1882 | if (curChar == PPP_ALLSTATIONS) { |
donatien | 0:632c9925f013 | 1883 | pcrx->inState = PDCONTROL; |
donatien | 0:632c9925f013 | 1884 | break; |
donatien | 0:632c9925f013 | 1885 | } |
donatien | 0:632c9925f013 | 1886 | /* Else assume compressed address and control fields so |
donatien | 0:632c9925f013 | 1887 | * fall through to get the protocol... */ |
donatien | 0:632c9925f013 | 1888 | case PDCONTROL: /* Process control field. */ |
donatien | 0:632c9925f013 | 1889 | /* If we don't get a valid control code, restart. */ |
donatien | 0:632c9925f013 | 1890 | if (curChar == PPP_UI) { |
donatien | 0:632c9925f013 | 1891 | pcrx->inState = PDPROTOCOL1; |
donatien | 0:632c9925f013 | 1892 | break; |
donatien | 0:632c9925f013 | 1893 | } |
donatien | 0:632c9925f013 | 1894 | #if 0 |
donatien | 0:632c9925f013 | 1895 | else { |
donatien | 0:632c9925f013 | 1896 | PPPDEBUG((LOG_WARNING, |
donatien | 0:632c9925f013 | 1897 | "pppInProc[%d]: Invalid control <%d>\n", pcrx->pd, curChar)); |
donatien | 0:632c9925f013 | 1898 | pcrx->inState = PDSTART; |
donatien | 0:632c9925f013 | 1899 | } |
donatien | 0:632c9925f013 | 1900 | #endif |
donatien | 0:632c9925f013 | 1901 | case PDPROTOCOL1: /* Process protocol field 1. */ |
donatien | 0:632c9925f013 | 1902 | /* If the lower bit is set, this is the end of the protocol |
donatien | 0:632c9925f013 | 1903 | * field. */ |
donatien | 0:632c9925f013 | 1904 | if (curChar & 1) { |
donatien | 0:632c9925f013 | 1905 | pcrx->inProtocol = curChar; |
donatien | 0:632c9925f013 | 1906 | pcrx->inState = PDDATA; |
donatien | 0:632c9925f013 | 1907 | } else { |
donatien | 0:632c9925f013 | 1908 | pcrx->inProtocol = (u_int)curChar << 8; |
donatien | 0:632c9925f013 | 1909 | pcrx->inState = PDPROTOCOL2; |
donatien | 0:632c9925f013 | 1910 | } |
donatien | 0:632c9925f013 | 1911 | break; |
donatien | 0:632c9925f013 | 1912 | case PDPROTOCOL2: /* Process protocol field 2. */ |
donatien | 0:632c9925f013 | 1913 | pcrx->inProtocol |= curChar; |
donatien | 0:632c9925f013 | 1914 | pcrx->inState = PDDATA; |
donatien | 0:632c9925f013 | 1915 | break; |
donatien | 0:632c9925f013 | 1916 | case PDDATA: /* Process data byte. */ |
donatien | 0:632c9925f013 | 1917 | /* Make space to receive processed data. */ |
donatien | 0:632c9925f013 | 1918 | if (pcrx->inTail == NULL || pcrx->inTail->len == PBUF_POOL_BUFSIZE) { |
donatien | 0:632c9925f013 | 1919 | if(pcrx->inTail) { |
donatien | 0:632c9925f013 | 1920 | pcrx->inTail->tot_len = pcrx->inTail->len; |
donatien | 0:632c9925f013 | 1921 | if (pcrx->inTail != pcrx->inHead) { |
donatien | 0:632c9925f013 | 1922 | pbuf_cat(pcrx->inHead, pcrx->inTail); |
donatien | 0:632c9925f013 | 1923 | } |
donatien | 0:632c9925f013 | 1924 | } |
donatien | 0:632c9925f013 | 1925 | /* If we haven't started a packet, we need a packet header. */ |
donatien | 0:632c9925f013 | 1926 | nextNBuf = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); |
donatien | 0:632c9925f013 | 1927 | if (nextNBuf == NULL) { |
donatien | 0:632c9925f013 | 1928 | /* No free buffers. Drop the input packet and let the |
donatien | 0:632c9925f013 | 1929 | * higher layers deal with it. Continue processing |
donatien | 0:632c9925f013 | 1930 | * the received pbuf chain in case a new packet starts. */ |
donatien | 0:632c9925f013 | 1931 | PPPDEBUG(LOG_ERR, ("pppInProc[%d]: NO FREE MBUFS!\n", pcrx->pd)); |
donatien | 0:632c9925f013 | 1932 | LINK_STATS_INC(link.memerr); |
donatien | 0:632c9925f013 | 1933 | pppDrop(pcrx); |
donatien | 0:632c9925f013 | 1934 | pcrx->inState = PDSTART; /* Wait for flag sequence. */ |
donatien | 0:632c9925f013 | 1935 | break; |
donatien | 0:632c9925f013 | 1936 | } |
donatien | 0:632c9925f013 | 1937 | if (pcrx->inHead == NULL) { |
donatien | 0:632c9925f013 | 1938 | struct pppInputHeader *pih = (struct pppInputHeader*) nextNBuf->payload; |
donatien | 0:632c9925f013 | 1939 | |
donatien | 0:632c9925f013 | 1940 | pih->unit = pcrx->pd; |
donatien | 0:632c9925f013 | 1941 | pih->proto = pcrx->inProtocol; |
donatien | 0:632c9925f013 | 1942 | |
donatien | 0:632c9925f013 | 1943 | nextNBuf->len += sizeof(*pih); |
donatien | 0:632c9925f013 | 1944 | |
donatien | 0:632c9925f013 | 1945 | pcrx->inHead = nextNBuf; |
donatien | 0:632c9925f013 | 1946 | } |
donatien | 0:632c9925f013 | 1947 | pcrx->inTail = nextNBuf; |
donatien | 0:632c9925f013 | 1948 | } |
donatien | 0:632c9925f013 | 1949 | /* Load character into buffer. */ |
donatien | 0:632c9925f013 | 1950 | ((u_char*)pcrx->inTail->payload)[pcrx->inTail->len++] = curChar; |
donatien | 0:632c9925f013 | 1951 | break; |
donatien | 0:632c9925f013 | 1952 | } |
donatien | 0:632c9925f013 | 1953 | |
donatien | 0:632c9925f013 | 1954 | /* update the frame check sequence number. */ |
donatien | 0:632c9925f013 | 1955 | pcrx->inFCS = PPP_FCS(pcrx->inFCS, curChar); |
donatien | 0:632c9925f013 | 1956 | } |
donatien | 0:632c9925f013 | 1957 | } /* while (l-- > 0), all bytes processed */ |
donatien | 0:632c9925f013 | 1958 | |
donatien | 0:632c9925f013 | 1959 | avRandomize(); |
donatien | 0:632c9925f013 | 1960 | } |
donatien | 0:632c9925f013 | 1961 | #endif /* PPPOS_SUPPORT */ |
donatien | 0:632c9925f013 | 1962 | |
donatien | 0:632c9925f013 | 1963 | #if PPPOE_SUPPORT |
donatien | 0:632c9925f013 | 1964 | void |
donatien | 0:632c9925f013 | 1965 | pppInProcOverEthernet(int pd, struct pbuf *pb) |
donatien | 0:632c9925f013 | 1966 | { |
donatien | 0:632c9925f013 | 1967 | struct pppInputHeader *pih; |
donatien | 0:632c9925f013 | 1968 | u16_t inProtocol; |
donatien | 0:632c9925f013 | 1969 | |
donatien | 0:632c9925f013 | 1970 | if(pb->len < sizeof(inProtocol)) { |
donatien | 0:632c9925f013 | 1971 | PPPDEBUG(LOG_ERR, ("pppInProcOverEthernet: too small for protocol field\n")); |
donatien | 0:632c9925f013 | 1972 | goto drop; |
donatien | 0:632c9925f013 | 1973 | } |
donatien | 0:632c9925f013 | 1974 | |
donatien | 0:632c9925f013 | 1975 | inProtocol = (((u8_t *)pb->payload)[0] << 8) | ((u8_t*)pb->payload)[1]; |
donatien | 0:632c9925f013 | 1976 | |
donatien | 0:632c9925f013 | 1977 | /* make room for pppInputHeader - should not fail */ |
donatien | 0:632c9925f013 | 1978 | if (pbuf_header(pb, sizeof(*pih) - sizeof(inProtocol)) != 0) { |
donatien | 0:632c9925f013 | 1979 | PPPDEBUG(LOG_ERR, ("pppInProcOverEthernet: could not allocate room for header\n")); |
donatien | 0:632c9925f013 | 1980 | goto drop; |
donatien | 0:632c9925f013 | 1981 | } |
donatien | 0:632c9925f013 | 1982 | |
donatien | 0:632c9925f013 | 1983 | pih = pb->payload; |
donatien | 0:632c9925f013 | 1984 | |
donatien | 0:632c9925f013 | 1985 | pih->unit = pd; |
donatien | 0:632c9925f013 | 1986 | pih->proto = inProtocol; |
donatien | 0:632c9925f013 | 1987 | |
donatien | 0:632c9925f013 | 1988 | /* Dispatch the packet thereby consuming it. */ |
donatien | 0:632c9925f013 | 1989 | pppInput(pb); |
donatien | 0:632c9925f013 | 1990 | return; |
donatien | 0:632c9925f013 | 1991 | |
donatien | 0:632c9925f013 | 1992 | drop: |
donatien | 0:632c9925f013 | 1993 | LINK_STATS_INC(link.drop); |
donatien | 0:632c9925f013 | 1994 | snmp_inc_ifindiscards(&pppControl[pd].netif); |
donatien | 0:632c9925f013 | 1995 | pbuf_free(pb); |
donatien | 0:632c9925f013 | 1996 | return; |
donatien | 0:632c9925f013 | 1997 | } |
donatien | 0:632c9925f013 | 1998 | #endif /* PPPOE_SUPPORT */ |
donatien | 0:632c9925f013 | 1999 | |
donatien | 0:632c9925f013 | 2000 | #if LWIP_NETIF_STATUS_CALLBACK |
donatien | 0:632c9925f013 | 2001 | /** Set the status callback of a PPP's netif |
donatien | 0:632c9925f013 | 2002 | * |
donatien | 0:632c9925f013 | 2003 | * @param pd The PPP descriptor returned by pppOpen() |
donatien | 0:632c9925f013 | 2004 | * @param status_callback pointer to the status callback function |
donatien | 0:632c9925f013 | 2005 | * |
donatien | 0:632c9925f013 | 2006 | * @see netif_set_status_callback |
donatien | 0:632c9925f013 | 2007 | */ |
donatien | 0:632c9925f013 | 2008 | void |
donatien | 0:632c9925f013 | 2009 | ppp_set_netif_statuscallback(int pd, netif_status_callback_fn status_callback) |
donatien | 0:632c9925f013 | 2010 | { |
donatien | 0:632c9925f013 | 2011 | netif_set_status_callback(&pppControl[pd].netif, status_callback); |
donatien | 0:632c9925f013 | 2012 | } |
donatien | 0:632c9925f013 | 2013 | #endif /* LWIP_NETIF_STATUS_CALLBACK */ |
donatien | 0:632c9925f013 | 2014 | |
donatien | 0:632c9925f013 | 2015 | #if LWIP_NETIF_LINK_CALLBACK |
donatien | 0:632c9925f013 | 2016 | /** Set the link callback of a PPP's netif |
donatien | 0:632c9925f013 | 2017 | * |
donatien | 0:632c9925f013 | 2018 | * @param pd The PPP descriptor returned by pppOpen() |
donatien | 0:632c9925f013 | 2019 | * @param link_callback pointer to the link callback function |
donatien | 0:632c9925f013 | 2020 | * |
donatien | 0:632c9925f013 | 2021 | * @see netif_set_link_callback |
donatien | 0:632c9925f013 | 2022 | */ |
donatien | 0:632c9925f013 | 2023 | void |
donatien | 0:632c9925f013 | 2024 | ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback) |
donatien | 0:632c9925f013 | 2025 | { |
donatien | 0:632c9925f013 | 2026 | netif_set_link_callback(&pppControl[pd].netif, link_callback); |
donatien | 0:632c9925f013 | 2027 | } |
donatien | 0:632c9925f013 | 2028 | #endif /* LWIP_NETIF_LINK_CALLBACK */ |
donatien | 0:632c9925f013 | 2029 | |
donatien | 0:632c9925f013 | 2030 | #endif /* PPP_SUPPORT */ |