wlan : Disconnect from the AP if security params changes in beacon.

Added a support to check the change in security in beacon and if
security is changed disconnect from AP.

Handled below security changes:
WPA     <-> WEP
RSN     <-> WEP
WPA/RSN <-> WEP

Logic to handle security change from OPEN to other and vice versa
is arleady present.

CRs-Fixed: 757941
Change-Id: I756686c2d9a0caaec32ff646f3a4d892a5cf8101
diff --git a/CORE/MAC/src/include/sirParams.h b/CORE/MAC/src/include/sirParams.h
index 5234bfc..72c2214 100644
--- a/CORE/MAC/src/include/sirParams.h
+++ b/CORE/MAC/src/include/sirParams.h
@@ -123,6 +123,7 @@
 
    MAC_SPOOFED_SCAN      = 44,
    WPS_PRBRSP_TMPL       = 48,
+   BCN_IE_FLT_DELTA      = 49,
    //MAX_FEATURE_SUPPORTED = 128
 } placeHolderInCapBitmap;
 
diff --git a/CORE/MAC/src/pe/lim/limApi.c b/CORE/MAC/src/pe/lim/limApi.c
index 7a24071..058146e 100644
--- a/CORE/MAC/src/pe/lim/limApi.c
+++ b/CORE/MAC/src/pe/lim/limApi.c
@@ -1730,6 +1730,55 @@
     return retCode;
 } /*** end limHandleIBSScoalescing() ***/
 
