Deprecated fork of old network stack source from github. Please use official library instead: https://mbed.org/users/mbed_official/code/EthernetInterface/

Committer:
AdamGreen
Date:
Sat Oct 26 08:51:36 2013 +0000
Revision:
1:eadc868c2acf
Parent:
0:3b00827bb0b7
Fix TCP checksum bug and stranded large TCP segments.

Who changed what in which revision?

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