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