Linux Audio

Check our new training course

Loading...
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2006	Jiri Benc <jbenc@suse.cz>
  4 * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
  5 * Copyright (C) 2020 Intel Corporation
 
 
 
  6 */
  7
  8#include <linux/kernel.h>
  9#include <linux/device.h>
 10#include <linux/if.h>
 11#include <linux/if_ether.h>
 12#include <linux/interrupt.h>
 13#include <linux/netdevice.h>
 14#include <linux/rtnetlink.h>
 15#include <linux/slab.h>
 16#include <linux/notifier.h>
 17#include <net/mac80211.h>
 18#include <net/cfg80211.h>
 19#include "ieee80211_i.h"
 20#include "rate.h"
 21#include "debugfs.h"
 22#include "debugfs_netdev.h"
 23#include "driver-ops.h"
 24
 25static ssize_t ieee80211_if_read(
 26	struct ieee80211_sub_if_data *sdata,
 27	char __user *userbuf,
 28	size_t count, loff_t *ppos,
 29	ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
 30{
 31	char buf[200];
 32	ssize_t ret = -EINVAL;
 33
 34	read_lock(&dev_base_lock);
 35	ret = (*format)(sdata, buf, sizeof(buf));
 36	read_unlock(&dev_base_lock);
 37
 38	if (ret >= 0)
 39		ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
 40
 41	return ret;
 42}
 43
 44static ssize_t ieee80211_if_write(
 45	struct ieee80211_sub_if_data *sdata,
 46	const char __user *userbuf,
 47	size_t count, loff_t *ppos,
 48	ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
 49{
 50	char buf[64];
 51	ssize_t ret;
 52
 53	if (count >= sizeof(buf))
 54		return -E2BIG;
 55
 56	if (copy_from_user(buf, userbuf, count))
 57		return -EFAULT;
 58	buf[count] = '\0';
 59
 
 60	rtnl_lock();
 61	ret = (*write)(sdata, buf, count);
 62	rtnl_unlock();
 63
 64	return ret;
 65}
 66
 67#define IEEE80211_IF_FMT(name, field, format_string)			\
 68static ssize_t ieee80211_if_fmt_##name(					\
 69	const struct ieee80211_sub_if_data *sdata, char *buf,		\
 70	int buflen)							\
 71{									\
 72	return scnprintf(buf, buflen, format_string, sdata->field);	\
 73}
 74#define IEEE80211_IF_FMT_DEC(name, field)				\
 75		IEEE80211_IF_FMT(name, field, "%d\n")
 76#define IEEE80211_IF_FMT_HEX(name, field)				\
 77		IEEE80211_IF_FMT(name, field, "%#x\n")
 78#define IEEE80211_IF_FMT_LHEX(name, field)				\
 79		IEEE80211_IF_FMT(name, field, "%#lx\n")
 80#define IEEE80211_IF_FMT_SIZE(name, field)				\
 81		IEEE80211_IF_FMT(name, field, "%zd\n")
 82
 83#define IEEE80211_IF_FMT_HEXARRAY(name, field)				\
 84static ssize_t ieee80211_if_fmt_##name(					\
 85	const struct ieee80211_sub_if_data *sdata,			\
 86	char *buf, int buflen)						\
 87{									\
 88	char *p = buf;							\
 89	int i;								\
 90	for (i = 0; i < sizeof(sdata->field); i++) {			\
 91		p += scnprintf(p, buflen + buf - p, "%.2x ",		\
 92				 sdata->field[i]);			\
 93	}								\
 94	p += scnprintf(p, buflen + buf - p, "\n");			\
 95	return p - buf;							\
 96}
 97
 98#define IEEE80211_IF_FMT_ATOMIC(name, field)				\
 99static ssize_t ieee80211_if_fmt_##name(					\
