void Test_uip_arp_arpin_2(CuTest *tc) { u8_t temp_buf[]= "\x11\x22\x33\x44\x55\x66\x77\x88\x99\x00\xAA\xBB\x08\x06" "\x00\x01" "\x08\x00" "\x06" "\x04" "\x00\x02" "\x77\x88\x99\x00\xAA\xBB" "\xC0\xA8\x00\x03" "\x11\x22\x33\x44\x55\x66" "\xC0\xA8\x00\x02" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00"; u8_t expect_buf[]= "\x77\x88\x99\x00\xAA\xBB\x11\x22\x33\x44\x55\x66\x08\x06" "\x00\x01" "\x08\x00" "\x06" "\x04" "\x00\x02" "\x11\x22\x33\x44\x55\x66" "\xC0\xA8\x00\x02" "\x77\x88\x99\x00\xAA\xBB" "\xC0\xA8\x00\x03"; memcpy(uip_buf,temp_buf,60); uip_len=42; uip_arp_arpin(); CuAssertIntEquals_Msg(tc,"arpin_len 2",0,uip_len); CuAssertTrue_Msg(tc,"tabl check 2",0==memcmp(arp_table,"\xC0\xA8\x00\x03" "\x77\x88\x99\x00\xAA\xBB\x00",11)); }
/*---------------------------------------------------------------------------*/ 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; } } }
void xtcp_process_incoming_packet(chanend mac_tx) { 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); } } } }
void ethernet_service(void) { int i; struct uip_eth_hdr *buf = (struct uip_eth_hdr *)&uip_buf[0]; etimer_request_poll(); process_run(); uip_len = liteethmac_poll(); if(uip_len > 0) { if(buf->type == uip_htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); liteethmac_send(); } } else if(buf->type == uip_htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if(uip_len > 0) liteethmac_send(); } } else if (elapsed(&uip_periodic_event, uip_periodic_period)) { for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { uip_arp_out(); liteethmac_send(); } } } if (elapsed(&uip_arp_event, uip_arp_period)) { uip_arp_timer(); } }
int netif_rx(u8_t *p, u16_t len) { /*avoid Rx packet length > UIP buffer size and cause UIP buffer overflow*/ if (len <= UIP_BUFSIZE + 2) { mt76xx_dev_read(p, len); } else { printf_high("netif_rx length error: %d > %d\n", len, UIP_BUFSIZE + 2); return -1; } if (uip_len > 0) { if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* 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) { uip_arp_out(); mt76xx_dev_send(); } } 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) { mt76xx_dev_send(); } } } return 0; }
/*---------------------------------------------------------------------------*/ 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(); } } } }
void Network::handlePacket(void) { if (uip_len > 0) { /* received packet */ //printf("handlePacket: %d\n", uip_len); if (BUF->type == htons(UIP_ETHTYPE_IP)) { /* IP packet */ uip_arp_ipin(); uip_input(); /* 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) { uip_arp_out(); network_device_send(); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { /*ARP packet */ 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(uip_buf, uip_len); /* ARP ack*/ } } else { printf("Unknown ethernet packet type %04X\n", htons(BUF->type)); uip_len = 0; } } }
void deal(){ int i; if(uip_len > 0) { if(BUF_IF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* 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) { uip_arp_out(); current_dev->eth_tx(current_dev, uip_buf, uip_len); } } else if(BUF_IF->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) { current_dev->eth_tx(current_dev, uip_buf, uip_len); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* 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) { uip_arp_out(); current_dev->eth_tx(current_dev, uip_buf, uip_len); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* 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) { uip_arp_out(); current_dev->eth_tx(current_dev, uip_buf, uip_len); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } //rt_exit_critical(); return 0; }
void NanodeUIP::poll(void) { int i; uip_len = enc28j60PacketReceive(UIP_BUFSIZE,uip_buf); if(uip_len > 0) { if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* 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) { uip_arp_out(); enc28j60PacketSend(uip_len,uip_buf); } } 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) { enc28j60PacketSend(uip_len,uip_buf); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* 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) { uip_arp_out(); enc28j60PacketSend(uip_len,uip_buf); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* 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) { uip_arp_out(); enc28j60PacketSend(uip_len,uip_buf); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } }
/** * @brief Process Network * @param None * @retval None */ void Network_Process(void) { static uint8_t arp_counter = 0; int i; for (i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if (uip_len > 0) { uip_arp_out(); enc28j60_send_packet((uint8_t *)uip_buf, uip_len); } } #if UIP_UDP for (i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if (uip_len > 0) { uip_arp_out(); network_send(); } } #endif /* UIP_UDP */ if (++arp_counter >= 50) { arp_counter = 0; uip_arp_timer(); } uip_len = enc28j60_recv_packet((uint8_t *)uip_buf, UIP_BUFSIZE); if (uip_len > 0) { if (((struct uip_eth_hdr *)&uip_buf[0])->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); enc28j60_send_packet((uint8_t *)uip_buf, uip_len); } } else if (((struct uip_eth_hdr *)&uip_buf[0])->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if (uip_len > 0) { enc28j60_send_packet((uint8_t *)uip_buf, uip_len); } } } }
/** ******************************************************************************************* * @fn void TcpIpMain(void) * @brief Update the uIP stack. * @return None * @attention ******************************************************************************************* */ void TcpIpMain(void) { uint8_t Index; uip_len = nic_poll(); if (uip_len == 0) { // If timed out, call periodic function for each connection if (TcpIpUipTimerCounter >= TCP_IP_CNT_TIME) { TcpIpUipTimerCounter = 0; for (Index = 0; Index < UIP_CONNS; Index++) { uip_periodic(Index); if (uip_len > 0) { uip_arp_out(); nic_send(); } } /* Call the ARP timer function every ~10 seconds. */ if (++TcpIpUipArpTimerCounter >= TCP_IP_ARP_CNT_TIME) { uip_arp_timer(); TcpIpUipArpTimerCounter = 0; } } } else // packet received { // process an IP packet if (TCP_IP_BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); nic_send(); } } // process an ARP packet else if (TCP_IP_BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if (uip_len > 0) nic_send(); } TcpIpUipTimerCounter = 0; } }
void rtos_vnet_recv(struct rgmp_vnet *vnet_dummy, char *data, int len) { // now only support 1 vnet struct vnet_driver_s *vnet = &g_vnet[0]; do { /* Check for errors and update statistics */ /* Check if the packet is a valid size for the uIP buffer configuration */ if (len > CONFIG_NET_BUFSIZE || len < 14) { #ifdef CONFIG_DEBUG cprintf("VNET: receive invalid packet of size %d\n", len); #endif return; } // Copy the data data from the hardware to vnet->sk_dev.d_buf. Set // amount of data in vnet->sk_dev.d_len memcpy(vnet->sk_dev.d_buf, data, len); vnet->sk_dev.d_len = len; /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) #else if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { uip_arp_ipin(&vnet->sk_dev); uip_input(&vnet->sk_dev); // If the above function invocation resulted in data that should be // sent out on the network, the field d_len will set to a value > 0. if (vnet->sk_dev.d_len > 0) { uip_arp_out(&vnet->sk_dev); vnet_transmit(vnet); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(&vnet->sk_dev); // If the above function invocation resulted in data that should be // sent out on the network, the field d_len will set to a value > 0. if (vnet->sk_dev.d_len > 0) { vnet_transmit(vnet); } } } while (0); /* While there are more packets to be processed */ }
static void skel_receive(FAR struct skel_driver_s *skel) { do { /* Check for errors and update statistics */ /* Check if the packet is a valid size for the uIP buffer configuration */ /* Copy the data data from the hardware to skel->sk_dev.d_buf. Set * amount of data in skel->sk_dev.d_len */ /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) #else if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { uip_arp_ipin(&skel->sk_dev); uip_input(&skel->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (skel->sk_dev.d_len > 0) { uip_arp_out(&skel->sk_dev); skel_transmit(skel); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(&skel->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (skel->sk_dev.d_len > 0) { skel_transmit(skel); } } } while (); /* While there are more packets to be processed */ }
PROCESS_THREAD(network_process, ev, data) { PROCESS_BEGIN(); while(1) { PROCESS_PAUSE(); uip_len = enc28j60_read(uip_buf, UIP_BUFSIZE); if (uip_len > 0) { HAL_IWDG_Refresh(&hiwdg); struct uip_eth_hdr *header = ((struct uip_eth_hdr *)&uip_buf[0]); uint16_t packetType = header->type; #ifdef ENC28J60_DEBUG printf("?receivePacket: len: %d, dest: %02x:%02x:%02x:%02x:%02x:%02x, src: %02x:%02x:%02x:%02x:%02x:%02x, type: %d\n", uip_len, header->dest.addr[0], header->dest.addr[1], header->dest.addr[2], header->dest.addr[3], header->dest.addr[4], header->dest.addr[5], header->src.addr[0], header->src.addr[1], header->src.addr[2], header->src.addr[3], header->src.addr[4], header->src.addr[5], packetType ); for (int i = 0; i < uip_len; i++) { printf("%02x ", uip_buf[i]); } printf("\n"); #endif if (packetType == UIP_HTONS(UIP_ETHTYPE_IP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type IP\n"); #endif uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); enc28j60_send(uip_buf, uip_len + sizeof(struct uip_eth_hdr)); } } else if (packetType == UIP_HTONS(UIP_ETHTYPE_ARP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type ARP\n"); #endif uip_arp_arpin(); if (uip_len > 0) { enc28j60_send(uip_buf, uip_len + sizeof(struct uip_eth_hdr)); } } } } PROCESS_END(); }
/** * Receive a single packet. * The contents will be placed in uip_buf, and uIP is called * as appropriate. */ void enc_receive_packet(void) { /* Receive a single packet */ uint8_t header[6]; uint8_t *status = header + 2; WRITE_REG(ENC_ERDPTL, enc_next_packet & 0xFF); WRITE_REG(ENC_ERDPTH, (enc_next_packet >> 8) & 0xFF); enc_rbm(header, 6); /* Update next packet pointer */ enc_next_packet = header[0] | (header[1] << 8); uint16_t data_count = status[0] | (status[1] << 8); if (status[2] & (1 << 7)) { uip_len = data_count; enc_rbm(uip_buf, data_count); if( BUF->type == htons(UIP_ETHTYPE_IP) ) { uip_arp_ipin(); uip_input(); if( uip_len > 0 ) { uip_arp_out(); enc_send_packet(uip_buf, uip_len); uip_len = 0; } } else if( BUF->type == htons(UIP_ETHTYPE_ARP) ) { uip_arp_arpin(); if( uip_len > 0 ) { //uip_arp_out(); enc_send_packet(uip_buf, uip_len); uip_len = 0; } } } uint16_t erxst = READ_REG(ENC_ERXSTL) | (READ_REG(ENC_ERXSTH) << 8); /* Mark packet as read */ if (enc_next_packet == erxst) { WRITE_REG(ENC_ERXRDPTL, READ_REG(ENC_ERXNDL)); WRITE_REG(ENC_ERXRDPTH, READ_REG(ENC_ERXNDH)); } else { WRITE_REG(ENC_ERXRDPTL, (enc_next_packet-1) & 0xFF); WRITE_REG(ENC_ERXRDPTH, ((enc_next_packet-1) >> 8) & 0xFF); } SET_REG_BITS(ENC_ECON2, ENC_ECON2_PKTDEC); }
/** 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)); }
int _kernel_net_uip_recv(desc_t desc_r,desc_t desc_w){ if(desc_r<0 || desc_w<0) return -1; uip_len = g_pf_net_recv_ip_packet(desc_r,uip_buf, sizeof(uip_buf)); if(uip_len > 0) { #if defined(USE_IF_ETHERNET) if(__eth_hdr->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_process(UIP_DATA); /* 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) { uip_arp_out(); g_pf_net_send_ip_packet(desc_w,uip_buf,uip_len); uip_len=0; } } else if(__eth_hdr->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) { g_pf_net_send_ip_packet(desc_w,uip_buf,uip_len); uip_len=0; } } #elif defined(USE_IF_SLIP) uip_process(UIP_DATA); /* 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) { g_pf_net_send_ip_packet(desc_w,uip_buf,uip_len); uip_len=0; } #endif } return 0; }
void ethernet_process(void) { if(linkstate == 0) { Dm9161 *pDm = &gDm9161; if( DM9161_GetLinkSpeed(pDm, 1) != 0 ) { TRACE_INFO("P: Link detected\n\r"); linkstate=1; LED2_ON(); // Auto Negotiate if (!DM9161_AutoNegotiate(pDm)) { TRACE_INFO("P: Auto Negotiate ERROR!\n\r"); return; } } } else { uip_len = network_read(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)){ uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); network_send(); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)){ uip_arp_arpin(); if(uip_len > 0){ network_send(); } } } } }
/* * Ethernet frame received. */ static void FrameReceivedHandler(eventid_t id) { (void)id; while ((uip_len = network_device_read()) > 0) { if (BUF->type == HTONS(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); network_device_send(); } } else if (BUF->type == HTONS(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if (uip_len > 0) network_device_send(); } } }
/*-----------------------------------------------------------------------------------*/ static void rtl8019_drv_idle(void) { /* Poll Ethernet device to see if there is a frame avaliable. */ uip_len = rtl8019as_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)) { /* debug_print16(uip_len);*/ uip_arp_ipin(); uip_len -= sizeof(struct uip_eth_hdr); uip_input(); /* 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) { /* debug_print(PSTR("Sending packet\n"));*/ uip_arp_out(); rtl8019as_send(); } } 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) { rtl8019as_send(); } } } /* Check the clock so see if we should call the periodic uIP processing. */ current = ek_clock(); if((current - start) >= CLK_TCK/2 || (current - start) < 0) { timer(); start = current; } }
void nethandler_rx() { uip_len = network_read(); if (uip_len > 0) { switch (ntohs(BUF->type)) { case UIP_ETHTYPE_IP: uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); network_send(); } break; case UIP_ETHTYPE_ARP: uip_arp_arpin(); if (uip_len > 0) network_send(); break; } } }
/** * \brief Ethernet IO function. * \param void There are no parameters needed. * \return No return values. */ static void eth_poll(void) { /*Get Buffer*/ uip_len = (u16_t)EthernetPacketGet(ETH_BASE, uip_buf, UIP_BUFSIZE); if(uip_len > 0) { if(BUF->type == HTONS(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); EthernetPacketPut(ETH_BASE, uip_buf, uip_len); } } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if(uip_len > 0) { EthernetPacketPut(ETH_BASE, uip_buf, uip_len); } } } EthernetIntEnable(ETH_BASE, ETH_INT_RX); }
void vuIP_Task( void *pvParameters ) { portBASE_TYPE i; unsigned long ulNewEvent = 0UL; unsigned long ulUIP_Events = 0UL; ( void ) pvParameters; /* Initialise the uIP stack. */ prvInitialise_uIP(); /* Initialise the MAC. */ vInitEmac(); while( lEMACWaitForLink() != pdPASS ) { vTaskDelay( uipINIT_WAIT ); } for( ;; ) { if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL ) { /* Is there received data ready to be processed? */ uip_len = ( unsigned short ) ulEMACRead(); if( ( uip_len > 0 ) && ( uip_buf != NULL ) ) { /* Standard uIP loop taken from the uIP manual. */ if( xHeader->type == htons( UIP_ETHTYPE_IP ) ) { uip_arp_ipin(); uip_input(); /* 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 ) { uip_arp_out(); vEMACWrite(); } } else if( xHeader->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 ) { vEMACWrite(); } } } else { ulUIP_Events &= ~uipETHERNET_RX_EVENT; } } if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL ) { ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT; for( i = 0; i < UIP_CONNS; i++ ) { uip_periodic( i ); /* 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 ) { uip_arp_out(); vEMACWrite(); } } } /* Call the ARP timer function every 10 seconds. */ if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 ) { ulUIP_Events &= ~uipARP_TIMER_EVENT; uip_arp_timer(); } if( ulUIP_Events == pdFALSE ) { xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY ); ulUIP_Events |= ulNewEvent; } } }
void vuIP_Task( void *pvParameters ) { portBASE_TYPE i; uip_ipaddr_t xIPAddr; struct timer periodic_timer, arp_timer; extern void ( vEMAC_ISR_Wrapper )( void ); /* Create the semaphore used by the ISR to wake this task. */ vSemaphoreCreateBinary( xEMACSemaphore ); /* Initialise the uIP stack. */ timer_set( &periodic_timer, configTICK_RATE_HZ / 2 ); timer_set( &arp_timer, configTICK_RATE_HZ * 10 ); uip_init(); uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 ); uip_sethostaddr( xIPAddr ); httpd_init(); /* Initialise the MAC. */ while( Init_EMAC() != pdPASS ) { vTaskDelay( uipINIT_WAIT ); } portENTER_CRITICAL(); { MAC_INTENABLE = INT_RX_DONE; VICIntEnable |= 0x00200000; VICVectAddr21 = ( portLONG ) vEMAC_ISR_Wrapper; prvSetMACAddress(); } portEXIT_CRITICAL(); for( ;; ) { /* Is there received data ready to be processed? */ uip_len = uiGetEMACRxData( uip_buf ); if( uip_len > 0 ) { /* Standard uIP loop taken from the uIP manual. */ if( xHeader->type == htons( UIP_ETHTYPE_IP ) ) { uip_arp_ipin(); uip_input(); /* 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 ) { uip_arp_out(); prvENET_Send(); } } else if( xHeader->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 ) { prvENET_Send(); } } } else { if( timer_expired( &periodic_timer ) ) { timer_reset( &periodic_timer ); for( i = 0; i < UIP_CONNS; i++ ) { uip_periodic( i ); /* 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 ) { uip_arp_out(); prvENET_Send(); } } /* Call the ARP timer function every 10 seconds. */ if( timer_expired( &arp_timer ) ) { timer_reset( &arp_timer ); uip_arp_timer(); } } else { /* We did not receive a packet, and there was no periodic processing to perform. Block for a fixed period. If a packet is received during this period we will be woken by the ISR giving us the Semaphore. */ xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 ); } } } }
static void e1000_receive(struct e1000_dev *e1000) { int head = e1000->rx_ring.head; unsigned char *cp = (unsigned char *) (e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); int cnt; while (e1000->rx_ring.desc[head].desc_status) { /* Check for errors and update statistics */ // Here we do not handle packets that exceed packet-buffer size if ((e1000->rx_ring.desc[head].desc_status & 3) == 1) { cprintf("NIC READ: Oversized packet\n"); goto next; } /* Check if the packet is a valid size for the uIP buffer configuration */ // get the number of actual data-bytes in this packet cnt = e1000->rx_ring.desc[head].packet_length; if (cnt > CONFIG_NET_BUFSIZE || cnt < 14) { cprintf("NIC READ: invalid package size\n"); goto next; } /* Copy the data data from the hardware to e1000->uip_dev.d_buf. Set * amount of data in e1000->uip_dev.d_len */ // now we try to copy these data-bytes to the UIP buffer memcpy(e1000->uip_dev.d_buf, cp, cnt); e1000->uip_dev.d_len = cnt; /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) #else if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { uip_arp_ipin(&e1000->uip_dev); uip_input(&e1000->uip_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (e1000->uip_dev.d_len > 0) { uip_arp_out(&e1000->uip_dev); e1000_transmit(e1000); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(&e1000->uip_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (e1000->uip_dev.d_len > 0) { e1000_transmit(e1000); } } next: e1000->rx_ring.desc[head].desc_status = 0; e1000->rx_ring.head = (head + 1) % CONFIG_E1000_N_RX_DESC; e1000->rx_ring.free++; head = e1000->rx_ring.head; cp = (unsigned char *)(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); } }
void uip_task(void *p) { int i; struct timer periodic_timer, arp_timer; enc28j60_open(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); while(1) { socket_process_pending_lists_(); uip_len = enc28j60_read(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_input(); /* 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) { uip_arp_out(); enc28j60_write(); } } 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) { enc28j60_write(); } } } if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* 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) { uip_arp_out(); enc28j60_write(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* 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) { uip_arp_out(); enc28j60_write(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } //yield so that other tasks can do something sys_msleep(UIP_TASK_YIELD_TIME_MS); } }
int main(int argc, char *argv[]) { uip_ipaddr_t ipaddr; int i; struct timer periodic_timer, arp_timer; if(connect_pci() < 0) return 1; printf("Starting up stack!\n"); uip_init(); uip_ipaddr(ipaddr, 192,168,1,8); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,1,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); uip_setethaddr(rtl8139_mac); resolv_init(); dhcpc_init(rtl8139_mac, 6); // httpd_init(); resolv_query("grindars.org.ru"); printf("Stack started\n"); while(1) { uip_len = rtl8139_poll(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* 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) { uip_arp_out(); rtl8139_transmit(); } } 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) { rtl8139_transmit(); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* 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) { uip_arp_out(); rtl8139_transmit(); } } //#if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* 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) { uip_arp_out(); rtl8139_transmit(); } } //#endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } return 0; }
/** 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); }
int main(void) { struct timer periodic_timer, arp_timer; // Flash the status LED two times to indicate that the AVR controller is living STATUS_LED_on(); _delay_ms(20); STATUS_LED_off(); _delay_ms(100); STATUS_LED_on(); _delay_ms(20); STATUS_LED_off(); // Initialize direction and level of I/O pins init_io_pins(); #if ADC_CHANNELS > 0 // initialize ADC converter initADC(); #endif // enable io functions isBusy=0; // Initialize system clock timers. clock_init(); timer_set(&periodic_timer, CLOCK_SECOND); timer_set(&arp_timer, CLOCK_SECOND*10); // check if the config reset jumper is connected. check_for_reset_jumper(); #ifdef SERIAL // start the serial port server seriald_init(); #endif // SERIAL // initialize ethernet controller // loop until link comes up while (init_CP2200()==0) { _delay_ms(200); } // replace config by hardcoded defaults if the flash is unprogrammed (all bits 1) if (uip_ipaddr_cmp(config.ipaddr, all_ones_addr) && uip_ipaddr_cmp(config.netmask, all_ones_addr) && uip_ipaddr_cmp(config.gateway, all_ones_addr)) { set_defaults(); } // initialize uIP protocol uip_arp_init(); uip_init(); // Configure the IP-Adrdess IP_config(); #ifdef EMAIL_APP // Initialize the email application email_app_init(); #endif // EMAIL_APP // Initialize the inetd inetd_init(); // main loop, dispatches network and timer events while (1) { uip_len = network_device_read(); if (uip_len > 0) { if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); // 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) { uip_arp_out(); network_device_send(); } } 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) { network_device_send(); } } } else if (timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for (int i = 0; i < UIP_CONNS; i++) { uip_periodic(i); // 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) { uip_arp_out(); network_device_send(); } } #if UIP_UDP for (int i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); // 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) { uip_arp_out(); network_device_send(); } } #endif // UIP_UDP // Call the ARP timer function every 10 seconds. if (timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } #ifdef EMAIL_APP email_app_main_loop(); #endif //EMAIL_APP } return 0; }