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