Linux Audio

Check our new training course

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