1f0166e5eSDmitry Eremin-Solenikov /* 2f0166e5eSDmitry Eremin-Solenikov * An interface between IEEE802.15.4 device and rest of the kernel. 3f0166e5eSDmitry Eremin-Solenikov * 474a02fcfSalex.bluesman.smirnov@gmail.com * Copyright (C) 2007-2012 Siemens AG 5f0166e5eSDmitry Eremin-Solenikov * 6f0166e5eSDmitry Eremin-Solenikov * This program is free software; you can redistribute it and/or modify 7f0166e5eSDmitry Eremin-Solenikov * it under the terms of the GNU General Public License version 2 8f0166e5eSDmitry Eremin-Solenikov * as published by the Free Software Foundation. 9f0166e5eSDmitry Eremin-Solenikov * 10f0166e5eSDmitry Eremin-Solenikov * This program is distributed in the hope that it will be useful, 11f0166e5eSDmitry Eremin-Solenikov * but WITHOUT ANY WARRANTY; without even the implied warranty of 12f0166e5eSDmitry Eremin-Solenikov * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13f0166e5eSDmitry Eremin-Solenikov * GNU General Public License for more details. 14f0166e5eSDmitry Eremin-Solenikov * 15f0166e5eSDmitry Eremin-Solenikov * Written by: 16f0166e5eSDmitry Eremin-Solenikov * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 17f0166e5eSDmitry Eremin-Solenikov * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 18f0166e5eSDmitry Eremin-Solenikov * Maxim Osipov <maxim.osipov@siemens.com> 19f0166e5eSDmitry Eremin-Solenikov * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 2074a02fcfSalex.bluesman.smirnov@gmail.com * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 21f0166e5eSDmitry Eremin-Solenikov */ 22f0166e5eSDmitry Eremin-Solenikov 23f0166e5eSDmitry Eremin-Solenikov #ifndef IEEE802154_NETDEVICE_H 24f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_NETDEVICE_H 25f0166e5eSDmitry Eremin-Solenikov 261cd829c8Salex.bluesman.smirnov@gmail.com #include <net/af_ieee802154.h> 2794b4f6c2SPhoebe Buckheister #include <linux/netdevice.h> 2894b4f6c2SPhoebe Buckheister #include <linux/skbuff.h> 29*4ca24acaSAlexander Aring #include <linux/ieee802154.h> 3094b4f6c2SPhoebe Buckheister 3194b4f6c2SPhoebe Buckheister struct ieee802154_sechdr { 3294b4f6c2SPhoebe Buckheister #if defined(__LITTLE_ENDIAN_BITFIELD) 3394b4f6c2SPhoebe Buckheister u8 level:3, 3494b4f6c2SPhoebe Buckheister key_id_mode:2, 3594b4f6c2SPhoebe Buckheister reserved:3; 3694b4f6c2SPhoebe Buckheister #elif defined(__BIG_ENDIAN_BITFIELD) 3794b4f6c2SPhoebe Buckheister u8 reserved:3, 3894b4f6c2SPhoebe Buckheister key_id_mode:2, 3994b4f6c2SPhoebe Buckheister level:3; 4094b4f6c2SPhoebe Buckheister #else 4194b4f6c2SPhoebe Buckheister #error "Please fix <asm/byteorder.h>" 4294b4f6c2SPhoebe Buckheister #endif 4394b4f6c2SPhoebe Buckheister u8 key_id; 4494b4f6c2SPhoebe Buckheister __le32 frame_counter; 4594b4f6c2SPhoebe Buckheister union { 4694b4f6c2SPhoebe Buckheister __le32 short_src; 4794b4f6c2SPhoebe Buckheister __le64 extended_src; 4894b4f6c2SPhoebe Buckheister }; 4994b4f6c2SPhoebe Buckheister }; 501cd829c8Salex.bluesman.smirnov@gmail.com 5146ef0eb3SPhoebe Buckheister struct ieee802154_addr { 5246ef0eb3SPhoebe Buckheister u8 mode; 5346ef0eb3SPhoebe Buckheister __le16 pan_id; 5446ef0eb3SPhoebe Buckheister union { 5546ef0eb3SPhoebe Buckheister __le16 short_addr; 5646ef0eb3SPhoebe Buckheister __le64 extended_addr; 5746ef0eb3SPhoebe Buckheister }; 5846ef0eb3SPhoebe Buckheister }; 5946ef0eb3SPhoebe Buckheister 6094b4f6c2SPhoebe Buckheister struct ieee802154_hdr_fc { 6194b4f6c2SPhoebe Buckheister #if defined(__LITTLE_ENDIAN_BITFIELD) 6294b4f6c2SPhoebe Buckheister u16 type:3, 6394b4f6c2SPhoebe Buckheister security_enabled:1, 6494b4f6c2SPhoebe Buckheister frame_pending:1, 6594b4f6c2SPhoebe Buckheister ack_request:1, 6694b4f6c2SPhoebe Buckheister intra_pan:1, 6794b4f6c2SPhoebe Buckheister reserved:3, 6894b4f6c2SPhoebe Buckheister dest_addr_mode:2, 6994b4f6c2SPhoebe Buckheister version:2, 7094b4f6c2SPhoebe Buckheister source_addr_mode:2; 7194b4f6c2SPhoebe Buckheister #elif defined(__BIG_ENDIAN_BITFIELD) 7294b4f6c2SPhoebe Buckheister u16 reserved:1, 7394b4f6c2SPhoebe Buckheister intra_pan:1, 7494b4f6c2SPhoebe Buckheister ack_request:1, 7594b4f6c2SPhoebe Buckheister frame_pending:1, 7694b4f6c2SPhoebe Buckheister security_enabled:1, 7794b4f6c2SPhoebe Buckheister type:3, 7894b4f6c2SPhoebe Buckheister source_addr_mode:2, 7994b4f6c2SPhoebe Buckheister version:2, 8094b4f6c2SPhoebe Buckheister dest_addr_mode:2, 8194b4f6c2SPhoebe Buckheister reserved2:2; 8294b4f6c2SPhoebe Buckheister #else 8394b4f6c2SPhoebe Buckheister #error "Please fix <asm/byteorder.h>" 8494b4f6c2SPhoebe Buckheister #endif 8594b4f6c2SPhoebe Buckheister }; 8694b4f6c2SPhoebe Buckheister 8794b4f6c2SPhoebe Buckheister struct ieee802154_hdr { 8894b4f6c2SPhoebe Buckheister struct ieee802154_hdr_fc fc; 8994b4f6c2SPhoebe Buckheister u8 seq; 9094b4f6c2SPhoebe Buckheister struct ieee802154_addr source; 9194b4f6c2SPhoebe Buckheister struct ieee802154_addr dest; 9294b4f6c2SPhoebe Buckheister struct ieee802154_sechdr sec; 9394b4f6c2SPhoebe Buckheister }; 9494b4f6c2SPhoebe Buckheister 9594b4f6c2SPhoebe Buckheister /* pushes hdr onto the skb. fields of hdr->fc that can be calculated from 9694b4f6c2SPhoebe Buckheister * the contents of hdr will be, and the actual value of those bits in 9794b4f6c2SPhoebe Buckheister * hdr->fc will be ignored. this includes the INTRA_PAN bit and the frame 9894b4f6c2SPhoebe Buckheister * version, if SECEN is set. 9994b4f6c2SPhoebe Buckheister */ 10094b4f6c2SPhoebe Buckheister int ieee802154_hdr_push(struct sk_buff *skb, const struct ieee802154_hdr *hdr); 10194b4f6c2SPhoebe Buckheister 10294b4f6c2SPhoebe Buckheister /* pulls the entire 802.15.4 header off of the skb, including the security 10394b4f6c2SPhoebe Buckheister * header, and performs pan id decompression 10494b4f6c2SPhoebe Buckheister */ 10594b4f6c2SPhoebe Buckheister int ieee802154_hdr_pull(struct sk_buff *skb, struct ieee802154_hdr *hdr); 10694b4f6c2SPhoebe Buckheister 10794b4f6c2SPhoebe Buckheister /* parses the frame control, sequence number of address fields in a given skb 10894b4f6c2SPhoebe Buckheister * and stores them into hdr, performing pan id decompression and length checks 10994b4f6c2SPhoebe Buckheister * to be suitable for use in header_ops.parse 11094b4f6c2SPhoebe Buckheister */ 11194b4f6c2SPhoebe Buckheister int ieee802154_hdr_peek_addrs(const struct sk_buff *skb, 11294b4f6c2SPhoebe Buckheister struct ieee802154_hdr *hdr); 11394b4f6c2SPhoebe Buckheister 114c3a6114fSPhoebe Buckheister /* parses the full 802.15.4 header a given skb and stores them into hdr, 115c3a6114fSPhoebe Buckheister * performing pan id decompression and length checks to be suitable for use in 116c3a6114fSPhoebe Buckheister * header_ops.parse 117c3a6114fSPhoebe Buckheister */ 118c3a6114fSPhoebe Buckheister int ieee802154_hdr_peek(const struct sk_buff *skb, struct ieee802154_hdr *hdr); 119c3a6114fSPhoebe Buckheister 120c3a6114fSPhoebe Buckheister int ieee802154_max_payload(const struct ieee802154_hdr *hdr); 121c3a6114fSPhoebe Buckheister 122c3a6114fSPhoebe Buckheister static inline int 123c3a6114fSPhoebe Buckheister ieee802154_sechdr_authtag_len(const struct ieee802154_sechdr *sec) 124c3a6114fSPhoebe Buckheister { 125c3a6114fSPhoebe Buckheister switch (sec->level) { 126c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_MIC32: 127c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC_MIC32: 128c3a6114fSPhoebe Buckheister return 4; 129c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_MIC64: 130c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC_MIC64: 131c3a6114fSPhoebe Buckheister return 8; 132c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_MIC128: 133c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC_MIC128: 134c3a6114fSPhoebe Buckheister return 16; 135c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_NONE: 136c3a6114fSPhoebe Buckheister case IEEE802154_SCF_SECLEVEL_ENC: 137c3a6114fSPhoebe Buckheister default: 138c3a6114fSPhoebe Buckheister return 0; 139c3a6114fSPhoebe Buckheister } 140c3a6114fSPhoebe Buckheister } 141c3a6114fSPhoebe Buckheister 14294b4f6c2SPhoebe Buckheister static inline int ieee802154_hdr_length(struct sk_buff *skb) 14394b4f6c2SPhoebe Buckheister { 14494b4f6c2SPhoebe Buckheister struct ieee802154_hdr hdr; 14594b4f6c2SPhoebe Buckheister int len = ieee802154_hdr_pull(skb, &hdr); 14694b4f6c2SPhoebe Buckheister 14794b4f6c2SPhoebe Buckheister if (len > 0) 14894b4f6c2SPhoebe Buckheister skb_push(skb, len); 14994b4f6c2SPhoebe Buckheister 15094b4f6c2SPhoebe Buckheister return len; 15194b4f6c2SPhoebe Buckheister } 15294b4f6c2SPhoebe Buckheister 15346ef0eb3SPhoebe Buckheister static inline bool ieee802154_addr_equal(const struct ieee802154_addr *a1, 15446ef0eb3SPhoebe Buckheister const struct ieee802154_addr *a2) 15546ef0eb3SPhoebe Buckheister { 15646ef0eb3SPhoebe Buckheister if (a1->pan_id != a2->pan_id || a1->mode != a2->mode) 15746ef0eb3SPhoebe Buckheister return false; 15846ef0eb3SPhoebe Buckheister 15946ef0eb3SPhoebe Buckheister if ((a1->mode == IEEE802154_ADDR_LONG && 16046ef0eb3SPhoebe Buckheister a1->extended_addr != a2->extended_addr) || 16146ef0eb3SPhoebe Buckheister (a1->mode == IEEE802154_ADDR_SHORT && 16246ef0eb3SPhoebe Buckheister a1->short_addr != a2->short_addr)) 16346ef0eb3SPhoebe Buckheister return false; 16446ef0eb3SPhoebe Buckheister 16546ef0eb3SPhoebe Buckheister return true; 16646ef0eb3SPhoebe Buckheister } 16746ef0eb3SPhoebe Buckheister 16846ef0eb3SPhoebe Buckheister static inline __le64 ieee802154_devaddr_from_raw(const void *raw) 16946ef0eb3SPhoebe Buckheister { 17046ef0eb3SPhoebe Buckheister u64 temp; 17146ef0eb3SPhoebe Buckheister 17246ef0eb3SPhoebe Buckheister memcpy(&temp, raw, IEEE802154_ADDR_LEN); 17346ef0eb3SPhoebe Buckheister return (__force __le64)swab64(temp); 17446ef0eb3SPhoebe Buckheister } 17546ef0eb3SPhoebe Buckheister 17646ef0eb3SPhoebe Buckheister static inline void ieee802154_devaddr_to_raw(void *raw, __le64 addr) 17746ef0eb3SPhoebe Buckheister { 17846ef0eb3SPhoebe Buckheister u64 temp = swab64((__force u64)addr); 17946ef0eb3SPhoebe Buckheister 18046ef0eb3SPhoebe Buckheister memcpy(raw, &temp, IEEE802154_ADDR_LEN); 18146ef0eb3SPhoebe Buckheister } 18246ef0eb3SPhoebe Buckheister 18346ef0eb3SPhoebe Buckheister static inline void ieee802154_addr_from_sa(struct ieee802154_addr *a, 18446ef0eb3SPhoebe Buckheister const struct ieee802154_addr_sa *sa) 18546ef0eb3SPhoebe Buckheister { 18646ef0eb3SPhoebe Buckheister a->mode = sa->addr_type; 18746ef0eb3SPhoebe Buckheister a->pan_id = cpu_to_le16(sa->pan_id); 18846ef0eb3SPhoebe Buckheister 18946ef0eb3SPhoebe Buckheister switch (a->mode) { 19046ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_SHORT: 19146ef0eb3SPhoebe Buckheister a->short_addr = cpu_to_le16(sa->short_addr); 19246ef0eb3SPhoebe Buckheister break; 19346ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_LONG: 19446ef0eb3SPhoebe Buckheister a->extended_addr = ieee802154_devaddr_from_raw(sa->hwaddr); 19546ef0eb3SPhoebe Buckheister break; 19646ef0eb3SPhoebe Buckheister } 19746ef0eb3SPhoebe Buckheister } 19846ef0eb3SPhoebe Buckheister 19946ef0eb3SPhoebe Buckheister static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa, 20046ef0eb3SPhoebe Buckheister const struct ieee802154_addr *a) 20146ef0eb3SPhoebe Buckheister { 20246ef0eb3SPhoebe Buckheister sa->addr_type = a->mode; 20346ef0eb3SPhoebe Buckheister sa->pan_id = le16_to_cpu(a->pan_id); 20446ef0eb3SPhoebe Buckheister 20546ef0eb3SPhoebe Buckheister switch (a->mode) { 20646ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_SHORT: 20746ef0eb3SPhoebe Buckheister sa->short_addr = le16_to_cpu(a->short_addr); 20846ef0eb3SPhoebe Buckheister break; 20946ef0eb3SPhoebe Buckheister case IEEE802154_ADDR_LONG: 21046ef0eb3SPhoebe Buckheister ieee802154_devaddr_to_raw(sa->hwaddr, a->extended_addr); 21146ef0eb3SPhoebe Buckheister break; 21246ef0eb3SPhoebe Buckheister } 21346ef0eb3SPhoebe Buckheister } 21446ef0eb3SPhoebe Buckheister 215f0166e5eSDmitry Eremin-Solenikov /* 216f0166e5eSDmitry Eremin-Solenikov * A control block of skb passed between the ARPHRD_IEEE802154 device 217f0166e5eSDmitry Eremin-Solenikov * and other stack parts. 218f0166e5eSDmitry Eremin-Solenikov */ 219f0166e5eSDmitry Eremin-Solenikov struct ieee802154_mac_cb { 220f0166e5eSDmitry Eremin-Solenikov u8 lqi; 22132edc40aSPhoebe Buckheister u8 type; 22232edc40aSPhoebe Buckheister bool ackreq; 22332edc40aSPhoebe Buckheister bool secen; 224f30be4d5SPhoebe Buckheister bool secen_override; 225f30be4d5SPhoebe Buckheister u8 seclevel; 226f30be4d5SPhoebe Buckheister bool seclevel_override; 227ae531b94SPhoebe Buckheister struct ieee802154_addr source; 228ae531b94SPhoebe Buckheister struct ieee802154_addr dest; 229f0166e5eSDmitry Eremin-Solenikov }; 230f0166e5eSDmitry Eremin-Solenikov 231f0166e5eSDmitry Eremin-Solenikov static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb) 232f0166e5eSDmitry Eremin-Solenikov { 233f0166e5eSDmitry Eremin-Solenikov return (struct ieee802154_mac_cb *)skb->cb; 234f0166e5eSDmitry Eremin-Solenikov } 235f0166e5eSDmitry Eremin-Solenikov 23632edc40aSPhoebe Buckheister static inline struct ieee802154_mac_cb *mac_cb_init(struct sk_buff *skb) 237f0166e5eSDmitry Eremin-Solenikov { 23832edc40aSPhoebe Buckheister BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb) > sizeof(skb->cb)); 239f0166e5eSDmitry Eremin-Solenikov 24032edc40aSPhoebe Buckheister memset(skb->cb, 0, sizeof(struct ieee802154_mac_cb)); 24132edc40aSPhoebe Buckheister return mac_cb(skb); 242f0166e5eSDmitry Eremin-Solenikov } 243f0166e5eSDmitry Eremin-Solenikov 244dc20759fSPhoebe Buckheister #define IEEE802154_LLSEC_KEY_SIZE 16 245dc20759fSPhoebe Buckheister 246dc20759fSPhoebe Buckheister struct ieee802154_llsec_key_id { 247dc20759fSPhoebe Buckheister u8 mode; 248dc20759fSPhoebe Buckheister u8 id; 249dc20759fSPhoebe Buckheister union { 250dc20759fSPhoebe Buckheister struct ieee802154_addr device_addr; 251dc20759fSPhoebe Buckheister __le32 short_source; 252dc20759fSPhoebe Buckheister __le64 extended_source; 253dc20759fSPhoebe Buckheister }; 254dc20759fSPhoebe Buckheister }; 255dc20759fSPhoebe Buckheister 256dc20759fSPhoebe Buckheister struct ieee802154_llsec_key { 257dc20759fSPhoebe Buckheister u8 frame_types; 258dc20759fSPhoebe Buckheister u32 cmd_frame_ids; 259dc20759fSPhoebe Buckheister u8 key[IEEE802154_LLSEC_KEY_SIZE]; 260dc20759fSPhoebe Buckheister }; 261dc20759fSPhoebe Buckheister 262dc20759fSPhoebe Buckheister struct ieee802154_llsec_key_entry { 263dc20759fSPhoebe Buckheister struct list_head list; 264dc20759fSPhoebe Buckheister 265dc20759fSPhoebe Buckheister struct ieee802154_llsec_key_id id; 266dc20759fSPhoebe Buckheister struct ieee802154_llsec_key *key; 267dc20759fSPhoebe Buckheister }; 268dc20759fSPhoebe Buckheister 269dc20759fSPhoebe Buckheister struct ieee802154_llsec_device_key { 270dc20759fSPhoebe Buckheister struct list_head list; 271dc20759fSPhoebe Buckheister 272dc20759fSPhoebe Buckheister struct ieee802154_llsec_key_id key_id; 273dc20759fSPhoebe Buckheister u32 frame_counter; 274dc20759fSPhoebe Buckheister }; 275dc20759fSPhoebe Buckheister 276dc20759fSPhoebe Buckheister enum { 277dc20759fSPhoebe Buckheister IEEE802154_LLSEC_DEVKEY_IGNORE, 278dc20759fSPhoebe Buckheister IEEE802154_LLSEC_DEVKEY_RESTRICT, 279f0f77dc6SPhoebe Buckheister IEEE802154_LLSEC_DEVKEY_RECORD, 280dc20759fSPhoebe Buckheister 281dc20759fSPhoebe Buckheister __IEEE802154_LLSEC_DEVKEY_MAX, 282dc20759fSPhoebe Buckheister }; 283dc20759fSPhoebe Buckheister 284dc20759fSPhoebe Buckheister struct ieee802154_llsec_device { 285dc20759fSPhoebe Buckheister struct list_head list; 286dc20759fSPhoebe Buckheister 287dc20759fSPhoebe Buckheister __le16 pan_id; 288dc20759fSPhoebe Buckheister __le16 short_addr; 289dc20759fSPhoebe Buckheister __le64 hwaddr; 290dc20759fSPhoebe Buckheister u32 frame_counter; 291dc20759fSPhoebe Buckheister bool seclevel_exempt; 292dc20759fSPhoebe Buckheister 293dc20759fSPhoebe Buckheister u8 key_mode; 294dc20759fSPhoebe Buckheister struct list_head keys; 295dc20759fSPhoebe Buckheister }; 296dc20759fSPhoebe Buckheister 297dc20759fSPhoebe Buckheister struct ieee802154_llsec_seclevel { 298dc20759fSPhoebe Buckheister struct list_head list; 299dc20759fSPhoebe Buckheister 300dc20759fSPhoebe Buckheister u8 frame_type; 301dc20759fSPhoebe Buckheister u8 cmd_frame_id; 302dc20759fSPhoebe Buckheister bool device_override; 303dc20759fSPhoebe Buckheister u32 sec_levels; 304dc20759fSPhoebe Buckheister }; 305dc20759fSPhoebe Buckheister 306dc20759fSPhoebe Buckheister struct ieee802154_llsec_params { 307dc20759fSPhoebe Buckheister bool enabled; 308dc20759fSPhoebe Buckheister 309dc20759fSPhoebe Buckheister __be32 frame_counter; 310dc20759fSPhoebe Buckheister u8 out_level; 311dc20759fSPhoebe Buckheister struct ieee802154_llsec_key_id out_key; 312dc20759fSPhoebe Buckheister 313dc20759fSPhoebe Buckheister __le64 default_key_source; 314dc20759fSPhoebe Buckheister 315dc20759fSPhoebe Buckheister __le16 pan_id; 316dc20759fSPhoebe Buckheister __le64 hwaddr; 317dc20759fSPhoebe Buckheister __le64 coord_hwaddr; 318dc20759fSPhoebe Buckheister __le16 coord_shortaddr; 319dc20759fSPhoebe Buckheister }; 320dc20759fSPhoebe Buckheister 321dc20759fSPhoebe Buckheister struct ieee802154_llsec_table { 322dc20759fSPhoebe Buckheister struct list_head keys; 323dc20759fSPhoebe Buckheister struct list_head devices; 324dc20759fSPhoebe Buckheister struct list_head security_levels; 325dc20759fSPhoebe Buckheister }; 326dc20759fSPhoebe Buckheister 327f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_ED 0 328f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_ACTIVE 1 329f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_PASSIVE 2 330f0166e5eSDmitry Eremin-Solenikov #define IEEE802154_MAC_SCAN_ORPHAN 3 331f0166e5eSDmitry Eremin-Solenikov 332e462ded6SPhoebe Buckheister struct ieee802154_mac_params { 333e462ded6SPhoebe Buckheister s8 transmit_power; 334e462ded6SPhoebe Buckheister u8 min_be; 335e462ded6SPhoebe Buckheister u8 max_be; 336e462ded6SPhoebe Buckheister u8 csma_retries; 337e462ded6SPhoebe Buckheister s8 frame_retries; 338e462ded6SPhoebe Buckheister 339e462ded6SPhoebe Buckheister bool lbt; 340e462ded6SPhoebe Buckheister u8 cca_mode; 341e462ded6SPhoebe Buckheister s32 cca_ed_level; 342e462ded6SPhoebe Buckheister }; 343e462ded6SPhoebe Buckheister 34442723448SDmitry Eremin-Solenikov struct wpan_phy; 345dc20759fSPhoebe Buckheister 346dc20759fSPhoebe Buckheister enum { 347dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_ENABLED = 1 << 0, 348dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_FRAME_COUNTER = 1 << 1, 349dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_OUT_LEVEL = 1 << 2, 350dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_OUT_KEY = 1 << 3, 351dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_KEY_SOURCE = 1 << 4, 352dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_PAN_ID = 1 << 5, 353dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_HWADDR = 1 << 6, 354dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_COORD_HWADDR = 1 << 7, 355dc20759fSPhoebe Buckheister IEEE802154_LLSEC_PARAM_COORD_SHORTADDR = 1 << 8, 356dc20759fSPhoebe Buckheister }; 357dc20759fSPhoebe Buckheister 35829e02374SPhoebe Buckheister struct ieee802154_llsec_ops { 35929e02374SPhoebe Buckheister int (*get_params)(struct net_device *dev, 36029e02374SPhoebe Buckheister struct ieee802154_llsec_params *params); 36129e02374SPhoebe Buckheister int (*set_params)(struct net_device *dev, 36229e02374SPhoebe Buckheister const struct ieee802154_llsec_params *params, 36329e02374SPhoebe Buckheister int changed); 36429e02374SPhoebe Buckheister 36529e02374SPhoebe Buckheister int (*add_key)(struct net_device *dev, 36629e02374SPhoebe Buckheister const struct ieee802154_llsec_key_id *id, 36729e02374SPhoebe Buckheister const struct ieee802154_llsec_key *key); 36829e02374SPhoebe Buckheister int (*del_key)(struct net_device *dev, 36929e02374SPhoebe Buckheister const struct ieee802154_llsec_key_id *id); 37029e02374SPhoebe Buckheister 37129e02374SPhoebe Buckheister int (*add_dev)(struct net_device *dev, 37229e02374SPhoebe Buckheister const struct ieee802154_llsec_device *llsec_dev); 37329e02374SPhoebe Buckheister int (*del_dev)(struct net_device *dev, __le64 dev_addr); 37429e02374SPhoebe Buckheister 37529e02374SPhoebe Buckheister int (*add_devkey)(struct net_device *dev, 37629e02374SPhoebe Buckheister __le64 device_addr, 37729e02374SPhoebe Buckheister const struct ieee802154_llsec_device_key *key); 37829e02374SPhoebe Buckheister int (*del_devkey)(struct net_device *dev, 37929e02374SPhoebe Buckheister __le64 device_addr, 38029e02374SPhoebe Buckheister const struct ieee802154_llsec_device_key *key); 38129e02374SPhoebe Buckheister 38229e02374SPhoebe Buckheister int (*add_seclevel)(struct net_device *dev, 38329e02374SPhoebe Buckheister const struct ieee802154_llsec_seclevel *sl); 38429e02374SPhoebe Buckheister int (*del_seclevel)(struct net_device *dev, 38529e02374SPhoebe Buckheister const struct ieee802154_llsec_seclevel *sl); 38629e02374SPhoebe Buckheister 38729e02374SPhoebe Buckheister void (*lock_table)(struct net_device *dev); 38829e02374SPhoebe Buckheister void (*get_table)(struct net_device *dev, 38929e02374SPhoebe Buckheister struct ieee802154_llsec_table **t); 39029e02374SPhoebe Buckheister void (*unlock_table)(struct net_device *dev); 39129e02374SPhoebe Buckheister }; 392f0166e5eSDmitry Eremin-Solenikov /* 393f0166e5eSDmitry Eremin-Solenikov * This should be located at net_device->ml_priv 39442723448SDmitry Eremin-Solenikov * 39542723448SDmitry Eremin-Solenikov * get_phy should increment the reference counting on returned phy. 39642723448SDmitry Eremin-Solenikov * Use wpan_wpy_put to put that reference. 397f0166e5eSDmitry Eremin-Solenikov */ 398f0166e5eSDmitry Eremin-Solenikov struct ieee802154_mlme_ops { 39956aa091dSWerner Almesberger /* The following fields are optional (can be NULL). */ 40056aa091dSWerner Almesberger 401f0166e5eSDmitry Eremin-Solenikov int (*assoc_req)(struct net_device *dev, 402ae531b94SPhoebe Buckheister struct ieee802154_addr *addr, 40316eea493SDmitry Eremin-Solenikov u8 channel, u8 page, u8 cap); 404f0166e5eSDmitry Eremin-Solenikov int (*assoc_resp)(struct net_device *dev, 405ae531b94SPhoebe Buckheister struct ieee802154_addr *addr, 406b70ab2e8SPhoebe Buckheister __le16 short_addr, u8 status); 407f0166e5eSDmitry Eremin-Solenikov int (*disassoc_req)(struct net_device *dev, 408ae531b94SPhoebe Buckheister struct ieee802154_addr *addr, 409f0166e5eSDmitry Eremin-Solenikov u8 reason); 410f0166e5eSDmitry Eremin-Solenikov int (*start_req)(struct net_device *dev, 411ae531b94SPhoebe Buckheister struct ieee802154_addr *addr, 41216eea493SDmitry Eremin-Solenikov u8 channel, u8 page, u8 bcn_ord, u8 sf_ord, 413f0166e5eSDmitry Eremin-Solenikov u8 pan_coord, u8 blx, u8 coord_realign); 414f0166e5eSDmitry Eremin-Solenikov int (*scan_req)(struct net_device *dev, 41516eea493SDmitry Eremin-Solenikov u8 type, u32 channels, u8 page, u8 duration); 416f0166e5eSDmitry Eremin-Solenikov 417e462ded6SPhoebe Buckheister int (*set_mac_params)(struct net_device *dev, 418e462ded6SPhoebe Buckheister const struct ieee802154_mac_params *params); 419e462ded6SPhoebe Buckheister void (*get_mac_params)(struct net_device *dev, 420e462ded6SPhoebe Buckheister struct ieee802154_mac_params *params); 421e462ded6SPhoebe Buckheister 42229e02374SPhoebe Buckheister struct ieee802154_llsec_ops *llsec; 42329e02374SPhoebe Buckheister 42456aa091dSWerner Almesberger /* The fields below are required. */ 42556aa091dSWerner Almesberger 42642723448SDmitry Eremin-Solenikov struct wpan_phy *(*get_phy)(const struct net_device *dev); 42742723448SDmitry Eremin-Solenikov 428f0166e5eSDmitry Eremin-Solenikov /* 429f0166e5eSDmitry Eremin-Solenikov * FIXME: these should become the part of PIB/MIB interface. 430f0166e5eSDmitry Eremin-Solenikov * However we still don't have IB interface of any kind 431f0166e5eSDmitry Eremin-Solenikov */ 432b70ab2e8SPhoebe Buckheister __le16 (*get_pan_id)(const struct net_device *dev); 433b70ab2e8SPhoebe Buckheister __le16 (*get_short_addr)(const struct net_device *dev); 434a9966b58SDmitry Eremin-Solenikov u8 (*get_dsn)(const struct net_device *dev); 435f0166e5eSDmitry Eremin-Solenikov }; 436f0166e5eSDmitry Eremin-Solenikov 43774a02fcfSalex.bluesman.smirnov@gmail.com /* The IEEE 802.15.4 standard defines 2 type of the devices: 43874a02fcfSalex.bluesman.smirnov@gmail.com * - FFD - full functionality device 43974a02fcfSalex.bluesman.smirnov@gmail.com * - RFD - reduce functionality device 44074a02fcfSalex.bluesman.smirnov@gmail.com * 44174a02fcfSalex.bluesman.smirnov@gmail.com * So 2 sets of mlme operations are needed 44274a02fcfSalex.bluesman.smirnov@gmail.com */ 44374a02fcfSalex.bluesman.smirnov@gmail.com struct ieee802154_reduced_mlme_ops { 44474a02fcfSalex.bluesman.smirnov@gmail.com struct wpan_phy *(*get_phy)(const struct net_device *dev); 44574a02fcfSalex.bluesman.smirnov@gmail.com }; 44674a02fcfSalex.bluesman.smirnov@gmail.com 44774a02fcfSalex.bluesman.smirnov@gmail.com static inline struct ieee802154_mlme_ops * 44874a02fcfSalex.bluesman.smirnov@gmail.com ieee802154_mlme_ops(const struct net_device *dev) 44974a02fcfSalex.bluesman.smirnov@gmail.com { 45074a02fcfSalex.bluesman.smirnov@gmail.com return dev->ml_priv; 45174a02fcfSalex.bluesman.smirnov@gmail.com } 45274a02fcfSalex.bluesman.smirnov@gmail.com 45374a02fcfSalex.bluesman.smirnov@gmail.com static inline struct ieee802154_reduced_mlme_ops * 45474a02fcfSalex.bluesman.smirnov@gmail.com ieee802154_reduced_mlme_ops(const struct net_device *dev) 455f0166e5eSDmitry Eremin-Solenikov { 456f0166e5eSDmitry Eremin-Solenikov return dev->ml_priv; 457f0166e5eSDmitry Eremin-Solenikov } 458f0166e5eSDmitry Eremin-Solenikov 459f0166e5eSDmitry Eremin-Solenikov #endif 460