xref: /wlan-dirver/qca-wifi-host-cmn/umac/wifi_pos/src/wifi_pos_ucfg.c (revision a86b23ee68a2491aede2e03991f3fb37046f4e41)
1 /*
2  * Copyright (c) 2017-2018, 2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * This file defines the important dispatcher APIs pertinent to
21  * wifi positioning.
22  */
23 #include "wifi_pos_utils_i.h"
24 #include "wifi_pos_api.h"
25 #include "wifi_pos_ucfg_i.h"
26 #include "wlan_ptt_sock_svc.h"
27 
28 QDF_STATUS ucfg_wifi_pos_process_req(struct wlan_objmgr_psoc *psoc,
29 				     struct wifi_pos_req_msg *req,
30 				     wifi_pos_send_rsp_handler send_rsp_cb)
31 {
32 	uint8_t err;
33 	uint32_t app_pid;
34 	bool is_app_registered;
35 	struct wifi_pos_psoc_priv_obj *wifi_pos_psoc_obj =
36 					wifi_pos_get_psoc_priv_obj(psoc);
37 
38 	wifi_pos_debug("enter");
39 
40 	if (!wifi_pos_psoc_obj) {
41 		wifi_pos_err("wifi_pos_psoc_obj is null");
42 		return QDF_STATUS_E_NULL_VALUE;
43 	}
44 
45 	qdf_spin_lock_bh(&wifi_pos_psoc_obj->wifi_pos_lock);
46 	wifi_pos_psoc_obj->wifi_pos_send_rsp = send_rsp_cb;
47 	is_app_registered = wifi_pos_psoc_obj->is_app_registered;
48 	app_pid = wifi_pos_psoc_obj->app_pid;
49 	wifi_pos_psoc_obj->rsp_version = req->rsp_version;
50 	qdf_spin_unlock_bh(&wifi_pos_psoc_obj->wifi_pos_lock);
51 
52 	if (!wifi_pos_psoc_obj->wifi_pos_req_handler) {
53 		wifi_pos_err("wifi_pos_psoc_obj->wifi_pos_req_handler is null");
54 		err = OEM_ERR_NULL_CONTEXT;
55 		send_rsp_cb(app_pid, WIFI_POS_CMD_ERROR, sizeof(err), &err);
56 		return QDF_STATUS_E_NULL_VALUE;
57 	}
58 
59 	if (req->msg_type != WIFI_POS_CMD_REGISTRATION &&
60 		(!is_app_registered || app_pid != req->pid)) {
61 		wifi_pos_err("requesting app is not registered, app_registered: %d, requesting pid: %d, stored pid: %d",
62 			is_app_registered, req->pid, app_pid);
63 		err = OEM_ERR_APP_NOT_REGISTERED;
64 		send_rsp_cb(app_pid, WIFI_POS_CMD_ERROR, sizeof(err), &err);
65 		return QDF_STATUS_E_INVAL;
66 	}
67 
68 	return wifi_pos_psoc_obj->wifi_pos_req_handler(psoc, req);
69 }
70 
71 
72 uint32_t ucfg_wifi_pos_get_ftm_cap(struct wlan_objmgr_psoc *psoc)
73 {
74 	uint32_t val = 0;
75 	struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
76 			wifi_pos_get_psoc_priv_obj(psoc);
77 
78 	if (!wifi_pos_psoc) {
79 		wifi_pos_alert("unable to get wifi_pos psoc obj");
80 		return val;
81 	}
82 
83 	qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
84 	val = wifi_pos_psoc->fine_time_meas_cap;
85 	qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
86 
87 	return val;
88 }
89 
90 void ucfg_wifi_pos_set_ftm_cap(struct wlan_objmgr_psoc *psoc, uint32_t val)
91 {
92 	struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
93 			wifi_pos_get_psoc_priv_obj(psoc);
94 
95 	if (!wifi_pos_psoc) {
96 		wifi_pos_alert("unable to get wifi_pos psoc obj");
97 		return;
98 	}
99 
100 	qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
101 	wifi_pos_psoc->fine_time_meas_cap = val;
102 	qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
103 }
104 
105 void ucfg_wifi_pos_set_oem_6g_supported(struct wlan_objmgr_psoc *psoc,
106 					bool val)
107 {
108 	struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
109 			wifi_pos_get_psoc_priv_obj(psoc);
110 	if (!wifi_pos_psoc) {
111 		wifi_pos_alert("unable to get wifi_pos psoc obj");
112 		return;
113 	}
114 
115 	qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
116 	wifi_pos_psoc->oem_6g_support_disable = val;
117 	qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
118 }
119 
120 bool ucfg_wifi_pos_is_nl_rsp(struct wlan_objmgr_psoc *psoc)
121 {
122 	uint32_t val = 0;
123 	struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
124 			wifi_pos_get_psoc_priv_obj(psoc);
125 
126 	if (!wifi_pos_psoc) {
127 		wifi_pos_alert("unable to get wifi_pos psoc obj");
128 		return false;
129 	}
130 
131 	qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
132 	val = wifi_pos_psoc->rsp_version;
133 	qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
134 
135 	if (val == WIFI_POS_RSP_V2_NL)
136 		return true;
137 	else
138 		return false;
139 
140 }
141 
142