LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
All rights reserved. 
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
derived from this software without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
donatien
Date:
Fri May 25 08:56:35 2012 +0000
Revision:
2:1a87f74b8e3b
Parent:
0:8e01dca41002
Removed compilation of EMAC driver when using PPP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:8e01dca41002 1 /*****************************************************************************
donatien 0:8e01dca41002 2 * ppp_oe.h - PPP Over Ethernet implementation for lwIP.
donatien 0:8e01dca41002 3 *
donatien 0:8e01dca41002 4 * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc.
donatien 0:8e01dca41002 5 *
donatien 0:8e01dca41002 6 * The authors hereby grant permission to use, copy, modify, distribute,
donatien 0:8e01dca41002 7 * and license this software and its documentation for any purpose, provided
donatien 0:8e01dca41002 8 * that existing copyright notices are retained in all copies and that this
donatien 0:8e01dca41002 9 * notice and the following disclaimer are included verbatim in any
donatien 0:8e01dca41002 10 * distributions. No written agreement, license, or royalty fee is required
donatien 0:8e01dca41002 11 * for any of the authorized uses.
donatien 0:8e01dca41002 12 *
donatien 0:8e01dca41002 13 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
donatien 0:8e01dca41002 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
donatien 0:8e01dca41002 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
donatien 0:8e01dca41002 16 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
donatien 0:8e01dca41002 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
donatien 0:8e01dca41002 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
donatien 0:8e01dca41002 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
donatien 0:8e01dca41002 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
donatien 0:8e01dca41002 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
donatien 0:8e01dca41002 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
donatien 0:8e01dca41002 23 *
donatien 0:8e01dca41002 24 ******************************************************************************
donatien 0:8e01dca41002 25 * REVISION HISTORY
donatien 0:8e01dca41002 26 *
donatien 0:8e01dca41002 27 * 06-01-01 Marc Boucher <marc@mbsi.ca>
donatien 0:8e01dca41002 28 * Ported to lwIP.
donatien 0:8e01dca41002 29 *****************************************************************************/
donatien 0:8e01dca41002 30
donatien 0:8e01dca41002 31
donatien 0:8e01dca41002 32
donatien 0:8e01dca41002 33 /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */
donatien 0:8e01dca41002 34
donatien 0:8e01dca41002 35 /*-
donatien 0:8e01dca41002 36 * Copyright (c) 2002 The NetBSD Foundation, Inc.
donatien 0:8e01dca41002 37 * All rights reserved.
donatien 0:8e01dca41002 38 *
donatien 0:8e01dca41002 39 * This code is derived from software contributed to The NetBSD Foundation
donatien 0:8e01dca41002 40 * by Martin Husemann <martin@NetBSD.org>.
donatien 0:8e01dca41002 41 *
donatien 0:8e01dca41002 42 * Redistribution and use in source and binary forms, with or without
donatien 0:8e01dca41002 43 * modification, are permitted provided that the following conditions
donatien 0:8e01dca41002 44 * are met:
donatien 0:8e01dca41002 45 * 1. Redistributions of source code must retain the above copyright
donatien 0:8e01dca41002 46 * notice, this list of conditions and the following disclaimer.
donatien 0:8e01dca41002 47 * 2. Redistributions in binary form must reproduce the above copyright
donatien 0:8e01dca41002 48 * notice, this list of conditions and the following disclaimer in the
donatien 0:8e01dca41002 49 * documentation and/or other materials provided with the distribution.
donatien 0:8e01dca41002 50 * 3. All advertising materials mentioning features or use of this software
donatien 0:8e01dca41002 51 * must display the following acknowledgement:
donatien 0:8e01dca41002 52 * This product includes software developed by the NetBSD
donatien 0:8e01dca41002 53 * Foundation, Inc. and its contributors.
donatien 0:8e01dca41002 54 * 4. Neither the name of The NetBSD Foundation nor the names of its
donatien 0:8e01dca41002 55 * contributors may be used to endorse or promote products derived
donatien 0:8e01dca41002 56 * from this software without specific prior written permission.
donatien 0:8e01dca41002 57 *
donatien 0:8e01dca41002 58 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
donatien 0:8e01dca41002 59 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
donatien 0:8e01dca41002 60 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
donatien 0:8e01dca41002 61 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
donatien 0:8e01dca41002 62 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
donatien 0:8e01dca41002 63 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
donatien 0:8e01dca41002 64 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
donatien 0:8e01dca41002 65 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
donatien 0:8e01dca41002 66 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
donatien 0:8e01dca41002 67 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
donatien 0:8e01dca41002 68 * POSSIBILITY OF SUCH DAMAGE.
donatien 0:8e01dca41002 69 */
donatien 0:8e01dca41002 70 #ifndef PPP_OE_H
donatien 0:8e01dca41002 71 #define PPP_OE_H
donatien 0:8e01dca41002 72
donatien 0:8e01dca41002 73 #include "lwip/opt.h"
donatien 0:8e01dca41002 74
donatien 0:8e01dca41002 75 #if PPPOE_SUPPORT > 0
donatien 0:8e01dca41002 76
donatien 0:8e01dca41002 77 #include "netif/etharp.h"
donatien 0:8e01dca41002 78
donatien 0:8e01dca41002 79 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:8e01dca41002 80 # include "arch/bpstruct.h"
donatien 0:8e01dca41002 81 #endif
donatien 0:8e01dca41002 82 PACK_STRUCT_BEGIN
donatien 0:8e01dca41002 83 struct pppoehdr {
donatien 0:8e01dca41002 84 PACK_STRUCT_FIELD(u8_t vertype);
donatien 0:8e01dca41002 85 PACK_STRUCT_FIELD(u8_t code);
donatien 0:8e01dca41002 86 PACK_STRUCT_FIELD(u16_t session);
donatien 0:8e01dca41002 87 PACK_STRUCT_FIELD(u16_t plen);
donatien 0:8e01dca41002 88 } PACK_STRUCT_STRUCT;
donatien 0:8e01dca41002 89 PACK_STRUCT_END
donatien 0:8e01dca41002 90 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:8e01dca41002 91 # include "arch/epstruct.h"
donatien 0:8e01dca41002 92 #endif
donatien 0:8e01dca41002 93
donatien 0:8e01dca41002 94 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:8e01dca41002 95 # include "arch/bpstruct.h"
donatien 0:8e01dca41002 96 #endif
donatien 0:8e01dca41002 97 PACK_STRUCT_BEGIN
donatien 0:8e01dca41002 98 struct pppoetag {
donatien 0:8e01dca41002 99 PACK_STRUCT_FIELD(u16_t tag);
donatien 0:8e01dca41002 100 PACK_STRUCT_FIELD(u16_t len);
donatien 0:8e01dca41002 101 } PACK_STRUCT_STRUCT;
donatien 0:8e01dca41002 102 PACK_STRUCT_END
donatien 0:8e01dca41002 103 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:8e01dca41002 104 # include "arch/epstruct.h"
donatien 0:8e01dca41002 105 #endif
donatien 0:8e01dca41002 106
donatien 0:8e01dca41002 107
donatien 0:8e01dca41002 108 #define PPPOE_STATE_INITIAL 0
donatien 0:8e01dca41002 109 #define PPPOE_STATE_PADI_SENT 1
donatien 0:8e01dca41002 110 #define PPPOE_STATE_PADR_SENT 2
donatien 0:8e01dca41002 111 #define PPPOE_STATE_SESSION 3
donatien 0:8e01dca41002 112 #define PPPOE_STATE_CLOSING 4
donatien 0:8e01dca41002 113 /* passive */
donatien 0:8e01dca41002 114 #define PPPOE_STATE_PADO_SENT 1
donatien 0:8e01dca41002 115
donatien 0:8e01dca41002 116 #define PPPOE_HEADERLEN sizeof(struct pppoehdr)
donatien 0:8e01dca41002 117 #define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */
donatien 0:8e01dca41002 118
donatien 0:8e01dca41002 119 #define PPPOE_TAG_EOL 0x0000 /* end of list */
donatien 0:8e01dca41002 120 #define PPPOE_TAG_SNAME 0x0101 /* service name */
donatien 0:8e01dca41002 121 #define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */
donatien 0:8e01dca41002 122 #define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */
donatien 0:8e01dca41002 123 #define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */
donatien 0:8e01dca41002 124 #define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */
donatien 0:8e01dca41002 125 #define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */
donatien 0:8e01dca41002 126 #define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */
donatien 0:8e01dca41002 127 #define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */
donatien 0:8e01dca41002 128 #define PPPOE_TAG_GENERIC_ERR 0x0203 /* gerneric error */
donatien 0:8e01dca41002 129
donatien 0:8e01dca41002 130 #define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
donatien 0:8e01dca41002 131 #define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
donatien 0:8e01dca41002 132 #define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
donatien 0:8e01dca41002 133 #define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */
donatien 0:8e01dca41002 134 #define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */
donatien 0:8e01dca41002 135
donatien 0:8e01dca41002 136 #ifndef ETHERMTU
donatien 0:8e01dca41002 137 #define ETHERMTU 1500
donatien 0:8e01dca41002 138 #endif
donatien 0:8e01dca41002 139
donatien 0:8e01dca41002 140 /* two byte PPP protocol discriminator, then IP data */
donatien 0:8e01dca41002 141 #define PPPOE_MAXMTU (ETHERMTU-PPPOE_HEADERLEN-2)
donatien 0:8e01dca41002 142
donatien 0:8e01dca41002 143 #ifndef PPPOE_MAX_AC_COOKIE_LEN
donatien 0:8e01dca41002 144 #define PPPOE_MAX_AC_COOKIE_LEN 64
donatien 0:8e01dca41002 145 #endif
donatien 0:8e01dca41002 146
donatien 0:8e01dca41002 147 struct pppoe_softc {
donatien 0:8e01dca41002 148 struct pppoe_softc *next;
donatien 0:8e01dca41002 149 struct netif *sc_ethif; /* ethernet interface we are using */
donatien 0:8e01dca41002 150 int sc_pd; /* ppp unit number */
donatien 0:8e01dca41002 151 void (*sc_linkStatusCB)(int pd, int up);
donatien 0:8e01dca41002 152
donatien 0:8e01dca41002 153 int sc_state; /* discovery phase or session connected */
donatien 0:8e01dca41002 154 struct eth_addr sc_dest; /* hardware address of concentrator */
donatien 0:8e01dca41002 155 u16_t sc_session; /* PPPoE session id */
donatien 0:8e01dca41002 156
donatien 0:8e01dca41002 157 #ifdef PPPOE_TODO
donatien 0:8e01dca41002 158 char *sc_service_name; /* if != NULL: requested name of service */
donatien 0:8e01dca41002 159 char *sc_concentrator_name; /* if != NULL: requested concentrator id */
donatien 0:8e01dca41002 160 #endif /* PPPOE_TODO */
donatien 0:8e01dca41002 161 u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */
donatien 0:8e01dca41002 162 size_t sc_ac_cookie_len; /* length of cookie data */
donatien 0:8e01dca41002 163 #ifdef PPPOE_SERVER
donatien 0:8e01dca41002 164 u8_t *sc_hunique; /* content of host unique we must echo back */
donatien 0:8e01dca41002 165 size_t sc_hunique_len; /* length of host unique */
donatien 0:8e01dca41002 166 #endif
donatien 0:8e01dca41002 167 int sc_padi_retried; /* number of PADI retries already done */
donatien 0:8e01dca41002 168 int sc_padr_retried; /* number of PADR retries already done */
donatien 0:8e01dca41002 169 };
donatien 0:8e01dca41002 170
donatien 0:8e01dca41002 171
donatien 0:8e01dca41002 172 #define pppoe_init() /* compatibility define, no initialization needed */
donatien 0:8e01dca41002 173
donatien 0:8e01dca41002 174 err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr);
donatien 0:8e01dca41002 175 err_t pppoe_destroy(struct netif *ifp);
donatien 0:8e01dca41002 176
donatien 0:8e01dca41002 177 int pppoe_connect(struct pppoe_softc *sc);
donatien 0:8e01dca41002 178 void pppoe_disconnect(struct pppoe_softc *sc);
donatien 0:8e01dca41002 179
donatien 0:8e01dca41002 180 void pppoe_disc_input(struct netif *netif, struct pbuf *p);
donatien 0:8e01dca41002 181 void pppoe_data_input(struct netif *netif, struct pbuf *p);
donatien 0:8e01dca41002 182
donatien 0:8e01dca41002 183 err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb);
donatien 0:8e01dca41002 184
donatien 0:8e01dca41002 185 /** used in ppp.c */
donatien 0:8e01dca41002 186 #define PPPOE_HDRLEN (sizeof(struct eth_hdr) + PPPOE_HEADERLEN)
donatien 0:8e01dca41002 187
donatien 0:8e01dca41002 188 #endif /* PPPOE_SUPPORT */
donatien 0:8e01dca41002 189
donatien 0:8e01dca41002 190 #endif /* PPP_OE_H */