Skip to content

Commit 35561c1

Browse files
The process is polled when a udp packet is sent
The application can now use the tcpip_udp_sent_event to know when a udp packet has finished sending. The data for the event also contains the status code from the MAC layer.
1 parent a410f0c commit 35561c1

File tree

10 files changed

+83
-33
lines changed

10 files changed

+83
-33
lines changed

core/net/ip/tcpip.c

+25-8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
7373
#endif
7474

7575
process_event_t tcpip_event;
76+
process_event_t tcpip_udp_sent_event;
7677
#if UIP_CONF_ICMP6
7778
process_event_t tcpip_icmp6_event;
7879
#endif /* UIP_CONF_ICMP6 */
@@ -109,22 +110,22 @@ enum {
109110
/* Called on IP packet output. */
110111
#if NETSTACK_CONF_WITH_IPV6
111112

112-
static uint8_t (* outputfunc)(const uip_lladdr_t *a);
113+
static uint8_t (*outputfunc)(const uip_lladdr_t *a, struct tcpip_sent *sent);
113114

114115
uint8_t
115-
tcpip_output(const uip_lladdr_t *a)
116+
tcpip_output_sent(const uip_lladdr_t *a, struct tcpip_sent *sent)
116117
{
117118
int ret;
118119
if(outputfunc != NULL) {
119-
ret = outputfunc(a);
120+
ret = outputfunc(a, sent);
120121
return ret;
121122
}
122123
UIP_LOG("tcpip_output: Use tcpip_set_outputfunc() to set an output function");
123124
return 0;
124125
}
125126

126127
void
127-
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *))
128+
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *, struct tcpip_sent *))
128129
{
129130
outputfunc = f;
130131
}
@@ -147,7 +148,19 @@ tcpip_set_outputfunc(uint8_t (*f)(void))
147148
outputfunc = f;
148149
}
149150
#endif
151+
/*---------------------------------------------------------------------------*/
152+
static void
153+
tcpip_udp_sent_callback(struct tcpip_sent *sent, int status)
154+
{
155+
struct uip_udp_conn *conn = sent->ptr;
156+
struct tcpip_udp_sent_status data;
157+
158+
data.conn = conn;
159+
data.status = status;
150160

161+
process_post_synch(conn->appstate.p, tcpip_udp_sent_event, &data);
162+
}
163+
/*---------------------------------------------------------------------------*/
151164
#if UIP_CONF_IP_FORWARD
152165
unsigned char tcpip_is_forwarding; /* Forwarding right now? */
153166
#endif /* UIP_CONF_IP_FORWARD */
@@ -321,6 +334,8 @@ udp_new(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
321334
s = &c->appstate;
322335
s->p = PROCESS_CURRENT();
323336
s->state = appstate;
337+
s->sent.ptr = c;
338+
s->sent.callback = tcpip_udp_sent_callback;
324339

325340
return c;
326341
}
@@ -537,7 +552,7 @@ tcpip_input(void)
537552
/*---------------------------------------------------------------------------*/
538553
#if NETSTACK_CONF_WITH_IPV6
539554
void
540-
tcpip_ipv6_output(void)
555+
tcpip_ipv6_output_sent(struct tcpip_sent *sent)
541556
{
542557
uip_ds6_nbr_t *nbr = NULL;
543558
uip_ipaddr_t *nexthop;
@@ -702,7 +717,7 @@ tcpip_ipv6_output(void)
702717
}
703718
#endif /* UIP_ND6_SEND_NA */
704719

705-
tcpip_output(uip_ds6_nbr_get_ll(nbr));
720+
tcpip_output_sent(uip_ds6_nbr_get_ll(nbr), sent);
706721

