EthernetNetIf

Dependents:   XBee_WiFi_EA_LPC4088

Committer:
hmike
Date:
Wed Nov 19 12:00:42 2014 +0000
Revision:
0:62580107d20c
EthernetNetIf

Who changed what in which revision?

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