/*----------------------------------------------------------------------------*/ P_STA_RECORD_T staRecGetStaRecordByAddr ( IN P_ADAPTER_T prAdapter, IN PUINT_8 pucStaAddr ) { P_STA_INFO_T prStaInfo; P_LINK_T prValidStaRecList; P_STA_RECORD_T prStaRec; ASSERT(prAdapter); ASSERT(pucStaAddr); prStaInfo = &prAdapter->rStaInfo; if (pucStaAddr) { /* To get the proper valid list through hash function */ prValidStaRecList = &prStaInfo->arValidStaRecList[STA_RECORD_HASH_FUNC(pucStaAddr)]; /* Check if such STA record exists in a valid list */ LINK_FOR_EACH_ENTRY(prStaRec, prValidStaRecList, rLinkEntry, STA_RECORD_T) { STA_RECORD_CHK_GUID(prStaRec); if (EQUAL_MAC_ADDR(pucStaAddr, prStaRec->aucMacAddr)) { return prStaRec; } } }
/*----------------------------------------------------------------------------*/ BOOLEAN kalP2PCmpBlackList ( IN P_GLUE_INFO_T prGlueInfo, IN PARAM_MAC_ADDRESS rbssid ) { UINT_8 aucNullAddr[] = NULL_MAC_ADDR; BOOLEAN fgIsExsit = FALSE; UINT_32 i; ASSERT(prGlueInfo); ASSERT(prGlueInfo->prP2PInfo); for(i = 0; i < 8; i++) { if(UNEQUAL_MAC_ADDR(rbssid, aucNullAddr)){ if(EQUAL_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), rbssid)) { fgIsExsit = TRUE; return fgIsExsit; } } } return fgIsExsit; }
/*----------------------------------------------------------------------------*/ VOID secPrivacyFreeSta ( IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec ) { UINT_32 entry; P_WLAN_TABLE_T prWtbl; if (!prStaRec) return; prWtbl = prAdapter->rWifiVar.arWtbl; prStaRec->ucWlanIndex = WTBL_RESERVED_ENTRY; prStaRec->ucBMCWlanIndex = WTBL_RESERVED_ENTRY; //if ((IS_ADHOC_STA(prStaRec) || IS_STA_IN_AIS(prStaRec)) /* && prStaRec->ucBMCWlanIndex < WTBL_SIZE */) { //the hotspot mode would be assert after connect-disconnect field try WTBL_SIZE times if (TRUE) { for (entry = 0; entry < WTBL_SIZE; entry++) { if (prWtbl[entry].ucUsed && EQUAL_MAC_ADDR(prStaRec->aucMacAddr, prWtbl[entry].aucMacAddr)) { secPrivacyFreeForEntry(prAdapter, entry); #if 1//DBG DBGLOG(RSN, INFO, ("Free the STA entry (%lu)!\n", entry)); #endif } } } }
/*----------------------------------------------------------------------------*/ VOID secPrivacyFreeSta ( IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec ) { UINT_32 entry; P_WLAN_TABLE_T prWtbl; if (!prStaRec) return; prWtbl = prAdapter->rWifiVar.arWtbl; prStaRec->ucWlanIndex = WTBL_RESERVED_ENTRY; prStaRec->ucBMCWlanIndex = WTBL_RESERVED_ENTRY; if ((IS_ADHOC_STA(prStaRec) || IS_STA_IN_AIS(prStaRec)) /* && prStaRec->ucBMCWlanIndex < WTBL_SIZE */) { for (entry = 0; entry < WTBL_SIZE; entry++) { if (prWtbl[entry].ucUsed && EQUAL_MAC_ADDR(prStaRec->aucMacAddr, prWtbl[entry].aucMacAddr)) { secPrivacyFreeForEntry(prAdapter, entry); #if DBG DBGLOG(RSN, TRACE, ("Free the STA entry (%lu)!\n", entry)); #endif } } } }
/*----------------------------------------------------------------------------*/ ENUM_BOW_DEVICE_STATE kalGetBowState(IN P_GLUE_INFO_T prGlueInfo, IN UINT_8 aucPeerAddress[6] ) { UINT_8 i; ASSERT(prGlueInfo); #if CFG_BOW_TEST DBGLOG(BOW, EVENT, ("kalGetBowState.\n")); #endif for (i = 0; i < CFG_BOW_PHYSICAL_LINK_NUM; i++) { if (EQUAL_MAC_ADDR(prGlueInfo->rBowInfo.arPeerAddr, aucPeerAddress) == 0) { #if CFG_BOW_TEST DBGLOG(BOW, EVENT, ("kalGetBowState, aucPeerAddress %x, %x:%x:%x:%x:%x:%x.\n", i, aucPeerAddress[0], aucPeerAddress[1], aucPeerAddress[2], aucPeerAddress[3], aucPeerAddress[4], aucPeerAddress[5])); DBGLOG(BOW, EVENT, ("kalGetBowState, prGlueInfo->rBowInfo.aeState %x, %x.\n", i, prGlueInfo->rBowInfo.aeState[i])); #endif return prGlueInfo->rBowInfo.aeState[i]; } } return BOW_DEVICE_STATE_DISCONNECTED; }
/*----------------------------------------------------------------------------*/ BOOLEAN kalP2PSetBlackList ( IN P_GLUE_INFO_T prGlueInfo, IN PARAM_MAC_ADDRESS rbssid, IN BOOLEAN fgIsblock ) { UINT_8 aucNullAddr[] = NULL_MAC_ADDR; BOOLEAN fgIsValid = FALSE; UINT_32 i; ASSERT(prGlueInfo); ASSERT(prGlueInfo->prP2PInfo); if(fgIsblock) { for(i = 0; i < 8; i++) { if(UNEQUAL_MAC_ADDR(rbssid, aucNullAddr)) { if(UNEQUAL_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), rbssid)) { if(EQUAL_MAC_ADDR (&(prGlueInfo->prP2PInfo->aucblackMACList[i]), aucNullAddr)) { COPY_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), rbssid); fgIsValid = FALSE; return fgIsValid; } } } } } else { for(i = 0; i < 8; i++) { if(EQUAL_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), rbssid)) { COPY_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), aucNullAddr); fgIsValid = FALSE; return fgIsValid; } } } return fgIsValid; }
/*----------------------------------------------------------------------------*/ VOID kalSetBowRole(IN P_GLUE_INFO_T prGlueInfo, IN UINT_8 ucRole, IN PARAM_MAC_ADDRESS rPeerAddr) { UINT_32 i; ASSERT(prGlueInfo); ASSERT(ucRole <= 1); for (i = 0; i < CFG_BOW_PHYSICAL_LINK_NUM; i++) { if (EQUAL_MAC_ADDR(prGlueInfo->rBowInfo.arPeerAddr[i], rPeerAddr) == 0) { prGlueInfo->rBowInfo.aucRole[i] = ucRole; /* Henry, 0 : Responder, 1 : Initiator */ } } }
/*----------------------------------------------------------------------------*/ UINT_8 kalGetBowRole(IN P_GLUE_INFO_T prGlueInfo, IN PARAM_MAC_ADDRESS rPeerAddr) { UINT_32 i; ASSERT(prGlueInfo); for (i = 0; i < CFG_BOW_PHYSICAL_LINK_NUM; i++) { if (EQUAL_MAC_ADDR(prGlueInfo->rBowInfo.arPeerAddr[i], rPeerAddr) == 0) { return prGlueInfo->rBowInfo.aucRole[i]; } } return 0; }
/*----------------------------------------------------------------------------*/ INT_32 kalP2PSetBlackList(IN P_GLUE_INFO_T prGlueInfo, IN PARAM_MAC_ADDRESS rbssid, IN BOOLEAN fgIsblock) { UINT_8 aucNullAddr[] = NULL_MAC_ADDR; UINT_32 i; ASSERT(prGlueInfo); ASSERT(prGlueInfo->prP2PInfo); if (EQUAL_MAC_ADDR(rbssid, aucNullAddr)) return -EINVAL; if (fgIsblock) { for (i = 0; i < 8; i++) { if (EQUAL_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), rbssid)) { break; } else if (EQUAL_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), aucNullAddr)) { COPY_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), rbssid); break; } } if (i >= 8) { DBGLOG(P2P, ERROR, "AP black list is full, cannot block more STA!!\n"); return -ENOBUFS; } } else { for (i = 0; i < 8; i++) { if (EQUAL_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), rbssid)) { COPY_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucblackMACList[i]), aucNullAddr); break; } } if (i >= 8) DBGLOG(P2P, ERROR, "The STA is not found in black list!!\n"); } return 0; }
/*----------------------------------------------------------------------------*/ BOOLEAN kalSetBowState(IN P_GLUE_INFO_T prGlueInfo, IN ENUM_BOW_DEVICE_STATE eBowState, IN UINT_8 aucPeerAddress[6] ) { UINT_8 i; ASSERT(prGlueInfo); #if CFG_BOW_TEST DBGLOG(BOW, EVENT, ("kalSetBowState.\n")); DBGLOG(BOW, EVENT, ("kalSetBowState, prGlueInfo->rBowInfo.arPeerAddr, %x:%x:%x:%x:%x:%x.\n", prGlueInfo->rBowInfo.arPeerAddr[0], prGlueInfo->rBowInfo.arPeerAddr[1], prGlueInfo->rBowInfo.arPeerAddr[2], prGlueInfo->rBowInfo.arPeerAddr[3], prGlueInfo->rBowInfo.arPeerAddr[4], prGlueInfo->rBowInfo.arPeerAddr[5])); DBGLOG(BOW, EVENT, ("kalSetBowState, aucPeerAddress, %x:%x:%x:%x:%x:%x.\n", aucPeerAddress[0], aucPeerAddress[1], aucPeerAddress[2], aucPeerAddress[3], aucPeerAddress[4], aucPeerAddress[5])); #endif for (i = 0; i < CFG_BOW_PHYSICAL_LINK_NUM; i++) { if (EQUAL_MAC_ADDR(prGlueInfo->rBowInfo.arPeerAddr, aucPeerAddress) == 0) { prGlueInfo->rBowInfo.aeState[i] = eBowState; #if CFG_BOW_TEST DBGLOG(BOW, EVENT, ("kalSetBowState, aucPeerAddress %x, %x:%x:%x:%x:%x:%x.\n", i, aucPeerAddress[0], aucPeerAddress[1], aucPeerAddress[2], aucPeerAddress[3], aucPeerAddress[4], aucPeerAddress[5])); DBGLOG(BOW, EVENT, ("kalSetBowState, prGlueInfo->rBowInfo.aeState %x, %x.\n", i, prGlueInfo->rBowInfo.aeState[i])); #endif return TRUE; } } return FALSE; }
/*----------------------------------------------------------------------------*/ UINT_8 secLookupStaRecIndexFromTA(P_ADAPTER_T prAdapter, PUINT_8 pucMacAddress) { int i; P_WLAN_TABLE_T prWtbl; ASSERT(prAdapter); prWtbl = prAdapter->rWifiVar.arWtbl; for (i = 0; i < WTBL_SIZE; i++) { if (prWtbl[i].ucUsed) { if (EQUAL_MAC_ADDR(pucMacAddress, prWtbl[i].aucMacAddr)) { return prWtbl[i].ucStaIndex; } } } return 0xff; }
/*----------------------------------------------------------------------------*/ WLAN_STATUS wlanoidSetP2PTerminateSDPhase(IN P_ADAPTER_T prAdapter, IN PVOID pvSetBuffer, IN UINT_32 u4SetBufferLen, OUT PUINT_32 pu4SetInfoLen) { WLAN_STATUS rWlanStatus = WLAN_STATUS_SUCCESS; P_PARAM_P2P_TERMINATE_SD_PHASE prP2pTerminateSD = (P_PARAM_P2P_TERMINATE_SD_PHASE) NULL; UINT_8 aucNullAddr[] = NULL_MAC_ADDR; do { if ((prAdapter == NULL) || (pu4SetInfoLen == NULL)) { break; } if ((u4SetBufferLen) && (pvSetBuffer == NULL)) { break; } if (u4SetBufferLen < sizeof(PARAM_P2P_TERMINATE_SD_PHASE)) { *pu4SetInfoLen = sizeof(PARAM_P2P_TERMINATE_SD_PHASE); rWlanStatus = WLAN_STATUS_BUFFER_TOO_SHORT; break; } prP2pTerminateSD = (P_PARAM_P2P_TERMINATE_SD_PHASE) pvSetBuffer; if (EQUAL_MAC_ADDR(prP2pTerminateSD->rPeerAddr, aucNullAddr)) { DBGLOG(P2P, TRACE, ("Service Discovery Version 2.0\n")); /* p2pFuncSetVersionNumOfSD(prAdapter, 2); */ } /* rWlanStatus = p2pFsmRunEventSDAbort(prAdapter); */ } while (FALSE); return rWlanStatus; } /* end of wlanoidSetP2PTerminateSDPhase() */
/*----------------------------------------------------------------------------*/ VOID nicRxAddP2pDevice ( IN P_ADAPTER_T prAdapter, IN P_EVENT_P2P_DEV_DISCOVER_RESULT_T prP2pResult, IN PUINT_8 pucRxIEBuf, IN UINT_16 u2RxIELength ) { P_P2P_INFO_T prP2pInfo = (P_P2P_INFO_T)NULL; P_EVENT_P2P_DEV_DISCOVER_RESULT_T prTargetResult = (P_EVENT_P2P_DEV_DISCOVER_RESULT_T)NULL; UINT_32 u4Idx = 0; BOOLEAN bUpdate = FALSE; PUINT_8 pucIeBuf = (PUINT_8)NULL; UINT_16 u2IELength = 0; UINT_8 zeroMac[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; ASSERT(prAdapter); prP2pInfo = prAdapter->prP2pInfo; for (u4Idx = 0; u4Idx < prP2pInfo->u4DeviceNum; u4Idx++) { prTargetResult = &prP2pInfo->arP2pDiscoverResult[u4Idx]; if (EQUAL_MAC_ADDR(prTargetResult->aucDeviceAddr, prP2pResult->aucDeviceAddr)) { bUpdate = TRUE; /* Backup OLD buffer result. */ pucIeBuf = prTargetResult->pucIeBuf; u2IELength = prTargetResult->u2IELength; /* Update Device Info. */ // zero kalMemZero(prTargetResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T)); // then buffer kalMemCopy(prTargetResult, (PVOID)prP2pResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T)); /* See if new IE length is longer or not. */ if ((u2RxIELength > u2IELength) && (u2IELength != 0)) { /* Buffer is not enough. */ u2RxIELength = u2IELength; } else if ((u2IELength == 0) && (u2RxIELength != 0)) { /* RX new IE buf. */ ASSERT(pucIeBuf == NULL); pucIeBuf = prP2pInfo->pucCurrIePtr; if (((UINT_32)prP2pInfo->pucCurrIePtr + (UINT_32)u2RxIELength) > (UINT_32)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN]) { /* Common Buffer is no enough. */ u2RxIELength = (UINT_16)((UINT_32)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN] - (UINT_32)prP2pInfo->pucCurrIePtr); } /* Step to next buffer address. */ prP2pInfo->pucCurrIePtr = (PUINT_8)((UINT_32)prP2pInfo->pucCurrIePtr + (UINT_32)u2RxIELength); } /* Restore buffer pointer. */ prTargetResult->pucIeBuf = pucIeBuf; if (pucRxIEBuf) { /* If new received IE is availabe. * Replace the old one & update new IE length. */ kalMemCopy(pucIeBuf, pucRxIEBuf, u2RxIELength); prTargetResult->u2IELength = u2RxIELength; } else { /* There is no new IE information, keep the old one. */ prTargetResult->u2IELength = u2IELength; } } } if (!bUpdate) { /* We would flush the whole scan result after each scan request is issued. * If P2P device is too many, it may over the scan list. */ if ((u4Idx < CFG_MAX_NUM_BSS_LIST) && (UNEQUAL_MAC_ADDR(zeroMac, prP2pResult->aucDeviceAddr))) { /* whsu:XXX */ prTargetResult = &prP2pInfo->arP2pDiscoverResult[u4Idx]; // zero kalMemZero(prTargetResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T)); // then buffer kalMemCopy(prTargetResult, (PVOID)prP2pResult, sizeof(EVENT_P2P_DEV_DISCOVER_RESULT_T)); //printk("DVC FND %d " MACSTR", " MACSTR "\n", prP2pInfo->u4DeviceNum, MAC2STR(prP2pResult->aucDeviceAddr), MAC2STR(prTargetResult->aucDeviceAddr)); if (u2RxIELength) { prTargetResult->pucIeBuf = prP2pInfo->pucCurrIePtr; if (((UINT_32)prP2pInfo->pucCurrIePtr + (UINT_32)u2RxIELength) > (UINT_32)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN]) { /* Common Buffer is no enough. */ u2IELength = (UINT_16)((UINT_32)&prP2pInfo->aucCommIePool[CFG_MAX_COMMON_IE_BUF_LEN] - (UINT_32)prP2pInfo->pucCurrIePtr); } else { u2IELength = u2RxIELength; } prP2pInfo->pucCurrIePtr = (PUINT_8)((UINT_32)prP2pInfo->pucCurrIePtr + (UINT_32)u2IELength); kalMemCopy((PVOID)prTargetResult->pucIeBuf, (PVOID)pucRxIEBuf, (UINT_32)u2IELength); prTargetResult->u2IELength = u2IELength; } else { prTargetResult->pucIeBuf = NULL; prTargetResult->u2IELength = 0; } prP2pInfo->u4DeviceNum++; } else { // TODO: Fixme to replace an old one. (?) ASSERT(FALSE); } } } /* nicRxAddP2pDevice */
/*----------------------------------------------------------------------------*/ BOOL secPrivacySeekForEntry ( IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta ) { UINT_8 ucEntry = WTBL_RESERVED_ENTRY; UINT_8 i; UINT_8 ucStartIDX = 0, ucMaxIDX = 0; P_WLAN_TABLE_T prWtbl; ASSERT(prSta); if (!prSta->fgIsInUse) ASSERT(FALSE); DBGLOG(RSN, TRACE, (MACSTR"\n", MAC2STR(prSta->aucMacAddr))); prWtbl = prAdapter->rWifiVar.arWtbl; #if 1 ucStartIDX = 0; ucMaxIDX = NIC_TX_DEFAULT_WLAN_INDEX - 1; #else if (prSta->eStaType == STA_TYPE_DLS_PEER) { ucStartIDX = WTBL_STA_IDX_MAX; ucMaxIDX = WTBL_AIS_DLS_MAX_IDX; } else if (IS_ADHOC_STA(prSta)) { ucStartIDX = 0; ucMaxIDX = WTBL_IBSS_STA_IDX_MAX; } else { ucStartIDX = 0; ucMaxIDX = WTBL_STA_IDX_MAX; } #endif if (ucStartIDX != 0 || ucMaxIDX != 0) { if (ucStartIDX > ucMaxIDX) { for (i = ucStartIDX; i > ucMaxIDX; i--){ if (prWtbl[i].ucUsed && EQUAL_MAC_ADDR(prSta->aucMacAddr, prWtbl[i].aucMacAddr) && prWtbl[i].ucPairwise) { ucEntry = i; DBGLOG(RSN, TRACE, ("[Wlan index]: Reuse entry #%d\n", i)); break; } } if (i == ucMaxIDX) { for (i = ucStartIDX; i > ucMaxIDX; i--){ if (prWtbl[i].ucUsed == FALSE) { ucEntry = i; DBGLOG(RSN, TRACE, ("[Wlan index]: Assign entry #%d\n", i)); break; } } } } else { for (i = ucStartIDX; i <= ucMaxIDX; i++){ if (prWtbl[i].ucUsed && EQUAL_MAC_ADDR(prSta->aucMacAddr, prWtbl[i].aucMacAddr) && prWtbl[i].ucPairwise) { ucEntry = i; DBGLOG(RSN, TRACE, ("[Wlan index]: Reuse entry #%d\n", i)); break; } } if (i == (ucMaxIDX + 1)) { for (i = ucStartIDX; i <= ucMaxIDX; i++){ if (prWtbl[i].ucUsed == FALSE) { ucEntry = i; DBGLOG(RSN, TRACE, ("[Wlan index]: Assign entry #%d\n", i)); break; } } } } } /* Save to the driver maintain table */ if (ucEntry < WTBL_SIZE) { prWtbl[ucEntry].ucUsed = TRUE; prWtbl[ucEntry].ucBssIndex = prSta->ucBssIndex; prWtbl[ucEntry].ucKeyId = 0; prWtbl[ucEntry].ucPairwise = 1; COPY_MAC_ADDR(prWtbl[ucEntry].aucMacAddr, prSta->aucMacAddr); prWtbl[ucEntry].ucStaIndex = prSta->ucIndex; prSta->ucWlanIndex = ucEntry; DBGLOG(RSN, TRACE, ("[Wlan index] BSS#%d keyid#%d P=%d use WlanIndex#%d STAIdx=%d "MACSTR" staType=%x\n", prSta->ucBssIndex, 0, prWtbl[ucEntry].ucPairwise, ucEntry, prSta->ucIndex, MAC2STR(prSta->aucMacAddr), prSta->eStaType)); if (IS_AP_STA(prSta)) { prSta->ucBMCWlanIndex = secGetBmcWlanIndex(prAdapter, NETWORK_TYPE_AIS, prSta); ASSERT(prSta->ucBMCWlanIndex < WTBL_SIZE); } else { //DBGLOG(RSN, TRACE, ("AP or GO\n")); /* For AP/GO, BC entry saved at BSS INFO */ prSta->ucBMCWlanIndex = 255; } #if DBG secCheckWTBLAssign(prAdapter); #endif return TRUE; } else { #if DBG secCheckWTBLAssign(prAdapter); #endif DBGLOG(RSN, WARN, ("[Wlan index] No more wlan table entry available!!!!\n")); return FALSE; } }