Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c122595 authored by Abhinav Kumar's avatar Abhinav Kumar
Browse files

wlan: Support for PMKSA caching

propagation from qcacld-3.0 to prima

Add support for PMK and PMKID cache based on either bssid or
ssid + cache identifier

CRs-Fixed: 2531198
Change-Id: Ic29b9dc3ad0c6c3d56af297494bc746d78e838d5
parent f70293bf
Loading
Loading
Loading
Loading
+112 −18
Original line number Diff line number Diff line
@@ -19344,6 +19344,92 @@ static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
    return ret;
}
#if defined(WLAN_FEATURE_SAE) && \
		defined(CFG80211_EXTERNAL_AUTH_SUPPORT)
/*
 * wlan_hdd_is_pmksa_valid: API to validate pmksa
 * @pmksa: pointer to cfg80211_pmksa structure
 *
 * Return: True if valid else false
 */
static inline bool wlan_hdd_is_pmksa_valid(struct cfg80211_pmksa *pmksa)
{
    if (pmksa->bssid){
        return true;
    }
    else
    {
        hddLog(LOGE, FL(" Either of  bssid (%p) is NULL"), pmksa->bssid);
        return false;
    }
}
/*
 * hdd_update_pmksa_info: API to update tPmkidCacheInfo from cfg80211_pmksa
 * @pmk_cache: pmksa from supplicant
 * @pmk_cache: pmk needs to be updated
 *
 * Return: None
 */
static void hdd_update_pmksa_info(tPmkidCacheInfo *pmk_cache,
        struct cfg80211_pmksa *pmksa, bool is_delete)
{
    if (pmksa->bssid) {
        hddLog(VOS_TRACE_LEVEL_DEBUG,"set PMKSA for " MAC_ADDRESS_STR,
                MAC_ADDR_ARRAY(pmksa->bssid));
        vos_mem_copy(pmk_cache->BSSID,
               pmksa->bssid, VOS_MAC_ADDR_SIZE);
    }
    if (is_delete)
        return;
    vos_mem_copy(pmk_cache->PMKID, pmksa->pmkid, CSR_RSN_PMKID_SIZE);
    if (pmksa->pmk_len && (pmksa->pmk_len <= CSR_RSN_MAX_PMK_LEN)) {
        vos_mem_copy(pmk_cache->pmk, pmksa->pmk, pmksa->pmk_len);
        pmk_cache->pmk_len = pmksa->pmk_len;
    } else
        hddLog(VOS_TRACE_LEVEL_INFO, "pmk len is %zu", pmksa->pmk_len);
}
#else
/*
 * wlan_hdd_is_pmksa_valid: API to validate pmksa
 * @pmksa: pointer to cfg80211_pmksa structure
 *
 * Return: True if valid else false
 */
static inline bool wlan_hdd_is_pmksa_valid(struct cfg80211_pmksa *pmksa)
{
    if (!pmksa->bssid) {
        hddLog(LOGE,FL("both bssid is NULL %p"), pmksa->bssid);
        return false;
    }
    return true;
}
/*
 * hdd_update_pmksa_info: API to update tPmkidCacheInfo from cfg80211_pmksa
 * @pmk_cache: pmksa from supplicant
 * @pmk_cache: pmk needs to be updated
 *
 * Return: None
 */
static void hdd_update_pmksa_info(tPmkidCacheInfo *pmk_cache,
        struct cfg80211_pmksa *pmksa, bool is_delete)
{
    hddLog(VOS_TRACE_LEVEL_INFO,"set PMKSA for " MAC_ADDRESS_STR,
            MAC_ADDR_ARRAY(pmksa->bssid));
    vos_mem_copy(pmk_cache->BSSID,
            pmksa->bssid, VOS_MAC_ADDR_SIZE);
    if (is_delete)
        return;
    vos_mem_copy(pmk_cache->PMKID, pmksa->pmkid, CSR_RSN_PMKID_SIZE);
}
#endif
#ifdef FEATURE_WLAN_LFR
static int __wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
@@ -19354,7 +19440,7 @@ static int __wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device
    eHalStatus result;
    int status;
    hdd_context_t *pHddCtx;
    tPmkidCacheInfo pmk_id;
    tPmkidCacheInfo pmk_cache;
    ENTER();
