xref: /wlan-driver/qcacld-3.0/core/hdd/src/wlan_hdd_sysfs_modify_acl.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: wlan_hdd_sysfs_modify_acl.c
20  *
21  * implementation for creating sysfs file modify_acl
22  */
23 
24 #include <wlan_hdd_includes.h>
25 #include "osif_vdev_sync.h"
26 #include "wlan_hdd_sysfs.h"
27 #include "wlan_hdd_sysfs_modify_acl.h"
28 
29 #define MAX_USER_COMMAND_SIZE_MODIFY_ACL 64
30 
__hdd_sysfs_modify_acl_store(struct net_device * net_dev,const char * buf,size_t count)31 static ssize_t __hdd_sysfs_modify_acl_store(
32 		struct net_device *net_dev,
33 		const char *buf, size_t count)
34 {
35 	struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(net_dev);
36 	struct hdd_context *hdd_ctx;
37 	char buf_local[MAX_USER_COMMAND_SIZE_MODIFY_ACL + 1];
38 	char *sptr, *token;
39 	uint8_t peer_mac[QDF_MAC_ADDR_SIZE];
40 	eSapACLType list_type;
41 	eSapACLCmdType cmd_type;
42 	int ret, i;
43 	QDF_STATUS qdf_status;
44 
45 	if (hdd_validate_adapter(adapter))
46 		return -EINVAL;
47 
48 	hdd_ctx = WLAN_HDD_GET_CTX(adapter);
49 	ret = wlan_hdd_validate_context(hdd_ctx);
50 	if (ret != 0)
51 		return ret;
52 
53 	if (!wlan_hdd_validate_modules_state(hdd_ctx))
54 		return -EINVAL;
55 
56 	if (adapter->device_mode != QDF_SAP_MODE) {
57 		hdd_err_rl("Command only allowed in sap mode");
58 		return -EINVAL;
59 	}
60 
61 	ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
62 					      buf, count);
63 	if (ret) {
64 		hdd_err_rl("invalid input");
65 		return ret;
66 	}
67 
68 	hdd_debug("modify_acl: count %zu buf_local:(%s) net_devname %s",
69 		  count, buf_local, net_dev->name);
70 
71 	sptr = buf_local;
72 	for (i = 0; i < QDF_MAC_ADDR_SIZE; i++) {
73 		token = strsep(&sptr, " ");
74 		if (!token)
75 			return -EINVAL;
76 		if (kstrtou8(token, 0, &peer_mac[i]))
77 			return -EINVAL;
78 	}
79 
80 	/* Get list_type */
81 	token = strsep(&sptr, " ");
82 	if (!token)
83 		return -EINVAL;
84 	if (kstrtou32(token, 0, &list_type))
85 		return -EINVAL;
86 
87 	/* Get cmd_type */
88 	token = strsep(&sptr, " ");
89 	if (!token)
90 		return -EINVAL;
91 	if (kstrtou32(token, 0, &cmd_type))
92 		return -EINVAL;
93 
94 	hdd_debug("Modify ACL mac:" QDF_MAC_ADDR_FMT " type: %d cmd: %d",
95 		  QDF_MAC_ADDR_REF(peer_mac), list_type, cmd_type);
96 
97 	qdf_status = wlansap_modify_acl(
98 		WLAN_HDD_GET_SAP_CTX_PTR(adapter->deflink),
99 		peer_mac, list_type, cmd_type);
100 	if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
101 		hdd_err("Modify ACL failed");
102 		return -EIO;
103 	}
104 
105 	return count;
106 }
107 
hdd_sysfs_modify_acl_store(struct device * dev,struct device_attribute * attr,char const * buf,size_t count)108 static ssize_t hdd_sysfs_modify_acl_store(struct device *dev,
109 					  struct device_attribute *attr,
110 					  char const *buf, size_t count)
111 {
112 	struct net_device *net_dev = container_of(dev, struct net_device, dev);
113 	struct osif_vdev_sync *vdev_sync;
114 	ssize_t errno_size;
115 
116 	errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
117 	if (errno_size)
118 		return errno_size;
119 
120 	errno_size = __hdd_sysfs_modify_acl_store(
121 				net_dev, buf, count);
122 	if (errno_size < 0)
123 		hdd_err_rl("errno_size %zd", errno_size);
124 
125 	osif_vdev_sync_op_stop(vdev_sync);
126 
127 	return errno_size;
128 }
129 
130 static DEVICE_ATTR(modify_acl, 0220,
131 		   NULL, hdd_sysfs_modify_acl_store);
132 
hdd_sysfs_modify_acl_create(struct hdd_adapter * adapter)133 int hdd_sysfs_modify_acl_create(struct hdd_adapter *adapter)
134 {
135 	int error;
136 
137 	error = device_create_file(&adapter->dev->dev, &dev_attr_modify_acl);
138 	if (error)
139 		hdd_err("could not create modify_acl sysfs file");
140 
141 	return error;
142 }
143 
hdd_sysfs_modify_acl_destroy(struct hdd_adapter * adapter)144 void hdd_sysfs_modify_acl_destroy(struct hdd_adapter *adapter)
145 {
146 	device_remove_file(&adapter->dev->dev, &dev_attr_modify_acl);
147 }
148