1 /* 2 * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved. 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 * 30 * @file wlan_hdd_p2p.c 31 * 32 * @brief WLAN Host Device Driver implementation for P2P commands interface 33 * 34 */ 35 36 #include <wlan_hdd_includes.h> 37 #include <wlan_hdd_hostapd.h> 38 #include <net/cfg80211.h> 39 #include "sme_api.h" 40 #include "sme_qos_api.h" 41 #include "wlan_hdd_p2p.h" 42 #include "sap_api.h" 43 #include "wlan_hdd_main.h" 44 #include "qdf_trace.h" 45 #include <linux/netdevice.h> 46 #include <linux/skbuff.h> 47 #include <linux/etherdevice.h> 48 #include <net/ieee80211_radiotap.h> 49 #include "wlan_hdd_tdls.h" 50 #include "wlan_hdd_trace.h" 51 #include "qdf_types.h" 52 #include "qdf_trace.h" 53 #include "cds_sched.h" 54 #include "cds_concurrency.h" 55 56 /* Ms to Time Unit Micro Sec */ 57 #define MS_TO_TU_MUS(x) ((x) * 1024) 58 #define MAX_MUS_VAL (INT_MAX / 1024) 59 60 static uint8_t *hdd_get_action_string(uint16_t MsgType) 61 { 62 switch (MsgType) { 63 CASE_RETURN_STRING(SIR_MAC_ACTION_SPECTRUM_MGMT); 64 CASE_RETURN_STRING(SIR_MAC_ACTION_QOS_MGMT); 65 CASE_RETURN_STRING(SIR_MAC_ACTION_DLP); 66 CASE_RETURN_STRING(SIR_MAC_ACTION_PUBLIC_USAGE); 67 CASE_RETURN_STRING(SIR_MAC_ACTION_RRM); 68 CASE_RETURN_STRING(SIR_MAC_ACTION_FAST_BSS_TRNST); 69 CASE_RETURN_STRING(SIR_MAC_ACTION_HT); 70 CASE_RETURN_STRING(SIR_MAC_ACTION_SA_QUERY); 71 CASE_RETURN_STRING(SIR_MAC_ACTION_PROT_DUAL_PUB); 72 CASE_RETURN_STRING(SIR_MAC_ACTION_WNM); 73 CASE_RETURN_STRING(SIR_MAC_ACTION_UNPROT_WNM); 74 CASE_RETURN_STRING(SIR_MAC_ACTION_TDLS); 75 CASE_RETURN_STRING(SIR_MAC_ACITON_MESH); 76 CASE_RETURN_STRING(SIR_MAC_ACTION_MHF); 77 CASE_RETURN_STRING(SIR_MAC_SELF_PROTECTED); 78 CASE_RETURN_STRING(SIR_MAC_ACTION_WME); 79 CASE_RETURN_STRING(SIR_MAC_ACTION_VHT); 80 default: 81 return "UNKNOWN"; 82 } 83 } 84 85 #ifdef WLAN_FEATURE_P2P_DEBUG 86 #define MAX_P2P_ACTION_FRAME_TYPE 9 87 const char *p2p_action_frame_type[] = { "GO Negotiation Request", 88 "GO Negotiation Response", 89 "GO Negotiation Confirmation", 90 "P2P Invitation Request", 91 "P2P Invitation Response", 92 "Device Discoverability Request", 93 "Device Discoverability Response", 94 "Provision Discovery Request", 95 "Provision Discovery Response"}; 96 97 /* We no need to protect this variable since 98 * there is no chance of race to condition 99 * and also not make any complicating the code 100 * just for debugging log 101 */ 102 tP2PConnectionStatus global_p2p_connection_status = P2P_NOT_ACTIVE; 103 104 #endif 105 #define MAX_TDLS_ACTION_FRAME_TYPE 11 106 const char *tdls_action_frame_type[] = { "TDLS Setup Request", 107 "TDLS Setup Response", 108 "TDLS Setup Confirm", 109 "TDLS Teardown", 110 "TDLS Peer Traffic Indication", 111 "TDLS Channel Switch Request", 112 "TDLS Channel Switch Response", 113 "TDLS Peer PSM Request", 114 "TDLS Peer PSM Response", 115 "TDLS Peer Traffic Response", 116 "TDLS Discovery Request"}; 117 118 static bool wlan_hdd_is_type_p2p_action(const u8 *buf) 119 { 120 const u8 *ouiPtr; 121 122 if (buf[WLAN_HDD_PUBLIC_ACTION_FRAME_CATEGORY_OFFSET] != 123 WLAN_HDD_PUBLIC_ACTION_FRAME) { 124 return false; 125 } 126 127 if (buf[WLAN_HDD_PUBLIC_ACTION_FRAME_ACTION_OFFSET] != 128 WLAN_HDD_VENDOR_SPECIFIC_ACTION) { 129 return false; 130 } 131 132 ouiPtr = &buf[WLAN_HDD_PUBLIC_ACTION_FRAME_OUI_OFFSET]; 133 134 if (WPA_GET_BE24(ouiPtr) != WLAN_HDD_WFA_OUI) { 135 return false; 136 } 137 138 if (buf[WLAN_HDD_PUBLIC_ACTION_FRAME_OUI_TYPE_OFFSET] != 139 WLAN_HDD_WFA_P2P_OUI_TYPE) { 140 return false; 141 } 142 143 return true; 144 } 145 146 static bool hdd_p2p_is_action_type_rsp(const u8 *buf) 147 { 148 tActionFrmType actionFrmType; 149 150 if (wlan_hdd_is_type_p2p_action(buf)) { 151 actionFrmType = 152 buf[WLAN_HDD_PUBLIC_ACTION_FRAME_SUB_TYPE_OFFSET]; 153 if (actionFrmType != WLAN_HDD_INVITATION_REQ 154 && actionFrmType != WLAN_HDD_GO_NEG_REQ 155 && actionFrmType != WLAN_HDD_DEV_DIS_REQ 156 && actionFrmType != WLAN_HDD_PROV_DIS_REQ) 157 return true; 158 } 159 160 return false; 161 } 162 163 static 164 QDF_STATUS wlan_hdd_remain_on_channel_callback(tHalHandle hHal, void *pCtx, 165 QDF_STATUS status, uint32_t scan_id) 166 { 167 hdd_adapter_t *pAdapter = (hdd_adapter_t *) pCtx; 168 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 169 hdd_remain_on_chan_ctx_t *pRemainChanCtx; 170 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); 171 172 if (!hdd_ctx) { 173 hdd_err("Invalid HDD context"); 174 return QDF_STATUS_E_FAILURE; 175 } 176 177 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 178 pRemainChanCtx = cfgState->remain_on_chan_ctx; 179 180 if (pRemainChanCtx == NULL) { 181 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 182 hdd_warn("No Rem on channel pending for which Rsp is received"); 183 return QDF_STATUS_SUCCESS; 184 } 185 186 hdd_notice("Received remain on channel rsp"); 187 qdf_mc_timer_stop(&pRemainChanCtx->hdd_remain_on_chan_timer); 188 qdf_mc_timer_destroy(&pRemainChanCtx->hdd_remain_on_chan_timer); 189 190 cfgState->remain_on_chan_ctx = NULL; 191 /* 192 * Resetting the roc in progress early ensures that the subsequent 193 * roc requests are immediately processed without being queued 194 */ 195 pAdapter->is_roc_inprogress = false; 196 qdf_runtime_pm_allow_suspend(hdd_ctx->runtime_context.roc); 197 /* 198 * If the allow suspend is done later, the scheduled roc wil prevent 199 * the system from going into suspend and immediately this logic 200 * will allow the system to go to suspend breaking the exising logic. 201 * Basically, the system must not go into suspend while roc is in 202 * progress. 203 */ 204 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 205 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 206 207 if (REMAIN_ON_CHANNEL_REQUEST == pRemainChanCtx->rem_on_chan_request) { 208 if (cfgState->buf) { 209 hdd_info("We need to receive yet an ack from one of tx packet"); 210 } 211 cfg80211_remain_on_channel_expired( 212 pRemainChanCtx->dev-> 213 ieee80211_ptr, 214 pRemainChanCtx-> 215 cookie, 216 &pRemainChanCtx->chan, 217 GFP_KERNEL); 218 pAdapter->last_roc_ts = 219 (uint64_t)qdf_mc_timer_get_system_time(); 220 } 221 222 /* Schedule any pending RoC: Any new roc request during this time 223 * would have got queued in 'wlan_hdd_request_remain_on_channel' 224 * since the queue is not empty. So, the roc at the head of the 225 * queue will only get the priority. Scheduling the work queue 226 * after sending any cancel remain on channel event will also 227 * ensure that the cancel roc is sent without any delays. 228 */ 229 schedule_delayed_work(&hdd_ctx->roc_req_work, 0); 230 231 if ((QDF_STA_MODE == pAdapter->device_mode) || 232 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) || 233 (QDF_P2P_DEVICE_MODE == pAdapter->device_mode) 234 ) { 235 uint8_t sessionId = pAdapter->sessionId; 236 if (REMAIN_ON_CHANNEL_REQUEST == 237 pRemainChanCtx->rem_on_chan_request) { 238 sme_deregister_mgmt_frame(hHal, sessionId, 239 (SIR_MAC_MGMT_FRAME << 2) | 240 (SIR_MAC_MGMT_PROBE_REQ << 4), 241 NULL, 0); 242 } 243 } else if ((QDF_SAP_MODE == pAdapter->device_mode) || 244 (QDF_P2P_GO_MODE == pAdapter->device_mode) 245 ) { 246 wlansap_de_register_mgmt_frame( 247 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), 248 (SIR_MAC_MGMT_FRAME << 2) | 249 (SIR_MAC_MGMT_PROBE_REQ << 4), 250 NULL, 0); 251 252 } 253 254 if (pRemainChanCtx->action_pkt_buff.frame_ptr != NULL 255 && pRemainChanCtx->action_pkt_buff.frame_length != 0) { 256 qdf_mem_free(pRemainChanCtx->action_pkt_buff.frame_ptr); 257 pRemainChanCtx->action_pkt_buff.frame_ptr = NULL; 258 pRemainChanCtx->action_pkt_buff.frame_length = 0; 259 } 260 qdf_mem_free(pRemainChanCtx); 261 complete(&pAdapter->cancel_rem_on_chan_var); 262 if (QDF_STATUS_SUCCESS != status) 263 complete(&pAdapter->rem_on_chan_ready_event); 264 return QDF_STATUS_SUCCESS; 265 } 266 267 void wlan_hdd_cancel_existing_remain_on_channel(hdd_adapter_t *pAdapter) 268 { 269 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 270 hdd_remain_on_chan_ctx_t *pRemainChanCtx; 271 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); 272 unsigned long rc; 273 274 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 275 if (cfgState->remain_on_chan_ctx != NULL) { 276 hdd_err("Cancel Existing Remain on Channel"); 277 278 if (QDF_TIMER_STATE_RUNNING == qdf_mc_timer_get_current_state( 279 &cfgState->remain_on_chan_ctx->hdd_remain_on_chan_timer)) 280 qdf_mc_timer_stop(&cfgState->remain_on_chan_ctx-> 281 hdd_remain_on_chan_timer); 282 283 pRemainChanCtx = cfgState->remain_on_chan_ctx; 284 if (pRemainChanCtx->hdd_remain_on_chan_cancel_in_progress == 285 true) { 286 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 287 hdd_err("ROC timer cancellation in progress wait for completion"); 288 rc = wait_for_completion_timeout(&pAdapter-> 289 cancel_rem_on_chan_var, 290 msecs_to_jiffies 291 (WAIT_CANCEL_REM_CHAN)); 292 if (!rc) { 293 hdd_err("wait on cancel_rem_on_chan_var timed out"); 294 } 295 return; 296 } 297 pRemainChanCtx->hdd_remain_on_chan_cancel_in_progress = true; 298 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 299 /* Wait till remain on channel ready indication before issuing cancel 300 * remain on channel request, otherwise if remain on channel not 301 * received and if the driver issues cancel remain on channel then lim 302 * will be in unknown state. 303 */ 304 rc = wait_for_completion_timeout(&pAdapter-> 305 rem_on_chan_ready_event, 306 msecs_to_jiffies 307 (WAIT_REM_CHAN_READY)); 308 if (!rc) { 309 hdd_err("timeout waiting for remain on channel ready indication"); 310 cds_flush_logs(WLAN_LOG_TYPE_FATAL, 311 WLAN_LOG_INDICATOR_HOST_DRIVER, 312 WLAN_LOG_REASON_HDD_TIME_OUT, 313 true, false); 314 } 315 316 INIT_COMPLETION(pAdapter->cancel_rem_on_chan_var); 317 318 /* Issue abort remain on chan request to sme. 319 * The remain on channel callback will make sure the remain_on_chan 320 * expired event is sent. 321 */ 322 if ((QDF_STA_MODE == pAdapter->device_mode) || 323 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) || 324 (QDF_P2P_DEVICE_MODE == pAdapter->device_mode) 325 ) { 326 sme_cancel_remain_on_channel(WLAN_HDD_GET_HAL_CTX 327 (pAdapter), 328 pAdapter->sessionId, 329 pRemainChanCtx->scan_id); 330 } else if ((QDF_SAP_MODE == pAdapter->device_mode) 331 || (QDF_P2P_GO_MODE == pAdapter->device_mode) 332 ) { 333 wlansap_cancel_remain_on_channel( 334 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), 335 pRemainChanCtx->scan_id); 336 } 337 338 rc = wait_for_completion_timeout(&pAdapter-> 339 cancel_rem_on_chan_var, 340 msecs_to_jiffies 341 (WAIT_CANCEL_REM_CHAN)); 342 343 if (!rc) { 344 hdd_err("timeout waiting for cancel remain on channel ready indication"); 345 } 346 qdf_runtime_pm_allow_suspend(hdd_ctx->runtime_context.roc); 347 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 348 } else 349 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 350 } 351 352 int wlan_hdd_check_remain_on_channel(hdd_adapter_t *pAdapter) 353 { 354 int status = 0; 355 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 356 357 if (QDF_P2P_GO_MODE != pAdapter->device_mode) { 358 /* Cancel Existing Remain On Channel */ 359 /* If no action frame is pending */ 360 if (cfgState->remain_on_chan_ctx != NULL) { 361 /* Check whether Action Frame is pending or not */ 362 if (cfgState->buf == NULL) { 363 wlan_hdd_cancel_existing_remain_on_channel 364 (pAdapter); 365 } else { 366 hdd_notice("Cannot Cancel Existing Remain on Channel"); 367 status = -EBUSY; 368 } 369 } 370 } 371 return status; 372 } 373 374 /** 375 * wlan_hdd_cancel_pending_roc() - Cancel pending roc 376 * @adapter: HDD adapter 377 * 378 * Cancels any pending remain on channel request 379 * 380 * Return: None 381 */ 382 static void wlan_hdd_cancel_pending_roc(hdd_adapter_t *adapter) 383 { 384 hdd_remain_on_chan_ctx_t *roc_ctx; 385 unsigned long rc; 386 hdd_cfg80211_state_t *cfg_state = WLAN_HDD_GET_CFG_STATE_PTR(adapter); 387 388 hdd_err("ROC completion is not received !!!"); 389 390 mutex_lock(&cfg_state->remain_on_chan_ctx_lock); 391 roc_ctx = cfg_state->remain_on_chan_ctx; 392 393 if (roc_ctx->hdd_remain_on_chan_cancel_in_progress) { 394 mutex_unlock(&cfg_state->remain_on_chan_ctx_lock); 395 hdd_debug("roc cancel already in progress"); 396 /* 397 * Since a cancel roc is already issued and is 398 * in progress, we need not send another 399 * cancel roc again. Instead we can just wait 400 * for cancel roc completion 401 */ 402 goto wait; 403 } 404 mutex_unlock(&cfg_state->remain_on_chan_ctx_lock); 405 406 if (adapter->device_mode == QDF_P2P_GO_MODE) { 407 wlansap_cancel_remain_on_channel((WLAN_HDD_GET_CTX 408 (adapter))->pcds_context, 409 cfg_state->remain_on_chan_ctx->scan_id); 410 } else if (adapter->device_mode == QDF_P2P_CLIENT_MODE 411 || adapter->device_mode == 412 QDF_P2P_DEVICE_MODE) { 413 sme_cancel_remain_on_channel(WLAN_HDD_GET_HAL_CTX 414 (adapter), 415 adapter->sessionId, 416 cfg_state->remain_on_chan_ctx->scan_id); 417 } 418 419 wait: 420 rc = wait_for_completion_timeout(&adapter->cancel_rem_on_chan_var, 421 msecs_to_jiffies 422 (WAIT_CANCEL_REM_CHAN)); 423 if (!rc) { 424 hdd_err("Timeout occurred while waiting for RoC Cancellation"); 425 mutex_lock(&cfg_state->remain_on_chan_ctx_lock); 426 roc_ctx = cfg_state->remain_on_chan_ctx; 427 if (roc_ctx != NULL) { 428 cfg_state->remain_on_chan_ctx = NULL; 429 qdf_mc_timer_stop(&roc_ctx->hdd_remain_on_chan_timer); 430 qdf_mc_timer_destroy( 431 &roc_ctx->hdd_remain_on_chan_timer); 432 if (roc_ctx->action_pkt_buff.frame_ptr != NULL 433 && roc_ctx->action_pkt_buff.frame_length != 0) { 434 qdf_mem_free( 435 roc_ctx->action_pkt_buff.frame_ptr); 436 roc_ctx->action_pkt_buff.frame_ptr = NULL; 437 roc_ctx->action_pkt_buff.frame_length = 0; 438 } 439 qdf_mem_free(roc_ctx); 440 adapter->is_roc_inprogress = false; 441 } 442 mutex_unlock(&cfg_state->remain_on_chan_ctx_lock); 443 } 444 } 445 446 /* Clean up RoC context at hdd_stop_adapter*/ 447 void wlan_hdd_cleanup_remain_on_channel_ctx(hdd_adapter_t *pAdapter) 448 { 449 uint8_t retry = 0; 450 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 451 452 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 453 while (pAdapter->is_roc_inprogress) { 454 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 455 hdd_err("ROC in progress for session %d!!!", 456 pAdapter->sessionId); 457 msleep(500); 458 if (retry++ > 3) { 459 wlan_hdd_cancel_pending_roc(pAdapter); 460 /* hold the lock before break from the loop */ 461 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 462 break; 463 } 464 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 465 } /* end of while */ 466 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 467 468 } 469 470 static void wlan_hdd_remain_on_chan_timeout(void *data) 471 { 472 hdd_adapter_t *pAdapter = (hdd_adapter_t *) data; 473 hdd_remain_on_chan_ctx_t *pRemainChanCtx; 474 hdd_cfg80211_state_t *cfgState; 475 hdd_context_t *hdd_ctx; 476 477 if ((NULL == pAdapter) || 478 (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)) { 479 hdd_err("pAdapter is invalid %p !!!", pAdapter); 480 return; 481 } 482 483 hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); 484 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 485 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 486 pRemainChanCtx = cfgState->remain_on_chan_ctx; 487 488 if (NULL == pRemainChanCtx) { 489 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 490 hdd_err("No Remain on channel is pending"); 491 return; 492 } 493 494 if (true == pRemainChanCtx->hdd_remain_on_chan_cancel_in_progress) { 495 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 496 hdd_err("Cancellation already in progress"); 497 return; 498 } 499 500 pRemainChanCtx->hdd_remain_on_chan_cancel_in_progress = true; 501 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 502 hdd_notice("Cancel Remain on Channel on timeout"); 503 504 if ((QDF_STA_MODE == pAdapter->device_mode) || 505 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) || 506 (QDF_P2P_DEVICE_MODE == pAdapter->device_mode) 507 ) { 508 sme_cancel_remain_on_channel(WLAN_HDD_GET_HAL_CTX(pAdapter), 509 pAdapter->sessionId, 510 pRemainChanCtx->scan_id); 511 } else if ((QDF_SAP_MODE == pAdapter->device_mode) || 512 (QDF_P2P_GO_MODE == pAdapter->device_mode) 513 ) { 514 wlansap_cancel_remain_on_channel( 515 (WLAN_HDD_GET_CTX(pAdapter))->pcds_context, 516 pRemainChanCtx->scan_id); 517 } 518 519 qdf_runtime_pm_allow_suspend(hdd_ctx->runtime_context.roc); 520 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 521 } 522 523 static int wlan_hdd_execute_remain_on_channel(hdd_adapter_t *pAdapter, 524 hdd_remain_on_chan_ctx_t *pRemainChanCtx) 525 { 526 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 527 QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE; 528 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter); 529 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL; 530 hdd_adapter_t *pAdapter_temp; 531 QDF_STATUS status; 532 bool isGoPresent = false; 533 unsigned int duration; 534 535 536 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 537 if (pAdapter->is_roc_inprogress == true) { 538 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 539 hdd_err("remain on channel request is in execution"); 540 return -EBUSY; 541 } 542 543 cfgState->remain_on_chan_ctx = pRemainChanCtx; 544 cfgState->current_freq = pRemainChanCtx->chan.center_freq; 545 pAdapter->is_roc_inprogress = true; 546 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 547 548 /* Initialize Remain on chan timer */ 549 qdf_status = 550 qdf_mc_timer_init(&pRemainChanCtx->hdd_remain_on_chan_timer, 551 QDF_TIMER_TYPE_SW, 552 wlan_hdd_remain_on_chan_timeout, pAdapter); 553 if (qdf_status != QDF_STATUS_SUCCESS) { 554 hdd_err("Not able to initialize remain_on_chan timer"); 555 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 556 cfgState->remain_on_chan_ctx = NULL; 557 pAdapter->is_roc_inprogress = false; 558 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 559 qdf_mem_free(pRemainChanCtx); 560 return -EINVAL; 561 } 562 563 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode); 564 while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) { 565 pAdapter_temp = pAdapterNode->pAdapter; 566 if (pAdapter_temp->device_mode == QDF_P2P_GO_MODE) 567 isGoPresent = true; 568 status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext); 569 pAdapterNode = pNext; 570 } 571 572 /* Extending duration for proactive extension logic for RoC */ 573 duration = pRemainChanCtx->duration; 574 if (isGoPresent == true) 575 duration = P2P_ROC_DURATION_MULTIPLIER_GO_PRESENT * duration; 576 else 577 duration = P2P_ROC_DURATION_MULTIPLIER_GO_ABSENT * duration; 578 579 hdd_prevent_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 580 qdf_runtime_pm_prevent_suspend(pHddCtx->runtime_context.roc); 581 INIT_COMPLETION(pAdapter->rem_on_chan_ready_event); 582 583 /* call sme API to start remain on channel. */ 584 if ((QDF_STA_MODE == pAdapter->device_mode) || 585 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) || 586 (QDF_P2P_DEVICE_MODE == pAdapter->device_mode) 587 ) { 588 uint8_t sessionId = pAdapter->sessionId; 589 /* call sme API to start remain on channel. */ 590 591 if (QDF_STATUS_SUCCESS != sme_remain_on_channel( 592 WLAN_HDD_GET_HAL_CTX(pAdapter), 593 sessionId, 594 pRemainChanCtx->chan.hw_value, duration, 595 wlan_hdd_remain_on_channel_callback, 596 pAdapter, 597 (pRemainChanCtx->rem_on_chan_request == 598 REMAIN_ON_CHANNEL_REQUEST) ? true : false, 599 &pRemainChanCtx->scan_id)) { 600 hdd_err("sme_remain_on_channel failed"); 601 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 602 cfgState->remain_on_chan_ctx = NULL; 603 pAdapter->is_roc_inprogress = false; 604 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 605 qdf_mc_timer_destroy( 606 &pRemainChanCtx->hdd_remain_on_chan_timer); 607 qdf_mem_free(pRemainChanCtx); 608 qdf_runtime_pm_allow_suspend(pHddCtx->runtime_context. 609 roc); 610 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 611 return -EINVAL; 612 } 613 614 if (REMAIN_ON_CHANNEL_REQUEST == 615 pRemainChanCtx->rem_on_chan_request) { 616 if (QDF_STATUS_SUCCESS != sme_register_mgmt_frame( 617 WLAN_HDD_GET_HAL_CTX(pAdapter), 618 sessionId, 619 (SIR_MAC_MGMT_FRAME << 2) | 620 (SIR_MAC_MGMT_PROBE_REQ << 4), 621 NULL, 0)) 622 hdd_err("sme_register_mgmt_frame failed"); 623 } 624 625 } else if ((QDF_SAP_MODE == pAdapter->device_mode) || 626 (QDF_P2P_GO_MODE == pAdapter->device_mode)) { 627 /* call sme API to start remain on channel. */ 628 if (QDF_STATUS_SUCCESS != wlansap_remain_on_channel( 629 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), 630 pRemainChanCtx->chan.hw_value, 631 duration, wlan_hdd_remain_on_channel_callback, 632 pAdapter, &pRemainChanCtx->scan_id)) { 633 hdd_err("wlansap_remain_on_channel failed"); 634 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 635 cfgState->remain_on_chan_ctx = NULL; 636 pAdapter->is_roc_inprogress = false; 637 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 638 qdf_mc_timer_destroy( 639 &pRemainChanCtx->hdd_remain_on_chan_timer); 640 qdf_mem_free(pRemainChanCtx); 641 qdf_runtime_pm_allow_suspend(pHddCtx->runtime_context. 642 roc); 643 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 644 return -EINVAL; 645 } 646 647 if (QDF_STATUS_SUCCESS != wlansap_register_mgmt_frame( 648 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), 649 (SIR_MAC_MGMT_FRAME << 2) | 650 (SIR_MAC_MGMT_PROBE_REQ << 4), NULL, 0)) { 651 hdd_err("wlansap_register_mgmt_frame return fail"); 652 wlansap_cancel_remain_on_channel( 653 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), 654 pRemainChanCtx->scan_id); 655 qdf_runtime_pm_allow_suspend(pHddCtx->runtime_context. 656 roc); 657 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 658 return -EINVAL; 659 } 660 661 } 662 return 0; 663 } 664 665 /** 666 * wlan_hdd_roc_request_enqueue() - enqueue remain on channel request 667 * @adapter: Pointer to the adapter 668 * @remain_chan_ctx: Pointer to the remain on channel context 669 * 670 * Return: 0 on success, error number otherwise 671 */ 672 static int wlan_hdd_roc_request_enqueue(hdd_adapter_t *adapter, 673 hdd_remain_on_chan_ctx_t *remain_chan_ctx) 674 { 675 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter); 676 hdd_roc_req_t *hdd_roc_req; 677 QDF_STATUS status; 678 679 /* 680 * "Driver is busy" OR "there is already RoC request inside the queue" 681 * so enqueue this RoC Request and execute sequentially later. 682 */ 683 684 hdd_roc_req = qdf_mem_malloc(sizeof(*hdd_roc_req)); 685 686 if (NULL == hdd_roc_req) { 687 hdd_alert("malloc failed for roc req context"); 688 return -ENOMEM; 689 } 690 691 hdd_roc_req->pAdapter = adapter; 692 hdd_roc_req->pRemainChanCtx = remain_chan_ctx; 693 694 /* Enqueue this RoC request */ 695 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock); 696 status = qdf_list_insert_back(&hdd_ctx->hdd_roc_req_q, 697 &hdd_roc_req->node); 698 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock); 699 700 if (QDF_STATUS_SUCCESS != status) { 701 hdd_alert("Not able to enqueue RoC Req context"); 702 qdf_mem_free(hdd_roc_req); 703 return -EINVAL; 704 } 705 706 return 0; 707 } 708 709 /** 710 * wlan_hdd_indicate_roc_drop() - Indicate roc drop to userspace 711 * @adapter: HDD adapter 712 * @ctx: Remain on channel context 713 * 714 * Send remain on channel ready and cancel event for the queued 715 * roc that is being dropped. This will ensure that the userspace 716 * will send more roc requests. If this drop is not indicated to 717 * userspace, subsequent roc will not be sent to the driver since 718 * the userspace times out waiting for the remain on channel ready 719 * event. 720 * 721 * Return: None 722 */ 723 static void wlan_hdd_indicate_roc_drop(hdd_adapter_t *adapter, 724 hdd_remain_on_chan_ctx_t *ctx) 725 { 726 hdd_debug("indicate roc drop to userspace"); 727 cfg80211_ready_on_channel( 728 adapter->dev->ieee80211_ptr, 729 (uintptr_t)ctx, 730 &ctx->chan, 731 ctx->duration, GFP_KERNEL); 732 733 cfg80211_remain_on_channel_expired( 734 ctx->dev->ieee80211_ptr, 735 ctx->cookie, 736 &ctx->chan, 737 GFP_KERNEL); 738 } 739 740 /** 741 * wlan_hdd_roc_request_dequeue() - dequeue remain on channel request 742 * @work: Pointer to work queue struct 743 * 744 * Return: none 745 */ 746 void wlan_hdd_roc_request_dequeue(struct work_struct *work) 747 { 748 QDF_STATUS status; 749 int ret = 0; 750 hdd_roc_req_t *hdd_roc_req; 751 hdd_context_t *hdd_ctx = 752 container_of(work, hdd_context_t, roc_req_work.work); 753 754 hdd_debug("going to dequeue roc"); 755 756 if (0 != (wlan_hdd_validate_context(hdd_ctx))) 757 return; 758 759 /* 760 * The queued roc requests is dequeued and processed one at a time. 761 * Callback 'wlan_hdd_remain_on_channel_callback' ensures 762 * that any pending roc in the queue will be scheduled 763 * on the current roc completion by scheduling the work queue. 764 */ 765 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock); 766 if (list_empty(&hdd_ctx->hdd_roc_req_q.anchor)) { 767 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock); 768 return; 769 } 770 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q, 771 (qdf_list_node_t **) &hdd_roc_req); 772 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock); 773 if (QDF_STATUS_SUCCESS != status) { 774 hdd_debug("unable to remove roc element from list"); 775 return; 776 } 777 ret = wlan_hdd_execute_remain_on_channel( 778 hdd_roc_req->pAdapter, 779 hdd_roc_req->pRemainChanCtx); 780 if (ret == -EBUSY) { 781 hdd_err("dropping RoC request"); 782 wlan_hdd_indicate_roc_drop(hdd_roc_req->pAdapter, 783 hdd_roc_req->pRemainChanCtx); 784 qdf_mem_free(hdd_roc_req->pRemainChanCtx); 785 } 786 qdf_mem_free(hdd_roc_req); 787 } 788 789 static int wlan_hdd_request_remain_on_channel(struct wiphy *wiphy, 790 struct net_device *dev, 791 struct ieee80211_channel *chan, 792 unsigned int duration, 793 u64 *cookie, 794 rem_on_channel_request_type_t 795 request_type) 796 { 797 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); 798 hdd_context_t *pHddCtx; 799 hdd_remain_on_chan_ctx_t *pRemainChanCtx; 800 bool isBusy = false; 801 uint32_t size = 0; 802 hdd_adapter_t *sta_adapter; 803 int ret; 804 int status = 0; 805 806 hdd_notice("Device_mode %s(%d)", 807 hdd_device_mode_to_string(pAdapter->device_mode), 808 pAdapter->device_mode); 809 hdd_info("chan(hw_val)0x%x chan(centerfreq) %d, duration %d", 810 chan->hw_value, chan->center_freq, duration); 811 812 pHddCtx = WLAN_HDD_GET_CTX(pAdapter); 813 ret = wlan_hdd_validate_context(pHddCtx); 814 if (0 != ret) 815 return ret; 816 if (cds_is_connection_in_progress()) { 817 hdd_err("Connection is in progress"); 818 isBusy = true; 819 } 820 pRemainChanCtx = qdf_mem_malloc(sizeof(hdd_remain_on_chan_ctx_t)); 821 if (NULL == pRemainChanCtx) { 822 hdd_alert("Not able to allocate memory for Channel context"); 823 return -ENOMEM; 824 } 825 826 qdf_mem_copy(&pRemainChanCtx->chan, chan, 827 sizeof(struct ieee80211_channel)); 828 pRemainChanCtx->duration = duration; 829 pRemainChanCtx->dev = dev; 830 *cookie = (uintptr_t) pRemainChanCtx; 831 pRemainChanCtx->cookie = *cookie; 832 pRemainChanCtx->rem_on_chan_request = request_type; 833 pRemainChanCtx->action_pkt_buff.freq = 0; 834 pRemainChanCtx->action_pkt_buff.frame_ptr = NULL; 835 pRemainChanCtx->action_pkt_buff.frame_length = 0; 836 pRemainChanCtx->hdd_remain_on_chan_cancel_in_progress = false; 837 if (REMAIN_ON_CHANNEL_REQUEST == request_type) { 838 sta_adapter = hdd_get_adapter(pHddCtx, QDF_STA_MODE); 839 if ((NULL != sta_adapter) && 840 hdd_conn_is_connected( 841 WLAN_HDD_GET_STATION_CTX_PTR(sta_adapter))) { 842 if (pAdapter->last_roc_ts != 0 && 843 (((uint64_t)qdf_mc_timer_get_system_time() - 844 pAdapter->last_roc_ts) < 845 pHddCtx->config->p2p_listen_defer_interval)) { 846 if (pRemainChanCtx->duration > HDD_P2P_MAX_ROC_DURATION) 847 pRemainChanCtx->duration = 848 HDD_P2P_MAX_ROC_DURATION; 849 850 wlan_hdd_roc_request_enqueue(pAdapter, pRemainChanCtx); 851 schedule_delayed_work(&pHddCtx->roc_req_work, 852 msecs_to_jiffies( 853 pHddCtx->config->p2p_listen_defer_interval)); 854 hdd_info("Defer interval is %hu, pAdapter %p", 855 pHddCtx->config->p2p_listen_defer_interval, 856 pAdapter); 857 return 0; 858 } 859 } 860 } 861 862 qdf_spin_lock(&pHddCtx->hdd_roc_req_q_lock); 863 size = qdf_list_size(&(pHddCtx->hdd_roc_req_q)); 864 qdf_spin_unlock(&pHddCtx->hdd_roc_req_q_lock); 865 if ((isBusy == false) && (!size)) { 866 status = wlan_hdd_execute_remain_on_channel(pAdapter, 867 pRemainChanCtx); 868 if (status == -EBUSY) { 869 if (wlan_hdd_roc_request_enqueue(pAdapter, 870 pRemainChanCtx)) { 871 qdf_mem_free(pRemainChanCtx); 872 return -EAGAIN; 873 } 874 } 875 return 0; 876 } else { 877 if (wlan_hdd_roc_request_enqueue(pAdapter, pRemainChanCtx)) { 878 qdf_mem_free(pRemainChanCtx); 879 return -EAGAIN; 880 } 881 } 882 883 /* 884 * If a connection is not in progress (isBusy), before scheduling 885 * the work queue it is necessary to check if a roc in in progress 886 * or not because: if an roc is in progress, the dequeued roc 887 * that will be processed will be dropped. To ensure that this new 888 * roc request is not dropped, it is suggested to check if an roc 889 * is in progress or not. The existing roc completion will provide 890 * the trigger to dequeue the next roc request. 891 */ 892 if (isBusy == false && pAdapter->is_roc_inprogress == false) { 893 hdd_debug("scheduling delayed work: no connection/roc active"); 894 schedule_delayed_work(&pHddCtx->roc_req_work, 0); 895 } 896 return 0; 897 } 898 899 static int __wlan_hdd_cfg80211_remain_on_channel(struct wiphy *wiphy, 900 struct wireless_dev *wdev, 901 struct ieee80211_channel *chan, 902 unsigned int duration, 903 u64 *cookie) 904 { 905 struct net_device *dev = wdev->netdev; 906 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); 907 hdd_context_t *hdd_ctx; 908 int ret; 909 910 ENTER(); 911 912 hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); 913 ret = wlan_hdd_validate_context(hdd_ctx); 914 if (0 != ret) 915 return ret; 916 917 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { 918 hdd_err("Command not allowed in FTM mode"); 919 return -EINVAL; 920 } 921 922 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, 923 TRACE_CODE_HDD_REMAIN_ON_CHANNEL, 924 pAdapter->sessionId, REMAIN_ON_CHANNEL_REQUEST)); 925 926 ret = wlan_hdd_request_remain_on_channel(wiphy, dev, chan, 927 duration, cookie, 928 REMAIN_ON_CHANNEL_REQUEST); 929 EXIT(); 930 return ret; 931 } 932 933 int wlan_hdd_cfg80211_remain_on_channel(struct wiphy *wiphy, 934 struct wireless_dev *wdev, 935 struct ieee80211_channel *chan, 936 unsigned int duration, u64 *cookie) 937 { 938 int ret; 939 940 cds_ssr_protect(__func__); 941 ret = __wlan_hdd_cfg80211_remain_on_channel(wiphy, 942 wdev, 943 chan, 944 duration, cookie); 945 cds_ssr_unprotect(__func__); 946 947 return ret; 948 } 949 950 void hdd_remain_chan_ready_handler(hdd_adapter_t *pAdapter, 951 uint32_t scan_id) 952 { 953 hdd_cfg80211_state_t *cfgState = NULL; 954 hdd_remain_on_chan_ctx_t *pRemainChanCtx = NULL; 955 QDF_STATUS status; 956 957 if (NULL == pAdapter) { 958 hdd_err("pAdapter is NULL"); 959 return; 960 } 961 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 962 hdd_notice("Ready on chan ind %d", scan_id); 963 964 pAdapter->start_roc_ts = (uint64_t)qdf_mc_timer_get_system_time(); 965 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 966 pRemainChanCtx = cfgState->remain_on_chan_ctx; 967 if (pRemainChanCtx != NULL) { 968 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, 969 TRACE_CODE_HDD_REMAINCHANREADYHANDLER, 970 pAdapter->sessionId, 971 pRemainChanCtx->duration)); 972 /* start timer for actual duration */ 973 if (QDF_TIMER_STATE_RUNNING == 974 qdf_mc_timer_get_current_state( 975 &pRemainChanCtx->hdd_remain_on_chan_timer)) { 976 hdd_err("Timer Started before ready event!!!"); 977 qdf_mc_timer_stop(&pRemainChanCtx-> 978 hdd_remain_on_chan_timer); 979 } 980 status = 981 qdf_mc_timer_start(&pRemainChanCtx-> 982 hdd_remain_on_chan_timer, 983 (pRemainChanCtx->duration + 984 COMPLETE_EVENT_PROPOGATE_TIME)); 985 if (status != QDF_STATUS_SUCCESS) { 986 hdd_err("Remain on Channel timer start failed"); 987 } 988 989 if (REMAIN_ON_CHANNEL_REQUEST == 990 pRemainChanCtx->rem_on_chan_request) { 991 cfg80211_ready_on_channel( 992 pAdapter->dev-> 993 ieee80211_ptr, 994 (uintptr_t) 995 pRemainChanCtx, 996 &pRemainChanCtx->chan, 997 pRemainChanCtx-> 998 duration, GFP_KERNEL); 999 } else if (OFF_CHANNEL_ACTION_TX == 1000 pRemainChanCtx->rem_on_chan_request) { 1001 complete(&pAdapter->offchannel_tx_event); 1002 } 1003 /* Check for cached action frame */ 1004 if (pRemainChanCtx->action_pkt_buff.frame_length != 0) { 1005 hdd_err("Sent cached action frame to supplicant"); 1006 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)) 1007 cfg80211_rx_mgmt(pAdapter->dev->ieee80211_ptr, 1008 pRemainChanCtx->action_pkt_buff.freq, 0, 1009 pRemainChanCtx->action_pkt_buff.frame_ptr, 1010 pRemainChanCtx->action_pkt_buff.frame_length, 1011 NL80211_RXMGMT_FLAG_ANSWERED); 1012 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) 1013 cfg80211_rx_mgmt(pAdapter->dev->ieee80211_ptr, 1014 pRemainChanCtx->action_pkt_buff.freq, 0, 1015 pRemainChanCtx->action_pkt_buff.frame_ptr, 1016 pRemainChanCtx->action_pkt_buff.frame_length, 1017 NL80211_RXMGMT_FLAG_ANSWERED, GFP_ATOMIC); 1018 #else 1019 cfg80211_rx_mgmt(pAdapter->dev->ieee80211_ptr, 1020 pRemainChanCtx->action_pkt_buff.freq, 1021 0, 1022 pRemainChanCtx->action_pkt_buff. 1023 frame_ptr, 1024 pRemainChanCtx->action_pkt_buff. 1025 frame_length, GFP_ATOMIC); 1026 #endif /* LINUX_VERSION_CODE */ 1027 1028 qdf_mem_free(pRemainChanCtx->action_pkt_buff.frame_ptr); 1029 pRemainChanCtx->action_pkt_buff.frame_length = 0; 1030 pRemainChanCtx->action_pkt_buff.freq = 0; 1031 pRemainChanCtx->action_pkt_buff.frame_ptr = NULL; 1032 } 1033 complete(&pAdapter->rem_on_chan_ready_event); 1034 } else { 1035 hdd_warn("No Pending Remain on channel Request"); 1036 } 1037 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1038 return; 1039 } 1040 1041 static int 1042 __wlan_hdd_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, 1043 struct wireless_dev *wdev, 1044 u64 cookie) 1045 { 1046 struct net_device *dev = wdev->netdev; 1047 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); 1048 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 1049 hdd_remain_on_chan_ctx_t *pRemainChanCtx; 1050 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter); 1051 int status; 1052 int qdf_status; 1053 unsigned long rc; 1054 qdf_list_node_t *tmp, *q; 1055 hdd_roc_req_t *curr_roc_req; 1056 1057 ENTER(); 1058 1059 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { 1060 hdd_err("Command not allowed in FTM mode"); 1061 return -EINVAL; 1062 } 1063 1064 status = wlan_hdd_validate_context(pHddCtx); 1065 1066 if (0 != status) 1067 return status; 1068 qdf_spin_lock(&pHddCtx->hdd_roc_req_q_lock); 1069 list_for_each_safe(tmp, q, &pHddCtx->hdd_roc_req_q.anchor) { 1070 curr_roc_req = list_entry(tmp, hdd_roc_req_t, node); 1071 if ((uintptr_t) curr_roc_req->pRemainChanCtx == cookie) { 1072 qdf_status = qdf_list_remove_node(&pHddCtx->hdd_roc_req_q, 1073 (qdf_list_node_t *) 1074 curr_roc_req); 1075 qdf_spin_unlock(&pHddCtx->hdd_roc_req_q_lock); 1076 if (qdf_status == QDF_STATUS_SUCCESS) { 1077 qdf_mem_free(curr_roc_req->pRemainChanCtx); 1078 qdf_mem_free(curr_roc_req); 1079 } 1080 return 0; 1081 } 1082 } 1083 qdf_spin_unlock(&pHddCtx->hdd_roc_req_q_lock); 1084 /* FIXME cancel currently running remain on chan. 1085 * Need to check cookie and cancel accordingly 1086 */ 1087 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 1088 pRemainChanCtx = cfgState->remain_on_chan_ctx; 1089 if ((cfgState->remain_on_chan_ctx == NULL) || 1090 (cfgState->remain_on_chan_ctx->cookie != cookie)) { 1091 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1092 hdd_err("No Remain on channel pending with specified cookie value"); 1093 return -EINVAL; 1094 } 1095 1096 if (NULL != cfgState->remain_on_chan_ctx) { 1097 qdf_mc_timer_stop(&cfgState->remain_on_chan_ctx-> 1098 hdd_remain_on_chan_timer); 1099 if (true == 1100 pRemainChanCtx->hdd_remain_on_chan_cancel_in_progress) { 1101 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1102 hdd_notice("ROC timer cancellation in progress, wait for completion"); 1103 rc = wait_for_completion_timeout(&pAdapter-> 1104 cancel_rem_on_chan_var, 1105 msecs_to_jiffies 1106 (WAIT_CANCEL_REM_CHAN)); 1107 if (!rc) { 1108 hdd_err("wait on cancel_rem_on_chan_var timed out"); 1109 } 1110 return 0; 1111 } else 1112 pRemainChanCtx->hdd_remain_on_chan_cancel_in_progress = 1113 true; 1114 } 1115 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1116 1117 /* wait until remain on channel ready event received 1118 * for already issued remain on channel request */ 1119 rc = wait_for_completion_timeout(&pAdapter->rem_on_chan_ready_event, 1120 msecs_to_jiffies(WAIT_REM_CHAN_READY)); 1121 if (!rc) { 1122 hdd_err("timeout waiting for remain on channel ready indication"); 1123 1124 if (cds_is_driver_recovering()) { 1125 hdd_err("Recovery in Progress. State: 0x%x Ignore!!!", 1126 cds_get_driver_state()); 1127 return -EAGAIN; 1128 } 1129 cds_flush_logs(WLAN_LOG_TYPE_FATAL, 1130 WLAN_LOG_INDICATOR_HOST_DRIVER, 1131 WLAN_LOG_REASON_HDD_TIME_OUT, 1132 true, false); 1133 } 1134 INIT_COMPLETION(pAdapter->cancel_rem_on_chan_var); 1135 /* Issue abort remain on chan request to sme. 1136 * The remain on channel callback will make sure the remain_on_chan 1137 * expired event is sent. 1138 */ 1139 if ((QDF_STA_MODE == pAdapter->device_mode) || 1140 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) || 1141 (QDF_P2P_DEVICE_MODE == pAdapter->device_mode) 1142 ) { 1143 1144 uint8_t sessionId = pAdapter->sessionId; 1145 sme_cancel_remain_on_channel(WLAN_HDD_GET_HAL_CTX(pAdapter), 1146 sessionId, 1147 pRemainChanCtx->scan_id); 1148 } else if ((QDF_SAP_MODE == pAdapter->device_mode) || 1149 (QDF_P2P_GO_MODE == pAdapter->device_mode) 1150 ) { 1151 wlansap_cancel_remain_on_channel( 1152 WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), 1153 pRemainChanCtx->scan_id); 1154 1155 } else { 1156 hdd_err("Invalid device_mode %s(%d)", 1157 hdd_device_mode_to_string(pAdapter->device_mode), 1158 pAdapter->device_mode); 1159 return -EIO; 1160 } 1161 rc = wait_for_completion_timeout(&pAdapter->cancel_rem_on_chan_var, 1162 msecs_to_jiffies 1163 (WAIT_CANCEL_REM_CHAN)); 1164 if (!rc) { 1165 hdd_err("wait on cancel_rem_on_chan_var timed out"); 1166 } 1167 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_ROC); 1168 EXIT(); 1169 return 0; 1170 } 1171 1172 int wlan_hdd_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, 1173 struct wireless_dev *wdev, 1174 u64 cookie) 1175 { 1176 int ret; 1177 1178 cds_ssr_protect(__func__); 1179 ret = __wlan_hdd_cfg80211_cancel_remain_on_channel(wiphy, 1180 wdev, 1181 cookie); 1182 cds_ssr_unprotect(__func__); 1183 1184 return ret; 1185 } 1186 1187 static int __wlan_hdd_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, 1188 struct ieee80211_channel *chan, bool offchan, 1189 unsigned int wait, 1190 const u8 *buf, size_t len, bool no_cck, 1191 bool dont_wait_for_ack, u64 *cookie) 1192 { 1193 struct net_device *dev = wdev->netdev; 1194 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); 1195 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 1196 hdd_remain_on_chan_ctx_t *pRemainChanCtx; 1197 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter); 1198 uint16_t extendedWait = 0; 1199 uint8_t type = WLAN_HDD_GET_TYPE_FRM_FC(buf[0]); 1200 uint8_t subType = WLAN_HDD_GET_SUBTYPE_FRM_FC(buf[0]); 1201 tActionFrmType actionFrmType; 1202 bool noack = 0; 1203 int status; 1204 unsigned long rc; 1205 hdd_adapter_t *goAdapter; 1206 uint16_t current_freq; 1207 uint8_t home_ch = 0; 1208 1209 ENTER(); 1210 1211 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { 1212 hdd_err("Command not allowed in FTM mode"); 1213 return -EINVAL; 1214 } 1215 1216 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, 1217 TRACE_CODE_HDD_ACTION, pAdapter->sessionId, 1218 pAdapter->device_mode)); 1219 status = wlan_hdd_validate_context(pHddCtx); 1220 1221 if (0 != status) 1222 return status; 1223 1224 hdd_notice("Device_mode %s(%d) type: %d, wait: %d, offchan: %d, category: %d, actionId: %d", 1225 hdd_device_mode_to_string(pAdapter->device_mode), 1226 pAdapter->device_mode, type, wait, offchan, 1227 buf[WLAN_HDD_PUBLIC_ACTION_FRAME_BODY_OFFSET + 1228 WLAN_HDD_PUBLIC_ACTION_FRAME_CATEGORY_OFFSET], 1229 buf[WLAN_HDD_PUBLIC_ACTION_FRAME_BODY_OFFSET + 1230 WLAN_HDD_PUBLIC_ACTION_FRAME_ACTION_OFFSET]); 1231 1232 #ifdef WLAN_FEATURE_P2P_DEBUG 1233 if ((type == SIR_MAC_MGMT_FRAME) && 1234 (subType == SIR_MAC_MGMT_ACTION) && 1235 wlan_hdd_is_type_p2p_action(&buf 1236 [WLAN_HDD_PUBLIC_ACTION_FRAME_BODY_OFFSET])) { 1237 actionFrmType = buf[WLAN_HDD_PUBLIC_ACTION_FRAME_TYPE_OFFSET]; 1238 if (actionFrmType >= MAX_P2P_ACTION_FRAME_TYPE) { 1239 hdd_err("[P2P] unknown[%d] ---> OTA to " MAC_ADDRESS_STR, 1240 actionFrmType, 1241 MAC_ADDR_ARRAY(&buf 1242 [WLAN_HDD_80211_FRM_DA_OFFSET])); 1243 } else { 1244 hdd_err("[P2P] %s ---> OTA to " 1245 MAC_ADDRESS_STR, 1246 p2p_action_frame_type[actionFrmType], 1247 MAC_ADDR_ARRAY(&buf 1248 [WLAN_HDD_80211_FRM_DA_OFFSET])); 1249 if ((actionFrmType == WLAN_HDD_PROV_DIS_REQ) 1250 && (global_p2p_connection_status == P2P_NOT_ACTIVE)) { 1251 global_p2p_connection_status = P2P_GO_NEG_PROCESS; 1252 hdd_err("[P2P State]Inactive state to GO negotiation progress state"); 1253 } else if ((actionFrmType == WLAN_HDD_GO_NEG_CNF) && 1254 (global_p2p_connection_status == 1255 P2P_GO_NEG_PROCESS)) { 1256 global_p2p_connection_status = 1257 P2P_GO_NEG_COMPLETED; 1258 hdd_err("[P2P State]GO nego progress to GO nego completed state"); 1259 } 1260 } 1261 } 1262 #endif 1263 1264 noack = dont_wait_for_ack; 1265 1266 /* If the wait is coming as 0 with off channel set */ 1267 /* then set the wait to 200 ms */ 1268 if (offchan && !wait) { 1269 wait = ACTION_FRAME_DEFAULT_WAIT; 1270 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 1271 if (cfgState->remain_on_chan_ctx) { 1272 1273 uint64_t current_time = 1274 (uint64_t)qdf_mc_timer_get_system_time(); 1275 int remaining_roc_time = 1276 ((int) cfgState->remain_on_chan_ctx->duration - 1277 (current_time - pAdapter->start_roc_ts)); 1278 1279 if (remaining_roc_time > ACTION_FRAME_DEFAULT_WAIT) 1280 wait = remaining_roc_time; 1281 } 1282 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1283 } 1284 1285 if ((QDF_STA_MODE == pAdapter->device_mode) && 1286 (type == SIR_MAC_MGMT_FRAME && 1287 subType == SIR_MAC_MGMT_PROBE_RSP)) { 1288 /* Drop Probe response received 1289 * from supplicant in sta mode 1290 */ 1291 goto err_rem_channel; 1292 } 1293 1294 /* Call sme API to send out a action frame. */ 1295 /* OR can we send it directly through data path?? */ 1296 /* After tx completion send tx status back. */ 1297 if ((QDF_SAP_MODE == pAdapter->device_mode) || 1298 (QDF_P2P_GO_MODE == pAdapter->device_mode) 1299 ) { 1300 if (type == SIR_MAC_MGMT_FRAME) { 1301 if (subType == SIR_MAC_MGMT_PROBE_RSP) { 1302 /* Drop Probe response recieved from supplicant, as for GO and 1303 SAP PE itself sends probe response 1304 */ 1305 goto err_rem_channel; 1306 } else if ((subType == SIR_MAC_MGMT_DISASSOC) || 1307 (subType == SIR_MAC_MGMT_DEAUTH)) { 1308 /* During EAP failure or P2P Group Remove supplicant 1309 * is sending del_station command to driver. From 1310 * del_station function, Driver will send deauth frame to 1311 * p2p client. No need to send disassoc frame from here. 1312 * so Drop the frame here and send tx indication back to 1313 * supplicant. 1314 */ 1315 uint8_t dstMac[ETH_ALEN] = { 0 }; 1316 memcpy(&dstMac, 1317 &buf[WLAN_HDD_80211_FRM_DA_OFFSET], 1318 ETH_ALEN); 1319 hdd_info("Deauth/Disassoc received for STA:" 1320 MAC_ADDRESS_STR, 1321 MAC_ADDR_ARRAY(dstMac)); 1322 goto err_rem_channel; 1323 } 1324 } 1325 } 1326 1327 if (NULL != cfgState->buf) { 1328 if (!noack) { 1329 hdd_err("Previous P2P Action frame packet pending"); 1330 hdd_cleanup_actionframe(pAdapter->pHddCtx, pAdapter); 1331 } else { 1332 hdd_err("Pending Action frame packet return EBUSY"); 1333 return -EBUSY; 1334 } 1335 } 1336 1337 if (subType == SIR_MAC_MGMT_ACTION) { 1338 hdd_notice("Action frame tx request : %s", 1339 hdd_get_action_string(buf 1340 [WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET])); 1341 } 1342 1343 if ((pAdapter->device_mode == QDF_SAP_MODE) && 1344 (test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))) { 1345 home_ch = pAdapter->sessionCtx.ap.operatingChannel; 1346 } else if ((pAdapter->device_mode == QDF_STA_MODE) && 1347 (pAdapter->sessionCtx.station.conn_info.connState == 1348 eConnectionState_Associated)) { 1349 home_ch = 1350 pAdapter->sessionCtx.station.conn_info.operationChannel; 1351 } else { 1352 goAdapter = hdd_get_adapter(pAdapter->pHddCtx, QDF_P2P_GO_MODE); 1353 if (goAdapter && 1354 (test_bit(SOFTAP_BSS_STARTED, &goAdapter->event_flags))) 1355 home_ch = goAdapter->sessionCtx.ap.operatingChannel; 1356 } 1357 1358 if (chan && 1359 (ieee80211_frequency_to_channel(chan->center_freq) == 1360 home_ch)) { 1361 /* if adapter is already on requested ch, no need for ROC */ 1362 wait = 0; 1363 hdd_notice("Adapter already on requested ch. No ROC needed"); 1364 goto send_frame; 1365 } 1366 1367 if (offchan && wait && chan) { 1368 int status; 1369 rem_on_channel_request_type_t req_type = OFF_CHANNEL_ACTION_TX; 1370 /* In case of P2P Client mode if we are already */ 1371 /* on the same channel then send the frame directly */ 1372 1373 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 1374 pRemainChanCtx = cfgState->remain_on_chan_ctx; 1375 if ((type == SIR_MAC_MGMT_FRAME) && 1376 (subType == SIR_MAC_MGMT_ACTION) && 1377 hdd_p2p_is_action_type_rsp(&buf 1378 [WLAN_HDD_PUBLIC_ACTION_FRAME_BODY_OFFSET]) 1379 && cfgState->remain_on_chan_ctx 1380 && cfgState->current_freq == chan->center_freq) { 1381 if (QDF_TIMER_STATE_RUNNING == 1382 qdf_mc_timer_get_current_state(&cfgState-> 1383 remain_on_chan_ctx-> 1384 hdd_remain_on_chan_timer)) { 1385 1386 /* In the latest wpa_supplicant, the wait time 1387 * for go negotiation response is set to 100ms, 1388 * due to which, there could be a possibility 1389 * that, if the go negotaition confirmation 1390 * frame is not received within 100 msec, ROC 1391 * would be timeout and resulting in connection 1392 * failures as the device will not be on the 1393 * listen channel anymore to receive the conf 1394 * frame. Also wpa_supplicant has set the wait 1395 * to 50msec for go negotiation confirmation, 1396 * invitation response and prov discovery rsp 1397 * frames. So increase the wait time for all 1398 * these frames. 1399 */ 1400 actionFrmType = buf 1401 [WLAN_HDD_PUBLIC_ACTION_FRAME_TYPE_OFFSET]; 1402 if (actionFrmType == WLAN_HDD_GO_NEG_RESP || 1403 actionFrmType == WLAN_HDD_PROV_DIS_RESP) 1404 wait = wait + ACTION_FRAME_RSP_WAIT; 1405 else if (actionFrmType == 1406 WLAN_HDD_GO_NEG_CNF || 1407 actionFrmType == 1408 WLAN_HDD_INVITATION_RESP) 1409 wait = wait + ACTION_FRAME_ACK_WAIT; 1410 1411 hddLog(LOG1, FL("Extending the wait time %d for actionFrmType=%d"), 1412 wait, actionFrmType); 1413 1414 qdf_mc_timer_stop(&cfgState-> 1415 remain_on_chan_ctx-> 1416 hdd_remain_on_chan_timer); 1417 status = 1418 qdf_mc_timer_start(&cfgState-> 1419 remain_on_chan_ctx-> 1420 hdd_remain_on_chan_timer, 1421 wait); 1422 if (status != QDF_STATUS_SUCCESS) { 1423 hdd_err("Remain on Channel timer start failed"); 1424 } 1425 mutex_unlock(&cfgState-> 1426 remain_on_chan_ctx_lock); 1427 goto send_frame; 1428 } else { 1429 if (pRemainChanCtx-> 1430 hdd_remain_on_chan_cancel_in_progress == 1431 true) { 1432 mutex_unlock(&cfgState-> 1433 remain_on_chan_ctx_lock); 1434 hdd_info("action frame tx: waiting for completion of ROC "); 1435 1436 rc = wait_for_completion_timeout 1437 (&pAdapter->cancel_rem_on_chan_var, 1438 msecs_to_jiffies 1439 (WAIT_CANCEL_REM_CHAN)); 1440 if (!rc) { 1441 hdd_err("wait on cancel_rem_on_chan_var timed out"); 1442 } 1443 1444 } else 1445 mutex_unlock(&cfgState-> 1446 remain_on_chan_ctx_lock); 1447 } 1448 } else 1449 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1450 1451 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 1452 if ((cfgState->remain_on_chan_ctx != NULL) && 1453 (cfgState->current_freq == chan->center_freq) 1454 ) { 1455 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1456 hdd_notice("action frame: extending the wait time"); 1457 extendedWait = (uint16_t) wait; 1458 goto send_frame; 1459 } 1460 1461 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1462 INIT_COMPLETION(pAdapter->offchannel_tx_event); 1463 1464 status = wlan_hdd_request_remain_on_channel(wiphy, dev, chan, 1465 wait, cookie, 1466 req_type); 1467 if (0 != status) { 1468 if ((-EBUSY == status) && 1469 (cfgState->current_freq == chan->center_freq)) { 1470 goto send_frame; 1471 } 1472 goto err_rem_channel; 1473 } 1474 /* This will extend timer in LIM when sending Any action frame 1475 * It will cover remain on channel timer till next action frame 1476 * in rx direction. 1477 */ 1478 extendedWait = (uint16_t) wait; 1479 /* Wait for driver to be ready on the requested channel */ 1480 rc = wait_for_completion_timeout(&pAdapter->offchannel_tx_event, 1481 msecs_to_jiffies 1482 (WAIT_CHANGE_CHANNEL_FOR_OFFCHANNEL_TX)); 1483 if (!rc) { 1484 hdd_err("wait on offchannel_tx_event timed out"); 1485 goto err_rem_channel; 1486 } 1487 } else if (offchan) { 1488 /* Check before sending action frame 1489 whether we already remain on channel */ 1490 if (NULL == cfgState->remain_on_chan_ctx) { 1491 goto err_rem_channel; 1492 } 1493 } 1494 send_frame: 1495 1496 if (!noack) { 1497 cfgState->buf = qdf_mem_malloc(len); /* buf; */ 1498 if (cfgState->buf == NULL) 1499 return -ENOMEM; 1500 1501 cfgState->len = len; 1502 1503 qdf_mem_copy(cfgState->buf, buf, len); 1504 1505 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 1506 1507 if (cfgState->remain_on_chan_ctx) { 1508 cfgState->action_cookie = 1509 cfgState->remain_on_chan_ctx->cookie; 1510 *cookie = cfgState->action_cookie; 1511 } else { 1512 *cookie = (uintptr_t) cfgState->buf; 1513 cfgState->action_cookie = *cookie; 1514 } 1515 1516 mutex_unlock(&cfgState->remain_on_chan_ctx_lock); 1517 } 1518 1519 /* 1520 * Firmware needs channel information for action frames 1521 * which are not sent on the current operating channel of VDEV 1522 */ 1523 if ((QDF_P2P_DEVICE_MODE == pAdapter->device_mode) || 1524 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) || 1525 (QDF_P2P_GO_MODE == pAdapter->device_mode)) { 1526 if (chan && (chan->center_freq != 0)) 1527 current_freq = chan->center_freq; 1528 else 1529 current_freq = cfgState->current_freq; 1530 } else { 1531 current_freq = 0; 1532 } 1533 1534 INIT_COMPLETION(pAdapter->tx_action_cnf_event); 1535 1536 if ((QDF_STA_MODE == pAdapter->device_mode) || 1537 (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) || 1538 (QDF_P2P_DEVICE_MODE == pAdapter->device_mode)) { 1539 uint8_t sessionId = pAdapter->sessionId; 1540 1541 if ((type == SIR_MAC_MGMT_FRAME) && 1542 (subType == SIR_MAC_MGMT_ACTION) && 1543 wlan_hdd_is_type_p2p_action(&buf 1544 [WLAN_HDD_PUBLIC_ACTION_FRAME_BODY_OFFSET])) { 1545 actionFrmType = 1546 buf[WLAN_HDD_PUBLIC_ACTION_FRAME_TYPE_OFFSET]; 1547 hdd_notice("Tx Action Frame %u", actionFrmType); 1548 if (actionFrmType == WLAN_HDD_PROV_DIS_REQ) { 1549 cfgState->actionFrmState = 1550 HDD_PD_REQ_ACK_PENDING; 1551 hdd_notice("HDD_PD_REQ_ACK_PENDING"); 1552 } else if (actionFrmType == WLAN_HDD_GO_NEG_REQ) { 1553 cfgState->actionFrmState = 1554 HDD_GO_NEG_REQ_ACK_PENDING; 1555 hdd_notice("HDD_GO_NEG_REQ_ACK_PENDING"); 1556 } 1557 } 1558 1559 if (QDF_STATUS_SUCCESS != 1560 sme_send_action(WLAN_HDD_GET_HAL_CTX(pAdapter), 1561 sessionId, buf, len, extendedWait, noack, 1562 current_freq)) { 1563 hdd_err("sme_send_action returned fail"); 1564 goto err; 1565 } 1566 } else if (QDF_SAP_MODE == pAdapter->device_mode || 1567 QDF_P2P_GO_MODE == pAdapter->device_mode) { 1568 if (QDF_STATUS_SUCCESS != 1569 wlansap_send_action(WLAN_HDD_GET_SAP_CTX_PTR(pAdapter), 1570 buf, len, 0, current_freq)) { 1571 hdd_err("wlansap_send_action returned fail"); 1572 goto err; 1573 } 1574 } 1575 1576 return 0; 1577 err: 1578 if (!noack) { 1579 hdd_send_action_cnf(pAdapter, false); 1580 } 1581 return 0; 1582 err_rem_channel: 1583 *cookie = (uintptr_t) cfgState; 1584 cfg80211_mgmt_tx_status( 1585 pAdapter->dev->ieee80211_ptr, 1586 *cookie, buf, len, false, GFP_KERNEL); 1587 EXIT(); 1588 return 0; 1589 } 1590 1591 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) 1592 int wlan_hdd_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, 1593 struct cfg80211_mgmt_tx_params *params, u64 *cookie) 1594 #else 1595 int wlan_hdd_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, 1596 struct ieee80211_channel *chan, bool offchan, 1597 unsigned int wait, 1598 const u8 *buf, size_t len, bool no_cck, 1599 bool dont_wait_for_ack, u64 *cookie) 1600 #endif /* LINUX_VERSION_CODE */ 1601 { 1602 int ret; 1603 1604 cds_ssr_protect(__func__); 1605 1606 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) 1607 ret = __wlan_hdd_mgmt_tx(wiphy, wdev, params->chan, params->offchan, 1608 params->wait, params->buf, params->len, 1609 params->no_cck, params->dont_wait_for_ack, 1610 cookie); 1611 #else 1612 ret = __wlan_hdd_mgmt_tx(wiphy, wdev, chan, offchan, 1613 wait, buf, len, no_cck, 1614 dont_wait_for_ack, cookie); 1615 #endif /* LINUX_VERSION_CODE */ 1616 cds_ssr_unprotect(__func__); 1617 1618 return ret; 1619 } 1620 1621 static int __wlan_hdd_cfg80211_mgmt_tx_cancel_wait(struct wiphy *wiphy, 1622 struct wireless_dev *wdev, 1623 u64 cookie) 1624 { 1625 return wlan_hdd_cfg80211_cancel_remain_on_channel(wiphy, wdev, cookie); 1626 } 1627 1628 int wlan_hdd_cfg80211_mgmt_tx_cancel_wait(struct wiphy *wiphy, 1629 struct wireless_dev *wdev, u64 cookie) 1630 { 1631 int ret; 1632 1633 cds_ssr_protect(__func__); 1634 ret = __wlan_hdd_cfg80211_mgmt_tx_cancel_wait(wiphy, wdev, cookie); 1635 cds_ssr_unprotect(__func__); 1636 1637 return ret; 1638 } 1639 1640 void hdd_send_action_cnf(hdd_adapter_t *pAdapter, bool actionSendSuccess) 1641 { 1642 hdd_cfg80211_state_t *cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 1643 1644 cfgState->actionFrmState = HDD_IDLE; 1645 1646 1647 if (NULL == cfgState->buf) { 1648 return; 1649 } 1650 1651 if (cfgState->is_go_neg_ack_received) { 1652 1653 cfgState->is_go_neg_ack_received = 0; 1654 /* Sometimes its possible that host may receive the ack for GO 1655 * negotiation req after sending go negotaition confirmation, 1656 * in such case drop the ack received for the go negotiation 1657 * request, so that supplicant waits for the confirmation ack 1658 * from firmware. 1659 */ 1660 hdd_info("Drop the pending ack received in cfgState->actionFrmState %d", 1661 cfgState->actionFrmState); 1662 return; 1663 } 1664 1665 hdd_info("Send Action cnf, actionSendSuccess %d", 1666 actionSendSuccess); 1667 /* 1668 * buf is the same pointer it passed us to send. Since we are sending 1669 * it through control path, we use different buffers. 1670 * In case of mac80211, they just push it to the skb and pass the same 1671 * data while sending tx ack status. 1672 * */ 1673 cfg80211_mgmt_tx_status( 1674 pAdapter->dev->ieee80211_ptr, 1675 cfgState->action_cookie, 1676 cfgState->buf, cfgState->len, 1677 actionSendSuccess, GFP_KERNEL); 1678 1679 qdf_mem_free(cfgState->buf); 1680 cfgState->buf = NULL; 1681 1682 complete(&pAdapter->tx_action_cnf_event); 1683 } 1684 1685 /** 1686 * hdd_send_action_cnf_cb - action confirmation callback 1687 * @session_id: SME session ID 1688 * @tx_completed: ack status 1689 * 1690 * This function invokes hdd_sendActionCnf to update ack status to 1691 * supplicant. 1692 */ 1693 void hdd_send_action_cnf_cb(uint32_t session_id, bool tx_completed) 1694 { 1695 hdd_context_t *hdd_ctx; 1696 hdd_adapter_t *adapter; 1697 1698 ENTER(); 1699 1700 /* Get the HDD context.*/ 1701 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD); 1702 if (0 != wlan_hdd_validate_context(hdd_ctx)) 1703 return; 1704 1705 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id); 1706 if (NULL == adapter) { 1707 hddLog(LOGE, FL("adapter not found")); 1708 return; 1709 } 1710 1711 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) { 1712 hddLog(LOGE, FL("adapter has invalid magic")); 1713 return; 1714 } 1715 1716 hdd_send_action_cnf(adapter, tx_completed); 1717 } 1718 1719 /** 1720 * hdd_set_p2p_noa 1721 * 1722 ***FUNCTION: 1723 * This function is called from hdd_hostapd_ioctl function when Driver 1724 * get P2P_SET_NOA comand from wpa_supplicant using private ioctl 1725 * 1726 ***LOGIC: 1727 * Fill NoA Struct According to P2P Power save Option and Pass it to SME layer 1728 * 1729 ***ASSUMPTIONS: 1730 * 1731 * 1732 ***NOTE: 1733 * 1734 * @param dev Pointer to net device structure 1735 * @param command Pointer to command 1736 * 1737 * @return Status 1738 */ 1739 1740 int hdd_set_p2p_noa(struct net_device *dev, uint8_t *command) 1741 { 1742 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); 1743 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); 1744 tP2pPsConfig NoA; 1745 int count, duration, interval; 1746 char *param; 1747 int ret; 1748 1749 param = strnchr(command, strlen(command), ' '); 1750 if (param == NULL) { 1751 hdd_err("strnchr failed to find delimeter"); 1752 return -EINVAL; 1753 } 1754 param++; 1755 ret = sscanf(param, "%d %d %d", &count, &interval, &duration); 1756 if (ret != 3) { 1757 hdd_err("P2P_SET GO NoA: fail to read params, ret=%d", 1758 ret); 1759 return -EINVAL; 1760 } 1761 if (count < 0 || interval < 0 || duration < 0 || 1762 interval > MAX_MUS_VAL || duration > MAX_MUS_VAL) { 1763 hdd_err("Invalid NOA parameters"); 1764 return -EINVAL; 1765 } 1766 hdd_info("P2P_SET GO NoA: count=%d interval=%d duration=%d", 1767 count, interval, duration); 1768 duration = MS_TO_TU_MUS(duration); 1769 /* PS Selection 1770 * Periodic NoA (2) 1771 * Single NOA (4) 1772 */ 1773 NoA.opp_ps = 0; 1774 NoA.ctWindow = 0; 1775 if (count == 1) { 1776 NoA.duration = 0; 1777 NoA.single_noa_duration = duration; 1778 NoA.psSelection = P2P_POWER_SAVE_TYPE_SINGLE_NOA; 1779 } else { 1780 NoA.duration = duration; 1781 NoA.single_noa_duration = 0; 1782 NoA.psSelection = P2P_POWER_SAVE_TYPE_PERIODIC_NOA; 1783 } 1784 NoA.interval = MS_TO_TU_MUS(interval); 1785 NoA.count = count; 1786 NoA.sessionid = pAdapter->sessionId; 1787 1788 hdd_info("P2P_PS_ATTR:oppPS %d ctWindow %d duration %d " 1789 "interval %d count %d single noa duration %d " 1790 "PsSelection %x", NoA.opp_ps, 1791 NoA.ctWindow, NoA.duration, NoA.interval, 1792 NoA.count, NoA.single_noa_duration, NoA.psSelection); 1793 1794 sme_p2p_set_ps(hHal, &NoA); 1795 return 0; 1796 } 1797 1798 /** 1799 * hdd_set_p2p_opps 1800 * 1801 ***FUNCTION: 1802 * This function is called from hdd_hostapd_ioctl function when Driver 1803 * get P2P_SET_PS comand from wpa_supplicant using private ioctl 1804 * 1805 ***LOGIC: 1806 * Fill NoA Struct According to P2P Power save Option and Pass it to SME layer 1807 * 1808 ***ASSUMPTIONS: 1809 * 1810 * 1811 ***NOTE: 1812 * 1813 * @param dev Pointer to net device structure 1814 * @param command Pointer to command 1815 * 1816 * @return Status 1817 */ 1818 1819 int hdd_set_p2p_opps(struct net_device *dev, uint8_t *command) 1820 { 1821 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); 1822 tHalHandle handle = WLAN_HDD_GET_HAL_CTX(adapter); 1823 tP2pPsConfig noa; 1824 char *param; 1825 int legacy_ps, opp_ps, ctwindow; 1826 int ret; 1827 1828 param = strnchr(command, strlen(command), ' '); 1829 if (param == NULL) { 1830 hdd_err("strnchr failed to find delimiter"); 1831 return -EINVAL; 1832 } 1833 param++; 1834 ret = sscanf(param, "%d %d %d", &legacy_ps, &opp_ps, &ctwindow); 1835 if (ret != 3) { 1836 hdd_err("P2P_SET GO PS: fail to read params, ret=%d", ret); 1837 return -EINVAL; 1838 } 1839 1840 if ((opp_ps != -1) && (opp_ps != 0) && (opp_ps != 1)) { 1841 hdd_err("Invalid opp_ps value:%d", opp_ps); 1842 return -EINVAL; 1843 } 1844 1845 /* P2P spec: 3.3.2 Power Management and discovery: 1846 * CTWindow should be at least 10 TU. 1847 * P2P spec: Table 27 - CTWindow and OppPS Parameters field format: 1848 * CTWindow and OppPS Parameters together is 8 bits. 1849 * CTWindow uses 7 bits (0-6, Bit 7 is for OppPS) 1850 * 0 indicates that there shall be no CTWindow 1851 */ 1852 if ((ctwindow != -1) && (ctwindow != 0) && 1853 (!((ctwindow >= 10) && (ctwindow <= 127)))) { 1854 hdd_err("Invalid CT window value:%d", ctwindow); 1855 return -EINVAL; 1856 } 1857 1858 hdd_info("P2P_SET GO PS: legacy_ps=%d opp_ps=%d ctwindow=%d", 1859 legacy_ps, opp_ps, ctwindow); 1860 1861 /* PS Selection 1862 * Opportunistic Power Save (1) 1863 */ 1864 1865 /* From wpa_cli user need to use separate command to set ctWindow and Opps 1866 * When user want to set ctWindow during that time other parameters 1867 * values are coming from wpa_supplicant as -1. 1868 * Example : User want to set ctWindow with 30 then wpa_cli command : 1869 * P2P_SET ctwindow 30 1870 * Command Received at hdd_hostapd_ioctl is as below: 1871 * P2P_SET_PS -1 -1 30 (legacy_ps = -1, opp_ps = -1, ctwindow = 30) 1872 * 1873 * e.g., 1: P2P_SET_PS 1 1 30 1874 * Driver sets the Opps and CTwindow as 30 and send it to FW. 1875 * e.g., 2: P2P_SET_PS 1 -1 15 1876 * Driver caches the CTwindow value but not send the command to FW. 1877 * e.g., 3: P2P_SET_PS 1 1 -1 1878 * Driver sends the command to FW with Opps enabled and CT window as 1879 * 15 (last cached CTWindow value). 1880 * (or) : P2P_SET_PS 1 1 20 1881 * Driver sends the command to FW with opps enabled and CT window 1882 * as 20. 1883 * 1884 * legacy_ps param remains unused until required in the future. 1885 */ 1886 if (ctwindow != -1) 1887 adapter->ctw = ctwindow; 1888 1889 /* Send command to FW when OppPS is either enabled(1)/disbaled(0) */ 1890 if (opp_ps != -1) { 1891 adapter->ops = opp_ps; 1892 noa.opp_ps = adapter->ops; 1893 noa.ctWindow = adapter->ctw; 1894 noa.duration = 0; 1895 noa.single_noa_duration = 0; 1896 noa.interval = 0; 1897 noa.count = 0; 1898 noa.psSelection = P2P_POWER_SAVE_TYPE_OPPORTUNISTIC; 1899 noa.sessionid = adapter->sessionId; 1900 1901 hdd_debug("P2P_PS_ATTR: oppPS %d ctWindow %d duration %d interval %d count %d single noa duration %d PsSelection %x", 1902 noa.opp_ps, noa.ctWindow, 1903 noa.duration, noa.interval, noa.count, 1904 noa.single_noa_duration, 1905 noa.psSelection); 1906 1907 sme_p2p_set_ps(handle, &noa); 1908 } 1909 1910 return 0; 1911 } 1912 1913 int hdd_set_p2p_ps(struct net_device *dev, void *msgData) 1914 { 1915 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); 1916 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); 1917 QDF_STATUS status = QDF_STATUS_SUCCESS; 1918 tP2pPsConfig NoA; 1919 p2p_app_setP2pPs_t *pappNoA = (p2p_app_setP2pPs_t *) msgData; 1920 1921 NoA.opp_ps = pappNoA->opp_ps; 1922 NoA.ctWindow = pappNoA->ctWindow; 1923 NoA.duration = pappNoA->duration; 1924 NoA.interval = pappNoA->interval; 1925 NoA.count = pappNoA->count; 1926 NoA.single_noa_duration = pappNoA->single_noa_duration; 1927 NoA.psSelection = pappNoA->psSelection; 1928 NoA.sessionid = pAdapter->sessionId; 1929 1930 sme_p2p_set_ps(hHal, &NoA); 1931 return status; 1932 } 1933 1934 static uint8_t wlan_hdd_get_session_type(enum nl80211_iftype type) 1935 { 1936 switch (type) { 1937 case NL80211_IFTYPE_AP: 1938 return QDF_SAP_MODE; 1939 case NL80211_IFTYPE_P2P_GO: 1940 return QDF_P2P_GO_MODE; 1941 case NL80211_IFTYPE_P2P_CLIENT: 1942 return QDF_P2P_CLIENT_MODE; 1943 case NL80211_IFTYPE_STATION: 1944 return QDF_STA_MODE; 1945 default: 1946 return QDF_STA_MODE; 1947 } 1948 } 1949 1950 /** 1951 * __wlan_hdd_add_virtual_intf() - Add virtual interface 1952 * @wiphy: wiphy pointer 1953 * @name: User-visible name of the interface 1954 * @name_assign_type: the name of assign type of the netdev 1955 * @nl80211_iftype: (virtual) interface types 1956 * @flags: moniter configuraiton flags (not used) 1957 * @vif_params: virtual interface parameters (not used) 1958 * 1959 * Return: the pointer of wireless dev, otherwise ERR_PTR. 1960 */ 1961 static 1962 struct wireless_dev *__wlan_hdd_add_virtual_intf(struct wiphy *wiphy, 1963 const char *name, 1964 unsigned char name_assign_type, 1965 enum nl80211_iftype type, 1966 u32 *flags, 1967 struct vif_params *params) 1968 { 1969 hdd_context_t *pHddCtx = (hdd_context_t *) wiphy_priv(wiphy); 1970 hdd_adapter_t *pAdapter = NULL; 1971 hdd_scaninfo_t *scan_info = NULL; 1972 int ret; 1973 uint8_t session_type; 1974 1975 ENTER(); 1976 1977 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { 1978 hdd_err("Command not allowed in FTM mode"); 1979 return ERR_PTR(-EINVAL); 1980 } 1981 1982 ret = wlan_hdd_validate_context(pHddCtx); 1983 if (0 != ret) 1984 return ERR_PTR(ret); 1985 1986 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, 1987 TRACE_CODE_HDD_ADD_VIRTUAL_INTF, NO_SESSION, type)); 1988 /* 1989 * Allow addition multiple interfaces for QDF_P2P_GO_MODE, 1990 * QDF_SAP_MODE, QDF_P2P_CLIENT_MODE and QDF_STA_MODE 1991 * session type. 1992 */ 1993 session_type = wlan_hdd_get_session_type(type); 1994 if (hdd_get_adapter(pHddCtx, session_type) != NULL 1995 && QDF_SAP_MODE != session_type 1996 && QDF_P2P_GO_MODE != session_type 1997 && QDF_P2P_CLIENT_MODE != session_type 1998 && QDF_STA_MODE != session_type) { 1999 hdd_err("Interface type %d already exists. Two interfaces of same type are not supported currently.", 2000 type); 2001 return ERR_PTR(-EINVAL); 2002 } 2003 2004 wlan_hdd_tdls_disable_offchan_and_teardown_links(pHddCtx); 2005 2006 pAdapter = hdd_get_adapter(pHddCtx, QDF_STA_MODE); 2007 if (pAdapter != NULL) { 2008 scan_info = &pAdapter->scan_info; 2009 if (scan_info->mScanPending) { 2010 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId, 2011 eCSR_SCAN_ABORT_DEFAULT); 2012 hdd_notice("Abort Scan while adding virtual interface"); 2013 } 2014 } 2015 2016 pAdapter = NULL; 2017 if (pHddCtx->config->isP2pDeviceAddrAdministrated && 2018 ((NL80211_IFTYPE_P2P_GO == type) || 2019 (NL80211_IFTYPE_P2P_CLIENT == type))) { 2020 /* 2021 * Generate the P2P Interface Address. this address must be 2022 * different from the P2P Device Address. 2023 */ 2024 struct qdf_mac_addr p2pDeviceAddress = 2025 pHddCtx->p2pDeviceAddress; 2026 p2pDeviceAddress.bytes[4] ^= 0x80; 2027 pAdapter = hdd_open_adapter(pHddCtx, 2028 session_type, 2029 name, p2pDeviceAddress.bytes, 2030 name_assign_type, 2031 true); 2032 } else { 2033 pAdapter = hdd_open_adapter(pHddCtx, 2034 session_type, 2035 name, 2036 wlan_hdd_get_intf_addr(pHddCtx), 2037 name_assign_type, 2038 true); 2039 } 2040 2041 if (NULL == pAdapter) { 2042 hdd_err("hdd_open_adapter failed"); 2043 return ERR_PTR(-ENOSPC); 2044 } 2045 2046 /* 2047 * Add interface can be requested from the upper layer at any time 2048 * check the statemachine for modules state and if they are closed 2049 * open the modules. 2050 */ 2051 ret = hdd_wlan_start_modules(pHddCtx, pAdapter, false); 2052 if (ret) 2053 return ERR_PTR(ret); 2054 2055 /* 2056 * Once the support for session creation/deletion from 2057 * hdd_hostapd_open/hdd_host_stop is in place. 2058 * The support for starting adapter from here can be removed. 2059 */ 2060 if (NL80211_IFTYPE_AP == type || (NL80211_IFTYPE_P2P_GO == type)) { 2061 ret = hdd_start_adapter(pAdapter); 2062 if (ret) { 2063 hdd_err("Failed to start %s", name); 2064 return ERR_PTR(-EINVAL); 2065 } 2066 } 2067 2068 if (pHddCtx->rps) 2069 hdd_send_rps_ind(pAdapter); 2070 2071 EXIT(); 2072 return pAdapter->dev->ieee80211_ptr; 2073 } 2074 2075 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)) || defined(WITH_BACKPORTS) 2076 /** 2077 * wlan_hdd_add_virtual_intf() - Add virtual interface wrapper 2078 * @wiphy: wiphy pointer 2079 * @name: User-visible name of the interface 2080 * @name_assign_type: the name of assign type of the netdev 2081 * @nl80211_iftype: (virtual) interface types 2082 * @flags: monitor mode configuration flags (not used) 2083 * @vif_params: virtual interface parameters (not used) 2084 * 2085 * Return: the pointer of wireless dev, otherwise ERR_PTR. 2086 */ 2087 struct wireless_dev *wlan_hdd_add_virtual_intf(struct wiphy *wiphy, 2088 const char *name, 2089 unsigned char name_assign_type, 2090 enum nl80211_iftype type, 2091 u32 *flags, 2092 struct vif_params *params) 2093 { 2094 struct wireless_dev *wdev; 2095 2096 cds_ssr_protect(__func__); 2097 wdev = __wlan_hdd_add_virtual_intf(wiphy, name, name_assign_type, 2098 type, flags, params); 2099 cds_ssr_unprotect(__func__); 2100 return wdev; 2101 2102 } 2103 #else 2104 /** 2105 * wlan_hdd_add_virtual_intf() - Add virtual interface wrapper 2106 * @wiphy: wiphy pointer 2107 * @name: User-visible name of the interface 2108 * @nl80211_iftype: (virtual) interface types 2109 * @flags: monitor mode configuration flags (not used) 2110 * @vif_params: virtual interface parameters (not used) 2111 * 2112 * Return: the pointer of wireless dev, otherwise ERR_PTR. 2113 */ 2114 struct wireless_dev *wlan_hdd_add_virtual_intf(struct wiphy *wiphy, 2115 const char *name, 2116 enum nl80211_iftype type, 2117 u32 *flags, 2118 struct vif_params *params) 2119 { 2120 struct wireless_dev *wdev; 2121 unsigned char name_assign_type = 0; 2122 2123 cds_ssr_protect(__func__); 2124 wdev = __wlan_hdd_add_virtual_intf(wiphy, name, name_assign_type, 2125 type, flags, params); 2126 cds_ssr_unprotect(__func__); 2127 return wdev; 2128 2129 } 2130 #endif 2131 2132 int __wlan_hdd_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev) 2133 { 2134 struct net_device *dev = wdev->netdev; 2135 hdd_context_t *pHddCtx = (hdd_context_t *) wiphy_priv(wiphy); 2136 hdd_adapter_t *pVirtAdapter = WLAN_HDD_GET_PRIV_PTR(dev); 2137 int status; 2138 ENTER(); 2139 2140 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { 2141 hdd_err("Command not allowed in FTM mode"); 2142 return -EINVAL; 2143 } 2144 2145 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, 2146 TRACE_CODE_HDD_DEL_VIRTUAL_INTF, 2147 pVirtAdapter->sessionId, pVirtAdapter->device_mode)); 2148 hdd_notice("Device_mode %s(%d)", 2149 hdd_device_mode_to_string(pVirtAdapter->device_mode), 2150 pVirtAdapter->device_mode); 2151 2152 status = wlan_hdd_validate_context(pHddCtx); 2153 2154 if (0 != status) 2155 return status; 2156 2157 /* 2158 * check state machine state and kickstart modules if they are closed. 2159 */ 2160 status = hdd_wlan_start_modules(pHddCtx, pVirtAdapter, false); 2161 if (status) 2162 return status; 2163 2164 wlan_hdd_release_intf_addr(pHddCtx, 2165 pVirtAdapter->macAddressCurrent.bytes); 2166 2167 if ((pVirtAdapter->device_mode == QDF_SAP_MODE) && 2168 wlan_sap_is_pre_cac_active(pHddCtx->hHal)) { 2169 hdd_clean_up_pre_cac_interface(pHddCtx); 2170 } 2171 2172 hdd_stop_adapter(pHddCtx, pVirtAdapter, true); 2173 hdd_close_adapter(pHddCtx, pVirtAdapter, true); 2174 EXIT(); 2175 return 0; 2176 } 2177 2178 int wlan_hdd_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev) 2179 { 2180 int ret; 2181 2182 cds_ssr_protect(__func__); 2183 ret = __wlan_hdd_del_virtual_intf(wiphy, wdev); 2184 cds_ssr_unprotect(__func__); 2185 2186 return ret; 2187 } 2188 2189 #ifdef WLAN_FEATURE_P2P_DEBUG 2190 /* 2191 * wlan_hdd_p2p_action_debug() - Log P2P state and update global status 2192 * @actionFrmType: action frame type 2193 * @macFrom: peer mac address 2194 * 2195 * return: void 2196 */ 2197 static void wlan_hdd_p2p_action_debug(tActionFrmType actionFrmType, 2198 uint8_t *macFrom) 2199 { 2200 if (actionFrmType >= MAX_P2P_ACTION_FRAME_TYPE) { 2201 hdd_err("[P2P] unknown[%d] <--- OTA from " MAC_ADDRESS_STR, 2202 actionFrmType, MAC_ADDR_ARRAY(macFrom)); 2203 } else { 2204 hdd_err("[P2P] %s <--- OTA from " MAC_ADDRESS_STR, 2205 p2p_action_frame_type[actionFrmType], 2206 MAC_ADDR_ARRAY(macFrom)); 2207 if ((actionFrmType == WLAN_HDD_PROV_DIS_REQ) 2208 && (global_p2p_connection_status == P2P_NOT_ACTIVE)) { 2209 global_p2p_connection_status = P2P_GO_NEG_PROCESS; 2210 hdd_err("[P2P State]Inactive state to GO negotiation progress state"); 2211 } else 2212 if ((actionFrmType == WLAN_HDD_GO_NEG_CNF) 2213 && (global_p2p_connection_status == P2P_GO_NEG_PROCESS)) { 2214 global_p2p_connection_status = P2P_GO_NEG_COMPLETED; 2215 hdd_err("[P2P State]GO negotiation progress to GO negotiation completed state"); 2216 } else 2217 if ((actionFrmType == WLAN_HDD_INVITATION_REQ) 2218 && (global_p2p_connection_status == P2P_NOT_ACTIVE)) { 2219 global_p2p_connection_status = P2P_GO_NEG_COMPLETED; 2220 hdd_err("[P2P State]Inactive state to GO negotiation completed state Autonomous GO formation"); 2221 } 2222 } 2223 } 2224 #else 2225 /* 2226 * wlan_hdd_p2p_action_debug() - dummy 2227 * @actionFrmType: action frame type 2228 * @macFrom: peer mac address 2229 * 2230 * return: void 2231 */ 2232 static void wlan_hdd_p2p_action_debug(tActionFrmType actionFrmType, 2233 uint8_t *macFrom) 2234 { 2235 2236 } 2237 #endif 2238 2239 void __hdd_indicate_mgmt_frame(hdd_adapter_t *pAdapter, 2240 uint32_t nFrameLength, 2241 uint8_t *pbFrames, 2242 uint8_t frameType, uint32_t rxChan, int8_t rxRssi) 2243 { 2244 uint16_t freq; 2245 uint16_t extend_time; 2246 uint8_t type = 0; 2247 uint8_t subType = 0; 2248 tActionFrmType actionFrmType; 2249 hdd_cfg80211_state_t *cfgState = NULL; 2250 QDF_STATUS status; 2251 hdd_remain_on_chan_ctx_t *pRemainChanCtx = NULL; 2252 hdd_context_t *pHddCtx; 2253 2254 hdd_info("Frame Type = %d Frame Length = %d", 2255 frameType, nFrameLength); 2256 2257 if (NULL == pAdapter) { 2258 hdd_err("pAdapter is NULL"); 2259 return; 2260 } 2261 pHddCtx = WLAN_HDD_GET_CTX(pAdapter); 2262 2263 if (0 == nFrameLength) { 2264 hdd_err("Frame Length is Invalid ZERO"); 2265 return; 2266 } 2267 2268 if (NULL == pbFrames) { 2269 hdd_err("pbFrames is NULL"); 2270 return; 2271 } 2272 2273 type = WLAN_HDD_GET_TYPE_FRM_FC(pbFrames[0]); 2274 subType = WLAN_HDD_GET_SUBTYPE_FRM_FC(pbFrames[0]); 2275 2276 /* Get pAdapter from Destination mac address of the frame */ 2277 if ((type == SIR_MAC_MGMT_FRAME) && (subType != SIR_MAC_MGMT_PROBE_REQ)) { 2278 pAdapter = 2279 hdd_get_adapter_by_macaddr(WLAN_HDD_GET_CTX(pAdapter), 2280 &pbFrames 2281 [WLAN_HDD_80211_FRM_DA_OFFSET]); 2282 if (NULL == pAdapter) { 2283 /* 2284 * Under assumtion that we don't receive any action 2285 * frame with BCST as destination, 2286 * we are dropping action frame 2287 */ 2288 hdd_alert("pAdapter for action frame is NULL Macaddr = " 2289 MAC_ADDRESS_STR, 2290 MAC_ADDR_ARRAY(&pbFrames 2291 [WLAN_HDD_80211_FRM_DA_OFFSET])); 2292 hdd_alert("Frame Type = %d Frame Length = %d subType = %d", 2293 frameType, nFrameLength, subType); 2294 return; 2295 } 2296 } 2297 2298 if (NULL == pAdapter->dev) { 2299 hdd_err("pAdapter->dev is NULL"); 2300 return; 2301 } 2302 2303 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic) { 2304 hdd_err("pAdapter has invalid magic"); 2305 return; 2306 } 2307 2308 /* Channel indicated may be wrong. TODO */ 2309 /* Indicate an action frame. */ 2310 if (rxChan <= MAX_NO_OF_2_4_CHANNELS) 2311 freq = ieee80211_channel_to_frequency(rxChan, 2312 IEEE80211_BAND_2GHZ); 2313 else 2314 freq = ieee80211_channel_to_frequency(rxChan, 2315 IEEE80211_BAND_5GHZ); 2316 2317 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(pAdapter); 2318 2319 if ((type == SIR_MAC_MGMT_FRAME) && (subType == SIR_MAC_MGMT_ACTION)) { 2320 if (pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET] == 2321 WLAN_HDD_PUBLIC_ACTION_FRAME) { 2322 /* Public action frame */ 2323 if ((pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET + 1] 2324 == SIR_MAC_ACTION_VENDOR_SPECIFIC) && 2325 !qdf_mem_cmp(&pbFrames 2326 [WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET 2327 + 2], SIR_MAC_P2P_OUI, 2328 SIR_MAC_P2P_OUI_SIZE)) { 2329 /* P2P action frames */ 2330 uint8_t *macFrom = &pbFrames 2331 [WLAN_HDD_80211_PEER_ADDR_OFFSET]; 2332 actionFrmType = 2333 pbFrames 2334 [WLAN_HDD_PUBLIC_ACTION_FRAME_TYPE_OFFSET]; 2335 hdd_info("Rx Action Frame %u", 2336 actionFrmType); 2337 2338 wlan_hdd_p2p_action_debug(actionFrmType, 2339 macFrom); 2340 2341 mutex_lock(&cfgState->remain_on_chan_ctx_lock); 2342 pRemainChanCtx = cfgState->remain_on_chan_ctx; 2343 if (pRemainChanCtx != NULL) { 2344 if (actionFrmType == WLAN_HDD_GO_NEG_REQ 2345 || actionFrmType == 2346 WLAN_HDD_GO_NEG_RESP 2347 || actionFrmType == 2348 WLAN_HDD_INVITATION_REQ 2349 || actionFrmType == 2350 WLAN_HDD_DEV_DIS_REQ 2351 || actionFrmType == 2352 WLAN_HDD_PROV_DIS_REQ) { 2353 hdd_notice("Extend RoC timer on reception of Action Frame"); 2354 2355 if ((actionFrmType == 2356 WLAN_HDD_GO_NEG_REQ) 2357 || (actionFrmType == 2358 WLAN_HDD_GO_NEG_RESP)) 2359 extend_time = 2360 2 * 2361 ACTION_FRAME_DEFAULT_WAIT; 2362 else 2363 extend_time = 2364 ACTION_FRAME_DEFAULT_WAIT; 2365 2366 if (completion_done 2367 (&pAdapter-> 2368 rem_on_chan_ready_event)) { 2369 if (QDF_TIMER_STATE_RUNNING == qdf_mc_timer_get_current_state(&pRemainChanCtx->hdd_remain_on_chan_timer)) { 2370 qdf_mc_timer_stop 2371 (&pRemainChanCtx-> 2372 hdd_remain_on_chan_timer); 2373 status = 2374 qdf_mc_timer_start 2375 (&pRemainChanCtx-> 2376 hdd_remain_on_chan_timer, 2377 extend_time); 2378 if (status != 2379 QDF_STATUS_SUCCESS) { 2380 hdd_err("Remain on Channel timer start failed"); 2381 } 2382 } else { 2383 hdd_notice("Rcvd action frame after timer expired"); 2384 } 2385 } else { 2386 /* Buffer Packet */ 2387 if (pRemainChanCtx-> 2388 action_pkt_buff. 2389 frame_length == 0) { 2390 pRemainChanCtx-> 2391 action_pkt_buff. 2392 frame_length 2393 = 2394 nFrameLength; 2395 pRemainChanCtx-> 2396 action_pkt_buff. 2397 freq = freq; 2398 pRemainChanCtx-> 2399 action_pkt_buff. 2400 frame_ptr = 2401 qdf_mem_malloc 2402 (nFrameLength); 2403 qdf_mem_copy 2404 (pRemainChanCtx-> 2405 action_pkt_buff. 2406 frame_ptr, 2407 pbFrames, 2408 nFrameLength); 2409 hdd_err("Action Pkt Cached successfully !!!"); 2410 } else { 2411 hdd_err("Frames are pending. dropping frame !!!"); 2412 } 2413 mutex_unlock(&cfgState-> 2414 remain_on_chan_ctx_lock); 2415 return; 2416 } 2417 } 2418 } 2419 mutex_unlock(&cfgState-> 2420 remain_on_chan_ctx_lock); 2421 2422 if (((actionFrmType == WLAN_HDD_PROV_DIS_RESP) 2423 && (cfgState->actionFrmState == 2424 HDD_PD_REQ_ACK_PENDING)) 2425 || ((actionFrmType == WLAN_HDD_GO_NEG_RESP) 2426 && (cfgState->actionFrmState == 2427 HDD_GO_NEG_REQ_ACK_PENDING))) { 2428 hdd_notice("ACK_PENDING and But received RESP for Action frame "); 2429 cfgState->is_go_neg_ack_received = 1; 2430 hdd_send_action_cnf(pAdapter, true); 2431 } 2432 } 2433 #ifdef FEATURE_WLAN_TDLS 2434 else if (pbFrames 2435 [WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET + 1] == 2436 WLAN_HDD_PUBLIC_ACTION_TDLS_DISC_RESP) { 2437 u8 *mac = &pbFrames 2438 [WLAN_HDD_80211_PEER_ADDR_OFFSET]; 2439 2440 hdd_notice("[TDLS] TDLS Discovery Response," 2441 MAC_ADDRESS_STR " RSSI[%d] <--- OTA", 2442 MAC_ADDR_ARRAY(mac), rxRssi); 2443 2444 wlan_hdd_tdls_set_rssi(pAdapter, mac, rxRssi); 2445 wlan_hdd_tdls_recv_discovery_resp(pAdapter, 2446 mac); 2447 cds_tdls_tx_rx_mgmt_event(SIR_MAC_ACTION_TDLS, 2448 SIR_MAC_ACTION_RX, SIR_MAC_MGMT_ACTION, 2449 WLAN_HDD_PUBLIC_ACTION_TDLS_DISC_RESP, 2450 &pbFrames[WLAN_HDD_80211_PEER_ADDR_OFFSET]); 2451 } 2452 #endif 2453 } 2454 2455 if (pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET] == 2456 WLAN_HDD_TDLS_ACTION_FRAME) { 2457 actionFrmType = 2458 pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET + 1]; 2459 if (actionFrmType >= MAX_TDLS_ACTION_FRAME_TYPE) { 2460 hdd_notice("[TDLS] unknown[%d] <--- OTA", 2461 actionFrmType); 2462 } else { 2463 hdd_notice("[TDLS] %s <--- OTA", 2464 tdls_action_frame_type[actionFrmType]); 2465 } 2466 cds_tdls_tx_rx_mgmt_event(SIR_MAC_ACTION_TDLS, 2467 SIR_MAC_ACTION_RX, SIR_MAC_MGMT_ACTION, 2468 actionFrmType, 2469 &pbFrames[WLAN_HDD_80211_PEER_ADDR_OFFSET]); 2470 } 2471 2472 if ((pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET] == 2473 WLAN_HDD_QOS_ACTION_FRAME) 2474 && (pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET + 1] == 2475 WLAN_HDD_QOS_MAP_CONFIGURE)) { 2476 sme_update_dsc_pto_up_mapping(pHddCtx->hHal, 2477 pAdapter->hddWmmDscpToUpMap, 2478 pAdapter->sessionId); 2479 } 2480 } 2481 /* Indicate Frame Over Normal Interface */ 2482 hdd_notice("Indicate Frame over NL80211 sessionid : %d, idx :%d", 2483 pAdapter->sessionId, pAdapter->dev->ifindex); 2484 2485 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)) 2486 cfg80211_rx_mgmt(pAdapter->dev->ieee80211_ptr, freq, 0, pbFrames, 2487 nFrameLength, NL80211_RXMGMT_FLAG_ANSWERED); 2488 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) 2489 cfg80211_rx_mgmt(pAdapter->dev->ieee80211_ptr, freq, 0, pbFrames, 2490 nFrameLength, NL80211_RXMGMT_FLAG_ANSWERED, 2491 GFP_ATOMIC); 2492 #else 2493 cfg80211_rx_mgmt(pAdapter->dev->ieee80211_ptr, freq, 0, 2494 pbFrames, nFrameLength, GFP_ATOMIC); 2495 #endif /* LINUX_VERSION_CODE */ 2496 } 2497 2498