aboutsummaryrefslogtreecommitdiffstats
path: root/net/ieee802154
diff options
context:
space:
mode:
authorAlexander Aring <alex.aring@gmail.com>2013-12-17 08:21:22 -0500
committerMarcel Holtmann <marcel@holtmann.org>2013-12-17 09:16:47 -0500
commit5cede84c9897f9db522699c4b3ff6ffe3d11e038 (patch)
tree0279134237485cfbd36daea82e2b1e80f48d9a2a /net/ieee802154
parent3109f2e28b0a3216e07d4933d28a8480c6520379 (diff)
6lowpan: udp use lowpan_push_hc_data function
This patch uses the lowpan_push_hc_data to generate iphc header. The current implementation has some wrong pointer arithmetic issues and works in a random case only. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/ieee802154')
-rw-r--r--net/ieee802154/6lowpan_iphc.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index 88e7da599558..77c0366a3b47 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -541,42 +541,45 @@ static u8 lowpan_compress_addr_64(u8 **hc06_ptr, u8 shift,
541static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb) 541static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
542{ 542{
543 struct udphdr *uh = udp_hdr(skb); 543 struct udphdr *uh = udp_hdr(skb);
544 u8 tmp;
544 545
545 if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) == 546 if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) ==
546 LOWPAN_NHC_UDP_4BIT_PORT) && 547 LOWPAN_NHC_UDP_4BIT_PORT) &&
547 ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) == 548 ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) ==
548 LOWPAN_NHC_UDP_4BIT_PORT)) { 549 LOWPAN_NHC_UDP_4BIT_PORT)) {
549 pr_debug("UDP header: both ports compression to 4 bits\n"); 550 pr_debug("UDP header: both ports compression to 4 bits\n");
550 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_11; 551 tmp = LOWPAN_NHC_UDP_CS_P_11;
551 **(hc06_ptr + 1) = /* subtraction is faster */ 552 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
553 tmp = /* subtraction is faster */
552 (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) + 554 (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) +
553 ((uh->source & LOWPAN_NHC_UDP_4BIT_PORT) << 4)); 555 ((uh->source & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
554 *hc06_ptr += 2; 556 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
555 } else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) == 557 } else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) ==
556 LOWPAN_NHC_UDP_8BIT_PORT) { 558 LOWPAN_NHC_UDP_8BIT_PORT) {
557 pr_debug("UDP header: remove 8 bits of dest\n"); 559 pr_debug("UDP header: remove 8 bits of dest\n");
558 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_01; 560 tmp = LOWPAN_NHC_UDP_CS_P_01;
559 memcpy(*hc06_ptr + 1, &uh->source, 2); 561 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
560 **(hc06_ptr + 3) = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT); 562 lowpan_push_hc_data(hc06_ptr, &uh->source, sizeof(uh->source));
561 *hc06_ptr += 4; 563 tmp = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT);
564 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
562 } else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) == 565 } else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) ==
563 LOWPAN_NHC_UDP_8BIT_PORT) { 566 LOWPAN_NHC_UDP_8BIT_PORT) {
564 pr_debug("UDP header: remove 8 bits of source\n"); 567 pr_debug("UDP header: remove 8 bits of source\n");
565 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_10; 568 tmp = LOWPAN_NHC_UDP_CS_P_10;
566 memcpy(*hc06_ptr + 1, &uh->dest, 2); 569 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
567 **(hc06_ptr + 3) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT); 570 lowpan_push_hc_data(hc06_ptr, &uh->dest, sizeof(uh->dest));
568 *hc06_ptr += 4; 571 tmp = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
572 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
569 } else { 573 } else {
570 pr_debug("UDP header: can't compress\n"); 574 pr_debug("UDP header: can't compress\n");
571 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_00; 575 tmp = LOWPAN_NHC_UDP_CS_P_00;
572 memcpy(*hc06_ptr + 1, &uh->source, 2); 576 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
573 memcpy(*hc06_ptr + 3, &uh->dest, 2); 577 lowpan_push_hc_data(hc06_ptr, &uh->source, sizeof(uh->source));
574 *hc06_ptr += 5; 578 lowpan_push_hc_data(hc06_ptr, &uh->dest, sizeof(uh->dest));
575 } 579 }
576 580
577 /* checksum is always inline */ 581 /* checksum is always inline */
578 memcpy(*hc06_ptr, &uh->check, 2); 582 lowpan_push_hc_data(hc06_ptr, &uh->check, sizeof(uh->check));
579 *hc06_ptr += 2;
580 583
581 /* skip the UDP header */ 584 /* skip the UDP header */
582 skb_pull(skb, sizeof(struct udphdr)); 585 skb_pull(skb, sizeof(struct udphdr));