diff --git a/CHANGELOG b/CHANGELOG index 62340256..baef5d00 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2007-10-03 Frédéric Bernon + * netifapi.h, netifapi.c: add functions netifapi_netif_set_up, netifapi_netif_set_down, + netifapi_autoip_start and netifapi_autoip_stop. Use a common function to reduce + a little bit the footprint (for all functions using only the "netif" parameter). + 2007-09-15 Frédéric Bernon * udp.h, udp.c, sockets.c: Changes for "#20503 IGMP Improvement". Add IP_MULTICAST_IF option in socket API, and a new field "multicast_ip" in "struct udp_pcb" (for diff --git a/src/api/netifapi.c b/src/api/netifapi.c index e11efd91..ad8916ef 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -38,6 +38,22 @@ #include "lwip/netifapi.h" #include "lwip/tcpip.h" +/** + * call the "do_function" in a thread-safe way by running that function inside the + * tcpip_thread context. + * + * @note use only for "do_netifapi" functions where there is only netif parameter. + */ +err_t +netifapi_netif_common(struct netif *netif, void (* function)(struct netifapi_msg_msg *msg)) +{ + struct netifapi_msg msg; + msg.function = function; + msg.msg.netif = netif; + TCPIP_NETIFAPI(&msg); + return msg.msg.err; +} + /** * Call netif_add() in a thread-safe way by running that function inside the * tcpip_thread context. @@ -67,57 +83,7 @@ netifapi_netif_add(struct netif *netif, } /** - * Call netif_remove() in a thread-safe way by running that function inside the - * tcpip_thread context. - * - * @note for params @see netif_remove() - */ -err_t -netifapi_netif_remove(struct netif *netif) -{ - struct netifapi_msg msg; - msg.function = do_netifapi_netif_remove; - msg.msg.netif = netif; - TCPIP_NETIFAPI(&msg); - return msg.msg.err; -} - -#if LWIP_DHCP -/** - * Call dhcp_start() in a thread-safe way by running that function inside the - * tcpip_thread context. - * - * @note for params @see dhcp_start() - */ -err_t -netifapi_dhcp_start(struct netif *netif) -{ - struct netifapi_msg msg; - msg.function = do_netifapi_dhcp_start; - msg.msg.netif = netif; - TCPIP_NETIFAPI(&msg); - return msg.msg.err; -} - -/** - * Call dhcp_stop() in a thread-safe way by running that function inside the - * tcpip_thread context. - * - * @note for params @see dhcp_stop() - */ -err_t -netifapi_dhcp_stop(struct netif *netif) -{ - struct netifapi_msg msg; - msg.function = do_netifapi_dhcp_stop; - msg.msg.netif = netif; - TCPIP_NETIFAPI(&msg); - return msg.msg.err; -} -#endif /* LWIP_DHCP */ - -/** - * TODO + * @todo comment */ void do_netifapi_netif_add( struct netifapi_msg_msg *msg) @@ -136,7 +102,7 @@ do_netifapi_netif_add( struct netifapi_msg_msg *msg) } /** - * TODO + * @todo comment */ void do_netifapi_netif_remove( struct netifapi_msg_msg *msg) @@ -146,9 +112,31 @@ do_netifapi_netif_remove( struct netifapi_msg_msg *msg) TCPIP_NETIFAPI_ACK(msg); } -#if LWIP_DHCP /** - * TODO + * @todo comment + */ +void +do_netifapi_netif_set_up( struct netifapi_msg_msg *msg) +{ + msg->err = ERR_OK; + netif_set_up(msg->netif); + TCPIP_NETIFAPI_ACK(msg); +} + +/** + * @todo comment + */ +void +do_netifapi_netif_set_down( struct netifapi_msg_msg *msg) +{ + msg->err = ERR_OK; + netif_set_down(msg->netif); + TCPIP_NETIFAPI_ACK(msg); +} + +#if LWIP_DHCP +/** + * @todo comment */ void do_netifapi_dhcp_start( struct netifapi_msg_msg *msg) @@ -158,7 +146,7 @@ do_netifapi_dhcp_start( struct netifapi_msg_msg *msg) } /** - * TODO + * @todo comment */ void do_netifapi_dhcp_stop( struct netifapi_msg_msg *msg) @@ -169,4 +157,26 @@ do_netifapi_dhcp_stop( struct netifapi_msg_msg *msg) } #endif /* LWIP_DHCP */ +#if LWIP_AUTOIP +/** + * @todo comment + */ +void +do_netifapi_autoip_start( struct netifapi_msg_msg *msg) +{ + msg->err = autoip_start(msg->netif); + TCPIP_NETIFAPI_ACK(msg); +} + +/** + * @todo comment + */ +void +do_netifapi_autoip_stop( struct netifapi_msg_msg *msg) +{ + msg->err = autoip_stop(msg->netif); + TCPIP_NETIFAPI_ACK(msg); +} +#endif /* LWIP_AUTOIP */ + #endif /* LWIP_NETIF_API */ diff --git a/src/include/lwip/netifapi.h b/src/include/lwip/netifapi.h index b9bb90e0..063441ad 100644 --- a/src/include/lwip/netifapi.h +++ b/src/include/lwip/netifapi.h @@ -44,7 +44,7 @@ extern "C" { struct netifapi_msg_msg { #if !LWIP_TCPIP_CORE_LOCKING sys_sem_t sem; -#endif /* !LWIP_TCPIP_CORE_LOCKING */ +#endif /* !LWIP_TCPIP_CORE_LOCKING */ err_t err; struct netif *netif; union { @@ -66,29 +66,39 @@ struct netifapi_msg { /* API for application */ -err_t netifapi_netif_add ( struct netif *netif, - struct ip_addr *ipaddr, - struct ip_addr *netmask, - struct ip_addr *gw, - void *state, - err_t (* init)(struct netif *netif), - err_t (* input)(struct pbuf *p, struct netif *netif) ); +err_t netifapi_netif_common ( struct netif *netif, void (* function)(struct netifapi_msg_msg *msg)); -err_t netifapi_netif_remove( struct netif *netif); +err_t netifapi_netif_add ( struct netif *netif, + struct ip_addr *ipaddr, + struct ip_addr *netmask, + struct ip_addr *gw, + void *state, + err_t (* init)(struct netif *netif), + err_t (* input)(struct pbuf *p, struct netif *netif) ); + +#define netifapi_netif_remove(n) netifapi_netif_common(n, do_netifapi_netif_remove) +#define netifapi_netif_set_up(n) netifapi_netif_common(n, do_netifapi_netif_set_up) +#define netifapi_netif_set_down(n) netifapi_netif_common(n, do_netifapi_netif_set_down) +#define netifapi_dhcp_start(n) netifapi_netif_common(n, do_netifapi_dhcp_start) +#define netifapi_dhcp_stop(n) netifapi_netif_common(n, do_netifapi_dhcp_stop) +#define netifapi_autoip_start(n) netifapi_netif_common(n, do_netifapi_autoip_start) +#define netifapi_autoip_stop(n) netifapi_netif_common(n, do_netifapi_autoip_stop) -#if LWIP_DHCP -err_t netifapi_dhcp_start ( struct netif *netif); -err_t netifapi_dhcp_stop ( struct netif *netif); -#endif /* LWIP_DHCP */ /* API for tcpip_thread */ -void do_netifapi_netif_add ( struct netifapi_msg_msg *msg); -void do_netifapi_netif_remove( struct netifapi_msg_msg *msg); - +void do_netifapi_netif_add ( struct netifapi_msg_msg *msg); +void do_netifapi_netif_remove ( struct netifapi_msg_msg *msg); +void do_netifapi_netif_set_up ( struct netifapi_msg_msg *msg); +void do_netifapi_netif_set_down( struct netifapi_msg_msg *msg); #if LWIP_DHCP -void do_netifapi_dhcp_start ( struct netifapi_msg_msg *msg); -void do_netifapi_dhcp_stop ( struct netifapi_msg_msg *msg); +void do_netifapi_dhcp_start ( struct netifapi_msg_msg *msg); +void do_netifapi_dhcp_stop ( struct netifapi_msg_msg *msg); #endif /* LWIP_DHCP */ +#if LWIP_AUTOIP +void do_netifapi_autoip_start ( struct netifapi_msg_msg *msg); +void do_netifapi_autoip_stop ( struct netifapi_msg_msg *msg); +#endif /* LWIP_AUTOIP */ + #ifdef __cplusplus }