xref: /wlan-driver/qcacld-3.0/core/hdd/src/wlan_hdd_sysfs_channel.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 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_channel.c
20  *
21  * implementation for creating sysfs file channel
22  */
23 
24 #include <wlan_hdd_includes.h>
25 #include "osif_vdev_sync.h"
26 #include "wlan_hdd_sysfs_channel.h"
27 
__show_channel_number(struct net_device * net_dev,char * buf)28 static ssize_t __show_channel_number(struct net_device *net_dev, char *buf)
29 {
30 	struct hdd_adapter *adapter = netdev_priv(net_dev);
31 	struct hdd_context *hdd_ctx;
32 	struct hdd_ap_ctx *ap_ctx;
33 	int chan_num = 0;
34 	int ret_val;
35 
36 	hdd_enter_dev(net_dev);
37 
38 	ret_val = hdd_validate_adapter(adapter);
39 	if (0 != ret_val)
40 		goto exit;
41 
42 	if (adapter->device_mode != QDF_SAP_MODE)
43 		goto exit;
44 
45 	hdd_ctx = WLAN_HDD_GET_CTX(adapter);
46 	ret_val = wlan_hdd_validate_context(hdd_ctx);
47 	if (0 != ret_val)
48 		goto exit;
49 
50 	ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter->deflink);
51 	if (test_bit(SOFTAP_BSS_STARTED, &adapter->deflink->link_flags)) {
52 		chan_num = wlan_reg_freq_to_chan(hdd_ctx->pdev,
53 						 ap_ctx->operating_chan_freq);
54 		ret_val = scnprintf(buf, PAGE_SIZE, "%s    getchannel:%d\n",
55 				    net_dev->name, chan_num);
56 	}
57 
58 exit:
59 	hdd_exit();
60 	return ret_val;
61 }
62 
show_channel_number(struct device * dev,struct device_attribute * attr,char * buf)63 static ssize_t show_channel_number(struct device *dev,
64 				   struct device_attribute *attr,
65 				   char *buf)
66 {
67 	struct net_device *net_dev = container_of(dev, struct net_device, dev);
68 	struct osif_vdev_sync *vdev_sync;
69 	ssize_t err_size;
70 
71 	err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
72 	if (err_size)
73 		return err_size;
74 
75 	err_size = __show_channel_number(net_dev, buf);
76 
77 	osif_vdev_sync_op_stop(vdev_sync);
78 
79 	return err_size;
80 }
81 
82 static DEVICE_ATTR(channel, 0444, show_channel_number, NULL);
83 
hdd_sysfs_channel_interface_create(struct hdd_adapter * adapter)84 void hdd_sysfs_channel_interface_create(struct hdd_adapter *adapter)
85 {
86 	int error;
87 
88 	error = device_create_file(&adapter->dev->dev, &dev_attr_channel);
89 	if (error)
90 		hdd_err("Could not create channel sysfs file");
91 }
92 
hdd_sysfs_channel_interface_destroy(struct hdd_adapter * adapter)93 void hdd_sysfs_channel_interface_destroy(struct hdd_adapter *adapter)
94 {
95 	device_remove_file(&adapter->dev->dev, &dev_attr_channel);
96 }
97