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 #ifndef CNSS_GENL 28 #include <wlan_objmgr_psoc_obj.h> 29 #endif 30 31 #ifndef CNSS_GENL 32 QDF_STATUS ucfg_wifi_psoc_get_pdev_id_by_dev_name( 33 char *dev_name, uint8_t *pdev_id, 34 struct wlan_objmgr_psoc **psoc) 35 { 36 struct wlan_objmgr_psoc *tmp_psoc = wifi_pos_get_psoc(); 37 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc_obj; 38 39 if (!tmp_psoc) { 40 wifi_pos_err("psoc is null"); 41 return QDF_STATUS_E_NULL_VALUE; 42 } 43 44 wifi_pos_psoc_obj = wifi_pos_get_psoc_priv_obj(tmp_psoc); 45 if (!wifi_pos_psoc_obj) { 46 wifi_pos_err("wifi_pos_psoc_obj is null"); 47 return QDF_STATUS_E_NULL_VALUE; 48 } 49 50 if (!wifi_pos_psoc_obj->wifi_pos_get_pdev_id_by_dev_name) { 51 wifi_pos_err("wifi_pos_get_pdev_id_by_dev_name is null"); 52 return QDF_STATUS_E_NULL_VALUE; 53 } 54 55 return wifi_pos_psoc_obj->wifi_pos_get_pdev_id_by_dev_name( 56 dev_name, pdev_id, psoc); 57 } 58 #endif 59 60 QDF_STATUS ucfg_wifi_pos_process_req(struct wlan_objmgr_psoc *psoc, 61 struct wifi_pos_req_msg *req, 62 wifi_pos_send_rsp_handler send_rsp_cb) 63 { 64 uint8_t err; 65 uint32_t app_pid; 66 bool is_app_registered; 67 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc_obj; 68 69 wifi_pos_debug("enter"); 70 71 wifi_pos_psoc_obj = wifi_pos_get_psoc_priv_obj(wifi_pos_get_psoc()); 72 if (!wifi_pos_psoc_obj) { 73 wifi_pos_err("wifi_pos_psoc_obj is null"); 74 return QDF_STATUS_E_NULL_VALUE; 75 } 76 77 qdf_spin_lock_bh(&wifi_pos_psoc_obj->wifi_pos_lock); 78 wifi_pos_psoc_obj->wifi_pos_send_rsp = send_rsp_cb; 79 is_app_registered = wifi_pos_psoc_obj->is_app_registered; 80 app_pid = wifi_pos_psoc_obj->app_pid; 81 wifi_pos_psoc_obj->rsp_version = req->rsp_version; 82 qdf_spin_unlock_bh(&wifi_pos_psoc_obj->wifi_pos_lock); 83 84 if (!wifi_pos_psoc_obj->wifi_pos_req_handler) { 85 wifi_pos_err("wifi_pos_psoc_obj->wifi_pos_req_handler is null"); 86 err = OEM_ERR_NULL_CONTEXT; 87 send_rsp_cb(psoc, app_pid, WIFI_POS_CMD_ERROR, sizeof(err), 88 &err); 89 return QDF_STATUS_E_NULL_VALUE; 90 } 91 92 if (req->msg_type != WIFI_POS_CMD_REGISTRATION && 93 (!is_app_registered || app_pid != req->pid)) { 94 wifi_pos_err("requesting app is not registered, app_registered: %d, requesting pid: %d, stored pid: %d", 95 is_app_registered, req->pid, app_pid); 96 err = OEM_ERR_APP_NOT_REGISTERED; 97 send_rsp_cb(psoc, app_pid, WIFI_POS_CMD_ERROR, sizeof(err), 98 &err); 99 return QDF_STATUS_E_INVAL; 100 } 101 102 return wifi_pos_psoc_obj->wifi_pos_req_handler(psoc, req); 103 } 104 105 106 uint32_t ucfg_wifi_pos_get_ftm_cap(struct wlan_objmgr_psoc *psoc) 107 { 108 uint32_t val = 0; 109 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 110 wifi_pos_get_psoc_priv_obj(psoc); 111 112 if (!wifi_pos_psoc) { 113 wifi_pos_alert("unable to get wifi_pos psoc obj"); 114 return val; 115 } 116 117 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 118 val = wifi_pos_psoc->fine_time_meas_cap; 119 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 120 121 return val; 122 } 123 124 void ucfg_wifi_pos_set_ftm_cap(struct wlan_objmgr_psoc *psoc, uint32_t val) 125 { 126 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 127 wifi_pos_get_psoc_priv_obj(psoc); 128 129 if (!wifi_pos_psoc) { 130 wifi_pos_alert("unable to get wifi_pos psoc obj"); 131 return; 132 } 133 134 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 135 wifi_pos_psoc->fine_time_meas_cap = val; 136 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 137 } 138 139 void ucfg_wifi_pos_set_oem_6g_supported(struct wlan_objmgr_psoc *psoc, 140 bool val) 141 { 142 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 143 wifi_pos_get_psoc_priv_obj(psoc); 144 if (!wifi_pos_psoc) { 145 wifi_pos_alert("unable to get wifi_pos psoc obj"); 146 return; 147 } 148 149 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 150 wifi_pos_psoc->oem_6g_support_disable = val; 151 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 152 } 153 154 bool ucfg_wifi_pos_is_nl_rsp(struct wlan_objmgr_psoc *psoc) 155 { 156 uint32_t val = 0; 157 struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = 158 wifi_pos_get_psoc_priv_obj(psoc); 159 160 if (!wifi_pos_psoc) { 161 wifi_pos_alert("unable to get wifi_pos psoc obj"); 162 return false; 163 } 164 165 qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock); 166 val = wifi_pos_psoc->rsp_version; 167 qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock); 168 169 if (val == WIFI_POS_RSP_V2_NL) 170 return true; 171 else 172 return false; 173 174 } 175 176