From d915283486b76e24b3e6f8dfc9648f817e49be68 Mon Sep 17 00:00:00 2001 From: Nachiket Kukade Date: Mon, 16 Oct 2017 16:18:22 +0530 Subject: [PATCH] qcacld-3.0: Correction in conditional logic in key operations In set default key operation module, under SAP mode, there are conditional checks on key type information derived from the Station's context. Also in get/add key operations SAP or STA context pointers are derived without knowing the device mode first, which is incorrect. Derive key type info from SAP context in set default key and derive station or sap context pointers only after knowing the device mode. Change-Id: I09b0e6f8d6315677e7584c7c24f003daa3eca9a3 CRs-Fixed: 2127288 --- core/hdd/src/wlan_hdd_cfg80211.c | 56 ++++++++++++++++++++++---------- core/sap/inc/sap_api.h | 10 ++++++ core/sap/src/sap_module.c | 18 ++++++++++ 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/core/hdd/src/wlan_hdd_cfg80211.c b/core/hdd/src/wlan_hdd_cfg80211.c index 0ab451a6c0ad..cab3ef7d659e 100644 --- a/core/hdd/src/wlan_hdd_cfg80211.c +++ b/core/hdd/src/wlan_hdd_cfg80211.c @@ -14249,10 +14249,8 @@ static int __wlan_hdd_cfg80211_add_key(struct wiphy *wiphy, tCsrRoamSetKey setKey; int status; uint32_t roamId = INVALID_ROAM_ID; - struct hdd_hostapd_state *hostapd_state; QDF_STATUS qdf_ret_status; struct hdd_context *hdd_ctx; - struct hdd_ap_ctx *ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter); ENTER(); @@ -14432,7 +14430,11 @@ static int __wlan_hdd_cfg80211_add_key(struct wiphy *wiphy, } if ((adapter->device_mode == QDF_SAP_MODE) || (adapter->device_mode == QDF_P2P_GO_MODE)) { - hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter); + struct hdd_hostapd_state *hostapd_state = + WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter); + struct hdd_ap_ctx *ap_ctx = + WLAN_HDD_GET_AP_CTX_PTR(adapter); + if (hostapd_state->bss_state == BSS_START) { status = wlansap_set_key_sta( WLAN_HDD_GET_SAP_CTX_PTR(adapter), &setKey); @@ -14570,9 +14572,7 @@ static int __wlan_hdd_cfg80211_get_key(struct wiphy *wiphy, ) { struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev); - struct hdd_wext_state *pWextState = - WLAN_HDD_GET_WEXT_STATE_PTR(adapter); - tCsrRoamProfile *roam_profile = &(pWextState->roamProfile); + tCsrRoamProfile *roam_profile; struct key_params params; ENTER(); @@ -14593,6 +14593,18 @@ static int __wlan_hdd_cfg80211_get_key(struct wiphy *wiphy, return -EINVAL; } + if ((adapter->device_mode == QDF_SAP_MODE) || + (adapter->device_mode == QDF_P2P_GO_MODE)) { + struct hdd_ap_ctx *ap_ctx = + WLAN_HDD_GET_AP_CTX_PTR(adapter); + roam_profile = + wlan_sap_get_roam_profile(ap_ctx->sap_context); + } else { + struct hdd_wext_state *pWextState = + WLAN_HDD_GET_WEXT_STATE_PTR(adapter); + roam_profile = &(pWextState->roamProfile); + } + switch (roam_profile->EncryptionType.encryptionType[0]) { case eCSR_ENCRYPT_TYPE_NONE: params.cipher = IW_AUTH_CIPHER_NONE; @@ -14741,10 +14753,6 @@ static int __wlan_hdd_cfg80211_set_default_key(struct wiphy *wiphy, bool unicast, bool multicast) { struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(ndev); - struct hdd_wext_state *pWextState = - WLAN_HDD_GET_WEXT_STATE_PTR(adapter); - struct hdd_station_ctx *sta_ctx = - WLAN_HDD_GET_STATION_CTX_PTR(adapter); struct hdd_context *hdd_ctx; int status; @@ -14781,6 +14789,11 @@ static int __wlan_hdd_cfg80211_set_default_key(struct wiphy *wiphy, if ((adapter->device_mode == QDF_STA_MODE) || (adapter->device_mode == QDF_P2P_CLIENT_MODE)) { + struct hdd_wext_state *pWextState = + WLAN_HDD_GET_WEXT_STATE_PTR(adapter); + struct hdd_station_ctx *sta_ctx = + WLAN_HDD_GET_STATION_CTX_PTR(adapter); + if ((eCSR_ENCRYPT_TYPE_TKIP != sta_ctx->conn_info.ucEncryptionType) && !hdd_is_wapi_enc_type( @@ -14850,23 +14863,30 @@ static int __wlan_hdd_cfg80211_set_default_key(struct wiphy *wiphy, } } } else if (QDF_SAP_MODE == adapter->device_mode) { + struct hdd_ap_ctx *ap_ctx = + WLAN_HDD_GET_AP_CTX_PTR(adapter); + tCsrRoamProfile *profile = + wlan_sap_get_roam_profile(ap_ctx->sap_context); + + if (!profile) { + hdd_err("Failed to get SAP Roam Profile"); + return -EINVAL; + } /* In SoftAp mode setting key direction for default mode */ if ((eCSR_ENCRYPT_TYPE_TKIP != - pWextState->roamProfile.EncryptionType.encryptionType[0]) && + profile->EncryptionType.encryptionType[0]) && (eCSR_ENCRYPT_TYPE_AES != - pWextState->roamProfile.EncryptionType.encryptionType[0]) && + profile->EncryptionType.encryptionType[0]) && (eCSR_ENCRYPT_TYPE_AES_GCMP != - pWextState->roamProfile.EncryptionType.encryptionType[0]) && + profile->EncryptionType.encryptionType[0]) && (eCSR_ENCRYPT_TYPE_AES_GCMP_256 != - pWextState->roamProfile.EncryptionType.encryptionType[0])) { + profile->EncryptionType.encryptionType[0])) { /* Saving key direction for default key index to TX default */ - struct hdd_ap_ctx *pAPCtx = - WLAN_HDD_GET_AP_CTX_PTR(adapter); - pAPCtx->wep_key[key_index].keyDirection = + ap_ctx->wep_key[key_index].keyDirection = eSIR_TX_DEFAULT; hdd_debug("WEP default key index set to SAP context %d", key_index); - pAPCtx->wep_def_key_idx = key_index; + ap_ctx->wep_def_key_idx = key_index; } } diff --git a/core/sap/inc/sap_api.h b/core/sap/inc/sap_api.h index 48d709f9a444..9afe04e5154f 100644 --- a/core/sap/inc/sap_api.h +++ b/core/sap/inc/sap_api.h @@ -1250,6 +1250,16 @@ QDF_STATUS wlansap_set_dfs_preferred_channel_location(tHalHandle hHal, QDF_STATUS wlansap_set_dfs_target_chnl(tHalHandle hHal, uint8_t target_channel); +/** + * wlan_sap_get_roam_profile() - Returns sap roam profile. + * @sap_ctx: Pointer to Sap Context. + * + * This function provides the SAP roam profile. + * + * Return: SAP RoamProfile + */ +tCsrRoamProfile *wlan_sap_get_roam_profile(struct sap_context *sap_ctx); + /** * wlan_sap_get_phymode() - Returns sap phymode. * @sap_ctx: Pointer to Sap Context. diff --git a/core/sap/src/sap_module.c b/core/sap/src/sap_module.c index 8b543cb197c9..7716d333429e 100644 --- a/core/sap/src/sap_module.c +++ b/core/sap/src/sap_module.c @@ -584,6 +584,24 @@ wlansap_set_scan_acs_channel_params(tsap_Config_t *pconfig, return status; } +/** + * wlan_sap_get_roam_profile() - Returns sap roam profile. + * @sap_ctx: Pointer to Sap Context. + * + * This function provides the SAP roam profile. + * + * Return: SAP RoamProfile + */ +tCsrRoamProfile *wlan_sap_get_roam_profile(struct sap_context *sap_ctx) +{ + if (!sap_ctx) { + QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_ERROR, + FL("Invalid SAP pointer from ctx")); + return NULL; + } + return &sap_ctx->csr_roamProfile; +} + eCsrPhyMode wlan_sap_get_phymode(struct sap_context *sap_ctx) { if (!sap_ctx) {