void UIP_UDP_APPCALL(void) { if (uip_flags & UIP_NEWDATA) { printf("UDP: UIP NEWDATA"); if (uip_udp_conn == bc_conn) printf("oops, this should not happen..."); if (uip_udp_conn == app_conn) appHandlePacket(); #ifdef USE_DHCPD if (uip_udp_conn == dhcpd_request_conn) dhcpdHandlePacket(); if (uip_udp_conn == dhcpd_reply_conn) { printf("packet to the reply connection?!?"); while (1); } #endif return; } if (uip_flags & UIP_POLL) { #ifdef USE_UDP if (state==CONNECTED && udp_disconnected==0) { state = NOT_CONNECTED; //lcdClear(); //lcdGoto(0); uint8_t* msg = "disconnected"; int i; //for (i=0; msg[i]; i++) lcdPrintChar(msg[i]); } //printf("{{{UDP: UIP POLL}}}"); if (state==NOT_CONNECTED && uip_udp_conn == bc_conn) { /* UIP does not know about UDP broadcasts, so we fix the ARP table manually * This function is declared static by default, so it needs to be made non-static to * call from here. */ uip_arp_update(&dhcpd_broadcast_ipaddr, &broadcast_ethaddr); uip_send("iLPC2148 Education Board\0", 25); udp_sync = 1000; /* send sync in one second */ //((uint8_t*) uip_appdata)[0] = 0; //uip_send(uip_appdata, 1); printf("<<< sending udp info packet >>>"); return; } if (state==CONNECTED && uip_udp_conn == app_conn) { if (state_change) { ((uint8_t*)uip_appdata)[0] = 's'; ((uint8_t*)uip_appdata)[1] = (uint8_t) switch14; uip_send(uip_appdata, 2); udp_sync = 1000; /* send sync in one second */ printf("<<< sending udp state packet >>>"); return; } if (udp_sync==0) { uip_send("h", 1); /* heartbeat */ udp_sync = 1000; /* send sync in one second */ } } #endif if (uip_udp_conn == dhcpd_reply_conn) dhcpdPollHandler(); return; } }
/*-----------------------------------------------------------------------------------*/ void uip_arp_arpin(void) { if(uip_len < sizeof(struct arp_hdr)) { uip_len = 0; return; } uip_len = 0; if(BUF->opcode == HTONS(ARP_REQUEST)) { /* ARP request. If it asked for our address, we send out a reply. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { /* First, we register the one who made the request in our ARP table, since it is likely that we will do more communication with this host in the future. */ uip_arp_update(BUF->sipaddr, &BUF->shwaddr); /* The reply opcode is 2. */ BUF->opcode = HTONS(2); memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); BUF->dipaddr[0] = BUF->sipaddr[0]; BUF->dipaddr[1] = BUF->sipaddr[1]; BUF->sipaddr[0] = uip_hostaddr[0]; BUF->sipaddr[1] = uip_hostaddr[1]; BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } } else if(BUF->opcode == HTONS(ARP_REPLY)) { /* ARP reply. We insert or update the ARP table if it was meant for us. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { uip_arp_update(BUF->sipaddr, &BUF->shwaddr); } } return; }
void uip_arp_ipin(void) { /* Only insert/update an entry if the source IP address of the incoming IP packet comes from a host on the local network. */ uip_stack_set_active(STACK_ENC); if (uip_ipaddr_maskcmp(IPBUF->srcipaddr, uip_hostaddr, uip_netmask)) uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src)); return; }
void uip_arp_arpin(void) { int ul; if(uip_len < sizeof(struct arp_hdr)) { uip_len = 0; return; } uip_len = 0; switch(BUF->opcode) { case HTONS(ARP_REQUEST): /* ARP request. If it asked for our address, we send out a reply. */ if(BUF->dipaddr[0] == uip_hostaddr[0] && BUF->dipaddr[1] == uip_hostaddr[1]) { /* The reply opcode is 2. */ BUF->opcode = HTONS(2); memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); BUF->dipaddr[0] = BUF->sipaddr[0]; BUF->dipaddr[1] = BUF->sipaddr[1]; BUF->sipaddr[0] = uip_hostaddr[0]; BUF->sipaddr[1] = uip_hostaddr[1]; ul = BUF->hwlen; BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } break; case HTONS(ARP_REPLY): /* ARP reply. We insert or update the ARP table if it was meant for us. */ if(BUF->dipaddr[0] == uip_hostaddr[0] && BUF->dipaddr[1] == uip_hostaddr[1]) { uip_arp_update(BUF->sipaddr, &BUF->shwaddr); } break; } ( void ) ul; return; }
/*-----------------------------------------------------------------------------------*/ void uip_arp_arpin(void) { if(uip_len < sizeof(struct arp_hdr)) { uip_len = 0; return; } uip_len = 0; switch(BUF->opcode) { case htons(ARP_REQUEST): /* ARP request. If it asked for our address, we send out a reply. */ if(BUF->dipaddr[0] == htons((UIP_IPADDR0 << 8) | UIP_IPADDR1) && BUF->dipaddr[1] == htons((UIP_IPADDR2 << 8) | UIP_IPADDR3)) { /* The reply opcode is 2. */ BUF->opcode = htons(2); BUF->dhwaddr = BUF->shwaddr; for(c = 0; c < 6; ++c) { BUF->shwaddr.addr[c] = BUF->ethhdr.src.addr[c] = ethaddr.addr[c]; BUF->ethhdr.dest.addr[c] = BUF->dhwaddr.addr[c]; } BUF->dipaddr[0] = BUF->sipaddr[0]; BUF->dipaddr[1] = BUF->sipaddr[1]; BUF->sipaddr[0] = htons((UIP_IPADDR0 << 8) | UIP_IPADDR1); BUF->sipaddr[1] = htons((UIP_IPADDR2 << 8) | UIP_IPADDR3); BUF->ethhdr.type = htons(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } break; case htons(ARP_REPLY): /* ARP reply. We insert or update the ARP table if it was meant for us. */ if(BUF->dipaddr[0] == htons((UIP_IPADDR0 << 8) | UIP_IPADDR1) && BUF->dipaddr[1] == htons((UIP_IPADDR2 << 8) | UIP_IPADDR3)) { uip_arp_update(BUF->sipaddr, &BUF->shwaddr); } break; } return; }
/** * ARP processing for incoming ARP packets. * * This function should be called by the device driver when an ARP * packet has been received. The function will act differently * depending on the ARP packet type: if it is a reply for a request * that we previously sent out, the ARP cache will be filled in with * the values from the ARP reply. If the incoming ARP packet is an ARP * request for our IP address, an ARP reply packet is created and put * into the uip_buf[] buffer. * * When the function returns, the value of the global variable uip_len * indicates whether the device driver should send out a packet or * not. If uip_len is zero, no packet should be sent. If uip_len is * non-zero, it contains the length of the outbound packet that is * present in the uip_buf[] buffer. * * This function expects an ARP packet with a prepended Ethernet * header in the uip_buf[] buffer, and the length of the packet in the * global variable uip_len. */ void uip_arp_ipin(struct uip_stack *ustack, packet_t *pkt) { struct ip_hdr *ip; struct uip_eth_hdr *eth; eth = (struct uip_eth_hdr *)pkt->data_link_layer; ip = (struct ip_hdr *)pkt->network_layer; if (uip_ip4addr_cmp(ip->destipaddr, ustack->hostaddr)) { /* First, we register the one who made the request in our ARP table, since it is likely that we will do more communication with this host in the future. */ uip_arp_update(ip->srcipaddr, ð->src); } }
/*-----------------------------------------------------------------------------------*/ void uip_arp_ipin(void) { uip_len -= sizeof(struct uip_eth_hdr); /* Only insert/update an entry if the source IP address of the incoming IP packet comes from a host on the local network. */ if((IPBUF->srcipaddr[0] & uip_arp_netmask[0]) != (uip_hostaddr[0] & uip_arp_netmask[0])) { return; } if((IPBUF->srcipaddr[1] & uip_arp_netmask[1]) != (uip_hostaddr[1] & uip_arp_netmask[1])) { return; } uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src)); return; }
/*-----------------------------------------------------------------------------------*/ void uip_arp_ipin(void) { /* Only insert/update an entry if the source IP address of the incoming IP packet comes from a host on the local network. */ if((IPBUF->srcipaddr[0] & htons((UIP_NETMASK0 << 8) | UIP_NETMASK1)) != (htons((UIP_IPADDR0 << 8) | UIP_IPADDR1) & htons((UIP_NETMASK0 << 8) | UIP_NETMASK1))) return; if((IPBUF->srcipaddr[1] & htons((UIP_NETMASK2 << 8) | UIP_NETMASK3)) != (htons((UIP_IPADDR2 << 8) | UIP_IPADDR3) & htons((UIP_NETMASK2 << 8) | UIP_NETMASK3))) return; uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src)); return; }
/*-----------------------------------------------------------------------------------*/ void uip_arp_arpin(void) { if(uip_len < sizeof(struct arp_hdr)) { uip_len = 0; return; } uip_len = 0; switch(BUF->opcode) { case HTONS(ARP_REQUEST): /* ARP request. If it asked for our address, we send out a reply. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr) #ifdef RFM12_ARP_PROXY /* If RFM12 ARP-proxy is enabled, check that one's IP address as well and possibly answer it. */ || uip_ipaddr_maskcmp(BUF->dipaddr, rfm12_stack_hostaddr, rfm12_stack_netmask) #endif #ifdef ZBUS_ARP_PROXY /* If ZBUS ARP-proxy is enabled, check that one's IP address as well and possibly answer it. */ || uip_ipaddr_maskcmp(BUF->dipaddr, zbus_stack_hostaddr, zbus_stack_netmask) #endif #ifdef USB_ARP_PROXY /* If USB ARP-proxy is enabled, check that one's IP address as well and possibly answer it. */ || uip_ipaddr_maskcmp(BUF->dipaddr, usb_stack_hostaddr, usb_stack_netmask) #endif ) { /* First, we register the one who made the request in our ARP table, since it is likely that we will do more communication with this host in the future. */ uip_arp_update(BUF->sipaddr, &BUF->shwaddr); /* The reply opcode is 2. */ BUF->opcode = HTONS(2); memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); for (uint8_t i = 0; i < 4; i ++) flip (uint8_t, ((uint8_t *) BUF->dipaddr)[i], ((uint8_t *) BUF->sipaddr)[i]); /* BUF->dipaddr[0] = BUF->sipaddr[0]; BUF->dipaddr[1] = BUF->sipaddr[1]; BUF->sipaddr[0] = uip_hostaddr[0]; BUF->sipaddr[1] = uip_hostaddr[1]; */ BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } break; case HTONS(ARP_REPLY): /* ARP reply. We insert or update the ARP table if it was meant for us. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { uip_arp_update(BUF->sipaddr, &BUF->shwaddr); } break; } return; }
/*----------------------------------------------------------------------------*/ void uip_arp_arpin(void) { //spark_print("\n****************************uip_arp_arpin\n"); //spark_printLong(uip_len); if(uip_len < sizeof(struct arp_hdr)) { //spark_print("\nuip len is not updated\n"); //spark_printLong(uip_len); uip_len = 0; return; } uip_len = 0; //spark_print("\n\n\nBUF->opcode\n"); //spark_printLong(BUF->opcode); //spark_print("\n\n\nBUF->hwlen\n"); //spark_printLong(BUF->hwlen); //spark_printLong( ((u16_t *)(BUF->dipaddr))[0] ); //spark_printLong( ((u16_t *)(BUF->dipaddr))[1] ); //spark_printLong( ((u16_t *)(uip_hostaddr))[0] ); //spark_printLong( ((u16_t *)(uip_hostaddr))[1] ); switch(BUF->opcode) { case HTONS(ARP_REQUEST): /* ARP request. If it asked for our address, we send out a reply. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { //spark_print("\n\n\n\n-----------------------ARP_REQUESTFOR Me\n"); //spark_print("--------------------------------FOR ME\n"); /* First, we register the one who made the request in our ARP table, since it is likely that we will do more communication with this host in the future. */ uip_arp_update(BUF->sipaddr, &BUF->shwaddr); /* The reply opcode is 2. */ BUF->opcode = HTONS(2); memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); BUF->dipaddr[0] = BUF->sipaddr[0]; BUF->dipaddr[1] = BUF->sipaddr[1]; BUF->sipaddr[0] = uip_hostaddr[0]; BUF->sipaddr[1] = uip_hostaddr[1]; BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } break; case HTONS(ARP_REPLY): //spark_print("\n--------------------------------ARP_REPLY\n"); /* ARP reply. We insert or update the ARP table if it was meant for us. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { //spark_print("\n\n\n\nuip_arp_updating the ARP table \n"); uip_arp_update(BUF->sipaddr, &BUF->shwaddr); } break; } return; }
/*-----------------------------------------------------------------------------------*/ void uip_arp_arpin(void) { if(uip_len < sizeof(struct arp_hdr)) { uip_len = 0; return; } uip_len = 0; switch(BUF->opcode) { case HTONS(ARP_HINT): /* Please note this is not a valid ARP type, this is just a * hint to implement prefetch/refresh of ARP mapping */ /* This is a valid hint if we are the source of this request, * the requested ipaddr is in dipaddress */ if(uip_ipaddr_cmp(BUF->sipaddr, uip_hostaddr)) { /* We first try to check for the destination address * in our ARP table */ if(uip_arp_update(BUF->dipaddr, &broadcast_ethaddr)) { /* If the destination address was not in our ARP table, * we send out an ARP request for the same */ memset(BUF->ethhdr.dest.addr, 0xff, 6); BUF->opcode = HTONS(ARP_REQUEST); /* The other ARP fields of incoming hint are * supposed to be same as ARP broadcast except * the opcode field */ uip_len = sizeof(struct arp_hdr); } } break; case HTONS(ARP_REQUEST): /* ARP request. If it asked for our address, we send out a reply. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { /* First, we register the one who made the request in our ARP table, since it is likely that we will do more communication with this host in the future. */ uip_arp_update(BUF->sipaddr, &BUF->shwaddr); BUF->opcode = HTONS(ARP_REPLY); memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); BUF->dipaddr[0] = BUF->sipaddr[0]; BUF->dipaddr[1] = BUF->sipaddr[1]; BUF->sipaddr[0] = uip_hostaddr[0]; BUF->sipaddr[1] = uip_hostaddr[1]; BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } break; case HTONS(ARP_REPLY): /* ARP reply. We insert or update the ARP table if it was meant for us. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { uip_arp_update(BUF->sipaddr, &BUF->shwaddr); vmm_completion_complete(&uip_arp_prefetch_done); } break; } return; }