debugfs_netdev.c 19.0 KB
Newer Older
J
Jiri Benc 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2006	Jiri Benc <jbenc@suse.cz>
 * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/if.h>
#include <linux/interrupt.h>
#include <linux/netdevice.h>
#include <linux/rtnetlink.h>
16
#include <linux/slab.h>
J
Jiri Benc 已提交
17 18 19 20
#include <linux/notifier.h>
#include <net/mac80211.h>
#include <net/cfg80211.h>
#include "ieee80211_i.h"
J
Johannes Berg 已提交
21
#include "rate.h"
J
Jiri Benc 已提交
22 23
#include "debugfs.h"
#include "debugfs_netdev.h"
24
#include "driver-ops.h"
J
Jiri Benc 已提交
25 26 27 28 29 30 31 32 33 34 35

static ssize_t ieee80211_if_read(
	struct ieee80211_sub_if_data *sdata,
	char __user *userbuf,
	size_t count, loff_t *ppos,
	ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
{
	char buf[70];
	ssize_t ret = -EINVAL;

	read_lock(&dev_base_lock);
36
	if (sdata->dev->reg_state == NETREG_REGISTERED)
J
Jiri Benc 已提交
37 38
		ret = (*format)(sdata, buf, sizeof(buf));
	read_unlock(&dev_base_lock);
39

40
	if (ret >= 0)
41 42
		ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);

J
Jiri Benc 已提交
43 44 45
	return ret;
}

46 47 48 49 50 51
static ssize_t ieee80211_if_write(
	struct ieee80211_sub_if_data *sdata,
	const char __user *userbuf,
	size_t count, loff_t *ppos,
	ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
{
52
	char buf[64];
53
	ssize_t ret;
54

55 56
	if (count >= sizeof(buf))
		return -E2BIG;
57 58

	if (copy_from_user(buf, userbuf, count))
59 60
		return -EFAULT;
	buf[count] = '\0';
61

62
	ret = -ENODEV;
63 64 65 66 67 68 69 70
	rtnl_lock();
	if (sdata->dev->reg_state == NETREG_REGISTERED)
		ret = (*write)(sdata, buf, count);
	rtnl_unlock();

	return ret;
}

J
Jiri Benc 已提交
71 72 73 74 75 76 77 78 79 80 81
#define IEEE80211_IF_FMT(name, field, format_string)			\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata, char *buf,		\
	int buflen)							\
{									\
	return scnprintf(buf, buflen, format_string, sdata->field);	\
}
#define IEEE80211_IF_FMT_DEC(name, field)				\
		IEEE80211_IF_FMT(name, field, "%d\n")
#define IEEE80211_IF_FMT_HEX(name, field)				\
		IEEE80211_IF_FMT(name, field, "%#x\n")
82 83
#define IEEE80211_IF_FMT_LHEX(name, field)				\
		IEEE80211_IF_FMT(name, field, "%#lx\n")
J
Jiri Benc 已提交
84 85 86
#define IEEE80211_IF_FMT_SIZE(name, field)				\
		IEEE80211_IF_FMT(name, field, "%zd\n")

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#define IEEE80211_IF_FMT_HEXARRAY(name, field)				\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata,			\
	char *buf, int buflen)						\
{									\
	char *p = buf;							\
	int i;								\
	for (i = 0; i < sizeof(sdata->field); i++) {			\
		p += scnprintf(p, buflen + buf - p, "%.2x ",		\
				 sdata->field[i]);			\
	}								\
	p += scnprintf(p, buflen + buf - p, "\n");			\
	return p - buf;							\
}

J
Jiri Benc 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114
#define IEEE80211_IF_FMT_ATOMIC(name, field)				\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata,			\
	char *buf, int buflen)						\
{									\
	return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
}

#define IEEE80211_IF_FMT_MAC(name, field)				\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata, char *buf,		\
	int buflen)							\
{									\
115
	return scnprintf(buf, buflen, "%pM\n", sdata->field);		\
J
Jiri Benc 已提交
116 117
}

118 119 120 121 122 123 124 125
#define IEEE80211_IF_FMT_DEC_DIV_16(name, field)			\
static ssize_t ieee80211_if_fmt_##name(					\
	const struct ieee80211_sub_if_data *sdata,			\
	char *buf, int buflen)						\
{									\
	return scnprintf(buf, buflen, "%d\n", sdata->field / 16);	\
}

