sec_fsm.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/sec_fsm.c#1
  3. */
  4. /*! \file "sec_fsm.c"
  5. \brief This is the file implement security check state machine.
  6. In security module, do the port control check after success join to an AP,
  7. and the path to NORMAL TR, the state machine handle these state transition.
  8. */
  9. /*
  10. ** Log: sec_fsm.c
  11. *
  12. * 11 24 2011 wh.su
  13. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  14. * Adjust code for DBG and CONFIG_XLOG.
  15. *
  16. * 11 11 2011 wh.su
  17. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  18. * modify the xlog related code.
  19. *
  20. * 11 10 2011 wh.su
  21. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  22. * change the debug module level.
  23. *
  24. * 11 02 2011 wh.su
  25. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  26. * adding the code for XLOG.
  27. *
  28. * 03 29 2011 wh.su
  29. * [WCXRP00000248] [MT6620 Wi-Fi][FW]Fixed the Klockwork error
  30. * fixed the kclocwork error.
  31. *
  32. * 01 26 2011 yuche.tsai
  33. * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
  34. * .
  35. *
  36. * 01 25 2011 yuche.tsai
  37. * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
  38. * Fix Compile Error when DBG is disabled.
  39. *
  40. * 01 25 2011 yuche.tsai
  41. * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
  42. * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
  43. *
  44. * 09 29 2010 wh.su
  45. * [WCXRP00000072] [MT6620 Wi-Fi][Driver] Fix TKIP Counter Measure EAPoL callback register issue
  46. * [MT6620 Wi-Fi][Driver] Fix TKIP Counter Measure EAPoL callback register issue.
  47. *
  48. * 09 24 2010 wh.su
  49. * NULL
  50. * [WCXRP00005002][MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning.
  51. *
  52. * 09 03 2010 kevin.huang
  53. * NULL
  54. * Refine #include sequence and solve recursive/nested #include issue
  55. *
  56. * 08 20 2010 wh.su
  57. * NULL
  58. * adding the eapol callback setting.
  59. *
  60. * 08 19 2010 wh.su
  61. * NULL
  62. * adding the tx pkt call back handle for countermeasure.
  63. *
  64. * 07 19 2010 wh.su
  65. *
  66. * fixed the compilng error at debug mode.
  67. *
  68. * 07 08 2010 cp.wu
  69. *
  70. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  71. *
  72. * 06 21 2010 wh.su
  73. * [WPD00003840][MT6620 5931] Security migration
  74. * modify some code for concurrent network.
  75. *
  76. * 06 19 2010 wh.su
  77. * [WPD00003840][MT6620 5931] Security migration
  78. * consdier the concurrent network setting.
  79. *
  80. * 05 28 2010 wh.su
  81. * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
  82. * fixed the ad-hoc wpa-none send non-encrypted frame issue.
  83. *
  84. * 05 24 2010 kevin.huang
  85. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  86. * Refine authSendAuthFrame() for NULL STA_RECORD_T case and minimum deauth interval.
  87. *
  88. * 04 24 2010 cm.chang
  89. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  90. * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
  91. *
  92. * 04 13 2010 wh.su
  93. * [BORA00000680][MT6620] Support the statistic for Micxxsoft os query
  94. * fixed the Klocwork error and refine the class error message.
  95. *
  96. * 03 03 2010 wh.su
  97. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  98. * move the AIS specific variable for security to AIS specific structure.
  99. *
  100. * 03 03 2010 wh.su
  101. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  102. * Fixed the pre-authentication timer not correctly init issue,
  103. * and modify the security related callback function prototype.
  104. *
  105. * 03 01 2010 wh.su
  106. * [BORA00000605][WIFISYS] Phase3 Integration
  107. * Refine the variable and parameter for security.
  108. *
  109. * 01 27 2010 wh.su
  110. * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
  111. * add and fixed some security function.
  112. *
  113. * 01 13 2010 wh.su
  114. * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
  115. * fixed the compiling warning
  116. *
  117. * 12 18 2009 cm.chang
  118. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  119. * .
  120. *
  121. * Dec 7 2009 mtk01088
  122. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  123. * refine some code
  124. *
  125. * Dec 4 2009 mtk01088
  126. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  127. * refine the code
  128. *
  129. * Dec 1 2009 mtk01088
  130. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  131. * code refine
  132. *
  133. * Nov 23 2009 mtk01088
  134. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  135. * adjust the function name
  136. *
  137. * Nov 19 2009 mtk01088
  138. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  139. * adjust the state machine, to meet the firmware security design v1.1
  140. *
  141. * Nov 18 2009 mtk01088
  142. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  143. *
  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. #if CFG_RSN_MIGRATION
  156. /*******************************************************************************
  157. * C O N S T A N T S
  158. ********************************************************************************
  159. */
  160. /*******************************************************************************
  161. * D A T A T Y P E S
  162. ********************************************************************************
  163. */
  164. /*******************************************************************************
  165. * P U B L I C D A T A
  166. ********************************************************************************
  167. */
  168. /*******************************************************************************
  169. * P R I V A T E D A T A
  170. ********************************************************************************
  171. */
  172. #if DBG
  173. /*lint -save -e64 Type mismatch */
  174. static PUINT_8 apucDebugSecState[SEC_STATE_NUM] = {
  175. (PUINT_8) DISP_STRING("SEC_STATE_INIT"),
  176. (PUINT_8) DISP_STRING("SEC_STATE_INITIATOR_PORT_BLOCKED"),
  177. (PUINT_8) DISP_STRING("SEC_STATE_RESPONDER_PORT_BLOCKED"),
  178. (PUINT_8) DISP_STRING("SEC_STATE_CHECK_OK"),
  179. (PUINT_8) DISP_STRING("SEC_STATE_SEND_EAPOL"),
  180. (PUINT_8) DISP_STRING("SEC_STATE_SEND_DEAUTH"),
  181. (PUINT_8) DISP_STRING("SEC_STATE_COUNTERMEASURE"),
  182. };
  183. /*lint -restore */
  184. #endif /* DBG */
  185. /*******************************************************************************
  186. * M A C R O S
  187. ********************************************************************************
  188. */
  189. /*******************************************************************************
  190. * F U N C T I O N D E C L A R A T I O N S
  191. ********************************************************************************
  192. */
  193. /*******************************************************************************
  194. * F U N C T I O N S
  195. ********************************************************************************
  196. */
  197. /*----------------------------------------------------------------------------*/
  198. /*!
  199. * \brief This function will do initialization of Security FSM and all variables in
  200. * SEC_INFO_T.
  201. *
  202. * \param[in] prSta Pointer to the STA record
  203. *
  204. * \return none
  205. */
  206. /*----------------------------------------------------------------------------*/
  207. VOID secFsmInit(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  208. {
  209. P_SEC_INFO_T prSecInfo;
  210. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  211. ASSERT(prSta);
  212. prSecInfo = &prSta->rSecInfo;
  213. #if 1 /* MT6620 */
  214. /* At MT5921, is ok, but at MT6620, firmware base ASIC, the firmware */
  215. /* will lost these data, thus, driver have to keep the wep material and */
  216. /* setting to firmware while awake from D3. */
  217. #endif
  218. prSecInfo->eCurrentState = SEC_STATE_INIT;
  219. prSecInfo->fg2nd1xSend = FALSE;
  220. prSecInfo->fgKeyStored = FALSE;
  221. if (IS_STA_IN_AIS(prSta)) {
  222. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  223. prAisSpecBssInfo->u4RsnaLastMICFailTime = 0;
  224. prAisSpecBssInfo->fgCheckEAPoLTxDone = FALSE;
  225. cnmTimerInitTimer(prAdapter,
  226. &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaEAPoLReportTimeoutTimer,
  227. (PFN_MGMT_TIMEOUT_FUNC) secFsmEventEapolTxTimeout, (ULONG) prSta);
  228. cnmTimerInitTimer(prAdapter,
  229. &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaBlockTrafficTimer,
  230. (PFN_MGMT_TIMEOUT_FUNC) secFsmEventEndOfCounterMeasure, (ULONG) prSta);
  231. }
  232. }
  233. /*----------------------------------------------------------------------------*/
  234. /*!
  235. * \brief This function will do uninitialization of Security FSM and all variables in
  236. * SEC_INFO_T.
  237. *
  238. * \param[in] prSta Pointer to the STA record
  239. *
  240. * \return none
  241. */
  242. /*----------------------------------------------------------------------------*/
  243. VOID /* whsu:Todo: */
  244. secFsmUnInit(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  245. {
  246. P_SEC_INFO_T prSecInfo;
  247. ASSERT(prSta);
  248. prSecInfo = &prSta->rSecInfo;
  249. prSecInfo->fg2nd1xSend = FALSE;
  250. prSecInfo->fgKeyStored = FALSE;
  251. /* nicPrivacyRemoveWlanTable(prSta->ucWTEntry); */
  252. if (IS_STA_IN_AIS(prSta)) {
  253. cnmTimerStopTimer(prAdapter, &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaEAPoLReportTimeoutTimer);
  254. cnmTimerStopTimer(prAdapter, &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaBlockTrafficTimer);
  255. }
  256. }
  257. /*----------------------------------------------------------------------------*/
  258. /*!
  259. * \brief This function will do action part while in STATE transition of
  260. * STANDBY to CHECK_OK.
  261. *
  262. * \param[in] prSta Pointer to the Sta record
  263. *
  264. * \return - none
  265. */
  266. /*----------------------------------------------------------------------------*/
  267. static inline VOID secFsmTrans_INIT_to_CHECK_OK(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  268. {
  269. secSetPortBlocked(prAdapter, prSta, FALSE);
  270. }
  271. /*----------------------------------------------------------------------------*/
  272. /*!
  273. * \brief This function will do action part while in STATE transition of
  274. * INIT to INITIATOR_PORT_BLOCKED.
  275. *
  276. * \param[in] prSta Pointer to the Sta record
  277. *
  278. * \return - none
  279. */
  280. /*----------------------------------------------------------------------------*/
  281. static inline VOID secFsmTrans_INIT_to_INITIATOR_PORT_BLOCKED(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  282. {
  283. }
  284. /*----------------------------------------------------------------------------*/
  285. /*!
  286. * \brief This function will do action part while in STATE transition of
  287. * INIT to RESPONDER_PORT_BLOCKED.
  288. *
  289. * \param[in] prSta Pointer to the Sta record
  290. *
  291. * \return - none
  292. */
  293. /*----------------------------------------------------------------------------*/
  294. static inline VOID secFsmTrans_INIT_to_RESPONDER_PORT_BLOCKED(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  295. {
  296. }
  297. /*----------------------------------------------------------------------------*/
  298. /*!
  299. * \brief This function will do action part while in STATE transition of
  300. * INITIATOR_PORT_BLOCKED to CHECK_OK.
  301. *
  302. * \param[in] prSta Pointer to the Sta record
  303. *
  304. * \return - none
  305. */
  306. /*----------------------------------------------------------------------------*/
  307. static inline VOID secFsmTrans_INITIATOR_PORT_BLOCKED_to_CHECK_OK(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  308. {
  309. secSetPortBlocked(prAdapter, prSta, FALSE);
  310. }
  311. /*----------------------------------------------------------------------------*/
  312. /*!
  313. * \brief This function will do action part while in STATE transition of
  314. * RESPONDER_PORT_BLOCKED to CHECK_OK.
  315. *
  316. * \param[in] prSta Pointer to the Sta record
  317. *
  318. * \return - none
  319. */
  320. /*----------------------------------------------------------------------------*/
  321. static inline VOID secFsmTrans_RESPONDER_PORT_BLOCKED_to_CHECK_OK(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  322. {
  323. secSetPortBlocked(prAdapter, prSta, FALSE);
  324. }
  325. /*----------------------------------------------------------------------------*/
  326. /*!
  327. * \brief This function will do action part while in STATE transition of
  328. * CHECK_OK to SEND_EAPOL
  329. *
  330. * \param[in] prSta Pointer to the Sta record
  331. *
  332. * \return -
  333. */
  334. /*----------------------------------------------------------------------------*/
  335. static inline VOID secFsmTrans_CHECK_OK_to_SEND_EAPOL(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  336. {
  337. P_AIS_SPECIFIC_BSS_INFO_T prAisBssInfo;
  338. ASSERT(prAdapter);
  339. ASSERT(prSta);
  340. prAisBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  341. ASSERT(prAisBssInfo);
  342. if (!IS_STA_IN_AIS(prSta)) {
  343. DBGLOG(RSN, INFO, "Counter Measure should occur at AIS network!!\n");
  344. /* ASSERT(0); */
  345. return;
  346. }
  347. prAisBssInfo->fgCheckEAPoLTxDone = TRUE;
  348. /* cnmTimerStartTimer(prAdapter, */
  349. /* &prAisBssInfo->rRsnaEAPoLReportTimeoutTimer, */
  350. /* SEC_TO_MSEC(EAPOL_REPORT_SEND_TIMEOUT_INTERVAL_SEC)); */
  351. }
  352. /*----------------------------------------------------------------------------*/
  353. /*!
  354. * \brief This function will do action part while in STATE transition of
  355. * SEND_EAPOL to SEND_DEAUTH.
  356. *
  357. * \param[in] prSta Pointer to the Sta record
  358. *
  359. * \return - none
  360. */
  361. /*----------------------------------------------------------------------------*/
  362. static inline VOID secFsmTrans_SEND_EAPOL_to_SEND_DEAUTH(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  363. {
  364. if (!IS_STA_IN_AIS(prSta)) {
  365. DBGLOG(RSN, INFO, "Counter Measure should occur at AIS network!!\n");
  366. /* ASSERT(0); */
  367. return;
  368. }
  369. /* Compose deauth frame to AP, a call back function for tx done */
  370. if (authSendDeauthFrame(prAdapter,
  371. prSta,
  372. (P_SW_RFB_T) NULL,
  373. REASON_CODE_MIC_FAILURE,
  374. (PFN_TX_DONE_HANDLER) secFsmEventDeauthTxDone) != WLAN_STATUS_SUCCESS) {
  375. ASSERT(FALSE);
  376. }
  377. }
  378. /*----------------------------------------------------------------------------*/
  379. /*!
  380. * \brief This function will do action part while in STATE transition of
  381. * SEND_DEAUTH to COUNTERMEASURE.
  382. *
  383. * \param[in] prSta Pointer to the Sta record
  384. *
  385. * \return -
  386. */
  387. /*----------------------------------------------------------------------------*/
  388. static inline VOID secFsmTrans_SEND_DEAUTH_to_COUNTERMEASURE(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  389. {
  390. ASSERT(prAdapter);
  391. ASSERT(prSta);
  392. if (!IS_STA_IN_AIS(prSta)) {
  393. DBGLOG(RSN, INFO, "Counter Measure should occur at AIS network!!\n");
  394. /* ASSERT(0); */
  395. return;
  396. }
  397. /* Start the 60 sec timer */
  398. cnmTimerStartTimer(prAdapter,
  399. &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaBlockTrafficTimer,
  400. SEC_TO_MSEC(COUNTER_MEASURE_TIMEOUT_INTERVAL_SEC));
  401. }
  402. /*----------------------------------------------------------------------------*/
  403. /*!
  404. * \brief This function will do action part while in STATE transition of
  405. * SEND_DEAUTH to COUNTERMEASURE.
  406. *
  407. * \param[in] prSta Pointer to the Sta record
  408. *
  409. * \return -
  410. */
  411. /*----------------------------------------------------------------------------*/
  412. static inline VOID secFsmTrans_COUNTERMEASURE_to_INIT(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  413. {
  414. /* Clear the counter measure flag */
  415. }
  416. /*----------------------------------------------------------------------------*/
  417. /*!
  418. * \brief The Core FSM engine of security module.
  419. *
  420. * \param[in] prSta Pointer to the Sta record
  421. * \param[in] eNextState Enum value of next sec STATE
  422. *
  423. * \return -
  424. */
  425. /*----------------------------------------------------------------------------*/
  426. VOID secFsmSteps(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta, IN ENUM_SEC_STATE_T eNextState)
  427. {
  428. P_SEC_INFO_T prSecInfo;
  429. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  430. ASSERT(prSta);
  431. prSecInfo = &prSta->rSecInfo;
  432. ASSERT(prSecInfo);
  433. DEBUGFUNC("secFsmSteps");
  434. do {
  435. /* Do entering Next State */
  436. prSecInfo->ePreviousState = prSecInfo->eCurrentState;
  437. /* Do entering Next State */
  438. #if DBG
  439. DBGLOG(RSN, STATE, "\n %pM TRANSITION: [%s] -> [%s]\n\n",
  440. prSta->aucMacAddr,
  441. apucDebugSecState[prSecInfo->eCurrentState], apucDebugSecState[eNextState]);
  442. #else
  443. DBGLOG(RSN, STATE, "\n %pM [%d] TRANSITION: [%d] -> [%d]\n\n",
  444. prSta->aucMacAddr, DBG_RSN_IDX, prSecInfo->eCurrentState, eNextState);
  445. #endif
  446. prSecInfo->eCurrentState = eNextState;
  447. fgIsTransition = (BOOLEAN) FALSE;
  448. #if 0
  449. /* Do tasks of the State that we just entered */
  450. switch (prSecInfo->eCurrentState) {
  451. case SEC_STATE_INIT:
  452. break;
  453. case SEC_STATE_INITIATOR_PORT_BLOCKED:
  454. break;
  455. case SEC_STATE_RESPONDER_PORT_BLOCKED:
  456. break;
  457. case SEC_STATE_CHECK_OK:
  458. break;
  459. case SEC_STATE_SEND_EAPOL:
  460. break;
  461. case SEC_STATE_SEND_DEAUTH:
  462. break;
  463. case SEC_STATE_COUNTERMEASURE:
  464. break;
  465. default:
  466. ASSERT(0); /* Make sure we have handle all STATEs */
  467. break;
  468. }
  469. #endif
  470. } while (fgIsTransition);
  471. return;
  472. }
  473. /*----------------------------------------------------------------------------*/
  474. /*!
  475. * \brief This function will do initialization of Security FSM and all variables in
  476. * SEC_INFO_T.
  477. *
  478. * \param[in] prSta Pointer to the Sta record
  479. *
  480. * \return none
  481. */
  482. /*----------------------------------------------------------------------------*/
  483. VOID secFsmEventStart(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  484. {
  485. P_SEC_INFO_T prSecInfo;
  486. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  487. ENUM_SEC_STATE_T eNextState;
  488. DBGLOG(RSN, TRACE, "secFsmRunEventStart\n");
  489. ASSERT(prSta);
  490. if (!prSta)
  491. return;
  492. if (!IS_STA_IN_AIS(prSta))
  493. return;
  494. DBGLOG(RSN, TRACE, "secFsmRunEventStart for sta %pM network %d\n",
  495. prSta->aucMacAddr, prSta->ucNetTypeIndex);
  496. prSecInfo = (P_SEC_INFO_T) &prSta->rSecInfo;
  497. eNextState = prSecInfo->eCurrentState;
  498. secSetPortBlocked(prAdapter, prSta, TRUE);
  499. /* prSta->fgTransmitKeyExist = FALSE; */
  500. /* whsu:: nicPrivacySetStaDefaultWTIdx(prSta); */
  501. #if 1 /* Since the 1x and key can set to firmware in order, always enter the check ok state */
  502. SEC_STATE_TRANSITION(prAdapter, prSta, INIT, CHECK_OK);
  503. #else
  504. if (IS_STA_IN_AIS(prSta->eStaType)) {
  505. if (secRsnKeyHandshakeEnabled(prAdapter) == TRUE
  506. #if CFG_SUPPORT_WAPI
  507. || (prAdapter->rWifiVar.rConnSettings.fgWapiMode)
  508. #endif
  509. ) {
  510. prSta->fgTransmitKeyExist = FALSE;
  511. /* nicPrivacyInitialize(prSta->ucNetTypeIndex); */
  512. SEC_STATE_TRANSITION(prAdapter, prSta, INIT, INITIATOR_PORT_BLOCKED);
  513. } else {
  514. SEC_STATE_TRANSITION(prAdapter, prSta, INIT, CHECK_OK);
  515. }
  516. }
  517. #if CFG_ENABLE_WIFI_DIRECT || CFG_ENABLE_BT_OVER_WIFI
  518. #if CFG_ENABLE_WIFI_DIRECT && CFG_ENABLE_BT_OVER_WIFI
  519. else if ((prSta->eStaType == STA_TYPE_BOW_CLIENT) || (prSta->eStaType == STA_TYPE_P2P_GC)) {
  520. #elif CFG_ENABLE_WIFI_DIRECT
  521. else if (prSta->eStaType == STA_TYPE_P2P_GC) {
  522. #elif CFG_ENABLE_BT_OVER_WIFI
  523. else if (prSta->eStaType == STA_TYPE_BOW_CLIENT) {
  524. #endif
  525. SEC_STATE_TRANSITION(prAdapter, prSta, INIT, RESPONDER_PORT_BLOCKED);
  526. }
  527. #endif
  528. else
  529. SEC_STATE_TRANSITION(prAdapter, prSta, INIT, INITIATOR_PORT_BLOCKED);
  530. #endif
  531. if (prSecInfo->eCurrentState != eNextState)
  532. secFsmSteps(prAdapter, prSta, eNextState);
  533. } /* secFsmRunEventStart */
  534. /*----------------------------------------------------------------------------*/
  535. /*!
  536. * \brief This function called by reset procedure to force the sec fsm enter
  537. * idle state
  538. *
  539. * \param[in] ucNetTypeIdx The Specific Network type index
  540. * \param[in] prSta Pointer to the Sta record
  541. *
  542. * \return none
  543. */
  544. /*----------------------------------------------------------------------------*/
  545. VOID secFsmEventAbort(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  546. {
  547. P_SEC_INFO_T prSecInfo;
  548. DBGLOG(RSN, TRACE, "secFsmEventAbort for sta %pM network %d\n",
  549. prSta->aucMacAddr, prSta->ucNetTypeIndex);
  550. ASSERT(prSta);
  551. if (!prSta)
  552. return;
  553. if (!IS_STA_IN_AIS(prSta))
  554. return;
  555. prSecInfo = (P_SEC_INFO_T) &prSta->rSecInfo;
  556. prSta->fgTransmitKeyExist = FALSE;
  557. secSetPortBlocked(prAdapter, prSta, TRUE);
  558. if (prSecInfo == NULL)
  559. return;
  560. if (IS_STA_IN_AIS(prSta)) {
  561. prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist = FALSE;
  562. if (prSecInfo->eCurrentState == SEC_STATE_SEND_EAPOL) {
  563. if (prAdapter->rWifiVar.rAisSpecificBssInfo.fgCheckEAPoLTxDone == FALSE) {
  564. DBGLOG(RSN, TRACE, "EAPOL STATE not match the flag\n");
  565. /* cnmTimerStopTimer(prAdapter, &prAdapter->rWifiVar.
  566. * rAisSpecificBssInfo.rRsnaEAPoLReportTimeoutTimer); */
  567. }
  568. }
  569. }
  570. prSecInfo->eCurrentState = SEC_STATE_INIT;
  571. }
  572. /*----------------------------------------------------------------------------*/
  573. /*!
  574. * \brief This function will indicate an Event of "2nd EAPoL Tx is sending" to Sec FSM.
  575. *
  576. * \param[in] prSta Pointer to the Sta record
  577. *
  578. * \return -
  579. */
  580. /*----------------------------------------------------------------------------*/
  581. VOID secFsmEvent2ndEapolTx(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  582. {
  583. P_SEC_INFO_T prSecInfo;
  584. ENUM_SEC_STATE_T eNextState;
  585. /* BOOLEAN fgIsTransition = (BOOLEAN)FALSE; */
  586. DEBUGFUNC("secFsmRunEvent2ndEapolTx");
  587. ASSERT(prSta);
  588. prSecInfo = &prSta->rSecInfo;
  589. eNextState = prSecInfo->eCurrentState;
  590. #if DBG
  591. DBGLOG(RSN, TRACE, "%pM Sec state %s\n", prSta->aucMacAddr,
  592. apucDebugSecState[prSecInfo->eCurrentState]);
  593. #else
  594. DBGLOG(RSN, TRACE, "%pM Sec state [%d]\n", prSta->aucMacAddr, prSecInfo->eCurrentState);
  595. #endif
  596. switch (prSecInfo->eCurrentState) {
  597. case SEC_STATE_INITIATOR_PORT_BLOCKED:
  598. case SEC_STATE_CHECK_OK:
  599. prSecInfo->fg2nd1xSend = TRUE;
  600. break;
  601. default:
  602. #if DBG
  603. DBGLOG(RSN, WARN, "Rcv 2nd EAPoL at %s\n", apucDebugSecState[prSecInfo->eCurrentState]);
  604. #else
  605. DBGLOG(RSN, WARN, "Rcv 2nd EAPoL at [%d]\n", prSecInfo->eCurrentState);
  606. #endif
  607. break;
  608. }
  609. if (prSecInfo->eCurrentState != eNextState)
  610. secFsmSteps(prAdapter, prSta, eNextState);
  611. return;
  612. } /* secFsmRunEvent2ndEapolTx */
  613. /*----------------------------------------------------------------------------*/
  614. /*!
  615. * \brief This function will indicate an Event of "4th EAPoL Tx is Tx done" to Sec FSM.
  616. *
  617. * \param[in] prSta Pointer to the Sta record
  618. *
  619. * \return -
  620. */
  621. /*----------------------------------------------------------------------------*/
  622. VOID secFsmEvent4ndEapolTxDone(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  623. {
  624. P_SEC_INFO_T prSecInfo;
  625. ENUM_SEC_STATE_T eNextState;
  626. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  627. P_CMD_802_11_KEY prStoredKey;
  628. DEBUGFUNC("secFsmRunEvent4ndEapolTx");
  629. ASSERT(prSta);
  630. prSecInfo = &prSta->rSecInfo;
  631. eNextState = prSecInfo->eCurrentState;
  632. #if DBG
  633. DBGLOG(RSN, TRACE, "%pM Sec state %s\n", prSta->aucMacAddr,
  634. apucDebugSecState[prSecInfo->eCurrentState]);
  635. #else
  636. DBGLOG(RSN, TRACE, "%pM Sec state [%d]\n", prSta->aucMacAddr, prSecInfo->eCurrentState);
  637. #endif
  638. switch (prSecInfo->eCurrentState) {
  639. case SEC_STATE_INITIATOR_PORT_BLOCKED:
  640. case SEC_STATE_CHECK_OK:
  641. prSecInfo->fg2nd1xSend = FALSE;
  642. if (prSecInfo->fgKeyStored) {
  643. prStoredKey = (P_CMD_802_11_KEY) prSecInfo->aucStoredKey;
  644. /* prSta = rxmLookupStaRecIndexFromTA(prStoredKey->aucPeerAddr); */
  645. /* if (nicPrivacySetKeyEntry(prStoredKey, prSta->ucWTEntry) == FALSE) */
  646. /* DBGLOG(RSN, WARN, ("nicPrivacySetKeyEntry() fail,..\n")); */
  647. /* key update */
  648. prSecInfo->fgKeyStored = FALSE;
  649. prSta->fgTransmitKeyExist = TRUE;
  650. }
  651. if (prSecInfo->eCurrentState == SEC_STATE_INITIATOR_PORT_BLOCKED)
  652. SEC_STATE_TRANSITION(prAdapter, prSta, INITIATOR_PORT_BLOCKED, CHECK_OK);
  653. break;
  654. default:
  655. #if DBG
  656. DBGLOG(RSN, WARN, "Rcv thh EAPoL Tx done at %s\n", apucDebugSecState[prSecInfo->eCurrentState]);
  657. #else
  658. DBGLOG(RSN, WARN, "Rcv thh EAPoL Tx done at [%d]\n", prSecInfo->eCurrentState);
  659. #endif
  660. break;
  661. }
  662. if (prSecInfo->eCurrentState != eNextState)
  663. secFsmSteps(prAdapter, prSta, eNextState);
  664. return;
  665. } /* secFsmRunEvent4ndEapolTx */
  666. /*----------------------------------------------------------------------------*/
  667. /*!
  668. * \brief This function will indicate an Event of "Pairwise key installed" to SEC FSM.
  669. *
  670. * \param[in] prSta Pointer to the Sta record
  671. *
  672. * \retval TRUE The key can be installed to HW
  673. * \retval FALSE The kay conflict with the current key, abort it
  674. */
  675. /*----------------------------------------------------------------------------*/
  676. BOOLEAN secFsmEventPTKInstalled(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  677. {
  678. P_SEC_INFO_T prSecInfo;
  679. ENUM_SEC_STATE_T eNextState;
  680. BOOLEAN fgStatus = TRUE;
  681. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  682. ASSERT(prSta);
  683. prSecInfo = &prSta->rSecInfo;
  684. if (prSecInfo == NULL)
  685. return TRUE; /* Not PTK */
  686. #if DBG
  687. DBGLOG(RSN, TRACE, "%pM Sec state %s\n", prSta->aucMacAdd),
  688. apucDebugSecState[prSecInfo->eCurrentState]);
  689. #else
  690. DBGLOG(RSN, TRACE, "%pM Sec state [%d]\n", prSta->aucMacAddr, prSecInfo->eCurrentState);
  691. #endif
  692. eNextState = prSecInfo->eCurrentState;
  693. switch (prSecInfo->eCurrentState) {
  694. case SEC_STATE_INIT:
  695. /* Legacy wep, wpa-none */
  696. break;
  697. case SEC_STATE_INITIATOR_PORT_BLOCKED:
  698. if (prSecInfo->fg2nd1xSend)
  699. ;
  700. else
  701. SEC_STATE_TRANSITION(prAdapter, prSta, INITIATOR_PORT_BLOCKED, CHECK_OK);
  702. break;
  703. case SEC_STATE_RESPONDER_PORT_BLOCKED:
  704. SEC_STATE_TRANSITION(prAdapter, prSta, RESPONDER_PORT_BLOCKED, CHECK_OK);
  705. break;
  706. case SEC_STATE_CHECK_OK:
  707. break;
  708. default:
  709. fgStatus = FALSE;
  710. break;
  711. }
  712. if (prSecInfo->eCurrentState != eNextState)
  713. secFsmSteps(prAdapter, prSta, eNextState);
  714. return fgStatus;
  715. } /* end of secFsmRunEventPTKInstalled() */
  716. /*----------------------------------------------------------------------------*/
  717. /*!
  718. * \brief This function will indicate an Event of "Counter Measure" to SEC FSM.
  719. *
  720. * \param[in] prSta Pointer to the Sta record
  721. *
  722. * \return -
  723. */
  724. /*----------------------------------------------------------------------------*/
  725. VOID secFsmEventStartCounterMeasure(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta)
  726. {
  727. P_SEC_INFO_T prSecInfo;
  728. ENUM_SEC_STATE_T eNextState;
  729. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  730. DEBUGFUNC("secFsmRunEventStartCounterMeasure");
  731. ASSERT(prSta);
  732. if (!IS_STA_IN_AIS(prSta)) {
  733. DBGLOG(RSN, INFO, "Counter Measure should occur at AIS network!!\n");
  734. /* ASSERT(0); */
  735. return;
  736. }
  737. prSecInfo = &prSta->rSecInfo;
  738. eNextState = prSecInfo->eCurrentState;
  739. #if DBG
  740. DBGLOG(RSN, TRACE, "%pM Sec state %s\n", prSta->aucMacAddr,
  741. apucDebugSecState[prSecInfo->eCurrentState]);
  742. #else
  743. DBGLOG(RSN, TRACE, "%pM Sec state [%d]\n", prSta->aucMacAddr, prSecInfo->eCurrentState);
  744. #endif
  745. prAdapter->rWifiVar.rAisSpecificBssInfo.u4RsnaLastMICFailTime = 0;
  746. switch (prSecInfo->eCurrentState) {
  747. case SEC_STATE_CHECK_OK:
  748. {
  749. prAdapter->rWifiVar.rAisSpecificBssInfo.fgCounterMeasure = TRUE;
  750. /* <Todo> dls port control */
  751. SEC_STATE_TRANSITION(prAdapter, prSta, CHECK_OK, SEND_EAPOL);
  752. }
  753. break;
  754. default:
  755. break;
  756. }
  757. /* Call arbFsmSteps() when we are going to change ARB STATE */
  758. if (prSecInfo->eCurrentState != eNextState)
  759. secFsmSteps(prAdapter, prSta, eNextState);
  760. return;
  761. } /* secFsmRunEventStartCounterMeasure */
  762. /*----------------------------------------------------------------------------*/
  763. /*!
  764. * \brief This function will indicate an Event of "802.1x EAPoL Tx Done" to Sec FSM.
  765. *
  766. * \param[in] prSta Pointer to the Sta record
  767. *
  768. * \return -
  769. */
  770. /*----------------------------------------------------------------------------*/
  771. VOID
  772. secFsmEventEapolTxDone(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec, IN ENUM_TX_RESULT_CODE_T rTxDoneStatus)
  773. {
  774. P_SEC_INFO_T prSecInfo;
  775. ENUM_SEC_STATE_T eNextState;
  776. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  777. P_AIS_SPECIFIC_BSS_INFO_T prAisBssInfo;
  778. DEBUGFUNC("secFsmRunEventEapolTxDone");
  779. ASSERT(prStaRec);
  780. if (rTxDoneStatus != TX_RESULT_SUCCESS) {
  781. DBGLOG(RSN, INFO, "Error EAPoL fram fail to send!!\n");
  782. /* ASSERT(0); */
  783. return;
  784. }
  785. if (!IS_STA_IN_AIS(prStaRec)) {
  786. DBGLOG(RSN, INFO, "Counter Measure should occur at AIS network!!\n");
  787. /* ASSERT(0); */
  788. return;
  789. }
  790. prAisBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  791. ASSERT(prAisBssInfo);
  792. prSecInfo = &prStaRec->rSecInfo;
  793. eNextState = prSecInfo->eCurrentState;
  794. #if DBG
  795. DBGLOG(RSN, TRACE, "%pM Sec state %s\n", prStaRec->aucMacAddr,
  796. apucDebugSecState[prSecInfo->eCurrentState]);
  797. #else
  798. DBGLOG(RSN, TRACE, "%pM Sec state [%d]\n", prStaRec->aucMacAddr, prSecInfo->eCurrentState);
  799. #endif
  800. switch (prSecInfo->eCurrentState) {
  801. case SEC_STATE_SEND_EAPOL:
  802. if (prAisBssInfo->fgCheckEAPoLTxDone == FALSE)
  803. ASSERT(0);
  804. prAisBssInfo->fgCheckEAPoLTxDone = FALSE;
  805. /* cnmTimerStopTimer(prAdapter, &prAisBssInfo->rRsnaEAPoLReportTimeoutTimer); */
  806. SEC_STATE_TRANSITION(prAdapter, prStaRec, SEND_EAPOL, SEND_DEAUTH);
  807. break;
  808. default:
  809. break;
  810. }
  811. if (prSecInfo->eCurrentState != eNextState)
  812. secFsmSteps(prAdapter, prStaRec, eNextState);
  813. return;
  814. } /* secFsmRunEventEapolTxDone */
  815. /*----------------------------------------------------------------------------*/
  816. /*!
  817. * \brief This function will indicate an Event of "Deauth frame Tx Done" to Sec FSM.
  818. *
  819. * \param[in] pMsduInfo Pointer to the Msdu Info
  820. * \param[in] rStatus The Tx done status
  821. *
  822. * \return -
  823. *
  824. * \note after receive deauth frame, callback function call this
  825. */
  826. /*----------------------------------------------------------------------------*/
  827. VOID
  828. secFsmEventDeauthTxDone(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo, IN ENUM_TX_RESULT_CODE_T rTxDoneStatus)
  829. {
  830. P_STA_RECORD_T prStaRec;
  831. P_SEC_INFO_T prSecInfo;
  832. ENUM_SEC_STATE_T eNextState;
  833. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  834. DEBUGFUNC("secFsmRunEventDeauthTxDone");
  835. ASSERT(prMsduInfo);
  836. prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
  837. ASSERT(prStaRec);
  838. if (!prStaRec)
  839. return;
  840. if (!IS_STA_IN_AIS(prStaRec)) {
  841. DBGLOG(RSN, INFO, "Counter Measure should occur at AIS network!!\n");
  842. /* ASSERT(0); */
  843. return;
  844. }
  845. prSecInfo = (P_SEC_INFO_T) &prStaRec->rSecInfo;
  846. #if DBG
  847. DBGLOG(RSN, TRACE, "%pM Sec state %s\n", prStaRec->aucMacAddr,
  848. apucDebugSecState[prSecInfo->eCurrentState]);
  849. #else
  850. DBGLOG(RSN, TRACE, "%pM Sec state [%d]\n", prStaRec->aucMacAddr, prSecInfo->eCurrentState);
  851. #endif
  852. switch (prSecInfo->eCurrentState) {
  853. case SEC_STATE_SEND_DEAUTH:
  854. DBGLOG(RSN, TRACE, "Set timer %d\n", COUNTER_MEASURE_TIMEOUT_INTERVAL_SEC);
  855. SEC_STATE_TRANSITION(prAdapter, prStaRec, SEND_DEAUTH, COUNTERMEASURE);
  856. break;
  857. default:
  858. ASSERT(0);
  859. break;
  860. }
  861. } /* secFsmRunEventDeauthTxDone */
  862. /*----------------------------------------------------------------------------*/
  863. /*!
  864. * \brief This function will check the eapol error frame fail to send issue.
  865. *
  866. * \param[in] prSta Pointer to the Sta record
  867. *
  868. * \return -
  869. */
  870. /*----------------------------------------------------------------------------*/
  871. VOID secFsmEventEapolTxTimeout(IN P_ADAPTER_T prAdapter, IN ULONG ulParm)
  872. {
  873. P_STA_RECORD_T prStaRec;
  874. DEBUGFUNC("secFsmRunEventEapolTxTimeout");
  875. prStaRec = (P_STA_RECORD_T) ulParm;
  876. ASSERT(prStaRec);
  877. /* Todo:: How to handle the Eapol Error fail to send case? */
  878. ASSERT(0);
  879. return;
  880. } /* secFsmEventEapolTxTimeout */
  881. /*----------------------------------------------------------------------------*/
  882. /*!
  883. * \brief This function will stop the counterMeasure duration.
  884. *
  885. * \param[in] prSta Pointer to the Sta record
  886. *
  887. * \return -
  888. */
  889. /*----------------------------------------------------------------------------*/
  890. VOID secFsmEventEndOfCounterMeasure(IN P_ADAPTER_T prAdapter, ULONG ulParm)
  891. {
  892. P_STA_RECORD_T prSta;
  893. P_SEC_INFO_T prSecInfo;
  894. ENUM_SEC_STATE_T eNextState;
  895. BOOLEAN fgIsTransition = (BOOLEAN) FALSE;
  896. DEBUGFUNC("secFsmRunEventEndOfCounterMeasure");
  897. prSta = (P_STA_RECORD_T) ulParm;
  898. ASSERT(prSta);
  899. if (!IS_STA_IN_AIS(prSta)) {
  900. DBGLOG(RSN, INFO, "Counter Measure should occur at AIS network!!\n");
  901. /* ASSERT(0); */
  902. return;
  903. }
  904. prSecInfo = &prSta->rSecInfo;
  905. eNextState = prSecInfo->eCurrentState;
  906. #if DBG
  907. DBGLOG(RSN, TRACE, "%pM Sec state %s\n", prSta->aucMacAddr,
  908. apucDebugSecState[prSecInfo->eCurrentState]);
  909. #else
  910. DBGLOG(RSN, TRACE, "%pM Sec state [%d]\n", prSta->aucMacAddr, prSecInfo->eCurrentState);
  911. #endif
  912. switch (prSecInfo->eCurrentState) {
  913. case SEC_STATE_SEND_DEAUTH:
  914. {
  915. prAdapter->rWifiVar.rAisSpecificBssInfo.fgCounterMeasure = FALSE;
  916. SEC_STATE_TRANSITION(prAdapter, prSta, COUNTERMEASURE, INIT);
  917. }
  918. break;
  919. default:
  920. ASSERT(0);
  921. }
  922. /* Call arbFsmSteps() when we are going to change ARB STATE */
  923. if (prSecInfo->eCurrentState != eNextState)
  924. secFsmSteps(prAdapter, prSta, eNextState);
  925. } /* end of secFsmRunEventEndOfCounterMeasure */
  926. #endif