Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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