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