I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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