blob: 9769db9818d2f4c468dd4128ac243d17ae7e15ba [file] [log] [blame]
Jiri Bence9f207f2007-05-05 11:46:38 -07001/*
2 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
3 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/kernel.h>
11#include <linux/device.h>
12#include <linux/if.h>
Johannes Berg28656a12012-11-05 20:24:38 +010013#include <linux/if_ether.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070014#include <linux/interrupt.h>
15#include <linux/netdevice.h>
16#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070018#include <linux/notifier.h>
19#include <net/mac80211.h>
20#include <net/cfg80211.h>
21#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040022#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070023#include "debugfs.h"
24#include "debugfs_netdev.h"
Eliad Peller37a41b42011-09-21 14:06:11 +030025#include "driver-ops.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070026
27static ssize_t ieee80211_if_read(
28 struct ieee80211_sub_if_data *sdata,
29 char __user *userbuf,
30 size_t count, loff_t *ppos,
31 ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
32{
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +020033 char buf[200];
Jiri Bence9f207f2007-05-05 11:46:38 -070034 ssize_t ret = -EINVAL;
35
36 read_lock(&dev_base_lock);
Arik Nemtsov923eaf32014-05-26 14:40:51 +030037 ret = (*format)(sdata, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -070038 read_unlock(&dev_base_lock);
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070039
Jouni Malinen681d1192011-02-03 18:35:19 +020040 if (ret >= 0)
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070041 ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
42
Jiri Bence9f207f2007-05-05 11:46:38 -070043 return ret;
44}
45
Johannes Berg0f782312009-12-01 13:37:02 +010046static ssize_t ieee80211_if_write(
47 struct ieee80211_sub_if_data *sdata,
48 const char __user *userbuf,
49 size_t count, loff_t *ppos,
50 ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
51{
Eliad Pellerada577c2012-03-14 16:15:02 +020052 char buf[64];
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010053 ssize_t ret;
Johannes Berg0f782312009-12-01 13:37:02 +010054
Eliad Pellerada577c2012-03-14 16:15:02 +020055 if (count >= sizeof(buf))
56 return -E2BIG;
Johannes Berg0f782312009-12-01 13:37:02 +010057
58 if (copy_from_user(buf, userbuf, count))
Eliad Pellerada577c2012-03-14 16:15:02 +020059 return -EFAULT;
60 buf[count] = '\0';
Johannes Berg0f782312009-12-01 13:37:02 +010061
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010062 ret = -ENODEV;
Johannes Berg0f782312009-12-01 13:37:02 +010063 rtnl_lock();
Arik Nemtsov923eaf32014-05-26 14:40:51 +030064 ret = (*write)(sdata, buf, count);
Johannes Berg0f782312009-12-01 13:37:02 +010065 rtnl_unlock();
66
67 return ret;
68}
69
Jiri Bence9f207f2007-05-05 11:46:38 -070070#define IEEE80211_IF_FMT(name, field, format_string) \
71static ssize_t ieee80211_if_fmt_##name( \
72 const struct ieee80211_sub_if_data *sdata, char *buf, \
73 int buflen) \
74{ \
75 return scnprintf(buf, buflen, format_string, sdata->field); \
76}
77#define IEEE80211_IF_FMT_DEC(name, field) \
78 IEEE80211_IF_FMT(name, field, "%d\n")
79#define IEEE80211_IF_FMT_HEX(name, field) \
80 IEEE80211_IF_FMT(name, field, "%#x\n")
Ben Greear4914b3b2011-01-27 22:09:34 -080081#define IEEE80211_IF_FMT_LHEX(name, field) \
82 IEEE80211_IF_FMT(name, field, "%#lx\n")
Jiri Bence9f207f2007-05-05 11:46:38 -070083#define IEEE80211_IF_FMT_SIZE(name, field) \
84 IEEE80211_IF_FMT(name, field, "%zd\n")
85
Simon Wunderlich19468412012-01-28 17:25:33 +010086#define IEEE80211_IF_FMT_HEXARRAY(name, field) \
87static ssize_t ieee80211_if_fmt_##name( \
88 const struct ieee80211_sub_if_data *sdata, \
89 char *buf, int buflen) \
90{ \
91 char *p = buf; \
92 int i; \
93 for (i = 0; i < sizeof(sdata->field); i++) { \
94 p += scnprintf(p, buflen + buf - p, "%.2x ", \
95 sdata->field[i]); \
96 } \
97 p += scnprintf(p, buflen + buf - p, "\n"); \
98 return p - buf; \
99}
100
Jiri Bence9f207f2007-05-05 11:46:38 -0700101#define IEEE80211_IF_FMT_ATOMIC(name, field) \
102static ssize_t ieee80211_if_fmt_##name( \
103 const struct ieee80211_sub_if_data *sdata, \
104 char *buf, int buflen) \
105{ \
106 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
107}
108
109#define IEEE80211_IF_FMT_MAC(name, field) \
110static ssize_t ieee80211_if_fmt_##name( \
111 const struct ieee80211_sub_if_data *sdata, char *buf, \
112 int buflen) \
113{ \
Johannes Berg0c68ae262008-10-27 15:56:10 -0700114 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700115}
116
Ben Greear78e443e2013-03-25 11:19:34 -0700117#define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field) \
118static ssize_t ieee80211_if_fmt_##name( \
119 const struct ieee80211_sub_if_data *sdata, \
120 char *buf, int buflen) \
121{ \
122 return scnprintf(buf, buflen, "%d\n", \
123 jiffies_to_msecs(sdata->field)); \
124}
125
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100126#define _IEEE80211_IF_FILE_OPS(name, _read, _write) \
127static const struct file_operations name##_ops = { \
128 .read = (_read), \
129 .write = (_write), \
130 .open = simple_open, \
131 .llseek = generic_file_llseek, \
132}
133
134#define _IEEE80211_IF_FILE_R_FN(name) \
Jiri Bence9f207f2007-05-05 11:46:38 -0700135static ssize_t ieee80211_if_read_##name(struct file *file, \
136 char __user *userbuf, \
137 size_t count, loff_t *ppos) \
138{ \
139 return ieee80211_if_read(file->private_data, \
140 userbuf, count, ppos, \
141 ieee80211_if_fmt_##name); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700142}
143
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100144#define _IEEE80211_IF_FILE_W_FN(name) \
Johannes Berg0f782312009-12-01 13:37:02 +0100145static ssize_t ieee80211_if_write_##name(struct file *file, \
146 const char __user *userbuf, \
147 size_t count, loff_t *ppos) \
148{ \
149 return ieee80211_if_write(file->private_data, userbuf, count, \
150 ppos, ieee80211_if_parse_##name); \
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100151}
Johannes Berg0f782312009-12-01 13:37:02 +0100152
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100153#define IEEE80211_IF_FILE_R(name) \
154 _IEEE80211_IF_FILE_R_FN(name) \
155 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
156
157#define IEEE80211_IF_FILE_W(name) \
158 _IEEE80211_IF_FILE_W_FN(name) \
159 _IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
160
161#define IEEE80211_IF_FILE_RW(name) \
162 _IEEE80211_IF_FILE_R_FN(name) \
163 _IEEE80211_IF_FILE_W_FN(name) \
164 _IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, \
165 ieee80211_if_write_##name)
Johannes Berg0f782312009-12-01 13:37:02 +0100166
Jiri Bence9f207f2007-05-05 11:46:38 -0700167#define IEEE80211_IF_FILE(name, field, format) \
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100168 IEEE80211_IF_FMT_##format(name, field) \
169 IEEE80211_IF_FILE_R(name)
Jiri Bence9f207f2007-05-05 11:46:38 -0700170
171/* common attributes */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200172IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200173 HEX);
Johannes Berg57fbcce2016-04-12 15:56:15 +0200174IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200175 HEX);
Simon Wunderlich19468412012-01-28 17:25:33 +0100176IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200177 rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
Simon Wunderlich19468412012-01-28 17:25:33 +0100178IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200179 rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
Simon Wunderlich19468412012-01-28 17:25:33 +0100180
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200181static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
182 const struct ieee80211_sub_if_data *sdata,
183 char *buf, int buflen)
184{
185 int i, len = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200186 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200187
188 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
189 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
190 len += scnprintf(buf + len, buflen - len, "\n");
191
192 return len;
193}
194
195IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
196
197static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
198 const struct ieee80211_sub_if_data *sdata,
199 char *buf, int buflen)
200{
201 int i, len = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200202 const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200203
204 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
205 len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
206 len += scnprintf(buf + len, buflen - len, "\n");
207
208 return len;
209}
210
211IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
212
Ben Greear4914b3b2011-01-27 22:09:34 -0800213IEEE80211_IF_FILE(flags, flags, HEX);
214IEEE80211_IF_FILE(state, state, LHEX);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200215IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
216IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
217IEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700218
Johannes Berg08643312012-11-08 15:29:28 +0100219static ssize_t
220ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
221 char *buf, int buflen)
222{
223 int len;
224
225 len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
226 sdata->vif.hw_queue[IEEE80211_AC_VO],
227 sdata->vif.hw_queue[IEEE80211_AC_VI],
228 sdata->vif.hw_queue[IEEE80211_AC_BE],
229 sdata->vif.hw_queue[IEEE80211_AC_BK]);
230
231 if (sdata->vif.type == NL80211_IFTYPE_AP)
232 len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
233 sdata->vif.cab_queue);
234
235 return len;
236}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100237IEEE80211_IF_FILE_R(hw_queues);
Johannes Berg08643312012-11-08 15:29:28 +0100238
Johannes Berg46900292009-02-15 12:44:28 +0100239/* STA attributes */
Johannes Berg46900292009-02-15 12:44:28 +0100240IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
Johannes Berg46900292009-02-15 12:44:28 +0100241IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
Ben Greear78e443e2013-03-25 11:19:34 -0700242IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
Jiri Bence9f207f2007-05-05 11:46:38 -0700243
Johannes Berg0f782312009-12-01 13:37:02 +0100244static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
245 enum ieee80211_smps_mode smps_mode)
246{
247 struct ieee80211_local *local = sdata->local;
248 int err;
249
Eliad Peller0d8614b2014-09-10 14:07:36 +0300250 if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
Johannes Berg0f782312009-12-01 13:37:02 +0100251 smps_mode == IEEE80211_SMPS_STATIC)
252 return -EINVAL;
253
254 /* auto should be dynamic if in PS mode */
Eliad Peller0d8614b2014-09-10 14:07:36 +0300255 if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
Johannes Berg0f782312009-12-01 13:37:02 +0100256 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
257 smps_mode == IEEE80211_SMPS_AUTOMATIC))
258 return -EINVAL;
259
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300260 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
261 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg0f782312009-12-01 13:37:02 +0100262 return -EOPNOTSUPP;
263
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200264 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300265 if (sdata->vif.type == NL80211_IFTYPE_STATION)
266 err = __ieee80211_request_smps_mgd(sdata, smps_mode);
267 else
268 err = __ieee80211_request_smps_ap(sdata, smps_mode);
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200269 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +0100270
271 return err;
272}
273
274static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
275 [IEEE80211_SMPS_AUTOMATIC] = "auto",
276 [IEEE80211_SMPS_OFF] = "off",
277 [IEEE80211_SMPS_STATIC] = "static",
278 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
279};
280
281static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
282 char *buf, int buflen)
283{
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300284 if (sdata->vif.type == NL80211_IFTYPE_STATION)
285 return snprintf(buf, buflen, "request: %s\nused: %s\n",
286 smps_modes[sdata->u.mgd.req_smps],
287 smps_modes[sdata->smps_mode]);
288 if (sdata->vif.type == NL80211_IFTYPE_AP)
289 return snprintf(buf, buflen, "request: %s\nused: %s\n",
290 smps_modes[sdata->u.ap.req_smps],
291 smps_modes[sdata->smps_mode]);
292 return -EINVAL;
Johannes Berg0f782312009-12-01 13:37:02 +0100293}
294
295static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
296 const char *buf, int buflen)
297{
298 enum ieee80211_smps_mode mode;
299
300 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
301 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
302 int err = ieee80211_set_smps(sdata, mode);
303 if (!err)
304 return buflen;
305 return err;
306 }
307 }
308
309 return -EINVAL;
310}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100311IEEE80211_IF_FILE_RW(smps);
Jouni Malinen681d1192011-02-03 18:35:19 +0200312
Jouni Malinen681d1192011-02-03 18:35:19 +0200313static ssize_t ieee80211_if_parse_tkip_mic_test(
314 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
315{
316 struct ieee80211_local *local = sdata->local;
317 u8 addr[ETH_ALEN];
318 struct sk_buff *skb;
319 struct ieee80211_hdr *hdr;
320 __le16 fc;
321
Johannes Berg28656a12012-11-05 20:24:38 +0100322 if (!mac_pton(buf, addr))
Jouni Malinen681d1192011-02-03 18:35:19 +0200323 return -EINVAL;
324
325 if (!ieee80211_sdata_running(sdata))
326 return -ENOTCONN;
327
328 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
329 if (!skb)
330 return -ENOMEM;
331 skb_reserve(skb, local->hw.extra_tx_headroom);
332
333 hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
334 memset(hdr, 0, 24);
335 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
336
337 switch (sdata->vif.type) {
338 case NL80211_IFTYPE_AP:
339 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
340 /* DA BSSID SA */
341 memcpy(hdr->addr1, addr, ETH_ALEN);
342 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
343 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
344 break;
345 case NL80211_IFTYPE_STATION:
346 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
347 /* BSSID SA DA */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200348 sdata_lock(sdata);
Johannes Berg41c97a22012-11-05 20:27:57 +0100349 if (!sdata->u.mgd.associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200350 sdata_unlock(sdata);
Jouni Malinen681d1192011-02-03 18:35:19 +0200351 dev_kfree_skb(skb);
352 return -ENOTCONN;
353 }
Johannes Berg41c97a22012-11-05 20:27:57 +0100354 memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
Jouni Malinen681d1192011-02-03 18:35:19 +0200355 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
356 memcpy(hdr->addr3, addr, ETH_ALEN);
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200357 sdata_unlock(sdata);
Jouni Malinen681d1192011-02-03 18:35:19 +0200358 break;
359 default:
360 dev_kfree_skb(skb);
361 return -EOPNOTSUPP;
362 }
363 hdr->frame_control = fc;
364
365 /*
366 * Add some length to the test frame to make it look bit more valid.
367 * The exact contents does not matter since the recipient is required
368 * to drop this because of the Michael MIC failure.
369 */
370 memset(skb_put(skb, 50), 0, 50);
371
372 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
373
374 ieee80211_tx_skb(sdata, skb);
375
376 return buflen;
377}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100378IEEE80211_IF_FILE_W(tkip_mic_test);
Jouni Malinen681d1192011-02-03 18:35:19 +0200379
Eliad Peller802ee9e2014-02-11 12:36:18 +0200380static ssize_t ieee80211_if_parse_beacon_loss(
381 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
382{
383 if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
384 return -ENOTCONN;
385
386 ieee80211_beacon_loss(&sdata->vif);
387
388 return buflen;
389}
390IEEE80211_IF_FILE_W(beacon_loss);
391
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200392static ssize_t ieee80211_if_fmt_uapsd_queues(
393 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
394{
395 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
396
397 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
398}
399
400static ssize_t ieee80211_if_parse_uapsd_queues(
401 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
402{
403 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
404 u8 val;
405 int ret;
406
407 ret = kstrtou8(buf, 0, &val);
408 if (ret)
409 return ret;
410
411 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
412 return -ERANGE;
413
414 ifmgd->uapsd_queues = val;
415
416 return buflen;
417}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100418IEEE80211_IF_FILE_RW(uapsd_queues);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200419
420static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
421 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
422{
423 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
424
425 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
426}
427
428static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
429 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
430{
431 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
432 unsigned long val;
433 int ret;
434
435 ret = kstrtoul(buf, 0, &val);
436 if (ret)
437 return -EINVAL;
438
439 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
440 return -ERANGE;
441
442 ifmgd->uapsd_max_sp_len = val;
443
444 return buflen;
445}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100446IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200447
Arik Nemtsov82c0cc92015-08-15 22:39:46 +0300448static ssize_t ieee80211_if_fmt_tdls_wider_bw(
449 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
450{
451 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
452 bool tdls_wider_bw;
453
454 tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
455 !ifmgd->tdls_wider_bw_prohibited;
456
457 return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
458}
459
460static ssize_t ieee80211_if_parse_tdls_wider_bw(
461 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
462{
463 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
464 u8 val;
465 int ret;
466
467 ret = kstrtou8(buf, 0, &val);
468 if (ret)
469 return ret;
470
471 ifmgd->tdls_wider_bw_prohibited = !val;
472 return buflen;
473}
474IEEE80211_IF_FILE_RW(tdls_wider_bw);
475
Jiri Bence9f207f2007-05-05 11:46:38 -0700476/* AP attributes */
Felix Fietkau030ef8f2012-04-23 19:49:02 +0200477IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
Marco Porschd012a602012-10-10 12:39:50 -0700478IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
479IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700480
481static ssize_t ieee80211_if_fmt_num_buffered_multicast(
482 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
483{
484 return scnprintf(buf, buflen, "%u\n",
Marco Porschd012a602012-10-10 12:39:50 -0700485 skb_queue_len(&sdata->u.ap.ps.bc_buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700486}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100487IEEE80211_IF_FILE_R(num_buffered_multicast);
Jiri Bence9f207f2007-05-05 11:46:38 -0700488
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200489static ssize_t ieee80211_if_fmt_aqm(
490 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
491{
492 struct ieee80211_local *local = sdata->local;
Miaoqing Pan8b6d5c12019-09-27 10:03:16 +0800493 struct txq_info *txqi;
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200494 int len;
495
Miaoqing Pan8b6d5c12019-09-27 10:03:16 +0800496 if (!sdata->vif.txq)
497 return 0;
498
499 txqi = to_txq_info(sdata->vif.txq);
500
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200501 spin_lock_bh(&local->fq.lock);
502 rcu_read_lock();
503
504 len = scnprintf(buf,
505 buflen,
506 "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
507 "%u %u %u %u %u %u %u %u %u %u\n",
508 txqi->txq.ac,
509 txqi->tin.backlog_bytes,
510 txqi->tin.backlog_packets,
511 txqi->tin.flows,
512 txqi->cstats.drop_count,
513 txqi->cstats.ecn_mark,
514 txqi->tin.overlimit,
515 txqi->tin.collisions,
516 txqi->tin.tx_bytes,
517 txqi->tin.tx_packets);
518
519 rcu_read_unlock();
520 spin_unlock_bh(&local->fq.lock);
521
522 return len;
523}
524IEEE80211_IF_FILE_R(aqm);
525
Eliad Peller37a41b42011-09-21 14:06:11 +0300526/* IBSS attributes */
527static ssize_t ieee80211_if_fmt_tsf(
528 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
529{
530 struct ieee80211_local *local = sdata->local;
531 u64 tsf;
532
533 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
534
535 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
536}
537
538static ssize_t ieee80211_if_parse_tsf(
539 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
540{
541 struct ieee80211_local *local = sdata->local;
542 unsigned long long tsf;
543 int ret;
Javier Cardona9bdd3a62012-03-31 11:31:31 -0700544 int tsf_is_delta = 0;
Eliad Peller37a41b42011-09-21 14:06:11 +0300545
546 if (strncmp(buf, "reset", 5) == 0) {
547 if (local->ops->reset_tsf) {
548 drv_reset_tsf(local, sdata);
549 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
550 }
551 } else {
Javier Cardona9bdd3a62012-03-31 11:31:31 -0700552 if (buflen > 10 && buf[1] == '=') {
553 if (buf[0] == '+')
554 tsf_is_delta = 1;
555 else if (buf[0] == '-')
556 tsf_is_delta = -1;
557 else
558 return -EINVAL;
559 buf += 2;
560 }
Eliad Peller37a41b42011-09-21 14:06:11 +0300561 ret = kstrtoull(buf, 10, &tsf);
562 if (ret < 0)
Johannes Berg6fc1da92012-11-05 20:30:39 +0100563 return ret;
Pedersen, Thomas354d3812016-09-28 16:56:28 -0700564 if (tsf_is_delta && local->ops->offset_tsf) {
565 drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
566 wiphy_info(local->hw.wiphy,
567 "debugfs offset TSF by %018lld\n",
568 tsf_is_delta * tsf);
569 } else if (local->ops->set_tsf) {
570 if (tsf_is_delta)
571 tsf = drv_get_tsf(local, sdata) +
572 tsf_is_delta * tsf;
Eliad Peller37a41b42011-09-21 14:06:11 +0300573 drv_set_tsf(local, sdata, tsf);
574 wiphy_info(local->hw.wiphy,
575 "debugfs set TSF to %#018llx\n", tsf);
576 }
577 }
578
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800579 ieee80211_recalc_dtim(local, sdata);
Eliad Peller37a41b42011-09-21 14:06:11 +0300580 return buflen;
581}
Johannes Berg4cd3c4e2014-01-06 15:47:15 +0100582IEEE80211_IF_FILE_RW(tsf);
Eliad Peller37a41b42011-09-21 14:06:11 +0300583
584
Jiri Bence9f207f2007-05-05 11:46:38 -0700585/* WDS attributes */
586IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
587
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100588#ifdef CONFIG_MAC80211_MESH
Ashok Nagarajand4a5a482013-05-13 17:08:04 -0700589IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
590
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100591/* Mesh stats attributes */
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700592IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
593IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
Johannes Berg472dbc42008-09-11 00:01:49 +0200594IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
595IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700596IEEE80211_IF_FILE(dropped_frames_congestion,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800597 u.mesh.mshstats.dropped_frames_congestion, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100598IEEE80211_IF_FILE(dropped_frames_no_route,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800599 u.mesh.mshstats.dropped_frames_no_route, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100600
601/* Mesh parameters */
Johannes Berg36ff3822008-10-07 12:04:31 +0200602IEEE80211_IF_FILE(dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800603 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200604IEEE80211_IF_FILE(dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800605 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200606IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800607 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200608IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800609 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200610IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
Javier Cardona45904f22010-12-03 09:20:40 +0100611IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200612IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
613IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800614 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200615IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800616 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200617IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800618 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800619IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800620 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200621IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800622 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200623IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800624 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200625IEEE80211_IF_FILE(path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800626 u.mesh.mshcfg.path_refresh_time, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200627IEEE80211_IF_FILE(min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800628 u.mesh.mshcfg.min_discovery_timeout, DEC);
Rui Paulo63c57232009-11-09 23:46:57 +0000629IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800630 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
Javier Cardona16dd7262011-08-09 16:45:11 -0700631IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800632 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
Javier Cardona0507e152011-08-09 16:45:10 -0700633IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800634 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +0800635IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800636IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
Ashok Nagarajan4416f5d2012-05-07 21:00:32 -0700637IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +0800638IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
639 u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
640IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
641 u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +0800642IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
643 u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100644IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
645IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
646 u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100647#endif
648
Johannes Berg0f782312009-12-01 13:37:02 +0100649#define DEBUGFS_ADD_MODE(name, mode) \
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100650 debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
Johannes Berg0f782312009-12-01 13:37:02 +0100651 sdata, &name##_ops);
652
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100653#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
654
655static void add_common_files(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700656{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100657 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
658 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
Simon Wunderlich19468412012-01-28 17:25:33 +0100659 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
660 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200661 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
662 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
Johannes Berg08643312012-11-08 15:29:28 +0100663 DEBUGFS_ADD(hw_queues);
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200664
Miaoqing Pan8b6d5c12019-09-27 10:03:16 +0800665 if (sdata->local->ops->wake_tx_queue &&
666 sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
667 sdata->vif.type != NL80211_IFTYPE_NAN)
Toke Høiland-Jørgensen8d51dbb2016-09-12 15:55:43 +0200668 DEBUGFS_ADD(aqm);
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100669}
Johannes Berg3e122be2008-07-09 14:40:34 +0200670
Felix Fietkaufcb2c9e2012-03-18 22:58:05 +0100671static void add_sta_files(struct ieee80211_sub_if_data *sdata)
672{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100673 DEBUGFS_ADD(bssid);
674 DEBUGFS_ADD(aid);
Ben Greear78e443e2013-03-25 11:19:34 -0700675 DEBUGFS_ADD(beacon_timeout);
Johannes Berg0f782312009-12-01 13:37:02 +0100676 DEBUGFS_ADD_MODE(smps, 0600);
Jouni Malinen681d1192011-02-03 18:35:19 +0200677 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
Eliad Peller802ee9e2014-02-11 12:36:18 +0200678 DEBUGFS_ADD_MODE(beacon_loss, 0200);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200679 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
680 DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
Arik Nemtsov82c0cc92015-08-15 22:39:46 +0300681 DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
Jiri Bence9f207f2007-05-05 11:46:38 -0700682}
683
684static void add_ap_files(struct ieee80211_sub_if_data *sdata)
685{
Felix Fietkau030ef8f2012-04-23 19:49:02 +0200686 DEBUGFS_ADD(num_mcast_sta);
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300687 DEBUGFS_ADD_MODE(smps, 0600);
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100688 DEBUGFS_ADD(num_sta_ps);
689 DEBUGFS_ADD(dtim_count);
690 DEBUGFS_ADD(num_buffered_multicast);
Jouni Malinen681d1192011-02-03 18:35:19 +0200691 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
Jiri Bence9f207f2007-05-05 11:46:38 -0700692}
693
Eliad Peller37a41b42011-09-21 14:06:11 +0300694static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
695{
696 DEBUGFS_ADD_MODE(tsf, 0600);
697}
698
Jiri Bence9f207f2007-05-05 11:46:38 -0700699static void add_wds_files(struct ieee80211_sub_if_data *sdata)
700{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100701 DEBUGFS_ADD(peer);
Jiri Bence9f207f2007-05-05 11:46:38 -0700702}
703
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100704#ifdef CONFIG_MAC80211_MESH
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100705
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800706static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
707{
708 DEBUGFS_ADD_MODE(tsf, 0600);
Ashok Nagarajand4a5a482013-05-13 17:08:04 -0700709 DEBUGFS_ADD_MODE(estab_plinks, 0400);
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800710}
711
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100712static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
713{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100714 struct dentry *dir = debugfs_create_dir("mesh_stats",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100715 sdata->vif.debugfs_dir);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100716#define MESHSTATS_ADD(name)\
717 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
718
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700719 MESHSTATS_ADD(fwded_mcast);
720 MESHSTATS_ADD(fwded_unicast);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100721 MESHSTATS_ADD(fwded_frames);
722 MESHSTATS_ADD(dropped_frames_ttl);
723 MESHSTATS_ADD(dropped_frames_no_route);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700724 MESHSTATS_ADD(dropped_frames_congestion);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100725#undef MESHSTATS_ADD
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100726}
727
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100728static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
729{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100730 struct dentry *dir = debugfs_create_dir("mesh_config",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100731 sdata->vif.debugfs_dir);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100732
733#define MESHPARAMS_ADD(name) \
734 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
735
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100736 MESHPARAMS_ADD(dot11MeshMaxRetries);
737 MESHPARAMS_ADD(dot11MeshRetryTimeout);
738 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
739 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
740 MESHPARAMS_ADD(dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +0100741 MESHPARAMS_ADD(element_ttl);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100742 MESHPARAMS_ADD(auto_open_plinks);
743 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
744 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
745 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800746 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100747 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
748 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
749 MESHPARAMS_ADD(path_refresh_time);
750 MESHPARAMS_ADD(min_discovery_timeout);
Javier Cardona699403d2011-08-09 16:45:09 -0700751 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -0700752 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
Chun-Yeow Yeoh8c06e8c2012-05-31 18:17:30 +0800753 MESHPARAMS_ADD(dot11MeshForwarding);
Javier Cardona16dd7262011-08-09 16:45:11 -0700754 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800755 MESHPARAMS_ADD(rssi_threshold);
Ashok Nagarajan4416f5d2012-05-07 21:00:32 -0700756 MESHPARAMS_ADD(ht_opmode);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +0800757 MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
758 MESHPARAMS_ADD(dot11MeshHWMProotInterval);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +0800759 MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100760 MESHPARAMS_ADD(power_mode);
761 MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
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;
Johannes Berg05c914f2008-09-11 00:01:58 +0200797 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700798 add_wds_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);
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100812 if (sdata->vif.debugfs_dir)
Ben Greear295bafb2010-09-22 20:29:01 -0700813 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100814 sdata->vif.debugfs_dir);
Johannes Berg75636522008-07-09 14:40:35 +0200815 add_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700816}
817
818void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
819{
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100820 if (!sdata->vif.debugfs_dir)
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100821 return;
822
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100823 debugfs_remove_recursive(sdata->vif.debugfs_dir);
824 sdata->vif.debugfs_dir = NULL;
Tom Hughes44790042015-06-29 19:41:49 +0100825 sdata->debugfs.subdir_stations = NULL;
Jiri Bence9f207f2007-05-05 11:46:38 -0700826}
827
Johannes Berg47846c92009-11-25 17:46:19 +0100828void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700829{
Johannes Berg7c8081e2007-06-21 18:30:19 +0200830 struct dentry *dir;
Johannes Berg47846c92009-11-25 17:46:19 +0100831 char buf[10 + IFNAMSIZ];
Johannes Berg3e122be2008-07-09 14:40:34 +0200832
Stanislaw Gruszkaddbfe862013-03-08 14:46:14 +0100833 dir = sdata->vif.debugfs_dir;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200834
835 if (!dir)
Johannes Berg47846c92009-11-25 17:46:19 +0100836 return;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200837
Johannes Berg47846c92009-11-25 17:46:19 +0100838 sprintf(buf, "netdev:%s", sdata->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200839 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200840 sdata_err(sdata,
841 "debugfs: failed to rename debugfs dir to %s\n",
842 buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700843}