@@ -19370,14 +19456,13 @@ static int __wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device
        return -EINVAL;
    }
    if (!pmksa->bssid || !pmksa->pmkid) {
       hddLog(LOGE, FL("pmksa->bssid(%pK) or pmksa->pmkid(%pK) is NULL"),
              pmksa->bssid, pmksa->pmkid);
    if (!pmksa->pmkid) {
       hddLog(LOGE, FL("pmksa->pmkid(%p) is NULL"), pmksa->pmkid);
       return -EINVAL;
    }
    hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
           __func__, MAC_ADDR_ARRAY(pmksa->bssid));
    if (!wlan_hdd_is_pmksa_valid(pmksa))
        return -EINVAL;
    pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
    status = wlan_hdd_validate_context(pHddCtx);
@@ -19389,12 +19474,19 @@ static int __wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device
    // Retrieve halHandle
    halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
    vos_mem_copy(pmk_id.BSSID, pmksa->bssid, ETHER_ADDR_LEN);
    vos_mem_copy(pmk_id.PMKID, pmksa->pmkid, CSR_RSN_PMKID_SIZE);
    vos_mem_zero(&pmk_cache, sizeof(pmk_cache));
    hdd_update_pmksa_info(&pmk_cache, pmksa, false);
    /* Add to the PMKSA ID Cache in CSR */
    /* Add to the PMKSA ID Cache in CSR
     * PMKSA cache will be having following
     * 1. pmkid id
     * 2. pmk 15733
     * 3. bssid or cache identifier
     */
     result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
                                   &pmk_id, 1, FALSE);
                                   &pmk_cache, 1, FALSE);
    MTRACE(vos_trace(VOS_MODULE_ID_HDD,
                     TRACE_CODE_HDD_CFG80211_SET_PMKSA,
@@ -19424,6 +19516,7 @@ static int __wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device
    tHalHandle halHandle;
    hdd_context_t *pHddCtx;
    int status = 0;
    tPmkidCacheInfo pmk_cache;
    ENTER();
@@ -19439,13 +19532,9 @@ static int __wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device
        return -EINVAL;
    }
    if (!pmksa->bssid) {
       hddLog(LOGE, FL("pmksa->bssid is NULL"));
    if (!wlan_hdd_is_pmksa_valid(pmksa))
        return -EINVAL;
    }
    hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
           __func__, MAC_ADDR_ARRAY(pmksa->bssid));
    pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
    status = wlan_hdd_validate_context(pHddCtx);
