Commit b70ab2e8 authored by Phoebe Buckheister's avatar Phoebe Buckheister Committed by David S. Miller

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: default avatarPhoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 46ef0eb3
...@@ -745,30 +745,31 @@ at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev, ...@@ -745,30 +745,31 @@ at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev,
struct at86rf230_local *lp = dev->priv; struct at86rf230_local *lp = dev->priv;
if (changed & IEEE802515_AFILT_SADDR_CHANGED) { if (changed & IEEE802515_AFILT_SADDR_CHANGED) {
u16 addr = le16_to_cpu(filt->short_addr);
dev_vdbg(&lp->spi->dev, dev_vdbg(&lp->spi->dev,
"at86rf230_set_hw_addr_filt called for saddr\n"); "at86rf230_set_hw_addr_filt called for saddr\n");
__at86rf230_write(lp, RG_SHORT_ADDR_0, filt->short_addr); __at86rf230_write(lp, RG_SHORT_ADDR_0, addr);
__at86rf230_write(lp, RG_SHORT_ADDR_1, filt->short_addr >> 8); __at86rf230_write(lp, RG_SHORT_ADDR_1, addr >> 8);
} }
if (changed & IEEE802515_AFILT_PANID_CHANGED) { if (changed & IEEE802515_AFILT_PANID_CHANGED) {
u16 pan = le16_to_cpu(filt->pan_id);
dev_vdbg(&lp->spi->dev, dev_vdbg(&lp->spi->dev,
"at86rf230_set_hw_addr_filt called for pan id\n"); "at86rf230_set_hw_addr_filt called for pan id\n");
__at86rf230_write(lp, RG_PAN_ID_0, filt->pan_id); __at86rf230_write(lp, RG_PAN_ID_0, pan);
__at86rf230_write(lp, RG_PAN_ID_1, filt->pan_id >> 8); __at86rf230_write(lp, RG_PAN_ID_1, pan >> 8);
} }
if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) { if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) {
u8 i, addr[8];
memcpy(addr, &filt->ieee_addr, 8);
dev_vdbg(&lp->spi->dev, dev_vdbg(&lp->spi->dev,
"at86rf230_set_hw_addr_filt called for IEEE addr\n"); "at86rf230_set_hw_addr_filt called for IEEE addr\n");
at86rf230_write_subreg(lp, SR_IEEE_ADDR_0, filt->ieee_addr[7]); for (i = 0; i < 8; i++)
at86rf230_write_subreg(lp, SR_IEEE_ADDR_1, filt->ieee_addr[6]); __at86rf230_write(lp, RG_IEEE_ADDR_0 + i, addr[i]);
at86rf230_write_subreg(lp, SR_IEEE_ADDR_2, filt->ieee_addr[5]);
at86rf230_write_subreg(lp, SR_IEEE_ADDR_3, filt->ieee_addr[4]);
at86rf230_write_subreg(lp, SR_IEEE_ADDR_4, filt->ieee_addr[3]);
at86rf230_write_subreg(lp, SR_IEEE_ADDR_5, filt->ieee_addr[2]);
at86rf230_write_subreg(lp, SR_IEEE_ADDR_6, filt->ieee_addr[1]);
at86rf230_write_subreg(lp, SR_IEEE_ADDR_7, filt->ieee_addr[0]);
} }
if (changed & IEEE802515_AFILT_PANC_CHANGED) { if (changed & IEEE802515_AFILT_PANC_CHANGED) {
......
...@@ -63,11 +63,11 @@ static struct wpan_phy *fake_get_phy(const struct net_device *dev) ...@@ -63,11 +63,11 @@ static struct wpan_phy *fake_get_phy(const struct net_device *dev)
* *
* Return the ID of the PAN from the PIB. * Return the ID of the PAN from the PIB.
*/ */
static u16 fake_get_pan_id(const struct net_device *dev) static __le16 fake_get_pan_id(const struct net_device *dev)
{ {
BUG_ON(dev->type != ARPHRD_IEEE802154); BUG_ON(dev->type != ARPHRD_IEEE802154);
return 0xeba1; return cpu_to_le16(0xeba1);
} }
/** /**
...@@ -78,11 +78,11 @@ static u16 fake_get_pan_id(const struct net_device *dev) ...@@ -78,11 +78,11 @@ static u16 fake_get_pan_id(const struct net_device *dev)
* device. If the device has not yet had a short address assigned * device. If the device has not yet had a short address assigned
* then this should return 0xFFFF to indicate a lack of association. * then this should return 0xFFFF to indicate a lack of association.
*/ */
static u16 fake_get_short_addr(const struct net_device *dev) static __le16 fake_get_short_addr(const struct net_device *dev)
{ {
BUG_ON(dev->type != ARPHRD_IEEE802154); BUG_ON(dev->type != ARPHRD_IEEE802154);
return 0x1; return cpu_to_le16(0x1);
} }
/** /**
...@@ -149,7 +149,7 @@ static int fake_assoc_req(struct net_device *dev, ...@@ -149,7 +149,7 @@ static int fake_assoc_req(struct net_device *dev,
* 802.15.4-2006 document. * 802.15.4-2006 document.
*/ */
static int fake_assoc_resp(struct net_device *dev, static int fake_assoc_resp(struct net_device *dev,
struct ieee802154_addr_sa *addr, u16 short_addr, u8 status) struct ieee802154_addr_sa *addr, __le16 short_addr, u8 status)
{ {
return 0; return 0;
} }
...@@ -281,8 +281,8 @@ static int ieee802154_fake_ioctl(struct net_device *dev, struct ifreq *ifr, ...@@ -281,8 +281,8 @@ static int ieee802154_fake_ioctl(struct net_device *dev, struct ifreq *ifr,
switch (cmd) { switch (cmd) {
case SIOCGIFADDR: case SIOCGIFADDR:
/* FIXME: fixed here, get from device IRL */ /* FIXME: fixed here, get from device IRL */
pan_id = fake_get_pan_id(dev); pan_id = le16_to_cpu(fake_get_pan_id(dev));
short_addr = fake_get_short_addr(dev); short_addr = le16_to_cpu(fake_get_short_addr(dev));
if (pan_id == IEEE802154_PANID_BROADCAST || if (pan_id == IEEE802154_PANID_BROADCAST ||
short_addr == IEEE802154_ADDR_BROADCAST) short_addr == IEEE802154_ADDR_BROADCAST)
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
......
...@@ -465,8 +465,8 @@ static int mrf24j40_filter(struct ieee802154_dev *dev, ...@@ -465,8 +465,8 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
if (changed & IEEE802515_AFILT_SADDR_CHANGED) { if (changed & IEEE802515_AFILT_SADDR_CHANGED) {
/* Short Addr */ /* Short Addr */
u8 addrh, addrl; u8 addrh, addrl;
addrh = filt->short_addr >> 8 & 0xff; addrh = le16_to_cpu(filt->short_addr) >> 8 & 0xff;
addrl = filt->short_addr & 0xff; addrl = le16_to_cpu(filt->short_addr) & 0xff;
write_short_reg(devrec, REG_SADRH, addrh); write_short_reg(devrec, REG_SADRH, addrh);
write_short_reg(devrec, REG_SADRL, addrl); write_short_reg(devrec, REG_SADRL, addrl);
...@@ -476,15 +476,16 @@ static int mrf24j40_filter(struct ieee802154_dev *dev, ...@@ -476,15 +476,16 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) { if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) {
/* Device Address */ /* Device Address */
int i; u8 i, addr[8];
memcpy(addr, &filt->ieee_addr, 8);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
write_short_reg(devrec, REG_EADR0+i, write_short_reg(devrec, REG_EADR0 + i, addr[i]);
filt->ieee_addr[7-i]);
#ifdef DEBUG #ifdef DEBUG
printk(KERN_DEBUG "Set long addr to: "); printk(KERN_DEBUG "Set long addr to: ");
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
printk("%02hhx ", filt->ieee_addr[i]); printk("%02hhx ", addr[7 - i]);
printk(KERN_DEBUG "\n"); printk(KERN_DEBUG "\n");
#endif #endif
} }
...@@ -492,8 +493,8 @@ static int mrf24j40_filter(struct ieee802154_dev *dev, ...@@ -492,8 +493,8 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
if (changed & IEEE802515_AFILT_PANID_CHANGED) { if (changed & IEEE802515_AFILT_PANID_CHANGED) {
/* PAN ID */ /* PAN ID */
u8 panidl, panidh; u8 panidl, panidh;
panidh = filt->pan_id >> 8 & 0xff; panidh = le16_to_cpu(filt->pan_id) >> 8 & 0xff;
panidl = filt->pan_id & 0xff; panidl = le16_to_cpu(filt->pan_id) & 0xff;
write_short_reg(devrec, REG_PANIDH, panidh); write_short_reg(devrec, REG_PANIDH, panidh);
write_short_reg(devrec, REG_PANIDL, panidl); write_short_reg(devrec, REG_PANIDL, panidl);
......
...@@ -171,7 +171,7 @@ struct ieee802154_mlme_ops { ...@@ -171,7 +171,7 @@ struct ieee802154_mlme_ops {
u8 channel, u8 page, u8 cap); u8 channel, u8 page, u8 cap);
int (*assoc_resp)(struct net_device *dev, int (*assoc_resp)(struct net_device *dev,
struct ieee802154_addr_sa *addr, struct ieee802154_addr_sa *addr,
u16 short_addr, u8 status); __le16 short_addr, u8 status);
int (*disassoc_req)(struct net_device *dev, int (*disassoc_req)(struct net_device *dev,
struct ieee802154_addr_sa *addr, struct ieee802154_addr_sa *addr,
u8 reason); u8 reason);
...@@ -190,8 +190,8 @@ struct ieee802154_mlme_ops { ...@@ -190,8 +190,8 @@ struct ieee802154_mlme_ops {
* FIXME: these should become the part of PIB/MIB interface. * FIXME: these should become the part of PIB/MIB interface.
* However we still don't have IB interface of any kind * However we still don't have IB interface of any kind
*/ */
u16 (*get_pan_id)(const struct net_device *dev); __le16 (*get_pan_id)(const struct net_device *dev);
u16 (*get_short_addr)(const struct net_device *dev); __le16 (*get_short_addr)(const struct net_device *dev);
u8 (*get_dsn)(const struct net_device *dev); u8 (*get_dsn)(const struct net_device *dev);
}; };
......
...@@ -50,7 +50,7 @@ struct ieee802154_hw_addr_filt { ...@@ -50,7 +50,7 @@ struct ieee802154_hw_addr_filt {
* devices across independent networks. * devices across independent networks.
*/ */
__le16 short_addr; __le16 short_addr;
u8 ieee_addr[IEEE802154_ADDR_LEN]; __le64 ieee_addr;
u8 pan_coord; u8 pan_coord;
}; };
...@@ -153,8 +153,7 @@ struct ieee802154_ops { ...@@ -153,8 +153,7 @@ struct ieee802154_ops {
int (*set_hw_addr_filt)(struct ieee802154_dev *dev, int (*set_hw_addr_filt)(struct ieee802154_dev *dev,
struct ieee802154_hw_addr_filt *filt, struct ieee802154_hw_addr_filt *filt,
unsigned long changed); unsigned long changed);
int (*ieee_addr)(struct ieee802154_dev *dev, int (*ieee_addr)(struct ieee802154_dev *dev, __le64 addr);
u8 addr[IEEE802154_ADDR_LEN]);
int (*set_txpower)(struct ieee802154_dev *dev, int db); int (*set_txpower)(struct ieee802154_dev *dev, int db);
int (*set_lbt)(struct ieee802154_dev *dev, bool on); int (*set_lbt)(struct ieee802154_dev *dev, bool on);
int (*set_cca_mode)(struct ieee802154_dev *dev, u8 mode); int (*set_cca_mode)(struct ieee802154_dev *dev, u8 mode);
......
...@@ -52,7 +52,7 @@ int ieee802154_nl_assoc_indic(struct net_device *dev, ...@@ -52,7 +52,7 @@ int ieee802154_nl_assoc_indic(struct net_device *dev,
* Note: This is in section 7.3.2 of the IEEE 802.15.4 document. * Note: This is in section 7.3.2 of the IEEE 802.15.4 document.
*/ */
int ieee802154_nl_assoc_confirm(struct net_device *dev, int ieee802154_nl_assoc_confirm(struct net_device *dev,
u16 short_addr, u8 status); __le16 short_addr, u8 status);
/** /**
* ieee802154_nl_disassoc_indic - Notify userland of disassociation. * ieee802154_nl_disassoc_indic - Notify userland of disassociation.
...@@ -111,8 +111,8 @@ int ieee802154_nl_scan_confirm(struct net_device *dev, ...@@ -111,8 +111,8 @@ int ieee802154_nl_scan_confirm(struct net_device *dev,
* Note: This API cannot indicate a beacon frame for a coordinator * Note: This API cannot indicate a beacon frame for a coordinator
* operating in long addressing mode. * operating in long addressing mode.
*/ */
int ieee802154_nl_beacon_indic(struct net_device *dev, u16 panid, int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
u16 coord_addr); __le16 coord_addr);
/** /**
* ieee802154_nl_start_confirm - Notify userland of completion of start. * ieee802154_nl_start_confirm - Notify userland of completion of start.
......
...@@ -120,11 +120,11 @@ static int lowpan_header_create(struct sk_buff *skb, ...@@ -120,11 +120,11 @@ static int lowpan_header_create(struct sk_buff *skb,
/* prepare wpan address data */ /* prepare wpan address data */
sa.addr_type = IEEE802154_ADDR_LONG; sa.addr_type = IEEE802154_ADDR_LONG;
sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); sa.pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev));
memcpy(&(sa.hwaddr), saddr, 8); memcpy(&(sa.hwaddr), saddr, 8);
/* intra-PAN communications */ /* intra-PAN communications */
da.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); da.pan_id = sa.pan_id;
/* if the destination address is the broadcast address, use the /* if the destination address is the broadcast address, use the
* corresponding short address * corresponding short address
...@@ -352,13 +352,13 @@ static struct wpan_phy *lowpan_get_phy(const struct net_device *dev) ...@@ -352,13 +352,13 @@ static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
return ieee802154_mlme_ops(real_dev)->get_phy(real_dev); return ieee802154_mlme_ops(real_dev)->get_phy(real_dev);
} }
static u16 lowpan_get_pan_id(const struct net_device *dev) static __le16 lowpan_get_pan_id(const struct net_device *dev)
{ {
struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev); return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev);
} }
static u16 lowpan_get_short_addr(const struct net_device *dev) static __le16 lowpan_get_short_addr(const struct net_device *dev)
{ {
struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev); return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev);
......
...@@ -5,3 +5,5 @@ obj-$(CONFIG_6LOWPAN_IPHC) += 6lowpan_iphc.o ...@@ -5,3 +5,5 @@ obj-$(CONFIG_6LOWPAN_IPHC) += 6lowpan_iphc.o
6lowpan-y := 6lowpan_rtnl.o reassembly.o 6lowpan-y := 6lowpan_rtnl.o reassembly.o
ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o
af_802154-y := af_ieee802154.o raw.o dgram.o af_802154-y := af_ieee802154.o raw.o dgram.o
ccflags-y += -D__CHECK_ENDIAN__
...@@ -48,7 +48,7 @@ struct net_device *ieee802154_get_dev(struct net *net, ...@@ -48,7 +48,7 @@ struct net_device *ieee802154_get_dev(struct net *net,
{ {
struct net_device *dev = NULL; struct net_device *dev = NULL;
struct net_device *tmp; struct net_device *tmp;
u16 pan_id, short_addr; __le16 pan_id, short_addr;
switch (addr->addr_type) { switch (addr->addr_type) {
case IEEE802154_ADDR_LONG: case IEEE802154_ADDR_LONG:
...@@ -59,9 +59,9 @@ struct net_device *ieee802154_get_dev(struct net *net, ...@@ -59,9 +59,9 @@ struct net_device *ieee802154_get_dev(struct net *net,
rcu_read_unlock(); rcu_read_unlock();
break; break;
case IEEE802154_ADDR_SHORT: case IEEE802154_ADDR_SHORT:
if (addr->pan_id == 0xffff || if (addr->pan_id == IEEE802154_PANID_BROADCAST ||
addr->short_addr == IEEE802154_ADDR_UNDEF || addr->short_addr == IEEE802154_ADDR_UNDEF ||
addr->short_addr == 0xffff) addr->short_addr == IEEE802154_ADDR_UNDEF)
break; break;
rtnl_lock(); rtnl_lock();
...@@ -74,8 +74,8 @@ struct net_device *ieee802154_get_dev(struct net *net, ...@@ -74,8 +74,8 @@ struct net_device *ieee802154_get_dev(struct net *net,
short_addr = short_addr =
ieee802154_mlme_ops(tmp)->get_short_addr(tmp); ieee802154_mlme_ops(tmp)->get_short_addr(tmp);
if (pan_id == addr->pan_id && if (le16_to_cpu(pan_id) == addr->pan_id &&
short_addr == addr->short_addr) { le16_to_cpu(short_addr) == addr->short_addr) {
dev = tmp; dev = tmp;
dev_hold(dev); dev_hold(dev);
break; break;
......
...@@ -363,8 +363,8 @@ int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb) ...@@ -363,8 +363,8 @@ int ieee802154_dgram_deliver(struct net_device *dev, struct sk_buff *skb)
/* Data frame processing */ /* Data frame processing */
BUG_ON(dev->type != ARPHRD_IEEE802154); BUG_ON(dev->type != ARPHRD_IEEE802154);
pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev));
short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev); short_addr = le16_to_cpu(ieee802154_mlme_ops(dev)->get_short_addr(dev));
read_lock(&dgram_lock); read_lock(&dgram_lock);
sk_for_each(sk, &dgram_head) { sk_for_each(sk, &dgram_head) {
......
...@@ -72,7 +72,7 @@ int ieee802154_nl_assoc_indic(struct net_device *dev, ...@@ -72,7 +72,7 @@ int ieee802154_nl_assoc_indic(struct net_device *dev,
} }
EXPORT_SYMBOL(ieee802154_nl_assoc_indic); EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr, int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr,
u8 status) u8 status)
{ {
struct sk_buff *msg; struct sk_buff *msg;
...@@ -87,7 +87,8 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr, ...@@ -87,7 +87,8 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr) || dev->dev_addr) ||
nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) || nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR,
le16_to_cpu(short_addr)) ||
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
goto nla_put_failure; goto nla_put_failure;
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
...@@ -157,8 +158,8 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status) ...@@ -157,8 +158,8 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
} }
EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm); EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
int ieee802154_nl_beacon_indic(struct net_device *dev, int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
u16 panid, u16 coord_addr) __le16 coord_addr)
{ {
struct sk_buff *msg; struct sk_buff *msg;
...@@ -172,8 +173,10 @@ int ieee802154_nl_beacon_indic(struct net_device *dev, ...@@ -172,8 +173,10 @@ int ieee802154_nl_beacon_indic(struct net_device *dev,
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr) || dev->dev_addr) ||
nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr) || nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR,
nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid)) le16_to_cpu(coord_addr)) ||
nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID,
le16_to_cpu(panid)))
goto nla_put_failure; goto nla_put_failure;
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
...@@ -243,6 +246,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid, ...@@ -243,6 +246,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
{ {
void *hdr; void *hdr;
struct wpan_phy *phy; struct wpan_phy *phy;
u16 short_addr, pan_id;
pr_debug("%s\n", __func__); pr_debug("%s\n", __func__);
...@@ -254,15 +258,16 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid, ...@@ -254,15 +258,16 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
phy = ieee802154_mlme_ops(dev)->get_phy(dev); phy = ieee802154_mlme_ops(dev)->get_phy(dev);
BUG_ON(!phy); BUG_ON(!phy);
short_addr = le16_to_cpu(ieee802154_mlme_ops(dev)->get_short_addr(dev));
pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev));
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) || nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr) || dev->dev_addr) ||
nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
ieee802154_mlme_ops(dev)->get_short_addr(dev)) || nla_put_u16(msg, IEEE802154_ATTR_PAN_ID, pan_id))
nla_put_u16(msg, IEEE802154_ATTR_PAN_ID,
ieee802154_mlme_ops(dev)->get_pan_id(dev)))
goto nla_put_failure; goto nla_put_failure;
wpan_phy_put(phy); wpan_phy_put(phy);
return genlmsg_end(msg, hdr); return genlmsg_end(msg, hdr);
...@@ -368,11 +373,10 @@ int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info) ...@@ -368,11 +373,10 @@ int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
addr.addr_type = IEEE802154_ADDR_LONG; addr.addr_type = IEEE802154_ADDR_LONG;
nla_memcpy(addr.hwaddr, info->attrs[IEEE802154_ATTR_DEST_HW_ADDR], nla_memcpy(addr.hwaddr, info->attrs[IEEE802154_ATTR_DEST_HW_ADDR],
IEEE802154_ADDR_LEN); IEEE802154_ADDR_LEN);
addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); addr.pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev));
ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr, ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
nla_get_u16(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]), cpu_to_le16(nla_get_u16(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR])),
nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS])); nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS]));
out: out:
...@@ -407,7 +411,7 @@ int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info) ...@@ -407,7 +411,7 @@ int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
addr.short_addr = nla_get_u16( addr.short_addr = nla_get_u16(
info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]); info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
} }
addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); addr.pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev));
ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr, ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
nla_get_u8(info->attrs[IEEE802154_ATTR_REASON])); nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
......
obj-$(CONFIG_MAC802154) += mac802154.o obj-$(CONFIG_MAC802154) += mac802154.o
mac802154-objs := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o monitor.o wpan.o mac802154-objs := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o monitor.o wpan.o
ccflags-y += -D__CHECK_ENDIAN__
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <net/netlink.h> #include <net/netlink.h>
#include <linux/nl802154.h> #include <linux/nl802154.h>
#include <net/mac802154.h> #include <net/mac802154.h>
#include <net/ieee802154_netdev.h>
#include <net/route.h> #include <net/route.h>
#include <net/wpan-phy.h> #include <net/wpan-phy.h>
...@@ -46,7 +47,9 @@ int mac802154_slave_open(struct net_device *dev) ...@@ -46,7 +47,9 @@ int mac802154_slave_open(struct net_device *dev)
} }
if (ipriv->ops->ieee_addr) { if (ipriv->ops->ieee_addr) {
res = ipriv->ops->ieee_addr(&ipriv->hw, dev->dev_addr); __le64 addr = ieee802154_devaddr_from_raw(dev->dev_addr);
res = ipriv->ops->ieee_addr(&ipriv->hw, addr);
WARN_ON(res); WARN_ON(res);
if (res) if (res)
goto err; goto err;
......
...@@ -76,6 +76,7 @@ struct mac802154_sub_if_data { ...@@ -76,6 +76,7 @@ struct mac802154_sub_if_data {
__le16 pan_id; __le16 pan_id;
__le16 short_addr; __le16 short_addr;
__le64 extended_addr;
u8 chan; u8 chan;
u8 page; u8 page;
...@@ -106,11 +107,11 @@ netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb, ...@@ -106,11 +107,11 @@ netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb,
u8 page, u8 chan); u8 page, u8 chan);
/* MIB callbacks */ /* MIB callbacks */
void mac802154_dev_set_short_addr(struct net_device *dev, u16 val); void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val);
u16 mac802154_dev_get_short_addr(const struct net_device *dev); __le16 mac802154_dev_get_short_addr(const struct net_device *dev);
void mac802154_dev_set_ieee_addr(struct net_device *dev); void mac802154_dev_set_ieee_addr(struct net_device *dev);
u16 mac802154_dev_get_pan_id(const struct net_device *dev); __le16 mac802154_dev_get_pan_id(const struct net_device *dev);
void mac802154_dev_set_pan_id(struct net_device *dev, u16 val); void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val);
void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
u8 mac802154_dev_get_dsn(const struct net_device *dev); u8 mac802154_dev_get_dsn(const struct net_device *dev);
......
...@@ -42,8 +42,8 @@ static int mac802154_mlme_start_req(struct net_device *dev, ...@@ -42,8 +42,8 @@ static int mac802154_mlme_start_req(struct net_device *dev,
{ {
BUG_ON(addr->addr_type != IEEE802154_ADDR_SHORT); BUG_ON(addr->addr_type != IEEE802154_ADDR_SHORT);
mac802154_dev_set_pan_id(dev, addr->pan_id); mac802154_dev_set_pan_id(dev, cpu_to_le16(addr->pan_id));
mac802154_dev_set_short_addr(dev, addr->short_addr); mac802154_dev_set_short_addr(dev, cpu_to_le16(addr->short_addr));
mac802154_dev_set_ieee_addr(dev); mac802154_dev_set_ieee_addr(dev);
mac802154_dev_set_page_channel(dev, page, channel); mac802154_dev_set_page_channel(dev, page, channel);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <net/mac802154.h> #include <net/mac802154.h>
#include <net/ieee802154_netdev.h>
#include <net/wpan-phy.h> #include <net/wpan-phy.h>
#include "mac802154.h" #include "mac802154.h"
...@@ -79,7 +80,7 @@ static void set_hw_addr_filt(struct net_device *dev, unsigned long changed) ...@@ -79,7 +80,7 @@ static void set_hw_addr_filt(struct net_device *dev, unsigned long changed)
queue_work(priv->hw->dev_workqueue, &work->work); queue_work(priv->hw->dev_workqueue, &work->work);
} }
void mac802154_dev_set_short_addr(struct net_device *dev, u16 val) void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val)
{ {
struct mac802154_sub_if_data *priv = netdev_priv(dev); struct mac802154_sub_if_data *priv = netdev_priv(dev);
...@@ -96,10 +97,10 @@ void mac802154_dev_set_short_addr(struct net_device *dev, u16 val) ...@@ -96,10 +97,10 @@ void mac802154_dev_set_short_addr(struct net_device *dev, u16 val)
} }
} }
u16 mac802154_dev_get_short_addr(const struct net_device *dev) __le16 mac802154_dev_get_short_addr(const struct net_device *dev)
{ {
struct mac802154_sub_if_data *priv = netdev_priv(dev); struct mac802154_sub_if_data *priv = netdev_priv(dev);
u16 ret; __le16 ret;
BUG_ON(dev->type != ARPHRD_IEEE802154); BUG_ON(dev->type != ARPHRD_IEEE802154);
...@@ -114,20 +115,21 @@ void mac802154_dev_set_ieee_addr(struct net_device *dev) ...@@ -114,20 +115,21 @@ void mac802154_dev_set_ieee_addr(struct net_device *dev)
{ {
struct mac802154_sub_if_data *priv = netdev_priv(dev); struct mac802154_sub_if_data *priv = netdev_priv(dev);
struct mac802154_priv *mac = priv->hw; struct mac802154_priv *mac = priv->hw;
__le64 addr;
if (mac->ops->set_hw_addr_filt && addr = ieee802154_devaddr_from_raw(dev->dev_addr);
memcmp(mac->hw.hw_filt.ieee_addr, priv->extended_addr = addr;
dev->dev_addr, IEEE802154_ADDR_LEN)) {
memcpy(mac->hw.hw_filt.ieee_addr, if (mac->ops->set_hw_addr_filt && mac->hw.hw_filt.ieee_addr != addr) {
dev->dev_addr, IEEE802154_ADDR_LEN); mac->hw.hw_filt.ieee_addr = addr;
set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED); set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED);
} }
} }
u16 mac802154_dev_get_pan_id(const struct net_device *dev) __le16 mac802154_dev_get_pan_id(const struct net_device *dev)
{ {
struct mac802154_sub_if_data *priv = netdev_priv(dev); struct mac802154_sub_if_data *priv = netdev_priv(dev);
u16 ret; __le16 ret;
BUG_ON(dev->type != ARPHRD_IEEE802154); BUG_ON(dev->type != ARPHRD_IEEE802154);
...@@ -138,7 +140,7 @@ u16 mac802154_dev_get_pan_id(const struct net_device *dev) ...@@ -138,7 +140,7 @@ u16 mac802154_dev_get_pan_id(const struct net_device *dev)
return ret; return ret;
} }
void mac802154_dev_set_pan_id(struct net_device *dev, u16 val) void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val)
{ {
struct mac802154_sub_if_data *priv = netdev_priv(dev); struct mac802154_sub_if_data *priv = netdev_priv(dev);
......
...@@ -76,19 +76,25 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -76,19 +76,25 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
switch (cmd) { switch (cmd) {
case SIOCGIFADDR: case SIOCGIFADDR:
if (priv->pan_id == IEEE802154_PANID_BROADCAST || {
priv->short_addr == IEEE802154_ADDR_BROADCAST) { u16 pan_id, short_addr;
pan_id = le16_to_cpu(priv->pan_id);
short_addr = le16_to_cpu(priv->short_addr);
if (pan_id == IEEE802154_PANID_BROADCAST ||
short_addr == IEEE802154_ADDR_BROADCAST) {
err = -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
break; break;
} }
sa->family = AF_IEEE802154; sa->family = AF_IEEE802154;
sa->addr.addr_type = IEEE802154_ADDR_SHORT; sa->addr.addr_type = IEEE802154_ADDR_SHORT;
sa->addr.pan_id = priv->pan_id; sa->addr.pan_id = pan_id;
sa->addr.short_addr = priv->short_addr; sa->addr.short_addr = short_addr;
err = 0; err = 0;
break; break;
}
case SIOCSIFADDR: case SIOCSIFADDR:
dev_warn(&dev->dev, dev_warn(&dev->dev,
"Using DEBUGing ioctl SIOCSIFADDR isn't recommened!\n"); "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,8 +107,8 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
break; break;
} }
priv->pan_id = sa->addr.pan_id; priv->pan_id = cpu_to_le16(sa->addr.pan_id);
priv->short_addr = sa->addr.short_addr; priv->short_addr = cpu_to_le16(sa->addr.short_addr);
err = 0; err = 0;
break; break;
...@@ -151,18 +157,18 @@ static int mac802154_header_create(struct sk_buff *skb, ...@@ -151,18 +157,18 @@ static int mac802154_header_create(struct sk_buff *skb,
if (!saddr) { if (!saddr) {
spin_lock_bh(&priv->mib_lock); spin_lock_bh(&priv->mib_lock);
if (priv->short_addr == IEEE802154_ADDR_BROADCAST || if (priv->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
priv->short_addr == IEEE802154_ADDR_UNDEF || priv->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
priv->pan_id == IEEE802154_PANID_BROADCAST) { priv->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
dev_addr.addr_type = IEEE802154_ADDR_LONG; dev_addr.addr_type = IEEE802154_ADDR_LONG;
memcpy(dev_addr.hwaddr, dev->dev_addr, memcpy(dev_addr.hwaddr, dev->dev_addr,
IEEE802154_ADDR_LEN); IEEE802154_ADDR_LEN);
} else { } else {
dev_addr.addr_type = IEEE802154_ADDR_SHORT; dev_addr.addr_type = IEEE802154_ADDR_SHORT;
dev_addr.short_addr = priv->short_addr; dev_addr.short_addr = le16_to_cpu(priv->short_addr);
} }
dev_addr.pan_id = priv->pan_id; dev_addr.pan_id = le16_to_cpu(priv->pan_id);
saddr = &dev_addr; saddr = &dev_addr;
spin_unlock_bh(&priv->mib_lock); spin_unlock_bh(&priv->mib_lock);
...@@ -382,8 +388,8 @@ void mac802154_wpan_setup(struct net_device *dev) ...@@ -382,8 +388,8 @@ void mac802154_wpan_setup(struct net_device *dev)
get_random_bytes(&priv->bsn, 1); get_random_bytes(&priv->bsn, 1);
get_random_bytes(&priv->dsn, 1); get_random_bytes(&priv->dsn, 1);
priv->pan_id = IEEE802154_PANID_BROADCAST; priv->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
priv->short_addr = IEEE802154_ADDR_BROADCAST; priv->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
} }
static int mac802154_process_data(struct net_device *dev, struct sk_buff *skb) 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,10 +400,15 @@ static int mac802154_process_data(struct net_device *dev, struct sk_buff *skb)
static int static int
mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb) mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb)
{ {
u16 span, sshort;
pr_debug("getting packet via slave interface %s\n", sdata->dev->name); pr_debug("getting packet via slave interface %s\n", sdata->dev->name);
spin_lock_bh(&sdata->mib_lock); spin_lock_bh(&sdata->mib_lock);
span = le16_to_cpu(sdata->pan_id);
sshort = le16_to_cpu(sdata->short_addr);
switch (mac_cb(skb)->da.addr_type) { switch (mac_cb(skb)->da.addr_type) {
case IEEE802154_ADDR_NONE: case IEEE802154_ADDR_NONE:
if (mac_cb(skb)->sa.addr_type != IEEE802154_ADDR_NONE) 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,7 +419,7 @@ mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb)
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
break; break;
case IEEE802154_ADDR_LONG: case IEEE802154_ADDR_LONG:
if (mac_cb(skb)->da.pan_id != sdata->pan_id && if (mac_cb(skb)->da.pan_id != span &&
mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST) mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST)
skb->pkt_type = PACKET_OTHERHOST; skb->pkt_type = PACKET_OTHERHOST;
else if (!memcmp(mac_cb(skb)->da.hwaddr, sdata->dev->dev_addr, 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,10 +429,10 @@ mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb)
skb->pkt_type = PACKET_OTHERHOST; skb->pkt_type = PACKET_OTHERHOST;
break; break;
case IEEE802154_ADDR_SHORT: case IEEE802154_ADDR_SHORT:
if (mac_cb(skb)->da.pan_id != sdata->pan_id && if (mac_cb(skb)->da.pan_id != span &&
mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST) mac_cb(skb)->da.pan_id != IEEE802154_PANID_BROADCAST)
skb->pkt_type = PACKET_OTHERHOST; skb->pkt_type = PACKET_OTHERHOST;
else if (mac_cb(skb)->da.short_addr == sdata->short_addr) else if (mac_cb(skb)->da.short_addr == sshort)
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
else if (mac_cb(skb)->da.short_addr == else if (mac_cb(skb)->da.short_addr ==
IEEE802154_ADDR_BROADCAST) IEEE802154_ADDR_BROADCAST)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment