Toyomasa Watarai / Mbed 2 deprecated IBMIoTClientWifiExample

Dependencies:   C12832_fix LM75B MMA7660 MQTT PowerControl SNICInterface mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by Toyomasa Watarai

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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