/*                                                     Global Variabls                                                                  */
 /*                                                                                                                                                      */
 /*****************************************************************************/
-
-
+/* Zero is not used, because a zero ID means termination */
+static tstrWILC_WFIDrv *wfidrv_list[NUM_CONCURRENT_IFC + 1];
 tstrWILC_WFIDrv *terminated_handle;
 tstrWILC_WFIDrv *gWFiDrvHandle;
 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 extern void chip_sleep_manually(u32 u32SleepTime);
 extern int linux_wlan_get_num_conn_ifcs(void);
 
+static int add_handler_in_list(tstrWILC_WFIDrv *handler)
+{
+       int i;
+
+       for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
+               if (!wfidrv_list[i]) {
+                       wfidrv_list[i] = handler;
+                       return 0;
+               }
+       }
+
+       return -ENOBUFS;
+}
+
+static int remove_handler_in_list(tstrWILC_WFIDrv *handler)
+{
+       int i;
+
+       for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
+               if (wfidrv_list[i] == handler) {
+                       wfidrv_list[i] = NULL;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+static int get_id_from_handler(tstrWILC_WFIDrv *handler)
+{
+       int i;
+
+       if (!handler)
+               return 0;
+
+       for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
+               if (wfidrv_list[i] == handler)
+                       return i;
+       }
+
+       return 0;
+}
+
+static tstrWILC_WFIDrv *get_handler_from_id(int id)
+{
+       if (id <= 0 || id > ARRAY_SIZE(wfidrv_list))
+               return NULL;
+       return wfidrv_list[id];
+}
+
 /**
  *  @brief Handle_SetChannel
  *  @details    Sending config packet to firmware to set channel
 
        PRINT_D(HOSTINF_DBG, "Setting channel\n");
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to set channel\n");
                WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
 
        /*Sending Cfg*/
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                pstrHostIfSetDrvHandler->u32Address);
 
        if (pstrWFIDrv == NULL)
                up(&hSemDeinitDrvHandle);
        /*Sending Cfg*/
        PRINT_INFO(HOSTINF_DBG, "pstrWFIDrv= %p\n", pstrWFIDrv);
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
 
 
        if ((pstrHostIfSetOperationMode->u32Mode) == (u32)NULL)
        strWID.ps8WidVal = (u8 *)pu8IPAddr;
        strWID.s32ValueSize = IP_ALEN;
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
 
 
        host_int_get_ipaddress(drvHandler, firmwareIPAddress, idx);
        strWID.ps8WidVal = WILC_MALLOC(IP_ALEN);
        strWID.s32ValueSize = IP_ALEN;
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
 
        PRINT_INFO(HOSTINF_DBG, "%pI4\n", strWID.ps8WidVal);
 
        strWID.s32ValueSize = ETH_ALEN;
        PRINT_D(GENERIC_DBG, "mac addr = :%pM\n", strWID.ps8WidVal);
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to set mac address\n");
                WILC_ERRORREPORT(s32Error, WILC_FAIL);
        strWID.s32ValueSize = ETH_ALEN;
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, false, (u32)drvHandler);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, false,
+                                get_id_from_handler(drvHandler));
        if (s32Error) {
                PRINT_ER("Failed to get mac address\n");
                WILC_ERRORREPORT(s32Error, WILC_FAIL);
                }
                u8WidCnt++;
        }
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u8WidCnt, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, strWIDList, u8WidCnt, false,
+                                get_id_from_handler(pstrWFIDrv));
 
        if (s32Error)
                PRINT_ER("Error in setting CFG params\n");
        else if (pstrWFIDrv->enuHostIFstate == HOST_IF_IDLE)
                gbScanWhileConnected = false;
 
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false,
+                                get_id_from_handler(pstrWFIDrv));
 
        if (s32Error) {
                PRINT_ER("Failed to send scan paramters config packet\n");
                strWID.s32ValueSize = sizeof(char);
 
                /*Sending Cfg*/
-               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                        get_id_from_handler(pstrWFIDrv));
                if (s32Error != WILC_SUCCESS) {
                        PRINT_ER("Failed to set abort running scan\n");
                        WILC_ERRORREPORT(s32Error, WILC_FAIL);
                gu32WidConnRstHack = 0;
                /* ////////////////////// */
 
-               s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
+               s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false,
+                                        get_id_from_handler(pstrWFIDrv));
                if (s32Error) {
                        PRINT_ER("Handle_Connect()] failed to send config packet\n");
                        WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
                PRINT_D(GENERIC_DBG, "save bssid = %pM\n", u8ConnectedSSID);
        }
 
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Handle_Connect()] failed to send config packet\n");
                WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
 
        #endif
 
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, gu8FlushedJoinReqDrvHandler);
+       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false,
+                                get_id_from_handler(gu8FlushedJoinReqDrvHandler));
        if (s32Error) {
                PRINT_ER("Handle_Flush_Connect()] failed to send config packet\n");
                WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
 
        PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error)
                PRINT_ER("Failed to send dissconect config packet\n");
 
                        strWIDList[3].ps8WidVal = (s8 *)pu8keybuf;
 
 
