Skip to content

Commit 46ef0eb

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

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

‎include/net/ieee802154_netdev.h‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,78 @@
2929

3030
#include <net/af_ieee802154.h>
3131

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+
32104
struct ieee802154_frag_info {
33105
__be16 d_tag;
34106
u16 d_size;

0 commit comments

Comments
 (0)