NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

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