Official mbed lwIP library (version 1.4.0)

Dependents:   LwIPNetworking NetServicesMin EthernetInterface EthernetInterface_RSF ... more

Legacy Networking Libraries

This is an mbed 2 networking library. For mbed OS 5, lwip has been integrated with built-in networking interfaces. The networking libraries have been revised to better support additional network stacks and thread safety here.

This library is based on the code of lwIP v1.4.0

Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
All rights reserved. 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
mbed_official
Date:
Mon Mar 14 16:15:36 2016 +0000
Revision:
20:08f08bfc3f3d
Parent:
5:89eb903836af
Synchronized with git revision fec574a5ed6db26aca1b13992ff271bf527d4a0d

Full URL: https://github.com/mbedmicro/mbed/commit/fec574a5ed6db26aca1b13992ff271bf527d4a0d/

Increased allocated netbufs to handle DTLS handshakes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:51ac1d130fd4 1 /*
mbed_official 0:51ac1d130fd4 2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
mbed_official 0:51ac1d130fd4 3 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
mbed_official 0:51ac1d130fd4 4 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
mbed_official 0:51ac1d130fd4 5 * All rights reserved.
mbed_official 0:51ac1d130fd4 6 *
mbed_official 0:51ac1d130fd4 7 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 0:51ac1d130fd4 8 * are permitted provided that the following conditions are met:
mbed_official 0:51ac1d130fd4 9 *
mbed_official 0:51ac1d130fd4 10 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 0:51ac1d130fd4 11 * this list of conditions and the following disclaimer.
mbed_official 0:51ac1d130fd4 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 0:51ac1d130fd4 13 * this list of conditions and the following disclaimer in the documentation
mbed_official 0:51ac1d130fd4 14 * and/or other materials provided with the distribution.
mbed_official 0:51ac1d130fd4 15 * 3. The name of the author may not be used to endorse or promote products
mbed_official 0:51ac1d130fd4 16 * derived from this software without specific prior written permission.
mbed_official 0:51ac1d130fd4 17 *
mbed_official 0:51ac1d130fd4 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mbed_official 0:51ac1d130fd4 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 0:51ac1d130fd4 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mbed_official 0:51ac1d130fd4 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mbed_official 0:51ac1d130fd4 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mbed_official 0:51ac1d130fd4 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed_official 0:51ac1d130fd4 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed_official 0:51ac1d130fd4 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mbed_official 0:51ac1d130fd4 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mbed_official 0:51ac1d130fd4 27 * OF SUCH DAMAGE.
mbed_official 0:51ac1d130fd4 28 *
mbed_official 0:51ac1d130fd4 29 * This file is part of the lwIP TCP/IP stack.
mbed_official 0:51ac1d130fd4 30 *
mbed_official 0:51ac1d130fd4 31 * Author: Adam Dunkels <adam@sics.se>
mbed_official 0:51ac1d130fd4 32 *
mbed_official 0:51ac1d130fd4 33 */
mbed_official 0:51ac1d130fd4 34
mbed_official 0:51ac1d130fd4 35 #ifndef __NETIF_ETHARP_H__
mbed_official 0:51ac1d130fd4 36 #define __NETIF_ETHARP_H__
mbed_official 0:51ac1d130fd4 37
mbed_official 0:51ac1d130fd4 38 #include "lwip/opt.h"
mbed_official 0:51ac1d130fd4 39
mbed_official 0:51ac1d130fd4 40 #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
mbed_official 0:51ac1d130fd4 41
mbed_official 0:51ac1d130fd4 42 #include "lwip/pbuf.h"
mbed_official 0:51ac1d130fd4 43 #include "lwip/ip_addr.h"
mbed_official 0:51ac1d130fd4 44 #include "lwip/netif.h"
mbed_official 0:51ac1d130fd4 45 #include "lwip/ip.h"
mbed_official 0:51ac1d130fd4 46
mbed_official 0:51ac1d130fd4 47 #ifdef __cplusplus
mbed_official 0:51ac1d130fd4 48 extern "C" {
mbed_official 0:51ac1d130fd4 49 #endif
mbed_official 0:51ac1d130fd4 50
mbed_official 0:51ac1d130fd4 51 #ifndef ETHARP_HWADDR_LEN
mbed_official 0:51ac1d130fd4 52 #define ETHARP_HWADDR_LEN 6
mbed_official 0:51ac1d130fd4 53 #endif
mbed_official 0:51ac1d130fd4 54
mbed_official 0:51ac1d130fd4 55 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 56 # include "arch/bpstruct.h"
mbed_official 0:51ac1d130fd4 57 #endif
mbed_official 0:51ac1d130fd4 58 PACK_STRUCT_BEGIN
mbed_official 0:51ac1d130fd4 59 struct eth_addr {
mbed_official 0:51ac1d130fd4 60 PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
mbed_official 0:51ac1d130fd4 61 } PACK_STRUCT_STRUCT;
mbed_official 0:51ac1d130fd4 62 PACK_STRUCT_END
mbed_official 0:51ac1d130fd4 63 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 64 # include "arch/epstruct.h"
mbed_official 0:51ac1d130fd4 65 #endif
mbed_official 0:51ac1d130fd4 66
mbed_official 0:51ac1d130fd4 67 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 68 # include "arch/bpstruct.h"
mbed_official 0:51ac1d130fd4 69 #endif
mbed_official 0:51ac1d130fd4 70 PACK_STRUCT_BEGIN
mbed_official 0:51ac1d130fd4 71 /** Ethernet header */
mbed_official 0:51ac1d130fd4 72 struct eth_hdr {
mbed_official 0:51ac1d130fd4 73 #if ETH_PAD_SIZE
mbed_official 0:51ac1d130fd4 74 PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
mbed_official 0:51ac1d130fd4 75 #endif
mbed_official 0:51ac1d130fd4 76 PACK_STRUCT_FIELD(struct eth_addr dest);
mbed_official 0:51ac1d130fd4 77 PACK_STRUCT_FIELD(struct eth_addr src);
mbed_official 0:51ac1d130fd4 78 PACK_STRUCT_FIELD(u16_t type);
mbed_official 0:51ac1d130fd4 79 } PACK_STRUCT_STRUCT;
mbed_official 0:51ac1d130fd4 80 PACK_STRUCT_END
mbed_official 0:51ac1d130fd4 81 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 82 # include "arch/epstruct.h"
mbed_official 0:51ac1d130fd4 83 #endif
mbed_official 0:51ac1d130fd4 84
mbed_official 0:51ac1d130fd4 85 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
mbed_official 0:51ac1d130fd4 86
mbed_official 0:51ac1d130fd4 87 #if ETHARP_SUPPORT_VLAN
mbed_official 0:51ac1d130fd4 88
mbed_official 0:51ac1d130fd4 89 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 90 # include "arch/bpstruct.h"
mbed_official 0:51ac1d130fd4 91 #endif
mbed_official 0:51ac1d130fd4 92 PACK_STRUCT_BEGIN
mbed_official 0:51ac1d130fd4 93 /** VLAN header inserted between ethernet header and payload
mbed_official 0:51ac1d130fd4 94 * if 'type' in ethernet header is ETHTYPE_VLAN.
mbed_official 0:51ac1d130fd4 95 * See IEEE802.Q */
mbed_official 0:51ac1d130fd4 96 struct eth_vlan_hdr {
mbed_official 0:51ac1d130fd4 97 PACK_STRUCT_FIELD(u16_t prio_vid);
mbed_official 0:51ac1d130fd4 98 PACK_STRUCT_FIELD(u16_t tpid);
mbed_official 0:51ac1d130fd4 99 } PACK_STRUCT_STRUCT;
mbed_official 0:51ac1d130fd4 100 PACK_STRUCT_END
mbed_official 0:51ac1d130fd4 101 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 102 # include "arch/epstruct.h"
mbed_official 0:51ac1d130fd4 103 #endif
mbed_official 0:51ac1d130fd4 104
mbed_official 0:51ac1d130fd4 105 #define SIZEOF_VLAN_HDR 4
mbed_official 0:51ac1d130fd4 106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
mbed_official 0:51ac1d130fd4 107
mbed_official 0:51ac1d130fd4 108 #endif /* ETHARP_SUPPORT_VLAN */
mbed_official 0:51ac1d130fd4 109
mbed_official 0:51ac1d130fd4 110 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 111 # include "arch/bpstruct.h"
mbed_official 0:51ac1d130fd4 112 #endif
mbed_official 0:51ac1d130fd4 113 PACK_STRUCT_BEGIN
mbed_official 0:51ac1d130fd4 114 /** the ARP message, see RFC 826 ("Packet format") */
mbed_official 0:51ac1d130fd4 115 struct etharp_hdr {
mbed_official 0:51ac1d130fd4 116 PACK_STRUCT_FIELD(u16_t hwtype);
mbed_official 0:51ac1d130fd4 117 PACK_STRUCT_FIELD(u16_t proto);
mbed_official 0:51ac1d130fd4 118 PACK_STRUCT_FIELD(u8_t hwlen);
mbed_official 0:51ac1d130fd4 119 PACK_STRUCT_FIELD(u8_t protolen);
mbed_official 0:51ac1d130fd4 120 PACK_STRUCT_FIELD(u16_t opcode);
mbed_official 0:51ac1d130fd4 121 PACK_STRUCT_FIELD(struct eth_addr shwaddr);
mbed_official 0:51ac1d130fd4 122 PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
mbed_official 0:51ac1d130fd4 123 PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
mbed_official 0:51ac1d130fd4 124 PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
mbed_official 0:51ac1d130fd4 125 } PACK_STRUCT_STRUCT;
mbed_official 0:51ac1d130fd4 126 PACK_STRUCT_END
mbed_official 0:51ac1d130fd4 127 #ifdef PACK_STRUCT_USE_INCLUDES
mbed_official 0:51ac1d130fd4 128 # include "arch/epstruct.h"
mbed_official 0:51ac1d130fd4 129 #endif
mbed_official 0:51ac1d130fd4 130
mbed_official 0:51ac1d130fd4 131 #define SIZEOF_ETHARP_HDR 28
mbed_official 0:51ac1d130fd4 132 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
mbed_official 0:51ac1d130fd4 133
mbed_official 0:51ac1d130fd4 134 /** 5 seconds period */
mbed_official 0:51ac1d130fd4 135 #define ARP_TMR_INTERVAL 5000
mbed_official 0:51ac1d130fd4 136
mbed_official 0:51ac1d130fd4 137 #define ETHTYPE_ARP 0x0806U
mbed_official 0:51ac1d130fd4 138 #define ETHTYPE_IP 0x0800U
mbed_official 0:51ac1d130fd4 139 #define ETHTYPE_VLAN 0x8100U
mbed_official 0:51ac1d130fd4 140 #define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */
mbed_official 0:51ac1d130fd4 141 #define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */
mbed_official 0:51ac1d130fd4 142
mbed_official 0:51ac1d130fd4 143 /** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
mbed_official 0:51ac1d130fd4 144 * or known to be 32-bit aligned within the protocol header. */
mbed_official 0:51ac1d130fd4 145 #ifndef ETHADDR32_COPY
mbed_official 0:51ac1d130fd4 146 #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
mbed_official 0:51ac1d130fd4 147 #endif
mbed_official 0:51ac1d130fd4 148
mbed_official 0:51ac1d130fd4 149 /** MEMCPY-like macro to copy to/from struct eth_addr's that are no local
mbed_official 0:51ac1d130fd4 150 * variables and known to be 16-bit aligned within the protocol header. */
mbed_official 0:51ac1d130fd4 151 #ifndef ETHADDR16_COPY
mbed_official 0:51ac1d130fd4 152 #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
mbed_official 0:51ac1d130fd4 153 #endif
mbed_official 0:51ac1d130fd4 154
mbed_official 0:51ac1d130fd4 155 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
mbed_official 0:51ac1d130fd4 156
mbed_official 0:51ac1d130fd4 157 /** ARP message types (opcodes) */
mbed_official 0:51ac1d130fd4 158 #define ARP_REQUEST 1
mbed_official 0:51ac1d130fd4 159 #define ARP_REPLY 2
mbed_official 0:51ac1d130fd4 160
mbed_official 0:51ac1d130fd4 161 /** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
mbed_official 0:51ac1d130fd4 162 * to a filter function that returns the correct netif when using multiple
mbed_official 0:51ac1d130fd4 163 * netifs on one hardware interface where the netif's low-level receive
mbed_official 0:51ac1d130fd4 164 * routine cannot decide for the correct netif (e.g. when mapping multiple
mbed_official 0:51ac1d130fd4 165 * IP addresses to one hardware interface).
mbed_official 0:51ac1d130fd4 166 */
mbed_official 0:51ac1d130fd4 167 #ifndef LWIP_ARP_FILTER_NETIF
mbed_official 0:51ac1d130fd4 168 #define LWIP_ARP_FILTER_NETIF 0
mbed_official 0:51ac1d130fd4 169 #endif
mbed_official 0:51ac1d130fd4 170
mbed_official 0:51ac1d130fd4 171 #if ARP_QUEUEING
mbed_official 0:51ac1d130fd4 172 /** struct for queueing outgoing packets for unknown address
mbed_official 0:51ac1d130fd4 173 * defined here to be accessed by memp.h
mbed_official 0:51ac1d130fd4 174 */
mbed_official 0:51ac1d130fd4 175 struct etharp_q_entry {
mbed_official 0:51ac1d130fd4 176 struct etharp_q_entry *next;
mbed_official 0:51ac1d130fd4 177 struct pbuf *p;
mbed_official 0:51ac1d130fd4 178 };
mbed_official 0:51ac1d130fd4 179 #endif /* ARP_QUEUEING */
mbed_official 0:51ac1d130fd4 180
mbed_official 0:51ac1d130fd4 181 #define etharp_init() /* Compatibility define, not init needed. */
mbed_official 0:51ac1d130fd4 182 void etharp_tmr(void);
mbed_official 0:51ac1d130fd4 183 s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr,
mbed_official 0:51ac1d130fd4 184 struct eth_addr **eth_ret, ip_addr_t **ip_ret);
mbed_official 0:51ac1d130fd4 185 err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
mbed_official 0:51ac1d130fd4 186 err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q);
mbed_official 0:51ac1d130fd4 187 err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr);
mbed_official 0:51ac1d130fd4 188 /** For Ethernet network interfaces, we might want to send "gratuitous ARP";
mbed_official 0:51ac1d130fd4 189 * this is an ARP packet sent by a node in order to spontaneously cause other
mbed_official 0:51ac1d130fd4 190 * nodes to update an entry in their ARP cache.
mbed_official 0:51ac1d130fd4 191 * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
mbed_official 0:51ac1d130fd4 192 #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
mbed_official 0:51ac1d130fd4 193
mbed_official 0:51ac1d130fd4 194 #if ETHARP_SUPPORT_STATIC_ENTRIES
mbed_official 0:51ac1d130fd4 195 err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr);
mbed_official 0:51ac1d130fd4 196 err_t etharp_remove_static_entry(ip_addr_t *ipaddr);
mbed_official 0:51ac1d130fd4 197 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
mbed_official 0:51ac1d130fd4 198
mbed_official 0:51ac1d130fd4 199 #if LWIP_AUTOIP
mbed_official 0:51ac1d130fd4 200 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
mbed_official 0:51ac1d130fd4 201 const struct eth_addr *ethdst_addr,
mbed_official 0:51ac1d130fd4 202 const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
mbed_official 0:51ac1d130fd4 203 const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
mbed_official 0:51ac1d130fd4 204 const u16_t opcode);
mbed_official 0:51ac1d130fd4 205 #endif /* LWIP_AUTOIP */
mbed_official 0:51ac1d130fd4 206
mbed_official 0:51ac1d130fd4 207 #endif /* LWIP_ARP */
mbed_official 0:51ac1d130fd4 208
mbed_official 0:51ac1d130fd4 209 err_t ethernet_input(struct pbuf *p, struct netif *netif);
mbed_official 0:51ac1d130fd4 210
mbed_official 0:51ac1d130fd4 211 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
mbed_official 0:51ac1d130fd4 212
mbed_official 0:51ac1d130fd4 213 extern const struct eth_addr ethbroadcast, ethzero;
mbed_official 0:51ac1d130fd4 214
mbed_official 0:51ac1d130fd4 215 #ifdef __cplusplus
mbed_official 0:51ac1d130fd4 216 }
mbed_official 0:51ac1d130fd4 217 #endif
mbed_official 0:51ac1d130fd4 218
donatien 5:89eb903836af 219 #endif /* LWIP_ARP || LWIP_ETHERNET */
donatien 5:89eb903836af 220
mbed_official 0:51ac1d130fd4 221 #endif /* __NETIF_ARP_H__ */