LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 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:
donatien
Date:
Fri May 25 08:56:35 2012 +0000
Revision:
2:1a87f74b8e3b
Parent:
0:8e01dca41002
Removed compilation of EMAC driver when using PPP

Who changed what in which revision?

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