Skip to content

Commit b70ab2e

Browse files
Phoebe Buckheisterdavem330
authored andcommitted
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>
1 parent 46ef0eb commit b70ab2e

17 files changed

Lines changed: 121 additions & 95 deletions

File tree

‎drivers/net/ieee802154/at86rf230.c‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -745,30 +745,31 @@ at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev,
745745
struct at86rf230_local *lp = dev->priv;
746746

747747
if (changed & IEEE802515_AFILT_SADDR_CHANGED) {
748+
u16 addr = le16_to_cpu(filt->short_addr);
749+
748750
dev_vdbg(&lp->spi->dev,
749751
"at86rf230_set_hw_addr_filt called for saddr\n");
750-
__at86rf230_write(lp, RG_SHORT_ADDR_0, filt->short_addr);
751-
__at86rf230_write(lp, RG_SHORT_ADDR_1, filt->short_addr >> 8);
752+
__at86rf230_write(lp, RG_SHORT_ADDR_0, addr);
753+
__at86rf230_write(lp, RG_SHORT_ADDR_1, addr >> 8);
752754
}
753755

754756
if (changed & IEEE802515_AFILT_PANID_CHANGED) {
757+
u16 pan = le16_to_cpu(filt->pan_id);
758+
755759
dev_vdbg(&lp->spi->dev,
756760
"at86rf230_set_hw_addr_filt called for pan id\n");
757-
__at86rf230_write(lp, RG_PAN_ID_0, filt->pan_id);
758-
__at86rf230_write(lp, RG_PAN_ID_1, filt->pan_id >> 8);
761+
__at86rf230_write(lp, RG_PAN_ID_0, pan);
762+
__at86rf230_write(lp, RG_PAN_ID_1, pan >> 8);
759763
}
760764

761765
if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) {
766+
u8 i, addr[8];
767+
768+
memcpy(addr, &filt->ieee_addr, 8);
762769
dev_vdbg(&lp->spi->dev,
763770
"at86rf230_set_hw_addr_filt called for IEEE addr\n");
764-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_0, filt->ieee_addr[7]);
765-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_1, filt->ieee_addr[6]);
766-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_2, filt->ieee_addr[5]);
767-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_3, filt->ieee_addr[4]);
768-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_4, filt->ieee_addr[3]);
769-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_5, filt->ieee_addr[2]);
770-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_6, filt->ieee_addr[1]);
771-
at86rf230_write_subreg(lp, SR_IEEE_ADDR_7, filt->ieee_addr[0]);
771+
for (i = 0; i < 8; i++)
772+
__at86rf230_write(lp, RG_IEEE_ADDR_0 + i, addr[i]);
772773
}
773774

