Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 2 | /* |
| 3 | * IEEE802.15.4-2003 specification |
| 4 | * |
| 5 | * Copyright (C) 2007-2012 Siemens AG |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 6 | */ |
| 7 | #ifndef NET_MAC802154_H |
| 8 | #define NET_MAC802154_H |
| 9 | |
Alexander Aring | f160892 | 2016-03-04 10:10:20 +0100 | [diff] [blame] | 10 | #include <asm/unaligned.h> |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 11 | #include <net/af_ieee802154.h> |
Alexander Aring | 239a84a | 2014-11-05 20:51:23 +0100 | [diff] [blame] | 12 | #include <linux/ieee802154.h> |
Phoebe Buckheister | 94b4f6c | 2014-03-14 21:24:00 +0100 | [diff] [blame] | 13 | #include <linux/skbuff.h> |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 14 | |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 15 | #include <net/cfg802154.h> |
| 16 | |
Alexander Aring | 6b70a43 | 2015-06-06 17:30:47 +0200 | [diff] [blame] | 17 | /** |
| 18 | * enum ieee802154_hw_addr_filt_flags - hardware address filtering flags |
| 19 | * |
| 20 | * The following flags are used to indicate changed address settings from |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 21 | * the stack to the hardware. |
Alexander Aring | 6b70a43 | 2015-06-06 17:30:47 +0200 | [diff] [blame] | 22 | * |
| 23 | * @IEEE802154_AFILT_SADDR_CHANGED: Indicates that the short address will be |
| 24 | * change. |
| 25 | * |
| 26 | * @IEEE802154_AFILT_IEEEADDR_CHANGED: Indicates that the extended address |
| 27 | * will be change. |
| 28 | * |
| 29 | * @IEEE802154_AFILT_PANID_CHANGED: Indicates that the pan id will be change. |
| 30 | * |
| 31 | * @IEEE802154_AFILT_PANC_CHANGED: Indicates that the address filter will |
| 32 | * do frame address filtering as a pan coordinator. |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 33 | */ |
Alexander Aring | 6b70a43 | 2015-06-06 17:30:47 +0200 | [diff] [blame] | 34 | enum ieee802154_hw_addr_filt_flags { |
Alexander Aring | 70f3650 | 2015-06-12 09:24:00 +0200 | [diff] [blame] | 35 | IEEE802154_AFILT_SADDR_CHANGED = BIT(0), |
| 36 | IEEE802154_AFILT_IEEEADDR_CHANGED = BIT(1), |
| 37 | IEEE802154_AFILT_PANID_CHANGED = BIT(2), |
| 38 | IEEE802154_AFILT_PANC_CHANGED = BIT(3), |
Alexander Aring | 6b70a43 | 2015-06-06 17:30:47 +0200 | [diff] [blame] | 39 | }; |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 40 | |
Alexander Aring | a0825b0 | 2015-06-06 17:30:52 +0200 | [diff] [blame] | 41 | /** |
| 42 | * struct ieee802154_hw_addr_filt - hardware address filtering settings |
| 43 | * |
| 44 | * @pan_id: pan_id which should be set to the hardware address filter. |
| 45 | * |
| 46 | * @short_addr: short_addr which should be set to the hardware address filter. |
| 47 | * |
| 48 | * @ieee_addr: extended address which should be set to the hardware address |
| 49 | * filter. |
| 50 | * |
| 51 | * @pan_coord: boolean if hardware filtering should be operate as coordinator. |
| 52 | */ |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 53 | struct ieee802154_hw_addr_filt { |
Alexander Aring | a0825b0 | 2015-06-06 17:30:52 +0200 | [diff] [blame] | 54 | __le16 pan_id; |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 55 | __le16 short_addr; |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 56 | __le64 ieee_addr; |
Alexander Aring | 623c123 | 2015-06-06 17:30:53 +0200 | [diff] [blame] | 57 | bool pan_coord; |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Alexander Aring | a0825b0 | 2015-06-06 17:30:52 +0200 | [diff] [blame] | 60 | /** |
| 61 | * struct ieee802154_hw - ieee802154 hardware |
| 62 | * |
| 63 | * @extra_tx_headroom: headroom to reserve in each transmit skb for use by the |
| 64 | * driver (e.g. for transmit headers.) |
| 65 | * |
| 66 | * @flags: hardware flags, see &enum ieee802154_hw_flags |
| 67 | * |
| 68 | * @parent: parent device of the hardware. |
| 69 | * |
| 70 | * @priv: pointer to private area that was allocated for driver use along with |
| 71 | * this structure. |
| 72 | * |
| 73 | * @phy: This points to the &struct wpan_phy allocated for this 802.15.4 PHY. |
| 74 | */ |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 75 | struct ieee802154_hw { |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 76 | /* filled by the driver */ |
| 77 | int extra_tx_headroom; |
| 78 | u32 flags; |
| 79 | struct device *parent; |
Alexander Aring | af69a34 | 2015-06-06 17:30:51 +0200 | [diff] [blame] | 80 | void *priv; |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 81 | |
| 82 | /* filled by mac802154 core */ |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 83 | struct wpan_phy *phy; |
| 84 | }; |
| 85 | |
Alexander Aring | bcbfd20 | 2015-06-06 17:30:49 +0200 | [diff] [blame] | 86 | /** |
| 87 | * enum ieee802154_hw_flags - hardware flags |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 88 | * |
Alexander Aring | bcbfd20 | 2015-06-06 17:30:49 +0200 | [diff] [blame] | 89 | * These flags are used to indicate hardware capabilities to |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 90 | * the stack. Generally, flags here should have their meaning |
| 91 | * done in a way that the simplest hardware doesn't need setting |
| 92 | * any particular flags. There are some exceptions to this rule, |
| 93 | * however, so you are advised to review these flags carefully. |
Alexander Aring | bcbfd20 | 2015-06-06 17:30:49 +0200 | [diff] [blame] | 94 | * |
| 95 | * @IEEE802154_HW_TX_OMIT_CKSUM: Indicates that xmitter will add FCS on it's |
| 96 | * own. |
| 97 | * |
| 98 | * @IEEE802154_HW_LBT: Indicates that transceiver will support listen before |
| 99 | * transmit. |
| 100 | * |
| 101 | * @IEEE802154_HW_CSMA_PARAMS: Indicates that transceiver will support csma |
| 102 | * parameters (max_be, min_be, backoff exponents). |
| 103 | * |
| 104 | * @IEEE802154_HW_FRAME_RETRIES: Indicates that transceiver will support ARET |
| 105 | * frame retries setting. |
| 106 | * |
| 107 | * @IEEE802154_HW_AFILT: Indicates that transceiver will support hardware |
| 108 | * address filter setting. |
| 109 | * |
| 110 | * @IEEE802154_HW_PROMISCUOUS: Indicates that transceiver will support |
| 111 | * promiscuous mode setting. |
| 112 | * |
| 113 | * @IEEE802154_HW_RX_OMIT_CKSUM: Indicates that receiver omits FCS. |
| 114 | * |
| 115 | * @IEEE802154_HW_RX_DROP_BAD_CKSUM: Indicates that receiver will not filter |
| 116 | * frames with bad checksum. |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 117 | */ |
Alexander Aring | bcbfd20 | 2015-06-06 17:30:49 +0200 | [diff] [blame] | 118 | enum ieee802154_hw_flags { |
Alexander Aring | 70f3650 | 2015-06-12 09:24:00 +0200 | [diff] [blame] | 119 | IEEE802154_HW_TX_OMIT_CKSUM = BIT(0), |
| 120 | IEEE802154_HW_LBT = BIT(1), |
| 121 | IEEE802154_HW_CSMA_PARAMS = BIT(2), |
| 122 | IEEE802154_HW_FRAME_RETRIES = BIT(3), |
| 123 | IEEE802154_HW_AFILT = BIT(4), |
| 124 | IEEE802154_HW_PROMISCUOUS = BIT(5), |
| 125 | IEEE802154_HW_RX_OMIT_CKSUM = BIT(6), |
| 126 | IEEE802154_HW_RX_DROP_BAD_CKSUM = BIT(7), |
Alexander Aring | bcbfd20 | 2015-06-06 17:30:49 +0200 | [diff] [blame] | 127 | }; |
Alexander Aring | 90386a7 | 2014-10-29 21:34:34 +0100 | [diff] [blame] | 128 | |
| 129 | /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */ |
| 130 | #define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \ |
| 131 | IEEE802154_HW_RX_OMIT_CKSUM) |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 132 | |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 133 | /* struct ieee802154_ops - callbacks from mac802154 to the driver |
| 134 | * |
| 135 | * This structure contains various callbacks that the driver may |
| 136 | * handle or, in some cases, must handle, for example to transmit |
| 137 | * a frame. |
| 138 | * |
| 139 | * start: Handler that 802.15.4 module calls for device initialization. |
| 140 | * This function is called before the first interface is attached. |
| 141 | * |
| 142 | * stop: Handler that 802.15.4 module calls for device cleanup. |
| 143 | * This function is called after the last interface is removed. |
| 144 | * |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 145 | * xmit_sync: |
| 146 | * Handler that 802.15.4 module calls for each transmitted frame. |
| 147 | * skb cntains the buffer starting from the IEEE 802.15.4 header. |
| 148 | * The low-level driver should send the frame based on available |
| 149 | * configuration. This is called by a workqueue and useful for |
| 150 | * synchronous 802.15.4 drivers. |
| 151 | * This function should return zero or negative errno. |
| 152 | * |
Alexander Aring | 1e7283a | 2014-10-26 09:37:14 +0100 | [diff] [blame] | 153 | * WARNING: |
| 154 | * This will be deprecated soon. We don't accept synced xmit callbacks |
| 155 | * drivers anymore. |
| 156 | * |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 157 | * xmit_async: |
| 158 | * Handler that 802.15.4 module calls for each transmitted frame. |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 159 | * skb cntains the buffer starting from the IEEE 802.15.4 header. |
| 160 | * The low-level driver should send the frame based on available |
| 161 | * configuration. |
Alexander Aring | dc67c6b | 2014-10-26 09:37:04 +0100 | [diff] [blame] | 162 | * This function should return zero or negative errno. |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 163 | * |
| 164 | * ed: Handler that 802.15.4 module calls for Energy Detection. |
| 165 | * This function should place the value for detected energy |
| 166 | * (usually device-dependant) in the level pointer and return |
| 167 | * either zero or negative errno. Called with pib_lock held. |
| 168 | * |
| 169 | * set_channel: |
| 170 | * Set radio for listening on specific channel. |
| 171 | * Set the device for listening on specified channel. |
| 172 | * Returns either zero, or negative errno. Called with pib_lock held. |
| 173 | * |
| 174 | * set_hw_addr_filt: |
| 175 | * Set radio for listening on specific address. |
| 176 | * Set the device for listening on specified address. |
| 177 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 9b2777d | 2014-02-17 11:34:08 +0100 | [diff] [blame] | 178 | * |
| 179 | * set_txpower: |
Alexander Aring | e2eb173 | 2015-05-17 21:44:40 +0200 | [diff] [blame] | 180 | * Set radio transmit power in mBm. Called with pib_lock held. |
Phoebe Buckheister | 9b2777d | 2014-02-17 11:34:08 +0100 | [diff] [blame] | 181 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 84dda3c | 2014-02-17 11:34:10 +0100 | [diff] [blame] | 182 | * |
| 183 | * set_lbt |
| 184 | * Enables or disables listen before talk on the device. Called with |
| 185 | * pib_lock held. |
| 186 | * Returns either zero, or negative errno. |
Phoebe Buckheister | ba08fea | 2014-02-17 11:34:11 +0100 | [diff] [blame] | 187 | * |
| 188 | * set_cca_mode |
| 189 | * Sets the CCA mode used by the device. Called with pib_lock held. |
| 190 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 191 | * |
| 192 | * set_cca_ed_level |
Alexander Aring | 32b2355 | 2015-05-17 21:44:41 +0200 | [diff] [blame] | 193 | * Sets the CCA energy detection threshold in mBm. Called with pib_lock |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 194 | * held. |
| 195 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 4244db1 | 2014-02-17 11:34:14 +0100 | [diff] [blame] | 196 | * |
| 197 | * set_csma_params |
| 198 | * Sets the CSMA parameter set for the PHY. Called with pib_lock held. |
| 199 | * Returns either zero, or negative errno. |
| 200 | * |
| 201 | * set_frame_retries |
| 202 | * Sets the retransmission attempt limit. Called with pib_lock held. |
| 203 | * Returns either zero, or negative errno. |
Alexander Aring | 94b7922 | 2014-10-29 21:34:32 +0100 | [diff] [blame] | 204 | * |
| 205 | * set_promiscuous_mode |
| 206 | * Enables or disable promiscuous mode. |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 207 | */ |
| 208 | struct ieee802154_ops { |
| 209 | struct module *owner; |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 210 | int (*start)(struct ieee802154_hw *hw); |
| 211 | void (*stop)(struct ieee802154_hw *hw); |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 212 | int (*xmit_sync)(struct ieee802154_hw *hw, |
| 213 | struct sk_buff *skb); |
| 214 | int (*xmit_async)(struct ieee802154_hw *hw, |
| 215 | struct sk_buff *skb); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 216 | int (*ed)(struct ieee802154_hw *hw, u8 *level); |
Alexander Aring | e37d2ec | 2014-10-28 18:21:19 +0100 | [diff] [blame] | 217 | int (*set_channel)(struct ieee802154_hw *hw, u8 page, |
| 218 | u8 channel); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 219 | int (*set_hw_addr_filt)(struct ieee802154_hw *hw, |
| 220 | struct ieee802154_hw_addr_filt *filt, |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 221 | unsigned long changed); |
Alexander Aring | e2eb173 | 2015-05-17 21:44:40 +0200 | [diff] [blame] | 222 | int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 223 | int (*set_lbt)(struct ieee802154_hw *hw, bool on); |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 224 | int (*set_cca_mode)(struct ieee802154_hw *hw, |
| 225 | const struct wpan_phy_cca *cca); |
Alexander Aring | 32b2355 | 2015-05-17 21:44:41 +0200 | [diff] [blame] | 226 | int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 227 | int (*set_csma_params)(struct ieee802154_hw *hw, |
Phoebe Buckheister | 4244db1 | 2014-02-17 11:34:14 +0100 | [diff] [blame] | 228 | u8 min_be, u8 max_be, u8 retries); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 229 | int (*set_frame_retries)(struct ieee802154_hw *hw, |
Phoebe Buckheister | 4244db1 | 2014-02-17 11:34:14 +0100 | [diff] [blame] | 230 | s8 retries); |
Alexander Aring | 94b7922 | 2014-10-29 21:34:32 +0100 | [diff] [blame] | 231 | int (*set_promiscuous_mode)(struct ieee802154_hw *hw, |
| 232 | const bool on); |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 233 | }; |
| 234 | |
Alexander Aring | ab24f50 | 2014-11-02 04:18:40 +0100 | [diff] [blame] | 235 | /** |
Alexander Aring | 54552d0 | 2015-09-02 14:21:29 +0200 | [diff] [blame] | 236 | * ieee802154_get_fc_from_skb - get the frame control field from an skb |
| 237 | * @skb: skb where the frame control field will be get from |
| 238 | */ |
| 239 | static inline __le16 ieee802154_get_fc_from_skb(const struct sk_buff *skb) |
| 240 | { |
Alexander Aring | aaa7088 | 2016-07-06 23:32:27 +0200 | [diff] [blame] | 241 | __le16 fc; |
| 242 | |
Alexander Aring | 07b0188 | 2016-02-19 09:59:11 +0100 | [diff] [blame] | 243 | /* check if we can fc at skb_mac_header of sk buffer */ |
Alexander Aring | 048e7f7 | 2016-07-06 23:32:30 +0200 | [diff] [blame] | 244 | if (WARN_ON(!skb_mac_header_was_set(skb) || |
| 245 | (skb_tail_pointer(skb) - |
| 246 | skb_mac_header(skb)) < IEEE802154_FC_LEN)) |
Alexander Aring | 54552d0 | 2015-09-02 14:21:29 +0200 | [diff] [blame] | 247 | return cpu_to_le16(0); |
Alexander Aring | 54552d0 | 2015-09-02 14:21:29 +0200 | [diff] [blame] | 248 | |
Alexander Aring | aaa7088 | 2016-07-06 23:32:27 +0200 | [diff] [blame] | 249 | memcpy(&fc, skb_mac_header(skb), IEEE802154_FC_LEN); |
| 250 | return fc; |
Alexander Aring | 54552d0 | 2015-09-02 14:21:29 +0200 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /** |
Alexander Aring | 9cc577d | 2016-07-06 23:32:24 +0200 | [diff] [blame] | 254 | * ieee802154_skb_dst_pan - get the pointer to destination pan field |
| 255 | * @fc: mac header frame control field |
| 256 | * @skb: skb where the destination pan pointer will be get from |
| 257 | */ |
| 258 | static inline unsigned char *ieee802154_skb_dst_pan(__le16 fc, |
| 259 | const struct sk_buff *skb) |
| 260 | { |
| 261 | unsigned char *dst_pan; |
| 262 | |
| 263 | switch (ieee802154_daddr_mode(fc)) { |
| 264 | case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE): |
| 265 | dst_pan = NULL; |
| 266 | break; |
| 267 | case cpu_to_le16(IEEE802154_FCTL_DADDR_SHORT): |
| 268 | case cpu_to_le16(IEEE802154_FCTL_DADDR_EXTENDED): |
| 269 | dst_pan = skb_mac_header(skb) + |
| 270 | IEEE802154_FC_LEN + |
| 271 | IEEE802154_SEQ_LEN; |
| 272 | break; |
| 273 | default: |
| 274 | WARN_ONCE(1, "invalid addr mode detected"); |
| 275 | dst_pan = NULL; |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | return dst_pan; |
| 280 | } |
| 281 | |
| 282 | /** |
Alexander Aring | 19580cc | 2016-07-06 23:32:25 +0200 | [diff] [blame] | 283 | * ieee802154_skb_src_pan - get the pointer to source pan field |
| 284 | * @fc: mac header frame control field |
| 285 | * @skb: skb where the source pan pointer will be get from |
| 286 | */ |
| 287 | static inline unsigned char *ieee802154_skb_src_pan(__le16 fc, |
| 288 | const struct sk_buff *skb) |
| 289 | { |
| 290 | unsigned char *src_pan; |
| 291 | |
| 292 | switch (ieee802154_saddr_mode(fc)) { |
| 293 | case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE): |
| 294 | src_pan = NULL; |
| 295 | break; |
| 296 | case cpu_to_le16(IEEE802154_FCTL_SADDR_SHORT): |
| 297 | case cpu_to_le16(IEEE802154_FCTL_SADDR_EXTENDED): |
| 298 | /* if intra-pan and source addr mode is non none, |
| 299 | * then source pan id is equal destination pan id. |
| 300 | */ |
| 301 | if (ieee802154_is_intra_pan(fc)) { |
| 302 | src_pan = ieee802154_skb_dst_pan(fc, skb); |
| 303 | break; |
| 304 | } |
| 305 | |
| 306 | switch (ieee802154_daddr_mode(fc)) { |
| 307 | case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE): |
| 308 | src_pan = skb_mac_header(skb) + |
| 309 | IEEE802154_FC_LEN + |
| 310 | IEEE802154_SEQ_LEN; |
| 311 | break; |
| 312 | case cpu_to_le16(IEEE802154_FCTL_DADDR_SHORT): |
| 313 | src_pan = skb_mac_header(skb) + |
| 314 | IEEE802154_FC_LEN + |
| 315 | IEEE802154_SEQ_LEN + |
| 316 | IEEE802154_PAN_ID_LEN + |
| 317 | IEEE802154_SHORT_ADDR_LEN; |
| 318 | break; |
| 319 | case cpu_to_le16(IEEE802154_FCTL_DADDR_EXTENDED): |
| 320 | src_pan = skb_mac_header(skb) + |
| 321 | IEEE802154_FC_LEN + |
| 322 | IEEE802154_SEQ_LEN + |
| 323 | IEEE802154_PAN_ID_LEN + |
| 324 | IEEE802154_EXTENDED_ADDR_LEN; |
| 325 | break; |
| 326 | default: |
| 327 | WARN_ONCE(1, "invalid addr mode detected"); |
| 328 | src_pan = NULL; |
| 329 | break; |
| 330 | } |
| 331 | break; |
| 332 | default: |
| 333 | WARN_ONCE(1, "invalid addr mode detected"); |
| 334 | src_pan = NULL; |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | return src_pan; |
| 339 | } |
| 340 | |
| 341 | /** |
Alexander Aring | 0ea0b9a | 2016-07-06 23:32:26 +0200 | [diff] [blame] | 342 | * ieee802154_skb_is_intra_pan_addressing - checks whenever the mac addressing |
| 343 | * is an intra pan communication |
| 344 | * @fc: mac header frame control field |
| 345 | * @skb: skb where the source and destination pan should be get from |
| 346 | */ |
| 347 | static inline bool ieee802154_skb_is_intra_pan_addressing(__le16 fc, |
| 348 | const struct sk_buff *skb) |
| 349 | { |
| 350 | unsigned char *dst_pan = ieee802154_skb_dst_pan(fc, skb), |
| 351 | *src_pan = ieee802154_skb_src_pan(fc, skb); |
| 352 | |
| 353 | /* if one is NULL is no intra pan addressing */ |
| 354 | if (!dst_pan || !src_pan) |
| 355 | return false; |
| 356 | |
| 357 | return !memcmp(dst_pan, src_pan, IEEE802154_PAN_ID_LEN); |
| 358 | } |
| 359 | |
| 360 | /** |
Alexander Aring | 705cbbb | 2014-11-05 20:51:24 +0100 | [diff] [blame] | 361 | * ieee802154_be64_to_le64 - copies and convert be64 to le64 |
| 362 | * @le64_dst: le64 destination pointer |
| 363 | * @be64_src: be64 source pointer |
Alexander Aring | ab24f50 | 2014-11-02 04:18:40 +0100 | [diff] [blame] | 364 | */ |
Alexander Aring | 705cbbb | 2014-11-05 20:51:24 +0100 | [diff] [blame] | 365 | static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src) |
Alexander Aring | ab24f50 | 2014-11-02 04:18:40 +0100 | [diff] [blame] | 366 | { |
Alexander Aring | f160892 | 2016-03-04 10:10:20 +0100 | [diff] [blame] | 367 | put_unaligned_le64(get_unaligned_be64(be64_src), le64_dst); |
Alexander Aring | ab24f50 | 2014-11-02 04:18:40 +0100 | [diff] [blame] | 368 | } |
| 369 | |
Alexander Aring | 239a84a | 2014-11-05 20:51:23 +0100 | [diff] [blame] | 370 | /** |
| 371 | * ieee802154_le64_to_be64 - copies and convert le64 to be64 |
| 372 | * @be64_dst: be64 destination pointer |
| 373 | * @le64_src: le64 source pointer |
| 374 | */ |
| 375 | static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src) |
| 376 | { |
Alexander Aring | f160892 | 2016-03-04 10:10:20 +0100 | [diff] [blame] | 377 | put_unaligned_be64(get_unaligned_le64(le64_src), be64_dst); |
Alexander Aring | 239a84a | 2014-11-05 20:51:23 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 380 | /** |
Alexander Aring | 8911d77 | 2015-10-13 13:42:58 +0200 | [diff] [blame] | 381 | * ieee802154_le16_to_be16 - copies and convert le16 to be16 |
| 382 | * @be16_dst: be16 destination pointer |
| 383 | * @le16_src: le16 source pointer |
| 384 | */ |
| 385 | static inline void ieee802154_le16_to_be16(void *be16_dst, const void *le16_src) |
| 386 | { |
Alexander Aring | f160892 | 2016-03-04 10:10:20 +0100 | [diff] [blame] | 387 | put_unaligned_be16(get_unaligned_le16(le16_src), be16_dst); |
Alexander Aring | 8911d77 | 2015-10-13 13:42:58 +0200 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /** |
Alexander Aring | 118a5cf | 2016-04-11 11:04:15 +0200 | [diff] [blame] | 391 | * ieee802154_be16_to_le16 - copies and convert be16 to le16 |
| 392 | * @le16_dst: le16 destination pointer |
| 393 | * @be16_src: be16 source pointer |
| 394 | */ |
| 395 | static inline void ieee802154_be16_to_le16(void *le16_dst, const void *be16_src) |
| 396 | { |
| 397 | put_unaligned_le16(get_unaligned_be16(be16_src), le16_dst); |
| 398 | } |
| 399 | |
| 400 | /** |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 401 | * ieee802154_alloc_hw - Allocate a new hardware device |
| 402 | * |
| 403 | * This must be called once for each hardware device. The returned pointer |
| 404 | * must be used to refer to this device when calling other functions. |
| 405 | * mac802154 allocates a private data area for the driver pointed to by |
| 406 | * @priv in &struct ieee802154_hw, the size of this area is given as |
| 407 | * @priv_data_len. |
| 408 | * |
| 409 | * @priv_data_len: length of private data |
| 410 | * @ops: callbacks for this device |
| 411 | * |
| 412 | * Return: A pointer to the new hardware device, or %NULL on error. |
| 413 | */ |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 414 | struct ieee802154_hw * |
Alexander Aring | 1630186 | 2014-10-28 18:21:18 +0100 | [diff] [blame] | 415 | ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops); |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 416 | |
| 417 | /** |
| 418 | * ieee802154_free_hw - free hardware descriptor |
| 419 | * |
| 420 | * This function frees everything that was allocated, including the |
| 421 | * private data for the driver. You must call ieee802154_unregister_hw() |
| 422 | * before calling this function. |
| 423 | * |
| 424 | * @hw: the hardware to free |
| 425 | */ |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 426 | void ieee802154_free_hw(struct ieee802154_hw *hw); |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * ieee802154_register_hw - Register hardware device |
| 430 | * |
| 431 | * You must call this function before any other functions in |
| 432 | * mac802154. Note that before a hardware can be registered, you |
| 433 | * need to fill the contained wpan_phy's information. |
| 434 | * |
| 435 | * @hw: the device to register as returned by ieee802154_alloc_hw() |
| 436 | * |
| 437 | * Return: 0 on success. An error code otherwise. |
| 438 | */ |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 439 | int ieee802154_register_hw(struct ieee802154_hw *hw); |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 440 | |
| 441 | /** |
| 442 | * ieee802154_unregister_hw - Unregister a hardware device |
| 443 | * |
| 444 | * This function instructs mac802154 to free allocated resources |
| 445 | * and unregister netdevices from the networking subsystem. |
| 446 | * |
| 447 | * @hw: the hardware to unregister |
| 448 | */ |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 449 | void ieee802154_unregister_hw(struct ieee802154_hw *hw); |
alex.bluesman.smirnov@gmail.com | 1010f54 | 2012-05-15 20:50:20 +0000 | [diff] [blame] | 450 | |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 451 | /** |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 452 | * ieee802154_rx_irqsafe - receive frame |
| 453 | * |
| 454 | * Like ieee802154_rx() but can be called in IRQ context |
| 455 | * (internally defers to a tasklet.) |
| 456 | * |
| 457 | * @hw: the hardware this frame came in on |
| 458 | * @skb: the buffer to receive, owned by mac802154 after this call |
| 459 | * @lqi: link quality indicator |
| 460 | */ |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 461 | void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, |
alex.bluesman.smirnov@gmail.com | 1cd829c | 2012-05-15 20:50:21 +0000 | [diff] [blame] | 462 | u8 lqi); |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 463 | /** |
| 464 | * ieee802154_wake_queue - wake ieee802154 queue |
| 465 | * @hw: pointer as obtained from ieee802154_alloc_hw(). |
| 466 | * |
| 467 | * Drivers should use this function instead of netif_wake_queue. |
| 468 | */ |
Alexander Aring | c208510 | 2014-10-26 09:37:05 +0100 | [diff] [blame] | 469 | void ieee802154_wake_queue(struct ieee802154_hw *hw); |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * ieee802154_stop_queue - stop ieee802154 queue |
| 473 | * @hw: pointer as obtained from ieee802154_alloc_hw(). |
| 474 | * |
| 475 | * Drivers should use this function instead of netif_stop_queue. |
| 476 | */ |
Alexander Aring | c208510 | 2014-10-26 09:37:05 +0100 | [diff] [blame] | 477 | void ieee802154_stop_queue(struct ieee802154_hw *hw); |
Varka Bhadram | 42fb23e | 2015-04-30 17:44:52 +0200 | [diff] [blame] | 478 | |
| 479 | /** |
| 480 | * ieee802154_xmit_complete - frame transmission complete |
| 481 | * |
| 482 | * @hw: pointer as obtained from ieee802154_alloc_hw(). |
| 483 | * @skb: buffer for transmission |
| 484 | * @ifs_handling: indicate interframe space handling |
| 485 | */ |
Alexander Aring | 61f2dcb | 2014-11-12 19:51:56 +0100 | [diff] [blame] | 486 | void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, |
| 487 | bool ifs_handling); |
Alexander Aring | c208510 | 2014-10-26 09:37:05 +0100 | [diff] [blame] | 488 | |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 489 | #endif /* NET_MAC802154_H */ |