diff options
author | Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> | 2014-03-14 16:23:58 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-03-14 22:15:26 -0400 |
commit | 46ef0eb3ea65e7043aac17cb92982be879c65366 (patch) | |
tree | f0058b58360c49cc20360ff2bec2886ac0e684e4 /include/net/ieee802154_netdev.h | |
parent | 376b7bd3558eaf12d3e5c24aa71d0c162d2701fd (diff) |
ieee802154: add address struct with proper endiannes and some operations
Add a replacement ieee802154_addr struct with proper endianness on
fields. Short address fields are stored as __le16 as on the network,
extended (EUI64) addresses are __le64 as opposed to the u8[8] format
used previously. This disconnect with the netdev address, which is
stored as big-endian u8[8], is intentional.
Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/ieee802154_netdev.h')
-rw-r--r-- | include/net/ieee802154_netdev.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/include/net/ieee802154_netdev.h b/include/net/ieee802154_netdev.h index 53937cdbcd82..86d5d50a6a53 100644 --- a/include/net/ieee802154_netdev.h +++ b/include/net/ieee802154_netdev.h | |||
@@ -29,6 +29,78 @@ | |||
29 | 29 | ||
30 | #include <net/af_ieee802154.h> | 30 | #include <net/af_ieee802154.h> |
31 | 31 | ||
32 | struct ieee802154_addr { | ||
33 | u8 mode; | ||
34 | __le16 pan_id; | ||
35 | union { | ||
36 | __le16 short_addr; | ||
37 | __le64 extended_addr; | ||
38 | }; | ||
39 | }; | ||
40 | |||
41 | static inline bool ieee802154_addr_equal(const struct ieee802154_addr *a1, | ||
42 | const struct ieee802154_addr *a2) | ||
43 | { | ||
44 | if (a1->pan_id != a2->pan_id || a1->mode != a2->mode) | ||
45 | return false; | ||
46 | |||
47 | if ((a1->mode == IEEE802154_ADDR_LONG && | ||
48 | a1->extended_addr != a2->extended_addr) || | ||
49 | (a1->mode == IEEE802154_ADDR_SHORT && | ||
50 | a1->short_addr != a2->short_addr)) | ||
51 | return false; | ||
52 | |||
53 | return true; | ||
54 | } | ||
55 | |||
56 | static inline __le64 ieee802154_devaddr_from_raw(const void *raw) | ||
57 | { | ||
58 | u64 temp; | ||
59 | |||
60 | memcpy(&temp, raw, IEEE802154_ADDR_LEN); | ||
61 | return (__force __le64)swab64(temp); | ||
62 | } | ||
63 | |||
64 | static inline void ieee802154_devaddr_to_raw(void *raw, __le64 addr) | ||
65 | { | ||
66 | u64 temp = swab64((__force u64)addr); | ||
67 | |||
68 | memcpy(raw, &temp, IEEE802154_ADDR_LEN); | ||
69 | } | ||
70 | |||
71 | static inline void ieee802154_addr_from_sa(struct ieee802154_addr *a, | ||
72 | const struct ieee802154_addr_sa *sa) | ||
73 | { | ||
74 | a->mode = sa->addr_type; | ||
75 | a->pan_id = cpu_to_le16(sa->pan_id); | ||
76 | |||
77 | switch (a->mode) { | ||
78 | case IEEE802154_ADDR_SHORT: | ||
79 | a->short_addr = cpu_to_le16(sa->short_addr); | ||
80 | break; | ||
81 | case IEEE802154_ADDR_LONG: | ||
82 | a->extended_addr = ieee802154_devaddr_from_raw(sa->hwaddr); | ||
83 | break; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa, | ||
88 | const struct ieee802154_addr *a) | ||
89 | { | ||
90 | sa->addr_type = a->mode; | ||
91 | sa->pan_id = le16_to_cpu(a->pan_id); | ||
92 | |||
93 | switch (a->mode) { | ||
94 | case IEEE802154_ADDR_SHORT: | ||
95 | sa->short_addr = le16_to_cpu(a->short_addr); | ||
96 | break; | ||
97 | case IEEE802154_ADDR_LONG: | ||
98 | ieee802154_devaddr_to_raw(sa->hwaddr, a->extended_addr); | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | |||
32 | struct ieee802154_frag_info { | 104 | struct ieee802154_frag_info { |
33 | __be16 d_tag; | 105 | __be16 d_tag; |
34 | u16 d_size; | 106 | u16 d_size; |