Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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