707722
#if UIP_CONF_IPV6_QUEUE_PKT
708723
/*
@@ -715,7 +730,7 @@ tcpip_ipv6_output(void)
715730
uip_len = uip_packetqueue_buflen(&nbr->packethandle);
716731
memcpy(UIP_IP_BUF, uip_packetqueue_buf(&nbr->packethandle), uip_len);
717732
uip_packetqueue_free(&nbr->packethandle);
718-
tcpip_output(uip_ds6_nbr_get_ll(nbr));
733+
tcpip_output_sent(uip_ds6_nbr_get_ll(nbr), sent);
719734
}
720735
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/
721736

@@ -725,7 +740,7 @@ tcpip_ipv6_output(void)
725740
return;
726741
}
727742
/* Multicast IP destination address. */
728-
tcpip_output(NULL);
743+
tcpip_output_sent(NULL, sent);
729744
uip_len = 0;
730745
uip_ext_len = 0;
731746
}
@@ -808,6 +823,8 @@ PROCESS_THREAD(tcpip_process, ev, data)
808823
#endif
809824

810825
tcpip_event = process_alloc_event();
826+
tcpip_udp_sent_event = process_alloc_event();
827+
811828
#if UIP_CONF_ICMP6
812829
tcpip_icmp6_event = process_alloc_event();
813830
#endif /* UIP_CONF_ICMP6 */

core/net/ip/tcpip.h

+27-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,20 @@
7171

7272
struct uip_conn;
7373

74+
struct tcpip_sent {
75+
void (*callback)(struct tcpip_sent *, int);
76+
void *ptr;
77+
};
78+
79+
struct tcpip_udp_sent_status {
80+
struct uip_udp_conn *conn;
81+
int status;
82+
};
83+
7484
struct tcpip_uipstate {
7585
struct process *p;
7686
void *state;
87+
struct tcpip_sent sent;
7788
};
7889

7990
#define UIP_APPCALL tcpip_uipcall
@@ -275,7 +286,7 @@ struct uip_udp_conn *udp_broadcast_new(uint16_t port, void *appstate);
275286
CCIF void tcpip_poll_udp(struct uip_udp_conn *conn);
276287

277288
/** @} */
278-
289+
279290
/**
280291
* \name ICMPv6 functions
281292
* @{
@@ -319,6 +330,14 @@ void tcpip_icmp6_call(uint8_t type);
319330
* This event is posted to a process whenever a uIP event has occurred.
320331
*/
321332
CCIF extern process_event_t tcpip_event;
333+
/** @} */
334+
/**
335+
* The udp sent event
336+
*
337+
* This event is posted to a process whenever a udp packet has finished sending
338+
* (possibly as a result of error).
339+
*/
340+
CCIF extern process_event_t tcpip_udp_sent_event;
322341

323342
/**
324343
* \name TCP/IP packet processing
@@ -341,8 +360,11 @@ CCIF void tcpip_input(void);
341360
* The eventual parameter is the MAC address of the destination.
342361
*/
343362
#if NETSTACK_CONF_WITH_IPV6
344-
uint8_t tcpip_output(const uip_lladdr_t *);
345-
void tcpip_set_outputfunc(uint8_t (* f)(const uip_lladdr_t *));
363+
uint8_t tcpip_output_sent(const uip_lladdr_t *, struct tcpip_sent *ptr);
364+
#define tcpip_output(addr) tcpip_output_sent(addr,NULL)
365+
void tcpip_set_outputfunc(
366+
uint8_t (*f)(const uip_lladdr_t *, struct tcpip_sent *)
367+
);
346368
#else
347369
uint8_t tcpip_output(void);
348370
void tcpip_set_outputfunc(uint8_t (* f)(void));
@@ -352,7 +374,8 @@ void tcpip_set_outputfunc(uint8_t (* f)(void));
352374
* \brief This function does address resolution and then calls tcpip_output
353375
*/
354376
#if NETSTACK_CONF_WITH_IPV6
355-
void tcpip_ipv6_output(void);
377+
void tcpip_ipv6_output_sent(struct tcpip_sent* sent);
378+
#define tcpip_ipv6_output() tcpip_ipv6_output_sent(NULL)
356379
#endif
357380

358381
/**

core/net/ip/uip-udp-packet.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len)
6767
#endif /* UIP_IPV6_MULTICAST */
6868

