mac802154: tx: squash multiple dereferencing
[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>
94b4f6c2 20#include <linux/skbuff.h>
0afd7ad9 21
32bad7e3 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
0afd7ad9 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 */
57205c14 35#define IEEE802154_AFILT_SADDR_CHANGED 0x00000001
0afd7ad9 36/* indicates that the IEEE Address changed */
57205c14 37#define IEEE802154_AFILT_IEEEADDR_CHANGED 0x00000002
0afd7ad9 38/* indicates that the PAN ID changed */
57205c14 39#define IEEE802154_AFILT_PANID_CHANGED 0x00000004
0afd7ad9 40/* indicates that PAN Coordinator status changed */
57205c14 41#define IEEE802154_AFILT_PANC_CHANGED 0x00000008
0afd7ad9 42
43struct 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;
b70ab2e8 51 __le64 ieee_addr;
0afd7ad9 52 u8 pan_coord;
53};
54
5a504397 55struct ieee802154_hw {
0afd7ad9 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
640985ec
AA
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)
0afd7ad9 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 *
112 * xmit: Handler that 802.15.4 module calls for each transmitted frame.
113 * skb cntains the buffer starting from the IEEE 802.15.4 header.
114 * The low-level driver should send the frame based on available
115 * configuration.
116 * This function should return zero or negative errno. Called with
117 * pib_lock held.
118 *
119 * ed: Handler that 802.15.4 module calls for Energy Detection.
120 * This function should place the value for detected energy
121 * (usually device-dependant) in the level pointer and return
122 * either zero or negative errno. Called with pib_lock held.
123 *
124 * set_channel:
125 * Set radio for listening on specific channel.
126 * Set the device for listening on specified channel.
127 * Returns either zero, or negative errno. Called with pib_lock held.
128 *
129 * set_hw_addr_filt:
130 * Set radio for listening on specific address.
131 * Set the device for listening on specified address.
132 * Returns either zero, or negative errno.
9b2777d6
PB
133 *
134 * set_txpower:
135 * Set radio transmit power in dB. Called with pib_lock held.
136 * Returns either zero, or negative errno.
84dda3c6
PB
137 *
138 * set_lbt
139 * Enables or disables listen before talk on the device. Called with
140 * pib_lock held.
141 * Returns either zero, or negative errno.
ba08fea5
PB
142 *
143 * set_cca_mode
144 * Sets the CCA mode used by the device. Called with pib_lock held.
145 * Returns either zero, or negative errno.
6ca00197
PB
146 *
147 * set_cca_ed_level
148 * Sets the CCA energy detection threshold in dBm. Called with pib_lock
149 * held.
150 * Returns either zero, or negative errno.
4244db1b
PB
151 *
152 * set_csma_params
153 * Sets the CSMA parameter set for the PHY. Called with pib_lock held.
154 * Returns either zero, or negative errno.
155 *
156 * set_frame_retries
157 * Sets the retransmission attempt limit. Called with pib_lock held.
158 * Returns either zero, or negative errno.
0afd7ad9 159 */
160struct ieee802154_ops {
161 struct module *owner;
5a504397
AA
162 int (*start)(struct ieee802154_hw *hw);
163 void (*stop)(struct ieee802154_hw *hw);
164 int (*xmit)(struct ieee802154_hw *hw,
0afd7ad9 165 struct sk_buff *skb);
5a504397
AA
166 int (*ed)(struct ieee802154_hw *hw, u8 *level);
167 int (*set_channel)(struct ieee802154_hw *hw,
0afd7ad9 168 int page,
169 int channel);
5a504397
AA
170 int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
171 struct ieee802154_hw_addr_filt *filt,
0afd7ad9 172 unsigned long changed);
5a504397
AA
173 int (*set_txpower)(struct ieee802154_hw *hw, int db);
174 int (*set_lbt)(struct ieee802154_hw *hw, bool on);
175 int (*set_cca_mode)(struct ieee802154_hw *hw, u8 mode);
176 int (*set_cca_ed_level)(struct ieee802154_hw *hw,
6ca00197 177 s32 level);
5a504397 178 int (*set_csma_params)(struct ieee802154_hw *hw,
4244db1b 179 u8 min_be, u8 max_be, u8 retries);
5a504397 180 int (*set_frame_retries)(struct ieee802154_hw *hw,
4244db1b 181 s8 retries);
0afd7ad9 182};
183
5a504397
AA
184/* Basic interface to register ieee802154 hwice */
185struct ieee802154_hw *
186ieee802154_alloc_hw(size_t priv_data_len, struct ieee802154_ops *ops);
187void ieee802154_free_hw(struct ieee802154_hw *hw);
188int ieee802154_register_hw(struct ieee802154_hw *hw);
189void ieee802154_unregister_hw(struct ieee802154_hw *hw);
1010f540 190
5a504397 191void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
1cd829c8 192 u8 lqi);
193
0afd7ad9 194#endif /* NET_MAC802154_H */