Measure system

Dependencies:   EthernetNetIf mbed RF12B

Committer:
benecsj
Date:
Thu Mar 10 19:56:45 2011 +0000
Revision:
1:b26ab2467b1a

        

Who changed what in which revision?

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