100	const struct ieee80211_sub_if_data *sdata,			\
101	char *buf, int buflen)						\
102{									\
103	return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
104}
105
106#define IEEE80211_IF_FMT_MAC(name, field)				\
107static ssize_t ieee80211_if_fmt_##name(					\
108	const struct ieee80211_sub_if_data *sdata, char *buf,		\
109	int buflen)							\
110{									\
111	return scnprintf(buf, buflen, "%pM\n", sdata->field);		\
112}
113
114#define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field)			\
115static ssize_t ieee80211_if_fmt_##name(					\
116	const struct ieee80211_sub_if_data *sdata,			\
117	char *buf, int buflen)						\
118{									\
119	return scnprintf(buf, buflen, "%d\n",				\
120			 jiffies_to_msecs(sdata->field));		\
121}
122
123#define _IEEE80211_IF_FILE_OPS(name, _read, _write)			\
124static const struct file_operations name##_ops = {			\
125	.read = (_read),						\
126	.write = (_write),						\
127	.open = simple_open,						\
128	.llseek = generic_file_llseek,					\
129}
130
131#define _IEEE80211_IF_FILE_R_FN(name)					\
132static ssize_t ieee80211_if_read_##name(struct file *file,		\
133					char __user *userbuf,		\
134					size_t count, loff_t *ppos)	\
135{									\
136	return ieee80211_if_read(file->private_data,			\
137				 userbuf, count, ppos,			\
138				 ieee80211_if_fmt_##name);		\
139}
140
141#define _IEEE80211_IF_FILE_W_FN(name)					\
142static ssize_t ieee80211_if_write_##name(struct file *file,		\
143					 const char __user *userbuf,	\
144					 size_t count, loff_t *ppos)	\
145{									\
146	return ieee80211_if_write(file->private_data, userbuf, count,	\
147				  ppos, ieee80211_if_parse_##name);	\
148}
149
150#define IEEE80211_IF_FILE_R(name)					\
151	_IEEE80211_IF_FILE_R_FN(name)					\
152	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
153
154#define IEEE80211_IF_FILE_W(name)					\
155	_IEEE80211_IF_FILE_W_FN(name)					\
156	_IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
157
158#define IEEE80211_IF_FILE_RW(name)					\
159	_IEEE80211_IF_FILE_R_FN(name)					\
160	_IEEE80211_IF_FILE_W_FN(name)					\
161	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name,		\
162			       ieee80211_if_write_##name)
163
164#define IEEE80211_IF_FILE(name, field, format)				\
165	IEEE80211_IF_FMT_##format(name, field)				\
166	IEEE80211_IF_FILE_R(name)
167
168/* common attributes */
169IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
170		  HEX);
171IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
172		  HEX);
173IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
174		  rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
175IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
176		  rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
177
178static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
179				const struct ieee80211_sub_if_data *sdata,
180				char *buf, int buflen)
181{
182	int i, len = 0;
183	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
184
185	for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
186		len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
187	len += scnprintf(buf + len, buflen - len, "\n");
188
189	return len;
190}
191
192IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
193
194static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
195				const struct ieee80211_sub_if_data *sdata,
196				char *buf, int buflen)
197{
198	int i, len = 0;
199	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
200
201	for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
202		len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
203	len += scnprintf(buf + len, buflen - len, "\n");
204
205	return len;
206}
207
208IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
209
210IEEE80211_IF_FILE(flags, flags, HEX);
211IEEE80211_IF_FILE(state, state, LHEX);
212IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
213IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
214IEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
215
216static ssize_t
217ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
218			   char *buf, int buflen)
219{
220	int len;
221
222	len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
223			sdata->vif.hw_queue[IEEE80211_AC_VO],
224			sdata->vif.hw_queue[IEEE80211_AC_VI],
225			sdata->vif.hw_queue[IEEE80211_AC_BE],
226			sdata->vif.hw_queue[IEEE80211_AC_BK]);
227
228	if (sdata->vif.type == NL80211_IFTYPE_AP)
229		len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
230				 sdata->vif.cab_queue);
231
232	return len;
233}
234IEEE80211_IF_FILE_R(hw_queues);
235
236/* STA attributes */
237IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
238IEEE80211_IF_FILE(aid, vif.bss_conf.aid, DEC);
239IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
240
241static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
242			      enum ieee80211_smps_mode smps_mode)
243{
244	struct ieee80211_local *local = sdata->local;
245	int err;
246
247	if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
248	    smps_mode == IEEE80211_SMPS_STATIC)
249		return -EINVAL;
250
251	/* auto should be dynamic if in PS mode */
252	if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
253	    (smps_mode == IEEE80211_SMPS_DYNAMIC ||
254	     smps_mode == IEEE80211_SMPS_AUTOMATIC))
255		return -EINVAL;
256
257	if (sdata->vif.type != NL80211_IFTYPE_STATION)
 
258		return -EOPNOTSUPP;
259
260	sdata_lock(sdata);
261	err = __ieee80211_request_smps_mgd(sdata, smps_mode);
 
 
 
