1 /* 2 * Copyright (c) 2017-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 * DOC: contains scan south bound interface definitions 21 */ 22 23 #include <wlan_cmn.h> 24 #include <qdf_list.h> 25 #include "../../core/src/wlan_scan_main.h" 26 #include <wlan_scan_utils_api.h> 27 #include <wlan_scan_ucfg_api.h> 28 #include <wlan_scan_tgt_api.h> 29 #include <wlan_objmgr_cmn.h> 30 #include <wlan_lmac_if_def.h> 31 #include <wlan_objmgr_psoc_obj.h> 32 #include <wlan_objmgr_pdev_obj.h> 33 #include <wlan_objmgr_vdev_obj.h> 34 #include <../../core/src/wlan_scan_manager.h> 35 36 static inline struct wlan_lmac_if_scan_tx_ops * 37 wlan_psoc_get_scan_txops(struct wlan_objmgr_psoc *psoc) 38 { 39 return &((psoc->soc_cb.tx_ops.scan)); 40 } 41 42 static inline struct wlan_lmac_if_scan_tx_ops * 43 wlan_vdev_get_scan_txops(struct wlan_objmgr_vdev *vdev) 44 { 45 struct wlan_objmgr_psoc *psoc = NULL; 46 47 psoc = wlan_vdev_get_psoc(vdev); 48 if (!psoc) { 49 scm_err("NULL psoc"); 50 return NULL; 51 } 52 53 return wlan_psoc_get_scan_txops(psoc); 54 } 55 56 static inline struct wlan_lmac_if_scan_rx_ops * 57 wlan_vdev_get_scan_rxops(struct wlan_objmgr_vdev *vdev) 58 { 59 struct wlan_objmgr_psoc *psoc = NULL; 60 61 psoc = wlan_vdev_get_psoc(vdev); 62 if (!psoc) { 63 scm_err("NULL psoc"); 64 return NULL; 65 } 66 67 return &((psoc->soc_cb.rx_ops.scan)); 68 } 69 70 #ifdef FEATURE_WLAN_SCAN_PNO 71 72 QDF_STATUS tgt_scan_pno_start(struct wlan_objmgr_vdev *vdev, 73 struct pno_scan_req_params *req) 74 { 75 struct wlan_lmac_if_scan_tx_ops *scan_ops; 76 struct wlan_objmgr_psoc *psoc; 77 78 psoc = wlan_vdev_get_psoc(vdev); 79 80 if (!psoc) { 81 scm_err("NULL PSOC"); 82 return QDF_STATUS_E_FAILURE; 83 } 84 scan_ops = wlan_psoc_get_scan_txops(psoc); 85 if (!scan_ops) { 86 scm_err("NULL scan_ops"); 87 return QDF_STATUS_E_FAILURE; 88 } 89 /* invoke wmi_unified_pno_start_cmd() */ 90 QDF_ASSERT(scan_ops->pno_start); 91 if (scan_ops->pno_start) 92 return scan_ops->pno_start(psoc, req); 93 94 return QDF_STATUS_SUCCESS; 95 } 96 97 QDF_STATUS tgt_scan_pno_stop(struct wlan_objmgr_vdev *vdev, 98 uint8_t vdev_id) 99 { 100 struct wlan_lmac_if_scan_tx_ops *scan_ops; 101 struct wlan_objmgr_psoc *psoc; 102 103 psoc = wlan_vdev_get_psoc(vdev); 104 105 if (!psoc) { 106 scm_err("NULL PSOC"); 107 return QDF_STATUS_E_FAILURE; 108 } 109 scan_ops = wlan_psoc_get_scan_txops(psoc); 110 if (!scan_ops) { 111 scm_err("NULL scan_ops"); 112 return QDF_STATUS_E_FAILURE; 113 } 114 /* invoke wmi_unified_pno_stop_cmd() */ 115 QDF_ASSERT(scan_ops->pno_stop); 116 if (scan_ops->pno_stop) 117 return scan_ops->pno_stop(psoc, vdev_id); 118 119 return QDF_STATUS_SUCCESS; 120 } 121 #endif 122 123 QDF_STATUS 124 tgt_scan_start(struct scan_start_request *req) 125 { 126 struct wlan_lmac_if_scan_tx_ops *scan_ops; 127 struct wlan_objmgr_psoc *psoc; 128 struct wlan_objmgr_pdev *pdev; 129 struct wlan_objmgr_vdev *vdev = req->vdev; 130 131 if (!vdev) { 132 scm_err("vdev is NULL"); 133 return QDF_STATUS_E_NULL_VALUE; 134 } 135 136 psoc = wlan_vdev_get_psoc(vdev); 137 pdev = wlan_vdev_get_pdev(vdev); 138 if (!psoc || !pdev) { 139 scm_err("psoc: 0x%pK or pdev: 0x%pK is NULL", psoc, pdev); 140 return QDF_STATUS_E_NULL_VALUE; 141 } 142 143 scan_ops = wlan_psoc_get_scan_txops(psoc); 144 /* invoke wmi_unified_scan_start_cmd_send() */ 145 QDF_ASSERT(scan_ops->scan_start); 146 if (scan_ops->scan_start) 147 return scan_ops->scan_start(pdev, req); 148 else 149 return QDF_STATUS_SUCCESS; 150 } 151 152 153 QDF_STATUS 154 tgt_scan_cancel(struct scan_cancel_request *req) 155 { 156 struct wlan_lmac_if_scan_tx_ops *scan_ops; 157 struct wlan_objmgr_psoc *psoc; 158 struct wlan_objmgr_pdev *pdev; 159 struct wlan_objmgr_vdev *vdev = req->vdev; 160 161 if (!vdev) { 162 scm_err("vdev is NULL"); 163 return QDF_STATUS_E_NULL_VALUE; 164 } 165 psoc = wlan_vdev_get_psoc(vdev); 166 pdev = wlan_vdev_get_pdev(vdev); 167 if (!psoc || !pdev) { 168 scm_err("psoc: 0x%pK or pdev: 0x%pK is NULL", psoc, pdev); 169 return QDF_STATUS_E_NULL_VALUE; 170 } 171 scan_ops = wlan_psoc_get_scan_txops(psoc); 172 /* invoke wmi_unified_scan_stop_cmd_send() */ 173 QDF_ASSERT(scan_ops->scan_cancel); 174 if (scan_ops->scan_cancel) 175 return scan_ops->scan_cancel(pdev, &req->cancel_req); 176 else 177 return QDF_STATUS_SUCCESS; 178 } 179 180 QDF_STATUS 181 tgt_scan_register_ev_handler(struct wlan_objmgr_psoc *psoc) 182 { 183 struct wlan_lmac_if_scan_tx_ops *scan_ops = NULL; 184 185 scan_ops = wlan_psoc_get_scan_txops(psoc); 186 /* invoke wmi_unified_register_event_handler() 187 * since event id, handler function and context is 188 * already known to offload lmac, passing NULL as argument. 189 * DA can pass necessary arguments by clubing then into 190 * some structure. 191 */ 192 QDF_ASSERT(scan_ops->scan_reg_ev_handler); 193 if (scan_ops->scan_reg_ev_handler) 194 return scan_ops->scan_reg_ev_handler(psoc, NULL); 195 else 196 return QDF_STATUS_SUCCESS; 197 } 198 199 QDF_STATUS 200 tgt_scan_unregister_ev_handler(struct wlan_objmgr_psoc *psoc) 201 { 202 struct wlan_lmac_if_scan_tx_ops *scan_ops = NULL; 203 204 scan_ops = wlan_psoc_get_scan_txops(psoc); 205 /* invoke wmi_unified_register_event_handler() 206 * since event id, handler function and context is 207 * already known to offload lmac, passing NULL as argument. 208 * DA can pass necessary arguments by clubing then into 209 * some structure. 210 */ 211 QDF_ASSERT(scan_ops->scan_unreg_ev_handler); 212 if (scan_ops->scan_unreg_ev_handler) 213 return scan_ops->scan_unreg_ev_handler(psoc, NULL); 214 else 215 return QDF_STATUS_SUCCESS; 216 } 217 218 QDF_STATUS 219 tgt_scan_event_handler(struct wlan_objmgr_psoc *psoc, 220 struct scan_event_info *event_info) 221 { 222 struct scheduler_msg msg = {0}; 223 struct scan_event *event = &event_info->event; 224 uint8_t vdev_id = event->vdev_id; 225 QDF_STATUS status; 226 227 if (!psoc || !event_info) { 228 scm_err("psoc: 0x%pK, event_info: 0x%pK", psoc, event_info); 229 return QDF_STATUS_E_NULL_VALUE; 230 } 231 232 event_info->vdev = 233 wlan_objmgr_get_vdev_by_id_from_psoc(psoc, 234 vdev_id, WLAN_SCAN_ID); 235 if (!event_info->vdev) { 236 scm_err("null vdev, vdev_id: %d, psoc: 0x%pK", vdev_id, psoc); 237 return QDF_STATUS_E_INVAL; 238 } 239 msg.bodyptr = event_info; 240 msg.callback = scm_scan_event_handler; 241 msg.flush_callback = scm_scan_event_flush_callback; 242 243 status = scheduler_post_message(QDF_MODULE_ID_SCAN, 244 QDF_MODULE_ID_SCAN, 245 QDF_MODULE_ID_SCAN, &msg); 246 if (QDF_IS_STATUS_ERROR(status)) { 247 wlan_objmgr_vdev_release_ref(event_info->vdev, WLAN_SCAN_ID); 248 } 249 250 return status; 251 } 252 253 QDF_STATUS tgt_scan_bcn_probe_rx_callback(struct wlan_objmgr_psoc *psoc, 254 struct wlan_objmgr_peer *peer, qdf_nbuf_t buf, 255 struct mgmt_rx_event_params *rx_param, 256 enum mgmt_frame_type frm_type) 257 { 258 struct scheduler_msg msg = {0}; 259 struct scan_bcn_probe_event *bcn = NULL; 260 QDF_STATUS status; 261 uint32_t scan_queue_size = 0; 262 263 if ((frm_type != MGMT_PROBE_RESP) && 264 (frm_type != MGMT_BEACON)) { 265 scm_err("frame is not beacon or probe resp"); 266 status = QDF_STATUS_E_INVAL; 267 goto free; 268 } 269 270 bcn = qdf_mem_malloc_atomic(sizeof(*bcn)); 271 if (!bcn) { 272 status = QDF_STATUS_E_NOMEM; 273 goto free; 274 } 275 bcn->rx_data = 276 qdf_mem_malloc_atomic(sizeof(*rx_param)); 277 if (!bcn->rx_data) { 278 status = QDF_STATUS_E_NOMEM; 279 goto free; 280 } 281 282 if (frm_type == MGMT_PROBE_RESP) 283 bcn->frm_type = MGMT_SUBTYPE_PROBE_RESP; 284 else 285 bcn->frm_type = MGMT_SUBTYPE_BEACON; 286 287 /* Check if the beacon/probe frame can be posted in the scan queue */ 288 status = scheduler_get_queue_size(QDF_MODULE_ID_SCAN, &scan_queue_size); 289 if (!QDF_IS_STATUS_SUCCESS(status) || 290 scan_queue_size > MAX_BCN_PROBE_IN_SCAN_QUEUE) { 291 scm_debug_rl("Dropping beacon/probe frame, queue size %d", 292 scan_queue_size); 293 status = QDF_STATUS_E_FAILURE; 294 goto free; 295 } 296 297 status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_SCAN_ID); 298 if (QDF_IS_STATUS_ERROR(status)) { 299 scm_info("unable to get reference"); 300 goto free; 301 } 302 303 bcn->psoc = psoc; 304 bcn->buf = buf; 305 qdf_mem_copy(bcn->rx_data, rx_param, sizeof(*rx_param)); 306 307 msg.bodyptr = bcn; 308 msg.callback = scm_handle_bcn_probe; 309 msg.flush_callback = scm_bcn_probe_flush_callback; 310 311 status = scheduler_post_message(QDF_MODULE_ID_SCAN, 312 QDF_MODULE_ID_SCAN, 313 QDF_MODULE_ID_SCAN, &msg); 314 315 if (QDF_IS_STATUS_SUCCESS(status)) 316 return status; 317 318 wlan_objmgr_psoc_release_ref(psoc, WLAN_SCAN_ID); 319 320 free: 321 if (bcn && bcn->rx_data) 322 qdf_mem_free(bcn->rx_data); 323 if (bcn) 324 qdf_mem_free(bcn); 325 if (buf) 326 qdf_nbuf_free(buf); 327 328 return status; 329 } 330 331 QDF_STATUS 332 tgt_scan_set_max_active_scans(struct wlan_objmgr_psoc *psoc, 333 uint32_t max_active_scans) 334 { 335 struct scan_default_params *scan_params = NULL; 336 337 if (!psoc) { 338 scm_err("null psoc"); 339 return QDF_STATUS_E_NULL_VALUE; 340 } 341 342 scan_params = wlan_scan_psoc_get_def_params(psoc); 343 if (!scan_params) { 344 scm_err("wlan_scan_psoc_get_def_params returned NULL"); 345 return QDF_STATUS_E_NULL_VALUE; 346 } 347 348 scan_params->max_active_scans_allowed = max_active_scans; 349 350 return QDF_STATUS_SUCCESS; 351 } 352