@@ -19460,10 +19549,15 @@ static int __wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device
    MTRACE(vos_trace(VOS_MODULE_ID_HDD,
                     TRACE_CODE_HDD_CFG80211_DEL_PMKSA,
                     pAdapter->sessionId, 0));
     vos_mem_zero(&pmk_cache, sizeof(pmk_cache));
     hdd_update_pmksa_info(&pmk_cache, pmksa, true);
    /* Delete the PMKID CSR cache */
    if (eHAL_STATUS_SUCCESS !=
        sme_RoamDelPMKIDfromCache(halHandle,
                                  pAdapter->sessionId, pmksa->bssid, FALSE)) {
                                  pAdapter->sessionId, &pmk_cache, FALSE)) {
        hddLog(LOGE, FL("Failed to delete PMKSA for "MAC_ADDRESS_STR),
                     MAC_ADDR_ARRAY(pmksa->bssid));
        status = -EINVAL;
+2 −0
Original line number Diff line number Diff line
@@ -149,6 +149,8 @@ typedef tANI_U8 tSirVersionString[SIR_VERSION_STRING_LEN];
#define PERIODIC_TX_PTRN_MAX_SIZE 1536
#define MAXNUM_PERIODIC_TX_PTRNS 6

/* Cache ID length */
#define CACHE_ID_LEN 2

#ifdef WLAN_FEATURE_EXTSCAN

+6 −0
Original line number Diff line number Diff line
@@ -220,6 +220,7 @@ typedef enum
#define CSR_SCAN_TIME_DEFAULT       0
#define CSR_VALUE_IGNORED           0xFFFFFFFF
#define CSR_RSN_PMKID_SIZE          16
#define CSR_RSN_MAX_PMK_LEN         48
#define CSR_MAX_PMKID_ALLOWED       32
#define CSR_WEP40_KEY_LEN       5
#define CSR_WEP104_KEY_LEN      13
@@ -848,6 +849,11 @@ typedef struct tagPmkidCacheInfo
{
    tCsrBssid BSSID;
    tANI_U8 PMKID[CSR_RSN_PMKID_SIZE];
    uint8_t pmk[CSR_RSN_MAX_PMK_LEN];
    uint8_t pmk_len;
    uint8_t ssid_len;
    uint8_t ssid[SIR_MAC_MAX_SSID_LENGTH];
    uint8_t cache_id[CACHE_ID_LEN];
}tPmkidCacheInfo;

#ifdef FEATURE_WLAN_WAPI
+2 −2
Original line number Diff line number Diff line
@@ -3731,9 +3731,9 @@ eHalStatus smeIssueFastRoamNeighborAPEvent (tHalHandle hHal,

eHalStatus sme_RoamDelPMKIDfromCache( tHalHandle hHal, tANI_U8 sessionId,
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
                                      const tANI_U8 *pBSSId,
                                      tPmkidCacheInfo *pmksa,
#else
                                      tANI_U8 *pBSSId,
                                      tPmkidCacheInfo *pmksa,
#endif
                                      tANI_BOOLEAN flush_cache );

+64 −28
Original line number Diff line number Diff line
@@ -12874,6 +12874,48 @@ tANI_U32 csrRoamGetNumBKIDCache(tpAniSirGlobal pMac, tANI_U32 sessionId)
   return (pMac->roam.roamSession[sessionId].NumBkidCache);
}
#endif /* FEATURE_WLAN_WAPI */
static void csr_update_pmk_cache(tCsrRoamSession *pSession,
        tPmkidCacheInfo *pmksa)
{
    uint16_t cache_idx = pSession->CurCacheIndex;
    /* Add entry to the cache */
    if (!pmksa->ssid_len) {
        vos_copy_macaddr(
                (v_MACADDR_t *)pSession->PmkidCacheInfo[cache_idx].BSSID,
                (v_MACADDR_t *)pmksa->BSSID);
        pSession->PmkidCacheInfo[cache_idx].ssid_len = 0;
    } else {
        vos_mem_copy(pSession->PmkidCacheInfo[cache_idx].ssid,
                pmksa->ssid, pmksa->ssid_len);
        pSession->PmkidCacheInfo[cache_idx].ssid_len =
            pmksa->ssid_len;
        vos_mem_copy(pSession->PmkidCacheInfo[cache_idx].cache_id,
                pmksa->cache_id, CACHE_ID_LEN);
    }
    vos_mem_copy(
            pSession->PmkidCacheInfo[cache_idx].PMKID,
            pmksa->PMKID, CSR_RSN_PMKID_SIZE);
    if (pmksa->pmk_len)
        vos_mem_copy(pSession->PmkidCacheInfo[cache_idx].pmk,
                pmksa->pmk, pmksa->pmk_len);
    pSession->PmkidCacheInfo[cache_idx].pmk_len = pmksa->pmk_len;
    /* Increment the CSR local cache index */
    if (cache_idx < (CSR_MAX_PMKID_ALLOWED - 1))
        pSession->CurCacheIndex++;
    else
        pSession->CurCacheIndex = 0;
    pSession->NumPmkidCache++;
    if (pSession->NumPmkidCache > CSR_MAX_PMKID_ALLOWED)
        pSession->NumPmkidCache = CSR_MAX_PMKID_ALLOWED;
}
eHalStatus csrRoamSetPMKIDCache( tpAniSirGlobal pMac, tANI_U32 sessionId,
                                 tPmkidCacheInfo *pPMKIDCache,
                                 tANI_U32 numItems,
@@ -12925,25 +12967,10 @@ eHalStatus csrRoamSetPMKIDCache( tpAniSirGlobal pMac, tANI_U32 sessionId,
                pmksa = &pPMKIDCache[i];
                /* Delete the entry if present */
                csrRoamDelPMKIDfromCache(pMac,sessionId,pmksa->BSSID,FALSE);
                csrRoamDelPMKIDfromCache(pMac,sessionId,pmksa,FALSE);
                /* Add entry to the cache */
                vos_mem_copy(
                   pSession->PmkidCacheInfo[pSession->CurCacheIndex].BSSID,
                   pmksa->BSSID, VOS_MAC_ADDR_SIZE);
                vos_mem_copy(
                   pSession->PmkidCacheInfo[pSession->CurCacheIndex].PMKID,
                   pmksa->PMKID, CSR_RSN_PMKID_SIZE);
                csr_update_pmk_cache(pSession, pmksa);
                /* Increment the CSR local cache index */
                if (pSession->CurCacheIndex < (CSR_MAX_PMKID_ALLOWED - 1))
                    pSession->CurCacheIndex++;
                else
                    pSession->CurCacheIndex = 0;
                pSession->NumPmkidCache++;
                if(pSession->NumPmkidCache > CSR_MAX_PMKID_ALLOWED)
                    pSession->NumPmkidCache = CSR_MAX_PMKID_ALLOWED;
            }
        }
    }
