aboutsummaryrefslogtreecommitdiffstats
path: root/net/ieee802154
diff options
context:
space:
mode:
Diffstat (limited to 'net/ieee802154')
-rw-r--r--net/ieee802154/6lowpan.c94
1 files changed, 37 insertions, 57 deletions
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index b45e229bc42c..ad0c2264e537 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -240,8 +240,7 @@ lowpan_uncompress_addr(struct sk_buff *skb, struct in6_addr *ipaddr,
240 lowpan_uip_ds6_set_addr_iid(ipaddr, lladdr); 240 lowpan_uip_ds6_set_addr_iid(ipaddr, lladdr);
241 } 241 }
242 242
243 pr_debug("(%s): uncompressing %d + %d => ", __func__, prefcount, 243 pr_debug("uncompressing %d + %d => ", prefcount, postcount);
244 postcount);
245 lowpan_raw_dump_inline(NULL, NULL, ipaddr->s6_addr, 16); 244 lowpan_raw_dump_inline(NULL, NULL, ipaddr->s6_addr, 16);
246 245
247 return 0; 246 return 0;
@@ -252,13 +251,11 @@ lowpan_compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
252{ 251{
253 struct udphdr *uh = udp_hdr(skb); 252 struct udphdr *uh = udp_hdr(skb);
254 253
255 pr_debug("(%s): UDP header compression\n", __func__);
256
257 if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) == 254 if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) ==
258 LOWPAN_NHC_UDP_4BIT_PORT) && 255 LOWPAN_NHC_UDP_4BIT_PORT) &&
259 ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) == 256 ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) ==
260 LOWPAN_NHC_UDP_4BIT_PORT)) { 257 LOWPAN_NHC_UDP_4BIT_PORT)) {
261 pr_debug("(%s): both ports compression to 4 bits\n", __func__); 258 pr_debug("UDP header: both ports compression to 4 bits\n");
262 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_11; 259 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_11;
263 **(hc06_ptr + 1) = /* subtraction is faster */ 260 **(hc06_ptr + 1) = /* subtraction is faster */
264 (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) + 261 (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) +
@@ -266,20 +263,20 @@ lowpan_compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
266 *hc06_ptr += 2; 263 *hc06_ptr += 2;
267 } else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) == 264 } else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) ==
268 LOWPAN_NHC_UDP_8BIT_PORT) { 265 LOWPAN_NHC_UDP_8BIT_PORT) {
269 pr_debug("(%s): remove 8 bits of dest\n", __func__); 266 pr_debug("UDP header: remove 8 bits of dest\n");
270 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_01; 267 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_01;
271 memcpy(*hc06_ptr + 1, &uh->source, 2); 268 memcpy(*hc06_ptr + 1, &uh->source, 2);
272 **(hc06_ptr + 3) = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT); 269 **(hc06_ptr + 3) = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT);
273 *hc06_ptr += 4; 270 *hc06_ptr += 4;
274 } else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) == 271 } else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) ==
275 LOWPAN_NHC_UDP_8BIT_PORT) { 272 LOWPAN_NHC_UDP_8BIT_PORT) {
276 pr_debug("(%s): remove 8 bits of source\n", __func__); 273 pr_debug("UDP header: remove 8 bits of source\n");
277 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_10; 274 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_10;
278 memcpy(*hc06_ptr + 1, &uh->dest, 2); 275 memcpy(*hc06_ptr + 1, &uh->dest, 2);
279 **(hc06_ptr + 3) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT); 276 **(hc06_ptr + 3) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
280 *hc06_ptr += 4; 277 *hc06_ptr += 4;
281 } else { 278 } else {
282 pr_debug("(%s): can't compress header\n", __func__); 279 pr_debug("UDP header: can't compress\n");
283 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_00; 280 **hc06_ptr = LOWPAN_NHC_UDP_CS_P_00;
284 memcpy(*hc06_ptr + 1, &uh->source, 2); 281 memcpy(*hc06_ptr + 1, &uh->source, 2);
285 memcpy(*hc06_ptr + 3, &uh->dest, 2); 282 memcpy(*hc06_ptr + 3, &uh->dest, 2);
@@ -323,7 +320,7 @@ lowpan_uncompress_udp_header(struct sk_buff *skb)
323 goto err; 320 goto err;
324 321
325 if ((tmp & LOWPAN_NHC_UDP_MASK) == LOWPAN_NHC_UDP_ID) { 322 if ((tmp & LOWPAN_NHC_UDP_MASK) == LOWPAN_NHC_UDP_ID) {
326 pr_debug("(%s): UDP header uncompression\n", __func__); 323 pr_debug("UDP header uncompression\n");
327 switch (tmp & LOWPAN_NHC_UDP_CS_P_11) { 324 switch (tmp & LOWPAN_NHC_UDP_CS_P_11) {
328 case LOWPAN_NHC_UDP_CS_P_00: 325 case LOWPAN_NHC_UDP_CS_P_00:
329 memcpy(&uh->source, &skb->data[0], 2); 326 memcpy(&uh->source, &skb->data[0], 2);
@@ -349,19 +346,19 @@ lowpan_uncompress_udp_header(struct sk_buff *skb)
349 skb_pull(skb, 1); 346 skb_pull(skb, 1);
350 break; 347 break;
351 default: 348 default:
352 pr_debug("(%s) ERROR: unknown UDP format\n", __func__); 349 pr_debug("ERROR: unknown UDP format\n");
353 goto err; 350 goto err;
354 break; 351 break;
355 } 352 }
356 353
357 pr_debug("(%s): uncompressed UDP ports: src = %d, dst = %d\n", 354 pr_debug("uncompressed UDP ports: src = %d, dst = %d\n",
358 __func__, uh->source, uh->dest); 355 uh->source, uh->dest);
359 356
360 /* copy checksum */ 357 /* copy checksum */
361 memcpy(&uh->check, &skb->data[0], 2); 358 memcpy(&uh->check, &skb->data[0], 2);
362 skb_pull(skb, 2); 359 skb_pull(skb, 2);
363 } else { 360 } else {
364 pr_debug("(%s): ERROR: unsupported NH format\n", __func__); 361 pr_debug("ERROR: unsupported NH format\n");
365 goto err; 362 goto err;
366 } 363 }
367 364
@@ -394,10 +391,9 @@ static int lowpan_header_create(struct sk_buff *skb,
394 hdr = ipv6_hdr(skb); 391 hdr = ipv6_hdr(skb);
395 hc06_ptr = head + 2; 392 hc06_ptr = head + 2;
396 393
397 pr_debug("(%s): IPv6 header dump:\n\tversion = %d\n\tlength = %d\n" 394 pr_debug("IPv6 header dump:\n\tversion = %d\n\tlength = %d\n"
398 "\tnexthdr = 0x%02x\n\thop_lim = %d\n", __func__, 395 "\tnexthdr = 0x%02x\n\thop_lim = %d\n", hdr->version,
399 hdr->version, ntohs(hdr->payload_len), hdr->nexthdr, 396 ntohs(hdr->payload_len), hdr->nexthdr, hdr->hop_limit);
400 hdr->hop_limit);
401 397
402 lowpan_raw_dump_table(__func__, "raw skb network header dump", 398 lowpan_raw_dump_table(__func__, "raw skb network header dump",
403 skb_network_header(skb), sizeof(struct ipv6hdr)); 399 skb_network_header(skb), sizeof(struct ipv6hdr));
@@ -498,23 +494,22 @@ static int lowpan_header_create(struct sk_buff *skb,
498 494
499 /* source address compression */ 495 /* source address compression */
500 if (is_addr_unspecified(&hdr->saddr)) { 496 if (is_addr_unspecified(&hdr->saddr)) {
501 pr_debug("(%s): source address is unspecified, setting SAC\n", 497 pr_debug("source address is unspecified, setting SAC\n");
502 __func__);
503 iphc1 |= LOWPAN_IPHC_SAC; 498 iphc1 |= LOWPAN_IPHC_SAC;
504 /* TODO: context lookup */ 499 /* TODO: context lookup */
505 } else if (is_addr_link_local(&hdr->saddr)) { 500 } else if (is_addr_link_local(&hdr->saddr)) {
506 pr_debug("(%s): source address is link-local\n", __func__); 501 pr_debug("source address is link-local\n");
507 iphc1 |= lowpan_compress_addr_64(&hc06_ptr, 502 iphc1 |= lowpan_compress_addr_64(&hc06_ptr,
508 LOWPAN_IPHC_SAM_BIT, &hdr->saddr, saddr); 503 LOWPAN_IPHC_SAM_BIT, &hdr->saddr, saddr);
509 } else { 504 } else {
510 pr_debug("(%s): send the full source address\n", __func__); 505 pr_debug("send the full source address\n");
511 memcpy(hc06_ptr, &hdr->saddr.s6_addr16[0], 16); 506 memcpy(hc06_ptr, &hdr->saddr.s6_addr16[0], 16);
512 hc06_ptr += 16; 507 hc06_ptr += 16;
513 } 508 }
514 509
515 /* destination address compression */ 510 /* destination address compression */
516 if (is_addr_mcast(&hdr->daddr)) { 511 if (is_addr_mcast(&hdr->daddr)) {
517 pr_debug("(%s): destination address is multicast", __func__); 512 pr_debug("destination address is multicast: ");
518 iphc1 |= LOWPAN_IPHC_M; 513 iphc1 |= LOWPAN_IPHC_M;
519 if (lowpan_is_mcast_addr_compressable8(&hdr->daddr)) { 514 if (lowpan_is_mcast_addr_compressable8(&hdr->daddr)) {
520 pr_debug("compressed to 1 octet\n"); 515 pr_debug("compressed to 1 octet\n");
@@ -543,14 +538,13 @@ static int lowpan_header_create(struct sk_buff *skb,
543 hc06_ptr += 16; 538 hc06_ptr += 16;
544 } 539 }
545 } else { 540 } else {
546 pr_debug("(%s): destination address is unicast: ", __func__);
547 /* TODO: context lookup */ 541 /* TODO: context lookup */
548 if (is_addr_link_local(&hdr->daddr)) { 542 if (is_addr_link_local(&hdr->daddr)) {
549 pr_debug("destination address is link-local\n"); 543 pr_debug("dest address is unicast and link-local\n");
550 iphc1 |= lowpan_compress_addr_64(&hc06_ptr, 544 iphc1 |= lowpan_compress_addr_64(&hc06_ptr,
551 LOWPAN_IPHC_DAM_BIT, &hdr->daddr, daddr); 545 LOWPAN_IPHC_DAM_BIT, &hdr->daddr, daddr);
552 } else { 546 } else {
553 pr_debug("using full address\n"); 547 pr_debug("dest address is unicast: using full one\n");
554 memcpy(hc06_ptr, &hdr->daddr.s6_addr16[0], 16); 548 memcpy(hc06_ptr, &hdr->daddr.s6_addr16[0], 16);
555 hc06_ptr += 16; 549 hc06_ptr += 16;
556 } 550 }
@@ -642,8 +636,7 @@ static void lowpan_fragment_timer_expired(unsigned long entry_addr)
642{ 636{
643 struct lowpan_fragment *entry = (struct lowpan_fragment *)entry_addr; 637 struct lowpan_fragment *entry = (struct lowpan_fragment *)entry_addr;
644 638
645 pr_debug("%s: timer expired for frame with tag %d\n", __func__, 639 pr_debug("timer expired for frame with tag %d\n", entry->tag);
646 entry->tag);
647 640
648 spin_lock(&flist_lock); 641 spin_lock(&flist_lock);
649 list_del(&entry->list); 642 list_del(&entry->list);
@@ -796,12 +789,11 @@ lowpan_process_data(struct sk_buff *skb)
796 _saddr = mac_cb(skb)->sa.hwaddr; 789 _saddr = mac_cb(skb)->sa.hwaddr;
797 _daddr = mac_cb(skb)->da.hwaddr; 790 _daddr = mac_cb(skb)->da.hwaddr;
798 791
799 pr_debug("(%s): iphc0 = %02x, iphc1 = %02x\n", __func__, iphc0, iphc1); 792 pr_debug("iphc0 = %02x, iphc1 = %02x\n", iphc0, iphc1);
800 793
801 /* another if the CID flag is set */ 794 /* another if the CID flag is set */
802 if (iphc1 & LOWPAN_IPHC_CID) { 795 if (iphc1 & LOWPAN_IPHC_CID) {
803 pr_debug("(%s): CID flag is set, increase header with one\n", 796 pr_debug("CID flag is set, increase header with one\n");
804 __func__);
805 if (lowpan_fetch_skb_u8(skb, &num_context)) 797 if (lowpan_fetch_skb_u8(skb, &num_context))
806 goto drop; 798 goto drop;
807 } 799 }
@@ -866,8 +858,8 @@ lowpan_process_data(struct sk_buff *skb)
866 if (lowpan_fetch_skb_u8(skb, &(hdr.nexthdr))) 858 if (lowpan_fetch_skb_u8(skb, &(hdr.nexthdr)))
867 goto drop; 859 goto drop;
868 860
869 pr_debug("(%s): NH flag is set, next header is carried " 861 pr_debug("NH flag is set, next header carried inline: %02x\n",
870 "inline: %02x\n", __func__, hdr.nexthdr); 862 hdr.nexthdr);
871 } 863 }
872 864
873 /* Hop Limit */ 865 /* Hop Limit */
@@ -882,7 +874,7 @@ lowpan_process_data(struct sk_buff *skb)
882 tmp = ((iphc1 & LOWPAN_IPHC_SAM) >> LOWPAN_IPHC_SAM_BIT) & 0x03; 874 tmp = ((iphc1 & LOWPAN_IPHC_SAM) >> LOWPAN_IPHC_SAM_BIT) & 0x03;
883 875
884 /* Source address uncompression */ 876 /* Source address uncompression */
885 pr_debug("(%s): source address stateless compression\n", __func__); 877 pr_debug("source address stateless compression\n");
886 err = lowpan_uncompress_addr(skb, &hdr.saddr, lowpan_llprefix, 878 err = lowpan_uncompress_addr(skb, &hdr.saddr, lowpan_llprefix,
887 lowpan_unc_llconf[tmp], skb->data); 879 lowpan_unc_llconf[tmp], skb->data);
888 if (err) 880 if (err)
@@ -894,14 +886,12 @@ lowpan_process_data(struct sk_buff *skb)
894 /* check for Multicast Compression */ 886 /* check for Multicast Compression */
895 if (iphc1 & LOWPAN_IPHC_M) { 887 if (iphc1 & LOWPAN_IPHC_M) {
896 if (iphc1 & LOWPAN_IPHC_DAC) { 888 if (iphc1 & LOWPAN_IPHC_DAC) {
897 pr_debug("(%s): destination address context-based " 889 pr_debug("dest: context-based mcast compression\n");
898 "multicast compression\n", __func__);
899 /* TODO: implement this */ 890 /* TODO: implement this */
900 } else { 891 } else {
901 u8 prefix[] = {0xff, 0x02}; 892 u8 prefix[] = {0xff, 0x02};
902 893
903 pr_debug("(%s): destination address non-context-based" 894 pr_debug("dest: non context-based mcast compression\n");
904 " multicast compression\n", __func__);
905 if (0 < tmp && tmp < 3) { 895 if (0 < tmp && tmp < 3) {
906 if (lowpan_fetch_skb_u8(skb, &prefix[1])) 896 if (lowpan_fetch_skb_u8(skb, &prefix[1]))
907 goto drop; 897 goto drop;
@@ -913,8 +903,7 @@ lowpan_process_data(struct sk_buff *skb)
913 goto drop; 903 goto drop;
914 } 904 }
915 } else { 905 } else {
916 pr_debug("(%s): destination address stateless compression\n", 906 pr_debug("dest: stateless compression\n");
917 __func__);
918 err = lowpan_uncompress_addr(skb, &hdr.daddr, lowpan_llprefix, 907 err = lowpan_uncompress_addr(skb, &hdr.daddr, lowpan_llprefix,
919 lowpan_unc_llconf[tmp], skb->data); 908 lowpan_unc_llconf[tmp], skb->data);
920 if (err) 909 if (err)
@@ -929,11 +918,11 @@ lowpan_process_data(struct sk_buff *skb)
929 /* Not fragmented package */ 918 /* Not fragmented package */
930 hdr.payload_len = htons(skb->len); 919 hdr.payload_len = htons(skb->len);
931 920
932 pr_debug("(%s): skb headroom size = %d, data length = %d\n", __func__, 921 pr_debug("skb headroom size = %d, data length = %d\n",
933 skb_headroom(skb), skb->len); 922 skb_headroom(skb), skb->len);
934 923
935 pr_debug("(%s): IPv6 header dump:\n\tversion = %d\n\tlength = %d\n\t" 924 pr_debug("IPv6 header dump:\n\tversion = %d\n\tlength = %d\n\t"
936 "nexthdr = 0x%02x\n\thop_lim = %d\n", __func__, hdr.version, 925 "nexthdr = 0x%02x\n\thop_lim = %d\n", hdr.version,
937 ntohs(hdr.payload_len), hdr.nexthdr, hdr.hop_limit); 926 ntohs(hdr.payload_len), hdr.nexthdr, hdr.hop_limit);
938 927
939 lowpan_raw_dump_table(__func__, "raw header dump", (u8 *)&hdr, 928 lowpan_raw_dump_table(__func__, "raw header dump", (u8 *)&hdr,
@@ -1035,11 +1024,11 @@ static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
1035{ 1024{
1036 int err = -1; 1025 int err = -1;
1037 1026
1038 pr_debug("(%s): package xmit\n", __func__); 1027 pr_debug("package xmit\n");
1039 1028
1040 skb->dev = lowpan_dev_info(dev)->real_dev; 1029 skb->dev = lowpan_dev_info(dev)->real_dev;
1041 if (skb->dev == NULL) { 1030 if (skb->dev == NULL) {
1042 pr_debug("(%s) ERROR: no real wpan device found\n", __func__); 1031 pr_debug("ERROR: no real wpan device found\n");
1043 goto error; 1032 goto error;
1044 } 1033 }
1045 1034
@@ -1048,14 +1037,13 @@ static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
1048 goto out; 1037 goto out;
1049 } 1038 }
1050 1039
1051 pr_debug("(%s): frame is too big, fragmentation is needed\n", 1040 pr_debug("frame is too big, fragmentation is needed\n");
1052 __func__);
1053 err = lowpan_skb_fragmentation(skb); 1041 err = lowpan_skb_fragmentation(skb);
1054error: 1042error:
1055 dev_kfree_skb(skb); 1043 dev_kfree_skb(skb);
1056out: 1044out:
1057 if (err < 0) 1045 if (err < 0)
1058 pr_debug("(%s): ERROR: xmit failed\n", __func__); 1046 pr_debug("ERROR: xmit failed\n");
1059 1047
1060 return (err < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK); 1048 return (err < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK);
1061} 1049}
@@ -1101,8 +1089,6 @@ static struct ieee802154_mlme_ops lowpan_mlme = {
1101 1089
1102static void lowpan_setup(struct net_device *dev) 1090static void lowpan_setup(struct net_device *dev)
1103{ 1091{
1104 pr_debug("(%s)\n", __func__);
1105
1106 dev->addr_len = IEEE802154_ADDR_LEN; 1092 dev->addr_len = IEEE802154_ADDR_LEN;
1107 memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN); 1093 memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
1108 dev->type = ARPHRD_IEEE802154; 1094 dev->type = ARPHRD_IEEE802154;
@@ -1122,8 +1108,6 @@ static void lowpan_setup(struct net_device *dev)
1122 1108
1123static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[]) 1109static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
1124{ 1110{
1125 pr_debug("(%s)\n", __func__);
1126
1127 if (tb[IFLA_ADDRESS]) { 1111 if (tb[IFLA_ADDRESS]) {
1128 if (nla_len(tb[IFLA_ADDRESS]) != IEEE802154_ADDR_LEN) 1112 if (nla_len(tb[IFLA_ADDRESS]) != IEEE802154_ADDR_LEN)
1129 return -EINVAL; 1113 return -EINVAL;
@@ -1164,7 +1148,7 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
1164 struct net_device *real_dev; 1148 struct net_device *real_dev;
1165 struct lowpan_dev_record *entry; 1149 struct lowpan_dev_record *entry;
1166 1150
1167 pr_debug("(%s)\n", __func__); 1151 pr_debug("adding new link\n");
1168 1152
1169 if (!tb[IFLA_LINK]) 1153 if (!tb[IFLA_LINK])
1170 return -EINVAL; 1154 return -EINVAL;
@@ -1259,8 +1243,6 @@ static int __init lowpan_init_module(void)
1259{ 1243{
1260 int err = 0; 1244 int err = 0;
1261 1245
1262 pr_debug("(%s)\n", __func__);
1263
1264 err = lowpan_netlink_init(); 1246 err = lowpan_netlink_init();
1265 if (err < 0) 1247 if (err < 0)
1266 goto out; 1248 goto out;
@@ -1272,8 +1254,6 @@ out:
1272 1254
1273static void __exit lowpan_cleanup_module(void) 1255static void __exit lowpan_cleanup_module(void)
1274{ 1256{
1275 pr_debug("(%s)\n", __func__);
1276
1277 lowpan_netlink_fini(); 1257 lowpan_netlink_fini();
1278 1258
1279 dev_remove_pack(&lowpan_packet_type); 1259 dev_remove_pack(&lowpan_packet_type);