ieee802154: Add support for allowing to answer BEACON_REQ
[linux-block.git] / net / mac802154 / ieee802154_i.h
CommitLineData
1802d0be 1/* SPDX-License-Identifier: GPL-2.0-only */
1010f540 2/*
3 * Copyright (C) 2007-2012 Siemens AG
4 *
1010f540 5 * Written by:
6 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
7 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
8 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
9 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
10 */
0f1556bc
AA
11#ifndef __IEEE802154_I_H
12#define __IEEE802154_I_H
1010f540 13
282ccf6e 14#include <linux/interrupt.h>
f30be4d5 15#include <linux/mutex.h>
61f2dcba 16#include <linux/hrtimer.h>
d5ae67ba 17#include <net/cfg802154.h>
5d637d5a 18#include <net/mac802154.h>
944742a3 19#include <net/nl802154.h>
e462ded6
PB
20#include <net/ieee802154_netdev.h>
21
f30be4d5
PB
22#include "llsec.h"
23
57588c71
MR
24enum ieee802154_ongoing {
25 IEEE802154_IS_SCANNING = BIT(0),
3accf476 26 IEEE802154_IS_BEACONING = BIT(1),
57588c71
MR
27};
28
1010f540 29/* mac802154 device private data */
a5e1ec53 30struct ieee802154_local {
5a504397 31 struct ieee802154_hw hw;
16301861 32 const struct ieee802154_ops *ops;
1010f540 33
ac8037c3
AA
34 /* hardware address filter */
35 struct ieee802154_hw_addr_filt addr_filt;
1010f540 36 /* ieee802154 phy */
37 struct wpan_phy *phy;
38
39 int open_count;
40
41 /* As in mac80211 slaves list is modified:
42 * 1) under the RTNL
43 * 2) protected by slaves_mtx;
44 * 3) in an RCU manner
45 *
46 * So atomic readers can use any of this protection methods.
47 */
d98be45b
AA
48 struct list_head interfaces;
49 struct mutex iflist_mtx;
1010f540 50
57588c71 51 /* Data related workqueue */
f7730542 52 struct workqueue_struct *workqueue;
57588c71
MR
53 /* MAC commands related workqueue */
54 struct workqueue_struct *mac_wq;
1010f540 55
61f2dcba
AA
56 struct hrtimer ifs_timer;
57
57588c71
MR
58 /* Scanning */
59 u8 scan_page;
60 u8 scan_channel;
e2c3e6f5 61 struct ieee802154_beacon_req_frame scan_beacon_req;
57588c71
MR
62 struct cfg802154_scan_request __rcu *scan_req;
63 struct delayed_work scan_work;
64
3accf476
MR
65 /* Beaconing */
66 unsigned int beacon_interval;
67 struct ieee802154_beacon_frame beacon;
68 struct cfg802154_beacon_request __rcu *beacon_req;
69 struct delayed_work beacon_work;
70
57588c71
MR
71 /* Asynchronous tasks */
72 struct list_head rx_beacon_list;
73 struct work_struct rx_beacon_work;
74
5d65cae4 75 bool started;
3cf24cf8 76 bool suspended;
57588c71 77 unsigned long ongoing;
c5c47e67
AA
78
79 struct tasklet_struct tasklet;
80 struct sk_buff_head skb_queue;
c22ff7b4
LB
81
82 struct sk_buff *tx_skb;
983a974b 83 struct work_struct sync_tx_work;
337e2f86
MR
84 /* A negative Linux error code or a null/positive MLME error status */
85 int tx_result;
1010f540 86};
87
c5c47e67
AA
88enum {
89 IEEE802154_RX_MSG = 1,
90};
91
0ea3da64
AA
92enum ieee802154_sdata_state_bits {
93 SDATA_STATE_RUNNING,
94};
95
4d23c9cc 96/* Slave interface definition.
97 *
98 * Slaves represent typical network interfaces available from userspace.
99 * Each ieee802154 device/transceiver may have several slaves and able
100 * to be associated with several networks at the same time.
101 */
036562f9 102struct ieee802154_sub_if_data {
4d23c9cc 103 struct list_head list; /* the ieee802154_priv->slaves list */
104
d5ae67ba
AA
105 struct wpan_dev wpan_dev;
106
04e850fe 107 struct ieee802154_local *local;
4d23c9cc 108 struct net_device *dev;
109
ac8037c3
AA
110 /* Each interface starts and works in nominal state at a given filtering
111 * level given by iface_default_filtering, which is set once for all at
112 * the interface creation and should not evolve over time. For some MAC
113 * operations however, the filtering level may change temporarily, as
114 * reflected in the required_filtering field. The actual filtering at
115 * the PHY level may be different and is shown in struct wpan_phy.
116 */
117 enum ieee802154_filtering_level iface_default_filtering;
118 enum ieee802154_filtering_level required_filtering;
119
0ea3da64 120 unsigned long state;
d5ae67ba 121 char name[IFNAMSIZ];
4d23c9cc 122
f30be4d5
PB
123 /* protects sec from concurrent access by netlink. access by
124 * encrypt/decrypt/header_create safe without additional protection.
125 */
126 struct mutex sec_mtx;
127
128 struct mac802154_llsec sec;
4d23c9cc 129};
130
6322d50d
AA
131/* utility functions/constants */
132extern const void *const mac802154_wpan_phy_privid; /* for wpan_phy privid */
133
60741361
AA
134static inline struct ieee802154_local *
135hw_to_local(struct ieee802154_hw *hw)
136{
137 return container_of(hw, struct ieee802154_local, hw);
138}
139
59d19cd7
AA
140static inline struct ieee802154_sub_if_data *
141IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
142{
143 return netdev_priv(dev);
144}
145
b821ecd4
AA
146static inline struct ieee802154_sub_if_data *
147IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
148{
149 return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
150}
151
0ea3da64
AA
152static inline bool
153ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
154{
155 return test_bit(SDATA_STATE_RUNNING, &sdata->state);
156}
157
32bad7e3 158extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
6e2128d4 159
d10270ce 160void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
be8c6d86 161void ieee802154_xmit_sync_worker(struct work_struct *work);
f0feb349 162int ieee802154_sync_and_hold_queue(struct ieee802154_local *local);
ddd9ee7c 163int ieee802154_mlme_op_pre(struct ieee802154_local *local);
fbdaa5ba
MR
164int ieee802154_mlme_tx(struct ieee802154_local *local,
165 struct ieee802154_sub_if_data *sdata,
166 struct sk_buff *skb);
dd180962
MR
167int ieee802154_mlme_tx_locked(struct ieee802154_local *local,
168 struct ieee802154_sub_if_data *sdata,
169 struct sk_buff *skb);
ddd9ee7c 170void ieee802154_mlme_op_post(struct ieee802154_local *local);
fbdaa5ba
MR
171int ieee802154_mlme_tx_one(struct ieee802154_local *local,
172 struct ieee802154_sub_if_data *sdata,
173 struct sk_buff *skb);
dd180962
MR
174int ieee802154_mlme_tx_one_locked(struct ieee802154_local *local,
175 struct ieee802154_sub_if_data *sdata,
176 struct sk_buff *skb);
e5e584fc
AA
177netdev_tx_t
178ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
e5e584fc
AA
179netdev_tx_t
180ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
61f2dcba 181enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
5b641ebe 182
20a19d1d
MR
183/**
184 * ieee802154_hold_queue - hold ieee802154 queue
185 * @local: main mac object
186 *
187 * Hold a queue by incrementing an atomic counter and requesting the netif
188 * queues to be stopped. The queues cannot be woken up while the counter has not
189 * been reset with as any ieee802154_release_queue() calls as needed.
190 */
191void ieee802154_hold_queue(struct ieee802154_local *local);
192
193/**
194 * ieee802154_release_queue - release ieee802154 queue
195 * @local: main mac object
196 *
197 * Release a queue which is held by decrementing an atomic counter and wake it
198 * up only if the counter reaches 0.
199 */
200void ieee802154_release_queue(struct ieee802154_local *local);
201
a40612f3
MR
202/**
203 * ieee802154_disable_queue - disable ieee802154 queue
204 * @local: main mac object
205 *
206 * When trying to sync the Tx queue, we cannot just stop the queue
207 * (which is basically a bit being set without proper lock handling)
208 * because it would be racy. We actually need to call netif_tx_disable()
209 * instead, which is done by this helper. Restarting the queue can
210 * however still be done with a regular wake call.
211 */
212void ieee802154_disable_queue(struct ieee802154_local *local);
213
ef2486f5 214/* MIB callbacks */
66b69d4d 215void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
ef2486f5 216
29e02374
PB
217int mac802154_get_params(struct net_device *dev,
218 struct ieee802154_llsec_params *params);
219int mac802154_set_params(struct net_device *dev,
220 const struct ieee802154_llsec_params *params,
221 int changed);
222
223int mac802154_add_key(struct net_device *dev,
224 const struct ieee802154_llsec_key_id *id,
225 const struct ieee802154_llsec_key *key);
226int mac802154_del_key(struct net_device *dev,
227 const struct ieee802154_llsec_key_id *id);
228
229int mac802154_add_dev(struct net_device *dev,
230 const struct ieee802154_llsec_device *llsec_dev);
231int mac802154_del_dev(struct net_device *dev, __le64 dev_addr);
232
233int mac802154_add_devkey(struct net_device *dev,
234 __le64 device_addr,
235 const struct ieee802154_llsec_device_key *key);
236int mac802154_del_devkey(struct net_device *dev,
237 __le64 device_addr,
238 const struct ieee802154_llsec_device_key *key);
239
240int mac802154_add_seclevel(struct net_device *dev,
241 const struct ieee802154_llsec_seclevel *sl);
242int mac802154_del_seclevel(struct net_device *dev,
243 const struct ieee802154_llsec_seclevel *sl);
244
245void mac802154_lock_table(struct net_device *dev);
246void mac802154_get_table(struct net_device *dev,
247 struct ieee802154_llsec_table **t);
248void mac802154_unlock_table(struct net_device *dev);
249
d77b4852
AA
250int mac802154_wpan_update_llsec(struct net_device *dev);
251
57588c71
MR
252/* PAN management handling */
253void mac802154_scan_worker(struct work_struct *work);
254int mac802154_trigger_scan_locked(struct ieee802154_sub_if_data *sdata,
255 struct cfg802154_scan_request *request);
256int mac802154_abort_scan_locked(struct ieee802154_local *local,
257 struct ieee802154_sub_if_data *sdata);
258int mac802154_process_beacon(struct ieee802154_local *local,
259 struct sk_buff *skb,
260 u8 page, u8 channel);
261void mac802154_rx_beacon_worker(struct work_struct *work);
262
263static inline bool mac802154_is_scanning(struct ieee802154_local *local)
264{
265 return test_bit(IEEE802154_IS_SCANNING, &local->ongoing);
266}
267
3accf476
MR
268void mac802154_beacon_worker(struct work_struct *work);
269int mac802154_send_beacons_locked(struct ieee802154_sub_if_data *sdata,
270 struct cfg802154_beacon_request *request);
271int mac802154_stop_beacons_locked(struct ieee802154_local *local,
272 struct ieee802154_sub_if_data *sdata);
273
274static inline bool mac802154_is_beaconing(struct ieee802154_local *local)
275{
276 return test_bit(IEEE802154_IS_BEACONING, &local->ongoing);
277}
278
be4fd8e5
AA
279/* interface handling */
280int ieee802154_iface_init(void);
281void ieee802154_iface_exit(void);
b210b187 282void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
986a8abf
AA
283struct net_device *
284ieee802154_if_add(struct ieee802154_local *local, const char *name,
5b4a1039
VB
285 unsigned char name_assign_type, enum nl802154_iftype type,
286 __le64 extended_addr);
592dfbfc 287void ieee802154_remove_interfaces(struct ieee802154_local *local);
c4227c8a 288void ieee802154_stop_device(struct ieee802154_local *local);
4a9a816a 289
0f1556bc 290#endif /* __IEEE802154_I_H */