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 | |
| 19 | #include <net/af_ieee802154.h> |
Alexander Aring | 239a84a | 2014-11-05 20:51:23 +0100 | [diff] [blame] | 20 | #include <linux/ieee802154.h> |
Phoebe Buckheister | 94b4f6c | 2014-03-14 21:24:00 +0100 | [diff] [blame] | 21 | #include <linux/skbuff.h> |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 22 | |
alex.bluesman.smirnov@gmail.com | 32bad7e | 2012-06-25 23:24:48 +0000 | [diff] [blame] | 23 | /* General MAC frame format: |
| 24 | * 2 bytes: Frame Control |
| 25 | * 1 byte: Sequence Number |
| 26 | * 20 bytes: Addressing fields |
| 27 | * 14 bytes: Auxiliary Security Header |
| 28 | */ |
| 29 | #define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14) |
| 30 | |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 31 | /* The following flags are used to indicate changed address settings from |
| 32 | * the stack to the hardware. |
| 33 | */ |
| 34 | |
| 35 | /* indicates that the Short Address changed */ |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 36 | #define IEEE802154_AFILT_SADDR_CHANGED 0x00000001 |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 37 | /* indicates that the IEEE Address changed */ |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 38 | #define IEEE802154_AFILT_IEEEADDR_CHANGED 0x00000002 |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 39 | /* indicates that the PAN ID changed */ |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 40 | #define IEEE802154_AFILT_PANID_CHANGED 0x00000004 |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 41 | /* indicates that PAN Coordinator status changed */ |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 42 | #define IEEE802154_AFILT_PANC_CHANGED 0x00000008 |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 43 | |
| 44 | struct ieee802154_hw_addr_filt { |
| 45 | __le16 pan_id; /* Each independent PAN selects a unique |
| 46 | * identifier. This PAN id allows communication |
| 47 | * between devices within a network using short |
| 48 | * addresses and enables transmissions between |
| 49 | * devices across independent networks. |
| 50 | */ |
| 51 | __le16 short_addr; |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 52 | __le64 ieee_addr; |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 53 | u8 pan_coord; |
| 54 | }; |
| 55 | |
Alexander Aring | 7c118c1 | 2014-11-05 20:51:20 +0100 | [diff] [blame] | 56 | struct ieee802154_vif { |
| 57 | int type; |
| 58 | |
| 59 | /* must be last */ |
| 60 | u8 drv_priv[0] __aligned(sizeof(void *)); |
| 61 | }; |
| 62 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 63 | struct ieee802154_hw { |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 64 | /* filled by the driver */ |
| 65 | int extra_tx_headroom; |
| 66 | u32 flags; |
| 67 | struct device *parent; |
| 68 | |
| 69 | /* filled by mac802154 core */ |
| 70 | struct ieee802154_hw_addr_filt hw_filt; |
| 71 | void *priv; |
| 72 | struct wpan_phy *phy; |
Alexander Aring | 7c118c1 | 2014-11-05 20:51:20 +0100 | [diff] [blame] | 73 | size_t vif_data_size; |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /* Checksum is in hardware and is omitted from a packet |
| 77 | * |
| 78 | * These following flags are used to indicate hardware capabilities to |
| 79 | * the stack. Generally, flags here should have their meaning |
| 80 | * done in a way that the simplest hardware doesn't need setting |
| 81 | * any particular flags. There are some exceptions to this rule, |
| 82 | * however, so you are advised to review these flags carefully. |
| 83 | */ |
| 84 | |
Alexander Aring | 90386a7 | 2014-10-29 21:34:34 +0100 | [diff] [blame] | 85 | /* Indicates that xmitter will add FCS on it's own. */ |
| 86 | #define IEEE802154_HW_TX_OMIT_CKSUM 0x00000001 |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 87 | /* Indicates that receiver will autorespond with ACK frames. */ |
Alexander Aring | 90a6161 | 2014-10-29 21:34:29 +0100 | [diff] [blame] | 88 | #define IEEE802154_HW_AACK 0x00000002 |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 89 | /* Indicates that transceiver will support transmit power setting. */ |
Alexander Aring | 90a6161 | 2014-10-29 21:34:29 +0100 | [diff] [blame] | 90 | #define IEEE802154_HW_TXPOWER 0x00000004 |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 91 | /* Indicates that transceiver will support listen before transmit. */ |
Alexander Aring | 90a6161 | 2014-10-29 21:34:29 +0100 | [diff] [blame] | 92 | #define IEEE802154_HW_LBT 0x00000008 |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 93 | /* Indicates that transceiver will support cca mode setting. */ |
Alexander Aring | 90a6161 | 2014-10-29 21:34:29 +0100 | [diff] [blame] | 94 | #define IEEE802154_HW_CCA_MODE 0x00000010 |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 95 | /* Indicates that transceiver will support cca ed level setting. */ |
Alexander Aring | 90a6161 | 2014-10-29 21:34:29 +0100 | [diff] [blame] | 96 | #define IEEE802154_HW_CCA_ED_LEVEL 0x00000020 |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 97 | /* Indicates that transceiver will support csma (max_be, min_be, csma retries) |
| 98 | * settings. */ |
Alexander Aring | 90a6161 | 2014-10-29 21:34:29 +0100 | [diff] [blame] | 99 | #define IEEE802154_HW_CSMA_PARAMS 0x00000040 |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 100 | /* Indicates that transceiver will support ARET frame retries setting. */ |
Alexander Aring | 90a6161 | 2014-10-29 21:34:29 +0100 | [diff] [blame] | 101 | #define IEEE802154_HW_FRAME_RETRIES 0x00000080 |
Alexander Aring | c8fc84e | 2014-10-29 21:34:31 +0100 | [diff] [blame] | 102 | /* Indicates that transceiver will support hardware address filter setting. */ |
| 103 | #define IEEE802154_HW_AFILT 0x00000100 |
Alexander Aring | 94b7922 | 2014-10-29 21:34:32 +0100 | [diff] [blame] | 104 | /* Indicates that transceiver will support promiscuous mode setting. */ |
| 105 | #define IEEE802154_HW_PROMISCUOUS 0x00000200 |
Alexander Aring | 90386a7 | 2014-10-29 21:34:34 +0100 | [diff] [blame] | 106 | /* Indicates that receiver omits FCS. */ |
| 107 | #define IEEE802154_HW_RX_OMIT_CKSUM 0x00000400 |
Alexander Aring | ec718f3 | 2014-10-29 21:34:37 +0100 | [diff] [blame] | 108 | /* Indicates that receiver will not filter frames with bad checksum. */ |
| 109 | #define IEEE802154_HW_RX_DROP_BAD_CKSUM 0x00000800 |
Alexander Aring | 90386a7 | 2014-10-29 21:34:34 +0100 | [diff] [blame] | 110 | |
| 111 | /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */ |
| 112 | #define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \ |
| 113 | IEEE802154_HW_RX_OMIT_CKSUM) |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 114 | |
| 115 | /* This groups the most common CSMA support fields into one. */ |
| 116 | #define IEEE802154_HW_CSMA (IEEE802154_HW_CCA_MODE | \ |
| 117 | IEEE802154_HW_CCA_ED_LEVEL | \ |
Alexander Aring | ab79be3 | 2014-10-29 21:34:30 +0100 | [diff] [blame] | 118 | IEEE802154_HW_CSMA_PARAMS) |
| 119 | |
| 120 | /* This groups the most common ARET support fields into one. */ |
| 121 | #define IEEE802154_HW_ARET (IEEE802154_HW_CSMA | \ |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 122 | IEEE802154_HW_FRAME_RETRIES) |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 123 | |
| 124 | /* struct ieee802154_ops - callbacks from mac802154 to the driver |
| 125 | * |
| 126 | * This structure contains various callbacks that the driver may |
| 127 | * handle or, in some cases, must handle, for example to transmit |
| 128 | * a frame. |
| 129 | * |
| 130 | * start: Handler that 802.15.4 module calls for device initialization. |
| 131 | * This function is called before the first interface is attached. |
| 132 | * |
| 133 | * stop: Handler that 802.15.4 module calls for device cleanup. |
| 134 | * This function is called after the last interface is removed. |
| 135 | * |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 136 | * xmit_sync: |
| 137 | * Handler that 802.15.4 module calls for each transmitted frame. |
| 138 | * skb cntains the buffer starting from the IEEE 802.15.4 header. |
| 139 | * The low-level driver should send the frame based on available |
| 140 | * configuration. This is called by a workqueue and useful for |
| 141 | * synchronous 802.15.4 drivers. |
| 142 | * This function should return zero or negative errno. |
| 143 | * |
Alexander Aring | 1e7283a | 2014-10-26 09:37:14 +0100 | [diff] [blame] | 144 | * WARNING: |
| 145 | * This will be deprecated soon. We don't accept synced xmit callbacks |
| 146 | * drivers anymore. |
| 147 | * |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 148 | * xmit_async: |
| 149 | * 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] | 150 | * skb cntains the buffer starting from the IEEE 802.15.4 header. |
| 151 | * The low-level driver should send the frame based on available |
| 152 | * configuration. |
Alexander Aring | dc67c6b | 2014-10-26 09:37:04 +0100 | [diff] [blame] | 153 | * This function should return zero or negative errno. |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 154 | * |
| 155 | * ed: Handler that 802.15.4 module calls for Energy Detection. |
| 156 | * This function should place the value for detected energy |
| 157 | * (usually device-dependant) in the level pointer and return |
| 158 | * either zero or negative errno. Called with pib_lock held. |
| 159 | * |
| 160 | * set_channel: |
| 161 | * Set radio for listening on specific channel. |
| 162 | * Set the device for listening on specified channel. |
| 163 | * Returns either zero, or negative errno. Called with pib_lock held. |
| 164 | * |
| 165 | * set_hw_addr_filt: |
| 166 | * Set radio for listening on specific address. |
| 167 | * Set the device for listening on specified address. |
| 168 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 9b2777d | 2014-02-17 11:34:08 +0100 | [diff] [blame] | 169 | * |
| 170 | * set_txpower: |
| 171 | * Set radio transmit power in dB. Called with pib_lock held. |
| 172 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 84dda3c | 2014-02-17 11:34:10 +0100 | [diff] [blame] | 173 | * |
| 174 | * set_lbt |
| 175 | * Enables or disables listen before talk on the device. Called with |
| 176 | * pib_lock held. |
| 177 | * Returns either zero, or negative errno. |
Phoebe Buckheister | ba08fea | 2014-02-17 11:34:11 +0100 | [diff] [blame] | 178 | * |
| 179 | * set_cca_mode |
| 180 | * Sets the CCA mode used by the device. Called with pib_lock held. |
| 181 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 182 | * |
| 183 | * set_cca_ed_level |
| 184 | * Sets the CCA energy detection threshold in dBm. Called with pib_lock |
| 185 | * held. |
| 186 | * Returns either zero, or negative errno. |
Phoebe Buckheister | 4244db1 | 2014-02-17 11:34:14 +0100 | [diff] [blame] | 187 | * |
| 188 | * set_csma_params |
| 189 | * Sets the CSMA parameter set for the PHY. Called with pib_lock held. |
| 190 | * Returns either zero, or negative errno. |
| 191 | * |
| 192 | * set_frame_retries |
| 193 | * Sets the retransmission attempt limit. Called with pib_lock held. |
| 194 | * Returns either zero, or negative errno. |
Alexander Aring | 94b7922 | 2014-10-29 21:34:32 +0100 | [diff] [blame] | 195 | * |
| 196 | * set_promiscuous_mode |
| 197 | * Enables or disable promiscuous mode. |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 198 | */ |
| 199 | struct ieee802154_ops { |
| 200 | struct module *owner; |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 201 | int (*start)(struct ieee802154_hw *hw); |
| 202 | void (*stop)(struct ieee802154_hw *hw); |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 203 | int (*xmit_sync)(struct ieee802154_hw *hw, |
| 204 | struct sk_buff *skb); |
| 205 | int (*xmit_async)(struct ieee802154_hw *hw, |
| 206 | struct sk_buff *skb); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 207 | int (*ed)(struct ieee802154_hw *hw, u8 *level); |
Alexander Aring | e37d2ec | 2014-10-28 18:21:19 +0100 | [diff] [blame] | 208 | int (*set_channel)(struct ieee802154_hw *hw, u8 page, |
| 209 | u8 channel); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 210 | int (*set_hw_addr_filt)(struct ieee802154_hw *hw, |
| 211 | struct ieee802154_hw_addr_filt *filt, |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 212 | unsigned long changed); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 213 | int (*set_txpower)(struct ieee802154_hw *hw, int db); |
| 214 | int (*set_lbt)(struct ieee802154_hw *hw, bool on); |
| 215 | int (*set_cca_mode)(struct ieee802154_hw *hw, u8 mode); |
| 216 | int (*set_cca_ed_level)(struct ieee802154_hw *hw, |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 217 | s32 level); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 218 | int (*set_csma_params)(struct ieee802154_hw *hw, |
Phoebe Buckheister | 4244db1 | 2014-02-17 11:34:14 +0100 | [diff] [blame] | 219 | u8 min_be, u8 max_be, u8 retries); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 220 | int (*set_frame_retries)(struct ieee802154_hw *hw, |
Phoebe Buckheister | 4244db1 | 2014-02-17 11:34:14 +0100 | [diff] [blame] | 221 | s8 retries); |
Alexander Aring | 94b7922 | 2014-10-29 21:34:32 +0100 | [diff] [blame] | 222 | int (*set_promiscuous_mode)(struct ieee802154_hw *hw, |
| 223 | const bool on); |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
Alexander Aring | ab24f50 | 2014-11-02 04:18:40 +0100 | [diff] [blame] | 226 | /** |
Alexander Aring | 705cbbb | 2014-11-05 20:51:24 +0100 | [diff] [blame] | 227 | * ieee802154_be64_to_le64 - copies and convert be64 to le64 |
| 228 | * @le64_dst: le64 destination pointer |
| 229 | * @be64_src: be64 source pointer |
Alexander Aring | ab24f50 | 2014-11-02 04:18:40 +0100 | [diff] [blame] | 230 | */ |
Alexander Aring | 705cbbb | 2014-11-05 20:51:24 +0100 | [diff] [blame] | 231 | 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] | 232 | { |
Alexander Aring | 705cbbb | 2014-11-05 20:51:24 +0100 | [diff] [blame] | 233 | __le64 tmp = (__force __le64)swab64p(be64_src); |
| 234 | |
| 235 | memcpy(le64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN); |
Alexander Aring | ab24f50 | 2014-11-02 04:18:40 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Alexander Aring | 239a84a | 2014-11-05 20:51:23 +0100 | [diff] [blame] | 238 | /** |
| 239 | * ieee802154_le64_to_be64 - copies and convert le64 to be64 |
| 240 | * @be64_dst: be64 destination pointer |
| 241 | * @le64_src: le64 source pointer |
| 242 | */ |
| 243 | static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src) |
| 244 | { |
| 245 | __be64 tmp = (__force __be64)swab64p(le64_src); |
| 246 | |
| 247 | memcpy(be64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN); |
| 248 | } |
| 249 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 250 | /* Basic interface to register ieee802154 hwice */ |
| 251 | struct ieee802154_hw * |
Alexander Aring | 1630186 | 2014-10-28 18:21:18 +0100 | [diff] [blame] | 252 | ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 253 | void ieee802154_free_hw(struct ieee802154_hw *hw); |
| 254 | int ieee802154_register_hw(struct ieee802154_hw *hw); |
| 255 | void ieee802154_unregister_hw(struct ieee802154_hw *hw); |
alex.bluesman.smirnov@gmail.com | 1010f54 | 2012-05-15 20:50:20 +0000 | [diff] [blame] | 256 | |
Alexander Aring | c5c47e6 | 2014-10-27 17:13:30 +0100 | [diff] [blame] | 257 | void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 258 | 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] | 259 | u8 lqi); |
| 260 | |
Alexander Aring | c208510 | 2014-10-26 09:37:05 +0100 | [diff] [blame] | 261 | void ieee802154_wake_queue(struct ieee802154_hw *hw); |
| 262 | void ieee802154_stop_queue(struct ieee802154_hw *hw); |
Alexander Aring | 61f2dcb | 2014-11-12 19:51:56 +0100 | [diff] [blame^] | 263 | void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, |
| 264 | bool ifs_handling); |
Alexander Aring | c208510 | 2014-10-26 09:37:05 +0100 | [diff] [blame] | 265 | |
alex.bluesman.smirnov@gmail.com | 0afd7ad | 2012-05-15 20:50:19 +0000 | [diff] [blame] | 266 | #endif /* NET_MAC802154_H */ |