Modification to work two socket servers at the same time

Fork of lwip by mbed official

Committer:
mmdonatti
Date:
Thu May 10 18:17:16 2018 +0000
Revision:
21:83acd30508d0
Parent:
4:f71f5d9d5846
hostname adjust + modified define to make 2 socket servers working at the same time

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