xref: /wlan-dirver/qca-wifi-host-cmn/umac/wifi_pos/src/wifi_pos_ucfg.c (revision 1f55ed1a9f5050d8da228aa8dd3fff7c0242aa71)
1 /*
2  * Copyright (c) 2017-2018 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 		void (*send_rsp_cb)(uint32_t, uint32_t, uint32_t, uint8_t *))
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 	qdf_spin_unlock_bh(&wifi_pos_psoc_obj->wifi_pos_lock);
50 
51 	if (!wifi_pos_psoc_obj->wifi_pos_req_handler) {
52 		wifi_pos_err("wifi_pos_psoc_obj->wifi_pos_req_handler is null");
53 		err = OEM_ERR_NULL_CONTEXT;
54 		send_rsp_cb(app_pid, ANI_MSG_OEM_ERROR, sizeof(err), &err);
55 		return QDF_STATUS_E_NULL_VALUE;
56 	}
57 
58 	if (req->msg_type != ANI_MSG_APP_REG_REQ &&
59 		(!is_app_registered || app_pid != req->pid)) {
60 		wifi_pos_err("requesting app is not registered, app_registered: %d, requesting pid: %d, stored pid: %d",
61 			is_app_registered, req->pid, app_pid);
62 		err = OEM_ERR_APP_NOT_REGISTERED;
63 		send_rsp_cb(app_pid, ANI_MSG_OEM_ERROR, sizeof(err), &err);
64 		return QDF_STATUS_E_INVAL;
65 	}
66 
67 	return wifi_pos_psoc_obj->wifi_pos_req_handler(psoc, req);
68 }
69 
70 
71 uint32_t ucfg_wifi_pos_get_ftm_cap(struct wlan_objmgr_psoc *psoc)
72 {
73 	uint32_t val = 0;
74 	struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
75 			wifi_pos_get_psoc_priv_obj(psoc);
76 
77 	if (!wifi_pos_psoc) {
78 		wifi_pos_alert("unable to get wifi_pos psoc obj");
79 		return val;
80 	}
81 
82 	qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
83 	val = wifi_pos_psoc->fine_time_meas_cap;
84 	qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
85 
86 	return val;
87 }
88 
89 void ucfg_wifi_pos_set_ftm_cap(struct wlan_objmgr_psoc *psoc, uint32_t val)
90 {
91 	struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
92 			wifi_pos_get_psoc_priv_obj(psoc);
93 
94 	if (!wifi_pos_psoc) {
95 		wifi_pos_alert("unable to get wifi_pos psoc obj");
96 		return;
97 	}
98 
99 	qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
100 	wifi_pos_psoc->fine_time_meas_cap = val;
101 	qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
102 }
103 
104