xref: /wlan-driver/qcacld-3.0/core/hdd/src/wlan_hdd_sysfs_reassoc.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2020-2021 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
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: wlan_hdd_sysfs_reassoc.c
22  *
23  * implementation for creating sysfs file reassoc
24  */
25 
26 #include <wlan_hdd_includes.h>
27 #include "osif_vdev_sync.h"
28 #include "wlan_hdd_sysfs_reassoc.h"
29 #include "wlan_cm_roam_ucfg_api.h"
30 
31 static ssize_t
__wlan_hdd_store_reassoc_sysfs(struct net_device * net_dev,char const * buf,size_t count)32 __wlan_hdd_store_reassoc_sysfs(struct net_device *net_dev, char const *buf,
33 			       size_t count)
34 {
35 	struct hdd_adapter *adapter = netdev_priv(net_dev);
36 	struct hdd_context *hdd_ctx;
37 	mac_handle_t mac_handle;
38 	uint32_t operating_ch;
39 	int ret;
40 	struct qdf_mac_addr target_bssid;
41 
42 	if (hdd_validate_adapter(adapter))
43 		return -EINVAL;
44 
45 	hdd_ctx = WLAN_HDD_GET_CTX(adapter);
46 	ret = wlan_hdd_validate_context(hdd_ctx);
47 	if (ret != 0)
48 		return ret;
49 
50 	if (!wlan_hdd_validate_modules_state(hdd_ctx))
51 		return -EINVAL;
52 
53 	mac_handle = hdd_ctx->mac_handle;
54 	operating_ch = wlan_get_operation_chan_freq(adapter->deflink->vdev);
55 	wlan_mlme_get_bssid_vdev_id(hdd_ctx->pdev, adapter->deflink->vdev_id,
56 				    &target_bssid);
57 	hdd_debug("reassoc: net_devname %s", net_dev->name);
58 	ucfg_wlan_cm_roam_invoke(hdd_ctx->pdev, adapter->deflink->vdev_id,
59 				 &target_bssid, operating_ch, CM_ROAMING_USER);
60 
61 	return count;
62 }
63 
wlan_hdd_store_reassoc_sysfs(struct device * dev,struct device_attribute * attr,char const * buf,size_t count)64 static ssize_t wlan_hdd_store_reassoc_sysfs(struct device *dev,
65 					    struct device_attribute *attr,
66 					    char const *buf, size_t count)
67 {
68 	struct net_device *net_dev = container_of(dev, struct net_device, dev);
69 	struct osif_vdev_sync *vdev_sync;
70 	ssize_t err_size;
71 
72 	err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
73 	if (err_size)
74 		return err_size;
75 
76 	err_size = __wlan_hdd_store_reassoc_sysfs(net_dev, buf, count);
77 
78 	osif_vdev_sync_op_stop(vdev_sync);
79 
80 	return err_size;
81 }
82 
83 static DEVICE_ATTR(reassoc, 0220,
84 		   NULL, wlan_hdd_store_reassoc_sysfs);
85 
hdd_sysfs_reassoc_create(struct hdd_adapter * adapter)86 int hdd_sysfs_reassoc_create(struct hdd_adapter *adapter)
87 {
88 	int error;
89 
90 	error = device_create_file(&adapter->dev->dev, &dev_attr_reassoc);
91 	if (error)
92 		hdd_err("could not create reassoc sysfs file");
93 
94 	return error;
95 }
96 
hdd_sysfs_reassoc_destroy(struct hdd_adapter * adapter)97 void hdd_sysfs_reassoc_destroy(struct hdd_adapter *adapter)
98 {
99 	device_remove_file(&adapter->dev->dev, &dev_attr_reassoc);
100 }
101