]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/net/mac802154.h
ieee802154: rework cca setting
[mirror_ubuntu-jammy-kernel.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>
0afd7ad9 22
7fe9a388
AA
23#include <net/cfg802154.h>
24
32bad7e3 25/* General MAC frame format:
26 * 2 bytes: Frame Control
27 * 1 byte: Sequence Number
28 * 20 bytes: Addressing fields
29 * 14 bytes: Auxiliary Security Header
30 */
31#define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14)
32
0afd7ad9 33/* The following flags are used to indicate changed address settings from
34 * the stack to the hardware.
35 */
36
37/* indicates that the Short Address changed */
57205c14 38#define IEEE802154_AFILT_SADDR_CHANGED 0x00000001
0afd7ad9 39/* indicates that the IEEE Address changed */
57205c14 40#define IEEE802154_AFILT_IEEEADDR_CHANGED 0x00000002
0afd7ad9 41/* indicates that the PAN ID changed */
57205c14 42#define IEEE802154_AFILT_PANID_CHANGED 0x00000004
0afd7ad9 43/* indicates that PAN Coordinator status changed */
57205c14 44#define IEEE802154_AFILT_PANC_CHANGED 0x00000008
0afd7ad9 45
46struct ieee802154_hw_addr_filt {
47 __le16 pan_id; /* Each independent PAN selects a unique
48 * identifier. This PAN id allows communication
49 * between devices within a network using short
50 * addresses and enables transmissions between
51 * devices across independent networks.
52 */
53 __le16 short_addr;
b70ab2e8 54 __le64 ieee_addr;
0afd7ad9 55 u8 pan_coord;
56};
57
7c118c1a
AA
58struct ieee802154_vif {
59 int type;
60
61 /* must be last */
62 u8 drv_priv[0] __aligned(sizeof(void *));
63};
64
5a504397 65struct ieee802154_hw {
0afd7ad9 66 /* filled by the driver */
67 int extra_tx_headroom;
68 u32 flags;
69 struct device *parent;
70
71 /* filled by mac802154 core */
72 struct ieee802154_hw_addr_filt hw_filt;
73 void *priv;
74 struct wpan_phy *phy;
7c118c1a 75 size_t vif_data_size;
0afd7ad9 76};
77
78/* Checksum is in hardware and is omitted from a packet
79 *
80 * These following flags are used to indicate hardware capabilities to
81 * the stack. Generally, flags here should have their meaning
82 * done in a way that the simplest hardware doesn't need setting
83 * any particular flags. There are some exceptions to this rule,
84 * however, so you are advised to review these flags carefully.
85 */
86
90386a7e
AA
87/* Indicates that xmitter will add FCS on it's own. */
88#define IEEE802154_HW_TX_OMIT_CKSUM 0x00000001
0afd7ad9 89/* Indicates that receiver will autorespond with ACK frames. */
90a6161d 90#define IEEE802154_HW_AACK 0x00000002
640985ec 91/* Indicates that transceiver will support transmit power setting. */
90a6161d 92#define IEEE802154_HW_TXPOWER 0x00000004
640985ec 93/* Indicates that transceiver will support listen before transmit. */
90a6161d 94#define IEEE802154_HW_LBT 0x00000008
640985ec 95/* Indicates that transceiver will support cca mode setting. */
90a6161d 96#define IEEE802154_HW_CCA_MODE 0x00000010
640985ec 97/* Indicates that transceiver will support cca ed level setting. */
90a6161d 98#define IEEE802154_HW_CCA_ED_LEVEL 0x00000020
640985ec
AA
99/* Indicates that transceiver will support csma (max_be, min_be, csma retries)
100 * settings. */
90a6161d 101#define IEEE802154_HW_CSMA_PARAMS 0x00000040
640985ec 102/* Indicates that transceiver will support ARET frame retries setting. */
90a6161d 103#define IEEE802154_HW_FRAME_RETRIES 0x00000080
c8fc84ed
AA
104/* Indicates that transceiver will support hardware address filter setting. */
105#define IEEE802154_HW_AFILT 0x00000100
94b79222
AA
106/* Indicates that transceiver will support promiscuous mode setting. */
107#define IEEE802154_HW_PROMISCUOUS 0x00000200
90386a7e
AA
108/* Indicates that receiver omits FCS. */
109#define IEEE802154_HW_RX_OMIT_CKSUM 0x00000400
ec718f3d
AA
110/* Indicates that receiver will not filter frames with bad checksum. */
111#define IEEE802154_HW_RX_DROP_BAD_CKSUM 0x00000800
90386a7e
AA
112
113/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
114#define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \
115 IEEE802154_HW_RX_OMIT_CKSUM)
640985ec
AA
116
117/* This groups the most common CSMA support fields into one. */
118#define IEEE802154_HW_CSMA (IEEE802154_HW_CCA_MODE | \
119 IEEE802154_HW_CCA_ED_LEVEL | \
ab79be3e
AA
120 IEEE802154_HW_CSMA_PARAMS)
121
122/* This groups the most common ARET support fields into one. */
123#define IEEE802154_HW_ARET (IEEE802154_HW_CSMA | \
640985ec 124 IEEE802154_HW_FRAME_RETRIES)
0afd7ad9 125
126/* struct ieee802154_ops - callbacks from mac802154 to the driver
127 *
128 * This structure contains various callbacks that the driver may
129 * handle or, in some cases, must handle, for example to transmit
130 * a frame.
131 *
132 * start: Handler that 802.15.4 module calls for device initialization.
133 * This function is called before the first interface is attached.
134 *
135 * stop: Handler that 802.15.4 module calls for device cleanup.
136 * This function is called after the last interface is removed.
137 *
ed0a5dce
AA
138 * xmit_sync:
139 * Handler that 802.15.4 module calls for each transmitted frame.
140 * skb cntains the buffer starting from the IEEE 802.15.4 header.
141 * The low-level driver should send the frame based on available
142 * configuration. This is called by a workqueue and useful for
143 * synchronous 802.15.4 drivers.
144 * This function should return zero or negative errno.
145 *
1e7283a2
AA
146 * WARNING:
147 * This will be deprecated soon. We don't accept synced xmit callbacks
148 * drivers anymore.
149 *
ed0a5dce
AA
150 * xmit_async:
151 * Handler that 802.15.4 module calls for each transmitted frame.
0afd7ad9 152 * skb cntains the buffer starting from the IEEE 802.15.4 header.
153 * The low-level driver should send the frame based on available
154 * configuration.
dc67c6b3 155 * This function should return zero or negative errno.
0afd7ad9 156 *
157 * ed: Handler that 802.15.4 module calls for Energy Detection.
158 * This function should place the value for detected energy
159 * (usually device-dependant) in the level pointer and return
160 * either zero or negative errno. Called with pib_lock held.
161 *
162 * set_channel:
163 * Set radio for listening on specific channel.
164 * Set the device for listening on specified channel.
165 * Returns either zero, or negative errno. Called with pib_lock held.
166 *
167 * set_hw_addr_filt:
168 * Set radio for listening on specific address.
169 * Set the device for listening on specified address.
170 * Returns either zero, or negative errno.
9b2777d6
PB
171 *
172 * set_txpower:
173 * Set radio transmit power in dB. Called with pib_lock held.
174 * Returns either zero, or negative errno.
84dda3c6
PB
175 *
176 * set_lbt
177 * Enables or disables listen before talk on the device. Called with
178 * pib_lock held.
179 * Returns either zero, or negative errno.
ba08fea5
PB
180 *
181 * set_cca_mode
182 * Sets the CCA mode used by the device. Called with pib_lock held.
183 * Returns either zero, or negative errno.
6ca00197
PB
184 *
185 * set_cca_ed_level
186 * Sets the CCA energy detection threshold in dBm. Called with pib_lock
187 * held.
188 * Returns either zero, or negative errno.
4244db1b
PB
189 *
190 * set_csma_params
191 * Sets the CSMA parameter set for the PHY. Called with pib_lock held.
192 * Returns either zero, or negative errno.
193 *
194 * set_frame_retries
195 * Sets the retransmission attempt limit. Called with pib_lock held.
196 * Returns either zero, or negative errno.
94b79222
AA
197 *
198 * set_promiscuous_mode
199 * Enables or disable promiscuous mode.
0afd7ad9 200 */
201struct ieee802154_ops {
202 struct module *owner;
5a504397
AA
203 int (*start)(struct ieee802154_hw *hw);
204 void (*stop)(struct ieee802154_hw *hw);
ed0a5dce
AA
205 int (*xmit_sync)(struct ieee802154_hw *hw,
206 struct sk_buff *skb);
207 int (*xmit_async)(struct ieee802154_hw *hw,
208 struct sk_buff *skb);
5a504397 209 int (*ed)(struct ieee802154_hw *hw, u8 *level);
e37d2ec8
AA
210 int (*set_channel)(struct ieee802154_hw *hw, u8 page,
211 u8 channel);
5a504397
AA
212 int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
213 struct ieee802154_hw_addr_filt *filt,
0afd7ad9 214 unsigned long changed);
5a504397
AA
215 int (*set_txpower)(struct ieee802154_hw *hw, int db);
216 int (*set_lbt)(struct ieee802154_hw *hw, bool on);
7fe9a388
AA
217 int (*set_cca_mode)(struct ieee802154_hw *hw,
218 const struct wpan_phy_cca *cca);
5a504397 219 int (*set_cca_ed_level)(struct ieee802154_hw *hw,
6ca00197 220 s32 level);
5a504397 221 int (*set_csma_params)(struct ieee802154_hw *hw,
4244db1b 222 u8 min_be, u8 max_be, u8 retries);
5a504397 223 int (*set_frame_retries)(struct ieee802154_hw *hw,
4244db1b 224 s8 retries);
94b79222
AA
225 int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
226 const bool on);
0afd7ad9 227};
228
ab24f50f 229/**
705cbbbe
AA
230 * ieee802154_be64_to_le64 - copies and convert be64 to le64
231 * @le64_dst: le64 destination pointer
232 * @be64_src: be64 source pointer
ab24f50f 233 */
705cbbbe 234static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
ab24f50f 235{
705cbbbe
AA
236 __le64 tmp = (__force __le64)swab64p(be64_src);
237
238 memcpy(le64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
ab24f50f
AA
239}
240
239a84a9
AA
241/**
242 * ieee802154_le64_to_be64 - copies and convert le64 to be64
243 * @be64_dst: be64 destination pointer
244 * @le64_src: le64 source pointer
245 */
246static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
247{
248 __be64 tmp = (__force __be64)swab64p(le64_src);
249
250 memcpy(be64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
251}
252
5a504397
AA
253/* Basic interface to register ieee802154 hwice */
254struct ieee802154_hw *
16301861 255ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
5a504397
AA
256void ieee802154_free_hw(struct ieee802154_hw *hw);
257int ieee802154_register_hw(struct ieee802154_hw *hw);
258void ieee802154_unregister_hw(struct ieee802154_hw *hw);
1010f540 259
c5c47e67 260void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb);
5a504397 261void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
1cd829c8 262 u8 lqi);
263
c2085103
AA
264void ieee802154_wake_queue(struct ieee802154_hw *hw);
265void ieee802154_stop_queue(struct ieee802154_hw *hw);
61f2dcba
AA
266void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
267 bool ifs_handling);
c2085103 268
0afd7ad9 269#endif /* NET_MAC802154_H */