Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

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