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)
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
43 * @IEEE802154_AFILT_IEEEADDR_CHANGED: Indicates that the extended address
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(1),
53 IEEE802154_AFILT_IEEEADDR_CHANGED = BIT(2),
54 IEEE802154_AFILT_PANID_CHANGED = BIT(3),
55 IEEE802154_AFILT_PANC_CHANGED = BIT(4),
58 struct 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.
70 struct ieee802154_hw {
71 /* filled by the driver */
72 int extra_tx_headroom;
74 struct device *parent;
76 /* filled by mac802154 core */
77 struct ieee802154_hw_addr_filt hw_filt;
83 * enum ieee802154_hw_flags - hardware flags
85 * These flags are used to indicate hardware capabilities to
86 * the stack. Generally, flags here should have their meaning
87 * done in a way that the simplest hardware doesn't need setting
88 * any particular flags. There are some exceptions to this rule,
89 * however, so you are advised to review these flags carefully.
91 * @IEEE802154_HW_TX_OMIT_CKSUM: Indicates that xmitter will add FCS on it's
94 * @IEEE802154_HW_LBT: Indicates that transceiver will support listen before
97 * @IEEE802154_HW_CSMA_PARAMS: Indicates that transceiver will support csma
98 * parameters (max_be, min_be, backoff exponents).
100 * @IEEE802154_HW_FRAME_RETRIES: Indicates that transceiver will support ARET
101 * frame retries setting.
103 * @IEEE802154_HW_AFILT: Indicates that transceiver will support hardware
104 * address filter setting.
106 * @IEEE802154_HW_PROMISCUOUS: Indicates that transceiver will support
107 * promiscuous mode setting.
109 * @IEEE802154_HW_RX_OMIT_CKSUM: Indicates that receiver omits FCS.
111 * @IEEE802154_HW_RX_DROP_BAD_CKSUM: Indicates that receiver will not filter
112 * frames with bad checksum.
114 enum ieee802154_hw_flags {
115 IEEE802154_HW_TX_OMIT_CKSUM = BIT(1),
116 IEEE802154_HW_LBT = BIT(2),
117 IEEE802154_HW_CSMA_PARAMS = BIT(3),
118 IEEE802154_HW_FRAME_RETRIES = BIT(4),
119 IEEE802154_HW_AFILT = BIT(5),
120 IEEE802154_HW_PROMISCUOUS = BIT(6),
121 IEEE802154_HW_RX_OMIT_CKSUM = BIT(7),
122 IEEE802154_HW_RX_DROP_BAD_CKSUM = BIT(8),
125 /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
126 #define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \
127 IEEE802154_HW_RX_OMIT_CKSUM)
129 /* struct ieee802154_ops - callbacks from mac802154 to the driver
131 * This structure contains various callbacks that the driver may
132 * handle or, in some cases, must handle, for example to transmit
135 * start: Handler that 802.15.4 module calls for device initialization.
136 * This function is called before the first interface is attached.
138 * stop: Handler that 802.15.4 module calls for device cleanup.
139 * This function is called after the last interface is removed.
142 * Handler that 802.15.4 module calls for each transmitted frame.
143 * skb cntains the buffer starting from the IEEE 802.15.4 header.
144 * The low-level driver should send the frame based on available
145 * configuration. This is called by a workqueue and useful for
146 * synchronous 802.15.4 drivers.
147 * This function should return zero or negative errno.
150 * This will be deprecated soon. We don't accept synced xmit callbacks
154 * Handler that 802.15.4 module calls for each transmitted frame.
155 * skb cntains the buffer starting from the IEEE 802.15.4 header.
156 * The low-level driver should send the frame based on available
158 * This function should return zero or negative errno.
160 * ed: Handler that 802.15.4 module calls for Energy Detection.
161 * This function should place the value for detected energy
162 * (usually device-dependant) in the level pointer and return
163 * either zero or negative errno. Called with pib_lock held.
166 * Set radio for listening on specific channel.
167 * Set the device for listening on specified channel.
168 * Returns either zero, or negative errno. Called with pib_lock held.
171 * Set radio for listening on specific address.
172 * Set the device for listening on specified address.
173 * Returns either zero, or negative errno.
176 * Set radio transmit power in mBm. Called with pib_lock held.
177 * Returns either zero, or negative errno.
180 * Enables or disables listen before talk on the device. Called with
182 * Returns either zero, or negative errno.
185 * Sets the CCA mode used by the device. Called with pib_lock held.
186 * Returns either zero, or negative errno.
189 * Sets the CCA energy detection threshold in mBm. Called with pib_lock
191 * Returns either zero, or negative errno.
194 * Sets the CSMA parameter set for the PHY. Called with pib_lock held.
195 * Returns either zero, or negative errno.
198 * Sets the retransmission attempt limit. Called with pib_lock held.
199 * Returns either zero, or negative errno.
201 * set_promiscuous_mode
202 * Enables or disable promiscuous mode.
204 struct ieee802154_ops {
205 struct module *owner;
206 int (*start)(struct ieee802154_hw *hw);
207 void (*stop)(struct ieee802154_hw *hw);
208 int (*xmit_sync)(struct ieee802154_hw *hw,
209 struct sk_buff *skb);
210 int (*xmit_async)(struct ieee802154_hw *hw,
211 struct sk_buff *skb);
212 int (*ed)(struct ieee802154_hw *hw, u8 *level);
213 int (*set_channel)(struct ieee802154_hw *hw, u8 page,
215 int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
216 struct ieee802154_hw_addr_filt *filt,
217 unsigned long changed);
218 int (*set_txpower)(struct ieee802154_hw *hw, s32 mbm);
219 int (*set_lbt)(struct ieee802154_hw *hw, bool on);
220 int (*set_cca_mode)(struct ieee802154_hw *hw,
221 const struct wpan_phy_cca *cca);
222 int (*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm);
223 int (*set_csma_params)(struct ieee802154_hw *hw,
224 u8 min_be, u8 max_be, u8 retries);
225 int (*set_frame_retries)(struct ieee802154_hw *hw,
227 int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
232 * ieee802154_be64_to_le64 - copies and convert be64 to le64
233 * @le64_dst: le64 destination pointer
234 * @be64_src: be64 source pointer
236 static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
238 __put_unaligned_memmove64(swab64p(be64_src), le64_dst);
242 * ieee802154_le64_to_be64 - copies and convert le64 to be64
243 * @be64_dst: be64 destination pointer
244 * @le64_src: le64 source pointer
246 static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
248 __put_unaligned_memmove64(swab64p(le64_src), be64_dst);
252 * ieee802154_alloc_hw - Allocate a new hardware device
254 * This must be called once for each hardware device. The returned pointer
255 * must be used to refer to this device when calling other functions.
256 * mac802154 allocates a private data area for the driver pointed to by
257 * @priv in &struct ieee802154_hw, the size of this area is given as
260 * @priv_data_len: length of private data
261 * @ops: callbacks for this device
263 * Return: A pointer to the new hardware device, or %NULL on error.
265 struct ieee802154_hw *
266 ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
269 * ieee802154_free_hw - free hardware descriptor
271 * This function frees everything that was allocated, including the
272 * private data for the driver. You must call ieee802154_unregister_hw()
273 * before calling this function.
275 * @hw: the hardware to free
277 void ieee802154_free_hw(struct ieee802154_hw *hw);
280 * ieee802154_register_hw - Register hardware device
282 * You must call this function before any other functions in
283 * mac802154. Note that before a hardware can be registered, you
284 * need to fill the contained wpan_phy's information.
286 * @hw: the device to register as returned by ieee802154_alloc_hw()
288 * Return: 0 on success. An error code otherwise.
290 int ieee802154_register_hw(struct ieee802154_hw *hw);
293 * ieee802154_unregister_hw - Unregister a hardware device
295 * This function instructs mac802154 to free allocated resources
296 * and unregister netdevices from the networking subsystem.
298 * @hw: the hardware to unregister
300 void ieee802154_unregister_hw(struct ieee802154_hw *hw);
303 * ieee802154_rx - receive frame
305 * Use this function to hand received frames to mac802154. The receive
306 * buffer in @skb must start with an IEEE 802.15.4 header. In case of a
307 * paged @skb is used, the driver is recommended to put the ieee802154
308 * header of the frame on the linear part of the @skb to avoid memory
309 * allocation and/or memcpy by the stack.
311 * This function may not be called in IRQ context. Calls to this function
312 * for a single hardware must be synchronized against each other.
314 * @hw: the hardware this frame came in on
315 * @skb: the buffer to receive, owned by mac802154 after this call
317 void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb);
320 * ieee802154_rx_irqsafe - receive frame
322 * Like ieee802154_rx() but can be called in IRQ context
323 * (internally defers to a tasklet.)
325 * @hw: the hardware this frame came in on
326 * @skb: the buffer to receive, owned by mac802154 after this call
327 * @lqi: link quality indicator
329 void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
332 * ieee802154_wake_queue - wake ieee802154 queue
333 * @hw: pointer as obtained from ieee802154_alloc_hw().
335 * Drivers should use this function instead of netif_wake_queue.
337 void ieee802154_wake_queue(struct ieee802154_hw *hw);
340 * ieee802154_stop_queue - stop ieee802154 queue
341 * @hw: pointer as obtained from ieee802154_alloc_hw().
343 * Drivers should use this function instead of netif_stop_queue.
345 void ieee802154_stop_queue(struct ieee802154_hw *hw);
348 * ieee802154_xmit_complete - frame transmission complete
350 * @hw: pointer as obtained from ieee802154_alloc_hw().
351 * @skb: buffer for transmission
352 * @ifs_handling: indicate interframe space handling
354 void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
357 #endif /* NET_MAC802154_H */