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).

This commit is contained in:
fbernon 2007-10-03 16:54:27 +00:00
parent 5dd1256769
commit 949efb414a
3 changed files with 98 additions and 73 deletions

View File

@ -19,6 +19,11 @@ HISTORY
++ New features: ++ 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 2007-09-15 Frédéric Bernon
* udp.h, udp.c, sockets.c: Changes for "#20503 IGMP Improvement". Add IP_MULTICAST_IF * 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 option in socket API, and a new field "multicast_ip" in "struct udp_pcb" (for

View File

@ -38,6 +38,22 @@
#include "lwip/netifapi.h" #include "lwip/netifapi.h"
#include "lwip/tcpip.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 * Call netif_add() in a thread-safe way by running that function inside the
* tcpip_thread context. * 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 * @todo comment
* 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
*/ */
void void
do_netifapi_netif_add( struct netifapi_msg_msg *msg) 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 void
do_netifapi_netif_remove( struct netifapi_msg_msg *msg) 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); TCPIP_NETIFAPI_ACK(msg);
} }
/**
* @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 #if LWIP_DHCP
/** /**
* TODO * @todo comment
*/ */
void void
do_netifapi_dhcp_start( struct netifapi_msg_msg *msg) 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 void
do_netifapi_dhcp_stop( struct netifapi_msg_msg *msg) 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 */ #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 */ #endif /* LWIP_NETIF_API */

View File

@ -66,6 +66,8 @@ struct netifapi_msg {
/* API for application */ /* API for application */
err_t netifapi_netif_common ( struct netif *netif, void (* function)(struct netifapi_msg_msg *msg));
err_t netifapi_netif_add ( struct netif *netif, err_t netifapi_netif_add ( struct netif *netif,
struct ip_addr *ipaddr, struct ip_addr *ipaddr,
struct ip_addr *netmask, struct ip_addr *netmask,
@ -74,21 +76,29 @@ err_t netifapi_netif_add ( struct netif *netif,
err_t (* init)(struct netif *netif), err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif) ); err_t (* input)(struct pbuf *p, struct netif *netif) );
err_t netifapi_netif_remove( 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 */ /* API for tcpip_thread */
void do_netifapi_netif_add ( 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_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 #if LWIP_DHCP
void do_netifapi_dhcp_start ( 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); void do_netifapi_dhcp_stop ( struct netifapi_msg_msg *msg);
#endif /* LWIP_DHCP */ #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 #ifdef __cplusplus
} }