/*---------------------------------------------------------------------------*/ static void pollhandler(void) { process_poll(ðernet_process); uip_len = ethernet_poll(); if(uip_len > 0) { #if UIP_CONF_IPV6 if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src); tcpip_input(); } else #endif /* UIP_CONF_IPV6 */ if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) { uip_len -= sizeof(struct uip_eth_hdr); tcpip_input(); } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { ethernet_send(); } } } }
/*---------------------------------------------------------------------------*/ static void pollhandler(void) { uip_len = tapdev_poll(); if(uip_len > 0) { #if UIP_CONF_IPV6 if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { tcpip_input(); } else #endif /* UIP_CONF_IPV6 */ if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) { uip_len -= sizeof(struct uip_eth_hdr); tcpip_input(); } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) { #if !UIP_CONF_IPV6 //math uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { tapdev_send(); } #endif } else { uip_len = 0; } } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(slip_process, ev, data) { PROCESS_BEGIN(); rxbuf_init(); while(1) { PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); slip_active = 1; /* Move packet from rxbuf to buffer provided by uIP. */ uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN], UIP_BUFSIZE - UIP_LLH_LEN); #if !UIP_CONF_IPV6 if(uip_len == 4 && strncmp((char*)&uip_buf[UIP_LLH_LEN], "?IPA", 4) == 0) { char buf[8]; memcpy(&buf[0], "=IPA", 4); memcpy(&buf[4], &uip_hostaddr, 4); if(input_callback) { input_callback(); } slip_write(buf, 8); } else if(uip_len > 0 && uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) && uip_ipchksum() == 0xffff) { #define IP_DF 0x40 if(BUF->ipid[0] == 0 && BUF->ipid[1] == 0 && BUF->ipoffset[0] & IP_DF) { static u16_t ip_id; u16_t nid = ip_id++; BUF->ipid[0] = nid >> 8; BUF->ipid[1] = nid; nid = uip_htons(nid); nid = ~nid; /* negate */ BUF->ipchksum += nid; /* add */ if(BUF->ipchksum < nid) { /* 1-complement overflow? */ BUF->ipchksum++; } } tcpip_input(); } else { uip_len = 0; SLIP_STATISTICS(slip_ip_drop++); } #else /* UIP_CONF_IPV6 */ if(uip_len > 0) { if(input_callback) { input_callback(); } tcpip_input(); } #endif /* UIP_CONF_IPV6 */ }
/*---------------------------------------------------------------------------*/ void ip64_eth_interface_input(uint8_t *packet, uint16_t len) { struct ip64_eth_hdr *ethhdr; ethhdr = (struct ip64_eth_hdr *)packet; if(ethhdr->type == UIP_HTONS(IP64_ETH_TYPE_ARP)) { len = ip64_arp_arp_input(packet, len); if(len > 0) { IP64_ETH_DRIVER.output(packet, len); } } else if(ethhdr->type == UIP_HTONS(IP64_ETH_TYPE_IP) && len > sizeof(struct ip64_eth_hdr)) { printf("-------------->\n"); uip_len = ip64_4to6(&packet[sizeof(struct ip64_eth_hdr)], len - sizeof(struct ip64_eth_hdr), &uip_buf[UIP_LLH_LEN]); if(uip_len > 0) { printf("ip64_interface_process: converted %d bytes\n", uip_len); printf("ip64-interface: input source "); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF(" destination "); PRINT6ADDR(&UIP_IP_BUF->destipaddr); PRINTF("\n"); tcpip_input(); printf("Done\n"); } } }
/*---------------------------------------------------------------------------*/ static void pollhandler(void) { #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) /* Poll Ethernet device to see if there is a frame avaliable. */ uip_len = cs8900a_poll(); if(uip_len > 0) { /* A frame was avaliable (and is now read into the uip_buf), so we process it. */ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_len -= sizeof(struct uip_eth_hdr); tcpip_input(); } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { cs8900a_send(); } } } }
/*---------------------------------------------------------------------------*/ static void recv_data(struct unicast_conn *c, const linkaddr_t *from) { struct route_entry *e; linkaddr_t source; uip_len = packetbuf_copyto(&uip_buf[UIP_LLH_LEN]); source.u8[0] = BUF->srcipaddr.u8[2]; source.u8[1] = BUF->srcipaddr.u8[3]; e = route_lookup(&source); if(e == NULL) { route_add(&source, from, 10, 0); } else { route_refresh(e); } /* If we received data via a gateway, we refresh the gateway route. * Note: we refresh OUR gateway route, although we are not sure it forwarded the data. */ if(!uip_ipaddr_maskcmp(&BUF->srcipaddr, &netaddr, &netmask)) { e = route_lookup(&gateway); if(e != NULL) { route_refresh(e); } } PRINTF("uip-over-mesh: %d.%d: recv_data with len %d\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1], uip_len); tcpip_input(); }
err_t eth_input(struct pbuf *p, struct netif *inp) { struct eth_hdr *ethhdr; if(p != RT_NULL) { #ifdef LINK_STATS LINK_STATS_INC(link.recv); #endif /* LINK_STATS */ ethhdr = p->payload; switch(htons(ethhdr->type)) { case ETHTYPE_IP: etharp_ip_input(inp, p); pbuf_header(p, -(s16_t) sizeof(struct eth_hdr)); tcpip_input(p, inp); break; case ETHTYPE_ARP: etharp_arp_input(inp, (struct eth_addr *)inp->hwaddr, p); break; default: pbuf_free(p); p = RT_NULL; break; } } return ERR_OK; }
static void handle_fd(fd_set *rset, fd_set *wset) { /* Optional delay between outgoing packets */ /* Base delay times number of 6lowpan fragments to be sent */ /* delaymsec = 10; */ if(delaymsec) { struct timeval tv; int dmsec; gettimeofday(&tv, NULL); dmsec=(tv.tv_sec-delaystartsec)*1000+tv.tv_usec/1000-delaystartmsec; if(dmsec<0) delaymsec=0; if(dmsec>delaymsec) delaymsec=0; } if(delaymsec==0) { int size; if(FD_ISSET(tunfd, rset)) { size = tun_input(&uip_buf[UIP_LLH_LEN], sizeof(uip_buf)); /* printf("TUN data incoming read:%d\n", size); */ uip_len = size; tcpip_input(); if(slip_config_basedelay) { struct timeval tv; gettimeofday(&tv, NULL) ; delaymsec=slip_config_basedelay; delaystartsec =tv.tv_sec; delaystartmsec=tv.tv_usec/1000; } } } }
static void receiver(const struct radio_driver *d) { uip_len = cc1020_read(&uip_buf[UIP_LLH_LEN], UIP_BUFSIZE - UIP_LLH_LEN); if(uip_len > 0) { uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], uip_len); tcpip_input(); } }
/*---------------------------------------------------------------------------*/ static void pollhandler(void) { uip_len = rs232dev_poll(); if(uip_len > 0) { tcpip_input(); } }
/*---------------------------------------------------------------------------*/ static void tr1001_uip_callback(const struct radio_driver *driver) { uip_len = driver->read(&uip_buf[UIP_LLH_LEN], UIP_BUFSIZE - UIP_LLH_LEN); if(uip_len > 0) { uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], uip_len); tcpip_input(); } }
/*--------------------------------------------------------------------*/ static void input(void) { if(packetbuf_datalen() > 0 && packetbuf_datalen() <= UIP_BUFSIZE - UIP_LLH_LEN) { memcpy(&uip_buf[UIP_LLH_LEN], packetbuf_dataptr(), packetbuf_datalen()); uip_len = packetbuf_datalen(); tcpip_input(); } }
static void net_rx_fiber(void) { struct net_buf *buf; NET_DBG("Starting RX fiber\n"); while (1) { buf = nano_fifo_get_wait(&netdev.rx_queue); /* Check stack usage (no-op if not enabled) */ analyze_stacks(buf, &buf); if (!tcpip_input(buf)) { net_buf_put(buf); } else { NET_BUF_CHECK_IF_NOT_IN_USE(buf); } } }
/* Eth Isr routine */ static void Eth_Isr(void) { uint32_t res = 0; while((ETH_GetRxPktSize() != 0) && (res == 0)) { /* move received packet into a new pbuf */ struct pbuf *p = low_level_input(&netif); if(p!=NULL){ tcpip_input(p, &netif); }else{ res = 1; } } /* Clear the Eth DMA Rx IT pending bits */ ETH_DMAClearITPendingBit(ETH_DMA_IT_R); ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS); ETH_DMAClearITPendingBit(ETH_DMA_IT_RO); ETH_DMAClearITPendingBit(ETH_DMA_IT_RBU); }
err_t eth_input(struct pbuf *p,struct netif *inp) { struct eth_hdr *ethhdr; if(p != NULL) { #ifdef LINK_STATS //LINK_STATS_INC(link.recv); #endif LINK_STATS ethhdr = p->payload; switch(uip_htons(ethhdr->type)) { case ETHTYPE_IP: //ETHTYPE_IP etharp_ip_input(inp, p); pbuf_header(p, -((rt_int16_t)sizeof(struct eth_hdr))); if (tcpip_input(p, inp) != ERR_OK) { // discard packet pbuf_free(p); } break; case ETHTYPE_ARP: etharp_arp_input(inp, (struct eth_addr *)inp->hwaddr, p); break; default: pbuf_free(p); p = NULL; break; } } return ERR_OK; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(ethernode_uip_process, ev, data) { PROCESS_BEGIN(); while(1) { process_poll(ðernode_uip_process); PROCESS_WAIT_EVENT(); /* Poll Ethernet device to see if there is a frame avaliable. */ uip_len = ethernode_read(uip_buf, UIP_BUFSIZE); if(uip_len > 0) { /* printf("%d: new packet len %d\n", node_id, uip_len);*/ /* if((random_rand() % drop) <= drop / 2) { printf("Bropp\n"); } else*/ { uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], uip_len); #ifdef __CYGWIN__ wpcap_send(); #else /* __CYGWIN__ */ tapdev_send(); #endif /* __CYGWIN__ */ /* if(uip_fw_forward() == UIP_FW_LOCAL)*/ { /* A frame was avaliable (and is now read into the uip_buf), so we process it. */ tcpip_input(); } } } } PROCESS_END(); }
static void netfront_input(struct netif *netif, unsigned char* data, int len) { struct eth_hdr *ethhdr; struct pbuf *p, *q; #if ETH_PAD_SIZE len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif /* move received packet into a new pbuf */ p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); if (p == NULL) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); return; } #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* We iterate over the pbuf chain until we have read the entire * packet into the pbuf. */ for(q = p; q != NULL && len > 0; q = q->next) { /* Read enough bytes to fill this pbuf in the chain. The * available data in the pbuf is given by the q->len * variable. */ memcpy(q->payload, data, len < q->len ? len : q->len); data += q->len; len -= q->len; } #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.recv); /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP packet? */ case ETHTYPE_IP: #if 0 /* CSi disabled ARP table update on ingress IP packets. This seems to work but needs thorough testing. */ /* update ARP table */ etharp_ip_input(netif, p); #endif /* skip Ethernet header */ pbuf_header(p, -(int16_t)sizeof(struct eth_hdr)); /* pass to network layer */ if (tcpip_input(p, netif) == ERR_MEM) /* Could not store it, drop */ pbuf_free(p); break; case ETHTYPE_ARP: /* pass p to ARP module */ etharp_arp_input(netif, (struct eth_addr *) netif->hwaddr, p); break; default: pbuf_free(p); p = NULL; break; } }
/** * \brief Take a packet received over the ethernet link, and send it * out over 802.15.4 */ void mac_ethernetToLowpan(uint8_t * ethHeader) { //Dest address uip_lladdr_t destAddr; uip_lladdr_t *destAddrPtr = NULL; PRINTF("Packet type: 0x%04x\n\r", uip_ntohs(((struct uip_eth_hdr *) ethHeader)->type)); //RUM doesn't support sending data #if UIP_CONF_USE_RUM return; #endif /* In sniffer or sneezr mode we don't ever send anything */ if ((usbstick_mode.sendToRf == 0) || (usbstick_mode.sneeze != 0)) { uip_len = 0; return; } /* If not IPv6 we don't do anything. Disable ipv4 on the interface to prevent possible hangs from discovery packet flooding */ if (((struct uip_eth_hdr *) ethHeader)->type != UIP_HTONS(UIP_ETHTYPE_IPV6)) { PRINTF("eth2low: Dropping packet w/type=0x%04x\n",uip_ntohs(((struct uip_eth_hdr *) ethHeader)->type)); // printf("!ipv6"); #if !RF230BB && !RF212BB usb_eth_stat.txbad++; #endif uip_len = 0; return; } /* IPv6 uses 33-33-xx-xx-xx-xx prefix for multicast ND stuff */ if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0x33) && (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0x33) ) { PRINTF("eth2low: Ethernet multicast packet received\n\r"); ;//Do Nothing } else if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0xFF) && (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0xFF) && (((struct uip_eth_hdr *) ethHeader)->dest.addr[2] == 0xFF) && (((struct uip_eth_hdr *) ethHeader)->dest.addr[3] == 0xFF) && (((struct uip_eth_hdr *) ethHeader)->dest.addr[4] == 0xFF) && (((struct uip_eth_hdr *) ethHeader)->dest.addr[5] == 0xFF) ) { /* IPv6 does not use broadcast addresses, hence this should not happen */ PRINTF("eth2low: Dropping broadcast packet\n\r"); #if !RF230BB && !RF212BB usb_eth_stat.txbad++; #endif uip_len = 0; return; } else { /* Simple Address Translation */ if(memcmp((uint8_t *)&simple_trans_ethernet_addr, &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), 6) == 0) { #if UIP_CONF_IPV6 //Addressed to us: make 802.15.4 address from IPv6 Address destAddr.addr[0] = UIP_IP_BUF->destipaddr.u8[8] ^ 0x02; destAddr.addr[1] = UIP_IP_BUF->destipaddr.u8[9]; destAddr.addr[2] = UIP_IP_BUF->destipaddr.u8[10]; destAddr.addr[3] = UIP_IP_BUF->destipaddr.u8[11]; destAddr.addr[4] = UIP_IP_BUF->destipaddr.u8[12]; destAddr.addr[5] = UIP_IP_BUF->destipaddr.u8[13]; destAddr.addr[6] = UIP_IP_BUF->destipaddr.u8[14]; destAddr.addr[7] = UIP_IP_BUF->destipaddr.u8[15]; #else //Not intended to be functional, but allows ip4 build without errors. destAddr.addr[0] = UIP_IP_BUF->destipaddr.u8[0] ^ 0x02; destAddr.addr[1] = UIP_IP_BUF->destipaddr.u8[1]; destAddr.addr[2] = UIP_IP_BUF->destipaddr.u8[2]; destAddr.addr[3] = UIP_IP_BUF->destipaddr.u8[3]; destAddr.addr[4] = UIP_IP_BUF->destipaddr.u8[0]; destAddr.addr[5] = UIP_IP_BUF->destipaddr.u8[1]; destAddr.addr[6] = UIP_IP_BUF->destipaddr.u8[2]; destAddr.addr[7] = UIP_IP_BUF->destipaddr.u8[3]; #endif destAddrPtr = &destAddr; } #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS else { //Not addressed to us uip_len = 0; return; } #else /* Complex Address Translation */ PRINTF("eth2low: Addressed packet received... "); //Check this returns OK if (mac_createSicslowpanLongAddr( &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), &destAddr) == 0) { PRINTF(" translation failed\n\r"); #if !RF230BB && !RF212BB usb_eth_stat.txbad++; #endif uip_len = 0; return; } PRINTF(" translated OK\n\r"); destAddrPtr = &destAddr; #endif /* UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS */ } //Remove header from length before passing onward uip_len -= UIP_LLH_LEN; //Some IP packets have link layer in them, need to change them around! if (usbstick_mode.translate) { #if DEBUG uint8_t transReturn = mac_translateIPLinkLayer(ll_802154_type); PRINTF("IPTranslation: returns %d\n\r", transReturn); #else mac_translateIPLinkLayer(ll_802154_type); #endif } #if UIP_CONF_IPV6 /* Send the packet to the uip6 stack if it exists, else send to 6lowpan */ #if UIP_CONF_IPV6_RPL /* Save the destination address, to trap ponging it back to the interface */ uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr); tcpip_input(); tcpip_output(destAddrPtr); #else // PRINTF("Input from %x %x %x %x %x %x %x %x\n",UIP_IP_BUF->srcipaddr.u8[0],UIP_IP_BUF->srcipaddr.u8[1],UIP_IP_BUF->srcipaddr.u8[2],UIP_IP_BUF->srcipaddr.u8[3],UIP_IP_BUF->srcipaddr.u8[4],UIP_IP_BUF->srcipaddr.u8[5],UIP_IP_BUF->srcipaddr.u8[6],UIP_IP_BUF->srcipaddr.u8[7]); // PRINTF("Output to %x %x %x %x %x %x %x %x\n",destAddr.addr[0],destAddr.addr[1],destAddr.addr[2],destAddr.addr[3],destAddr.addr[4],destAddr.addr[5],destAddr.addr[6],destAddr.addr[7]); tcpip_output(destAddrPtr); #endif #else /* UIP_CONF_IPV6 */ tcpip_output(); //Allow non-ipv6 builds (Hello World) #endif /* UIP_CONF_IPV6 */ #if !RF230BB && !RF212BB usb_eth_stat.txok++; #endif uip_len = 0; }
PROCESS_THREAD(cc2420_process, ev, data) { PROCESS_BEGIN(); process_start(&cc2420_retransmit_process, NULL); while (1) { unsigned len; int s; PROCESS_YIELD(); len = rx_fifo_remaining_bytes; if (len > 0) { /* Read payload and two bytes of footer */ if ((len - 2) > (UIP_BUFSIZE - UIP_LLH_LEN) || len < 2) { PRINTF("cc2420_process too big len=%d\n", len); s = splhigh(); FASTSPI_READ_FIFO_GARBAGE(len); rx_fifo_remaining_bytes = 0; /* RX FIFO emptied! */ splx(s); len = 0; } else { u8_t footer[2]; uip_len = 0; s = splhigh(); if (len > 2) FASTSPI_READ_FIFO_NO_WAIT(&uip_buf[UIP_LLH_LEN], len - 2); FASTSPI_READ_FIFO_NO_WAIT(footer, 2); rx_fifo_remaining_bytes = 0; /* RX FIFO emptied! */ splx(s); if (footer[1] & FOOTER1_CRC_OK) { cc2420_last_rssi = footer[0]; cc2420_last_correlation = footer[1] & FOOTER1_CORRELATION; if ((h.fc0 & FC0_TYPE_MASK) == FC0_TYPE_DATA) uip_len = len - 2; } } } if (len == 2) PRINTF("recv data_ack\n"); /* Clean up in case of FIFO overflow! This happens for every full * length frame and is signaled by FIFOP = 1 and FIFO = 0. */ if (FIFOP_IS_1 && !FIFO_IS_1) { cc2420_strobe(CC2420_SFLUSHRX); cc2420_strobe(CC2420_SFLUSHRX); } if (FIFOP_IS_1) { s = splhigh(); __cc2420_intr(); /* Fake interrupt! */ splx(s); } if (len == 2) { /* A DATA ACK packet. */ if (last_dst == h.src) cc2420_ack_received = 1; neigbour_update(h.src, 0); } else if (len > 2 && uip_len > 0 && uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1])) { /* * If we are the unique receiver send DATA ACK. */ if (h.dst == 0xffff && uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) cc2420_send_data_ack(h.src); leds_toggle(LEDS_GREEN); cc2420_is_input = 1; tcpip_input(); cc2420_is_input = 0; leds_toggle(LEDS_GREEN); } } PROCESS_END(); }
int main(int argc, char **argv) { printf("uIPv6 test project\n"); uip_ipaddr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); if((ipaddr.u16[0] != 0) || (ipaddr.u16[1] != 0) || (ipaddr.u16[2] != 0) || (ipaddr.u16[3] != 0)) { uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); } printf("Process subsystem init\n"); process_init(); printf("Ok\n"); printf("Start etimer process\n"); process_start(&etimer_process, NULL); printf("Ok\n"); printf("Init ctimer\n"); ctimer_init(); printf("Ok\n"); printf("Init tapdev\n"); tapdev_init(); tcpip_set_outputfunc(tapdev_send); printf("Ok\n"); printf("Start tcpip process\n"); process_start(&tcpip_process, NULL); printf("Ok\n"); printf("Start TCP server on 8080 port\n"); process_start(&tcp_server, NULL); printf("Ok\n"); uint8_t i; for(i = 0; i < UIP_DS6_ADDR_NB; i++) { if(uip_ds6_if.addr_list[i].isused) { printf("IPV6 Addresss: "); printf("%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X", uip_ds6_if.addr_list[i].ipaddr.u8[0], uip_ds6_if.addr_list[i].ipaddr.u8[1], uip_ds6_if.addr_list[i].ipaddr.u8[2], uip_ds6_if.addr_list[i].ipaddr.u8[3], uip_ds6_if.addr_list[i].ipaddr.u8[4], uip_ds6_if.addr_list[i].ipaddr.u8[5], uip_ds6_if.addr_list[i].ipaddr.u8[6], uip_ds6_if.addr_list[i].ipaddr.u8[7], uip_ds6_if.addr_list[i].ipaddr.u8[8], uip_ds6_if.addr_list[i].ipaddr.u8[9], uip_ds6_if.addr_list[i].ipaddr.u8[10], uip_ds6_if.addr_list[i].ipaddr.u8[11], uip_ds6_if.addr_list[i].ipaddr.u8[12], uip_ds6_if.addr_list[i].ipaddr.u8[13], uip_ds6_if.addr_list[i].ipaddr.u8[14], uip_ds6_if.addr_list[i].ipaddr.u8[15]); printf("\n"); } } while(1){ process_run(); etimer_request_poll(); uip_len = tapdev_poll(); if(uip_len > 0){ if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)){ tcpip_input(); } } } }
/*---------------------------------------------------------------------------*/ static void receiver(const struct radio_driver *d) { uip_len = d->read((char*)UIP_IP_BUF, UIP_BUFSIZE - UIP_LLH_LEN); tcpip_input(); }
PROCESS_THREAD(usb_eth_process, ev , data) { PROCESS_BEGIN(); usb_register_request_handler(&cdc_eth_request_hook); usb_setup(); usb_set_ep_event_process(DATA_OUT, process_current); usb_set_global_event_process(process_current); uip_fw_default(&usbethif); uip_setethaddr(default_uip_ethaddr); uip_arp_init(); while(1) { PROCESS_WAIT_EVENT(); if (ev == PROCESS_EVENT_EXIT) break; if (ev == PROCESS_EVENT_POLL) { unsigned int events = usb_get_global_events(); if (events) { if (events & USB_EVENT_CONFIG) { if (usb_get_current_configuration() != 0) { printf("Configured\n"); usb_setup_bulk_endpoint(DATA_IN); usb_setup_bulk_endpoint(DATA_OUT); usb_setup_interrupt_endpoint(INTERRUPT_IN); init_recv_buffer(); usb_submit_recv_buffer(DATA_OUT, &recv_buffer); #if 0 { static const uint8_t foo[4] = {0x12,0x34,0x56,0x78}; xmit_buffer[0].next = NULL; xmit_buffer[0].left = sizeof(foo); xmit_buffer[0].flags = USB_BUFFER_SHORT_END; xmit_buffer[0].data = &foo; usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]); } #endif } else { usb_disable_endpoint(DATA_IN); usb_disable_endpoint(DATA_OUT); usb_disable_endpoint(INTERRUPT_IN); } } } events = usb_get_ep_events(DATA_OUT); if (events & USB_EP_EVENT_NOTIFICATION) { uip_len = sizeof(recv_data) - recv_buffer.left; /* printf("Received: %d bytes\n", uip_len); */ memcpy(uip_buf, recv_data, uip_len); #if UIP_CONF_IPV6 if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src); tcpip_input(); } else #endif /* UIP_CONF_IPV6 */ if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) { uip_len -= sizeof(struct uip_eth_hdr); tcpip_input(); } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { memcpy(xmit_data, uip_buf, uip_len); xmit_buffer[0].next = NULL; xmit_buffer[0].data = xmit_data; xmit_buffer[0].left = uip_len; xmit_buffer[0].flags = USB_BUFFER_SHORT_END; usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]); /* printf("Sent: %d bytes\n", uip_len); */ } } init_recv_buffer(); usb_submit_recv_buffer(DATA_OUT, &recv_buffer); } } } PROCESS_END(); }
/** * Process tx and rx packets at the low-level interrupt. * * Should be called from the Stellaris Ethernet Interrupt Handler. This * function will read packets from the Stellaris Ethernet fifo and place them * into a pbuf queue. If the transmitter is idle and there is at least one packet * on the transmit queue, it will place it in the transmit fifo and start the * transmitter. * */ void stellarisif_interrupt(struct netif *netif) { struct stellarisif *stellarisif; struct pbuf *p; /* setup pointer to the if state data */ stellarisif = netif->state; /** * Process the transmit and receive queues as long as there is receive * data available * */ p = stellarisif_receive(netif); while(p != NULL) { /* process the packet */ #if NO_SYS if(ethernet_input(p, netif)!=ERR_OK) { #else if(tcpip_input(p, netif)!=ERR_OK) { #endif /* drop the packet */ LWIP_DEBUGF(NETIF_DEBUG, ("stellarisif_input: input error\n")); pbuf_free(p); /* Adjust the link statistics */ LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); } /* Check if TX fifo is empty and packet available */ if((HWREG(ETH_BASE + MAC_O_TR) & MAC_TR_NEWTX) == 0) { p = dequeue_packet(&stellarisif->txq); if(p != NULL) { stellarisif_transmit(netif, p); } } /* Read another packet from the RX fifo */ p = stellarisif_receive(netif); } /* One more check of the transmit queue/fifo */ if((HWREG(ETH_BASE + MAC_O_TR) & MAC_TR_NEWTX) == 0) { p = dequeue_packet(&stellarisif->txq); if(p != NULL) { stellarisif_transmit(netif, p); } } } #if NETIF_DEBUG /* Print an IP header by using LWIP_DEBUGF * @param p an IP packet, p->payload pointing to the IP header */ void stellarisif_debug_print(struct pbuf *p) { struct eth_hdr *ethhdr = (struct eth_hdr *)p->payload; u16_t *plen = (u16_t *)p->payload; LWIP_DEBUGF(NETIF_DEBUG, ("ETH header:\n")); LWIP_DEBUGF(NETIF_DEBUG, ("Packet Length:%5"U16_F" \n",*plen)); LWIP_DEBUGF(NETIF_DEBUG, ("Destination: %02"X8_F"-%02"X8_F"-%02"X8_F"-%02"X8_F"-%02"X8_F"-%02"X8_F"\n", ethhdr->dest.addr[0], ethhdr->dest.addr[1], ethhdr->dest.addr[2], ethhdr->dest.addr[3], ethhdr->dest.addr[4], ethhdr->dest.addr[5])); LWIP_DEBUGF(NETIF_DEBUG, ("Source: %02"X8_F"-%02"X8_F"-%02"X8_F"-%02"X8_F"-%02"X8_F"-%02"X8_F"\n", ethhdr->src.addr[0], ethhdr->src.addr[1], ethhdr->src.addr[2], ethhdr->src.addr[3], ethhdr->src.addr[4], ethhdr->src.addr[5])); LWIP_DEBUGF(NETIF_DEBUG, ("Packet Type:0x%04"U16_F" \n", ethhdr->type)); }
/*---------------------------------------------------------------------------*/ static void pollhandler(void) { #if !FALLBACK_HAS_ETHERNET_HEADERS //native br is fallback only process_poll(&wpcap_process); uip_len = wpcap_poll(); if(uip_len > 0) { #if UIP_CONF_IPV6 if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { printf("wpcap poll calls tcpip"); tcpip_input(); } else #endif /* UIP_CONF_IPV6 */ if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) { uip_len -= sizeof(struct uip_eth_hdr); tcpip_input(); #if !UIP_CONF_IPV6 } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); //math /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { wpcap_send(); } #endif /* !UIP_CONF_IPV6 */ } else { uip_len = 0; } } #endif #ifdef UIP_FALLBACK_INTERFACE process_poll(&wpcap_process); uip_len = wfall_poll(); if(uip_len > 0) { #if FALLBACK_HAS_ETHERNET_HEADERS if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { //remove ethernet header and pass ipv6 packet to stack uip_len-=14; //{int i;printf("\n0000 ");for (i=0;i<uip_len;i++) printf("%02x ",*(unsigned char*)(uip_buf+i));printf("\n");} // memcpy(uip_buf, uip_buf+14, uip_len); memcpy(&uip_buf[UIP_LLH_LEN], uip_buf+14, uip_len); //LLH_LEN is zero for native border router to slip radio // CopyMemory(uip_buf, uip_buf+14, uip_len); //{int i;printf("\n0000 ");for (i=0;i<uip_len;i++) printf("%02x ",*(char*)(uip_buf+i));printf("\n");} tcpip_input(); } else goto bail; #elif UIP_CONF_IPV6 if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { tcpip_input(); } else goto bail; #endif /* UIP_CONF_IPV6 */ if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) { uip_len -= sizeof(struct uip_eth_hdr); tcpip_input(); #if !UIP_CONF_IPV6 } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); //math /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { wfall_send(); } #endif /* !UIP_CONF_IPV6 */ } else { bail: uip_len = 0; } } #endif }