Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested

Dependencies:   mbed-rtos

Dependents:   IMU_ethernet

Fork of F7_Ethernet by Dieter Graef

Committer:
rctaduio
Date:
Thu Oct 06 16:55:16 2016 +0000
Revision:
2:e0a4035b5cd1
Parent:
0:d26c1b55cfca
Ethernet library for F7

Who changed what in which revision?

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