@@ -12952,9 +12979,9 @@ eHalStatus csrRoamSetPMKIDCache( tpAniSirGlobal pMac, tANI_U32 sessionId,
eHalStatus csrRoamDelPMKIDfromCache( tpAniSirGlobal pMac, tANI_U32 sessionId,
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
                                     const tANI_U8 *pBSSId,
                                     tPmkidCacheInfo *pmksa,
#else
                                     tANI_U8 *pBSSId,
                                     tPmkidCacheInfo *pmksa,
#endif
                                     tANI_BOOLEAN flush_cache )
{
@@ -12963,6 +12990,7 @@ eHalStatus csrRoamDelPMKIDfromCache( tpAniSirGlobal pMac, tANI_U32 sessionId,
    tANI_U32 Index;
    tANI_U32 CurIndex;
    tANI_U32 i;
    tPmkidCacheInfo *cached_pmksa;
    if(!pSession)
    {
@@ -12978,20 +13006,28 @@ eHalStatus csrRoamDelPMKIDfromCache( tpAniSirGlobal pMac, tANI_U32 sessionId,
    if (!flush_cache) {
        for (Index = 0; Index < CSR_MAX_PMKID_ALLOWED; Index++) {
            if (vos_mem_compare(pSession->PmkidCacheInfo[Index].BSSID,
                pBSSId, VOS_MAC_ADDR_SIZE)) {
             cached_pmksa = &pSession->PmkidCacheInfo[Index];
             if (((!cached_pmksa->ssid_len) &&
                  vos_is_macaddr_equal((v_MACADDR_t *)cached_pmksa->BSSID,
                                       (v_MACADDR_t *)pmksa->BSSID))) {
                  fMatchFound = 1;
             } else if ((!vos_mem_compare(cached_pmksa->ssid,
                         pmksa->ssid, pmksa->ssid_len)) &&
                         (!vos_mem_compare(cached_pmksa->cache_id,
                         pmksa->cache_id, CACHE_ID_LEN)))
                 fMatchFound = 1;
            if(fMatchFound) {
                /* Clear this - the matched entry */
                vos_mem_zero(&pSession->PmkidCacheInfo[Index],
                             sizeof(tPmkidCacheInfo));
                vos_mem_zero(cached_pmksa, sizeof(tPmkidCacheInfo));
                break;
            }
        }
        if (Index == CSR_MAX_PMKID_ALLOWED && !fMatchFound) {
            smsLog(pMac, LOG1, FL("No such PMKSA entry exists "MAC_ADDRESS_STR),
                   MAC_ADDR_ARRAY(pBSSId));
            smsLog(pMac, LOG1, FL("No such PMKSA entry exists "));
        }
        else {
            /* Match Found */
Loading