Contiki 2.5
tcpip.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  *
32  * $Id: tcpip.c,v 1.30 2010/10/29 05:36:07 adamdunkels Exp $
33  */
34 /**
35  * \file
36  * Code for tunnelling uIP packets over the Rime mesh routing module
37  *
38  * \author Adam Dunkels <adam@sics.se>\author
39  * \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
40  * \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
41  */
42 #include "contiki-net.h"
43 
44 #include "net/uip-split.h"
45 
46 #include "net/uip-packetqueue.h"
47 
48 #include <string.h>
49 
50 #if UIP_CONF_IPV6
51 #include "net/uip-nd6.h"
52 #include "net/uip-ds6.h"
53 #endif
54 
55 #define DEBUG 0
56 #if DEBUG
57 #include <stdio.h>
58 #define PRINTF(...) printf(__VA_ARGS__)
59 #define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
60 #define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5])
61 #else
62 #define PRINTF(...)
63 #define PRINT6ADDR(addr)
64 #endif
65 
66 #if UIP_LOGGING
67 #include <stdio.h>
68 void uip_log(char *msg);
69 #define UIP_LOG(m) uip_log(m)
70 #else
71 #define UIP_LOG(m)
72 #endif
73 
74 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len])
75 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
76 #define UIP_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
77 
78 #ifdef UIP_FALLBACK_INTERFACE
79 extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
80 #endif
81 #if UIP_CONF_IPV6_RPL
82 void rpl_init(void);
83 #endif
84 process_event_t tcpip_event;
85 #if UIP_CONF_ICMP6
86 process_event_t tcpip_icmp6_event;
87 #endif /* UIP_CONF_ICMP6 */
88 
89 /*static struct tcpip_event_args ev_args;*/
90 
91 /*periodic check of active connections*/
92 static struct etimer periodic;
93 
94 #if UIP_CONF_IPV6 && UIP_CONF_IPV6_REASSEMBLY
95 /*timer for reassembly*/
96 extern struct etimer uip_reass_timer;
97 #endif
98 
99 #if UIP_TCP
100 /**
101  * \internal Structure for holding a TCP port and a process ID.
102  */
103 struct listenport {
104  u16_t port;
105  struct process *p;
106 };
107 
108 static struct internal_state {
109  struct listenport listenports[UIP_LISTENPORTS];
110  struct process *p;
111 } s;
112 #endif
113 
114 enum {
115  TCP_POLL,
116  UDP_POLL,
117  PACKET_INPUT
118 };
119 
120 /* Called on IP packet output. */
121 #if UIP_CONF_IPV6
122 
123 static u8_t (* outputfunc)(uip_lladdr_t *a);
124 
125 u8_t
127 {
128  int ret;
129  if(outputfunc != NULL) {
130  ret = outputfunc(a);
131  return ret;
132  }
133  UIP_LOG("tcpip_output: Use tcpip_set_outputfunc() to set an output function");
134  return 0;
135 }
136 
137 void
138 tcpip_set_outputfunc(u8_t (*f)(uip_lladdr_t *))
139 {
140  outputfunc = f;
141 }
142 #else
143 
144 static u8_t (* outputfunc)(void);
145 u8_t
147 {
148  if(outputfunc != NULL) {
149  return outputfunc();
150  }
151  UIP_LOG("tcpip_output: Use tcpip_set_outputfunc() to set an output function");
152  return 0;
153 }
154 
155 void
156 tcpip_set_outputfunc(u8_t (*f)(void))
157 {
158  outputfunc = f;
159 }
160 #endif
161 
162 #if UIP_CONF_IP_FORWARD
163 unsigned char tcpip_is_forwarding; /* Forwarding right now? */
164 #endif /* UIP_CONF_IP_FORWARD */
165 
166 PROCESS(tcpip_process, "TCP/IP stack");
167 
168 /*---------------------------------------------------------------------------*/
169 static void
170 start_periodic_tcp_timer(void)
171 {
172  if(etimer_expired(&periodic)) {
173  etimer_restart(&periodic);
174  }
175 }
176 /*---------------------------------------------------------------------------*/
177 static void
178 check_for_tcp_syn(void)
179 {
180  /* This is a hack that is needed to start the periodic TCP timer if
181  an incoming packet contains a SYN: since uIP does not inform the
182  application if a SYN arrives, we have no other way of starting
183  this timer. This function is called for every incoming IP packet
184  to check for such SYNs. */
185 #define TCP_SYN 0x02
186  if(UIP_IP_BUF->proto == UIP_PROTO_TCP &&
187  (UIP_TCP_BUF->flags & TCP_SYN) == TCP_SYN) {
188  start_periodic_tcp_timer();
189  }
190 }
191 /*---------------------------------------------------------------------------*/
192 static void
193 packet_input(void)
194 {
195 #if UIP_CONF_IP_FORWARD
196  if(uip_len > 0) {
197  tcpip_is_forwarding = 1;
198  if(uip_fw_forward() == UIP_FW_LOCAL) {
199  tcpip_is_forwarding = 0;
200  check_for_tcp_syn();
201  uip_input();
202  if(uip_len > 0) {
203 #if UIP_CONF_TCP_SPLIT
205 #else /* UIP_CONF_TCP_SPLIT */
206 #if UIP_CONF_IPV6
207  tcpip_ipv6_output();
208 #else
209  PRINTF("tcpip packet_input forward output len %d\n", uip_len);
210  tcpip_output();
211 #endif
212 #endif /* UIP_CONF_TCP_SPLIT */
213  }
214  }
215  tcpip_is_forwarding = 0;
216  }
217 #else /* UIP_CONF_IP_FORWARD */
218  if(uip_len > 0) {
219  check_for_tcp_syn();
220  uip_input();
221  if(uip_len > 0) {
222 #if UIP_CONF_TCP_SPLIT
224 #else /* UIP_CONF_TCP_SPLIT */
225 #if UIP_CONF_IPV6
226  tcpip_ipv6_output();
227 #else
228  PRINTF("tcpip packet_input output len %d\n", uip_len);
229  tcpip_output();
230 #endif
231 #endif /* UIP_CONF_TCP_SPLIT */
232  }
233  }
234 #endif /* UIP_CONF_IP_FORWARD */
235 }
236 /*---------------------------------------------------------------------------*/
237 #if UIP_TCP
238 #if UIP_ACTIVE_OPEN
239 struct uip_conn *
240 tcp_connect(uip_ipaddr_t *ripaddr, u16_t port, void *appstate)
241 {
242  struct uip_conn *c;
243 
244  c = uip_connect(ripaddr, port);
245  if(c == NULL) {
246  return NULL;
247  }
248 
249  c->appstate.p = PROCESS_CURRENT();
250  c->appstate.state = appstate;
251 
252  tcpip_poll_tcp(c);
253 
254  return c;
255 }
256 #endif /* UIP_ACTIVE_OPEN */
257 /*---------------------------------------------------------------------------*/
258 void
259 tcp_unlisten(u16_t port)
260 {
261  static unsigned char i;
262  struct listenport *l;
263 
264  l = s.listenports;
265  for(i = 0; i < UIP_LISTENPORTS; ++i) {
266  if(l->port == port &&
267  l->p == PROCESS_CURRENT()) {
268  l->port = 0;
269  uip_unlisten(port);
270  break;
271  }
272  ++l;
273  }
274 }
275 /*---------------------------------------------------------------------------*/
276 void
277 tcp_listen(u16_t port)
278 {
279  static unsigned char i;
280  struct listenport *l;
281 
282  l = s.listenports;
283  for(i = 0; i < UIP_LISTENPORTS; ++i) {
284  if(l->port == 0) {
285  l->port = port;
286  l->p = PROCESS_CURRENT();
287  uip_listen(port);
288  break;
289  }
290  ++l;
291  }
292 }
293 /*---------------------------------------------------------------------------*/
294 void
295 tcp_attach(struct uip_conn *conn,
296  void *appstate)
297 {
298  register uip_tcp_appstate_t *s;
299 
300  s = &conn->appstate;
301  s->p = PROCESS_CURRENT();
302  s->state = appstate;
303 }
304 
305 #endif /* UIP_TCP */
306 /*---------------------------------------------------------------------------*/
307 #if UIP_UDP
308 void
310  void *appstate)
311 {
312  register uip_udp_appstate_t *s;
313 
314  s = &conn->appstate;
315  s->p = PROCESS_CURRENT();
316  s->state = appstate;
317 }
318 /*---------------------------------------------------------------------------*/
319 struct uip_udp_conn *
320 udp_new(const uip_ipaddr_t *ripaddr, u16_t port, void *appstate)
321 {
322  struct uip_udp_conn *c;
324 
325  c = uip_udp_new(ripaddr, port);
326  if(c == NULL) {
327  return NULL;
328  }
329 
330  s = &c->appstate;
331  s->p = PROCESS_CURRENT();
332  s->state = appstate;
333 
334  return c;
335 }
336 /*---------------------------------------------------------------------------*/
337 struct uip_udp_conn *
338 udp_broadcast_new(u16_t port, void *appstate)
339 {
340  uip_ipaddr_t addr;
341  struct uip_udp_conn *conn;
342 
343 #if UIP_CONF_IPV6
344  uip_create_linklocal_allnodes_mcast(&addr);
345 #else
346  uip_ipaddr(&addr, 255,255,255,255);
347 #endif /* UIP_CONF_IPV6 */
348  conn = udp_new(&addr, port, appstate);
349  if(conn != NULL) {
350  udp_bind(conn, port);
351  }
352  return conn;
353 }
354 #endif /* UIP_UDP */
355 /*---------------------------------------------------------------------------*/
356 #if UIP_CONF_ICMP6
357 u8_t
358 icmp6_new(void *appstate) {
359  if(uip_icmp6_conns.appstate.p == PROCESS_NONE) {
360  uip_icmp6_conns.appstate.p = PROCESS_CURRENT();
361  uip_icmp6_conns.appstate.state = appstate;
362  return 0;
363  }
364  return 1;
365 }
366 
367 void
368 tcpip_icmp6_call(u8_t type)
369 {
370  if(uip_icmp6_conns.appstate.p != PROCESS_NONE) {
371  /* XXX: This is a hack that needs to be updated. Passing a pointer (&type)
372  like this only works with process_post_synch. */
373  process_post_synch(uip_icmp6_conns.appstate.p, tcpip_icmp6_event, &type);
374  }
375  return;
376 }
377 #endif /* UIP_CONF_ICMP6 */
378 /*---------------------------------------------------------------------------*/
379 static void
380 eventhandler(process_event_t ev, process_data_t data)
381 {
382 #if UIP_TCP
383  static unsigned char i;
384  register struct listenport *l;
385 #endif /*UIP_TCP*/
386  struct process *p;
387 
388  switch(ev) {
389  case PROCESS_EVENT_EXITED:
390  /* This is the event we get if a process has exited. We go through
391  the TCP/IP tables to see if this process had any open
392  connections or listening TCP ports. If so, we'll close those
393  connections. */
394 
395  p = (struct process *)data;
396 #if UIP_TCP
397  l = s.listenports;
398  for(i = 0; i < UIP_LISTENPORTS; ++i) {
399  if(l->p == p) {
400  uip_unlisten(l->port);
401  l->port = 0;
402  l->p = PROCESS_NONE;
403  }
404  ++l;
405  }
406 
407  {
408  register struct uip_conn *cptr;
409 
410  for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) {
411  if(cptr->appstate.p == p) {
412  cptr->appstate.p = PROCESS_NONE;
413  cptr->tcpstateflags = UIP_CLOSED;
414  }
415 
416  }
417 
418  }
419 #endif /* UIP_TCP */
420 #if UIP_UDP
421  {
422  register struct uip_udp_conn *cptr;
423  for(cptr = &uip_udp_conns[0];
424  cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) {
425  if(cptr->appstate.p == p) {
426  cptr->lport = 0;
427  }
428  }
429 
430  }
431 #endif /* UIP_UDP */
432  break;
433 
434  case PROCESS_EVENT_TIMER:
435  /* We get this event if one of our timers have expired. */
436  {
437  /* Check the clock so see if we should call the periodic uIP
438  processing. */
439  if(data == &periodic &&
440  etimer_expired(&periodic)) {
441 #if UIP_TCP
442  for(i = 0; i < UIP_CONNS; ++i) {
443  if(uip_conn_active(i)) {
444  /* Only restart the timer if there are active
445  connections. */
446  etimer_restart(&periodic);
447  uip_periodic(i);
448 #if UIP_CONF_IPV6
449  tcpip_ipv6_output();
450 #else
451  if(uip_len > 0) {
452  PRINTF("tcpip_output from periodic len %d\n", uip_len);
453  tcpip_output();
454  PRINTF("tcpip_output after periodic len %d\n", uip_len);
455  }
456 #endif /* UIP_CONF_IPV6 */
457  }
458  }
459 #endif /* UIP_TCP */
460 #if UIP_CONF_IP_FORWARD
461  uip_fw_periodic();
462 #endif /* UIP_CONF_IP_FORWARD */
463  }
464 
465 #if UIP_CONF_IPV6
466 #if UIP_CONF_IPV6_REASSEMBLY
467  /*
468  * check the timer for reassembly
469  */
470  if(data == &uip_reass_timer &&
471  etimer_expired(&uip_reass_timer)) {
472  uip_reass_over();
473  tcpip_ipv6_output();
474  }
475 #endif /* UIP_CONF_IPV6_REASSEMBLY */
476  /*
477  * check the different timers for neighbor discovery and
478  * stateless autoconfiguration
479  */
480  /*if(data == &uip_nd6_timer_periodic &&
481  etimer_expired(&uip_nd6_timer_periodic)) {
482  uip_nd6_periodic();
483  tcpip_ipv6_output();
484  }*/
485 #if !UIP_CONF_ROUTER
486  if(data == &uip_ds6_timer_rs &&
488  uip_ds6_send_rs();
489  tcpip_ipv6_output();
490  }
491 #endif /* !UIP_CONF_ROUTER */
492  if(data == &uip_ds6_timer_periodic &&
493  etimer_expired(&uip_ds6_timer_periodic)){
495  tcpip_ipv6_output();
496  }
497 #endif /* UIP_CONF_IPV6 */
498  }
499  break;
500 
501 #if UIP_TCP
502  case TCP_POLL:
503  if(data != NULL) {
504  uip_poll_conn(data);
505 #if UIP_CONF_IPV6
506  tcpip_ipv6_output();
507 #else /* UIP_CONF_IPV6 */
508  if(uip_len > 0) {
509  PRINTF("tcpip_output from tcp poll len %d\n", uip_len);
510  tcpip_output();
511  }
512 #endif /* UIP_CONF_IPV6 */
513  /* Start the periodic polling, if it isn't already active. */
514  start_periodic_tcp_timer();
515  }
516  break;
517 #endif /* UIP_TCP */
518 #if UIP_UDP
519  case UDP_POLL:
520  if(data != NULL) {
521  uip_udp_periodic_conn(data);
522 #if UIP_CONF_IPV6
523  tcpip_ipv6_output();
524 #else
525  if(uip_len > 0) {
526  tcpip_output();
527  }
528 #endif /* UIP_UDP */
529  }
530  break;
531 #endif /* UIP_UDP */
532 
533  case PACKET_INPUT:
534  packet_input();
535  break;
536  };
537 }
538 /*---------------------------------------------------------------------------*/
539 void
541 {
542  process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
543  uip_len = 0;
544 #if UIP_CONF_IPV6
545  uip_ext_len = 0;
546 #endif /*UIP_CONF_IPV6*/
547 }
548 /*---------------------------------------------------------------------------*/
549 #if UIP_CONF_IPV6
550 void
551 tcpip_ipv6_output(void)
552 {
553  uip_ds6_nbr_t *nbr = NULL;
554  uip_ipaddr_t* nexthop;
555 
556  if(uip_len == 0) {
557  return;
558  }
559 
560  if(uip_len > UIP_LINK_MTU) {
561  UIP_LOG("tcpip_ipv6_output: Packet to big");
562  uip_len = 0;
563  return;
564  }
565  if(uip_is_addr_unspecified(&UIP_IP_BUF->destipaddr)){
566  UIP_LOG("tcpip_ipv6_output: Destination address unspecified");
567  uip_len = 0;
568  return;
569  }
570  if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
571  /* Next hop determination */
572  nbr = NULL;
573  if(uip_ds6_is_addr_onlink(&UIP_IP_BUF->destipaddr)){
574  nexthop = &UIP_IP_BUF->destipaddr;
575  } else {
576  uip_ds6_route_t* locrt;
577  locrt = uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr);
578  if(locrt == NULL) {
579  if((nexthop = uip_ds6_defrt_choose()) == NULL) {
580 #ifdef UIP_FALLBACK_INTERFACE
581  UIP_FALLBACK_INTERFACE.output();
582 #else
583  PRINTF("tcpip_ipv6_output: Destination off-link but no route\n");
584 #endif
585  uip_len = 0;
586  return;
587  }
588  } else {
589  nexthop = &locrt->nexthop;
590  }
591  }
592  /* end of next hop determination */
593  if((nbr = uip_ds6_nbr_lookup(nexthop)) == NULL) {
594  // printf("add1 %d\n", nexthop->u8[15]);
595  if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE)) == NULL) {
596  // printf("add n\n");
597  uip_len = 0;
598  return;
599  } else {
600 #if UIP_CONF_IPV6_QUEUE_PKT
601  /* copy outgoing pkt in the queuing buffer for later transmmit */
602  if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) != NULL) {
603  memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF, uip_len);
604  uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
605  }
606 #endif
607  /* RFC4861, 7.2.2:
608  * "If the source address of the packet prompting the solicitation is the
609  * same as one of the addresses assigned to the outgoing interface, that
610  * address SHOULD be placed in the IP Source Address of the outgoing
611  * solicitation. Otherwise, any one of the addresses assigned to the
612  * interface should be used."*/
613  if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)){
614  uip_nd6_ns_output(&UIP_IP_BUF->srcipaddr, NULL, &nbr->ipaddr);
615  } else {
616  uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
617  }
618 
619  stimer_set(&(nbr->sendns), uip_ds6_if.retrans_timer / 1000);
620  nbr->nscount = 1;
621  }
622  } else {
623  if(nbr->state == NBR_INCOMPLETE) {
624  PRINTF("tcpip_ipv6_output: nbr cache entry incomplete\n");
625 #if UIP_CONF_IPV6_QUEUE_PKT
626  /* copy outgoing pkt in the queuing buffer for later transmmit and set
627  the destination nbr to nbr */
628  if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) != NULL) {
629  memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF, uip_len);
630  uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
631  }
632  /* memcpy(nbr->queue_buf, UIP_IP_BUF, uip_len);
633  nbr->queue_buf_len = uip_len;*/
634  uip_len = 0;
635 #endif /*UIP_CONF_IPV6_QUEUE_PKT*/
636  return;
637  }
638  /* if running NUD (nbc->state == STALE, DELAY, or PROBE ) keep
639  sending in parallel see rfc 4861 Node behavior in section 7.7.3*/
640 
641  if(nbr->state == NBR_STALE) {
642  nbr->state = NBR_DELAY;
643  stimer_set(&(nbr->reachable),
644  UIP_ND6_DELAY_FIRST_PROBE_TIME);
645  nbr->nscount = 0;
646  PRINTF("tcpip_ipv6_output: nbr cache entry stale moving to delay\n");
647  }
648 
649  stimer_set(&(nbr->sendns),
650  uip_ds6_if.retrans_timer / 1000);
651 
652  tcpip_output(&(nbr->lladdr));
653 
654 
655 #if UIP_CONF_IPV6_QUEUE_PKT
656  /* Send the queued packets from here, may not be 100% perfect though.
657  * This happens in a few cases, for example when instead of receiving a
658  * NA after sendiong a NS, you receive a NS with SLLAO: the entry moves
659  *to STALE, and you must both send a NA and the queued packet
660  */
661  /* if(nbr->queue_buf_len != 0) {
662  uip_len = nbr->queue_buf_len;
663  memcpy(UIP_IP_BUF, nbr->queue_buf, uip_len);
664  nbr->queue_buf_len = 0;
665  tcpip_output(&(nbr->lladdr));
666  }*/
667  if(uip_packetqueue_buflen(&nbr->packethandle) != 0) {
668  uip_len = uip_packetqueue_buflen(&nbr->packethandle);
669  memcpy(UIP_IP_BUF, uip_packetqueue_buf(&nbr->packethandle), uip_len);
670  uip_packetqueue_free(&nbr->packethandle);
671  tcpip_output(&(nbr->lladdr));
672  }
673 #endif /*UIP_CONF_IPV6_QUEUE_PKT*/
674 
675  uip_len = 0;
676  return;
677  }
678  }
679 
680  /*multicast IP destination address */
682  uip_len = 0;
683  uip_ext_len = 0;
684 
685 }
686 #endif
687 /*---------------------------------------------------------------------------*/
688 #if UIP_UDP
689 void
691 {
692  process_post(&tcpip_process, UDP_POLL, conn);
693 }
694 #endif /* UIP_UDP */
695 /*---------------------------------------------------------------------------*/
696 #if UIP_TCP
697 void
698 tcpip_poll_tcp(struct uip_conn *conn)
699 {
700  process_post(&tcpip_process, TCP_POLL, conn);
701 }
702 #endif /* UIP_TCP */
703 /*---------------------------------------------------------------------------*/
704 void
705 tcpip_uipcall(void)
706 {
707  register uip_udp_appstate_t *ts;
708 
709 #if UIP_UDP
710  if(uip_conn != NULL) {
711  ts = &uip_conn->appstate;
712  } else {
713  ts = &uip_udp_conn->appstate;
714  }
715 #else /* UIP_UDP */
716  ts = &uip_conn->appstate;
717 #endif /* UIP_UDP */
718 
719 #if UIP_TCP
720  {
721  static unsigned char i;
722  register struct listenport *l;
723 
724  /* If this is a connection request for a listening port, we must
725  mark the connection with the right process ID. */
726  if(uip_connected()) {
727  l = &s.listenports[0];
728  for(i = 0; i < UIP_LISTENPORTS; ++i) {
729  if(l->port == uip_conn->lport &&
730  l->p != PROCESS_NONE) {
731  ts->p = l->p;
732  ts->state = NULL;
733  break;
734  }
735  ++l;
736  }
737 
738  /* Start the periodic polling, if it isn't already active. */
739  start_periodic_tcp_timer();
740  }
741  }
742 #endif /* UIP_TCP */
743 
744  if(ts->p != NULL) {
745  process_post_synch(ts->p, tcpip_event, ts->state);
746  }
747 }
748 /*---------------------------------------------------------------------------*/
749 PROCESS_THREAD(tcpip_process, ev, data)
750 {
751  PROCESS_BEGIN();
752 
753 #if UIP_TCP
754  {
755  static unsigned char i;
756 
757  for(i = 0; i < UIP_LISTENPORTS; ++i) {
758  s.listenports[i].port = 0;
759  }
760  s.p = PROCESS_CURRENT();
761  }
762 #endif
763 
765 #if UIP_CONF_ICMP6
766  tcpip_icmp6_event = process_alloc_event();
767 #endif /* UIP_CONF_ICMP6 */
768  etimer_set(&periodic, CLOCK_SECOND / 2);
769 
770  uip_init();
771 #ifdef UIP_FALLBACK_INTERFACE
772  UIP_FALLBACK_INTERFACE.init();
773 #endif
774 /* initialize RPL if configured for using RPL */
775 #if UIP_CONF_IPV6_RPL
776  rpl_init();
777 #endif /* UIP_CONF_IPV6_RPL */
778 
779  while(1) {
780  PROCESS_YIELD();
781  eventhandler(ev, data);
782  }
783 
784  PROCESS_END();
785 }
786 /*---------------------------------------------------------------------------*/