-                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 4, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 4, true,
+                                                get_id_from_handler(pstrWFIDrv));
                        kfree(pu8keybuf);
 
 
                        strWID.ps8WidVal        = (s8 *)pu8keybuf;
                        strWID.s32ValueSize = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2;
 
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                                get_id_from_handler(pstrWFIDrv));
                        kfree(pu8keybuf);
                } else if (pstrHostIFkeyAttr->u8KeyAction & REMOVEKEY)    {
 
                        strWID.ps8WidVal = s8idxarray;
                        strWID.s32ValueSize = 1;
 
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                                get_id_from_handler(pstrWFIDrv));
                } else {
                        strWID.u16WIDid = (u16)WID_KEY_ID;
                        strWID.enuWIDtype       = WID_CHAR;
 
                        PRINT_D(HOSTINF_DBG, "Setting default key index\n");
 
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                                get_id_from_handler(pstrWFIDrv));
                }
                up(&(pstrWFIDrv->hSemTestKeyBlock));
                break;
                        strWIDList[1].ps8WidVal = (s8 *)pu8keybuf;
                        strWIDList[1].s32ValueSize = RX_MIC_KEY_MSG_LEN;
 
-                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true,
+                                                get_id_from_handler(pstrWFIDrv));
 
                        kfree(pu8keybuf);
 
                        strWID.ps8WidVal        = (s8 *)pu8keybuf;
                        strWID.s32ValueSize = RX_MIC_KEY_MSG_LEN;
 
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                                get_id_from_handler(pstrWFIDrv));
 
                        kfree(pu8keybuf);
 
                        strWIDList[1].ps8WidVal = (s8 *)pu8keybuf;
                        strWIDList[1].s32ValueSize = PTK_KEY_MSG_LEN + 1;
 
-                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true,
+                                                get_id_from_handler(pstrWFIDrv));
                        kfree(pu8keybuf);
 
                        /* ////////////////////////// */
                        strWID.ps8WidVal        = (s8 *)pu8keybuf;
                        strWID.s32ValueSize = PTK_KEY_MSG_LEN;
 
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                                get_id_from_handler(pstrWFIDrv));
                        kfree(pu8keybuf);
 
                        /* ////////////////////////// */
                strWID.ps8WidVal = (s8 *)pu8keybuf;
                strWID.s32ValueSize = (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid * PMKSA_KEY_LEN) + 1;
 
-               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                        get_id_from_handler(pstrWFIDrv));
 
                kfree(pu8keybuf);
                break;
 
        memset(u8ConnectedSSID, 0, ETH_ALEN);
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(pstrWFIDrv));
 
        if (s32Error) {
                PRINT_ER("Failed to send dissconect config packet\n");
        strWID.ps8WidVal = &dummy;
        strWID.s32ValueSize = sizeof(char);
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
 
 
        if (s32Error) {
 
        PRINT_D(HOSTINF_DBG, "Getting channel value\n");
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        /*get the value by searching the local copy*/
        if (s32Error) {
                PRINT_ER("Failed to get channel number\n");
        /*Sending Cfg*/
        PRINT_D(HOSTINF_DBG, "Getting RSSI value\n");
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to get RSSI value\n");
                WILC_ERRORREPORT(s32Error, WILC_FAIL);
        /*Sending Cfg*/
        PRINT_D(HOSTINF_DBG, "Getting LINKSPEED value\n");
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to get LINKSPEED value\n");
                WILC_ERRORREPORT(s32Error, WILC_FAIL);
        strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u32TxFailureCount));
        u32WidsCount++;
 
-       s32Error = SendConfigPkt(GET_CFG, strWIDList, u32WidsCount, false, (u32)drvHandler);
+       s32Error = SendConfigPkt(GET_CFG, strWIDList, u32WidsCount, false,
+                                get_id_from_handler(drvHandler));
 
        if (s32Error) {
                PRINT_ER("Failed to send scan paramters config packet\n");
        PRINT_D(CFG80211_DBG, "SETING STA inactive time\n");
 
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        /*get the value by searching the local copy*/
        if (s32Error) {
                PRINT_ER("Failed to SET incative time\n");
        strWID.s32ValueSize = sizeof(u32);
 
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        /*get the value by searching the local copy*/
        if (s32Error) {
                PRINT_ER("Failed to get incative time\n");
 
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to send add beacon config packet\n");
                WILC_ERRORREPORT(s32Error, WILC_FAIL);
        /* TODO: build del beacon message*/
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
 
                PRINT_ER("Failed to send delete beacon config packet\n");
        pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error != WILC_SUCCESS) {
 
                PRINT_ER("Failed to send add station config packet\n");
        }
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
 
                PRINT_ER("Failed to send add station config packet\n");
        memcpy(pu8CurrByte, pstrDelStaParam->au8MacAddr, ETH_ALEN);
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
 
                PRINT_ER("Failed to send add station config packet\n");
        pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
 
                PRINT_ER("Failed to send edit station config packet\n");
        strWID.ps8WidVal[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error != WILC_SUCCESS)
                PRINT_ER("Failed to set remain on channel\n");
 
 
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to frame register config packet\n");
                WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
                strWID.ps8WidVal[1] = FALSE_FRMWR_CHANNEL;
 
                /*Sending Cfg*/
-               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                        get_id_from_handler(pstrWFIDrv));
                if (s32Error != WILC_SUCCESS) {
                        PRINT_ER("Failed to set remain on channel\n");
                        goto _done_;
        PRINT_D(HOSTINF_DBG, "Handling Power Management\n");
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to send power management config packet\n");
                WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
                memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->u32count) * ETH_ALEN));
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)drvHandler);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false,
+                                get_id_from_handler(drvHandler));
        if (s32Error) {
                PRINT_ER("Failed to send setup multicast config packet\n");
                WILC_ERRORREPORT(s32Error, WILC_FAIL);
        /* Group Buffer Timeout */
        *ptr++ = 0;
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error)
                PRINT_D(HOSTINF_DBG, "Couldn't open BA Session\n");
 
        *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
        /*Ack-Policy */
        *ptr++ = 3;
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
 
        if (strWID.ps8WidVal != NULL)
                kfree(strWID.ps8WidVal);
        /* Delba Reason */
        *ptr++ = 32; /* Unspecific QOS reason */
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error)
                PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
 
        /* TID*/
        *ptr++ = strHostIfBASessionInfo->u8Ted;
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
 
        if (strWID.ps8WidVal != NULL)
                kfree(strWID.ps8WidVal);
        /* Delba Reason */
        *ptr++ = 32; /* Unspecific QOS reason */
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error)
                PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
 
        astrWIDList[1].ps8WidVal = ppu8RcvdSiteSurveyResults[1];
        astrWIDList[1].s32ValueSize = u32MaxSiteSrvyFragLen;
 
