42 #include "contiki-net.h"
46 #include "net/uip-packetqueue.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])
63 #define PRINT6ADDR(addr)
69 #define UIP_LOG(m) uip_log(m)
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])
78 #ifdef UIP_FALLBACK_INTERFACE
79 extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
86 process_event_t tcpip_icmp6_event;
92 static struct etimer periodic;
94 #if UIP_CONF_IPV6 && UIP_CONF_IPV6_REASSEMBLY
96 extern struct etimer uip_reass_timer;
108 static struct internal_state {
129 if(outputfunc !=
NULL) {
133 UIP_LOG(
"tcpip_output: Use tcpip_set_outputfunc() to set an output function");
144 static u8_t (* outputfunc)(void);
148 if(outputfunc !=
NULL) {
151 UIP_LOG(
"tcpip_output: Use tcpip_set_outputfunc() to set an output function");
156 tcpip_set_outputfunc(u8_t (*f)(
void))
162 #if UIP_CONF_IP_FORWARD
163 unsigned char tcpip_is_forwarding;
166 PROCESS(tcpip_process,
"TCP/IP stack");
170 start_periodic_tcp_timer(
void)
178 check_for_tcp_syn(
void)
187 (UIP_TCP_BUF->flags & TCP_SYN) == TCP_SYN) {
188 start_periodic_tcp_timer();
195 #if UIP_CONF_IP_FORWARD
197 tcpip_is_forwarding = 1;
199 tcpip_is_forwarding = 0;
203 #if UIP_CONF_TCP_SPLIT
209 PRINTF(
"tcpip packet_input forward output len %d\n",
uip_len);
215 tcpip_is_forwarding = 0;
222 #if UIP_CONF_TCP_SPLIT
228 PRINTF(
"tcpip packet_input output len %d\n",
uip_len);
261 static unsigned char i;
262 struct listenport *l;
266 if(l->port == port &&
279 static unsigned char i;
280 struct listenport *l;
344 uip_create_linklocal_allnodes_mcast(&addr);
348 conn =
udp_new(&addr, port, appstate);
358 icmp6_new(
void *appstate) {
359 if(uip_icmp6_conns.appstate.p == PROCESS_NONE) {
361 uip_icmp6_conns.appstate.state =
appstate;
368 tcpip_icmp6_call(u8_t type)
370 if(uip_icmp6_conns.appstate.p != PROCESS_NONE) {
380 eventhandler(process_event_t ev, process_data_t data)
383 static unsigned char i;
384 register struct listenport *l;
389 case PROCESS_EVENT_EXITED:
395 p = (
struct process *)data;
410 for(cptr = &uip_conns[0]; cptr < &uip_conns[
UIP_CONNS]; ++cptr) {
423 for(cptr = &uip_udp_conns[0];
434 case PROCESS_EVENT_TIMER:
439 if(data == &periodic &&
443 if(uip_conn_active(i)) {
452 PRINTF(
"tcpip_output from periodic len %d\n",
uip_len);
454 PRINTF(
"tcpip_output after periodic len %d\n",
uip_len);
460 #if UIP_CONF_IP_FORWARD
466 #if UIP_CONF_IPV6_REASSEMBLY
470 if(data == &uip_reass_timer &&
492 if(data == &uip_ds6_timer_periodic &&
509 PRINTF(
"tcpip_output from tcp poll len %d\n",
uip_len);
514 start_periodic_tcp_timer();
551 tcpip_ipv6_output(
void)
561 UIP_LOG(
"tcpip_ipv6_output: Packet to big");
565 if(uip_is_addr_unspecified(&
UIP_IP_BUF->destipaddr)){
566 UIP_LOG(
"tcpip_ipv6_output: Destination address unspecified");
570 if(!uip_is_addr_mcast(&
UIP_IP_BUF->destipaddr)) {
573 if(uip_ds6_is_addr_onlink(&
UIP_IP_BUF->destipaddr)){
577 locrt = uip_ds6_route_lookup(&
UIP_IP_BUF->destipaddr);
579 if((nexthop = uip_ds6_defrt_choose()) ==
NULL) {
580 #ifdef UIP_FALLBACK_INTERFACE
581 UIP_FALLBACK_INTERFACE.output();
583 PRINTF(
"tcpip_ipv6_output: Destination off-link but no route\n");
589 nexthop = &locrt->nexthop;
593 if((nbr = uip_ds6_nbr_lookup(nexthop)) ==
NULL) {
600 #if UIP_CONF_IPV6_QUEUE_PKT
602 if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) !=
NULL) {
604 uip_packetqueue_set_buflen(&nbr->packethandle,
uip_len);
613 if(uip_ds6_is_my_addr(&
UIP_IP_BUF->srcipaddr)){
619 stimer_set(&(nbr->sendns), uip_ds6_if.retrans_timer / 1000);
624 PRINTF(
"tcpip_ipv6_output: nbr cache entry incomplete\n");
625 #if UIP_CONF_IPV6_QUEUE_PKT
628 if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) !=
NULL) {
630 uip_packetqueue_set_buflen(&nbr->packethandle,
uip_len);
641 if(nbr->state == NBR_STALE) {
642 nbr->state = NBR_DELAY;
644 UIP_ND6_DELAY_FIRST_PROBE_TIME);
646 PRINTF(
"tcpip_ipv6_output: nbr cache entry stale moving to delay\n");
650 uip_ds6_if.retrans_timer / 1000);
655 #if UIP_CONF_IPV6_QUEUE_PKT
667 if(uip_packetqueue_buflen(&nbr->packethandle) != 0) {
668 uip_len = uip_packetqueue_buflen(&nbr->packethandle);
670 uip_packetqueue_free(&nbr->packethandle);
721 static unsigned char i;
722 register struct listenport *l;
727 l = &s.listenports[0];
730 l->p != PROCESS_NONE) {
739 start_periodic_tcp_timer();
755 static unsigned char i;
758 s.listenports[i].port = 0;
771 #ifdef UIP_FALLBACK_INTERFACE
772 UIP_FALLBACK_INTERFACE.init();
775 #if UIP_CONF_IPV6_RPL
781 eventhandler(ev, data);