Commit | Line | Data |
---|---|---|
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 |
24 | enum 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 | 30 | struct 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; | |
d021d218 MR |
74 | struct list_head rx_mac_cmd_list; |
75 | struct work_struct rx_mac_cmd_work; | |
57588c71 | 76 | |
5d65cae4 | 77 | bool started; |
3cf24cf8 | 78 | bool suspended; |
57588c71 | 79 | unsigned long ongoing; |
c5c47e67 AA |
80 | |
81 | struct tasklet_struct tasklet; | |
82 | struct sk_buff_head skb_queue; | |
c22ff7b4 LB |
83 | |
84 | struct sk_buff *tx_skb; | |
983a974b | 85 | struct work_struct sync_tx_work; |
337e2f86 MR |
86 | /* A negative Linux error code or a null/positive MLME error status */ |
87 | int tx_result; | |
1010f540 | 88 | }; |
89 | ||
c5c47e67 AA |
90 | enum { |
91 | IEEE802154_RX_MSG = 1, | |
92 | }; | |
93 | ||
0ea3da64 AA |
94 | enum ieee802154_sdata_state_bits { |
95 | SDATA_STATE_RUNNING, | |
96 | }; | |
97 | ||
4d23c9cc | 98 | /* Slave interface definition. |
99 | * | |
100 | * Slaves represent typical network interfaces available from userspace. | |
101 | * Each ieee802154 device/transceiver may have several slaves and able | |
102 | * to be associated with several networks at the same time. | |
103 | */ | |
036562f9 | 104 | struct ieee802154_sub_if_data { |
4d23c9cc | 105 | struct list_head list; /* the ieee802154_priv->slaves list */ |
106 | ||
d5ae67ba AA |
107 | struct wpan_dev wpan_dev; |
108 | ||
04e850fe | 109 | struct ieee802154_local *local; |
4d23c9cc | 110 | struct net_device *dev; |
111 | ||
ac8037c3 AA |
112 | /* Each interface starts and works in nominal state at a given filtering |
113 | * level given by iface_default_filtering, which is set once for all at | |
114 | * the interface creation and should not evolve over time. For some MAC | |
115 | * operations however, the filtering level may change temporarily, as | |
116 | * reflected in the required_filtering field. The actual filtering at | |
117 | * the PHY level may be different and is shown in struct wpan_phy. | |
118 | */ | |
119 | enum ieee802154_filtering_level iface_default_filtering; | |
120 | enum ieee802154_filtering_level required_filtering; | |
121 | ||
0ea3da64 | 122 | unsigned long state; |
d5ae67ba | 123 | char name[IFNAMSIZ]; |
4d23c9cc | 124 | |
f30be4d5 PB |
125 | /* protects sec from concurrent access by netlink. access by |
126 | * encrypt/decrypt/header_create safe without additional protection. | |
127 | */ | |
128 | struct mutex sec_mtx; | |
129 | ||
130 | struct mac802154_llsec sec; | |
4d23c9cc | 131 | }; |
132 | ||
6322d50d AA |
133 | /* utility functions/constants */ |
134 | extern const void *const mac802154_wpan_phy_privid; /* for wpan_phy privid */ | |
135 | ||
60741361 AA |
136 | static inline struct ieee802154_local * |
137 | hw_to_local(struct ieee802154_hw *hw) | |
138 | { | |
139 | return container_of(hw, struct ieee802154_local, hw); | |
140 | } | |
141 | ||
59d19cd7 AA |
142 | static inline struct ieee802154_sub_if_data * |
143 | IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev) | |
144 | { | |
145 | return netdev_priv(dev); | |
146 | } | |
147 | ||
b821ecd4 AA |
148 | static inline struct ieee802154_sub_if_data * |
149 | IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev) | |
150 | { | |
151 | return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev); | |
152 | } | |
153 | ||
0ea3da64 AA |
154 | static inline bool |
155 | ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata) | |
156 | { | |
157 | return test_bit(SDATA_STATE_RUNNING, &sdata->state); | |
158 | } | |
159 | ||
d021d218 MR |
160 | static inline int ieee802154_get_mac_cmd(struct sk_buff *skb, u8 *mac_cmd) |
161 | { | |
162 | struct ieee802154_mac_cmd_pl mac_pl; | |
163 | int ret; | |
164 | ||
165 | if (mac_cb(skb)->type != IEEE802154_FC_TYPE_MAC_CMD) | |
166 | return -EINVAL; | |
167 | ||
168 | ret = ieee802154_mac_cmd_pl_pull(skb, &mac_pl); | |
169 | if (ret) | |
170 | return ret; | |
171 | ||
172 | *mac_cmd = mac_pl.cmd_id; | |
173 | return 0; | |
174 | } | |
175 | ||
32bad7e3 | 176 | extern struct ieee802154_mlme_ops mac802154_mlme_wpan; |
6e2128d4 | 177 | |
d10270ce | 178 | void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb); |
be8c6d86 | 179 | void ieee802154_xmit_sync_worker(struct work_struct *work); |
f0feb349 | 180 | int ieee802154_sync_and_hold_queue(struct ieee802154_local *local); |
ddd9ee7c | 181 | int ieee802154_mlme_op_pre(struct ieee802154_local *local); |
fbdaa5ba MR |
182 | int ieee802154_mlme_tx(struct ieee802154_local *local, |
183 | struct ieee802154_sub_if_data *sdata, | |
184 | struct sk_buff *skb); | |
dd180962 MR |
185 | int ieee802154_mlme_tx_locked(struct ieee802154_local *local, |
186 | struct ieee802154_sub_if_data *sdata, | |
187 | struct sk_buff *skb); | |
ddd9ee7c | 188 | void ieee802154_mlme_op_post(struct ieee802154_local *local); |
fbdaa5ba MR |
189 | int ieee802154_mlme_tx_one(struct ieee802154_local *local, |
190 | struct ieee802154_sub_if_data *sdata, | |
191 | struct sk_buff *skb); | |
dd180962 MR |
192 | int ieee802154_mlme_tx_one_locked(struct ieee802154_local *local, |
193 | struct ieee802154_sub_if_data *sdata, | |
194 | struct sk_buff *skb); | |
e5e584fc AA |
195 | netdev_tx_t |
196 | ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev); | |
e5e584fc AA |
197 | netdev_tx_t |
198 | ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev); | |
61f2dcba | 199 | enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer); |
5b641ebe | 200 | |
20a19d1d MR |
201 | /** |
202 | * ieee802154_hold_queue - hold ieee802154 queue | |
203 | * @local: main mac object | |
204 | * | |
205 | * Hold a queue by incrementing an atomic counter and requesting the netif | |
206 | * queues to be stopped. The queues cannot be woken up while the counter has not | |
207 | * been reset with as any ieee802154_release_queue() calls as needed. | |
208 | */ | |
209 | void ieee802154_hold_queue(struct ieee802154_local *local); | |
210 | ||
211 | /** | |
212 | * ieee802154_release_queue - release ieee802154 queue | |
213 | * @local: main mac object | |
214 | * | |
215 | * Release a queue which is held by decrementing an atomic counter and wake it | |
216 | * up only if the counter reaches 0. | |
217 | */ | |
218 | void ieee802154_release_queue(struct ieee802154_local *local); | |
219 | ||
a40612f3 MR |
220 | /** |
221 | * ieee802154_disable_queue - disable ieee802154 queue | |
222 | * @local: main mac object | |
223 | * | |
224 | * When trying to sync the Tx queue, we cannot just stop the queue | |
225 | * (which is basically a bit being set without proper lock handling) | |
226 | * because it would be racy. We actually need to call netif_tx_disable() | |
227 | * instead, which is done by this helper. Restarting the queue can | |
228 | * however still be done with a regular wake call. | |
229 | */ | |
230 | void ieee802154_disable_queue(struct ieee802154_local *local); | |
231 | ||
ef2486f5 | 232 | /* MIB callbacks */ |
66b69d4d | 233 | void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); |
ef2486f5 | 234 | |
29e02374 PB |
235 | int mac802154_get_params(struct net_device *dev, |
236 | struct ieee802154_llsec_params *params); | |
237 | int mac802154_set_params(struct net_device *dev, | |
238 | const struct ieee802154_llsec_params *params, | |
239 | int changed); | |
240 | ||
241 | int mac802154_add_key(struct net_device *dev, | |
242 | const struct ieee802154_llsec_key_id *id, | |
243 | const struct ieee802154_llsec_key *key); | |
244 | int mac802154_del_key(struct net_device *dev, | |
245 | const struct ieee802154_llsec_key_id *id); | |
246 | ||
247 | int mac802154_add_dev(struct net_device *dev, | |
248 | const struct ieee802154_llsec_device *llsec_dev); | |
249 | int mac802154_del_dev(struct net_device *dev, __le64 dev_addr); | |
250 | ||
251 | int mac802154_add_devkey(struct net_device *dev, | |
252 | __le64 device_addr, | |
253 | const struct ieee802154_llsec_device_key *key); | |
254 | int mac802154_del_devkey(struct net_device *dev, | |
255 | __le64 device_addr, | |
256 | const struct ieee802154_llsec_device_key *key); | |
257 | ||
258 | int mac802154_add_seclevel(struct net_device *dev, | |
259 | const struct ieee802154_llsec_seclevel *sl); | |
260 | int mac802154_del_seclevel(struct net_device *dev, | |
261 | const struct ieee802154_llsec_seclevel *sl); | |
262 | ||
263 | void mac802154_lock_table(struct net_device *dev); | |
264 | void mac802154_get_table(struct net_device *dev, | |
265 | struct ieee802154_llsec_table **t); | |
266 | void mac802154_unlock_table(struct net_device *dev); | |
267 | ||
d77b4852 AA |
268 | int mac802154_wpan_update_llsec(struct net_device *dev); |
269 | ||
57588c71 MR |
270 | /* PAN management handling */ |
271 | void mac802154_scan_worker(struct work_struct *work); | |
272 | int mac802154_trigger_scan_locked(struct ieee802154_sub_if_data *sdata, | |
273 | struct cfg802154_scan_request *request); | |
274 | int mac802154_abort_scan_locked(struct ieee802154_local *local, | |
275 | struct ieee802154_sub_if_data *sdata); | |
276 | int mac802154_process_beacon(struct ieee802154_local *local, | |
277 | struct sk_buff *skb, | |
278 | u8 page, u8 channel); | |
279 | void mac802154_rx_beacon_worker(struct work_struct *work); | |
280 | ||
281 | static inline bool mac802154_is_scanning(struct ieee802154_local *local) | |
282 | { | |
283 | return test_bit(IEEE802154_IS_SCANNING, &local->ongoing); | |
284 | } | |
285 | ||
3accf476 MR |
286 | void mac802154_beacon_worker(struct work_struct *work); |
287 | int mac802154_send_beacons_locked(struct ieee802154_sub_if_data *sdata, | |
288 | struct cfg802154_beacon_request *request); | |
289 | int mac802154_stop_beacons_locked(struct ieee802154_local *local, | |
290 | struct ieee802154_sub_if_data *sdata); | |
291 | ||
292 | static inline bool mac802154_is_beaconing(struct ieee802154_local *local) | |
293 | { | |
294 | return test_bit(IEEE802154_IS_BEACONING, &local->ongoing); | |
295 | } | |
296 | ||
d021d218 MR |
297 | void mac802154_rx_mac_cmd_worker(struct work_struct *work); |
298 | ||
be4fd8e5 AA |
299 | /* interface handling */ |
300 | int ieee802154_iface_init(void); | |
301 | void ieee802154_iface_exit(void); | |
b210b187 | 302 | void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); |
986a8abf AA |
303 | struct net_device * |
304 | ieee802154_if_add(struct ieee802154_local *local, const char *name, | |
5b4a1039 VB |
305 | unsigned char name_assign_type, enum nl802154_iftype type, |
306 | __le64 extended_addr); | |
592dfbfc | 307 | void ieee802154_remove_interfaces(struct ieee802154_local *local); |
c4227c8a | 308 | void ieee802154_stop_device(struct ieee802154_local *local); |
4a9a816a | 309 | |
0f1556bc | 310 | #endif /* __IEEE802154_I_H */ |