diff options
author | Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> | 2014-03-14 16:23:59 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-03-14 22:15:26 -0400 |
commit | b70ab2e87f17176d18f67ef331064441a032b5f3 (patch) | |
tree | 634b1482ab909ebe4d62b2a786378ad9584f922a /net/mac802154 | |
parent | 46ef0eb3ea65e7043aac17cb92982be879c65366 (diff) |
ieee802154: enforce consistent endianness in the 802.15.4 stack
Enable sparse warnings about endianness, replace the remaining fields
regarding network operations without explicit endianness annotations
with such that are annotated, and propagate this through the entire
stack.
Uses of ieee802154_addr_sa are not changed yet, this patch is only
concerned with all other fields (such as address filters, operation
parameters and the likes).
Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/mac802154')
-rw-r--r-- | net/mac802154/Makefile | 2 | ||||
-rw-r--r-- | net/mac802154/ieee802154_dev.c | 5 | ||||
-rw-r--r-- | net/mac802154/mac802154.h | 9 | ||||
-rw-r--r-- | net/mac802154/mac_cmd.c | 4 | ||||
-rw-r--r-- | net/mac802154/mib.c | 24 | ||||
-rw-r--r-- | net/mac802154/wpan.c | 43 |
6 files changed, 53 insertions, 34 deletions
diff --git a/net/mac802154/Makefile b/net/mac802154/Makefile index 57cf5d1a2e4a..15d62df52182 100644 --- a/net/mac802154/Makefile +++ b/net/mac802154/Makefile | |||
@@ -1,2 +1,4 @@ | |||
1 | obj-$(CONFIG_MAC802154) += mac802154.o | 1 | obj-$(CONFIG_MAC802154) += mac802154.o |
2 | mac802154-objs := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o monitor.o wpan.o | 2 | mac802154-objs := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o monitor.o wpan.o |
3 | |||
4 | ccflags-y += -D__CHECK_ENDIAN__ | ||
diff --git a/net/mac802154/ieee802154_dev.c b/net/mac802154/ieee802154_dev.c index b75bb01e5c6b..10cdb091b775 100644 --- a/net/mac802154/ieee802154_dev.c +++ b/net/mac802154/ieee802154_dev.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <net/netlink.h> | 27 | #include <net/netlink.h> |
28 | #include <linux/nl802154.h> | 28 | #include <linux/nl802154.h> |
29 | #include <net/mac802154.h> | 29 | #include <net/mac802154.h> |
30 | #include <net/ieee802154_netdev.h> | ||
30 | #include <net/route.h> | 31 | #include <net/route.h> |
31 | #include <net/wpan-phy.h> | 32 | #include <net/wpan-phy.h> |
32 | 33 | ||
@@ -46,7 +47,9 @@ int mac802154_slave_open(struct net_device *dev) | |||
46 | } | 47 | } |
47 | 48 | ||
48 | if (ipriv->ops->ieee_addr) { | 49 | if (ipriv->ops->ieee_addr) { |
49 | res = ipriv->ops->ieee_addr(&ipriv->hw, dev->dev_addr); | 50 | __le64 addr = ieee802154_devaddr_from_raw(dev->dev_addr); |
51 | |||
52 | res = ipriv->ops->ieee_addr(&ipriv->hw, addr); | ||
50 | WARN_ON(res); | 53 | WARN_ON(res); |
51 | if (res) | 54 | if (res) |
52 | goto err; | 55 | goto err; |
diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h index d48422e27110..4619486f1da2 100644 --- a/net/mac802154/mac802154.h +++ b/net/mac802154/mac802154.h | |||
@@ -76,6 +76,7 @@ struct mac802154_sub_if_data { | |||
76 | 76 | ||
77 | __le16 pan_id; | 77 | __le16 pan_id; |
78 | __le16 short_addr; | 78 | __le16 short_addr; |
79 | __le64 extended_addr; | ||
79 | 80 | ||
80 | u8 chan; | 81 | u8 chan; |
81 | u8 page; | 82 | u8 page; |
@@ -106,11 +107,11 @@ netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb, | |||
106 | u8 page, u8 chan); | 107 | u8 page, u8 chan); |
107 | 108 | ||
108 | /* MIB callbacks */ | 109 | /* MIB callbacks */ |
109 | void mac802154_dev_set_short_addr(struct net_device *dev, u16 val); | 110 | void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val); |
110 | u16 mac802154_dev_get_short_addr(const struct net_device *dev); | 111 | __le16 mac802154_dev_get_short_addr(const struct net_device *dev); |
111 | void mac802154_dev_set_ieee_addr(struct net_device *dev); | 112 | void mac802154_dev_set_ieee_addr(struct net_device *dev); |
112 | u16 mac802154_dev_get_pan_id(const struct net_device *dev); | 113 | __le16 mac802154_dev_get_pan_id(const struct net_device *dev); |
113 | void mac802154_dev_set_pan_id(struct net_device *dev, u16 val); | 114 | void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val); |
114 | void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); | 115 | void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); |
115 | u8 mac802154_dev_get_dsn(const struct net_device *dev); | 116 | u8 mac802154_dev_get_dsn(const struct net_device *dev); |
116 | 117 | ||
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c index e079c57c48ca..f551ef2cdf56 100644 --- a/net/mac802154/mac_cmd.c +++ b/net/mac802154/mac_cmd.c | |||
@@ -42,8 +42,8 @@ static int mac802154_mlme_start_req(struct net_device *dev, | |||
42 | { | 42 | { |
43 | BUG_ON(addr->addr_type != IEEE802154_ADDR_SHORT); | 43 | BUG_ON(addr->addr_type != IEEE802154_ADDR_SHORT); |
44 | 44 | ||
45 | mac802154_dev_set_pan_id(dev, addr->pan_id); | 45 | mac802154_dev_set_pan_id(dev, cpu_to_le16(addr->pan_id)); |
46 | mac802154_dev_set_short_addr(dev, addr->short_addr); | 46 | mac802154_dev_set_short_addr(dev, cpu_to_le16(addr->short_addr)); |
47 | mac802154_dev_set_ieee_addr(dev); | 47 | mac802154_dev_set_ieee_addr(dev); |
48 | mac802154_dev_set_page_channel(dev, page, channel); | 48 | mac802154_dev_set_page_channel(dev, page, channel); |
49 | 49 | ||
diff --git a/net/mac802154/mib.c b/net/mac802154/mib.c index f48f40c1da1a..ba5abdcbd25f 100644 --- a/net/mac802154/mib.c +++ b/net/mac802154/mib.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/if_arp.h> | 24 | #include <linux/if_arp.h> |
25 | 25 | ||
26 | #include <net/mac802154.h> | 26 | #include <net/mac802154.h> |
27 | #include <net/ieee802154_netdev.h> | ||
27 | #include <net/wpan-phy.h> | 28 | #include <net/wpan-phy.h> |
28 | 29 | ||
29 | #include "mac802154.h" | 30 | #include "mac802154.h" |
@@ -79,7 +80,7 @@ static void set_hw_addr_filt(struct net_device *dev, unsigned long changed) | |||
79 | queue_work(priv->hw->dev_workqueue, &work->work); | 80 | queue_work(priv->hw->dev_workqueue, &work->work); |
80 | } | 81 | } |
81 | 82 | ||
82 | void mac802154_dev_set_short_addr(struct net_device *dev, u16 val) | 83 | void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val) |
83 | { | 84 | { |
84 | struct mac802154_sub_if_data *priv = netdev_priv(dev); | 85 | struct mac802154_sub_if_data *priv = netdev_priv(dev); |
85 | 86 | ||
@@ -96,10 +97,10 @@ void mac802154_dev_set_short_addr(struct net_device *dev, u16 val) | |||
96 | } | 97 | } |
97 | } | 98 | } |
98 | 99 | ||
99 | u16 mac802154_dev_get_short_addr(const struct net_device *dev) | 100 | __le16 mac802154_dev_get_short_addr(const struct net_device *dev) |
100 | { | 101 | { |
101 | struct mac802154_sub_if_data *priv = netdev_priv(dev); | 102 | struct mac802154_sub_if_data *priv = netdev_priv(dev); |
102 | u16 ret; | 103 | __le16 ret; |
103 | 104 | ||
104 | BUG_ON(dev->type != ARPHRD_IEEE802154); | 105 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
105 | 106 | ||
@@ -114,20 +115,21 @@ void mac802154_dev_set_ieee_addr(struct net_device *dev) | |||
114 | { | 115 | { |
115 | struct mac802154_sub_if_data *priv = netdev_priv(dev); | 116 | struct mac802154_sub_if_data *priv = netdev_priv(dev); |
116 | struct mac802154_priv *mac = priv->hw; | 117 | struct mac802154_priv *mac = priv->hw; |
118 | __le64 addr; | ||
117 | 119 | ||
118 | if (mac->ops->set_hw_addr_filt && | 120 | addr = ieee802154_devaddr_from_raw(dev->dev_addr); |
119 | memcmp(mac->hw.hw_filt.ieee_addr, | 121 | priv->extended_addr = addr; |
120 | dev->dev_addr, IEEE802154_ADDR_LEN)) { | 122 | |
121 | memcpy(mac->hw.hw_filt.ieee_addr, | 123 | if (mac->ops->set_hw_addr_filt && mac->hw.hw_filt.ieee_addr != addr) { |
122 | dev->dev_addr, IEEE802154_ADDR_LEN); | 124 | mac->hw.hw_filt.ieee_addr = addr; |
123 | set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED); | 125 | set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED); |
124 | } | 126 | } |
125 | } | 127 | } |
126 | 128 | ||
127 | u16 mac802154_dev_get_pan_id(const struct net_device *dev) | 129 | __le16 mac802154_dev_get_pan_id(const struct net_device *dev) |
128 | { | 130 | { |
129 | struct mac802154_sub_if_data *priv = netdev_priv(dev); | 131 | struct mac802154_sub_if_data *priv = netdev_priv(dev); |
130 | u16 ret; | 132 | __le16 ret; |
131 | 133 | ||
132 | BUG_ON(dev->type != ARPHRD_IEEE802154); | 134 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
133 | 135 | ||
@@ -138,7 +140,7 @@ u16 mac802154_dev_get_pan_id(const struct net_device *dev) | |||
138 | return ret; | 140 | return ret; |
139 | } | 141 | } |
140 | 142 | ||
141 | void mac802154_dev_set_pan_id(struct net_device *dev, u16 val) | 143 | void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val) |
142 | { | 144 | { |
143 | struct mac802154_sub_if_data *priv = netdev_priv(dev); | 145 | struct mac802154_sub_if_data *priv = netdev_priv(dev); |
144 | 146 | ||
diff --git a/net/mac802154/wpan.c b/net/mac802154/wpan.c index b2bc3f030190..43e886bb9073 100644 --- a/net/mac802154/wpan.c +++ b/net/mac802154/wpan.c | |||
@@ -76,19 +76,25 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |||
76 | 76 | ||
77 | switch (cmd) { | 77 | switch (cmd) { |
78 | case SIOCGIFADDR: | 78 | case SIOCGIFADDR: |
79 | if (priv->pan_id == IEEE802154_PANID_BROADCAST || | 79 | { |
80 | priv->short_addr == IEEE802154_ADDR_BROADCAST) { | 80 | u16 pan_id, short_addr; |
81 | |||
82 | pan_id = le16_to_cpu(priv->pan_id); | ||
83 | short_addr = le16_to_cpu(priv->short_addr); | ||
84 | if (pan_id == IEEE802154_PANID_BROADCAST || | ||
85 | short_addr == IEEE802154_ADDR_BROADCAST) { | ||
81 | err = -EADDRNOTAVAIL; | 86 | err = -EADDRNOTAVAIL; |
82 | break; | 87 | break; |
83 | } | 88 | } |
84 | 89 | ||
85 | sa->family = AF_IEEE802154; | 90 | sa->family = AF_IEEE802154; |
86 | sa->addr.addr_type = IEEE802154_ADDR_SHORT; | 91 | sa->addr.addr_type = IEEE802154_ADDR_SHORT; |
87 | sa->addr.pan_id = priv->pan_id; | 92 | sa->addr.pan_id = pan_id; |
88 | sa->addr.short_addr = priv->short_addr; | 93 | sa->addr.short_addr = short_addr; |
89 | 94 | ||
90 | err = 0; | 95 | err = 0; |
91 | break; | 96 | break; |
97 | } | ||
92 | case SIOCSIFADDR: | 98 | case SIOCSIFADDR: |
93 | dev_warn(&dev->dev, | 99 | dev_warn(&dev->dev, |
94 | "Using DEBUGing ioctl SIOCSIFADDR isn't recommened!\n"); | 100 | "Using DEBUGing ioctl SIOCSIFADDR isn't recommened!\n"); |
@@ -101,8 +107,8 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |||
101 | break; | 107 | break; |
102 | } | 108 | } |
103 | 109 | ||
104 | priv->pan_id = sa->addr.pan_id; | 110 | priv->pan_id = cpu_to_le16(sa->addr.pan_id); |
105 | priv->short_addr = sa->addr.short_addr; | 111 | priv->short_addr = cpu_to_le16(sa->addr.short_addr); |
106 | 112 | ||
107 | err = 0; | 113 | err = 0; |
108 | break; | 114 | break; |
@@ -151,18 +157,18 @@ static int mac802154_header_create(struct sk_buff *skb, | |||
151 | if (!saddr) { | 157 | if (!saddr) { |
152 | spin_lock_bh(&priv->mib_lock); | 158 | spin_lock_bh(&priv->mib_lock); |
153 | 159 | ||
154 | if (priv->short_addr == IEEE802154_ADDR_BROADCAST || | 160 | if (priv->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) || |
155 | priv->short_addr == IEEE802154_ADDR_UNDEF || | 161 | priv->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) || |
156 | priv->pan_id == IEEE802154_PANID_BROADCAST) { | 162 | priv->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) { |
157 | dev_addr.addr_type = IEEE802154_ADDR_LONG; | 163 | dev_addr.addr_type = IEEE802154_ADDR_LONG; |
158 | memcpy(dev_addr.hwaddr, dev->dev_addr, | 164 | memcpy(dev_addr.hwaddr, dev->dev_addr, |
159 | IEEE802154_ADDR_LEN); | 165 | IEEE802154_ADDR_LEN); |
160 | } else { | 166 | } else { |
161 | dev_addr.addr_type = IEEE802154_ADDR_SHORT; | 167 | dev_addr.addr_type = IEEE802154_ADDR_SHORT; |
162 | dev_addr.short_addr = priv->short_addr; | 168 | dev_addr.short_addr = le16_to_cpu(priv->short_addr); |
163 | } | 169 | } |
164 | 170 | ||
165 | dev_addr.pan_id = priv->pan_id; | 171 | dev_addr.pan_id = le16_to_cpu(priv->pan_id); |
166 | saddr = &dev_addr; | 172 | saddr = &dev_addr; |
167 | 173 | ||
168 | spin_unlock_bh(&priv->mib_lock); | 174 | spin_unlock_bh(&priv->mib_lock); |
@@ -382,8 +388,8 @@ void mac802154_wpan_setup(struct net_device *dev) | |||
382 | get_random_bytes(&priv->bsn, 1); | 388 | get_random_bytes(&priv->bsn, 1); |
383 | get_random_bytes(&priv->dsn, 1); | 389 | get_random_bytes(&priv->dsn, 1); |
384 | 390 | ||
385 | priv->pan_id = IEEE802154_PANID_BROADCAST; | 391 | priv->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST); |
386 | priv->short_addr = IEEE802154_ADDR_BROADCAST; | 392 | priv->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST); |
387 | } | 393 | } |
388 | 394 | ||
389 | static int mac802154_process_data(struct net_device *dev, struct sk_buff *skb) | 395 | static int mac802154_process_data(struct net_device *dev, struct sk_buff *skb) |
@@ -394,10 +400,15 @@ static int mac802154_process_data(struct net_device *dev, struct sk_buff *skb) | |||
394 | static int | 400 | static int |
395 | mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb) | 401 | mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb) |
396 | { | 402 | { |
403 | u16 span, sshort; | ||
404 | |||
397 | pr_debug("getting packet via slave interface %s\n", sdata->dev->name); | 405 | pr_debug("getting packet via slave interface %s\n", sdata->dev->name); |
398 | 406 | ||
399 | spin_lock_bh(&sdata->mib_lock); | 407 | spin_lock_bh(&sdata->mib_lock); |
400 | 408 | ||
409 | span = le16_to_cpu(sdata->pan_id); | ||
410 | sshort = le16_to_cpu(sdata->short_addr); | ||
411 | |||
401 | switch (mac_cb(skb)->da.addr_type) { | 412 | switch (mac_cb(skb)->da.addr_type) { |
402 | case IEEE802154_ADDR_NONE: | 413 | case IEEE802154_ADDR_NONE: |
403 | if (mac_cb(skb)->sa.addr_type != IEEE802154_ADDR_NONE) | 414 | if (mac_cb(skb)->sa.addr_type != IEEE802154_ADDR_NONE) |
@@ -408,7 +419,7 @@ mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb) | |||
408 | skb->pkt_type = PACKET_HOST; | 419 | skb->pkt_type = PACKET_HOST; |
409 | break; | 420 | break; |
410 | case IEEE802154_ADDR_LONG: | 421 | case IEEE802154_ADDR_LONG: |
411 | if (mac_cb(skb)->da.pan_id != sdata->pan_id && | 422 | if (mac_cb(skb)->da.pan_id != span && |
412 | mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST) | 423 | mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST) |
413 | skb->pkt_type = PACKET_OTHERHOST; | 424 | skb->pkt_type = PACKET_OTHERHOST; |
414 | else if (!memcmp(mac_cb(skb)->da.hwaddr, sdata->dev->dev_addr, | 425 | else if (!memcmp(mac_cb(skb)->da.hwaddr, sdata->dev->dev_addr, |
@@ -418,10 +429,10 @@ mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb) | |||
418 | skb->pkt_type = PACKET_OTHERHOST; | 429 | skb->pkt_type = PACKET_OTHERHOST; |
419 | break; | 430 | break; |
420 | case IEEE802154_ADDR_SHORT: | 431 | case IEEE802154_ADDR_SHORT: |
421 | if (mac_cb(skb)->da.pan_id != sdata->pan_id && | 432 | if (mac_cb(skb)->da.pan_id != span && |
422 | mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST) | 433 | mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST) |
423 | skb->pkt_type = PACKET_OTHERHOST; | 434 | skb->pkt_type = PACKET_OTHERHOST; |
424 | else if (mac_cb(skb)->da.short_addr == sdata->short_addr) | 435 | else if (mac_cb(skb)->da.short_addr == sshort) |
425 | skb->pkt_type = PACKET_HOST; | 436 | skb->pkt_type = PACKET_HOST; |
426 | else if (mac_cb(skb)->da.short_addr == | 437 | else if (mac_cb(skb)->da.short_addr == |
427 | IEEE802154_ADDR_BROADCAST) | 438 | IEEE802154_ADDR_BROADCAST) |