+tAniBool limEncTypeMatched(tpAniSirGlobal pMac, tpSchBeaconStruct  pBeacon,
+                                      tpPESession    pSession)
+{
+    if (!pBeacon || !pSession)
+        return eSIR_FALSE;
+
+    limLog(pMac, LOG1,
+            FL("Beacon/Probe:: Privacy :%d WPA Present:%d RSN Present: %d"),
+                  pBeacon->capabilityInfo.privacy, pBeacon->wpaPresent,
+                                                         pBeacon->rsnPresent);
+    limLog(pMac, LOG1,
+            FL("pSession:: Privacy :%d EncyptionType: %d"),
+                  SIR_MAC_GET_PRIVACY(pSession->limCurrentBssCaps),
+                                               pSession->encryptType);
+
+    /* This is handled by sending probe req due to IOT issues so return TRUE
+     */
+    if ( (pBeacon->capabilityInfo.privacy) !=
+              SIR_MAC_GET_PRIVACY(pSession->limCurrentBssCaps))
+    {
+        limLog(pMac, LOG1, FL("Return for Privacy bit miss match, As "
+             "for this driver need to send the probe request to handle"
+             " IOT issues "));
+        return eSIR_TRUE;
+    }
+
+    /*Open*/
+    if( (pBeacon->capabilityInfo.privacy == 0) &&
+           (pSession->encryptType == eSIR_ED_NONE))
+        return eSIR_TRUE;
+
+    /* WEP */
+    if ( (pBeacon->capabilityInfo.privacy == 1) && (pBeacon->wpaPresent == 0) &&
+            (pBeacon->rsnPresent == 0) &&
+            ( (pSession->encryptType == eSIR_ED_WEP40) ||
+                     (pSession->encryptType == eSIR_ED_WEP104)))
+        return eSIR_TRUE;
+
+    /* WPA OR RSN*/
+    if ( (pBeacon->capabilityInfo.privacy == 1) &&
+           ( (pBeacon->wpaPresent == 1) ||
+             ( pBeacon->rsnPresent == 1)) &&
+            ( (pSession->encryptType == eSIR_ED_TKIP) ||
+                (pSession->encryptType == eSIR_ED_CCMP) ||
+                (pSession->encryptType == eSIR_ED_AES_128_CMAC)))
+        return eSIR_TRUE;
+
+    return eSIR_FALSE;
+}
 
 
 /**
@@ -1764,9 +1813,13 @@
     tSirSmeApNewCaps   apNewCaps;
     tANI_U8            newChannel;
     tSirRetStatus status = eSIR_SUCCESS;
+    tAniBool           securityCapsMatched = eSIR_TRUE;
+
     apNewCaps.capabilityInfo = limGetU16((tANI_U8 *) &pBeacon->capabilityInfo);
     newChannel = (tANI_U8) pBeacon->channelNumber;
 
+    securityCapsMatched = limEncTypeMatched(pMac, pBeacon, psessionEntry);
+
     if ( ( false == psessionEntry->limSentCapsChangeNtf ) &&
         ( ( ( !limIsNullSsid(&pBeacon->ssId) ) &&
              ( false == limCmpSSid(pMac, &pBeacon->ssId, psessionEntry) ) ) ||
@@ -1778,10 +1831,14 @@
             SIR_MAC_GET_SHORT_PREAMBLE(psessionEntry->limCurrentBssCaps) ) ||
           ( SIR_MAC_GET_QOS(apNewCaps.capabilityInfo) !=
             SIR_MAC_GET_QOS(psessionEntry->limCurrentBssCaps) ) ||
-          ( newChannel !=  psessionEntry->currentOperChannel )
+          ( newChannel !=  psessionEntry->currentOperChannel )  ||
+          (eSIR_FALSE == securityCapsMatched)
           ) ) )
     {
-        if( false == psessionEntry->fWaitForProbeRsp )
+        /* No need to send probe request if security
+         * capability doesnt match, Disconnect directly.*/
+        if( (false == psessionEntry->fWaitForProbeRsp) &&
+                              (eSIR_TRUE == securityCapsMatched))
         {
             /* If Beacon capabilities is not matching with the current capability,
              * then send unicast probe request to AP and take decision after
diff --git a/CORE/MAC/src/pe/lim/limSendMessages.c b/CORE/MAC/src/pe/lim/limSendMessages.c
index a2258a6..b71640f 100644
--- a/CORE/MAC/src/pe/lim/limSendMessages.c
+++ b/CORE/MAC/src/pe/lim/limSendMessages.c
@@ -71,6 +71,8 @@
    ,{SIR_MAC_VHT_OPMODE_EID,     0,  {0, 0, 0, 0}}
    ,{SIR_MAC_VHT_OPERATION_EID,  0,  {0, 0, VHTOP_CHWIDTH_MASK, 0}}
 #endif
+   ,{SIR_MAC_RSN_EID,             1, {0, 0, 0,                    0}}
+   ,{SIR_MAC_WPA_EID,             1, {0, 0, 0,                    0}}
 };
 
 /**
@@ -794,7 +796,16 @@
         retCode = eSIR_FAILURE;
         return retCode;
     }
-    msgSize = sizeof(tBeaconFilterMsg) + sizeof(beaconFilterTable);
+    /*
+     * Dont send the WPA and RSN iE in filter if FW doesnt support
+     * IS_FEATURE_BCN_FLT_DELTA_ENABLE,
+     * else host will get all beacons which have RSN IE or WPA IE
+     */
+    if(IS_FEATURE_BCN_FLT_DELTA_ENABLE)
+        msgSize = sizeof(tBeaconFilterMsg) + sizeof(beaconFilterTable);
+    else
+        msgSize = sizeof(tBeaconFilterMsg) + sizeof(beaconFilterTable) - (2 * sizeof(tBeaconFilterIe));
+
     pBeaconFilterMsg = vos_mem_malloc(msgSize);
     if ( NULL == pBeaconFilterMsg )
     {
@@ -810,7 +821,16 @@
     pBeaconFilterMsg->capabilityMask = CAPABILITY_FILTER_MASK;
     pBeaconFilterMsg->beaconInterval = (tANI_U16) psessionEntry->beaconParams.beaconInterval;
     // Fill in number of IEs in beaconFilterTable
-    pBeaconFilterMsg->ieNum = (tANI_U16) (sizeof(beaconFilterTable) / sizeof(tBeaconFilterIe));
+    /*
+     * Dont send the WPA and RSN iE in filter if FW doesnt support
+     * IS_FEATURE_BCN_FLT_DELTA_ENABLE,
+     * else host will get all beacons which have RSN IE or WPA IE
+     */
+    if(IS_FEATURE_BCN_FLT_DELTA_ENABLE)
+        pBeaconFilterMsg->ieNum = (tANI_U16) (sizeof(beaconFilterTable) / sizeof(tBeaconFilterIe));
+    else
+        pBeaconFilterMsg->ieNum = (tANI_U16) ((sizeof(beaconFilterTable) / sizeof(tBeaconFilterIe)) - 2);
+
     //Fill the BSSIDX
     pBeaconFilterMsg->bssIdx = psessionEntry->bssIdx;
 
diff --git a/CORE/WDA/inc/wlan_qct_wda.h b/CORE/WDA/inc/wlan_qct_wda.h
index a3db25e..f8f3d6c 100644
--- a/CORE/WDA/inc/wlan_qct_wda.h
+++ b/CORE/WDA/inc/wlan_qct_wda.h
@@ -134,6 +134,7 @@
 
 #define IS_FW_IN_TX_PATH_FEATURE_ENABLE ((WDI_getHostWlanFeatCaps(FW_IN_TX_PATH)) & (WDA_getFwWlanFeatCaps(FW_IN_TX_PATH)))
 #define IS_MUMIMO_BFORMEE_CAPABLE ((WDI_getHostWlanFeatCaps(MU_MIMO)) & (WDA_getFwWlanFeatCaps(MU_MIMO)))
+#define IS_FEATURE_BCN_FLT_DELTA_ENABLE ((WDI_getHostWlanFeatCaps(BCN_IE_FLT_DELTA)) & (WDA_getFwWlanFeatCaps(BCN_IE_FLT_DELTA)))
 /*--------------------------------------------------------------------------
   Utilities
  --------------------------------------------------------------------------*/
diff --git a/CORE/WDI/CP/inc/wlan_qct_wdi.h b/CORE/WDI/CP/inc/wlan_qct_wdi.h
index 93b6f18..a9cd910 100644
--- a/CORE/WDI/CP/inc/wlan_qct_wdi.h
+++ b/CORE/WDI/CP/inc/wlan_qct_wdi.h
@@ -127,7 +127,7 @@
 #define TOTALFRAGMENTS(x) (((x % FRAGMENT_SIZE) == 0) ? (x / FRAGMENT_SIZE):((x / FRAGMENT_SIZE) + 1))
 
 /* Beacon Filter Length*/
-#define WDI_BEACON_FILTER_LEN 70
+#define WDI_BEACON_FILTER_LEN 90
 
 /* Coex Indication data size - should match WLAN_COEX_IND_DATA_SIZE */
 #define WDI_COEX_IND_DATA_SIZE (4)
diff --git a/CORE/WDI/CP/src/wlan_qct_wdi.c b/CORE/WDI/CP/src/wlan_qct_wdi.c
index 66d54f3..d4599ed 100644
--- a/CORE/WDI/CP/src/wlan_qct_wdi.c
+++ b/CORE/WDI/CP/src/wlan_qct_wdi.c
@@ -194,6 +194,7 @@
    ,FEATURE_NOT_SUPPORTED          //46
    ,FEATURE_NOT_SUPPORTED          //47
    ,WPS_PRBRSP_TMPL                //48
+   ,BCN_IE_FLT_DELTA               //49
 
 };
 
@@ -1401,6 +1402,10 @@
                      case WPS_PRBRSP_TMPL: snprintf(pCapStr, sizeof("WPS_PRBRSP_TMPL"), "%s", "WPS_PRBRSP_TMPL");
                           pCapStr += strlen("WPS_PRBRSP_TMPL");
                           break;
+                     case BCN_IE_FLT_DELTA: snprintf(pCapStr, sizeof("BCN_IE_FLT_DELTA"), "%s", "BCN_IE_FLT_DELTA");
+                          pCapStr += strlen("BCN_IE_FLT_DELTA");
+                          break;
+
 
                  }
                  *pCapStr++ = ',';