Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Prashanth Bhatta | 98f04d2 | 2016-01-08 16:46:21 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * DOC: wlan_hdd_ftm.c |
| 30 | * |
| 31 | * This file contains the WLAN factory test mode implementation |
| 32 | */ |
| 33 | |
| 34 | #include <cds_mq.h> |
| 35 | #include "cds_sched.h" |
| 36 | #include <cds_api.h> |
| 37 | #include "sir_types.h" |
| 38 | #include "cdf_types.h" |
| 39 | #include "sir_api.h" |
| 40 | #include "sir_mac_prot_def.h" |
| 41 | #include "sme_api.h" |
| 42 | #include "mac_init_api.h" |
| 43 | #include "wlan_qct_sys.h" |
| 44 | #include "wlan_hdd_misc.h" |
| 45 | #include "i_cds_packet.h" |
| 46 | #include "cds_reg_service.h" |
| 47 | #include "wlan_hdd_main.h" |
| 48 | #include "qwlan_version.h" |
| 49 | #include "wma_types.h" |
| 50 | #include "cfg_api.h" |
| 51 | |
| 52 | #if defined(QCA_WIFI_FTM) |
| 53 | #include "bmi.h" |
| 54 | #include "ol_fw.h" |
| 55 | #include "wlan_hdd_cfg80211.h" |
| 56 | #include "wlan_hdd_main.h" |
| 57 | #include "hif.h" |
| 58 | #endif |
| 59 | |
| 60 | #define HDD_FTM_WMA_PRE_START_TIMEOUT (30000) /* 30 seconds */ |
| 61 | |
| 62 | #if defined(QCA_WIFI_FTM) |
| 63 | #if defined(LINUX_QCMBR) |
| 64 | #define ATH_XIOCTL_UNIFIED_UTF_CMD 0x1000 |
| 65 | #define ATH_XIOCTL_UNIFIED_UTF_RSP 0x1001 |
| 66 | #define MAX_UTF_LENGTH 1024 |
| 67 | typedef struct qcmbr_data_s { |
| 68 | unsigned int cmd; |
| 69 | unsigned int length; |
| 70 | unsigned char buf[MAX_UTF_LENGTH + 4]; |
| 71 | unsigned int copy_to_user; |
| 72 | } qcmbr_data_t; |
| 73 | typedef struct qcmbr_queue_s { |
| 74 | unsigned char utf_buf[MAX_UTF_LENGTH + 4]; |
| 75 | struct list_head list; |
| 76 | } qcmbr_queue_t; |
| 77 | LIST_HEAD(qcmbr_queue_head); |
| 78 | DEFINE_SPINLOCK(qcmbr_queue_lock); |
| 79 | #endif |
| 80 | #endif |
| 81 | |
| 82 | /** |
| 83 | * wlan_ftm_postmsg() - Post FTM message |
| 84 | * @cmd_ptr: Pointer to FTM command buffer |
| 85 | * @cmd_len: Length of command in @cmd_ptr |
| 86 | * |
| 87 | * This function is used to send FTM commands to firmware |
| 88 | * |
| 89 | * Return: 0 for success, non zero for failure |
| 90 | */ |
| 91 | static uint32_t wlan_ftm_postmsg(uint8_t *cmd_ptr, uint16_t cmd_len) |
| 92 | { |
| 93 | cds_msg_t ftmMsg; |
| 94 | |
| 95 | ENTER(); |
| 96 | |
| 97 | ftmMsg.type = WMA_FTM_CMD_REQ; |
| 98 | ftmMsg.reserved = 0; |
| 99 | ftmMsg.bodyptr = (uint8_t *) cmd_ptr; |
| 100 | ftmMsg.bodyval = 0; |
| 101 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 102 | if (QDF_STATUS_SUCCESS != cds_mq_post_message(CDF_MODULE_ID_WMA, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 103 | &ftmMsg)) { |
| 104 | hddLog(CDF_TRACE_LEVEL_ERROR, "%s: : Failed to post Msg to HAL", |
| 105 | __func__); |
| 106 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 107 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | EXIT(); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 111 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
| 115 | * wlan_hdd_ftm_update_tgt_cfg() - Update target configuration |
| 116 | * @context: context registered with WMA |
| 117 | * @param: target configuration |
| 118 | * |
| 119 | * This function is registered with WMA via wma_open(), and is |
| 120 | * invoked via callback when target parameters are received |
| 121 | * from firmware. |
| 122 | * |
| 123 | * Return: None |
| 124 | */ |
| 125 | static void wlan_hdd_ftm_update_tgt_cfg(void *context, void *param) |
| 126 | { |
| 127 | hdd_context_t *hdd_ctx = (hdd_context_t *) context; |
| 128 | struct wma_tgt_cfg *cfg = (struct wma_tgt_cfg *)param; |
| 129 | |
| 130 | if (!cdf_is_macaddr_zero(&cfg->hw_macaddr)) { |
| 131 | hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr); |
| 132 | } else { |
| 133 | hddLog(CDF_TRACE_LEVEL_ERROR, |
| 134 | "%s: Invalid MAC passed from target, using MAC from ini file" |
| 135 | MAC_ADDRESS_STR, __func__, |
| 136 | MAC_ADDR_ARRAY(hdd_ctx->config->intfMacAddr[0].bytes)); |
| 137 | } |
| 138 | } |
| 139 | |
Komal Seelam | c11bb22 | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 140 | #ifdef WLAN_FEATURE_LPSS |
| 141 | static inline void hdd_is_lpass_supported(tMacOpenParameters *mac_openParms, |
| 142 | hdd_context_t *hdd_ctx) |
| 143 | { |
| 144 | mac_openParms->is_lpass_enabled = hdd_ctx->config->enable_lpass_support; |
| 145 | } |
| 146 | #else |
| 147 | static inline void hdd_is_lpass_supported(tMacOpenParameters *mac_openParms, |
| 148 | hdd_context_t *hdd_ctx) |
| 149 | { } |
| 150 | #endif |
| 151 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 152 | /** |
| 153 | * wlan_ftm_cds_open() - Open the CDS Module in FTM mode |
| 154 | * @p_cds_context: pointer to the global CDS context |
| 155 | * @hddContextSize: Size of the HDD context to allocate. |
| 156 | * |
| 157 | * The wlan_ftm_cds_open() function opens the CDF Scheduler |
| 158 | * Upon successful initialization: |
| 159 | * - All CDS submodules should have been initialized |
| 160 | * - The CDS scheduler should have opened |
| 161 | * - All the WLAN SW components should have been opened. This includes MAC. |
| 162 | * |
| 163 | * Returns: |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 164 | * QDF_STATUS_SUCCESS - Scheduler was successfully initialized and |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 165 | * is ready to be used. |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 166 | * QDF_STATUS_E_RESOURCES - System resources (other than memory) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 167 | * are unavailable to initialize the scheduler |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 168 | * QDF_STATUS_E_FAILURE - Failure to initialize the scheduler |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 169 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 170 | static QDF_STATUS wlan_ftm_cds_open(v_CONTEXT_t p_cds_context, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 171 | uint32_t hddContextSize) |
| 172 | { |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 173 | QDF_STATUS vStatus = QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 174 | int iter = 0; |
| 175 | tSirRetStatus sirStatus = eSIR_SUCCESS; |
| 176 | tMacOpenParameters mac_openParms; |
| 177 | p_cds_contextType gp_cds_context = (p_cds_contextType) p_cds_context; |
| 178 | #if defined(QCA_WIFI_FTM) |
| 179 | cdf_device_t cdf_ctx; |
| 180 | HTC_INIT_INFO htcInfo; |
| 181 | void *pHifContext = NULL; |
| 182 | void *pHtcContext = NULL; |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 183 | struct ol_context *ol_ctx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 184 | #endif |
| 185 | hdd_context_t *hdd_ctx; |
| 186 | |
| 187 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_INFO_HIGH, |
| 188 | "%s: Opening CDS", __func__); |
| 189 | |
| 190 | if (NULL == gp_cds_context) { |
| 191 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 192 | "%s: Trying to open CDS without a PreOpen", __func__); |
| 193 | CDF_ASSERT(0); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 194 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* Initialize the probe event */ |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 198 | if (qdf_event_create(&gp_cds_context->ProbeEvent) != QDF_STATUS_SUCCESS) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 199 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 200 | "%s: Unable to init probeEvent", __func__); |
| 201 | CDF_ASSERT(0); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 202 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 205 | if (qdf_event_create(&(gp_cds_context->wmaCompleteEvent)) != |
| 206 | QDF_STATUS_SUCCESS) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 207 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 208 | "%s: Unable to init wmaCompleteEvent", __func__); |
| 209 | CDF_ASSERT(0); |
| 210 | |
| 211 | goto err_probe_event; |
| 212 | } |
| 213 | |
| 214 | /* Initialize the free message queue */ |
| 215 | vStatus = cds_mq_init(&gp_cds_context->freeVosMq); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 216 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 217 | |
| 218 | /* Critical Error ... Cannot proceed further */ |
| 219 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 220 | "%s: Failed to initialize CDS free message queue %d", |
| 221 | __func__, vStatus); |
| 222 | CDF_ASSERT(0); |
| 223 | goto err_wma_complete_event; |
| 224 | } |
| 225 | |
| 226 | for (iter = 0; iter < CDS_CORE_MAX_MESSAGES; iter++) { |
| 227 | (gp_cds_context->aMsgWrappers[iter]).pVosMsg = |
| 228 | &(gp_cds_context->aMsgBuffers[iter]); |
| 229 | INIT_LIST_HEAD(&gp_cds_context->aMsgWrappers[iter].msgNode); |
| 230 | cds_mq_put(&gp_cds_context->freeVosMq, |
| 231 | &(gp_cds_context->aMsgWrappers[iter])); |
| 232 | } |
| 233 | |
| 234 | /* Now Open the CDS Scheduler */ |
| 235 | vStatus = cds_sched_open(gp_cds_context, &gp_cds_context->cdf_sched, |
| 236 | sizeof(cds_sched_context)); |
| 237 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 238 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 239 | /* Critical Error ... Cannot proceed further */ |
| 240 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 241 | "%s: Failed to open CDS Scheduler %d", __func__, |
| 242 | vStatus); |
| 243 | CDF_ASSERT(0); |
| 244 | goto err_msg_queue; |
| 245 | } |
| 246 | #if defined(QCA_WIFI_FTM) |
| 247 | /* Initialize BMI and Download firmware */ |
| 248 | pHifContext = cds_get_context(CDF_MODULE_ID_HIF); |
| 249 | if (!pHifContext) { |
| 250 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_FATAL, |
| 251 | "%s: failed to get HIF context", __func__); |
| 252 | goto err_sched_close; |
| 253 | } |
| 254 | |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 255 | ol_ctx = cds_get_context(CDF_MODULE_ID_BMI); |
| 256 | if (bmi_download_firmware(ol_ctx)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 257 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_FATAL, |
| 258 | "%s: BMI failed to download target", __func__); |
| 259 | goto err_bmi_close; |
| 260 | } |
Komal Seelam | 0863349 | 2016-02-24 18:05:07 +0530 | [diff] [blame] | 261 | |
| 262 | htcInfo.pContext = ol_ctx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 263 | htcInfo.TargetFailure = ol_target_failure; |
| 264 | htcInfo.TargetSendSuspendComplete = wma_target_suspend_acknowledge; |
| 265 | cdf_ctx = cds_get_context(CDF_MODULE_ID_CDF_DEVICE); |
| 266 | |
| 267 | /* Create HTC */ |
| 268 | gp_cds_context->htc_ctx = |
Komal Seelam | 0863349 | 2016-02-24 18:05:07 +0530 | [diff] [blame] | 269 | htc_create(pHifContext, &htcInfo, cdf_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 270 | if (!gp_cds_context->htc_ctx) { |
| 271 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_FATAL, |
| 272 | "%s: Failed to Create HTC", __func__); |
| 273 | goto err_bmi_close; |
| 274 | } |
| 275 | |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 276 | if (bmi_done(ol_ctx)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 277 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_FATAL, |
| 278 | "%s: Failed to complete BMI phase", __func__); |
| 279 | goto err_htc_close; |
| 280 | } |
| 281 | #endif /* QCA_WIFI_FTM */ |
| 282 | |
| 283 | /*Open the WMA module */ |
| 284 | cdf_mem_set(&mac_openParms, sizeof(mac_openParms), 0); |
| 285 | mac_openParms.driverType = eDRIVER_TYPE_MFG; |
| 286 | |
| 287 | hdd_ctx = (hdd_context_t *) (gp_cds_context->pHDDContext); |
| 288 | if ((NULL == hdd_ctx) || (NULL == hdd_ctx->config)) { |
| 289 | /* Critical Error ... Cannot proceed further */ |
| 290 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 291 | "%s: Hdd Context is Null", __func__); |
| 292 | CDF_ASSERT(0); |
| 293 | goto err_htc_close; |
| 294 | } |
| 295 | |
| 296 | mac_openParms.powersaveOffloadEnabled = |
| 297 | hdd_ctx->config->enablePowersaveOffload; |
| 298 | |
Komal Seelam | c11bb22 | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 299 | hdd_is_lpass_supported(&mac_openParms, hdd_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 300 | |
| 301 | vStatus = wma_open(gp_cds_context, |
| 302 | wlan_hdd_ftm_update_tgt_cfg, NULL, &mac_openParms); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 303 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 304 | /* Critical Error ... Cannot proceed further */ |
| 305 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 306 | "%s: Failed to open WMA module %d", __func__, |
| 307 | vStatus); |
| 308 | CDF_ASSERT(0); |
| 309 | goto err_htc_close; |
| 310 | } |
| 311 | #if defined(QCA_WIFI_FTM) |
Komal Seelam | ec702b0 | 2016-02-24 18:42:16 +0530 | [diff] [blame] | 312 | hdd_update_config(hdd_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 313 | |
| 314 | pHtcContext = cds_get_context(CDF_MODULE_ID_HTC); |
| 315 | if (!pHtcContext) { |
| 316 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_FATAL, |
| 317 | "%s: failed to get HTC context", __func__); |
| 318 | goto err_wma_close; |
| 319 | } |
| 320 | if (htc_wait_target(pHtcContext)) { |
| 321 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_FATAL, |
| 322 | "%s: Failed to complete BMI phase", __func__); |
| 323 | goto err_wma_close; |
| 324 | } |
| 325 | #endif |
| 326 | |
| 327 | /* Now proceed to open the MAC */ |
| 328 | |
| 329 | /* UMA is supported in hardware for performing the |
| 330 | * frame translation 802.11 <-> 802.3 |
| 331 | */ |
| 332 | mac_openParms.frameTransRequired = 1; |
| 333 | |
| 334 | sirStatus = |
| 335 | mac_open(&(gp_cds_context->pMACContext), |
| 336 | gp_cds_context->pHDDContext, |
| 337 | &mac_openParms); |
| 338 | |
| 339 | if (eSIR_SUCCESS != sirStatus) { |
| 340 | /* Critical Error ... Cannot proceed further */ |
| 341 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 342 | "%s: Failed to open MAC %d", __func__, sirStatus); |
| 343 | CDF_ASSERT(0); |
| 344 | goto err_wma_close; |
| 345 | } |
| 346 | #ifndef QCA_WIFI_FTM |
| 347 | /* Now proceed to open the SME */ |
| 348 | vStatus = sme_open(gp_cds_context->pMACContext); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 349 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 350 | /* Critical Error ... Cannot proceed further */ |
| 351 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 352 | "%s: Failed to open SME %d", __func__, vStatus); |
| 353 | goto err_mac_close; |
| 354 | } |
| 355 | |
| 356 | vStatus = sme_init_chan_list(gp_cds_context->pMACContext, |
| 357 | hdd_ctx->reg.alpha2, hdd_ctx->reg.cc_src); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 358 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 359 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 360 | "%s: Failed to init sme channel list", __func__); |
| 361 | } else { |
| 362 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_INFO_HIGH, |
| 363 | "%s: CDS successfully Opened", __func__); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 364 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 365 | } |
| 366 | #else |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 367 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 368 | #endif |
| 369 | |
| 370 | #ifndef QCA_WIFI_FTM |
| 371 | err_mac_close: |
| 372 | #endif |
| 373 | mac_close(gp_cds_context->pMACContext); |
| 374 | |
| 375 | err_wma_close: |
| 376 | wma_close(gp_cds_context); |
| 377 | |
| 378 | err_htc_close: |
| 379 | #if defined(QCA_WIFI_FTM) |
| 380 | if (gp_cds_context->htc_ctx) { |
| 381 | htc_destroy(gp_cds_context->htc_ctx); |
| 382 | gp_cds_context->htc_ctx = NULL; |
| 383 | } |
| 384 | |
| 385 | err_bmi_close: |
Komal Seelam | 5a6e508 | 2016-02-24 17:59:09 +0530 | [diff] [blame] | 386 | bmi_cleanup(ol_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 387 | #endif /* QCA_WIFI_FTM */ |
| 388 | |
| 389 | err_sched_close: |
| 390 | cds_sched_close(gp_cds_context); |
| 391 | err_msg_queue: |
| 392 | cds_mq_deinit(&gp_cds_context->freeVosMq); |
| 393 | |
| 394 | err_wma_complete_event: |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 395 | qdf_event_destroy(&gp_cds_context->wmaCompleteEvent); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 396 | |
| 397 | err_probe_event: |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 398 | qdf_event_destroy(&gp_cds_context->ProbeEvent); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 399 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 400 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 401 | |
| 402 | } /* wlan_ftm_cds_open() */ |
| 403 | |
| 404 | /** |
| 405 | * wlan_ftm_cds_close() - Close the CDF Module in FTM mode |
| 406 | * @cds_context: context of cds |
| 407 | * |
| 408 | * The wlan_ftm_cds_close() function closes the CDF Module |
| 409 | * |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 410 | * Return: QDF_STATUS_SUCCESS - successfully closed |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 411 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 412 | static QDF_STATUS wlan_ftm_cds_close(v_CONTEXT_t cds_context) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 413 | { |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 414 | QDF_STATUS qdf_status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 415 | p_cds_contextType gp_cds_context = (p_cds_contextType) cds_context; |
| 416 | |
| 417 | #ifndef QCA_WIFI_FTM |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 418 | qdf_status = sme_close(((p_cds_contextType) cds_context)->pMACContext); |
| 419 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 420 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 421 | "%s: Failed to close SME %d", __func__, qdf_status); |
| 422 | CDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 423 | } |
| 424 | #endif |
| 425 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 426 | qdf_status = mac_close(((p_cds_contextType) cds_context)->pMACContext); |
| 427 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 428 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 429 | "%s: Failed to close MAC %d", __func__, qdf_status); |
| 430 | CDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | ((p_cds_contextType) cds_context)->pMACContext = NULL; |
| 434 | |
| 435 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 436 | qdf_status = wma_close(cds_context); |
| 437 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 438 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 439 | "%s: Failed to close WMA %d", __func__, qdf_status); |
| 440 | CDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 441 | } |
| 442 | #if defined(QCA_WIFI_FTM) |
| 443 | if (gp_cds_context->htc_ctx) { |
| 444 | htc_stop(gp_cds_context->htc_ctx); |
| 445 | htc_destroy(gp_cds_context->htc_ctx); |
| 446 | gp_cds_context->htc_ctx = NULL; |
| 447 | } |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 448 | qdf_status = wma_wmi_service_close(cds_context); |
| 449 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 450 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 451 | "%s: Failed to close wma_wmi_service", __func__); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 452 | CDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | hif_disable_isr(gp_cds_context->pHIFContext); |
| 456 | #endif |
| 457 | |
| 458 | cds_mq_deinit(&((p_cds_contextType) cds_context)->freeVosMq); |
| 459 | |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 460 | qdf_status = qdf_event_destroy(&gp_cds_context->ProbeEvent); |
| 461 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 462 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 463 | "%s: Failed to destroy ProbeEvent %d", __func__, |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 464 | qdf_status); |
| 465 | CDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 466 | } |
| 467 | |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 468 | qdf_status = qdf_event_destroy(&gp_cds_context->wmaCompleteEvent); |
| 469 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 470 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 471 | "%s: Failed to destroy wmaCompleteEvent %d", __func__, |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 472 | qdf_status); |
| 473 | CDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 476 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
| 480 | * cds_ftm_pre_start() - Pre-start CDS Module in FTM Mode |
| 481 | * @cds_context: The CDS context |
| 482 | * |
| 483 | * The cds_ftm_pre_start() function performs all pre-start activities |
| 484 | * in FTM mode. |
| 485 | * |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 486 | * Return: QDF_STATUS_SUCCESS if pre-start was successful, an |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 487 | * appropriate CDF_STATUS_E_* error code otherwise |
| 488 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 489 | static QDF_STATUS cds_ftm_pre_start(v_CONTEXT_t cds_context) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 490 | { |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 491 | QDF_STATUS vStatus = QDF_STATUS_SUCCESS; |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 492 | QDF_STATUS qdf_status = QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 493 | p_cds_contextType p_cds_context = (p_cds_contextType) cds_context; |
| 494 | #if defined(QCA_WIFI_FTM) |
| 495 | p_cds_contextType gp_cds_context = |
| 496 | cds_get_global_context(); |
| 497 | #endif |
| 498 | |
| 499 | CDF_TRACE(CDF_MODULE_ID_SYS, CDF_TRACE_LEVEL_INFO, "cds prestart"); |
| 500 | if (NULL == p_cds_context->pWMAContext) { |
| 501 | CDF_ASSERT(0); |
| 502 | CDF_TRACE(CDF_MODULE_ID_SYS, CDF_TRACE_LEVEL_ERROR, |
| 503 | "%s: WMA NULL context", __func__); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 504 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* Reset WMA wait event */ |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 508 | qdf_event_reset(&p_cds_context->wmaCompleteEvent); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 509 | |
| 510 | /*call WMA pre start */ |
| 511 | vStatus = wma_pre_start(p_cds_context); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 512 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 513 | CDF_TRACE(CDF_MODULE_ID_SYS, CDF_TRACE_LEVEL_ERROR, |
| 514 | "Failed to WMA prestart "); |
| 515 | CDF_ASSERT(0); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 516 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | /* Need to update time out of complete */ |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 520 | qdf_status = qdf_wait_single_event(&p_cds_context->wmaCompleteEvent, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 521 | HDD_FTM_WMA_PRE_START_TIMEOUT); |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 522 | if (qdf_status != QDF_STATUS_SUCCESS) { |
| 523 | if (qdf_status == QDF_STATUS_E_TIMEOUT) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 524 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 525 | "%s: Timeout occurred before WMA complete", |
| 526 | __func__); |
| 527 | } else { |
| 528 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 529 | "%s: wma_pre_start reporting other error", |
| 530 | __func__); |
| 531 | } |
| 532 | CDF_ASSERT(0); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 533 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 534 | } |
| 535 | #if defined(QCA_WIFI_FTM) |
| 536 | vStatus = htc_start(gp_cds_context->htc_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 537 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 538 | CDF_TRACE(CDF_MODULE_ID_SYS, CDF_TRACE_LEVEL_FATAL, |
| 539 | "Failed to Start HTC"); |
| 540 | CDF_ASSERT(0); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 541 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 542 | } |
| 543 | wma_wait_for_ready_event(gp_cds_context->pWMAContext); |
| 544 | #endif /* QCA_WIFI_FTM */ |
| 545 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 546 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /** |
| 550 | * wlan_hdd_ftm_open() - Open HDD in FTM Mode |
| 551 | * @hdd_ctx: global HDD context |
| 552 | * |
| 553 | * The function hdd_wlan_startup calls this function to initialize the |
| 554 | * FTM specific modules. |
| 555 | * |
| 556 | * Return: 0 on success, non-zero on error |
| 557 | */ |
| 558 | int wlan_hdd_ftm_open(hdd_context_t *hdd_ctx) |
| 559 | { |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 560 | QDF_STATUS vStatus = QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 561 | p_cds_contextType p_cds_context = NULL; |
| 562 | |
| 563 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_INFO_HIGH, |
| 564 | "%s: Opening CDS", __func__); |
| 565 | |
| 566 | p_cds_context = cds_get_global_context(); |
| 567 | |
| 568 | if (NULL == p_cds_context) { |
| 569 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_ERROR, |
| 570 | "%s: Trying to open CDS without a PreOpen", __func__); |
| 571 | CDF_ASSERT(0); |
| 572 | goto err_cdf_status_failure; |
| 573 | } |
| 574 | |
| 575 | vStatus = wlan_ftm_cds_open(p_cds_context, 0); |
| 576 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 577 | if (!QDF_IS_STATUS_SUCCESS(vStatus)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 578 | hddLog(CDF_TRACE_LEVEL_FATAL, "%s: cds_open failed", __func__); |
| 579 | goto err_cdf_status_failure; |
| 580 | } |
| 581 | |
| 582 | /* |
| 583 | * only needed to start WMA, which happens in wlan_hdd_ftm_start() |
| 584 | */ |
| 585 | |
| 586 | /* Save the hal context in Adapter */ |
| 587 | hdd_ctx->hHal = |
| 588 | (tHalHandle) cds_get_context(CDF_MODULE_ID_SME); |
| 589 | |
| 590 | if (NULL == hdd_ctx->hHal) { |
| 591 | hddLog(CDF_TRACE_LEVEL_ERROR, "%s: HAL context is null", |
| 592 | __func__); |
| 593 | goto err_ftm_close; |
| 594 | } |
| 595 | |
| 596 | return 0; |
| 597 | |
| 598 | err_ftm_close: |
| 599 | wlan_ftm_cds_close(p_cds_context); |
| 600 | |
| 601 | err_cdf_status_failure: |
| 602 | return -EPERM; |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * hdd_ftm_service_registration() - Register FTM service |
| 607 | * @hdd_ctx: global HDD context |
| 608 | * |
| 609 | * Return: 0 on success, non-zero on failure |
| 610 | */ |
| 611 | static int hdd_ftm_service_registration(hdd_context_t *hdd_ctx) |
| 612 | { |
| 613 | hdd_adapter_t *adapter; |
| 614 | adapter = hdd_open_adapter(hdd_ctx, WLAN_HDD_FTM, "wlan%d", |
| 615 | wlan_hdd_get_intf_addr(hdd_ctx), false); |
| 616 | if (NULL == adapter) { |
| 617 | hddLog(CDF_TRACE_LEVEL_ERROR, "%s: hdd_open_adapter failed", |
| 618 | __func__); |
| 619 | goto err_adapter_open_failure; |
| 620 | } |
| 621 | |
| 622 | hdd_ctx->ftm.ftm_state = WLAN_FTM_INITIALIZED; |
| 623 | |
| 624 | return 0; |
| 625 | |
| 626 | err_adapter_open_failure: |
| 627 | |
| 628 | return -EPERM; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * wlan_ftm_stop() - Stop HDD in FTM mode |
| 633 | * @hdd_ctx: pointer to HDD context |
| 634 | * |
| 635 | * This function stops the following modules |
Varun Reddy Yeturu | 08efa3a | 2015-11-03 16:59:57 -0800 | [diff] [blame] | 636 | * WMA |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 637 | * |
| 638 | * Return: 0 on success, non-zero on failure |
| 639 | */ |
| 640 | static int wlan_ftm_stop(hdd_context_t *hdd_ctx) |
| 641 | { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 642 | if (hdd_ctx->ftm.ftm_state != WLAN_FTM_STARTED) { |
Varun Reddy Yeturu | 08efa3a | 2015-11-03 16:59:57 -0800 | [diff] [blame] | 643 | hddLog(LOGP, FL("FTM has not started. No need to stop")); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 644 | return -EPERM; |
| 645 | } |
Varun Reddy Yeturu | 08efa3a | 2015-11-03 16:59:57 -0800 | [diff] [blame] | 646 | wma_stop(hdd_ctx->pcds_context, HAL_STOP_TYPE_RF_KILL); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * wlan_hdd_ftm_close() - Close HDD in FTM mode |
| 652 | * @hdd_ctx: pointer to HDD context |
| 653 | * |
| 654 | * Return: 0 on success, non-zero on failure |
| 655 | */ |
| 656 | int wlan_hdd_ftm_close(hdd_context_t *hdd_ctx) |
| 657 | { |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 658 | QDF_STATUS qdf_status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 659 | v_CONTEXT_t cds_context = hdd_ctx->pcds_context; |
| 660 | |
| 661 | hdd_adapter_t *adapter = hdd_get_adapter(hdd_ctx, WLAN_HDD_FTM); |
| 662 | ENTER(); |
| 663 | if (adapter == NULL) { |
| 664 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_FATAL, |
| 665 | "%s:adapter is NULL", __func__); |
| 666 | return -ENXIO; |
| 667 | } |
| 668 | |
| 669 | if (WLAN_FTM_STARTED == hdd_ctx->ftm.ftm_state) { |
| 670 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_FATAL, |
| 671 | "%s: Ftm has been started. stopping ftm", __func__); |
| 672 | wlan_ftm_stop(hdd_ctx); |
| 673 | } |
| 674 | |
Prashanth Bhatta | 98f04d2 | 2016-01-08 16:46:21 -0800 | [diff] [blame] | 675 | hdd_close_all_adapters(hdd_ctx, false); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 676 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 677 | qdf_status = cds_sched_close(cds_context); |
| 678 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 679 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 680 | "%s: Failed to close CDS Scheduler", __func__); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 681 | CDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 682 | } |
| 683 | /* Close CDS */ |
| 684 | wlan_ftm_cds_close(cds_context); |
| 685 | |
| 686 | #if defined(QCA_WIFI_FTM) && defined(LINUX_QCMBR) |
| 687 | spin_lock_bh(&qcmbr_queue_lock); |
| 688 | if (!list_empty(&qcmbr_queue_head)) { |
| 689 | qcmbr_queue_t *msg_buf, *tmp_buf; |
| 690 | list_for_each_entry_safe(msg_buf, tmp_buf, &qcmbr_queue_head, |
| 691 | list) { |
| 692 | list_del(&msg_buf->list); |
| 693 | kfree(msg_buf); |
| 694 | } |
| 695 | } |
| 696 | spin_unlock_bh(&qcmbr_queue_lock); |
| 697 | #endif |
| 698 | |
| 699 | return 0; |
| 700 | |
| 701 | } |
| 702 | |
| 703 | |
| 704 | /** |
| 705 | * hdd_ftm_mc_process_msg() - Process FTM mailbox message |
| 706 | * @message: FTM response message |
| 707 | * |
| 708 | * Process FTM mailbox message |
| 709 | * |
| 710 | * Return: void |
| 711 | */ |
| 712 | static void hdd_ftm_mc_process_msg(void *message) |
| 713 | { |
| 714 | void *data; |
| 715 | uint32_t data_len; |
| 716 | |
| 717 | if (!message) { |
| 718 | hdd_err("Message is NULL, nothing to process."); |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | data_len = *((uint32_t *) message); |
| 723 | data = (uint32_t *) message + 1; |
| 724 | |
| 725 | #if defined(LINUX_QCMBR) |
| 726 | wlanqcmbr_mc_process_msg(message); |
| 727 | #else |
| 728 | #ifdef CONFIG_NL80211_TESTMODE |
| 729 | wlan_hdd_testmode_rx_event(data, (size_t) data_len); |
| 730 | #endif |
| 731 | #endif |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * wlan_hdd_ftm_start() - Start HDD in FTM mode |
| 737 | * @hdd_ctx: Global HDD context |
| 738 | * |
| 739 | * This function starts the following modules. |
| 740 | * 1) WMA Start. |
| 741 | * 2) HTC Start. |
| 742 | * 3) MAC Start to download the firmware. |
| 743 | * |
| 744 | * Return: 0 for success, non zero for failure |
| 745 | */ |
| 746 | static int wlan_hdd_ftm_start(hdd_context_t *hdd_ctx) |
| 747 | { |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 748 | QDF_STATUS vStatus = QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 749 | p_cds_contextType p_cds_context = |
| 750 | (p_cds_contextType) (hdd_ctx->pcds_context); |
| 751 | |
| 752 | if (WLAN_FTM_STARTED == hdd_ctx->ftm.ftm_state) { |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_INFO, |
| 757 | "%s: Starting CLD SW", __func__); |
| 758 | |
| 759 | /* We support only one instance for now ... */ |
| 760 | if (p_cds_context == NULL) { |
| 761 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_ERROR, |
| 762 | "%s: mismatch in context", __func__); |
| 763 | goto err_status_failure; |
| 764 | } |
| 765 | |
| 766 | if (p_cds_context->pMACContext == NULL) { |
| 767 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_ERROR, |
| 768 | "%s: MAC NULL context", __func__); |
| 769 | goto err_status_failure; |
| 770 | } |
| 771 | |
| 772 | /* Vos preStart is calling */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 773 | if (!QDF_IS_STATUS_SUCCESS(cds_ftm_pre_start(hdd_ctx->pcds_context))) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 774 | hddLog(CDF_TRACE_LEVEL_FATAL, "%s: cds_pre_enable failed", |
| 775 | __func__); |
| 776 | goto err_status_failure; |
| 777 | } |
| 778 | |
| 779 | sme_register_ftm_msg_processor(hdd_ctx->hHal, hdd_ftm_mc_process_msg); |
| 780 | |
| 781 | vStatus = wma_start(p_cds_context); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 782 | if (vStatus != QDF_STATUS_SUCCESS) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 783 | CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR, |
| 784 | "%s: Failed to start WMA", __func__); |
| 785 | goto err_status_failure; |
| 786 | } |
| 787 | |
| 788 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_INFO, |
| 789 | "%s: MAC correctly started", __func__); |
| 790 | |
| 791 | if (hdd_ftm_service_registration(hdd_ctx)) { |
| 792 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_ERROR, |
| 793 | "%s: failed", __func__); |
| 794 | goto err_ftm_service_reg; |
| 795 | } |
| 796 | |
| 797 | hdd_ctx->ftm.ftm_state = WLAN_FTM_STARTED; |
| 798 | |
| 799 | return 0; |
| 800 | |
| 801 | err_ftm_service_reg: |
| 802 | wlan_hdd_ftm_close(hdd_ctx); |
| 803 | |
| 804 | err_status_failure: |
| 805 | |
| 806 | return -EPERM; |
| 807 | |
| 808 | } |
| 809 | |
| 810 | #if defined(QCA_WIFI_FTM) |
| 811 | /** |
| 812 | * hdd_ftm_start() - Start HDD in FTM mode |
| 813 | * @hdd_ctx: Global HDD context |
| 814 | * |
| 815 | * Return: 0 for success, non zero for failure |
| 816 | */ |
| 817 | int hdd_ftm_start(hdd_context_t *hdd_ctx) |
| 818 | { |
| 819 | return wlan_hdd_ftm_start(hdd_ctx); |
| 820 | } |
| 821 | #endif |
| 822 | |
| 823 | #if defined(QCA_WIFI_FTM) |
| 824 | /** |
| 825 | * hdd_ftm_stop() - Stop HDD in FTM mode |
| 826 | * @hdd_ctx: Global HDD context |
| 827 | * |
| 828 | * Return: 0 for success, non zero for failure |
| 829 | */ |
| 830 | int hdd_ftm_stop(hdd_context_t *hdd_ctx) |
| 831 | { |
| 832 | return wlan_ftm_stop(hdd_ctx); |
| 833 | } |
| 834 | #endif |
| 835 | |
| 836 | #if defined(QCA_WIFI_FTM) |
| 837 | #if defined(LINUX_QCMBR) |
| 838 | /** |
| 839 | * wlan_hdd_qcmbr_command() - QCMBR command handler |
| 840 | * @adapter: adapter upon which the command was received |
| 841 | * @pqcmbr_data: QCMBR command |
| 842 | * |
| 843 | * Return: 0 on success, non-zero on error |
| 844 | */ |
| 845 | static int wlan_hdd_qcmbr_command(hdd_adapter_t *adapter, |
| 846 | qcmbr_data_t *pqcmbr_data) |
| 847 | { |
| 848 | int ret = 0; |
| 849 | qcmbr_queue_t *qcmbr_buf = NULL; |
| 850 | |
| 851 | switch (pqcmbr_data->cmd) { |
| 852 | case ATH_XIOCTL_UNIFIED_UTF_CMD: { |
| 853 | pqcmbr_data->copy_to_user = 0; |
| 854 | if (pqcmbr_data->length) { |
| 855 | if (wlan_hdd_ftm_testmode_cmd(pqcmbr_data->buf, |
| 856 | pqcmbr_data-> |
| 857 | length) |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 858 | != QDF_STATUS_SUCCESS) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 859 | ret = -EBUSY; |
| 860 | } else { |
| 861 | ret = 0; |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | break; |
| 866 | |
| 867 | case ATH_XIOCTL_UNIFIED_UTF_RSP: { |
| 868 | pqcmbr_data->copy_to_user = 1; |
| 869 | if (!list_empty(&qcmbr_queue_head)) { |
| 870 | spin_lock_bh(&qcmbr_queue_lock); |
| 871 | qcmbr_buf = list_first_entry(&qcmbr_queue_head, |
| 872 | qcmbr_queue_t, |
| 873 | list); |
| 874 | list_del(&qcmbr_buf->list); |
| 875 | spin_unlock_bh(&qcmbr_queue_lock); |
| 876 | ret = 0; |
| 877 | } else { |
| 878 | ret = -1; |
| 879 | } |
| 880 | |
| 881 | if (!ret) { |
| 882 | memcpy(pqcmbr_data->buf, qcmbr_buf->utf_buf, |
| 883 | (MAX_UTF_LENGTH + 4)); |
| 884 | kfree(qcmbr_buf); |
| 885 | } else { |
| 886 | ret = -EAGAIN; |
| 887 | } |
| 888 | } |
| 889 | break; |
| 890 | } |
| 891 | |
| 892 | return ret; |
| 893 | } |
| 894 | |
| 895 | #ifdef CONFIG_COMPAT |
| 896 | /** |
| 897 | * wlan_hdd_qcmbr_ioctl() - Compatability-mode QCMBR ioctl handler |
| 898 | * @adapter: adapter upon which the ioctl was received |
| 899 | * @ifr: the ioctl request |
| 900 | * |
| 901 | * Return: 0 on success, non-zero on error |
| 902 | */ |
| 903 | static int wlan_hdd_qcmbr_compat_ioctl(hdd_adapter_t *adapter, |
| 904 | struct ifreq *ifr) |
| 905 | { |
| 906 | qcmbr_data_t *qcmbr_data; |
| 907 | int ret = 0; |
| 908 | |
| 909 | qcmbr_data = kzalloc(sizeof(qcmbr_data_t), GFP_KERNEL); |
| 910 | if (qcmbr_data == NULL) |
| 911 | return -ENOMEM; |
| 912 | |
| 913 | if (copy_from_user(qcmbr_data, ifr->ifr_data, sizeof(*qcmbr_data))) { |
| 914 | ret = -EFAULT; |
| 915 | goto exit; |
| 916 | } |
| 917 | |
| 918 | ret = wlan_hdd_qcmbr_command(adapter, qcmbr_data); |
| 919 | if (qcmbr_data->copy_to_user) { |
| 920 | ret = copy_to_user(ifr->ifr_data, qcmbr_data->buf, |
| 921 | (MAX_UTF_LENGTH + 4)); |
| 922 | } |
| 923 | |
| 924 | exit: |
| 925 | kfree(qcmbr_data); |
| 926 | return ret; |
| 927 | } |
| 928 | #else /* CONFIG_COMPAT */ |
| 929 | static int wlan_hdd_qcmbr_compat_ioctl(hdd_adapter_t *adapter, |
| 930 | struct ifreq *ifr) |
| 931 | { |
| 932 | return 0; |
| 933 | } |
| 934 | #endif /* CONFIG_COMPAT */ |
| 935 | |
| 936 | /** |
| 937 | * wlan_hdd_qcmbr_ioctl() - Standard QCMBR ioctl handler |
| 938 | * @adapter: adapter upon which the ioctl was received |
| 939 | * @ifr: the ioctl request |
| 940 | * |
| 941 | * Return: 0 on success, non-zero on error |
| 942 | */ |
| 943 | static int wlan_hdd_qcmbr_ioctl(hdd_adapter_t *adapter, struct ifreq *ifr) |
| 944 | { |
| 945 | qcmbr_data_t *qcmbr_data; |
| 946 | int ret = 0; |
| 947 | |
| 948 | qcmbr_data = kzalloc(sizeof(qcmbr_data_t), GFP_KERNEL); |
| 949 | if (qcmbr_data == NULL) |
| 950 | return -ENOMEM; |
| 951 | |
| 952 | if (copy_from_user(qcmbr_data, ifr->ifr_data, sizeof(*qcmbr_data))) { |
| 953 | ret = -EFAULT; |
| 954 | goto exit; |
| 955 | } |
| 956 | |
| 957 | ret = wlan_hdd_qcmbr_command(adapter, qcmbr_data); |
| 958 | if (qcmbr_data->copy_to_user) { |
| 959 | ret = copy_to_user(ifr->ifr_data, qcmbr_data->buf, |
| 960 | (MAX_UTF_LENGTH + 4)); |
| 961 | } |
| 962 | |
| 963 | exit: |
| 964 | kfree(qcmbr_data); |
| 965 | return ret; |
| 966 | } |
| 967 | |
| 968 | /** |
| 969 | * wlan_hdd_qcmbr_unified_ioctl() - Unified QCMBR ioctl handler |
| 970 | * @adapter: adapter upon which the ioctl was received |
| 971 | * @ifr: the ioctl request |
| 972 | * |
| 973 | * Return: 0 on success, non-zero on error |
| 974 | */ |
| 975 | int wlan_hdd_qcmbr_unified_ioctl(hdd_adapter_t *adapter, struct ifreq *ifr) |
| 976 | { |
| 977 | int ret = 0; |
| 978 | |
| 979 | if (is_compat_task()) { |
| 980 | ret = wlan_hdd_qcmbr_compat_ioctl(adapter, ifr); |
| 981 | } else { |
| 982 | ret = wlan_hdd_qcmbr_ioctl(adapter, ifr); |
| 983 | } |
| 984 | |
| 985 | return ret; |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * wlanqcmbr_mc_process_msg() - Process QCMBR response message |
| 990 | * @message: QCMBR message |
| 991 | * |
| 992 | * Return: None |
| 993 | */ |
| 994 | static void wlanqcmbr_mc_process_msg(void *message) |
| 995 | { |
| 996 | qcmbr_queue_t *qcmbr_buf = NULL; |
| 997 | uint32_t data_len; |
| 998 | |
| 999 | data_len = *((uint32_t *) message) + sizeof(uint32_t); |
| 1000 | qcmbr_buf = kzalloc(sizeof(qcmbr_queue_t), GFP_KERNEL); |
| 1001 | if (qcmbr_buf != NULL) { |
| 1002 | memcpy(qcmbr_buf->utf_buf, message, data_len); |
| 1003 | spin_lock_bh(&qcmbr_queue_lock); |
| 1004 | list_add_tail(&(qcmbr_buf->list), &qcmbr_queue_head); |
| 1005 | spin_unlock_bh(&qcmbr_queue_lock); |
| 1006 | } |
| 1007 | } |
| 1008 | #endif /*LINUX_QCMBR */ |
| 1009 | |
| 1010 | /** |
| 1011 | * wlan_hdd_ftm_testmode_cmd() - Process FTM testmode command |
| 1012 | * @data: FTM testmode command |
| 1013 | * @len: length of @data |
| 1014 | * |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1015 | * Return: QDF_STATUS_SUCCESS on success, CDF_STATUS_E_* on error |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1016 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1017 | QDF_STATUS wlan_hdd_ftm_testmode_cmd(void *data, int len) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1018 | { |
| 1019 | struct ar6k_testmode_cmd_data *cmd_data; |
| 1020 | |
| 1021 | cmd_data = (struct ar6k_testmode_cmd_data *) |
| 1022 | cdf_mem_malloc(sizeof(*cmd_data)); |
| 1023 | |
| 1024 | if (!cmd_data) { |
| 1025 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_ERROR, |
| 1026 | ("Failed to allocate FTM command data")); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1027 | return QDF_STATUS_E_NOMEM; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | cmd_data->data = cdf_mem_malloc(len); |
| 1031 | |
| 1032 | if (!cmd_data->data) { |
| 1033 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_ERROR, |
| 1034 | ("Failed to allocate FTM command data buffer")); |
| 1035 | cdf_mem_free(cmd_data); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1036 | return QDF_STATUS_E_NOMEM; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | cmd_data->len = len; |
| 1040 | cdf_mem_copy(cmd_data->data, data, len); |
| 1041 | |
| 1042 | if (wlan_ftm_postmsg((uint8_t *) cmd_data, sizeof(*cmd_data))) { |
| 1043 | cdf_mem_free(cmd_data->data); |
| 1044 | cdf_mem_free(cmd_data); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1045 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1048 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1049 | } |
| 1050 | #endif /*QCA_WIFI_FTM */ |