lwip_bleedingedge

Fork of lwip by mbed official

Committer:
donatien
Date:
Thu Apr 10 17:37:32 2014 +0000
Revision:
16:a61070aa2e98
Parent:
15:e5bb25d5506f
Fixed race condition in PPP

Who changed what in which revision?

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