auth.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/auth.c#1
  3. */
  4. /*! \file "auth.c"
  5. \brief This file includes the authentication-related functions.
  6. This file includes the authentication-related functions.
  7. */
  8. /*
  9. ** Log: auth.c
  10. **
  11. ** 04 22 2014 eason.tsai
  12. ** [ALPS01511962] [WFD][Case Fail]Device can't connect to another AP successfully after connect to WFD.
  13. ** remove force tx de-auth
  14. **
  15. ** 04 21 2014 eason.tsai
  16. ** [ALPS01511962] [WFD][Case Fail]Device can't connect to another AP successfully after connect to WFD.
  17. **
  18. ** [ALPS01511962] [WFD][Case Fail]Device can't connect to another AP successfully after connect to WFD.
  19. ** deauth retry limit 100ms and force to TX
  20. **
  21. **
  22. ** 08 13 2013 terry.wu
  23. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  24. ** Remove unused code
  25. **
  26. ** 03 12 2013 terry.wu
  27. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  28. ** Update Tx utility function for management frame
  29. **
  30. ** 02 27 2013 yuche.tsai
  31. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  32. ** Add aaa_fsm.c, p2p_ie.c, fix compile warning & error.
  33. **
  34. ** 02 19 2013 cp.wu
  35. ** [BORA00002227] [MT6630 Wi-Fi][Driver] Update for Makefile and HIFSYS modifications
  36. ** take use of GET_BSS_INFO_BY_INDEX() and MAX_BSS_INDEX macros
  37. ** for correctly indexing of BSS-INFO pointers
  38. **
  39. ** 02 06 2013 yuche.tsai
  40. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  41. ** Fix BSS index to BSS Info MACRO
  42. **
  43. ** 01 22 2013 cp.wu
  44. ** [BORA00002253] [MT6630 Wi-Fi][Driver][Firmware] Add NLO and timeout mechanism to SCN module
  45. ** modification for ucBssIndex migration
  46. **
  47. ** 01 07 2013 terry.wu
  48. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  49. ** <saved by Perforce>
  50. ** Fix reassoc req issue
  51. **
  52. ** 09 17 2012 cm.chang
  53. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  54. ** Duplicate source from MT6620 v2.3 driver branch
  55. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  56. *
  57. * 02 13 2012 cp.wu
  58. * NULL
  59. * show error message only instead of raise assertion when
  60. * received authentication frame is carrying illegal parameters.
  61. *
  62. * 11 09 2011 yuche.tsai
  63. * NULL
  64. * Fix a network index & station record index issue when TX deauth frame.
  65. *
  66. * 10 12 2011 wh.su
  67. * [WCXRP00001036] [MT6620 Wi-Fi][Driver][FW] Adding the 802.11w code for MFP
  68. * adding the 802.11w related function and define .
  69. *
  70. * 06 22 2011 yuche.tsai
  71. * NULL
  72. * Fix coding error.
  73. *
  74. * 06 20 2011 yuche.tsai
  75. * [WCXRP00000796] [Volunteer Patch][MT6620][Driver] Add BC deauth frame TX feature.
  76. * BC deauth support.
  77. *
  78. * 04 21 2011 terry.wu
  79. * [WCXRP00000674] [MT6620 Wi-Fi][Driver] Refine AAA authSendAuthFrame
  80. * Add network type parameter to authSendAuthFrame.
  81. *
  82. * 04 15 2011 chinghwa.yu
  83. * [WCXRP00000065] Update BoW design and settings
  84. * Add BOW short range mode.
  85. *
  86. * 02 08 2011 yuche.tsai
  87. * [WCXRP00000245] 1. Invitation Request/Response.
  88. 2. Provision Discovery Request/Response
  89. * 1. Fix Service Disocvery Logical issue.
  90. * 2. Fix a NULL pointer access violation issue when sending deauthentication packet to a class error station.
  91. *
  92. * 01 24 2011 cp.wu
  93. * [WCXRP00000382] [MT6620 Wi-Fi][Driver] Track forwarding packet number with notifying tx thread for serving
  94. * 1. add an extra counter for tracking pending forward frames.
  95. * 2. notify TX service thread as well when there is pending forward frame
  96. * 3. correct build errors leaded by introduction of Wi-Fi direct separation module
  97. *
  98. * 01 21 2011 terry.wu
  99. * [WCXRP00000381] [MT6620 Wi-Fi][Driver] Kernel panic when replying unaccept Auth in AP mode
  100. * In AP mode, use STA_REC_INDEX_NOT_FOUND(0xFE) instead of StaRec index when replying an unaccept Auth frame.
  101. *
  102. * 10 18 2010 cp.wu
  103. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  104. * use definition macro to replace hard-coded constant
  105. *
  106. * 09 03 2010 kevin.huang
  107. * NULL
  108. * Refine #include sequence and solve recursive/nested #include issue
  109. *
  110. * 08 30 2010 cp.wu
  111. * NULL
  112. * eliminate klockwork errors
  113. *
  114. * 08 16 2010 cp.wu
  115. * NULL
  116. * Replace CFG_SUPPORT_BOW by CFG_ENABLE_BT_OVER_WIFI.
  117. * There is no CFG_SUPPORT_BOW in driver domain source.
  118. *
  119. * 08 16 2010 kevin.huang
  120. * NULL
  121. * Refine AAA functions
  122. *
  123. * 08 03 2010 cp.wu
  124. * NULL
  125. * surpress compilation warning.
  126. *
  127. * 07 08 2010 cp.wu
  128. *
  129. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  130. *
  131. * 06 28 2010 cp.wu
  132. * [WPD00003833][MT6620 and MT5931] Driver migration
  133. * send MMPDU in basic rate.
  134. *
  135. * 06 21 2010 cp.wu
  136. * [WPD00003833][MT6620 and MT5931] Driver migration
  137. * specify correct value for management frames.
  138. *
  139. * 06 18 2010 cm.chang
  140. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  141. * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
  142. *
  143. * 06 14 2010 cp.wu
  144. * [WPD00003833][MT6620 and MT5931] Driver migration
  145. * add management dispatching function table.
  146. *
  147. * 06 11 2010 cp.wu
  148. * [WPD00003833][MT6620 and MT5931] Driver migration
  149. * auth.c is migrated.
  150. *
  151. * 05 28 2010 kevin.huang
  152. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  153. * Update authSendDeauthFrame() for correct the value of eNetTypeIndex in MSDU_INFO_T
  154. *
  155. * 05 24 2010 kevin.huang
  156. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  157. * Check Net is active before sending Deauth frame.
  158. *
  159. * 05 24 2010 kevin.huang
  160. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  161. * Refine authSendAuthFrame() for NULL STA_RECORD_T case and minimum deauth interval.
  162. *
  163. * 04 24 2010 cm.chang
  164. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  165. * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
  166. *
  167. * 04 19 2010 kevin.huang
  168. * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
  169. * Add Send Deauth for Class 3 Error and Leave Network Support
  170. *
  171. * 02 23 2010 kevin.huang
  172. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  173. * Fix compile warning
  174. *
  175. * 02 05 2010 kevin.huang
  176. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  177. * Add debug message for abnormal authentication frame from AP
  178. *
  179. * 02 04 2010 kevin.huang
  180. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  181. * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
  182. *
  183. * 01 11 2010 kevin.huang
  184. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  185. * Add Deauth and Disassoc Handler
  186. *
  187. * 01 07 2010 kevin.huang
  188. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  189. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  190. *
  191. * Fix the Debug Label
  192. *
  193. * 12 18 2009 cm.chang
  194. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  195. * .
  196. *
  197. * Dec 7 2009 mtk01461
  198. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  199. * Update the authComposeAuthFrameHeader()
  200. *
  201. * Dec 7 2009 mtk01088
  202. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  203. * adding the send deauth frame function
  204. *
  205. * Dec 3 2009 mtk01461
  206. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  207. * Integrate send Auth with TXM
  208. *
  209. * Nov 24 2009 mtk01461
  210. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  211. * Revise MGMT Handler with Retain Status
  212. *
  213. * Nov 23 2009 mtk01461
  214. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  215. *
  216. */
  217. /*******************************************************************************
  218. * C O M P I L E R F L A G S
  219. ********************************************************************************
  220. */
  221. /*******************************************************************************
  222. * E X T E R N A L R E F E R E N C E S
  223. ********************************************************************************
  224. */
  225. #include "precomp.h"
  226. /*******************************************************************************
  227. * C O N S T A N T S
  228. ********************************************************************************
  229. */
  230. /*******************************************************************************
  231. * D A T A T Y P E S
  232. ********************************************************************************
  233. */
  234. /*******************************************************************************
  235. * P U B L I C D A T A
  236. ********************************************************************************
  237. */
  238. APPEND_IE_ENTRY_T txAuthIETable[] = {
  239. {(ELEM_HDR_LEN + ELEM_MAX_LEN_CHALLENGE_TEXT), authAddIEChallengeText}
  240. };
  241. HANDLE_IE_ENTRY_T rxAuthIETable[] = {
  242. {ELEM_ID_CHALLENGE_TEXT, authHandleIEChallengeText}
  243. };
  244. /*******************************************************************************
  245. * P R I V A T E D A T A
  246. ********************************************************************************
  247. */
  248. /*******************************************************************************
  249. * M A C R O S
  250. ********************************************************************************
  251. */
  252. /*******************************************************************************
  253. * F U N C T I O N D E C L A R A T I O N S
  254. ********************************************************************************
  255. */
  256. /*******************************************************************************
  257. * F U N C T I O N S
  258. ********************************************************************************
  259. */
  260. /*----------------------------------------------------------------------------*/
  261. /*!
  262. * @brief This function will compose the Authentication frame header and fixed fields.
  263. *
  264. * @param[in] pucBuffer Pointer to the frame buffer.
  265. * @param[in] aucPeerMACAddress Given Peer MAC Address.
  266. * @param[in] aucMACAddress Given Our MAC Address.
  267. * @param[in] u2AuthAlgNum Authentication Algorithm Number
  268. * @param[in] u2TransactionSeqNum Transaction Sequence Number
  269. * @param[in] u2StatusCode Status Code
  270. *
  271. * \return (none)
  272. */
  273. /*----------------------------------------------------------------------------*/
  274. __KAL_INLINE__ VOID
  275. authComposeAuthFrameHeaderAndFF(IN PUINT_8 pucBuffer,
  276. IN UINT_8 aucPeerMACAddress[],
  277. IN UINT_8 aucMACAddress[],
  278. IN UINT_16 u2AuthAlgNum, IN UINT_16 u2TransactionSeqNum, IN UINT_16 u2StatusCode)
  279. {
  280. P_WLAN_AUTH_FRAME_T prAuthFrame;
  281. UINT_16 u2FrameCtrl;
  282. ASSERT(pucBuffer);
  283. ASSERT(aucPeerMACAddress);
  284. ASSERT(aucMACAddress);
  285. prAuthFrame = (P_WLAN_AUTH_FRAME_T) pucBuffer;
  286. /* 4 <1> Compose the frame header of the Authentication frame. */
  287. /* Fill the Frame Control field. */
  288. u2FrameCtrl = MAC_FRAME_AUTH;
  289. /* If this frame is the third frame in the shared key authentication
  290. * sequence, it shall be encrypted.
  291. */
  292. if ((u2AuthAlgNum == AUTH_ALGORITHM_NUM_SHARED_KEY) && (u2TransactionSeqNum == AUTH_TRANSACTION_SEQ_3))
  293. u2FrameCtrl |= MASK_FC_PROTECTED_FRAME; /* HW will also detect this bit for applying encryption */
  294. /* WLAN_SET_FIELD_16(&prAuthFrame->u2FrameCtrl, u2FrameCtrl); */
  295. prAuthFrame->u2FrameCtrl = u2FrameCtrl; /* NOTE(Kevin): Optimized for ARM */
  296. /* Fill the DA field with Target BSSID. */
  297. COPY_MAC_ADDR(prAuthFrame->aucDestAddr, aucPeerMACAddress);
  298. /* Fill the SA field with our MAC Address. */
  299. COPY_MAC_ADDR(prAuthFrame->aucSrcAddr, aucMACAddress);
  300. switch (u2TransactionSeqNum) {
  301. case AUTH_TRANSACTION_SEQ_1:
  302. case AUTH_TRANSACTION_SEQ_3:
  303. /* Fill the BSSID field with Target BSSID. */
  304. COPY_MAC_ADDR(prAuthFrame->aucBSSID, aucPeerMACAddress);
  305. break;
  306. case AUTH_TRANSACTION_SEQ_2:
  307. case AUTH_TRANSACTION_SEQ_4:
  308. /* Fill the BSSID field with Current BSSID. */
  309. COPY_MAC_ADDR(prAuthFrame->aucBSSID, aucMACAddress);
  310. break;
  311. default:
  312. ASSERT(0);
  313. }
  314. /* Clear the SEQ/FRAG_NO field. */
  315. prAuthFrame->u2SeqCtrl = 0;
  316. /* 4 <2> Compose the frame body's fixed field part of the Authentication frame. */
  317. /* Fill the Authentication Algorithm Number field. */
  318. /* WLAN_SET_FIELD_16(&prAuthFrame->u2AuthAlgNum, u2AuthAlgNum); */
  319. prAuthFrame->u2AuthAlgNum = u2AuthAlgNum; /* NOTE(Kevin): Optimized for ARM */
  320. /* Fill the Authentication Transaction Sequence Number field. */
  321. /* WLAN_SET_FIELD_16(&prAuthFrame->u2AuthTransSeqNo, u2TransactionSeqNum); */
  322. prAuthFrame->u2AuthTransSeqNo = u2TransactionSeqNum; /* NOTE(Kevin): Optimized for ARM */
  323. /* Fill the Status Code field. */
  324. /* WLAN_SET_FIELD_16(&prAuthFrame->u2StatusCode, u2StatusCode); */
  325. prAuthFrame->u2StatusCode = u2StatusCode; /* NOTE(Kevin): Optimized for ARM */
  326. } /* end of authComposeAuthFrameHeaderAndFF() */
  327. /*----------------------------------------------------------------------------*/
  328. /*!
  329. * @brief This function will append Challenge Text IE to the Authentication frame
  330. *
  331. * @param[in] prMsduInfo Pointer to the composed MSDU_INFO_T.
  332. *
  333. * @return (none)
  334. */
  335. /*----------------------------------------------------------------------------*/
  336. VOID authAddIEChallengeText(IN P_ADAPTER_T prAdapter, IN OUT P_MSDU_INFO_T prMsduInfo)
  337. {
  338. P_WLAN_AUTH_FRAME_T prAuthFrame;
  339. P_STA_RECORD_T prStaRec;
  340. UINT_16 u2TransactionSeqNum;
  341. ASSERT(prMsduInfo);
  342. prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
  343. if (!prStaRec)
  344. return;
  345. ASSERT(prStaRec);
  346. /* For Management, frame header and payload are in a continuous buffer */
  347. prAuthFrame = (P_WLAN_AUTH_FRAME_T) prMsduInfo->prPacket;
  348. WLAN_GET_FIELD_16(&prAuthFrame->u2AuthTransSeqNo, &u2TransactionSeqNum)
  349. /* Only consider SEQ_3 for Challenge Text */
  350. if ((u2TransactionSeqNum == AUTH_TRANSACTION_SEQ_3) &&
  351. (prStaRec->ucAuthAlgNum == AUTH_ALGORITHM_NUM_SHARED_KEY) && (prStaRec->prChallengeText != NULL)) {
  352. COPY_IE(((ULONG) (prMsduInfo->prPacket) + prMsduInfo->u2FrameLength), (prStaRec->prChallengeText));
  353. prMsduInfo->u2FrameLength += IE_SIZE(prStaRec->prChallengeText);
  354. }
  355. return;
  356. } /* end of authAddIEChallengeText() */
  357. #if !CFG_SUPPORT_AAA
  358. /*----------------------------------------------------------------------------*/
  359. /*!
  360. * @brief This function will send the Authenticiation frame
  361. *
  362. * @param[in] prStaRec Pointer to the STA_RECORD_T
  363. * @param[in] u2TransactionSeqNum Transaction Sequence Number
  364. *
  365. * @retval WLAN_STATUS_RESOURCES No available resource for frame composing.
  366. * @retval WLAN_STATUS_SUCCESS Successfully send frame to TX Module
  367. */
  368. /*----------------------------------------------------------------------------*/
  369. WLAN_STATUS authSendAuthFrame(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec, IN UINT_16 u2TransactionSeqNum)
  370. {
  371. P_MSDU_INFO_T prMsduInfo;
  372. P_BSS_INFO_T prBssInfo;
  373. UINT_16 u2EstimatedFrameLen;
  374. UINT_16 u2EstimatedExtraIELen;
  375. UINT_16 u2PayloadLen;
  376. UINT_32 i;
  377. DBGLOG(SAA, LOUD, "Send Auth Frame\n");
  378. ASSERT(prStaRec);
  379. /* 4 <1> Allocate a PKT_INFO_T for Authentication Frame */
  380. /* Init with MGMT Header Length + Length of Fixed Fields */
  381. u2EstimatedFrameLen = (MAC_TX_RESERVED_FIELD +
  382. WLAN_MAC_MGMT_HEADER_LEN +
  383. AUTH_ALGORITHM_NUM_FIELD_LEN +
  384. AUTH_TRANSACTION_SEQENCE_NUM_FIELD_LEN + STATUS_CODE_FIELD_LEN);
  385. /* + Extra IE Length */
  386. u2EstimatedExtraIELen = 0;
  387. for (i = 0; i < sizeof(txAuthIETable) / sizeof(APPEND_IE_ENTRY_T); i++)
  388. u2EstimatedExtraIELen += txAuthIETable[i].u2EstimatedIELen;
  389. u2EstimatedFrameLen += u2EstimatedExtraIELen;
  390. /* Allocate a MSDU_INFO_T */
  391. prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen);
  392. if (prMsduInfo == NULL) {
  393. DBGLOG(SAA, WARN, "No PKT_INFO_T for sending Auth Frame.\n");
  394. return WLAN_STATUS_RESOURCES;
  395. }
  396. /* 4 <2> Compose Authentication Request frame header and fixed fields in MSDU_INfO_T. */
  397. ASSERT(prStaRec->ucBssIndex <= MAX_BSS_INDEX);
  398. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prStaRec->ucBssIndex)
  399. /* Compose Header and some Fixed Fields */
  400. authComposeAuthFrameHeaderAndFF((PUINT_8)
  401. ((UINT_32) (prMsduInfo->prPacket) +
  402. MAC_TX_RESERVED_FIELD), prStaRec->aucMacAddr,
  403. prBssInfo->aucOwnMacAddr, prStaRec->ucAuthAlgNum,
  404. u2TransactionSeqNum, STATUS_CODE_RESERVED);
  405. u2PayloadLen = (AUTH_ALGORITHM_NUM_FIELD_LEN + AUTH_TRANSACTION_SEQENCE_NUM_FIELD_LEN + STATUS_CODE_FIELD_LEN);
  406. /* 4 <3> Update information of MSDU_INFO_T */
  407. TX_SET_MMPDU(prAdapter,
  408. prMsduInfo,
  409. prStaRec->ucBssIndex,
  410. prStaRec->ucIndex,
  411. WLAN_MAC_MGMT_HEADER_LEN,
  412. WLAN_MAC_MGMT_HEADER_LEN + u2PayloadLen, saaFsmRunEventTxDone, MSDU_RATE_MODE_AUTO);
  413. /* 4 <4> Compose IEs in MSDU_INFO_T */
  414. for (i = 0; i < sizeof(txAuthIETable) / sizeof(APPEND_IE_ENTRY_T); i++) {
  415. if (txAuthIETable[i].pfnAppendIE)
  416. txAuthIETable[i].pfnAppendIE(prAdapter, prMsduInfo);
  417. }
  418. /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
  419. nicTxConfigPktControlFlag(prMsduInfo, MSDU_CONTROL_FLAG_FORCE_TX, TRUE);
  420. /* 4 <6> Inform TXM to send this Authentication frame. */
  421. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  422. return WLAN_STATUS_SUCCESS;
  423. } /* end of authSendAuthFrame() */
  424. #else
  425. /*----------------------------------------------------------------------------*/
  426. /*!
  427. * @brief This function will send the Authenticiation frame
  428. *
  429. * @param[in] prStaRec Pointer to the STA_RECORD_T
  430. * @param[in] u2TransactionSeqNum Transaction Sequence Number
  431. *
  432. * @retval WLAN_STATUS_RESOURCES No available resource for frame composing.
  433. * @retval WLAN_STATUS_SUCCESS Successfully send frame to TX Module
  434. */
  435. /*----------------------------------------------------------------------------*/
  436. WLAN_STATUS
  437. authSendAuthFrame(IN P_ADAPTER_T prAdapter,
  438. IN P_STA_RECORD_T prStaRec,
  439. IN UINT_8 ucBssIndex,
  440. IN P_SW_RFB_T prFalseAuthSwRfb, IN UINT_16 u2TransactionSeqNum, IN UINT_16 u2StatusCode)
  441. {
  442. PUINT_8 pucReceiveAddr;
  443. PUINT_8 pucTransmitAddr;
  444. P_MSDU_INFO_T prMsduInfo;
  445. P_BSS_INFO_T prBssInfo;
  446. /*get from input parameter */
  447. /* ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex = NETWORK_TYPE_AIS_INDEX; */
  448. PFN_TX_DONE_HANDLER pfTxDoneHandler = (PFN_TX_DONE_HANDLER) NULL;
  449. UINT_16 u2EstimatedFrameLen;
  450. UINT_16 u2EstimatedExtraIELen;
  451. UINT_16 u2PayloadLen;
  452. UINT_16 ucAuthAlgNum;
  453. UINT_32 i;
  454. DBGLOG(SAA, LOUD, "Send Auth Frame %d, Status Code = %d\n", u2TransactionSeqNum, u2StatusCode);
  455. /* 4 <1> Allocate a PKT_INFO_T for Authentication Frame */
  456. /* Init with MGMT Header Length + Length of Fixed Fields */
  457. u2EstimatedFrameLen = (MAC_TX_RESERVED_FIELD +
  458. WLAN_MAC_MGMT_HEADER_LEN +
  459. AUTH_ALGORITHM_NUM_FIELD_LEN +
  460. AUTH_TRANSACTION_SEQENCE_NUM_FIELD_LEN + STATUS_CODE_FIELD_LEN);
  461. /* + Extra IE Length */
  462. u2EstimatedExtraIELen = 0;
  463. for (i = 0; i < sizeof(txAuthIETable) / sizeof(APPEND_IE_ENTRY_T); i++)
  464. u2EstimatedExtraIELen += txAuthIETable[i].u2EstimatedIELen;
  465. u2EstimatedFrameLen += u2EstimatedExtraIELen;
  466. /* Allocate a MSDU_INFO_T */
  467. prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen);
  468. if (prMsduInfo == NULL) {
  469. DBGLOG(SAA, WARN, "No PKT_INFO_T for sending Auth Frame.\n");
  470. return WLAN_STATUS_RESOURCES;
  471. }
  472. /* 4 <2> Compose Authentication Request frame header and fixed fields in MSDU_INfO_T. */
  473. if (prStaRec) {
  474. ASSERT(prStaRec->ucBssIndex <= MAX_BSS_INDEX);
  475. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prStaRec->ucBssIndex);
  476. pucTransmitAddr = prBssInfo->aucOwnMacAddr;
  477. pucReceiveAddr = prStaRec->aucMacAddr;
  478. ucAuthAlgNum = prStaRec->ucAuthAlgNum;
  479. switch (u2TransactionSeqNum) {
  480. case AUTH_TRANSACTION_SEQ_1:
  481. case AUTH_TRANSACTION_SEQ_3:
  482. pfTxDoneHandler = saaFsmRunEventTxDone;
  483. break;
  484. case AUTH_TRANSACTION_SEQ_2:
  485. case AUTH_TRANSACTION_SEQ_4:
  486. pfTxDoneHandler = aaaFsmRunEventTxDone;
  487. break;
  488. }
  489. } else { /* For Error Status Code */
  490. P_WLAN_AUTH_FRAME_T prFalseAuthFrame;
  491. ASSERT(prFalseAuthSwRfb);
  492. prFalseAuthFrame = (P_WLAN_AUTH_FRAME_T) prFalseAuthSwRfb->pvHeader;
  493. ASSERT(u2StatusCode != STATUS_CODE_SUCCESSFUL);
  494. pucTransmitAddr = prFalseAuthFrame->aucDestAddr;
  495. pucReceiveAddr = prFalseAuthFrame->aucSrcAddr;
  496. ucAuthAlgNum = prFalseAuthFrame->u2AuthAlgNum;
  497. u2TransactionSeqNum = (prFalseAuthFrame->u2AuthTransSeqNo + 1);
  498. }
  499. /* Compose Header and some Fixed Fields */
  500. authComposeAuthFrameHeaderAndFF((PUINT_8)
  501. ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
  502. pucReceiveAddr, pucTransmitAddr, ucAuthAlgNum,
  503. u2TransactionSeqNum, u2StatusCode);
  504. u2PayloadLen = (AUTH_ALGORITHM_NUM_FIELD_LEN + AUTH_TRANSACTION_SEQENCE_NUM_FIELD_LEN + STATUS_CODE_FIELD_LEN);
  505. /* 4 <3> Update information of MSDU_INFO_T */
  506. TX_SET_MMPDU(prAdapter,
  507. prMsduInfo,
  508. ucBssIndex,
  509. (prStaRec != NULL) ? (prStaRec->ucIndex) : (STA_REC_INDEX_NOT_FOUND),
  510. WLAN_MAC_MGMT_HEADER_LEN,
  511. WLAN_MAC_MGMT_HEADER_LEN + u2PayloadLen, pfTxDoneHandler, MSDU_RATE_MODE_AUTO);
  512. if ((ucAuthAlgNum == AUTH_ALGORITHM_NUM_SHARED_KEY) && (u2TransactionSeqNum == AUTH_TRANSACTION_SEQ_3))
  513. nicTxConfigPktOption(prMsduInfo, MSDU_OPT_PROTECTED_FRAME, TRUE);
  514. /* 4 <4> Compose IEs in MSDU_INFO_T */
  515. for (i = 0; i < sizeof(txAuthIETable) / sizeof(APPEND_IE_ENTRY_T); i++) {
  516. if (txAuthIETable[i].pfnAppendIE)
  517. txAuthIETable[i].pfnAppendIE(prAdapter, prMsduInfo);
  518. }
  519. /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
  520. nicTxConfigPktControlFlag(prMsduInfo, MSDU_CONTROL_FLAG_FORCE_TX, TRUE);
  521. /* 4 <6> Inform TXM to send this Authentication frame. */
  522. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  523. return WLAN_STATUS_SUCCESS;
  524. } /* end of authSendAuthFrame() */
  525. #endif /* CFG_SUPPORT_AAA */
  526. /*----------------------------------------------------------------------------*/
  527. /*!
  528. * @brief This function will strictly check the TX Authentication frame for SAA/AAA event
  529. * handling.
  530. *
  531. * @param[in] prMsduInfo Pointer of MSDU_INFO_T
  532. * @param[in] u2TransactionSeqNum Transaction Sequence Number
  533. *
  534. * @retval WLAN_STATUS_FAILURE This is not the frame we should handle at current state.
  535. * @retval WLAN_STATUS_SUCCESS This is the frame we should handle.
  536. */
  537. /*----------------------------------------------------------------------------*/
  538. WLAN_STATUS authCheckTxAuthFrame(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo, IN UINT_16 u2TransactionSeqNum)
  539. {
  540. P_WLAN_AUTH_FRAME_T prAuthFrame;
  541. P_STA_RECORD_T prStaRec;
  542. UINT_16 u2TxFrameCtrl;
  543. UINT_16 u2TxAuthAlgNum;
  544. UINT_16 u2TxTransactionSeqNum;
  545. ASSERT(prMsduInfo);
  546. prAuthFrame = (P_WLAN_AUTH_FRAME_T) (prMsduInfo->prPacket);
  547. ASSERT(prAuthFrame);
  548. prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
  549. ASSERT(prStaRec);
  550. if (!prStaRec)
  551. return WLAN_STATUS_INVALID_PACKET;
  552. /* WLAN_GET_FIELD_16(&prAuthFrame->u2FrameCtrl, &u2TxFrameCtrl) */
  553. u2TxFrameCtrl = prAuthFrame->u2FrameCtrl; /* NOTE(Kevin): Optimized for ARM */
  554. u2TxFrameCtrl &= MASK_FRAME_TYPE;
  555. if (u2TxFrameCtrl != MAC_FRAME_AUTH)
  556. return WLAN_STATUS_FAILURE;
  557. /* WLAN_GET_FIELD_16(&prAuthFrame->u2AuthAlgNum, &u2TxAuthAlgNum) */
  558. u2TxAuthAlgNum = prAuthFrame->u2AuthAlgNum; /* NOTE(Kevin): Optimized for ARM */
  559. if (u2TxAuthAlgNum != (UINT_16) (prStaRec->ucAuthAlgNum))
  560. return WLAN_STATUS_FAILURE;
  561. /* WLAN_GET_FIELD_16(&prAuthFrame->u2AuthTransSeqNo, &u2TxTransactionSeqNum) */
  562. u2TxTransactionSeqNum = prAuthFrame->u2AuthTransSeqNo; /* NOTE(Kevin): Optimized for ARM */
  563. if (u2TxTransactionSeqNum != u2TransactionSeqNum)
  564. return WLAN_STATUS_FAILURE;
  565. return WLAN_STATUS_SUCCESS;
  566. } /* end of authCheckTxAuthFrame() */
  567. /*----------------------------------------------------------------------------*/
  568. /*!
  569. * @brief This function will check the incoming Auth Frame's Transaction Sequence
  570. * Number before delivering it to the corresponding SAA or AAA Module.
  571. *
  572. * @param[in] prSwRfb Pointer to the SW_RFB_T structure.
  573. *
  574. * @retval WLAN_STATUS_SUCCESS Always not retain authentication frames
  575. */
  576. /*----------------------------------------------------------------------------*/
  577. WLAN_STATUS authCheckRxAuthFrameTransSeq(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  578. {
  579. P_WLAN_AUTH_FRAME_T prAuthFrame;
  580. UINT_16 u2RxTransactionSeqNum;
  581. UINT_16 u2MinPayloadLen;
  582. ASSERT(prSwRfb);
  583. /* 4 <1> locate the Authentication Frame. */
  584. prAuthFrame = (P_WLAN_AUTH_FRAME_T) prSwRfb->pvHeader;
  585. /* 4 <2> Parse the Header of Authentication Frame. */
  586. u2MinPayloadLen = (AUTH_ALGORITHM_NUM_FIELD_LEN +
  587. AUTH_TRANSACTION_SEQENCE_NUM_FIELD_LEN + STATUS_CODE_FIELD_LEN);
  588. if ((prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) < u2MinPayloadLen) {
  589. DBGLOG(SAA, WARN, "Rx Auth payload: len[%u] < min expected len[%u]\n",
  590. (prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen), u2MinPayloadLen);
  591. DBGLOG(SAA, WARN, "=== Dump Rx Auth ===\n");
  592. DBGLOG_MEM8(SAA, WARN, prAuthFrame, prSwRfb->u2PacketLen);
  593. return WLAN_STATUS_SUCCESS;
  594. }
  595. /* 4 <3> Parse the Fixed Fields of Authentication Frame Body. */
  596. /* WLAN_GET_FIELD_16(&prAuthFrame->u2AuthTransSeqNo, &u2RxTransactionSeqNum); */
  597. u2RxTransactionSeqNum = prAuthFrame->u2AuthTransSeqNo; /* NOTE(Kevin): Optimized for ARM */
  598. switch (u2RxTransactionSeqNum) {
  599. case AUTH_TRANSACTION_SEQ_2:
  600. case AUTH_TRANSACTION_SEQ_4:
  601. saaFsmRunEventRxAuth(prAdapter, prSwRfb);
  602. break;
  603. case AUTH_TRANSACTION_SEQ_1:
  604. case AUTH_TRANSACTION_SEQ_3:
  605. #if CFG_SUPPORT_AAA
  606. aaaFsmRunEventRxAuth(prAdapter, prSwRfb);
  607. #endif /* CFG_SUPPORT_AAA */
  608. break;
  609. default:
  610. DBGLOG(SAA, WARN,
  611. "Strange Authentication Packet: Auth Trans Seq No = %d, Error Status Code = %d\n",
  612. u2RxTransactionSeqNum, prAuthFrame->u2StatusCode);
  613. break;
  614. }
  615. return WLAN_STATUS_SUCCESS;
  616. } /* end of authCheckRxAuthFrameTransSeq() */
  617. /*----------------------------------------------------------------------------*/
  618. /*!
  619. * @brief This function will validate the incoming Authentication Frame and take
  620. * the status code out.
  621. *
  622. * @param[in] prSwRfb Pointer to SW RFB data structure.
  623. * @param[in] u2TransactionSeqNum Transaction Sequence Number
  624. * @param[out] pu2StatusCode Pointer to store the Status Code from Authentication.
  625. *
  626. * @retval WLAN_STATUS_FAILURE This is not the frame we should handle at current state.
  627. * @retval WLAN_STATUS_SUCCESS This is the frame we should handle.
  628. */
  629. /*----------------------------------------------------------------------------*/
  630. WLAN_STATUS
  631. authCheckRxAuthFrameStatus(IN P_ADAPTER_T prAdapter,
  632. IN P_SW_RFB_T prSwRfb, IN UINT_16 u2TransactionSeqNum, OUT PUINT_16 pu2StatusCode)
  633. {
  634. P_STA_RECORD_T prStaRec;
  635. P_WLAN_AUTH_FRAME_T prAuthFrame;
  636. UINT_16 u2RxAuthAlgNum;
  637. UINT_16 u2RxTransactionSeqNum;
  638. /* UINT_16 u2RxStatusCode; // NOTE(Kevin): Optimized for ARM */
  639. ASSERT(prSwRfb);
  640. ASSERT(pu2StatusCode);
  641. prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
  642. ASSERT(prStaRec);
  643. if (!prStaRec)
  644. return WLAN_STATUS_INVALID_PACKET;
  645. /* 4 <1> locate the Authentication Frame. */
  646. prAuthFrame = (P_WLAN_AUTH_FRAME_T) prSwRfb->pvHeader;
  647. /* 4 <2> Parse the Fixed Fields of Authentication Frame Body. */
  648. /* WLAN_GET_FIELD_16(&prAuthFrame->u2AuthAlgNum, &u2RxAuthAlgNum); */
  649. u2RxAuthAlgNum = prAuthFrame->u2AuthAlgNum; /* NOTE(Kevin): Optimized for ARM */
  650. if (u2RxAuthAlgNum != (UINT_16) prStaRec->ucAuthAlgNum) {
  651. DBGLOG(SAA, WARN, "Discard Auth frame with auth type = %d, current = %d\n",
  652. u2RxAuthAlgNum, prStaRec->ucAuthAlgNum);
  653. *pu2StatusCode = STATUS_CODE_AUTH_ALGORITHM_NOT_SUPPORTED;
  654. return WLAN_STATUS_SUCCESS;
  655. }
  656. /* WLAN_GET_FIELD_16(&prAuthFrame->u2AuthTransSeqNo, &u2RxTransactionSeqNum); */
  657. u2RxTransactionSeqNum = prAuthFrame->u2AuthTransSeqNo; /* NOTE(Kevin): Optimized for ARM */
  658. if (u2RxTransactionSeqNum != u2TransactionSeqNum) {
  659. DBGLOG(SAA, WARN, "Discard Auth frame with Transaction Seq No = %d\n", u2RxTransactionSeqNum);
  660. *pu2StatusCode = STATUS_CODE_AUTH_OUT_OF_SEQ;
  661. return WLAN_STATUS_FAILURE;
  662. }
  663. /* 4 <3> Get the Status code */
  664. /* WLAN_GET_FIELD_16(&prAuthFrame->u2StatusCode, &u2RxStatusCode); */
  665. /* *pu2StatusCode = u2RxStatusCode; */
  666. *pu2StatusCode = prAuthFrame->u2StatusCode; /* NOTE(Kevin): Optimized for ARM */
  667. return WLAN_STATUS_SUCCESS;
  668. } /* end of authCheckRxAuthFrameStatus() */
  669. /*----------------------------------------------------------------------------*/
  670. /*!
  671. * @brief This function will handle the Challenge Text IE from the Authentication frame
  672. *
  673. * @param[in] prSwRfb Pointer to SW RFB data structure.
  674. * @param[in] prIEHdr Pointer to start address of IE
  675. *
  676. * @return (none)
  677. */
  678. /*----------------------------------------------------------------------------*/
  679. VOID authHandleIEChallengeText(P_ADAPTER_T prAdapter, P_SW_RFB_T prSwRfb, P_IE_HDR_T prIEHdr)
  680. {
  681. P_WLAN_AUTH_FRAME_T prAuthFrame;
  682. P_STA_RECORD_T prStaRec;
  683. UINT_16 u2TransactionSeqNum;
  684. ASSERT(prSwRfb);
  685. ASSERT(prIEHdr);
  686. prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
  687. ASSERT(prStaRec);
  688. if (!prStaRec)
  689. return;
  690. /* For Management, frame header and payload are in a continuous buffer */
  691. prAuthFrame = (P_WLAN_AUTH_FRAME_T) prSwRfb->pvHeader;
  692. /* WLAN_GET_FIELD_16(&prAuthFrame->u2AuthTransSeqNo, &u2TransactionSeqNum) */
  693. u2TransactionSeqNum = prAuthFrame->u2AuthTransSeqNo; /* NOTE(Kevin): Optimized for ARM */
  694. /* Only consider SEQ_2 for Challenge Text */
  695. if ((u2TransactionSeqNum == AUTH_TRANSACTION_SEQ_2) &&
  696. (prStaRec->ucAuthAlgNum == AUTH_ALGORITHM_NUM_SHARED_KEY)) {
  697. /* Free previous allocated TCM memory */
  698. if (prStaRec->prChallengeText) {
  699. /* ASSERT(0); */
  700. cnmMemFree(prAdapter, prStaRec->prChallengeText);
  701. prStaRec->prChallengeText = (P_IE_CHALLENGE_TEXT_T) NULL;
  702. }
  703. prStaRec->prChallengeText = cnmMemAlloc(prAdapter, RAM_TYPE_MSG, IE_SIZE(prIEHdr));
  704. if (prStaRec->prChallengeText == NULL)
  705. return;
  706. /* Save the Challenge Text from Auth Seq 2 Frame, before sending Auth Seq 3 Frame */
  707. COPY_IE(prStaRec->prChallengeText, prIEHdr);
  708. }
  709. return;
  710. } /* end of authAddIEChallengeText() */
  711. /*----------------------------------------------------------------------------*/
  712. /*!
  713. * @brief This function will parse and process the incoming Authentication frame.
  714. *
  715. * @param[in] prSwRfb Pointer to SW RFB data structure.
  716. *
  717. * @retval WLAN_STATUS_SUCCESS This is the frame we should handle.
  718. */
  719. /*----------------------------------------------------------------------------*/
  720. WLAN_STATUS authProcessRxAuth2_Auth4Frame(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  721. {
  722. P_WLAN_AUTH_FRAME_T prAuthFrame;
  723. PUINT_8 pucIEsBuffer;
  724. UINT_16 u2IEsLen;
  725. UINT_16 u2Offset;
  726. UINT_8 ucIEID;
  727. UINT_32 i;
  728. ASSERT(prSwRfb);
  729. prAuthFrame = (P_WLAN_AUTH_FRAME_T) prSwRfb->pvHeader;
  730. pucIEsBuffer = &prAuthFrame->aucInfoElem[0];
  731. u2IEsLen = (prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) -
  732. (AUTH_ALGORITHM_NUM_FIELD_LEN + AUTH_TRANSACTION_SEQENCE_NUM_FIELD_LEN + STATUS_CODE_FIELD_LEN);
  733. IE_FOR_EACH(pucIEsBuffer, u2IEsLen, u2Offset) {
  734. ucIEID = IE_ID(pucIEsBuffer);
  735. for (i = 0; i < (sizeof(rxAuthIETable) / sizeof(HANDLE_IE_ENTRY_T)); i++) {
  736. if ((ucIEID == rxAuthIETable[i].ucElemID) && (rxAuthIETable[i].pfnHandleIE != NULL))
  737. rxAuthIETable[i].pfnHandleIE(prAdapter, prSwRfb, (P_IE_HDR_T) pucIEsBuffer);
  738. }
  739. }
  740. return WLAN_STATUS_SUCCESS;
  741. } /* end of authProcessRxAuth2_Auth4Frame() */
  742. /*----------------------------------------------------------------------------*/
  743. /*!
  744. * @brief This function will compose the Deauthentication frame
  745. *
  746. * @param[in] pucBuffer Pointer to the frame buffer.
  747. * @param[in] aucPeerMACAddress Given Peer MAC Address.
  748. * @param[in] aucMACAddress Given Our MAC Address.
  749. * @param[in] u2StatusCode Status Code
  750. *
  751. * @return (none)
  752. */
  753. /*----------------------------------------------------------------------------*/
  754. __KAL_INLINE__ VOID
  755. authComposeDeauthFrameHeaderAndFF(IN PUINT_8 pucBuffer,
  756. IN UINT_8 aucPeerMACAddress[],
  757. IN UINT_8 aucMACAddress[], IN UINT_8 aucBssid[], IN UINT_16 u2ReasonCode)
  758. {
  759. P_WLAN_DEAUTH_FRAME_T prDeauthFrame;
  760. UINT_16 u2FrameCtrl;
  761. ASSERT(pucBuffer);
  762. ASSERT(aucPeerMACAddress);
  763. ASSERT(aucMACAddress);
  764. ASSERT(aucBssid);
  765. prDeauthFrame = (P_WLAN_DEAUTH_FRAME_T) pucBuffer;
  766. /* 4 <1> Compose the frame header of the Deauthentication frame. */
  767. /* Fill the Frame Control field. */
  768. u2FrameCtrl = MAC_FRAME_DEAUTH;
  769. /* WLAN_SET_FIELD_16(&prDeauthFrame->u2FrameCtrl, u2FrameCtrl); */
  770. prDeauthFrame->u2FrameCtrl = u2FrameCtrl; /* NOTE(Kevin): Optimized for ARM */
  771. /* Fill the DA field with Target BSSID. */
  772. COPY_MAC_ADDR(prDeauthFrame->aucDestAddr, aucPeerMACAddress);
  773. /* Fill the SA field with our MAC Address. */
  774. COPY_MAC_ADDR(prDeauthFrame->aucSrcAddr, aucMACAddress);
  775. /* Fill the BSSID field with Target BSSID. */
  776. COPY_MAC_ADDR(prDeauthFrame->aucBSSID, aucBssid);
  777. /* Clear the SEQ/FRAG_NO field(HW won't overide the FRAG_NO, so we need to clear it). */
  778. prDeauthFrame->u2SeqCtrl = 0;
  779. /* 4 <2> Compose the frame body's fixed field part of the Authentication frame. */
  780. /* Fill the Status Code field. */
  781. /* WLAN_SET_FIELD_16(&prDeauthFrame->u2ReasonCode, u2ReasonCode); */
  782. prDeauthFrame->u2ReasonCode = u2ReasonCode; /* NOTE(Kevin): Optimized for ARM */
  783. } /* end of authComposeDeauthFrameHeaderAndFF() */
  784. /*----------------------------------------------------------------------------*/
  785. /*!
  786. * @brief This function will send the Deauthenticiation frame
  787. *
  788. * @param[in] prStaRec Pointer to the STA_RECORD_T
  789. * @param[in] prClassErrSwRfb Pointer to the SW_RFB_T which is Class Error.
  790. * @param[in] u2ReasonCode A reason code to indicate why to leave BSS.
  791. * @param[in] pfTxDoneHandler TX Done call back function
  792. *
  793. * @retval WLAN_STATUS_RESOURCES No available resource for frame composing.
  794. * @retval WLAN_STATUS_SUCCESS Successfully send frame to TX Module
  795. * @retval WLAN_STATUS_FAILURE Didn't send Deauth frame for various reasons.
  796. */
  797. /*----------------------------------------------------------------------------*/
  798. WLAN_STATUS
  799. authSendDeauthFrame(IN P_ADAPTER_T prAdapter,
  800. IN P_BSS_INFO_T prBssInfo,
  801. IN P_STA_RECORD_T prStaRec,
  802. IN P_SW_RFB_T prClassErrSwRfb, IN UINT_16 u2ReasonCode, IN PFN_TX_DONE_HANDLER pfTxDoneHandler)
  803. {
  804. PUINT_8 pucReceiveAddr;
  805. PUINT_8 pucTransmitAddr;
  806. PUINT_8 pucBssid = NULL;
  807. P_MSDU_INFO_T prMsduInfo;
  808. UINT_16 u2EstimatedFrameLen;
  809. P_DEAUTH_INFO_T prDeauthInfo;
  810. OS_SYSTIME rCurrentTime;
  811. INT_32 i4NewEntryIndex, i;
  812. UINT_8 ucStaRecIdx = STA_REC_INDEX_NOT_FOUND;
  813. UINT_8 ucBssIndex = BSS_INFO_NUM;
  814. UINT_8 aucBMC[] = BC_MAC_ADDR;
  815. /* NOTE(Kevin): The best way to reply the Deauth is according to the incoming data
  816. * frame
  817. */
  818. /* 4 <1.1> Find the Receiver Address */
  819. if (prClassErrSwRfb) {
  820. BOOLEAN fgIsAbleToSendDeauth = FALSE;
  821. UINT_16 u2RxFrameCtrl;
  822. P_WLAN_MAC_HEADER_A4_T prWlanMacHeader = NULL;
  823. prWlanMacHeader = (P_WLAN_MAC_HEADER_A4_T) prClassErrSwRfb->pvHeader;
  824. /* WLAN_GET_FIELD_16(&prWlanMacHeader->u2FrameCtrl, &u2RxFrameCtrl); */
  825. u2RxFrameCtrl = prWlanMacHeader->u2FrameCtrl; /* NOTE(Kevin): Optimized for ARM */
  826. /* TODO(Kevin): Currently we won't send Deauth for IBSS node. How about DLS ? */
  827. if ((prWlanMacHeader->u2FrameCtrl & MASK_TO_DS_FROM_DS) == 0)
  828. return WLAN_STATUS_FAILURE;
  829. /* Check if corresponding BSS is able to send Deauth */
  830. for (i = 0; i < BSS_INFO_NUM; i++) {
  831. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, i);
  832. if (IS_NET_ACTIVE(prAdapter, i) &&
  833. (EQUAL_MAC_ADDR(prWlanMacHeader->aucAddr1, prBssInfo->aucOwnMacAddr))) {
  834. fgIsAbleToSendDeauth = TRUE;
  835. ucBssIndex = (UINT_8) i;
  836. break;
  837. }
  838. }
  839. if (!fgIsAbleToSendDeauth)
  840. return WLAN_STATUS_FAILURE;
  841. pucReceiveAddr = prWlanMacHeader->aucAddr2;
  842. } else if (prStaRec) {
  843. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prStaRec->ucBssIndex);
  844. ucStaRecIdx = prStaRec->ucIndex;
  845. ucBssIndex = prBssInfo->ucBssIndex;
  846. pucReceiveAddr = prStaRec->aucMacAddr;
  847. } else if (prBssInfo) {
  848. ucBssIndex = prBssInfo->ucBssIndex;
  849. ucStaRecIdx = STA_REC_INDEX_BMCAST;
  850. pucReceiveAddr = aucBMC;
  851. } else {
  852. DBGLOG(SAA, WARN, "Not to send Deauth, invalid data!\n");
  853. return WLAN_STATUS_INVALID_DATA;
  854. }
  855. /* 4 <1.2> Find Transmitter Address and BSSID. */
  856. pucTransmitAddr = prBssInfo->aucOwnMacAddr;
  857. pucBssid = prBssInfo->aucBSSID;
  858. if (ucStaRecIdx != STA_REC_INDEX_BMCAST) {
  859. /* 4 <2> Check if already send a Deauth frame in MIN_DEAUTH_INTERVAL_MSEC */
  860. GET_CURRENT_SYSTIME(&rCurrentTime);
  861. i4NewEntryIndex = -1;
  862. for (i = 0; i < MAX_DEAUTH_INFO_COUNT; i++) {
  863. prDeauthInfo = &(prAdapter->rWifiVar.arDeauthInfo[i]);
  864. /* For continuously sending Deauth frame, the minimum interval is
  865. * MIN_DEAUTH_INTERVAL_MSEC.
  866. */
  867. if (CHECK_FOR_TIMEOUT(rCurrentTime,
  868. prDeauthInfo->rLastSendTime, MSEC_TO_SYSTIME(MIN_DEAUTH_INTERVAL_MSEC))) {
  869. i4NewEntryIndex = i;
  870. } else if (EQUAL_MAC_ADDR(pucReceiveAddr, prDeauthInfo->aucRxAddr) && (!pfTxDoneHandler)) {
  871. return WLAN_STATUS_FAILURE;
  872. }
  873. }
  874. /* 4 <3> Update information. */
  875. if (i4NewEntryIndex > 0) {
  876. prDeauthInfo = &(prAdapter->rWifiVar.arDeauthInfo[i4NewEntryIndex]);
  877. COPY_MAC_ADDR(prDeauthInfo->aucRxAddr, pucReceiveAddr);
  878. prDeauthInfo->rLastSendTime = rCurrentTime;
  879. } else {
  880. /* NOTE(Kevin): for the case of AP mode, we may encounter this case
  881. * if deauth all the associated clients.
  882. */
  883. DBGLOG(SAA, WARN, "No unused DEAUTH_INFO_T !\n");
  884. }
  885. }
  886. /* 4 <5> Allocate a PKT_INFO_T for Deauthentication Frame */
  887. /* Init with MGMT Header Length + Length of Fixed Fields + IE Length */
  888. u2EstimatedFrameLen = (MAC_TX_RESERVED_FIELD + WLAN_MAC_MGMT_HEADER_LEN + REASON_CODE_FIELD_LEN);
  889. /* Allocate a MSDU_INFO_T */
  890. prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen);
  891. if (prMsduInfo == NULL) {
  892. DBGLOG(SAA, WARN, "No PKT_INFO_T for sending Deauth Request.\n");
  893. return WLAN_STATUS_RESOURCES;
  894. }
  895. /* 4 <6> compose Deauthentication frame header and some fixed fields */
  896. authComposeDeauthFrameHeaderAndFF((PUINT_8)
  897. ((ULONG) (prMsduInfo->prPacket) +
  898. MAC_TX_RESERVED_FIELD), pucReceiveAddr, pucTransmitAddr,
  899. pucBssid, u2ReasonCode);
  900. #if CFG_SUPPORT_802_11W
  901. if (rsnCheckBipKeyInstalled(prAdapter, prStaRec)) {
  902. P_WLAN_DEAUTH_FRAME_T prDeauthFrame;
  903. prDeauthFrame =
  904. (P_WLAN_DEAUTH_FRAME_T) (PUINT_8) ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD);
  905. prDeauthFrame->u2FrameCtrl |= MASK_FC_PROTECTED_FRAME;
  906. }
  907. #endif
  908. nicTxSetPktLifeTime(prMsduInfo, 100);
  909. nicTxSetPktRetryLimit(prMsduInfo, TX_DESC_TX_COUNT_NO_LIMIT);
  910. /* 4 <7> Update information of MSDU_INFO_T */
  911. TX_SET_MMPDU(prAdapter,
  912. prMsduInfo,
  913. ucBssIndex,
  914. ucStaRecIdx,
  915. WLAN_MAC_MGMT_HEADER_LEN,
  916. WLAN_MAC_MGMT_HEADER_LEN + REASON_CODE_FIELD_LEN, pfTxDoneHandler, MSDU_RATE_MODE_AUTO);
  917. #if CFG_SUPPORT_802_11W
  918. if (rsnCheckBipKeyInstalled(prAdapter, prStaRec))
  919. nicTxConfigPktOption(prMsduInfo, MSDU_OPT_PROTECTED_FRAME, TRUE);
  920. #endif
  921. /* 4 <8> Inform TXM to send this Deauthentication frame. */
  922. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  923. return WLAN_STATUS_SUCCESS;
  924. } /* end of authSendDeauthFrame() */
  925. /*----------------------------------------------------------------------------*/
  926. /*!
  927. * @brief This function will parse and process the incoming Deauthentication frame
  928. * if the given BSSID is matched.
  929. *
  930. * @param[in] prSwRfb Pointer to SW RFB data structure.
  931. * @param[in] aucBSSID Given BSSID
  932. * @param[out] pu2ReasonCode Pointer to store the Reason Code from Deauthentication.
  933. *
  934. * @retval WLAN_STATUS_FAILURE This is not the frame we should handle at current state.
  935. * @retval WLAN_STATUS_SUCCESS This is the frame we should handle.
  936. */
  937. /*----------------------------------------------------------------------------*/
  938. WLAN_STATUS authProcessRxDeauthFrame(IN P_SW_RFB_T prSwRfb, IN UINT_8 aucBSSID[], OUT PUINT_16 pu2ReasonCode)
  939. {
  940. P_WLAN_DEAUTH_FRAME_T prDeauthFrame;
  941. UINT_16 u2RxReasonCode;
  942. ASSERT(prSwRfb);
  943. ASSERT(aucBSSID);
  944. ASSERT(pu2ReasonCode);
  945. /* 4 <1> locate the Deauthentication Frame. */
  946. prDeauthFrame = (P_WLAN_DEAUTH_FRAME_T) prSwRfb->pvHeader;
  947. /* 4 <2> Parse the Header of Deauthentication Frame. */
  948. #if 0 /* Kevin: Seems redundant */
  949. WLAN_GET_FIELD_16(&prDeauthFrame->u2FrameCtrl, &u2RxFrameCtrl)
  950. u2RxFrameCtrl &= MASK_FRAME_TYPE;
  951. if (u2RxFrameCtrl != MAC_FRAME_DEAUTH)
  952. return WLAN_STATUS_FAILURE;
  953. #endif
  954. if ((prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) < REASON_CODE_FIELD_LEN) {
  955. ASSERT(0);
  956. return WLAN_STATUS_FAILURE;
  957. }
  958. /* Check if this Deauth Frame is coming from Target BSSID */
  959. if (UNEQUAL_MAC_ADDR(prDeauthFrame->aucBSSID, aucBSSID)) {
  960. DBGLOG(SAA, LOUD, "Ignore Deauth Frame from other BSS [" MACSTR "]\n",
  961. MAC2STR(prDeauthFrame->aucSrcAddr));
  962. return WLAN_STATUS_FAILURE;
  963. }
  964. /* 4 <3> Parse the Fixed Fields of Deauthentication Frame Body. */
  965. WLAN_GET_FIELD_16(&prDeauthFrame->u2ReasonCode, &u2RxReasonCode);
  966. *pu2ReasonCode = u2RxReasonCode;
  967. return WLAN_STATUS_SUCCESS;
  968. } /* end of authProcessRxDeauthFrame() */
  969. /*----------------------------------------------------------------------------*/
  970. /*!
  971. * @brief This function will parse and process the incoming Authentication frame.
  972. *
  973. * @param[in] prSwRfb Pointer to SW RFB data structure.
  974. * @param[in] aucExpectedBSSID Given Expected BSSID.
  975. * @param[in] u2ExpectedAuthAlgNum Given Expected Authentication Algorithm Number
  976. * @param[in] u2ExpectedTransSeqNum Given Expected Transaction Sequence Number.
  977. * @param[out] pu2ReturnStatusCode Return Status Code.
  978. *
  979. * @retval WLAN_STATUS_SUCCESS This is the frame we should handle.
  980. * @retval WLAN_STATUS_FAILURE The frame we will ignore.
  981. */
  982. /*----------------------------------------------------------------------------*/
  983. WLAN_STATUS
  984. authProcessRxAuth1Frame(IN P_ADAPTER_T prAdapter,
  985. IN P_SW_RFB_T prSwRfb,
  986. IN UINT_8 aucExpectedBSSID[],
  987. IN UINT_16 u2ExpectedAuthAlgNum,
  988. IN UINT_16 u2ExpectedTransSeqNum, OUT PUINT_16 pu2ReturnStatusCode)
  989. {
  990. P_WLAN_AUTH_FRAME_T prAuthFrame;
  991. UINT_16 u2ReturnStatusCode = STATUS_CODE_SUCCESSFUL;
  992. ASSERT(prSwRfb);
  993. ASSERT(aucExpectedBSSID);
  994. ASSERT(pu2ReturnStatusCode);
  995. /* 4 <1> locate the Authentication Frame. */
  996. prAuthFrame = (P_WLAN_AUTH_FRAME_T) prSwRfb->pvHeader;
  997. /* 4 <2> Check the BSSID */
  998. if (UNEQUAL_MAC_ADDR(prAuthFrame->aucBSSID, aucExpectedBSSID))
  999. return WLAN_STATUS_FAILURE; /* Just Ignore this MMPDU */
  1000. /* 4 <3> Check the SA, which should not be MC/BC */
  1001. if (prAuthFrame->aucSrcAddr[0] & BIT(0)) {
  1002. DBGLOG(P2P, WARN, "Invalid STA MAC with MC/BC bit set: " MACSTR "\n",
  1003. MAC2STR(prAuthFrame->aucSrcAddr));
  1004. return WLAN_STATUS_FAILURE;
  1005. }
  1006. /* 4 <4> Parse the Fixed Fields of Authentication Frame Body. */
  1007. if (prAuthFrame->u2AuthAlgNum != u2ExpectedAuthAlgNum)
  1008. u2ReturnStatusCode = STATUS_CODE_AUTH_ALGORITHM_NOT_SUPPORTED;
  1009. if (prAuthFrame->u2AuthTransSeqNo != u2ExpectedTransSeqNum)
  1010. u2ReturnStatusCode = STATUS_CODE_AUTH_OUT_OF_SEQ;
  1011. *pu2ReturnStatusCode = u2ReturnStatusCode;
  1012. return WLAN_STATUS_SUCCESS;
  1013. } /* end of authProcessRxAuth1Frame() */