18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * IEEE802.15.4-2003 specification 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2007-2012 Siemens AG 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#ifndef NET_MAC802154_H 88c2ecf20Sopenharmony_ci#define NET_MAC802154_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 118c2ecf20Sopenharmony_ci#include <net/af_ieee802154.h> 128c2ecf20Sopenharmony_ci#include <linux/ieee802154.h> 138c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <net/cfg802154.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/** 188c2ecf20Sopenharmony_ci * enum ieee802154_hw_addr_filt_flags - hardware address filtering flags 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * The following flags are used to indicate changed address settings from 218c2ecf20Sopenharmony_ci * the stack to the hardware. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * @IEEE802154_AFILT_SADDR_CHANGED: Indicates that the short address will be 248c2ecf20Sopenharmony_ci * change. 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * @IEEE802154_AFILT_IEEEADDR_CHANGED: Indicates that the extended address 278c2ecf20Sopenharmony_ci * will be change. 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * @IEEE802154_AFILT_PANID_CHANGED: Indicates that the pan id will be change. 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * @IEEE802154_AFILT_PANC_CHANGED: Indicates that the address filter will 328c2ecf20Sopenharmony_ci * do frame address filtering as a pan coordinator. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_cienum ieee802154_hw_addr_filt_flags { 358c2ecf20Sopenharmony_ci IEEE802154_AFILT_SADDR_CHANGED = BIT(0), 368c2ecf20Sopenharmony_ci IEEE802154_AFILT_IEEEADDR_CHANGED = BIT(1), 378c2ecf20Sopenharmony_ci IEEE802154_AFILT_PANID_CHANGED = BIT(2), 388c2ecf20Sopenharmony_ci IEEE802154_AFILT_PANC_CHANGED = BIT(3), 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/** 428c2ecf20Sopenharmony_ci * struct ieee802154_hw_addr_filt - hardware address filtering settings 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * @pan_id: pan_id which should be set to the hardware address filter. 458c2ecf20Sopenharmony_ci * 468c2ecf20Sopenharmony_ci * @short_addr: short_addr which should be set to the hardware address filter. 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci * @ieee_addr: extended address which should be set to the hardware address 498c2ecf20Sopenharmony_ci * filter. 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci * @pan_coord: boolean if hardware filtering should be operate as coordinator. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_cistruct ieee802154_hw_addr_filt { 548c2ecf20Sopenharmony_ci __le16 pan_id; 558c2ecf20Sopenharmony_ci __le16 short_addr; 568c2ecf20Sopenharmony_ci __le64 ieee_addr; 578c2ecf20Sopenharmony_ci bool pan_coord; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/** 618c2ecf20Sopenharmony_ci * struct ieee802154_hw - ieee802154 hardware 628c2ecf20Sopenharmony_ci * 638c2ecf20Sopenharmony_ci * @extra_tx_headroom: headroom to reserve in each transmit skb for use by the 648c2ecf20Sopenharmony_ci * driver (e.g. for transmit headers.) 658c2ecf20Sopenharmony_ci * 668c2ecf20Sopenharmony_ci * @flags: hardware flags, see &enum ieee802154_hw_flags 678c2ecf20Sopenharmony_ci * 688c2ecf20Sopenharmony_ci * @parent: parent device of the hardware. 698c2ecf20Sopenharmony_ci * 708c2ecf20Sopenharmony_ci * @priv: pointer to private area that was allocated for driver use along with 718c2ecf20Sopenharmony_ci * this structure. 728c2ecf20Sopenharmony_ci * 738c2ecf20Sopenharmony_ci * @phy: This points to the &struct wpan_phy allocated for this 802.15.4 PHY. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistruct ieee802154_hw { 768c2ecf20Sopenharmony_ci /* filled by the driver */ 778c2ecf20Sopenharmony_ci int extra_tx_headroom; 788c2ecf20Sopenharmony_ci u32 flags; 798c2ecf20Sopenharmony_ci struct device *parent; 808c2ecf20Sopenharmony_ci void *priv; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci /* filled by mac802154 core */ 838c2ecf20Sopenharmony_ci struct wpan_phy *phy; 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/** 878c2ecf20Sopenharmony_ci * enum ieee802154_hw_flags - hardware flags 888c2ecf20Sopenharmony_ci * 898c2ecf20Sopenharmony_ci * These flags are used to indicate hardware capabilities to 908c2ecf20Sopenharmony_ci * the stack. Generally, flags here should have their meaning 918c2ecf20Sopenharmony_ci * done in a way that the simplest hardware doesn't need setting 928c2ecf20Sopenharmony_ci * any particular flags. There are some exceptions to this rule, 938c2ecf20Sopenharmony_ci * however, so you are advised to review these flags carefully. 948c2ecf20Sopenharmony_ci * 958c2ecf20Sopenharmony_ci * @IEEE802154_HW_TX_OMIT_CKSUM: Indicates that xmitter will add FCS on it's 968c2ecf20Sopenharmony_ci * own. 978c2ecf20Sopenharmony_ci * 988c2ecf20Sopenharmony_ci * @IEEE802154_HW_LBT: Indicates that transceiver will support listen before 998c2ecf20Sopenharmony_ci * transmit. 1008c2ecf20Sopenharmony_ci * 1018c2ecf20Sopenharmony_ci * @IEEE802154_HW_CSMA_PARAMS: Indicates that transceiver will support csma 1028c2ecf20Sopenharmony_ci * parameters (max_be, min_be, backoff exponents). 1038c2ecf20Sopenharmony_ci * 1048c2ecf20Sopenharmony_ci * @IEEE802154_HW_FRAME_RETRIES: Indicates that transceiver will support ARET 1058c2ecf20Sopenharmony_ci * frame retries setting. 1068c2ecf20Sopenharmony_ci * 1078c2ecf20Sopenharmony_ci * @IEEE802154_HW_AFILT: Indicates that transceiver will support hardware 1088c2ecf20Sopenharmony_ci * address filter setting. 1098c2ecf20Sopenharmony_ci * 1108c2ecf20Sopenharmony_ci * @IEEE802154_HW_PROMISCUOUS: Indicates that transceiver will support 1118c2ecf20Sopenharmony_ci * promiscuous mode setting. 1128c2ecf20Sopenharmony_ci * 1138c2ecf20Sopenharmony_ci * @IEEE802154_HW_RX_OMIT_CKSUM: Indicates that receiver omits FCS. 1148c2ecf20Sopenharmony_ci * 1158c2ecf20Sopenharmony_ci * @IEEE802154_HW_RX_DROP_BAD_CKSUM: Indicates that receiver will not filter 1168c2ecf20Sopenharmony_ci * frames with bad checksum. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_cienum ieee802154_hw_flags { 1198c2ecf20Sopenharmony_ci IEEE802154_HW_TX_OMIT_CKSUM = BIT(0), 1208c2ecf20Sopenharmony_ci IEEE802154_HW_LBT = BIT(1), 1218c2ecf20Sopenharmony_ci IEEE802154_HW_CSMA_PARAMS = BIT(2), 1228c2ecf20Sopenharmony_ci IEEE802154_HW_FRAME_RETRIES = BIT(3), 1238c2ecf20Sopenharmony_ci IEEE802154_HW_AFILT = BIT(4), 1248c2ecf20Sopenharmony_ci IEEE802154_HW_PROMISCUOUS = BIT(5), 1258c2ecf20Sopenharmony_ci IEEE802154_HW_RX_OMIT_CKSUM = BIT(6), 1268c2ecf20Sopenharmony_ci IEEE802154_HW_RX_DROP_BAD_CKSUM = BIT(7), 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */ 1308c2ecf20Sopenharmony_ci#define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \ 1318c2ecf20Sopenharmony_ci IEEE802154_HW_RX_OMIT_CKSUM) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* struct ieee802154_ops - callbacks from mac802154 to the driver 1348c2ecf20Sopenharmony_ci * 1358c2ecf20Sopenharmony_ci * This structure contains various callbacks that the driver may 1368c2ecf20Sopenharmony_ci * handle or, in some cases, must handle, for example to transmit 1378c2ecf20Sopenharmony_ci * a frame. 1388c2ecf20Sopenharmony_ci * 1398c2ecf20Sopenharmony_ci * start: Handler that 802.15.4 module calls for device initialization. 1408c2ecf20Sopenharmony_ci * This function is called before the first interface is attached. 1418c2ecf20Sopenharmony_ci * 1428c2ecf20Sopenharmony_ci * stop: Handler that 802.15.4 module calls for device cleanup. 1438c2ecf20Sopenharmony_ci * This function is called after the last interface is removed. 1448c2ecf20Sopenharmony_ci * 1458c2ecf20Sopenharmony_ci * xmit_sync: 1468c2ecf20Sopenharmony_ci * Handler that 802.15.4 module calls for each transmitted frame. 1478c2ecf20Sopenharmony_ci * skb cntains the buffer starting from the IEEE 802.15.4 header. 1488c2ecf20Sopenharmony_ci * The low-level driver should send the frame based on available 1498c2ecf20Sopenharmony_ci * configuration. This is called by a workqueue and useful for 1508c2ecf20Sopenharmony_ci * synchronous 802.15.4 drivers. 1518c2ecf20Sopenharmony_ci * This function should return zero or negative errno. 1528c2ecf20Sopenharmony_ci * 1538c2ecf20Sopenharmony_ci * WARNING: 1548c2ecf20Sopenharmony_ci * This will be deprecated soon. We don't accept synced xmit callbacks 1558c2ecf20Sopenharmony_ci * drivers anymore. 1568c2ecf20Sopenharmony_ci * 1578c2ecf20Sopenharmony_ci * xmit_async: 1588c2ecf20Sopenharmony_ci * Handler that 802.15.4 module calls for each transmitted frame. 1598c2ecf20Sopenharmony_ci * skb cntains the buffer starting from the IEEE 802.15.4 header. 1608c2ecf20Sopenharmony_ci * The low-level driver should send the frame based on available 1618c2ecf20Sopenharmony_ci * configuration. 1628c2ecf20Sopenharmony_ci * This function should return zero or negative errno. 1638c2ecf20Sopenharmony_ci * 1648c2ecf20Sopenharmony_ci * ed: Handler that 802.15.4 module calls for Energy Detection. 1658c2ecf20Sopenharmony_ci * This function should place the value for detected energy 1668c2ecf20Sopenharmony_ci * (usually device-dependant) in the level pointer and return 1678c2ecf20Sopenharmony_ci * either zero or negative errno. Called with pib_lock held. 1688c2ecf20Sopenharmony_ci * 1698c2ecf20Sopenharmony_ci * set_channel: 1708c2ecf20Sopenharmony_ci * Set radio for listening on specific channel. 1718c2ecf20Sopenharmony_ci * Set the device for listening on specified channel. 1728c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. Called with pib_lock held. 1738c2ecf20Sopenharmony_ci * 1748c2ecf20Sopenharmony_ci * set_hw_addr_filt: 1758c2ecf20Sopenharmony_ci * Set radio for listening on specific address. 1768c2ecf20Sopenharmony_ci * Set the device for listening on specified address. 1778c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. 1788c2ecf20Sopenharmony_ci * 1798c2ecf20Sopenharmony_ci * set_txpower: 1808c2ecf20Sopenharmony_ci * Set radio transmit power in mBm. Called with pib_lock held. 1818c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. 1828c2ecf20Sopenharmony_ci * 1838c2ecf20Sopenharmony_ci * set_lbt 1848c2ecf20Sopenharmony_ci * Enables or disables listen before talk on the device. Called with 1858c2ecf20Sopenharmony_ci * pib_lock held. 1868c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. 1878c2ecf20Sopenharmony_ci * 1888c2ecf20Sopenharmony_ci * set_cca_mode 1898c2ecf20Sopenharmony_ci * Sets the CCA mode used by the device. Called with pib_lock held. 1908c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. 1918c2ecf20Sopenharmony_ci * 1928c2ecf20Sopenharmony_ci * set_cca_ed_level 1938c2ecf20Sopenharmony_ci * Sets the CCA energy detection threshold in mBm. Called with pib_lock 1948c2ecf20Sopenharmony_ci * held. 1958c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. 1968c2ecf20Sopenharmony_ci * 1978c2ecf20Sopenharmony_ci * set_csma_params 1988c2ecf20Sopenharmony_ci * Sets the CSMA parameter set for the PHY. Called with pib_lock held. 1998c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. 2008c2ecf20Sopenharmony_ci * 2018c2ecf20Sopenharmony_ci * set_frame_retries 2028c2ecf20Sopenharmony_ci * Sets the retransmission attempt limit. Called with pib_lock held. 2038c2ecf20Sopenharmony_ci * Returns either zero, or negative errno. 2048c2ecf20Sopenharmony_ci * 2058c2ecf20Sopenharmony_ci * set_promiscuous_mode 2068c2ecf20Sopenharmony_ci * Enables or disable promiscuous mode. 2078c2ecf20Sopenharmony_ci */ 2088c2ecf20Sopenharmony_cistruct ieee802154_ops { 2098c2ecf20Sopenharmony_ci struct module *owner; 2108c2ecf20Sopenharmony_ci int (*start)(struct ieee802154_hw *hw); 2118c2ecf20Sopenharmony_ci void (*stop)(struct ieee802154_hw *hw); 2128c2ecf20Sopenharmony_ci int (*xmit_sync)(struct ieee802154_hw *hw, 2138c2ecf20Sopenharmony_ci struct sk_buff *skb); 2148c2ecf20Sopenharmony_ci int (*xmit_async)(struct ieee802154_hw *hw, 2158c2ecf20Sopenharmony_ci struct sk_buff *skb); 2168c2ecf20Sopenharmony_ci int (*ed)(struct ieee802154_hw *hw, u8 *level); 2178c2ecf20Sopenharmony_ci int (*set_channel)(struct ieee802154_hw *hw, u8 page, 2188c2ecf20Sopenharmony_ci u8 channel); 2198c2ecf20Sopenharmony_ci int (*set_hw_addr_filt)(struct ieee802154_hw *hw, 2208c2ecf20Sopenharmony_ci struct ieee802154_hw_addr_filt *filt, 2218c2ecf20Sopenharmony_ci unsigned long changed); 2228c2ecf20Sopenharmony_ci int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm); 2238c2ecf20Sopenharmony_ci int (*set_lbt)(struct ieee802154_hw *hw, bool on); 2248c2ecf20Sopenharmony_ci int (*set_cca_mode)(struct ieee802154_hw *hw, 2258c2ecf20Sopenharmony_ci const struct wpan_phy_cca *cca); 2268c2ecf20Sopenharmony_ci int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm); 2278c2ecf20Sopenharmony_ci int (*set_csma_params)(struct ieee802154_hw *hw, 2288c2ecf20Sopenharmony_ci u8 min_be, u8 max_be, u8 retries); 2298c2ecf20Sopenharmony_ci int (*set_frame_retries)(struct ieee802154_hw *hw, 2308c2ecf20Sopenharmony_ci s8 retries); 2318c2ecf20Sopenharmony_ci int (*set_promiscuous_mode)(struct ieee802154_hw *hw, 2328c2ecf20Sopenharmony_ci const bool on); 2338c2ecf20Sopenharmony_ci}; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci/** 2368c2ecf20Sopenharmony_ci * ieee802154_get_fc_from_skb - get the frame control field from an skb 2378c2ecf20Sopenharmony_ci * @skb: skb where the frame control field will be get from 2388c2ecf20Sopenharmony_ci */ 2398c2ecf20Sopenharmony_cistatic inline __le16 ieee802154_get_fc_from_skb(const struct sk_buff *skb) 2408c2ecf20Sopenharmony_ci{ 2418c2ecf20Sopenharmony_ci __le16 fc; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci /* check if we can fc at skb_mac_header of sk buffer */ 2448c2ecf20Sopenharmony_ci if (WARN_ON(!skb_mac_header_was_set(skb) || 2458c2ecf20Sopenharmony_ci (skb_tail_pointer(skb) - 2468c2ecf20Sopenharmony_ci skb_mac_header(skb)) < IEEE802154_FC_LEN)) 2478c2ecf20Sopenharmony_ci return cpu_to_le16(0); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci memcpy(&fc, skb_mac_header(skb), IEEE802154_FC_LEN); 2508c2ecf20Sopenharmony_ci return fc; 2518c2ecf20Sopenharmony_ci} 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci/** 2548c2ecf20Sopenharmony_ci * ieee802154_skb_dst_pan - get the pointer to destination pan field 2558c2ecf20Sopenharmony_ci * @fc: mac header frame control field 2568c2ecf20Sopenharmony_ci * @skb: skb where the destination pan pointer will be get from 2578c2ecf20Sopenharmony_ci */ 2588c2ecf20Sopenharmony_cistatic inline unsigned char *ieee802154_skb_dst_pan(__le16 fc, 2598c2ecf20Sopenharmony_ci const struct sk_buff *skb) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci unsigned char *dst_pan; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci switch (ieee802154_daddr_mode(fc)) { 2648c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE): 2658c2ecf20Sopenharmony_ci dst_pan = NULL; 2668c2ecf20Sopenharmony_ci break; 2678c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_DADDR_SHORT): 2688c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_DADDR_EXTENDED): 2698c2ecf20Sopenharmony_ci dst_pan = skb_mac_header(skb) + 2708c2ecf20Sopenharmony_ci IEEE802154_FC_LEN + 2718c2ecf20Sopenharmony_ci IEEE802154_SEQ_LEN; 2728c2ecf20Sopenharmony_ci break; 2738c2ecf20Sopenharmony_ci default: 2748c2ecf20Sopenharmony_ci WARN_ONCE(1, "invalid addr mode detected"); 2758c2ecf20Sopenharmony_ci dst_pan = NULL; 2768c2ecf20Sopenharmony_ci break; 2778c2ecf20Sopenharmony_ci } 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci return dst_pan; 2808c2ecf20Sopenharmony_ci} 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci/** 2838c2ecf20Sopenharmony_ci * ieee802154_skb_src_pan - get the pointer to source pan field 2848c2ecf20Sopenharmony_ci * @fc: mac header frame control field 2858c2ecf20Sopenharmony_ci * @skb: skb where the source pan pointer will be get from 2868c2ecf20Sopenharmony_ci */ 2878c2ecf20Sopenharmony_cistatic inline unsigned char *ieee802154_skb_src_pan(__le16 fc, 2888c2ecf20Sopenharmony_ci const struct sk_buff *skb) 2898c2ecf20Sopenharmony_ci{ 2908c2ecf20Sopenharmony_ci unsigned char *src_pan; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci switch (ieee802154_saddr_mode(fc)) { 2938c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE): 2948c2ecf20Sopenharmony_ci src_pan = NULL; 2958c2ecf20Sopenharmony_ci break; 2968c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_SADDR_SHORT): 2978c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_SADDR_EXTENDED): 2988c2ecf20Sopenharmony_ci /* if intra-pan and source addr mode is non none, 2998c2ecf20Sopenharmony_ci * then source pan id is equal destination pan id. 3008c2ecf20Sopenharmony_ci */ 3018c2ecf20Sopenharmony_ci if (ieee802154_is_intra_pan(fc)) { 3028c2ecf20Sopenharmony_ci src_pan = ieee802154_skb_dst_pan(fc, skb); 3038c2ecf20Sopenharmony_ci break; 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci switch (ieee802154_daddr_mode(fc)) { 3078c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE): 3088c2ecf20Sopenharmony_ci src_pan = skb_mac_header(skb) + 3098c2ecf20Sopenharmony_ci IEEE802154_FC_LEN + 3108c2ecf20Sopenharmony_ci IEEE802154_SEQ_LEN; 3118c2ecf20Sopenharmony_ci break; 3128c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_DADDR_SHORT): 3138c2ecf20Sopenharmony_ci src_pan = skb_mac_header(skb) + 3148c2ecf20Sopenharmony_ci IEEE802154_FC_LEN + 3158c2ecf20Sopenharmony_ci IEEE802154_SEQ_LEN + 3168c2ecf20Sopenharmony_ci IEEE802154_PAN_ID_LEN + 3178c2ecf20Sopenharmony_ci IEEE802154_SHORT_ADDR_LEN; 3188c2ecf20Sopenharmony_ci break; 3198c2ecf20Sopenharmony_ci case cpu_to_le16(IEEE802154_FCTL_DADDR_EXTENDED): 3208c2ecf20Sopenharmony_ci src_pan = skb_mac_header(skb) + 3218c2ecf20Sopenharmony_ci IEEE802154_FC_LEN + 3228c2ecf20Sopenharmony_ci IEEE802154_SEQ_LEN + 3238c2ecf20Sopenharmony_ci IEEE802154_PAN_ID_LEN + 3248c2ecf20Sopenharmony_ci IEEE802154_EXTENDED_ADDR_LEN; 3258c2ecf20Sopenharmony_ci break; 3268c2ecf20Sopenharmony_ci default: 3278c2ecf20Sopenharmony_ci WARN_ONCE(1, "invalid addr mode detected"); 3288c2ecf20Sopenharmony_ci src_pan = NULL; 3298c2ecf20Sopenharmony_ci break; 3308c2ecf20Sopenharmony_ci } 3318c2ecf20Sopenharmony_ci break; 3328c2ecf20Sopenharmony_ci default: 3338c2ecf20Sopenharmony_ci WARN_ONCE(1, "invalid addr mode detected"); 3348c2ecf20Sopenharmony_ci src_pan = NULL; 3358c2ecf20Sopenharmony_ci break; 3368c2ecf20Sopenharmony_ci } 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci return src_pan; 3398c2ecf20Sopenharmony_ci} 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci/** 3428c2ecf20Sopenharmony_ci * ieee802154_skb_is_intra_pan_addressing - checks whenever the mac addressing 3438c2ecf20Sopenharmony_ci * is an intra pan communication 3448c2ecf20Sopenharmony_ci * @fc: mac header frame control field 3458c2ecf20Sopenharmony_ci * @skb: skb where the source and destination pan should be get from 3468c2ecf20Sopenharmony_ci */ 3478c2ecf20Sopenharmony_cistatic inline bool ieee802154_skb_is_intra_pan_addressing(__le16 fc, 3488c2ecf20Sopenharmony_ci const struct sk_buff *skb) 3498c2ecf20Sopenharmony_ci{ 3508c2ecf20Sopenharmony_ci unsigned char *dst_pan = ieee802154_skb_dst_pan(fc, skb), 3518c2ecf20Sopenharmony_ci *src_pan = ieee802154_skb_src_pan(fc, skb); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci /* if one is NULL is no intra pan addressing */ 3548c2ecf20Sopenharmony_ci if (!dst_pan || !src_pan) 3558c2ecf20Sopenharmony_ci return false; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci return !memcmp(dst_pan, src_pan, IEEE802154_PAN_ID_LEN); 3588c2ecf20Sopenharmony_ci} 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci/** 3618c2ecf20Sopenharmony_ci * ieee802154_be64_to_le64 - copies and convert be64 to le64 3628c2ecf20Sopenharmony_ci * @le64_dst: le64 destination pointer 3638c2ecf20Sopenharmony_ci * @be64_src: be64 source pointer 3648c2ecf20Sopenharmony_ci */ 3658c2ecf20Sopenharmony_cistatic inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci put_unaligned_le64(get_unaligned_be64(be64_src), le64_dst); 3688c2ecf20Sopenharmony_ci} 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci/** 3718c2ecf20Sopenharmony_ci * ieee802154_le64_to_be64 - copies and convert le64 to be64 3728c2ecf20Sopenharmony_ci * @be64_dst: be64 destination pointer 3738c2ecf20Sopenharmony_ci * @le64_src: le64 source pointer 3748c2ecf20Sopenharmony_ci */ 3758c2ecf20Sopenharmony_cistatic inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src) 3768c2ecf20Sopenharmony_ci{ 3778c2ecf20Sopenharmony_ci put_unaligned_be64(get_unaligned_le64(le64_src), be64_dst); 3788c2ecf20Sopenharmony_ci} 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci/** 3818c2ecf20Sopenharmony_ci * ieee802154_le16_to_be16 - copies and convert le16 to be16 3828c2ecf20Sopenharmony_ci * @be16_dst: be16 destination pointer 3838c2ecf20Sopenharmony_ci * @le16_src: le16 source pointer 3848c2ecf20Sopenharmony_ci */ 3858c2ecf20Sopenharmony_cistatic inline void ieee802154_le16_to_be16(void *be16_dst, const void *le16_src) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci put_unaligned_be16(get_unaligned_le16(le16_src), be16_dst); 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci/** 3918c2ecf20Sopenharmony_ci * ieee802154_be16_to_le16 - copies and convert be16 to le16 3928c2ecf20Sopenharmony_ci * @le16_dst: le16 destination pointer 3938c2ecf20Sopenharmony_ci * @be16_src: be16 source pointer 3948c2ecf20Sopenharmony_ci */ 3958c2ecf20Sopenharmony_cistatic inline void ieee802154_be16_to_le16(void *le16_dst, const void *be16_src) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci put_unaligned_le16(get_unaligned_be16(be16_src), le16_dst); 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci/** 4018c2ecf20Sopenharmony_ci * ieee802154_alloc_hw - Allocate a new hardware device 4028c2ecf20Sopenharmony_ci * 4038c2ecf20Sopenharmony_ci * This must be called once for each hardware device. The returned pointer 4048c2ecf20Sopenharmony_ci * must be used to refer to this device when calling other functions. 4058c2ecf20Sopenharmony_ci * mac802154 allocates a private data area for the driver pointed to by 4068c2ecf20Sopenharmony_ci * @priv in &struct ieee802154_hw, the size of this area is given as 4078c2ecf20Sopenharmony_ci * @priv_data_len. 4088c2ecf20Sopenharmony_ci * 4098c2ecf20Sopenharmony_ci * @priv_data_len: length of private data 4108c2ecf20Sopenharmony_ci * @ops: callbacks for this device 4118c2ecf20Sopenharmony_ci * 4128c2ecf20Sopenharmony_ci * Return: A pointer to the new hardware device, or %NULL on error. 4138c2ecf20Sopenharmony_ci */ 4148c2ecf20Sopenharmony_cistruct ieee802154_hw * 4158c2ecf20Sopenharmony_ciieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops); 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci/** 4188c2ecf20Sopenharmony_ci * ieee802154_free_hw - free hardware descriptor 4198c2ecf20Sopenharmony_ci * 4208c2ecf20Sopenharmony_ci * This function frees everything that was allocated, including the 4218c2ecf20Sopenharmony_ci * private data for the driver. You must call ieee802154_unregister_hw() 4228c2ecf20Sopenharmony_ci * before calling this function. 4238c2ecf20Sopenharmony_ci * 4248c2ecf20Sopenharmony_ci * @hw: the hardware to free 4258c2ecf20Sopenharmony_ci */ 4268c2ecf20Sopenharmony_civoid ieee802154_free_hw(struct ieee802154_hw *hw); 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci/** 4298c2ecf20Sopenharmony_ci * ieee802154_register_hw - Register hardware device 4308c2ecf20Sopenharmony_ci * 4318c2ecf20Sopenharmony_ci * You must call this function before any other functions in 4328c2ecf20Sopenharmony_ci * mac802154. Note that before a hardware can be registered, you 4338c2ecf20Sopenharmony_ci * need to fill the contained wpan_phy's information. 4348c2ecf20Sopenharmony_ci * 4358c2ecf20Sopenharmony_ci * @hw: the device to register as returned by ieee802154_alloc_hw() 4368c2ecf20Sopenharmony_ci * 4378c2ecf20Sopenharmony_ci * Return: 0 on success. An error code otherwise. 4388c2ecf20Sopenharmony_ci */ 4398c2ecf20Sopenharmony_ciint ieee802154_register_hw(struct ieee802154_hw *hw); 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci/** 4428c2ecf20Sopenharmony_ci * ieee802154_unregister_hw - Unregister a hardware device 4438c2ecf20Sopenharmony_ci * 4448c2ecf20Sopenharmony_ci * This function instructs mac802154 to free allocated resources 4458c2ecf20Sopenharmony_ci * and unregister netdevices from the networking subsystem. 4468c2ecf20Sopenharmony_ci * 4478c2ecf20Sopenharmony_ci * @hw: the hardware to unregister 4488c2ecf20Sopenharmony_ci */ 4498c2ecf20Sopenharmony_civoid ieee802154_unregister_hw(struct ieee802154_hw *hw); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci/** 4528c2ecf20Sopenharmony_ci * ieee802154_rx_irqsafe - receive frame 4538c2ecf20Sopenharmony_ci * 4548c2ecf20Sopenharmony_ci * Like ieee802154_rx() but can be called in IRQ context 4558c2ecf20Sopenharmony_ci * (internally defers to a tasklet.) 4568c2ecf20Sopenharmony_ci * 4578c2ecf20Sopenharmony_ci * @hw: the hardware this frame came in on 4588c2ecf20Sopenharmony_ci * @skb: the buffer to receive, owned by mac802154 after this call 4598c2ecf20Sopenharmony_ci * @lqi: link quality indicator 4608c2ecf20Sopenharmony_ci */ 4618c2ecf20Sopenharmony_civoid ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, 4628c2ecf20Sopenharmony_ci u8 lqi); 4638c2ecf20Sopenharmony_ci/** 4648c2ecf20Sopenharmony_ci * ieee802154_wake_queue - wake ieee802154 queue 4658c2ecf20Sopenharmony_ci * @hw: pointer as obtained from ieee802154_alloc_hw(). 4668c2ecf20Sopenharmony_ci * 4678c2ecf20Sopenharmony_ci * Drivers should use this function instead of netif_wake_queue. 4688c2ecf20Sopenharmony_ci */ 4698c2ecf20Sopenharmony_civoid ieee802154_wake_queue(struct ieee802154_hw *hw); 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci/** 4728c2ecf20Sopenharmony_ci * ieee802154_stop_queue - stop ieee802154 queue 4738c2ecf20Sopenharmony_ci * @hw: pointer as obtained from ieee802154_alloc_hw(). 4748c2ecf20Sopenharmony_ci * 4758c2ecf20Sopenharmony_ci * Drivers should use this function instead of netif_stop_queue. 4768c2ecf20Sopenharmony_ci */ 4778c2ecf20Sopenharmony_civoid ieee802154_stop_queue(struct ieee802154_hw *hw); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci/** 4808c2ecf20Sopenharmony_ci * ieee802154_xmit_complete - frame transmission complete 4818c2ecf20Sopenharmony_ci * 4828c2ecf20Sopenharmony_ci * @hw: pointer as obtained from ieee802154_alloc_hw(). 4838c2ecf20Sopenharmony_ci * @skb: buffer for transmission 4848c2ecf20Sopenharmony_ci * @ifs_handling: indicate interframe space handling 4858c2ecf20Sopenharmony_ci */ 4868c2ecf20Sopenharmony_civoid ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, 4878c2ecf20Sopenharmony_ci bool ifs_handling); 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci#endif /* NET_MAC802154_H */ 490