774775
if (changed & IEEE802515_AFILT_PANC_CHANGED) {

‎drivers/net/ieee802154/fakehard.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ static struct wpan_phy *fake_get_phy(const struct net_device *dev)
6363
*
6464
* Return the ID of the PAN from the PIB.
6565
*/
66-
static u16 fake_get_pan_id(const struct net_device *dev)
66+
static __le16 fake_get_pan_id(const struct net_device *dev)
6767
{
6868
BUG_ON(dev->type != ARPHRD_IEEE802154);
6969

70-
return 0xeba1;
70+
return cpu_to_le16(0xeba1);
7171
}
7272

7373
/**
@@ -78,11 +78,11 @@ static u16 fake_get_pan_id(const struct net_device *dev)
7878
* device. If the device has not yet had a short address assigned
7979
* then this should return 0xFFFF to indicate a lack of association.
8080
*/
81-
static u16 fake_get_short_addr(const struct net_device *dev)
81+
static __le16 fake_get_short_addr(const struct net_device *dev)
8282
{
8383
BUG_ON(dev->type != ARPHRD_IEEE802154);
8484

85-
return 0x1;
85+
return cpu_to_le16(0x1);
8686
}
8787

8888
/**
@@ -149,7 +149,7 @@ static int fake_assoc_req(struct net_device *dev,
149149
* 802.15.4-2006 document.
150150
*/
151151
static int fake_assoc_resp(struct net_device *dev,
152-
struct ieee802154_addr_sa *addr, u16 short_addr, u8 status)
152+
struct ieee802154_addr_sa *addr, __le16 short_addr, u8 status)
153153
{
154154
return 0;
155155
}
@@ -281,8 +281,8 @@ static int ieee802154_fake_ioctl(struct net_device *dev, struct ifreq *ifr,
281281
switch (cmd) {
282282
case SIOCGIFADDR:
283283
/* FIXME: fixed here, get from device IRL */
284-
pan_id = fake_get_pan_id(dev);
285-
short_addr = fake_get_short_addr(dev);
284+
pan_id = le16_to_cpu(fake_get_pan_id(dev));
285+
short_addr = le16_to_cpu(fake_get_short_addr(dev));
286286
if (pan_id == IEEE802154_PANID_BROADCAST ||
287287
short_addr == IEEE802154_ADDR_BROADCAST)
288288
return -EADDRNOTAVAIL;

‎drivers/net/ieee802154/mrf24j40.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
465465
if (changed & IEEE802515_AFILT_SADDR_CHANGED) {
466466
/* Short Addr */
467467
u8 addrh, addrl;
468-
addrh = filt->short_addr >> 8 & 0xff;
469-
addrl = filt->short_addr & 0xff;
468+
addrh = le16_to_cpu(filt->short_addr) >> 8 & 0xff;
469+
addrl = le16_to_cpu(filt->short_addr) & 0xff;
470470

471471
write_short_reg(devrec, REG_SADRH, addrh);
472472
write_short_reg(devrec, REG_SADRL, addrl);
@@ -476,24 +476,25 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
476476

477477
if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) {
478478
/* Device Address */
479-
int i;
479+
u8 i, addr[8];
480+
481+
memcpy(addr, &filt->ieee_addr, 8);
480482
for (i = 0; i < 8; i++)
481-
write_short_reg(devrec, REG_EADR0+i,
482-
filt->ieee_addr[7-i]);
483+
write_short_reg(devrec, REG_EADR0 + i, addr[i]);
483484

484485
#ifdef DEBUG
485486
printk(KERN_DEBUG "Set long addr to: ");
486487
for (i = 0; i < 8; i++)
487-
printk("%02hhx ", filt->ieee_addr[i]);
488+
printk("%02hhx ", addr[7 - i]);
488489
printk(KERN_DEBUG "\n");
489490
#endif
490491
}
491492

492493
if (changed & IEEE802515_AFILT_PANID_CHANGED) {
493494
/* PAN ID */
494495
u8 panidl, panidh;
495-
panidh = filt->pan_id >> 8 & 0xff;
496-
panidl = filt->pan_id & 0xff;
496+
panidh = le16_to_cpu(filt->pan_id) >> 8 & 0xff;
497+
panidl = le16_to_cpu(filt->pan_id) & 0xff;
497498
write_short_reg(devrec, REG_PANIDH, panidh);
498499
write_short_reg(devrec, REG_PANIDL, panidl);
499500

‎include/net/ieee802154_netdev.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct ieee802154_mlme_ops {
171171
u8 channel, u8 page, u8 cap);
172172
int (*assoc_resp)(struct net_device *dev,
173173
struct ieee802154_addr_sa *addr,
174-
u16 short_addr, u8 status);
174+
__le16 short_addr, u8 status);
175175
int (*disassoc_req)(struct net_device *dev,
176176
struct ieee802154_addr_sa *addr,
177177
u8 reason);
@@ -190,8 +190,8 @@ struct ieee802154_mlme_ops {
190190
* FIXME: these should become the part of PIB/MIB interface.
191191
* However we still don't have IB interface of any kind
192192
*/
193-
u16 (*get_pan_id)(const struct net_device *dev);
194-
u16 (*get_short_addr)(const struct net_device *dev);
193+
__le16 (*get_pan_id)(const struct net_device *dev);
194+
__le16 (*get_short_addr)(const struct net_device *dev);
195195
u8 (*get_dsn)(const struct net_device *dev);
196196
};
197197

‎include/net/mac802154.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct ieee802154_hw_addr_filt {
5050
* devices across independent networks.
5151
*/
5252
__le16 short_addr;
53-
u8 ieee_addr[IEEE802154_ADDR_LEN];
53+
__le64 ieee_addr;
5454
u8 pan_coord;
5555
};
5656

@@ -153,8 +153,7 @@ struct ieee802154_ops {
153153
int (*set_hw_addr_filt)(struct ieee802154_dev *dev,
154154
struct ieee802154_hw_addr_filt *filt,
155155
unsigned long changed);
156-
int (*ieee_addr)(struct ieee802154_dev *dev,
157-
u8 addr[IEEE802154_ADDR_LEN]);
156+
int (*ieee_addr)(struct ieee802154_dev *dev, __le64 addr);
158157
int (*set_txpower)(struct ieee802154_dev *dev, int db);
159158
int (*set_lbt)(struct ieee802154_dev *dev, bool on);
160159
int (*set_cca_mode)(struct ieee802154_dev *dev, u8 mode);

‎include/net/nl802154.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int ieee802154_nl_assoc_indic(struct net_device *dev,
5252
* Note: This is in section 7.3.2 of the IEEE 802.15.4 document.
5353
*/
5454
int ieee802154_nl_assoc_confirm(struct net_device *dev,
55-
u16 short_addr, u8 status);
55+
__le16 short_addr, u8 status);
5656

5757
/**
5858
* ieee802154_nl_disassoc_indic - Notify userland of disassociation.
@@ -111,8 +111,8 @@ int ieee802154_nl_scan_confirm(struct net_device *dev,
111111
* Note: This API cannot indicate a beacon frame for a coordinator
112112
* operating in long addressing mode.
113113
*/
114-
int ieee802154_nl_beacon_indic(struct net_device *dev, u16 panid,
115-
u16 coord_addr);
114+
int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
115+
__le16 coord_addr);
116116

117117
/**
118118
* ieee802154_nl_start_confirm - Notify userland of completion of start.

‎net/ieee802154/6lowpan_rtnl.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ static int lowpan_header_create(struct sk_buff *skb,
120120

121121
/* prepare wpan address data */
122122
sa.addr_type = IEEE802154_ADDR_LONG;
123-
sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
123+
sa.pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev));
124124

