uint8_t vNet_RetrieveData_M1(uint8_t *data) { // Retrieve the first byte of the message uint8_t len=*appdata; uint8_t* ip_addr; // Retrieve the complete message if((len>0 && len <= vnetlenght) && len <= (VNET_MAX_FRAME)) { memmove(data, appdata+1, len-1); vnetlenght = 0; // Reset the length // Verify the incoming address, is a not conventional procedure at this layer // but is required to record the IP address in case of User Mode addresses #if(UMODE_ENABLE) // Get the IP source address for the last frame, ripadrr and sportnumber are processed // in vNet_UDP_callback() with a callback from the uIP stack. // Is an UserMode frame, record the incoming source information if(((*(U16*)&data[4]) & 0xFF00) != 0x0000) { sportnumber = HTONS(sportnumber); // Swap byte before record the source port UserMode_Record((*(U16*)&data[4]), ripadrr, (uint8_t*)&sportnumber); } #endif } else { vnetlenght = 0; return ETH_FAIL; } return len; }
uint8_t vNet_RetrieveData_M1(uint8_t *data) { uint8_t *data_pnt; data_pnt=data; if(!recvfrom(UDP_SOCK, data, dataframe.len, dataframe.ip, (uint16_t*)(&dataframe.port))) return ETH_FAIL; // Verify the incoming address, is a not conventional procedure at this layer // but is required to record the IP address in case of User Mode addresses (0x0100 - 0x64FF) #if(UMODE_ENABLE) uint16_t umrec = ((*(U16*)&data_pnt[5]) & 0xFF00); if((umrec != 0x0000) && (umrec <= VNET_ADDR_H_M1)) UserMode_Record((*(U16*)&data_pnt[5]), dataframe.ip, (uint8_t *)(&dataframe.port)); #endif // If the addressing server is used, get the subnet from the first broadcast // message received. This trick is due to the missing DHCP support in vNet/IP // and is supposed to work in most, but not all cases (fixed address will be needed // in case of failure) #if(UMODE_ENABLE && DYNAMICADDRESSING) if(addrsrv == true) { // Use the incoming IP address to get the subnet to use, we are not changing // the part of the IP address related to the vNet address uint8_t i; for(i=0;i<4;i++) { // Remove the subnet bits from the actual address stack.base_ip[i] &= ~stack.subnetmask[i]; stack.ip[i] &= ~stack.subnetmask[i]; stack.gateway[i] &= ~stack.subnetmask[i]; // Get the subnet bits from the incoming adress stack.base_ip[i] |= (dataframe.ip[i] & stack.subnetmask[i]); stack.ip[i] |= (dataframe.ip[i] & stack.subnetmask[i]); stack.gateway[i] |= (dataframe.ip[i] & stack.subnetmask[i]); } // Reset the IP drivers W5x00.setIPAddress(stack.ip); W5x00.setGatewayIp(stack.gateway); W5x00.setSubnetMask(stack.subnetmask); vNet_Begin_M1(UDP_SOCK); // Start listen on socket addrsrv = false; } #endif // Remove the header data_pnt++; dataframe.len--; memmove(data, data_pnt, dataframe.len); return dataframe.len; }