SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lorcansmith 0:2a53a4c3238c 1 /*****************************************************************************
lorcansmith 0:2a53a4c3238c 2 * ppp_oe.c - PPP Over Ethernet implementation for lwIP.
lorcansmith 0:2a53a4c3238c 3 *
lorcansmith 0:2a53a4c3238c 4 * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc.
lorcansmith 0:2a53a4c3238c 5 *
lorcansmith 0:2a53a4c3238c 6 * The authors hereby grant permission to use, copy, modify, distribute,
lorcansmith 0:2a53a4c3238c 7 * and license this software and its documentation for any purpose, provided
lorcansmith 0:2a53a4c3238c 8 * that existing copyright notices are retained in all copies and that this
lorcansmith 0:2a53a4c3238c 9 * notice and the following disclaimer are included verbatim in any
lorcansmith 0:2a53a4c3238c 10 * distributions. No written agreement, license, or royalty fee is required
lorcansmith 0:2a53a4c3238c 11 * for any of the authorized uses.
lorcansmith 0:2a53a4c3238c 12 *
lorcansmith 0:2a53a4c3238c 13 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
lorcansmith 0:2a53a4c3238c 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
lorcansmith 0:2a53a4c3238c 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
lorcansmith 0:2a53a4c3238c 16 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
lorcansmith 0:2a53a4c3238c 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lorcansmith 0:2a53a4c3238c 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
lorcansmith 0:2a53a4c3238c 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
lorcansmith 0:2a53a4c3238c 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
lorcansmith 0:2a53a4c3238c 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
lorcansmith 0:2a53a4c3238c 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lorcansmith 0:2a53a4c3238c 23 *
lorcansmith 0:2a53a4c3238c 24 ******************************************************************************
lorcansmith 0:2a53a4c3238c 25 * REVISION HISTORY
lorcansmith 0:2a53a4c3238c 26 *
lorcansmith 0:2a53a4c3238c 27 * 06-01-01 Marc Boucher <marc@mbsi.ca>
lorcansmith 0:2a53a4c3238c 28 * Ported to lwIP.
lorcansmith 0:2a53a4c3238c 29 *****************************************************************************/
lorcansmith 0:2a53a4c3238c 30
lorcansmith 0:2a53a4c3238c 31
lorcansmith 0:2a53a4c3238c 32
lorcansmith 0:2a53a4c3238c 33 /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */
lorcansmith 0:2a53a4c3238c 34
lorcansmith 0:2a53a4c3238c 35 /*-
lorcansmith 0:2a53a4c3238c 36 * Copyright (c) 2002 The NetBSD Foundation, Inc.
lorcansmith 0:2a53a4c3238c 37 * All rights reserved.
lorcansmith 0:2a53a4c3238c 38 *
lorcansmith 0:2a53a4c3238c 39 * This code is derived from software contributed to The NetBSD Foundation
lorcansmith 0:2a53a4c3238c 40 * by Martin Husemann <martin@NetBSD.org>.
lorcansmith 0:2a53a4c3238c 41 *
lorcansmith 0:2a53a4c3238c 42 * Redistribution and use in source and binary forms, with or without
lorcansmith 0:2a53a4c3238c 43 * modification, are permitted provided that the following conditions
lorcansmith 0:2a53a4c3238c 44 * are met:
lorcansmith 0:2a53a4c3238c 45 * 1. Redistributions of source code must retain the above copyright
lorcansmith 0:2a53a4c3238c 46 * notice, this list of conditions and the following disclaimer.
lorcansmith 0:2a53a4c3238c 47 * 2. Redistributions in binary form must reproduce the above copyright
lorcansmith 0:2a53a4c3238c 48 * notice, this list of conditions and the following disclaimer in the
lorcansmith 0:2a53a4c3238c 49 * documentation and/or other materials provided with the distribution.
lorcansmith 0:2a53a4c3238c 50 * 3. All advertising materials mentioning features or use of this software
lorcansmith 0:2a53a4c3238c 51 * must display the following acknowledgement:
lorcansmith 0:2a53a4c3238c 52 * This product includes software developed by the NetBSD
lorcansmith 0:2a53a4c3238c 53 * Foundation, Inc. and its contributors.
lorcansmith 0:2a53a4c3238c 54 * 4. Neither the name of The NetBSD Foundation nor the names of its
lorcansmith 0:2a53a4c3238c 55 * contributors may be used to endorse or promote products derived
lorcansmith 0:2a53a4c3238c 56 * from this software without specific prior written permission.
lorcansmith 0:2a53a4c3238c 57 *
lorcansmith 0:2a53a4c3238c 58 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
lorcansmith 0:2a53a4c3238c 59 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
lorcansmith 0:2a53a4c3238c 60 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
lorcansmith 0:2a53a4c3238c 61 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
lorcansmith 0:2a53a4c3238c 62 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
lorcansmith 0:2a53a4c3238c 63 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
lorcansmith 0:2a53a4c3238c 64 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
lorcansmith 0:2a53a4c3238c 65 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
lorcansmith 0:2a53a4c3238c 66 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lorcansmith 0:2a53a4c3238c 67 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
lorcansmith 0:2a53a4c3238c 68 * POSSIBILITY OF SUCH DAMAGE.
lorcansmith 0:2a53a4c3238c 69 */
lorcansmith 0:2a53a4c3238c 70
lorcansmith 0:2a53a4c3238c 71 #include "lwip/opt.h"
lorcansmith 0:2a53a4c3238c 72
lorcansmith 0:2a53a4c3238c 73 #if PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */
lorcansmith 0:2a53a4c3238c 74
lorcansmith 0:2a53a4c3238c 75 #include "netif/ppp_oe.h"
lorcansmith 0:2a53a4c3238c 76
lorcansmith 0:2a53a4c3238c 77 #include "ppp.h"
lorcansmith 0:2a53a4c3238c 78 #include "pppdebug.h"
lorcansmith 0:2a53a4c3238c 79
lorcansmith 0:2a53a4c3238c 80 #include "lwip/timers.h"
lorcansmith 0:2a53a4c3238c 81 #include "lwip/memp.h"
lorcansmith 0:2a53a4c3238c 82
lorcansmith 0:2a53a4c3238c 83 #include <string.h>
lorcansmith 0:2a53a4c3238c 84 #include <stdio.h>
lorcansmith 0:2a53a4c3238c 85
lorcansmith 0:2a53a4c3238c 86
lorcansmith 0:2a53a4c3238c 87 /* Add a 16 bit unsigned value to a buffer pointed to by PTR */
lorcansmith 0:2a53a4c3238c 88 #define PPPOE_ADD_16(PTR, VAL) \
lorcansmith 0:2a53a4c3238c 89 *(PTR)++ = (u8_t)((VAL) / 256); \
lorcansmith 0:2a53a4c3238c 90 *(PTR)++ = (u8_t)((VAL) % 256)
lorcansmith 0:2a53a4c3238c 91
lorcansmith 0:2a53a4c3238c 92 /* Add a complete PPPoE header to the buffer pointed to by PTR */
lorcansmith 0:2a53a4c3238c 93 #define PPPOE_ADD_HEADER(PTR, CODE, SESS, LEN) \
lorcansmith 0:2a53a4c3238c 94 *(PTR)++ = PPPOE_VERTYPE; \
lorcansmith 0:2a53a4c3238c 95 *(PTR)++ = (CODE); \
lorcansmith 0:2a53a4c3238c 96 PPPOE_ADD_16(PTR, SESS); \
lorcansmith 0:2a53a4c3238c 97 PPPOE_ADD_16(PTR, LEN)
lorcansmith 0:2a53a4c3238c 98
lorcansmith 0:2a53a4c3238c 99 #define PPPOE_DISC_TIMEOUT (5*1000) /* base for quick timeout calculation */
lorcansmith 0:2a53a4c3238c 100 #define PPPOE_SLOW_RETRY (60*1000) /* persistent retry interval */
lorcansmith 0:2a53a4c3238c 101 #define PPPOE_DISC_MAXPADI 4 /* retry PADI four times (quickly) */
lorcansmith 0:2a53a4c3238c 102 #define PPPOE_DISC_MAXPADR 2 /* retry PADR twice */
lorcansmith 0:2a53a4c3238c 103
lorcansmith 0:2a53a4c3238c 104 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 105 #error "PPPOE_SERVER is not yet supported under lwIP!"
lorcansmith 0:2a53a4c3238c 106 /* from if_spppsubr.c */
lorcansmith 0:2a53a4c3238c 107 #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */
lorcansmith 0:2a53a4c3238c 108 #endif
lorcansmith 0:2a53a4c3238c 109
lorcansmith 0:2a53a4c3238c 110 #ifndef PPPOE_ERRORSTRING_LEN
lorcansmith 0:2a53a4c3238c 111 #define PPPOE_ERRORSTRING_LEN 64
lorcansmith 0:2a53a4c3238c 112 #endif
lorcansmith 0:2a53a4c3238c 113 static char pppoe_error_tmp[PPPOE_ERRORSTRING_LEN];
lorcansmith 0:2a53a4c3238c 114
lorcansmith 0:2a53a4c3238c 115
lorcansmith 0:2a53a4c3238c 116 /* input routines */
lorcansmith 0:2a53a4c3238c 117 static void pppoe_dispatch_disc_pkt(struct netif *, struct pbuf *);
lorcansmith 0:2a53a4c3238c 118
lorcansmith 0:2a53a4c3238c 119 /* management routines */
lorcansmith 0:2a53a4c3238c 120 static int pppoe_do_disconnect(struct pppoe_softc *);
lorcansmith 0:2a53a4c3238c 121 static void pppoe_abort_connect(struct pppoe_softc *);
lorcansmith 0:2a53a4c3238c 122 static void pppoe_clear_softc(struct pppoe_softc *, const char *);
lorcansmith 0:2a53a4c3238c 123
lorcansmith 0:2a53a4c3238c 124 /* internal timeout handling */
lorcansmith 0:2a53a4c3238c 125 static void pppoe_timeout(void *);
lorcansmith 0:2a53a4c3238c 126
lorcansmith 0:2a53a4c3238c 127 /* sending actual protocol controll packets */
lorcansmith 0:2a53a4c3238c 128 static err_t pppoe_send_padi(struct pppoe_softc *);
lorcansmith 0:2a53a4c3238c 129 static err_t pppoe_send_padr(struct pppoe_softc *);
lorcansmith 0:2a53a4c3238c 130 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 131 static err_t pppoe_send_pado(struct pppoe_softc *);
lorcansmith 0:2a53a4c3238c 132 static err_t pppoe_send_pads(struct pppoe_softc *);
lorcansmith 0:2a53a4c3238c 133 #endif
lorcansmith 0:2a53a4c3238c 134 static err_t pppoe_send_padt(struct netif *, u_int, const u8_t *);
lorcansmith 0:2a53a4c3238c 135
lorcansmith 0:2a53a4c3238c 136 /* internal helper functions */
lorcansmith 0:2a53a4c3238c 137 static struct pppoe_softc * pppoe_find_softc_by_session(u_int, struct netif *);
lorcansmith 0:2a53a4c3238c 138 static struct pppoe_softc * pppoe_find_softc_by_hunique(u8_t *, size_t, struct netif *);
lorcansmith 0:2a53a4c3238c 139
lorcansmith 0:2a53a4c3238c 140 /** linked list of created pppoe interfaces */
lorcansmith 0:2a53a4c3238c 141 static struct pppoe_softc *pppoe_softc_list;
lorcansmith 0:2a53a4c3238c 142
lorcansmith 0:2a53a4c3238c 143 err_t
lorcansmith 0:2a53a4c3238c 144 pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr)
lorcansmith 0:2a53a4c3238c 145 {
lorcansmith 0:2a53a4c3238c 146 struct pppoe_softc *sc;
lorcansmith 0:2a53a4c3238c 147
lorcansmith 0:2a53a4c3238c 148 sc = (struct pppoe_softc *)memp_malloc(MEMP_PPPOE_IF);
lorcansmith 0:2a53a4c3238c 149 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 150 *scptr = NULL;
lorcansmith 0:2a53a4c3238c 151 return ERR_MEM;
lorcansmith 0:2a53a4c3238c 152 }
lorcansmith 0:2a53a4c3238c 153 memset(sc, 0, sizeof(struct pppoe_softc));
lorcansmith 0:2a53a4c3238c 154
lorcansmith 0:2a53a4c3238c 155 /* changed to real address later */
lorcansmith 0:2a53a4c3238c 156 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
lorcansmith 0:2a53a4c3238c 157
lorcansmith 0:2a53a4c3238c 158 sc->sc_pd = pd;
lorcansmith 0:2a53a4c3238c 159 sc->sc_linkStatusCB = linkStatusCB;
lorcansmith 0:2a53a4c3238c 160 sc->sc_ethif = ethif;
lorcansmith 0:2a53a4c3238c 161
lorcansmith 0:2a53a4c3238c 162 /* put the new interface at the head of the list */
lorcansmith 0:2a53a4c3238c 163 sc->next = pppoe_softc_list;
lorcansmith 0:2a53a4c3238c 164 pppoe_softc_list = sc;
lorcansmith 0:2a53a4c3238c 165
lorcansmith 0:2a53a4c3238c 166 *scptr = sc;
lorcansmith 0:2a53a4c3238c 167
lorcansmith 0:2a53a4c3238c 168 return ERR_OK;
lorcansmith 0:2a53a4c3238c 169 }
lorcansmith 0:2a53a4c3238c 170
lorcansmith 0:2a53a4c3238c 171 err_t
lorcansmith 0:2a53a4c3238c 172 pppoe_destroy(struct netif *ifp)
lorcansmith 0:2a53a4c3238c 173 {
lorcansmith 0:2a53a4c3238c 174 struct pppoe_softc *sc, *prev = NULL;
lorcansmith 0:2a53a4c3238c 175
lorcansmith 0:2a53a4c3238c 176 for (sc = pppoe_softc_list; sc != NULL; prev = sc, sc = sc->next) {
lorcansmith 0:2a53a4c3238c 177 if (sc->sc_ethif == ifp) {
lorcansmith 0:2a53a4c3238c 178 break;
lorcansmith 0:2a53a4c3238c 179 }
lorcansmith 0:2a53a4c3238c 180 }
lorcansmith 0:2a53a4c3238c 181
lorcansmith 0:2a53a4c3238c 182 if(!(sc && (sc->sc_ethif == ifp))) {
lorcansmith 0:2a53a4c3238c 183 return ERR_IF;
lorcansmith 0:2a53a4c3238c 184 }
lorcansmith 0:2a53a4c3238c 185
lorcansmith 0:2a53a4c3238c 186 sys_untimeout(pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 187 if (prev == NULL) {
lorcansmith 0:2a53a4c3238c 188 /* remove sc from the head of the list */
lorcansmith 0:2a53a4c3238c 189 pppoe_softc_list = sc->next;
lorcansmith 0:2a53a4c3238c 190 } else {
lorcansmith 0:2a53a4c3238c 191 /* remove sc from the list */
lorcansmith 0:2a53a4c3238c 192 prev->next = sc->next;
lorcansmith 0:2a53a4c3238c 193 }
lorcansmith 0:2a53a4c3238c 194
lorcansmith 0:2a53a4c3238c 195 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 196 if (sc->sc_concentrator_name) {
lorcansmith 0:2a53a4c3238c 197 mem_free(sc->sc_concentrator_name);
lorcansmith 0:2a53a4c3238c 198 }
lorcansmith 0:2a53a4c3238c 199 if (sc->sc_service_name) {
lorcansmith 0:2a53a4c3238c 200 mem_free(sc->sc_service_name);
lorcansmith 0:2a53a4c3238c 201 }
lorcansmith 0:2a53a4c3238c 202 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 203 memp_free(MEMP_PPPOE_IF, sc);
lorcansmith 0:2a53a4c3238c 204
lorcansmith 0:2a53a4c3238c 205 return ERR_OK;
lorcansmith 0:2a53a4c3238c 206 }
lorcansmith 0:2a53a4c3238c 207
lorcansmith 0:2a53a4c3238c 208 /*
lorcansmith 0:2a53a4c3238c 209 * Find the interface handling the specified session.
lorcansmith 0:2a53a4c3238c 210 * Note: O(number of sessions open), this is a client-side only, mean
lorcansmith 0:2a53a4c3238c 211 * and lean implementation, so number of open sessions typically should
lorcansmith 0:2a53a4c3238c 212 * be 1.
lorcansmith 0:2a53a4c3238c 213 */
lorcansmith 0:2a53a4c3238c 214 static struct pppoe_softc *
lorcansmith 0:2a53a4c3238c 215 pppoe_find_softc_by_session(u_int session, struct netif *rcvif)
lorcansmith 0:2a53a4c3238c 216 {
lorcansmith 0:2a53a4c3238c 217 struct pppoe_softc *sc;
lorcansmith 0:2a53a4c3238c 218
lorcansmith 0:2a53a4c3238c 219 if (session == 0) {
lorcansmith 0:2a53a4c3238c 220 return NULL;
lorcansmith 0:2a53a4c3238c 221 }
lorcansmith 0:2a53a4c3238c 222
lorcansmith 0:2a53a4c3238c 223 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
lorcansmith 0:2a53a4c3238c 224 if (sc->sc_state == PPPOE_STATE_SESSION
lorcansmith 0:2a53a4c3238c 225 && sc->sc_session == session) {
lorcansmith 0:2a53a4c3238c 226 if (sc->sc_ethif == rcvif) {
lorcansmith 0:2a53a4c3238c 227 return sc;
lorcansmith 0:2a53a4c3238c 228 } else {
lorcansmith 0:2a53a4c3238c 229 return NULL;
lorcansmith 0:2a53a4c3238c 230 }
lorcansmith 0:2a53a4c3238c 231 }
lorcansmith 0:2a53a4c3238c 232 }
lorcansmith 0:2a53a4c3238c 233 return NULL;
lorcansmith 0:2a53a4c3238c 234 }
lorcansmith 0:2a53a4c3238c 235
lorcansmith 0:2a53a4c3238c 236 /* Check host unique token passed and return appropriate softc pointer,
lorcansmith 0:2a53a4c3238c 237 * or NULL if token is bogus. */
lorcansmith 0:2a53a4c3238c 238 static struct pppoe_softc *
lorcansmith 0:2a53a4c3238c 239 pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif)
lorcansmith 0:2a53a4c3238c 240 {
lorcansmith 0:2a53a4c3238c 241 struct pppoe_softc *sc, *t;
lorcansmith 0:2a53a4c3238c 242
lorcansmith 0:2a53a4c3238c 243 if (pppoe_softc_list == NULL) {
lorcansmith 0:2a53a4c3238c 244 return NULL;
lorcansmith 0:2a53a4c3238c 245 }
lorcansmith 0:2a53a4c3238c 246
lorcansmith 0:2a53a4c3238c 247 if (len != sizeof sc) {
lorcansmith 0:2a53a4c3238c 248 return NULL;
lorcansmith 0:2a53a4c3238c 249 }
lorcansmith 0:2a53a4c3238c 250 MEMCPY(&t, token, len);
lorcansmith 0:2a53a4c3238c 251
lorcansmith 0:2a53a4c3238c 252 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
lorcansmith 0:2a53a4c3238c 253 if (sc == t) {
lorcansmith 0:2a53a4c3238c 254 break;
lorcansmith 0:2a53a4c3238c 255 }
lorcansmith 0:2a53a4c3238c 256 }
lorcansmith 0:2a53a4c3238c 257
lorcansmith 0:2a53a4c3238c 258 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 259 PPPDEBUG(LOG_DEBUG, ("pppoe: alien host unique tag, no session found\n"));
lorcansmith 0:2a53a4c3238c 260 return NULL;
lorcansmith 0:2a53a4c3238c 261 }
lorcansmith 0:2a53a4c3238c 262
lorcansmith 0:2a53a4c3238c 263 /* should be safe to access *sc now */
lorcansmith 0:2a53a4c3238c 264 if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) {
lorcansmith 0:2a53a4c3238c 265 printf("%c%c%"U16_F": host unique tag found, but it belongs to a connection in state %d\n",
lorcansmith 0:2a53a4c3238c 266 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_state);
lorcansmith 0:2a53a4c3238c 267 return NULL;
lorcansmith 0:2a53a4c3238c 268 }
lorcansmith 0:2a53a4c3238c 269 if (sc->sc_ethif != rcvif) {
lorcansmith 0:2a53a4c3238c 270 printf("%c%c%"U16_F": wrong interface, not accepting host unique\n",
lorcansmith 0:2a53a4c3238c 271 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
lorcansmith 0:2a53a4c3238c 272 return NULL;
lorcansmith 0:2a53a4c3238c 273 }
lorcansmith 0:2a53a4c3238c 274 return sc;
lorcansmith 0:2a53a4c3238c 275 }
lorcansmith 0:2a53a4c3238c 276
lorcansmith 0:2a53a4c3238c 277 static void
lorcansmith 0:2a53a4c3238c 278 pppoe_linkstatus_up(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 279 {
lorcansmith 0:2a53a4c3238c 280 sc->sc_linkStatusCB(sc->sc_pd, 1);
lorcansmith 0:2a53a4c3238c 281 }
lorcansmith 0:2a53a4c3238c 282
lorcansmith 0:2a53a4c3238c 283 /* analyze and handle a single received packet while not in session state */
lorcansmith 0:2a53a4c3238c 284 static void
lorcansmith 0:2a53a4c3238c 285 pppoe_dispatch_disc_pkt(struct netif *netif, struct pbuf *pb)
lorcansmith 0:2a53a4c3238c 286 {
lorcansmith 0:2a53a4c3238c 287 u16_t tag, len;
lorcansmith 0:2a53a4c3238c 288 u16_t session, plen;
lorcansmith 0:2a53a4c3238c 289 struct pppoe_softc *sc;
lorcansmith 0:2a53a4c3238c 290 const char *err_msg;
lorcansmith 0:2a53a4c3238c 291 char devname[6];
lorcansmith 0:2a53a4c3238c 292 u8_t *ac_cookie;
lorcansmith 0:2a53a4c3238c 293 u16_t ac_cookie_len;
lorcansmith 0:2a53a4c3238c 294 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 295 u8_t *hunique;
lorcansmith 0:2a53a4c3238c 296 size_t hunique_len;
lorcansmith 0:2a53a4c3238c 297 #endif
lorcansmith 0:2a53a4c3238c 298 struct pppoehdr *ph;
lorcansmith 0:2a53a4c3238c 299 struct pppoetag pt;
lorcansmith 0:2a53a4c3238c 300 int off, err, errortag;
lorcansmith 0:2a53a4c3238c 301 struct eth_hdr *ethhdr;
lorcansmith 0:2a53a4c3238c 302
lorcansmith 0:2a53a4c3238c 303 pb = pppSingleBuf(pb);
lorcansmith 0:2a53a4c3238c 304
lorcansmith 0:2a53a4c3238c 305 strcpy(devname, "pppoe"); /* as long as we don't know which instance */
lorcansmith 0:2a53a4c3238c 306 err_msg = NULL;
lorcansmith 0:2a53a4c3238c 307 errortag = 0;
lorcansmith 0:2a53a4c3238c 308 if (pb->len < sizeof(*ethhdr)) {
lorcansmith 0:2a53a4c3238c 309 goto done;
lorcansmith 0:2a53a4c3238c 310 }
lorcansmith 0:2a53a4c3238c 311 ethhdr = (struct eth_hdr *)pb->payload;
lorcansmith 0:2a53a4c3238c 312 off = sizeof(*ethhdr);
lorcansmith 0:2a53a4c3238c 313
lorcansmith 0:2a53a4c3238c 314 ac_cookie = NULL;
lorcansmith 0:2a53a4c3238c 315 ac_cookie_len = 0;
lorcansmith 0:2a53a4c3238c 316 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 317 hunique = NULL;
lorcansmith 0:2a53a4c3238c 318 hunique_len = 0;
lorcansmith 0:2a53a4c3238c 319 #endif
lorcansmith 0:2a53a4c3238c 320 session = 0;
lorcansmith 0:2a53a4c3238c 321 if (pb->len - off < PPPOE_HEADERLEN) {
lorcansmith 0:2a53a4c3238c 322 printf("pppoe: packet too short: %d\n", pb->len);
lorcansmith 0:2a53a4c3238c 323 goto done;
lorcansmith 0:2a53a4c3238c 324 }
lorcansmith 0:2a53a4c3238c 325
lorcansmith 0:2a53a4c3238c 326 ph = (struct pppoehdr *) (ethhdr + 1);
lorcansmith 0:2a53a4c3238c 327 if (ph->vertype != PPPOE_VERTYPE) {
lorcansmith 0:2a53a4c3238c 328 printf("pppoe: unknown version/type packet: 0x%x\n", ph->vertype);
lorcansmith 0:2a53a4c3238c 329 goto done;
lorcansmith 0:2a53a4c3238c 330 }
lorcansmith 0:2a53a4c3238c 331 session = ntohs(ph->session);
lorcansmith 0:2a53a4c3238c 332 plen = ntohs(ph->plen);
lorcansmith 0:2a53a4c3238c 333 off += sizeof(*ph);
lorcansmith 0:2a53a4c3238c 334
lorcansmith 0:2a53a4c3238c 335 if (plen + off > pb->len) {
lorcansmith 0:2a53a4c3238c 336 printf("pppoe: packet content does not fit: data available = %d, packet size = %u\n",
lorcansmith 0:2a53a4c3238c 337 pb->len - off, plen);
lorcansmith 0:2a53a4c3238c 338 goto done;
lorcansmith 0:2a53a4c3238c 339 }
lorcansmith 0:2a53a4c3238c 340 if(pb->tot_len == pb->len) {
lorcansmith 0:2a53a4c3238c 341 pb->tot_len = pb->len = (u16_t)off + plen; /* ignore trailing garbage */
lorcansmith 0:2a53a4c3238c 342 }
lorcansmith 0:2a53a4c3238c 343 tag = 0;
lorcansmith 0:2a53a4c3238c 344 len = 0;
lorcansmith 0:2a53a4c3238c 345 sc = NULL;
lorcansmith 0:2a53a4c3238c 346 while (off + sizeof(pt) <= pb->len) {
lorcansmith 0:2a53a4c3238c 347 MEMCPY(&pt, (u8_t*)pb->payload + off, sizeof(pt));
lorcansmith 0:2a53a4c3238c 348 tag = ntohs(pt.tag);
lorcansmith 0:2a53a4c3238c 349 len = ntohs(pt.len);
lorcansmith 0:2a53a4c3238c 350 if (off + sizeof(pt) + len > pb->len) {
lorcansmith 0:2a53a4c3238c 351 printf("pppoe: tag 0x%x len 0x%x is too long\n", tag, len);
lorcansmith 0:2a53a4c3238c 352 goto done;
lorcansmith 0:2a53a4c3238c 353 }
lorcansmith 0:2a53a4c3238c 354 switch (tag) {
lorcansmith 0:2a53a4c3238c 355 case PPPOE_TAG_EOL:
lorcansmith 0:2a53a4c3238c 356 goto breakbreak;
lorcansmith 0:2a53a4c3238c 357 case PPPOE_TAG_SNAME:
lorcansmith 0:2a53a4c3238c 358 break; /* ignored */
lorcansmith 0:2a53a4c3238c 359 case PPPOE_TAG_ACNAME:
lorcansmith 0:2a53a4c3238c 360 break; /* ignored */
lorcansmith 0:2a53a4c3238c 361 case PPPOE_TAG_HUNIQUE:
lorcansmith 0:2a53a4c3238c 362 if (sc != NULL) {
lorcansmith 0:2a53a4c3238c 363 break;
lorcansmith 0:2a53a4c3238c 364 }
lorcansmith 0:2a53a4c3238c 365 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 366 hunique = (u8_t*)pb->payload + off + sizeof(pt);
lorcansmith 0:2a53a4c3238c 367 hunique_len = len;
lorcansmith 0:2a53a4c3238c 368 #endif
lorcansmith 0:2a53a4c3238c 369 sc = pppoe_find_softc_by_hunique((u8_t*)pb->payload + off + sizeof(pt), len, netif);
lorcansmith 0:2a53a4c3238c 370 if (sc != NULL) {
lorcansmith 0:2a53a4c3238c 371 snprintf(devname, sizeof(devname), "%c%c%"U16_F, sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
lorcansmith 0:2a53a4c3238c 372 }
lorcansmith 0:2a53a4c3238c 373 break;
lorcansmith 0:2a53a4c3238c 374 case PPPOE_TAG_ACCOOKIE:
lorcansmith 0:2a53a4c3238c 375 if (ac_cookie == NULL) {
lorcansmith 0:2a53a4c3238c 376 ac_cookie = (u8_t*)pb->payload + off + sizeof(pt);
lorcansmith 0:2a53a4c3238c 377 ac_cookie_len = len;
lorcansmith 0:2a53a4c3238c 378 }
lorcansmith 0:2a53a4c3238c 379 break;
lorcansmith 0:2a53a4c3238c 380 case PPPOE_TAG_SNAME_ERR:
lorcansmith 0:2a53a4c3238c 381 err_msg = "SERVICE NAME ERROR";
lorcansmith 0:2a53a4c3238c 382 errortag = 1;
lorcansmith 0:2a53a4c3238c 383 break;
lorcansmith 0:2a53a4c3238c 384 case PPPOE_TAG_ACSYS_ERR:
lorcansmith 0:2a53a4c3238c 385 err_msg = "AC SYSTEM ERROR";
lorcansmith 0:2a53a4c3238c 386 errortag = 1;
lorcansmith 0:2a53a4c3238c 387 break;
lorcansmith 0:2a53a4c3238c 388 case PPPOE_TAG_GENERIC_ERR:
lorcansmith 0:2a53a4c3238c 389 err_msg = "GENERIC ERROR";
lorcansmith 0:2a53a4c3238c 390 errortag = 1;
lorcansmith 0:2a53a4c3238c 391 break;
lorcansmith 0:2a53a4c3238c 392 }
lorcansmith 0:2a53a4c3238c 393 if (err_msg) {
lorcansmith 0:2a53a4c3238c 394 if (errortag && len) {
lorcansmith 0:2a53a4c3238c 395 u16_t error_len = LWIP_MIN(len, sizeof(pppoe_error_tmp)-1);
lorcansmith 0:2a53a4c3238c 396 strncpy(pppoe_error_tmp, (char*)pb->payload + off + sizeof(pt), error_len);
lorcansmith 0:2a53a4c3238c 397 pppoe_error_tmp[error_len-1] = '\0';
lorcansmith 0:2a53a4c3238c 398 printf("%s: %s: %s\n", devname, err_msg, pppoe_error_tmp);
lorcansmith 0:2a53a4c3238c 399 } else {
lorcansmith 0:2a53a4c3238c 400 printf("%s: %s\n", devname, err_msg);
lorcansmith 0:2a53a4c3238c 401 }
lorcansmith 0:2a53a4c3238c 402 if (errortag) {
lorcansmith 0:2a53a4c3238c 403 goto done;
lorcansmith 0:2a53a4c3238c 404 }
lorcansmith 0:2a53a4c3238c 405 }
lorcansmith 0:2a53a4c3238c 406 off += sizeof(pt) + len;
lorcansmith 0:2a53a4c3238c 407 }
lorcansmith 0:2a53a4c3238c 408
lorcansmith 0:2a53a4c3238c 409 breakbreak:;
lorcansmith 0:2a53a4c3238c 410 switch (ph->code) {
lorcansmith 0:2a53a4c3238c 411 case PPPOE_CODE_PADI:
lorcansmith 0:2a53a4c3238c 412 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 413 /*
lorcansmith 0:2a53a4c3238c 414 * got service name, concentrator name, and/or host unique.
lorcansmith 0:2a53a4c3238c 415 * ignore if we have no interfaces with IFF_PASSIVE|IFF_UP.
lorcansmith 0:2a53a4c3238c 416 */
lorcansmith 0:2a53a4c3238c 417 if (LIST_EMPTY(&pppoe_softc_list)) {
lorcansmith 0:2a53a4c3238c 418 goto done;
lorcansmith 0:2a53a4c3238c 419 }
lorcansmith 0:2a53a4c3238c 420 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
lorcansmith 0:2a53a4c3238c 421 if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) {
lorcansmith 0:2a53a4c3238c 422 continue;
lorcansmith 0:2a53a4c3238c 423 }
lorcansmith 0:2a53a4c3238c 424 if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
lorcansmith 0:2a53a4c3238c 425 continue;
lorcansmith 0:2a53a4c3238c 426 }
lorcansmith 0:2a53a4c3238c 427 if (sc->sc_state == PPPOE_STATE_INITIAL) {
lorcansmith 0:2a53a4c3238c 428 break;
lorcansmith 0:2a53a4c3238c 429 }
lorcansmith 0:2a53a4c3238c 430 }
lorcansmith 0:2a53a4c3238c 431 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 432 /* printf("pppoe: free passive interface is not found\n"); */
lorcansmith 0:2a53a4c3238c 433 goto done;
lorcansmith 0:2a53a4c3238c 434 }
lorcansmith 0:2a53a4c3238c 435 if (hunique) {
lorcansmith 0:2a53a4c3238c 436 if (sc->sc_hunique) {
lorcansmith 0:2a53a4c3238c 437 mem_free(sc->sc_hunique);
lorcansmith 0:2a53a4c3238c 438 }
lorcansmith 0:2a53a4c3238c 439 sc->sc_hunique = mem_malloc(hunique_len);
lorcansmith 0:2a53a4c3238c 440 if (sc->sc_hunique == NULL) {
lorcansmith 0:2a53a4c3238c 441 goto done;
lorcansmith 0:2a53a4c3238c 442 }
lorcansmith 0:2a53a4c3238c 443 sc->sc_hunique_len = hunique_len;
lorcansmith 0:2a53a4c3238c 444 MEMCPY(sc->sc_hunique, hunique, hunique_len);
lorcansmith 0:2a53a4c3238c 445 }
lorcansmith 0:2a53a4c3238c 446 MEMCPY(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest);
lorcansmith 0:2a53a4c3238c 447 sc->sc_state = PPPOE_STATE_PADO_SENT;
lorcansmith 0:2a53a4c3238c 448 pppoe_send_pado(sc);
lorcansmith 0:2a53a4c3238c 449 break;
lorcansmith 0:2a53a4c3238c 450 #endif /* PPPOE_SERVER */
lorcansmith 0:2a53a4c3238c 451 case PPPOE_CODE_PADR:
lorcansmith 0:2a53a4c3238c 452 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 453 /*
lorcansmith 0:2a53a4c3238c 454 * get sc from ac_cookie if IFF_PASSIVE
lorcansmith 0:2a53a4c3238c 455 */
lorcansmith 0:2a53a4c3238c 456 if (ac_cookie == NULL) {
lorcansmith 0:2a53a4c3238c 457 /* be quiet if there is not a single pppoe instance */
lorcansmith 0:2a53a4c3238c 458 printf("pppoe: received PADR but not includes ac_cookie\n");
lorcansmith 0:2a53a4c3238c 459 goto done;
lorcansmith 0:2a53a4c3238c 460 }
lorcansmith 0:2a53a4c3238c 461 sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif);
lorcansmith 0:2a53a4c3238c 462 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 463 /* be quiet if there is not a single pppoe instance */
lorcansmith 0:2a53a4c3238c 464 if (!LIST_EMPTY(&pppoe_softc_list)) {
lorcansmith 0:2a53a4c3238c 465 printf("pppoe: received PADR but could not find request for it\n");
lorcansmith 0:2a53a4c3238c 466 }
lorcansmith 0:2a53a4c3238c 467 goto done;
lorcansmith 0:2a53a4c3238c 468 }
lorcansmith 0:2a53a4c3238c 469 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
lorcansmith 0:2a53a4c3238c 470 printf("%c%c%"U16_F": received unexpected PADR\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
lorcansmith 0:2a53a4c3238c 471 goto done;
lorcansmith 0:2a53a4c3238c 472 }
lorcansmith 0:2a53a4c3238c 473 if (hunique) {
lorcansmith 0:2a53a4c3238c 474 if (sc->sc_hunique) {
lorcansmith 0:2a53a4c3238c 475 mem_free(sc->sc_hunique);
lorcansmith 0:2a53a4c3238c 476 }
lorcansmith 0:2a53a4c3238c 477 sc->sc_hunique = mem_malloc(hunique_len);
lorcansmith 0:2a53a4c3238c 478 if (sc->sc_hunique == NULL) {
lorcansmith 0:2a53a4c3238c 479 goto done;
lorcansmith 0:2a53a4c3238c 480 }
lorcansmith 0:2a53a4c3238c 481 sc->sc_hunique_len = hunique_len;
lorcansmith 0:2a53a4c3238c 482 MEMCPY(sc->sc_hunique, hunique, hunique_len);
lorcansmith 0:2a53a4c3238c 483 }
lorcansmith 0:2a53a4c3238c 484 pppoe_send_pads(sc);
lorcansmith 0:2a53a4c3238c 485 sc->sc_state = PPPOE_STATE_SESSION;
lorcansmith 0:2a53a4c3238c 486 pppoe_linkstatus_up(sc); /* notify upper layers */
lorcansmith 0:2a53a4c3238c 487 break;
lorcansmith 0:2a53a4c3238c 488 #else
lorcansmith 0:2a53a4c3238c 489 /* ignore, we are no access concentrator */
lorcansmith 0:2a53a4c3238c 490 goto done;
lorcansmith 0:2a53a4c3238c 491 #endif /* PPPOE_SERVER */
lorcansmith 0:2a53a4c3238c 492 case PPPOE_CODE_PADO:
lorcansmith 0:2a53a4c3238c 493 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 494 /* be quiet if there is not a single pppoe instance */
lorcansmith 0:2a53a4c3238c 495 if (pppoe_softc_list != NULL) {
lorcansmith 0:2a53a4c3238c 496 printf("pppoe: received PADO but could not find request for it\n");
lorcansmith 0:2a53a4c3238c 497 }
lorcansmith 0:2a53a4c3238c 498 goto done;
lorcansmith 0:2a53a4c3238c 499 }
lorcansmith 0:2a53a4c3238c 500 if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
lorcansmith 0:2a53a4c3238c 501 printf("%c%c%"U16_F": received unexpected PADO\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
lorcansmith 0:2a53a4c3238c 502 goto done;
lorcansmith 0:2a53a4c3238c 503 }
lorcansmith 0:2a53a4c3238c 504 if (ac_cookie) {
lorcansmith 0:2a53a4c3238c 505 sc->sc_ac_cookie_len = ac_cookie_len;
lorcansmith 0:2a53a4c3238c 506 MEMCPY(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
lorcansmith 0:2a53a4c3238c 507 }
lorcansmith 0:2a53a4c3238c 508 MEMCPY(&sc->sc_dest, ethhdr->src.addr, sizeof(sc->sc_dest.addr));
lorcansmith 0:2a53a4c3238c 509 sys_untimeout(pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 510 sc->sc_padr_retried = 0;
lorcansmith 0:2a53a4c3238c 511 sc->sc_state = PPPOE_STATE_PADR_SENT;
lorcansmith 0:2a53a4c3238c 512 if ((err = pppoe_send_padr(sc)) != 0) {
lorcansmith 0:2a53a4c3238c 513 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
lorcansmith 0:2a53a4c3238c 514 }
lorcansmith 0:2a53a4c3238c 515 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 516 break;
lorcansmith 0:2a53a4c3238c 517 case PPPOE_CODE_PADS:
lorcansmith 0:2a53a4c3238c 518 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 519 goto done;
lorcansmith 0:2a53a4c3238c 520 }
lorcansmith 0:2a53a4c3238c 521 sc->sc_session = session;
lorcansmith 0:2a53a4c3238c 522 sys_untimeout(pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 523 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x connected\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, session));
lorcansmith 0:2a53a4c3238c 524 sc->sc_state = PPPOE_STATE_SESSION;
lorcansmith 0:2a53a4c3238c 525 pppoe_linkstatus_up(sc); /* notify upper layers */
lorcansmith 0:2a53a4c3238c 526 break;
lorcansmith 0:2a53a4c3238c 527 case PPPOE_CODE_PADT:
lorcansmith 0:2a53a4c3238c 528 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 529 goto done;
lorcansmith 0:2a53a4c3238c 530 }
lorcansmith 0:2a53a4c3238c 531 pppoe_clear_softc(sc, "received PADT");
lorcansmith 0:2a53a4c3238c 532 break;
lorcansmith 0:2a53a4c3238c 533 default:
lorcansmith 0:2a53a4c3238c 534 if(sc) {
lorcansmith 0:2a53a4c3238c 535 printf("%c%c%"U16_F": unknown code (0x%"X16_F") session = 0x%"X16_F"\n",
lorcansmith 0:2a53a4c3238c 536 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
lorcansmith 0:2a53a4c3238c 537 (u16_t)ph->code, session);
lorcansmith 0:2a53a4c3238c 538 } else {
lorcansmith 0:2a53a4c3238c 539 printf("pppoe: unknown code (0x%"X16_F") session = 0x%"X16_F"\n", (u16_t)ph->code, session);
lorcansmith 0:2a53a4c3238c 540 }
lorcansmith 0:2a53a4c3238c 541 break;
lorcansmith 0:2a53a4c3238c 542 }
lorcansmith 0:2a53a4c3238c 543
lorcansmith 0:2a53a4c3238c 544 done:
lorcansmith 0:2a53a4c3238c 545 pbuf_free(pb);
lorcansmith 0:2a53a4c3238c 546 return;
lorcansmith 0:2a53a4c3238c 547 }
lorcansmith 0:2a53a4c3238c 548
lorcansmith 0:2a53a4c3238c 549 void
lorcansmith 0:2a53a4c3238c 550 pppoe_disc_input(struct netif *netif, struct pbuf *p)
lorcansmith 0:2a53a4c3238c 551 {
lorcansmith 0:2a53a4c3238c 552 /* avoid error messages if there is not a single pppoe instance */
lorcansmith 0:2a53a4c3238c 553 if (pppoe_softc_list != NULL) {
lorcansmith 0:2a53a4c3238c 554 pppoe_dispatch_disc_pkt(netif, p);
lorcansmith 0:2a53a4c3238c 555 } else {
lorcansmith 0:2a53a4c3238c 556 pbuf_free(p);
lorcansmith 0:2a53a4c3238c 557 }
lorcansmith 0:2a53a4c3238c 558 }
lorcansmith 0:2a53a4c3238c 559
lorcansmith 0:2a53a4c3238c 560 void
lorcansmith 0:2a53a4c3238c 561 pppoe_data_input(struct netif *netif, struct pbuf *pb)
lorcansmith 0:2a53a4c3238c 562 {
lorcansmith 0:2a53a4c3238c 563 u16_t session, plen;
lorcansmith 0:2a53a4c3238c 564 struct pppoe_softc *sc;
lorcansmith 0:2a53a4c3238c 565 struct pppoehdr *ph;
lorcansmith 0:2a53a4c3238c 566 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS
lorcansmith 0:2a53a4c3238c 567 u8_t shost[ETHER_ADDR_LEN];
lorcansmith 0:2a53a4c3238c 568 #endif
lorcansmith 0:2a53a4c3238c 569
lorcansmith 0:2a53a4c3238c 570 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS
lorcansmith 0:2a53a4c3238c 571 MEMCPY(shost, ((struct eth_hdr *)pb->payload)->src.addr, sizeof(shost));
lorcansmith 0:2a53a4c3238c 572 #endif
lorcansmith 0:2a53a4c3238c 573 if (pbuf_header(pb, -(int)sizeof(struct eth_hdr)) != 0) {
lorcansmith 0:2a53a4c3238c 574 /* bail out */
lorcansmith 0:2a53a4c3238c 575 PPPDEBUG(LOG_ERR, ("pppoe_data_input: pbuf_header failed\n"));
lorcansmith 0:2a53a4c3238c 576 LINK_STATS_INC(link.lenerr);
lorcansmith 0:2a53a4c3238c 577 goto drop;
lorcansmith 0:2a53a4c3238c 578 }
lorcansmith 0:2a53a4c3238c 579
lorcansmith 0:2a53a4c3238c 580 pb = pppSingleBuf (pb);
lorcansmith 0:2a53a4c3238c 581
lorcansmith 0:2a53a4c3238c 582 if (pb->len <= PPPOE_HEADERLEN) {
lorcansmith 0:2a53a4c3238c 583 printf("pppoe (data): dropping too short packet: %d bytes\n", pb->len);
lorcansmith 0:2a53a4c3238c 584 goto drop;
lorcansmith 0:2a53a4c3238c 585 }
lorcansmith 0:2a53a4c3238c 586
lorcansmith 0:2a53a4c3238c 587 if (pb->len < sizeof(*ph)) {
lorcansmith 0:2a53a4c3238c 588 printf("pppoe_data_input: could not get PPPoE header\n");
lorcansmith 0:2a53a4c3238c 589 goto drop;
lorcansmith 0:2a53a4c3238c 590 }
lorcansmith 0:2a53a4c3238c 591 ph = (struct pppoehdr *)pb->payload;
lorcansmith 0:2a53a4c3238c 592
lorcansmith 0:2a53a4c3238c 593 if (ph->vertype != PPPOE_VERTYPE) {
lorcansmith 0:2a53a4c3238c 594 printf("pppoe (data): unknown version/type packet: 0x%x\n", ph->vertype);
lorcansmith 0:2a53a4c3238c 595 goto drop;
lorcansmith 0:2a53a4c3238c 596 }
lorcansmith 0:2a53a4c3238c 597 if (ph->code != 0) {
lorcansmith 0:2a53a4c3238c 598 goto drop;
lorcansmith 0:2a53a4c3238c 599 }
lorcansmith 0:2a53a4c3238c 600
lorcansmith 0:2a53a4c3238c 601 session = ntohs(ph->session);
lorcansmith 0:2a53a4c3238c 602 sc = pppoe_find_softc_by_session(session, netif);
lorcansmith 0:2a53a4c3238c 603 if (sc == NULL) {
lorcansmith 0:2a53a4c3238c 604 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS
lorcansmith 0:2a53a4c3238c 605 printf("pppoe: input for unknown session 0x%x, sending PADT\n", session);
lorcansmith 0:2a53a4c3238c 606 pppoe_send_padt(netif, session, shost);
lorcansmith 0:2a53a4c3238c 607 #endif
lorcansmith 0:2a53a4c3238c 608 goto drop;
lorcansmith 0:2a53a4c3238c 609 }
lorcansmith 0:2a53a4c3238c 610
lorcansmith 0:2a53a4c3238c 611 plen = ntohs(ph->plen);
lorcansmith 0:2a53a4c3238c 612
lorcansmith 0:2a53a4c3238c 613 if (pbuf_header(pb, -(int)(PPPOE_HEADERLEN)) != 0) {
lorcansmith 0:2a53a4c3238c 614 /* bail out */
lorcansmith 0:2a53a4c3238c 615 PPPDEBUG(LOG_ERR, ("pppoe_data_input: pbuf_header PPPOE_HEADERLEN failed\n"));
lorcansmith 0:2a53a4c3238c 616 LINK_STATS_INC(link.lenerr);
lorcansmith 0:2a53a4c3238c 617 goto drop;
lorcansmith 0:2a53a4c3238c 618 }
lorcansmith 0:2a53a4c3238c 619
lorcansmith 0:2a53a4c3238c 620 PPPDEBUG(LOG_DEBUG, ("pppoe_data_input: %c%c%"U16_F": pkthdr.len=%d, pppoe.len=%d\n",
lorcansmith 0:2a53a4c3238c 621 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
lorcansmith 0:2a53a4c3238c 622 pb->len, plen));
lorcansmith 0:2a53a4c3238c 623
lorcansmith 0:2a53a4c3238c 624 if (pb->len < plen) {
lorcansmith 0:2a53a4c3238c 625 goto drop;
lorcansmith 0:2a53a4c3238c 626 }
lorcansmith 0:2a53a4c3238c 627
lorcansmith 0:2a53a4c3238c 628 pppInProcOverEthernet(sc->sc_pd, pb);
lorcansmith 0:2a53a4c3238c 629
lorcansmith 0:2a53a4c3238c 630 return;
lorcansmith 0:2a53a4c3238c 631
lorcansmith 0:2a53a4c3238c 632 drop:
lorcansmith 0:2a53a4c3238c 633 pbuf_free(pb);
lorcansmith 0:2a53a4c3238c 634 }
lorcansmith 0:2a53a4c3238c 635
lorcansmith 0:2a53a4c3238c 636 static err_t
lorcansmith 0:2a53a4c3238c 637 pppoe_output(struct pppoe_softc *sc, struct pbuf *pb)
lorcansmith 0:2a53a4c3238c 638 {
lorcansmith 0:2a53a4c3238c 639 struct eth_hdr *ethhdr;
lorcansmith 0:2a53a4c3238c 640 u16_t etype;
lorcansmith 0:2a53a4c3238c 641 err_t res;
lorcansmith 0:2a53a4c3238c 642
lorcansmith 0:2a53a4c3238c 643 if (!sc->sc_ethif) {
lorcansmith 0:2a53a4c3238c 644 pbuf_free(pb);
lorcansmith 0:2a53a4c3238c 645 return ERR_IF;
lorcansmith 0:2a53a4c3238c 646 }
lorcansmith 0:2a53a4c3238c 647
lorcansmith 0:2a53a4c3238c 648 ethhdr = (struct eth_hdr *)pb->payload;
lorcansmith 0:2a53a4c3238c 649 etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC;
lorcansmith 0:2a53a4c3238c 650 ethhdr->type = htons(etype);
lorcansmith 0:2a53a4c3238c 651 MEMCPY(ethhdr->dest.addr, sc->sc_dest.addr, sizeof(ethhdr->dest.addr));
lorcansmith 0:2a53a4c3238c 652 MEMCPY(ethhdr->src.addr, ((struct eth_addr *)sc->sc_ethif->hwaddr)->addr, sizeof(ethhdr->src.addr));
lorcansmith 0:2a53a4c3238c 653
lorcansmith 0:2a53a4c3238c 654 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F" (%x) state=%d, session=0x%x output -> %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F", len=%d\n",
lorcansmith 0:2a53a4c3238c 655 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, etype,
lorcansmith 0:2a53a4c3238c 656 sc->sc_state, sc->sc_session,
lorcansmith 0:2a53a4c3238c 657 sc->sc_dest.addr[0], sc->sc_dest.addr[1], sc->sc_dest.addr[2], sc->sc_dest.addr[3], sc->sc_dest.addr[4], sc->sc_dest.addr[5],
lorcansmith 0:2a53a4c3238c 658 pb->tot_len));
lorcansmith 0:2a53a4c3238c 659
lorcansmith 0:2a53a4c3238c 660 res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb);
lorcansmith 0:2a53a4c3238c 661
lorcansmith 0:2a53a4c3238c 662 pbuf_free(pb);
lorcansmith 0:2a53a4c3238c 663
lorcansmith 0:2a53a4c3238c 664 return res;
lorcansmith 0:2a53a4c3238c 665 }
lorcansmith 0:2a53a4c3238c 666
lorcansmith 0:2a53a4c3238c 667 static err_t
lorcansmith 0:2a53a4c3238c 668 pppoe_send_padi(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 669 {
lorcansmith 0:2a53a4c3238c 670 struct pbuf *pb;
lorcansmith 0:2a53a4c3238c 671 u8_t *p;
lorcansmith 0:2a53a4c3238c 672 int len;
lorcansmith 0:2a53a4c3238c 673 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 674 int l1 = 0, l2 = 0; /* XXX: gcc */
lorcansmith 0:2a53a4c3238c 675 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 676
lorcansmith 0:2a53a4c3238c 677 if (sc->sc_state >PPPOE_STATE_PADI_SENT) {
lorcansmith 0:2a53a4c3238c 678 PPPDEBUG(LOG_ERR, ("ERROR: pppoe_send_padi in state %d", sc->sc_state));
lorcansmith 0:2a53a4c3238c 679 }
lorcansmith 0:2a53a4c3238c 680
lorcansmith 0:2a53a4c3238c 681 /* calculate length of frame (excluding ethernet header + pppoe header) */
lorcansmith 0:2a53a4c3238c 682 len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */
lorcansmith 0:2a53a4c3238c 683 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 684 if (sc->sc_service_name != NULL) {
lorcansmith 0:2a53a4c3238c 685 l1 = (int)strlen(sc->sc_service_name);
lorcansmith 0:2a53a4c3238c 686 len += l1;
lorcansmith 0:2a53a4c3238c 687 }
lorcansmith 0:2a53a4c3238c 688 if (sc->sc_concentrator_name != NULL) {
lorcansmith 0:2a53a4c3238c 689 l2 = (int)strlen(sc->sc_concentrator_name);
lorcansmith 0:2a53a4c3238c 690 len += 2 + 2 + l2;
lorcansmith 0:2a53a4c3238c 691 }
lorcansmith 0:2a53a4c3238c 692 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 693 LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
lorcansmith 0:2a53a4c3238c 694 sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
lorcansmith 0:2a53a4c3238c 695
lorcansmith 0:2a53a4c3238c 696 /* allocate a buffer */
lorcansmith 0:2a53a4c3238c 697 pb = pbuf_alloc(PBUF_LINK, (u16_t)(sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len), PBUF_RAM);
lorcansmith 0:2a53a4c3238c 698 if (!pb) {
lorcansmith 0:2a53a4c3238c 699 return ERR_MEM;
lorcansmith 0:2a53a4c3238c 700 }
lorcansmith 0:2a53a4c3238c 701 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
lorcansmith 0:2a53a4c3238c 702
lorcansmith 0:2a53a4c3238c 703 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
lorcansmith 0:2a53a4c3238c 704 /* fill in pkt */
lorcansmith 0:2a53a4c3238c 705 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADI, 0, (u16_t)len);
lorcansmith 0:2a53a4c3238c 706 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
lorcansmith 0:2a53a4c3238c 707 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 708 if (sc->sc_service_name != NULL) {
lorcansmith 0:2a53a4c3238c 709 PPPOE_ADD_16(p, l1);
lorcansmith 0:2a53a4c3238c 710 MEMCPY(p, sc->sc_service_name, l1);
lorcansmith 0:2a53a4c3238c 711 p += l1;
lorcansmith 0:2a53a4c3238c 712 } else
lorcansmith 0:2a53a4c3238c 713 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 714 {
lorcansmith 0:2a53a4c3238c 715 PPPOE_ADD_16(p, 0);
lorcansmith 0:2a53a4c3238c 716 }
lorcansmith 0:2a53a4c3238c 717 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 718 if (sc->sc_concentrator_name != NULL) {
lorcansmith 0:2a53a4c3238c 719 PPPOE_ADD_16(p, PPPOE_TAG_ACNAME);
lorcansmith 0:2a53a4c3238c 720 PPPOE_ADD_16(p, l2);
lorcansmith 0:2a53a4c3238c 721 MEMCPY(p, sc->sc_concentrator_name, l2);
lorcansmith 0:2a53a4c3238c 722 p += l2;
lorcansmith 0:2a53a4c3238c 723 }
lorcansmith 0:2a53a4c3238c 724 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 725 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
lorcansmith 0:2a53a4c3238c 726 PPPOE_ADD_16(p, sizeof(sc));
lorcansmith 0:2a53a4c3238c 727 MEMCPY(p, &sc, sizeof sc);
lorcansmith 0:2a53a4c3238c 728
lorcansmith 0:2a53a4c3238c 729 /* send pkt */
lorcansmith 0:2a53a4c3238c 730 return pppoe_output(sc, pb);
lorcansmith 0:2a53a4c3238c 731 }
lorcansmith 0:2a53a4c3238c 732
lorcansmith 0:2a53a4c3238c 733 static void
lorcansmith 0:2a53a4c3238c 734 pppoe_timeout(void *arg)
lorcansmith 0:2a53a4c3238c 735 {
lorcansmith 0:2a53a4c3238c 736 int retry_wait, err;
lorcansmith 0:2a53a4c3238c 737 struct pppoe_softc *sc = (struct pppoe_softc*)arg;
lorcansmith 0:2a53a4c3238c 738
lorcansmith 0:2a53a4c3238c 739 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": timeout\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
lorcansmith 0:2a53a4c3238c 740
lorcansmith 0:2a53a4c3238c 741 switch (sc->sc_state) {
lorcansmith 0:2a53a4c3238c 742 case PPPOE_STATE_PADI_SENT:
lorcansmith 0:2a53a4c3238c 743 /*
lorcansmith 0:2a53a4c3238c 744 * We have two basic ways of retrying:
lorcansmith 0:2a53a4c3238c 745 * - Quick retry mode: try a few times in short sequence
lorcansmith 0:2a53a4c3238c 746 * - Slow retry mode: we already had a connection successfully
lorcansmith 0:2a53a4c3238c 747 * established and will try infinitely (without user
lorcansmith 0:2a53a4c3238c 748 * intervention)
lorcansmith 0:2a53a4c3238c 749 * We only enter slow retry mode if IFF_LINK1 (aka autodial)
lorcansmith 0:2a53a4c3238c 750 * is not set.
lorcansmith 0:2a53a4c3238c 751 */
lorcansmith 0:2a53a4c3238c 752
lorcansmith 0:2a53a4c3238c 753 /* initialize for quick retry mode */
lorcansmith 0:2a53a4c3238c 754 retry_wait = PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried);
lorcansmith 0:2a53a4c3238c 755
lorcansmith 0:2a53a4c3238c 756 sc->sc_padi_retried++;
lorcansmith 0:2a53a4c3238c 757 if (sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) {
lorcansmith 0:2a53a4c3238c 758 #if 0
lorcansmith 0:2a53a4c3238c 759 if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) {
lorcansmith 0:2a53a4c3238c 760 /* slow retry mode */
lorcansmith 0:2a53a4c3238c 761 retry_wait = PPPOE_SLOW_RETRY;
lorcansmith 0:2a53a4c3238c 762 } else
lorcansmith 0:2a53a4c3238c 763 #endif
lorcansmith 0:2a53a4c3238c 764 {
lorcansmith 0:2a53a4c3238c 765 pppoe_abort_connect(sc);
lorcansmith 0:2a53a4c3238c 766 return;
lorcansmith 0:2a53a4c3238c 767 }
lorcansmith 0:2a53a4c3238c 768 }
lorcansmith 0:2a53a4c3238c 769 if ((err = pppoe_send_padi(sc)) != 0) {
lorcansmith 0:2a53a4c3238c 770 sc->sc_padi_retried--;
lorcansmith 0:2a53a4c3238c 771 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to transmit PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
lorcansmith 0:2a53a4c3238c 772 }
lorcansmith 0:2a53a4c3238c 773 sys_timeout(retry_wait, pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 774 break;
lorcansmith 0:2a53a4c3238c 775
lorcansmith 0:2a53a4c3238c 776 case PPPOE_STATE_PADR_SENT:
lorcansmith 0:2a53a4c3238c 777 sc->sc_padr_retried++;
lorcansmith 0:2a53a4c3238c 778 if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
lorcansmith 0:2a53a4c3238c 779 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
lorcansmith 0:2a53a4c3238c 780 sc->sc_state = PPPOE_STATE_PADI_SENT;
lorcansmith 0:2a53a4c3238c 781 sc->sc_padr_retried = 0;
lorcansmith 0:2a53a4c3238c 782 if ((err = pppoe_send_padi(sc)) != 0) {
lorcansmith 0:2a53a4c3238c 783 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
lorcansmith 0:2a53a4c3238c 784 }
lorcansmith 0:2a53a4c3238c 785 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 786 return;
lorcansmith 0:2a53a4c3238c 787 }
lorcansmith 0:2a53a4c3238c 788 if ((err = pppoe_send_padr(sc)) != 0) {
lorcansmith 0:2a53a4c3238c 789 sc->sc_padr_retried--;
lorcansmith 0:2a53a4c3238c 790 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
lorcansmith 0:2a53a4c3238c 791 }
lorcansmith 0:2a53a4c3238c 792 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 793 break;
lorcansmith 0:2a53a4c3238c 794 case PPPOE_STATE_CLOSING:
lorcansmith 0:2a53a4c3238c 795 pppoe_do_disconnect(sc);
lorcansmith 0:2a53a4c3238c 796 break;
lorcansmith 0:2a53a4c3238c 797 default:
lorcansmith 0:2a53a4c3238c 798 return; /* all done, work in peace */
lorcansmith 0:2a53a4c3238c 799 }
lorcansmith 0:2a53a4c3238c 800 }
lorcansmith 0:2a53a4c3238c 801
lorcansmith 0:2a53a4c3238c 802 /* Start a connection (i.e. initiate discovery phase) */
lorcansmith 0:2a53a4c3238c 803 int
lorcansmith 0:2a53a4c3238c 804 pppoe_connect(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 805 {
lorcansmith 0:2a53a4c3238c 806 int err;
lorcansmith 0:2a53a4c3238c 807
lorcansmith 0:2a53a4c3238c 808 if (sc->sc_state != PPPOE_STATE_INITIAL) {
lorcansmith 0:2a53a4c3238c 809 return EBUSY;
lorcansmith 0:2a53a4c3238c 810 }
lorcansmith 0:2a53a4c3238c 811
lorcansmith 0:2a53a4c3238c 812 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 813 /* wait PADI if IFF_PASSIVE */
lorcansmith 0:2a53a4c3238c 814 if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
lorcansmith 0:2a53a4c3238c 815 return 0;
lorcansmith 0:2a53a4c3238c 816 }
lorcansmith 0:2a53a4c3238c 817 #endif
lorcansmith 0:2a53a4c3238c 818 /* save state, in case we fail to send PADI */
lorcansmith 0:2a53a4c3238c 819 sc->sc_state = PPPOE_STATE_PADI_SENT;
lorcansmith 0:2a53a4c3238c 820 sc->sc_padr_retried = 0;
lorcansmith 0:2a53a4c3238c 821 err = pppoe_send_padi(sc);
lorcansmith 0:2a53a4c3238c 822 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
lorcansmith 0:2a53a4c3238c 823 sys_timeout(PPPOE_DISC_TIMEOUT, pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 824 return err;
lorcansmith 0:2a53a4c3238c 825 }
lorcansmith 0:2a53a4c3238c 826
lorcansmith 0:2a53a4c3238c 827 /* disconnect */
lorcansmith 0:2a53a4c3238c 828 void
lorcansmith 0:2a53a4c3238c 829 pppoe_disconnect(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 830 {
lorcansmith 0:2a53a4c3238c 831 if (sc->sc_state < PPPOE_STATE_SESSION) {
lorcansmith 0:2a53a4c3238c 832 return;
lorcansmith 0:2a53a4c3238c 833 }
lorcansmith 0:2a53a4c3238c 834 /*
lorcansmith 0:2a53a4c3238c 835 * Do not call pppoe_disconnect here, the upper layer state
lorcansmith 0:2a53a4c3238c 836 * machine gets confused by this. We must return from this
lorcansmith 0:2a53a4c3238c 837 * function and defer disconnecting to the timeout handler.
lorcansmith 0:2a53a4c3238c 838 */
lorcansmith 0:2a53a4c3238c 839 sc->sc_state = PPPOE_STATE_CLOSING;
lorcansmith 0:2a53a4c3238c 840 sys_timeout(20, pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 841 }
lorcansmith 0:2a53a4c3238c 842
lorcansmith 0:2a53a4c3238c 843 static int
lorcansmith 0:2a53a4c3238c 844 pppoe_do_disconnect(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 845 {
lorcansmith 0:2a53a4c3238c 846 int err;
lorcansmith 0:2a53a4c3238c 847
lorcansmith 0:2a53a4c3238c 848 if (sc->sc_state < PPPOE_STATE_SESSION) {
lorcansmith 0:2a53a4c3238c 849 err = EBUSY;
lorcansmith 0:2a53a4c3238c 850 } else {
lorcansmith 0:2a53a4c3238c 851 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
lorcansmith 0:2a53a4c3238c 852 err = pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest);
lorcansmith 0:2a53a4c3238c 853 }
lorcansmith 0:2a53a4c3238c 854
lorcansmith 0:2a53a4c3238c 855 /* cleanup softc */
lorcansmith 0:2a53a4c3238c 856 sc->sc_state = PPPOE_STATE_INITIAL;
lorcansmith 0:2a53a4c3238c 857 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
lorcansmith 0:2a53a4c3238c 858 sc->sc_ac_cookie_len = 0;
lorcansmith 0:2a53a4c3238c 859 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 860 if (sc->sc_hunique) {
lorcansmith 0:2a53a4c3238c 861 mem_free(sc->sc_hunique);
lorcansmith 0:2a53a4c3238c 862 sc->sc_hunique = NULL;
lorcansmith 0:2a53a4c3238c 863 }
lorcansmith 0:2a53a4c3238c 864 sc->sc_hunique_len = 0;
lorcansmith 0:2a53a4c3238c 865 #endif
lorcansmith 0:2a53a4c3238c 866 sc->sc_session = 0;
lorcansmith 0:2a53a4c3238c 867
lorcansmith 0:2a53a4c3238c 868 sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
lorcansmith 0:2a53a4c3238c 869
lorcansmith 0:2a53a4c3238c 870 return err;
lorcansmith 0:2a53a4c3238c 871 }
lorcansmith 0:2a53a4c3238c 872
lorcansmith 0:2a53a4c3238c 873 /* Connection attempt aborted */
lorcansmith 0:2a53a4c3238c 874 static void
lorcansmith 0:2a53a4c3238c 875 pppoe_abort_connect(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 876 {
lorcansmith 0:2a53a4c3238c 877 printf("%c%c%"U16_F": could not establish connection\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
lorcansmith 0:2a53a4c3238c 878 sc->sc_state = PPPOE_STATE_CLOSING;
lorcansmith 0:2a53a4c3238c 879
lorcansmith 0:2a53a4c3238c 880 sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
lorcansmith 0:2a53a4c3238c 881
lorcansmith 0:2a53a4c3238c 882 /* clear connection state */
lorcansmith 0:2a53a4c3238c 883 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
lorcansmith 0:2a53a4c3238c 884 sc->sc_state = PPPOE_STATE_INITIAL;
lorcansmith 0:2a53a4c3238c 885 }
lorcansmith 0:2a53a4c3238c 886
lorcansmith 0:2a53a4c3238c 887 /* Send a PADR packet */
lorcansmith 0:2a53a4c3238c 888 static err_t
lorcansmith 0:2a53a4c3238c 889 pppoe_send_padr(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 890 {
lorcansmith 0:2a53a4c3238c 891 struct pbuf *pb;
lorcansmith 0:2a53a4c3238c 892 u8_t *p;
lorcansmith 0:2a53a4c3238c 893 size_t len;
lorcansmith 0:2a53a4c3238c 894 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 895 size_t l1 = 0; /* XXX: gcc */
lorcansmith 0:2a53a4c3238c 896 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 897
lorcansmith 0:2a53a4c3238c 898 if (sc->sc_state != PPPOE_STATE_PADR_SENT) {
lorcansmith 0:2a53a4c3238c 899 return ERR_CONN;
lorcansmith 0:2a53a4c3238c 900 }
lorcansmith 0:2a53a4c3238c 901
lorcansmith 0:2a53a4c3238c 902 len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */
lorcansmith 0:2a53a4c3238c 903 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 904 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
lorcansmith 0:2a53a4c3238c 905 l1 = strlen(sc->sc_service_name);
lorcansmith 0:2a53a4c3238c 906 len += l1;
lorcansmith 0:2a53a4c3238c 907 }
lorcansmith 0:2a53a4c3238c 908 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 909 if (sc->sc_ac_cookie_len > 0) {
lorcansmith 0:2a53a4c3238c 910 len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */
lorcansmith 0:2a53a4c3238c 911 }
lorcansmith 0:2a53a4c3238c 912 LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
lorcansmith 0:2a53a4c3238c 913 sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
lorcansmith 0:2a53a4c3238c 914 pb = pbuf_alloc(PBUF_LINK, (u16_t)(sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len), PBUF_RAM);
lorcansmith 0:2a53a4c3238c 915 if (!pb) {
lorcansmith 0:2a53a4c3238c 916 return ERR_MEM;
lorcansmith 0:2a53a4c3238c 917 }
lorcansmith 0:2a53a4c3238c 918 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
lorcansmith 0:2a53a4c3238c 919 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
lorcansmith 0:2a53a4c3238c 920 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len);
lorcansmith 0:2a53a4c3238c 921 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
lorcansmith 0:2a53a4c3238c 922 #ifdef PPPOE_TODO
lorcansmith 0:2a53a4c3238c 923 if (sc->sc_service_name != NULL) {
lorcansmith 0:2a53a4c3238c 924 PPPOE_ADD_16(p, l1);
lorcansmith 0:2a53a4c3238c 925 MEMCPY(p, sc->sc_service_name, l1);
lorcansmith 0:2a53a4c3238c 926 p += l1;
lorcansmith 0:2a53a4c3238c 927 } else
lorcansmith 0:2a53a4c3238c 928 #endif /* PPPOE_TODO */
lorcansmith 0:2a53a4c3238c 929 {
lorcansmith 0:2a53a4c3238c 930 PPPOE_ADD_16(p, 0);
lorcansmith 0:2a53a4c3238c 931 }
lorcansmith 0:2a53a4c3238c 932 if (sc->sc_ac_cookie_len > 0) {
lorcansmith 0:2a53a4c3238c 933 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
lorcansmith 0:2a53a4c3238c 934 PPPOE_ADD_16(p, sc->sc_ac_cookie_len);
lorcansmith 0:2a53a4c3238c 935 MEMCPY(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len);
lorcansmith 0:2a53a4c3238c 936 p += sc->sc_ac_cookie_len;
lorcansmith 0:2a53a4c3238c 937 }
lorcansmith 0:2a53a4c3238c 938 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
lorcansmith 0:2a53a4c3238c 939 PPPOE_ADD_16(p, sizeof(sc));
lorcansmith 0:2a53a4c3238c 940 MEMCPY(p, &sc, sizeof sc);
lorcansmith 0:2a53a4c3238c 941
lorcansmith 0:2a53a4c3238c 942 return pppoe_output(sc, pb);
lorcansmith 0:2a53a4c3238c 943 }
lorcansmith 0:2a53a4c3238c 944
lorcansmith 0:2a53a4c3238c 945 /* send a PADT packet */
lorcansmith 0:2a53a4c3238c 946 static err_t
lorcansmith 0:2a53a4c3238c 947 pppoe_send_padt(struct netif *outgoing_if, u_int session, const u8_t *dest)
lorcansmith 0:2a53a4c3238c 948 {
lorcansmith 0:2a53a4c3238c 949 struct pbuf *pb;
lorcansmith 0:2a53a4c3238c 950 struct eth_hdr *ethhdr;
lorcansmith 0:2a53a4c3238c 951 err_t res;
lorcansmith 0:2a53a4c3238c 952 u8_t *p;
lorcansmith 0:2a53a4c3238c 953
lorcansmith 0:2a53a4c3238c 954 pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN, PBUF_RAM);
lorcansmith 0:2a53a4c3238c 955 if (!pb) {
lorcansmith 0:2a53a4c3238c 956 return ERR_MEM;
lorcansmith 0:2a53a4c3238c 957 }
lorcansmith 0:2a53a4c3238c 958 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
lorcansmith 0:2a53a4c3238c 959
lorcansmith 0:2a53a4c3238c 960 ethhdr = (struct eth_hdr *)pb->payload;
lorcansmith 0:2a53a4c3238c 961 ethhdr->type = PP_HTONS(ETHTYPE_PPPOEDISC);
lorcansmith 0:2a53a4c3238c 962 MEMCPY(ethhdr->dest.addr, dest, sizeof(ethhdr->dest.addr));
lorcansmith 0:2a53a4c3238c 963 MEMCPY(ethhdr->src.addr, ((struct eth_addr *)outgoing_if->hwaddr)->addr, sizeof(ethhdr->src.addr));
lorcansmith 0:2a53a4c3238c 964
lorcansmith 0:2a53a4c3238c 965 p = (u8_t*)(ethhdr + 1);
lorcansmith 0:2a53a4c3238c 966 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADT, session, 0);
lorcansmith 0:2a53a4c3238c 967
lorcansmith 0:2a53a4c3238c 968 res = outgoing_if->linkoutput(outgoing_if, pb);
lorcansmith 0:2a53a4c3238c 969
lorcansmith 0:2a53a4c3238c 970 pbuf_free(pb);
lorcansmith 0:2a53a4c3238c 971
lorcansmith 0:2a53a4c3238c 972 return res;
lorcansmith 0:2a53a4c3238c 973 }
lorcansmith 0:2a53a4c3238c 974
lorcansmith 0:2a53a4c3238c 975 #ifdef PPPOE_SERVER
lorcansmith 0:2a53a4c3238c 976 static err_t
lorcansmith 0:2a53a4c3238c 977 pppoe_send_pado(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 978 {
lorcansmith 0:2a53a4c3238c 979 struct pbuf *pb;
lorcansmith 0:2a53a4c3238c 980 u8_t *p;
lorcansmith 0:2a53a4c3238c 981 size_t len;
lorcansmith 0:2a53a4c3238c 982
lorcansmith 0:2a53a4c3238c 983 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
lorcansmith 0:2a53a4c3238c 984 return ERR_CONN;
lorcansmith 0:2a53a4c3238c 985 }
lorcansmith 0:2a53a4c3238c 986
lorcansmith 0:2a53a4c3238c 987 /* calc length */
lorcansmith 0:2a53a4c3238c 988 len = 0;
lorcansmith 0:2a53a4c3238c 989 /* include ac_cookie */
lorcansmith 0:2a53a4c3238c 990 len += 2 + 2 + sizeof(sc);
lorcansmith 0:2a53a4c3238c 991 /* include hunique */
lorcansmith 0:2a53a4c3238c 992 len += 2 + 2 + sc->sc_hunique_len;
lorcansmith 0:2a53a4c3238c 993 pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
lorcansmith 0:2a53a4c3238c 994 if (!pb) {
lorcansmith 0:2a53a4c3238c 995 return ERR_MEM;
lorcansmith 0:2a53a4c3238c 996 }
lorcansmith 0:2a53a4c3238c 997 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
lorcansmith 0:2a53a4c3238c 998 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
lorcansmith 0:2a53a4c3238c 999 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len);
lorcansmith 0:2a53a4c3238c 1000 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
lorcansmith 0:2a53a4c3238c 1001 PPPOE_ADD_16(p, sizeof(sc));
lorcansmith 0:2a53a4c3238c 1002 MEMCPY(p, &sc, sizeof(sc));
lorcansmith 0:2a53a4c3238c 1003 p += sizeof(sc);
lorcansmith 0:2a53a4c3238c 1004 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
lorcansmith 0:2a53a4c3238c 1005 PPPOE_ADD_16(p, sc->sc_hunique_len);
lorcansmith 0:2a53a4c3238c 1006 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
lorcansmith 0:2a53a4c3238c 1007 return pppoe_output(sc, pb);
lorcansmith 0:2a53a4c3238c 1008 }
lorcansmith 0:2a53a4c3238c 1009
lorcansmith 0:2a53a4c3238c 1010 static err_t
lorcansmith 0:2a53a4c3238c 1011 pppoe_send_pads(struct pppoe_softc *sc)
lorcansmith 0:2a53a4c3238c 1012 {
lorcansmith 0:2a53a4c3238c 1013 struct pbuf *pb;
lorcansmith 0:2a53a4c3238c 1014 u8_t *p;
lorcansmith 0:2a53a4c3238c 1015 size_t len, l1 = 0; /* XXX: gcc */
lorcansmith 0:2a53a4c3238c 1016
lorcansmith 0:2a53a4c3238c 1017 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
lorcansmith 0:2a53a4c3238c 1018 return ERR_CONN;
lorcansmith 0:2a53a4c3238c 1019 }
lorcansmith 0:2a53a4c3238c 1020
lorcansmith 0:2a53a4c3238c 1021 sc->sc_session = mono_time.tv_sec % 0xff + 1;
lorcansmith 0:2a53a4c3238c 1022 /* calc length */
lorcansmith 0:2a53a4c3238c 1023 len = 0;
lorcansmith 0:2a53a4c3238c 1024 /* include hunique */
lorcansmith 0:2a53a4c3238c 1025 len += 2 + 2 + 2 + 2 + sc->sc_hunique_len; /* service name, host unique*/
lorcansmith 0:2a53a4c3238c 1026 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
lorcansmith 0:2a53a4c3238c 1027 l1 = strlen(sc->sc_service_name);
lorcansmith 0:2a53a4c3238c 1028 len += l1;
lorcansmith 0:2a53a4c3238c 1029 }
lorcansmith 0:2a53a4c3238c 1030 pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
lorcansmith 0:2a53a4c3238c 1031 if (!pb) {
lorcansmith 0:2a53a4c3238c 1032 return ERR_MEM;
lorcansmith 0:2a53a4c3238c 1033 }
lorcansmith 0:2a53a4c3238c 1034 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
lorcansmith 0:2a53a4c3238c 1035 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
lorcansmith 0:2a53a4c3238c 1036 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
lorcansmith 0:2a53a4c3238c 1037 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
lorcansmith 0:2a53a4c3238c 1038 if (sc->sc_service_name != NULL) {
lorcansmith 0:2a53a4c3238c 1039 PPPOE_ADD_16(p, l1);
lorcansmith 0:2a53a4c3238c 1040 MEMCPY(p, sc->sc_service_name, l1);
lorcansmith 0:2a53a4c3238c 1041 p += l1;
lorcansmith 0:2a53a4c3238c 1042 } else {
lorcansmith 0:2a53a4c3238c 1043 PPPOE_ADD_16(p, 0);
lorcansmith 0:2a53a4c3238c 1044 }
lorcansmith 0:2a53a4c3238c 1045 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
lorcansmith 0:2a53a4c3238c 1046 PPPOE_ADD_16(p, sc->sc_hunique_len);
lorcansmith 0:2a53a4c3238c 1047 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
lorcansmith 0:2a53a4c3238c 1048 return pppoe_output(sc, pb);
lorcansmith 0:2a53a4c3238c 1049 }
lorcansmith 0:2a53a4c3238c 1050 #endif
lorcansmith 0:2a53a4c3238c 1051
lorcansmith 0:2a53a4c3238c 1052 err_t
lorcansmith 0:2a53a4c3238c 1053 pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb)
lorcansmith 0:2a53a4c3238c 1054 {
lorcansmith 0:2a53a4c3238c 1055 u8_t *p;
lorcansmith 0:2a53a4c3238c 1056 size_t len;
lorcansmith 0:2a53a4c3238c 1057
lorcansmith 0:2a53a4c3238c 1058 /* are we ready to process data yet? */
lorcansmith 0:2a53a4c3238c 1059 if (sc->sc_state < PPPOE_STATE_SESSION) {
lorcansmith 0:2a53a4c3238c 1060 /*sppp_flush(&sc->sc_sppp.pp_if);*/
lorcansmith 0:2a53a4c3238c 1061 pbuf_free(pb);
lorcansmith 0:2a53a4c3238c 1062 return ERR_CONN;
lorcansmith 0:2a53a4c3238c 1063 }
lorcansmith 0:2a53a4c3238c 1064
lorcansmith 0:2a53a4c3238c 1065 len = pb->tot_len;
lorcansmith 0:2a53a4c3238c 1066
lorcansmith 0:2a53a4c3238c 1067 /* make room for Ethernet header - should not fail */
lorcansmith 0:2a53a4c3238c 1068 if (pbuf_header(pb, sizeof(struct eth_hdr) + PPPOE_HEADERLEN) != 0) {
lorcansmith 0:2a53a4c3238c 1069 /* bail out */
lorcansmith 0:2a53a4c3238c 1070 PPPDEBUG(LOG_ERR, ("pppoe: %c%c%"U16_F": pppoe_xmit: could not allocate room for header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
lorcansmith 0:2a53a4c3238c 1071 LINK_STATS_INC(link.lenerr);
lorcansmith 0:2a53a4c3238c 1072 pbuf_free(pb);
lorcansmith 0:2a53a4c3238c 1073 return ERR_BUF;
lorcansmith 0:2a53a4c3238c 1074 }
lorcansmith 0:2a53a4c3238c 1075
lorcansmith 0:2a53a4c3238c 1076 p = (u8_t*)pb->payload + sizeof(struct eth_hdr);
lorcansmith 0:2a53a4c3238c 1077 PPPOE_ADD_HEADER(p, 0, sc->sc_session, len);
lorcansmith 0:2a53a4c3238c 1078
lorcansmith 0:2a53a4c3238c 1079 return pppoe_output(sc, pb);
lorcansmith 0:2a53a4c3238c 1080 }
lorcansmith 0:2a53a4c3238c 1081
lorcansmith 0:2a53a4c3238c 1082 #if 0 /*def PFIL_HOOKS*/
lorcansmith 0:2a53a4c3238c 1083 static int
lorcansmith 0:2a53a4c3238c 1084 pppoe_ifattach_hook(void *arg, struct pbuf **mp, struct netif *ifp, int dir)
lorcansmith 0:2a53a4c3238c 1085 {
lorcansmith 0:2a53a4c3238c 1086 struct pppoe_softc *sc;
lorcansmith 0:2a53a4c3238c 1087 int s;
lorcansmith 0:2a53a4c3238c 1088
lorcansmith 0:2a53a4c3238c 1089 if (mp != (struct pbuf **)PFIL_IFNET_DETACH) {
lorcansmith 0:2a53a4c3238c 1090 return 0;
lorcansmith 0:2a53a4c3238c 1091 }
lorcansmith 0:2a53a4c3238c 1092
lorcansmith 0:2a53a4c3238c 1093 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
lorcansmith 0:2a53a4c3238c 1094 if (sc->sc_ethif != ifp) {
lorcansmith 0:2a53a4c3238c 1095 continue;
lorcansmith 0:2a53a4c3238c 1096 }
lorcansmith 0:2a53a4c3238c 1097 if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
lorcansmith 0:2a53a4c3238c 1098 sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
lorcansmith 0:2a53a4c3238c 1099 printf("%c%c%"U16_F": ethernet interface detached, going down\n",
lorcansmith 0:2a53a4c3238c 1100 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
lorcansmith 0:2a53a4c3238c 1101 }
lorcansmith 0:2a53a4c3238c 1102 sc->sc_ethif = NULL;
lorcansmith 0:2a53a4c3238c 1103 pppoe_clear_softc(sc, "ethernet interface detached");
lorcansmith 0:2a53a4c3238c 1104 }
lorcansmith 0:2a53a4c3238c 1105
lorcansmith 0:2a53a4c3238c 1106 return 0;
lorcansmith 0:2a53a4c3238c 1107 }
lorcansmith 0:2a53a4c3238c 1108 #endif
lorcansmith 0:2a53a4c3238c 1109
lorcansmith 0:2a53a4c3238c 1110 static void
lorcansmith 0:2a53a4c3238c 1111 pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
lorcansmith 0:2a53a4c3238c 1112 {
lorcansmith 0:2a53a4c3238c 1113 LWIP_UNUSED_ARG(message);
lorcansmith 0:2a53a4c3238c 1114
lorcansmith 0:2a53a4c3238c 1115 /* stop timer */
lorcansmith 0:2a53a4c3238c 1116 sys_untimeout(pppoe_timeout, sc);
lorcansmith 0:2a53a4c3238c 1117 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x terminated, %s\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_session, message));
lorcansmith 0:2a53a4c3238c 1118
lorcansmith 0:2a53a4c3238c 1119 /* fix our state */
lorcansmith 0:2a53a4c3238c 1120 sc->sc_state = PPPOE_STATE_INITIAL;
lorcansmith 0:2a53a4c3238c 1121
lorcansmith 0:2a53a4c3238c 1122 /* notify upper layers */
lorcansmith 0:2a53a4c3238c 1123 sc->sc_linkStatusCB(sc->sc_pd, 0);
lorcansmith 0:2a53a4c3238c 1124
lorcansmith 0:2a53a4c3238c 1125 /* clean up softc */
lorcansmith 0:2a53a4c3238c 1126 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
lorcansmith 0:2a53a4c3238c 1127 sc->sc_ac_cookie_len = 0;
lorcansmith 0:2a53a4c3238c 1128 sc->sc_session = 0;
lorcansmith 0:2a53a4c3238c 1129 }
lorcansmith 0:2a53a4c3238c 1130
lorcansmith 0:2a53a4c3238c 1131 #endif /* PPPOE_SUPPORT */
lorcansmith 0:2a53a4c3238c 1132