wifi_pos_ucfg.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2017-2018, 2020 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021, 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: This file defines the important dispatcher APIs pertinent to
  21. * wifi positioning.
  22. */
  23. #include <wlan_lmac_if_def.h>
  24. #include "wifi_pos_utils_i.h"
  25. #include "wifi_pos_api.h"
  26. #include "wifi_pos_ucfg_i.h"
  27. #include "wlan_ptt_sock_svc.h"
  28. #ifndef CNSS_GENL
  29. #include <wlan_objmgr_psoc_obj.h>
  30. #include "wifi_pos_main_i.h"
  31. #endif
  32. #ifndef CNSS_GENL
  33. QDF_STATUS ucfg_wifi_psoc_get_pdev_id_by_dev_name(
  34. char *dev_name, uint8_t *pdev_id,
  35. struct wlan_objmgr_psoc **psoc)
  36. {
  37. struct wlan_objmgr_psoc *tmp_psoc = wifi_pos_get_psoc();
  38. struct wifi_pos_psoc_priv_obj *wifi_pos_psoc_obj;
  39. if (!tmp_psoc) {
  40. wifi_pos_err("psoc is null");
  41. return QDF_STATUS_E_NULL_VALUE;
  42. }
  43. wifi_pos_psoc_obj = wifi_pos_get_psoc_priv_obj(tmp_psoc);
  44. if (!wifi_pos_psoc_obj) {
  45. wifi_pos_err("wifi_pos_psoc_obj is null");
  46. return QDF_STATUS_E_NULL_VALUE;
  47. }
  48. if (!wifi_pos_psoc_obj->wifi_pos_get_pdev_id_by_dev_name) {
  49. wifi_pos_err("wifi_pos_get_pdev_id_by_dev_name is null");
  50. return QDF_STATUS_E_NULL_VALUE;
  51. }
  52. return wifi_pos_psoc_obj->wifi_pos_get_pdev_id_by_dev_name(
  53. dev_name, pdev_id, psoc);
  54. }
  55. #ifdef WLAN_RTT_MEASUREMENT_NOTIFICATION
  56. QDF_STATUS ucfg_wifi_pos_measurement_request_notification(
  57. struct wlan_objmgr_pdev *pdev,
  58. struct wifi_pos_req_msg *req)
  59. {
  60. struct wlan_objmgr_psoc *psoc = wifi_pos_get_psoc();
  61. struct wifi_pos_psoc_priv_obj *wifi_pos_psoc_obj;
  62. struct wlan_lmac_if_wifi_pos_tx_ops *tx_ops;
  63. struct rtt_channel_info chinfo = {0};
  64. if (!psoc) {
  65. wifi_pos_err("psoc is null");
  66. return QDF_STATUS_E_NULL_VALUE;
  67. }
  68. wifi_pos_psoc_obj = wifi_pos_get_psoc_priv_obj(psoc);
  69. if (!wifi_pos_psoc_obj) {
  70. wifi_pos_err("wifi_pos_psoc_obj is null");
  71. return QDF_STATUS_E_NULL_VALUE;
  72. }
  73. if (!wifi_pos_psoc_obj->wifi_pos_measurement_request_notification) {
  74. wifi_pos_debug("wifi_pos_measurement_request_notification is not registered");
  75. return QDF_STATUS_SUCCESS;
  76. }
  77. tx_ops = wifi_pos_get_tx_ops(psoc);
  78. if (!tx_ops) {
  79. wifi_pos_err("tx_ops null");
  80. return QDF_STATUS_E_NULL_VALUE;
  81. }
  82. if (!tx_ops->wifi_pos_parse_measreq_chan_info) {
  83. wifi_pos_err("wifi_pos_parse_measreq_chan_info is null");
  84. return QDF_STATUS_E_NULL_VALUE;
  85. }
  86. tx_ops->wifi_pos_parse_measreq_chan_info(pdev, req->buf_len, req->buf,
  87. &chinfo);
  88. if (!chinfo.freq) {
  89. wifi_pos_debug("Not a measurement request buffer, proceed");
  90. return QDF_STATUS_SUCCESS;
  91. }
  92. return wifi_pos_psoc_obj->wifi_pos_measurement_request_notification(
  93. pdev, &chinfo);
  94. }
  95. #endif /* WLAN_RTT_MEASUREMENT_NOTIFICATION */
  96. #endif
  97. QDF_STATUS ucfg_wifi_pos_process_req(struct wlan_objmgr_psoc *psoc,
  98. struct wifi_pos_req_msg *req,
  99. wifi_pos_send_rsp_handler send_rsp_cb)
  100. {
  101. uint8_t err;
  102. uint32_t app_pid;
  103. bool is_app_registered;
  104. struct wifi_pos_psoc_priv_obj *wifi_pos_psoc_obj;
  105. wifi_pos_debug("enter");
  106. wifi_pos_psoc_obj = wifi_pos_get_psoc_priv_obj(wifi_pos_get_psoc());
  107. if (!wifi_pos_psoc_obj) {
  108. wifi_pos_err("wifi_pos_psoc_obj is null");
  109. return QDF_STATUS_E_NULL_VALUE;
  110. }
  111. qdf_spin_lock_bh(&wifi_pos_psoc_obj->wifi_pos_lock);
  112. wifi_pos_psoc_obj->wifi_pos_send_rsp = send_rsp_cb;
  113. is_app_registered = wifi_pos_psoc_obj->is_app_registered;
  114. app_pid = wifi_pos_psoc_obj->app_pid;
  115. wifi_pos_psoc_obj->rsp_version = req->rsp_version;
  116. qdf_spin_unlock_bh(&wifi_pos_psoc_obj->wifi_pos_lock);
  117. if (!wifi_pos_psoc_obj->wifi_pos_req_handler) {
  118. wifi_pos_err("wifi_pos_psoc_obj->wifi_pos_req_handler is null");
  119. err = OEM_ERR_NULL_CONTEXT;
  120. send_rsp_cb(psoc, app_pid, WIFI_POS_CMD_ERROR, sizeof(err),
  121. &err);
  122. return QDF_STATUS_E_NULL_VALUE;
  123. }
  124. if (req->msg_type != WIFI_POS_CMD_REGISTRATION &&
  125. (!is_app_registered || app_pid != req->pid)) {
  126. wifi_pos_err("requesting app is not registered, app_registered: %d, requesting pid: %d, stored pid: %d",
  127. is_app_registered, req->pid, app_pid);
  128. err = OEM_ERR_APP_NOT_REGISTERED;
  129. send_rsp_cb(psoc, app_pid, WIFI_POS_CMD_ERROR, sizeof(err),
  130. &err);
  131. return QDF_STATUS_E_INVAL;
  132. }
  133. return wifi_pos_psoc_obj->wifi_pos_req_handler(psoc, req);
  134. }
  135. uint32_t ucfg_wifi_pos_get_ftm_cap(struct wlan_objmgr_psoc *psoc)
  136. {
  137. uint32_t val = 0;
  138. struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
  139. wifi_pos_get_psoc_priv_obj(psoc);
  140. if (!wifi_pos_psoc) {
  141. wifi_pos_alert("unable to get wifi_pos psoc obj");
  142. return val;
  143. }
  144. qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
  145. val = wifi_pos_psoc->fine_time_meas_cap;
  146. qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
  147. return val;
  148. }
  149. void ucfg_wifi_pos_set_ftm_cap(struct wlan_objmgr_psoc *psoc, uint32_t val)
  150. {
  151. struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
  152. wifi_pos_get_psoc_priv_obj(psoc);
  153. if (!wifi_pos_psoc) {
  154. wifi_pos_alert("unable to get wifi_pos psoc obj");
  155. return;
  156. }
  157. qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
  158. wifi_pos_psoc->fine_time_meas_cap = val;
  159. qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
  160. }
  161. void ucfg_wifi_pos_set_oem_6g_supported(struct wlan_objmgr_psoc *psoc,
  162. bool val)
  163. {
  164. struct wifi_pos_psoc_priv_obj *wifi_pos_psoc =
  165. wifi_pos_get_psoc_priv_obj(psoc);
  166. if (!wifi_pos_psoc) {
  167. wifi_pos_alert("unable to get wifi_pos psoc obj");
  168. return;
  169. }
  170. qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
  171. wifi_pos_psoc->oem_6g_support_disable = val;
  172. qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
  173. }
  174. bool ucfg_wifi_pos_is_nl_rsp(struct wlan_objmgr_psoc *psoc)
  175. {
  176. uint32_t val = 0;
  177. struct wifi_pos_psoc_priv_obj *wifi_pos_psoc = NULL;
  178. struct wlan_objmgr_psoc *tmp_psoc = wifi_pos_get_psoc();
  179. if (tmp_psoc)
  180. wifi_pos_psoc = wifi_pos_get_psoc_priv_obj(tmp_psoc);
  181. if (!wifi_pos_psoc) {
  182. wifi_pos_alert("unable to get wifi_pos psoc obj");
  183. return false;
  184. }
  185. qdf_spin_lock_bh(&wifi_pos_psoc->wifi_pos_lock);
  186. val = wifi_pos_psoc->rsp_version;
  187. qdf_spin_unlock_bh(&wifi_pos_psoc->wifi_pos_lock);
  188. if (val == WIFI_POS_RSP_V2_NL)
  189. return true;
  190. else
  191. return false;
  192. }