11802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2f0166e5eSDmitry Eremin-Solenikov /*
3f0166e5eSDmitry Eremin-Solenikov * An interface between IEEE802.15.4 device and rest of the kernel.
4f0166e5eSDmitry Eremin-Solenikov *
574a02fcfSalex.bluesman.smirnov@gmail.com * Copyright (C) 2007-2012 Siemens AG
6f0166e5eSDmitry Eremin-Solenikov *
7f0166e5eSDmitry Eremin-Solenikov * Written by:
8f0166e5eSDmitry Eremin-Solenikov * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
9f0166e5eSDmitry Eremin-Solenikov * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
10f0166e5eSDmitry Eremin-Solenikov * Maxim Osipov <maxim.osipov@siemens.com>
11f0166e5eSDmitry Eremin-Solenikov * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
1274a02fcfSalex.bluesman.smirnov@gmail.com * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
13f0166e5eSDmitry Eremin-Solenikov */
14f0166e5eSDmitry Eremin-Solenikov
15f0166e5eSDmitry Eremin-Solenikov #ifndef IEEE802154_NETDEVICE_H
16f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_NETDEVICE_H
17f0166e5eSDmitry Eremin-Solenikov
1894160108SHaimin Zhang #define IEEE802154_REQUIRED_SIZE(struct_type, member) \
1994160108SHaimin Zhang (offsetof(typeof(struct_type), member) + \
2094160108SHaimin Zhang sizeof(((typeof(struct_type) *)(NULL))->member))
2194160108SHaimin Zhang
2294160108SHaimin Zhang #define IEEE802154_ADDR_OFFSET \
2394160108SHaimin Zhang offsetof(typeof(struct sockaddr_ieee802154), addr)
2494160108SHaimin Zhang
2594160108SHaimin Zhang #define IEEE802154_MIN_NAMELEN (IEEE802154_ADDR_OFFSET + \
2694160108SHaimin Zhang IEEE802154_REQUIRED_SIZE(struct ieee802154_addr_sa, addr_type))
2794160108SHaimin Zhang
2894160108SHaimin Zhang #define IEEE802154_NAMELEN_SHORT (IEEE802154_ADDR_OFFSET + \
2994160108SHaimin Zhang IEEE802154_REQUIRED_SIZE(struct ieee802154_addr_sa, short_addr))
3094160108SHaimin Zhang
3194160108SHaimin Zhang #define IEEE802154_NAMELEN_LONG (IEEE802154_ADDR_OFFSET + \
3294160108SHaimin Zhang IEEE802154_REQUIRED_SIZE(struct ieee802154_addr_sa, hwaddr))
3394160108SHaimin Zhang
341cd829c8Salex.bluesman.smirnov@gmail.com #include <net/af_ieee802154.h>
3594b4f6c2SPhoebe Buckheister #include <linux/netdevice.h>
3694b4f6c2SPhoebe Buckheister #include <linux/skbuff.h>
374ca24acaSAlexander Aring #include <linux/ieee802154.h>
3894b4f6c2SPhoebe Buckheister
397fe9a388SAlexander Aring #include <net/cfg802154.h>
407fe9a388SAlexander Aring
4144def58fSMiquel Raynal struct ieee802154_beacon_hdr {
4244def58fSMiquel Raynal #if defined(__LITTLE_ENDIAN_BITFIELD)
4344def58fSMiquel Raynal u16 beacon_order:4,
4444def58fSMiquel Raynal superframe_order:4,
4544def58fSMiquel Raynal final_cap_slot:4,
4644def58fSMiquel Raynal battery_life_ext:1,
4744def58fSMiquel Raynal reserved0:1,
4844def58fSMiquel Raynal pan_coordinator:1,
4944def58fSMiquel Raynal assoc_permit:1;
5044def58fSMiquel Raynal u8 gts_count:3,
5144def58fSMiquel Raynal gts_reserved:4,
5244def58fSMiquel Raynal gts_permit:1;
5344def58fSMiquel Raynal u8 pend_short_addr_count:3,
5444def58fSMiquel Raynal reserved1:1,
5544def58fSMiquel Raynal pend_ext_addr_count:3,
5644def58fSMiquel Raynal reserved2:1;
5744def58fSMiquel Raynal #elif defined(__BIG_ENDIAN_BITFIELD)
5844def58fSMiquel Raynal u16 assoc_permit:1,
5944def58fSMiquel Raynal pan_coordinator:1,
6044def58fSMiquel Raynal reserved0:1,
6144def58fSMiquel Raynal battery_life_ext:1,
6244def58fSMiquel Raynal final_cap_slot:4,
6344def58fSMiquel Raynal superframe_order:4,
6444def58fSMiquel Raynal beacon_order:4;
6544def58fSMiquel Raynal u8 gts_permit:1,
6644def58fSMiquel Raynal gts_reserved:4,
6744def58fSMiquel Raynal gts_count:3;
6844def58fSMiquel Raynal u8 reserved2:1,
6944def58fSMiquel Raynal pend_ext_addr_count:3,
7044def58fSMiquel Raynal reserved1:1,
7144def58fSMiquel Raynal pend_short_addr_count:3;
7244def58fSMiquel Raynal #else
7344def58fSMiquel Raynal #error "Please fix <asm/byteorder.h>"
7444def58fSMiquel Raynal #endif
7544def58fSMiquel Raynal } __packed;
7644def58fSMiquel Raynal
77e2c3e6f5SMiquel Raynal struct ieee802154_mac_cmd_pl {
78e2c3e6f5SMiquel Raynal u8 cmd_id;
79e2c3e6f5SMiquel Raynal } __packed;
80e2c3e6f5SMiquel Raynal
8194b4f6c2SPhoebe Buckheister struct ieee802154_sechdr {
8294b4f6c2SPhoebe Buckheister #if defined(__LITTLE_ENDIAN_BITFIELD)
8394b4f6c2SPhoebe Buckheister u8 level:3,
8494b4f6c2SPhoebe Buckheister key_id_mode:2,
8594b4f6c2SPhoebe Buckheister reserved:3;
8694b4f6c2SPhoebe Buckheister #elif defined(__BIG_ENDIAN_BITFIELD)
8794b4f6c2SPhoebe Buckheister u8 reserved:3,
8894b4f6c2SPhoebe Buckheister key_id_mode:2,
8994b4f6c2SPhoebe Buckheister level:3;
9094b4f6c2SPhoebe Buckheister #else
9194b4f6c2SPhoebe Buckheister #error "Please fix <asm/byteorder.h>"
9294b4f6c2SPhoebe Buckheister #endif
9394b4f6c2SPhoebe Buckheister u8 key_id;
9494b4f6c2SPhoebe Buckheister __le32 frame_counter;
9594b4f6c2SPhoebe Buckheister union {
9694b4f6c2SPhoebe Buckheister __le32 short_src;
9794b4f6c2SPhoebe Buckheister __le64 extended_src;
9894b4f6c2SPhoebe Buckheister };
9994b4f6c2SPhoebe Buckheister };
1001cd829c8Salex.bluesman.smirnov@gmail.com
10194b4f6c2SPhoebe Buckheister struct ieee802154_hdr_fc {
10294b4f6c2SPhoebe Buckheister #if defined(__LITTLE_ENDIAN_BITFIELD)
10394b4f6c2SPhoebe Buckheister u16 type:3,
10494b4f6c2SPhoebe Buckheister security_enabled:1,
10594b4f6c2SPhoebe Buckheister frame_pending:1,
10694b4f6c2SPhoebe Buckheister ack_request:1,
10794b4f6c2SPhoebe Buckheister intra_pan:1,
10894b4f6c2SPhoebe Buckheister reserved:3,
10994b4f6c2SPhoebe Buckheister dest_addr_mode:2,
11094b4f6c2SPhoebe Buckheister version:2,
11194b4f6c2SPhoebe Buckheister source_addr_mode:2;
11294b4f6c2SPhoebe Buckheister #elif defined(__BIG_ENDIAN_BITFIELD)
11394b4f6c2SPhoebe Buckheister u16 reserved:1,
11494b4f6c2SPhoebe Buckheister intra_pan:1,
11594b4f6c2SPhoebe Buckheister ack_request:1,
11694b4f6c2SPhoebe Buckheister frame_pending:1,
11794b4f6c2SPhoebe Buckheister security_enabled:1,
11894b4f6c2SPhoebe Buckheister type:3,
11994b4f6c2SPhoebe Buckheister source_addr_mode:2,
12094b4f6c2SPhoebe Buckheister version:2,
12194b4f6c2SPhoebe Buckheister dest_addr_mode:2,
12294b4f6c2SPhoebe Buckheister reserved2:2;
12394b4f6c2SPhoebe Buckheister #else
12494b4f6c2SPhoebe Buckheister #error "Please fix <asm/byteorder.h>"
12594b4f6c2SPhoebe Buckheister #endif
12694b4f6c2SPhoebe Buckheister };
12794b4f6c2SPhoebe Buckheister
128ea562d8cSMiquel Raynal enum ieee802154_frame_version {
129ea562d8cSMiquel Raynal IEEE802154_2003_STD,
130ea562d8cSMiquel Raynal IEEE802154_2006_STD,
131ea562d8cSMiquel Raynal IEEE802154_STD,
132ea562d8cSMiquel Raynal IEEE802154_RESERVED_STD,
133ea562d8cSMiquel Raynal IEEE802154_MULTIPURPOSE_STD = IEEE802154_2003_STD,
134ea562d8cSMiquel Raynal };
135ea562d8cSMiquel Raynal
1363accf476SMiquel Raynal enum ieee802154_addressing_mode {
1373accf476SMiquel Raynal IEEE802154_NO_ADDRESSING,
1383accf476SMiquel Raynal IEEE802154_RESERVED,
1393accf476SMiquel Raynal IEEE802154_SHORT_ADDRESSING,
1403accf476SMiquel Raynal IEEE802154_EXTENDED_ADDRESSING,
1413accf476SMiquel Raynal };
1423accf476SMiquel Raynal
14394b4f6c2SPhoebe Buckheister struct ieee802154_hdr {
14494b4f6c2SPhoebe Buckheister struct ieee802154_hdr_fc fc;
14594b4f6c2SPhoebe Buckheister u8 seq;
14694b4f6c2SPhoebe Buckheister struct ieee802154_addr source;
14794b4f6c2SPhoebe Buckheister struct ieee802154_addr dest;
14894b4f6c2SPhoebe Buckheister struct ieee802154_sechdr sec;
14994b4f6c2SPhoebe Buckheister };
15094b4f6c2SPhoebe Buckheister
1513accf476SMiquel Raynal struct ieee802154_beacon_frame {
1523accf476SMiquel Raynal struct ieee802154_hdr mhr;
1533accf476SMiquel Raynal struct ieee802154_beacon_hdr mac_pl;
1543accf476SMiquel Raynal };
1553accf476SMiquel Raynal
156e2c3e6f5SMiquel Raynal struct ieee802154_mac_cmd_frame {
157e2c3e6f5SMiquel Raynal struct ieee802154_hdr mhr;
158e2c3e6f5SMiquel Raynal struct ieee802154_mac_cmd_pl mac_pl;
159e2c3e6f5SMiquel Raynal };
160e2c3e6f5SMiquel Raynal
161e2c3e6f5SMiquel Raynal struct ieee802154_beacon_req_frame {
162e2c3e6f5SMiquel Raynal struct ieee802154_hdr mhr;
163e2c3e6f5SMiquel Raynal struct ieee802154_mac_cmd_pl mac_pl;
164e2c3e6f5SMiquel Raynal };
165e2c3e6f5SMiquel Raynal
16694b4f6c2SPhoebe Buckheister /* pushes hdr onto the skb. fields of hdr->fc that can be calculated from
16794b4f6c2SPhoebe Buckheister * the contents of hdr will be, and the actual value of those bits in
16894b4f6c2SPhoebe Buckheister * hdr->fc will be ignored. this includes the INTRA_PAN bit and the frame
16994b4f6c2SPhoebe Buckheister * version, if SECEN is set.
17094b4f6c2SPhoebe Buckheister */
171a1da67b8SAlexander Aring int ieee802154_hdr_push(struct sk_buff *skb, struct ieee802154_hdr *hdr);
17294b4f6c2SPhoebe Buckheister
17394b4f6c2SPhoebe Buckheister /* pulls the entire 802.15.4 header off of the skb, including the security
17494b4f6c2SPhoebe Buckheister * header, and performs pan id decompression
17594b4f6c2SPhoebe Buckheister */
17694b4f6c2SPhoebe Buckheister int ieee802154_hdr_pull(struct sk_buff *skb, struct ieee802154_hdr *hdr);
17794b4f6c2SPhoebe Buckheister
17894b4f6c2SPhoebe Buckheister /* parses the frame control, sequence number of address fields in a given skb
17994b4f6c2SPhoebe Buckheister * and stores them into hdr, performing pan id decompression and length checks
18094b4f6c2SPhoebe Buckheister * to be suitable for use in header_ops.parse
18194b4f6c2SPhoebe Buckheister */
18294b4f6c2SPhoebe Buckheister int ieee802154_hdr_peek_addrs(const struct sk_buff *skb,
18394b4f6c2SPhoebe Buckheister struct ieee802154_hdr *hdr);
18494b4f6c2SPhoebe Buckheister
185c3a6114fSPhoebe Buckheister /* parses the full 802.15.4 header a given skb and stores them into hdr,
186c3a6114fSPhoebe Buckheister * performing pan id decompression and length checks to be suitable for use in
187c3a6114fSPhoebe Buckheister * header_ops.parse
188c3a6114fSPhoebe Buckheister */
189c3a6114fSPhoebe Buckheister int ieee802154_hdr_peek(const struct sk_buff *skb, struct ieee802154_hdr *hdr);
190c3a6114fSPhoebe Buckheister
191e2c3e6f5SMiquel Raynal /* pushes/pulls various frame types into/from an skb */
1923accf476SMiquel Raynal int ieee802154_beacon_push(struct sk_buff *skb,
1933accf476SMiquel Raynal struct ieee802154_beacon_frame *beacon);
194e2c3e6f5SMiquel Raynal int ieee802154_mac_cmd_push(struct sk_buff *skb, void *frame,
195e2c3e6f5SMiquel Raynal const void *pl, unsigned int pl_len);
196*d021d218SMiquel Raynal int ieee802154_mac_cmd_pl_pull(struct sk_buff *skb,
197*d021d218SMiquel Raynal struct ieee802154_mac_cmd_pl *mac_pl);
1983accf476SMiquel Raynal
199c3a6114fSPhoebe Buckheister int ieee802154_max_payload(const struct ieee802154_hdr *hdr);
200c3a6114fSPhoebe Buckheister
201c3a6114fSPhoebe Buckheister static inline int
ieee802154_sechdr_authtag_len(const struct ieee802154_sechdr * sec)202c3a6114fSPhoebe Buckheister ieee802154_sechdr_authtag_len(const struct ieee802154_sechdr *sec)
203c3a6114fSPhoebe Buckheister {
204c3a6114fSPhoebe Buckheister switch (sec->level) {
205c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_MIC32:
206c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC_MIC32:
207c3a6114fSPhoebe Buckheister return 4;
208c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_MIC64:
209c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC_MIC64:
210c3a6114fSPhoebe Buckheister return 8;
211c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_MIC128:
212c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC_MIC128:
213c3a6114fSPhoebe Buckheister return 16;
214c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_NONE:
215c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC:
216c3a6114fSPhoebe Buckheister default:
217c3a6114fSPhoebe Buckheister return 0;
218c3a6114fSPhoebe Buckheister }
219c3a6114fSPhoebe Buckheister }
220c3a6114fSPhoebe Buckheister
ieee802154_hdr_length(struct sk_buff * skb)22194b4f6c2SPhoebe Buckheister static inline int ieee802154_hdr_length(struct sk_buff *skb)
22294b4f6c2SPhoebe Buckheister {
22394b4f6c2SPhoebe Buckheister struct ieee802154_hdr hdr;
22494b4f6c2SPhoebe Buckheister int len = ieee802154_hdr_pull(skb, &hdr);
22594b4f6c2SPhoebe Buckheister
22694b4f6c2SPhoebe Buckheister if (len > 0)
22794b4f6c2SPhoebe Buckheister skb_push(skb, len);
22894b4f6c2SPhoebe Buckheister
22994b4f6c2SPhoebe Buckheister return len;
23094b4f6c2SPhoebe Buckheister }
23194b4f6c2SPhoebe Buckheister
ieee802154_addr_equal(const struct ieee802154_addr * a1,const struct ieee802154_addr * a2)23246ef0eb3SPhoebe Buckheister static inline bool ieee802154_addr_equal(const struct ieee802154_addr *a1,
23346ef0eb3SPhoebe Buckheister const struct ieee802154_addr *a2)
23446ef0eb3SPhoebe Buckheister {
23546ef0eb3SPhoebe Buckheister if (a1->pan_id != a2->pan_id || a1->mode != a2->mode)
23646ef0eb3SPhoebe Buckheister return false;
23746ef0eb3SPhoebe Buckheister
23846ef0eb3SPhoebe Buckheister if ((a1->mode == IEEE802154_ADDR_LONG &&
23946ef0eb3SPhoebe Buckheister a1->extended_addr != a2->extended_addr) ||
24046ef0eb3SPhoebe Buckheister (a1->mode == IEEE802154_ADDR_SHORT &&
24146ef0eb3SPhoebe Buckheister a1->short_addr != a2->short_addr))
24246ef0eb3SPhoebe Buckheister return false;
24346ef0eb3SPhoebe Buckheister
24446ef0eb3SPhoebe Buckheister return true;
24546ef0eb3SPhoebe Buckheister }
24646ef0eb3SPhoebe Buckheister
ieee802154_devaddr_from_raw(const void * raw)24746ef0eb3SPhoebe Buckheister static inline __le64 ieee802154_devaddr_from_raw(const void *raw)
24846ef0eb3SPhoebe Buckheister {
24946ef0eb3SPhoebe Buckheister u64 temp;
25046ef0eb3SPhoebe Buckheister
25146ef0eb3SPhoebe Buckheister memcpy(&temp, raw, IEEE802154_ADDR_LEN);
25246ef0eb3SPhoebe Buckheister return (__force __le64)swab64(temp);
25346ef0eb3SPhoebe Buckheister }
25446ef0eb3SPhoebe Buckheister
ieee802154_devaddr_to_raw(void * raw,__le64 addr)25546ef0eb3SPhoebe Buckheister static inline void ieee802154_devaddr_to_raw(void *raw, __le64 addr)
25646ef0eb3SPhoebe Buckheister {
25746ef0eb3SPhoebe Buckheister u64 temp = swab64((__force u64)addr);
25846ef0eb3SPhoebe Buckheister
25946ef0eb3SPhoebe Buckheister memcpy(raw, &temp, IEEE802154_ADDR_LEN);
26046ef0eb3SPhoebe Buckheister }
26146ef0eb3SPhoebe Buckheister
26294160108SHaimin Zhang static inline int
ieee802154_sockaddr_check_size(struct sockaddr_ieee802154 * daddr,int len)26394160108SHaimin Zhang ieee802154_sockaddr_check_size(struct sockaddr_ieee802154 *daddr, int len)
26494160108SHaimin Zhang {
26594160108SHaimin Zhang struct ieee802154_addr_sa *sa;
26630393181SAlexander Aring int ret = 0;
26794160108SHaimin Zhang
26894160108SHaimin Zhang sa = &daddr->addr;
26994160108SHaimin Zhang if (len < IEEE802154_MIN_NAMELEN)
27094160108SHaimin Zhang return -EINVAL;
27194160108SHaimin Zhang switch (sa->addr_type) {
27230393181SAlexander Aring case IEEE802154_ADDR_NONE:
27330393181SAlexander Aring break;
27494160108SHaimin Zhang case IEEE802154_ADDR_SHORT:
27594160108SHaimin Zhang if (len < IEEE802154_NAMELEN_SHORT)
27630393181SAlexander Aring ret = -EINVAL;
27794160108SHaimin Zhang break;
27894160108SHaimin Zhang case IEEE802154_ADDR_LONG:
27994160108SHaimin Zhang if (len < IEEE802154_NAMELEN_LONG)
28030393181SAlexander Aring ret = -EINVAL;
28130393181SAlexander Aring break;
28230393181SAlexander Aring default:
28330393181SAlexander Aring ret = -EINVAL;
28494160108SHaimin Zhang break;
28594160108SHaimin Zhang }
28630393181SAlexander Aring return ret;
28794160108SHaimin Zhang }
28894160108SHaimin Zhang
ieee802154_addr_from_sa(struct ieee802154_addr * a,const struct ieee802154_addr_sa * sa)28946ef0eb3SPhoebe Buckheister static inline void ieee802154_addr_from_sa(struct ieee802154_addr *a,
29046ef0eb3SPhoebe Buckheister const struct ieee802154_addr_sa *sa)
29146ef0eb3SPhoebe Buckheister {
29246ef0eb3SPhoebe Buckheister a->mode = sa->addr_type;
29346ef0eb3SPhoebe Buckheister a->pan_id = cpu_to_le16(sa->pan_id);
29446ef0eb3SPhoebe Buckheister
29546ef0eb3SPhoebe Buckheister switch (a->mode) {
29646ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_SHORT:
29746ef0eb3SPhoebe Buckheister a->short_addr = cpu_to_le16(sa->short_addr);
29846ef0eb3SPhoebe Buckheister break;
29946ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_LONG:
30046ef0eb3SPhoebe Buckheister a->extended_addr = ieee802154_devaddr_from_raw(sa->hwaddr);
30146ef0eb3SPhoebe Buckheister break;
30246ef0eb3SPhoebe Buckheister }
30346ef0eb3SPhoebe Buckheister }
30446ef0eb3SPhoebe Buckheister
ieee802154_addr_to_sa(struct ieee802154_addr_sa * sa,const struct ieee802154_addr * a)30546ef0eb3SPhoebe Buckheister static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa,
30646ef0eb3SPhoebe Buckheister const struct ieee802154_addr *a)
30746ef0eb3SPhoebe Buckheister {
30846ef0eb3SPhoebe Buckheister sa->addr_type = a->mode;
30946ef0eb3SPhoebe Buckheister sa->pan_id = le16_to_cpu(a->pan_id);
31046ef0eb3SPhoebe Buckheister
31146ef0eb3SPhoebe Buckheister switch (a->mode) {
31246ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_SHORT:
31346ef0eb3SPhoebe Buckheister sa->short_addr = le16_to_cpu(a->short_addr);
31446ef0eb3SPhoebe Buckheister break;
31546ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_LONG:
31646ef0eb3SPhoebe Buckheister ieee802154_devaddr_to_raw(sa->hwaddr, a->extended_addr);
31746ef0eb3SPhoebe Buckheister break;
31846ef0eb3SPhoebe Buckheister }
31946ef0eb3SPhoebe Buckheister }
32046ef0eb3SPhoebe Buckheister
321f0166e5eSDmitry Eremin-Solenikov /*
322f0166e5eSDmitry Eremin-Solenikov * A control block of skb passed between the ARPHRD_IEEE802154 device
323f0166e5eSDmitry Eremin-Solenikov * and other stack parts.
324f0166e5eSDmitry Eremin-Solenikov */
325f0166e5eSDmitry Eremin-Solenikov struct ieee802154_mac_cb {
326f0166e5eSDmitry Eremin-Solenikov u8 lqi;
32732edc40aSPhoebe Buckheister u8 type;
32832edc40aSPhoebe Buckheister bool ackreq;
32932edc40aSPhoebe Buckheister bool secen;
330f30be4d5SPhoebe Buckheister bool secen_override;
331f30be4d5SPhoebe Buckheister u8 seclevel;
332f30be4d5SPhoebe Buckheister bool seclevel_override;
333ae531b94SPhoebe Buckheister struct ieee802154_addr source;
334ae531b94SPhoebe Buckheister struct ieee802154_addr dest;
335f0166e5eSDmitry Eremin-Solenikov };
336f0166e5eSDmitry Eremin-Solenikov
mac_cb(struct sk_buff * skb)337f0166e5eSDmitry Eremin-Solenikov static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
338f0166e5eSDmitry Eremin-Solenikov {
339f0166e5eSDmitry Eremin-Solenikov return (struct ieee802154_mac_cb *)skb->cb;
340f0166e5eSDmitry Eremin-Solenikov }
341f0166e5eSDmitry Eremin-Solenikov
mac_cb_init(struct sk_buff * skb)34232edc40aSPhoebe Buckheister static inline struct ieee802154_mac_cb *mac_cb_init(struct sk_buff *skb)
343f0166e5eSDmitry Eremin-Solenikov {
34432edc40aSPhoebe Buckheister BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb) > sizeof(skb->cb));
345f0166e5eSDmitry Eremin-Solenikov
34632edc40aSPhoebe Buckheister memset(skb->cb, 0, sizeof(struct ieee802154_mac_cb));
34732edc40aSPhoebe Buckheister return mac_cb(skb);
348f0166e5eSDmitry Eremin-Solenikov }
349f0166e5eSDmitry Eremin-Solenikov
350dc20759fSPhoebe Buckheister enum {
351dc20759fSPhoebe Buckheister IEEE802154_LLSEC_DEVKEY_IGNORE,
352dc20759fSPhoebe Buckheister IEEE802154_LLSEC_DEVKEY_RESTRICT,
353f0f77dc6SPhoebe Buckheister IEEE802154_LLSEC_DEVKEY_RECORD,
354dc20759fSPhoebe Buckheister
355dc20759fSPhoebe Buckheister __IEEE802154_LLSEC_DEVKEY_MAX,
356dc20759fSPhoebe Buckheister };
357dc20759fSPhoebe Buckheister
358f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_ED 0
359f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_ACTIVE 1
360f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_PASSIVE 2
361f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_ORPHAN 3
362f0166e5eSDmitry Eremin-Solenikov
363e462ded6SPhoebe Buckheister struct ieee802154_mac_params {
364e462ded6SPhoebe Buckheister s8 transmit_power;
365e462ded6SPhoebe Buckheister u8 min_be;
366e462ded6SPhoebe Buckheister u8 max_be;
367e462ded6SPhoebe Buckheister u8 csma_retries;
368e462ded6SPhoebe Buckheister s8 frame_retries;
369e462ded6SPhoebe Buckheister
370e462ded6SPhoebe Buckheister bool lbt;
3717fe9a388SAlexander Aring struct wpan_phy_cca cca;
372e462ded6SPhoebe Buckheister s32 cca_ed_level;
373e462ded6SPhoebe Buckheister };
374e462ded6SPhoebe Buckheister
37542723448SDmitry Eremin-Solenikov struct wpan_phy;
376dc20759fSPhoebe Buckheister
377dc20759fSPhoebe Buckheister enum {
378fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_ENABLED = BIT(0),
379fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_FRAME_COUNTER = BIT(1),
380fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_OUT_LEVEL = BIT(2),
381fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_OUT_KEY = BIT(3),
382fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_KEY_SOURCE = BIT(4),
383fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_PAN_ID = BIT(5),
384fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_HWADDR = BIT(6),
385fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_COORD_HWADDR = BIT(7),
386fe89e690SVarka Bhadram IEEE802154_LLSEC_PARAM_COORD_SHORTADDR = BIT(8),
387dc20759fSPhoebe Buckheister };
388dc20759fSPhoebe Buckheister
38929e02374SPhoebe Buckheister struct ieee802154_llsec_ops {
39029e02374SPhoebe Buckheister int (*get_params)(struct net_device *dev,
39129e02374SPhoebe Buckheister struct ieee802154_llsec_params *params);
39229e02374SPhoebe Buckheister int (*set_params)(struct net_device *dev,
39329e02374SPhoebe Buckheister const struct ieee802154_llsec_params *params,
39429e02374SPhoebe Buckheister int changed);
39529e02374SPhoebe Buckheister
39629e02374SPhoebe Buckheister int (*add_key)(struct net_device *dev,
39729e02374SPhoebe Buckheister const struct ieee802154_llsec_key_id *id,
39829e02374SPhoebe Buckheister const struct ieee802154_llsec_key *key);
39929e02374SPhoebe Buckheister int (*del_key)(struct net_device *dev,
40029e02374SPhoebe Buckheister const struct ieee802154_llsec_key_id *id);
40129e02374SPhoebe Buckheister
40229e02374SPhoebe Buckheister int (*add_dev)(struct net_device *dev,
40329e02374SPhoebe Buckheister const struct ieee802154_llsec_device *llsec_dev);
40429e02374SPhoebe Buckheister int (*del_dev)(struct net_device *dev, __le64 dev_addr);
40529e02374SPhoebe Buckheister
40629e02374SPhoebe Buckheister int (*add_devkey)(struct net_device *dev,
40729e02374SPhoebe Buckheister __le64 device_addr,
40829e02374SPhoebe Buckheister const struct ieee802154_llsec_device_key *key);
40929e02374SPhoebe Buckheister int (*del_devkey)(struct net_device *dev,
41029e02374SPhoebe Buckheister __le64 device_addr,
41129e02374SPhoebe Buckheister const struct ieee802154_llsec_device_key *key);
41229e02374SPhoebe Buckheister
41329e02374SPhoebe Buckheister int (*add_seclevel)(struct net_device *dev,
41429e02374SPhoebe Buckheister const struct ieee802154_llsec_seclevel *sl);
41529e02374SPhoebe Buckheister int (*del_seclevel)(struct net_device *dev,
41629e02374SPhoebe Buckheister const struct ieee802154_llsec_seclevel *sl);
41729e02374SPhoebe Buckheister
41829e02374SPhoebe Buckheister void (*lock_table)(struct net_device *dev);
41929e02374SPhoebe Buckheister void (*get_table)(struct net_device *dev,
42029e02374SPhoebe Buckheister struct ieee802154_llsec_table **t);
42129e02374SPhoebe Buckheister void (*unlock_table)(struct net_device *dev);
42229e02374SPhoebe Buckheister };
423f0166e5eSDmitry Eremin-Solenikov /*
424f0166e5eSDmitry Eremin-Solenikov * This should be located at net_device->ml_priv
42542723448SDmitry Eremin-Solenikov *
42642723448SDmitry Eremin-Solenikov * get_phy should increment the reference counting on returned phy.
42742723448SDmitry Eremin-Solenikov * Use wpan_wpy_put to put that reference.
428f0166e5eSDmitry Eremin-Solenikov */
429f0166e5eSDmitry Eremin-Solenikov struct ieee802154_mlme_ops {
43056aa091dSWerner Almesberger /* The following fields are optional (can be NULL). */
43156aa091dSWerner Almesberger
432f0166e5eSDmitry Eremin-Solenikov int (*assoc_req)(struct net_device *dev,
433ae531b94SPhoebe Buckheister struct ieee802154_addr *addr,
43416eea493SDmitry Eremin-Solenikov u8 channel, u8 page, u8 cap);
435f0166e5eSDmitry Eremin-Solenikov int (*assoc_resp)(struct net_device *dev,
436ae531b94SPhoebe Buckheister struct ieee802154_addr *addr,
437b70ab2e8SPhoebe Buckheister __le16 short_addr, u8 status);
438f0166e5eSDmitry Eremin-Solenikov int (*disassoc_req)(struct net_device *dev,
439ae531b94SPhoebe Buckheister struct ieee802154_addr *addr,
440f0166e5eSDmitry Eremin-Solenikov u8 reason);
441f0166e5eSDmitry Eremin-Solenikov int (*start_req)(struct net_device *dev,
442ae531b94SPhoebe Buckheister struct ieee802154_addr *addr,
44316eea493SDmitry Eremin-Solenikov u8 channel, u8 page, u8 bcn_ord, u8 sf_ord,
444f0166e5eSDmitry Eremin-Solenikov u8 pan_coord, u8 blx, u8 coord_realign);
445f0166e5eSDmitry Eremin-Solenikov int (*scan_req)(struct net_device *dev,
44616eea493SDmitry Eremin-Solenikov u8 type, u32 channels, u8 page, u8 duration);
447f0166e5eSDmitry Eremin-Solenikov
448e462ded6SPhoebe Buckheister int (*set_mac_params)(struct net_device *dev,
449e462ded6SPhoebe Buckheister const struct ieee802154_mac_params *params);
450e462ded6SPhoebe Buckheister void (*get_mac_params)(struct net_device *dev,
451e462ded6SPhoebe Buckheister struct ieee802154_mac_params *params);
452e462ded6SPhoebe Buckheister
45329663b0cSJulia Lawall const struct ieee802154_llsec_ops *llsec;
454f0166e5eSDmitry Eremin-Solenikov };
455f0166e5eSDmitry Eremin-Solenikov
45674a02fcfSalex.bluesman.smirnov@gmail.com static inline struct ieee802154_mlme_ops *
ieee802154_mlme_ops(const struct net_device * dev)45774a02fcfSalex.bluesman.smirnov@gmail.com ieee802154_mlme_ops(const struct net_device *dev)
45874a02fcfSalex.bluesman.smirnov@gmail.com {
45974a02fcfSalex.bluesman.smirnov@gmail.com return dev->ml_priv;
46074a02fcfSalex.bluesman.smirnov@gmail.com }
46174a02fcfSalex.bluesman.smirnov@gmail.com
462f0166e5eSDmitry Eremin-Solenikov #endif
463