mac802154: remove aack hw flag
[linux-block.git] / include / net / mac802154.h
CommitLineData
0afd7ad9 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 *
0afd7ad9 15 */
16#ifndef NET_MAC802154_H
17#define NET_MAC802154_H
18
19#include <net/af_ieee802154.h>
239a84a9 20#include <linux/ieee802154.h>
94b4f6c2 21#include <linux/skbuff.h>
ba5bf17e 22#include <linux/unaligned/memmove.h>
0afd7ad9 23
7fe9a388
AA
24#include <net/cfg802154.h>
25
32bad7e3 26/* General MAC frame format:
27 * 2 bytes: Frame Control
28 * 1 byte: Sequence Number
29 * 20 bytes: Addressing fields
30 * 14 bytes: Auxiliary Security Header
31 */
32#define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14)
33
6b70a43c
AA
34/**
35 * enum ieee802154_hw_addr_filt_flags - hardware address filtering flags
36 *
37 * The following flags are used to indicate changed address settings from
0afd7ad9 38 * the stack to the hardware.
6b70a43c
AA
39 *
40 * @IEEE802154_AFILT_SADDR_CHANGED: Indicates that the short address will be
41 * change.
42 *
43 * @IEEE802154_AFILT_IEEEADDR_CHANGED: Indicates that the extended address
44 * will be change.
45 *
46 * @IEEE802154_AFILT_PANID_CHANGED: Indicates that the pan id will be change.
47 *
48 * @IEEE802154_AFILT_PANC_CHANGED: Indicates that the address filter will
49 * do frame address filtering as a pan coordinator.
0afd7ad9 50 */
6b70a43c
AA
51enum ieee802154_hw_addr_filt_flags {
52 IEEE802154_AFILT_SADDR_CHANGED = BIT(1),
53 IEEE802154_AFILT_IEEEADDR_CHANGED = BIT(2),
54 IEEE802154_AFILT_PANID_CHANGED = BIT(3),
55 IEEE802154_AFILT_PANC_CHANGED = BIT(4),
56};
0afd7ad9 57
58struct ieee802154_hw_addr_filt {
59 __le16 pan_id; /* Each independent PAN selects a unique
60 * identifier. This PAN id allows communication
61 * between devices within a network using short
62 * addresses and enables transmissions between
63 * devices across independent networks.
64 */
65 __le16 short_addr;
b70ab2e8 66 __le64 ieee_addr;
0afd7ad9 67 u8 pan_coord;
68};
69
5a504397 70struct ieee802154_hw {
0afd7ad9 71 /* filled by the driver */
72 int extra_tx_headroom;
73 u32 flags;
74 struct device *parent;
75
76 /* filled by mac802154 core */
77 struct ieee802154_hw_addr_filt hw_filt;
78 void *priv;
79 struct wpan_phy *phy;
80};
81
82/* Checksum is in hardware and is omitted from a packet
83 *
84 * These following flags are used to indicate hardware capabilities to
85 * the stack. Generally, flags here should have their meaning
86 * done in a way that the simplest hardware doesn't need setting
87 * any particular flags. There are some exceptions to this rule,
88 * however, so you are advised to review these flags carefully.
89 */
90
90386a7e
AA
91/* Indicates that xmitter will add FCS on it's own. */
92#define IEEE802154_HW_TX_OMIT_CKSUM 0x00000001
640985ec 93/* Indicates that transceiver will support listen before transmit. */
edea8f7c 94#define IEEE802154_HW_LBT 0x00000004
640985ec
AA
95/* Indicates that transceiver will support csma (max_be, min_be, csma retries)
96 * settings. */
edea8f7c 97#define IEEE802154_HW_CSMA_PARAMS 0x00000008
640985ec 98/* Indicates that transceiver will support ARET frame retries setting. */
edea8f7c 99#define IEEE802154_HW_FRAME_RETRIES 0x00000010
c8fc84ed 100/* Indicates that transceiver will support hardware address filter setting. */
edea8f7c 101#define IEEE802154_HW_AFILT 0x00000020
94b79222 102/* Indicates that transceiver will support promiscuous mode setting. */
edea8f7c 103#define IEEE802154_HW_PROMISCUOUS 0x00000040
90386a7e 104/* Indicates that receiver omits FCS. */
edea8f7c 105#define IEEE802154_HW_RX_OMIT_CKSUM 0x00000080
ec718f3d 106/* Indicates that receiver will not filter frames with bad checksum. */
edea8f7c 107#define IEEE802154_HW_RX_DROP_BAD_CKSUM 0x00000100
90386a7e
AA
108
109/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
110#define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \
111 IEEE802154_HW_RX_OMIT_CKSUM)
640985ec 112
0afd7ad9 113/* struct ieee802154_ops - callbacks from mac802154 to the driver
114 *
115 * This structure contains various callbacks that the driver may
116 * handle or, in some cases, must handle, for example to transmit
117 * a frame.
118 *
119 * start: Handler that 802.15.4 module calls for device initialization.
120 * This function is called before the first interface is attached.
121 *
122 * stop: Handler that 802.15.4 module calls for device cleanup.
123 * This function is called after the last interface is removed.
124 *
ed0a5dce
AA
125 * xmit_sync:
126 * Handler that 802.15.4 module calls for each transmitted frame.
127 * skb cntains the buffer starting from the IEEE 802.15.4 header.
128 * The low-level driver should send the frame based on available
129 * configuration. This is called by a workqueue and useful for
130 * synchronous 802.15.4 drivers.
131 * This function should return zero or negative errno.
132 *
1e7283a2
AA
133 * WARNING:
134 * This will be deprecated soon. We don't accept synced xmit callbacks
135 * drivers anymore.
136 *
ed0a5dce
AA
137 * xmit_async:
138 * Handler that 802.15.4 module calls for each transmitted frame.
0afd7ad9 139 * skb cntains the buffer starting from the IEEE 802.15.4 header.
140 * The low-level driver should send the frame based on available
141 * configuration.
dc67c6b3 142 * This function should return zero or negative errno.
0afd7ad9 143 *
144 * ed: Handler that 802.15.4 module calls for Energy Detection.
145 * This function should place the value for detected energy
146 * (usually device-dependant) in the level pointer and return
147 * either zero or negative errno. Called with pib_lock held.
148 *
149 * set_channel:
150 * Set radio for listening on specific channel.
151 * Set the device for listening on specified channel.
152 * Returns either zero, or negative errno. Called with pib_lock held.
153 *
154 * set_hw_addr_filt:
155 * Set radio for listening on specific address.
156 * Set the device for listening on specified address.
157 * Returns either zero, or negative errno.
9b2777d6
PB
158 *
159 * set_txpower:
e2eb173a 160 * Set radio transmit power in mBm. Called with pib_lock held.
9b2777d6 161 * Returns either zero, or negative errno.
84dda3c6
PB
162 *
163 * set_lbt
164 * Enables or disables listen before talk on the device. Called with
165 * pib_lock held.
166 * Returns either zero, or negative errno.
ba08fea5
PB
167 *
168 * set_cca_mode
169 * Sets the CCA mode used by the device. Called with pib_lock held.
170 * Returns either zero, or negative errno.
6ca00197
PB
171 *
172 * set_cca_ed_level
32b23550 173 * Sets the CCA energy detection threshold in mBm. Called with pib_lock
6ca00197
PB
174 * held.
175 * Returns either zero, or negative errno.
4244db1b
PB
176 *
177 * set_csma_params
178 * Sets the CSMA parameter set for the PHY. Called with pib_lock held.
179 * Returns either zero, or negative errno.
180 *
181 * set_frame_retries
182 * Sets the retransmission attempt limit. Called with pib_lock held.
183 * Returns either zero, or negative errno.
94b79222
AA
184 *
185 * set_promiscuous_mode
186 * Enables or disable promiscuous mode.
0afd7ad9 187 */
188struct ieee802154_ops {
189 struct module *owner;
5a504397
AA
190 int (*start)(struct ieee802154_hw *hw);
191 void (*stop)(struct ieee802154_hw *hw);
ed0a5dce
AA
192 int (*xmit_sync)(struct ieee802154_hw *hw,
193 struct sk_buff *skb);
194 int (*xmit_async)(struct ieee802154_hw *hw,
195 struct sk_buff *skb);
5a504397 196 int (*ed)(struct ieee802154_hw *hw, u8 *level);
e37d2ec8
AA
197 int (*set_channel)(struct ieee802154_hw *hw, u8 page,
198 u8 channel);
5a504397
AA
199 int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
200 struct ieee802154_hw_addr_filt *filt,
0afd7ad9 201 unsigned long changed);
e2eb173a 202 int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm);
5a504397 203 int (*set_lbt)(struct ieee802154_hw *hw, bool on);
7fe9a388
AA
204 int (*set_cca_mode)(struct ieee802154_hw *hw,
205 const struct wpan_phy_cca *cca);
32b23550 206 int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm);
5a504397 207 int (*set_csma_params)(struct ieee802154_hw *hw,
4244db1b 208 u8 min_be, u8 max_be, u8 retries);
5a504397 209 int (*set_frame_retries)(struct ieee802154_hw *hw,
4244db1b 210 s8 retries);
94b79222
AA
211 int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
212 const bool on);
0afd7ad9 213};
214
ab24f50f 215/**
705cbbbe
AA
216 * ieee802154_be64_to_le64 - copies and convert be64 to le64
217 * @le64_dst: le64 destination pointer
218 * @be64_src: be64 source pointer
ab24f50f 219 */
705cbbbe 220static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
ab24f50f 221{
ba5bf17e 222 __put_unaligned_memmove64(swab64p(be64_src), le64_dst);
ab24f50f
AA
223}
224
239a84a9
AA
225/**
226 * ieee802154_le64_to_be64 - copies and convert le64 to be64
227 * @be64_dst: be64 destination pointer
228 * @le64_src: le64 source pointer
229 */
230static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
231{
b9767969 232 __put_unaligned_memmove64(swab64p(le64_src), be64_dst);
239a84a9
AA
233}
234
42fb23e2
VB
235/**
236 * ieee802154_alloc_hw - Allocate a new hardware device
237 *
238 * This must be called once for each hardware device. The returned pointer
239 * must be used to refer to this device when calling other functions.
240 * mac802154 allocates a private data area for the driver pointed to by
241 * @priv in &struct ieee802154_hw, the size of this area is given as
242 * @priv_data_len.
243 *
244 * @priv_data_len: length of private data
245 * @ops: callbacks for this device
246 *
247 * Return: A pointer to the new hardware device, or %NULL on error.
248 */
5a504397 249struct ieee802154_hw *
16301861 250ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
42fb23e2
VB
251
252/**
253 * ieee802154_free_hw - free hardware descriptor
254 *
255 * This function frees everything that was allocated, including the
256 * private data for the driver. You must call ieee802154_unregister_hw()
257 * before calling this function.
258 *
259 * @hw: the hardware to free
260 */
5a504397 261void ieee802154_free_hw(struct ieee802154_hw *hw);
42fb23e2
VB
262
263/**
264 * ieee802154_register_hw - Register hardware device
265 *
266 * You must call this function before any other functions in
267 * mac802154. Note that before a hardware can be registered, you
268 * need to fill the contained wpan_phy's information.
269 *
270 * @hw: the device to register as returned by ieee802154_alloc_hw()
271 *
272 * Return: 0 on success. An error code otherwise.
273 */
5a504397 274int ieee802154_register_hw(struct ieee802154_hw *hw);
42fb23e2
VB
275
276/**
277 * ieee802154_unregister_hw - Unregister a hardware device
278 *
279 * This function instructs mac802154 to free allocated resources
280 * and unregister netdevices from the networking subsystem.
281 *
282 * @hw: the hardware to unregister
283 */
5a504397 284void ieee802154_unregister_hw(struct ieee802154_hw *hw);
1010f540 285
42fb23e2
VB
286/**
287 * ieee802154_rx - receive frame
288 *
289 * Use this function to hand received frames to mac802154. The receive
290 * buffer in @skb must start with an IEEE 802.15.4 header. In case of a
291 * paged @skb is used, the driver is recommended to put the ieee802154
292 * header of the frame on the linear part of the @skb to avoid memory
293 * allocation and/or memcpy by the stack.
294 *
295 * This function may not be called in IRQ context. Calls to this function
296 * for a single hardware must be synchronized against each other.
297 *
298 * @hw: the hardware this frame came in on
299 * @skb: the buffer to receive, owned by mac802154 after this call
300 */
c5c47e67 301void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb);
42fb23e2
VB
302
303/**
304 * ieee802154_rx_irqsafe - receive frame
305 *
306 * Like ieee802154_rx() but can be called in IRQ context
307 * (internally defers to a tasklet.)
308 *
309 * @hw: the hardware this frame came in on
310 * @skb: the buffer to receive, owned by mac802154 after this call
311 * @lqi: link quality indicator
312 */
5a504397 313void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
1cd829c8 314 u8 lqi);
42fb23e2
VB
315/**
316 * ieee802154_wake_queue - wake ieee802154 queue
317 * @hw: pointer as obtained from ieee802154_alloc_hw().
318 *
319 * Drivers should use this function instead of netif_wake_queue.
320 */
c2085103 321void ieee802154_wake_queue(struct ieee802154_hw *hw);
42fb23e2
VB
322
323/**
324 * ieee802154_stop_queue - stop ieee802154 queue
325 * @hw: pointer as obtained from ieee802154_alloc_hw().
326 *
327 * Drivers should use this function instead of netif_stop_queue.
328 */
c2085103 329void ieee802154_stop_queue(struct ieee802154_hw *hw);
42fb23e2
VB
330
331/**
332 * ieee802154_xmit_complete - frame transmission complete
333 *
334 * @hw: pointer as obtained from ieee802154_alloc_hw().
335 * @skb: buffer for transmission
336 * @ifs_handling: indicate interframe space handling
337 */
61f2dcba
AA
338void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
339 bool ifs_handling);
c2085103 340
0afd7ad9 341#endif /* NET_MAC802154_H */