126
#define __IEEE80211_IF_FILE(name, _write)				\
J
Jiri Benc 已提交
127 128 129 130 131 132 133 134 135 136
static ssize_t ieee80211_if_read_##name(struct file *file,		\
					char __user *userbuf,		\
					size_t count, loff_t *ppos)	\
{									\
	return ieee80211_if_read(file->private_data,			\
				 userbuf, count, ppos,			\
				 ieee80211_if_fmt_##name);		\
}									\
static const struct file_operations name##_ops = {			\
	.read = ieee80211_if_read_##name,				\
137
	.write = (_write),						\
138
	.open = simple_open,						\
139
	.llseek = generic_file_llseek,					\
J
Jiri Benc 已提交
140 141
}

142 143 144 145 146 147 148 149 150 151 152
#define __IEEE80211_IF_FILE_W(name)					\
static ssize_t ieee80211_if_write_##name(struct file *file,		\
					 const char __user *userbuf,	\
					 size_t count, loff_t *ppos)	\
{									\
	return ieee80211_if_write(file->private_data, userbuf, count,	\
				  ppos, ieee80211_if_parse_##name);	\
}									\
__IEEE80211_IF_FILE(name, ieee80211_if_write_##name)


J
Jiri Benc 已提交
153 154
#define IEEE80211_IF_FILE(name, field, format)				\
		IEEE80211_IF_FMT_##format(name, field)			\
155
		__IEEE80211_IF_FILE(name, NULL)
J
Jiri Benc 已提交
156 157 158

/* common attributes */
IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
159 160 161 162
IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[IEEE80211_BAND_2GHZ],
		  HEX);
IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[IEEE80211_BAND_5GHZ],
		  HEX);
163 164 165 166 167
IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
		  rc_rateidx_mcs_mask[IEEE80211_BAND_2GHZ], HEXARRAY);
IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
		  rc_rateidx_mcs_mask[IEEE80211_BAND_5GHZ], HEXARRAY);

168 169
IEEE80211_IF_FILE(flags, flags, HEX);
IEEE80211_IF_FILE(state, state, LHEX);
170
IEEE80211_IF_FILE(channel_type, vif.bss_conf.channel_type, DEC);
J
Jiri Benc 已提交
171

172 173 174
/* STA attributes */
IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
175 176
IEEE80211_IF_FILE(last_beacon, u.mgd.last_beacon_signal, DEC);
IEEE80211_IF_FILE(ave_beacon, u.mgd.ave_beacon_signal, DEC_DIV_16);
J
Jiri Benc 已提交
177

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
			      enum ieee80211_smps_mode smps_mode)
{
	struct ieee80211_local *local = sdata->local;
	int err;

	if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) &&
	    smps_mode == IEEE80211_SMPS_STATIC)
		return -EINVAL;

	/* auto should be dynamic if in PS mode */
	if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) &&
	    (smps_mode == IEEE80211_SMPS_DYNAMIC ||
	     smps_mode == IEEE80211_SMPS_AUTOMATIC))
		return -EINVAL;

	/* supported only on managed interfaces for now */
	if (sdata->vif.type != NL80211_IFTYPE_STATION)
		return -EOPNOTSUPP;

198
	mutex_lock(&sdata->u.mgd.mtx);
199
	err = __ieee80211_request_smps(sdata, smps_mode);
200
	mutex_unlock(&sdata->u.mgd.mtx);
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

	return err;
}

static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
	[IEEE80211_SMPS_AUTOMATIC] = "auto",
	[IEEE80211_SMPS_OFF] = "off",
	[IEEE80211_SMPS_STATIC] = "static",
	[IEEE80211_SMPS_DYNAMIC] = "dynamic",
};

static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
				     char *buf, int buflen)
{
	if (sdata->vif.type != NL80211_IFTYPE_STATION)
		return -EOPNOTSUPP;

	return snprintf(buf, buflen, "request: %s\nused: %s\n",
			smps_modes[sdata->u.mgd.req_smps],
			smps_modes[sdata->u.mgd.ap_smps]);
}

static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
				       const char *buf, int buflen)
{
	enum ieee80211_smps_mode mode;

	for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
		if (strncmp(buf, smps_modes[mode], buflen) == 0) {
			int err = ieee80211_set_smps(sdata, mode);
			if (!err)
				return buflen;
			return err;
		}
	}

	return -EINVAL;
}

