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