1 /*
2  * Copyright (c) 2020, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-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_sta_info.c
20  *
21  * implementation for creating sysfs file sta_info
22  */
23 
24 #include <wlan_hdd_includes.h>
25 #include "osif_vdev_sync.h"
26 #include "wlan_hdd_sysfs_sta_info.h"
27 
__show_sta_info(struct net_device * net_dev,char * buf)28 static ssize_t __show_sta_info(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_station_info *sta, *tmp = NULL;
33 	int ret_val;
34 
35 	hdd_enter_dev(net_dev);
36 
37 	ret_val = hdd_validate_adapter(adapter);
38 	if (0 != ret_val)
39 		goto exit;
40 
41 	if (adapter->device_mode != QDF_SAP_MODE)
42 		goto exit;
43 
44 	hdd_ctx = WLAN_HDD_GET_CTX(adapter);
45 	ret_val = wlan_hdd_validate_context(hdd_ctx);
46 	if (0 != ret_val)
47 		goto exit;
48 
49 	ret_val = scnprintf(buf, PAGE_SIZE,
50 			    "%s    get_sta_info:\nstaAddress\n",
51 			    net_dev->name);
52 
53 	hdd_for_each_sta_ref_safe(adapter->sta_info_list, sta, tmp,
54 				  STA_INFO_SHOW) {
55 		if (QDF_IS_ADDR_BROADCAST(sta->sta_mac.bytes)) {
56 			hdd_put_sta_info_ref(&adapter->sta_info_list, &sta,
57 					     true, STA_INFO_SHOW);
58 			continue;
59 		}
60 		ret_val += scnprintf(buf + ret_val, PAGE_SIZE - ret_val,
61 				     QDF_MAC_ADDR_FMT " ecsa=%d\n",
62 				     QDF_MAC_ADDR_REF(sta->sta_mac.bytes),
63 				     sta->ecsa_capable);
64 
65 		hdd_put_sta_info_ref(&adapter->sta_info_list, &sta, true,
66 				     STA_INFO_SHOW);
67 	}
68 
69 exit:
70 	hdd_exit();
71 	return ret_val;
72 }
73 
show_sta_info(struct device * dev,struct device_attribute * attr,char * buf)74 static ssize_t show_sta_info(struct device *dev,
75 			     struct device_attribute *attr,
76 			     char *buf)
77 {
78 	struct net_device *net_dev = container_of(dev, struct net_device, dev);
79 	struct osif_vdev_sync *vdev_sync;
80 	ssize_t err_size;
81 
82 	err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
83 	if (err_size)
84 		return err_size;
85 
86 	err_size = __show_sta_info(net_dev, buf);
87 
88 	osif_vdev_sync_op_stop(vdev_sync);
89 
90 	return err_size;
91 }
92 
93 static DEVICE_ATTR(sta_info, 0444, show_sta_info, NULL);
94 
hdd_sysfs_sta_info_interface_create(struct hdd_adapter * adapter)95 void hdd_sysfs_sta_info_interface_create(struct hdd_adapter *adapter)
96 {
97 	int error;
98 
99 	error = device_create_file(&adapter->dev->dev, &dev_attr_sta_info);
100 	if (error)
101 		hdd_err("Could not create sta_info sysfs file");
102 }
103 
hdd_sysfs_sta_info_interface_destroy(struct hdd_adapter * adapter)104 void hdd_sysfs_sta_info_interface_destroy(struct hdd_adapter *adapter)
105 {
106 	device_remove_file(&adapter->dev->dev, &dev_attr_sta_info);
107 }
108