Linux Audio

Check our new training course

Loading...
v4.10.11
 
  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 = (struct ieee80211_hdr *) skb_put(skb, 24);
334	memset(hdr, 0, 24);
335	fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
336
337	switch (sdata->vif.type) {
338	case NL80211_IFTYPE_AP:
339		fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
340		/* DA BSSID SA */
341		memcpy(hdr->addr1, addr, ETH_ALEN);
342		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
343		memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
344		break;
345	case NL80211_IFTYPE_STATION:
346		fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
347		/* BSSID SA DA */
348		sdata_lock(sdata);
349		if (!sdata->u.mgd.associated) {
350			sdata_unlock(sdata);
351			dev_kfree_skb(skb);
352			return -ENOTCONN;
353		}
354		memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
355		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
356		memcpy(hdr->addr3, addr, ETH_ALEN);
357		sdata_unlock(sdata);
358		break;
359	default:
360		dev_kfree_skb(skb);
361		return -EOPNOTSUPP;
362	}
363	hdr->frame_control = fc;
364
365	/*
366	 * Add some length to the test frame to make it look bit more valid.
367	 * The exact contents does not matter since the recipient is required
368	 * to drop this because of the Michael MIC failure.
369	 */
370	memset(skb_put(skb, 50), 0, 50);
371
372	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
373
374	ieee80211_tx_skb(sdata, skb);
375
376	return buflen;
377}
378IEEE80211_IF_FILE_W(tkip_mic_test);
379
380static ssize_t ieee80211_if_parse_beacon_loss(
381	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
382{
383	if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
384		return -ENOTCONN;
385
386	ieee80211_beacon_loss(&sdata->vif);
387
388	return buflen;
389}
390IEEE80211_IF_FILE_W(beacon_loss);
391
392static ssize_t ieee80211_if_fmt_uapsd_queues(
393	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
394{
395	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
396
397	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
398}
399
400static ssize_t ieee80211_if_parse_uapsd_queues(
401	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
402{
403	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
404	u8 val;
405	int ret;
406
407	ret = kstrtou8(buf, 0, &val);
408	if (ret)
409		return ret;
410
411	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
412		return -ERANGE;
413
414	ifmgd->uapsd_queues = val;
415
416	return buflen;
417}
418IEEE80211_IF_FILE_RW(uapsd_queues);
419
420static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
421	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
422{
423	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
424
425	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
426}
427
428static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
429	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
430{
431	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
432	unsigned long val;
433	int ret;
434
435	ret = kstrtoul(buf, 0, &val);
436	if (ret)
437		return -EINVAL;
438
439	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
440		return -ERANGE;
441
442	ifmgd->uapsd_max_sp_len = val;
443
444	return buflen;
445}
446IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
447
448static ssize_t ieee80211_if_fmt_tdls_wider_bw(
449	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
450{
451	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
452	bool tdls_wider_bw;
453
454	tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
455			!ifmgd->tdls_wider_bw_prohibited;
456
457	return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
458}
459
460static ssize_t ieee80211_if_parse_tdls_wider_bw(
461	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
462{
463	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
464	u8 val;
465	int ret;
466
467	ret = kstrtou8(buf, 0, &val);
468	if (ret)
469		return ret;
470
471	ifmgd->tdls_wider_bw_prohibited = !val;
472	return buflen;
473}
474IEEE80211_IF_FILE_RW(tdls_wider_bw);
475
476/* AP attributes */
477IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
478IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
479IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
480IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
481
482static ssize_t ieee80211_if_fmt_num_buffered_multicast(
483	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
484{
485	return scnprintf(buf, buflen, "%u\n",
486			 skb_queue_len(&sdata->u.ap.ps.bc_buf));
487}
488IEEE80211_IF_FILE_R(num_buffered_multicast);
489
490static ssize_t ieee80211_if_fmt_aqm(
491	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
492{
493	struct ieee80211_local *local = sdata->local;
494	struct txq_info *txqi = to_txq_info(sdata->vif.txq);
495	int len;
496
 
 
 
 
 
497	spin_lock_bh(&local->fq.lock);
498	rcu_read_lock();
499
500	len = scnprintf(buf,
501			buflen,
502			"ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
503			"%u %u %u %u %u %u %u %u %u %u\n",
504			txqi->txq.ac,
505			txqi->tin.backlog_bytes,
506			txqi->tin.backlog_packets,
507			txqi->tin.flows,
508			txqi->cstats.drop_count,
509			txqi->cstats.ecn_mark,
510			txqi->tin.overlimit,
511			txqi->tin.collisions,
512			txqi->tin.tx_bytes,
513			txqi->tin.tx_packets);
514
515	rcu_read_unlock();
516	spin_unlock_bh(&local->fq.lock);
517
518	return len;
519}
520IEEE80211_IF_FILE_R(aqm);
521
 
 
522/* IBSS attributes */
523static ssize_t ieee80211_if_fmt_tsf(
524	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
525{
526	struct ieee80211_local *local = sdata->local;
527	u64 tsf;
528
529	tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
530
531	return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
532}
533
534static ssize_t ieee80211_if_parse_tsf(
535	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
536{
537	struct ieee80211_local *local = sdata->local;
538	unsigned long long tsf;
539	int ret;
540	int tsf_is_delta = 0;
541
542	if (strncmp(buf, "reset", 5) == 0) {
543		if (local->ops->reset_tsf) {
544			drv_reset_tsf(local, sdata);
545			wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
546		}
547	} else {
548		if (buflen > 10 && buf[1] == '=') {
549			if (buf[0] == '+')
550				tsf_is_delta = 1;
551			else if (buf[0] == '-')
552				tsf_is_delta = -1;
553			else
554				return -EINVAL;
555			buf += 2;
556		}
557		ret = kstrtoull(buf, 10, &tsf);
558		if (ret < 0)
559			return ret;
560		if (tsf_is_delta && local->ops->offset_tsf) {
561			drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
562			wiphy_info(local->hw.wiphy,
563				   "debugfs offset TSF by %018lld\n",
564				   tsf_is_delta * tsf);
565		} else if (local->ops->set_tsf) {
566			if (tsf_is_delta)
567				tsf = drv_get_tsf(local, sdata) +
568				      tsf_is_delta * tsf;
569			drv_set_tsf(local, sdata, tsf);
570			wiphy_info(local->hw.wiphy,
571				   "debugfs set TSF to %#018llx\n", tsf);
572		}
573	}
574
575	ieee80211_recalc_dtim(local, sdata);
576	return buflen;
577}
578IEEE80211_IF_FILE_RW(tsf);
579
 
 
 
 
 
 
580
581/* WDS attributes */
582IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
584#ifdef CONFIG_MAC80211_MESH
585IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
586
587/* Mesh stats attributes */
588IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
589IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
590IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
591IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
592IEEE80211_IF_FILE(dropped_frames_congestion,
593		  u.mesh.mshstats.dropped_frames_congestion, DEC);
594IEEE80211_IF_FILE(dropped_frames_no_route,
595		  u.mesh.mshstats.dropped_frames_no_route, DEC);
596
597/* Mesh parameters */
598IEEE80211_IF_FILE(dot11MeshMaxRetries,
599		  u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
600IEEE80211_IF_FILE(dot11MeshRetryTimeout,
601		  u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
602IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
603		  u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
604IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
605		  u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
606IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
607IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
608IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
609IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
610		  u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
611IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
612		  u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
613IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
614		  u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
615IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
616		  u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
617IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
618		  u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
619IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
620		  u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
621IEEE80211_IF_FILE(path_refresh_time,
622		  u.mesh.mshcfg.path_refresh_time, DEC);
623IEEE80211_IF_FILE(min_discovery_timeout,
624		  u.mesh.mshcfg.min_discovery_timeout, DEC);
625IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
626		  u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
627IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
628		  u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
629IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
630		  u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
631IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
632IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
633IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
634IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
635		  u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
636IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
637		  u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
638IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
639		  u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
640IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
641IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
642		  u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
 
 
 
 
 
643#endif
644
645#define DEBUGFS_ADD_MODE(name, mode) \
646	debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
647			    sdata, &name##_ops);
 
 
 
 
 
 
 
 
 
 
 
 
 
648
649#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
650
651static void add_common_files(struct ieee80211_sub_if_data *sdata)
652{
653	DEBUGFS_ADD(rc_rateidx_mask_2ghz);
654	DEBUGFS_ADD(rc_rateidx_mask_5ghz);
655	DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
656	DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
657	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
658	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
659	DEBUGFS_ADD(hw_queues);
660
661	if (sdata->local->ops->wake_tx_queue)
 
662		DEBUGFS_ADD(aqm);
663}
664
665static void add_sta_files(struct ieee80211_sub_if_data *sdata)
666{
667	DEBUGFS_ADD(bssid);
668	DEBUGFS_ADD(aid);
669	DEBUGFS_ADD(beacon_timeout);
670	DEBUGFS_ADD_MODE(smps, 0600);
671	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
672	DEBUGFS_ADD_MODE(beacon_loss, 0200);
673	DEBUGFS_ADD_MODE(uapsd_queues, 0600);
674	DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
675	DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
 
 
 
676}
677
678static void add_ap_files(struct ieee80211_sub_if_data *sdata)
679{
680	DEBUGFS_ADD(num_mcast_sta);
681	DEBUGFS_ADD_MODE(smps, 0600);
682	DEBUGFS_ADD(num_sta_ps);
683	DEBUGFS_ADD(dtim_count);
684	DEBUGFS_ADD(num_buffered_multicast);
685	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
 
686}
687
688static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
689{
690	/* add num_mcast_sta_vlan using name num_mcast_sta */
691	debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
692			    sdata, &num_mcast_sta_vlan_ops);
693}
694
695static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
696{
697	DEBUGFS_ADD_MODE(tsf, 0600);
698}
699
700static void add_wds_files(struct ieee80211_sub_if_data *sdata)
701{
702	DEBUGFS_ADD(peer);
703}
704
705#ifdef CONFIG_MAC80211_MESH
706
707static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
708{
709	DEBUGFS_ADD_MODE(tsf, 0600);
710	DEBUGFS_ADD_MODE(estab_plinks, 0400);
711}
712
713static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
714{
715	struct dentry *dir = debugfs_create_dir("mesh_stats",
716						sdata->vif.debugfs_dir);
717#define MESHSTATS_ADD(name)\
718	debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
719
720	MESHSTATS_ADD(fwded_mcast);
721	MESHSTATS_ADD(fwded_unicast);
722	MESHSTATS_ADD(fwded_frames);
723	MESHSTATS_ADD(dropped_frames_ttl);
724	MESHSTATS_ADD(dropped_frames_no_route);
725	MESHSTATS_ADD(dropped_frames_congestion);
726#undef MESHSTATS_ADD
727}
728
729static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
730{
731	struct dentry *dir = debugfs_create_dir("mesh_config",
732						sdata->vif.debugfs_dir);
733
734#define MESHPARAMS_ADD(name) \
735	debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
736
737	MESHPARAMS_ADD(dot11MeshMaxRetries);
738	MESHPARAMS_ADD(dot11MeshRetryTimeout);
739	MESHPARAMS_ADD(dot11MeshConfirmTimeout);
740	MESHPARAMS_ADD(dot11MeshHoldingTimeout);
741	MESHPARAMS_ADD(dot11MeshTTL);
742	MESHPARAMS_ADD(element_ttl);
743	MESHPARAMS_ADD(auto_open_plinks);
744	MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
745	MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
746	MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
747	MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
748	MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
749	MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
750	MESHPARAMS_ADD(path_refresh_time);
751	MESHPARAMS_ADD(min_discovery_timeout);
752	MESHPARAMS_ADD(dot11MeshHWMPRootMode);
753	MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
754	MESHPARAMS_ADD(dot11MeshForwarding);
755	MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
756	MESHPARAMS_ADD(rssi_threshold);
757	MESHPARAMS_ADD(ht_opmode);
758	MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
759	MESHPARAMS_ADD(dot11MeshHWMProotInterval);
760	MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
761	MESHPARAMS_ADD(power_mode);
762	MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
 
 
 
763#undef MESHPARAMS_ADD
764}
765#endif
766
767static void add_files(struct ieee80211_sub_if_data *sdata)
768{
769	if (!sdata->vif.debugfs_dir)
770		return;
771
772	DEBUGFS_ADD(flags);
773	DEBUGFS_ADD(state);
774	DEBUGFS_ADD(txpower);
775	DEBUGFS_ADD(user_power_level);
776	DEBUGFS_ADD(ap_power_level);
777
778	if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
779		add_common_files(sdata);
780
781	switch (sdata->vif.type) {
782	case NL80211_IFTYPE_MESH_POINT:
783#ifdef CONFIG_MAC80211_MESH
784		add_mesh_files(sdata);
785		add_mesh_stats(sdata);
786		add_mesh_config(sdata);
787#endif
788		break;
789	case NL80211_IFTYPE_STATION:
790		add_sta_files(sdata);
791		break;
792	case NL80211_IFTYPE_ADHOC:
793		add_ibss_files(sdata);
794		break;
795	case NL80211_IFTYPE_AP:
796		add_ap_files(sdata);
797		break;
798	case NL80211_IFTYPE_AP_VLAN:
799		add_vlan_files(sdata);
800		break;
801	case NL80211_IFTYPE_WDS:
802		add_wds_files(sdata);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
803		break;
804	default:
805		break;
806	}
807}
808
809void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
 
810{
811	char buf[10+IFNAMSIZ];
812
813	sprintf(buf, "netdev:%s", sdata->name);
814	sdata->vif.debugfs_dir = debugfs_create_dir(buf,
815		sdata->local->hw.wiphy->debugfsdir);
816	if (sdata->vif.debugfs_dir)
817		sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
818			sdata->vif.debugfs_dir);
 
819	add_files(sdata);
 
 
820}
821
822void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
823{
824	if (!sdata->vif.debugfs_dir)
825		return;
826
827	debugfs_remove_recursive(sdata->vif.debugfs_dir);
828	sdata->vif.debugfs_dir = NULL;
829	sdata->debugfs.subdir_stations = NULL;
830}
831
832void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
833{
834	struct dentry *dir;
835	char buf[10 + IFNAMSIZ];
836
837	dir = sdata->vif.debugfs_dir;
838
839	if (!dir)
840		return;
841
842	sprintf(buf, "netdev:%s", sdata->name);
843	if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
844		sdata_err(sdata,
845			  "debugfs: failed to rename debugfs dir to %s\n",
846			  buf);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
847}
v6.13.7
   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-2023 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
  25struct ieee80211_if_read_sdata_data {
  26	ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int);
  27	struct ieee80211_sub_if_data *sdata;
  28};
  29
  30static ssize_t ieee80211_if_read_sdata_handler(struct wiphy *wiphy,
  31					       struct file *file,
  32					       char *buf,
  33					       size_t bufsize,
  34					       void *data)
  35{
  36	struct ieee80211_if_read_sdata_data *d = data;
  37
  38	return d->format(d->sdata, buf, bufsize);
  39}
  40
  41static ssize_t ieee80211_if_read_sdata(
  42	struct file *file,
  43	char __user *userbuf,
  44	size_t count, loff_t *ppos,
  45	ssize_t (*format)(const struct ieee80211_sub_if_data *sdata, char *, int))
  46{
  47	struct ieee80211_sub_if_data *sdata = file->private_data;
  48	struct ieee80211_if_read_sdata_data data = {
  49		.format = format,
  50		.sdata = sdata,
  51	};
  52	char buf[200];
 
  53
  54	return wiphy_locked_debugfs_read(sdata->local->hw.wiphy,
  55					 file, buf, sizeof(buf),
  56					 userbuf, count, ppos,
  57					 ieee80211_if_read_sdata_handler,
  58					 &data);
  59}
  60
  61struct ieee80211_if_write_sdata_data {
  62	ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int);
  63	struct ieee80211_sub_if_data *sdata;
  64};
  65
  66static ssize_t ieee80211_if_write_sdata_handler(struct wiphy *wiphy,
  67						struct file *file,
  68						char *buf,
  69						size_t count,
  70						void *data)
  71{
  72	struct ieee80211_if_write_sdata_data *d = data;
  73
  74	return d->write(d->sdata, buf, count);
  75}
  76
  77static ssize_t ieee80211_if_write_sdata(
  78	struct file *file,
  79	const char __user *userbuf,
  80	size_t count, loff_t *ppos,
  81	ssize_t (*write)(struct ieee80211_sub_if_data *sdata, const char *, int))
  82{
  83	struct ieee80211_sub_if_data *sdata = file->private_data;
  84	struct ieee80211_if_write_sdata_data data = {
  85		.write = write,
  86		.sdata = sdata,
  87	};
  88	char buf[64];
 
  89
  90	return wiphy_locked_debugfs_write(sdata->local->hw.wiphy,
  91					  file, buf, sizeof(buf),
  92					  userbuf, count,
  93					  ieee80211_if_write_sdata_handler,
  94					  &data);
  95}
  96
  97struct ieee80211_if_read_link_data {
  98	ssize_t (*format)(const struct ieee80211_link_data *, char *, int);
  99	struct ieee80211_link_data *link;
 100};
 101
 102static ssize_t ieee80211_if_read_link_handler(struct wiphy *wiphy,
 103					      struct file *file,
 104					      char *buf,
 105					      size_t bufsize,
 106					      void *data)
 107{
 108	struct ieee80211_if_read_link_data *d = data;
 109
 110	return d->format(d->link, buf, bufsize);
 111}
 112
 113static ssize_t ieee80211_if_read_link(
 114	struct file *file,
 115	char __user *userbuf,
 116	size_t count, loff_t *ppos,
 117	ssize_t (*format)(const struct ieee80211_link_data *link, char *, int))
 118{
 119	struct ieee80211_link_data *link = file->private_data;
 120	struct ieee80211_if_read_link_data data = {
 121		.format = format,
 122		.link = link,
 123	};
 124	char buf[200];
 125
 126	return wiphy_locked_debugfs_read(link->sdata->local->hw.wiphy,
 127					 file, buf, sizeof(buf),
 128					 userbuf, count, ppos,
 129					 ieee80211_if_read_link_handler,
 130					 &data);
 131}
 132
 133struct ieee80211_if_write_link_data {
 134	ssize_t (*write)(struct ieee80211_link_data *, const char *, int);
 135	struct ieee80211_link_data *link;
 136};
 137
 138static ssize_t ieee80211_if_write_link_handler(struct wiphy *wiphy,
 139					       struct file *file,
 140					       char *buf,
 141					       size_t count,
 142					       void *data)
 143{
 144	struct ieee80211_if_write_sdata_data *d = data;
 145
 146	return d->write(d->sdata, buf, count);
 147}
 148
 149static ssize_t ieee80211_if_write_link(
 150	struct file *file,
 151	const char __user *userbuf,
 152	size_t count, loff_t *ppos,
 153	ssize_t (*write)(struct ieee80211_link_data *link, const char *, int))
 154{
 155	struct ieee80211_link_data *link = file->private_data;
 156	struct ieee80211_if_write_link_data data = {
 157		.write = write,
 158		.link = link,
 159	};
 160	char buf[64];
 161
 162	return wiphy_locked_debugfs_write(link->sdata->local->hw.wiphy,
 163					  file, buf, sizeof(buf),
 164					  userbuf, count,
 165					  ieee80211_if_write_link_handler,
 166					  &data);
 167}
 168
 169#define IEEE80211_IF_FMT(name, type, field, format_string)		\
 170static ssize_t ieee80211_if_fmt_##name(					\
 171	const type *data, char *buf,					\
 172	int buflen)							\
 173{									\
 174	return scnprintf(buf, buflen, format_string, data->field);	\
 175}
 176#define IEEE80211_IF_FMT_DEC(name, type, field)				\
 177		IEEE80211_IF_FMT(name, type, field, "%d\n")
 178#define IEEE80211_IF_FMT_HEX(name, type, field)				\
 179		IEEE80211_IF_FMT(name, type, field, "%#x\n")
 180#define IEEE80211_IF_FMT_LHEX(name, type, field)			\
 181		IEEE80211_IF_FMT(name, type, field, "%#lx\n")
 
 
 182
 183#define IEEE80211_IF_FMT_HEXARRAY(name, type, field)			\
 184static ssize_t ieee80211_if_fmt_##name(					\
 185	const type *data,						\
 186	char *buf, int buflen)						\
 187{									\
 188	char *p = buf;							\
 189	int i;								\
 190	for (i = 0; i < sizeof(data->field); i++) {			\
 191		p += scnprintf(p, buflen + buf - p, "%.2x ",		\
 192				 data->field[i]);			\
 193	}								\
 194	p += scnprintf(p, buflen + buf - p, "\n");			\
 195	return p - buf;							\
 196}
 197
 198#define IEEE80211_IF_FMT_ATOMIC(name, type, field)			\
 199static ssize_t ieee80211_if_fmt_##name(					\
 200	const type *data,						\
 201	char *buf, int buflen)						\
 202{									\
 203	return scnprintf(buf, buflen, "%d\n", atomic_read(&data->field));\
 204}
 205
 206#define IEEE80211_IF_FMT_MAC(name, type, field)				\
 207static ssize_t ieee80211_if_fmt_##name(					\
 208	const type *data, char *buf,					\
 209	int buflen)							\
 210{									\
 211	return scnprintf(buf, buflen, "%pM\n", data->field);		\
 212}
 213
 214#define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, type, field)		\
 215static ssize_t ieee80211_if_fmt_##name(					\
 216	const type *data,						\
 217	char *buf, int buflen)						\
 218{									\
 219	return scnprintf(buf, buflen, "%d\n",				\
 220			 jiffies_to_msecs(data->field));		\
 221}
 222
 223#define _IEEE80211_IF_FILE_OPS(name, _read, _write)			\
 224static const struct debugfs_short_fops name##_ops = {				\
 225	.read = (_read),						\
 226	.write = (_write),						\
 
 227	.llseek = generic_file_llseek,					\
 228}
 229
 230#define _IEEE80211_IF_FILE_R_FN(name)					\
 231static ssize_t ieee80211_if_read_##name(struct file *file,		\
 232					char __user *userbuf,		\
 233					size_t count, loff_t *ppos)	\
 234{									\
 235	return ieee80211_if_read_sdata(file,				\
 236				       userbuf, count, ppos,		\
 237				       ieee80211_if_fmt_##name);	\
 238}
 239
 240#define _IEEE80211_IF_FILE_W_FN(name)					\
 241static ssize_t ieee80211_if_write_##name(struct file *file,		\
 242					 const char __user *userbuf,	\
 243					 size_t count, loff_t *ppos)	\
 244{									\
 245	return ieee80211_if_write_sdata(file, userbuf,			\
 246					count, ppos,			\
 247					ieee80211_if_parse_##name);	\
 248}
 249
 250#define IEEE80211_IF_FILE_R(name)					\
 251	_IEEE80211_IF_FILE_R_FN(name)					\
 252	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
 253
 254#define IEEE80211_IF_FILE_W(name)					\
 255	_IEEE80211_IF_FILE_W_FN(name)					\
 256	_IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
 257
 258#define IEEE80211_IF_FILE_RW(name)					\
 259	_IEEE80211_IF_FILE_R_FN(name)					\
 260	_IEEE80211_IF_FILE_W_FN(name)					\
 261	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name,		\
 262			       ieee80211_if_write_##name)
 263
 264#define IEEE80211_IF_FILE(name, field, format)				\
 265	IEEE80211_IF_FMT_##format(name, struct ieee80211_sub_if_data, field) \
 266	IEEE80211_IF_FILE_R(name)
 267
 268#define _IEEE80211_IF_LINK_R_FN(name)					\
 269static ssize_t ieee80211_if_read_##name(struct file *file,		\
 270					char __user *userbuf,		\
 271					size_t count, loff_t *ppos)	\
 272{									\
 273	return ieee80211_if_read_link(file,				\
 274				      userbuf, count, ppos,		\
 275				      ieee80211_if_fmt_##name);	\
 276}
 277
 278#define _IEEE80211_IF_LINK_W_FN(name)					\
 279static ssize_t ieee80211_if_write_##name(struct file *file,		\
 280					 const char __user *userbuf,	\
 281					 size_t count, loff_t *ppos)	\
 282{									\
 283	return ieee80211_if_write_link(file, userbuf,			\
 284				       count, ppos,			\
 285				       ieee80211_if_parse_##name);	\
 286}
 287
 288#define IEEE80211_IF_LINK_FILE_R(name)					\
 289	_IEEE80211_IF_LINK_R_FN(name)					\
 290	_IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name, NULL)
 291
 292#define IEEE80211_IF_LINK_FILE_W(name)					\
 293	_IEEE80211_IF_LINK_W_FN(name)					\
 294	_IEEE80211_IF_FILE_OPS(link_##name, NULL, ieee80211_if_write_##name)
 295
 296#define IEEE80211_IF_LINK_FILE_RW(name)					\
 297	_IEEE80211_IF_LINK_R_FN(name)					\
 298	_IEEE80211_IF_LINK_W_FN(name)					\
 299	_IEEE80211_IF_FILE_OPS(link_##name, ieee80211_if_read_##name,	\
 300			       ieee80211_if_write_##name)
 301
 302#define IEEE80211_IF_LINK_FILE(name, field, format)				\
 303	IEEE80211_IF_FMT_##format(name, struct ieee80211_link_data, field) \
 304	IEEE80211_IF_LINK_FILE_R(name)
 305
 306/* common attributes */
 307IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
 308		  HEX);
 309IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
 310		  HEX);
 311IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
 312		  rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
 313IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
 314		  rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
 315
 316static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
 317				const struct ieee80211_sub_if_data *sdata,
 318				char *buf, int buflen)
 319{
 320	int i, len = 0;
 321	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
 322
 323	for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
 324		len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
 325	len += scnprintf(buf + len, buflen - len, "\n");
 326
 327	return len;
 328}
 329
 330IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
 331
 332static ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
 333				const struct ieee80211_sub_if_data *sdata,
 334				char *buf, int buflen)
 335{
 336	int i, len = 0;
 337	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
 338
 339	for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
 340		len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
 341	len += scnprintf(buf + len, buflen - len, "\n");
 342
 343	return len;
 344}
 345
 346IEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
 347
 348IEEE80211_IF_FILE(flags, flags, HEX);
 349IEEE80211_IF_FILE(state, state, LHEX);
 350IEEE80211_IF_LINK_FILE(txpower, conf->txpower, DEC);
 351IEEE80211_IF_LINK_FILE(ap_power_level, ap_power_level, DEC);
 352IEEE80211_IF_LINK_FILE(user_power_level, user_power_level, DEC);
 353
 354static ssize_t
 355ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
 356			   char *buf, int buflen)
 357{
 358	int len;
 359
 360	len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
 361			sdata->vif.hw_queue[IEEE80211_AC_VO],
 362			sdata->vif.hw_queue[IEEE80211_AC_VI],
 363			sdata->vif.hw_queue[IEEE80211_AC_BE],
 364			sdata->vif.hw_queue[IEEE80211_AC_BK]);
 365
 366	if (sdata->vif.type == NL80211_IFTYPE_AP)
 367		len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
 368				 sdata->vif.cab_queue);
 369
 370	return len;
 371}
 372IEEE80211_IF_FILE_R(hw_queues);
 373
 374/* STA attributes */
 375IEEE80211_IF_FILE(bssid, deflink.u.mgd.bssid, MAC);
 376IEEE80211_IF_FILE(aid, vif.cfg.aid, DEC);
 377IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
 378
 379static int ieee80211_set_smps(struct ieee80211_link_data *link,
 380			      enum ieee80211_smps_mode smps_mode)
 381{
 382	struct ieee80211_sub_if_data *sdata = link->sdata;
 383	struct ieee80211_local *local = sdata->local;
 384
 385	/* The driver indicated that EML is enabled for the interface, thus do
 386	 * not allow to override the SMPS state.
 387	 */
 388	if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE)
 389		return -EOPNOTSUPP;
 390
 391	if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
 392	    smps_mode == IEEE80211_SMPS_STATIC)
 393		return -EINVAL;
 394
 395	/* auto should be dynamic if in PS mode */
 396	if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
 397	    (smps_mode == IEEE80211_SMPS_DYNAMIC ||
 398	     smps_mode == IEEE80211_SMPS_AUTOMATIC))
 399		return -EINVAL;
 400
 401	if (sdata->vif.type != NL80211_IFTYPE_STATION)
 
 402		return -EOPNOTSUPP;
 403
 404	return __ieee80211_request_smps_mgd(link->sdata, link, smps_mode);
 
 
 
 
 
 
 
 405}
 406
 407static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
 408	[IEEE80211_SMPS_AUTOMATIC] = "auto",
 409	[IEEE80211_SMPS_OFF] = "off",
 410	[IEEE80211_SMPS_STATIC] = "static",
 411	[IEEE80211_SMPS_DYNAMIC] = "dynamic",
 412};
 413
 414static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_link_data *link,
 415				     char *buf, int buflen)
 416{
 417	if (link->sdata->vif.type == NL80211_IFTYPE_STATION)
 418		return snprintf(buf, buflen, "request: %s\nused: %s\n",
 419				smps_modes[link->u.mgd.req_smps],
 420				smps_modes[link->smps_mode]);
 
 
 
 
 421	return -EINVAL;
 422}
 423
 424static ssize_t ieee80211_if_parse_smps(struct ieee80211_link_data *link,
 425				       const char *buf, int buflen)
 426{
 427	enum ieee80211_smps_mode mode;
 428
 429	for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
 430		if (strncmp(buf, smps_modes[mode], buflen) == 0) {
 431			int err = ieee80211_set_smps(link, mode);
 432			if (!err)
 433				return buflen;
 434			return err;
 435		}
 436	}
 437
 438	return -EINVAL;
 439}
 440IEEE80211_IF_LINK_FILE_RW(smps);
 441
 442static ssize_t ieee80211_if_parse_tkip_mic_test(
 443	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
 444{
 445	struct ieee80211_local *local = sdata->local;
 446	u8 addr[ETH_ALEN];
 447	struct sk_buff *skb;
 448	struct ieee80211_hdr *hdr;
 449	__le16 fc;
 450
 451	if (!mac_pton(buf, addr))
 452		return -EINVAL;
 453
 454	if (!ieee80211_sdata_running(sdata))
 455		return -ENOTCONN;
 456
 457	skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
 458	if (!skb)
 459		return -ENOMEM;
 460	skb_reserve(skb, local->hw.extra_tx_headroom);
 461
 462	hdr = skb_put_zero(skb, 24);
 
 463	fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
 464
 465	switch (sdata->vif.type) {
 466	case NL80211_IFTYPE_AP:
 467		fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
 468		/* DA BSSID SA */
 469		memcpy(hdr->addr1, addr, ETH_ALEN);
 470		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
 471		memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
 472		break;
 473	case NL80211_IFTYPE_STATION:
 474		fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
 475		/* BSSID SA DA */
 
 476		if (!sdata->u.mgd.associated) {
 
 477			dev_kfree_skb(skb);
 478			return -ENOTCONN;
 479		}
 480		memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
 481		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
 482		memcpy(hdr->addr3, addr, ETH_ALEN);
 
 483		break;
 484	default:
 485		dev_kfree_skb(skb);
 486		return -EOPNOTSUPP;
 487	}
 488	hdr->frame_control = fc;
 489
 490	/*
 491	 * Add some length to the test frame to make it look bit more valid.
 492	 * The exact contents does not matter since the recipient is required
 493	 * to drop this because of the Michael MIC failure.
 494	 */
 495	skb_put_zero(skb, 50);
 496
 497	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
 498
 499	ieee80211_tx_skb(sdata, skb);
 500
 501	return buflen;
 502}
 503IEEE80211_IF_FILE_W(tkip_mic_test);
 504
 505static ssize_t ieee80211_if_parse_beacon_loss(
 506	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
 507{
 508	if (!ieee80211_sdata_running(sdata) || !sdata->vif.cfg.assoc)
 509		return -ENOTCONN;
 510
 511	ieee80211_beacon_loss(&sdata->vif);
 512
 513	return buflen;
 514}
 515IEEE80211_IF_FILE_W(beacon_loss);
 516
 517static ssize_t ieee80211_if_fmt_uapsd_queues(
 518	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
 519{
 520	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 521
 522	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
 523}
 524
 525static ssize_t ieee80211_if_parse_uapsd_queues(
 526	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
 527{
 528	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 529	u8 val;
 530	int ret;
 531
 532	ret = kstrtou8(buf, 0, &val);
 533	if (ret)
 534		return ret;
 535
 536	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
 537		return -ERANGE;
 538
 539	ifmgd->uapsd_queues = val;
 540
 541	return buflen;
 542}
 543IEEE80211_IF_FILE_RW(uapsd_queues);
 544
 545static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
 546	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
 547{
 548	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 549
 550	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
 551}
 552
 553static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
 554	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
 555{
 556	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 557	unsigned long val;
 558	int ret;
 559
 560	ret = kstrtoul(buf, 0, &val);
 561	if (ret)
 562		return -EINVAL;
 563
 564	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
 565		return -ERANGE;
 566
 567	ifmgd->uapsd_max_sp_len = val;
 568
 569	return buflen;
 570}
 571IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
 572
 573static ssize_t ieee80211_if_fmt_tdls_wider_bw(
 574	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
 575{
 576	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 577	bool tdls_wider_bw;
 578
 579	tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
 580			!ifmgd->tdls_wider_bw_prohibited;
 581
 582	return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
 583}
 584
 585static ssize_t ieee80211_if_parse_tdls_wider_bw(
 586	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
 587{
 588	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 589	u8 val;
 590	int ret;
 591
 592	ret = kstrtou8(buf, 0, &val);
 593	if (ret)
 594		return ret;
 595
 596	ifmgd->tdls_wider_bw_prohibited = !val;
 597	return buflen;
 598}
 599IEEE80211_IF_FILE_RW(tdls_wider_bw);
 600
 601/* AP attributes */
 602IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
 603IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
 604IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
 605IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
 606
 607static ssize_t ieee80211_if_fmt_num_buffered_multicast(
 608	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
 609{
 610	return scnprintf(buf, buflen, "%u\n",
 611			 skb_queue_len(&sdata->u.ap.ps.bc_buf));
 612}
 613IEEE80211_IF_FILE_R(num_buffered_multicast);
 614
 615static ssize_t ieee80211_if_fmt_aqm(
 616	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
 617{
 618	struct ieee80211_local *local = sdata->local;
 619	struct txq_info *txqi;
 620	int len;
 621
 622	if (!sdata->vif.txq)
 623		return 0;
 624
 625	txqi = to_txq_info(sdata->vif.txq);
 626
 627	spin_lock_bh(&local->fq.lock);
 628	rcu_read_lock();
 629
 630	len = scnprintf(buf,
 631			buflen,
 632			"ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
 633			"%u %u %u %u %u %u %u %u %u %u\n",
 634			txqi->txq.ac,
 635			txqi->tin.backlog_bytes,
 636			txqi->tin.backlog_packets,
 637			txqi->tin.flows,
 638			txqi->cstats.drop_count,
 639			txqi->cstats.ecn_mark,
 640			txqi->tin.overlimit,
 641			txqi->tin.collisions,
 642			txqi->tin.tx_bytes,
 643			txqi->tin.tx_packets);
 644
 645	rcu_read_unlock();
 646	spin_unlock_bh(&local->fq.lock);
 647
 648	return len;
 649}
 650IEEE80211_IF_FILE_R(aqm);
 651
 652IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
 653
 654/* IBSS attributes */
 655static ssize_t ieee80211_if_fmt_tsf(
 656	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
 657{
 658	struct ieee80211_local *local = sdata->local;
 659	u64 tsf;
 660
 661	tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
 662
 663	return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
 664}
 665
 666static ssize_t ieee80211_if_parse_tsf(
 667	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
 668{
 669	struct ieee80211_local *local = sdata->local;
 670	unsigned long long tsf;
 671	int ret;
 672	int tsf_is_delta = 0;
 673
 674	if (strncmp(buf, "reset", 5) == 0) {
 675		if (local->ops->reset_tsf) {
 676			drv_reset_tsf(local, sdata);
 677			wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
 678		}
 679	} else {
 680		if (buflen > 10 && buf[1] == '=') {
 681			if (buf[0] == '+')
 682				tsf_is_delta = 1;
 683			else if (buf[0] == '-')
 684				tsf_is_delta = -1;
 685			else
 686				return -EINVAL;
 687			buf += 2;
 688		}
 689		ret = kstrtoull(buf, 10, &tsf);
 690		if (ret < 0)
 691			return ret;
 692		if (tsf_is_delta && local->ops->offset_tsf) {
 693			drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
 694			wiphy_info(local->hw.wiphy,
 695				   "debugfs offset TSF by %018lld\n",
 696				   tsf_is_delta * tsf);
 697		} else if (local->ops->set_tsf) {
 698			if (tsf_is_delta)
 699				tsf = drv_get_tsf(local, sdata) +
 700				      tsf_is_delta * tsf;
 701			drv_set_tsf(local, sdata, tsf);
 702			wiphy_info(local->hw.wiphy,
 703				   "debugfs set TSF to %#018llx\n", tsf);
 704		}
 705	}
 706
 707	ieee80211_recalc_dtim(local, sdata);
 708	return buflen;
 709}
 710IEEE80211_IF_FILE_RW(tsf);
 711
 712static ssize_t ieee80211_if_fmt_valid_links(const struct ieee80211_sub_if_data *sdata,
 713					    char *buf, int buflen)
 714{
 715	return snprintf(buf, buflen, "0x%x\n", sdata->vif.valid_links);
 716}
 717IEEE80211_IF_FILE_R(valid_links);
 718
 719static ssize_t ieee80211_if_fmt_active_links(const struct ieee80211_sub_if_data *sdata,
 720					     char *buf, int buflen)
 721{
 722	return snprintf(buf, buflen, "0x%x\n", sdata->vif.active_links);
 723}
 724
 725static ssize_t ieee80211_if_parse_active_links(struct ieee80211_sub_if_data *sdata,
 726					       const char *buf, int buflen)
 727{
 728	u16 active_links;
 729
 730	if (kstrtou16(buf, 0, &active_links) || !active_links)
 731		return -EINVAL;
 732
 733	return ieee80211_set_active_links(&sdata->vif, active_links) ?: buflen;
 734}
 735IEEE80211_IF_FILE_RW(active_links);
 736
 737IEEE80211_IF_LINK_FILE(addr, conf->addr, MAC);
 738
 739#ifdef CONFIG_MAC80211_MESH
 740IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
 741
 742/* Mesh stats attributes */
 743IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
 744IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
 745IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
 746IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
 
 
 747IEEE80211_IF_FILE(dropped_frames_no_route,
 748		  u.mesh.mshstats.dropped_frames_no_route, DEC);
 749
 750/* Mesh parameters */
 751IEEE80211_IF_FILE(dot11MeshMaxRetries,
 752		  u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
 753IEEE80211_IF_FILE(dot11MeshRetryTimeout,
 754		  u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
 755IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
 756		  u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
 757IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
 758		  u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
 759IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
 760IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
 761IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
 762IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
 763		  u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
 764IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
 765		  u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
 766IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
 767		  u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
 768IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
 769		  u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
 770IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
 771		  u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
 772IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
 773		  u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
 774IEEE80211_IF_FILE(path_refresh_time,
 775		  u.mesh.mshcfg.path_refresh_time, DEC);
 776IEEE80211_IF_FILE(min_discovery_timeout,
 777		  u.mesh.mshcfg.min_discovery_timeout, DEC);
 778IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
 779		  u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
 780IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
 781		  u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
 782IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
 783		  u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
 784IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
 785IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
 786IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
 787IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
 788		  u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
 789IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
 790		  u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
 791IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
 792		  u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
 793IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
 794IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
 795		  u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
 796IEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
 797		  u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
 798IEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC);
 799IEEE80211_IF_FILE(dot11MeshConnectedToAuthServer,
 800		  u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC);
 801#endif
 802
 803#define DEBUGFS_ADD_MODE(name, mode) \
 804	debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
 805			    sdata, &name##_ops)
 806
 807#define DEBUGFS_ADD_X(_bits, _name, _mode) \
 808	debugfs_create_x##_bits(#_name, _mode, sdata->vif.debugfs_dir, \
 809				&sdata->vif._name)
 810
 811#define DEBUGFS_ADD_X8(_name, _mode) \
 812	DEBUGFS_ADD_X(8, _name, _mode)
 813
 814#define DEBUGFS_ADD_X16(_name, _mode) \
 815	DEBUGFS_ADD_X(16, _name, _mode)
 816
 817#define DEBUGFS_ADD_X32(_name, _mode) \
 818	DEBUGFS_ADD_X(32, _name, _mode)
 819
 820#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
 821
 822static void add_common_files(struct ieee80211_sub_if_data *sdata)
 823{
 824	DEBUGFS_ADD(rc_rateidx_mask_2ghz);
 825	DEBUGFS_ADD(rc_rateidx_mask_5ghz);
 826	DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
 827	DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
 828	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
 829	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
 830	DEBUGFS_ADD(hw_queues);
 831
 832	if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
 833	    sdata->vif.type != NL80211_IFTYPE_NAN)
 834		DEBUGFS_ADD(aqm);
 835}
 836
 837static void add_sta_files(struct ieee80211_sub_if_data *sdata)
 838{
 839	DEBUGFS_ADD(bssid);
 840	DEBUGFS_ADD(aid);
 841	DEBUGFS_ADD(beacon_timeout);
 
 842	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
 843	DEBUGFS_ADD_MODE(beacon_loss, 0200);
 844	DEBUGFS_ADD_MODE(uapsd_queues, 0600);
 845	DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
 846	DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
 847	DEBUGFS_ADD_MODE(valid_links, 0400);
 848	DEBUGFS_ADD_MODE(active_links, 0600);
 849	DEBUGFS_ADD_X16(dormant_links, 0400);
 850}
 851
 852static void add_ap_files(struct ieee80211_sub_if_data *sdata)
 853{
 854	DEBUGFS_ADD(num_mcast_sta);
 
 855	DEBUGFS_ADD(num_sta_ps);
 856	DEBUGFS_ADD(dtim_count);
 857	DEBUGFS_ADD(num_buffered_multicast);
 858	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
 859	DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
 860}
 861
 862static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
 863{
 864	/* add num_mcast_sta_vlan using name num_mcast_sta */
 865	debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
 866			    sdata, &num_mcast_sta_vlan_ops);
 867}
 868
 869static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
 870{
 871	DEBUGFS_ADD_MODE(tsf, 0600);
 872}
 873
 
 
 
 
 
 874#ifdef CONFIG_MAC80211_MESH
 875
 876static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
 877{
 878	DEBUGFS_ADD_MODE(tsf, 0600);
 879	DEBUGFS_ADD_MODE(estab_plinks, 0400);
 880}
 881
 882static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
 883{
 884	struct dentry *dir = debugfs_create_dir("mesh_stats",
 885						sdata->vif.debugfs_dir);
 886#define MESHSTATS_ADD(name)\
 887	debugfs_create_file(#name, 0400, dir, sdata, &name##_ops)
 888
 889	MESHSTATS_ADD(fwded_mcast);
 890	MESHSTATS_ADD(fwded_unicast);
 891	MESHSTATS_ADD(fwded_frames);
 892	MESHSTATS_ADD(dropped_frames_ttl);
 893	MESHSTATS_ADD(dropped_frames_no_route);
 
 894#undef MESHSTATS_ADD
 895}
 896
 897static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
 898{
 899	struct dentry *dir = debugfs_create_dir("mesh_config",
 900						sdata->vif.debugfs_dir);
 901
 902#define MESHPARAMS_ADD(name) \
 903	debugfs_create_file(#name, 0600, dir, sdata, &name##_ops)
 904
 905	MESHPARAMS_ADD(dot11MeshMaxRetries);
 906	MESHPARAMS_ADD(dot11MeshRetryTimeout);
 907	MESHPARAMS_ADD(dot11MeshConfirmTimeout);
 908	MESHPARAMS_ADD(dot11MeshHoldingTimeout);
 909	MESHPARAMS_ADD(dot11MeshTTL);
 910	MESHPARAMS_ADD(element_ttl);
 911	MESHPARAMS_ADD(auto_open_plinks);
 912	MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
 913	MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
 914	MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
 915	MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
 916	MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
 917	MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
 918	MESHPARAMS_ADD(path_refresh_time);
 919	MESHPARAMS_ADD(min_discovery_timeout);
 920	MESHPARAMS_ADD(dot11MeshHWMPRootMode);
 921	MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
 922	MESHPARAMS_ADD(dot11MeshForwarding);
 923	MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
 924	MESHPARAMS_ADD(rssi_threshold);
 925	MESHPARAMS_ADD(ht_opmode);
 926	MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
 927	MESHPARAMS_ADD(dot11MeshHWMProotInterval);
 928	MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
 929	MESHPARAMS_ADD(power_mode);
 930	MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
 931	MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
 932	MESHPARAMS_ADD(dot11MeshNolearn);
 933	MESHPARAMS_ADD(dot11MeshConnectedToAuthServer);
 934#undef MESHPARAMS_ADD
 935}
 936#endif
 937
 938static void add_files(struct ieee80211_sub_if_data *sdata)
 939{
 940	if (!sdata->vif.debugfs_dir)
 941		return;
 942
 943	DEBUGFS_ADD(flags);
 944	DEBUGFS_ADD(state);
 
 
 
 945
 946	if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
 947		add_common_files(sdata);
 948
 949	switch (sdata->vif.type) {
 950	case NL80211_IFTYPE_MESH_POINT:
 951#ifdef CONFIG_MAC80211_MESH
 952		add_mesh_files(sdata);
 953		add_mesh_stats(sdata);
 954		add_mesh_config(sdata);
 955#endif
 956		break;
 957	case NL80211_IFTYPE_STATION:
 958		add_sta_files(sdata);
 959		break;
 960	case NL80211_IFTYPE_ADHOC:
 961		add_ibss_files(sdata);
 962		break;
 963	case NL80211_IFTYPE_AP:
 964		add_ap_files(sdata);
 965		break;
 966	case NL80211_IFTYPE_AP_VLAN:
 967		add_vlan_files(sdata);
 968		break;
 969	default:
 970		break;
 971	}
 972}
 973
 974#undef DEBUGFS_ADD_MODE
 975#undef DEBUGFS_ADD
 976
 977#define DEBUGFS_ADD_MODE(dentry, name, mode) \
 978	debugfs_create_file(#name, mode, dentry, \
 979			    link, &link_##name##_ops)
 980
 981#define DEBUGFS_ADD(dentry, name) DEBUGFS_ADD_MODE(dentry, name, 0400)
 982
 983static void add_link_files(struct ieee80211_link_data *link,
 984			   struct dentry *dentry)
 985{
 986	DEBUGFS_ADD(dentry, txpower);
 987	DEBUGFS_ADD(dentry, user_power_level);
 988	DEBUGFS_ADD(dentry, ap_power_level);
 989
 990	switch (link->sdata->vif.type) {
 991	case NL80211_IFTYPE_STATION:
 992		DEBUGFS_ADD_MODE(dentry, smps, 0600);
 993		break;
 994	default:
 995		break;
 996	}
 997}
 998
 999static void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata,
1000					 bool mld_vif)
1001{
1002	char buf[10+IFNAMSIZ];
1003
1004	sprintf(buf, "netdev:%s", sdata->name);
1005	sdata->vif.debugfs_dir = debugfs_create_dir(buf,
1006		sdata->local->hw.wiphy->debugfsdir);
1007	/* deflink also has this */
1008	sdata->deflink.debugfs_dir = sdata->vif.debugfs_dir;
1009	sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
1010							sdata->vif.debugfs_dir);
1011	add_files(sdata);
1012	if (!mld_vif)
1013		add_link_files(&sdata->deflink, sdata->vif.debugfs_dir);
1014}
1015
1016void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
1017{
1018	if (!sdata->vif.debugfs_dir)
1019		return;
1020
1021	debugfs_remove_recursive(sdata->vif.debugfs_dir);
1022	sdata->vif.debugfs_dir = NULL;
1023	sdata->debugfs.subdir_stations = NULL;
1024}
1025
1026void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
1027{
1028	struct dentry *dir;
1029	char buf[10 + IFNAMSIZ];
1030
1031	dir = sdata->vif.debugfs_dir;
1032
1033	if (IS_ERR_OR_NULL(dir))
1034		return;
1035
1036	sprintf(buf, "netdev:%s", sdata->name);
1037	debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);
1038}
1039
1040void ieee80211_debugfs_recreate_netdev(struct ieee80211_sub_if_data *sdata,
1041				       bool mld_vif)
1042{
1043	ieee80211_debugfs_remove_netdev(sdata);
1044	ieee80211_debugfs_add_netdev(sdata, mld_vif);
1045
1046	if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) {
1047		drv_vif_add_debugfs(sdata->local, sdata);
1048		if (!mld_vif)
1049			ieee80211_link_debugfs_drv_add(&sdata->deflink);
1050	}
1051}
1052
1053void ieee80211_link_debugfs_add(struct ieee80211_link_data *link)
1054{
1055	char link_dir_name[10];
1056
1057	if (WARN_ON(!link->sdata->vif.debugfs_dir || link->debugfs_dir))
1058		return;
1059
1060	/* For now, this should not be called for non-MLO capable drivers */
1061	if (WARN_ON(!(link->sdata->local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)))
1062		return;
1063
1064	snprintf(link_dir_name, sizeof(link_dir_name),
1065		 "link-%d", link->link_id);
1066
1067	link->debugfs_dir =
1068		debugfs_create_dir(link_dir_name,
1069				   link->sdata->vif.debugfs_dir);
1070
1071	DEBUGFS_ADD(link->debugfs_dir, addr);
1072	add_link_files(link, link->debugfs_dir);
1073}
1074
1075void ieee80211_link_debugfs_remove(struct ieee80211_link_data *link)
1076{
1077	if (!link->sdata->vif.debugfs_dir || !link->debugfs_dir) {
1078		link->debugfs_dir = NULL;
1079		return;
1080	}
1081
1082	if (link->debugfs_dir == link->sdata->vif.debugfs_dir) {
1083		WARN_ON(link != &link->sdata->deflink);
1084		link->debugfs_dir = NULL;
1085		return;
1086	}
1087
1088	debugfs_remove_recursive(link->debugfs_dir);
1089	link->debugfs_dir = NULL;
1090}
1091
1092void ieee80211_link_debugfs_drv_add(struct ieee80211_link_data *link)
1093{
1094	if (link->sdata->vif.type == NL80211_IFTYPE_MONITOR ||
1095	    WARN_ON(!link->debugfs_dir))
1096		return;
1097
1098	drv_link_add_debugfs(link->sdata->local, link->sdata,
1099			     link->conf, link->debugfs_dir);
1100}
1101
1102void ieee80211_link_debugfs_drv_remove(struct ieee80211_link_data *link)
1103{
1104	if (!link || !link->debugfs_dir)
1105		return;
1106
1107	if (WARN_ON(link->debugfs_dir == link->sdata->vif.debugfs_dir))
1108		return;
1109
1110	/* Recreate the directory excluding the driver data */
1111	debugfs_remove_recursive(link->debugfs_dir);
1112	link->debugfs_dir = NULL;
1113
1114	ieee80211_link_debugfs_add(link);
1115}