mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-06 18:41:30 +00: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:
parent
dd1cd5e491
commit
d6fbe45296
@ -238,6 +238,11 @@ HISTORY
|
|||||||
|
|
||||||
++ Bug fixes:
|
++ Bug fixes:
|
||||||
|
|
||||||
|
2007-06-28 Frédéric Bernon
|
||||||
|
* 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...)
|
||||||
|
|
||||||
2007-06-26 Simon Goldschmidt
|
2007-06-26 Simon Goldschmidt
|
||||||
* udp.h: Fixed bug #20259: struct udp_hdr was lacking the packin defines.
|
* udp.h: Fixed bug #20259: struct udp_hdr was lacking the packin defines.
|
||||||
|
|
||||||
|
@ -48,16 +48,16 @@ netifapi_netif_add(struct netif *netif,
|
|||||||
err_t (* input)(struct pbuf *p, struct netif *netif))
|
err_t (* input)(struct pbuf *p, struct netif *netif))
|
||||||
{
|
{
|
||||||
struct netifapi_msg msg;
|
struct netifapi_msg msg;
|
||||||
msg.type = NETIFAPI_MSG_NETIF_ADD;
|
msg.function = do_netifapi_netif_add;
|
||||||
msg.netif = netif;
|
msg.msg.netif = netif;
|
||||||
msg.msg.add.ipaddr = ipaddr;
|
msg.msg.msg.add.ipaddr = ipaddr;
|
||||||
msg.msg.add.netmask = netmask;
|
msg.msg.msg.add.netmask = netmask;
|
||||||
msg.msg.add.gw = gw;
|
msg.msg.msg.add.gw = gw;
|
||||||
msg.msg.add.state = state;
|
msg.msg.msg.add.state = state;
|
||||||
msg.msg.add.init = init;
|
msg.msg.msg.add.init = init;
|
||||||
msg.msg.add.input = input;
|
msg.msg.msg.add.input = input;
|
||||||
TCPIP_APIMSG(&msg);
|
TCPIP_NETIFAPI(&msg);
|
||||||
return msg.err;
|
return msg.msg.err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,12 +70,13 @@ err_t
|
|||||||
netifapi_netif_remove(struct netif *netif)
|
netifapi_netif_remove(struct netif *netif)
|
||||||
{
|
{
|
||||||
struct netifapi_msg msg;
|
struct netifapi_msg msg;
|
||||||
msg.type = NETIFAPI_MSG_NETIF_REMOVE;
|
msg.function = do_netifapi_netif_remove;
|
||||||
msg.netif = netif;
|
msg.msg.netif = netif;
|
||||||
TCPIP_APIMSG(&msg);
|
TCPIP_NETIFAPI(&msg);
|
||||||
return msg.err;
|
return msg.msg.err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LWIP_DHCP
|
||||||
/**
|
/**
|
||||||
* Call dhcp_start() in a thread-safe way by running that function inside the
|
* Call dhcp_start() in a thread-safe way by running that function inside the
|
||||||
* tcpip_thread context.
|
* tcpip_thread context.
|
||||||
@ -86,10 +87,10 @@ err_t
|
|||||||
netifapi_dhcp_start(struct netif *netif)
|
netifapi_dhcp_start(struct netif *netif)
|
||||||
{
|
{
|
||||||
struct netifapi_msg msg;
|
struct netifapi_msg msg;
|
||||||
msg.type = NETIFAPI_MSG_DHCP_START;
|
msg.function = do_netifapi_dhcp_start;
|
||||||
msg.netif = netif;
|
msg.msg.netif = netif;
|
||||||
TCPIP_APIMSG(&msg);
|
TCPIP_NETIFAPI(&msg);
|
||||||
return msg.err;
|
return msg.msg.err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,48 +103,64 @@ err_t
|
|||||||
netifapi_dhcp_stop(struct netif *netif)
|
netifapi_dhcp_stop(struct netif *netif)
|
||||||
{
|
{
|
||||||
struct netifapi_msg msg;
|
struct netifapi_msg msg;
|
||||||
msg.type = NETIFAPI_MSG_DHCP_STOP;
|
msg.function = do_netifapi_dhcp_stop;
|
||||||
msg.netif = netif;
|
msg.msg.netif = netif;
|
||||||
TCPIP_APIMSG(&msg);
|
TCPIP_NETIFAPI(&msg);
|
||||||
return msg.err;
|
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
|
* TODO
|
||||||
* by the above functions.
|
|
||||||
*
|
|
||||||
* It is responsible for doing the actual work inside the thread context
|
|
||||||
* of tcpip_thread.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
netifapi_msg_input(struct netifapi_msg *msg)
|
do_netifapi_dhcp_stop( struct netifapi_msg_msg *msg)
|
||||||
{
|
{
|
||||||
msg->err = ERR_OK;
|
msg->err = ERR_OK;
|
||||||
switch (msg->type) {
|
dhcp_stop(msg->netif);
|
||||||
case NETIFAPI_MSG_NETIF_ADD: {
|
TCPIP_NETIFAPI_ACK(msg);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
#endif /* LWIP_DHCP */
|
||||||
|
|
||||||
#endif /* LWIP_NETIF_API */
|
#endif /* LWIP_NETIF_API */
|
||||||
|
@ -313,7 +313,7 @@ tcpip_thread(void *arg)
|
|||||||
#if LWIP_NETIF_API
|
#if LWIP_NETIF_API
|
||||||
case TCPIP_MSG_NETIFAPI:
|
case TCPIP_MSG_NETIFAPI:
|
||||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Netif API message %p\n", (void *)msg));
|
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;
|
break;
|
||||||
#endif /* LWIP_NETIF_API */
|
#endif /* LWIP_NETIF_API */
|
||||||
|
|
||||||
@ -440,7 +440,7 @@ tcpip_apimsg(struct api_msg *apimsg)
|
|||||||
#if LWIP_TCPIP_CORE_LOCKING
|
#if LWIP_TCPIP_CORE_LOCKING
|
||||||
/**
|
/**
|
||||||
* Call the lower part of a netconn_* function
|
* 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.
|
* before the function is called.
|
||||||
*
|
*
|
||||||
* @param apimsg a struct containing the function to call and its parameters
|
* @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 */
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
#if LWIP_NETIF_API
|
#if LWIP_NETIF_API
|
||||||
|
#if !LWIP_TCPIP_CORE_LOCKING
|
||||||
/**
|
/**
|
||||||
* Much like tcpip_apimsg, but calls the lower part of a netifapi_*
|
* Much like tcpip_apimsg, but calls the lower part of a netifapi_*
|
||||||
* function.
|
* function.
|
||||||
@ -471,21 +472,39 @@ tcpip_netifapi(struct netifapi_msg* netifapimsg)
|
|||||||
struct tcpip_msg msg;
|
struct tcpip_msg msg;
|
||||||
|
|
||||||
if (mbox != SYS_MBOX_NULL) {
|
if (mbox != SYS_MBOX_NULL) {
|
||||||
netifapimsg->sem = sys_sem_new(0);
|
netifapimsg->msg.sem = sys_sem_new(0);
|
||||||
if (netifapimsg->sem == SYS_SEM_NULL) {
|
if (netifapimsg->msg.sem == SYS_SEM_NULL) {
|
||||||
netifapimsg->err = ERR_MEM;
|
netifapimsg->msg.err = ERR_MEM;
|
||||||
return netifapimsg->err;
|
return netifapimsg->msg.err;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.type = TCPIP_MSG_NETIFAPI;
|
msg.type = TCPIP_MSG_NETIFAPI;
|
||||||
msg.msg.netifapimsg = netifapimsg;
|
msg.msg.netifapimsg = netifapimsg;
|
||||||
sys_mbox_post(mbox, &msg);
|
sys_mbox_post(mbox, &msg);
|
||||||
sys_sem_wait(netifapimsg->sem);
|
sys_sem_wait(netifapimsg->msg.sem);
|
||||||
sys_sem_free(netifapimsg->sem);
|
sys_sem_free(netifapimsg->msg.sem);
|
||||||
return netifapimsg->err;
|
return netifapimsg->msg.err;
|
||||||
}
|
}
|
||||||
return ERR_VAL;
|
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 */
|
#endif /* LWIP_NETIF_API */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,18 +40,10 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum netifapi_msg_type {
|
struct netifapi_msg_msg {
|
||||||
NETIFAPI_MSG_NETIF_ADD,
|
#if !LWIP_TCPIP_CORE_LOCKING
|
||||||
NETIFAPI_MSG_NETIF_REMOVE,
|
|
||||||
#if LWIP_DHCP
|
|
||||||
NETIFAPI_MSG_DHCP_START,
|
|
||||||
NETIFAPI_MSG_DHCP_STOP
|
|
||||||
#endif /* LWIP_DHCP */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct netifapi_msg {
|
|
||||||
enum netifapi_msg_type type;
|
|
||||||
sys_sem_t sem;
|
sys_sem_t sem;
|
||||||
|
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
||||||
err_t err;
|
err_t err;
|
||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
union {
|
union {
|
||||||
@ -66,6 +58,11 @@ struct netifapi_msg {
|
|||||||
} msg;
|
} msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct netifapi_msg {
|
||||||
|
void (* function)(struct netifapi_msg_msg *msg);
|
||||||
|
struct netifapi_msg_msg msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* API for application */
|
/* API for application */
|
||||||
err_t netifapi_netif_add ( struct netif *netif,
|
err_t netifapi_netif_add ( struct netif *netif,
|
||||||
@ -78,13 +75,19 @@ err_t netifapi_netif_add ( struct netif *netif,
|
|||||||
|
|
||||||
err_t netifapi_netif_remove( struct netif *netif);
|
err_t netifapi_netif_remove( struct netif *netif);
|
||||||
|
|
||||||
err_t netifapi_dhcp_start ( struct netif *netif);
|
#if LWIP_DHCP
|
||||||
|
err_t netifapi_dhcp_start ( struct netif *netif);
|
||||||
err_t netifapi_dhcp_stop ( struct netif *netif);
|
err_t netifapi_dhcp_stop ( struct netif *netif);
|
||||||
|
#endif /* LWIP_DHCP */
|
||||||
|
|
||||||
/* API for tcpip_thread */
|
/* API for tcpip_thread */
|
||||||
void netifapi_msg_input(struct netifapi_msg *msg);
|
void do_netifapi_netif_add ( struct netifapi_msg_msg *msg);
|
||||||
|
void do_netifapi_netif_remove( 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);
|
||||||
|
#endif /* LWIP_DHCP */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,19 @@ extern "C" {
|
|||||||
#if LWIP_TCPIP_CORE_LOCKING
|
#if LWIP_TCPIP_CORE_LOCKING
|
||||||
/** The global semaphore to lock the stack. */
|
/** The global semaphore to lock the stack. */
|
||||||
extern sys_sem_t lock_tcpip_core;
|
extern sys_sem_t lock_tcpip_core;
|
||||||
#define LOCK_TCPIP_CORE() sys_sem_wait(lock_tcpip_core)
|
#define LOCK_TCPIP_CORE() sys_sem_wait(lock_tcpip_core)
|
||||||
#define UNLOCK_TCPIP_CORE() sys_sem_signal(lock_tcpip_core)
|
#define UNLOCK_TCPIP_CORE() sys_sem_signal(lock_tcpip_core)
|
||||||
#define TCPIP_APIMSG(m) tcpip_apimsg_lock(m)
|
#define TCPIP_APIMSG(m) tcpip_apimsg_lock(m)
|
||||||
#define TCPIP_APIMSG_ACK(m)
|
#define TCPIP_APIMSG_ACK(m)
|
||||||
|
#define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m)
|
||||||
|
#define TCPIP_NETIFAPI_ACK(m)
|
||||||
#else
|
#else
|
||||||
#define LOCK_TCPIP_CORE()
|
#define LOCK_TCPIP_CORE()
|
||||||
#define UNLOCK_TCPIP_CORE()
|
#define UNLOCK_TCPIP_CORE()
|
||||||
#define TCPIP_APIMSG(m) tcpip_apimsg(m)
|
#define TCPIP_APIMSG(m) tcpip_apimsg(m)
|
||||||
#define TCPIP_APIMSG_ACK(m) sys_mbox_post(m->conn->mbox, NULL)
|
#define TCPIP_APIMSG_ACK(m) sys_mbox_post(m->conn->mbox, NULL)
|
||||||
|
#define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
|
||||||
|
#define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(m->sem)
|
||||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
|
void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
|
||||||
@ -59,15 +63,22 @@ err_t tcpip_apimsg(struct api_msg *apimsg);
|
|||||||
#if LWIP_TCPIP_CORE_LOCKING
|
#if LWIP_TCPIP_CORE_LOCKING
|
||||||
err_t tcpip_apimsg_lock(struct api_msg *apimsg);
|
err_t tcpip_apimsg_lock(struct api_msg *apimsg);
|
||||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
#if ETHARP_TCPIP_INPUT
|
#if ETHARP_TCPIP_INPUT
|
||||||
err_t tcpip_input(struct pbuf *p, struct netif *inp);
|
err_t tcpip_input(struct pbuf *p, struct netif *inp);
|
||||||
#endif /* ETHARP_TCPIP_INPUT */
|
#endif /* ETHARP_TCPIP_INPUT */
|
||||||
|
|
||||||
#if ETHARP_TCPIP_ETHINPUT
|
#if ETHARP_TCPIP_ETHINPUT
|
||||||
err_t tcpip_ethinput(struct pbuf *p, struct netif *inp);
|
err_t tcpip_ethinput(struct pbuf *p, struct netif *inp);
|
||||||
#endif /* ETHARP_TCPIP_ETHINPUT */
|
#endif /* ETHARP_TCPIP_ETHINPUT */
|
||||||
|
|
||||||
#if LWIP_NETIF_API
|
#if LWIP_NETIF_API
|
||||||
err_t tcpip_netifapi(struct netifapi_msg* netifapimsg);
|
err_t tcpip_netifapi(struct netifapi_msg *netifapimsg);
|
||||||
|
#if LWIP_TCPIP_CORE_LOCKING
|
||||||
|
err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg);
|
||||||
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
#endif /* LWIP_NETIF_API */
|
#endif /* LWIP_NETIF_API */
|
||||||
|
|
||||||
err_t tcpip_callback(void (*f)(void *ctx), void *ctx);
|
err_t tcpip_callback(void (*f)(void *ctx), void *ctx);
|
||||||
|
|
||||||
enum tcpip_msg_type {
|
enum tcpip_msg_type {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user