CRIS: UAPI: use generic sembuf.h
[linux-2.6/btrfs-unstable.git] / include / net / mac802154.h
blobb7f99615224bd05d7e4cb926aca27f14f44aab81
1 /*
2 * IEEE802.15.4-2003 specification
4 * Copyright (C) 2007-2012 Siemens AG
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.
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.
16 #ifndef NET_MAC802154_H
17 #define NET_MAC802154_H
19 #include <net/af_ieee802154.h>
20 #include <linux/ieee802154.h>
21 #include <linux/skbuff.h>
22 #include <linux/unaligned/memmove.h>
24 #include <net/cfg802154.h>
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
32 #define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14)
34 /**
35 * enum ieee802154_hw_addr_filt_flags - hardware address filtering flags
37 * The following flags are used to indicate changed address settings from
38 * the stack to the hardware.
40 * @IEEE802154_AFILT_SADDR_CHANGED: Indicates that the short address will be
41 * change.
43 * @IEEE802154_AFILT_IEEEADDR_CHANGED: Indicates that the extended address
44 * will be change.
46 * @IEEE802154_AFILT_PANID_CHANGED: Indicates that the pan id will be change.
48 * @IEEE802154_AFILT_PANC_CHANGED: Indicates that the address filter will
49 * do frame address filtering as a pan coordinator.
51 enum ieee802154_hw_addr_filt_flags {
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),
58 /**
59 * struct ieee802154_hw_addr_filt - hardware address filtering settings
61 * @pan_id: pan_id which should be set to the hardware address filter.
63 * @short_addr: short_addr which should be set to the hardware address filter.
65 * @ieee_addr: extended address which should be set to the hardware address
66 * filter.
68 * @pan_coord: boolean if hardware filtering should be operate as coordinator.
70 struct ieee802154_hw_addr_filt {
71 __le16 pan_id;
72 __le16 short_addr;
73 __le64 ieee_addr;
74 bool pan_coord;
77 /**
78 * struct ieee802154_hw - ieee802154 hardware
80 * @extra_tx_headroom: headroom to reserve in each transmit skb for use by the
81 * driver (e.g. for transmit headers.)
83 * @flags: hardware flags, see &enum ieee802154_hw_flags
85 * @parent: parent device of the hardware.
87 * @priv: pointer to private area that was allocated for driver use along with
88 * this structure.
90 * @phy: This points to the &struct wpan_phy allocated for this 802.15.4 PHY.
92 struct ieee802154_hw {
93 /* filled by the driver */
94 int extra_tx_headroom;
95 u32 flags;
96 struct device *parent;
97 void *priv;
99 /* filled by mac802154 core */
100 struct wpan_phy *phy;
104 * enum ieee802154_hw_flags - hardware flags
106 * These flags are used to indicate hardware capabilities to
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.
112 * @IEEE802154_HW_TX_OMIT_CKSUM: Indicates that xmitter will add FCS on it's
113 * own.
115 * @IEEE802154_HW_LBT: Indicates that transceiver will support listen before
116 * transmit.
118 * @IEEE802154_HW_CSMA_PARAMS: Indicates that transceiver will support csma
119 * parameters (max_be, min_be, backoff exponents).
121 * @IEEE802154_HW_FRAME_RETRIES: Indicates that transceiver will support ARET
122 * frame retries setting.
124 * @IEEE802154_HW_AFILT: Indicates that transceiver will support hardware
125 * address filter setting.
127 * @IEEE802154_HW_PROMISCUOUS: Indicates that transceiver will support
128 * promiscuous mode setting.
130 * @IEEE802154_HW_RX_OMIT_CKSUM: Indicates that receiver omits FCS.
132 * @IEEE802154_HW_RX_DROP_BAD_CKSUM: Indicates that receiver will not filter
133 * frames with bad checksum.
135 enum ieee802154_hw_flags {
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),
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)
150 /* struct ieee802154_ops - callbacks from mac802154 to the driver
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.
156 * start: Handler that 802.15.4 module calls for device initialization.
157 * This function is called before the first interface is attached.
159 * stop: Handler that 802.15.4 module calls for device cleanup.
160 * This function is called after the last interface is removed.
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.
170 * WARNING:
171 * This will be deprecated soon. We don't accept synced xmit callbacks
172 * drivers anymore.
174 * xmit_async:
175 * Handler that 802.15.4 module calls for each transmitted frame.
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.
179 * This function should return zero or negative errno.
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.
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.
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.
196 * set_txpower:
197 * Set radio transmit power in mBm. Called with pib_lock held.
198 * Returns either zero, or negative errno.
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.
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.
209 * set_cca_ed_level
210 * Sets the CCA energy detection threshold in mBm. Called with pib_lock
211 * held.
212 * Returns either zero, or negative errno.
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.
218 * set_frame_retries
219 * Sets the retransmission attempt limit. Called with pib_lock held.
220 * Returns either zero, or negative errno.
222 * set_promiscuous_mode
223 * Enables or disable promiscuous mode.
225 struct ieee802154_ops {
226 struct module *owner;
227 int (*start)(struct ieee802154_hw *hw);
228 void (*stop)(struct ieee802154_hw *hw);
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);
233 int (*ed)(struct ieee802154_hw *hw, u8 *level);
234 int (*set_channel)(struct ieee802154_hw *hw, u8 page,
235 u8 channel);
236 int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
237 struct ieee802154_hw_addr_filt *filt,
238 unsigned long changed);
239 int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm);
240 int (*set_lbt)(struct ieee802154_hw *hw, bool on);
241 int (*set_cca_mode)(struct ieee802154_hw *hw,
242 const struct wpan_phy_cca *cca);
243 int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm);
244 int (*set_csma_params)(struct ieee802154_hw *hw,
245 u8 min_be, u8 max_be, u8 retries);
246 int (*set_frame_retries)(struct ieee802154_hw *hw,
247 s8 retries);
248 int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
249 const bool on);
253 * ieee802154_be64_to_le64 - copies and convert be64 to le64
254 * @le64_dst: le64 destination pointer
255 * @be64_src: be64 source pointer
257 static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
259 __put_unaligned_memmove64(swab64p(be64_src), le64_dst);
263 * ieee802154_le64_to_be64 - copies and convert le64 to be64
264 * @be64_dst: be64 destination pointer
265 * @le64_src: le64 source pointer
267 static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
269 __put_unaligned_memmove64(swab64p(le64_src), be64_dst);
273 * ieee802154_alloc_hw - Allocate a new hardware device
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.
281 * @priv_data_len: length of private data
282 * @ops: callbacks for this device
284 * Return: A pointer to the new hardware device, or %NULL on error.
286 struct ieee802154_hw *
287 ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
290 * ieee802154_free_hw - free hardware descriptor
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.
296 * @hw: the hardware to free
298 void ieee802154_free_hw(struct ieee802154_hw *hw);
301 * ieee802154_register_hw - Register hardware device
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.
307 * @hw: the device to register as returned by ieee802154_alloc_hw()
309 * Return: 0 on success. An error code otherwise.
311 int ieee802154_register_hw(struct ieee802154_hw *hw);
314 * ieee802154_unregister_hw - Unregister a hardware device
316 * This function instructs mac802154 to free allocated resources
317 * and unregister netdevices from the networking subsystem.
319 * @hw: the hardware to unregister
321 void ieee802154_unregister_hw(struct ieee802154_hw *hw);
324 * ieee802154_rx_irqsafe - receive frame
326 * Like ieee802154_rx() but can be called in IRQ context
327 * (internally defers to a tasklet.)
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
333 void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
334 u8 lqi);
336 * ieee802154_wake_queue - wake ieee802154 queue
337 * @hw: pointer as obtained from ieee802154_alloc_hw().
339 * Drivers should use this function instead of netif_wake_queue.
341 void ieee802154_wake_queue(struct ieee802154_hw *hw);
344 * ieee802154_stop_queue - stop ieee802154 queue
345 * @hw: pointer as obtained from ieee802154_alloc_hw().
347 * Drivers should use this function instead of netif_stop_queue.
349 void ieee802154_stop_queue(struct ieee802154_hw *hw);
352 * ieee802154_xmit_complete - frame transmission complete
354 * @hw: pointer as obtained from ieee802154_alloc_hw().
355 * @skb: buffer for transmission
356 * @ifs_handling: indicate interframe space handling
358 void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
359 bool ifs_handling);
361 #endif /* NET_MAC802154_H */