privacy.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. * 11 10 2011 wh.su
  13. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  14. * change the debug module level.
  15. *
  16. * 10 20 2011 terry.wu
  17. * NULL
  18. * Fix Hotspot deauth send failed.
  19. *
  20. * 10 12 2011 wh.su
  21. * [WCXRP00001036] [MT6620 Wi-Fi][Driver][FW] Adding the 802.11w code for MFP
  22. * adding the 802.11w related function and define .
  23. *
  24. * 06 28 2011 tsaiyuan.hsu
  25. * [WCXRP00000819] [MT6620 Wi-Fi][Driver] check if staRec is NULL or not in secCheckClassError
  26. * check if staRec is NULL or not in secCheckClassError.
  27. *
  28. * 06 09 2011 tsaiyuan.hsu
  29. * [WCXRP00000760] [MT5931 Wi-Fi][FW] Refine rxmHandleMacRxDone to reduce code size
  30. * move send_auth at rxmHandleMacRxDone in firmware to driver to reduce code size.
  31. *
  32. * 01 25 2011 yuche.tsai
  33. * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
  34. * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
  35. *
  36. * 11 04 2010 wh.su
  37. * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
  38. * adding the p2p random ssid support.
  39. *
  40. * 10 04 2010 cp.wu
  41. * [WCXRP00000077] [MT6620 Wi-Fi][Driver][FW] Eliminate use of ENUM_NETWORK_TYPE_T
  42. * and replaced by ENUM_NETWORK_TYPE_INDEX_T only
  43. * remove ENUM_NETWORK_TYPE_T definitions
  44. *
  45. * 09 03 2010 kevin.huang
  46. * NULL
  47. * Refine #include sequence and solve recursive/nested #include issue
  48. *
  49. * 09 01 2010 wh.su
  50. * NULL
  51. * adding the wapi support for integration test.
  52. *
  53. * 07 24 2010 wh.su
  54. *
  55. * .support the Wi-Fi RSN
  56. *
  57. * 07 20 2010 wh.su
  58. *
  59. * adding the wapi code.
  60. *
  61. * 07 08 2010 cp.wu
  62. *
  63. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  64. *
  65. * 06 21 2010 wh.su
  66. * [WPD00003840][MT6620 5931] Security migration
  67. * modify some code for concurrent network.
  68. *
  69. * 06 21 2010 cp.wu
  70. * [WPD00003833][MT6620 and MT5931] Driver migration
  71. * [WPD00003833][MT6620 and MT5931] Driver migration
  72. * enable RX management frame handling.
  73. *
  74. * 06 19 2010 wh.su
  75. * [WPD00003840][MT6620 5931] Security migration
  76. * adding the compiling flag for migration.
  77. *
  78. * 06 19 2010 wh.su
  79. * [WPD00003840][MT6620 5931] Security migration
  80. * consdier the concurrent network setting.
  81. *
  82. * 06 18 2010 wh.su
  83. * [WPD00003840][MT6620 5931] Security migration
  84. * migration the security related function from firmware.
  85. *
  86. * 05 28 2010 wh.su
  87. * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
  88. * fixed the ad-hoc wpa-none send non-encrypted frame issue.
  89. *
  90. * 05 24 2010 kevin.huang
  91. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  92. * Refine authSendAuthFrame() for NULL STA_RECORD_T case and minimum deauth interval.
  93. *
  94. * 04 29 2010 wh.su
  95. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  96. * adjsut the pre-authentication code.
  97. *
  98. * 04 22 2010 wh.su
  99. * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
  100. * fixed the wpi same key id rx issue and fixed the remove wep key issue.
  101. *
  102. * 04 19 2010 kevin.huang
  103. * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
  104. * Add Send Deauth for Class 3 Error and Leave Network Support
  105. *
  106. * 04 15 2010 wh.su
  107. * [BORA00000680][MT6620] Support the statistic for Micxxsoft os query
  108. * remove the assert code for allow ad-hoc pkt.
  109. *
  110. * 04 13 2010 wh.su
  111. * [BORA00000680][MT6620] Support the statistic for Micxxsoft os query
  112. * fixed the Klocwork error and refine the class error message.
  113. *
  114. * 03 04 2010 wh.su
  115. * [BORA00000605][WIFISYS] Phase3 Integration
  116. * Code refine, and remove non-used code.
  117. *
  118. * 03 03 2010 wh.su
  119. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  120. * move the AIS specific variable for security to AIS specific structure.
  121. *
  122. * 03 03 2010 wh.su
  123. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  124. * Fixed the pre-authentication timer not correctly init issue,
  125. * and modify the security related callback function prototype.
  126. *
  127. * 03 01 2010 wh.su
  128. * [BORA00000605][WIFISYS] Phase3 Integration
  129. * Refine the variable and parameter for security.
  130. *
  131. * 02 26 2010 wh.su
  132. * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
  133. * change the waning message shown level, and clear the global transmit flag for CMD INFRASTRUCTURE.
  134. *
  135. * 02 25 2010 wh.su
  136. * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
  137. * For support the WHQL test, do the remove key code refine.
  138. *
  139. * 01 27 2010 wh.su
  140. * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
  141. * add and fixed some security function.
  142. *
  143. * 12 25 2009 tehuang.liu
  144. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  145. * Integrated modifications for 1st connection (mainly on FW modules MQM, TXM, and RXM)
  146. * * * * * * * * * MQM: BA handling
  147. * * * * * * * * * TXM: Macros updates
  148. * * * * * * * * * RXM: Macros/Duplicate Removal updates
  149. *
  150. * 12 18 2009 cm.chang
  151. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  152. * .
  153. *
  154. * Dec 11 2009 mtk01088
  155. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  156. * modify the cmd with result return
  157. *
  158. * Dec 11 2009 mtk01088
  159. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  160. * fixed the value not initialize issue
  161. *
  162. * Dec 10 2009 mtk01088
  163. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  164. * change the cmd return type
  165. *
  166. * Dec 8 2009 mtk01088
  167. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  168. * adding the function to update the auth mode and encryption status for cmd build connection
  169. *
  170. * Dec 7 2009 mtk01088
  171. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  172. * adding some code for wapi mode
  173. *
  174. * Dec 7 2009 mtk01088
  175. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  176. * adding the call to check the 4th and eapol error report frame
  177. *
  178. * Dec 7 2009 mtk01088
  179. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  180. * rename the function name
  181. *
  182. * Dec 4 2009 mtk01088
  183. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  184. * adding the code for parsing the EAPoL frame, and do some code refine
  185. *
  186. * Dec 3 2009 mtk01088
  187. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  188. * adding the class error check
  189. *
  190. * Dec 3 2009 mtk01088
  191. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  192. * adding the cmd_802_11_pmkid code
  193. *
  194. * Dec 1 2009 mtk01088
  195. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  196. * doing some function rename, and adding the code for cmd CMD_ADD_REMOVE_KEY
  197. *
  198. * Nov 23 2009 mtk01088
  199. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  200. * adding the clear pmkid function
  201. *
  202. * Nov 23 2009 mtk01461
  203. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  204. * Fix eStaType check for AIS
  205. *
  206. * Nov 19 2009 mtk01088
  207. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  208. * adding the ap selection related code
  209. *
  210. * Nov 18 2009 mtk01088
  211. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  212. *
  213. */
  214. /*******************************************************************************
  215. * C O M P I L E R F L A G S
  216. ********************************************************************************
  217. */
  218. /*******************************************************************************
  219. * E X T E R N A L R E F E R E N C E S
  220. ********************************************************************************
  221. */
  222. #include "precomp.h"
  223. #if CFG_PRIVACY_MIGRATION
  224. /*******************************************************************************
  225. * C O N S T A N T S
  226. ********************************************************************************
  227. */
  228. /*******************************************************************************
  229. * D A T A T Y P E S
  230. ********************************************************************************
  231. */
  232. /*******************************************************************************
  233. * P U B L I C D A T A
  234. ********************************************************************************
  235. */
  236. /*******************************************************************************
  237. * P R I V A T E D A T A
  238. ********************************************************************************
  239. */
  240. /*******************************************************************************
  241. * M A C R O S
  242. ********************************************************************************
  243. */
  244. /*******************************************************************************
  245. * F U N C T I O N D E C L A R A T I O N S
  246. ********************************************************************************
  247. */
  248. /*******************************************************************************
  249. * F U N C T I O N S
  250. ********************************************************************************
  251. */
  252. /*----------------------------------------------------------------------------*/
  253. /*!
  254. * \brief This routine is called to initialize the privacy-related
  255. * parameters.
  256. *
  257. * \param[in] prAdapter Pointer to the Adapter structure
  258. * \param[in] ucNetTypeIdx Pointer to netowrk type index
  259. *
  260. * \retval NONE
  261. */
  262. /*----------------------------------------------------------------------------*/
  263. VOID secInit(IN P_ADAPTER_T prAdapter, IN UINT_8 ucNetTypeIdx)
  264. {
  265. UINT_8 i;
  266. P_CONNECTION_SETTINGS_T prConnSettings;
  267. P_BSS_INFO_T prBssInfo;
  268. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  269. DEBUGFUNC("secInit");
  270. ASSERT(prAdapter);
  271. prConnSettings = &prAdapter->rWifiVar.rConnSettings;
  272. prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX];
  273. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  274. prBssInfo->u4RsnSelectedGroupCipher = 0;
  275. prBssInfo->u4RsnSelectedPairwiseCipher = 0;
  276. prBssInfo->u4RsnSelectedAKMSuite = 0;
  277. #if CFG_ENABLE_WIFI_DIRECT
  278. prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX];
  279. prBssInfo->u4RsnSelectedGroupCipher = RSN_CIPHER_SUITE_CCMP;
  280. prBssInfo->u4RsnSelectedPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
  281. prBssInfo->u4RsnSelectedAKMSuite = RSN_AKM_SUITE_PSK;
  282. #endif
  283. #if CFG_ENABLE_BT_OVER_WIFI
  284. prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_BOW_INDEX];
  285. prBssInfo->u4RsnSelectedGroupCipher = RSN_CIPHER_SUITE_CCMP;
  286. prBssInfo->u4RsnSelectedPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
  287. prBssInfo->u4RsnSelectedAKMSuite = RSN_AKM_SUITE_PSK;
  288. #endif
  289. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[0].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_WEP40;
  290. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[1].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_TKIP;
  291. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[2].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_CCMP;
  292. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[3].dot11RSNAConfigPairwiseCipher = WPA_CIPHER_SUITE_WEP104;
  293. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[4].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_WEP40;
  294. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[5].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_TKIP;
  295. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[6].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
  296. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[7].dot11RSNAConfigPairwiseCipher = RSN_CIPHER_SUITE_WEP104;
  297. for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++)
  298. prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[i].dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  299. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[0].dot11RSNAConfigAuthenticationSuite =
  300. WPA_AKM_SUITE_NONE;
  301. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[1].dot11RSNAConfigAuthenticationSuite =
  302. WPA_AKM_SUITE_802_1X;
  303. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[2].dot11RSNAConfigAuthenticationSuite =
  304. WPA_AKM_SUITE_PSK;
  305. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[3].dot11RSNAConfigAuthenticationSuite =
  306. RSN_AKM_SUITE_NONE;
  307. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[4].dot11RSNAConfigAuthenticationSuite =
  308. RSN_AKM_SUITE_802_1X;
  309. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[5].dot11RSNAConfigAuthenticationSuite =
  310. RSN_AKM_SUITE_PSK;
  311. #if CFG_SUPPORT_802_11W
  312. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[6].dot11RSNAConfigAuthenticationSuite =
  313. RSN_AKM_SUITE_802_1X_SHA256;
  314. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[7].dot11RSNAConfigAuthenticationSuite =
  315. RSN_AKM_SUITE_PSK_SHA256;
  316. #endif
  317. for (i = 0; i < MAX_NUM_SUPPORTED_AKM_SUITES; i++) {
  318. prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[i].dot11RSNAConfigAuthenticationSuiteEnabled =
  319. FALSE;
  320. }
  321. secClearPmkid(prAdapter);
  322. cnmTimerInitTimer(prAdapter,
  323. &prAisSpecBssInfo->rPreauthenticationTimer,
  324. (PFN_MGMT_TIMEOUT_FUNC) rsnIndicatePmkidCand, (ULONG) NULL);
  325. #if CFG_SUPPORT_802_11W
  326. cnmTimerInitTimer(prAdapter,
  327. &prAisSpecBssInfo->rSaQueryTimer, (PFN_MGMT_TIMEOUT_FUNC) rsnStartSaQueryTimer, (ULONG) NULL);
  328. #endif
  329. prAisSpecBssInfo->fgCounterMeasure = FALSE;
  330. prAisSpecBssInfo->ucWEPDefaultKeyID = 0;
  331. #if 0
  332. for (i = 0; i < WTBL_SIZE; i++) {
  333. g_prWifiVar->arWtbl[i].fgUsed = FALSE;
  334. g_prWifiVar->arWtbl[i].prSta = NULL;
  335. g_prWifiVar->arWtbl[i].ucNetTypeIdx = NETWORK_TYPE_INDEX_NUM;
  336. }
  337. nicPrivacyInitialize((UINT_8) NETWORK_TYPE_INDEX_NUM);
  338. #endif
  339. } /* secInit */
  340. /*----------------------------------------------------------------------------*/
  341. /*!
  342. * \brief This function will indicate an Event of "Rx Class Error" to SEC_FSM for
  343. * JOIN Module.
  344. *
  345. * \param[in] prAdapter Pointer to the Adapter structure
  346. * \param[in] prSwRfb Pointer to the SW RFB.
  347. *
  348. * \return FALSE Class Error
  349. */
  350. /*----------------------------------------------------------------------------*/
  351. BOOLEAN secCheckClassError(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb, IN P_STA_RECORD_T prStaRec)
  352. {
  353. ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex;
  354. P_BSS_INFO_T prBssInfo;
  355. ASSERT(prAdapter);
  356. ASSERT(prSwRfb);
  357. if (!prStaRec)
  358. return FALSE;
  359. eNetTypeIndex = prStaRec->ucNetTypeIndex;
  360. if (!IS_NET_ACTIVE(prAdapter, eNetTypeIndex))
  361. return FALSE;
  362. prBssInfo = &prAdapter->rWifiVar.arBssInfo[eNetTypeIndex];
  363. if ((STA_STATE_3 != prStaRec->ucStaState) && prBssInfo->fgIsNetAbsent == FALSE) {
  364. /*(IS_AP_STA(prStaRec) || IS_CLIENT_STA(prStaRec))) { */
  365. #if 0 /* by scott's suggestions, do not put work-around in JB2,we need to find the root cause */
  366. /* work-around for CR ALPS00816361 */
  367. if (eNetTypeIndex == NETWORK_TYPE_P2P_INDEX) {
  368. DBGLOG(RSN, INFO,
  369. "p2p> skip to send Deauth to MAC:[%pM] for Rx Class 3.\n",
  370. prStaRec->aucMacAddr);
  371. return TRUE;
  372. }
  373. #endif
  374. if (WLAN_STATUS_SUCCESS == authSendDeauthFrame(prAdapter,
  375. prStaRec,
  376. NULL,
  377. REASON_CODE_CLASS_3_ERR,
  378. (PFN_TX_DONE_HANDLER) NULL))
  379. DBGLOG(RSN, INFO, "Send Deauth to [ %pM ] for Rx Class 3 Error.\n",
  380. prStaRec->aucMacAddr);
  381. else
  382. DBGLOG(RSN, INFO, "Host sends Deauth to [ %pM ] for Rx Class 3 fail.\n",
  383. prStaRec->aucMacAddr);
  384. return FALSE;
  385. }
  386. return secRxPortControlCheck(prAdapter, prSwRfb);
  387. } /* end of secCheckClassError() */
  388. /*----------------------------------------------------------------------------*/
  389. /*!
  390. * \brief This routine is used to setting the sta port status.
  391. *
  392. * \param[in] prAdapter Pointer to the Adapter structure
  393. * \param[in] prSta Pointer to the sta
  394. * \param[in] fgPortBlock The port status
  395. *
  396. * \retval none
  397. *
  398. */
  399. /*----------------------------------------------------------------------------*/
  400. VOID secSetPortBlocked(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta, IN BOOLEAN fgPortBlock)
  401. {
  402. if (prSta == NULL)
  403. return;
  404. prSta->fgPortBlock = fgPortBlock;
  405. DBGLOG(RSN, TRACE,
  406. "The STA %pM port %s\n", prSta->aucMacAddr, fgPortBlock == TRUE ? "BLOCK" : " OPEN");
  407. }
  408. /*----------------------------------------------------------------------------*/
  409. /*!
  410. * \brief This routine is used to report the sta port status.
  411. *
  412. * \param[in] prAdapter Pointer to the Adapter structure
  413. * \param[in] prSta Pointer to the sta
  414. * \param[out] fgPortBlock The port status
  415. *
  416. * \return TRUE sta exist, FALSE sta not exist
  417. *
  418. */
  419. /*----------------------------------------------------------------------------*/
  420. BOOLEAN secGetPortStatus(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta, OUT PBOOLEAN pfgPortStatus)
  421. {
  422. if (prSta == NULL)
  423. return FALSE;
  424. *pfgPortStatus = prSta->fgPortBlock;
  425. return TRUE;
  426. }
  427. /*----------------------------------------------------------------------------*/
  428. /*!
  429. * \brief This routine is called to handle Peer device Tx Security process MSDU.
  430. *
  431. * \param[in] prMsduInfo pointer to the packet info pointer
  432. *
  433. * \retval TRUE Accept the packet
  434. * \retval FALSE Refuse the MSDU packet due port blocked
  435. *
  436. */
  437. /*----------------------------------------------------------------------------*/
  438. BOOLEAN /* ENUM_PORT_CONTROL_RESULT */
  439. secTxPortControlCheck(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo, IN P_STA_RECORD_T prStaRec)
  440. {
  441. ASSERT(prAdapter);
  442. ASSERT(prMsduInfo);
  443. ASSERT(prStaRec);
  444. if (prStaRec) {
  445. /* Todo:: */
  446. if (prMsduInfo->fgIs802_1x)
  447. return TRUE;
  448. if (prStaRec->fgPortBlock == TRUE) {
  449. DBGLOG(SEC, TRACE, "Drop Tx packet due Port Control!\n");
  450. return FALSE;
  451. }
  452. #if CFG_SUPPORT_WAPI
  453. if (prAdapter->rWifiVar.rConnSettings.fgWapiMode)
  454. return TRUE;
  455. #endif
  456. if (IS_STA_IN_AIS(prStaRec)) {
  457. if (!prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist &&
  458. (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION1_ENABLED)) {
  459. DBGLOG(SEC, TRACE, "Drop Tx packet due the key is removed!!!\n");
  460. return FALSE;
  461. }
  462. }
  463. }
  464. return TRUE;
  465. }
  466. /*----------------------------------------------------------------------------*/
  467. /*!
  468. * \brief This routine is called to handle The Rx Security process MSDU.
  469. *
  470. * \param[in] prAdapter Pointer to the Adapter structure
  471. * \param[in] prSWRfb SW rfb pinter
  472. *
  473. * \retval TRUE Accept the packet
  474. * \retval FALSE Refuse the MSDU packet due port control
  475. */
  476. /*----------------------------------------------------------------------------*/
  477. BOOLEAN secRxPortControlCheck(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSWRfb)
  478. {
  479. ASSERT(prSWRfb);
  480. #if 0
  481. /* whsu:Todo: Process MGMT and DATA */
  482. if (prSWRfb->prStaRec) {
  483. if (prSWRfb->prStaRec->fgPortBlock == TRUE) {
  484. if (1 /* prSWRfb->fgIsDataFrame and not 1x */ &&
  485. (g_prWifiVar->rConnSettings.eAuthMode >= AUTH_MODE_WPA)) {
  486. /* DBGLOG(SEC, WARN, ("Drop Rx data due port control !\r\n")); */
  487. return TRUE; /* Todo: whsu FALSE; */
  488. }
  489. /* if (!RX_STATUS_IS_PROTECT(prSWRfb->prRxStatus)) { */
  490. /* DBGLOG(RSN, WARN, ("Drop rcv non-encrypted data frame!\n")); */
  491. /* return FALSE; */
  492. /* } */
  493. }
  494. } else {
  495. }
  496. #endif
  497. return TRUE;
  498. }
  499. /*----------------------------------------------------------------------------*/
  500. /*!
  501. * \brief This routine will enable/disable the cipher suite
  502. *
  503. * \param[in] prAdapter Pointer to the adapter object data area.
  504. * \param[in] u4CipherSuitesFlags flag for cipher suite
  505. *
  506. * \retval none
  507. */
  508. /*----------------------------------------------------------------------------*/
  509. VOID secSetCipherSuite(IN P_ADAPTER_T prAdapter, IN UINT_32 u4CipherSuitesFlags)
  510. {
  511. UINT_32 i;
  512. P_DOT11_RSNA_CONFIG_PAIRWISE_CIPHERS_ENTRY prEntry;
  513. P_IEEE_802_11_MIB_T prMib;
  514. ASSERT(prAdapter);
  515. prMib = &prAdapter->rMib;
  516. ASSERT(prMib);
  517. if (u4CipherSuitesFlags == CIPHER_FLAG_NONE) {
  518. /* Disable all the pairwise cipher suites. */
  519. for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++)
  520. prMib->dot11RSNAConfigPairwiseCiphersTable[i].dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  521. /* Update the group cipher suite. */
  522. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_NONE;
  523. return;
  524. }
  525. for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++) {
  526. prEntry = &prMib->dot11RSNAConfigPairwiseCiphersTable[i];
  527. switch (prEntry->dot11RSNAConfigPairwiseCipher) {
  528. case WPA_CIPHER_SUITE_WEP40:
  529. case RSN_CIPHER_SUITE_WEP40:
  530. if (u4CipherSuitesFlags & CIPHER_FLAG_WEP40)
  531. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  532. else
  533. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  534. break;
  535. case WPA_CIPHER_SUITE_TKIP:
  536. case RSN_CIPHER_SUITE_TKIP:
  537. if (u4CipherSuitesFlags & CIPHER_FLAG_TKIP)
  538. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  539. else
  540. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  541. break;
  542. case WPA_CIPHER_SUITE_CCMP:
  543. case RSN_CIPHER_SUITE_CCMP:
  544. if (u4CipherSuitesFlags & CIPHER_FLAG_CCMP)
  545. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  546. else
  547. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  548. break;
  549. case WPA_CIPHER_SUITE_WEP104:
  550. case RSN_CIPHER_SUITE_WEP104:
  551. if (u4CipherSuitesFlags & CIPHER_FLAG_WEP104)
  552. prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
  553. else
  554. prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
  555. break;
  556. default:
  557. break;
  558. }
  559. }
  560. /* Update the group cipher suite. */
  561. if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_CCMP, &i))
  562. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_CCMP;
  563. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_TKIP, &i))
  564. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_TKIP;
  565. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP104, &i))
  566. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_WEP104;
  567. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP40, &i))
  568. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_WEP40;
  569. else
  570. prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_NONE;
  571. } /* secSetCipherSuite */
  572. /*----------------------------------------------------------------------------*/
  573. /*!
  574. * \brief This routine is called to handle The 2nd Tx EAPoL Frame.
  575. *
  576. * \param[in] prAdapter Pointer to the Adapter structure
  577. * \param[in] prMsduInfo pointer to the packet info pointer
  578. * \param[in] pucPayload pointer to the 1x hdr
  579. * \param[in] u2PayloadLen the 1x payload length
  580. *
  581. * \retval TRUE Accept the packet
  582. * \retval FALSE Refuse the MSDU packet due port control
  583. *
  584. */
  585. /*----------------------------------------------------------------------------*/
  586. BOOLEAN
  587. secProcessEAPOL(IN P_ADAPTER_T prAdapter,
  588. IN P_MSDU_INFO_T prMsduInfo, IN P_STA_RECORD_T prStaRec, IN PUINT_8 pucPayload, IN UINT_16 u2PayloadLen)
  589. {
  590. P_EAPOL_KEY prEapol = (P_EAPOL_KEY) NULL;
  591. P_IEEE_802_1X_HDR pr1xHdr;
  592. UINT_16 u2KeyInfo;
  593. ASSERT(prMsduInfo);
  594. ASSERT(prStaRec);
  595. /* prStaRec = &(g_arStaRec[prMsduInfo->ucStaRecIndex]); */
  596. ASSERT(prStaRec);
  597. if (prStaRec && IS_AP_STA(prStaRec)) {
  598. pr1xHdr = (P_IEEE_802_1X_HDR) pucPayload;
  599. if ((pr1xHdr->ucType == 3) /* EAPoL key */ && ((u2PayloadLen - 4) > sizeof(EAPOL_KEY))) {
  600. prEapol = (P_EAPOL_KEY) ((PUINT_32) (pucPayload + 4));
  601. WLAN_GET_FIELD_BE16(prEapol->aucKeyInfo, &u2KeyInfo);
  602. if ((prEapol->ucType == 254) && (u2KeyInfo & MASK_2ND_EAPOL)) {
  603. if (u2KeyInfo & WPA_KEY_INFO_SECURE) {
  604. /* 4th EAPoL check at secHandleTxDoneCallback() */
  605. /* DBGLOG(RSN, TRACE, ("Tx 4th EAPoL frame\r\n")); */
  606. } else if (u2PayloadLen == 123 /* Not include LLC */) {
  607. DBGLOG(RSN, INFO, "Tx 2nd EAPoL frame\r\n");
  608. secFsmEvent2ndEapolTx(prAdapter, prStaRec);
  609. }
  610. }
  611. }
  612. }
  613. return TRUE;
  614. }
  615. /*----------------------------------------------------------------------------*/
  616. /*!
  617. * \brief This function will handle the 4th EAPoL Tx done and mic Error Report frame.
  618. *
  619. * \param[in] prAdapter Pointer to the Adapter structure
  620. * \param[in] pMsduInfo Pointer to the Msdu Info
  621. * \param[in] rStatus The Tx done status
  622. *
  623. * \return -
  624. */
  625. /*----------------------------------------------------------------------------*/
  626. VOID
  627. secHandleTxDoneCallback(IN P_ADAPTER_T prAdapter,
  628. IN P_MSDU_INFO_T prMsduInfo, IN P_STA_RECORD_T prStaRec, IN WLAN_STATUS rStatus)
  629. {
  630. PUINT_8 pucPayload;
  631. P_IEEE_802_1X_HDR pr1xHdr = (P_IEEE_802_1X_HDR) NULL;
  632. P_EAPOL_KEY prEapol = (P_EAPOL_KEY) NULL;
  633. UINT_16 u2KeyInfo;
  634. UINT_16 u2PayloadLen;
  635. DEBUGFUNC("secHandleTxDoneCallback");
  636. ASSERT(prMsduInfo);
  637. /* Todo:: Notice if using the TX free immediate after send to firmware, the payload may not correcttly!!!! */
  638. ASSERT(prStaRec);
  639. /* Todo:: This call back may not need because the order of set key and send 4th 1x can be make sure */
  640. /* Todo:: Notice the LLC offset */
  641. #if 1
  642. pucPayload = (PUINT_8) prMsduInfo->prPacket;
  643. ASSERT(pucPayload);
  644. u2PayloadLen = prMsduInfo->u2FrameLength;
  645. if (0 /* prMsduInfo->fgIs1xFrame */) {
  646. if (prStaRec && IS_AP_STA(prStaRec)) {
  647. pr1xHdr = (P_IEEE_802_1X_HDR) (PUINT_32) (pucPayload + 8);
  648. if ((pr1xHdr->ucType == 3) /* EAPoL key */ && ((u2PayloadLen - 4) > sizeof(EAPOL_KEY))) {
  649. prEapol = (P_EAPOL_KEY) (PUINT_32) (pucPayload + 12);
  650. WLAN_GET_FIELD_BE16(prEapol->aucKeyInfo, &u2KeyInfo);
  651. if ((prEapol->ucType == 254) && (u2KeyInfo & MASK_2ND_EAPOL)) {
  652. if (prStaRec->rSecInfo.fg2nd1xSend == TRUE
  653. && u2PayloadLen ==
  654. 107 /* include LLC *//* u2KeyInfo & WPA_KEY_INFO_SECURE */) {
  655. DBGLOG(RSN, INFO, "Tx 4th EAPoL frame\r\n");
  656. secFsmEvent4ndEapolTxDone(prAdapter, prStaRec);
  657. } else if (prAdapter->rWifiVar.rAisSpecificBssInfo.fgCheckEAPoLTxDone) {
  658. DBGLOG(RSN, INFO, "Tx EAPoL Error report frame\r\n");
  659. /* secFsmEventEapolTxDone(prAdapter, (UINT_32)prMsduInfo->prStaRec); */
  660. }
  661. }
  662. }
  663. }
  664. }
  665. #endif
  666. }
  667. /*----------------------------------------------------------------------------*/
  668. /*!
  669. * \brief This routine is called to initialize the pmkid parameters.
  670. *
  671. * \param[in] prAdapter Pointer to the Adapter structure
  672. *
  673. * \retval NONE
  674. */
  675. /*----------------------------------------------------------------------------*/
  676. VOID secClearPmkid(IN P_ADAPTER_T prAdapter)
  677. {
  678. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  679. DEBUGFUNC("secClearPmkid");
  680. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  681. DBGLOG(RSN, TRACE, "secClearPmkid\n");
  682. prAisSpecBssInfo->u4PmkidCandicateCount = 0;
  683. prAisSpecBssInfo->u4PmkidCacheCount = 0;
  684. kalMemZero((PVOID) prAisSpecBssInfo->arPmkidCandicate, sizeof(PMKID_CANDICATE_T) * CFG_MAX_PMKID_CACHE);
  685. kalMemZero((PVOID) prAisSpecBssInfo->arPmkidCache, sizeof(PMKID_ENTRY_T) * CFG_MAX_PMKID_CACHE);
  686. }
  687. /*----------------------------------------------------------------------------*/
  688. /*!
  689. * \brief Whether WPA, or WPA2 but not WPA-None is enabled.
  690. *
  691. * \param[in] prAdapter Pointer to the Adapter structure
  692. *
  693. * \retval BOOLEAN
  694. */
  695. /*----------------------------------------------------------------------------*/
  696. BOOLEAN secRsnKeyHandshakeEnabled(IN P_ADAPTER_T prAdapter)
  697. {
  698. P_CONNECTION_SETTINGS_T prConnSettings;
  699. ASSERT(prAdapter);
  700. prConnSettings = &prAdapter->rWifiVar.rConnSettings;
  701. ASSERT(prConnSettings);
  702. ASSERT(prConnSettings->eEncStatus < ENUM_ENCRYPTION3_KEY_ABSENT);
  703. if (prConnSettings->eEncStatus == ENUM_ENCRYPTION_DISABLED)
  704. return FALSE;
  705. ASSERT(prConnSettings->eAuthMode < AUTH_MODE_NUM);
  706. if ((prConnSettings->eAuthMode >= AUTH_MODE_WPA) && (prConnSettings->eAuthMode != AUTH_MODE_WPA_NONE))
  707. return TRUE;
  708. return FALSE;
  709. } /* secRsnKeyHandshakeEnabled */
  710. /*----------------------------------------------------------------------------*/
  711. /*!
  712. * \brief Return whether the transmit key alread installed.
  713. *
  714. * \param[in] prAdapter Pointer to the Adapter structure
  715. * \param[in] prSta Pointer the sta record
  716. *
  717. * \retval TRUE Default key or Transmit key installed
  718. * FALSE Default key or Transmit key not installed
  719. *
  720. * \note:
  721. */
  722. /*----------------------------------------------------------------------------*/
  723. BOOLEAN secTransmitKeyExist(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  724. {
  725. ASSERT(prSta);
  726. if (prSta->fgTransmitKeyExist)
  727. return TRUE;
  728. else
  729. return FALSE;
  730. } /* secTransmitKeyExist */
  731. /*----------------------------------------------------------------------------*/
  732. /*!
  733. * \brief Whether 802.11 privacy is enabled.
  734. *
  735. * \param[in] prAdapter Pointer to the Adapter structure
  736. *
  737. * \retval BOOLEAN
  738. */
  739. /*----------------------------------------------------------------------------*/
  740. BOOLEAN secEnabledInAis(IN P_ADAPTER_T prAdapter)
  741. {
  742. DEBUGFUNC("secEnabled");
  743. ASSERT(prAdapter->rWifiVar.rConnSettings.eEncStatus < ENUM_ENCRYPTION3_KEY_ABSENT);
  744. switch (prAdapter->rWifiVar.rConnSettings.eEncStatus) {
  745. case ENUM_ENCRYPTION_DISABLED:
  746. return FALSE;
  747. case ENUM_ENCRYPTION1_ENABLED:
  748. case ENUM_ENCRYPTION2_ENABLED:
  749. case ENUM_ENCRYPTION3_ENABLED:
  750. return TRUE;
  751. default:
  752. DBGLOG(RSN, TRACE, "Unknown encryption setting %d\n", prAdapter->rWifiVar.rConnSettings.eEncStatus);
  753. break;
  754. }
  755. return FALSE;
  756. } /* secEnabled */
  757. /*----------------------------------------------------------------------------*/
  758. /*!
  759. * \brief This routine is called to set the privacy bit at mac header for TxM
  760. *
  761. * \param[in] prAdapter Pointer to the Adapter structure
  762. * \param[in] prMsdu the msdu for known the sta record
  763. *
  764. * \return TRUE the privacy need to set
  765. * FALSE the privacy no need to set
  766. */
  767. /*----------------------------------------------------------------------------*/
  768. BOOLEAN secIsProtectedFrame(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsdu, IN P_STA_RECORD_T prStaRec)
  769. {
  770. ASSERT(prAdapter);
  771. ASSERT(prMsdu);
  772. ASSERT(prStaRec);
  773. /* prStaRec = &(g_arStaRec[prMsdu->ucStaRecIndex]); */
  774. if (prStaRec == NULL) {
  775. if (prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist)
  776. return TRUE;
  777. return FALSE; /* No privacy bit */
  778. }
  779. /* Todo:: */
  780. if (0 /* prMsdu->fgIs1xFrame */) {
  781. if (IS_STA_IN_AIS(prStaRec) && prAdapter->rWifiVar.rConnSettings.eAuthMode < AUTH_MODE_WPA) {
  782. DBGLOG(RSN, LOUD, "For AIS Legacy 1x, always not encryped\n");
  783. return FALSE;
  784. } else if (!prStaRec->fgTransmitKeyExist) {
  785. DBGLOG(RSN, LOUD, "1x Not Protected.\n");
  786. return FALSE;
  787. } else if (prStaRec->rSecInfo.fgKeyStored) {
  788. DBGLOG(RSN, LOUD, "1x not Protected due key stored!\n");
  789. return FALSE;
  790. }
  791. DBGLOG(RSN, LOUD, "1x Protected.\n");
  792. return TRUE;
  793. }
  794. if (!prStaRec->fgTransmitKeyExist) {
  795. /* whsu , check for AIS only */
  796. if (prAdapter->rWifiVar.rConnSettings.eAuthMode < AUTH_MODE_WPA &&
  797. prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist) {
  798. DBGLOG(RSN, LOUD, "Protected\n");
  799. return TRUE;
  800. }
  801. } else {
  802. DBGLOG(RSN, LOUD, "Protected.\n");
  803. return TRUE;
  804. }
  805. /* No sec or key is removed!!! */
  806. return FALSE;
  807. }
  808. #endif