18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2006	Jiri Benc <jbenc@suse.cz>
48c2ecf20Sopenharmony_ci * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
58c2ecf20Sopenharmony_ci * Copyright (C) 2020 Intel Corporation
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/kernel.h>
98c2ecf20Sopenharmony_ci#include <linux/device.h>
108c2ecf20Sopenharmony_ci#include <linux/if.h>
118c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
128c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
138c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
148c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h>
158c2ecf20Sopenharmony_ci#include <linux/slab.h>
168c2ecf20Sopenharmony_ci#include <linux/notifier.h>
178c2ecf20Sopenharmony_ci#include <net/mac80211.h>
188c2ecf20Sopenharmony_ci#include <net/cfg80211.h>
198c2ecf20Sopenharmony_ci#include "ieee80211_i.h"
208c2ecf20Sopenharmony_ci#include "rate.h"
218c2ecf20Sopenharmony_ci#include "debugfs.h"
228c2ecf20Sopenharmony_ci#include "debugfs_netdev.h"
238c2ecf20Sopenharmony_ci#include "driver-ops.h"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_read(
268c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata,
278c2ecf20Sopenharmony_ci	char __user *userbuf,
288c2ecf20Sopenharmony_ci	size_t count, loff_t *ppos,
298c2ecf20Sopenharmony_ci	ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	char buf[200];
328c2ecf20Sopenharmony_ci	ssize_t ret = -EINVAL;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	read_lock(&dev_base_lock);
358c2ecf20Sopenharmony_ci	ret = (*format)(sdata, buf, sizeof(buf));
368c2ecf20Sopenharmony_ci	read_unlock(&dev_base_lock);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	if (ret >= 0)
398c2ecf20Sopenharmony_ci		ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	return ret;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_write(
458c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata,
468c2ecf20Sopenharmony_ci	const char __user *userbuf,
478c2ecf20Sopenharmony_ci	size_t count, loff_t *ppos,
488c2ecf20Sopenharmony_ci	ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	char buf[64];
518c2ecf20Sopenharmony_ci	ssize_t ret;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	if (count >= sizeof(buf))
548c2ecf20Sopenharmony_ci		return -E2BIG;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	if (copy_from_user(buf, userbuf, count))
578c2ecf20Sopenharmony_ci		return -EFAULT;
588c2ecf20Sopenharmony_ci	buf[count] = '\0';
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	ret = -ENODEV;
618c2ecf20Sopenharmony_ci	rtnl_lock();
628c2ecf20Sopenharmony_ci	ret = (*write)(sdata, buf, count);
638c2ecf20Sopenharmony_ci	rtnl_unlock();
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	return ret;
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT(name, field, format_string)			\
698c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_##name(					\
708c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf,		\
718c2ecf20Sopenharmony_ci	int buflen)							\
728c2ecf20Sopenharmony_ci{									\
738c2ecf20Sopenharmony_ci	return scnprintf(buf, buflen, format_string, sdata->field);	\
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_DEC(name, field)				\
768c2ecf20Sopenharmony_ci		IEEE80211_IF_FMT(name, field, "%d\n")
778c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_HEX(name, field)				\
788c2ecf20Sopenharmony_ci		IEEE80211_IF_FMT(name, field, "%#x\n")
798c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_LHEX(name, field)				\
808c2ecf20Sopenharmony_ci		IEEE80211_IF_FMT(name, field, "%#lx\n")
818c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_SIZE(name, field)				\
828c2ecf20Sopenharmony_ci		IEEE80211_IF_FMT(name, field, "%zd\n")
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_HEXARRAY(name, field)				\
858c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_##name(					\
868c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata,			\
878c2ecf20Sopenharmony_ci	char *buf, int buflen)						\
888c2ecf20Sopenharmony_ci{									\
898c2ecf20Sopenharmony_ci	char *p = buf;							\
908c2ecf20Sopenharmony_ci	int i;								\
918c2ecf20Sopenharmony_ci	for (i = 0; i < sizeof(sdata->field); i++) {			\
928c2ecf20Sopenharmony_ci		p += scnprintf(p, buflen + buf - p, "%.2x ",		\
938c2ecf20Sopenharmony_ci				 sdata->field[i]);			\
948c2ecf20Sopenharmony_ci	}								\
958c2ecf20Sopenharmony_ci	p += scnprintf(p, buflen + buf - p, "\n");			\
968c2ecf20Sopenharmony_ci	return p - buf;							\
978c2ecf20Sopenharmony_ci}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_ATOMIC(name, field)				\
1008c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_##name(					\
1018c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata,			\
1028c2ecf20Sopenharmony_ci	char *buf, int buflen)						\
1038c2ecf20Sopenharmony_ci{									\
1048c2ecf20Sopenharmony_ci	return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_MAC(name, field)				\
1088c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_##name(					\
1098c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf,		\
1108c2ecf20Sopenharmony_ci	int buflen)							\
1118c2ecf20Sopenharmony_ci{									\
1128c2ecf20Sopenharmony_ci	return scnprintf(buf, buflen, "%pM\n", sdata->field);		\
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define IEEE80211_IF_FMT_JIFFIES_TO_MS(name, field)			\
1168c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_##name(					\
1178c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata,			\
1188c2ecf20Sopenharmony_ci	char *buf, int buflen)						\
1198c2ecf20Sopenharmony_ci{									\
1208c2ecf20Sopenharmony_ci	return scnprintf(buf, buflen, "%d\n",				\
1218c2ecf20Sopenharmony_ci			 jiffies_to_msecs(sdata->field));		\
1228c2ecf20Sopenharmony_ci}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define _IEEE80211_IF_FILE_OPS(name, _read, _write)			\
1258c2ecf20Sopenharmony_cistatic const struct file_operations name##_ops = {			\
1268c2ecf20Sopenharmony_ci	.read = (_read),						\
1278c2ecf20Sopenharmony_ci	.write = (_write),						\
1288c2ecf20Sopenharmony_ci	.open = simple_open,						\
1298c2ecf20Sopenharmony_ci	.llseek = generic_file_llseek,					\
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#define _IEEE80211_IF_FILE_R_FN(name)					\
1338c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_read_##name(struct file *file,		\
1348c2ecf20Sopenharmony_ci					char __user *userbuf,		\
1358c2ecf20Sopenharmony_ci					size_t count, loff_t *ppos)	\
1368c2ecf20Sopenharmony_ci{									\
1378c2ecf20Sopenharmony_ci	return ieee80211_if_read(file->private_data,			\
1388c2ecf20Sopenharmony_ci				 userbuf, count, ppos,			\
1398c2ecf20Sopenharmony_ci				 ieee80211_if_fmt_##name);		\
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define _IEEE80211_IF_FILE_W_FN(name)					\
1438c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_write_##name(struct file *file,		\
1448c2ecf20Sopenharmony_ci					 const char __user *userbuf,	\
1458c2ecf20Sopenharmony_ci					 size_t count, loff_t *ppos)	\
1468c2ecf20Sopenharmony_ci{									\
1478c2ecf20Sopenharmony_ci	return ieee80211_if_write(file->private_data, userbuf, count,	\
1488c2ecf20Sopenharmony_ci				  ppos, ieee80211_if_parse_##name);	\
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#define IEEE80211_IF_FILE_R(name)					\
1528c2ecf20Sopenharmony_ci	_IEEE80211_IF_FILE_R_FN(name)					\
1538c2ecf20Sopenharmony_ci	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name, NULL)
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define IEEE80211_IF_FILE_W(name)					\
1568c2ecf20Sopenharmony_ci	_IEEE80211_IF_FILE_W_FN(name)					\
1578c2ecf20Sopenharmony_ci	_IEEE80211_IF_FILE_OPS(name, NULL, ieee80211_if_write_##name)
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci#define IEEE80211_IF_FILE_RW(name)					\
1608c2ecf20Sopenharmony_ci	_IEEE80211_IF_FILE_R_FN(name)					\
1618c2ecf20Sopenharmony_ci	_IEEE80211_IF_FILE_W_FN(name)					\
1628c2ecf20Sopenharmony_ci	_IEEE80211_IF_FILE_OPS(name, ieee80211_if_read_##name,		\
1638c2ecf20Sopenharmony_ci			       ieee80211_if_write_##name)
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci#define IEEE80211_IF_FILE(name, field, format)				\
1668c2ecf20Sopenharmony_ci	IEEE80211_IF_FMT_##format(name, field)				\
1678c2ecf20Sopenharmony_ci	IEEE80211_IF_FILE_R(name)
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/* common attributes */
1708c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[NL80211_BAND_2GHZ],
1718c2ecf20Sopenharmony_ci		  HEX);
1728c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
1738c2ecf20Sopenharmony_ci		  HEX);
1748c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
1758c2ecf20Sopenharmony_ci		  rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
1768c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
1778c2ecf20Sopenharmony_ci		  rc_rateidx_mcs_mask[NL80211_BAND_5GHZ], HEXARRAY);
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_2ghz(
1808c2ecf20Sopenharmony_ci				const struct ieee80211_sub_if_data *sdata,
1818c2ecf20Sopenharmony_ci				char *buf, int buflen)
1828c2ecf20Sopenharmony_ci{
1838c2ecf20Sopenharmony_ci	int i, len = 0;
1848c2ecf20Sopenharmony_ci	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_2GHZ];
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci	for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
1878c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
1888c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buflen - len, "\n");
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	return len;
1918c2ecf20Sopenharmony_ci}
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_2ghz);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_rc_rateidx_vht_mcs_mask_5ghz(
1968c2ecf20Sopenharmony_ci				const struct ieee80211_sub_if_data *sdata,
1978c2ecf20Sopenharmony_ci				char *buf, int buflen)
1988c2ecf20Sopenharmony_ci{
1998c2ecf20Sopenharmony_ci	int i, len = 0;
2008c2ecf20Sopenharmony_ci	const u16 *mask = sdata->rc_rateidx_vht_mcs_mask[NL80211_BAND_5GHZ];
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
2038c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, buflen - len, "%04x ", mask[i]);
2048c2ecf20Sopenharmony_ci	len += scnprintf(buf + len, buflen - len, "\n");
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	return len;
2078c2ecf20Sopenharmony_ci}
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_R(rc_rateidx_vht_mcs_mask_5ghz);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(flags, flags, HEX);
2128c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(state, state, LHEX);
2138c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
2148c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
2158c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistatic ssize_t
2188c2ecf20Sopenharmony_ciieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
2198c2ecf20Sopenharmony_ci			   char *buf, int buflen)
2208c2ecf20Sopenharmony_ci{
2218c2ecf20Sopenharmony_ci	int len;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
2248c2ecf20Sopenharmony_ci			sdata->vif.hw_queue[IEEE80211_AC_VO],
2258c2ecf20Sopenharmony_ci			sdata->vif.hw_queue[IEEE80211_AC_VI],
2268c2ecf20Sopenharmony_ci			sdata->vif.hw_queue[IEEE80211_AC_BE],
2278c2ecf20Sopenharmony_ci			sdata->vif.hw_queue[IEEE80211_AC_BK]);
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	if (sdata->vif.type == NL80211_IFTYPE_AP)
2308c2ecf20Sopenharmony_ci		len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
2318c2ecf20Sopenharmony_ci				 sdata->vif.cab_queue);
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	return len;
2348c2ecf20Sopenharmony_ci}
2358c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_R(hw_queues);
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci/* STA attributes */
2388c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
2398c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(aid, vif.bss_conf.aid, DEC);
2408c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS);
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_cistatic int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
2438c2ecf20Sopenharmony_ci			      enum ieee80211_smps_mode smps_mode)
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sdata->local;
2468c2ecf20Sopenharmony_ci	int err;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) &&
2498c2ecf20Sopenharmony_ci	    smps_mode == IEEE80211_SMPS_STATIC)
2508c2ecf20Sopenharmony_ci		return -EINVAL;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	/* auto should be dynamic if in PS mode */
2538c2ecf20Sopenharmony_ci	if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) &&
2548c2ecf20Sopenharmony_ci	    (smps_mode == IEEE80211_SMPS_DYNAMIC ||
2558c2ecf20Sopenharmony_ci	     smps_mode == IEEE80211_SMPS_AUTOMATIC))
2568c2ecf20Sopenharmony_ci		return -EINVAL;
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	if (sdata->vif.type != NL80211_IFTYPE_STATION)
2598c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	sdata_lock(sdata);
2628c2ecf20Sopenharmony_ci	err = __ieee80211_request_smps_mgd(sdata, smps_mode);
2638c2ecf20Sopenharmony_ci	sdata_unlock(sdata);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	return err;
2668c2ecf20Sopenharmony_ci}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cistatic const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
2698c2ecf20Sopenharmony_ci	[IEEE80211_SMPS_AUTOMATIC] = "auto",
2708c2ecf20Sopenharmony_ci	[IEEE80211_SMPS_OFF] = "off",
2718c2ecf20Sopenharmony_ci	[IEEE80211_SMPS_STATIC] = "static",
2728c2ecf20Sopenharmony_ci	[IEEE80211_SMPS_DYNAMIC] = "dynamic",
2738c2ecf20Sopenharmony_ci};
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
2768c2ecf20Sopenharmony_ci				     char *buf, int buflen)
2778c2ecf20Sopenharmony_ci{
2788c2ecf20Sopenharmony_ci	if (sdata->vif.type == NL80211_IFTYPE_STATION)
2798c2ecf20Sopenharmony_ci		return snprintf(buf, buflen, "request: %s\nused: %s\n",
2808c2ecf20Sopenharmony_ci				smps_modes[sdata->u.mgd.req_smps],
2818c2ecf20Sopenharmony_ci				smps_modes[sdata->smps_mode]);
2828c2ecf20Sopenharmony_ci	return -EINVAL;
2838c2ecf20Sopenharmony_ci}
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
2868c2ecf20Sopenharmony_ci				       const char *buf, int buflen)
2878c2ecf20Sopenharmony_ci{
2888c2ecf20Sopenharmony_ci	enum ieee80211_smps_mode mode;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
2918c2ecf20Sopenharmony_ci		if (strncmp(buf, smps_modes[mode], buflen) == 0) {
2928c2ecf20Sopenharmony_ci			int err = ieee80211_set_smps(sdata, mode);
2938c2ecf20Sopenharmony_ci			if (!err)
2948c2ecf20Sopenharmony_ci				return buflen;
2958c2ecf20Sopenharmony_ci			return err;
2968c2ecf20Sopenharmony_ci		}
2978c2ecf20Sopenharmony_ci	}
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	return -EINVAL;
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_RW(smps);
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_parse_tkip_mic_test(
3048c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sdata->local;
3078c2ecf20Sopenharmony_ci	u8 addr[ETH_ALEN];
3088c2ecf20Sopenharmony_ci	struct sk_buff *skb;
3098c2ecf20Sopenharmony_ci	struct ieee80211_hdr *hdr;
3108c2ecf20Sopenharmony_ci	__le16 fc;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	if (!mac_pton(buf, addr))
3138c2ecf20Sopenharmony_ci		return -EINVAL;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	if (!ieee80211_sdata_running(sdata))
3168c2ecf20Sopenharmony_ci		return -ENOTCONN;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
3198c2ecf20Sopenharmony_ci	if (!skb)
3208c2ecf20Sopenharmony_ci		return -ENOMEM;
3218c2ecf20Sopenharmony_ci	skb_reserve(skb, local->hw.extra_tx_headroom);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	hdr = skb_put_zero(skb, 24);
3248c2ecf20Sopenharmony_ci	fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	switch (sdata->vif.type) {
3278c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
3288c2ecf20Sopenharmony_ci		fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
3298c2ecf20Sopenharmony_ci		/* DA BSSID SA */
3308c2ecf20Sopenharmony_ci		memcpy(hdr->addr1, addr, ETH_ALEN);
3318c2ecf20Sopenharmony_ci		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3328c2ecf20Sopenharmony_ci		memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
3338c2ecf20Sopenharmony_ci		break;
3348c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
3358c2ecf20Sopenharmony_ci		fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
3368c2ecf20Sopenharmony_ci		/* BSSID SA DA */
3378c2ecf20Sopenharmony_ci		sdata_lock(sdata);
3388c2ecf20Sopenharmony_ci		if (!sdata->u.mgd.associated) {
3398c2ecf20Sopenharmony_ci			sdata_unlock(sdata);
3408c2ecf20Sopenharmony_ci			dev_kfree_skb(skb);
3418c2ecf20Sopenharmony_ci			return -ENOTCONN;
3428c2ecf20Sopenharmony_ci		}
3438c2ecf20Sopenharmony_ci		memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
3448c2ecf20Sopenharmony_ci		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3458c2ecf20Sopenharmony_ci		memcpy(hdr->addr3, addr, ETH_ALEN);
3468c2ecf20Sopenharmony_ci		sdata_unlock(sdata);
3478c2ecf20Sopenharmony_ci		break;
3488c2ecf20Sopenharmony_ci	default:
3498c2ecf20Sopenharmony_ci		dev_kfree_skb(skb);
3508c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
3518c2ecf20Sopenharmony_ci	}
3528c2ecf20Sopenharmony_ci	hdr->frame_control = fc;
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	/*
3558c2ecf20Sopenharmony_ci	 * Add some length to the test frame to make it look bit more valid.
3568c2ecf20Sopenharmony_ci	 * The exact contents does not matter since the recipient is required
3578c2ecf20Sopenharmony_ci	 * to drop this because of the Michael MIC failure.
3588c2ecf20Sopenharmony_ci	 */
3598c2ecf20Sopenharmony_ci	skb_put_zero(skb, 50);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	ieee80211_tx_skb(sdata, skb);
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci	return buflen;
3668c2ecf20Sopenharmony_ci}
3678c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_W(tkip_mic_test);
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_parse_beacon_loss(
3708c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
3738c2ecf20Sopenharmony_ci		return -ENOTCONN;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	ieee80211_beacon_loss(&sdata->vif);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	return buflen;
3788c2ecf20Sopenharmony_ci}
3798c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_W(beacon_loss);
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_uapsd_queues(
3828c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
3838c2ecf20Sopenharmony_ci{
3848c2ecf20Sopenharmony_ci	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
3878c2ecf20Sopenharmony_ci}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_parse_uapsd_queues(
3908c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3938c2ecf20Sopenharmony_ci	u8 val;
3948c2ecf20Sopenharmony_ci	int ret;
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	ret = kstrtou8(buf, 0, &val);
3978c2ecf20Sopenharmony_ci	if (ret)
3988c2ecf20Sopenharmony_ci		return ret;
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4018c2ecf20Sopenharmony_ci		return -ERANGE;
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	ifmgd->uapsd_queues = val;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	return buflen;
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_RW(uapsd_queues);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
4108c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
4118c2ecf20Sopenharmony_ci{
4128c2ecf20Sopenharmony_ci	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
4158c2ecf20Sopenharmony_ci}
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_parse_uapsd_max_sp_len(
4188c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
4198c2ecf20Sopenharmony_ci{
4208c2ecf20Sopenharmony_ci	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4218c2ecf20Sopenharmony_ci	unsigned long val;
4228c2ecf20Sopenharmony_ci	int ret;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	ret = kstrtoul(buf, 0, &val);
4258c2ecf20Sopenharmony_ci	if (ret)
4268c2ecf20Sopenharmony_ci		return -EINVAL;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4298c2ecf20Sopenharmony_ci		return -ERANGE;
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci	ifmgd->uapsd_max_sp_len = val;
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci	return buflen;
4348c2ecf20Sopenharmony_ci}
4358c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_RW(uapsd_max_sp_len);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_tdls_wider_bw(
4388c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
4398c2ecf20Sopenharmony_ci{
4408c2ecf20Sopenharmony_ci	const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4418c2ecf20Sopenharmony_ci	bool tdls_wider_bw;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
4448c2ecf20Sopenharmony_ci			!ifmgd->tdls_wider_bw_prohibited;
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
4478c2ecf20Sopenharmony_ci}
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_parse_tdls_wider_bw(
4508c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
4518c2ecf20Sopenharmony_ci{
4528c2ecf20Sopenharmony_ci	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4538c2ecf20Sopenharmony_ci	u8 val;
4548c2ecf20Sopenharmony_ci	int ret;
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	ret = kstrtou8(buf, 0, &val);
4578c2ecf20Sopenharmony_ci	if (ret)
4588c2ecf20Sopenharmony_ci		return ret;
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	ifmgd->tdls_wider_bw_prohibited = !val;
4618c2ecf20Sopenharmony_ci	return buflen;
4628c2ecf20Sopenharmony_ci}
4638c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_RW(tdls_wider_bw);
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci/* AP attributes */
4668c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
4678c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
4688c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
4698c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_num_buffered_multicast(
4728c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
4738c2ecf20Sopenharmony_ci{
4748c2ecf20Sopenharmony_ci	return scnprintf(buf, buflen, "%u\n",
4758c2ecf20Sopenharmony_ci			 skb_queue_len(&sdata->u.ap.ps.bc_buf));
4768c2ecf20Sopenharmony_ci}
4778c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_R(num_buffered_multicast);
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_aqm(
4808c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
4818c2ecf20Sopenharmony_ci{
4828c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sdata->local;
4838c2ecf20Sopenharmony_ci	struct txq_info *txqi;
4848c2ecf20Sopenharmony_ci	int len;
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci	if (!sdata->vif.txq)
4878c2ecf20Sopenharmony_ci		return 0;
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	txqi = to_txq_info(sdata->vif.txq);
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	spin_lock_bh(&local->fq.lock);
4928c2ecf20Sopenharmony_ci	rcu_read_lock();
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	len = scnprintf(buf,
4958c2ecf20Sopenharmony_ci			buflen,
4968c2ecf20Sopenharmony_ci			"ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
4978c2ecf20Sopenharmony_ci			"%u %u %u %u %u %u %u %u %u %u\n",
4988c2ecf20Sopenharmony_ci			txqi->txq.ac,
4998c2ecf20Sopenharmony_ci			txqi->tin.backlog_bytes,
5008c2ecf20Sopenharmony_ci			txqi->tin.backlog_packets,
5018c2ecf20Sopenharmony_ci			txqi->tin.flows,
5028c2ecf20Sopenharmony_ci			txqi->cstats.drop_count,
5038c2ecf20Sopenharmony_ci			txqi->cstats.ecn_mark,
5048c2ecf20Sopenharmony_ci			txqi->tin.overlimit,
5058c2ecf20Sopenharmony_ci			txqi->tin.collisions,
5068c2ecf20Sopenharmony_ci			txqi->tin.tx_bytes,
5078c2ecf20Sopenharmony_ci			txqi->tin.tx_packets);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	rcu_read_unlock();
5108c2ecf20Sopenharmony_ci	spin_unlock_bh(&local->fq.lock);
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	return len;
5138c2ecf20Sopenharmony_ci}
5148c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_R(aqm);
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci/* IBSS attributes */
5198c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_fmt_tsf(
5208c2ecf20Sopenharmony_ci	const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
5218c2ecf20Sopenharmony_ci{
5228c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sdata->local;
5238c2ecf20Sopenharmony_ci	u64 tsf;
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci	tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
5288c2ecf20Sopenharmony_ci}
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_cistatic ssize_t ieee80211_if_parse_tsf(
5318c2ecf20Sopenharmony_ci	struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
5328c2ecf20Sopenharmony_ci{
5338c2ecf20Sopenharmony_ci	struct ieee80211_local *local = sdata->local;
5348c2ecf20Sopenharmony_ci	unsigned long long tsf;
5358c2ecf20Sopenharmony_ci	int ret;
5368c2ecf20Sopenharmony_ci	int tsf_is_delta = 0;
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_ci	if (strncmp(buf, "reset", 5) == 0) {
5398c2ecf20Sopenharmony_ci		if (local->ops->reset_tsf) {
5408c2ecf20Sopenharmony_ci			drv_reset_tsf(local, sdata);
5418c2ecf20Sopenharmony_ci			wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
5428c2ecf20Sopenharmony_ci		}
5438c2ecf20Sopenharmony_ci	} else {
5448c2ecf20Sopenharmony_ci		if (buflen > 10 && buf[1] == '=') {
5458c2ecf20Sopenharmony_ci			if (buf[0] == '+')
5468c2ecf20Sopenharmony_ci				tsf_is_delta = 1;
5478c2ecf20Sopenharmony_ci			else if (buf[0] == '-')
5488c2ecf20Sopenharmony_ci				tsf_is_delta = -1;
5498c2ecf20Sopenharmony_ci			else
5508c2ecf20Sopenharmony_ci				return -EINVAL;
5518c2ecf20Sopenharmony_ci			buf += 2;
5528c2ecf20Sopenharmony_ci		}
5538c2ecf20Sopenharmony_ci		ret = kstrtoull(buf, 10, &tsf);
5548c2ecf20Sopenharmony_ci		if (ret < 0)
5558c2ecf20Sopenharmony_ci			return ret;
5568c2ecf20Sopenharmony_ci		if (tsf_is_delta && local->ops->offset_tsf) {
5578c2ecf20Sopenharmony_ci			drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
5588c2ecf20Sopenharmony_ci			wiphy_info(local->hw.wiphy,
5598c2ecf20Sopenharmony_ci				   "debugfs offset TSF by %018lld\n",
5608c2ecf20Sopenharmony_ci				   tsf_is_delta * tsf);
5618c2ecf20Sopenharmony_ci		} else if (local->ops->set_tsf) {
5628c2ecf20Sopenharmony_ci			if (tsf_is_delta)
5638c2ecf20Sopenharmony_ci				tsf = drv_get_tsf(local, sdata) +
5648c2ecf20Sopenharmony_ci				      tsf_is_delta * tsf;
5658c2ecf20Sopenharmony_ci			drv_set_tsf(local, sdata, tsf);
5668c2ecf20Sopenharmony_ci			wiphy_info(local->hw.wiphy,
5678c2ecf20Sopenharmony_ci				   "debugfs set TSF to %#018llx\n", tsf);
5688c2ecf20Sopenharmony_ci		}
5698c2ecf20Sopenharmony_ci	}
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci	ieee80211_recalc_dtim(local, sdata);
5728c2ecf20Sopenharmony_ci	return buflen;
5738c2ecf20Sopenharmony_ci}
5748c2ecf20Sopenharmony_ciIEEE80211_IF_FILE_RW(tsf);
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci/* WDS attributes */
5788c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_MESH
5818c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci/* Mesh stats attributes */
5848c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
5858c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
5868c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
5878c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
5888c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dropped_frames_congestion,
5898c2ecf20Sopenharmony_ci		  u.mesh.mshstats.dropped_frames_congestion, DEC);
5908c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dropped_frames_no_route,
5918c2ecf20Sopenharmony_ci		  u.mesh.mshstats.dropped_frames_no_route, DEC);
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci/* Mesh parameters */
5948c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshMaxRetries,
5958c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
5968c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshRetryTimeout,
5978c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
5988c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshConfirmTimeout,
5998c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
6008c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHoldingTimeout,
6018c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
6028c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
6038c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
6048c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
6058c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
6068c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
6078c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
6088c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
6098c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
6108c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
6118c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
6128c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
6138c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
6148c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
6158c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
6168c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
6178c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(path_refresh_time,
6188c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.path_refresh_time, DEC);
6198c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(min_discovery_timeout,
6208c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.min_discovery_timeout, DEC);
6218c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPRootMode,
6228c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
6238c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
6248c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
6258c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
6268c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
6278c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
6288c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
6298c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
6308c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
6318c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
6328c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMProotInterval,
6338c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
6348c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
6358c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
6368c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
6378c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
6388c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
6398c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshConnectedToMeshGate,
6408c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshConnectedToMeshGate, DEC);
6418c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshNolearn, u.mesh.mshcfg.dot11MeshNolearn, DEC);
6428c2ecf20Sopenharmony_ciIEEE80211_IF_FILE(dot11MeshConnectedToAuthServer,
6438c2ecf20Sopenharmony_ci		  u.mesh.mshcfg.dot11MeshConnectedToAuthServer, DEC);
6448c2ecf20Sopenharmony_ci#endif
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci#define DEBUGFS_ADD_MODE(name, mode) \
6478c2ecf20Sopenharmony_ci	debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
6488c2ecf20Sopenharmony_ci			    sdata, &name##_ops);
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci#define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_cistatic void add_common_files(struct ieee80211_sub_if_data *sdata)
6538c2ecf20Sopenharmony_ci{
6548c2ecf20Sopenharmony_ci	DEBUGFS_ADD(rc_rateidx_mask_2ghz);
6558c2ecf20Sopenharmony_ci	DEBUGFS_ADD(rc_rateidx_mask_5ghz);
6568c2ecf20Sopenharmony_ci	DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
6578c2ecf20Sopenharmony_ci	DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
6588c2ecf20Sopenharmony_ci	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
6598c2ecf20Sopenharmony_ci	DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
6608c2ecf20Sopenharmony_ci	DEBUGFS_ADD(hw_queues);
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci	if (sdata->local->ops->wake_tx_queue &&
6638c2ecf20Sopenharmony_ci	    sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
6648c2ecf20Sopenharmony_ci	    sdata->vif.type != NL80211_IFTYPE_NAN)
6658c2ecf20Sopenharmony_ci		DEBUGFS_ADD(aqm);
6668c2ecf20Sopenharmony_ci}
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistatic void add_sta_files(struct ieee80211_sub_if_data *sdata)
6698c2ecf20Sopenharmony_ci{
6708c2ecf20Sopenharmony_ci	DEBUGFS_ADD(bssid);
6718c2ecf20Sopenharmony_ci	DEBUGFS_ADD(aid);
6728c2ecf20Sopenharmony_ci	DEBUGFS_ADD(beacon_timeout);
6738c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(smps, 0600);
6748c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
6758c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(beacon_loss, 0200);
6768c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(uapsd_queues, 0600);
6778c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
6788c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
6798c2ecf20Sopenharmony_ci}
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_cistatic void add_ap_files(struct ieee80211_sub_if_data *sdata)
6828c2ecf20Sopenharmony_ci{
6838c2ecf20Sopenharmony_ci	DEBUGFS_ADD(num_mcast_sta);
6848c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(smps, 0600);
6858c2ecf20Sopenharmony_ci	DEBUGFS_ADD(num_sta_ps);
6868c2ecf20Sopenharmony_ci	DEBUGFS_ADD(dtim_count);
6878c2ecf20Sopenharmony_ci	DEBUGFS_ADD(num_buffered_multicast);
6888c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
6898c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
6908c2ecf20Sopenharmony_ci}
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_cistatic void add_vlan_files(struct ieee80211_sub_if_data *sdata)
6938c2ecf20Sopenharmony_ci{
6948c2ecf20Sopenharmony_ci	/* add num_mcast_sta_vlan using name num_mcast_sta */
6958c2ecf20Sopenharmony_ci	debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
6968c2ecf20Sopenharmony_ci			    sdata, &num_mcast_sta_vlan_ops);
6978c2ecf20Sopenharmony_ci}
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_cistatic void add_ibss_files(struct ieee80211_sub_if_data *sdata)
7008c2ecf20Sopenharmony_ci{
7018c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(tsf, 0600);
7028c2ecf20Sopenharmony_ci}
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_cistatic void add_wds_files(struct ieee80211_sub_if_data *sdata)
7058c2ecf20Sopenharmony_ci{
7068c2ecf20Sopenharmony_ci	DEBUGFS_ADD(peer);
7078c2ecf20Sopenharmony_ci}
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_MESH
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_cistatic void add_mesh_files(struct ieee80211_sub_if_data *sdata)
7128c2ecf20Sopenharmony_ci{
7138c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(tsf, 0600);
7148c2ecf20Sopenharmony_ci	DEBUGFS_ADD_MODE(estab_plinks, 0400);
7158c2ecf20Sopenharmony_ci}
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_cistatic void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
7188c2ecf20Sopenharmony_ci{
7198c2ecf20Sopenharmony_ci	struct dentry *dir = debugfs_create_dir("mesh_stats",
7208c2ecf20Sopenharmony_ci						sdata->vif.debugfs_dir);
7218c2ecf20Sopenharmony_ci#define MESHSTATS_ADD(name)\
7228c2ecf20Sopenharmony_ci	debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci	MESHSTATS_ADD(fwded_mcast);
7258c2ecf20Sopenharmony_ci	MESHSTATS_ADD(fwded_unicast);
7268c2ecf20Sopenharmony_ci	MESHSTATS_ADD(fwded_frames);
7278c2ecf20Sopenharmony_ci	MESHSTATS_ADD(dropped_frames_ttl);
7288c2ecf20Sopenharmony_ci	MESHSTATS_ADD(dropped_frames_no_route);
7298c2ecf20Sopenharmony_ci	MESHSTATS_ADD(dropped_frames_congestion);
7308c2ecf20Sopenharmony_ci#undef MESHSTATS_ADD
7318c2ecf20Sopenharmony_ci}
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_cistatic void add_mesh_config(struct ieee80211_sub_if_data *sdata)
7348c2ecf20Sopenharmony_ci{
7358c2ecf20Sopenharmony_ci	struct dentry *dir = debugfs_create_dir("mesh_config",
7368c2ecf20Sopenharmony_ci						sdata->vif.debugfs_dir);
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci#define MESHPARAMS_ADD(name) \
7398c2ecf20Sopenharmony_ci	debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshMaxRetries);
7428c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshRetryTimeout);
7438c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshConfirmTimeout);
7448c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHoldingTimeout);
7458c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshTTL);
7468c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(element_ttl);
7478c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(auto_open_plinks);
7488c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
7498c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
7508c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
7518c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
7528c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
7538c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
7548c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(path_refresh_time);
7558c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(min_discovery_timeout);
7568c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPRootMode);
7578c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
7588c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshForwarding);
7598c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
7608c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(rssi_threshold);
7618c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(ht_opmode);
7628c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
7638c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMProotInterval);
7648c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
7658c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(power_mode);
7668c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
7678c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshConnectedToMeshGate);
7688c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshNolearn);
7698c2ecf20Sopenharmony_ci	MESHPARAMS_ADD(dot11MeshConnectedToAuthServer);
7708c2ecf20Sopenharmony_ci#undef MESHPARAMS_ADD
7718c2ecf20Sopenharmony_ci}
7728c2ecf20Sopenharmony_ci#endif
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_cistatic void add_files(struct ieee80211_sub_if_data *sdata)
7758c2ecf20Sopenharmony_ci{
7768c2ecf20Sopenharmony_ci	if (!sdata->vif.debugfs_dir)
7778c2ecf20Sopenharmony_ci		return;
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_ci	DEBUGFS_ADD(flags);
7808c2ecf20Sopenharmony_ci	DEBUGFS_ADD(state);
7818c2ecf20Sopenharmony_ci	DEBUGFS_ADD(txpower);
7828c2ecf20Sopenharmony_ci	DEBUGFS_ADD(user_power_level);
7838c2ecf20Sopenharmony_ci	DEBUGFS_ADD(ap_power_level);
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
7868c2ecf20Sopenharmony_ci		add_common_files(sdata);
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_ci	switch (sdata->vif.type) {
7898c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_MESH_POINT:
7908c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_MESH
7918c2ecf20Sopenharmony_ci		add_mesh_files(sdata);
7928c2ecf20Sopenharmony_ci		add_mesh_stats(sdata);
7938c2ecf20Sopenharmony_ci		add_mesh_config(sdata);
7948c2ecf20Sopenharmony_ci#endif
7958c2ecf20Sopenharmony_ci		break;
7968c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
7978c2ecf20Sopenharmony_ci		add_sta_files(sdata);
7988c2ecf20Sopenharmony_ci		break;
7998c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
8008c2ecf20Sopenharmony_ci		add_ibss_files(sdata);
8018c2ecf20Sopenharmony_ci		break;
8028c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
8038c2ecf20Sopenharmony_ci		add_ap_files(sdata);
8048c2ecf20Sopenharmony_ci		break;
8058c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP_VLAN:
8068c2ecf20Sopenharmony_ci		add_vlan_files(sdata);
8078c2ecf20Sopenharmony_ci		break;
8088c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_WDS:
8098c2ecf20Sopenharmony_ci		add_wds_files(sdata);
8108c2ecf20Sopenharmony_ci		break;
8118c2ecf20Sopenharmony_ci	default:
8128c2ecf20Sopenharmony_ci		break;
8138c2ecf20Sopenharmony_ci	}
8148c2ecf20Sopenharmony_ci}
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_civoid ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
8178c2ecf20Sopenharmony_ci{
8188c2ecf20Sopenharmony_ci	char buf[10+IFNAMSIZ];
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci	sprintf(buf, "netdev:%s", sdata->name);
8218c2ecf20Sopenharmony_ci	sdata->vif.debugfs_dir = debugfs_create_dir(buf,
8228c2ecf20Sopenharmony_ci		sdata->local->hw.wiphy->debugfsdir);
8238c2ecf20Sopenharmony_ci	sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
8248c2ecf20Sopenharmony_ci							sdata->vif.debugfs_dir);
8258c2ecf20Sopenharmony_ci	add_files(sdata);
8268c2ecf20Sopenharmony_ci}
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_civoid ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
8298c2ecf20Sopenharmony_ci{
8308c2ecf20Sopenharmony_ci	if (!sdata->vif.debugfs_dir)
8318c2ecf20Sopenharmony_ci		return;
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ci	debugfs_remove_recursive(sdata->vif.debugfs_dir);
8348c2ecf20Sopenharmony_ci	sdata->vif.debugfs_dir = NULL;
8358c2ecf20Sopenharmony_ci	sdata->debugfs.subdir_stations = NULL;
8368c2ecf20Sopenharmony_ci}
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_civoid ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
8398c2ecf20Sopenharmony_ci{
8408c2ecf20Sopenharmony_ci	struct dentry *dir;
8418c2ecf20Sopenharmony_ci	char buf[10 + IFNAMSIZ];
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	dir = sdata->vif.debugfs_dir;
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci	if (IS_ERR_OR_NULL(dir))
8468c2ecf20Sopenharmony_ci		return;
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci	sprintf(buf, "netdev:%s", sdata->name);
8498c2ecf20Sopenharmony_ci	debugfs_rename(dir->d_parent, dir, dir->d_parent, buf);
8508c2ecf20Sopenharmony_ci}
851