SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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