SAMV71 Xplained Ultra Software Package 1.4

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 netif_set_addr() inside the tcpip_thread context.
00063  */
00064 void
00065 do_netifapi_netif_set_addr( struct netifapi_msg_msg *msg)
00066 {
00067   netif_set_addr( msg->netif,
00068                   msg->msg.add.ipaddr,
00069                   msg->msg.add.netmask,
00070                   msg->msg.add.gw);
00071   msg->err = ERR_OK;
00072   TCPIP_NETIFAPI_ACK(msg);
00073 }
00074 
00075 /**
00076  * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
00077  * tcpip_thread context.
00078  */
00079 void
00080 do_netifapi_netif_common( struct netifapi_msg_msg *msg)
00081 {
00082   if (msg->msg.common.errtfunc!=NULL) {
00083     msg->err =
00084     msg->msg.common.errtfunc(msg->netif);
00085   } else {
00086     msg->err = ERR_OK;
00087     msg->msg.common.voidfunc(msg->netif);
00088   }
00089   TCPIP_NETIFAPI_ACK(msg);
00090 }
00091 
00092 /**
00093  * Call netif_add() in a thread-safe way by running that function inside the
00094  * tcpip_thread context.
00095  *
00096  * @note for params @see netif_add()
00097  */
00098 err_t
00099 netifapi_netif_add(struct netif *netif,
00100                    struct ip_addr *ipaddr,
00101                    struct ip_addr *netmask,
00102                    struct ip_addr *gw,
00103                    void *state,
00104                    err_t (* init)(struct netif *netif),
00105                    err_t (* input)(struct pbuf *p, struct netif *netif))
00106 {
00107   struct netifapi_msg msg;
00108   msg.function = do_netifapi_netif_add;
00109   msg.msg.netif = netif;
00110   msg.msg.msg.add.ipaddr  = ipaddr;
00111   msg.msg.msg.add.netmask = netmask;
00112   msg.msg.msg.add.gw      = gw;
00113   msg.msg.msg.add.state   = state;
00114   msg.msg.msg.add.init    = init;
00115   msg.msg.msg.add.input   = input;
00116   TCPIP_NETIFAPI(&msg);
00117   return msg.msg.err;
00118 }
00119 
00120 /**
00121  * Call netif_set_addr() in a thread-safe way by running that function inside the
00122  * tcpip_thread context.
00123  *
00124  * @note for params @see netif_set_addr()
00125  */
00126 err_t
00127 netifapi_netif_set_addr(struct netif *netif,
00128                         struct ip_addr *ipaddr,
00129                         struct ip_addr *netmask,
00130                         struct ip_addr *gw)
00131 {
00132   struct netifapi_msg msg;
00133   msg.function = do_netifapi_netif_set_addr;
00134   msg.msg.netif = netif;
00135   msg.msg.msg.add.ipaddr  = ipaddr;
00136   msg.msg.msg.add.netmask = netmask;
00137   msg.msg.msg.add.gw      = gw;
00138   TCPIP_NETIFAPI(&msg);
00139   return msg.msg.err;
00140 }
00141 
00142 /**
00143  * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
00144  * way by running that function inside the tcpip_thread context.
00145  *
00146  * @note use only for functions where there is only "netif" parameter.
00147  */
00148 err_t
00149 netifapi_netif_common( struct netif *netif,
00150                        void  (* voidfunc)(struct netif *netif),
00151                        err_t (* errtfunc)(struct netif *netif) )
00152 {
00153   struct netifapi_msg msg;
00154   msg.function = do_netifapi_netif_common;
00155   msg.msg.netif = netif;
00156   msg.msg.msg.common.voidfunc = voidfunc;
00157   msg.msg.msg.common.errtfunc = errtfunc;
00158   TCPIP_NETIFAPI(&msg);
00159   return msg.msg.err;
00160 }
00161 
00162 #endif /* LWIP_NETIF_API */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines