mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-17 05:36:46 +08:00
netifapi.h, netifapi.c, tcpip.h, tcpip.c: Update code to handle the option LWIP_TCPIP_CORE_LOCKING, and do some changes to be coherent with last modifications in api_lib/api_msg (use pointers and not type with table, etc...)
This commit is contained in:
@@ -48,16 +48,16 @@ netifapi_netif_add(struct netif *netif,
|
||||
err_t (* input)(struct pbuf *p, struct netif *netif))
|
||||
{
|
||||
struct netifapi_msg msg;
|
||||
msg.type = NETIFAPI_MSG_NETIF_ADD;
|
||||
msg.netif = netif;
|
||||
msg.msg.add.ipaddr = ipaddr;
|
||||
msg.msg.add.netmask = netmask;
|
||||
msg.msg.add.gw = gw;
|
||||
msg.msg.add.state = state;
|
||||
msg.msg.add.init = init;
|
||||
msg.msg.add.input = input;
|
||||
TCPIP_APIMSG(&msg);
|
||||
return msg.err;
|
||||
msg.function = do_netifapi_netif_add;
|
||||
msg.msg.netif = netif;
|
||||
msg.msg.msg.add.ipaddr = ipaddr;
|
||||
msg.msg.msg.add.netmask = netmask;
|
||||
msg.msg.msg.add.gw = gw;
|
||||
msg.msg.msg.add.state = state;
|
||||
msg.msg.msg.add.init = init;
|
||||
msg.msg.msg.add.input = input;
|
||||
TCPIP_NETIFAPI(&msg);
|
||||
return msg.msg.err;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,12 +70,13 @@ err_t
|
||||
netifapi_netif_remove(struct netif *netif)
|
||||
{
|
||||
struct netifapi_msg msg;
|
||||
msg.type = NETIFAPI_MSG_NETIF_REMOVE;
|
||||
msg.netif = netif;
|
||||
TCPIP_APIMSG(&msg);
|
||||
return msg.err;
|
||||
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.
|
||||
@@ -86,10 +87,10 @@ err_t
|
||||
netifapi_dhcp_start(struct netif *netif)
|
||||
{
|
||||
struct netifapi_msg msg;
|
||||
msg.type = NETIFAPI_MSG_DHCP_START;
|
||||
msg.netif = netif;
|
||||
TCPIP_APIMSG(&msg);
|
||||
return msg.err;
|
||||
msg.function = do_netifapi_dhcp_start;
|
||||
msg.msg.netif = netif;
|
||||
TCPIP_NETIFAPI(&msg);
|
||||
return msg.msg.err;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,48 +103,64 @@ err_t
|
||||
netifapi_dhcp_stop(struct netif *netif)
|
||||
{
|
||||
struct netifapi_msg msg;
|
||||
msg.type = NETIFAPI_MSG_DHCP_STOP;
|
||||
msg.netif = netif;
|
||||
TCPIP_APIMSG(&msg);
|
||||
return msg.err;
|
||||
msg.function = do_netifapi_dhcp_stop;
|
||||
msg.msg.netif = netif;
|
||||
TCPIP_NETIFAPI(&msg);
|
||||
return msg.msg.err;
|
||||
}
|
||||
#endif /* LWIP_DHCP */
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
void
|
||||
do_netifapi_netif_add( struct netifapi_msg_msg *msg)
|
||||
{
|
||||
msg->err = ERR_OK;
|
||||
if (!netif_add( msg->netif,
|
||||
msg->msg.add.ipaddr,
|
||||
msg->msg.add.netmask,
|
||||
msg->msg.add.gw,
|
||||
msg->msg.add.state,
|
||||
msg->msg.add.init,
|
||||
msg->msg.add.input)) {
|
||||
msg->err = ERR_IF;
|
||||
}
|
||||
TCPIP_NETIFAPI_ACK(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
void
|
||||
do_netifapi_netif_remove( struct netifapi_msg_msg *msg)
|
||||
{
|
||||
msg->err = ERR_OK;
|
||||
netif_remove(msg->netif);
|
||||
TCPIP_NETIFAPI_ACK(msg);
|
||||
}
|
||||
|
||||
#if LWIP_DHCP
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
void
|
||||
do_netifapi_dhcp_start( struct netifapi_msg_msg *msg)
|
||||
{
|
||||
msg->err = dhcp_start(msg->netif);
|
||||
TCPIP_NETIFAPI_ACK(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function processes the messages posted to the tcpip_thread
|
||||
* by the above functions.
|
||||
*
|
||||
* It is responsible for doing the actual work inside the thread context
|
||||
* of tcpip_thread.
|
||||
* TODO
|
||||
*/
|
||||
void
|
||||
netifapi_msg_input(struct netifapi_msg *msg)
|
||||
{
|
||||
do_netifapi_dhcp_stop( struct netifapi_msg_msg *msg)
|
||||
{
|
||||
msg->err = ERR_OK;
|
||||
switch (msg->type) {
|
||||
case NETIFAPI_MSG_NETIF_ADD: {
|
||||
if (!netif_add( msg->netif,
|
||||
msg->msg.add.ipaddr,
|
||||
msg->msg.add.netmask,
|
||||
msg->msg.add.gw,
|
||||
msg->msg.add.state,
|
||||
msg->msg.add.init,
|
||||
msg->msg.add.input))
|
||||
msg->err = ERR_IF;
|
||||
break;
|
||||
}
|
||||
case NETIFAPI_MSG_NETIF_REMOVE:
|
||||
netif_remove(msg->netif);
|
||||
break;
|
||||
#if LWIP_DHCP
|
||||
case NETIFAPI_MSG_DHCP_START:
|
||||
msg->err = dhcp_start(msg->netif);
|
||||
break;
|
||||
case NETIFAPI_MSG_DHCP_STOP:
|
||||
dhcp_stop(msg->netif);
|
||||
break;
|
||||
#endif /* LWIP_DHCP */
|
||||
}
|
||||
sys_sem_signal(msg->sem);
|
||||
dhcp_stop(msg->netif);
|
||||
TCPIP_NETIFAPI_ACK(msg);
|
||||
}
|
||||
#endif /* LWIP_DHCP */
|
||||
|
||||
#endif /* LWIP_NETIF_API */
|
||||
|
||||
@@ -313,7 +313,7 @@ tcpip_thread(void *arg)
|
||||
#if LWIP_NETIF_API
|
||||
case TCPIP_MSG_NETIFAPI:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Netif API message %p\n", (void *)msg));
|
||||
netifapi_msg_input(msg->msg.netifapimsg);
|
||||
msg->msg.netifapimsg->function(&(msg->msg.netifapimsg->msg));
|
||||
break;
|
||||
#endif /* LWIP_NETIF_API */
|
||||
|
||||
@@ -440,7 +440,7 @@ tcpip_apimsg(struct api_msg *apimsg)
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
/**
|
||||
* Call the lower part of a netconn_* function
|
||||
* This function ihas exclusive access to lwIP core code by locking it
|
||||
* This function has exclusive access to lwIP core code by locking it
|
||||
* before the function is called.
|
||||
*
|
||||
* @param apimsg a struct containing the function to call and its parameters
|
||||
@@ -458,6 +458,7 @@ tcpip_apimsg_lock(struct api_msg *apimsg)
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
#if LWIP_NETIF_API
|
||||
#if !LWIP_TCPIP_CORE_LOCKING
|
||||
/**
|
||||
* Much like tcpip_apimsg, but calls the lower part of a netifapi_*
|
||||
* function.
|
||||
@@ -471,21 +472,39 @@ tcpip_netifapi(struct netifapi_msg* netifapimsg)
|
||||
struct tcpip_msg msg;
|
||||
|
||||
if (mbox != SYS_MBOX_NULL) {
|
||||
netifapimsg->sem = sys_sem_new(0);
|
||||
if (netifapimsg->sem == SYS_SEM_NULL) {
|
||||
netifapimsg->err = ERR_MEM;
|
||||
return netifapimsg->err;
|
||||
netifapimsg->msg.sem = sys_sem_new(0);
|
||||
if (netifapimsg->msg.sem == SYS_SEM_NULL) {
|
||||
netifapimsg->msg.err = ERR_MEM;
|
||||
return netifapimsg->msg.err;
|
||||
}
|
||||
|
||||
msg.type = TCPIP_MSG_NETIFAPI;
|
||||
msg.msg.netifapimsg = netifapimsg;
|
||||
sys_mbox_post(mbox, &msg);
|
||||
sys_sem_wait(netifapimsg->sem);
|
||||
sys_sem_free(netifapimsg->sem);
|
||||
return netifapimsg->err;
|
||||
sys_sem_wait(netifapimsg->msg.sem);
|
||||
sys_sem_free(netifapimsg->msg.sem);
|
||||
return netifapimsg->msg.err;
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
#else /* !LWIP_TCPIP_CORE_LOCKING */
|
||||
/**
|
||||
* Call the lower part of a netifapi_* function
|
||||
* This function has exclusive access to lwIP core code by locking it
|
||||
* before the function is called.
|
||||
*
|
||||
* @param netifapimsg a struct containing the function to call and its parameters
|
||||
* @return ERR_OK (only for compatibility fo tcpip_netifapi())
|
||||
*/
|
||||
err_t
|
||||
tcpip_netifapi_lock(struct netifapi_msg* netifapimsg)
|
||||
{
|
||||
LOCK_TCPIP_CORE();
|
||||
netifapimsg->function(&(netifapimsg->msg));
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return netifapimsg->msg.err;
|
||||
}
|
||||
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
||||
#endif /* LWIP_NETIF_API */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user