aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/ieee802154_netdev.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/ieee802154_netdev.h')
-rw-r--r--include/net/ieee802154_netdev.h195
1 files changed, 182 insertions, 13 deletions
diff --git a/include/net/ieee802154_netdev.h b/include/net/ieee802154_netdev.h
index 8196d5d40359..5a719ca892f4 100644
--- a/include/net/ieee802154_netdev.h
+++ b/include/net/ieee802154_netdev.h
@@ -28,6 +28,164 @@
28#define IEEE802154_NETDEVICE_H 28#define IEEE802154_NETDEVICE_H
29 29
30#include <net/af_ieee802154.h> 30#include <net/af_ieee802154.h>
31#include <linux/netdevice.h>
32#include <linux/skbuff.h>
33
34struct ieee802154_sechdr {
35#if defined(__LITTLE_ENDIAN_BITFIELD)
36 u8 level:3,
37 key_id_mode:2,
38 reserved:3;
39#elif defined(__BIG_ENDIAN_BITFIELD)
40 u8 reserved:3,
41 key_id_mode:2,
42 level:3;
43#else
44#error "Please fix <asm/byteorder.h>"
45#endif
46 u8 key_id;
47 __le32 frame_counter;
48 union {
49 __le32 short_src;
50 __le64 extended_src;
51 };
52};
53
54struct ieee802154_addr {
55 u8 mode;
56 __le16 pan_id;
57 union {
58 __le16 short_addr;
59 __le64 extended_addr;
60 };
61};
62
63struct ieee802154_hdr_fc {
64#if defined(__LITTLE_ENDIAN_BITFIELD)
65 u16 type:3,
66 security_enabled:1,
67 frame_pending:1,
68 ack_request:1,
69 intra_pan:1,
70 reserved:3,
71 dest_addr_mode:2,
72 version:2,
73 source_addr_mode:2;
74#elif defined(__BIG_ENDIAN_BITFIELD)
75 u16 reserved:1,
76 intra_pan:1,
77 ack_request:1,
78 frame_pending:1,
79 security_enabled:1,
80 type:3,
81 source_addr_mode:2,
82 version:2,
83 dest_addr_mode:2,
84 reserved2:2;
85#else
86#error "Please fix <asm/byteorder.h>"
87#endif
88};
89
90struct ieee802154_hdr {
91 struct ieee802154_hdr_fc fc;
92 u8 seq;
93 struct ieee802154_addr source;
94 struct ieee802154_addr dest;
95 struct ieee802154_sechdr sec;
96};
97
98/* pushes hdr onto the skb. fields of hdr->fc that can be calculated from
99 * the contents of hdr will be, and the actual value of those bits in
100 * hdr->fc will be ignored. this includes the INTRA_PAN bit and the frame
101 * version, if SECEN is set.
102 */
103int ieee802154_hdr_push(struct sk_buff *skb, const struct ieee802154_hdr *hdr);
104
105/* pulls the entire 802.15.4 header off of the skb, including the security
106 * header, and performs pan id decompression
107 */
108int ieee802154_hdr_pull(struct sk_buff *skb, struct ieee802154_hdr *hdr);
109
110/* parses the frame control, sequence number of address fields in a given skb
111 * and stores them into hdr, performing pan id decompression and length checks
112 * to be suitable for use in header_ops.parse
113 */
114int ieee802154_hdr_peek_addrs(const struct sk_buff *skb,
115 struct ieee802154_hdr *hdr);
116
117static inline int ieee802154_hdr_length(struct sk_buff *skb)
118{
119 struct ieee802154_hdr hdr;
120 int len = ieee802154_hdr_pull(skb, &hdr);
121
122 if (len > 0)
123 skb_push(skb, len);
124
125 return len;
126}
127
128static inline bool ieee802154_addr_equal(const struct ieee802154_addr *a1,
129 const struct ieee802154_addr *a2)
130{
131 if (a1->pan_id != a2->pan_id || a1->mode != a2->mode)
132 return false;
133
134 if ((a1->mode == IEEE802154_ADDR_LONG &&
135 a1->extended_addr != a2->extended_addr) ||
136 (a1->mode == IEEE802154_ADDR_SHORT &&
137 a1->short_addr != a2->short_addr))
138 return false;
139
140 return true;
141}
142
143static inline __le64 ieee802154_devaddr_from_raw(const void *raw)
144{
145 u64 temp;
146
147 memcpy(&temp, raw, IEEE802154_ADDR_LEN);
148 return (__force __le64)swab64(temp);
149}
150
151static inline void ieee802154_devaddr_to_raw(void *raw, __le64 addr)
152{
153 u64 temp = swab64((__force u64)addr);
154
155 memcpy(raw, &temp, IEEE802154_ADDR_LEN);
156}
157
158static inline void ieee802154_addr_from_sa(struct ieee802154_addr *a,
159 const struct ieee802154_addr_sa *sa)
160{
161 a->mode = sa->addr_type;
162 a->pan_id = cpu_to_le16(sa->pan_id);
163
164 switch (a->mode) {
165 case IEEE802154_ADDR_SHORT:
166 a->short_addr = cpu_to_le16(sa->short_addr);
167 break;
168 case IEEE802154_ADDR_LONG:
169 a->extended_addr = ieee802154_devaddr_from_raw(sa->hwaddr);
170 break;
171 }
172}
173
174static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa,
175 const struct ieee802154_addr *a)
176{
177 sa->addr_type = a->mode;
178 sa->pan_id = le16_to_cpu(a->pan_id);
179
180 switch (a->mode) {
181 case IEEE802154_ADDR_SHORT:
182 sa->short_addr = le16_to_cpu(a->short_addr);
183 break;
184 case IEEE802154_ADDR_LONG:
185 ieee802154_devaddr_to_raw(sa->hwaddr, a->extended_addr);
186 break;
187 }
188}
31 189
32/* 190/*
33 * A control block of skb passed between the ARPHRD_IEEE802154 device 191 * A control block of skb passed between the ARPHRD_IEEE802154 device
@@ -35,10 +193,10 @@
35 */ 193 */
36struct ieee802154_mac_cb { 194struct ieee802154_mac_cb {
37 u8 lqi; 195 u8 lqi;
38 struct ieee802154_addr sa;
39 struct ieee802154_addr da;
40 u8 flags; 196 u8 flags;
41 u8 seq; 197 u8 seq;
198 struct ieee802154_addr source;
199 struct ieee802154_addr dest;
42}; 200};
43 201
44static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb) 202static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
@@ -50,23 +208,17 @@ static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
50 208
51#define MAC_CB_FLAG_ACKREQ (1 << 3) 209#define MAC_CB_FLAG_ACKREQ (1 << 3)
52#define MAC_CB_FLAG_SECEN (1 << 4) 210#define MAC_CB_FLAG_SECEN (1 << 4)
53#define MAC_CB_FLAG_INTRAPAN (1 << 5)
54 211
55static inline int mac_cb_is_ackreq(struct sk_buff *skb) 212static inline bool mac_cb_is_ackreq(struct sk_buff *skb)
56{ 213{
57 return mac_cb(skb)->flags & MAC_CB_FLAG_ACKREQ; 214 return mac_cb(skb)->flags & MAC_CB_FLAG_ACKREQ;
58} 215}
59 216
60static inline int mac_cb_is_secen(struct sk_buff *skb) 217static inline bool mac_cb_is_secen(struct sk_buff *skb)
61{ 218{
62 return mac_cb(skb)->flags & MAC_CB_FLAG_SECEN; 219 return mac_cb(skb)->flags & MAC_CB_FLAG_SECEN;
63} 220}
64 221
65static inline int mac_cb_is_intrapan(struct sk_buff *skb)
66{
67 return mac_cb(skb)->flags & MAC_CB_FLAG_INTRAPAN;
68}
69
70static inline int mac_cb_type(struct sk_buff *skb) 222static inline int mac_cb_type(struct sk_buff *skb)
71{ 223{
72 return mac_cb(skb)->flags & MAC_CB_FLAG_TYPEMASK; 224 return mac_cb(skb)->flags & MAC_CB_FLAG_TYPEMASK;
@@ -77,6 +229,18 @@ static inline int mac_cb_type(struct sk_buff *skb)
77#define IEEE802154_MAC_SCAN_PASSIVE 2 229#define IEEE802154_MAC_SCAN_PASSIVE 2
78#define IEEE802154_MAC_SCAN_ORPHAN 3 230#define IEEE802154_MAC_SCAN_ORPHAN 3
79 231
232struct ieee802154_mac_params {
233 s8 transmit_power;
234 u8 min_be;
235 u8 max_be;
236 u8 csma_retries;
237 s8 frame_retries;
238
239 bool lbt;
240 u8 cca_mode;
241 s32 cca_ed_level;
242};
243
80struct wpan_phy; 244struct wpan_phy;
81/* 245/*
82 * This should be located at net_device->ml_priv 246 * This should be located at net_device->ml_priv
@@ -92,7 +256,7 @@ struct ieee802154_mlme_ops {
92 u8 channel, u8 page, u8 cap); 256 u8 channel, u8 page, u8 cap);
93 int (*assoc_resp)(struct net_device *dev, 257 int (*assoc_resp)(struct net_device *dev,
94 struct ieee802154_addr *addr, 258 struct ieee802154_addr *addr,
95 u16 short_addr, u8 status); 259 __le16 short_addr, u8 status);
96 int (*disassoc_req)(struct net_device *dev, 260 int (*disassoc_req)(struct net_device *dev,
97 struct ieee802154_addr *addr, 261 struct ieee802154_addr *addr,
98 u8 reason); 262 u8 reason);
@@ -103,6 +267,11 @@ struct ieee802154_mlme_ops {
103 int (*scan_req)(struct net_device *dev, 267 int (*scan_req)(struct net_device *dev,
104 u8 type, u32 channels, u8 page, u8 duration); 268 u8 type, u32 channels, u8 page, u8 duration);
105 269
270 int (*set_mac_params)(struct net_device *dev,
271 const struct ieee802154_mac_params *params);
272 void (*get_mac_params)(struct net_device *dev,
273 struct ieee802154_mac_params *params);
274
106 /* The fields below are required. */ 275 /* The fields below are required. */
107 276
108 struct wpan_phy *(*get_phy)(const struct net_device *dev); 277 struct wpan_phy *(*get_phy)(const struct net_device *dev);
@@ -111,8 +280,8 @@ struct ieee802154_mlme_ops {
111 * FIXME: these should become the part of PIB/MIB interface. 280 * FIXME: these should become the part of PIB/MIB interface.
112 * However we still don't have IB interface of any kind 281 * However we still don't have IB interface of any kind
113 */ 282 */
114 u16 (*get_pan_id)(const struct net_device *dev); 283 __le16 (*get_pan_id)(const struct net_device *dev);
115 u16 (*get_short_addr)(const struct net_device *dev); 284 __le16 (*get_short_addr)(const struct net_device *dev);
116 u8 (*get_dsn)(const struct net_device *dev); 285 u8 (*get_dsn)(const struct net_device *dev);
117}; 286};
118 287