262	sdata_unlock(sdata);
263
264	return err;
265}
266
267static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
268	[IEEE80211_SMPS_AUTOMATIC] = "auto",
269	[IEEE80211_SMPS_OFF] = "off",
270	[IEEE80211_SMPS_STATIC] = "static",
271	[IEEE80211_SMPS_DYNAMIC] = "dynamic",
272};
273
274static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
275				     char *buf, int buflen)
276{
277	if (sdata->vif.type == NL80211_IFTYPE_STATION)
278		return snprintf(buf, buflen, "request: %s\nused: %s\n",
279				smps_modes[sdata->u.mgd.req_smps],
280				smps_modes[sdata->smps_mode]);
 
 
 
 
281	return -EINVAL;
282}
283
284static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
285				       const char *buf, int buflen)
286{
287	enum ieee80211_smps_mode mode;
288
289	for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
290		if (strncmp(buf, smps_modes[mode], buflen) == 0) {
291			int err = ieee80211_set_smps(sdata, mode);
292			if (!err)
293				return buflen;
294			return err;
295		}
296	}
297
298	return -EINVAL;
299}
300IEEE80211_IF_FILE_RW(smps);
301
302static ssize_t ieee80211_if_parse_tkip_mic_test(
303	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
304{
305	struct ieee80211_local *local = sdata->local;
306	u8 addr[ETH_ALEN];
307	struct sk_buff *skb;
308	struct ieee80211_hdr *hdr;
309	__le16 fc;
310
311	if (!mac_pton(buf, addr))
312		return -EINVAL;
313
314	if (!ieee80211_sdata_running(sdata))
315		return -ENOTCONN;
316
317	skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
318	if (!skb)
319		return -ENOMEM;
320	skb_reserve(skb, local->hw.extra_tx_headroom);
321
322	hdr = skb_put_zero(skb, 24);
323	fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
324
325	switch (sdata->vif.type) {
326	case NL80211_IFTYPE_AP:
327		fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
328		/* DA BSSID SA */
329		memcpy(hdr->addr1, addr, ETH_ALEN);
330		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
331		memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
332		break;
333	case NL80211_IFTYPE_STATION:
334		fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
335		/* BSSID SA DA */
336		sdata_lock(sdata);
337		if (!sdata->u.mgd.associated) {
338			sdata_unlock(sdata);
339			dev_kfree_skb(skb);
340			return -ENOTCONN;
341		}
342		memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
343		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
344		memcpy(hdr->addr3, addr, ETH_ALEN);
345		sdata_unlock(sdata);
346		break;
347	default:
348		dev_kfree_skb(skb);
349		return -EOPNOTSUPP;
350	}
351	hdr->frame_control = fc;
352
353	/*
354	 * Add some length to the test frame to make it look bit more valid.
355	 * The exact contents does not matter since the recipient is required
356	 * to drop this because of the Michael MIC failure.
357	 */
358	skb_put_zero(skb, 50);
359
360	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
361
362	ieee80211_tx_skb(sdata, skb);
363
364	return buflen;
365}
366IEEE80211_IF_FILE_W(tkip_mic_test);
367
368static ssize_t ieee80211_if_parse_beacon_loss(
369	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
370{
371	if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
372		return -ENOTCONN;
373
374	ieee80211_beacon_loss(&sdata->vif);
375
376	return buflen;
377}
378IEEE80211_IF_FILE_W(beacon_loss);
379
380static ssize_t ieee80211_if_fmt_uapsd_queues(
381	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
382{
383	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
384
385	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
386}
387
388static ssize_t ieee80211_if_parse_uapsd_queues(
389	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
390{
391	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
392	u8 val;
393	int ret;
394
395	ret = kstrtou8(buf, 0, &val);
396	if (ret)
397		return ret;
398
399	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
400		return -ERANGE;
401
402	ifmgd->uapsd_queues = val;
403
404	return buflen;
405}
406IEEE80211_IF_FILE_RW(uapsd_queues);
407
408static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
409	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
410{
411	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
412
413	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
414}
415
416static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
417	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
418{
419	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
420	unsigned long val;
421	int ret;
422
423	ret = kstrtoul(buf, 0, &val);
424	if (ret)
425		return -EINVAL;
426
427	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
428		return -ERANGE;
429
430	ifmgd->uapsd_max_sp_len = val;
431
432	return buflen;
433}
434IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
435
436static ssize_t ieee80211_if_fmt_tdls_wider_bw(
437	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
438{
439	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
440	bool tdls_wider_bw;
441
442	tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
443			!ifmgd->tdls_wider_bw_prohibited;
444
445	return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
446}
447
448static ssize_t ieee80211_if_parse_tdls_wider_bw(
449	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
450{
451	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
452	u8 val;
453	int ret;
454
455	ret = kstrtou8(buf, 0, &val);
456	if (ret)
457		return ret;
458
459	ifmgd->tdls_wider_bw_prohibited = !val;
460	return buflen;
461}
462IEEE80211_IF_FILE_RW(tdls_wider_bw);
463
464/* AP attributes */
465IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
466IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
467IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
468IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
469
470static ssize_t ieee80211_if_fmt_num_buffered_multicast(
471	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
472{
473	return scnprintf(buf, buflen, "%u\n",
474			 skb_queue_len(&sdata->u.ap.ps.bc_buf));
475}
476IEEE80211_IF_FILE_R(num_buffered_multicast);
477
478static ssize_t ieee80211_if_fmt_aqm(
479	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
480{
481	struct ieee80211_local *local = sdata->local;
482	struct txq_info *txqi;
483	int len;
484
485	if (!sdata->vif.txq)
486		return 0;
487
488	txqi = to_txq_info(sdata->vif.txq);
489
490	spin_lock_bh(&local->fq.lock);
491	rcu_read_lock();
492
493	len = scnprintf(buf,
494			buflen,
495			"ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
496			"%u %u %u %u %u %u %u %u %u %u\n",
497			txqi->txq.ac,
498			txqi->tin.backlog_bytes,
499			txqi->tin.backlog_packets,
500			txqi->tin.flows,
501			txqi->cstats.drop_count,
502			txqi->cstats.ecn_mark,
503			txqi->tin.overlimit,
504			txqi->tin.collisions,
505			txqi->tin.tx_bytes,
506			txqi->tin.tx_packets);
507
508	rcu_read_unlock();
509	spin_unlock_bh(&local->fq.lock);
510
511	return len;
512}
513IEEE80211_IF_FILE_R(aqm);
514
515static ssize_t ieee80211_if_fmt_airtime(
516	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
517{
518	struct ieee80211_local *local = sdata->local;
519	struct ieee80211_txq *txq = sdata->vif.txq;
520	struct airtime_info *air_info;
521	int len;
522
523	if (!txq)
524		return 0;
525
526	spin_lock_bh(&local->airtime[txq->ac].lock);
527	air_info = to_airtime_info(txq);
528	len = scnprintf(buf,
529			buflen,
530			"RX: %llu us\nTX: %llu us\nWeight: %u\n"
531			"Virt-T: %lld us\n",
532			air_info->rx_airtime,
533			air_info->tx_airtime,
534			air_info->weight,
535			air_info->v_t);
536	spin_unlock_bh(&local->airtime[txq->ac].lock);
537
538	return len;
539}
540
541IEEE80211_IF_FILE_R(airtime);
542
543IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
544
545/* IBSS attributes */
546static ssize_t ieee80211_if_fmt_tsf(
547	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
548{
549	struct ieee80211_local *local = sdata->local;
550	u64 tsf;
551
552	tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
553
554	return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
555}
556
557static ssize_t ieee80211_if_parse_tsf(
558	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
559{
560	struct ieee80211_local *local = sdata->local;
561	unsigned long long tsf;
562	int ret;
563	int tsf_is_delta = 0;
564
565	if (strncmp(buf, "reset", 5) == 0) {
566		if (local->ops->reset_tsf) {
567			drv_reset_tsf(local, sdata);
568			wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
569		}
570	} else {
571		if (buflen > 10 && buf[1] == '=') {
572			if (buf[0] == '+')
573				tsf_is_delta = 1;
574			else if (buf[0] == '-')
575				tsf_is_delta = -1;
576			else
577				return -EINVAL;
578			buf += 2;
579		}
580		ret = kstrtoull(buf, 10, &tsf);
581		if (ret < 0)
582			return ret;
583		if (tsf_is_delta && local->ops->offset_tsf) {
584			drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
585			wiphy_info(local->hw.wiphy,
586				   "debugfs offset TSF by %018lld\n",
587				   tsf_is_delta * tsf);
588		} else if (local->ops->set_tsf) {
589			if (tsf_is_delta)
590				tsf = drv_get_tsf(local, sdata) +
591				      tsf_is_delta * tsf;
592			drv_set_tsf(local, sdata, tsf);
593			wiphy_info(local->hw.wiphy,
594				   "debugfs set TSF to %#018llx\n", tsf);
595		}
596	}
597
598	ieee80211_recalc_dtim(local, sdata);
599	return buflen;
600}
601IEEE80211_IF_FILE_RW(tsf);
602
603
 
 
 
604#ifdef CONFIG_MAC80211_MESH
605IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
606
607/* Mesh stats attributes */
608IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
609IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
610IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
611IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
612IEEE80211_IF_FILE(dropped_frames_congestion,
613		  u.mesh.mshstats.dropped_frames_congestion, DEC);
614IEEE80211_IF_FILE(dropped_frames_no_route,
615		  u.mesh.mshstats.dropped_frames_no_route, DEC);
616
617/* Mesh parameters */
618IEEE80211_IF_FILE(dot11MeshMaxRetries,
619		  u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
620IEEE80211_IF_FILE(dot11MeshRetryTimeout,
621		  u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
622IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
623		  u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
624IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
625		  u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
626IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
627IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
628IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
629IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
630		  u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
631IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
632		  u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
633IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
634		  u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
635IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
636		  u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
637IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
638		  u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
639IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
640		  u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
641IEEE80211_IF_FILE(path_refresh_time,
642		  u.mesh.mshcfg.path_refresh_time, DEC);
643IEEE80211_IF_FILE(min_discovery_timeout,
644		  u.mesh.mshcfg.min_discovery_timeout, DEC);
645IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
646		  u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
647IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
648		  u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
649IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
650		  u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
651IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
652IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
653IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
654IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
655		  u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
656IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
657		  u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
658IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
659		  u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
660IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
661IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
662		  u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
663IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
664		  u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
665IEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC);
666IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer,
667		  u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC);
668#endif
669
670#define DEBUGFS_ADD_MODE(name, mode) \
671	debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
672			    sdata, &name##_ops)
673
674#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
675
676static void add_common_files(struct ieee80211_sub_if_data *sdata)
677{
678	DEBUGFS_ADD(rc_rateidx_mask_2ghz);
679	DEBUGFS_ADD(rc_rateidx_mask_5ghz);
680	DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
681	DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
682	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
683	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
684	DEBUGFS_ADD(hw_queues);
685
686	if (sdata->local->ops->wake_tx_queue &&
687	    sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
688	    sdata->vif.type != NL80211_IFTYPE_NAN) {
689		DEBUGFS_ADD(aqm);
690		DEBUGFS_ADD(airtime);
691	}
692}
693
694static void add_sta_files(struct ieee80211_sub_if_data *sdata)
695{
696	DEBUGFS_ADD(bssid);
697	DEBUGFS_ADD(aid);
698	DEBUGFS_ADD(beacon_timeout);
699	DEBUGFS_ADD_MODE(smps, 0600);
700	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
701	DEBUGFS_ADD_MODE(beacon_loss, 0200);
702	DEBUGFS_ADD_MODE(uapsd_queues, 0600);
703	DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
704	DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
705}
706
707static void add_ap_files(struct ieee80211_sub_if_data *sdata)
708{
709	DEBUGFS_ADD(num_mcast_sta);
710	DEBUGFS_ADD_MODE(smps, 0600);
711	DEBUGFS_ADD(num_sta_ps);
712	DEBUGFS_ADD(dtim_count);
713	DEBUGFS_ADD(num_buffered_multicast);
714	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
715	DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
716}
717
718static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
719{
720	/* add num_mcast_sta_vlan using name num_mcast_sta */
721	debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
722			    sdata, &num_mcast_sta_vlan_ops);
723}
724
725static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
726{
727	DEBUGFS_ADD_MODE(tsf, 0600);
728}
729
 
 
 
 
 
730#ifdef CONFIG_MAC80211_MESH
731
732static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
733{
734	DEBUGFS_ADD_MODE(tsf, 0600);
735	DEBUGFS_ADD_MODE(estab_plinks, 0400);
736}
737
738static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
739{
740	struct dentry *dir = debugfs_create_dir("mesh_stats",
741						sdata->vif.debugfs_dir);
742#define MESHSTATS_ADD(name)\
743	debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
744
745	MESHSTATS_ADD(fwded_mcast);
746	MESHSTATS_ADD(fwded_unicast);
747	MESHSTATS_ADD(fwded_frames);
748	MESHSTATS_ADD(dropped_frames_ttl);
749	MESHSTATS_ADD(dropped_frames_no_route);
750	MESHSTATS_ADD(dropped_frames_congestion);
751#undef MESHSTATS_ADD
752}
753
754static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
755{
756	struct dentry *dir = debugfs_create_dir("mesh_config",
757						sdata->vif.debugfs_dir);
758
759#define MESHPARAMS_ADD(name) \
760	debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
761
762	MESHPARAMS_ADD(dot11MeshMaxRetries);
763	MESHPARAMS_ADD(dot11MeshRetryTimeout);
764	MESHPARAMS_ADD(dot11MeshConfirmTimeout);
765	MESHPARAMS_ADD(dot11MeshHoldingTimeout);
766	MESHPARAMS_ADD(dot11MeshTTL);
767	MESHPARAMS_ADD(element_ttl);
768	MESHPARAMS_ADD(auto_open_plinks);
769	MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
770	MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
771	MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
772	MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
773	MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
774	MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
775	MESHPARAMS_ADD(path_refresh_time);
776	MESHPARAMS_ADD(min_discovery_timeout);
777	MESHPARAMS_ADD(dot11MeshHWMPRootMode);
778	MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
779	MESHPARAMS_ADD(dot11MeshForwarding);
780	MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
781	MESHPARAMS_ADD(rssi_threshold);
782	MESHPARAMS_ADD(ht_opmode);
783	MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
784	MESHPARAMS_ADD(dot11MeshHWMProotInterval);
785	MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
786	MESHPARAMS_ADD(power_mode);
787	MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
788	MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
789	MESHPARAMS_ADD(dot11MeshNolearn);
790	MESHPARAMS_ADD(dot11MeshConnectedToAuthServer);
791#undef MESHPARAMS_ADD
792}
793#endif
794
795static void add_files(struct ieee80211_sub_if_data *sdata)
796{
797	if (!sdata->vif.debugfs_dir)
798		return;
799
800	DEBUGFS_ADD(flags);
801	DEBUGFS_ADD(state);
802	DEBUGFS_ADD(txpower);
803	DEBUGFS_ADD(user_power_level);
804	DEBUGFS_ADD(ap_power_level);
805
806	if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
807		add_common_files(sdata);
808
809	switch (sdata->vif.type) {
810	case NL80211_IFTYPE_MESH_POINT:
811#ifdef CONFIG_MAC80211_MESH
812		add_mesh_files(sdata);
813		add_mesh_stats(sdata);
814		add_mesh_config(sdata);
815#endif
816		break;
817	case NL80211_IFTYPE_STATION:
818		add_sta_files(sdata);
819		break;
820	case NL80211_IFTYPE_ADHOC:
821		add_ibss_files(sdata);
822		break;
823	case NL80211_IFTYPE_AP:
824		add_ap_files(sdata);
825		break;
826	case NL80211_IFTYPE_AP_VLAN:
827		add_vlan_files(sdata);
828		break;
 
 
 
829	default:
830		break;
831	}
832}
833
834void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
835{
836	char buf[10+IFNAMSIZ];
837
838	sprintf(buf, "netdev:%s", sdata->name);
839	sdata->vif.debugfs_dir = debugfs_create_dir(buf,
840		sdata->local->hw.wiphy->debugfsdir);
841	sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
842							sdata->vif.debugfs_dir);
 
843	add_files(sdata);
844}
845
846void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
847{
848	if (!sdata->vif.debugfs_dir)
849		return;
850
851	debugfs_remove_recursive(sdata->vif.debugfs_dir);
852	sdata->vif.debugfs_dir = NULL;
853	sdata->debugfs.subdir_stations = NULL;
854}
855
856void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
857{
858	struct dentry *dir;
859	char buf[10 + IFNAMSIZ];
860
861	dir = sdata->vif.debugfs_dir;
862
863	if (IS_ERR_OR_NULL(dir))
864		return;
865
866	sprintf(buf, "netdev:%s", sdata->name);
867	debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);
 
 
 
868}
v4.17
 
  1/*
  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/if_ether.h>
 14#include <linux/interrupt.h>
 15#include <linux/netdevice.h>
 16#include <linux/rtnetlink.h>
 17#include <linux/slab.h>
 18#include <linux/notifier.h>
 19#include <net/mac80211.h>
 20#include <net/cfg80211.h>
 21#include "ieee80211_i.h"
 22#include "rate.h"
 23#include "debugfs.h"
 24#include "debugfs_netdev.h"
 25#include "driver-ops.h"
 26
 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{
 33	char buf[200];
 34	ssize_t ret = -EINVAL;
 35
 36	read_lock(&dev_base_lock);
 37	ret = (*format)(sdata, buf, sizeof(buf));
 38	read_unlock(&dev_base_lock);
 39
 40	if (ret >= 0)
 41		ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
 42
 43	return ret;
 44}
 45
 46static 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{
 52	char buf[64];
 53	ssize_t ret;
 54
 55	if (count >= sizeof(buf))
 56		return -E2BIG;
 57
 58	if (copy_from_user(buf, userbuf, count))
 59		return -EFAULT;
 60	buf[count] = '\0';
 61
 62	ret = -ENODEV;
 63	rtnl_lock();
 64	ret = (*write)(sdata, buf, count);
 65	rtnl_unlock();
 66
 67	return ret;
 68}
 69
 70#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")
 81#define IEEE80211_IF_FMT_LHEX(name, field)				\
 82		IEEE80211_IF_FMT(name, field, "%#lx\n")
 83#define IEEE80211_IF_FMT_SIZE(name, field)				\
 84		IEEE80211_IF_FMT(name, field, "%zd\n")
 85
 86#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
101#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{									\
114	return scnprintf(buf, buflen, "%pM\n", sdata->field);		\
115}
116
117#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
126#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)					\
135static 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);		\
142}
143
144#define _IEEE80211_IF_FILE_W_FN(name)					\
145static 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);	\
151}
152
153#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)
166
167#define IEEE80211_IF_FILE(name, field, format)				\
168	IEEE80211_IF_FMT_##format(name, field)				\
169	IEEE80211_IF_FILE_R(name)
170
171/* common attributes */
172IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
173		  HEX);
174IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
175		  HEX);
176IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
177		  rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
178IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
179		  rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
180
181static 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;
186	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
187
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;
202	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
203
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
213IEEE80211_IF_FILE(flags, flags, HEX);
214IEEE80211_IF_FILE(state, state, LHEX);
215IEEE80211_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);
218
219static 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}
237IEEE80211_IF_FILE_R(hw_queues);
238
239/* STA attributes */
240IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
241IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
242IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
243
244static 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
250	if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
251	    smps_mode == IEEE80211_SMPS_STATIC)
252		return -EINVAL;
253
254	/* auto should be dynamic if in PS mode */
255	if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
256	    (smps_mode == IEEE80211_SMPS_DYNAMIC ||
257	     smps_mode == IEEE80211_SMPS_AUTOMATIC))
258		return -EINVAL;
259
260	if (sdata->vif.type != NL80211_IFTYPE_STATION &&
261	    sdata->vif.type != NL80211_IFTYPE_AP)
262		return -EOPNOTSUPP;
263
264	sdata_lock(sdata);
265	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);
269	sdata_unlock(sdata);
270
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{
284	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;
293}
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}
311IEEE80211_IF_FILE_RW(smps);
312
313static 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
322	if (!mac_pton(buf, addr))
323		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 = skb_put_zero(skb, 24);
334	fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
335
336	switch (sdata->vif.type) {
337	case NL80211_IFTYPE_AP:
338		fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
339		/* DA BSSID SA */
340		memcpy(hdr->addr1, addr, ETH_ALEN);
341		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
342		memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
343		break;
344	case NL80211_IFTYPE_STATION:
345		fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
346		/* BSSID SA DA */
347		sdata_lock(sdata);
348		if (!sdata->u.mgd.associated) {
349			sdata_unlock(sdata);
350			dev_kfree_skb(skb);
351			return -ENOTCONN;
352		}
353		memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
354		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
355		memcpy(hdr->addr3, addr, ETH_ALEN);
356		sdata_unlock(sdata);
357		break;
358	default:
359		dev_kfree_skb(skb);
360		return -EOPNOTSUPP;
361	}
362	hdr->frame_control = fc;
363
364	/*
365	 * Add some length to the test frame to make it look bit more valid.
366	 * The exact contents does not matter since the recipient is required
367	 * to drop this because of the Michael MIC failure.
368	 */
369	skb_put_zero(skb, 50);
370
371	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
372
373	ieee80211_tx_skb(sdata, skb);
374
375	return buflen;
376}
377IEEE80211_IF_FILE_W(tkip_mic_test);
378
379static ssize_t ieee80211_if_parse_beacon_loss(
380	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
381{
382	if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
383		return -ENOTCONN;
384
385	ieee80211_beacon_loss(&sdata->vif);
386
387	return buflen;
388}
389IEEE80211_IF_FILE_W(beacon_loss);
390
391static ssize_t ieee80211_if_fmt_uapsd_queues(
392	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
393{
394	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
395
396	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
397}
398
399static ssize_t ieee80211_if_parse_uapsd_queues(
400	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
401{
402	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
403	u8 val;
404	int ret;
405
406	ret = kstrtou8(buf, 0, &val);
407	if (ret)
408		return ret;
409
410	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
411		return -ERANGE;
412
413	ifmgd->uapsd_queues = val;
414
415	return buflen;
416}
417IEEE80211_IF_FILE_RW(uapsd_queues);
418
419static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
420	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
421{
422	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
423
424	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
425}
426
427static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
428	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
429{
430	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
431	unsigned long val;
432	int ret;
433
434	ret = kstrtoul(buf, 0, &val);
435	if (ret)
436		return -EINVAL;
437
438	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
439		return -ERANGE;
440
441	ifmgd->uapsd_max_sp_len = val;
442
443	return buflen;
444}
445IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
446
447static ssize_t ieee80211_if_fmt_tdls_wider_bw(
448	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
449{
450	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
451	bool tdls_wider_bw;
452
453	tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
454			!ifmgd->tdls_wider_bw_prohibited;
455
456	return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
457}
458
459static ssize_t ieee80211_if_parse_tdls_wider_bw(
460	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
461{
462	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
463	u8 val;
464	int ret;
465
466	ret = kstrtou8(buf, 0, &val);
467	if (ret)
468		return ret;
469
470	ifmgd->tdls_wider_bw_prohibited = !val;
471	return buflen;
472}
473IEEE80211_IF_FILE_RW(tdls_wider_bw);
474
475/* AP attributes */
476IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
477IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
478IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
479IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
480
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",
485			 skb_queue_len(&sdata->u.ap.ps.bc_buf));
486}
487IEEE80211_IF_FILE_R(num_buffered_multicast);
488
489static 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;
493	struct txq_info *txqi = to_txq_info(sdata->vif.txq);
494	int len;
495
 
 
 
 
 
496	spin_lock_bh(&local->fq.lock);
497	rcu_read_lock();
498
499	len = scnprintf(buf,
500			buflen,
501			"ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
502			"%u %u %u %u %u %u %u %u %u %u\n",
503			txqi->txq.ac,
504			txqi->tin.backlog_bytes,
505			txqi->tin.backlog_packets,
506			txqi->tin.flows,
507			txqi->cstats.drop_count,
508			txqi->cstats.ecn_mark,
509			txqi->tin.overlimit,
510			txqi->tin.collisions,
511			txqi->tin.tx_bytes,
512			txqi->tin.tx_packets);
513
514	rcu_read_unlock();
515	spin_unlock_bh(&local->fq.lock);
516
517	return len;
518}
519IEEE80211_IF_FILE_R(aqm);
520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
522
523/* IBSS attributes */
524static ssize_t ieee80211_if_fmt_tsf(
525	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
526{
527	struct ieee80211_local *local = sdata->local;
528	u64 tsf;
529
530	tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
531
532	return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
533}
534
535static ssize_t ieee80211_if_parse_tsf(
536	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
537{
538	struct ieee80211_local *local = sdata->local;
539	unsigned long long tsf;
540	int ret;
541	int tsf_is_delta = 0;
542
543	if (strncmp(buf, "reset", 5) == 0) {
544		if (local->ops->reset_tsf) {
545			drv_reset_tsf(local, sdata);
546			wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
547		}
548	} else {
549		if (buflen > 10 && buf[1] == '=') {
550			if (buf[0] == '+')
551				tsf_is_delta = 1;
552			else if (buf[0] == '-')
553				tsf_is_delta = -1;
554			else
555				return -EINVAL;
556			buf += 2;
557		}
558		ret = kstrtoull(buf, 10, &tsf);
559		if (ret < 0)
560			return ret;
561		if (tsf_is_delta && local->ops->offset_tsf) {
562			drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
563			wiphy_info(local->hw.wiphy,
564				   "debugfs offset TSF by %018lld\n",
565				   tsf_is_delta * tsf);
566		} else if (local->ops->set_tsf) {
567			if (tsf_is_delta)
568				tsf = drv_get_tsf(local, sdata) +
569				      tsf_is_delta * tsf;
570			drv_set_tsf(local, sdata, tsf);
571			wiphy_info(local->hw.wiphy,
572				   "debugfs set TSF to %#018llx\n", tsf);
573		}
574	}
575
576	ieee80211_recalc_dtim(local, sdata);
577	return buflen;
578}
579IEEE80211_IF_FILE_RW(tsf);
580
581
582/* WDS attributes */
583IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
584
585#ifdef CONFIG_MAC80211_MESH
586IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
587
588/* Mesh stats attributes */
589IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
590IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
591IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
592IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
593IEEE80211_IF_FILE(dropped_frames_congestion,
594		  u.mesh.mshstats.dropped_frames_congestion, DEC);
595IEEE80211_IF_FILE(dropped_frames_no_route,
596		  u.mesh.mshstats.dropped_frames_no_route, DEC);
597
598/* Mesh parameters */
599IEEE80211_IF_FILE(dot11MeshMaxRetries,
600		  u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
601IEEE80211_IF_FILE(dot11MeshRetryTimeout,
602		  u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
603IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
604		  u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
605IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
606		  u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
607IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
608IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
609IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
610IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
611		  u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
612IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
613		  u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
614IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
615		  u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
616IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
617		  u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
618IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
619		  u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
620IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
621		  u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
622IEEE80211_IF_FILE(path_refresh_time,
623		  u.mesh.mshcfg.path_refresh_time, DEC);
624IEEE80211_IF_FILE(min_discovery_timeout,
625		  u.mesh.mshcfg.min_discovery_timeout, DEC);
626IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
627		  u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
628IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
629		  u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
630IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
631		  u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
632IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
633IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
634IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
635IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
636		  u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
637IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
638		  u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
639IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
640		  u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
641IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
642IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
643		  u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
 
 
 
 
 
644#endif
645
646#define DEBUGFS_ADD_MODE(name, mode) \
647	debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
648			    sdata, &name##_ops);
649
650#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
651
652static void add_common_files(struct ieee80211_sub_if_data *sdata)
653{
654	DEBUGFS_ADD(rc_rateidx_mask_2ghz);
655	DEBUGFS_ADD(rc_rateidx_mask_5ghz);
656	DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
657	DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
658	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
659	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
660	DEBUGFS_ADD(hw_queues);
661
662	if (sdata->local->ops->wake_tx_queue)
 
 
663		DEBUGFS_ADD(aqm);
 
 
664}
665
666static void add_sta_files(struct ieee80211_sub_if_data *sdata)
667{
668	DEBUGFS_ADD(bssid);
669	DEBUGFS_ADD(aid);
670	DEBUGFS_ADD(beacon_timeout);
671	DEBUGFS_ADD_MODE(smps, 0600);
672	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
673	DEBUGFS_ADD_MODE(beacon_loss, 0200);
674	DEBUGFS_ADD_MODE(uapsd_queues, 0600);
675	DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
676	DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
677}
678
679static void add_ap_files(struct ieee80211_sub_if_data *sdata)
680{
681	DEBUGFS_ADD(num_mcast_sta);
682	DEBUGFS_ADD_MODE(smps, 0600);
683	DEBUGFS_ADD(num_sta_ps);
684	DEBUGFS_ADD(dtim_count);
685	DEBUGFS_ADD(num_buffered_multicast);
686	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
687	DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
688}
689
690static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
691{
692	/* add num_mcast_sta_vlan using name num_mcast_sta */
693	debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
694			    sdata, &num_mcast_sta_vlan_ops);
695}
696
697static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
698{
699	DEBUGFS_ADD_MODE(tsf, 0600);
700}
701
702static void add_wds_files(struct ieee80211_sub_if_data *sdata)
703{
704	DEBUGFS_ADD(peer);
705}
706
707#ifdef CONFIG_MAC80211_MESH
708
709static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
710{
711	DEBUGFS_ADD_MODE(tsf, 0600);
712	DEBUGFS_ADD_MODE(estab_plinks, 0400);
713}
714
715static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
716{
717	struct dentry *dir = debugfs_create_dir("mesh_stats",
718						sdata->vif.debugfs_dir);
719#define MESHSTATS_ADD(name)\
720	debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
721
722	MESHSTATS_ADD(fwded_mcast);
723	MESHSTATS_ADD(fwded_unicast);
724	MESHSTATS_ADD(fwded_frames);
725	MESHSTATS_ADD(dropped_frames_ttl);
726	MESHSTATS_ADD(dropped_frames_no_route);
727	MESHSTATS_ADD(dropped_frames_congestion);
728#undef MESHSTATS_ADD
729}
730
731static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
732{
733	struct dentry *dir = debugfs_create_dir("mesh_config",
734						sdata->vif.debugfs_dir);
735
736#define MESHPARAMS_ADD(name) \
737	debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
738
739	MESHPARAMS_ADD(dot11MeshMaxRetries);
740	MESHPARAMS_ADD(dot11MeshRetryTimeout);
741	MESHPARAMS_ADD(dot11MeshConfirmTimeout);
742	MESHPARAMS_ADD(dot11MeshHoldingTimeout);
743	MESHPARAMS_ADD(dot11MeshTTL);
744	MESHPARAMS_ADD(element_ttl);
745	MESHPARAMS_ADD(auto_open_plinks);
746	MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
747	MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
748	MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
749	MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
750	MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
751	MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
752	MESHPARAMS_ADD(path_refresh_time);
753	MESHPARAMS_ADD(min_discovery_timeout);
754	MESHPARAMS_ADD(dot11MeshHWMPRootMode);
755	MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
756	MESHPARAMS_ADD(dot11MeshForwarding);
757	MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
758	MESHPARAMS_ADD(rssi_threshold);
759	MESHPARAMS_ADD(ht_opmode);
760	MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
761	MESHPARAMS_ADD(dot11MeshHWMProotInterval);
762	MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
763	MESHPARAMS_ADD(power_mode);
764	MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
 
 
 
765#undef MESHPARAMS_ADD
766}
767#endif
768
769static void add_files(struct ieee80211_sub_if_data *sdata)
770{
771	if (!sdata->vif.debugfs_dir)
772		return;
773
774	DEBUGFS_ADD(flags);
775	DEBUGFS_ADD(state);
776	DEBUGFS_ADD(txpower);
777	DEBUGFS_ADD(user_power_level);
778	DEBUGFS_ADD(ap_power_level);
779
780	if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
781		add_common_files(sdata);
782
783	switch (sdata->vif.type) {
784	case NL80211_IFTYPE_MESH_POINT:
785#ifdef CONFIG_MAC80211_MESH
786		add_mesh_files(sdata);
787		add_mesh_stats(sdata);
788		add_mesh_config(sdata);
789#endif
790		break;
791	case NL80211_IFTYPE_STATION:
792		add_sta_files(sdata);
793		break;
794	case NL80211_IFTYPE_ADHOC:
795		add_ibss_files(sdata);
796		break;
797	case NL80211_IFTYPE_AP:
798		add_ap_files(sdata);
799		break;
800	case NL80211_IFTYPE_AP_VLAN:
801		add_vlan_files(sdata);
802		break;
803	case NL80211_IFTYPE_WDS:
804		add_wds_files(sdata);
805		break;
806	default:
807		break;
808	}
809}
810
811void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
812{
813	char buf[10+IFNAMSIZ];
814
815	sprintf(buf, "netdev:%s", sdata->name);
816	sdata->vif.debugfs_dir = debugfs_create_dir(buf,
817		sdata->local->hw.wiphy->debugfsdir);
818	if (sdata->vif.debugfs_dir)
819		sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
820			sdata->vif.debugfs_dir);
821	add_files(sdata);
822}
823
824void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
825{
826	if (!sdata->vif.debugfs_dir)
827		return;
828
829	debugfs_remove_recursive(sdata->vif.debugfs_dir);
830	sdata->vif.debugfs_dir = NULL;
831	sdata->debugfs.subdir_stations = NULL;
832}
833
834void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
835{
836	struct dentry *dir;
837	char buf[10 + IFNAMSIZ];
838
839	dir = sdata->vif.debugfs_dir;
840
841	if (!dir)
842		return;
843
844	sprintf(buf, "netdev:%s", sdata->name);
845	if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
846		sdata_err(sdata,
847			  "debugfs: failed to rename debugfs dir to %s\n",
848			  buf);
849}