40 #include "contiki-net.h"
42 #include "net/ip/uip-packetqueue.h"
45 #include "net/ipv6/uip-nd6.h"
46 #include "net/ipv6/uip-ds6.h"
51 #define DEBUG DEBUG_PRINT
57 #define UIP_LOG(m) uip_log(m)
62 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len])
63 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
64 #define UIP_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
66 #ifdef UIP_FALLBACK_INTERFACE
67 extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
76 process_event_t tcpip_icmp6_event;
80 static struct etimer periodic;
82 #if UIP_CONF_IPV6 && UIP_CONF_IPV6_REASSEMBLY
84 extern struct etimer uip_reass_timer;
96 static struct internal_state {
117 if(outputfunc !=
NULL) {
121 UIP_LOG(
"tcpip_output: Use tcpip_set_outputfunc() to set an output function");
126 tcpip_set_outputfunc(uint8_t (*f)(
const uip_lladdr_t *))
132 static uint8_t (* outputfunc)(void);
136 if(outputfunc !=
NULL) {
139 UIP_LOG(
"tcpip_output: Use tcpip_set_outputfunc() to set an output function");
144 tcpip_set_outputfunc(uint8_t (*f)(
void))
150 #if UIP_CONF_IP_FORWARD
151 unsigned char tcpip_is_forwarding;
154 PROCESS(tcpip_process,
"TCP/IP stack");
158 start_periodic_tcp_timer(
void)
166 check_for_tcp_syn(
void)
168 #if UIP_TCP || UIP_CONF_IP_FORWARD
176 (UIP_TCP_BUF->flags & TCP_SYN) == TCP_SYN) {
177 start_periodic_tcp_timer();
185 #if UIP_CONF_IP_FORWARD
187 tcpip_is_forwarding = 1;
189 tcpip_is_forwarding = 0;
193 #if UIP_CONF_TCP_SPLIT
199 PRINTF(
"tcpip packet_input forward output len %d\n",
uip_len);
205 tcpip_is_forwarding = 0;
212 #if UIP_CONF_TCP_SPLIT
218 PRINTF(
"tcpip packet_input output len %d\n",
uip_len);
251 static unsigned char i;
252 struct listenport *l;
256 if(l->port == port &&
269 static unsigned char i;
270 struct listenport *l;
310 udp_new(
const uip_ipaddr_t *ripaddr, uint16_t port,
void *appstate)
338 conn =
udp_new(&addr, port, appstate);
348 icmp6_new(
void *appstate) {
349 if(uip_icmp6_conns.appstate.p == PROCESS_NONE) {
351 uip_icmp6_conns.appstate.state =
appstate;
358 tcpip_icmp6_call(uint8_t type)
360 if(uip_icmp6_conns.appstate.p != PROCESS_NONE) {
370 eventhandler(process_event_t ev, process_data_t data)
373 static unsigned char i;
374 register struct listenport *l;
379 case PROCESS_EVENT_EXITED:
385 p = (
struct process *)data;
400 for(cptr = &uip_conns[0]; cptr < &uip_conns[
UIP_CONNS]; ++cptr) {
412 for(cptr = &uip_udp_conns[0];
422 case PROCESS_EVENT_TIMER:
427 if(data == &periodic &&
431 if(uip_conn_active(i)) {
440 PRINTF(
"tcpip_output from periodic len %d\n",
uip_len);
442 PRINTF(
"tcpip_output after periodic len %d\n",
uip_len);
448 #if UIP_CONF_IP_FORWARD
454 #if UIP_CONF_IPV6_REASSEMBLY
458 if(data == &uip_reass_timer &&
480 if(data == &uip_ds6_timer_periodic &&
497 PRINTF(
"tcpip_output from tcp poll len %d\n",
uip_len);
502 start_periodic_tcp_timer();
509 uip_udp_periodic_conn(data);
542 uip_ipaddr_t *nexthop;
549 UIP_LOG(
"tcpip_ipv6_output: Packet to big");
555 UIP_LOG(
"tcpip_ipv6_output: Destination address unspecified");
567 if(uip_ds6_is_addr_onlink(&
UIP_IP_BUF->destipaddr)){
576 PRINTF(
"tcpip_ipv6_output: no route found, using default route\n");
578 if(nexthop ==
NULL) {
579 #ifdef UIP_FALLBACK_INTERFACE
580 PRINTF(
"FALLBACK: removing ext hdrs & setting proto %d %d\n",
583 extern void remove_ext_hdr(
void);
584 uint8_t proto = *((uint8_t *)
UIP_IP_BUF + 40);
589 UIP_FALLBACK_INTERFACE.output();
591 PRINTF(
"tcpip_ipv6_output: Destination off-link but no route\n");
600 nexthop = uip_ds6_route_nexthop(route);
604 if(nexthop ==
NULL) {
605 #if UIP_CONF_IPV6_RPL
614 instance = dag->instance;
616 rpl_repair_root(instance->instance_id);
626 #if TCPIP_CONF_ANNOTATE_TRANSMISSIONS
627 if(nexthop !=
NULL) {
628 static uint8_t annotate_last;
629 static uint8_t annotate_has_last = 0;
631 if(annotate_has_last) {
632 printf(
"#L %u 0; red\n", annotate_last);
634 printf(
"#L %u 1; red\n", nexthop->u8[
sizeof(uip_ipaddr_t) - 1]);
635 annotate_last = nexthop->u8[
sizeof(uip_ipaddr_t) - 1];
636 annotate_has_last = 1;
643 #if UIP_CONF_IPV6_RPL
644 if(rpl_update_header_final(nexthop)) {
656 #if UIP_CONF_IPV6_QUEUE_PKT
658 if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) !=
NULL) {
660 uip_packetqueue_set_buflen(&nbr->packethandle,
uip_len);
675 stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
681 if(nbr->state == NBR_INCOMPLETE) {
682 PRINTF(
"tcpip_ipv6_output: nbr cache entry incomplete\n");
683 #if UIP_CONF_IPV6_QUEUE_PKT
686 if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) !=
NULL) {
688 uip_packetqueue_set_buflen(&nbr->packethandle,
uip_len);
696 if(nbr->state == NBR_STALE) {
697 nbr->state = NBR_DELAY;
698 stimer_set(&nbr->reachable, UIP_ND6_DELAY_FIRST_PROBE_TIME);
700 PRINTF(
"tcpip_ipv6_output: nbr cache entry stale moving to delay\n");
706 #if UIP_CONF_IPV6_QUEUE_PKT
713 if(uip_packetqueue_buflen(&nbr->packethandle) != 0) {
714 uip_len = uip_packetqueue_buflen(&nbr->packethandle);
716 uip_packetqueue_free(&nbr->packethandle);
766 static unsigned char i;
767 struct listenport *l;
772 l = &s.listenports[0];
775 l->p != PROCESS_NONE) {
784 start_periodic_tcp_timer();
800 static unsigned char i;
803 s.listenports[i].port = 0;
816 #ifdef UIP_FALLBACK_INTERFACE
817 UIP_FALLBACK_INTERFACE.init();
820 #if UIP_CONF_IPV6 && UIP_CONF_IPV6_RPL
826 eventhandler(ev, data);