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 * 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 scm_debug("vdev: %d, type: %d, reason: %d, freq: %d, req: %d, scanid: %d", 232 vdev_id, event->type, event->reason, event->chan_freq, 233 event->requester, event->scan_id); 234 235 event_info->vdev = 236 wlan_objmgr_get_vdev_by_id_from_psoc(psoc, 237 vdev_id, WLAN_SCAN_ID); 238 if (!event_info->vdev) { 239 scm_err("null vdev, vdev_id: %d, psoc: 0x%pK", vdev_id, psoc); 240 return QDF_STATUS_E_INVAL; 241 } 242 msg.bodyptr = event_info; 243 msg.callback = scm_scan_event_handler; 244 msg.flush_callback = scm_scan_event_flush_callback; 245 246 status = scheduler_post_msg(QDF_MODULE_ID_SCAN, &msg); 247 if (QDF_IS_STATUS_ERROR(status)) { 248 wlan_objmgr_vdev_release_ref(event_info->vdev, WLAN_SCAN_ID); 249 } 250 251 return status; 252 } 253 254 QDF_STATUS tgt_scan_bcn_probe_rx_callback(struct wlan_objmgr_psoc *psoc, 255 struct wlan_objmgr_peer *peer, qdf_nbuf_t buf, 256 struct mgmt_rx_event_params *rx_param, 257 enum mgmt_frame_type frm_type) 258 { 259 struct scheduler_msg msg = {0}; 260 struct scan_bcn_probe_event *bcn; 261 QDF_STATUS status; 262 263 if ((frm_type != MGMT_PROBE_RESP) && 264 (frm_type != MGMT_BEACON)) { 265 scm_err("frame is not beacon or probe resp"); 266 qdf_nbuf_free(buf); 267 return QDF_STATUS_E_INVAL; 268 } 269 bcn = qdf_mem_malloc_atomic(sizeof(*bcn)); 270 271 if (!bcn) { 272 scm_err("Failed to allocate memory for bcn"); 273 qdf_nbuf_free(buf); 274 return QDF_STATUS_E_NOMEM; 275 } 276 bcn->rx_data = 277 qdf_mem_malloc_atomic(sizeof(*rx_param)); 278 if (!bcn->rx_data) { 279 scm_err("Failed to allocate memory for rx_data"); 280 qdf_mem_free(bcn); 281 qdf_nbuf_free(buf); 282 return QDF_STATUS_E_NOMEM; 283 } 284 285 if (frm_type == MGMT_PROBE_RESP) 286 bcn->frm_type = MGMT_SUBTYPE_PROBE_RESP; 287 else 288 bcn->frm_type = MGMT_SUBTYPE_BEACON; 289 290 status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_SCAN_ID); 291 if (QDF_IS_STATUS_ERROR(status)) { 292 scm_info("unable to get reference"); 293 qdf_mem_free(bcn->rx_data); 294 qdf_mem_free(bcn); 295 qdf_nbuf_free(buf); 296 return status; 297 } 298 299 bcn->psoc = psoc; 300 bcn->buf = buf; 301 qdf_mem_copy(bcn->rx_data, rx_param, sizeof(*rx_param)); 302 303 msg.bodyptr = bcn; 304 msg.callback = scm_handle_bcn_probe; 305 msg.flush_callback = scm_bcn_probe_flush_callback; 306 307 status = scheduler_post_msg(QDF_MODULE_ID_SCAN, &msg); 308 309 if (!QDF_IS_STATUS_SUCCESS(status)) { 310 wlan_objmgr_psoc_release_ref(psoc, WLAN_SCAN_ID); 311 scm_err("failed to post to QDF_MODULE_ID_SCAN"); 312 qdf_mem_free(bcn->rx_data); 313 qdf_mem_free(bcn); 314 qdf_nbuf_free(buf); 315 } 316 317 return status; 318 } 319 320 QDF_STATUS 321 tgt_scan_set_max_active_scans(struct wlan_objmgr_psoc *psoc, 322 uint32_t max_active_scans) 323 { 324 struct scan_default_params *scan_params = NULL; 325 326 if (!psoc) { 327 scm_err("null psoc"); 328 return QDF_STATUS_E_NULL_VALUE; 329 } 330 331 scan_params = wlan_scan_psoc_get_def_params(psoc); 332 if (!scan_params) { 333 scm_err("wlan_scan_psoc_get_def_params returned NULL"); 334 return QDF_STATUS_E_NULL_VALUE; 335 } 336 337 scan_params->max_active_scans_allowed = max_active_scans; 338 339 return QDF_STATUS_SUCCESS; 340 } 341