Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/lwip/api/netifapi.c need to be fixed.

0001 /**
0002  * @file
0003  * Network Interface Sequential API module
0004  *
0005  */
0006 
0007 /*
0008  * Redistribution and use in source and binary forms, with or without modification, 
0009  * are permitted provided that the following conditions are met:
0010  *
0011  * 1. Redistributions of source code must retain the above copyright notice,
0012  *    this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright notice,
0014  *    this list of conditions and the following disclaimer in the documentation
0015  *    and/or other materials provided with the distribution.
0016  * 3. The name of the author may not be used to endorse or promote products
0017  *    derived from this software without specific prior written permission. 
0018  *
0019  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
0020  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
0021  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
0022  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
0023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
0024  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
0027  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
0028  * OF SUCH DAMAGE.
0029  *
0030  * This file is part of the lwIP TCP/IP stack.
0031  * 
0032  */
0033 
0034 #include "lwip/opt.h"
0035 
0036 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
0037 
0038 #include "lwip/netifapi.h"
0039 #include "lwip/tcpip.h"
0040 
0041 /**
0042  * Call netif_add() inside the tcpip_thread context.
0043  */
0044 void
0045 do_netifapi_netif_add( struct netifapi_msg_msg *msg)
0046 {
0047   if (!netif_add( msg->netif,
0048                   msg->msg.add.ipaddr,
0049                   msg->msg.add.netmask,
0050                   msg->msg.add.gw,
0051                   msg->msg.add.state,
0052                   msg->msg.add.init,
0053                   msg->msg.add.input)) {
0054     msg->err = ERR_IF;
0055   } else {
0056     msg->err = ERR_OK;
0057   }
0058   TCPIP_NETIFAPI_ACK(msg);
0059 }
0060 
0061 /**
0062  * Call netif_set_addr() inside the tcpip_thread context.
0063  */
0064 void
0065 do_netifapi_netif_set_addr( struct netifapi_msg_msg *msg)
0066 {
0067   netif_set_addr( msg->netif,
0068                   msg->msg.add.ipaddr,
0069                   msg->msg.add.netmask,
0070                   msg->msg.add.gw);
0071   msg->err = ERR_OK;
0072   TCPIP_NETIFAPI_ACK(msg);
0073 }
0074 
0075 /**
0076  * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
0077  * tcpip_thread context.
0078  */
0079 void
0080 do_netifapi_netif_common( struct netifapi_msg_msg *msg)
0081 {
0082   if (msg->msg.common.errtfunc!=NULL) {
0083     msg->err =
0084     msg->msg.common.errtfunc(msg->netif);
0085   } else {
0086     msg->err = ERR_OK;
0087     msg->msg.common.voidfunc(msg->netif);
0088   }
0089   TCPIP_NETIFAPI_ACK(msg);
0090 }
0091 
0092 /**
0093  * Call netif_add() in a thread-safe way by running that function inside the
0094  * tcpip_thread context.
0095  *
0096  * @note for params @see netif_add()
0097  */
0098 err_t
0099 netifapi_netif_add(struct netif *netif,
0100                    struct ip_addr *ipaddr,
0101                    struct ip_addr *netmask,
0102                    struct ip_addr *gw,
0103                    void *state,
0104                    err_t (* init)(struct netif *netif),
0105                    err_t (* input)(struct pbuf *p, struct netif *netif))
0106 {
0107   struct netifapi_msg msg;
0108   msg.function = do_netifapi_netif_add;
0109   msg.msg.netif = netif;
0110   msg.msg.msg.add.ipaddr  = ipaddr;
0111   msg.msg.msg.add.netmask = netmask;
0112   msg.msg.msg.add.gw      = gw;
0113   msg.msg.msg.add.state   = state;
0114   msg.msg.msg.add.init    = init;
0115   msg.msg.msg.add.input   = input;
0116   TCPIP_NETIFAPI(&msg);
0117   return msg.msg.err;
0118 }
0119 
0120 /**
0121  * Call netif_set_addr() in a thread-safe way by running that function inside the
0122  * tcpip_thread context.
0123  *
0124  * @note for params @see netif_set_addr()
0125  */
0126 err_t
0127 netifapi_netif_set_addr(struct netif *netif,
0128                         struct ip_addr *ipaddr,
0129                         struct ip_addr *netmask,
0130                         struct ip_addr *gw)
0131 {
0132   struct netifapi_msg msg;
0133   msg.function = do_netifapi_netif_set_addr;
0134   msg.msg.netif = netif;
0135   msg.msg.msg.add.ipaddr  = ipaddr;
0136   msg.msg.msg.add.netmask = netmask;
0137   msg.msg.msg.add.gw      = gw;
0138   TCPIP_NETIFAPI(&msg);
0139   return msg.msg.err;
0140 }
0141 
0142 /**
0143  * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
0144  * way by running that function inside the tcpip_thread context.
0145  *
0146  * @note use only for functions where there is only "netif" parameter.
0147  */
0148 err_t
0149 netifapi_netif_common( struct netif *netif,
0150                        void  (* voidfunc)(struct netif *netif),
0151                        err_t (* errtfunc)(struct netif *netif) )
0152 {
0153   struct netifapi_msg msg;
0154   msg.function = do_netifapi_netif_common;
0155   msg.msg.netif = netif;
0156   msg.msg.msg.common.voidfunc = voidfunc;
0157   msg.msg.msg.common.errtfunc = errtfunc;
0158   TCPIP_NETIFAPI(&msg);
0159   return msg.msg.err;
0160 }
0161 
0162 #endif /* LWIP_NETIF_API */