diff options
author | Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> | 2014-03-14 16:24:02 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-03-14 22:15:26 -0400 |
commit | ae531b9475f62c5e1863508604cd6b3faf362d56 (patch) | |
tree | c719f25779f44c4241d799e44c8fc2c8c8065957 /net/ieee802154/nl-mac.c | |
parent | e6278d92005e9d6e374f269b4ce39c908a68ad5d (diff) |
ieee802154: use ieee802154_addr instead of *_sa variants
Change all internal uses of ieee802154_addr_sa to ieee802154_addr,
except for those instances that communicate directly with userspace.
Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ieee802154/nl-mac.c')
-rw-r--r-- | net/ieee802154/nl-mac.c | 114 |
1 files changed, 66 insertions, 48 deletions
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c index 58fa523fb536..bda8dba4f993 100644 --- a/net/ieee802154/nl-mac.c +++ b/net/ieee802154/nl-mac.c | |||
@@ -39,14 +39,34 @@ | |||
39 | 39 | ||
40 | #include "ieee802154.h" | 40 | #include "ieee802154.h" |
41 | 41 | ||
42 | static int nla_put_hwaddr(struct sk_buff *msg, int type, __le64 hwaddr) | ||
43 | { | ||
44 | return nla_put_u64(msg, type, swab64((__force u64)hwaddr)); | ||
45 | } | ||
46 | |||
47 | static __le64 nla_get_hwaddr(const struct nlattr *nla) | ||
48 | { | ||
49 | return ieee802154_devaddr_from_raw(nla_data(nla)); | ||
50 | } | ||
51 | |||
52 | static int nla_put_shortaddr(struct sk_buff *msg, int type, __le16 addr) | ||
53 | { | ||
54 | return nla_put_u16(msg, type, le16_to_cpu(addr)); | ||
55 | } | ||
56 | |||
57 | static __le16 nla_get_shortaddr(const struct nlattr *nla) | ||
58 | { | ||
59 | return cpu_to_le16(nla_get_u16(nla)); | ||
60 | } | ||
61 | |||
42 | int ieee802154_nl_assoc_indic(struct net_device *dev, | 62 | int ieee802154_nl_assoc_indic(struct net_device *dev, |
43 | struct ieee802154_addr_sa *addr, u8 cap) | 63 | struct ieee802154_addr *addr, u8 cap) |
44 | { | 64 | { |
45 | struct sk_buff *msg; | 65 | struct sk_buff *msg; |
46 | 66 | ||
47 | pr_debug("%s\n", __func__); | 67 | pr_debug("%s\n", __func__); |
48 | 68 | ||
49 | if (addr->addr_type != IEEE802154_ADDR_LONG) { | 69 | if (addr->mode != IEEE802154_ADDR_LONG) { |
50 | pr_err("%s: received non-long source address!\n", __func__); | 70 | pr_err("%s: received non-long source address!\n", __func__); |
51 | return -EINVAL; | 71 | return -EINVAL; |
52 | } | 72 | } |
@@ -59,8 +79,8 @@ int ieee802154_nl_assoc_indic(struct net_device *dev, | |||
59 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || | 79 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
60 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 80 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
61 | dev->dev_addr) || | 81 | dev->dev_addr) || |
62 | nla_put(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, | 82 | nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR, |
63 | addr->hwaddr) || | 83 | addr->extended_addr) || |
64 | nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap)) | 84 | nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap)) |
65 | goto nla_put_failure; | 85 | goto nla_put_failure; |
66 | 86 | ||
@@ -87,8 +107,7 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr, | |||
87 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || | 107 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
88 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 108 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
89 | dev->dev_addr) || | 109 | dev->dev_addr) || |
90 | nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, | 110 | nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) || |
91 | le16_to_cpu(short_addr)) || | ||
92 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) | 111 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) |
93 | goto nla_put_failure; | 112 | goto nla_put_failure; |
94 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); | 113 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
@@ -100,7 +119,7 @@ nla_put_failure: | |||
100 | EXPORT_SYMBOL(ieee802154_nl_assoc_confirm); | 119 | EXPORT_SYMBOL(ieee802154_nl_assoc_confirm); |
101 | 120 | ||
102 | int ieee802154_nl_disassoc_indic(struct net_device *dev, | 121 | int ieee802154_nl_disassoc_indic(struct net_device *dev, |
103 | struct ieee802154_addr_sa *addr, u8 reason) | 122 | struct ieee802154_addr *addr, u8 reason) |
104 | { | 123 | { |
105 | struct sk_buff *msg; | 124 | struct sk_buff *msg; |
106 | 125 | ||
@@ -115,13 +134,13 @@ int ieee802154_nl_disassoc_indic(struct net_device *dev, | |||
115 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 134 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
116 | dev->dev_addr)) | 135 | dev->dev_addr)) |
117 | goto nla_put_failure; | 136 | goto nla_put_failure; |
118 | if (addr->addr_type == IEEE802154_ADDR_LONG) { | 137 | if (addr->mode == IEEE802154_ADDR_LONG) { |
119 | if (nla_put(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, | 138 | if (nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR, |
120 | addr->hwaddr)) | 139 | addr->extended_addr)) |
121 | goto nla_put_failure; | 140 | goto nla_put_failure; |
122 | } else { | 141 | } else { |
123 | if (nla_put_u16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR, | 142 | if (nla_put_shortaddr(msg, IEEE802154_ATTR_SRC_SHORT_ADDR, |
124 | addr->short_addr)) | 143 | addr->short_addr)) |
125 | goto nla_put_failure; | 144 | goto nla_put_failure; |
126 | } | 145 | } |
127 | if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason)) | 146 | if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason)) |
@@ -173,10 +192,9 @@ int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid, | |||
173 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || | 192 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
174 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 193 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
175 | dev->dev_addr) || | 194 | dev->dev_addr) || |
176 | nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, | 195 | nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, |
177 | le16_to_cpu(coord_addr)) || | 196 | coord_addr) || |
178 | nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, | 197 | nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_PAN_ID, panid)) |
179 | le16_to_cpu(panid))) | ||
180 | goto nla_put_failure; | 198 | goto nla_put_failure; |
181 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); | 199 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
182 | 200 | ||
@@ -246,7 +264,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid, | |||
246 | { | 264 | { |
247 | void *hdr; | 265 | void *hdr; |
248 | struct wpan_phy *phy; | 266 | struct wpan_phy *phy; |
249 | u16 short_addr, pan_id; | 267 | __le16 short_addr, pan_id; |
250 | 268 | ||
251 | pr_debug("%s\n", __func__); | 269 | pr_debug("%s\n", __func__); |
252 | 270 | ||
@@ -258,16 +276,16 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid, | |||
258 | phy = ieee802154_mlme_ops(dev)->get_phy(dev); | 276 | phy = ieee802154_mlme_ops(dev)->get_phy(dev); |
259 | BUG_ON(!phy); | 277 | BUG_ON(!phy); |
260 | 278 | ||
261 | short_addr = le16_to_cpu(ieee802154_mlme_ops(dev)->get_short_addr(dev)); | 279 | short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev); |
262 | pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev)); | 280 | pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); |
263 | 281 | ||
264 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || | 282 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
265 | nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) || | 283 | nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) || |
266 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || | 284 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
267 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 285 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
268 | dev->dev_addr) || | 286 | dev->dev_addr) || |
269 | nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) || | 287 | nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) || |
270 | nla_put_u16(msg, IEEE802154_ATTR_PAN_ID, pan_id)) | 288 | nla_put_shortaddr(msg, IEEE802154_ATTR_PAN_ID, pan_id)) |
271 | goto nla_put_failure; | 289 | goto nla_put_failure; |
272 | wpan_phy_put(phy); | 290 | wpan_phy_put(phy); |
273 | return genlmsg_end(msg, hdr); | 291 | return genlmsg_end(msg, hdr); |
@@ -309,7 +327,7 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info) | |||
309 | int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info) | 327 | int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info) |
310 | { | 328 | { |
311 | struct net_device *dev; | 329 | struct net_device *dev; |
312 | struct ieee802154_addr_sa addr; | 330 | struct ieee802154_addr addr; |
313 | u8 page; | 331 | u8 page; |
314 | int ret = -EOPNOTSUPP; | 332 | int ret = -EOPNOTSUPP; |
315 | 333 | ||
@@ -327,16 +345,16 @@ int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info) | |||
327 | goto out; | 345 | goto out; |
328 | 346 | ||
329 | if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) { | 347 | if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) { |
330 | addr.addr_type = IEEE802154_ADDR_LONG; | 348 | addr.mode = IEEE802154_ADDR_LONG; |
331 | nla_memcpy(addr.hwaddr, | 349 | addr.extended_addr = nla_get_hwaddr( |
332 | info->attrs[IEEE802154_ATTR_COORD_HW_ADDR], | 350 | info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]); |
333 | IEEE802154_ADDR_LEN); | ||
334 | } else { | 351 | } else { |
335 | addr.addr_type = IEEE802154_ADDR_SHORT; | 352 | addr.mode = IEEE802154_ADDR_SHORT; |
336 | addr.short_addr = nla_get_u16( | 353 | addr.short_addr = nla_get_shortaddr( |
337 | info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]); | 354 | info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]); |
338 | } | 355 | } |
339 | addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]); | 356 | addr.pan_id = nla_get_shortaddr( |
357 | info->attrs[IEEE802154_ATTR_COORD_PAN_ID]); | ||
340 | 358 | ||
341 | if (info->attrs[IEEE802154_ATTR_PAGE]) | 359 | if (info->attrs[IEEE802154_ATTR_PAGE]) |
342 | page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]); | 360 | page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]); |
@@ -356,7 +374,7 @@ out: | |||
356 | int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info) | 374 | int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info) |
357 | { | 375 | { |
358 | struct net_device *dev; | 376 | struct net_device *dev; |
359 | struct ieee802154_addr_sa addr; | 377 | struct ieee802154_addr addr; |
360 | int ret = -EOPNOTSUPP; | 378 | int ret = -EOPNOTSUPP; |
361 | 379 | ||
362 | if (!info->attrs[IEEE802154_ATTR_STATUS] || | 380 | if (!info->attrs[IEEE802154_ATTR_STATUS] || |
@@ -370,13 +388,13 @@ int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info) | |||
370 | if (!ieee802154_mlme_ops(dev)->assoc_resp) | 388 | if (!ieee802154_mlme_ops(dev)->assoc_resp) |
371 | goto out; | 389 | goto out; |
372 | 390 | ||
373 | addr.addr_type = IEEE802154_ADDR_LONG; | 391 | addr.mode = IEEE802154_ADDR_LONG; |
374 | nla_memcpy(addr.hwaddr, info->attrs[IEEE802154_ATTR_DEST_HW_ADDR], | 392 | addr.extended_addr = nla_get_hwaddr( |
375 | IEEE802154_ADDR_LEN); | 393 | info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]); |
376 | addr.pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev)); | 394 | addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); |
377 | 395 | ||
378 | ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr, | 396 | ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr, |
379 | cpu_to_le16(nla_get_u16(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR])), | 397 | nla_get_shortaddr(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]), |
380 | nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS])); | 398 | nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS])); |
381 | 399 | ||
382 | out: | 400 | out: |
@@ -387,7 +405,7 @@ out: | |||
387 | int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info) | 405 | int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info) |
388 | { | 406 | { |
389 | struct net_device *dev; | 407 | struct net_device *dev; |
390 | struct ieee802154_addr_sa addr; | 408 | struct ieee802154_addr addr; |
391 | int ret = -EOPNOTSUPP; | 409 | int ret = -EOPNOTSUPP; |
392 | 410 | ||
393 | if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] && | 411 | if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] && |
@@ -402,16 +420,15 @@ int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info) | |||
402 | goto out; | 420 | goto out; |
403 | 421 | ||
404 | if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) { | 422 | if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) { |
405 | addr.addr_type = IEEE802154_ADDR_LONG; | 423 | addr.mode = IEEE802154_ADDR_LONG; |
406 | nla_memcpy(addr.hwaddr, | 424 | addr.extended_addr = nla_get_hwaddr( |
407 | info->attrs[IEEE802154_ATTR_DEST_HW_ADDR], | 425 | info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]); |
408 | IEEE802154_ADDR_LEN); | ||
409 | } else { | 426 | } else { |
410 | addr.addr_type = IEEE802154_ADDR_SHORT; | 427 | addr.mode = IEEE802154_ADDR_SHORT; |
411 | addr.short_addr = nla_get_u16( | 428 | addr.short_addr = nla_get_shortaddr( |
412 | info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]); | 429 | info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]); |
413 | } | 430 | } |
414 | addr.pan_id = le16_to_cpu(ieee802154_mlme_ops(dev)->get_pan_id(dev)); | 431 | addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev); |
415 | 432 | ||
416 | ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr, | 433 | ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr, |
417 | nla_get_u8(info->attrs[IEEE802154_ATTR_REASON])); | 434 | nla_get_u8(info->attrs[IEEE802154_ATTR_REASON])); |
@@ -429,7 +446,7 @@ out: | |||
429 | int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info) | 446 | int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info) |
430 | { | 447 | { |
431 | struct net_device *dev; | 448 | struct net_device *dev; |
432 | struct ieee802154_addr_sa addr; | 449 | struct ieee802154_addr addr; |
433 | 450 | ||
434 | u8 channel, bcn_ord, sf_ord; | 451 | u8 channel, bcn_ord, sf_ord; |
435 | u8 page; | 452 | u8 page; |
@@ -453,10 +470,11 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info) | |||
453 | if (!ieee802154_mlme_ops(dev)->start_req) | 470 | if (!ieee802154_mlme_ops(dev)->start_req) |
454 | goto out; | 471 | goto out; |
455 | 472 | ||
456 | addr.addr_type = IEEE802154_ADDR_SHORT; | 473 | addr.mode = IEEE802154_ADDR_SHORT; |
457 | addr.short_addr = nla_get_u16( | 474 | addr.short_addr = nla_get_shortaddr( |
458 | info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]); | 475 | info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]); |
459 | addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]); | 476 | addr.pan_id = nla_get_shortaddr( |
477 | info->attrs[IEEE802154_ATTR_COORD_PAN_ID]); | ||
460 | 478 | ||
461 | channel = nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]); | 479 | channel = nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]); |
462 | bcn_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_BCN_ORD]); | 480 | bcn_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_BCN_ORD]); |
@@ -471,7 +489,7 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info) | |||
471 | page = 0; | 489 | page = 0; |
472 | 490 | ||
473 | 491 | ||
474 | if (addr.short_addr == IEEE802154_ADDR_BROADCAST) { | 492 | if (addr.short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST)) { |
475 | ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS); | 493 | ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS); |
476 | dev_put(dev); | 494 | dev_put(dev); |
477 | return -EINVAL; | 495 | return -EINVAL; |