blob: d5404cc0248d9488c340995cd91f906a3431d892 [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>
13#include <linux/interrupt.h>
14#include <linux/netdevice.h>
15#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Jiri Bence9f207f2007-05-05 11:46:38 -070017#include <linux/notifier.h>
18#include <net/mac80211.h>
19#include <net/cfg80211.h>
20#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040021#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070022#include "debugfs.h"
23#include "debugfs_netdev.h"
Eliad Peller37a41b42011-09-21 14:06:11 +030024#include "driver-ops.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070025
26static ssize_t ieee80211_if_read(
27 struct ieee80211_sub_if_data *sdata,
28 char __user *userbuf,
29 size_t count, loff_t *ppos,
30 ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
31{
32 char buf[70];
33 ssize_t ret = -EINVAL;
34
35 read_lock(&dev_base_lock);
Arik Nemtsovdc0bfd62014-05-26 14:40:51 +030036 ret = (*format)(sdata, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -070037 read_unlock(&dev_base_lock);
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070038
Jouni Malinen681d1192011-02-03 18:35:19 +020039 if (ret >= 0)
Luis Carlos Cobo73bb3e42008-03-31 15:10:22 -070040 ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
41
Jiri Bence9f207f2007-05-05 11:46:38 -070042 return ret;
43}
44
Johannes Berg0f782312009-12-01 13:37:02 +010045static ssize_t ieee80211_if_write(
46 struct ieee80211_sub_if_data *sdata,
47 const char __user *userbuf,
48 size_t count, loff_t *ppos,
49 ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
50{
Eliad Pellerada577c2012-03-14 16:15:02 +020051 char buf[64];
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010052 ssize_t ret;
Johannes Berg0f782312009-12-01 13:37:02 +010053
Eliad Pellerada577c2012-03-14 16:15:02 +020054 if (count >= sizeof(buf))
55 return -E2BIG;
Johannes Berg0f782312009-12-01 13:37:02 +010056
57 if (copy_from_user(buf, userbuf, count))
Eliad Pellerada577c2012-03-14 16:15:02 +020058 return -EFAULT;
59 buf[count] = '\0';
Johannes Berg0f782312009-12-01 13:37:02 +010060
Eric Dumazet51f5f8c2010-03-10 17:13:36 +010061 ret = -ENODEV;
Johannes Berg0f782312009-12-01 13:37:02 +010062 rtnl_lock();
Arik Nemtsovdc0bfd62014-05-26 14:40:51 +030063 ret = (*write)(sdata, buf, count);
Johannes Berg0f782312009-12-01 13:37:02 +010064 rtnl_unlock();
65
66 return ret;
67}
68
Jiri Bence9f207f2007-05-05 11:46:38 -070069#define IEEE80211_IF_FMT(name, field, format_string) \
70static ssize_t ieee80211_if_fmt_##name( \
71 const struct ieee80211_sub_if_data *sdata, char *buf, \
72 int buflen) \
73{ \
74 return scnprintf(buf, buflen, format_string, sdata->field); \
75}
76#define IEEE80211_IF_FMT_DEC(name, field) \
77 IEEE80211_IF_FMT(name, field, "%d\n")
78#define IEEE80211_IF_FMT_HEX(name, field) \
79 IEEE80211_IF_FMT(name, field, "%#x\n")
Ben Greear4914b3b2011-01-27 22:09:34 -080080#define IEEE80211_IF_FMT_LHEX(name, field) \
81 IEEE80211_IF_FMT(name, field, "%#lx\n")
Jiri Bence9f207f2007-05-05 11:46:38 -070082#define IEEE80211_IF_FMT_SIZE(name, field) \
83 IEEE80211_IF_FMT(name, field, "%zd\n")
84
Simon Wunderlich19468412012-01-28 17:25:33 +010085#define IEEE80211_IF_FMT_HEXARRAY(name, field) \
86static ssize_t ieee80211_if_fmt_##name( \
87 const struct ieee80211_sub_if_data *sdata, \
88 char *buf, int buflen) \
89{ \
90 char *p = buf; \
91 int i; \
92 for (i = 0; i < sizeof(sdata->field); i++) { \
93 p += scnprintf(p, buflen + buf - p, "%.2x ", \
94 sdata->field[i]); \
95 } \
96 p += scnprintf(p, buflen + buf - p, "\n"); \
97 return p - buf; \
98}
99
Jiri Bence9f207f2007-05-05 11:46:38 -0700100#define IEEE80211_IF_FMT_ATOMIC(name, field) \
101static ssize_t ieee80211_if_fmt_##name( \
102 const struct ieee80211_sub_if_data *sdata, \
103 char *buf, int buflen) \
104{ \
105 return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
106}
107
108#define IEEE80211_IF_FMT_MAC(name, field) \
109static ssize_t ieee80211_if_fmt_##name( \
110 const struct ieee80211_sub_if_data *sdata, char *buf, \
111 int buflen) \
112{ \
Johannes Berg0c68ae262008-10-27 15:56:10 -0700113 return scnprintf(buf, buflen, "%pM\n", sdata->field); \
Jiri Bence9f207f2007-05-05 11:46:38 -0700114}
115
Jouni Malinen17e4ec12010-03-29 23:28:30 -0700116#define IEEE80211_IF_FMT_DEC_DIV_16(name, field) \
117static ssize_t ieee80211_if_fmt_##name( \
118 const struct ieee80211_sub_if_data *sdata, \
119 char *buf, int buflen) \
120{ \
121 return scnprintf(buf, buflen, "%d\n", sdata->field / 16); \
122}
123
Johannes Berg0f782312009-12-01 13:37:02 +0100124#define __IEEE80211_IF_FILE(name, _write) \
Jiri Bence9f207f2007-05-05 11:46:38 -0700125static ssize_t ieee80211_if_read_##name(struct file *file, \
126 char __user *userbuf, \
127 size_t count, loff_t *ppos) \
128{ \
129 return ieee80211_if_read(file->private_data, \
130 userbuf, count, ppos, \
131 ieee80211_if_fmt_##name); \
132} \
133static const struct file_operations name##_ops = { \
134 .read = ieee80211_if_read_##name, \
Johannes Berg0f782312009-12-01 13:37:02 +0100135 .write = (_write), \
Stephen Boyd234e3402012-04-05 14:25:11 -0700136 .open = simple_open, \
Arnd Bergmann2b18ab32010-07-06 19:05:31 +0200137 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -0700138}
139
Johannes Berg0f782312009-12-01 13:37:02 +0100140#define __IEEE80211_IF_FILE_W(name) \
141static ssize_t ieee80211_if_write_##name(struct file *file, \
142 const char __user *userbuf, \
143 size_t count, loff_t *ppos) \
144{ \
145 return ieee80211_if_write(file->private_data, userbuf, count, \
146 ppos, ieee80211_if_parse_##name); \
147} \
148__IEEE80211_IF_FILE(name, ieee80211_if_write_##name)
149
150
Jiri Bence9f207f2007-05-05 11:46:38 -0700151#define IEEE80211_IF_FILE(name, field, format) \
152 IEEE80211_IF_FMT_##format(name, field) \
Johannes Berg0f782312009-12-01 13:37:02 +0100153 __IEEE80211_IF_FILE(name, NULL)
Jiri Bence9f207f2007-05-05 11:46:38 -0700154
155/* common attributes */
Jiri Bence9f207f2007-05-05 11:46:38 -0700156IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200157IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[IEEE80211_BAND_2GHZ],
158 HEX);
159IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[IEEE80211_BAND_5GHZ],
160 HEX);
Simon Wunderlich19468412012-01-28 17:25:33 +0100161IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
162 rc_rateidx_mcs_mask[IEEE80211_BAND_2GHZ], HEXARRAY);
163IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
164 rc_rateidx_mcs_mask[IEEE80211_BAND_5GHZ], HEXARRAY);
165
Ben Greear4914b3b2011-01-27 22:09:34 -0800166IEEE80211_IF_FILE(flags, flags, HEX);
167IEEE80211_IF_FILE(state, state, LHEX);
Ben Greear0fa025f2011-01-28 17:05:42 -0800168IEEE80211_IF_FILE(channel_type, vif.bss_conf.channel_type, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700169
Johannes Berg46900292009-02-15 12:44:28 +0100170/* STA attributes */
Johannes Berg46900292009-02-15 12:44:28 +0100171IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
Johannes Berg46900292009-02-15 12:44:28 +0100172IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
Jouni Malinen17e4ec12010-03-29 23:28:30 -0700173IEEE80211_IF_FILE(last_beacon, u.mgd.last_beacon_signal, DEC);
174IEEE80211_IF_FILE(ave_beacon, u.mgd.ave_beacon_signal, DEC_DIV_16);
Jiri Bence9f207f2007-05-05 11:46:38 -0700175
Johannes Berg0f782312009-12-01 13:37:02 +0100176static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
177 enum ieee80211_smps_mode smps_mode)
178{
179 struct ieee80211_local *local = sdata->local;
180 int err;
181
182 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) &&
183 smps_mode == IEEE80211_SMPS_STATIC)
184 return -EINVAL;
185
186 /* auto should be dynamic if in PS mode */
187 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) &&
188 (smps_mode == IEEE80211_SMPS_DYNAMIC ||
189 smps_mode == IEEE80211_SMPS_AUTOMATIC))
190 return -EINVAL;
191
192 /* supported only on managed interfaces for now */
193 if (sdata->vif.type != NL80211_IFTYPE_STATION)
194 return -EOPNOTSUPP;
195
Johannes Berg243e6df2011-04-19 20:44:04 +0200196 mutex_lock(&sdata->u.mgd.mtx);
Johannes Berg0f782312009-12-01 13:37:02 +0100197 err = __ieee80211_request_smps(sdata, smps_mode);
Johannes Berg243e6df2011-04-19 20:44:04 +0200198 mutex_unlock(&sdata->u.mgd.mtx);
Johannes Berg0f782312009-12-01 13:37:02 +0100199
200 return err;
201}
202
203static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
204 [IEEE80211_SMPS_AUTOMATIC] = "auto",
205 [IEEE80211_SMPS_OFF] = "off",
206 [IEEE80211_SMPS_STATIC] = "static",
207 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
208};
209
210static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
211 char *buf, int buflen)
212{
213 if (sdata->vif.type != NL80211_IFTYPE_STATION)
214 return -EOPNOTSUPP;
215
216 return snprintf(buf, buflen, "request: %s\nused: %s\n",
217 smps_modes[sdata->u.mgd.req_smps],
218 smps_modes[sdata->u.mgd.ap_smps]);
219}
220
221static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
222 const char *buf, int buflen)
223{
224 enum ieee80211_smps_mode mode;
225
226 for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
227 if (strncmp(buf, smps_modes[mode], buflen) == 0) {
228 int err = ieee80211_set_smps(sdata, mode);
229 if (!err)
230 return buflen;
231 return err;
232 }
233 }
234
235 return -EINVAL;
236}
237
238__IEEE80211_IF_FILE_W(smps);
239
Jouni Malinen681d1192011-02-03 18:35:19 +0200240static ssize_t ieee80211_if_fmt_tkip_mic_test(
241 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
242{
243 return -EOPNOTSUPP;
244}
245
246static int hwaddr_aton(const char *txt, u8 *addr)
247{
248 int i;
249
250 for (i = 0; i < ETH_ALEN; i++) {
251 int a, b;
252
253 a = hex_to_bin(*txt++);
254 if (a < 0)
255 return -1;
256 b = hex_to_bin(*txt++);
257 if (b < 0)
258 return -1;
259 *addr++ = (a << 4) | b;
260 if (i < 5 && *txt++ != ':')
261 return -1;
262 }
263
264 return 0;
265}
266
267static ssize_t ieee80211_if_parse_tkip_mic_test(
268 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
269{
270 struct ieee80211_local *local = sdata->local;
271 u8 addr[ETH_ALEN];
272 struct sk_buff *skb;
273 struct ieee80211_hdr *hdr;
274 __le16 fc;
275
276 /*
277 * Assume colon-delimited MAC address with possible white space
278 * following.
279 */
280 if (buflen < 3 * ETH_ALEN - 1)
281 return -EINVAL;
282 if (hwaddr_aton(buf, addr) < 0)
283 return -EINVAL;
284
285 if (!ieee80211_sdata_running(sdata))
286 return -ENOTCONN;
287
288 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
289 if (!skb)
290 return -ENOMEM;
291 skb_reserve(skb, local->hw.extra_tx_headroom);
292
293 hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
294 memset(hdr, 0, 24);
295 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
296
297 switch (sdata->vif.type) {
298 case NL80211_IFTYPE_AP:
299 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
300 /* DA BSSID SA */
301 memcpy(hdr->addr1, addr, ETH_ALEN);
302 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
303 memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
304 break;
305 case NL80211_IFTYPE_STATION:
306 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
307 /* BSSID SA DA */
308 if (sdata->vif.bss_conf.bssid == NULL) {
309 dev_kfree_skb(skb);
310 return -ENOTCONN;
311 }
312 memcpy(hdr->addr1, sdata->vif.bss_conf.bssid, ETH_ALEN);
313 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
314 memcpy(hdr->addr3, addr, ETH_ALEN);
315 break;
316 default:
317 dev_kfree_skb(skb);
318 return -EOPNOTSUPP;
319 }
320 hdr->frame_control = fc;
321
322 /*
323 * Add some length to the test frame to make it look bit more valid.
324 * The exact contents does not matter since the recipient is required
325 * to drop this because of the Michael MIC failure.
326 */
327 memset(skb_put(skb, 50), 0, 50);
328
329 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
330
331 ieee80211_tx_skb(sdata, skb);
332
333 return buflen;
334}
335
336__IEEE80211_IF_FILE_W(tkip_mic_test);
337
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200338static ssize_t ieee80211_if_fmt_uapsd_queues(
339 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
340{
341 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
342
343 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
344}
345
346static ssize_t ieee80211_if_parse_uapsd_queues(
347 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
348{
349 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
350 u8 val;
351 int ret;
352
353 ret = kstrtou8(buf, 0, &val);
354 if (ret)
355 return ret;
356
357 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
358 return -ERANGE;
359
360 ifmgd->uapsd_queues = val;
361
362 return buflen;
363}
364__IEEE80211_IF_FILE_W(uapsd_queues);
365
366static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
367 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
368{
369 const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
370
371 return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
372}
373
374static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
375 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
376{
377 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
378 unsigned long val;
379 int ret;
380
381 ret = kstrtoul(buf, 0, &val);
382 if (ret)
383 return -EINVAL;
384
385 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
386 return -ERANGE;
387
388 ifmgd->uapsd_max_sp_len = val;
389
390 return buflen;
391}
392__IEEE80211_IF_FILE_W(uapsd_max_sp_len);
393
Jiri Bence9f207f2007-05-05 11:46:38 -0700394/* AP attributes */
Johannes Berg29623892011-12-14 12:20:31 +0100395IEEE80211_IF_FILE(num_sta_authorized, u.ap.num_sta_authorized, ATOMIC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700396IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700397IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
Jiri Bence9f207f2007-05-05 11:46:38 -0700398
399static ssize_t ieee80211_if_fmt_num_buffered_multicast(
400 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
401{
402 return scnprintf(buf, buflen, "%u\n",
403 skb_queue_len(&sdata->u.ap.ps_bc_buf));
404}
Johannes Berg0f782312009-12-01 13:37:02 +0100405__IEEE80211_IF_FILE(num_buffered_multicast, NULL);
Jiri Bence9f207f2007-05-05 11:46:38 -0700406
Eliad Peller37a41b42011-09-21 14:06:11 +0300407/* IBSS attributes */
408static ssize_t ieee80211_if_fmt_tsf(
409 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
410{
411 struct ieee80211_local *local = sdata->local;
412 u64 tsf;
413
414 tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
415
416 return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
417}
418
419static ssize_t ieee80211_if_parse_tsf(
420 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
421{
422 struct ieee80211_local *local = sdata->local;
423 unsigned long long tsf;
424 int ret;
425
426 if (strncmp(buf, "reset", 5) == 0) {
427 if (local->ops->reset_tsf) {
428 drv_reset_tsf(local, sdata);
429 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
430 }
431 } else {
432 ret = kstrtoull(buf, 10, &tsf);
433 if (ret < 0)
434 return -EINVAL;
435 if (local->ops->set_tsf) {
436 drv_set_tsf(local, sdata, tsf);
437 wiphy_info(local->hw.wiphy,
438 "debugfs set TSF to %#018llx\n", tsf);
439 }
440 }
441
442 return buflen;
443}
444__IEEE80211_IF_FILE_W(tsf);
445
446
Jiri Bence9f207f2007-05-05 11:46:38 -0700447/* WDS attributes */
448IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
449
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100450#ifdef CONFIG_MAC80211_MESH
451/* Mesh stats attributes */
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700452IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
453IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
Johannes Berg472dbc42008-09-11 00:01:49 +0200454IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
455IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700456IEEE80211_IF_FILE(dropped_frames_congestion,
457 u.mesh.mshstats.dropped_frames_congestion, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100458IEEE80211_IF_FILE(dropped_frames_no_route,
Johannes Berg472dbc42008-09-11 00:01:49 +0200459 u.mesh.mshstats.dropped_frames_no_route, DEC);
460IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100461
462/* Mesh parameters */
Johannes Berg36ff3822008-10-07 12:04:31 +0200463IEEE80211_IF_FILE(dot11MeshMaxRetries,
464 u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
465IEEE80211_IF_FILE(dot11MeshRetryTimeout,
466 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
467IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
468 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
469IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
470 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
471IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
Javier Cardona45904f22010-12-03 09:20:40 +0100472IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200473IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
474IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
475 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
476IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
477 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
478IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
479 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800480IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
481 u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
Johannes Berg36ff3822008-10-07 12:04:31 +0200482IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
483 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
484IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
485 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
486IEEE80211_IF_FILE(path_refresh_time,
487 u.mesh.mshcfg.path_refresh_time, DEC);
488IEEE80211_IF_FILE(min_discovery_timeout,
489 u.mesh.mshcfg.min_discovery_timeout, DEC);
Rui Paulo63c57232009-11-09 23:46:57 +0000490IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
491 u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
Javier Cardona16dd7262011-08-09 16:45:11 -0700492IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
493 u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
Javier Cardona0507e152011-08-09 16:45:10 -0700494IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
495 u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +0800496IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800497IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100498#endif
499
500
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100501#define DEBUGFS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100502 debugfs_create_file(#name, 0400, sdata->debugfs.dir, \
503 sdata, &name##_ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700504
Johannes Berg0f782312009-12-01 13:37:02 +0100505#define DEBUGFS_ADD_MODE(name, mode) \
506 debugfs_create_file(#name, mode, sdata->debugfs.dir, \
507 sdata, &name##_ops);
508
Jiri Bence9f207f2007-05-05 11:46:38 -0700509static void add_sta_files(struct ieee80211_sub_if_data *sdata)
510{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100511 DEBUGFS_ADD(drop_unencrypted);
Ben Greear4914b3b2011-01-27 22:09:34 -0800512 DEBUGFS_ADD(flags);
513 DEBUGFS_ADD(state);
Ben Greear0fa025f2011-01-28 17:05:42 -0800514 DEBUGFS_ADD(channel_type);
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100515 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
516 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
Simon Wunderlich19468412012-01-28 17:25:33 +0100517 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
518 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
Johannes Berg3e122be2008-07-09 14:40:34 +0200519
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100520 DEBUGFS_ADD(bssid);
521 DEBUGFS_ADD(aid);
Jouni Malinen17e4ec12010-03-29 23:28:30 -0700522 DEBUGFS_ADD(last_beacon);
523 DEBUGFS_ADD(ave_beacon);
Johannes Berg0f782312009-12-01 13:37:02 +0100524 DEBUGFS_ADD_MODE(smps, 0600);
Jouni Malinen681d1192011-02-03 18:35:19 +0200525 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200526 DEBUGFS_ADD_MODE(uapsd_queues, 0600);
527 DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
Jiri Bence9f207f2007-05-05 11:46:38 -0700528}
529
530static void add_ap_files(struct ieee80211_sub_if_data *sdata)
531{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100532 DEBUGFS_ADD(drop_unencrypted);
Ben Greear4914b3b2011-01-27 22:09:34 -0800533 DEBUGFS_ADD(flags);
534 DEBUGFS_ADD(state);
Ben Greear0fa025f2011-01-28 17:05:42 -0800535 DEBUGFS_ADD(channel_type);
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100536 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
537 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
Simon Wunderlich19468412012-01-28 17:25:33 +0100538 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
539 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
Johannes Berg3e122be2008-07-09 14:40:34 +0200540
Johannes Berg29623892011-12-14 12:20:31 +0100541 DEBUGFS_ADD(num_sta_authorized);
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100542 DEBUGFS_ADD(num_sta_ps);
543 DEBUGFS_ADD(dtim_count);
544 DEBUGFS_ADD(num_buffered_multicast);
Jouni Malinen681d1192011-02-03 18:35:19 +0200545 DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
Jiri Bence9f207f2007-05-05 11:46:38 -0700546}
547
Eliad Peller37a41b42011-09-21 14:06:11 +0300548static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
549{
Simon Wunderlich19468412012-01-28 17:25:33 +0100550 DEBUGFS_ADD(channel_type);
551 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
552 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
553 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
554 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
555
Eliad Peller37a41b42011-09-21 14:06:11 +0300556 DEBUGFS_ADD_MODE(tsf, 0600);
557}
558
Jiri Bence9f207f2007-05-05 11:46:38 -0700559static void add_wds_files(struct ieee80211_sub_if_data *sdata)
560{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100561 DEBUGFS_ADD(drop_unencrypted);
Ben Greear4914b3b2011-01-27 22:09:34 -0800562 DEBUGFS_ADD(flags);
563 DEBUGFS_ADD(state);
Ben Greear0fa025f2011-01-28 17:05:42 -0800564 DEBUGFS_ADD(channel_type);
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100565 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
566 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
Simon Wunderlich19468412012-01-28 17:25:33 +0100567 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
568 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
Johannes Berg3e122be2008-07-09 14:40:34 +0200569
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100570 DEBUGFS_ADD(peer);
Jiri Bence9f207f2007-05-05 11:46:38 -0700571}
572
573static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
574{
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100575 DEBUGFS_ADD(drop_unencrypted);
Ben Greear4914b3b2011-01-27 22:09:34 -0800576 DEBUGFS_ADD(flags);
577 DEBUGFS_ADD(state);
Ben Greear0fa025f2011-01-28 17:05:42 -0800578 DEBUGFS_ADD(channel_type);
Johannes Berg2d46d7c2010-01-10 17:12:41 +0100579 DEBUGFS_ADD(rc_rateidx_mask_2ghz);
580 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
Simon Wunderlich19468412012-01-28 17:25:33 +0100581 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
582 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
Jiri Bence9f207f2007-05-05 11:46:38 -0700583}
584
585static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
586{
Ben Greear4914b3b2011-01-27 22:09:34 -0800587 DEBUGFS_ADD(flags);
588 DEBUGFS_ADD(state);
Ben Greear0fa025f2011-01-28 17:05:42 -0800589 DEBUGFS_ADD(channel_type);
Jiri Bence9f207f2007-05-05 11:46:38 -0700590}
591
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100592#ifdef CONFIG_MAC80211_MESH
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100593
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800594static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
595{
596 DEBUGFS_ADD_MODE(tsf, 0600);
597}
598
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100599static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
600{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100601 struct dentry *dir = debugfs_create_dir("mesh_stats",
602 sdata->debugfs.dir);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100603#define MESHSTATS_ADD(name)\
604 debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
605
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700606 MESHSTATS_ADD(fwded_mcast);
607 MESHSTATS_ADD(fwded_unicast);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100608 MESHSTATS_ADD(fwded_frames);
609 MESHSTATS_ADD(dropped_frames_ttl);
610 MESHSTATS_ADD(dropped_frames_no_route);
Javier Cardonacfee66b2011-09-06 13:05:21 -0700611 MESHSTATS_ADD(dropped_frames_congestion);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100612 MESHSTATS_ADD(estab_plinks);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100613#undef MESHSTATS_ADD
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100614}
615
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100616static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
617{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100618 struct dentry *dir = debugfs_create_dir("mesh_config",
619 sdata->debugfs.dir);
620
621#define MESHPARAMS_ADD(name) \
622 debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
623
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100624 MESHPARAMS_ADD(dot11MeshMaxRetries);
625 MESHPARAMS_ADD(dot11MeshRetryTimeout);
626 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
627 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
628 MESHPARAMS_ADD(dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +0100629 MESHPARAMS_ADD(element_ttl);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100630 MESHPARAMS_ADD(auto_open_plinks);
631 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
632 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
633 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
Thomas Pedersendca7e942011-11-24 17:15:24 -0800634 MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100635 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
636 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
637 MESHPARAMS_ADD(path_refresh_time);
638 MESHPARAMS_ADD(min_discovery_timeout);
Javier Cardona699403d2011-08-09 16:45:09 -0700639 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -0700640 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
Javier Cardona16dd7262011-08-09 16:45:11 -0700641 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800642 MESHPARAMS_ADD(rssi_threshold);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100643#undef MESHPARAMS_ADD
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100644}
645#endif
646
Jiri Bence9f207f2007-05-05 11:46:38 -0700647static void add_files(struct ieee80211_sub_if_data *sdata)
648{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100649 if (!sdata->debugfs.dir)
Jiri Bence9f207f2007-05-05 11:46:38 -0700650 return;
651
Johannes Berg51fb61e2007-12-19 01:31:27 +0100652 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200653 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100654#ifdef CONFIG_MAC80211_MESH
Javier Cardona12ce8ba2012-03-05 17:20:38 -0800655 add_mesh_files(sdata);
Luis Carlos Cobo9f42f602008-02-23 15:17:16 +0100656 add_mesh_stats(sdata);
657 add_mesh_config(sdata);
658#endif
Johannes Berg472dbc42008-09-11 00:01:49 +0200659 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200660 case NL80211_IFTYPE_STATION:
Jiri Bence9f207f2007-05-05 11:46:38 -0700661 add_sta_files(sdata);
662 break;
Johannes Berg46900292009-02-15 12:44:28 +0100663 case NL80211_IFTYPE_ADHOC:
Eliad Peller37a41b42011-09-21 14:06:11 +0300664 add_ibss_files(sdata);
Johannes Berg46900292009-02-15 12:44:28 +0100665 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200666 case NL80211_IFTYPE_AP:
Jiri Bence9f207f2007-05-05 11:46:38 -0700667 add_ap_files(sdata);
668 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200669 case NL80211_IFTYPE_WDS:
Jiri Bence9f207f2007-05-05 11:46:38 -0700670 add_wds_files(sdata);
671 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200672 case NL80211_IFTYPE_MONITOR:
Jiri Bence9f207f2007-05-05 11:46:38 -0700673 add_monitor_files(sdata);
674 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200675 case NL80211_IFTYPE_AP_VLAN:
Jiri Bence9f207f2007-05-05 11:46:38 -0700676 add_vlan_files(sdata);
677 break;
678 default:
679 break;
680 }
681}
682
Jiri Bence9f207f2007-05-05 11:46:38 -0700683void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
684{
685 char buf[10+IFNAMSIZ];
686
Johannes Berg47846c92009-11-25 17:46:19 +0100687 sprintf(buf, "netdev:%s", sdata->name);
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100688 sdata->debugfs.dir = debugfs_create_dir(buf,
Jiri Bence9f207f2007-05-05 11:46:38 -0700689 sdata->local->hw.wiphy->debugfsdir);
Ben Greear295bafb2010-09-22 20:29:01 -0700690 if (sdata->debugfs.dir)
691 sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
692 sdata->debugfs.dir);
Johannes Berg75636522008-07-09 14:40:35 +0200693 add_files(sdata);
Jiri Bence9f207f2007-05-05 11:46:38 -0700694}
695
696void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
697{
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100698 if (!sdata->debugfs.dir)
699 return;
700
701 debugfs_remove_recursive(sdata->debugfs.dir);
702 sdata->debugfs.dir = NULL;
Jiri Bence9f207f2007-05-05 11:46:38 -0700703}
704
Johannes Berg47846c92009-11-25 17:46:19 +0100705void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
Jiri Bence9f207f2007-05-05 11:46:38 -0700706{
Johannes Berg7c8081e2007-06-21 18:30:19 +0200707 struct dentry *dir;
Johannes Berg47846c92009-11-25 17:46:19 +0100708 char buf[10 + IFNAMSIZ];
Johannes Berg3e122be2008-07-09 14:40:34 +0200709
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100710 dir = sdata->debugfs.dir;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200711
712 if (!dir)
Johannes Berg47846c92009-11-25 17:46:19 +0100713 return;
Johannes Bergc74e90a2008-10-08 10:18:36 +0200714
Johannes Berg47846c92009-11-25 17:46:19 +0100715 sprintf(buf, "netdev:%s", sdata->name);
Johannes Berg7c8081e2007-06-21 18:30:19 +0200716 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
717 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
718 "dir to %s\n", buf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700719}