2 * An interface between IEEE802.15.4 device and rest of the kernel.
4 * Copyright (C) 2007-2012 Siemens AG
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
17 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
18 * Maxim Osipov <maxim.osipov@siemens.com>
19 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
20 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
23 #ifndef IEEE802154_NETDEVICE_H
24 #define IEEE802154_NETDEVICE_H
26 #include <net/af_ieee802154.h>
27 #include <linux/netdevice.h>
28 #include <linux/skbuff.h>
29 #include <linux/ieee802154.h>
31 #include <net/cfg802154.h>
33 struct ieee802154_sechdr
{
34 #if defined(__LITTLE_ENDIAN_BITFIELD)
38 #elif defined(__BIG_ENDIAN_BITFIELD)
43 #error "Please fix <asm/byteorder.h>"
53 struct ieee802154_addr
{
62 struct ieee802154_hdr_fc
{
63 #if defined(__LITTLE_ENDIAN_BITFIELD)
73 #elif defined(__BIG_ENDIAN_BITFIELD)
85 #error "Please fix <asm/byteorder.h>"
89 struct ieee802154_hdr
{
90 struct ieee802154_hdr_fc fc
;
92 struct ieee802154_addr source
;
93 struct ieee802154_addr dest
;
94 struct ieee802154_sechdr sec
;
97 /* pushes hdr onto the skb. fields of hdr->fc that can be calculated from
98 * the contents of hdr will be, and the actual value of those bits in
99 * hdr->fc will be ignored. this includes the INTRA_PAN bit and the frame
100 * version, if SECEN is set.
102 int ieee802154_hdr_push(struct sk_buff
*skb
, const struct ieee802154_hdr
*hdr
);
104 /* pulls the entire 802.15.4 header off of the skb, including the security
105 * header, and performs pan id decompression
107 int ieee802154_hdr_pull(struct sk_buff
*skb
, struct ieee802154_hdr
*hdr
);
109 /* parses the frame control, sequence number of address fields in a given skb
110 * and stores them into hdr, performing pan id decompression and length checks
111 * to be suitable for use in header_ops.parse
113 int ieee802154_hdr_peek_addrs(const struct sk_buff
*skb
,
114 struct ieee802154_hdr
*hdr
);
116 /* parses the full 802.15.4 header a given skb and stores them into hdr,
117 * performing pan id decompression and length checks to be suitable for use in
120 int ieee802154_hdr_peek(const struct sk_buff
*skb
, struct ieee802154_hdr
*hdr
);
122 int ieee802154_max_payload(const struct ieee802154_hdr
*hdr
);
125 ieee802154_sechdr_authtag_len(const struct ieee802154_sechdr
*sec
)
127 switch (sec
->level
) {
128 case IEEE802154_SCF_SECLEVEL_MIC32
:
129 case IEEE802154_SCF_SECLEVEL_ENC_MIC32
:
131 case IEEE802154_SCF_SECLEVEL_MIC64
:
132 case IEEE802154_SCF_SECLEVEL_ENC_MIC64
:
134 case IEEE802154_SCF_SECLEVEL_MIC128
:
135 case IEEE802154_SCF_SECLEVEL_ENC_MIC128
:
137 case IEEE802154_SCF_SECLEVEL_NONE
:
138 case IEEE802154_SCF_SECLEVEL_ENC
:
144 static inline int ieee802154_hdr_length(struct sk_buff
*skb
)
146 struct ieee802154_hdr hdr
;
147 int len
= ieee802154_hdr_pull(skb
, &hdr
);
155 static inline bool ieee802154_addr_equal(const struct ieee802154_addr
*a1
,
156 const struct ieee802154_addr
*a2
)
158 if (a1
->pan_id
!= a2
->pan_id
|| a1
->mode
!= a2
->mode
)
161 if ((a1
->mode
== IEEE802154_ADDR_LONG
&&
162 a1
->extended_addr
!= a2
->extended_addr
) ||
163 (a1
->mode
== IEEE802154_ADDR_SHORT
&&
164 a1
->short_addr
!= a2
->short_addr
))
170 static inline __le64
ieee802154_devaddr_from_raw(const void *raw
)
174 memcpy(&temp
, raw
, IEEE802154_ADDR_LEN
);
175 return (__force __le64
)swab64(temp
);
178 static inline void ieee802154_devaddr_to_raw(void *raw
, __le64 addr
)
180 u64 temp
= swab64((__force u64
)addr
);
182 memcpy(raw
, &temp
, IEEE802154_ADDR_LEN
);
185 static inline void ieee802154_addr_from_sa(struct ieee802154_addr
*a
,
186 const struct ieee802154_addr_sa
*sa
)
188 a
->mode
= sa
->addr_type
;
189 a
->pan_id
= cpu_to_le16(sa
->pan_id
);
192 case IEEE802154_ADDR_SHORT
:
193 a
->short_addr
= cpu_to_le16(sa
->short_addr
);
195 case IEEE802154_ADDR_LONG
:
196 a
->extended_addr
= ieee802154_devaddr_from_raw(sa
->hwaddr
);
201 static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa
*sa
,
202 const struct ieee802154_addr
*a
)
204 sa
->addr_type
= a
->mode
;
205 sa
->pan_id
= le16_to_cpu(a
->pan_id
);
208 case IEEE802154_ADDR_SHORT
:
209 sa
->short_addr
= le16_to_cpu(a
->short_addr
);
211 case IEEE802154_ADDR_LONG
:
212 ieee802154_devaddr_to_raw(sa
->hwaddr
, a
->extended_addr
);
218 * A control block of skb passed between the ARPHRD_IEEE802154 device
219 * and other stack parts.
221 struct ieee802154_mac_cb
{
228 bool seclevel_override
;
229 struct ieee802154_addr source
;
230 struct ieee802154_addr dest
;
233 static inline struct ieee802154_mac_cb
*mac_cb(struct sk_buff
*skb
)
235 return (struct ieee802154_mac_cb
*)skb
->cb
;
238 static inline struct ieee802154_mac_cb
*mac_cb_init(struct sk_buff
*skb
)
240 BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb
) > sizeof(skb
->cb
));
242 memset(skb
->cb
, 0, sizeof(struct ieee802154_mac_cb
));
246 #define IEEE802154_LLSEC_KEY_SIZE 16
248 struct ieee802154_llsec_key_id
{
252 struct ieee802154_addr device_addr
;
254 __le64 extended_source
;
258 struct ieee802154_llsec_key
{
261 u8 key
[IEEE802154_LLSEC_KEY_SIZE
];
264 struct ieee802154_llsec_key_entry
{
265 struct list_head list
;
267 struct ieee802154_llsec_key_id id
;
268 struct ieee802154_llsec_key
*key
;
271 struct ieee802154_llsec_device_key
{
272 struct list_head list
;
274 struct ieee802154_llsec_key_id key_id
;
279 IEEE802154_LLSEC_DEVKEY_IGNORE
,
280 IEEE802154_LLSEC_DEVKEY_RESTRICT
,
281 IEEE802154_LLSEC_DEVKEY_RECORD
,
283 __IEEE802154_LLSEC_DEVKEY_MAX
,
286 struct ieee802154_llsec_device
{
287 struct list_head list
;
293 bool seclevel_exempt
;
296 struct list_head keys
;
299 struct ieee802154_llsec_seclevel
{
300 struct list_head list
;
304 bool device_override
;
308 struct ieee802154_llsec_params
{
311 __be32 frame_counter
;
313 struct ieee802154_llsec_key_id out_key
;
315 __le64 default_key_source
;
320 __le16 coord_shortaddr
;
323 struct ieee802154_llsec_table
{
324 struct list_head keys
;
325 struct list_head devices
;
326 struct list_head security_levels
;
329 #define IEEE802154_MAC_SCAN_ED 0
330 #define IEEE802154_MAC_SCAN_ACTIVE 1
331 #define IEEE802154_MAC_SCAN_PASSIVE 2
332 #define IEEE802154_MAC_SCAN_ORPHAN 3
334 struct ieee802154_mac_params
{
342 struct wpan_phy_cca cca
;
349 IEEE802154_LLSEC_PARAM_ENABLED
= 1 << 0,
350 IEEE802154_LLSEC_PARAM_FRAME_COUNTER
= 1 << 1,
351 IEEE802154_LLSEC_PARAM_OUT_LEVEL
= 1 << 2,
352 IEEE802154_LLSEC_PARAM_OUT_KEY
= 1 << 3,
353 IEEE802154_LLSEC_PARAM_KEY_SOURCE
= 1 << 4,
354 IEEE802154_LLSEC_PARAM_PAN_ID
= 1 << 5,
355 IEEE802154_LLSEC_PARAM_HWADDR
= 1 << 6,
356 IEEE802154_LLSEC_PARAM_COORD_HWADDR
= 1 << 7,
357 IEEE802154_LLSEC_PARAM_COORD_SHORTADDR
= 1 << 8,
360 struct ieee802154_llsec_ops
{
361 int (*get_params
)(struct net_device
*dev
,
362 struct ieee802154_llsec_params
*params
);
363 int (*set_params
)(struct net_device
*dev
,
364 const struct ieee802154_llsec_params
*params
,
367 int (*add_key
)(struct net_device
*dev
,
368 const struct ieee802154_llsec_key_id
*id
,
369 const struct ieee802154_llsec_key
*key
);
370 int (*del_key
)(struct net_device
*dev
,
371 const struct ieee802154_llsec_key_id
*id
);
373 int (*add_dev
)(struct net_device
*dev
,
374 const struct ieee802154_llsec_device
*llsec_dev
);
375 int (*del_dev
)(struct net_device
*dev
, __le64 dev_addr
);
377 int (*add_devkey
)(struct net_device
*dev
,
379 const struct ieee802154_llsec_device_key
*key
);
380 int (*del_devkey
)(struct net_device
*dev
,
382 const struct ieee802154_llsec_device_key
*key
);
384 int (*add_seclevel
)(struct net_device
*dev
,
385 const struct ieee802154_llsec_seclevel
*sl
);
386 int (*del_seclevel
)(struct net_device
*dev
,
387 const struct ieee802154_llsec_seclevel
*sl
);
389 void (*lock_table
)(struct net_device
*dev
);
390 void (*get_table
)(struct net_device
*dev
,
391 struct ieee802154_llsec_table
**t
);
392 void (*unlock_table
)(struct net_device
*dev
);
395 * This should be located at net_device->ml_priv
397 * get_phy should increment the reference counting on returned phy.
398 * Use wpan_wpy_put to put that reference.
400 struct ieee802154_mlme_ops
{
401 /* The following fields are optional (can be NULL). */
403 int (*assoc_req
)(struct net_device
*dev
,
404 struct ieee802154_addr
*addr
,
405 u8 channel
, u8 page
, u8 cap
);
406 int (*assoc_resp
)(struct net_device
*dev
,
407 struct ieee802154_addr
*addr
,
408 __le16 short_addr
, u8 status
);
409 int (*disassoc_req
)(struct net_device
*dev
,
410 struct ieee802154_addr
*addr
,
412 int (*start_req
)(struct net_device
*dev
,
413 struct ieee802154_addr
*addr
,
414 u8 channel
, u8 page
, u8 bcn_ord
, u8 sf_ord
,
415 u8 pan_coord
, u8 blx
, u8 coord_realign
);
416 int (*scan_req
)(struct net_device
*dev
,
417 u8 type
, u32 channels
, u8 page
, u8 duration
);
419 int (*set_mac_params
)(struct net_device
*dev
,
420 const struct ieee802154_mac_params
*params
);
421 void (*get_mac_params
)(struct net_device
*dev
,
422 struct ieee802154_mac_params
*params
);
424 struct ieee802154_llsec_ops
*llsec
;
426 /* The fields below are required. */
429 * FIXME: these should become the part of PIB/MIB interface.
430 * However we still don't have IB interface of any kind
432 __le16 (*get_pan_id
)(const struct net_device
*dev
);
433 __le16 (*get_short_addr
)(const struct net_device
*dev
);
434 u8 (*get_dsn
)(const struct net_device
*dev
);
437 static inline struct ieee802154_mlme_ops
*
438 ieee802154_mlme_ops(const struct net_device
*dev
)
443 static inline struct ieee802154_reduced_mlme_ops
*
444 ieee802154_reduced_mlme_ops(const struct net_device
*dev
)