6loWPAN: Fix a faulty assumption about relationship between some sizes and offsets.
This commit is contained in:
parent
dea251783a
commit
fe722e44b9
@ -187,7 +187,7 @@ void up_initialize(void)
|
||||
* separately.
|
||||
*/
|
||||
|
||||
syslog(LOG_INFO, "SIM: Initializing");
|
||||
syslog(LOG_INFO, "SIM: Initializing\n");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
@ -144,9 +144,7 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
||||
static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
||||
FAR uint8_t *fptr)
|
||||
{
|
||||
uint16_t combined;
|
||||
uint16_t protosize;
|
||||
uint16_t copysize;
|
||||
|
||||
/* What is the total size of the IPv6 + protocol header? */
|
||||
|
||||
@ -162,7 +160,6 @@ static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
||||
*/
|
||||
|
||||
protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2;
|
||||
combined = sizeof(struct ipv6_hdr_s) + protosize;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@ -170,48 +167,27 @@ static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
||||
#ifdef CONFIG_NET_UDP
|
||||
case IP_PROTO_UDP:
|
||||
protosize = sizeof(struct udp_hdr_s);
|
||||
combined = sizeof(struct ipv6udp_hdr_s);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6
|
||||
case IP_PROTO_ICMP6:
|
||||
protosize = sizeof(struct icmpv6_hdr_s);
|
||||
combined = sizeof(struct ipv6icmp_hdr_s);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto);
|
||||
protosize = 0;
|
||||
combined = sizeof(struct ipv6_hdr_s);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Copy the remaining protocol header. */
|
||||
|
||||
if (g_uncomp_hdrlen > IPv6_HDRLEN)
|
||||
{
|
||||
nwarn("WARNING: Protocol header not copied: "
|
||||
"g_uncomp_hdren=%u IPv6_HDRLEN=%u\n",
|
||||
g_uncomp_hdrlen, IPv6_HDRLEN);
|
||||
return;
|
||||
}
|
||||
|
||||
copysize = combined - g_uncomp_hdrlen;
|
||||
if (copysize != protosize)
|
||||
{
|
||||
nwarn("WARNING: Protocol header size mismatch: "
|
||||
"g_uncomp_hdren=%u copysize=%u protosize=%u\n",
|
||||
g_uncomp_hdrlen, copysize, protosize);
|
||||
return;
|
||||
}
|
||||
/* Copy the protocol header. */
|
||||
|
||||
memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)ipv6hdr + g_uncomp_hdrlen,
|
||||
copysize);
|
||||
protosize);
|
||||
|
||||
g_frame_hdrlen += copysize;
|
||||
g_uncomp_hdrlen += copysize;
|
||||
g_frame_hdrlen += protosize;
|
||||
g_uncomp_hdrlen += protosize;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user