125125
memcpy(&(sa.hwaddr), saddr, 8);
126126
/* intra-PAN communications */
127-
da.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
127+
da.pan_id = sa.pan_id;
128128

129129
/* if the destination address is the broadcast address, use the
130130
* corresponding short address
@@ -352,13 +352,13 @@ static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
352352
return ieee802154_mlme_ops(real_dev)->get_phy(real_dev);
353353
}
354354

355-
static u16 lowpan_get_pan_id(const struct net_device *dev)
355+
static __le16 lowpan_get_pan_id(const struct net_device *dev)
356356
{
357357
struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
358358
return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev);
359359
}
360360

361-
static u16 lowpan_get_short_addr(const struct net_device *dev)
361+
static __le16 lowpan_get_short_addr(const struct net_device *dev)
362362
{
363363
struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
364364
return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev);

‎net/ieee802154/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ obj-$(CONFIG_6LOWPAN_IPHC) += 6lowpan_iphc.o
55
6lowpan-y := 6lowpan_rtnl.o reassembly.o
66
ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o
77
af_802154-y := af_ieee802154.o raw.o dgram.o
8+
9+
ccflags-y += -D__CHECK_ENDIAN__

‎net/ieee802154/af_ieee802154.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct net_device *ieee802154_get_dev(struct net *net,
4848
{
4949
struct net_device *dev = NULL;
5050
struct net_device *tmp;
51-
u16 pan_id, short_addr;
51+
__le16 pan_id, short_addr;
5252

5353
switch (addr->addr_type) {
5454
case IEEE802154_ADDR_LONG:
@@ -59,9 +59,9 @@ struct net_device *ieee802154_get_dev(struct net *net,
5959
rcu_read_unlock();
6060
break;
6161
case IEEE802154_ADDR_SHORT:
62-
if (addr->pan_id == 0xffff ||
62+
if (addr->pan_id == IEEE802154_PANID_BROADCAST ||
6363
addr->short_addr == IEEE802154_ADDR_UNDEF ||
64-
addr->short_addr == 0xffff)
64+
addr->short_addr == IEEE802154_ADDR_UNDEF)
6565
break;
6666

6767
rtnl_lock();
@@ -74,8 +74,8 @@ struct net_device *ieee802154_get_dev(struct net *net,
7474
short_addr =
7575
ieee802154_mlme_ops(tmp)->get_short_addr(tmp);
7676

77-
if (pan_id == addr->pan_id &&
78-
short_addr == addr->short_addr) {
77+
if (le16_to_cpu(pan_id) == addr->pan_id &&
78+
le16_to_cpu(short_addr) == addr->short_addr) {
7979
dev = tmp;
8080
dev_hold(dev);
8181
break;

‎net/ieee802154/dgram.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
363363
/* Data frame processing */
364364
BUG_ON(dev->type != ARPHRD_IEEE802154);
365365

366-
pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
367-
short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev);
366+
pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev));
367+
short_addr = le16_to_cpu(ieee802154_mlme_ops(dev)->get_short_addr(dev));
368368

369369
read_lock(&dgram_lock);
370370
sk_for_each(sk, &dgram_head) {

0 commit comments

Comments
 (0)