HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

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