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 #include "wlan_hdd_ftm_time_sync.h"
19 #include "ftm_time_sync_ucfg_api.h"
20 #include "wlan_hdd_object_manager.h"
21
hdd_ftm_time_sync_show(struct device * dev,struct device_attribute * attr,char * buf)22 static ssize_t hdd_ftm_time_sync_show(struct device *dev,
23 struct device_attribute *attr, char *buf)
24 {
25 struct hdd_station_ctx *hdd_sta_ctx;
26 struct hdd_adapter *adapter;
27 struct wlan_objmgr_vdev *vdev;
28 ssize_t size = 0;
29
30 struct net_device *net_dev = qdf_container_of(dev, struct net_device,
31 dev);
32
33 adapter = (struct hdd_adapter *)(netdev_priv(net_dev));
34 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
35 return scnprintf(buf, PAGE_SIZE, "Invalid device\n");
36
37 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter->deflink);
38 vdev = hdd_objmgr_get_vdev_by_user(adapter->deflink, FTM_TIME_SYNC_ID);
39 if (!vdev)
40 return -EINVAL;
41
42 if (adapter->device_mode == QDF_STA_MODE)
43 size = ucfg_ftm_time_sync_show(vdev, buf);
44
45 hdd_objmgr_put_vdev_by_user(vdev, FTM_TIME_SYNC_ID);
46 return size;
47 }
48
49 static DEVICE_ATTR(ftm_time_sync, 0400, hdd_ftm_time_sync_show, NULL);
50
51 void
hdd_ftm_time_sync_sta_state_notify(struct hdd_adapter * adapter,enum ftm_time_sync_sta_state state)52 hdd_ftm_time_sync_sta_state_notify(struct hdd_adapter *adapter,
53 enum ftm_time_sync_sta_state state)
54 {
55 struct hdd_station_ctx *hdd_sta_ctx;
56 struct wlan_objmgr_psoc *psoc;
57 struct net_device *net_dev;
58 struct wlan_objmgr_vdev *vdev;
59
60 vdev = hdd_objmgr_get_vdev_by_user(adapter->deflink, FTM_TIME_SYNC_ID);
61 if (!vdev)
62 return;
63
64 psoc = wlan_vdev_get_psoc(vdev);
65 if (!psoc)
66 goto out;
67
68 if (!ucfg_is_ftm_time_sync_enable(psoc))
69 goto out;
70
71 net_dev = adapter->dev;
72
73 if (net_dev) {
74 if (state == FTM_TIME_SYNC_STA_CONNECTED)
75 device_create_file(&net_dev->dev,
76 &dev_attr_ftm_time_sync);
77 else
78 device_remove_file(&net_dev->dev,
79 &dev_attr_ftm_time_sync);
80 }
81
82 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter->deflink);
83 ucfg_ftm_time_sync_update_sta_connect_state(
84 vdev, state,
85 hdd_sta_ctx->conn_info.bssid);
86 out:
87 hdd_objmgr_put_vdev_by_user(vdev, FTM_TIME_SYNC_ID);
88 }
89