privacy.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/privacy.c#1
  3. */
  4. /*! \file "privacy.c"
  5. \brief This file including the protocol layer privacy function.
  6. This file provided the macros and functions library support for the
  7. protocol layer security setting from rsn.c and nic_privacy.c
  8. */
  9. /*
  10. ** Log: privacy.c
  11. **
  12. ** 07 16 2014 eason.tsai
  13. ** [ALPS01070904] [Need Patch] [Volunteer Patch]
  14. ** .
  15. **
  16. ** 07 16 2014 eason.tsai
  17. ** [ALPS01070904] [Need Patch] [Volunteer Patch]
  18. ** fix ap assert after 32 times connect-disconnct
  19. **
  20. ** 08 19 2013 wh.su
  21. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  22. ** .Adjust some debug message, refine the wlan table assign for bss
  23. **
  24. ** 07 30 2013 wh.su
  25. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  26. ** Add a function, for rx, input the rx wlan index to get the bss index
  27. **
  28. ** 07 26 2013 terry.wu
  29. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  30. ** 1. Reduce extra Tx frame header parsing
  31. ** 2. Add TX port control
  32. ** 3. Add net interface to BSS binding
  33. **
  34. ** 07 25 2013 wh.su
  35. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  36. ** fix at 11w config, mgmt and data privacy setting issue
  37. **
  38. ** 07 23 2013 cp.wu
  39. ** [BORA00002227] [MT6630 Wi-Fi][Driver] Update for Makefile and HIFSYS modifications
  40. ** 1. build success for win32 port
  41. ** 2. add SDIO test read/write pattern for HQA tests (default off)
  42. **
  43. ** 07 23 2013 wh.su
  44. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  45. ** Sync the latest jb2.mp 11w code as draft version
  46. ** Not the CM bit for avoid wapi 1x drop at re-key
  47. **
  48. ** 07 19 2013 wh.su
  49. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  50. ** wapi 1x frame don't need encrypt
  51. **
  52. ** 07 19 2013 wh.su
  53. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  54. ** fix wrong pointer usage.
  55. **
  56. ** 07 18 2013 wh.su
  57. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  58. ** At nicTxComposeDesc (Mgmt and Data) function, use security setting
  59. ** to decide frame protect or not.
  60. **
  61. ** 07 17 2013 wh.su
  62. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  63. ** fix and modify some security code
  64. **
  65. ** 07 15 2013 wh.su
  66. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  67. ** .
  68. **
  69. ** 07 05 2013 wh.su
  70. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  71. ** Fix to let the wpa-psk ok
  72. **
  73. ** 07 04 2013 wh.su
  74. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  75. ** Add a <<temp function>> to decide data frame need encrypted or not
  76. **
  77. ** 07 04 2013 wh.su
  78. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  79. ** Add the function to got the STA index via the wlan index
  80. ** report at Rx status
  81. **
  82. ** 07 03 2013 wh.su
  83. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  84. ** Refine some normal security code
  85. **
  86. ** 07 02 2013 wh.su
  87. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  88. ** Refine some secutity code
  89. **
  90. ** 07 02 2013 wh.su
  91. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  92. ** Refine security BMC wlan index assign
  93. ** Fix some compiling warning
  94. **
  95. ** 07 01 2013 wh.su
  96. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  97. ** Add some debug code, fixed some compiling warning
  98. **
  99. ** 06 25 2013 terry.wu
  100. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  101. ** Update for 1st connection
  102. **
  103. ** 06 18 2013 terry.wu
  104. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  105. ** Update for 1st connection
  106. **
  107. ** 03 29 2013 cp.wu
  108. ** [BORA00002227] [MT6630 Wi-Fi][Driver] Update for Makefile and HIFSYS modifications
  109. ** 1. remove unused HIF definitions
  110. ** 2. enable NDIS 5.1 build success
  111. **
  112. ** 03 29 2013 wh.su
  113. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  114. ** Do more sta record free mechanism check
  115. ** remove non-used code
  116. **
  117. ** 03 27 2013 wh.su
  118. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  119. ** add default ket handler
  120. **
  121. ** 03 20 2013 wh.su
  122. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  123. ** Add the security code for wlan table assign operation
  124. **
  125. ** 03 18 2013 wh.su
  126. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  127. ** fixed compiling error
  128. **
  129. ** 03 15 2013 wh.su
  130. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  131. ** Modify some security part code
  132. **
  133. ** 03 14 2013 wh.su
  134. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  135. ** .modify some code define and flow
  136. **
  137. ** 03 13 2013 wh.su
  138. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  139. ** .remove non-used code
  140. **
  141. ** 03 12 2013 tsaiyuan.hsu
  142. ** [BORA00002222] MT6630 unified MAC RXM
  143. ** add rx data and management processing.
  144. **
  145. */
  146. /*******************************************************************************
  147. * C O M P I L E R F L A G S
  148. ********************************************************************************
  149. */
  150. /*******************************************************************************
  151. * E X T E R N A L R E F E R E N C E S
  152. ********************************************************************************
  153. */
  154. #include "precomp.h"
  155. /*******************************************************************************
  156. * C O N S T A N T S
  157. ********************************************************************************
  158. */
  159. /*******************************************************************************
  160. * D A T A T Y P E S
  161. ********************************************************************************
  162. */
  163. /*******************************************************************************
  164. * P U B L I C D A T A
  165. ********************************************************************************
  166. */
  167. /*******************************************************************************
  168. * P R I V A T E D A T A
  169. ********************************************************************************
  170. */
  171. /*******************************************************************************
  172. * M A C R O S
  173. ********************************************************************************
  174. */
  175. /*******************************************************************************
  176. * F U N C T I O N D E C L A R A T I O N S
  177. ********************************************************************************
  178. */
  179. /*******************************************************************************
  180. * F U N C T I O N S
  181. ********************************************************************************
  182. */
  183. /*----------------------------------------------------------------------------*/
  184. /*!
  185. * \brief This routine is called to initialize the privacy-related
  186. * parameters.
  187. *
  188. * \param[in] prAdapter Pointer to the Adapter structure
  189. * \param[in] ucNetTypeIdx Pointer to netowrk type index
  190. *
  191. * \retval NONE
  192. */
  193. /*----------------------------------------------------------------------------*/
  194. VOID secInit(IN P_ADAPTER_T prAdapter, IN UINT_8 ucBssIndex)
  195. {
  196. UINT_8 i;
  197. P_BSS_INFO_T prBssInfo;
  198. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  199. DEBUGFUNC("secInit");
  200. ASSERT(prAdapter);
  201. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, ucBssIndex);
  202. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  203. prBssInfo->u4RsnSelectedGroupCipher = 0;
  204. prBssInfo->u4RsnSelectedPairwiseCipher = 0;
  205. prBssInfo->u4RsnSelectedAKMSuite = 0;
  206. #if 0 /* CFG_ENABLE_WIFI_DIRECT */
  207. prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P];
  208. prBssInfo->u4RsnSelectedGroupCipher = RSN_CIPHER_SUITE_CCMP;
  209. prBssInfo->u4RsnSelectedPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
  210. prBssInfo->u4RsnSelectedAKMSuite = RSN_AKM_SUITE_PSK;
  211. #endif
  212. #if 0 /* CFG_ENABLE_BT_OVER_WIFI */
  213. prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_BOW];
  214. prBssInfo->u4RsnSelectedGroupCipher = RSN_CIPHER_SUITE_CCMP;
  215. prBssInfo->u4RsnSelectedPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
  216. prBssInfo->u4RsnSelectedAKMSuite = RSN_AKM_SUITE_PSK;
  217. #endif
  218. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[0].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_WEP40;
  219. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[1].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_TKIP;
  220. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[2].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_CCMP;
  221. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[3].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_WEP104;
  222. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[4].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_WEP40;
  223. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[5].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_TKIP;
  224. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[6].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
  225. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[7].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_WEP104;
  226. for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++)
  227. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[i].dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  228. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[0].dot11RSNAConfigAuthenticationSuite =
  229. WPA_AKM_SUITE_NONE;
  230. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[1].dot11RSNAConfigAuthenticationSuite =
  231. WPA_AKM_SUITE_802_1X;
  232. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[2].dot11RSNAConfigAuthenticationSuite =
  233. WPA_AKM_SUITE_PSK;
  234. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[3].dot11RSNAConfigAuthenticationSuite =
  235. RSN_AKM_SUITE_NONE;
  236. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[4].dot11RSNAConfigAuthenticationSuite =
  237. RSN_AKM_SUITE_802_1X;
  238. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[5].dot11RSNAConfigAuthenticationSuite =
  239. RSN_AKM_SUITE_PSK;
  240. #if CFG_SUPPORT_802_11W
  241. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[6].dot11RSNAConfigAuthenticationSuite =
  242. RSN_AKM_SUITE_802_1X_SHA256;
  243. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[7].dot11RSNAConfigAuthenticationSuite =
  244. RSN_AKM_SUITE_PSK_SHA256;
  245. #endif
  246. for (i = 0; i < MAX_NUM_SUPPORTED_AKM_SUITES; i++) {
  247. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[i].dot11RSNAConfigAuthenticationSuiteEnabled =
  248. FALSE;
  249. }
  250. secClearPmkid(prAdapter);
  251. cnmTimerInitTimer(prAdapter,
  252. &prAisSpecBssInfo->rPreauthenticationTimer,
  253. (PFN_MGMT_TIMEOUT_FUNC) rsnIndicatePmkidCand, (ULONG) NULL);
  254. #if CFG_SUPPORT_802_11W
  255. cnmTimerInitTimer(prAdapter,
  256. &prAisSpecBssInfo->rSaQueryTimer, (PFN_MGMT_TIMEOUT_FUNC) rsnStartSaQueryTimer, (ULONG) NULL);
  257. #endif
  258. prAisSpecBssInfo->fgCounterMeasure = FALSE;
  259. prAdapter->prAisBssInfo->ucTxDefaultKeyID = 0;
  260. prAdapter->prAisBssInfo->fgTxBcKeyExist = FALSE;
  261. #if 0
  262. for (i = 0; i < WTBL_SIZE; i++) {
  263. g_prWifiVar->arWtbl[i].ucUsed = FALSE;
  264. g_prWifiVar->arWtbl[i].prSta = NULL;
  265. g_prWifiVar->arWtbl[i].ucNetTypeIdx = NETWORK_TYPE_INDEX_NUM;
  266. }
  267. nicPrivacyInitialize((UINT_8) NETWORK_TYPE_INDEX_NUM);
  268. #endif
  269. } /* secInit */
  270. /*----------------------------------------------------------------------------*/
  271. /*!
  272. * \brief This function will indicate an Event of "Rx Class Error" to SEC_FSM for
  273. * JOIN Module.
  274. *
  275. * \param[in] prAdapter Pointer to the Adapter structure
  276. * \param[in] prSwRfb Pointer to the SW RFB.
  277. *
  278. * \return FALSE Class Error
  279. */
  280. /*----------------------------------------------------------------------------*/
  281. BOOL secCheckClassError(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb, IN P_STA_RECORD_T prStaRec)
  282. {
  283. P_HW_MAC_RX_DESC_T prRxStatus;
  284. ASSERT(prAdapter);
  285. ASSERT(prSwRfb);
  286. prRxStatus = prSwRfb->prRxStatus;
  287. #if 1
  288. if (!prStaRec || (prRxStatus->u2StatusFlag & RXS_DW2_RX_CLASSERR_BITMAP) == RXS_DW2_RX_CLASSERR_VALUE) {
  289. DBGLOG(RSN, TRACE,
  290. "prStaRec=%x RX Status = %x RX_CLASSERR check!\n", prStaRec, prRxStatus->u2StatusFlag);
  291. /* if (IS_NET_ACTIVE(prAdapter, ucBssIndex)) { */
  292. authSendDeauthFrame(prAdapter,
  293. NULL, NULL, prSwRfb, REASON_CODE_CLASS_3_ERR, (PFN_TX_DONE_HANDLER) NULL);
  294. return FALSE;
  295. /* } */
  296. }
  297. #else
  298. if ((prStaRec) && 1 /* RXM_IS_DATA_FRAME(prSwRfb) */) {
  299. UINT_8 ucBssIndex = prStaRec->ucBssIndex;
  300. if (IS_NET_ACTIVE(prAdapter, ucBssIndex)) {
  301. /* P_BSS_INFO_T prBssInfo; */
  302. /* prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, ucBssIndex); */
  303. if ((prRxStatus->u2StatusFlag & RXS_DW2_RX_CLASSERR_BITMAP) == RXS_DW2_RX_CLASSERR_VALUE) {
  304. /*if ((STA_STATE_3 != prStaRec->ucStaState) &&
  305. IS_BSS_ACTIVE(prBssInfo) &&
  306. prBssInfo->fgIsNetAbsent == FALSE) {
  307. (IS_AP_STA(prStaRec) || IS_CLIENT_STA(prStaRec))) { */
  308. if (WLAN_STATUS_SUCCESS == authSendDeauthFrame(prAdapter,
  309. prStaRec,
  310. NULL,
  311. REASON_CODE_CLASS_3_ERR,
  312. (PFN_TX_DONE_HANDLER)
  313. NULL)) {
  314. DBGLOG(RSN, TRACE,
  315. "Send Deauth to MAC:[" MACSTR
  316. "] for Rx Class 3 Error.\n", MAC2STR(prStaRec->aucMacAddr));
  317. }
  318. return FALSE;
  319. }
  320. return secRxPortControlCheck(prAdapter, prSwRfb);
  321. }
  322. }
  323. #endif
  324. return TRUE;
  325. } /* end of secCheckClassError() */
  326. /*----------------------------------------------------------------------------*/
  327. /*!
  328. * \brief This routine is used to setting the sta port status.
  329. *
  330. * \param[in] prAdapter Pointer to the Adapter structure
  331. * \param[in] prSta Pointer to the sta
  332. * \param[in] fgPortBlock The port status
  333. *
  334. * \retval none
  335. *
  336. */
  337. /*----------------------------------------------------------------------------*/
  338. VOID secSetPortBlocked(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta, IN BOOLEAN fgPortBlock)
  339. {
  340. #if 0 /* Marked for MT6630 */
  341. if (prSta == NULL)
  342. return;
  343. prSta->fgPortBlock = fgPortBlock;
  344. DBGLOG(RSN, TRACE,
  345. "The STA " MACSTR " port %s\n", MAC2STR(prSta->aucMacAddr), fgPortBlock == TRUE ? "BLOCK" : " OPEN");
  346. #endif
  347. }
  348. #if 0 /* Marked for MT6630 */
  349. /*----------------------------------------------------------------------------*/
  350. /*!
  351. * \brief This routine is used to report the sta port status.
  352. *
  353. * \param[in] prAdapter Pointer to the Adapter structure
  354. * \param[in] prSta Pointer to the sta
  355. * \param[out] fgPortBlock The port status
  356. *
  357. * \return TRUE sta exist, FALSE sta not exist
  358. *
  359. */
  360. /*----------------------------------------------------------------------------*/
  361. BOOLEAN secGetPortStatus(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta, OUT PBOOLEAN pfgPortStatus)
  362. {
  363. if (prSta == NULL)
  364. return FALSE;
  365. *pfgPortStatus = prSta->fgPortBlock;
  366. return TRUE;
  367. }
  368. /*----------------------------------------------------------------------------*/
  369. /*!
  370. * \brief This routine is called to handle Peer device Tx Security process MSDU.
  371. *
  372. * \param[in] prMsduInfo pointer to the packet info pointer
  373. *
  374. * \retval TRUE Accept the packet
  375. * \retval FALSE Refuse the MSDU packet due port blocked
  376. *
  377. */
  378. /*----------------------------------------------------------------------------*/
  379. BOOL /* ENUM_PORT_CONTROL_RESULT */
  380. secTxPortControlCheck(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo, IN P_STA_RECORD_T prStaRec)
  381. {
  382. ASSERT(prAdapter);
  383. ASSERT(prMsduInfo);
  384. ASSERT(prStaRec);
  385. if (prStaRec) {
  386. /* Todo:: */
  387. if (prMsduInfo->fgIs802_1x)
  388. return TRUE;
  389. if (prStaRec->fgPortBlock == TRUE) {
  390. DBGLOG(INIT, TRACE, "Drop Tx packet due Port Control!\n");
  391. return FALSE;
  392. }
  393. #if CFG_SUPPORT_WAPI
  394. if (prAdapter->rWifiVar.rConnSettings.fgWapiMode)
  395. return TRUE;
  396. #endif
  397. if (IS_STA_IN_AIS(prStaRec)) {
  398. if (!prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist &&
  399. (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION1_ENABLED)) {
  400. DBGLOG(INIT, TRACE, "Drop Tx packet due the key is removed!!!\n");
  401. return FALSE;
  402. }
  403. }
  404. }
  405. return TRUE;
  406. }
  407. #endif /* Marked for MT6630 */
  408. /*----------------------------------------------------------------------------*/
  409. /*!
  410. * \brief This routine is called to handle The Rx Security process MSDU.
  411. *
  412. * \param[in] prAdapter Pointer to the Adapter structure
  413. * \param[in] prSWRfb SW rfb pinter
  414. *
  415. * \retval TRUE Accept the packet
  416. * \retval FALSE Refuse the MSDU packet due port control
  417. */
  418. /*----------------------------------------------------------------------------*/
  419. BOOLEAN secRxPortControlCheck(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSWRfb)
  420. {
  421. ASSERT(prSWRfb);
  422. #if 0
  423. /* whsu:Todo: Process MGMT and DATA */
  424. if (prSWRfb->prStaRec) {
  425. if (prSWRfb->prStaRec->fgPortBlock == TRUE) {
  426. if (1 /* prSWRfb->fgIsDataFrame and not 1x */ &&
  427. (g_prWifiVar->rConnSettings.eAuthMode >= AUTH_MODE_WPA)) {
  428. /* DBGLOG(SEC, WARN, ("Drop Rx data due port control !\r\n")); */
  429. return TRUE; /* Todo: whsu FALSE; */
  430. }
  431. /* if (!RX_STATUS_IS_PROTECT(prSWRfb->prRxStatus)) { */
  432. /* DBGLOG(RSN, WARN, ("Drop rcv non-encrypted data frame!\n")); */
  433. /* return FALSE; */
  434. /* } */
  435. }
  436. } else {
  437. }
  438. #endif
  439. return TRUE;
  440. }
  441. /*----------------------------------------------------------------------------*/
  442. /*!
  443. * \brief This routine will enable/disable the cipher suite
  444. *
  445. * \param[in] prAdapter Pointer to the adapter object data area.
  446. * \param[in] u4CipherSuitesFlags flag for cipher suite
  447. *
  448. * \retval none
  449. */
  450. /*----------------------------------------------------------------------------*/
  451. VOID secSetCipherSuite(IN P_ADAPTER_T prAdapter, IN UINT_32 u4CipherSuitesFlags)
  452. {
  453. UINT_32 i;
  454. P_DOT11_RSNA_CONFIG_PAIRWISE_CIPHERS_ENTRY prEntry;
  455. P_IEEE_802_11_MIB_T prMib;
  456. ASSERT(prAdapter);
  457. prMib = &prAdapter->rMib;
  458. ASSERT(prMib);
  459. if (u4CipherSuitesFlags == CIPHER_FLAG_NONE) {
  460. /* Disable all the pairwise cipher suites. */
  461. for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++)
  462. prMib->dot11RSNAConfigPairwiseCiphersTable[i].dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  463. /* Update the group cipher suite. */
  464. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_NONE;
  465. return;
  466. }
  467. for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++) {
  468. prEntry = &prMib->dot11RSNAConfigPairwiseCiphersTable[i];
  469. switch (prEntry->dot11RSNAConfigPairwiseCipher) {
  470. case WPA_CIPHER_SUITE_WEP40:
  471. case RSN_CIPHER_SUITE_WEP40:
  472. if (u4CipherSuitesFlags & CIPHER_FLAG_WEP40)
  473. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  474. else
  475. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  476. break;
  477. case WPA_CIPHER_SUITE_TKIP:
  478. case RSN_CIPHER_SUITE_TKIP:
  479. if (u4CipherSuitesFlags & CIPHER_FLAG_TKIP)
  480. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  481. else
  482. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  483. break;
  484. case WPA_CIPHER_SUITE_CCMP:
  485. case RSN_CIPHER_SUITE_CCMP:
  486. if (u4CipherSuitesFlags & CIPHER_FLAG_CCMP)
  487. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  488. else
  489. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  490. break;
  491. case WPA_CIPHER_SUITE_WEP104:
  492. case RSN_CIPHER_SUITE_WEP104:
  493. if (u4CipherSuitesFlags & CIPHER_FLAG_WEP104)
  494. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  495. else
  496. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  497. break;
  498. default:
  499. break;
  500. }
  501. }
  502. /* Update the group cipher suite. */
  503. if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_CCMP, &i))
  504. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_CCMP;
  505. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_TKIP, &i))
  506. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_TKIP;
  507. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP104, &i))
  508. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_WEP104;
  509. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP40, &i))
  510. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_WEP40;
  511. else
  512. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_NONE;
  513. } /* secSetCipherSuite */
  514. /*----------------------------------------------------------------------------*/
  515. /*!
  516. * \brief This routine is called to initialize the pmkid parameters.
  517. *
  518. * \param[in] prAdapter Pointer to the Adapter structure
  519. *
  520. * \retval NONE
  521. */
  522. /*----------------------------------------------------------------------------*/
  523. VOID secClearPmkid(IN P_ADAPTER_T prAdapter)
  524. {
  525. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  526. DEBUGFUNC("secClearPmkid");
  527. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  528. DBGLOG(RSN, TRACE, "secClearPmkid\n");
  529. prAisSpecBssInfo->u4PmkidCandicateCount = 0;
  530. prAisSpecBssInfo->u4PmkidCacheCount = 0;
  531. kalMemZero((PVOID) prAisSpecBssInfo->arPmkidCandicate, sizeof(PMKID_CANDICATE_T) * CFG_MAX_PMKID_CACHE);
  532. kalMemZero((PVOID) prAisSpecBssInfo->arPmkidCache, sizeof(PMKID_ENTRY_T) * CFG_MAX_PMKID_CACHE);
  533. }
  534. /*----------------------------------------------------------------------------*/
  535. /*!
  536. * \brief Whether 802.11 privacy is enabled.
  537. *
  538. * \param[in] prAdapter Pointer to the Adapter structure
  539. *
  540. * \retval BOOLEAN
  541. */
  542. /*----------------------------------------------------------------------------*/
  543. BOOLEAN secEnabledInAis(IN P_ADAPTER_T prAdapter)
  544. {
  545. DEBUGFUNC("secEnabledInAis");
  546. ASSERT(prAdapter->rWifiVar.rConnSettings.eEncStatus < ENUM_ENCRYPTION3_KEY_ABSENT);
  547. switch (prAdapter->rWifiVar.rConnSettings.eEncStatus) {
  548. case ENUM_ENCRYPTION_DISABLED:
  549. return FALSE;
  550. case ENUM_ENCRYPTION1_ENABLED:
  551. case ENUM_ENCRYPTION2_ENABLED:
  552. case ENUM_ENCRYPTION3_ENABLED:
  553. return TRUE;
  554. default:
  555. DBGLOG(RSN, TRACE, "Unknown encryption setting %d\n", prAdapter->rWifiVar.rConnSettings.eEncStatus);
  556. break;
  557. }
  558. return FALSE;
  559. } /* secEnabledInAis */
  560. BOOLEAN secIsProtected1xFrame(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec)
  561. {
  562. P_BSS_INFO_T prBssInfo;
  563. ASSERT(prAdapter);
  564. if (prStaRec) {
  565. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prStaRec->ucBssIndex);
  566. if (prBssInfo && prBssInfo->eNetworkType == NETWORK_TYPE_AIS) {
  567. #if CFG_SUPPORT_WAPI
  568. if (wlanQueryWapiMode(prAdapter))
  569. return FALSE;
  570. #endif
  571. }
  572. return prStaRec->fgTransmitKeyExist;
  573. }
  574. return FALSE;
  575. }
  576. /*----------------------------------------------------------------------------*/
  577. /*!
  578. * \brief This routine is called to set the privacy bit at mac header for TxM
  579. *
  580. * \param[in] prAdapter Pointer to the Adapter structure
  581. * \param[in] prMsdu the msdu for known the sta record
  582. *
  583. * \return TRUE the privacy need to set
  584. * FALSE the privacy no need to set
  585. */
  586. /*----------------------------------------------------------------------------*/
  587. BOOLEAN secIsProtectedFrame(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsdu, IN P_STA_RECORD_T prStaRec)
  588. {
  589. /* P_BSS_INFO_T prBssInfo; */
  590. ASSERT(prAdapter);
  591. ASSERT(prMsdu);
  592. /* ASSERT(prStaRec); */
  593. #if CFG_SUPPORT_802_11W
  594. if (prMsdu->ucPacketType == TX_PACKET_TYPE_MGMT) {
  595. BOOL fgRobustActionWithProtect = FALSE;
  596. #if 0 /* Decide by Compose module */
  597. P_BSS_INFO_T prBssInfo;
  598. if (prStaRec) {
  599. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prStaRec->ucBssIndex);
  600. ASSERT(prBssInfo);
  601. if ((prBssInfo->eNetworkType == NETWORK_TYPE_AIS) &&
  602. prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection /* Use MFP */) {
  603. fgRobustActionWithProtect = TRUE;
  604. }
  605. }
  606. #endif
  607. if (prStaRec && fgRobustActionWithProtect /* AIS & Robust action frame */)
  608. return TRUE;
  609. else
  610. return FALSE;
  611. }
  612. #else
  613. if (prMsdu->ucPacketType == TX_PACKET_TYPE_MGMT)
  614. return FALSE;
  615. #endif
  616. #if 1
  617. return secIsProtectedBss(prAdapter, GET_BSS_INFO_BY_INDEX(prAdapter, prMsdu->ucBssIndex));
  618. #else
  619. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prMsdu->ucBssIndex);
  620. ASSERT(prBssInfo);
  621. if (prBssInfo->eNetworkType == NETWORK_TYPE_AIS) {
  622. #if CFG_SUPPORT_WAPI
  623. if (wlanQueryWapiMode(prAdapter))
  624. return TRUE;
  625. #endif
  626. return secEnabledInAis(prAdapter);
  627. }
  628. #if CFG_ENABLE_WIFI_DIRECT
  629. else if (prBssInfo->eNetworkType == NETWORK_TYPE_P2P)
  630. return kalP2PGetCipher(prAdapter->prGlueInfo);
  631. #endif
  632. else if (prBssInfo->eNetworkType == NETWORK_TYPE_BOW)
  633. return TRUE;
  634. ASSERT(FALSE);
  635. return FALSE;
  636. #endif
  637. }
  638. BOOLEAN secIsProtectedBss(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo)
  639. {
  640. ASSERT(prBssInfo);
  641. if (prBssInfo->eNetworkType == NETWORK_TYPE_AIS) {
  642. #if CFG_SUPPORT_WAPI
  643. if (wlanQueryWapiMode(prAdapter))
  644. return TRUE;
  645. #endif
  646. return secEnabledInAis(prAdapter);
  647. }
  648. #if CFG_ENABLE_WIFI_DIRECT
  649. else if (prBssInfo->eNetworkType == NETWORK_TYPE_P2P)
  650. return kalP2PGetCipher(prAdapter->prGlueInfo);
  651. #endif
  652. else if (prBssInfo->eNetworkType == NETWORK_TYPE_BOW)
  653. return TRUE;
  654. ASSERT(FALSE);
  655. return FALSE;
  656. }
  657. UINT_8 secGetBmcWlanIndex(IN P_ADAPTER_T prAdapter, IN ENUM_NETWORK_TYPE_T eNetType, IN P_STA_RECORD_T prStaRec)
  658. {
  659. UINT_8 ucBssIndex;
  660. UINT_8 ucEntry;
  661. if ((!prAdapter) || (!prStaRec))
  662. return WTBL_RESERVED_ENTRY;
  663. ucBssIndex = prStaRec->ucBssIndex;
  664. if (prAdapter->aprBssInfo[ucBssIndex]->fgTxBcKeyExist) {
  665. if (prStaRec && prAdapter->aprBssInfo[ucBssIndex]->ucBMCWlanIndex == WTBL_RESERVED_ENTRY) {
  666. ucEntry =
  667. secPrivacySeekForBcEntry(prAdapter, ucBssIndex, prStaRec->aucMacAddr,
  668. prStaRec->ucIndex, CIPHER_SUITE_NONE, 0xff, 0x0, BIT(0));
  669. prAdapter->aprBssInfo[ucBssIndex]->ucBMCWlanIndex = ucEntry;
  670. }
  671. DBGLOG(RSN, INFO,
  672. "[Wlan index] secGetBmcWlanIndex = %d\n", prAdapter->aprBssInfo[ucBssIndex]->ucBMCWlanIndex);
  673. return prAdapter->aprBssInfo[ucBssIndex]->ucBMCWlanIndex;
  674. }
  675. ucEntry = secPrivacySeekForBcEntry(prAdapter, ucBssIndex, prStaRec->aucMacAddr,
  676. prStaRec->ucIndex, CIPHER_SUITE_NONE, 0xff, 0x0, BIT(0));
  677. return ucEntry;
  678. }
  679. /*----------------------------------------------------------------------------*/
  680. /*!
  681. * \brief This routine is used before add/update a WLAN entry.
  682. * Info the WLAN Table has available entry for this request
  683. *
  684. * \param[in] prAdapter Pointer to the Adapter structure
  685. * \param[in] prSta the P_STA_RECORD_T for store
  686. *
  687. * \return TRUE Free Wlan table is reserved for this request
  688. * FALSE No free entry for this request
  689. *
  690. * \note
  691. */
  692. /*----------------------------------------------------------------------------*/
  693. BOOL secPrivacySeekForEntry(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  694. {
  695. UINT_8 ucEntry = WTBL_RESERVED_ENTRY;
  696. UINT_8 i;
  697. UINT_8 ucStartIDX = 0, ucMaxIDX = 0;
  698. P_WLAN_TABLE_T prWtbl;
  699. ASSERT(prSta);
  700. if (!prSta->fgIsInUse)
  701. ASSERT(FALSE);
  702. DBGLOG(RSN, TRACE, MACSTR "\n", MAC2STR(prSta->aucMacAddr));
  703. prWtbl = prAdapter->rWifiVar.arWtbl;
  704. #if 1
  705. ucStartIDX = 0;
  706. ucMaxIDX = NIC_TX_DEFAULT_WLAN_INDEX - 1;
  707. #else
  708. if (prSta->eStaType == STA_TYPE_DLS_PEER) {
  709. ucStartIDX = WTBL_STA_IDX_MAX;
  710. ucMaxIDX = WTBL_AIS_DLS_MAX_IDX;
  711. } else if (IS_ADHOC_STA(prSta)) {
  712. ucStartIDX = 0;
  713. ucMaxIDX = WTBL_IBSS_STA_IDX_MAX;
  714. } else {
  715. ucStartIDX = 0;
  716. ucMaxIDX = WTBL_STA_IDX_MAX;
  717. }
  718. #endif
  719. if (ucStartIDX != 0 || ucMaxIDX != 0) {
  720. if (ucStartIDX > ucMaxIDX) {
  721. for (i = ucStartIDX; i > ucMaxIDX; i--) {
  722. if (prWtbl[i].ucUsed && EQUAL_MAC_ADDR(prSta->aucMacAddr, prWtbl[i].aucMacAddr)
  723. && prWtbl[i].ucPairwise) {
  724. ucEntry = i;
  725. DBGLOG(RSN, TRACE, "[Wlan index]: Reuse entry #%d\n", i);
  726. break;
  727. }
  728. }
  729. if (i == ucMaxIDX) {
  730. for (i = ucStartIDX; i > ucMaxIDX; i--) {
  731. if (prWtbl[i].ucUsed == FALSE) {
  732. ucEntry = i;
  733. DBGLOG(RSN, TRACE, "[Wlan index]: Assign entry #%d\n", i);
  734. break;
  735. }
  736. }
  737. }
  738. } else {
  739. for (i = ucStartIDX; i <= ucMaxIDX; i++) {
  740. if (prWtbl[i].ucUsed && EQUAL_MAC_ADDR(prSta->aucMacAddr, prWtbl[i].aucMacAddr)
  741. && prWtbl[i].ucPairwise) {
  742. ucEntry = i;
  743. DBGLOG(RSN, TRACE, "[Wlan index]: Reuse entry #%d\n", i);
  744. break;
  745. }
  746. }
  747. if (i == (ucMaxIDX + 1)) {
  748. for (i = ucStartIDX; i <= ucMaxIDX; i++) {
  749. if (prWtbl[i].ucUsed == FALSE) {
  750. ucEntry = i;
  751. DBGLOG(RSN, TRACE, "[Wlan index]: Assign entry #%d\n", i);
  752. break;
  753. }
  754. }
  755. }
  756. }
  757. }
  758. /* Save to the driver maintain table */
  759. if (ucEntry < WTBL_SIZE) {
  760. prWtbl[ucEntry].ucUsed = TRUE;
  761. prWtbl[ucEntry].ucBssIndex = prSta->ucBssIndex;
  762. prWtbl[ucEntry].ucKeyId = 0;
  763. prWtbl[ucEntry].ucPairwise = 1;
  764. COPY_MAC_ADDR(prWtbl[ucEntry].aucMacAddr, prSta->aucMacAddr);
  765. prWtbl[ucEntry].ucStaIndex = prSta->ucIndex;
  766. prSta->ucWlanIndex = ucEntry;
  767. DBGLOG(RSN, INFO,
  768. "[Wlan index] BSS#%d keyid#%d P=%d use WlanIndex#%d STAIdx=%d " MACSTR
  769. " staType=%x\n", prSta->ucBssIndex, 0, prWtbl[ucEntry].ucPairwise, ucEntry,
  770. prSta->ucIndex, MAC2STR(prSta->aucMacAddr), prSta->eStaType);
  771. if (IS_AP_STA(prSta)) {
  772. prSta->ucBMCWlanIndex = secGetBmcWlanIndex(prAdapter, NETWORK_TYPE_AIS, prSta);
  773. ASSERT(prSta->ucBMCWlanIndex < WTBL_SIZE);
  774. } else {
  775. /* DBGLOG(RSN, TRACE, ("AP or GO\n")); */
  776. /* For AP/GO, BC entry saved at BSS INFO */
  777. prSta->ucBMCWlanIndex = 255;
  778. }
  779. #if DBG
  780. secCheckWTBLAssign(prAdapter);
  781. #endif
  782. } else {
  783. #if DBG
  784. secCheckWTBLAssign(prAdapter);
  785. #endif
  786. DBGLOG(RSN, WARN, "[Wlan index] No more wlan table entry available!!!!\n");
  787. return FALSE;
  788. }
  789. return TRUE;
  790. }
  791. /*----------------------------------------------------------------------------*/
  792. /*!
  793. * \brief This routine is used free a WLAN entry.
  794. *
  795. * \param[in] prAdapter Pointer to the Adapter structure
  796. * \param[in] ucEntry the wlan table index to free
  797. *
  798. * \return none
  799. */
  800. /*----------------------------------------------------------------------------*/
  801. VOID secPrivacyFreeForEntry(IN P_ADAPTER_T prAdapter, IN UINT_8 ucEntry)
  802. {
  803. P_WLAN_TABLE_T prWtbl;
  804. ASSERT(prAdapter);
  805. if (ucEntry > WTBL_SIZE)
  806. return;
  807. DBGLOG(RSN, TRACE, "secPrivacyFreeForEntry %d", ucEntry);
  808. prWtbl = prAdapter->rWifiVar.arWtbl;
  809. prWtbl[ucEntry].ucUsed = FALSE;
  810. prWtbl[ucEntry].ucKeyId = 0;
  811. prWtbl[ucEntry].ucBssIndex = 0; /* Set non-Zero as default ? */
  812. prWtbl[ucEntry].ucPairwise = 0;
  813. kalMemSet(prWtbl[ucEntry].aucMacAddr, 0x0, MAC_ADDR_LEN);
  814. prWtbl[ucEntry].ucStaIndex = 0xff;
  815. #if DBG
  816. {
  817. P_HAL_WTBL_SEC_CONFIG_T prWtblCfg;
  818. prWtblCfg = prAdapter->rWifiVar.arWtblCfg;
  819. kalMemZero((PUINT_8)&prWtblCfg[ucEntry], sizeof(HAL_WTBL_SEC_CONFIG_T));
  820. secPrivacyDumpWTBL3(prAdapter, ucEntry);
  821. secCheckWTBLAssign(prAdapter);
  822. }
  823. #endif
  824. }
  825. /*----------------------------------------------------------------------------*/
  826. /*!
  827. * \brief This routine is used free a STA WLAN entry.
  828. *
  829. * \param[in] prAdapter Pointer to the Adapter structure
  830. * \param[in] prStaRec the sta which want to free
  831. *
  832. * \return none
  833. */
  834. /*----------------------------------------------------------------------------*/
  835. VOID secPrivacyFreeSta(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec)
  836. {
  837. UINT_32 entry;
  838. P_WLAN_TABLE_T prWtbl;
  839. if (!prStaRec)
  840. return;
  841. prWtbl = prAdapter->rWifiVar.arWtbl;
  842. prStaRec->ucWlanIndex = WTBL_RESERVED_ENTRY;
  843. prStaRec->ucBMCWlanIndex = WTBL_RESERVED_ENTRY;
  844. /* if ((IS_ADHOC_STA(prStaRec) || IS_STA_IN_AIS(prStaRec)) */
  845. /* && prStaRec->ucBMCWlanIndex < WTBL_SIZE *//*) { */
  846. /* the hotspot mode would be assert after connect-disconnect field try WTBL_SIZE times */
  847. if (TRUE) {
  848. for (entry = 0; entry < WTBL_SIZE; entry++) {
  849. if (prWtbl[entry].ucUsed && EQUAL_MAC_ADDR(prStaRec->aucMacAddr, prWtbl[entry].aucMacAddr)) {
  850. secPrivacyFreeForEntry(prAdapter, entry);
  851. #if 1 /* DBG */
  852. DBGLOG(RSN, INFO, "Free the STA entry (%lu)!\n", entry);
  853. #endif
  854. }
  855. }
  856. }
  857. }
  858. /*----------------------------------------------------------------------------*/
  859. /*!
  860. * \brief This routine is used for adding the broadcast key used, to assign a wlan table entry
  861. * for reserved the specific entry for these key for
  862. *
  863. * \param[in] prAdapter Pointer to the Adapter structure
  864. * \param[in] ucBssIndex The BSS index
  865. * \param[in] ucNetTypeIdx The Network index
  866. * \param[in] ucAlg the entry assign related with algorithm
  867. * \param[in] ucKeyId The key id
  868. * \param[in] ucTxRx The Type of the key
  869. *
  870. * \return ucEntryIndex The entry to be used, WTBL_ALLOC_FAIL for allocation fail
  871. *
  872. * \note
  873. */
  874. /*----------------------------------------------------------------------------*/
  875. UINT_8
  876. secPrivacySeekForBcEntry(IN P_ADAPTER_T prAdapter,
  877. IN UINT_8 ucBssIndex,
  878. IN PUINT_8 pucAddr,
  879. IN UINT_8 ucStaIdx,
  880. IN UINT_8 ucAlg, IN UINT_8 ucKeyId, IN UINT_8 ucCurrentKeyId, IN UINT_8 ucTxRx)
  881. {
  882. UINT_8 ucEntry = WTBL_ALLOC_FAIL;
  883. UINT_8 ucStartIDX = 0, ucMaxIDX = 0;
  884. UINT_8 i;
  885. BOOLEAN fgCheckKeyId = TRUE;
  886. P_WLAN_TABLE_T prWtbl;
  887. /* P_BSS_INFO_T prBSSInfo = GET_BSS_INFO_BY_INDEX(prAdapter,ucBssIndex); */
  888. prWtbl = prAdapter->rWifiVar.arWtbl;
  889. ASSERT(prAdapter);
  890. ASSERT(pucAddr);
  891. #if 1
  892. ucStartIDX = 0;
  893. ucMaxIDX = NIC_TX_DEFAULT_WLAN_INDEX - 1;
  894. #else
  895. if (ucAlg == CIPHER_SUITE_BIP) {
  896. if (ucNetTypeIdx != NETWORK_TYPE_AIS) {
  897. ASSERT(FALSE);
  898. return ucEntry;
  899. }
  900. ucEntry = WTBL_AIS_BIP_IDX; /* Only support 11w at STA mode */
  901. }
  902. #endif
  903. if (ucAlg == CIPHER_SUITE_WPI || ucAlg == CIPHER_SUITE_WEP40 ||
  904. ucAlg == CIPHER_SUITE_WEP104 || ucAlg == CIPHER_SUITE_WEP128 || ucAlg == CIPHER_SUITE_NONE)
  905. fgCheckKeyId = FALSE;
  906. #if 0
  907. if ((ucNetTypeIdx == NETWORK_TYPE_AIS)
  908. && (prAdapter->aprBssInfo[ucBssIndex]->eCurrentOPMode == OP_MODE_IBSS)) {
  909. ucStartIDX = WTBL_IBSS_BC_IDX_0;
  910. ucMaxIDX = WTBL_BC_IDX_MAX;
  911. } else {
  912. ucStartIDX = WTBL_BC_IDX_0;
  913. ucMaxIDX = WTBL_BC_IDX_MAX;
  914. }
  915. #endif
  916. for (i = ucStartIDX; i <= ucMaxIDX; i++) {
  917. #if DBG
  918. if (i < 10) {
  919. DBGLOG(RSN, TRACE,
  920. "idx=%d use=%d P=%d BSSIdx=%d Addr=" MACSTR " keyid=%d\n", i,
  921. prWtbl[i].ucUsed, prWtbl[i].ucPairwise, prWtbl[i].ucBssIndex,
  922. MAC2STR(prWtbl[i].aucMacAddr),
  923. prWtbl[i].ucKeyId);
  924. }
  925. #endif
  926. if (prWtbl[i].ucUsed && !prWtbl[i].ucPairwise && prWtbl[i].ucBssIndex == ucBssIndex && 1
  927. /* (EQUAL_MAC_ADDR(prWtbl[i].aucMacAddr, pucAddr) ||
  928. * (prBSSInfo && EQUAL_MAC_ADDR(prWtbl[i].aucMacAddr, prBSSInfo->aucOwnMacAddr))) */
  929. ) {
  930. if (!fgCheckKeyId || prWtbl[i].ucKeyId == 0xff
  931. || (fgCheckKeyId && prWtbl[i].ucKeyId == ucKeyId)) {
  932. ucEntry = i;
  933. DBGLOG(RSN, TRACE, "[Wlan index]: Reuse entry #%d\n", i);
  934. break;
  935. }
  936. if (fgCheckKeyId && (prWtbl[i].ucKeyId != ucCurrentKeyId)) {
  937. ucEntry = i;
  938. DBGLOG(RSN, TRACE, "[Wlan index]: Replace the not current keyid entry #%d\n", i);
  939. break;
  940. }
  941. }
  942. }
  943. if (i == (ucMaxIDX + 1)) {
  944. for (i = ucStartIDX; i <= ucMaxIDX; i++) {
  945. if (prWtbl[i].ucUsed == FALSE) {
  946. ucEntry = i;
  947. DBGLOG(RSN, TRACE, "[Wlan index]: Assign entry #%d\n", i);
  948. break;
  949. }
  950. }
  951. }
  952. if (ucEntry < WTBL_SIZE) {
  953. prWtbl[ucEntry].ucUsed = TRUE;
  954. prWtbl[ucEntry].ucKeyId = ucKeyId;
  955. prWtbl[ucEntry].ucBssIndex = ucBssIndex;
  956. prWtbl[ucEntry].ucPairwise = 0;
  957. kalMemCopy(prWtbl[ucEntry].aucMacAddr, pucAddr, MAC_ADDR_LEN);
  958. prWtbl[ucEntry].ucStaIndex = ucStaIdx;
  959. DBGLOG(RSN, TRACE,
  960. "[Wlan index] BSS#%d keyid#%d P=%d use WlanIndex#%d STAIdx=%d " MACSTR
  961. "\n", ucBssIndex, ucKeyId, prWtbl[ucEntry].ucPairwise, ucEntry, ucStaIdx, MAC2STR(pucAddr));
  962. #if DBG
  963. secCheckWTBLAssign(prAdapter);
  964. #endif
  965. }
  966. ASSERT(ucEntry != WTBL_ALLOC_FAIL);
  967. return ucEntry;
  968. }
  969. /*----------------------------------------------------------------------------*/
  970. /*!
  971. * \brief
  972. *
  973. * \param[in] prAdapter Pointer to the Adapter structure
  974. *
  975. * \return ucEntryIndex The entry to be used, WTBL_ALLOC_FAIL for allocation fail
  976. *
  977. * \note
  978. */
  979. /*----------------------------------------------------------------------------*/
  980. BOOLEAN secCheckWTBLAssign(IN P_ADAPTER_T prAdapter)
  981. {
  982. UINT_8 i;
  983. BOOLEAN fgCheckFail = FALSE;
  984. secPrivacyDumpWTBL(prAdapter);
  985. for (i = 0; i <= WTBL_SIZE; i++) {
  986. /* AIS STA should just has max 2 entry */
  987. /* Max STA check */
  988. }
  989. if (fgCheckFail)
  990. ASSERT(FALSE);
  991. return TRUE;
  992. }
  993. /*----------------------------------------------------------------------------*/
  994. /*!
  995. * \brief Got the STA record index by wlan index
  996. *
  997. * \param[in] prAdapter Pointer to the Adapter structure
  998. * \param[in] ucWlanIdx The Rx wlan index
  999. *
  1000. * \return The STA record index, 0xff for invalid sta index
  1001. */
  1002. /*----------------------------------------------------------------------------*/
  1003. UINT_8 secGetStaIdxByWlanIdx(P_ADAPTER_T prAdapter, UINT_8 ucWlanIdx)
  1004. {
  1005. P_WLAN_TABLE_T prWtbl;
  1006. ASSERT(prAdapter);
  1007. if (ucWlanIdx >= WTBL_SIZE)
  1008. return 0xff;
  1009. prWtbl = prAdapter->rWifiVar.arWtbl;
  1010. /* DBGLOG(RSN, TRACE, ("secGetStaIdxByWlanIdx=%d "MACSTR" used=%d\n",
  1011. * ucWlanIdx, MAC2STR(prWtbl[ucWlanIdx].aucMacAddr), prWtbl[ucWlanIdx].ucUsed)); */
  1012. if (prWtbl[ucWlanIdx].ucUsed)
  1013. return prWtbl[ucWlanIdx].ucStaIndex;
  1014. else
  1015. return 0xff;
  1016. }
  1017. /*----------------------------------------------------------------------------*/
  1018. /*!
  1019. * \brief At Sw wlan table, got the BSS index by wlan index
  1020. *
  1021. * \param[in] prAdapter Pointer to the Adapter structure
  1022. * \param[in] ucWlanIdx The Rx wlan index
  1023. *
  1024. * \return The BSS index, 0xff for invalid bss index
  1025. */
  1026. /*----------------------------------------------------------------------------*/
  1027. UINT_8 secGetBssIdxByWlanIdx(P_ADAPTER_T prAdapter, UINT_8 ucWlanIdx)
  1028. {
  1029. P_WLAN_TABLE_T prWtbl;
  1030. ASSERT(prAdapter);
  1031. if (ucWlanIdx >= WTBL_SIZE)
  1032. return 0xff;
  1033. prWtbl = prAdapter->rWifiVar.arWtbl;
  1034. if (prWtbl[ucWlanIdx].ucUsed)
  1035. return prWtbl[ucWlanIdx].ucBssIndex;
  1036. else
  1037. return 0xff;
  1038. }
  1039. /*----------------------------------------------------------------------------*/
  1040. /*!
  1041. * \brief Got the STA record index by mac addr
  1042. *
  1043. * \param[in] prAdapter Pointer to the Adapter structure
  1044. * \param[in] pucMacAddress MAC Addr
  1045. *
  1046. * \return The STA record index, 0xff for invalid sta index
  1047. */
  1048. /*----------------------------------------------------------------------------*/
  1049. UINT_8 secLookupStaRecIndexFromTA(P_ADAPTER_T prAdapter, PUINT_8 pucMacAddress)
  1050. {
  1051. int i;
  1052. P_WLAN_TABLE_T prWtbl;
  1053. ASSERT(prAdapter);
  1054. prWtbl = prAdapter->rWifiVar.arWtbl;
  1055. for (i = 0; i < WTBL_SIZE; i++) {
  1056. if (prWtbl[i].ucUsed) {
  1057. if (EQUAL_MAC_ADDR(pucMacAddress, prWtbl[i].aucMacAddr))
  1058. return prWtbl[i].ucStaIndex;
  1059. }
  1060. }
  1061. return 0xff;
  1062. }
  1063. /*----------------------------------------------------------------------------*/
  1064. /*!
  1065. * \brief
  1066. *
  1067. * \param[in] prAdapter Pointer to the Adapter structure
  1068. *
  1069. * \note
  1070. */
  1071. /*----------------------------------------------------------------------------*/
  1072. void secPrivacyDumpWTBL(IN P_ADAPTER_T prAdapter)
  1073. {
  1074. P_WLAN_TABLE_T prWtbl;
  1075. UINT_8 i;
  1076. prWtbl = prAdapter->rWifiVar.arWtbl;
  1077. DBGLOG(RSN, INFO, "The Wlan Table content\n");
  1078. for (i = 0; i <= WTBL_SIZE; i++) {
  1079. DBGLOG(RSN, INFO,
  1080. "#%d Used=%d BSSIdx=%d keyid=%d pairwise=%d STAIdx=%d" MACSTR "\n", i,
  1081. prWtbl[i].ucUsed, prWtbl[i].ucBssIndex, prWtbl[i].ucKeyId,
  1082. prWtbl[i].ucPairwise, prWtbl[i].ucStaIndex, MAC2STR(prWtbl[i].aucMacAddr));
  1083. }
  1084. }
  1085. #if DBG
  1086. void secPrivacyDumpWTBL3(IN P_ADAPTER_T prAdapter, IN UINT_8 ucIndex)
  1087. {
  1088. P_HAL_WTBL_SEC_CONFIG_T prWtblCfg;
  1089. P_WLAN_TABLE_T prWtbl;
  1090. UINT_8 i;
  1091. prWtbl = prAdapter->rWifiVar.arWtbl;
  1092. prWtblCfg = prAdapter->rWifiVar.arWtblCfg;
  1093. if (ucIndex < WTBL_SIZE) {
  1094. DBGLOG(RSN, INFO, "The Wlan Table#3 content\n");
  1095. /* for (i = 0; i <= WTBL_SIZE; i++){ */
  1096. i = ucIndex;
  1097. DBGLOG(RSN, INFO,
  1098. "#%d(%d) BSS=%d " MACSTR
  1099. " RV=%d RKV=%d RCA2=%d ALG=%d RCID=%d keyid=%d RCA1=%d MUAR=%02x IKV=%d PN=%d\n",
  1100. i, prWtbl[i].ucUsed, prWtbl[i].ucBssIndex, MAC2STR(prWtbl[i].aucMacAddr),
  1101. prWtblCfg[i].fgRV, prWtblCfg[i].fgRKV, prWtblCfg[i].fgRCA2,
  1102. prWtblCfg[i].ucCipherSuit, prWtblCfg[i].fgRCID, prWtbl[i].ucKeyId,
  1103. prWtblCfg[i].fgRCA1, prWtblCfg[i].ucMUARIdx, prWtblCfg[i].fgIKV, prWtblCfg[i].fgEvenPN));
  1104. /* } */
  1105. }
  1106. }
  1107. #endif