6969
#if NETSTACK_CONF_WITH_IPV6
70-
tcpip_ipv6_output();
70+
tcpip_ipv6_output_sent(&(c->appstate.sent));
7171
#else
7272
if(uip_len > 0) {
7373
tcpip_output();

core/net/ipv6/sicslowpan.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,12 @@ packet_sent(void *ptr, int status, int transmissions)
13141314
if(callback != NULL) {
13151315
callback->output_callback(status);
13161316
}
1317+
1318+
if(ptr) {
1319+
struct tcpip_sent *sent = ptr;
1320+
sent->callback(sent, status);
1321+
}
1322+
13171323
last_tx_status = status;
13181324
}
13191325
/*--------------------------------------------------------------------*/
@@ -1323,7 +1329,7 @@ packet_sent(void *ptr, int status, int transmissions)
13231329
* \param dest the link layer destination address of the packet
13241330
*/
13251331
static void
1326-
send_packet(linkaddr_t *dest)
1332+
send_packet(linkaddr_t *dest,struct tcpip_sent *sent)
13271333
{
13281334
/* Set the link layer destination address for the packet as a
13291335
* packetbuf attribute. The MAC layer can access the destination
@@ -1338,7 +1344,7 @@ send_packet(linkaddr_t *dest)
13381344

13391345
/* Provide a callback function to receive the result of
13401346
a packet transmission. */
1341-
NETSTACK_LLSEC.send(&packet_sent, NULL);
1347+
NETSTACK_LLSEC.send(&packet_sent, sent);
13421348

13431349
/* If we are sending multiple packets in a row, we need to let the
13441350
watchdog know that we are still alive. */
@@ -1355,7 +1361,7 @@ send_packet(linkaddr_t *dest)
13551361
* MAC.
13561362
*/
13571363
static uint8_t
1358-
output(const uip_lladdr_t *localdest)
1364+
output(const uip_lladdr_t *localdest, struct tcpip_sent* sent)
13591365
{
13601366
int framer_hdrlen;
13611367
int max_payload;
@@ -1495,7 +1501,7 @@ output(const uip_lladdr_t *localdest)
14951501
PRINTFO("could not allocate queuebuf for first fragment, dropping packet\n");
14961502
return 0;
14971503
}
1498-
send_packet(&dest);
1504+
send_packet(&dest, sent);
14991505
queuebuf_to_packetbuf(q);
15001506
queuebuf_free(q);
15011507
q = NULL;
@@ -1541,7 +1547,7 @@ output(const uip_lladdr_t *localdest)
15411547
PRINTFO("could not allocate queuebuf, dropping fragment\n");
15421548
return 0;
15431549
}
1544-
send_packet(&dest);
1550+
send_packet(&dest, sent);
15451551
queuebuf_to_packetbuf(q);
15461552
queuebuf_free(q);
15471553
q = NULL;
@@ -1568,7 +1574,7 @@ output(const uip_lladdr_t *localdest)
15681574
memcpy(packetbuf_ptr + packetbuf_hdr_len, (uint8_t *)UIP_IP_BUF + uncomp_hdr_len,
15691575
uip_len - uncomp_hdr_len);
15701576
packetbuf_set_datalen(uip_len - uncomp_hdr_len + packetbuf_hdr_len);
1571-
send_packet(&dest);
1577+
send_packet(&dest, sent);
15721578
}
15731579
return 1;
15741580
}

cpu/native/net/tapdev6.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static unsigned long lasttime;
9898
#endif
9999

100100
static void do_send(void);
101-
uint8_t tapdev_send(const uip_lladdr_t *lladdr);
101+
uint8_t tapdev_send(const uip_lladdr_t *lladdr, struct tcpip_sent *sent);
102102

