A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers netifapi.c Source File

netifapi.c

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Network Interface Sequential API module
00004  *
00005  */
00006 
00007 /*
00008  * Redistribution and use in source and binary forms, with or without modification, 
00009  * are permitted provided that the following conditions are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright notice,
00012  *    this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright notice,
00014  *    this list of conditions and the following disclaimer in the documentation
00015  *    and/or other materials provided with the distribution.
00016  * 3. The name of the author may not be used to endorse or promote products
00017  *    derived from this software without specific prior written permission. 
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00020  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00021  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00022  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00024  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00027  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00028  * OF SUCH DAMAGE.
00029  *
00030  * This file is part of the lwIP TCP/IP stack.
00031  * 
00032  */
00033 
00034 #include "lwip/opt.h"
00035 
00036 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
00037 
00038 #include "lwip/netifapi.h"
00039 #include "lwip/tcpip.h"
00040 
00041 /**
00042  * Call netif_add() inside the tcpip_thread context.
00043  */
00044 void
00045 do_netifapi_netif_add( struct netifapi_msg_msg *msg)
00046 {
00047   if (!netif_add( msg->netif,
00048                   msg->msg.add.ipaddr,
00049                   msg->msg.add.netmask,
00050                   msg->msg.add.gw,
00051                   msg->msg.add.state,
00052                   msg->msg.add.init,
00053                   msg->msg.add.input)) {
00054     msg->err = ERR_IF;
00055   } else {
00056     msg->err = ERR_OK;
00057   }
00058   TCPIP_NETIFAPI_ACK(msg);
00059 }
00060 
00061 /**
00062  * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
00063  * tcpip_thread context.
00064  */
00065 void
00066 do_netifapi_netif_common( struct netifapi_msg_msg *msg)
00067 {
00068   if (msg->msg.common.errtfunc!=NULL) {
00069     msg->err =
00070     msg->msg.common.errtfunc(msg->netif);
00071   } else {
00072     msg->err = ERR_OK;
00073     msg->msg.common.voidfunc(msg->netif);
00074   }
00075   TCPIP_NETIFAPI_ACK(msg);
00076 }
00077 
00078 /**
00079  * Call netif_add() in a thread-safe way by running that function inside the
00080  * tcpip_thread context.
00081  *
00082  * @note for params @see netif_add()
00083  */
00084 err_t
00085 netifapi_netif_add(struct netif *netif,
00086                    struct ip_addr *ipaddr,
00087                    struct ip_addr *netmask,
00088                    struct ip_addr *gw,
00089                    void *state,
00090                    err_t (* init)(struct netif *netif),
00091                    err_t (* input)(struct pbuf *p, struct netif *netif))
00092 {
00093   struct netifapi_msg msg;
00094   msg.function = do_netifapi_netif_add;
00095   msg.msg.netif = netif;
00096   msg.msg.msg.add.ipaddr  = ipaddr;
00097   msg.msg.msg.add.netmask = netmask;
00098   msg.msg.msg.add.gw      = gw;
00099   msg.msg.msg.add.state   = state;
00100   msg.msg.msg.add.init    = init;
00101   msg.msg.msg.add.input   = input;
00102   TCPIP_NETIFAPI(&msg);
00103   return msg.msg.err;
00104 }
00105 
00106 /**
00107  * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
00108  * way by running that function inside the tcpip_thread context.
00109  *
00110  * @note use only for functions where there is only "netif" parameter.
00111  */
00112 err_t
00113 netifapi_netif_common( struct netif *netif,
00114                        void  (* voidfunc)(struct netif *netif),
00115                        err_t (* errtfunc)(struct netif *netif) )
00116 {
00117   struct netifapi_msg msg;
00118   msg.function = do_netifapi_netif_common;
00119   msg.msg.netif = netif;
00120   msg.msg.msg.common.voidfunc = voidfunc;
00121   msg.msg.msg.common.errtfunc = errtfunc;
00122   TCPIP_NETIFAPI(&msg);
00123   return msg.msg.err;
00124 }
00125 
00126 #endif /* LWIP_NETIF_API */