diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 10b586c8..ae68221c 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -310,21 +310,13 @@ tcpip_thread(void *arg) msg->msg.apimsg->function(&(msg->msg.apimsg->msg)); break; -#if ETHARP_TCPIP_INPUT +#if ETHARP_TCPIP_INPUT || ETHARP_TCPIP_ETHINPUT case TCPIP_MSG_INPUT: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: IP packet %p\n", (void *)msg)); - ip_input(msg->msg.inp.p, msg->msg.inp.netif); - memp_free(MEMP_TCPIP_MSG, msg); + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg)); + msg->msg.inp.f(msg->msg.inp.p, msg->msg.inp.netif); + memp_free(MEMP_TCPIP_MSG_INPUT, msg); break; -#endif /* ETHARP_TCPIP_INPUT */ - -#if ETHARP_TCPIP_ETHINPUT - case TCPIP_MSG_ETHINPUT: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Ethernet packet %p\n", (void *)msg)); - ethernet_input(msg->msg.inp.p, msg->msg.inp.netif); - memp_free(MEMP_TCPIP_MSG, msg); - break; -#endif /* ETHARP_TCPIP_ETHINPUT */ +#endif /* ETHARP_TCPIP_INPUT || ETHARP_TCPIP_ETHINPUT */ #if LWIP_NETIF_API case TCPIP_MSG_NETIFAPI: @@ -345,6 +337,7 @@ tcpip_thread(void *arg) sys_timeout (msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg); else sys_untimeout (msg->msg.tmo.h, msg->msg.tmo.arg); + memp_free(MEMP_TCPIP_MSG, msg); break; default: break; @@ -365,12 +358,34 @@ tcpip_input(struct pbuf *p, struct netif *inp) struct tcpip_msg *msg; if (mbox != SYS_MBOX_NULL) { - msg = memp_malloc(MEMP_TCPIP_MSG); + msg = memp_malloc(MEMP_TCPIP_MSG_INPUT); if (msg == NULL) { return ERR_MEM; } msg->type = TCPIP_MSG_INPUT; + msg->msg.inp.f = ip_input; + msg->msg.inp.p = p; + msg->msg.inp.netif = inp; + sys_mbox_post(mbox, msg); + return ERR_OK; + } + return ERR_VAL; +} + +err_t +tcpip_input_callback(struct pbuf *p, struct netif *inp, err_t (*f)(struct pbuf *, struct netif *)) +{ + struct tcpip_msg *msg; + + if (mbox != SYS_MBOX_NULL) { + msg = memp_malloc(MEMP_TCPIP_MSG_INPUT); + if (msg == NULL) { + return ERR_MEM; + } + + msg->type = TCPIP_MSG_INPUT; + msg->msg.inp.f = f; msg->msg.inp.p = p; msg->msg.inp.netif = inp; sys_mbox_post(mbox, msg); @@ -390,21 +405,7 @@ tcpip_input(struct pbuf *p, struct netif *inp) err_t tcpip_ethinput(struct pbuf *p, struct netif *inp) { - struct tcpip_msg *msg; - - if (mbox != SYS_MBOX_NULL) { - msg = memp_malloc(MEMP_TCPIP_MSG); - if (msg == NULL) { - return ERR_MEM; - } - - msg->type = TCPIP_MSG_ETHINPUT; - msg->msg.inp.p = p; - msg->msg.inp.netif = inp; - sys_mbox_post(mbox, msg); - return ERR_OK; - } - return ERR_VAL; + return tcpip_input_callback(p, inp, ethernet_input); } #endif /* ETHARP_TCPIP_ETHINPUT */ diff --git a/src/core/memp.c b/src/core/memp.c index 81f7bdcb..fa9f66ff 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -118,6 +118,7 @@ const u16_t memp_sizes[MEMP_MAX] = { MEMP_ALIGN_SIZE(sizeof(struct netbuf)), MEMP_ALIGN_SIZE(sizeof(struct netconn)), MEMP_ALIGN_SIZE(sizeof(struct tcpip_msg)), + MEMP_ALIGN_SIZE(sizeof(struct tcpip_msg)), #if ARP_QUEUEING MEMP_ALIGN_SIZE(sizeof(struct etharp_q_entry)), #endif @@ -141,6 +142,7 @@ static const u16_t memp_num[MEMP_MAX] = { MEMP_NUM_NETBUF, MEMP_NUM_NETCONN, MEMP_NUM_TCPIP_MSG, + MEMP_NUM_TCPIP_MSG_INPUT, #if ARP_QUEUEING MEMP_NUM_ARP_QUEUE, #endif @@ -167,6 +169,7 @@ static u8_t memp_memory[MEM_ALIGNMENT - 1 + MEMP_TYPE_SIZE(MEMP_NUM_NETBUF, struct netbuf) + MEMP_TYPE_SIZE(MEMP_NUM_NETCONN, struct netconn) + MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG, struct tcpip_msg) + + MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG_INPUT, struct tcpip_msg) + #if ARP_QUEUEING MEMP_TYPE_SIZE(MEMP_NUM_ARP_QUEUE, struct etharp_q_entry) + #endif diff --git a/src/include/lwip/memp.h b/src/include/lwip/memp.h index 3f272b4c..01078b28 100644 --- a/src/include/lwip/memp.h +++ b/src/include/lwip/memp.h @@ -51,6 +51,7 @@ typedef enum { MEMP_NETBUF, MEMP_NETCONN, MEMP_TCPIP_MSG, + MEMP_TCPIP_MSG_INPUT, #if ARP_QUEUEING MEMP_ARP_QUEUE, #endif diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index 23ae5ab3..6c00b3f8 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -66,6 +66,7 @@ err_t tcpip_apimsg_lock(struct api_msg *apimsg); #if ETHARP_TCPIP_INPUT err_t tcpip_input(struct pbuf *p, struct netif *inp); +err_t tcpip_input_callback(struct pbuf *p, struct netif *inp, err_t (*f)(struct pbuf *, struct netif *)); #endif /* ETHARP_TCPIP_INPUT */ #if ETHARP_TCPIP_ETHINPUT