diff --git a/CHANGELOG b/CHANGELOG index e26e3e77..9dc0ed2c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -46,6 +46,9 @@ HISTORY ++ Bugfixes: + 2010-01-14: Simon Goldschmidt + * ...: Use typedef for function prototypes throughout the stack. + 2010-01-13: Simon Goldschmidt * api_msg.h/.c, api_lib.c: Fixed bug #26672 (close connection when receive window = 0) by correctly draining recvmbox/acceptmbox diff --git a/src/api/netifapi.c b/src/api/netifapi.c index 57089864..4052f91b 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -42,7 +42,7 @@ * Call netif_add() inside the tcpip_thread context. */ void -do_netifapi_netif_add( struct netifapi_msg_msg *msg) +do_netifapi_netif_add(struct netifapi_msg_msg *msg) { if (!netif_add( msg->netif, msg->msg.add.ipaddr, @@ -62,7 +62,7 @@ do_netifapi_netif_add( struct netifapi_msg_msg *msg) * Call netif_set_addr() inside the tcpip_thread context. */ void -do_netifapi_netif_set_addr( struct netifapi_msg_msg *msg) +do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg) { netif_set_addr( msg->netif, msg->msg.add.ipaddr, @@ -77,11 +77,10 @@ do_netifapi_netif_set_addr( struct netifapi_msg_msg *msg) * tcpip_thread context. */ void -do_netifapi_netif_common( struct netifapi_msg_msg *msg) +do_netifapi_netif_common(struct netifapi_msg_msg *msg) { - if (msg->msg.common.errtfunc!=NULL) { - msg->err = - msg->msg.common.errtfunc(msg->netif); + if (msg->msg.common.errtfunc != NULL) { + msg->err = msg->msg.common.errtfunc(msg->netif); } else { msg->err = ERR_OK; msg->msg.common.voidfunc(msg->netif); @@ -101,8 +100,8 @@ netifapi_netif_add(struct netif *netif, 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)) + netif_init_fn init, + netif_input_fn input) { struct netifapi_msg msg; msg.function = do_netifapi_netif_add; @@ -146,9 +145,8 @@ netifapi_netif_set_addr(struct netif *netif, * @note use only for functions where there is only "netif" parameter. */ err_t -netifapi_netif_common( struct netif *netif, - void (* voidfunc)(struct netif *netif), - err_t (* errtfunc)(struct netif *netif) ) +netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc, + netifapi_errt_fn errtfunc) { struct netifapi_msg msg; msg.function = do_netifapi_netif_common; diff --git a/src/api/tcpip.c b/src/api/tcpip.c index a5e23a8b..9d09ab69 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -50,7 +50,7 @@ #include "netif/ppp_oe.h" /* global variables */ -static void (* tcpip_init_done)(void *arg); +static tcpip_init_done_fn tcpip_init_done; static void *tcpip_init_done_arg; static sys_mbox_t mbox = SYS_MBOX_NULL; @@ -115,7 +115,7 @@ tcpip_thread(void *arg) case TCPIP_MSG_CALLBACK: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg)); - msg->msg.cb.f(msg->msg.cb.ctx); + msg->msg.cb.function(msg->msg.cb.ctx); memp_free(MEMP_TCPIP_MSG_API, msg); break; @@ -178,7 +178,7 @@ tcpip_input(struct pbuf *p, struct netif *inp) * @return ERR_OK if the function was called, another err_t if not */ err_t -tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block) +tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block) { struct tcpip_msg *msg; @@ -189,7 +189,7 @@ tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block) } msg->type = TCPIP_MSG_CALLBACK; - msg->msg.cb.f = f; + msg->msg.cb.function = function; msg->msg.cb.ctx = ctx; if (block) { sys_mbox_post(mbox, msg); @@ -365,7 +365,7 @@ tcpip_netifapi_lock(struct netifapi_msg* netifapimsg) * @param arg argument to pass to initfunc */ void -tcpip_init(void (* initfunc)(void *), void *arg) +tcpip_init(tcpip_init_done_fn initfunc, void *arg) { lwip_init(); diff --git a/src/core/netif.c b/src/core/netif.c index b8cce191..2b903f98 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -90,10 +90,7 @@ struct netif *netif_default; */ struct netif * 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)) + struct ip_addr *gw, void *state, netif_init_fn init, netif_input_fn input) { static u8_t netifnum = 0; @@ -452,7 +449,7 @@ void netif_set_down(struct netif *netif) /** * Set callback to be called when interface is brought up/down */ -void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif )) +void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback) { if (netif) { netif->status_callback = status_callback; @@ -510,7 +507,7 @@ void netif_set_link_down(struct netif *netif ) /** * Set callback to be called when link is brought up/down */ -void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif )) +void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback) { if (netif) { netif->link_callback = link_callback; @@ -589,7 +586,7 @@ netif_loop_output(struct netif *netif, struct pbuf *p, #if LWIP_NETIF_LOOPBACK_MULTITHREADING /* For multithreading environment, schedule a call to netif_poll */ - tcpip_callback((void (*)(void *))(netif_poll), netif); + tcpip_callback((tcpip_callback_fn)netif_poll, netif); #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ return ERR_OK; diff --git a/src/core/raw.c b/src/core/raw.c index d7583827..ffc4c1cb 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -49,7 +49,6 @@ #include "lwip/netif.h" #include "lwip/raw.h" #include "lwip/stats.h" -#include "lwip/snmp.h" #include "arch/perf.h" #include @@ -182,10 +181,7 @@ raw_connect(struct raw_pcb *pcb, struct ip_addr *ipaddr) * available for others. */ void -raw_recv(struct raw_pcb *pcb, - u8_t (* recv)(void *arg, struct raw_pcb *upcb, struct pbuf *p, - struct ip_addr *addr), - void *recv_arg) +raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg) { /* remember recv() callback and user data */ pcb->recv = recv; diff --git a/src/core/tcp.c b/src/core/tcp.c index 27c66012..e341af31 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -218,7 +218,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) u16_t remote_port, local_port; struct ip_addr remote_ip, local_ip; #if LWIP_CALLBACK_API - void (* errf)(void *arg, err_t err); + tcp_err_fn errf; #endif /* LWIP_CALLBACK_API */ void *errf_arg; @@ -516,7 +516,7 @@ tcp_new_port(void) */ err_t tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port, - err_t (* connected)(void *arg, struct tcp_pcb *tpcb, err_t err)) + tcp_connected_fn connected) { err_t ret; u32_t iss; @@ -1118,8 +1118,7 @@ tcp_arg(struct tcp_pcb *pcb, void *arg) * @param recv callback function to call for this pcb when data is received */ void -tcp_recv(struct tcp_pcb *pcb, - err_t (* recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)) +tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv) { pcb->recv = recv; } @@ -1132,8 +1131,7 @@ tcp_recv(struct tcp_pcb *pcb, * @param sent callback function to call for this pcb when data is successfully sent */ void -tcp_sent(struct tcp_pcb *pcb, - err_t (* sent)(void *arg, struct tcp_pcb *tpcb, u16_t len)) +tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) { pcb->sent = sent; } @@ -1143,14 +1141,13 @@ tcp_sent(struct tcp_pcb *pcb, * has occured on the connection. * * @param pcb tcp_pcb to set the err callback - * @param errf callback function to call for this pcb when a fatal error + * @param err callback function to call for this pcb when a fatal error * has occured on the connection */ void -tcp_err(struct tcp_pcb *pcb, - void (* errf)(void *arg, err_t err)) +tcp_err(struct tcp_pcb *pcb, tcp_err_fn err) { - pcb->errf = errf; + pcb->errf = err; } /** @@ -1162,8 +1159,7 @@ tcp_err(struct tcp_pcb *pcb, * connection has been connected to another host */ void -tcp_accept(struct tcp_pcb *pcb, - err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err)) +tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept) { pcb->accept = accept; } @@ -1177,8 +1173,7 @@ tcp_accept(struct tcp_pcb *pcb, * */ void -tcp_poll(struct tcp_pcb *pcb, - err_t (* poll)(void *arg, struct tcp_pcb *tpcb), u8_t interval) +tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval) { #if LWIP_CALLBACK_API pcb->poll = poll; diff --git a/src/core/udp.c b/src/core/udp.c index bede3cc4..661d5487 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -759,10 +759,7 @@ udp_disconnect(struct udp_pcb *pcb) * @param recv_arg additional argument to pass to the callback function */ void -udp_recv(struct udp_pcb *pcb, - void (* recv)(void *arg, struct udp_pcb *upcb, struct pbuf *p, - struct ip_addr *addr, u16_t port), - void *recv_arg) +udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg) { /* remember recv() callback and user data */ pcb->recv = recv; diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index e546a3e1..c5c3cd4e 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -81,10 +81,45 @@ extern "C" { /** if set, the netif has IGMP capability */ #define NETIF_FLAG_IGMP 0x40U +/** Function prototype for netif init functions. Set up flags and output/linkoutput + * callback functions in this function. + * + * @param netif The netif to initialize + */ +typedef err_t (*netif_init_fn)(struct netif *netif); +/** Function prototype for netif->input functions. This function is saved as 'input' + * callback function in the netif struct. Call it when a packet has been received. + * + * @param p The received packet, copied into a pbuf + * @param inp The netif which received the packet + */ +typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); +/** Function prototype for netif->output functions. Called by lwIP when a packet + * shall be sent. For ethernet netif, set this to 'etharp_output' and set + * 'linkoutput'. + * + * @param netif The netif which shall send a packet + * @param p The packet to send (p->payload points to IP header) + * @param ipaddr The IP address to which the packet shall be sent + */ +typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, + struct ip_addr *ipaddr); +/** Function prototype for netif->linkoutput functions. Only used for ethernet + * netifs. This function is called by ARP when a packet shall be sent. + * + * @param netif The netif which shall send a packet + * @param p The packet to send (raw ethernet packet) + */ +typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); +/** Function prototype for netif status- or link-callback functions. */ +typedef void (*netif_status_callback_fn)(struct netif *netif); +/** Function prototype for netif igmp_mac_filter functions */ +typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, + struct ip_addr *group, u8_t action); + /** Generic data structure used for all lwIP network interfaces. * The following fields should be filled in by the initialization * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ - struct netif { /** pointer to next in linked list */ struct netif *next; @@ -96,25 +131,24 @@ struct netif { /** This function is called by the network device driver * to pass a packet up the TCP/IP stack. */ - err_t (* input)(struct pbuf *p, struct netif *inp); + netif_input_fn input; /** This function is called by the IP module when it wants * to send a packet on the interface. This function typically * first resolves the hardware address, then sends the packet. */ - err_t (* output)(struct netif *netif, struct pbuf *p, - struct ip_addr *ipaddr); + netif_output_fn output; /** This function is called by the ARP module when it wants * to send a packet on the interface. This function outputs * the pbuf as-is on the link medium. */ - err_t (* linkoutput)(struct netif *netif, struct pbuf *p); + netif_linkoutput_fn linkoutput; #if LWIP_NETIF_STATUS_CALLBACK /** This function is called when the netif state is set to up or down */ - void (* status_callback)(struct netif *netif); + netif_status_callback_fn status_callback; #endif /* LWIP_NETIF_STATUS_CALLBACK */ #if LWIP_NETIF_LINK_CALLBACK /** This function is called when the netif link is set to up or down */ - void (* link_callback)(struct netif *netif); + netif_status_callback_fn link_callback; #endif /* LWIP_NETIF_LINK_CALLBACK */ /** This field can be set by the device driver and could point * to state information for the device. */ @@ -161,8 +195,9 @@ struct netif { u32_t ifoutdiscards; #endif /* LWIP_SNMP */ #if LWIP_IGMP - /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/ - err_t (*igmp_mac_filter)(struct netif *netif, struct ip_addr *group, u8_t action); + /** This function could be called to add or delete a entry in the multicast + filter table of the ethernet MAC.*/ + netif_igmp_mac_filter_fn igmp_mac_filter; #endif /* LWIP_IGMP */ #if LWIP_NETIF_HWADDRHINT u8_t *addr_hint; @@ -205,10 +240,7 @@ extern struct netif *netif_default; #define netif_init() /* Compatibility define, no init needed. */ struct netif *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)); + struct ip_addr *gw, void *state, netif_init_fn init, netif_input_fn input); void netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask, @@ -236,7 +268,7 @@ void netif_set_down(struct netif *netif); /* * Set callback to be called when interface is brought up/down */ -void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif)); +void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ #if LWIP_NETIF_LINK_CALLBACK @@ -245,7 +277,7 @@ void netif_set_link_down(struct netif *netif); /** Ask if a link is up */ #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) -void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif)); +void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback); #endif /* LWIP_NETIF_LINK_CALLBACK */ #if ENABLE_LOOPBACK diff --git a/src/include/lwip/netifapi.h b/src/include/lwip/netifapi.h index 4145dd74..bd004ff6 100644 --- a/src/include/lwip/netifapi.h +++ b/src/include/lwip/netifapi.h @@ -41,6 +41,9 @@ extern "C" { #endif +typedef void (*netifapi_void_fn)(struct netif *netif); +typedef err_t (*netifapi_errt_fn)(struct netif *netif); + struct netifapi_msg_msg { #if !LWIP_TCPIP_CORE_LOCKING sys_sem_t sem; @@ -53,12 +56,12 @@ struct netifapi_msg_msg { 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); + netif_init_fn init; + netif_input_fn input; } add; struct { - void (* voidfunc)(struct netif *netif); - err_t (* errtfunc)(struct netif *netif); + netifapi_void_fn voidfunc; + netifapi_errt_fn errtfunc; } common; } msg; }; @@ -75,8 +78,8 @@ err_t netifapi_netif_add ( struct netif *netif, 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) ); + netif_init_fn init, + netif_input_fn input); err_t netifapi_netif_set_addr ( struct netif *netif, struct ip_addr *ipaddr, @@ -84,8 +87,8 @@ err_t netifapi_netif_set_addr ( struct netif *netif, struct ip_addr *gw ); err_t netifapi_netif_common ( struct netif *netif, - void (* voidfunc)(struct netif *netif), - err_t (* errtfunc)(struct netif *netif) ); + netifapi_void_fn voidfunc, + netifapi_errt_fn errtfunc); #define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL) #define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL) diff --git a/src/include/lwip/raw.h b/src/include/lwip/raw.h index 20b0a11b..395f7dbd 100644 --- a/src/include/lwip/raw.h +++ b/src/include/lwip/raw.h @@ -45,26 +45,31 @@ extern "C" { #endif +struct raw_pcb; + +/** Function prototype for raw pcb receive callback functions. + * @param arg user supplied argument (raw_pcb.recv_arg) + * @param pcb the raw_pcb which received data + * @param p the packet buffer that was received + * @param addr the remote IP address from which the packet was received + * @return 1 if the packet was 'eaten' (aka. deleted), + * 0 if the packet lives on + * If returning 1, the callback is responsible for freeing the pbuf + * if it's not used any more. + */ +typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p, + struct ip_addr *addr); + struct raw_pcb { -/* Common members of all PCB types */ + /* Common members of all PCB types */ IP_PCB; struct raw_pcb *next; u8_t protocol; - /* receive callback function - * @param arg user supplied argument (raw_pcb.recv_arg) - * @param pcb the raw_pcb which received data - * @param p the packet buffer that was received - * @param addr the remote IP address from which the packet was received - * @return 1 if the packet was 'eaten' (aka. deleted), - * 0 if the packet lives on - * If returning 1, the callback is responsible for freeing the pbuf - * if it's not used any more. - */ - u8_t (* recv)(void *arg, struct raw_pcb *pcb, struct pbuf *p, - struct ip_addr *addr); + /** receive callback function */ + raw_recv_fn recv; /* user-supplied argument for the recv callback */ void *recv_arg; }; @@ -76,11 +81,7 @@ void raw_remove (struct raw_pcb *pcb); err_t raw_bind (struct raw_pcb *pcb, struct ip_addr *ipaddr); err_t raw_connect (struct raw_pcb *pcb, struct ip_addr *ipaddr); -void raw_recv (struct raw_pcb *pcb, - u8_t (* recv)(void *arg, struct raw_pcb *pcb, - struct pbuf *p, - struct ip_addr *addr), - void *recv_arg); +void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg); err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr); err_t raw_send (struct raw_pcb *pcb, struct pbuf *p); diff --git a/src/include/lwip/sys.h b/src/include/lwip/sys.h index 96231ed1..65c00e1c 100644 --- a/src/include/lwip/sys.h +++ b/src/include/lwip/sys.h @@ -75,6 +75,9 @@ typedef u8_t sys_mbox_t; #include "lwip/err.h" #include "arch/sys_arch.h" +/** Function prototype for thread functions */ +typedef void (*lwip_thread_fn)(void *arg); + /* Semaphore functions. */ sys_sem_t sys_sem_new(u8_t count); void sys_sem_signal(sys_sem_t sem); @@ -103,7 +106,7 @@ void sys_mbox_free(sys_mbox_t mbox); #define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0) /* Thread functions. */ -sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio); +sys_thread_t sys_thread_new(char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio); #endif /* NO_SYS */ diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index e70e9b73..7cb86ab5 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -49,6 +49,71 @@ extern "C" { struct tcp_pcb; +/** Function prototype for tcp accept callback functions. Called when a new + * connection can be accepted on a listening pcb. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param newpcb The new connection pcb + * @param err An error code if there has been an error accepting + */ +typedef err_t (*tcp_accept_fn)(void *arg, struct tcp_pcb *newpcb, err_t err); + +/** Function prototype for tcp receive callback functions. Called when data has + * been received. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb The connection pcb which received data + * @param p The received data (or NULL when the connection has been closed!) + * @param err An error code if there has been an error receiving + */ +typedef err_t (*tcp_recv_fn)(void *arg, struct tcp_pcb *tpcb, + struct pbuf *p, err_t err); + +/** Function prototype for tcp sent callback functions. Called when sent data has + * been acknowledged by the remote side. Use it to free corresponding resources. + * This also means that the pcb has now space available to send new data. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb The connection pcb for which data has been acknowledged + * @param len The amount of bytes acknowledged + * @return ERR_OK: try to send some data by calling tcp_output + */ +typedef err_t (*tcp_sent_fn)(void *arg, struct tcp_pcb *tpcb, + u16_t len); + +/** Function prototype for tcp poll callback functions. Called periodically as + * specified by @see tcp_poll. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb tcp pcb + * @return ERR_OK: try to send some data by calling tcp_output + */ +typedef err_t (*tcp_poll_fn)(void *arg, struct tcp_pcb *tpcb); + +/** Function prototype for tcp error callback functions. Called when the pcb + * receives a RST or is unexpectedly closed for any other reason. + * + * @note The corresponding pcb is already freed when this callback is called! + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param err Error code to indicate why the pcb has been closed + * ERR_ABRT: aborted through tcp_abort or by a TCP timer + * ERR_RST: the connection was reset by the remote host + */ +typedef void (*tcp_err_fn)(void *arg, err_t err); + +/** Function prototype for tcp connected callback functions. Called when a pcb + * is connected to the remote side after initiating a connection attempt by + * calling tcp_connect(). + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb The connection pcb which is connected + * @param err An unused error code, always ERR_OK currently ;-) TODO! + * + * @note When a connection attempt fails, the error callback is currently called! + */ +typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err); + /* Functions for interfacing with TCP: */ /* Lower layer interface to TCP: */ @@ -61,20 +126,11 @@ struct tcp_pcb * tcp_new (void); struct tcp_pcb * tcp_alloc (u8_t prio); void tcp_arg (struct tcp_pcb *pcb, void *arg); -void tcp_accept (struct tcp_pcb *pcb, - err_t (* accept)(void *arg, struct tcp_pcb *newpcb, - err_t err)); -void tcp_recv (struct tcp_pcb *pcb, - err_t (* recv)(void *arg, struct tcp_pcb *tpcb, - struct pbuf *p, err_t err)); -void tcp_sent (struct tcp_pcb *pcb, - err_t (* sent)(void *arg, struct tcp_pcb *tpcb, - u16_t len)); -void tcp_poll (struct tcp_pcb *pcb, - err_t (* poll)(void *arg, struct tcp_pcb *tpcb), - u8_t interval); -void tcp_err (struct tcp_pcb *pcb, - void (* err)(void *arg, err_t err)); +void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept); +void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv); +void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent); +void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval); +void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err); #define tcp_mss(pcb) ((pcb)->mss) #define tcp_sndbuf(pcb) ((pcb)->snd_buf) @@ -92,9 +148,7 @@ void tcp_recved (struct tcp_pcb *pcb, u16_t len); err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port); err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr, - u16_t port, err_t (* connected)(void *arg, - struct tcp_pcb *tpcb, - err_t err)); + u16_t port, tcp_connected_fn connected); struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog); #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG) @@ -271,7 +325,7 @@ enum tcp_state { * @return ERR_OK: accept the new connection, * any other err_t abortsthe new connection */ -#define DEF_ACCEPT_CALLBACK err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err) +#define DEF_ACCEPT_CALLBACK tcp_accept_fn accept #else /* LWIP_CALLBACK_API */ #define DEF_ACCEPT_CALLBACK #endif /* LWIP_CALLBACK_API */ @@ -366,49 +420,16 @@ struct tcp_pcb { struct pbuf *refused_data; /* Data previously received but not yet taken by upper layer */ #if LWIP_CALLBACK_API - /* Function to be called when more send buffer space is available. - * @param arg user-supplied argument (tcp_pcb.callback_arg) - * @param pcb the tcp_pcb which has send buffer space available - * @param space the amount of bytes available - * @return ERR_OK: try to send some data by calling tcp_output - */ - err_t (* sent)(void *arg, struct tcp_pcb *pcb, u16_t space); - - /* Function to be called when (in-sequence) data has arrived. - * @param arg user-supplied argument (tcp_pcb.callback_arg) - * @param pcb the tcp_pcb for which data has arrived - * @param p the packet buffer which arrived - * @param err an error argument (TODO: that is current always ERR_OK?) - * @return ERR_OK: try to send some data by calling tcp_output - */ - err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); - - /* Function to be called when a connection has been set up. - * @param arg user-supplied argument (tcp_pcb.callback_arg) - * @param pcb the tcp_pcb that now is connected - * @param err an error argument (TODO: that is current always ERR_OK?) - * @return value is currently ignored - */ - err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err); - - /* Function which is called periodically. - * The period can be adjusted in multiples of the TCP slow timer interval - * by changing tcp_pcb.polltmr. - * @param arg user-supplied argument (tcp_pcb.callback_arg) - * @param pcb the tcp_pcb to poll for - * @return ERR_OK: try to send some data by calling tcp_output - */ - err_t (* poll)(void *arg, struct tcp_pcb *pcb); - - /* Function to be called whenever a fatal error occurs. - * There is no pcb parameter since most of the times, the pcb is - * already deallocated (or there is no pcb) when this function is called. - * @param arg user-supplied argument (tcp_pcb.callback_arg) - * @param err an indication why the error callback is called: - * ERR_ABRT: aborted through tcp_abort or by a TCP timer - * ERR_RST: the connection was reset by the remote host - */ - void (* errf)(void *arg, err_t err); + /* Function to be called when more send buffer space is available. */ + tcp_sent_fn sent; + /* Function to be called when (in-sequence) data has arrived. */ + tcp_recv_fn recv; + /* Function to be called when a connection has been set up. */ + tcp_connected_fn connected; + /* Function which is called periodically. */ + tcp_poll_fn poll; + /* Function to be called whenever a fatal error occurs. */ + tcp_err_fn errf; #endif /* LWIP_CALLBACK_API */ #if LWIP_TCP_TIMESTAMPS diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index 69016022..464a48ee 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -66,7 +66,12 @@ extern sys_sem_t lock_tcpip_core; #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(m->sem) #endif /* LWIP_TCPIP_CORE_LOCKING */ -void tcpip_init(void (* tcpip_init_done)(void *), void *arg); +/** Function prototype for the init_done function passed to tcpip_init */ +typedef void (*tcpip_init_done_fn)(void *arg); +/** Function prototype for functions passed to tcpip_callback() */ +typedef void (*tcpip_callback_fn)(void *ctx); + +void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg); #if LWIP_NETCONN err_t tcpip_apimsg(struct api_msg *apimsg); @@ -84,7 +89,7 @@ err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg); #endif /* LWIP_TCPIP_CORE_LOCKING */ #endif /* LWIP_NETIF_API */ -err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block); +err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block); #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) /* free pbufs or heap memory from another context without blocking */ @@ -122,7 +127,7 @@ struct tcpip_msg { struct netif *netif; } inp; struct { - void (*f)(void *ctx); + tcpip_callback_fn function; void *ctx; } cb; struct { diff --git a/src/include/lwip/timers.h b/src/include/lwip/timers.h index f54f9fc7..3268edd2 100644 --- a/src/include/lwip/timers.h +++ b/src/include/lwip/timers.h @@ -50,6 +50,11 @@ extern "C" { #endif /* LWIP_DEBUG*/ #endif +/** Function prototype for a timeout callback function. Register such a function + * using sys_timeout(). + * + * @param arg Additional argument to pass to the function - set up by sys_timeout() + */ typedef void (* sys_timeout_handler)(void *arg); struct sys_timeo { diff --git a/src/include/lwip/udp.h b/src/include/lwip/udp.h index 08d1817b..6186c3cd 100644 --- a/src/include/lwip/udp.h +++ b/src/include/lwip/udp.h @@ -67,6 +67,26 @@ PACK_STRUCT_END #define UDP_FLAGS_UDPLITE 0x02U #define UDP_FLAGS_CONNECTED 0x04U +struct udp_pcb; + +/** Function prototype for udp pcb receive callback functions + * addr and port are in same byte order as in the pcb + * The callback is responsible for freeing the pbuf + * if it's not used any more. + * + * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf + * makes 'addr' invalid, too. + * + * @param arg user supplied argument (udp_pcb.recv_arg) + * @param pcb the udp_pcb which received data + * @param p the packet buffer that was received + * @param addr the remote IP address from which the packet was received + * @param port the remote port from which the packet was received + */ +typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p, + struct ip_addr *addr, u16_t port); + + struct udp_pcb { /* Common members of all PCB types */ IP_PCB; @@ -76,36 +96,22 @@ struct udp_pcb { struct udp_pcb *next; u8_t flags; - /* ports are in host byte order */ + /** ports are in host byte order */ u16_t local_port, remote_port; #if LWIP_IGMP - /* outgoing network interface for multicast packets */ + /** outgoing network interface for multicast packets */ struct ip_addr multicast_ip; #endif /* LWIP_IGMP */ #if LWIP_UDPLITE - /* used for UDP_LITE only */ + /** used for UDP_LITE only */ u16_t chksum_len_rx, chksum_len_tx; #endif /* LWIP_UDPLITE */ - /* receive callback function - * addr and port are in same byte order as in the pcb - * The callback is responsible for freeing the pbuf - * if it's not used any more. - * - * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf - * makes 'addr' invalid, too. - * - * @param arg user supplied argument (udp_pcb.recv_arg) - * @param pcb the udp_pcb which received data - * @param p the packet buffer that was received - * @param addr the remote IP address from which the packet was received - * @param port the remote port from which the packet was received - */ - void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p, - struct ip_addr *addr, u16_t port); - /* user-supplied argument for the recv callback */ + /** receive callback function */ + udp_recv_fn recv; + /** user-supplied argument for the recv callback */ void *recv_arg; }; /* udp_pcbs export for exernal reference (e.g. SNMP agent) */ @@ -116,21 +122,20 @@ extern struct udp_pcb *udp_pcbs; struct udp_pcb * udp_new (void); void udp_remove (struct udp_pcb *pcb); err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr, - u16_t port); + u16_t port); err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr, - u16_t port); -void udp_disconnect (struct udp_pcb *pcb); -void udp_recv (struct udp_pcb *pcb, - void (* recv)(void *arg, struct udp_pcb *upcb, - struct pbuf *p, - struct ip_addr *addr, - u16_t port), - void *recv_arg); -err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port, struct netif *netif); -err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port); + u16_t port); +void udp_disconnect (struct udp_pcb *pcb); +void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, + void *recv_arg); +err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, + struct ip_addr *dst_ip, u16_t dst_port, + struct netif *netif); +err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, + struct ip_addr *dst_ip, u16_t dst_port); err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); -#define udp_flags(pcb) ((pcb)->flags) +#define udp_flags(pcb) ((pcb)->flags) #define udp_setflags(pcb, f) ((pcb)->flags = (f)) /* The following functions are the lower layer interface to UDP. */