1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* |
3 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> |
4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
5 | * Copyright (C) 2020-2023 Intel Corporation |
6 | */ |
7 | |
8 | #include <linux/kernel.h> |
9 | #include <linux/device.h> |
10 | #include <linux/if.h> |
11 | #include <linux/if_ether.h> |
12 | #include <linux/interrupt.h> |
13 | #include <linux/netdevice.h> |
14 | #include <linux/rtnetlink.h> |
15 | #include <linux/slab.h> |
16 | #include <linux/notifier.h> |
17 | #include <net/mac80211.h> |
18 | #include <net/cfg80211.h> |
19 | #include "ieee80211_i.h" |
20 | #include "rate.h" |
21 | #include "debugfs.h" |
22 | #include "debugfs_netdev.h" |
23 | #include "driver-ops.h" |
24 | |
25 | static ssize_t ieee80211_if_read_sdata( |
26 | struct ieee80211_sub_if_data *sdata, |
27 | char __user *userbuf, |
28 | size_t count, loff_t *ppos, |
29 | ssize_t (*format)(const struct ieee80211_sub_if_data *sdata, char *, int)) |
30 | { |
31 | char buf[200]; |
32 | ssize_t ret = -EINVAL; |
33 | |
34 | wiphy_lock(wiphy: sdata->local->hw.wiphy); |
35 | ret = (*format)(sdata, buf, sizeof(buf)); |
36 | wiphy_unlock(wiphy: sdata->local->hw.wiphy); |
37 | |
38 | if (ret >= 0) |
39 | ret = simple_read_from_buffer(to: userbuf, count, ppos, from: buf, available: ret); |
40 | |
41 | return ret; |
42 | } |
43 | |
44 | static ssize_t ieee80211_if_write_sdata( |
45 | struct ieee80211_sub_if_data *sdata, |
46 | const char __user *userbuf, |
47 | size_t count, loff_t *ppos, |
48 | ssize_t (*write)(struct ieee80211_sub_if_data *sdata, const char *, int)) |
49 | { |
50 | char buf[64]; |
51 | ssize_t ret; |
52 | |
53 | if (count >= sizeof(buf)) |
54 | return -E2BIG; |
55 | |
56 | if (copy_from_user(to: buf, from: userbuf, n: count)) |
57 | return -EFAULT; |
58 | buf[count] = '\0'; |
59 | |
60 | wiphy_lock(wiphy: sdata->local->hw.wiphy); |
61 | ret = (*write)(sdata, buf, count); |
62 | wiphy_unlock(wiphy: sdata->local->hw.wiphy); |
63 | |
64 | return ret; |
65 | } |
66 | |
67 | static ssize_t ieee80211_if_read_link( |
68 | struct ieee80211_link_data *link, |
69 | char __user *userbuf, |
70 | size_t count, loff_t *ppos, |
71 | ssize_t (*format)(const struct ieee80211_link_data *link, char *, int)) |
72 | { |
73 | char buf[200]; |
74 | ssize_t ret = -EINVAL; |
75 | |
76 | wiphy_lock(wiphy: link->sdata->local->hw.wiphy); |
77 | ret = (*format)(link, buf, sizeof(buf)); |
78 | wiphy_unlock(wiphy: link->sdata->local->hw.wiphy); |
79 | |
80 | if (ret >= 0) |
81 | ret = simple_read_from_buffer(to: userbuf, count, ppos, from: buf, available: ret); |
82 | |
83 | return ret; |
84 | } |
85 | |
86 | static ssize_t ieee80211_if_write_link( |
87 | struct ieee80211_link_data *link, |
88 | const char __user *userbuf, |
89 | size_t count, loff_t *ppos, |
90 | ssize_t (*write)(struct ieee80211_link_data *link, const char *, int)) |
91 | { |
92 | char buf[64]; |
93 | ssize_t ret; |
94 | |
95 | if (count >= sizeof(buf)) |
96 | return -E2BIG; |
97 | |
98 | if (copy_from_user(to: buf, from: userbuf, n: count)) |
99 | return -EFAULT; |
100 | buf[count] = '\0'; |
101 | |
102 | wiphy_lock(wiphy: link->sdata->local->hw.wiphy); |
103 | ret = (*write)(link, buf, count); |
104 | wiphy_unlock(wiphy: link->sdata->local->hw.wiphy); |
105 | |
106 | return ret; |
107 | } |
108 | |
109 | #define IEEE80211_IF_FMT(name, type, field, format_string) \ |
110 | static ssize_t ieee80211_if_fmt_##name( \ |
111 | const type *data, char *buf, \ |
112 | int buflen) \ |
113 | { \ |
114 | return scnprintf(buf, buflen, format_string, data->field); \ |
115 | } |
116 | #define IEEE80211_IF_FMT_DEC(name, type, field) \ |
117 | IEEE80211_IF_FMT(name, type, field, "%d\n") |
118 | #define IEEE80211_IF_FMT_HEX(name, type, field) \ |
119 | IEEE80211_IF_FMT(name, type, field, "%#x\n") |
120 | #define IEEE80211_IF_FMT_LHEX(name, type, field) \ |
121 | IEEE80211_IF_FMT(name, type, field, "%#lx\n") |
122 | |
123 | #define IEEE80211_IF_FMT_HEXARRAY(name, type, field) \ |
124 | static ssize_t ieee80211_if_fmt_##name( \ |
125 | const type *data, \ |
126 | char *buf, int buflen) \ |
127 | { \ |
128 | char *p = buf; \ |
129 | int i; \ |
130 | for (i = 0; i < sizeof(data->field); i++) { \ |
131 | p += scnprintf(p, buflen + buf - p, "%.2x ", \ |
132 | data->field[i]); \ |
133 | } \ |
134 | p += scnprintf(p, buflen + buf - p, "\n"); \ |
135 | return p - buf; \ |
136 | } |
137 | |
138 | #define IEEE80211_IF_FMT_ATOMIC(name, type, field) \ |
139 | static ssize_t ieee80211_if_fmt_##name( \ |
140 | const type *data, \ |
141 | char *buf, int buflen) \ |
142 | { \ |
143 | return scnprintf(buf, buflen, "%d\n", atomic_read(&data->field));\ |
144 | } |
145 | |
146 | #define IEEE80211_IF_FMT_MAC(name, type, field) \ |
147 | static ssize_t ieee80211_if_fmt_##name( \ |
148 | const type *data, char *buf, \ |
149 | int buflen) \ |
150 | { \ |
151 | return scnprintf(buf, buflen, "%pM\n", data->field); \ |
152 | } |
153 | |
154 | #define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, type, field) \ |
155 | static ssize_t ieee80211_if_fmt_##name( \ |
156 | const type *data, \ |
157 | char *buf, int buflen) \ |
158 | { \ |
159 | return scnprintf(buf, buflen, "%d\n", \ |
160 | jiffies_to_msecs(data->field)); \ |
161 | } |
162 | |
163 | #define _IEEE80211_IF_FILE_OPS(name, _read, _write) \ |
164 | static const struct file_operations name##_ops = { \ |
165 | .read = (_read), \ |
166 | .write = (_write), \ |
167 | .open = simple_open, \ |
168 | .llseek = generic_file_llseek, \ |
169 | } |
170 | |
171 | #define _IEEE80211_IF_FILE_R_FN(name) \ |
172 | static ssize_t ieee80211_if_read_##name(struct file *file, \ |
173 | char __user *userbuf, \ |
174 | size_t count, loff_t *ppos) \ |
175 | { \ |
176 | return ieee80211_if_read_sdata(file->private_data, \ |
177 | userbuf, count, ppos, \ |
178 | ieee80211_if_fmt_##name); \ |
179 | } |
180 | |
181 | #define _IEEE80211_IF_FILE_W_FN(name) \ |
182 | static ssize_t ieee80211_if_write_##name(struct file *file, \ |
183 | const char __user *userbuf, \ |
184 | size_t count, loff_t *ppos) \ |
185 | { \ |
186 | return ieee80211_if_write_sdata(file->private_data, userbuf, \ |
187 | count, ppos, \ |
188 | ieee80211_if_parse_##name); \ |
189 | } |
190 | |
191 | #define IEEE80211_IF_FILE_R(name) \ |
192 | _IEEE80211_IF_FILE_R_FN(name) \ |
193 | _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL) |
194 | |
195 | #define IEEE80211_IF_FILE_W(name) \ |
196 | _IEEE80211_IF_FILE_W_FN(name) \ |
197 | _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name) |
198 | |
199 | #define IEEE80211_IF_FILE_RW(name) \ |
200 | _IEEE80211_IF_FILE_R_FN(name) \ |
201 | _IEEE80211_IF_FILE_W_FN(name) \ |
202 | _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \ |
203 | ieee80211_if_write_##name) |
204 | |
205 | #define IEEE80211_IF_FILE(name, field, format) \ |
206 | IEEE80211_IF_FMT_##format(name, struct ieee80211_sub_if_data, field) \ |
207 | IEEE80211_IF_FILE_R(name) |
208 | |
209 | #define _IEEE80211_IF_LINK_R_FN(name) \ |
210 | static ssize_t ieee80211_if_read_##name(struct file *file, \ |
211 | char __user *userbuf, \ |
212 | size_t count, loff_t *ppos) \ |
213 | { \ |
214 | return ieee80211_if_read_link(file->private_data, \ |
215 | userbuf, count, ppos, \ |
216 | ieee80211_if_fmt_##name); \ |
217 | } |
218 | |
219 | #define _IEEE80211_IF_LINK_W_FN(name) \ |
220 | static ssize_t ieee80211_if_write_##name(struct file *file, \ |
221 | const char __user *userbuf, \ |
222 | size_t count, loff_t *ppos) \ |
223 | { \ |
224 | return ieee80211_if_write_link(file->private_data, userbuf, \ |
225 | count, ppos, \ |
226 | ieee80211_if_parse_##name); \ |
227 | } |
228 | |
229 | #define IEEE80211_IF_LINK_FILE_R(name) \ |
230 | _IEEE80211_IF_LINK_R_FN(name) \ |
231 | _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, NULL) |
232 | |
233 | #define IEEE80211_IF_LINK_FILE_W(name) \ |
234 | _IEEE80211_IF_LINK_W_FN(name) \ |
235 | _IEEE80211_IF_FILE_OPS(link_##name, NULL, ieee80211_if_write_##name) |
236 | |
237 | #define IEEE80211_IF_LINK_FILE_RW(name) \ |
238 | _IEEE80211_IF_LINK_R_FN(name) \ |
239 | _IEEE80211_IF_LINK_W_FN(name) \ |
240 | _IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, \ |
241 | ieee80211_if_write_##name) |
242 | |
243 | #define IEEE80211_IF_LINK_FILE(name, field, format) \ |
244 | IEEE80211_IF_FMT_##format(name, struct ieee80211_link_data, field) \ |
245 | IEEE80211_IF_LINK_FILE_R(name) |
246 | |
247 | /* common attributes */ |
248 | IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ], |
249 | HEX); |
250 | IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ], |
251 | HEX); |
252 | IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz, |
253 | rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY); |
254 | IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz, |
255 | rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY); |
256 | |
257 | static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz( |
258 | const struct ieee80211_sub_if_data *sdata, |
259 | char *buf, int buflen) |
260 | { |
261 | int i, len = 0; |
262 | const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ]; |
263 | |
264 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
265 | len += scnprintf(buf: buf + len, size: buflen - len, fmt: "%04x " , mask[i]); |
266 | len += scnprintf(buf: buf + len, size: buflen - len, fmt: "\n" ); |
267 | |
268 | return len; |
269 | } |
270 | |
271 | IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz); |
272 | |
273 | static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz( |
274 | const struct ieee80211_sub_if_data *sdata, |
275 | char *buf, int buflen) |
276 | { |
277 | int i, len = 0; |
278 | const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ]; |
279 | |
280 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
281 | len += scnprintf(buf: buf + len, size: buflen - len, fmt: "%04x " , mask[i]); |
282 | len += scnprintf(buf: buf + len, size: buflen - len, fmt: "\n" ); |
283 | |
284 | return len; |
285 | } |
286 | |
287 | IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz); |
288 | |
289 | IEEE80211_IF_FILE(flags, flags, HEX); |
290 | IEEE80211_IF_FILE(state, state, LHEX); |
291 | IEEE80211_IF_LINK_FILE(txpower, conf->txpower, DEC); |
292 | IEEE80211_IF_LINK_FILE(ap_power_level, ap_power_level, DEC); |
293 | IEEE80211_IF_LINK_FILE(user_power_level, user_power_level, DEC); |
294 | |
295 | static ssize_t |
296 | ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata, |
297 | char *buf, int buflen) |
298 | { |
299 | int len; |
300 | |
301 | len = scnprintf(buf, size: buflen, fmt: "AC queues: VO:%d VI:%d BE:%d BK:%d\n" , |
302 | sdata->vif.hw_queue[IEEE80211_AC_VO], |
303 | sdata->vif.hw_queue[IEEE80211_AC_VI], |
304 | sdata->vif.hw_queue[IEEE80211_AC_BE], |
305 | sdata->vif.hw_queue[IEEE80211_AC_BK]); |
306 | |
307 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
308 | len += scnprintf(buf: buf + len, size: buflen - len, fmt: "cab queue: %d\n" , |
309 | sdata->vif.cab_queue); |
310 | |
311 | return len; |
312 | } |
313 | IEEE80211_IF_FILE_R(hw_queues); |
314 | |
315 | /* STA attributes */ |
316 | IEEE80211_IF_FILE(bssid, deflink.u.mgd.bssid, MAC); |
317 | IEEE80211_IF_FILE(aid, vif.cfg.aid, DEC); |
318 | IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS); |
319 | |
320 | static int ieee80211_set_smps(struct ieee80211_link_data *link, |
321 | enum ieee80211_smps_mode smps_mode) |
322 | { |
323 | struct ieee80211_sub_if_data *sdata = link->sdata; |
324 | struct ieee80211_local *local = sdata->local; |
325 | |
326 | /* The driver indicated that EML is enabled for the interface, thus do |
327 | * not allow to override the SMPS state. |
328 | */ |
329 | if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE) |
330 | return -EOPNOTSUPP; |
331 | |
332 | if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) && |
333 | smps_mode == IEEE80211_SMPS_STATIC) |
334 | return -EINVAL; |
335 | |
336 | /* auto should be dynamic if in PS mode */ |
337 | if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) && |
338 | (smps_mode == IEEE80211_SMPS_DYNAMIC || |
339 | smps_mode == IEEE80211_SMPS_AUTOMATIC)) |
340 | return -EINVAL; |
341 | |
342 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
343 | return -EOPNOTSUPP; |
344 | |
345 | return __ieee80211_request_smps_mgd(sdata: link->sdata, link, smps_mode); |
346 | } |
347 | |
348 | static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = { |
349 | [IEEE80211_SMPS_AUTOMATIC] = "auto" , |
350 | [IEEE80211_SMPS_OFF] = "off" , |
351 | [IEEE80211_SMPS_STATIC] = "static" , |
352 | [IEEE80211_SMPS_DYNAMIC] = "dynamic" , |
353 | }; |
354 | |
355 | static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_link_data *link, |
356 | char *buf, int buflen) |
357 | { |
358 | if (link->sdata->vif.type == NL80211_IFTYPE_STATION) |
359 | return snprintf(buf, size: buflen, fmt: "request: %s\nused: %s\n" , |
360 | smps_modes[link->u.mgd.req_smps], |
361 | smps_modes[link->smps_mode]); |
362 | return -EINVAL; |
363 | } |
364 | |
365 | static ssize_t ieee80211_if_parse_smps(struct ieee80211_link_data *link, |
366 | const char *buf, int buflen) |
367 | { |
368 | enum ieee80211_smps_mode mode; |
369 | |
370 | for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) { |
371 | if (strncmp(buf, smps_modes[mode], buflen) == 0) { |
372 | int err = ieee80211_set_smps(link, smps_mode: mode); |
373 | if (!err) |
374 | return buflen; |
375 | return err; |
376 | } |
377 | } |
378 | |
379 | return -EINVAL; |
380 | } |
381 | IEEE80211_IF_LINK_FILE_RW(smps); |
382 | |
383 | static ssize_t ieee80211_if_parse_tkip_mic_test( |
384 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
385 | { |
386 | struct ieee80211_local *local = sdata->local; |
387 | u8 addr[ETH_ALEN]; |
388 | struct sk_buff *skb; |
389 | struct ieee80211_hdr *hdr; |
390 | __le16 fc; |
391 | |
392 | if (!mac_pton(s: buf, mac: addr)) |
393 | return -EINVAL; |
394 | |
395 | if (!ieee80211_sdata_running(sdata)) |
396 | return -ENOTCONN; |
397 | |
398 | skb = dev_alloc_skb(length: local->hw.extra_tx_headroom + 24 + 100); |
399 | if (!skb) |
400 | return -ENOMEM; |
401 | skb_reserve(skb, len: local->hw.extra_tx_headroom); |
402 | |
403 | hdr = skb_put_zero(skb, len: 24); |
404 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); |
405 | |
406 | switch (sdata->vif.type) { |
407 | case NL80211_IFTYPE_AP: |
408 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); |
409 | /* DA BSSID SA */ |
410 | memcpy(hdr->addr1, addr, ETH_ALEN); |
411 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
412 | memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN); |
413 | break; |
414 | case NL80211_IFTYPE_STATION: |
415 | fc |= cpu_to_le16(IEEE80211_FCTL_TODS); |
416 | /* BSSID SA DA */ |
417 | if (!sdata->u.mgd.associated) { |
418 | dev_kfree_skb(skb); |
419 | return -ENOTCONN; |
420 | } |
421 | memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN); |
422 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
423 | memcpy(hdr->addr3, addr, ETH_ALEN); |
424 | break; |
425 | default: |
426 | dev_kfree_skb(skb); |
427 | return -EOPNOTSUPP; |
428 | } |
429 | hdr->frame_control = fc; |
430 | |
431 | /* |
432 | * Add some length to the test frame to make it look bit more valid. |
433 | * The exact contents does not matter since the recipient is required |
434 | * to drop this because of the Michael MIC failure. |
435 | */ |
436 | skb_put_zero(skb, len: 50); |
437 | |
438 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE; |
439 | |
440 | ieee80211_tx_skb(sdata, skb); |
441 | |
442 | return buflen; |
443 | } |
444 | IEEE80211_IF_FILE_W(tkip_mic_test); |
445 | |
446 | static ssize_t ieee80211_if_parse_beacon_loss( |
447 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
448 | { |
449 | if (!ieee80211_sdata_running(sdata) || !sdata->vif.cfg.assoc) |
450 | return -ENOTCONN; |
451 | |
452 | ieee80211_beacon_loss(vif: &sdata->vif); |
453 | |
454 | return buflen; |
455 | } |
456 | IEEE80211_IF_FILE_W(beacon_loss); |
457 | |
458 | static ssize_t ieee80211_if_fmt_uapsd_queues( |
459 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
460 | { |
461 | const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
462 | |
463 | return snprintf(buf, size: buflen, fmt: "0x%x\n" , ifmgd->uapsd_queues); |
464 | } |
465 | |
466 | static ssize_t ieee80211_if_parse_uapsd_queues( |
467 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
468 | { |
469 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
470 | u8 val; |
471 | int ret; |
472 | |
473 | ret = kstrtou8(s: buf, base: 0, res: &val); |
474 | if (ret) |
475 | return ret; |
476 | |
477 | if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
478 | return -ERANGE; |
479 | |
480 | ifmgd->uapsd_queues = val; |
481 | |
482 | return buflen; |
483 | } |
484 | IEEE80211_IF_FILE_RW(uapsd_queues); |
485 | |
486 | static ssize_t ieee80211_if_fmt_uapsd_max_sp_len( |
487 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
488 | { |
489 | const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
490 | |
491 | return snprintf(buf, size: buflen, fmt: "0x%x\n" , ifmgd->uapsd_max_sp_len); |
492 | } |
493 | |
494 | static ssize_t ieee80211_if_parse_uapsd_max_sp_len( |
495 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
496 | { |
497 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
498 | unsigned long val; |
499 | int ret; |
500 | |
501 | ret = kstrtoul(s: buf, base: 0, res: &val); |
502 | if (ret) |
503 | return -EINVAL; |
504 | |
505 | if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
506 | return -ERANGE; |
507 | |
508 | ifmgd->uapsd_max_sp_len = val; |
509 | |
510 | return buflen; |
511 | } |
512 | IEEE80211_IF_FILE_RW(uapsd_max_sp_len); |
513 | |
514 | static ssize_t ieee80211_if_fmt_tdls_wider_bw( |
515 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
516 | { |
517 | const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
518 | bool tdls_wider_bw; |
519 | |
520 | tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) && |
521 | !ifmgd->tdls_wider_bw_prohibited; |
522 | |
523 | return snprintf(buf, size: buflen, fmt: "%d\n" , tdls_wider_bw); |
524 | } |
525 | |
526 | static ssize_t ieee80211_if_parse_tdls_wider_bw( |
527 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
528 | { |
529 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
530 | u8 val; |
531 | int ret; |
532 | |
533 | ret = kstrtou8(s: buf, base: 0, res: &val); |
534 | if (ret) |
535 | return ret; |
536 | |
537 | ifmgd->tdls_wider_bw_prohibited = !val; |
538 | return buflen; |
539 | } |
540 | IEEE80211_IF_FILE_RW(tdls_wider_bw); |
541 | |
542 | /* AP attributes */ |
543 | IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC); |
544 | IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC); |
545 | IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC); |
546 | IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC); |
547 | |
548 | static ssize_t ieee80211_if_fmt_num_buffered_multicast( |
549 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
550 | { |
551 | return scnprintf(buf, size: buflen, fmt: "%u\n" , |
552 | skb_queue_len(list_: &sdata->u.ap.ps.bc_buf)); |
553 | } |
554 | IEEE80211_IF_FILE_R(num_buffered_multicast); |
555 | |
556 | static ssize_t ieee80211_if_fmt_aqm( |
557 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
558 | { |
559 | struct ieee80211_local *local = sdata->local; |
560 | struct txq_info *txqi; |
561 | int len; |
562 | |
563 | if (!sdata->vif.txq) |
564 | return 0; |
565 | |
566 | txqi = to_txq_info(txq: sdata->vif.txq); |
567 | |
568 | spin_lock_bh(lock: &local->fq.lock); |
569 | rcu_read_lock(); |
570 | |
571 | len = scnprintf(buf, |
572 | size: buflen, |
573 | fmt: "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n" |
574 | "%u %u %u %u %u %u %u %u %u %u\n" , |
575 | txqi->txq.ac, |
576 | txqi->tin.backlog_bytes, |
577 | txqi->tin.backlog_packets, |
578 | txqi->tin.flows, |
579 | txqi->cstats.drop_count, |
580 | txqi->cstats.ecn_mark, |
581 | txqi->tin.overlimit, |
582 | txqi->tin.collisions, |
583 | txqi->tin.tx_bytes, |
584 | txqi->tin.tx_packets); |
585 | |
586 | rcu_read_unlock(); |
587 | spin_unlock_bh(lock: &local->fq.lock); |
588 | |
589 | return len; |
590 | } |
591 | IEEE80211_IF_FILE_R(aqm); |
592 | |
593 | IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX); |
594 | |
595 | /* IBSS attributes */ |
596 | static ssize_t ieee80211_if_fmt_tsf( |
597 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
598 | { |
599 | struct ieee80211_local *local = sdata->local; |
600 | u64 tsf; |
601 | |
602 | tsf = drv_get_tsf(local, sdata: (struct ieee80211_sub_if_data *)sdata); |
603 | |
604 | return scnprintf(buf, size: buflen, fmt: "0x%016llx\n" , (unsigned long long) tsf); |
605 | } |
606 | |
607 | static ssize_t ieee80211_if_parse_tsf( |
608 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
609 | { |
610 | struct ieee80211_local *local = sdata->local; |
611 | unsigned long long tsf; |
612 | int ret; |
613 | int tsf_is_delta = 0; |
614 | |
615 | if (strncmp(buf, "reset" , 5) == 0) { |
616 | if (local->ops->reset_tsf) { |
617 | drv_reset_tsf(local, sdata); |
618 | wiphy_info(local->hw.wiphy, "debugfs reset TSF\n" ); |
619 | } |
620 | } else { |
621 | if (buflen > 10 && buf[1] == '=') { |
622 | if (buf[0] == '+') |
623 | tsf_is_delta = 1; |
624 | else if (buf[0] == '-') |
625 | tsf_is_delta = -1; |
626 | else |
627 | return -EINVAL; |
628 | buf += 2; |
629 | } |
630 | ret = kstrtoull(s: buf, base: 10, res: &tsf); |
631 | if (ret < 0) |
632 | return ret; |
633 | if (tsf_is_delta && local->ops->offset_tsf) { |
634 | drv_offset_tsf(local, sdata, offset: tsf_is_delta * tsf); |
635 | wiphy_info(local->hw.wiphy, |
636 | "debugfs offset TSF by %018lld\n" , |
637 | tsf_is_delta * tsf); |
638 | } else if (local->ops->set_tsf) { |
639 | if (tsf_is_delta) |
640 | tsf = drv_get_tsf(local, sdata) + |
641 | tsf_is_delta * tsf; |
642 | drv_set_tsf(local, sdata, tsf); |
643 | wiphy_info(local->hw.wiphy, |
644 | "debugfs set TSF to %#018llx\n" , tsf); |
645 | } |
646 | } |
647 | |
648 | ieee80211_recalc_dtim(local, sdata); |
649 | return buflen; |
650 | } |
651 | IEEE80211_IF_FILE_RW(tsf); |
652 | |
653 | static ssize_t ieee80211_if_fmt_valid_links(const struct ieee80211_sub_if_data *sdata, |
654 | char *buf, int buflen) |
655 | { |
656 | return snprintf(buf, size: buflen, fmt: "0x%x\n" , sdata->vif.valid_links); |
657 | } |
658 | IEEE80211_IF_FILE_R(valid_links); |
659 | |
660 | static ssize_t ieee80211_if_fmt_active_links(const struct ieee80211_sub_if_data *sdata, |
661 | char *buf, int buflen) |
662 | { |
663 | return snprintf(buf, size: buflen, fmt: "0x%x\n" , sdata->vif.active_links); |
664 | } |
665 | |
666 | static ssize_t ieee80211_if_parse_active_links(struct ieee80211_sub_if_data *sdata, |
667 | const char *buf, int buflen) |
668 | { |
669 | u16 active_links; |
670 | |
671 | if (kstrtou16(s: buf, base: 0, res: &active_links)) |
672 | return -EINVAL; |
673 | |
674 | return ieee80211_set_active_links(vif: &sdata->vif, active_links) ?: buflen; |
675 | } |
676 | IEEE80211_IF_FILE_RW(active_links); |
677 | |
678 | IEEE80211_IF_LINK_FILE(addr, conf->addr, MAC); |
679 | |
680 | #ifdef CONFIG_MAC80211_MESH |
681 | IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC); |
682 | |
683 | /* Mesh stats attributes */ |
684 | IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC); |
685 | IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC); |
686 | IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC); |
687 | IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC); |
688 | IEEE80211_IF_FILE(dropped_frames_no_route, |
689 | u.mesh.mshstats.dropped_frames_no_route, DEC); |
690 | |
691 | /* Mesh parameters */ |
692 | IEEE80211_IF_FILE(dot11MeshMaxRetries, |
693 | u.mesh.mshcfg.dot11MeshMaxRetries, DEC); |
694 | IEEE80211_IF_FILE(dot11MeshRetryTimeout, |
695 | u.mesh.mshcfg.dot11MeshRetryTimeout, DEC); |
696 | IEEE80211_IF_FILE(dot11MeshConfirmTimeout, |
697 | u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC); |
698 | IEEE80211_IF_FILE(dot11MeshHoldingTimeout, |
699 | u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC); |
700 | IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC); |
701 | IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC); |
702 | IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC); |
703 | IEEE80211_IF_FILE(dot11MeshMaxPeerLinks, |
704 | u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC); |
705 | IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout, |
706 | u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC); |
707 | IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval, |
708 | u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC); |
709 | IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval, |
710 | u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC); |
711 | IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime, |
712 | u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC); |
713 | IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries, |
714 | u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC); |
715 | IEEE80211_IF_FILE(path_refresh_time, |
716 | u.mesh.mshcfg.path_refresh_time, DEC); |
717 | IEEE80211_IF_FILE(min_discovery_timeout, |
718 | u.mesh.mshcfg.min_discovery_timeout, DEC); |
719 | IEEE80211_IF_FILE(dot11MeshHWMPRootMode, |
720 | u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC); |
721 | IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol, |
722 | u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC); |
723 | IEEE80211_IF_FILE(dot11MeshHWMPRannInterval, |
724 | u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC); |
725 | IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC); |
726 | IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC); |
727 | IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC); |
728 | IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout, |
729 | u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC); |
730 | IEEE80211_IF_FILE(dot11MeshHWMProotInterval, |
731 | u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC); |
732 | IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval, |
733 | u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC); |
734 | IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC); |
735 | IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration, |
736 | u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC); |
737 | IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate, |
738 | u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC); |
739 | IEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC); |
740 | IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer, |
741 | u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC); |
742 | #endif |
743 | |
744 | #define DEBUGFS_ADD_MODE(name, mode) \ |
745 | debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \ |
746 | sdata, &name##_ops) |
747 | |
748 | #define DEBUGFS_ADD_X(_bits, _name, _mode) \ |
749 | debugfs_create_x##_bits(#_name, _mode, sdata->vif.debugfs_dir, \ |
750 | &sdata->vif._name) |
751 | |
752 | #define DEBUGFS_ADD_X8(_name, _mode) \ |
753 | DEBUGFS_ADD_X(8, _name, _mode) |
754 | |
755 | #define DEBUGFS_ADD_X16(_name, _mode) \ |
756 | DEBUGFS_ADD_X(16, _name, _mode) |
757 | |
758 | #define DEBUGFS_ADD_X32(_name, _mode) \ |
759 | DEBUGFS_ADD_X(32, _name, _mode) |
760 | |
761 | #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400) |
762 | |
763 | static void add_common_files(struct ieee80211_sub_if_data *sdata) |
764 | { |
765 | DEBUGFS_ADD(rc_rateidx_mask_2ghz); |
766 | DEBUGFS_ADD(rc_rateidx_mask_5ghz); |
767 | DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz); |
768 | DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz); |
769 | DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz); |
770 | DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz); |
771 | DEBUGFS_ADD(hw_queues); |
772 | |
773 | if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE && |
774 | sdata->vif.type != NL80211_IFTYPE_NAN) |
775 | DEBUGFS_ADD(aqm); |
776 | } |
777 | |
778 | static void add_sta_files(struct ieee80211_sub_if_data *sdata) |
779 | { |
780 | DEBUGFS_ADD(bssid); |
781 | DEBUGFS_ADD(aid); |
782 | DEBUGFS_ADD(beacon_timeout); |
783 | DEBUGFS_ADD_MODE(tkip_mic_test, 0200); |
784 | DEBUGFS_ADD_MODE(beacon_loss, 0200); |
785 | DEBUGFS_ADD_MODE(uapsd_queues, 0600); |
786 | DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600); |
787 | DEBUGFS_ADD_MODE(tdls_wider_bw, 0600); |
788 | DEBUGFS_ADD_MODE(valid_links, 0400); |
789 | DEBUGFS_ADD_MODE(active_links, 0600); |
790 | DEBUGFS_ADD_X16(dormant_links, 0400); |
791 | } |
792 | |
793 | static void add_ap_files(struct ieee80211_sub_if_data *sdata) |
794 | { |
795 | DEBUGFS_ADD(num_mcast_sta); |
796 | DEBUGFS_ADD(num_sta_ps); |
797 | DEBUGFS_ADD(dtim_count); |
798 | DEBUGFS_ADD(num_buffered_multicast); |
799 | DEBUGFS_ADD_MODE(tkip_mic_test, 0200); |
800 | DEBUGFS_ADD_MODE(multicast_to_unicast, 0600); |
801 | } |
802 | |
803 | static void add_vlan_files(struct ieee80211_sub_if_data *sdata) |
804 | { |
805 | /* add num_mcast_sta_vlan using name num_mcast_sta */ |
806 | debugfs_create_file(name: "num_mcast_sta" , mode: 0400, parent: sdata->vif.debugfs_dir, |
807 | data: sdata, fops: &num_mcast_sta_vlan_ops); |
808 | } |
809 | |
810 | static void add_ibss_files(struct ieee80211_sub_if_data *sdata) |
811 | { |
812 | DEBUGFS_ADD_MODE(tsf, 0600); |
813 | } |
814 | |
815 | #ifdef CONFIG_MAC80211_MESH |
816 | |
817 | static void add_mesh_files(struct ieee80211_sub_if_data *sdata) |
818 | { |
819 | DEBUGFS_ADD_MODE(tsf, 0600); |
820 | DEBUGFS_ADD_MODE(estab_plinks, 0400); |
821 | } |
822 | |
823 | static void add_mesh_stats(struct ieee80211_sub_if_data *sdata) |
824 | { |
825 | struct dentry *dir = debugfs_create_dir(name: "mesh_stats" , |
826 | parent: sdata->vif.debugfs_dir); |
827 | #define MESHSTATS_ADD(name)\ |
828 | debugfs_create_file(#name, 0400, dir, sdata, &name##_ops) |
829 | |
830 | MESHSTATS_ADD(fwded_mcast); |
831 | MESHSTATS_ADD(fwded_unicast); |
832 | MESHSTATS_ADD(fwded_frames); |
833 | MESHSTATS_ADD(dropped_frames_ttl); |
834 | MESHSTATS_ADD(dropped_frames_no_route); |
835 | #undef MESHSTATS_ADD |
836 | } |
837 | |
838 | static void add_mesh_config(struct ieee80211_sub_if_data *sdata) |
839 | { |
840 | struct dentry *dir = debugfs_create_dir(name: "mesh_config" , |
841 | parent: sdata->vif.debugfs_dir); |
842 | |
843 | #define MESHPARAMS_ADD(name) \ |
844 | debugfs_create_file(#name, 0600, dir, sdata, &name##_ops) |
845 | |
846 | MESHPARAMS_ADD(dot11MeshMaxRetries); |
847 | MESHPARAMS_ADD(dot11MeshRetryTimeout); |
848 | MESHPARAMS_ADD(dot11MeshConfirmTimeout); |
849 | MESHPARAMS_ADD(dot11MeshHoldingTimeout); |
850 | MESHPARAMS_ADD(dot11MeshTTL); |
851 | MESHPARAMS_ADD(element_ttl); |
852 | MESHPARAMS_ADD(auto_open_plinks); |
853 | MESHPARAMS_ADD(dot11MeshMaxPeerLinks); |
854 | MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout); |
855 | MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval); |
856 | MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval); |
857 | MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime); |
858 | MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries); |
859 | MESHPARAMS_ADD(path_refresh_time); |
860 | MESHPARAMS_ADD(min_discovery_timeout); |
861 | MESHPARAMS_ADD(dot11MeshHWMPRootMode); |
862 | MESHPARAMS_ADD(dot11MeshHWMPRannInterval); |
863 | MESHPARAMS_ADD(dot11MeshForwarding); |
864 | MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol); |
865 | MESHPARAMS_ADD(rssi_threshold); |
866 | MESHPARAMS_ADD(ht_opmode); |
867 | MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout); |
868 | MESHPARAMS_ADD(dot11MeshHWMProotInterval); |
869 | MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval); |
870 | MESHPARAMS_ADD(power_mode); |
871 | MESHPARAMS_ADD(dot11MeshAwakeWindowDuration); |
872 | MESHPARAMS_ADD(dot11MeshConnectedToMeshGate); |
873 | MESHPARAMS_ADD(dot11MeshNolearn); |
874 | MESHPARAMS_ADD(dot11MeshConnectedToAuthServer); |
875 | #undef MESHPARAMS_ADD |
876 | } |
877 | #endif |
878 | |
879 | static void add_files(struct ieee80211_sub_if_data *sdata) |
880 | { |
881 | if (!sdata->vif.debugfs_dir) |
882 | return; |
883 | |
884 | DEBUGFS_ADD(flags); |
885 | DEBUGFS_ADD(state); |
886 | |
887 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
888 | add_common_files(sdata); |
889 | |
890 | switch (sdata->vif.type) { |
891 | case NL80211_IFTYPE_MESH_POINT: |
892 | #ifdef CONFIG_MAC80211_MESH |
893 | add_mesh_files(sdata); |
894 | add_mesh_stats(sdata); |
895 | add_mesh_config(sdata); |
896 | #endif |
897 | break; |
898 | case NL80211_IFTYPE_STATION: |
899 | add_sta_files(sdata); |
900 | break; |
901 | case NL80211_IFTYPE_ADHOC: |
902 | add_ibss_files(sdata); |
903 | break; |
904 | case NL80211_IFTYPE_AP: |
905 | add_ap_files(sdata); |
906 | break; |
907 | case NL80211_IFTYPE_AP_VLAN: |
908 | add_vlan_files(sdata); |
909 | break; |
910 | default: |
911 | break; |
912 | } |
913 | } |
914 | |
915 | #undef DEBUGFS_ADD_MODE |
916 | #undef DEBUGFS_ADD |
917 | |
918 | #define DEBUGFS_ADD_MODE(dentry, name, mode) \ |
919 | debugfs_create_file(#name, mode, dentry, \ |
920 | link, &link_##name##_ops) |
921 | |
922 | #define DEBUGFS_ADD(dentry, name) DEBUGFS_ADD_MODE(dentry, name, 0400) |
923 | |
924 | static void add_link_files(struct ieee80211_link_data *link, |
925 | struct dentry *dentry) |
926 | { |
927 | DEBUGFS_ADD(dentry, txpower); |
928 | DEBUGFS_ADD(dentry, user_power_level); |
929 | DEBUGFS_ADD(dentry, ap_power_level); |
930 | |
931 | switch (link->sdata->vif.type) { |
932 | case NL80211_IFTYPE_STATION: |
933 | DEBUGFS_ADD_MODE(dentry, smps, 0600); |
934 | break; |
935 | default: |
936 | break; |
937 | } |
938 | } |
939 | |
940 | void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata, |
941 | bool mld_vif) |
942 | { |
943 | char buf[10+IFNAMSIZ]; |
944 | |
945 | sprintf(buf, fmt: "netdev:%s" , sdata->name); |
946 | sdata->vif.debugfs_dir = debugfs_create_dir(name: buf, |
947 | parent: sdata->local->hw.wiphy->debugfsdir); |
948 | /* deflink also has this */ |
949 | sdata->deflink.debugfs_dir = sdata->vif.debugfs_dir; |
950 | sdata->debugfs.subdir_stations = debugfs_create_dir(name: "stations" , |
951 | parent: sdata->vif.debugfs_dir); |
952 | add_files(sdata); |
953 | if (!mld_vif) |
954 | add_link_files(link: &sdata->deflink, dentry: sdata->vif.debugfs_dir); |
955 | } |
956 | |
957 | void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) |
958 | { |
959 | if (!sdata->vif.debugfs_dir) |
960 | return; |
961 | |
962 | debugfs_remove_recursive(dentry: sdata->vif.debugfs_dir); |
963 | sdata->vif.debugfs_dir = NULL; |
964 | sdata->debugfs.subdir_stations = NULL; |
965 | } |
966 | |
967 | void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata) |
968 | { |
969 | struct dentry *dir; |
970 | char buf[10 + IFNAMSIZ]; |
971 | |
972 | dir = sdata->vif.debugfs_dir; |
973 | |
974 | if (IS_ERR_OR_NULL(ptr: dir)) |
975 | return; |
976 | |
977 | sprintf(buf, fmt: "netdev:%s" , sdata->name); |
978 | debugfs_rename(old_dir: dir->d_parent, old_dentry: dir, new_dir: dir->d_parent, new_name: buf); |
979 | } |
980 | |
981 | void ieee80211_debugfs_recreate_netdev(struct ieee80211_sub_if_data *sdata, |
982 | bool mld_vif) |
983 | { |
984 | ieee80211_debugfs_remove_netdev(sdata); |
985 | ieee80211_debugfs_add_netdev(sdata, mld_vif); |
986 | drv_vif_add_debugfs(local: sdata->local, sdata); |
987 | if (!mld_vif) |
988 | ieee80211_link_debugfs_drv_add(link: &sdata->deflink); |
989 | } |
990 | |
991 | void ieee80211_link_debugfs_add(struct ieee80211_link_data *link) |
992 | { |
993 | char link_dir_name[10]; |
994 | |
995 | if (WARN_ON(!link->sdata->vif.debugfs_dir || link->debugfs_dir)) |
996 | return; |
997 | |
998 | /* For now, this should not be called for non-MLO capable drivers */ |
999 | if (WARN_ON(!(link->sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))) |
1000 | return; |
1001 | |
1002 | snprintf(buf: link_dir_name, size: sizeof(link_dir_name), |
1003 | fmt: "link-%d" , link->link_id); |
1004 | |
1005 | link->debugfs_dir = |
1006 | debugfs_create_dir(name: link_dir_name, |
1007 | parent: link->sdata->vif.debugfs_dir); |
1008 | |
1009 | DEBUGFS_ADD(link->debugfs_dir, addr); |
1010 | add_link_files(link, dentry: link->debugfs_dir); |
1011 | } |
1012 | |
1013 | void ieee80211_link_debugfs_remove(struct ieee80211_link_data *link) |
1014 | { |
1015 | if (!link->sdata->vif.debugfs_dir || !link->debugfs_dir) { |
1016 | link->debugfs_dir = NULL; |
1017 | return; |
1018 | } |
1019 | |
1020 | if (link->debugfs_dir == link->sdata->vif.debugfs_dir) { |
1021 | WARN_ON(link != &link->sdata->deflink); |
1022 | link->debugfs_dir = NULL; |
1023 | return; |
1024 | } |
1025 | |
1026 | debugfs_remove_recursive(dentry: link->debugfs_dir); |
1027 | link->debugfs_dir = NULL; |
1028 | } |
1029 | |
1030 | void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data *link) |
1031 | { |
1032 | if (link->sdata->vif.type == NL80211_IFTYPE_MONITOR || |
1033 | WARN_ON(!link->debugfs_dir)) |
1034 | return; |
1035 | |
1036 | drv_link_add_debugfs(local: link->sdata->local, sdata: link->sdata, |
1037 | link_conf: link->conf, dir: link->debugfs_dir); |
1038 | } |
1039 | |
1040 | void ieee80211_link_debugfs_drv_remove(struct ieee80211_link_data *link) |
1041 | { |
1042 | if (!link || !link->debugfs_dir) |
1043 | return; |
1044 | |
1045 | if (WARN_ON(link->debugfs_dir == link->sdata->vif.debugfs_dir)) |
1046 | return; |
1047 | |
1048 | /* Recreate the directory excluding the driver data */ |
1049 | debugfs_remove_recursive(dentry: link->debugfs_dir); |
1050 | link->debugfs_dir = NULL; |
1051 | |
1052 | ieee80211_link_debugfs_add(link); |
1053 | } |
1054 | |