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