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:
Fri Jun 22 09:25:39 2012 +0000
Revision:
0:51ac1d130fd4
Initial import from lwip-1.4.0: http://download.savannah.gnu.org/releases/lwip/lwip-1.4.0.zip

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:51ac1d130fd4 1 /**
mbed_official 0:51ac1d130fd4 2 * @file
mbed_official 0:51ac1d130fd4 3 * Network Interface Sequential API module
mbed_official 0:51ac1d130fd4 4 *
mbed_official 0:51ac1d130fd4 5 */
mbed_official 0:51ac1d130fd4 6
mbed_official 0:51ac1d130fd4 7 /*
mbed_official 0:51ac1d130fd4 8 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 0:51ac1d130fd4 9 * are permitted provided that the following conditions are met:
mbed_official 0:51ac1d130fd4 10 *
mbed_official 0:51ac1d130fd4 11 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 0:51ac1d130fd4 12 * this list of conditions and the following disclaimer.
mbed_official 0:51ac1d130fd4 13 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 0:51ac1d130fd4 14 * this list of conditions and the following disclaimer in the documentation
mbed_official 0:51ac1d130fd4 15 * and/or other materials provided with the distribution.
mbed_official 0:51ac1d130fd4 16 * 3. The name of the author may not be used to endorse or promote products
mbed_official 0:51ac1d130fd4 17 * derived from this software without specific prior written permission.
mbed_official 0:51ac1d130fd4 18 *
mbed_official 0:51ac1d130fd4 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mbed_official 0:51ac1d130fd4 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 0:51ac1d130fd4 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mbed_official 0:51ac1d130fd4 22 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mbed_official 0:51ac1d130fd4 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mbed_official 0:51ac1d130fd4 24 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed_official 0:51ac1d130fd4 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed_official 0:51ac1d130fd4 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mbed_official 0:51ac1d130fd4 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mbed_official 0:51ac1d130fd4 28 * OF SUCH DAMAGE.
mbed_official 0:51ac1d130fd4 29 *
mbed_official 0:51ac1d130fd4 30 * This file is part of the lwIP TCP/IP stack.
mbed_official 0:51ac1d130fd4 31 *
mbed_official 0:51ac1d130fd4 32 */
mbed_official 0:51ac1d130fd4 33
mbed_official 0:51ac1d130fd4 34 #include "lwip/opt.h"
mbed_official 0:51ac1d130fd4 35
mbed_official 0:51ac1d130fd4 36 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
mbed_official 0:51ac1d130fd4 37
mbed_official 0:51ac1d130fd4 38 #include "lwip/netifapi.h"
mbed_official 0:51ac1d130fd4 39 #include "lwip/tcpip.h"
mbed_official 0:51ac1d130fd4 40
mbed_official 0:51ac1d130fd4 41 /**
mbed_official 0:51ac1d130fd4 42 * Call netif_add() inside the tcpip_thread context.
mbed_official 0:51ac1d130fd4 43 */
mbed_official 0:51ac1d130fd4 44 void
mbed_official 0:51ac1d130fd4 45 do_netifapi_netif_add(struct netifapi_msg_msg *msg)
mbed_official 0:51ac1d130fd4 46 {
mbed_official 0:51ac1d130fd4 47 if (!netif_add( msg->netif,
mbed_official 0:51ac1d130fd4 48 msg->msg.add.ipaddr,
mbed_official 0:51ac1d130fd4 49 msg->msg.add.netmask,
mbed_official 0:51ac1d130fd4 50 msg->msg.add.gw,
mbed_official 0:51ac1d130fd4 51 msg->msg.add.state,
mbed_official 0:51ac1d130fd4 52 msg->msg.add.init,
mbed_official 0:51ac1d130fd4 53 msg->msg.add.input)) {
mbed_official 0:51ac1d130fd4 54 msg->err = ERR_IF;
mbed_official 0:51ac1d130fd4 55 } else {
mbed_official 0:51ac1d130fd4 56 msg->err = ERR_OK;
mbed_official 0:51ac1d130fd4 57 }
mbed_official 0:51ac1d130fd4 58 TCPIP_NETIFAPI_ACK(msg);
mbed_official 0:51ac1d130fd4 59 }
mbed_official 0:51ac1d130fd4 60
mbed_official 0:51ac1d130fd4 61 /**
mbed_official 0:51ac1d130fd4 62 * Call netif_set_addr() inside the tcpip_thread context.
mbed_official 0:51ac1d130fd4 63 */
mbed_official 0:51ac1d130fd4 64 void
mbed_official 0:51ac1d130fd4 65 do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg)
mbed_official 0:51ac1d130fd4 66 {
mbed_official 0:51ac1d130fd4 67 netif_set_addr( msg->netif,
mbed_official 0:51ac1d130fd4 68 msg->msg.add.ipaddr,
mbed_official 0:51ac1d130fd4 69 msg->msg.add.netmask,
mbed_official 0:51ac1d130fd4 70 msg->msg.add.gw);
mbed_official 0:51ac1d130fd4 71 msg->err = ERR_OK;
mbed_official 0:51ac1d130fd4 72 TCPIP_NETIFAPI_ACK(msg);
mbed_official 0:51ac1d130fd4 73 }
mbed_official 0:51ac1d130fd4 74
mbed_official 0:51ac1d130fd4 75 /**
mbed_official 0:51ac1d130fd4 76 * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
mbed_official 0:51ac1d130fd4 77 * tcpip_thread context.
mbed_official 0:51ac1d130fd4 78 */
mbed_official 0:51ac1d130fd4 79 void
mbed_official 0:51ac1d130fd4 80 do_netifapi_netif_common(struct netifapi_msg_msg *msg)
mbed_official 0:51ac1d130fd4 81 {
mbed_official 0:51ac1d130fd4 82 if (msg->msg.common.errtfunc != NULL) {
mbed_official 0:51ac1d130fd4 83 msg->err = msg->msg.common.errtfunc(msg->netif);
mbed_official 0:51ac1d130fd4 84 } else {
mbed_official 0:51ac1d130fd4 85 msg->err = ERR_OK;
mbed_official 0:51ac1d130fd4 86 msg->msg.common.voidfunc(msg->netif);
mbed_official 0:51ac1d130fd4 87 }
mbed_official 0:51ac1d130fd4 88 TCPIP_NETIFAPI_ACK(msg);
mbed_official 0:51ac1d130fd4 89 }
mbed_official 0:51ac1d130fd4 90
mbed_official 0:51ac1d130fd4 91 /**
mbed_official 0:51ac1d130fd4 92 * Call netif_add() in a thread-safe way by running that function inside the
mbed_official 0:51ac1d130fd4 93 * tcpip_thread context.
mbed_official 0:51ac1d130fd4 94 *
mbed_official 0:51ac1d130fd4 95 * @note for params @see netif_add()
mbed_official 0:51ac1d130fd4 96 */
mbed_official 0:51ac1d130fd4 97 err_t
mbed_official 0:51ac1d130fd4 98 netifapi_netif_add(struct netif *netif,
mbed_official 0:51ac1d130fd4 99 ip_addr_t *ipaddr,
mbed_official 0:51ac1d130fd4 100 ip_addr_t *netmask,
mbed_official 0:51ac1d130fd4 101 ip_addr_t *gw,
mbed_official 0:51ac1d130fd4 102 void *state,
mbed_official 0:51ac1d130fd4 103 netif_init_fn init,
mbed_official 0:51ac1d130fd4 104 netif_input_fn input)
mbed_official 0:51ac1d130fd4 105 {
mbed_official 0:51ac1d130fd4 106 struct netifapi_msg msg;
mbed_official 0:51ac1d130fd4 107 msg.function = do_netifapi_netif_add;
mbed_official 0:51ac1d130fd4 108 msg.msg.netif = netif;
mbed_official 0:51ac1d130fd4 109 msg.msg.msg.add.ipaddr = ipaddr;
mbed_official 0:51ac1d130fd4 110 msg.msg.msg.add.netmask = netmask;
mbed_official 0:51ac1d130fd4 111 msg.msg.msg.add.gw = gw;
mbed_official 0:51ac1d130fd4 112 msg.msg.msg.add.state = state;
mbed_official 0:51ac1d130fd4 113 msg.msg.msg.add.init = init;
mbed_official 0:51ac1d130fd4 114 msg.msg.msg.add.input = input;
mbed_official 0:51ac1d130fd4 115 TCPIP_NETIFAPI(&msg);
mbed_official 0:51ac1d130fd4 116 return msg.msg.err;
mbed_official 0:51ac1d130fd4 117 }
mbed_official 0:51ac1d130fd4 118
mbed_official 0:51ac1d130fd4 119 /**
mbed_official 0:51ac1d130fd4 120 * Call netif_set_addr() in a thread-safe way by running that function inside the
mbed_official 0:51ac1d130fd4 121 * tcpip_thread context.
mbed_official 0:51ac1d130fd4 122 *
mbed_official 0:51ac1d130fd4 123 * @note for params @see netif_set_addr()
mbed_official 0:51ac1d130fd4 124 */
mbed_official 0:51ac1d130fd4 125 err_t
mbed_official 0:51ac1d130fd4 126 netifapi_netif_set_addr(struct netif *netif,
mbed_official 0:51ac1d130fd4 127 ip_addr_t *ipaddr,
mbed_official 0:51ac1d130fd4 128 ip_addr_t *netmask,
mbed_official 0:51ac1d130fd4 129 ip_addr_t *gw)
mbed_official 0:51ac1d130fd4 130 {
mbed_official 0:51ac1d130fd4 131 struct netifapi_msg msg;
mbed_official 0:51ac1d130fd4 132 msg.function = do_netifapi_netif_set_addr;
mbed_official 0:51ac1d130fd4 133 msg.msg.netif = netif;
mbed_official 0:51ac1d130fd4 134 msg.msg.msg.add.ipaddr = ipaddr;
mbed_official 0:51ac1d130fd4 135 msg.msg.msg.add.netmask = netmask;
mbed_official 0:51ac1d130fd4 136 msg.msg.msg.add.gw = gw;
mbed_official 0:51ac1d130fd4 137 TCPIP_NETIFAPI(&msg);
mbed_official 0:51ac1d130fd4 138 return msg.msg.err;
mbed_official 0:51ac1d130fd4 139 }
mbed_official 0:51ac1d130fd4 140
mbed_official 0:51ac1d130fd4 141 /**
mbed_official 0:51ac1d130fd4 142 * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
mbed_official 0:51ac1d130fd4 143 * way by running that function inside the tcpip_thread context.
mbed_official 0:51ac1d130fd4 144 *
mbed_official 0:51ac1d130fd4 145 * @note use only for functions where there is only "netif" parameter.
mbed_official 0:51ac1d130fd4 146 */
mbed_official 0:51ac1d130fd4 147 err_t
mbed_official 0:51ac1d130fd4 148 netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
mbed_official 0:51ac1d130fd4 149 netifapi_errt_fn errtfunc)
mbed_official 0:51ac1d130fd4 150 {
mbed_official 0:51ac1d130fd4 151 struct netifapi_msg msg;
mbed_official 0:51ac1d130fd4 152 msg.function = do_netifapi_netif_common;
mbed_official 0:51ac1d130fd4 153 msg.msg.netif = netif;
mbed_official 0:51ac1d130fd4 154 msg.msg.msg.common.voidfunc = voidfunc;
mbed_official 0:51ac1d130fd4 155 msg.msg.msg.common.errtfunc = errtfunc;
mbed_official 0:51ac1d130fd4 156 TCPIP_NETIFAPI(&msg);
mbed_official 0:51ac1d130fd4 157 return msg.msg.err;
mbed_official 0:51ac1d130fd4 158 }
mbed_official 0:51ac1d130fd4 159
mbed_official 0:51ac1d130fd4 160 #endif /* LWIP_NETIF_API */