Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

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