diff --git a/Kbuild b/Kbuild index 4a8179981f..64211e615a 100644 --- a/Kbuild +++ b/Kbuild @@ -291,6 +291,9 @@ endif ifeq ($(CONFIG_WLAN_SET_SCAN_CFG), y) HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_set_scan_cfg.o endif +ifeq ($(CONFIG_WLAN_SET_MON_CHAN), y) +HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_set_mon_chan.o +endif endif ifeq ($(CONFIG_QCACLD_FEATURE_FW_STATE), y) @@ -2523,6 +2526,7 @@ cppflags-$(CONFIG_WLAN_SCAN_DISABLE) += -DCONFIG_WLAN_SCAN_DISABLE cppflags-$(CONFIG_WLAN_WOW_ITO) += -DCONFIG_WLAN_WOW_ITO cppflags-$(CONFIG_WLAN_WOWL_ADD_PTRN) += -DCONFIG_WLAN_WOWL_ADD_PTRN cppflags-$(CONFIG_WLAN_SET_SCAN_CFG) += -DCONFIG_WLAN_SET_SCAN_CFG +cppflags-$(CONFIG_WLAN_SET_MON_CHAN) += -DCONFIG_WLAN_SET_MON_CHAN cppflags-$(CONFIG_FEATURE_UNIT_TEST_SUSPEND) += -DWLAN_SUSPEND_RESUME_TEST cppflags-$(CONFIG_FEATURE_WLM_STATS) += -DFEATURE_WLM_STATS diff --git a/configs/default_defconfig b/configs/default_defconfig index 15c9feff62..21e566b12b 100644 --- a/configs/default_defconfig +++ b/configs/default_defconfig @@ -183,6 +183,7 @@ ifeq ($(CONFIG_WLAN_SYSFS), y) CONFIG_WLAN_WOW_ITO := y CONFIG_WLAN_WOWL_ADD_PTRN := y CONFIG_WLAN_SET_SCAN_CFG := y + CONFIG_WLAN_SET_MON_CHAN := y endif CONFIG_WLAN_POWER_DEBUG := y diff --git a/core/hdd/src/wlan_hdd_sysfs.c b/core/hdd/src/wlan_hdd_sysfs.c index d6ce6aaf27..9f95f2af64 100644 --- a/core/hdd/src/wlan_hdd_sysfs.c +++ b/core/hdd/src/wlan_hdd_sysfs.c @@ -49,6 +49,7 @@ #include #include #include +#include #define MAX_PSOC_ID_SIZE 10 @@ -668,6 +669,18 @@ hdd_sysfs_destroy_sap_adapter_root_obj(struct hdd_adapter *adapter) hdd_sysfs_get_sta_info_interface_destroy(adapter); } +static void +hdd_sysfs_create_monitor_adapter_root_obj(struct hdd_adapter *adapter) +{ + hdd_sysfs_set_mon_chan_create(adapter); +} + +static void +hdd_sysfs_destroy_monitor_adapter_root_obj(struct hdd_adapter *adapter) +{ + hdd_sysfs_set_mon_chan_destroy(adapter); +} + void hdd_create_sysfs_files(struct hdd_context *hdd_ctx) { hdd_sysfs_create_driver_root_obj(); @@ -706,6 +719,9 @@ void hdd_create_adapter_sysfs_files(struct hdd_adapter *adapter) case QDF_SAP_MODE: hdd_sysfs_create_sap_adapter_root_obj(adapter); break; + case QDF_MONITOR_MODE: + hdd_sysfs_create_monitor_adapter_root_obj(adapter); + break; default: break; } @@ -722,6 +738,9 @@ void hdd_destroy_adapter_sysfs_files(struct hdd_adapter *adapter) case QDF_SAP_MODE: hdd_sysfs_destroy_sap_adapter_root_obj(adapter); break; + case QDF_MONITOR_MODE: + hdd_sysfs_destroy_monitor_adapter_root_obj(adapter); + break; default: break; } diff --git a/core/hdd/src/wlan_hdd_sysfs_set_mon_chan.c b/core/hdd/src/wlan_hdd_sysfs_set_mon_chan.c new file mode 100644 index 0000000000..fbf33b180b --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_set_mon_chan.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2011-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_set_mon_chan.c + * + * implementation for creating sysfs file set_mon_chan + */ + +#include +#include "osif_vdev_sync.h" +#include +#include + +static ssize_t +__hdd_sysfs_set_mon_chan_store(struct net_device *net_dev, + char const *buf, size_t count) +{ + struct hdd_adapter *adapter = netdev_priv(net_dev); + char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1]; + struct hdd_context *hdd_ctx; + char *sptr, *token; + uint32_t val1, val2; + int ret; + + if (hdd_validate_adapter(adapter)) { + hdd_err_rl("adapter validate fail"); + return -EINVAL; + } + + hdd_ctx = WLAN_HDD_GET_CTX(adapter); + ret = wlan_hdd_validate_context(hdd_ctx); + if (ret != 0) + return ret; + + if (!wlan_hdd_validate_modules_state(hdd_ctx)) + return -EINVAL; + + ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local), + buf, count); + + if (ret) { + hdd_err_rl("invalid input"); + return ret; + } + + sptr = buf_local; + hdd_debug("set_mon_chan: count %zu buf_local:(%s) net_devname %s", + count, buf_local, net_dev->name); + + /* Get val1 */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou32(token, 0, &val1)) + return -EINVAL; + + /* Get val2 */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou32(token, 0, &val2)) + return -EINVAL; + + if (val1 > 256) + ret = wlan_hdd_set_mon_chan(adapter, val1, val2); + else + ret = wlan_hdd_set_mon_chan(adapter, + wlan_reg_legacy_chan_to_freq( + hdd_ctx->pdev, val1), + val2); + + return count; +} + +static ssize_t +hdd_sysfs_set_mon_chan_store(struct device *dev, + struct device_attribute *attr, + char const *buf, size_t count) +{ + struct net_device *net_dev = container_of(dev, struct net_device, dev); + struct osif_vdev_sync *vdev_sync; + ssize_t errno_size; + + errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync); + if (errno_size) + return errno_size; + + errno_size = __hdd_sysfs_set_mon_chan_store(net_dev, buf, count); + + osif_vdev_sync_op_stop(vdev_sync); + + return errno_size; +} + +static DEVICE_ATTR(set_mon_chan, 0220, + NULL, hdd_sysfs_set_mon_chan_store); + +int hdd_sysfs_set_mon_chan_create(struct hdd_adapter *adapter) +{ + int error; + + error = device_create_file(&adapter->dev->dev, &dev_attr_set_mon_chan); + if (error) + hdd_err("could not create set_mon_chan sysfs file"); + + return error; +} + +void hdd_sysfs_set_mon_chan_destroy(struct hdd_adapter *adapter) +{ + device_remove_file(&adapter->dev->dev, &dev_attr_set_mon_chan); +} diff --git a/core/hdd/src/wlan_hdd_sysfs_set_mon_chan.h b/core/hdd/src/wlan_hdd_sysfs_set_mon_chan.h new file mode 100644 index 0000000000..3a3dca60f4 --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_set_mon_chan.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2011-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_set_mon_chan.h + * + * implementation for creating sysfs file set_mon_chan + */ + +#ifndef _WLAN_HDD_SYSFS_SET_MON_CHAN_H +#define _WLAN_HDD_SYSFS_SET_MON_CHAN_H + +#if defined(WLAN_SYSFS) && defined(CONFIG_WLAN_SET_MON_CHAN) +/** + * wlan_hdd_sysfs_set_mon_chan_create() - API to create set_mon_chan + * @adapter: hdd adapter + * + * this file is created per adapter. + * file path: /sys/class/net/wlanxx/set_mon_chan + * (wlanxx is adapter name) + * usage: + * echo [arg_0] [arg_1] > set_mon_chan + * + * Return: 0 on success and errno on failure + */ +int hdd_sysfs_set_mon_chan_create(struct hdd_adapter *adapter); + +/** + * hdd_sysfs_set_mon_chan_destroy() - + * API to destroy set_mon_chan + * @adapter: pointer to adapter + * + * Return: none + */ +void hdd_sysfs_set_mon_chan_destroy(struct hdd_adapter *adapter); +#else +static inline int +hdd_sysfs_set_mon_chan_create(struct hdd_adapter *adapter) +{ + return 0; +} + +static inline void +hdd_sysfs_set_mon_chan_destroy(struct hdd_adapter *adapter) +{ +} +#endif +#endif /* #ifndef _WLAN_HDD_SYSFS_SET_MON_CHAN_H */