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