103103
/*---------------------------------------------------------------------------*/
104104
int
@@ -372,7 +372,7 @@ do_send(void)
372372
}
373373
/*---------------------------------------------------------------------------*/
374374
uint8_t
375-
tapdev_send(const uip_lladdr_t *lladdr)
375+
tapdev_send(const uip_lladdr_t *lladdr, struct tcpip_sent *sent)
376376
{
377377
/*
378378
* If L3 dest is multicast, build L2 multicast address

cpu/native/net/tapdev6.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "contiki-net.h"
4040

4141
void tapdev_init(void);
42-
uint8_t tapdev_send(const uip_lladdr_t *lladdr);
42+
uint8_t tapdev_send(const uip_lladdr_t *lladdr, struct tcpip_sent *sent);
4343
uint16_t tapdev_poll(void);
4444
void tapdev_do_send(void);
4545
void tapdev_exit(void); //math

cpu/native/net/wpcap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ wfall_poll(void)
708708
/*---------------------------------------------------------------------------*/
709709
#if NETSTACK_CONF_WITH_IPV6
710710
uint8_t
711-
wpcap_send(const uip_lladdr_t *lladdr)
711+
wpcap_send(const uip_lladdr_t *lladdr, struct tcpip_sent *sent)
712712
{
713713
if(lladdr == NULL) {
714714
/* the dest must be multicast*/

examples/ravenusbstick/fakeuip.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,26 @@ struct uip_stats uip_stat;
1717

1818
uip_lladdr_t uip_lladdr;
1919

20-
static uint8_t (* output)(uip_lladdr_t *);
20+
static uint8_t (* output)(uip_lladdr_t *, struct tcpip_sent *);
2121
extern void mac_LowpanToEthernet(void);
2222
void tcpip_input( void )
2323
{
2424
// printf("tcpip_input");
2525
mac_LowpanToEthernet();
2626
}
2727

28-
uint8_t tcpip_output(const uip_lladdr_t * lladdr){
28+
uint8_t
29+
tcpip_output_sent(const uip_lladdr_t * lladdr, struct tcpip_sent *sent)
30+
{
2931
if(output != NULL) {
30-
return output(lladdr);
32+
return output(lladdr,sent);
3133
}
3234
return 0;
3335
}
3436
//Called from sicslowpan.c
35-
void tcpip_set_outputfunc(uint8_t (* f)(const uip_lladdr_t *)) {
37+
void
38+
tcpip_set_outputfunc(uint8_t (* f)(const uip_lladdr_t *, struct tcpip_sent *))
39+
{
3640
output = f;
3741
}
3842

tools/sky/uip6-bridge/uip6-bridge-tap.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ PROCESS(tcpip_process, "tcpip dummy");
5555
AUTOSTART_PROCESSES(&uip6_bridge);
5656

5757
/*---------------------------------------------------------------------------*/
58-
static uint8_t (* outputfunc)(const uip_lladdr_t *a);
58+
static uint8_t (* outputfunc)(const uip_lladdr_t *a, struct tcpip_sent *);
5959
uint8_t
60-
tcpip_output(const uip_lladdr_t *a)
60+
tcpip_output(const uip_lladdr_t *a, struct tcpip_sent *sent)
6161
{
6262
if(outputfunc != NULL) {
6363
outputfunc(a);
@@ -73,7 +73,7 @@ tcpip_ipv6_output(void)
7373
{
7474
}
7575
void
76-
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *))
76+
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *, struct tcpip_sent *))
7777
{
7878
outputfunc = f;
7979
}

tools/stm32w/uip6_bridge/uip6-bridge-tap.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ PROCESS(tcpip_process, "tcpip dummy");
5757
AUTOSTART_PROCESSES(&uip6_bridge);
5858

5959
/*---------------------------------------------------------------------------*/
60-
static uint8_t (* outputfunc)(const uip_lladdr_t *a);
60+
static uint8_t (* outputfunc)(const uip_lladdr_t *a, struct tcpip_sent *);
6161
uint8_t
62-
tcpip_output(const uip_lladdr_t *a)
62+
tcpip_output(const uip_lladdr_t *a, struct tcpip_sent *sent)
6363
{
6464
if(outputfunc != NULL) {
6565
leds_on(LEDS_GREEN);
@@ -76,7 +76,7 @@ tcpip_ipv6_output(void)
7676
{
7777
}
7878
void
79-
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *))
79+
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *, struct tcpip_sent *))
8080
{
8181
outputfunc = f;
8282
}

0 commit comments

Comments
 (0)