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