-       s32Error = SendConfigPkt(GET_CFG, astrWIDList, 2, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, astrWIDList, 2, true,
+                                get_id_from_handler(pstrWFIDrv));
 
        /*get the value by searching the local copy*/
        if (s32Error) {
 
 
        /* Sending Configuration packet */
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Failed to send association response config packet\n");
                *pu32RcvdAssocRespInfoLen = 0;
 
        memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
        strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_WFIDRV_HANDLER;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler.u32Address = u32address;
+       strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler.u32Address = get_id_from_handler(u32address);
        strHostIFmsg.drvHandler = u32address;
 
        s32Error = wilc_mq_send(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
        strWID.s32ValueSize = sizeof(u32);
 
        /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        if (s32Error) {
                PRINT_ER("Test Function: Failed to set wid value\n");
                WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
        strWID.ps8WidVal = (s8 *)pu32TestMemAddr;
        strWID.s32ValueSize = sizeof(u32);
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true,
+                                get_id_from_handler(pstrWFIDrv));
        /*get the value by searching the local copy*/
        if (s32Error) {
                PRINT_ER("Test Function: Failed to get wid value\n");
 {
        s32 s32Error = WILC_SUCCESS;
        tstrWILC_WFIDrv *pstrWFIDrv;
+       int err;
 
        /*if(u32Intialized == 1)
         * {
        /*return driver handle to user*/
        *phWFIDrv = pstrWFIDrv;
        /*save into globl handle*/
+       err = add_handler_in_list(pstrWFIDrv);
+       if (err) {
+               s32Error = WILC_FAIL;
+               goto _fail_timer_2;
+       }
 
        #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 
 {
        s32 s32Error = WILC_SUCCESS;
        tstrHostIFmsg strHostIFmsg;
-
+       int ret;
 
        /*obtain driver handle*/
        tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
        /*Setting the gloabl driver handler with NULL*/
        u32Intialized = 0;
        /* gWFiDrvHandle = NULL; */
+       ret = remove_handler_in_list(pstrWFIDrv);
+       if (ret)
+               s32Error = WILC_NOT_FOUND;
+
        if (pstrWFIDrv != NULL) {
                kfree(pstrWFIDrv);
                /* pstrWFIDrv=NULL; */
 {
        s32 s32Error = WILC_SUCCESS;
        tstrHostIFmsg strHostIFmsg;
-       u32 drvHandler;
+       int id;
        tstrWILC_WFIDrv *pstrWFIDrv = NULL;
 
-       drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
-       pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
+       pstrWFIDrv = get_handler_from_id(id);
 
 
 
 {
        s32 s32Error = WILC_SUCCESS;
        tstrHostIFmsg strHostIFmsg;
-       u32 drvHandler;
+       int id;
        tstrWILC_WFIDrv *pstrWFIDrv = NULL;
 
        /*BugID_5348*/
        down(&hSemHostIntDeinit);
 
-       drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
-       pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
+       pstrWFIDrv = get_handler_from_id(id);
        PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n");
 
 
 {
        s32 s32Error = WILC_SUCCESS;
        tstrHostIFmsg strHostIFmsg;
-       u32 drvHandler;
+       int id;
        tstrWILC_WFIDrv *pstrWFIDrv = NULL;
 
-       drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
-       pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
+       pstrWFIDrv = get_handler_from_id(id);
 
 
        PRINT_D(GENERIC_DBG, "Scan notification received %p\n", pstrWFIDrv);