__IEEE80211_IF_FILE_W(smps);

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
static ssize_t ieee80211_if_fmt_tkip_mic_test(
	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
{
	return -EOPNOTSUPP;
}

static int hwaddr_aton(const char *txt, u8 *addr)
{
	int i;

	for (i = 0; i < ETH_ALEN; i++) {
		int a, b;

		a = hex_to_bin(*txt++);
		if (a < 0)
			return -1;
		b = hex_to_bin(*txt++);
		if (b < 0)
			return -1;
		*addr++ = (a << 4) | b;
		if (i < 5 && *txt++ != ':')
			return -1;
	}

	return 0;
}

static ssize_t ieee80211_if_parse_tkip_mic_test(
	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
{
	struct ieee80211_local *local = sdata->local;
	u8 addr[ETH_ALEN];
	struct sk_buff *skb;
	struct ieee80211_hdr *hdr;
	__le16 fc;

	/*
	 * Assume colon-delimited MAC address with possible white space
	 * following.
	 */
	if (buflen < 3 * ETH_ALEN - 1)
		return -EINVAL;
	if (hwaddr_aton(buf, addr) < 0)
		return -EINVAL;

	if (!ieee80211_sdata_running(sdata))
		return -ENOTCONN;

	skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
	if (!skb)
		return -ENOMEM;
	skb_reserve(skb, local->hw.extra_tx_headroom);

	hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
	memset(hdr, 0, 24);
	fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);

	switch (sdata->vif.type) {
	case NL80211_IFTYPE_AP:
		fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
		/* DA BSSID SA */
		memcpy(hdr->addr1, addr, ETH_ALEN);
		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
		memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
		break;
	case NL80211_IFTYPE_STATION:
		fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
		/* BSSID SA DA */
		if (sdata->vif.bss_conf.bssid == NULL) {
			dev_kfree_skb(skb);
			return -ENOTCONN;
		}
		memcpy(hdr->addr1, sdata->vif.bss_conf.bssid, ETH_ALEN);
		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
		memcpy(hdr->addr3, addr, ETH_ALEN);
		break;
	default:
		dev_kfree_skb(skb);
		return -EOPNOTSUPP;
	}
	hdr->frame_control = fc;

	/*
	 * Add some length to the test frame to make it look bit more valid.
	 * The exact contents does not matter since the recipient is required
	 * to drop this because of the Michael MIC failure.
	 */
	memset(skb_put(skb, 50), 0, 50);

	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;

	ieee80211_tx_skb(sdata, skb);

	return buflen;
}

__IEEE80211_IF_FILE_W(tkip_mic_test);

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
static ssize_t ieee80211_if_fmt_uapsd_queues(
	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
{
	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;

	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
}

static ssize_t ieee80211_if_parse_uapsd_queues(
	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
{
	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
	u8 val;
	int ret;

	ret = kstrtou8(buf, 0, &val);
	if (ret)
		return ret;

	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
		return -ERANGE;

	ifmgd->uapsd_queues = val;

	return buflen;
}
__IEEE80211_IF_FILE_W(uapsd_queues);

static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
{
	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;

	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
}

static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
{
	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
	unsigned long val;
	int ret;

	ret = kstrtoul(buf, 0, &val);
	if (ret)
		return -EINVAL;

	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
		return -ERANGE;

	ifmgd->uapsd_max_sp_len = val;

	return buflen;
}
__IEEE80211_IF_FILE_W(uapsd_max_sp_len);

J
Jiri Benc 已提交
396
/* AP attributes */
397
IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
J
Jiri Benc 已提交
398 399 400 401 402 403 404 405 406
IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);

static ssize_t ieee80211_if_fmt_num_buffered_multicast(
	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
{
	return scnprintf(buf, buflen, "%u\n",
			 skb_queue_len(&sdata->u.ap.ps_bc_buf));
}
407
__IEEE80211_IF_FILE(num_buffered_multicast, NULL);
J
Jiri Benc 已提交
408

409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
/* IBSS attributes */
static ssize_t ieee80211_if_fmt_tsf(
	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
{
	struct ieee80211_local *local = sdata->local;
	u64 tsf;

	tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);

	return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
}

static ssize_t ieee80211_if_parse_tsf(
	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
{
	struct ieee80211_local *local = sdata->local;
	unsigned long long tsf;
	int ret;
427
	int tsf_is_delta = 0;
428 429 430 431 432 433 434

	if (strncmp(buf, "reset", 5) == 0) {
		if (local->ops->reset_tsf) {
			drv_reset_tsf(local, sdata);
			wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
		}
	} else {
435 436 437 438 439 440 441 442 443
		if (buflen > 10 && buf[1] == '=') {
			if (buf[0] == '+')
				tsf_is_delta = 1;
			else if (buf[0] == '-')
				tsf_is_delta = -1;
			else
				return -EINVAL;
			buf += 2;
		}
444 445 446
		ret = kstrtoull(buf, 10, &tsf);
		if (ret < 0)
			return -EINVAL;
447 448
		if (tsf_is_delta)
			tsf = drv_get_tsf(local, sdata) + tsf_is_delta * tsf;
449 450 451 452 453 454 455 456 457 458 459 460
		if (local->ops->set_tsf) {
			drv_set_tsf(local, sdata, tsf);
			wiphy_info(local->hw.wiphy,
				   "debugfs set TSF to %#018llx\n", tsf);
		}
	}

	return buflen;
}
__IEEE80211_IF_FILE_W(tsf);


J
Jiri Benc 已提交
461 462 463
/* WDS attributes */
IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);

464 465
#ifdef CONFIG_MAC80211_MESH
/* Mesh stats attributes */
466 467
IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
468 469
IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
470
IEEE80211_IF_FILE(dropped_frames_congestion,
471
		  u.mesh.mshstats.dropped_frames_congestion, DEC);
472
IEEE80211_IF_FILE(dropped_frames_no_route,
473
		  u.mesh.mshstats.dropped_frames_no_route, DEC);
474
IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
475 476

/* Mesh parameters */
477
IEEE80211_IF_FILE(dot11MeshMaxRetries,
478
		  u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
479
IEEE80211_IF_FILE(dot11MeshRetryTimeout,
480
		  u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
481
IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
482
		  u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
483
IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
484
		  u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
485
IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
486
IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
487 488
IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
489
		  u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
490
IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
491
		  u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
492
IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
493
		  u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
494
IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
495
		  u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
496
IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
497
		  u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
498
IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
499
		  u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
500
IEEE80211_IF_FILE(path_refresh_time,
501
		  u.mesh.mshcfg.path_refresh_time, DEC);
502
IEEE80211_IF_FILE(min_discovery_timeout,
503
		  u.mesh.mshcfg.min_discovery_timeout, DEC);
504
IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
505
		  u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
506
IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
507
		  u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
508
IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
509
		  u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
510
IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
511
IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
512
IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
513 514
#endif

515 516 517 518
#define DEBUGFS_ADD_MODE(name, mode) \
	debugfs_create_file(#name, mode, sdata->debugfs.dir, \
			    sdata, &name##_ops);

519 520 521
#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)

static void add_common_files(struct ieee80211_sub_if_data *sdata)
J
Jiri Benc 已提交
522
{
523 524 525
	DEBUGFS_ADD(drop_unencrypted);
	DEBUGFS_ADD(rc_rateidx_mask_2ghz);
	DEBUGFS_ADD(rc_rateidx_mask_5ghz);
526 527
	DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
	DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
528
}
529

530 531
static void add_sta_files(struct ieee80211_sub_if_data *sdata)
{
532 533
	DEBUGFS_ADD(bssid);
	DEBUGFS_ADD(aid);
534 535
	DEBUGFS_ADD(last_beacon);
	DEBUGFS_ADD(ave_beacon);
536
	DEBUGFS_ADD_MODE(smps, 0600);
537
	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
538 539
	DEBUGFS_ADD_MODE(uapsd_queues, 0600);
	DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
J
Jiri Benc 已提交
540 541 542 543
}

static void add_ap_files(struct ieee80211_sub_if_data *sdata)
{
544
	DEBUGFS_ADD(num_mcast_sta);
545 546 547
	DEBUGFS_ADD(num_sta_ps);
	DEBUGFS_ADD(dtim_count);
	DEBUGFS_ADD(num_buffered_multicast);
548
	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
J
Jiri Benc 已提交
549 550
}

551 552 553 554 555
static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_ADD_MODE(tsf, 0600);
}

J
Jiri Benc 已提交
556 557
static void add_wds_files(struct ieee80211_sub_if_data *sdata)
{
558
	DEBUGFS_ADD(peer);
J
Jiri Benc 已提交
559 560
}

561 562
#ifdef CONFIG_MAC80211_MESH

563 564 565 566 567
static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
{
	DEBUGFS_ADD_MODE(tsf, 0600);
}

568 569
static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
{
570 571 572 573 574
	struct dentry *dir = debugfs_create_dir("mesh_stats",
						sdata->debugfs.dir);
#define MESHSTATS_ADD(name)\
	debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);

575 576
	MESHSTATS_ADD(fwded_mcast);
	MESHSTATS_ADD(fwded_unicast);
577 578 579
	MESHSTATS_ADD(fwded_frames);
	MESHSTATS_ADD(dropped_frames_ttl);
	MESHSTATS_ADD(dropped_frames_no_route);
580
	MESHSTATS_ADD(dropped_frames_congestion);
581
	MESHSTATS_ADD(estab_plinks);
582
#undef MESHSTATS_ADD
583 584 585 586
}

static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
{
587 588 589 590 591 592
	struct dentry *dir = debugfs_create_dir("mesh_config",
						sdata->debugfs.dir);

#define MESHPARAMS_ADD(name) \
	debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);

593 594 595 596 597
	MESHPARAMS_ADD(dot11MeshMaxRetries);
	MESHPARAMS_ADD(dot11MeshRetryTimeout);
	MESHPARAMS_ADD(dot11MeshConfirmTimeout);
	MESHPARAMS_ADD(dot11MeshHoldingTimeout);
	MESHPARAMS_ADD(dot11MeshTTL);
598
	MESHPARAMS_ADD(element_ttl);
599 600 601 602
	MESHPARAMS_ADD(auto_open_plinks);
	MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
	MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
	MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
603
	MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
604 605 606 607
	MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
	MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
	MESHPARAMS_ADD(path_refresh_time);
	MESHPARAMS_ADD(min_discovery_timeout);
608
	MESHPARAMS_ADD(dot11MeshHWMPRootMode);
609
	MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
610
	MESHPARAMS_ADD(dot11MeshForwarding);
611
	MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
612
	MESHPARAMS_ADD(rssi_threshold);
613
	MESHPARAMS_ADD(ht_opmode);
614
#undef MESHPARAMS_ADD
615 616 617
}
#endif

J
Jiri Benc 已提交
618 619
static void add_files(struct ieee80211_sub_if_data *sdata)
{
620
	if (!sdata->debugfs.dir)
J
Jiri Benc 已提交
621 622
		return;

623 624 625 626 627 628 629
	DEBUGFS_ADD(flags);
	DEBUGFS_ADD(state);
	DEBUGFS_ADD(channel_type);

	if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
		add_common_files(sdata);

630
	switch (sdata->vif.type) {
631
	case NL80211_IFTYPE_MESH_POINT:
632
#ifdef CONFIG_MAC80211_MESH
633
		add_mesh_files(sdata);
634 635 636
		add_mesh_stats(sdata);
		add_mesh_config(sdata);
#endif
637
		break;
638
	case NL80211_IFTYPE_STATION:
J
Jiri Benc 已提交
639 640
		add_sta_files(sdata);
		break;
641
	case NL80211_IFTYPE_ADHOC:
642
		add_ibss_files(sdata);
643
		break;
644
	case NL80211_IFTYPE_AP:
J
Jiri Benc 已提交
645 646
		add_ap_files(sdata);
		break;
647
	case NL80211_IFTYPE_WDS:
J
Jiri Benc 已提交
648 649 650 651 652 653 654 655 656 657 658
		add_wds_files(sdata);
		break;
	default:
		break;
	}
}

void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
{
	char buf[10+IFNAMSIZ];

659
	sprintf(buf, "netdev:%s", sdata->name);
660
	sdata->debugfs.dir = debugfs_create_dir(buf,
J
Jiri Benc 已提交
661
		sdata->local->hw.wiphy->debugfsdir);
662 663 664
	if (sdata->debugfs.dir)
		sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
			sdata->debugfs.dir);
665
	add_files(sdata);
J
Jiri Benc 已提交
666 667 668 669
}

void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
{
670 671 672 673 674
	if (!sdata->debugfs.dir)
		return;

	debugfs_remove_recursive(sdata->debugfs.dir);
	sdata->debugfs.dir = NULL;
J
Jiri Benc 已提交
675 676
}

677
void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
J
Jiri Benc 已提交
678
{
679
	struct dentry *dir;
680
	char buf[10 + IFNAMSIZ];
681

682
	dir = sdata->debugfs.dir;
683 684

	if (!dir)
685
		return;
686

687
	sprintf(buf, "netdev:%s", sdata->name);
688
	if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
689
		pr_err("mac80211: debugfs: failed to rename debugfs "
690
		       "dir to %s\n", buf);
J
Jiri Benc 已提交
691
}