Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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