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 void (*send_rsp_cb)(uint32_t, enum wifi_pos_cmd_ids, 31 uint32_t, uint8_t *)) 32 { 33 uint8_t err; 34 uint32_t app_pid; 35 bool is_app_registered; 36 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc_obj = 37 wifi_pos_get_psoc_priv_obj(psoc); 38 39 wifi_pos_debug("enter"); 40 41 if (!wifi_pos_psoc_obj) { 42 wifi_pos_err("wifi_pos_psoc_obj is null"); 43 return QDF_STATUS_E_NULL_VALUE; 44 } 45 46 qdf_spin_lock_bh(&wifi_pos_psoc_obj->wifi_pos_lock); 47 wifi_pos_psoc_obj->wifi_pos_send_rsp = send_rsp_cb; 48 is_app_registered = wifi_pos_psoc_obj->is_app_registered; 49 app_pid = wifi_pos_psoc_obj->app_pid; 50 wifi_pos_psoc_obj->rsp_version = req->rsp_version; 51 qdf_spin_unlock_bh(&wifi_pos_psoc_obj->wifi_pos_lock); 52 53 if (!wifi_pos_psoc_obj->wifi_pos_req_handler) { 54 wifi_pos_err("wifi_pos_psoc_obj->wifi_pos_req_handler is null"); 55 err = OEM_ERR_NULL_CONTEXT; 56 send_rsp_cb(app_pid, WIFI_POS_CMD_ERROR, sizeof(err), &err); 57 return QDF_STATUS_E_NULL_VALUE; 58 } 59 60 if (req->msg_type != WIFI_POS_CMD_REGISTRATION && 61 (!is_app_registered || app_pid != req->pid)) { 62 wifi_pos_err("requesting app is not registered, app_registered: %d, requesting pid: %d, stored pid: %d", 63 is_app_registered, req->pid, app_pid); 64 err = OEM_ERR_APP_NOT_REGISTERED; 65 send_rsp_cb(app_pid, WIFI_POS_CMD_ERROR, sizeof(err), &err); 66 return QDF_STATUS_E_INVAL; 67 } 68 69 return wifi_pos_psoc_obj->wifi_pos_req_handler(psoc, req); 70 } 71 72 73 uint32_t ucfg_wifi_pos_get_ftm_cap(struct wlan_objmgr_psoc *psoc) 74 { 75 uint32_t val = 0; 76 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 77 wifi_pos_get_psoc_priv_obj(psoc); 78 79 if (!wifi_pos_psoc) { 80 wifi_pos_alert("unable to get wifi_pos psoc obj"); 81 return val; 82 } 83 84 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 85 val = wifi_pos_psoc->fine_time_meas_cap; 86 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 87 88 return val; 89 } 90 91 void ucfg_wifi_pos_set_ftm_cap(struct wlan_objmgr_psoc *psoc, uint32_t val) 92 { 93 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 94 wifi_pos_get_psoc_priv_obj(psoc); 95 96 if (!wifi_pos_psoc) { 97 wifi_pos_alert("unable to get wifi_pos psoc obj"); 98 return; 99 } 100 101 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 102 wifi_pos_psoc->fine_time_meas_cap = val; 103 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 104 } 105 106 void ucfg_wifi_pos_set_oem_6g_supported(struct wlan_objmgr_psoc *psoc, 107 bool val) 108 { 109 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 110 wifi_pos_get_psoc_priv_obj(psoc); 111 if (!wifi_pos_psoc) { 112 wifi_pos_alert("unable to get wifi_pos psoc obj"); 113 return; 114 } 115 116 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 117 wifi_pos_psoc->oem_6g_support_disable = val; 118 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 119 } 120 121 bool ucfg_wifi_pos_is_nl_rsp(struct wlan_objmgr_psoc *psoc) 122 { 123 uint32_t val = 0; 124 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 125 wifi_pos_get_psoc_priv_obj(psoc); 126 127 if (!wifi_pos_psoc) { 128 wifi_pos_alert("unable to get wifi_pos psoc obj"); 129 return false; 130 } 131 132 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 133 val = wifi_pos_psoc->rsp_version; 134 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 135 136 if (val == WIFI_POS_RSP_V2_NL) 137 return true; 138 else 139 return false; 140 141 } 142 143