From ba6b3520d32c7675348717b626788bad7c755a5d Mon Sep 17 00:00:00 2001 From: Bapiraju Alla Date: Fri, 8 May 2020 23:44:33 +0530 Subject: [PATCH] qcacld-3.0: Add a sysfs replacement for get_sta_info As part of WEXT replacement, replace get_sta_info with a sysfs file. This feature can be controlled using configuration flag CONFIG_WLAN_SYSFS_GET_STA_INFO file path: /sys/class/net/wlanxx/get_sta_info where wlanxx is adapter name example command: cat /sys/class/net/wlanxx/get_tdls_peers Change-Id: Iac23cdc92a860279480ec9703697f22b2f0b5223 CRs-Fixed: 2682163 --- Kbuild | 5 + configs/default_defconfig | 1 + core/hdd/inc/wlan_hdd_sysfs_get_sta_info.h | 62 ++++++++++++ core/hdd/src/wlan_hdd_sysfs.c | 5 + core/hdd/src/wlan_hdd_sysfs_get_sta_info.c | 109 +++++++++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 core/hdd/inc/wlan_hdd_sysfs_get_sta_info.h create mode 100644 core/hdd/src/wlan_hdd_sysfs_get_sta_info.c diff --git a/Kbuild b/Kbuild index d4f237a60e..165846f682 100644 --- a/Kbuild +++ b/Kbuild @@ -265,6 +265,9 @@ endif ifeq ($(CONFIG_WLAN_REASSOC), y) HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_reassoc.o endif +ifeq ($(CONFIG_WLAN_SYSFS_GET_STA_INFO), y) +HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_get_sta_info.o +endif ifeq ($(CONFIG_WLAN_DEBUG_CRASH_INJECT), y) HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_crash_inject.o endif @@ -2519,6 +2522,8 @@ cppflags-$(CONFIG_WLAN_WOWL_ADD_PTRN) += -DCONFIG_WLAN_WOWL_ADD_PTRN cppflags-$(CONFIG_FEATURE_UNIT_TEST_SUSPEND) += -DWLAN_SUSPEND_RESUME_TEST cppflags-$(CONFIG_FEATURE_WLM_STATS) += -DFEATURE_WLM_STATS +cppflags-$(CONFIG_WLAN_SYSFS_GET_STA_INFO) += -DWLAN_SYSFS_GET_STA_INFO + ifeq ($(CONFIG_LEAK_DETECTION), y) cppflags-y += \ -DCONFIG_HALT_KMEMLEAK \ diff --git a/configs/default_defconfig b/configs/default_defconfig index dc5a684f04..3852a34514 100644 --- a/configs/default_defconfig +++ b/configs/default_defconfig @@ -175,6 +175,7 @@ CONFIG_QCOM_TDLS := y CONFIG_WLAN_SYSFS := y ifeq ($(CONFIG_WLAN_SYSFS), y) + CONFIG_WLAN_SYSFS_GET_STA_INFO := y CONFIG_WLAN_SET_FW_MODE_CFG := y CONFIG_WLAN_REASSOC := y CONFIG_WLAN_SYSFS_CONNECT_INFO := y diff --git a/core/hdd/inc/wlan_hdd_sysfs_get_sta_info.h b/core/hdd/inc/wlan_hdd_sysfs_get_sta_info.h new file mode 100644 index 0000000000..98de7e0d96 --- /dev/null +++ b/core/hdd/inc/wlan_hdd_sysfs_get_sta_info.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/** + * DOC: wlan_hdd_sysfs_get_sta_info.h + * + * implementation for creating sysfs file get_sta_info + */ + +#ifndef _WLAN_HDD_SYSFS_GET_STA_INFO_H +#define _WLAN_HDD_SYSFS_GET_STA_INFO_H + +#if defined(WLAN_SYSFS) && defined(WLAN_SYSFS_GET_STA_INFO) +/** + * hdd_sysfs_get_sta_info_interface_create() - API to create get_sta_info sysfs + * interface + * @adapter: pointer to adapter + * + * this file is created for SAP adapter. + * file path: /sys/class/net/wlanxx/get_sta_info + * where wlanxx is adapter name + * + * usage: + * cat /sys/class/net/wlanxx/get_sta_info + * + * Return: none + */ +void hdd_sysfs_get_sta_info_interface_create(struct hdd_adapter *adapter); + +/** + * hdd_sysfs_get_sta_info_interface_destroy() - API to destroy get_sta_info + * @adapter: pointer to adapter + * + * Return: none + */ +void hdd_sysfs_get_sta_info_interface_destroy(struct hdd_adapter *adapter); + +#else +static inline +void hdd_sysfs_get_sta_info_interface_create(struct hdd_adapter *adapter) +{ +} + +static inline +void hdd_sysfs_get_sta_info_interface_destroy(struct hdd_adapter *adapter) +{ +} +#endif +#endif /* #ifndef _WLAN_HDD_SYSFS_GET_STA_INFO_H */ diff --git a/core/hdd/src/wlan_hdd_sysfs.c b/core/hdd/src/wlan_hdd_sysfs.c index 6f4877ad79..e0ca26a84a 100644 --- a/core/hdd/src/wlan_hdd_sysfs.c +++ b/core/hdd/src/wlan_hdd_sysfs.c @@ -37,6 +37,7 @@ #include #endif #include "osif_sync.h" +#include "wlan_hdd_sysfs_get_sta_info.h" #include #include #include "wlan_hdd_sysfs_crash_inject.h" @@ -617,6 +618,7 @@ static void hdd_sysfs_destroy_bcn_reception_interface(struct hdd_adapter static void hdd_sysfs_create_sta_adapter_root_obj(struct hdd_adapter *adapter) { + hdd_sysfs_get_sta_info_interface_create(adapter); hdd_sysfs_create_bcn_reception_interface(adapter); hdd_sysfs_reassoc_create(adapter); hdd_sysfs_crash_inject_create(adapter); @@ -638,11 +640,13 @@ hdd_sysfs_destroy_sta_adapter_root_obj(struct hdd_adapter *adapter) hdd_sysfs_crash_inject_destroy(adapter); hdd_sysfs_reassoc_destroy(adapter); hdd_sysfs_destroy_bcn_reception_interface(adapter); + hdd_sysfs_get_sta_info_interface_destroy(adapter); } static void hdd_sysfs_create_sap_adapter_root_obj(struct hdd_adapter *adapter) { + hdd_sysfs_get_sta_info_interface_create(adapter); hdd_sysfs_crash_inject_create(adapter); hdd_sysfs_suspend_create(adapter); hdd_sysfs_resume_create(adapter); @@ -660,6 +664,7 @@ hdd_sysfs_destroy_sap_adapter_root_obj(struct hdd_adapter *adapter) hdd_sysfs_resume_destroy(adapter); hdd_sysfs_suspend_destroy(adapter); hdd_sysfs_crash_inject_destroy(adapter); + hdd_sysfs_get_sta_info_interface_destroy(adapter); } void hdd_create_sysfs_files(struct hdd_context *hdd_ctx) diff --git a/core/hdd/src/wlan_hdd_sysfs_get_sta_info.c b/core/hdd/src/wlan_hdd_sysfs_get_sta_info.c new file mode 100644 index 0000000000..6e67e3f9b3 --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_get_sta_info.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/** + * DOC: wlan_hdd_sysfs_get_sta_info.c + * + * implementation for creating sysfs file get_sta_info + */ + +#include +#include "osif_vdev_sync.h" +#include "wlan_hdd_sysfs_get_sta_info.h" + +static ssize_t __show_sta_info(struct net_device *net_dev, char *buf) +{ + struct hdd_adapter *adapter = netdev_priv(net_dev); + struct hdd_context *hdd_ctx; + struct hdd_station_info *sta; + int ret_val; + + hdd_enter_dev(net_dev); + + ret_val = hdd_validate_adapter(adapter); + if (0 != ret_val) + goto exit; + + if (adapter->device_mode != QDF_SAP_MODE) + goto exit; + + hdd_ctx = WLAN_HDD_GET_CTX(adapter); + ret_val = wlan_hdd_validate_context(hdd_ctx); + if (0 != ret_val) + goto exit; + + ret_val = scnprintf(buf, PAGE_SIZE, + "%s get_sta_info:\nstaAddress\n", + net_dev->name); + + hdd_for_each_sta_ref(adapter->sta_info_list, sta) { + if (QDF_IS_ADDR_BROADCAST(sta->sta_mac.bytes)) { + hdd_put_sta_info_ref(&adapter->sta_info_list, &sta, + true); + continue; + } + ret_val += scnprintf(buf + ret_val, PAGE_SIZE - ret_val, + QDF_MAC_ADDR_STR " ecsa=%d\n", + sta->sta_mac.bytes[0], + sta->sta_mac.bytes[1], + sta->sta_mac.bytes[2], + sta->sta_mac.bytes[3], + sta->sta_mac.bytes[4], + sta->sta_mac.bytes[5], + sta->ecsa_capable); + + hdd_put_sta_info_ref(&adapter->sta_info_list, &sta, true); + } + +exit: + hdd_exit(); + return ret_val; +} + +static ssize_t show_sta_info(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct net_device *net_dev = container_of(dev, struct net_device, dev); + struct osif_vdev_sync *vdev_sync; + ssize_t err_size; + + err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync); + if (err_size) + return err_size; + + err_size = __show_sta_info(net_dev, buf); + + osif_vdev_sync_op_stop(vdev_sync); + + return err_size; +} + +static DEVICE_ATTR(get_sta_info, 0444, show_sta_info, NULL); + +void hdd_sysfs_get_sta_info_interface_create(struct hdd_adapter *adapter) +{ + int error; + + error = device_create_file(&adapter->dev->dev, &dev_attr_get_sta_info); + if (error) + hdd_err("Could not create get_sta_info sysfs file"); +} + +void hdd_sysfs_get_sta_info_interface_destroy(struct hdd_adapter *adapter) +{ + device_remove_file(&adapter->dev->dev, &dev_attr_get_sta_info); +}