blob: 0ad3860852fffb5919e4f97e234c6c2c7142ae06 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Jiri Bence9f207f2007-05-05 11:46:38 -07002/*
3 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
Ilan Peer52b48102020-01-31 13:12:56 +02005 * Copyright (C) 2020 Intel Corporation
Jiri Bence9f207f2007-05-05 11:46:38 -07006 */
7
8#include <linux/kernel.h>
9#include <linux/device.h>
10#include <linux/if.h>
Johannes Berg28656a12012-11-05 20:24:38 +010011#include <linux/if_ether.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070012#include <linux/interrupt.h>
13#include <linux/netdevice.h>
14#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070016#include <linux/notifier.h>
17#include <net/mac80211.h>
18#include <net/cfg80211.h>
19#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070021#include "debugfs.h"
22#include "debugfs_netdev.h"
Eliad Peller37a41b42011-09-21 14:06:11 +030023#include "driver-ops.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070024
25static ssize_t ieee80211_if_read(
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 *, char *, int))
30{
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +020031 char buf[200];
Jiri Bence9f207f2007-05-05 11:46:38 -070032 ssize_t ret = -EINVAL;
33
34 read_lock(&dev_base_lock);
Arik Nemtsov923eaf32014-05-26 14:40:51 +030035 ret = (*format)(sdata, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -070036 read_unlock(&dev_base_lock);
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070037
Jouni Malinen681d1192011-02-03 18:35:19 +020038 if (ret >= 0)
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070039 ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
40
Jiri Bence9f207f2007-05-05 11:46:38 -070041 return ret;
42}
43
Johannes Berg0f782312009-12-01 13:37:02 +010044static ssize_t ieee80211_if_write(
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 *, const char *, int))
49{
Eliad Pellerada577c2012-03-14 16:15:02 +020050 char buf[64];
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010051 ssize_t ret;
Johannes Berg0f782312009-12-01 13:37:02 +010052
Eliad Pellerada577c2012-03-14 16:15:02 +020053 if (count >= sizeof(buf))
54 return -E2BIG;
Johannes Berg0f782312009-12-01 13:37:02 +010055
56 if (copy_from_user(buf, userbuf, count))
Eliad Pellerada577c2012-03-14 16:15:02 +020057 return -EFAULT;
58 buf[count] = '\0';
Johannes Berg0f782312009-12-01 13:37:02 +010059
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010060 ret = -ENODEV;
Johannes Berg0f782312009-12-01 13:37:02 +010061 rtnl_lock();
Arik Nemtsov923eaf32014-05-26 14:40:51 +030062 ret = (*write)(sdata, buf, count);
Johannes Berg0f782312009-12-01 13:37:02 +010063 rtnl_unlock();
64
65 return ret;
66}
67
Jiri Bence9f207f2007-05-05 11:46:38 -070068#define IEEE80211_IF_FMT(name, field, format_string) \
69static ssize_t ieee80211_if_fmt_##name( \
70 const struct ieee80211_sub_if_data *sdata, char *buf, \
71 int buflen) \
72{ \
73 return scnprintf(buf, buflen, format_string, sdata->field); \
74}
75#define IEEE80211_IF_FMT_DEC(name, field) \
76 IEEE80211_IF_FMT(name, field, "%d\n")
77#define IEEE80211_IF_FMT_HEX(name, field) \
78 IEEE80211_IF_FMT(name, field, "%#x\n")
Ben Greear4914b3b2011-01-27 22:09:34 -080079#define IEEE80211_IF_FMT_LHEX(name, field) \
80 IEEE80211_IF_FMT(name, field, "%#lx\n")
Jiri Bence9f207f2007-05-05 11:46:38 -070081#define IEEE80211_IF_FMT_SIZE(name, field) \
82 IEEE80211_IF_FMT(name, field, "%zd\n")
83
Simon Wunderlich19468412012-01-28 17:25:33 +010084#define IEEE80211_IF_FMT_HEXARRAY(name, field) \
85static ssize_t ieee80211_if_fmt_##name( \
86 const struct ieee80211_sub_if_data *sdata, \
87 char *buf, int buflen) \
88{ \
89 char *p = buf; \
90 int i; \
91 for (i = 0; i < sizeof(sdata->field); i++) { \
92 p += scnprintf(p, buflen + buf - p, "%.2x ", \
93 sdata->field[i]); \
94 } \
95 p += scnprintf(p, buflen + buf - p, "\n"); \
96 return p - buf; \
97}
98
Jiri Bence9f207f2007-05-05 11:46:38 -070099#define IEEE80211_IF_FMT_ATOMIC(name, field) \
100static ssize_t ieee80211_if_fmt_##name( \
101 const struct ieee80211_sub_if_data *sdata, \
102 char *buf, int buflen) \
103{ \
104 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
105}
106
107#define IEEE80211_IF_FMT_MAC(name, field) \
108static ssize_t ieee80211_if_fmt_##name( \
109 const struct ieee80211_sub_if_data *sdata, char *buf, \
110 int buflen) \
111{ \
Johannes Berg0c68ae262008-10-27 15:56:10 -0700112 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700113}
114
Ben Greear78e443e2013-03-25 11:19:34 -0700115#define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field) \
116static ssize_t ieee80211_if_fmt_##name( \
117 const struct ieee80211_sub_if_data *sdata, \
118 char *buf, int buflen) \
119{ \
120 return scnprintf(buf, buflen, "%d\n", \
121 jiffies_to_msecs(sdata->field)); \
122}
123
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100124#define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
125static const struct file_operations name##_ops = { \
126 .read = (_read), \
127 .write = (_write), \
128 .open = simple_open, \
129 .llseek = generic_file_llseek, \
130}
131
132#define _IEEE80211_IF_FILE_R_FN(name) \
Jiri Bence9f207f2007-05-05 11:46:38 -0700133static ssize_t ieee80211_if_read_##name(struct file *file, \
134 char __user *userbuf, \
135 size_t count, loff_t *ppos) \
136{ \
137 return ieee80211_if_read(file->private_data, \
138 userbuf, count, ppos, \
139 ieee80211_if_fmt_##name); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700140}
141
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100142#define _IEEE80211_IF_FILE_W_FN(name) \
Johannes Berg0f782312009-12-01 13:37:02 +0100143static ssize_t ieee80211_if_write_##name(struct file *file, \
144 const char __user *userbuf, \
145 size_t count, loff_t *ppos) \
146{ \
147 return ieee80211_if_write(file->private_data, userbuf, count, \
148 ppos, ieee80211_if_parse_##name); \
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100149}
Johannes Berg0f782312009-12-01 13:37:02 +0100150
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100151#define IEEE80211_IF_FILE_R(name) \
152 _IEEE80211_IF_FILE_R_FN(name) \
153 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
154
155#define IEEE80211_IF_FILE_W(name) \
156 _IEEE80211_IF_FILE_W_FN(name) \
157 _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
158
159#define IEEE80211_IF_FILE_RW(name) \
160 _IEEE80211_IF_FILE_R_FN(name) \
161 _IEEE80211_IF_FILE_W_FN(name) \
162 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \
163 ieee80211_if_write_##name)
Johannes Berg0f782312009-12-01 13:37:02 +0100164
Jiri Bence9f207f2007-05-05 11:46:38 -0700165#define IEEE80211_IF_FILE(name, field, format) \
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100166 IEEE80211_IF_FMT_##format(name, field) \
167 IEEE80211_IF_FILE_R(name)
Jiri Bence9f207f2007-05-05 11:46:38 -0700168
169/* common attributes */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200170IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200171 HEX);
Johannes Berg57fbcce2016-04-12 15:56:15 +0200172IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200173 HEX);
Simon Wunderlich19468412012-01-28 17:25:33 +0100174IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200175 rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
Simon Wunderlich19468412012-01-28 17:25:33 +0100176IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200177 rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
Simon Wunderlich19468412012-01-28 17:25:33 +0100178
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200179static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
180 const struct ieee80211_sub_if_data *sdata,
181 char *buf, int buflen)
182{
183 int i, len = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200184 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200185
186 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
187 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
188 len += scnprintf(buf + len, buflen - len, "\n");
189
190 return len;
191}
192
193IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
194
195static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
196 const struct ieee80211_sub_if_data *sdata,
197 char *buf, int buflen)
198{
199 int i, len = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200200 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200201
202 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
203 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
204 len += scnprintf(buf + len, buflen - len, "\n");
205
206 return len;
207}
208
209IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
210
Ben Greear4914b3b2011-01-27 22:09:34 -0800211IEEE80211_IF_FILE(flags, flags, HEX);
212IEEE80211_IF_FILE(state, state, LHEX);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200213IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
214IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
215IEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700216
Johannes Berg08643312012-11-08 15:29:28 +0100217static ssize_t
218ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
219 char *buf, int buflen)
220{
221 int len;
222
223 len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
224 sdata->vif.hw_queue[IEEE80211_AC_VO],
225 sdata->vif.hw_queue[IEEE80211_AC_VI],
226 sdata->vif.hw_queue[IEEE80211_AC_BE],
227 sdata->vif.hw_queue[IEEE80211_AC_BK]);
228
229 if (sdata->vif.type == NL80211_IFTYPE_AP)
230 len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
231 sdata->vif.cab_queue);
232
233 return len;
234}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100235IEEE80211_IF_FILE_R(hw_queues);
Johannes Berg08643312012-11-08 15:29:28 +0100236
Johannes Berg46900292009-02-15 12:44:28 +0100237/* STA attributes */
Johannes Berg46900292009-02-15 12:44:28 +0100238IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
Johannes Berg1db364c2020-04-17 12:38:04 +0200239IEEE80211_IF_FILE(aid, vif.bss_conf.aid, DEC);
Ben Greear78e443e2013-03-25 11:19:34 -0700240IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
Jiri Bence9f207f2007-05-05 11:46:38 -0700241
Johannes Berg0f782312009-12-01 13:37:02 +0100242static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
243 enum ieee80211_smps_mode smps_mode)
244{
245 struct ieee80211_local *local = sdata->local;
246 int err;
247
Eliad Peller0d8614b2014-09-10 14:07:36 +0300248 if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
Johannes Berg0f782312009-12-01 13:37:02 +0100249 smps_mode == IEEE80211_SMPS_STATIC)
250 return -EINVAL;
251
252 /* auto should be dynamic if in PS mode */
Eliad Peller0d8614b2014-09-10 14:07:36 +0300253 if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
Johannes Berg0f782312009-12-01 13:37:02 +0100254 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
255 smps_mode == IEEE80211_SMPS_AUTOMATIC))
256 return -EINVAL;
257
Ilan Peer52b48102020-01-31 13:12:56 +0200258 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg0f782312009-12-01 13:37:02 +0100259 return -EOPNOTSUPP;
260
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200261 sdata_lock(sdata);
Ilan Peer52b48102020-01-31 13:12:56 +0200262 err = __ieee80211_request_smps_mgd(sdata, smps_mode);
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200263 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +0100264
265 return err;
266}
267
268static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
269 [IEEE80211_SMPS_AUTOMATIC] = "auto",
270 [IEEE80211_SMPS_OFF] = "off",
271 [IEEE80211_SMPS_STATIC] = "static",
272 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
273};
274
275static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
276 char *buf, int buflen)
277{
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300278 if (sdata->vif.type == NL80211_IFTYPE_STATION)
279 return snprintf(buf, buflen, "request: %s\nused: %s\n",
280 smps_modes[sdata->u.mgd.req_smps],
281 smps_modes[sdata->smps_mode]);
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300282 return -EINVAL;
Johannes Berg0f782312009-12-01 13:37:02 +0100283}
284
285static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
286 const char *buf, int buflen)
287{
288 enum ieee80211_smps_mode mode;
289
290 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
291 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
292 int err = ieee80211_set_smps(sdata, mode);
293 if (!err)
294 return buflen;
295 return err;
296 }
297 }
298
299 return -EINVAL;
300}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100301IEEE80211_IF_FILE_RW(smps);
Jouni Malinen681d1192011-02-03 18:35:19 +0200302
Jouni Malinen681d1192011-02-03 18:35:19 +0200303static ssize_t ieee80211_if_parse_tkip_mic_test(
304 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
305{
306 struct ieee80211_local *local = sdata->local;
307 u8 addr[ETH_ALEN];
308 struct sk_buff *skb;
309 struct ieee80211_hdr *hdr;
310 __le16 fc;
311
Johannes Berg28656a12012-11-05 20:24:38 +0100312 if (!mac_pton(buf, addr))
Jouni Malinen681d1192011-02-03 18:35:19 +0200313 return -EINVAL;
314
315 if (!ieee80211_sdata_running(sdata))
316 return -ENOTCONN;
317
318 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
319 if (!skb)
320 return -ENOMEM;
321 skb_reserve(skb, local->hw.extra_tx_headroom);
322
Johannes Bergb080db52017-06-16 14:29:19 +0200323 hdr = skb_put_zero(skb, 24);
Jouni Malinen681d1192011-02-03 18:35:19 +0200324 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
325
326 switch (sdata->vif.type) {
327 case NL80211_IFTYPE_AP:
328 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
329 /* DA BSSID SA */
330 memcpy(hdr->addr1, addr, ETH_ALEN);
331 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
332 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
333 break;
334 case NL80211_IFTYPE_STATION:
335 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
336 /* BSSID SA DA */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200337 sdata_lock(sdata);
Johannes Berg41c97a22012-11-05 20:27:57 +0100338 if (!sdata->u.mgd.associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200339 sdata_unlock(sdata);
Jouni Malinen681d1192011-02-03 18:35:19 +0200340 dev_kfree_skb(skb);
341 return -ENOTCONN;
342 }
Johannes Berg41c97a22012-11-05 20:27:57 +0100343 memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
Jouni Malinen681d1192011-02-03 18:35:19 +0200344 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
345 memcpy(hdr->addr3, addr, ETH_ALEN);
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200346 sdata_unlock(sdata);
Jouni Malinen681d1192011-02-03 18:35:19 +0200347 break;
348 default:
349 dev_kfree_skb(skb);
350 return -EOPNOTSUPP;
351 }
352 hdr->frame_control = fc;
353
354 /*
355 * Add some length to the test frame to make it look bit more valid.
356 * The exact contents does not matter since the recipient is required
357 * to drop this because of the Michael MIC failure.
358 */
Johannes Bergb080db52017-06-16 14:29:19 +0200359 skb_put_zero(skb, 50);
Jouni Malinen681d1192011-02-03 18:35:19 +0200360
361 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
362
363 ieee80211_tx_skb(sdata, skb);
364
365 return buflen;
366}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100367IEEE80211_IF_FILE_W(tkip_mic_test);
Jouni Malinen681d1192011-02-03 18:35:19 +0200368
Eliad Peller802ee9e2014-02-11 12:36:18 +0200369static ssize_t ieee80211_if_parse_beacon_loss(
370 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
371{
372 if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
373 return -ENOTCONN;
374
375 ieee80211_beacon_loss(&sdata->vif);
376
377 return buflen;
378}
379IEEE80211_IF_FILE_W(beacon_loss);
380
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200381static ssize_t ieee80211_if_fmt_uapsd_queues(
382 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
383{
384 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
385
386 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
387}
388
389static ssize_t ieee80211_if_parse_uapsd_queues(
390 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
391{
392 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
393 u8 val;
394 int ret;
395
396 ret = kstrtou8(buf, 0, &val);
397 if (ret)
398 return ret;
399
400 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
401 return -ERANGE;
402
403 ifmgd->uapsd_queues = val;
404
405 return buflen;
406}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100407IEEE80211_IF_FILE_RW(uapsd_queues);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200408
409static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
410 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
411{
412 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
413
414 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
415}
416
417static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
418 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
419{
420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
421 unsigned long val;
422 int ret;
423
424 ret = kstrtoul(buf, 0, &val);
425 if (ret)
426 return -EINVAL;
427
428 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
429 return -ERANGE;
430
431 ifmgd->uapsd_max_sp_len = val;
432
433 return buflen;
434}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100435IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200436
Arik Nemtsov82c0cc90d2015-08-15 22:39:46 +0300437static ssize_t ieee80211_if_fmt_tdls_wider_bw(
438 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
439{
440 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
441 bool tdls_wider_bw;
442
443 tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
444 !ifmgd->tdls_wider_bw_prohibited;
445
446 return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
447}
448
449static ssize_t ieee80211_if_parse_tdls_wider_bw(
450 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
451{
452 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
453 u8 val;
454 int ret;
455
456 ret = kstrtou8(buf, 0, &val);
457 if (ret)
458 return ret;
459
460 ifmgd->tdls_wider_bw_prohibited = !val;
461 return buflen;
462}
463IEEE80211_IF_FILE_RW(tdls_wider_bw);
464
Jiri Bence9f207f2007-05-05 11:46:38 -0700465/* AP attributes */
Felix Fietkau030ef8f2012-04-23 19:49:02 +0200466IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
Marco Porschd012a602012-10-10 12:39:50 -0700467IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
468IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
Michael Braun72f15d52016-10-10 19:12:21 +0200469IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700470
471static ssize_t ieee80211_if_fmt_num_buffered_multicast(
472 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
473{
474 return scnprintf(buf, buflen, "%u\n",
Marco Porschd012a602012-10-10 12:39:50 -0700475 skb_queue_len(&sdata->u.ap.ps.bc_buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700476}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100477IEEE80211_IF_FILE_R(num_buffered_multicast);
Jiri Bence9f207f2007-05-05 11:46:38 -0700478
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200479static ssize_t ieee80211_if_fmt_aqm(
480 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
481{
482 struct ieee80211_local *local = sdata->local;
Miaoqing Pan8ed31a22019-09-27 10:03:16 +0800483 struct txq_info *txqi;
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200484 int len;
485
Miaoqing Pan8ed31a22019-09-27 10:03:16 +0800486 if (!sdata->vif.txq)
487 return 0;
488
489 txqi = to_txq_info(sdata->vif.txq);
490
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200491 spin_lock_bh(&local->fq.lock);
492 rcu_read_lock();
493
494 len = scnprintf(buf,
495 buflen,
496 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
497 "%u %u %u %u %u %u %u %u %u %u\n",
498 txqi->txq.ac,
499 txqi->tin.backlog_bytes,
500 txqi->tin.backlog_packets,
501 txqi->tin.flows,
502 txqi->cstats.drop_count,
503 txqi->cstats.ecn_mark,
504 txqi->tin.overlimit,
505 txqi->tin.collisions,
506 txqi->tin.tx_bytes,
507 txqi->tin.tx_packets);
508
509 rcu_read_unlock();
510 spin_unlock_bh(&local->fq.lock);
511
512 return len;
513}
514IEEE80211_IF_FILE_R(aqm);
515
Michael Braunebceec82016-11-22 11:52:18 +0100516IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
517
Eliad Peller37a41b42011-09-21 14:06:11 +0300518/* IBSS attributes */
519static ssize_t ieee80211_if_fmt_tsf(
520 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
521{
522 struct ieee80211_local *local = sdata->local;
523 u64 tsf;
524
525 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
526
527 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
528}
529
530static ssize_t ieee80211_if_parse_tsf(
531 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
532{
533 struct ieee80211_local *local = sdata->local;
534 unsigned long long tsf;
535 int ret;
Javier Cardona9bdd3a62012-03-31 11:31:31 -0700536 int tsf_is_delta = 0;
Eliad Peller37a41b42011-09-21 14:06:11 +0300537
538 if (strncmp(buf, "reset", 5) == 0) {
539 if (local->ops->reset_tsf) {
540 drv_reset_tsf(local, sdata);
541 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
542 }
543 } else {
Javier Cardona9bdd3a62012-03-31 11:31:31 -0700544 if (buflen > 10 && buf[1] == '=') {
545 if (buf[0] == '+')
546 tsf_is_delta = 1;
547 else if (buf[0] == '-')
548 tsf_is_delta = -1;
549 else
550 return -EINVAL;
551 buf += 2;
552 }
Eliad Peller37a41b42011-09-21 14:06:11 +0300553 ret = kstrtoull(buf, 10, &tsf);
554 if (ret < 0)
Johannes Berg6fc1da92012-11-05 20:30:39 +0100555 return ret;
Pedersen, Thomas354d3812016-09-28 16:56:28 -0700556 if (tsf_is_delta && local->ops->offset_tsf) {
557 drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
558 wiphy_info(local->hw.wiphy,
559 "debugfs offset TSF by %018lld\n",
560 tsf_is_delta * tsf);
561 } else if (local->ops->set_tsf) {
562 if (tsf_is_delta)
563 tsf = drv_get_tsf(local, sdata) +
564 tsf_is_delta * tsf;
Eliad Peller37a41b42011-09-21 14:06:11 +0300565 drv_set_tsf(local, sdata, tsf);
566 wiphy_info(local->hw.wiphy,
567 "debugfs set TSF to %#018llx\n", tsf);
568 }
569 }
570
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800571 ieee80211_recalc_dtim(local, sdata);
Eliad Peller37a41b42011-09-21 14:06:11 +0300572 return buflen;
573}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100574IEEE80211_IF_FILE_RW(tsf);
Eliad Peller37a41b42011-09-21 14:06:11 +0300575
576
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100577#ifdef CONFIG_MAC80211_MESH
Ashok Nagarajand4a5a482013-05-13 17:08:04 -0700578IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
579
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100580/* Mesh stats attributes */
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700581IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
582IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
Johannes Berg472dbc42008-09-11 00:01:49 +0200583IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
584IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700585IEEE80211_IF_FILE(dropped_frames_congestion,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800586 u.mesh.mshstats.dropped_frames_congestion, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100587IEEE80211_IF_FILE(dropped_frames_no_route,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800588 u.mesh.mshstats.dropped_frames_no_route, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100589
590/* Mesh parameters */
Johannes Berg36ff3822008-10-07 12:04:31 +0200591IEEE80211_IF_FILE(dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800592 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200593IEEE80211_IF_FILE(dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800594 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200595IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800596 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200597IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800598 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200599IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
Javier Cardona45904f22010-12-03 09:20:40 +0100600IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200601IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
602IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800603 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200604IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800605 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200606IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800607 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800608IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800609 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200610IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800611 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200612IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800613 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200614IEEE80211_IF_FILE(path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800615 u.mesh.mshcfg.path_refresh_time, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200616IEEE80211_IF_FILE(min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800617 u.mesh.mshcfg.min_discovery_timeout, DEC);
Rui Paulo63c57232009-11-09 23:46:57 +0000618IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800619 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
Javier Cardona16dd7262011-08-09 16:45:11 -0700620IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800621 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
Javier Cardona0507e152011-08-09 16:45:10 -0700622IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800623 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +0800624IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800625IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
Ashok Nagarajan4416f5d2012-05-07 21:00:32 -0700626IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +0800627IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
628 u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
629IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
630 u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +0800631IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
632 u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100633IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
634IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
635 u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
Bob Copeland01d66fb2018-10-25 17:36:34 -0400636IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
637 u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
Linus Lüssinge3718a62020-06-17 09:30:33 +0200638IEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC);
Markus Theil184eebe2020-06-11 16:02:37 +0200639IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer,
640 u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100641#endif
642
Johannes Berg0f782312009-12-01 13:37:02 +0100643#define DEBUGFS_ADD_MODE(name, mode) \
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100644 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
Tom Rix84674ef2020-11-27 11:38:42 -0800645 sdata, &name##_ops)
Johannes Berg0f782312009-12-01 13:37:02 +0100646
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100647#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
648
649static void add_common_files(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700650{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100651 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
652 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
Simon Wunderlich19468412012-01-28 17:25:33 +0100653 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
654 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200655 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
656 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
Johannes Berg08643312012-11-08 15:29:28 +0100657 DEBUGFS_ADD(hw_queues);
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200658
Miaoqing Pan8ed31a22019-09-27 10:03:16 +0800659 if (sdata->local->ops->wake_tx_queue &&
660 sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
661 sdata->vif.type != NL80211_IFTYPE_NAN)
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200662 DEBUGFS_ADD(aqm);
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100663}
Johannes Berg3e122be2008-07-09 14:40:34 +0200664
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100665static void add_sta_files(struct ieee80211_sub_if_data *sdata)
666{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100667 DEBUGFS_ADD(bssid);
668 DEBUGFS_ADD(aid);
Ben Greear78e443e2013-03-25 11:19:34 -0700669 DEBUGFS_ADD(beacon_timeout);
Johannes Berg0f782312009-12-01 13:37:02 +0100670 DEBUGFS_ADD_MODE(smps, 0600);
Jouni Malinen681d1192011-02-03 18:35:19 +0200671 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
Eliad Peller802ee9e2014-02-11 12:36:18 +0200672 DEBUGFS_ADD_MODE(beacon_loss, 0200);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200673 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
674 DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
Arik Nemtsov82c0cc90d2015-08-15 22:39:46 +0300675 DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
Jiri Bence9f207f2007-05-05 11:46:38 -0700676}
677
678static void add_ap_files(struct ieee80211_sub_if_data *sdata)
679{
Felix Fietkau030ef8f2012-04-23 19:49:02 +0200680 DEBUGFS_ADD(num_mcast_sta);
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300681 DEBUGFS_ADD_MODE(smps, 0600);
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100682 DEBUGFS_ADD(num_sta_ps);
683 DEBUGFS_ADD(dtim_count);
684 DEBUGFS_ADD(num_buffered_multicast);
Jouni Malinen681d1192011-02-03 18:35:19 +0200685 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
Michael Braunebceec82016-11-22 11:52:18 +0100686 DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
Jiri Bence9f207f2007-05-05 11:46:38 -0700687}
688
Michael Braun72f15d52016-10-10 19:12:21 +0200689static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
690{
691 /* add num_mcast_sta_vlan using name num_mcast_sta */
692 debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
693 sdata, &num_mcast_sta_vlan_ops);
694}
695
Eliad Peller37a41b42011-09-21 14:06:11 +0300696static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
697{
698 DEBUGFS_ADD_MODE(tsf, 0600);
699}
700
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100701#ifdef CONFIG_MAC80211_MESH
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100702
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800703static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
704{
705 DEBUGFS_ADD_MODE(tsf, 0600);
Ashok Nagarajand4a5a482013-05-13 17:08:04 -0700706 DEBUGFS_ADD_MODE(estab_plinks, 0400);
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800707}
708
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100709static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
710{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100711 struct dentry *dir = debugfs_create_dir("mesh_stats",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100712 sdata->vif.debugfs_dir);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100713#define MESHSTATS_ADD(name)\
Tom Rix84674ef2020-11-27 11:38:42 -0800714 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100715
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700716 MESHSTATS_ADD(fwded_mcast);
717 MESHSTATS_ADD(fwded_unicast);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100718 MESHSTATS_ADD(fwded_frames);
719 MESHSTATS_ADD(dropped_frames_ttl);
720 MESHSTATS_ADD(dropped_frames_no_route);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700721 MESHSTATS_ADD(dropped_frames_congestion);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100722#undef MESHSTATS_ADD
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100723}
724
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100725static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
726{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100727 struct dentry *dir = debugfs_create_dir("mesh_config",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100728 sdata->vif.debugfs_dir);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100729
730#define MESHPARAMS_ADD(name) \
Tom Rix84674ef2020-11-27 11:38:42 -0800731 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100732
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100733 MESHPARAMS_ADD(dot11MeshMaxRetries);
734 MESHPARAMS_ADD(dot11MeshRetryTimeout);
735 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
736 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
737 MESHPARAMS_ADD(dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +0100738 MESHPARAMS_ADD(element_ttl);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100739 MESHPARAMS_ADD(auto_open_plinks);
740 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
741 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
742 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800743 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100744 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
745 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
746 MESHPARAMS_ADD(path_refresh_time);
747 MESHPARAMS_ADD(min_discovery_timeout);
Javier Cardona699403d2011-08-09 16:45:09 -0700748 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -0700749 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
Chun-Yeow Yeoh8c06e8c2012-05-31 18:17:30 +0800750 MESHPARAMS_ADD(dot11MeshForwarding);
Javier Cardona16dd7262011-08-09 16:45:11 -0700751 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800752 MESHPARAMS_ADD(rssi_threshold);
Ashok Nagarajan4416f5d2012-05-07 21:00:32 -0700753 MESHPARAMS_ADD(ht_opmode);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +0800754 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
755 MESHPARAMS_ADD(dot11MeshHWMProotInterval);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +0800756 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100757 MESHPARAMS_ADD(power_mode);
758 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
Bob Copeland01d66fb2018-10-25 17:36:34 -0400759 MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
Linus Lüssinge3718a62020-06-17 09:30:33 +0200760 MESHPARAMS_ADD(dot11MeshNolearn);
Markus Theil184eebe2020-06-11 16:02:37 +0200761 MESHPARAMS_ADD(dot11MeshConnectedToAuthServer);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100762#undef MESHPARAMS_ADD
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100763}
764#endif
765
Jiri Bence9f207f2007-05-05 11:46:38 -0700766static void add_files(struct ieee80211_sub_if_data *sdata)
767{
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100768 if (!sdata->vif.debugfs_dir)
Jiri Bence9f207f2007-05-05 11:46:38 -0700769 return;
770
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100771 DEBUGFS_ADD(flags);
772 DEBUGFS_ADD(state);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200773 DEBUGFS_ADD(txpower);
774 DEBUGFS_ADD(user_power_level);
775 DEBUGFS_ADD(ap_power_level);
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100776
777 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
778 add_common_files(sdata);
779
Johannes Berg51fb61e2007-12-19 01:31:27 +0100780 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200781 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100782#ifdef CONFIG_MAC80211_MESH
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800783 add_mesh_files(sdata);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100784 add_mesh_stats(sdata);
785 add_mesh_config(sdata);
786#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200787 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200788 case NL80211_IFTYPE_STATION:
Jiri Bence9f207f2007-05-05 11:46:38 -0700789 add_sta_files(sdata);
790 break;
Johannes Berg46900292009-02-15 12:44:28 +0100791 case NL80211_IFTYPE_ADHOC:
Eliad Peller37a41b42011-09-21 14:06:11 +0300792 add_ibss_files(sdata);
Johannes Berg46900292009-02-15 12:44:28 +0100793 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200794 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700795 add_ap_files(sdata);
796 break;
Michael Braun72f15d52016-10-10 19:12:21 +0200797 case NL80211_IFTYPE_AP_VLAN:
798 add_vlan_files(sdata);
799 break;
Jiri Bence9f207f2007-05-05 11:46:38 -0700800 default:
801 break;
802 }
803}
804
Jiri Bence9f207f2007-05-05 11:46:38 -0700805void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
806{
807 char buf[10+IFNAMSIZ];
808
Johannes Berg47846c92009-11-25 17:46:19 +0100809 sprintf(buf, "netdev:%s", sdata->name);
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100810 sdata->vif.debugfs_dir = debugfs_create_dir(buf,
Jiri Bence9f207f2007-05-05 11:46:38 -0700811 sdata->local->hw.wiphy->debugfsdir);
Greg Kroah-Hartman5a7bb7c2019-06-14 08:59:34 +0200812 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
813 sdata->vif.debugfs_dir);
Johannes Berg75636522008-07-09 14:40:35 +0200814 add_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700815}
816
817void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
818{
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100819 if (!sdata->vif.debugfs_dir)
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100820 return;
821
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100822 debugfs_remove_recursive(sdata->vif.debugfs_dir);
823 sdata->vif.debugfs_dir = NULL;
Tom Hughes44790042015-06-29 19:41:49 +0100824 sdata->debugfs.subdir_stations = NULL;
Jiri Bence9f207f2007-05-05 11:46:38 -0700825}
826
Johannes Berg47846c92009-11-25 17:46:19 +0100827void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700828{
Johannes Berg7c8081e2007-06-21 18:30:19 +0200829 struct dentry *dir;
Johannes Berg47846c92009-11-25 17:46:19 +0100830 char buf[10 + IFNAMSIZ];
Johannes Berg3e122be2008-07-09 14:40:34 +0200831
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100832 dir = sdata->vif.debugfs_dir;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200833
Johannes Berg51787912019-04-15 11:39:33 +0200834 if (IS_ERR_OR_NULL(dir))
Johannes Berg47846c92009-11-25 17:46:19 +0100835 return;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200836
Johannes Berg47846c92009-11-25 17:46:19 +0100837 sprintf(buf, "netdev:%s", sdata->name);
Greg Kroah-Hartman5a7bb7c2019-06-14 08:59:34 +0200838 debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700839}