/*---------------------------------------------------------------------------*/ static void packet_input(void) { // printf("Tcpip: packet_input"); // rpl_trace(rpl_dataptr_from_packetbuf()); #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; if(uip_fw_forward() == UIP_FW_LOCAL) { tcpip_is_forwarding = 0; check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input forward output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } tcpip_is_forwarding = 0; } #else /* UIP_CONF_IP_FORWARD */ if(uip_len > 0) { // printf("Tcpip: packet_input 2"); // rpl_trace(rpl_dataptr_from_packetbuf()); if(packetbuf_attr(PACKETBUF_ATTR_IS_ANYCAST)) { anycast_packet_received(); } check_for_tcp_syn(); uip_input(); if(uip_len > 0) { // printf("Tcpip: packet_input 3"); // rpl_trace(rpl_dataptr_from_packetbuf()); #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } #endif /* UIP_CONF_IP_FORWARD */ }
/*---------------------------------------------------------------------------*/ static void packet_input(void) { if(uip_len > 0) { #if UIP_CONF_IP_FORWARD tcpip_is_forwarding = 1; if(uip_fw_forward() != UIP_FW_LOCAL) { tcpip_is_forwarding = 0; return; } tcpip_is_forwarding = 0; #endif /* UIP_CONF_IP_FORWARD */ check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else /* NETSTACK_CONF_WITH_IPV6 */ PRINTF("tcpip packet_input output len %d\n", uip_len); tcpip_output(); #endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* UIP_CONF_TCP_SPLIT */ } } }
/*---------------------------------------------------------------------------*/ static uint8_t packet_input(struct net_buf *buf) { uint8_t ret = 0; #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; if(uip_fw_forward() == UIP_FW_LOCAL) { tcpip_is_forwarding = 0; check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input forward output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } tcpip_is_forwarding = 0; } #else /* UIP_CONF_IP_FORWARD */ if(uip_len(buf) > 0) { check_for_tcp_syn(buf); ret = uip_input(buf); if(ret && uip_len(buf) > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(buf); #else /* UIP_CONF_TCP_SPLIT */ #if NETSTACK_CONF_WITH_IPV6 PRINTF("tcpip packet_input output len %d\n", uip_len(buf)); ret = tcpip_ipv6_output(buf); #else PRINTF("tcpip packet_input output len %d\n", uip_len(buf)); ret = tcpip_output(buf, NULL); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } #endif /* UIP_CONF_IP_FORWARD */ return ret; }
/** Processes Incoming packets to the server from the connected RNDIS device, creating responses as needed. */ static void uIPManagement_ProcessIncomingPacket(void) { /* If no packet received, exit processing routine */ if (!(RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface))) return; LEDs_SetAllLEDs(LEDMASK_USB_BUSY); /* Read the Incoming packet straight into the UIP packet buffer */ RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, uip_buf, &uip_len); /* If the packet contains an Ethernet frame, process it */ if (uip_len > 0) { switch (((struct uip_eth_hdr*)uip_buf)->type) { case HTONS(UIP_ETHTYPE_IP): /* Filter packet by MAC destination */ uip_arp_ipin(); /* Process Incoming packet */ uip_input(); /* If a response was generated, send it */ if (uip_len > 0) { /* Add destination MAC to outgoing packet */ uip_arp_out(); uip_split_output(); } break; case HTONS(UIP_ETHTYPE_ARP): /* Process ARP packet */ uip_arp_arpin(); /* If a response was generated, send it */ if (uip_len > 0) uip_split_output(); break; } } LEDs_SetAllLEDs(LEDMASK_USB_READY | ((HaveIPConfiguration) ? LEDMASK_UIP_READY_CONFIG : LEDMASK_UIP_READY_NOCONFIG)); }
/*---------------------------------------------------------------------------*/ static void packet_input(void) { #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; if(uip_fw_forward() == UIP_FW_LOCAL) { tcpip_is_forwarding = 0; check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input forward output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } tcpip_is_forwarding = 0; } #else /* UIP_CONF_IP_FORWARD */ if(uip_len > 0) { check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } #endif /* UIP_CONF_IP_FORWARD */ }
/** Manages the currently open network connections, including TCP and (if enabled) UDP. */ static void uIPManagement_ManageConnections(void) { /* Poll TCP connections for more data to send back to the host */ for (uint8_t i = 0; i < UIP_CONNS; i++) { uip_poll_conn(&uip_conns[i]); /* If a response was generated, send it */ if (uip_len > 0) { /* Add destination MAC to outgoing packet */ uip_arp_out(); /* Split and send the outgoing packet */ uip_split_output(); } } /* Manage open connections for timeouts */ if (timer_expired(&ConnectionTimer)) { timer_reset(&ConnectionTimer); LEDs_SetAllLEDs(LEDMASK_USB_BUSY); for (uint8_t i = 0; i < UIP_CONNS; i++) { /* Run periodic connection management for each TCP connection */ uip_periodic(i); /* If a response was generated, send it */ if (uip_len > 0) { /* Add destination MAC to outgoing packet */ uip_arp_out(); /* Split and send the outgoing packet */ uip_split_output(); } } #if defined(ENABLE_DHCP_CLIENT) for (uint8_t i = 0; i < UIP_UDP_CONNS; i++) { /* Run periodic connection management for each UDP connection */ uip_udp_periodic(i); /* If a response was generated, send it */ if (uip_len > 0) { /* Add destination MAC to outgoing packet */ uip_arp_out(); /* Split and send the outgoing packet */ uip_split_output(); } } #endif LEDs_SetAllLEDs(LEDMASK_USB_READY); } /* Manage ARP cache refreshing */ if (timer_expired(&ARPTimer)) { timer_reset(&ARPTimer); uip_arp_timer(); } }
/** Processes Incoming packets to the server from the connected RNDIS device, creating responses as needed. */ static void uIPManagement_ProcessIncomingPacket(void) { /* Determine which USB mode the system is currently initialized in */ if (USB_CurrentMode == USB_MODE_Device) { /* If no packet received, exit processing routine */ if (!(RNDIS_Device_IsPacketReceived(&Ethernet_RNDIS_Interface_Device))) return; LEDs_SetAllLEDs(LEDMASK_USB_BUSY); /* Read the Incoming packet straight into the UIP packet buffer */ RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, &uip_len); } else { /* If no packet received, exit processing routine */ if (!(RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface_Host))) return; LEDs_SetAllLEDs(LEDMASK_USB_BUSY); /* Read the Incoming packet straight into the UIP packet buffer */ RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, &uip_len); } /* If the packet contains an Ethernet frame, process it */ // cppcheck-suppress redundantOperationIn if (uip_len > 0) { switch (((struct uip_eth_hdr*)uip_buf)->type) { case HTONS(UIP_ETHTYPE_IP): /* Filter packet by MAC destination */ uip_arp_ipin(); /* Process Incoming packet */ uip_input(); /* If a response was generated, send it */ if (uip_len > 0) { /* Add destination MAC to outgoing packet */ uip_arp_out(); uip_split_output(); } break; case HTONS(UIP_ETHTYPE_ARP): /* Process ARP packet */ uip_arp_arpin(); /* If a response was generated, send it */ if (uip_len > 0) uip_split_output(); break; } } LEDs_SetAllLEDs(LEDMASK_USB_READY); }
void network_device_send() { uip_split_output(); //tcpip_output(); }
/*---------------------------------------------------------------------------*/ static void packet_input(void) { #if FORWARDER rpl_instance_t *instance; uint8_t octet; uint8_t ip6id; int rssi_temp; uint8_t send_rssi; rimeaddr_t packet_from_addr; packet_from_addr = *packetbuf_addr(PACKETBUF_ADDR_SENDER); instance = &instance_table[0]; octet = packet_from_addr.u8[7]; ip6id = (octet & 0b00111111) << 2; tcp_rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI); if(is_mobile_node(octet) == 1) { packet_input_count++; rssi_temp = tcp_rssi - 45; if(tcp_rssi > 200) { rssi_temp = tcp_rssi - 255 - 46; } rssi_sum += rssi_temp; if(packet_input_count == WINDOW_SIZE) { rssi_sum = rssi_sum / WINDOW_SIZE; PRINTF("RSSI = %d\n", rssi_sum); PRINTF("packet input count = %d\n", packet_input_count); if(rssi_sum <= -90) { send_rssi = rssi_sum + 255 + 46; dis_output(NULL, 1, 0, send_rssi, ip6id); } rssi_sum = 0; packet_input_count = 0; } } #endif #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; if(uip_fw_forward() == UIP_FW_LOCAL) { tcpip_is_forwarding = 0; check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input forward output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } tcpip_is_forwarding = 0; } #else /* UIP_CONF_IP_FORWARD */ if(uip_len > 0) { check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } #endif /* UIP_CONF_IP_FORWARD */ }
void netMainThread(void* arg) { uint8_t i; #if !NETSTACK_CONF_WITH_IPV6 POSTIMER_t arpTimer; #endif POSTIMER_t periodicTimer; int sendRequested; bool packetSeen; #if !NETSTACK_CONF_WITH_IPV6 arpTimer = posTimerCreate(); P_ASSERT("netMainThread1", arpTimer != NULL); posTimerSet(arpTimer, uipGiant, MS(10000), MS(10000)); posTimerStart(arpTimer); #endif periodicTimer = posTimerCreate(); P_ASSERT("netMainThread2", periodicTimer != NULL); posTimerSet(periodicTimer, uipGiant, MS(500), MS(500)); posTimerStart(periodicTimer); posMutexLock(uipMutex); packetSeen = false; while(1) { posMutexUnlock(uipMutex); // Using semaphore here is not fully optimal. // As it is a counting one, it can get bumped // to larger value than 1 by upper or interrupt // layer. However, not much harm is done, // this loop just spins extra times without // doing nothing useful. // A Pico]OS Flag object would be perfect, // but it doesn't work with posTimer* functions. if (!packetSeen || pollTicks == INFINITE) posSemaWait(uipGiant, pollTicks); posMutexLock(uipMutex); sendRequested = dataToSend; dataToSend = 0; packetSeen = false; if (sendRequested) { for(i = 0; i < UIP_CONNS; i++) { uip_len = 0; uip_poll_conn(&uip_conns[i]); if(uip_len > 0) { #if NETCFG_UIP_SPLIT == 1 uip_split_output(); #else #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif #endif } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_len = 0; uip_udp_periodic(i); if(uip_len > 0) { #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif } } #endif /* UIP_UDP */ } packetSeen = netInterfacePoll(); if (posTimerFired(periodicTimer)) { for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { #if NETCFG_UIP_SPLIT == 1 uip_split_output(); #else #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif #endif } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif } } #endif /* UIP_UDP */ } #if NETSTACK_CONF_WITH_IPV6 == 0 if (posTimerFired(arpTimer)) { uip_arp_timer(); } #endif // Run contiki-style timers. // Instead of posting events to process like // contiki does, it just calls common callback function // to do the work. etimer_request_poll(); } }
/* ----------------------------------------------------------------------------- * \brief Deliver an incoming packet to the TCP/IP stack * * This function is called by theServer to * deliver an incoming packet to the TCP/IP stack. The * incoming packet must be present in the uip_buf buffer, * and the length of the packet must be in the global * uip_len variable. * -------------------------------------------------------------------------- */ void xtcpip_input(chanend mac_tx) { /*_______________*/ #if UIP_CONF_IPV4 /* ORIGINAL_XMOS */ if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); if (uip_len > 0) { if (uip_udpconnection() && (TCPBUF->proto != UIP_PROTO_ICMP) && (TCPBUF->proto != UIP_PROTO_IGMP)) uip_arp_out( uip_udp_conn); else uip_arp_out( NULL); xtcp_tx_buffer(mac_tx); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if (uip_len > 0) { xtcp_tx_buffer(mac_tx); } for (int i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_arp_event(i); if (uip_len > 0) { uip_arp_out(&uip_udp_conns[i]); xtcp_tx_buffer(mac_tx); } } } #endif /* UIP_CONF_IPV4 ORIGINAL_XMOS */ /*_______________*/ /* contiki tcpip.c */ #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; if(uip_fw_forward() == UIP_FW_LOCAL) { tcpip_is_forwarding = 0; check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(mac_tx); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 xtcpip_ipv6_output(mac_tx); #else PRINTF("tcpip packet_input forward output len %d\n", uip_len); xtcpip_output(mac_tx); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } tcpip_is_forwarding = 0; } #else /* UIP_CONF_IP_FORWARD */ if(uip_len > 0) { uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(mac_tx); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 xtcpip_ipv6_output(mac_tx); #else PRINTF("tcpip packet_input output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } #endif /* UIP_CONF_IP_FORWARD */ }
void xtcp_tx_buffer(chanend mac_tx) { uip_split_output(mac_tx); uip_len = 0; }