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