blob: f1f2e1c7ac0c91c2f127dd1cbe4ac150b4a133e0 [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>
Jiri Bence9f207f2007-05-05 11:46:38 -07005 */
6
7#include <linux/kernel.h>
8#include <linux/device.h>
9#include <linux/if.h>
Johannes Berg28656a12012-11-05 20:24:38 +010010#include <linux/if_ether.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070011#include <linux/interrupt.h>
12#include <linux/netdevice.h>
13#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070015#include <linux/notifier.h>
16#include <net/mac80211.h>
17#include <net/cfg80211.h>
18#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040019#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070020#include "debugfs.h"
21#include "debugfs_netdev.h"
Eliad Peller37a41b42011-09-21 14:06:11 +030022#include "driver-ops.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070023
24static ssize_t ieee80211_if_read(
25 struct ieee80211_sub_if_data *sdata,
26 char __user *userbuf,
27 size_t count, loff_t *ppos,
28 ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
29{
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +020030 char buf[200];
Jiri Bence9f207f2007-05-05 11:46:38 -070031 ssize_t ret = -EINVAL;
32
33 read_lock(&dev_base_lock);
Arik Nemtsov923eaf32014-05-26 14:40:51 +030034 ret = (*format)(sdata, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -070035 read_unlock(&dev_base_lock);
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070036
Jouni Malinen681d1192011-02-03 18:35:19 +020037 if (ret >= 0)
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070038 ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
39
Jiri Bence9f207f2007-05-05 11:46:38 -070040 return ret;
41}
42
Johannes Berg0f782312009-12-01 13:37:02 +010043static ssize_t ieee80211_if_write(
44 struct ieee80211_sub_if_data *sdata,
45 const char __user *userbuf,
46 size_t count, loff_t *ppos,
47 ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
48{
Eliad Pellerada577c2012-03-14 16:15:02 +020049 char buf[64];
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010050 ssize_t ret;
Johannes Berg0f782312009-12-01 13:37:02 +010051
Eliad Pellerada577c2012-03-14 16:15:02 +020052 if (count >= sizeof(buf))
53 return -E2BIG;
Johannes Berg0f782312009-12-01 13:37:02 +010054
55 if (copy_from_user(buf, userbuf, count))
Eliad Pellerada577c2012-03-14 16:15:02 +020056 return -EFAULT;
57 buf[count] = '\0';
Johannes Berg0f782312009-12-01 13:37:02 +010058
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010059 ret = -ENODEV;
Johannes Berg0f782312009-12-01 13:37:02 +010060 rtnl_lock();
Arik Nemtsov923eaf32014-05-26 14:40:51 +030061 ret = (*write)(sdata, buf, count);
Johannes Berg0f782312009-12-01 13:37:02 +010062 rtnl_unlock();
63
64 return ret;
65}
66
Jiri Bence9f207f2007-05-05 11:46:38 -070067#define IEEE80211_IF_FMT(name, field, format_string) \
68static ssize_t ieee80211_if_fmt_##name( \
69 const struct ieee80211_sub_if_data *sdata, char *buf, \
70 int buflen) \
71{ \
72 return scnprintf(buf, buflen, format_string, sdata->field); \
73}
74#define IEEE80211_IF_FMT_DEC(name, field) \
75 IEEE80211_IF_FMT(name, field, "%d\n")
76#define IEEE80211_IF_FMT_HEX(name, field) \
77 IEEE80211_IF_FMT(name, field, "%#x\n")
Ben Greear4914b3b2011-01-27 22:09:34 -080078#define IEEE80211_IF_FMT_LHEX(name, field) \
79 IEEE80211_IF_FMT(name, field, "%#lx\n")
Jiri Bence9f207f2007-05-05 11:46:38 -070080#define IEEE80211_IF_FMT_SIZE(name, field) \
81 IEEE80211_IF_FMT(name, field, "%zd\n")
82
Simon Wunderlich19468412012-01-28 17:25:33 +010083#define IEEE80211_IF_FMT_HEXARRAY(name, field) \
84static ssize_t ieee80211_if_fmt_##name( \
85 const struct ieee80211_sub_if_data *sdata, \
86 char *buf, int buflen) \
87{ \
88 char *p = buf; \
89 int i; \
90 for (i = 0; i < sizeof(sdata->field); i++) { \
91 p += scnprintf(p, buflen + buf - p, "%.2x ", \
92 sdata->field[i]); \
93 } \
94 p += scnprintf(p, buflen + buf - p, "\n"); \
95 return p - buf; \
96}
97
Jiri Bence9f207f2007-05-05 11:46:38 -070098#define IEEE80211_IF_FMT_ATOMIC(name, field) \
99static ssize_t ieee80211_if_fmt_##name( \
100 const struct ieee80211_sub_if_data *sdata, \
101 char *buf, int buflen) \
102{ \
103 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
104}
105
106#define IEEE80211_IF_FMT_MAC(name, field) \
107static ssize_t ieee80211_if_fmt_##name( \
108 const struct ieee80211_sub_if_data *sdata, char *buf, \
109 int buflen) \
110{ \
Johannes Berg0c68ae262008-10-27 15:56:10 -0700111 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700112}
113
Ben Greear78e443e2013-03-25 11:19:34 -0700114#define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field) \
115static ssize_t ieee80211_if_fmt_##name( \
116 const struct ieee80211_sub_if_data *sdata, \
117 char *buf, int buflen) \
118{ \
119 return scnprintf(buf, buflen, "%d\n", \
120 jiffies_to_msecs(sdata->field)); \
121}
122
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100123#define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
124static const struct file_operations name##_ops = { \
125 .read = (_read), \
126 .write = (_write), \
127 .open = simple_open, \
128 .llseek = generic_file_llseek, \
129}
130
131#define _IEEE80211_IF_FILE_R_FN(name) \
Jiri Bence9f207f2007-05-05 11:46:38 -0700132static ssize_t ieee80211_if_read_##name(struct file *file, \
133 char __user *userbuf, \
134 size_t count, loff_t *ppos) \
135{ \
136 return ieee80211_if_read(file->private_data, \
137 userbuf, count, ppos, \
138 ieee80211_if_fmt_##name); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700139}
140
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100141#define _IEEE80211_IF_FILE_W_FN(name) \
Johannes Berg0f782312009-12-01 13:37:02 +0100142static ssize_t ieee80211_if_write_##name(struct file *file, \
143 const char __user *userbuf, \
144 size_t count, loff_t *ppos) \
145{ \
146 return ieee80211_if_write(file->private_data, userbuf, count, \
147 ppos, ieee80211_if_parse_##name); \
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100148}
Johannes Berg0f782312009-12-01 13:37:02 +0100149
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100150#define IEEE80211_IF_FILE_R(name) \
151 _IEEE80211_IF_FILE_R_FN(name) \
152 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
153
154#define IEEE80211_IF_FILE_W(name) \
155 _IEEE80211_IF_FILE_W_FN(name) \
156 _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
157
158#define IEEE80211_IF_FILE_RW(name) \
159 _IEEE80211_IF_FILE_R_FN(name) \
160 _IEEE80211_IF_FILE_W_FN(name) \
161 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \
162 ieee80211_if_write_##name)
Johannes Berg0f782312009-12-01 13:37:02 +0100163
Jiri Bence9f207f2007-05-05 11:46:38 -0700164#define IEEE80211_IF_FILE(name, field, format) \
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100165 IEEE80211_IF_FMT_##format(name, field) \
166 IEEE80211_IF_FILE_R(name)
Jiri Bence9f207f2007-05-05 11:46:38 -0700167
168/* common attributes */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200169IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200170 HEX);
Johannes Berg57fbcce2016-04-12 15:56:15 +0200171IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200172 HEX);
Simon Wunderlich19468412012-01-28 17:25:33 +0100173IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200174 rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
Simon Wunderlich19468412012-01-28 17:25:33 +0100175IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200176 rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
Simon Wunderlich19468412012-01-28 17:25:33 +0100177
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200178static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
179 const struct ieee80211_sub_if_data *sdata,
180 char *buf, int buflen)
181{
182 int i, len = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200183 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200184
185 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
186 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
187 len += scnprintf(buf + len, buflen - len, "\n");
188
189 return len;
190}
191
192IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
193
194static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
195 const struct ieee80211_sub_if_data *sdata,
196 char *buf, int buflen)
197{
198 int i, len = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200199 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200200
201 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
202 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
203 len += scnprintf(buf + len, buflen - len, "\n");
204
205 return len;
206}
207
208IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
209
Ben Greear4914b3b2011-01-27 22:09:34 -0800210IEEE80211_IF_FILE(flags, flags, HEX);
211IEEE80211_IF_FILE(state, state, LHEX);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200212IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
213IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
214IEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700215
Johannes Berg08643312012-11-08 15:29:28 +0100216static ssize_t
217ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
218 char *buf, int buflen)
219{
220 int len;
221
222 len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
223 sdata->vif.hw_queue[IEEE80211_AC_VO],
224 sdata->vif.hw_queue[IEEE80211_AC_VI],
225 sdata->vif.hw_queue[IEEE80211_AC_BE],
226 sdata->vif.hw_queue[IEEE80211_AC_BK]);
227
228 if (sdata->vif.type == NL80211_IFTYPE_AP)
229 len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
230 sdata->vif.cab_queue);
231
232 return len;
233}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100234IEEE80211_IF_FILE_R(hw_queues);
Johannes Berg08643312012-11-08 15:29:28 +0100235
Johannes Berg46900292009-02-15 12:44:28 +0100236/* STA attributes */
Johannes Berg46900292009-02-15 12:44:28 +0100237IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
Johannes Berg46900292009-02-15 12:44:28 +0100238IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
Ben Greear78e443e2013-03-25 11:19:34 -0700239IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
Jiri Bence9f207f2007-05-05 11:46:38 -0700240
Johannes Berg0f782312009-12-01 13:37:02 +0100241static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
242 enum ieee80211_smps_mode smps_mode)
243{
244 struct ieee80211_local *local = sdata->local;
245 int err;
246
Eliad Peller0d8614b2014-09-10 14:07:36 +0300247 if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
Johannes Berg0f782312009-12-01 13:37:02 +0100248 smps_mode == IEEE80211_SMPS_STATIC)
249 return -EINVAL;
250
251 /* auto should be dynamic if in PS mode */
Eliad Peller0d8614b2014-09-10 14:07:36 +0300252 if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
Johannes Berg0f782312009-12-01 13:37:02 +0100253 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
254 smps_mode == IEEE80211_SMPS_AUTOMATIC))
255 return -EINVAL;
256
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300257 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
258 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg0f782312009-12-01 13:37:02 +0100259 return -EOPNOTSUPP;
260
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200261 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300262 if (sdata->vif.type == NL80211_IFTYPE_STATION)
263 err = __ieee80211_request_smps_mgd(sdata, smps_mode);
264 else
265 err = __ieee80211_request_smps_ap(sdata, smps_mode);
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200266 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +0100267
268 return err;
269}
270
271static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
272 [IEEE80211_SMPS_AUTOMATIC] = "auto",
273 [IEEE80211_SMPS_OFF] = "off",
274 [IEEE80211_SMPS_STATIC] = "static",
275 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
276};
277
278static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
279 char *buf, int buflen)
280{
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300281 if (sdata->vif.type == NL80211_IFTYPE_STATION)
282 return snprintf(buf, buflen, "request: %s\nused: %s\n",
283 smps_modes[sdata->u.mgd.req_smps],
284 smps_modes[sdata->smps_mode]);
285 if (sdata->vif.type == NL80211_IFTYPE_AP)
286 return snprintf(buf, buflen, "request: %s\nused: %s\n",
287 smps_modes[sdata->u.ap.req_smps],
288 smps_modes[sdata->smps_mode]);
289 return -EINVAL;
Johannes Berg0f782312009-12-01 13:37:02 +0100290}
291
292static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
293 const char *buf, int buflen)
294{
295 enum ieee80211_smps_mode mode;
296
297 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
298 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
299 int err = ieee80211_set_smps(sdata, mode);
300 if (!err)
301 return buflen;
302 return err;
303 }
304 }
305
306 return -EINVAL;
307}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100308IEEE80211_IF_FILE_RW(smps);
Jouni Malinen681d1192011-02-03 18:35:19 +0200309
Jouni Malinen681d1192011-02-03 18:35:19 +0200310static ssize_t ieee80211_if_parse_tkip_mic_test(
311 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
312{
313 struct ieee80211_local *local = sdata->local;
314 u8 addr[ETH_ALEN];
315 struct sk_buff *skb;
316 struct ieee80211_hdr *hdr;
317 __le16 fc;
318
Johannes Berg28656a12012-11-05 20:24:38 +0100319 if (!mac_pton(buf, addr))
Jouni Malinen681d1192011-02-03 18:35:19 +0200320 return -EINVAL;
321
322 if (!ieee80211_sdata_running(sdata))
323 return -ENOTCONN;
324
325 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
326 if (!skb)
327 return -ENOMEM;
328 skb_reserve(skb, local->hw.extra_tx_headroom);
329
Johannes Bergb080db52017-06-16 14:29:19 +0200330 hdr = skb_put_zero(skb, 24);
Jouni Malinen681d1192011-02-03 18:35:19 +0200331 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
332
333 switch (sdata->vif.type) {
334 case NL80211_IFTYPE_AP:
335 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
336 /* DA BSSID SA */
337 memcpy(hdr->addr1, addr, ETH_ALEN);
338 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
339 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
340 break;
341 case NL80211_IFTYPE_STATION:
342 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
343 /* BSSID SA DA */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200344 sdata_lock(sdata);
Johannes Berg41c97a22012-11-05 20:27:57 +0100345 if (!sdata->u.mgd.associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200346 sdata_unlock(sdata);
Jouni Malinen681d1192011-02-03 18:35:19 +0200347 dev_kfree_skb(skb);
348 return -ENOTCONN;
349 }
Johannes Berg41c97a22012-11-05 20:27:57 +0100350 memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
Jouni Malinen681d1192011-02-03 18:35:19 +0200351 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
352 memcpy(hdr->addr3, addr, ETH_ALEN);
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200353 sdata_unlock(sdata);
Jouni Malinen681d1192011-02-03 18:35:19 +0200354 break;
355 default:
356 dev_kfree_skb(skb);
357 return -EOPNOTSUPP;
358 }
359 hdr->frame_control = fc;
360
361 /*
362 * Add some length to the test frame to make it look bit more valid.
363 * The exact contents does not matter since the recipient is required
364 * to drop this because of the Michael MIC failure.
365 */
Johannes Bergb080db52017-06-16 14:29:19 +0200366 skb_put_zero(skb, 50);
Jouni Malinen681d1192011-02-03 18:35:19 +0200367
368 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
369
370 ieee80211_tx_skb(sdata, skb);
371
372 return buflen;
373}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100374IEEE80211_IF_FILE_W(tkip_mic_test);
Jouni Malinen681d1192011-02-03 18:35:19 +0200375
Eliad Peller802ee9e2014-02-11 12:36:18 +0200376static ssize_t ieee80211_if_parse_beacon_loss(
377 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
378{
379 if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
380 return -ENOTCONN;
381
382 ieee80211_beacon_loss(&sdata->vif);
383
384 return buflen;
385}
386IEEE80211_IF_FILE_W(beacon_loss);
387
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200388static ssize_t ieee80211_if_fmt_uapsd_queues(
389 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
390{
391 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
392
393 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
394}
395
396static ssize_t ieee80211_if_parse_uapsd_queues(
397 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
398{
399 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
400 u8 val;
401 int ret;
402
403 ret = kstrtou8(buf, 0, &val);
404 if (ret)
405 return ret;
406
407 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
408 return -ERANGE;
409
410 ifmgd->uapsd_queues = val;
411
412 return buflen;
413}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100414IEEE80211_IF_FILE_RW(uapsd_queues);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200415
416static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
417 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
418{
419 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
420
421 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
422}
423
424static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
425 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
426{
427 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
428 unsigned long val;
429 int ret;
430
431 ret = kstrtoul(buf, 0, &val);
432 if (ret)
433 return -EINVAL;
434
435 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
436 return -ERANGE;
437
438 ifmgd->uapsd_max_sp_len = val;
439
440 return buflen;
441}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100442IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200443
Arik Nemtsov82c0cc90d2015-08-15 22:39:46 +0300444static ssize_t ieee80211_if_fmt_tdls_wider_bw(
445 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
446{
447 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
448 bool tdls_wider_bw;
449
450 tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
451 !ifmgd->tdls_wider_bw_prohibited;
452
453 return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
454}
455
456static ssize_t ieee80211_if_parse_tdls_wider_bw(
457 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
458{
459 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
460 u8 val;
461 int ret;
462
463 ret = kstrtou8(buf, 0, &val);
464 if (ret)
465 return ret;
466
467 ifmgd->tdls_wider_bw_prohibited = !val;
468 return buflen;
469}
470IEEE80211_IF_FILE_RW(tdls_wider_bw);
471
Jiri Bence9f207f2007-05-05 11:46:38 -0700472/* AP attributes */
Felix Fietkau030ef8f2012-04-23 19:49:02 +0200473IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
Marco Porschd012a602012-10-10 12:39:50 -0700474IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
475IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
Michael Braun72f15d52016-10-10 19:12:21 +0200476IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700477
478static ssize_t ieee80211_if_fmt_num_buffered_multicast(
479 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
480{
481 return scnprintf(buf, buflen, "%u\n",
Marco Porschd012a602012-10-10 12:39:50 -0700482 skb_queue_len(&sdata->u.ap.ps.bc_buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700483}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100484IEEE80211_IF_FILE_R(num_buffered_multicast);
Jiri Bence9f207f2007-05-05 11:46:38 -0700485
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200486static ssize_t ieee80211_if_fmt_aqm(
487 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
488{
489 struct ieee80211_local *local = sdata->local;
490 struct txq_info *txqi = to_txq_info(sdata->vif.txq);
491 int len;
492
493 spin_lock_bh(&local->fq.lock);
494 rcu_read_lock();
495
496 len = scnprintf(buf,
497 buflen,
498 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
499 "%u %u %u %u %u %u %u %u %u %u\n",
500 txqi->txq.ac,
501 txqi->tin.backlog_bytes,
502 txqi->tin.backlog_packets,
503 txqi->tin.flows,
504 txqi->cstats.drop_count,
505 txqi->cstats.ecn_mark,
506 txqi->tin.overlimit,
507 txqi->tin.collisions,
508 txqi->tin.tx_bytes,
509 txqi->tin.tx_packets);
510
511 rcu_read_unlock();
512 spin_unlock_bh(&local->fq.lock);
513
514 return len;
515}
516IEEE80211_IF_FILE_R(aqm);
517
Michael Braunebceec82016-11-22 11:52:18 +0100518IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
519
Eliad Peller37a41b42011-09-21 14:06:11 +0300520/* IBSS attributes */
521static ssize_t ieee80211_if_fmt_tsf(
522 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
523{
524 struct ieee80211_local *local = sdata->local;
525 u64 tsf;
526
527 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
528
529 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
530}
531
532static ssize_t ieee80211_if_parse_tsf(
533 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
534{
535 struct ieee80211_local *local = sdata->local;
536 unsigned long long tsf;
537 int ret;
Javier Cardona9bdd3a62012-03-31 11:31:31 -0700538 int tsf_is_delta = 0;
Eliad Peller37a41b42011-09-21 14:06:11 +0300539
540 if (strncmp(buf, "reset", 5) == 0) {
541 if (local->ops->reset_tsf) {
542 drv_reset_tsf(local, sdata);
543 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
544 }
545 } else {
Javier Cardona9bdd3a62012-03-31 11:31:31 -0700546 if (buflen > 10 && buf[1] == '=') {
547 if (buf[0] == '+')
548 tsf_is_delta = 1;
549 else if (buf[0] == '-')
550 tsf_is_delta = -1;
551 else
552 return -EINVAL;
553 buf += 2;
554 }
Eliad Peller37a41b42011-09-21 14:06:11 +0300555 ret = kstrtoull(buf, 10, &tsf);
556 if (ret < 0)
Johannes Berg6fc1da92012-11-05 20:30:39 +0100557 return ret;
Pedersen, Thomas354d3812016-09-28 16:56:28 -0700558 if (tsf_is_delta && local->ops->offset_tsf) {
559 drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
560 wiphy_info(local->hw.wiphy,
561 "debugfs offset TSF by %018lld\n",
562 tsf_is_delta * tsf);
563 } else if (local->ops->set_tsf) {
564 if (tsf_is_delta)
565 tsf = drv_get_tsf(local, sdata) +
566 tsf_is_delta * tsf;
Eliad Peller37a41b42011-09-21 14:06:11 +0300567 drv_set_tsf(local, sdata, tsf);
568 wiphy_info(local->hw.wiphy,
569 "debugfs set TSF to %#018llx\n", tsf);
570 }
571 }
572
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800573 ieee80211_recalc_dtim(local, sdata);
Eliad Peller37a41b42011-09-21 14:06:11 +0300574 return buflen;
575}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100576IEEE80211_IF_FILE_RW(tsf);
Eliad Peller37a41b42011-09-21 14:06:11 +0300577
578
Jiri Bence9f207f2007-05-05 11:46:38 -0700579/* WDS attributes */
580IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
581
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100582#ifdef CONFIG_MAC80211_MESH
Ashok Nagarajand4a5a482013-05-13 17:08:04 -0700583IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
584
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100585/* Mesh stats attributes */
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700586IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
587IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
Johannes Berg472dbc42008-09-11 00:01:49 +0200588IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
589IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700590IEEE80211_IF_FILE(dropped_frames_congestion,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800591 u.mesh.mshstats.dropped_frames_congestion, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100592IEEE80211_IF_FILE(dropped_frames_no_route,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800593 u.mesh.mshstats.dropped_frames_no_route, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100594
595/* Mesh parameters */
Johannes Berg36ff3822008-10-07 12:04:31 +0200596IEEE80211_IF_FILE(dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800597 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200598IEEE80211_IF_FILE(dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800599 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200600IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800601 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200602IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800603 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200604IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
Javier Cardona45904f22010-12-03 09:20:40 +0100605IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200606IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
607IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800608 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200609IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800610 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200611IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800612 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800613IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800614 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200615IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800616 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200617IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800618 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200619IEEE80211_IF_FILE(path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800620 u.mesh.mshcfg.path_refresh_time, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200621IEEE80211_IF_FILE(min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800622 u.mesh.mshcfg.min_discovery_timeout, DEC);
Rui Paulo63c57232009-11-09 23:46:57 +0000623IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800624 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
Javier Cardona16dd7262011-08-09 16:45:11 -0700625IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800626 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
Javier Cardona0507e152011-08-09 16:45:10 -0700627IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800628 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +0800629IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800630IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
Ashok Nagarajan4416f5d2012-05-07 21:00:32 -0700631IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +0800632IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
633 u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
634IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
635 u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +0800636IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
637 u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100638IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
639IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
640 u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
Bob Copeland01d66fb2018-10-25 17:36:34 -0400641IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
642 u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100643#endif
644
Johannes Berg0f782312009-12-01 13:37:02 +0100645#define DEBUGFS_ADD_MODE(name, mode) \
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100646 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
Johannes Berg0f782312009-12-01 13:37:02 +0100647 sdata, &name##_ops);
648
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100649#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
650
651static void add_common_files(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700652{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100653 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
654 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
Simon Wunderlich19468412012-01-28 17:25:33 +0100655 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
656 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200657 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
658 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
Johannes Berg08643312012-11-08 15:29:28 +0100659 DEBUGFS_ADD(hw_queues);
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200660
661 if (sdata->local->ops->wake_tx_queue)
662 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
Jiri Bence9f207f2007-05-05 11:46:38 -0700701static void add_wds_files(struct ieee80211_sub_if_data *sdata)
702{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100703 DEBUGFS_ADD(peer);
Jiri Bence9f207f2007-05-05 11:46:38 -0700704}
705
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100706#ifdef CONFIG_MAC80211_MESH
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100707
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800708static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
709{
710 DEBUGFS_ADD_MODE(tsf, 0600);
Ashok Nagarajand4a5a482013-05-13 17:08:04 -0700711 DEBUGFS_ADD_MODE(estab_plinks, 0400);
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800712}
713
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100714static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
715{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100716 struct dentry *dir = debugfs_create_dir("mesh_stats",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100717 sdata->vif.debugfs_dir);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100718#define MESHSTATS_ADD(name)\
719 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
720
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700721 MESHSTATS_ADD(fwded_mcast);
722 MESHSTATS_ADD(fwded_unicast);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100723 MESHSTATS_ADD(fwded_frames);
724 MESHSTATS_ADD(dropped_frames_ttl);
725 MESHSTATS_ADD(dropped_frames_no_route);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700726 MESHSTATS_ADD(dropped_frames_congestion);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100727#undef MESHSTATS_ADD
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100728}
729
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100730static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
731{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100732 struct dentry *dir = debugfs_create_dir("mesh_config",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100733 sdata->vif.debugfs_dir);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100734
735#define MESHPARAMS_ADD(name) \
736 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
737
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100738 MESHPARAMS_ADD(dot11MeshMaxRetries);
739 MESHPARAMS_ADD(dot11MeshRetryTimeout);
740 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
741 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
742 MESHPARAMS_ADD(dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +0100743 MESHPARAMS_ADD(element_ttl);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100744 MESHPARAMS_ADD(auto_open_plinks);
745 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
746 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
747 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800748 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100749 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
750 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
751 MESHPARAMS_ADD(path_refresh_time);
752 MESHPARAMS_ADD(min_discovery_timeout);
Javier Cardona699403d2011-08-09 16:45:09 -0700753 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -0700754 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
Chun-Yeow Yeoh8c06e8c2012-05-31 18:17:30 +0800755 MESHPARAMS_ADD(dot11MeshForwarding);
Javier Cardona16dd7262011-08-09 16:45:11 -0700756 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800757 MESHPARAMS_ADD(rssi_threshold);
Ashok Nagarajan4416f5d2012-05-07 21:00:32 -0700758 MESHPARAMS_ADD(ht_opmode);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +0800759 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
760 MESHPARAMS_ADD(dot11MeshHWMProotInterval);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +0800761 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100762 MESHPARAMS_ADD(power_mode);
763 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
Bob Copeland01d66fb2018-10-25 17:36:34 -0400764 MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100765#undef MESHPARAMS_ADD
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100766}
767#endif
768
Jiri Bence9f207f2007-05-05 11:46:38 -0700769static void add_files(struct ieee80211_sub_if_data *sdata)
770{
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100771 if (!sdata->vif.debugfs_dir)
Jiri Bence9f207f2007-05-05 11:46:38 -0700772 return;
773
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100774 DEBUGFS_ADD(flags);
775 DEBUGFS_ADD(state);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200776 DEBUGFS_ADD(txpower);
777 DEBUGFS_ADD(user_power_level);
778 DEBUGFS_ADD(ap_power_level);
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100779
780 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
781 add_common_files(sdata);
782
Johannes Berg51fb61e2007-12-19 01:31:27 +0100783 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200784 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100785#ifdef CONFIG_MAC80211_MESH
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800786 add_mesh_files(sdata);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100787 add_mesh_stats(sdata);
788 add_mesh_config(sdata);
789#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200790 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200791 case NL80211_IFTYPE_STATION:
Jiri Bence9f207f2007-05-05 11:46:38 -0700792 add_sta_files(sdata);
793 break;
Johannes Berg46900292009-02-15 12:44:28 +0100794 case NL80211_IFTYPE_ADHOC:
Eliad Peller37a41b42011-09-21 14:06:11 +0300795 add_ibss_files(sdata);
Johannes Berg46900292009-02-15 12:44:28 +0100796 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200797 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700798 add_ap_files(sdata);
799 break;
Michael Braun72f15d52016-10-10 19:12:21 +0200800 case NL80211_IFTYPE_AP_VLAN:
801 add_vlan_files(sdata);
802 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200803 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700804 add_wds_files(sdata);
805 break;
Jiri Bence9f207f2007-05-05 11:46:38 -0700806 default:
807 break;
808 }
809}
810
Jiri Bence9f207f2007-05-05 11:46:38 -0700811void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
812{
813 char buf[10+IFNAMSIZ];
814
Johannes Berg47846c92009-11-25 17:46:19 +0100815 sprintf(buf, "netdev:%s", sdata->name);
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100816 sdata->vif.debugfs_dir = debugfs_create_dir(buf,
Jiri Bence9f207f2007-05-05 11:46:38 -0700817 sdata->local->hw.wiphy->debugfsdir);
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100818 if (sdata->vif.debugfs_dir)
Ben Greear295bafb2010-09-22 20:29:01 -0700819 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100820 sdata->vif.debugfs_dir);
Johannes Berg75636522008-07-09 14:40:35 +0200821 add_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700822}
823
824void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
825{
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100826 if (!sdata->vif.debugfs_dir)
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100827 return;
828
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100829 debugfs_remove_recursive(sdata->vif.debugfs_dir);
830 sdata->vif.debugfs_dir = NULL;
Tom Hughes44790042015-06-29 19:41:49 +0100831 sdata->debugfs.subdir_stations = NULL;
Jiri Bence9f207f2007-05-05 11:46:38 -0700832}
833
Johannes Berg47846c92009-11-25 17:46:19 +0100834void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700835{
Johannes Berg7c8081e2007-06-21 18:30:19 +0200836 struct dentry *dir;
Johannes Berg47846c92009-11-25 17:46:19 +0100837 char buf[10 + IFNAMSIZ];
Johannes Berg3e122be2008-07-09 14:40:34 +0200838
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100839 dir = sdata->vif.debugfs_dir;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200840
Johannes Berg51787912019-04-15 11:39:33 +0200841 if (IS_ERR_OR_NULL(dir))
Johannes Berg47846c92009-11-25 17:46:19 +0100842 return;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200843
Johannes Berg47846c92009-11-25 17:46:19 +0100844 sprintf(buf, "netdev:%s", sdata->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200845 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200846 sdata_err(sdata,
847 "debugfs: failed to rename debugfs dir to %s\n",
848 buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700849}