From fa85d03310f322143a1d2d8e93b9cb2c8fbd388e Mon Sep 17 00:00:00 2001 From: Jingxiang Ge Date: Mon, 11 May 2020 15:03:28 +0800 Subject: [PATCH] qcacld-3.0: Add a sysfs replacement for modify_acl As part of WEXT replacement, replace modify_acl with a sysfs file. file path: /sys/class/net/wlanxx/modify_acl example: echo 0x00 0x11 0x22 0x33 0x44 0x55 0 0 > modify_acl Change-Id: I2022a50be84fa21a437aed9ecfdbe4d4bba613df CRs-Fixed: 2682881 --- Kbuild | 1 + core/hdd/src/wlan_hdd_sysfs.c | 3 + core/hdd/src/wlan_hdd_sysfs_modify_acl.c | 148 +++++++++++++++++++++++ core/hdd/src/wlan_hdd_sysfs_modify_acl.h | 61 ++++++++++ 4 files changed, 213 insertions(+) create mode 100644 core/hdd/src/wlan_hdd_sysfs_modify_acl.c create mode 100644 core/hdd/src/wlan_hdd_sysfs_modify_acl.h diff --git a/Kbuild b/Kbuild index 66837efab750..6c8cf9ad4efd 100644 --- a/Kbuild +++ b/Kbuild @@ -273,6 +273,7 @@ ifeq ($(CONFIG_FEATURE_UNIT_TEST_SUSPEND), y) HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_suspend_resume.o endif HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_unit_test.o +HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_modify_acl.o endif ifeq ($(CONFIG_QCACLD_FEATURE_FW_STATE), y) diff --git a/core/hdd/src/wlan_hdd_sysfs.c b/core/hdd/src/wlan_hdd_sysfs.c index d8640243db55..9e023457fbad 100644 --- a/core/hdd/src/wlan_hdd_sysfs.c +++ b/core/hdd/src/wlan_hdd_sysfs.c @@ -42,6 +42,7 @@ #include "wlan_hdd_sysfs_crash_inject.h" #include "wlan_hdd_sysfs_suspend_resume.h" #include "wlan_hdd_sysfs_unit_test.h" +#include "wlan_hdd_sysfs_modify_acl.h" #define MAX_PSOC_ID_SIZE 10 @@ -638,11 +639,13 @@ hdd_sysfs_create_sap_adapter_root_obj(struct hdd_adapter *adapter) hdd_sysfs_suspend_create(adapter); hdd_sysfs_resume_create(adapter); hdd_sysfs_unit_test_target_create(adapter); + hdd_sysfs_modify_acl_create(adapter); } static void hdd_sysfs_destroy_sap_adapter_root_obj(struct hdd_adapter *adapter) { + hdd_sysfs_modify_acl_destroy(adapter); hdd_sysfs_unit_test_target_destroy(adapter); hdd_sysfs_resume_destroy(adapter); hdd_sysfs_suspend_destroy(adapter); diff --git a/core/hdd/src/wlan_hdd_sysfs_modify_acl.c b/core/hdd/src/wlan_hdd_sysfs_modify_acl.c new file mode 100644 index 000000000000..4fac3130a173 --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_modify_acl.c @@ -0,0 +1,148 @@ +/* + * 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_modify_acl.c + * + * implementation for creating sysfs file modify_acl + */ + +#include +#include "osif_vdev_sync.h" +#include "wlan_hdd_sysfs.h" +#include "wlan_hdd_sysfs_modify_acl.h" + +#define MAX_USER_COMMAND_SIZE_MODIFY_ACL 64 + +static ssize_t __hdd_sysfs_modify_acl_store( + struct net_device *net_dev, + const char *buf, size_t count) +{ + struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(net_dev); + struct hdd_context *hdd_ctx; + char buf_local[MAX_USER_COMMAND_SIZE_MODIFY_ACL + 1]; + char *sptr, *token; + uint8_t peer_mac[QDF_MAC_ADDR_SIZE]; + eSapACLType list_type; + eSapACLCmdType cmd_type; + int ret, i; + QDF_STATUS qdf_status; + + 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; + + if (adapter->device_mode != QDF_SAP_MODE) { + hdd_err_rl("Command only allowed in sap mode"); + 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; + } + + hdd_debug("modify_acl: count %zu buf_local:(%s) net_devname %s", + count, buf_local, net_dev->name); + + sptr = buf_local; + for (i = 0; i < QDF_MAC_ADDR_SIZE; i++) { + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou8(token, 0, &peer_mac[i])) + return -EINVAL; + } + + /* Get list_type */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou32(token, 0, &list_type)) + return -EINVAL; + + /* Get cmd_type */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou32(token, 0, &cmd_type)) + return -EINVAL; + + hdd_debug("Modify ACL mac:" QDF_MAC_ADDR_STR " type: %d cmd: %d", + QDF_MAC_ADDR_ARRAY(peer_mac), list_type, cmd_type); + + qdf_status = wlansap_modify_acl( + WLAN_HDD_GET_SAP_CTX_PTR(adapter), + peer_mac, list_type, cmd_type); + if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { + hdd_err("Modify ACL failed"); + return -EIO; + } + + return count; +} + +static ssize_t hdd_sysfs_modify_acl_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_modify_acl_store( + net_dev, buf, count); + if (errno_size < 0) + hdd_err_rl("errno_size %zd", errno_size); + + osif_vdev_sync_op_stop(vdev_sync); + + return errno_size; +} + +static DEVICE_ATTR(modify_acl, 0220, + NULL, hdd_sysfs_modify_acl_store); + +int hdd_sysfs_modify_acl_create(struct hdd_adapter *adapter) +{ + int error; + + error = device_create_file(&adapter->dev->dev, &dev_attr_modify_acl); + if (error) + hdd_err("could not create modify_acl sysfs file"); + + return error; +} + +void hdd_sysfs_modify_acl_destroy(struct hdd_adapter *adapter) +{ + device_remove_file(&adapter->dev->dev, &dev_attr_modify_acl); +} diff --git a/core/hdd/src/wlan_hdd_sysfs_modify_acl.h b/core/hdd/src/wlan_hdd_sysfs_modify_acl.h new file mode 100644 index 000000000000..1247a29dd76c --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_modify_acl.h @@ -0,0 +1,61 @@ +/* + * 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_modify_acl.h + * + * implementation for creating sysfs file modify_acl + */ + +#ifndef _WLAN_HDD_SYSFS_MODIFY_ACL_H +#define _WLAN_HDD_SYSFS_MODIFY_ACL_H + +#if defined(WLAN_SYSFS) +/** + * hdd_sysfs_modify_acl_create() - API to create modify_acl + * @adapter: hdd adapter + * + * this file is created for sap adapter. + * file path: /sys/class/net/wlan_xx/modify_acl + * (wlan_xx is adapter name) + * usage: + * echo <6 octet mac addr> > modify_acl + * eg: echo 0x00 0x11 0x22 0x33 0x44 0x55 0 0 >modify_acls + * Return: 0 on success and errno on failure + */ +int hdd_sysfs_modify_acl_create(struct hdd_adapter *adapter); + +/** + * hdd_sysfs_modify_acl_destroy() - + * API to destroy modify_acl sys file + * @adapter: pointer to adapter + * + * Return: none + */ +void hdd_sysfs_modify_acl_destroy(struct hdd_adapter *adapter); +#else +static inline int +hdd_sysfs_modify_acl_create(struct hdd_adapter *adapter) +{ + return 0; +} + +static inline void +hdd_sysfs_modify_acl_destroy(struct hdd_adapter *adapter) +{ +} +#endif +#endif /* #ifndef _WLAN_HDD_SYSFS_MODIFY_ACL_H */