*** stock_iot-lab_M3/openwsn/cross-layers/packetfunctions.c Thu Apr 24 11:01:37 2014 --- riot-openwsn-wip/openwsn/cross-layers/packetfunctions.c Thu Apr 24 16:55:54 2014 *************** *** 178,185 **** --- 178,187 ---- address_length = 8; break; case ADDR_128B: + case ADDR_ANYCAST: address_length = 16; break; + default: openserial_printCritical(COMPONENT_PACKETFUNCTIONS,ERR_WRONG_ADDR_TYPE, (errorparameter_t)address_1->type, *************** *** 267,273 **** pkt->payload -= header_length; pkt->length += header_length; if ( (uint8_t*)(pkt->payload) < (uint8_t*)(pkt->packet) ) { ! openserial_printError(COMPONENT_PACKETFUNCTIONS,ERR_HEADER_TOO_LONG, (errorparameter_t)0, (errorparameter_t)pkt->length); } --- 269,275 ---- pkt->payload -= header_length; pkt->length += header_length; if ( (uint8_t*)(pkt->payload) < (uint8_t*)(pkt->packet) ) { ! openserial_printCritical(COMPONENT_PACKETFUNCTIONS,ERR_HEADER_TOO_LONG, (errorparameter_t)0, (errorparameter_t)pkt->length); } *************** *** 352,399 **** //see http://www-net.cs.umass.edu/kurose/transport/UDP.html, or http://tools.ietf.org/html/rfc1071 //see http://en.wikipedia.org/wiki/User_Datagram_Protocol#IPv6_PSEUDO-HEADER void packetfunctions_calculateChecksum(OpenQueueEntry_t* msg, uint8_t* checksum_ptr) { - open_addr_t temp_dest_prefix; - open_addr_t temp_dest_mac64b; uint8_t temp_checksum[2]; uint8_t little_helper[2]; ! //initialization temp_checksum[0] = 0; temp_checksum[1] = 0; ! *checksum_ptr = 0; ! *(checksum_ptr+1) = 0; ! //source/destination address ! packetfunctions_ip128bToMac64b(&(msg->l3_destinationAdd),&temp_dest_prefix,&temp_dest_mac64b); ! if (packetfunctions_sameAddress(&temp_dest_prefix,idmanager_getMyID(ADDR_PREFIX))) { ! little_helper[0] = 0xfe; ! little_helper[1] = 0x80; ! //source address prefix ! onesComplementSum(temp_checksum,little_helper,2); ! //source address EUI ! onesComplementSum(temp_checksum,(idmanager_getMyID(ADDR_64B))->addr_64b,8); ! //destination address prefix (fe:80) ! onesComplementSum(temp_checksum,little_helper,2); ! //destination address EUI ! onesComplementSum(temp_checksum,temp_dest_mac64b.addr_64b,8); ! } else { ! //source address prefix ! onesComplementSum(temp_checksum,(idmanager_getMyID(ADDR_PREFIX))->prefix,8); ! //source address EUI ! onesComplementSum(temp_checksum,(idmanager_getMyID(ADDR_64B))->addr_64b,8); ! //destination address ! onesComplementSum(temp_checksum,msg->l3_destinationAdd.addr_128b,16); ! } ! //length little_helper[0] = 0; little_helper[1] = msg->length; onesComplementSum(temp_checksum,little_helper,2); ! //next header little_helper[0] = 0; little_helper[1] = msg->l4_protocol; onesComplementSum(temp_checksum,little_helper,2); ! //ICMPv6 packet onesComplementSum(temp_checksum,msg->payload,msg->length); temp_checksum[0] ^= 0xFF; temp_checksum[1] ^= 0xFF; //write in packet *checksum_ptr = temp_checksum[0]; *(checksum_ptr+1) = temp_checksum[1]; --- 354,395 ---- //see http://www-net.cs.umass.edu/kurose/transport/UDP.html, or http://tools.ietf.org/html/rfc1071 //see http://en.wikipedia.org/wiki/User_Datagram_Protocol#IPv6_PSEUDO-HEADER void packetfunctions_calculateChecksum(OpenQueueEntry_t* msg, uint8_t* checksum_ptr) { uint8_t temp_checksum[2]; uint8_t little_helper[2]; ! ! // initialize running checksum temp_checksum[0] = 0; temp_checksum[1] = 0; ! ! //===== IPv6 pseudo header ! ! // source address (prefix and EUI64) ! onesComplementSum(temp_checksum,(idmanager_getMyID(ADDR_PREFIX))->prefix,8); ! onesComplementSum(temp_checksum,(idmanager_getMyID(ADDR_64B))->addr_64b,8); ! ! // destination address ! onesComplementSum(temp_checksum,msg->l3_destinationAdd.addr_128b,16); ! ! // length little_helper[0] = 0; little_helper[1] = msg->length; onesComplementSum(temp_checksum,little_helper,2); ! ! // next header little_helper[0] = 0; little_helper[1] = msg->l4_protocol; onesComplementSum(temp_checksum,little_helper,2); ! ! //===== payload ! ! // reset the checksum currently in the payload ! *checksum_ptr = 0; ! *(checksum_ptr+1) = 0; ! onesComplementSum(temp_checksum,msg->payload,msg->length); temp_checksum[0] ^= 0xFF; temp_checksum[1] ^= 0xFF; + //write in packet *checksum_ptr = temp_checksum[0]; *(checksum_ptr+1) = temp_checksum[1];