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