rsn.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/rsn.c#2
  3. */
  4. /*! \file "rsn.c"
  5. \brief This file including the 802.11i, wpa and wpa2(rsn) related function.
  6. This file provided the macros and functions library support the wpa/rsn ie parsing,
  7. cipher and AKM check to help the AP seleced deciding, tkip mic error handler and rsn PMKID support.
  8. */
  9. /*
  10. ** Log: rsn.c
  11. *
  12. * 07 17 2012 yuche.tsai
  13. * NULL
  14. * Compile no error before trial run.
  15. *
  16. * 03 09 2012 chinglan.wang
  17. * NULL
  18. * Fix the condition error.
  19. *
  20. * 03 02 2012 terry.wu
  21. * NULL
  22. * Snc CFG80211 modification for ICS migration from branch 2.2.
  23. *
  24. * 03 02 2012 terry.wu
  25. * NULL
  26. * Sync CFG80211 modification from branch 2,2.
  27. *
  28. * 11 11 2011 wh.su
  29. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  30. * modify the xlog related code.
  31. *
  32. * 11 10 2011 wh.su
  33. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  34. * change the debug module level.
  35. *
  36. * 10 12 2011 wh.su
  37. * [WCXRP00001036] [MT6620 Wi-Fi][Driver][FW] Adding the 802.11w code for MFP
  38. * adding the 802.11w related function and define .
  39. *
  40. * 03 17 2011 chinglan.wang
  41. * [WCXRP00000570] [MT6620 Wi-Fi][Driver] Add Wi-Fi Protected Setup v2.0 feature
  42. * .
  43. *
  44. * 02 09 2011 wh.su
  45. * [WCXRP00000432] [MT6620 Wi-Fi][Driver] Add STA privacy check at hotspot mode
  46. * adding the code for check STA privacy bit at AP mode, .
  47. *
  48. * 12 24 2010 chinglan.wang
  49. * NULL
  50. * [MT6620][Wi-Fi] Modify the key management in the driver for WPS function.
  51. *
  52. * 12 13 2010 cp.wu
  53. * [WCXRP00000260] [MT6620 Wi-Fi][Driver][Firmware] Create V1.1 branch for both firmware and driver
  54. * create branch for Wi-Fi driver v1.1
  55. *
  56. * 11 05 2010 wh.su
  57. * [WCXRP00000165] [MT6620 Wi-Fi] [Pre-authentication] Assoc req rsn ie use wrong pmkid value
  58. * fixed the.pmkid value mismatch issue
  59. *
  60. * 11 03 2010 wh.su
  61. * [WCXRP00000124] [MT6620 Wi-Fi] [Driver] Support the dissolve P2P Group
  62. * Refine the HT rate disallow TKIP pairwise cipher .
  63. *
  64. * 10 04 2010 cp.wu
  65. * [WCXRP00000077] [MT6620 Wi-Fi][Driver][FW] Eliminate use of ENUM_NETWORK_TYPE_T
  66. * and replaced by ENUM_NETWORK_TYPE_INDEX_T only
  67. * remove ENUM_NETWORK_TYPE_T definitions
  68. *
  69. * 09 29 2010 yuche.tsai
  70. * NULL
  71. * Fix compile error, remove unused pointer in rsnGenerateRSNIE().
  72. *
  73. * 09 28 2010 wh.su
  74. * NULL
  75. * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
  76. *
  77. * 09 24 2010 wh.su
  78. * NULL
  79. * [WCXRP00005002][MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning.
  80. *
  81. * 09 06 2010 wh.su
  82. * NULL
  83. * let the p2p can set the privacy bit at beacon and rsn ie at assoc req at key handshake state.
  84. *
  85. * 08 30 2010 wh.su
  86. * NULL
  87. * remove non-used code.
  88. *
  89. * 08 19 2010 wh.su
  90. * NULL
  91. * adding the tx pkt call back handle for countermeasure.
  92. *
  93. * 07 24 2010 wh.su
  94. *
  95. * .support the Wi-Fi RSN
  96. *
  97. * 07 08 2010 cp.wu
  98. *
  99. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  100. *
  101. * 06 21 2010 wh.su
  102. * [WPD00003840][MT6620 5931] Security migration
  103. * modify some code for concurrent network.
  104. *
  105. * 06 21 2010 cp.wu
  106. * [WPD00003833][MT6620 and MT5931] Driver migration
  107. * [WPD00003833][MT6620 and MT5931] Driver migration
  108. * enable RX management frame handling.
  109. *
  110. * 06 19 2010 wh.su
  111. * [WPD00003840][MT6620 5931] Security migration
  112. * consdier the concurrent network setting.
  113. *
  114. * 06 18 2010 wh.su
  115. * [WPD00003840][MT6620 5931] Security migration
  116. * [WPD00003840] [MT6620 5931] Security migration
  117. * migration from firmware.
  118. *
  119. * 05 27 2010 wh.su
  120. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  121. * not indicate pmkid candidate while no new one scanned.
  122. *
  123. * 04 29 2010 wh.su
  124. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  125. * adjsut the pre-authentication code.
  126. *
  127. * 03 03 2010 wh.su
  128. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  129. * move the AIS specific variable for security to AIS specific structure.
  130. *
  131. * 03 03 2010 wh.su
  132. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  133. * Fixed the pre-authentication timer not correctly init issue,
  134. * and modify the security related callback function prototype.
  135. *
  136. * 01 27 2010 wh.su
  137. * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
  138. * add and fixed some security function.
  139. *
  140. * 12 18 2009 cm.chang
  141. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  142. * .
  143. *
  144. * Dec 8 2009 mtk01088
  145. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  146. * change the name
  147. *
  148. * Dec 7 2009 mtk01088
  149. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  150. * using the Rx0 port to indicate event
  151. *
  152. * Dec 4 2009 mtk01088
  153. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  154. * refine the code for generate the WPA/RSN IE for assoc req
  155. *
  156. * Dec 3 2009 mtk01088
  157. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  158. * adjust code for pmkid event
  159. *
  160. * Dec 1 2009 mtk01088
  161. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  162. * adding the code for event (mic error and pmkid indicate) and do some function rename
  163. *
  164. * Nov 23 2009 mtk01088
  165. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  166. * adding some security function
  167. *
  168. * Nov 19 2009 mtk01088
  169. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  170. * adding some security feature, including pmkid
  171. *
  172. * Nov 18 2009 mtk01088
  173. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  174. *
  175. **
  176. */
  177. /*******************************************************************************
  178. * C O M P I L E R F L A G S
  179. ********************************************************************************
  180. */
  181. /*******************************************************************************
  182. * E X T E R N A L R E F E R E N C E S
  183. ********************************************************************************
  184. */
  185. #include "precomp.h"
  186. #if CFG_RSN_MIGRATION
  187. /* extern PHY_ATTRIBUTE_T rPhyAttributes[]; */
  188. /*******************************************************************************
  189. * C O N S T A N T S
  190. ********************************************************************************
  191. */
  192. /*******************************************************************************
  193. * D A T A T Y P E S
  194. ********************************************************************************
  195. */
  196. /*******************************************************************************
  197. * P U B L I C D A T A
  198. ********************************************************************************
  199. */
  200. /*******************************************************************************
  201. * P R I V A T E D A T A
  202. ********************************************************************************
  203. */
  204. /*******************************************************************************
  205. * M A C R O S
  206. ********************************************************************************
  207. */
  208. /*******************************************************************************
  209. * F U N C T I O N D E C L A R A T I O N S
  210. ********************************************************************************
  211. */
  212. /*******************************************************************************
  213. * F U N C T I O N S
  214. ********************************************************************************
  215. */
  216. /*----------------------------------------------------------------------------*/
  217. /*!
  218. * \brief This routine is called to parse RSN IE.
  219. *
  220. * \param[in] prInfoElem Pointer to the RSN IE
  221. * \param[out] prRsnInfo Pointer to the BSSDescription structure to store the
  222. ** RSN information from the given RSN IE
  223. *
  224. * \retval TRUE - Succeeded
  225. * \retval FALSE - Failed
  226. */
  227. /*----------------------------------------------------------------------------*/
  228. BOOLEAN rsnParseRsnIE(IN P_ADAPTER_T prAdapter, IN P_RSN_INFO_ELEM_T prInfoElem, OUT P_RSN_INFO_T prRsnInfo)
  229. {
  230. UINT_32 i;
  231. INT_32 u4RemainRsnIeLen;
  232. UINT_16 u2Version;
  233. UINT_16 u2Cap = 0;
  234. UINT_32 u4GroupSuite = RSN_CIPHER_SUITE_CCMP;
  235. UINT_16 u2PairSuiteCount = 0;
  236. UINT_16 u2AuthSuiteCount = 0;
  237. PUINT_8 pucPairSuite = NULL;
  238. PUINT_8 pucAuthSuite = NULL;
  239. PUINT_8 cp;
  240. DEBUGFUNC("rsnParseRsnIE");
  241. ASSERT(prInfoElem);
  242. ASSERT(prRsnInfo);
  243. /* Verify the length of the RSN IE. */
  244. if (prInfoElem->ucLength < 2) {
  245. DBGLOG(RSN, TRACE, "RSN IE length too short (length=%d)\n", prInfoElem->ucLength);
  246. return FALSE;
  247. }
  248. /* Check RSN version: currently, we only support version 1. */
  249. WLAN_GET_FIELD_16(&prInfoElem->u2Version, &u2Version);
  250. if (u2Version != 1) {
  251. DBGLOG(RSN, TRACE, "Unsupported RSN IE version: %d\n", u2Version);
  252. return FALSE;
  253. }
  254. cp = (PUCHAR) & prInfoElem->u4GroupKeyCipherSuite;
  255. u4RemainRsnIeLen = (INT_32) prInfoElem->ucLength - 2;
  256. do {
  257. if (u4RemainRsnIeLen == 0)
  258. break;
  259. /* Parse the Group Key Cipher Suite field. */
  260. if (u4RemainRsnIeLen < 4) {
  261. DBGLOG(RSN, TRACE, "Fail to parse RSN IE in group cipher suite (IE len: %d)\n",
  262. prInfoElem->ucLength);
  263. return FALSE;
  264. }
  265. WLAN_GET_FIELD_32(cp, &u4GroupSuite);
  266. cp += 4;
  267. u4RemainRsnIeLen -= 4;
  268. if (u4RemainRsnIeLen == 0)
  269. break;
  270. /* Parse the Pairwise Key Cipher Suite Count field. */
  271. if (u4RemainRsnIeLen < 2) {
  272. DBGLOG(RSN, TRACE, "Fail to parse RSN IE in pairwise cipher suite count (IE len: %d)\n",
  273. prInfoElem->ucLength);
  274. return FALSE;
  275. }
  276. WLAN_GET_FIELD_16(cp, &u2PairSuiteCount);
  277. cp += 2;
  278. u4RemainRsnIeLen -= 2;
  279. /* Parse the Pairwise Key Cipher Suite List field. */
  280. i = (UINT_32) u2PairSuiteCount * 4;
  281. if (u4RemainRsnIeLen < (INT_32) i) {
  282. DBGLOG(RSN, TRACE, "Fail to parse RSN IE in pairwise cipher suite list (IE len: %d)\n",
  283. prInfoElem->ucLength);
  284. return FALSE;
  285. }
  286. pucPairSuite = cp;
  287. cp += i;
  288. u4RemainRsnIeLen -= (INT_32) i;
  289. if (u4RemainRsnIeLen == 0)
  290. break;
  291. /* Parse the Authentication and Key Management Cipher Suite Count field. */
  292. if (u4RemainRsnIeLen < 2) {
  293. DBGLOG(RSN, TRACE, "Fail to parse RSN IE in auth & key mgt suite count (IE len: %d)\n",
  294. prInfoElem->ucLength);
  295. return FALSE;
  296. }
  297. WLAN_GET_FIELD_16(cp, &u2AuthSuiteCount);
  298. cp += 2;
  299. u4RemainRsnIeLen -= 2;
  300. /* Parse the Authentication and Key Management Cipher Suite List
  301. field. */
  302. i = (UINT_32) u2AuthSuiteCount * 4;
  303. if (u4RemainRsnIeLen < (INT_32) i) {
  304. DBGLOG(RSN, TRACE, "Fail to parse RSN IE in auth & key mgt suite list (IE len: %d)\n",
  305. prInfoElem->ucLength);
  306. return FALSE;
  307. }
  308. pucAuthSuite = cp;
  309. cp += i;
  310. u4RemainRsnIeLen -= (INT_32) i;
  311. if (u4RemainRsnIeLen == 0)
  312. break;
  313. /* Parse the RSN u2Capabilities field. */
  314. if (u4RemainRsnIeLen < 2) {
  315. DBGLOG(RSN, TRACE, "Fail to parse RSN IE in RSN capabilities (IE len: %d)\n",
  316. prInfoElem->ucLength);
  317. return FALSE;
  318. }
  319. WLAN_GET_FIELD_16(cp, &u2Cap);
  320. } while (FALSE);
  321. /* Save the RSN information for the BSS. */
  322. prRsnInfo->ucElemId = ELEM_ID_RSN;
  323. prRsnInfo->u2Version = u2Version;
  324. prRsnInfo->u4GroupKeyCipherSuite = u4GroupSuite;
  325. DBGLOG(RSN, LOUD, "RSN: version %d, group key cipher suite %02x-%02x-%02x-%02x\n",
  326. u2Version, (UCHAR) (u4GroupSuite & 0x000000FF),
  327. (UCHAR) ((u4GroupSuite >> 8) & 0x000000FF),
  328. (UCHAR) ((u4GroupSuite >> 16) & 0x000000FF), (UCHAR) ((u4GroupSuite >> 24) & 0x000000FF));
  329. if (pucPairSuite) {
  330. /* The information about the pairwise key cipher suites is present. */
  331. if (u2PairSuiteCount > MAX_NUM_SUPPORTED_CIPHER_SUITES)
  332. u2PairSuiteCount = MAX_NUM_SUPPORTED_CIPHER_SUITES;
  333. prRsnInfo->u4PairwiseKeyCipherSuiteCount = (UINT_32) u2PairSuiteCount;
  334. for (i = 0; i < (UINT_32) u2PairSuiteCount; i++) {
  335. WLAN_GET_FIELD_32(pucPairSuite, &prRsnInfo->au4PairwiseKeyCipherSuite[i]);
  336. pucPairSuite += 4;
  337. DBGLOG(RSN, LOUD, "RSN: pairwise key cipher suite [%d]: %02x-%02x-%02x-%02x\n",
  338. (UINT_8) i, (UCHAR) (prRsnInfo->au4PairwiseKeyCipherSuite[i] & 0x000000FF),
  339. (UCHAR) ((prRsnInfo->au4PairwiseKeyCipherSuite[i] >> 8) & 0x000000FF),
  340. (UCHAR) ((prRsnInfo->au4PairwiseKeyCipherSuite[i] >> 16) & 0x000000FF),
  341. (UCHAR) ((prRsnInfo->au4PairwiseKeyCipherSuite[i] >> 24) & 0x000000FF));
  342. }
  343. } else {
  344. /* The information about the pairwise key cipher suites is not present.
  345. Use the default chipher suite for RSN: CCMP. */
  346. prRsnInfo->u4PairwiseKeyCipherSuiteCount = 1;
  347. prRsnInfo->au4PairwiseKeyCipherSuite[0] = RSN_CIPHER_SUITE_CCMP;
  348. DBGLOG(RSN, LOUD, "RSN: pairwise key cipher suite: %02x-%02x-%02x-%02x (default)\n",
  349. (UCHAR) (prRsnInfo->au4PairwiseKeyCipherSuite[0] & 0x000000FF),
  350. (UCHAR) ((prRsnInfo->au4PairwiseKeyCipherSuite[0] >> 8) & 0x000000FF),
  351. (UCHAR) ((prRsnInfo->au4PairwiseKeyCipherSuite[0] >> 16) & 0x000000FF),
  352. (UCHAR) ((prRsnInfo->au4PairwiseKeyCipherSuite[0] >> 24) & 0x000000FF));
  353. }
  354. if (pucAuthSuite) {
  355. /* The information about the authentication and key management suites
  356. is present. */
  357. if (u2AuthSuiteCount > MAX_NUM_SUPPORTED_AKM_SUITES)
  358. u2AuthSuiteCount = MAX_NUM_SUPPORTED_AKM_SUITES;
  359. prRsnInfo->u4AuthKeyMgtSuiteCount = (UINT_32) u2AuthSuiteCount;
  360. for (i = 0; i < (UINT_32) u2AuthSuiteCount; i++) {
  361. WLAN_GET_FIELD_32(pucAuthSuite, &prRsnInfo->au4AuthKeyMgtSuite[i]);
  362. pucAuthSuite += 4;
  363. DBGLOG(RSN, LOUD, "RSN: AKM suite [%d]: %02x-%02x-%02x-%02x\n",
  364. (UINT_8) i, (UCHAR) (prRsnInfo->au4AuthKeyMgtSuite[i] & 0x000000FF),
  365. (UCHAR) ((prRsnInfo->au4AuthKeyMgtSuite[i] >> 8) & 0x000000FF),
  366. (UCHAR) ((prRsnInfo->au4AuthKeyMgtSuite[i] >> 16) & 0x000000FF),
  367. (UCHAR) ((prRsnInfo->au4AuthKeyMgtSuite[i] >> 24) & 0x000000FF));
  368. }
  369. } else {
  370. /* The information about the authentication and key management suites
  371. is not present. Use the default AKM suite for RSN. */
  372. prRsnInfo->u4AuthKeyMgtSuiteCount = 1;
  373. prRsnInfo->au4AuthKeyMgtSuite[0] = RSN_AKM_SUITE_802_1X;
  374. DBGLOG(RSN, LOUD, "RSN: AKM suite: %02x-%02x-%02x-%02x (default)\n",
  375. (UCHAR) (prRsnInfo->au4AuthKeyMgtSuite[0] & 0x000000FF),
  376. (UCHAR) ((prRsnInfo->au4AuthKeyMgtSuite[0] >> 8) & 0x000000FF),
  377. (UCHAR) ((prRsnInfo->au4AuthKeyMgtSuite[0] >> 16) & 0x000000FF),
  378. (UCHAR) ((prRsnInfo->au4AuthKeyMgtSuite[0] >> 24) & 0x000000FF));
  379. }
  380. prRsnInfo->u2RsnCap = u2Cap;
  381. #if CFG_SUPPORT_802_11W
  382. prRsnInfo->fgRsnCapPresent = TRUE;
  383. #endif
  384. DBGLOG(RSN, LOUD, "RSN cap: 0x%04x\n", prRsnInfo->u2RsnCap);
  385. return TRUE;
  386. } /* rsnParseRsnIE */
  387. /*----------------------------------------------------------------------------*/
  388. /*!
  389. * \brief This routine is called to parse WPA IE.
  390. *
  391. * \param[in] prInfoElem Pointer to the WPA IE.
  392. * \param[out] prWpaInfo Pointer to the BSSDescription structure to store the
  393. * WPA information from the given WPA IE.
  394. *
  395. * \retval TRUE Succeeded.
  396. * \retval FALSE Failed.
  397. */
  398. /*----------------------------------------------------------------------------*/
  399. BOOLEAN rsnParseWpaIE(IN P_ADAPTER_T prAdapter, IN P_WPA_INFO_ELEM_T prInfoElem, OUT P_RSN_INFO_T prWpaInfo)
  400. {
  401. UINT_32 i;
  402. INT_32 u4RemainWpaIeLen;
  403. UINT_16 u2Version;
  404. UINT_16 u2Cap = 0;
  405. UINT_32 u4GroupSuite = WPA_CIPHER_SUITE_TKIP;
  406. UINT_16 u2PairSuiteCount = 0;
  407. UINT_16 u2AuthSuiteCount = 0;
  408. PUCHAR pucPairSuite = NULL;
  409. PUCHAR pucAuthSuite = NULL;
  410. PUCHAR cp;
  411. BOOLEAN fgCapPresent = FALSE;
  412. DEBUGFUNC("rsnParseWpaIE");
  413. ASSERT(prInfoElem);
  414. ASSERT(prWpaInfo);
  415. /* Verify the length of the WPA IE. */
  416. if (prInfoElem->ucLength < 6) {
  417. DBGLOG(RSN, TRACE, "WPA IE length too short (length=%d)\n", prInfoElem->ucLength);
  418. return FALSE;
  419. }
  420. /* Check WPA version: currently, we only support version 1. */
  421. WLAN_GET_FIELD_16(&prInfoElem->u2Version, &u2Version);
  422. if (u2Version != 1) {
  423. DBGLOG(RSN, TRACE, "Unsupported WPA IE version: %d\n", u2Version);
  424. return FALSE;
  425. }
  426. cp = (PUCHAR) &prInfoElem->u4GroupKeyCipherSuite;
  427. u4RemainWpaIeLen = (INT_32) prInfoElem->ucLength - 6;
  428. do {
  429. if (u4RemainWpaIeLen == 0)
  430. break;
  431. /* WPA_OUI : 4
  432. Version : 2
  433. GroupSuite : 4
  434. PairwiseCount: 2
  435. PairwiseSuite: 4 * pairSuiteCount
  436. AuthCount : 2
  437. AuthSuite : 4 * authSuiteCount
  438. Cap : 2 */
  439. /* Parse the Group Key Cipher Suite field. */
  440. if (u4RemainWpaIeLen < 4) {
  441. DBGLOG(RSN, TRACE, "Fail to parse WPA IE in group cipher suite (IE len: %d)\n",
  442. prInfoElem->ucLength);
  443. return FALSE;
  444. }
  445. WLAN_GET_FIELD_32(cp, &u4GroupSuite);
  446. cp += 4;
  447. u4RemainWpaIeLen -= 4;
  448. if (u4RemainWpaIeLen == 0)
  449. break;
  450. /* Parse the Pairwise Key Cipher Suite Count field. */
  451. if (u4RemainWpaIeLen < 2) {
  452. DBGLOG(RSN, TRACE, "Fail to parse WPA IE in pairwise cipher suite count (IE len: %d)\n",
  453. prInfoElem->ucLength);
  454. return FALSE;
  455. }
  456. WLAN_GET_FIELD_16(cp, &u2PairSuiteCount);
  457. cp += 2;
  458. u4RemainWpaIeLen -= 2;
  459. /* Parse the Pairwise Key Cipher Suite List field. */
  460. i = (UINT_32) u2PairSuiteCount * 4;
  461. if (u4RemainWpaIeLen < (INT_32) i) {
  462. DBGLOG(RSN, TRACE, "Fail to parse WPA IE in pairwise cipher suite list (IE len: %d)\n",
  463. prInfoElem->ucLength);
  464. return FALSE;
  465. }
  466. pucPairSuite = cp;
  467. cp += i;
  468. u4RemainWpaIeLen -= (INT_32) i;
  469. if (u4RemainWpaIeLen == 0)
  470. break;
  471. /* Parse the Authentication and Key Management Cipher Suite Count
  472. field. */
  473. if (u4RemainWpaIeLen < 2) {
  474. DBGLOG(RSN, TRACE, "Fail to parse WPA IE in auth & key mgt suite count (IE len: %d)\n",
  475. prInfoElem->ucLength);
  476. return FALSE;
  477. }
  478. WLAN_GET_FIELD_16(cp, &u2AuthSuiteCount);
  479. cp += 2;
  480. u4RemainWpaIeLen -= 2;
  481. /* Parse the Authentication and Key Management Cipher Suite List
  482. field. */
  483. i = (UINT_32) u2AuthSuiteCount * 4;
  484. if (u4RemainWpaIeLen < (INT_32) i) {
  485. DBGLOG(RSN, TRACE, "Fail to parse WPA IE in auth & key mgt suite list (IE len: %d)\n",
  486. prInfoElem->ucLength);
  487. return FALSE;
  488. }
  489. pucAuthSuite = cp;
  490. cp += i;
  491. u4RemainWpaIeLen -= (INT_32) i;
  492. if (u4RemainWpaIeLen == 0)
  493. break;
  494. /* Parse the WPA u2Capabilities field. */
  495. if (u4RemainWpaIeLen < 2) {
  496. DBGLOG(RSN, TRACE, "Fail to parse WPA IE in WPA capabilities (IE len: %d)\n",
  497. prInfoElem->ucLength);
  498. return FALSE;
  499. }
  500. fgCapPresent = TRUE;
  501. WLAN_GET_FIELD_16(cp, &u2Cap);
  502. u4RemainWpaIeLen -= 2;
  503. } while (FALSE);
  504. /* Save the WPA information for the BSS. */
  505. prWpaInfo->ucElemId = ELEM_ID_WPA;
  506. prWpaInfo->u2Version = u2Version;
  507. prWpaInfo->u4GroupKeyCipherSuite = u4GroupSuite;
  508. DBGLOG(RSN, LOUD, "WPA: version %d, group key cipher suite %02x-%02x-%02x-%02x\n",
  509. u2Version, (UCHAR) (u4GroupSuite & 0x000000FF),
  510. (UCHAR) ((u4GroupSuite >> 8) & 0x000000FF),
  511. (UCHAR) ((u4GroupSuite >> 16) & 0x000000FF), (UCHAR) ((u4GroupSuite >> 24) & 0x000000FF));
  512. if (pucPairSuite) {
  513. /* The information about the pairwise key cipher suites is present. */
  514. if (u2PairSuiteCount > MAX_NUM_SUPPORTED_CIPHER_SUITES)
  515. u2PairSuiteCount = MAX_NUM_SUPPORTED_CIPHER_SUITES;
  516. prWpaInfo->u4PairwiseKeyCipherSuiteCount = (UINT_32) u2PairSuiteCount;
  517. for (i = 0; i < (UINT_32) u2PairSuiteCount; i++) {
  518. WLAN_GET_FIELD_32(pucPairSuite, &prWpaInfo->au4PairwiseKeyCipherSuite[i]);
  519. pucPairSuite += 4;
  520. DBGLOG(RSN, LOUD, "WPA: pairwise key cipher suite [%d]: %02x-%02x-%02x-%02x\n",
  521. (UINT_8) i, (UCHAR) (prWpaInfo->au4PairwiseKeyCipherSuite[i] & 0x000000FF),
  522. (UCHAR) ((prWpaInfo->au4PairwiseKeyCipherSuite[i] >> 8) & 0x000000FF),
  523. (UCHAR) ((prWpaInfo->au4PairwiseKeyCipherSuite[i] >> 16) & 0x000000FF),
  524. (UCHAR) ((prWpaInfo->au4PairwiseKeyCipherSuite[i] >> 24) & 0x000000FF));
  525. }
  526. } else {
  527. /* The information about the pairwise key cipher suites is not present.
  528. Use the default chipher suite for WPA: TKIP. */
  529. prWpaInfo->u4PairwiseKeyCipherSuiteCount = 1;
  530. prWpaInfo->au4PairwiseKeyCipherSuite[0] = WPA_CIPHER_SUITE_TKIP;
  531. DBGLOG(RSN, LOUD, "WPA: pairwise key cipher suite: %02x-%02x-%02x-%02x (default)\n",
  532. (UCHAR) (prWpaInfo->au4PairwiseKeyCipherSuite[0] & 0x000000FF),
  533. (UCHAR) ((prWpaInfo->au4PairwiseKeyCipherSuite[0] >> 8) & 0x000000FF),
  534. (UCHAR) ((prWpaInfo->au4PairwiseKeyCipherSuite[0] >> 16) & 0x000000FF),
  535. (UCHAR) ((prWpaInfo->au4PairwiseKeyCipherSuite[0] >> 24) & 0x000000FF));
  536. }
  537. if (pucAuthSuite) {
  538. /* The information about the authentication and key management suites
  539. is present. */
  540. if (u2AuthSuiteCount > MAX_NUM_SUPPORTED_AKM_SUITES)
  541. u2AuthSuiteCount = MAX_NUM_SUPPORTED_AKM_SUITES;
  542. prWpaInfo->u4AuthKeyMgtSuiteCount = (UINT_32) u2AuthSuiteCount;
  543. for (i = 0; i < (UINT_32) u2AuthSuiteCount; i++) {
  544. WLAN_GET_FIELD_32(pucAuthSuite, &prWpaInfo->au4AuthKeyMgtSuite[i]);
  545. pucAuthSuite += 4;
  546. DBGLOG(RSN, LOUD, "WPA: AKM suite [%d]: %02x-%02x-%02x-%02x\n",
  547. (UINT_8) i, (UCHAR) (prWpaInfo->au4AuthKeyMgtSuite[i] & 0x000000FF),
  548. (UCHAR) ((prWpaInfo->au4AuthKeyMgtSuite[i] >> 8) & 0x000000FF),
  549. (UCHAR) ((prWpaInfo->au4AuthKeyMgtSuite[i] >> 16) & 0x000000FF),
  550. (UCHAR) ((prWpaInfo->au4AuthKeyMgtSuite[i] >> 24) & 0x000000FF));
  551. }
  552. } else {
  553. /* The information about the authentication and key management suites
  554. is not present. Use the default AKM suite for WPA. */
  555. prWpaInfo->u4AuthKeyMgtSuiteCount = 1;
  556. prWpaInfo->au4AuthKeyMgtSuite[0] = WPA_AKM_SUITE_802_1X;
  557. DBGLOG(RSN, LOUD, "WPA: AKM suite: %02x-%02x-%02x-%02x (default)\n",
  558. (UCHAR) (prWpaInfo->au4AuthKeyMgtSuite[0] & 0x000000FF),
  559. (UCHAR) ((prWpaInfo->au4AuthKeyMgtSuite[0] >> 8) & 0x000000FF),
  560. (UCHAR) ((prWpaInfo->au4AuthKeyMgtSuite[0] >> 16) & 0x000000FF),
  561. (UCHAR) ((prWpaInfo->au4AuthKeyMgtSuite[0] >> 24) & 0x000000FF));
  562. }
  563. if (fgCapPresent) {
  564. prWpaInfo->fgRsnCapPresent = TRUE;
  565. prWpaInfo->u2RsnCap = u2Cap;
  566. DBGLOG(RSN, LOUD, "WPA: RSN cap: 0x%04x\n", prWpaInfo->u2RsnCap);
  567. } else {
  568. prWpaInfo->fgRsnCapPresent = FALSE;
  569. prWpaInfo->u2RsnCap = 0;
  570. }
  571. return TRUE;
  572. } /* rsnParseWpaIE */
  573. /*----------------------------------------------------------------------------*/
  574. /*!
  575. * \brief This routine is called to search the desired pairwise
  576. * cipher suite from the MIB Pairwise Cipher Suite
  577. * configuration table.
  578. *
  579. * \param[in] u4Cipher The desired pairwise cipher suite to be searched
  580. * \param[out] pu4Index Pointer to the index of the desired pairwise cipher in
  581. * the table
  582. *
  583. * \retval TRUE - The desired pairwise cipher suite is found in the table.
  584. * \retval FALSE - The desired pairwise cipher suite is not found in the
  585. * table.
  586. */
  587. /*----------------------------------------------------------------------------*/
  588. BOOLEAN rsnSearchSupportedCipher(IN P_ADAPTER_T prAdapter, IN UINT_32 u4Cipher, OUT PUINT_32 pu4Index)
  589. {
  590. UINT_8 i;
  591. P_DOT11_RSNA_CONFIG_PAIRWISE_CIPHERS_ENTRY prEntry;
  592. DEBUGFUNC("rsnSearchSupportedCipher");
  593. ASSERT(pu4Index);
  594. for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++) {
  595. prEntry = &prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[i];
  596. if (prEntry->dot11RSNAConfigPairwiseCipher == u4Cipher &&
  597. prEntry->dot11RSNAConfigPairwiseCipherEnabled) {
  598. *pu4Index = i;
  599. return TRUE;
  600. }
  601. }
  602. return FALSE;
  603. } /* rsnSearchSupportedCipher */
  604. /*----------------------------------------------------------------------------*/
  605. /*!
  606. * \brief Whether BSS RSN is matched from upper layer set.
  607. *
  608. * \param[in] prAdapter Pointer to the Adapter structure, BSS RSN Information
  609. *
  610. * \retval BOOLEAN
  611. */
  612. /*----------------------------------------------------------------------------*/
  613. BOOLEAN rsnIsSuitableBSS(IN P_ADAPTER_T prAdapter, IN P_RSN_INFO_T prBssRsnInfo)
  614. {
  615. UINT_8 i = 0;
  616. DEBUGFUNC("rsnIsSuitableBSS");
  617. do {
  618. if ((prAdapter->rWifiVar.rConnSettings.rRsnInfo.u4GroupKeyCipherSuite & 0x000000FF) !=
  619. GET_SELECTOR_TYPE(prBssRsnInfo->u4GroupKeyCipherSuite)) {
  620. DBGLOG(RSN, TRACE, "Break by GroupKeyCipherSuite\n");
  621. break;
  622. }
  623. for (i = 0; i < prBssRsnInfo->u4PairwiseKeyCipherSuiteCount; i++) {
  624. if (((prAdapter->rWifiVar.rConnSettings.rRsnInfo.au4PairwiseKeyCipherSuite[0] & 0x000000FF) !=
  625. GET_SELECTOR_TYPE(prBssRsnInfo->au4PairwiseKeyCipherSuite[i]))
  626. && (i == prBssRsnInfo->u4PairwiseKeyCipherSuiteCount - 1)) {
  627. DBGLOG(RSN, TRACE, "Break by PairwiseKeyCipherSuite\n");
  628. break;
  629. }
  630. }
  631. for (i = 0; i < prBssRsnInfo->u4AuthKeyMgtSuiteCount; i++) {
  632. if (((prAdapter->rWifiVar.rConnSettings.rRsnInfo.au4AuthKeyMgtSuite[0] & 0x000000FF) !=
  633. GET_SELECTOR_TYPE(prBssRsnInfo->au4AuthKeyMgtSuite[0]))
  634. && (i == prBssRsnInfo->u4AuthKeyMgtSuiteCount - 1)) {
  635. DBGLOG(RSN, TRACE, "Break by AuthKeyMgtSuite\n");
  636. break;
  637. }
  638. }
  639. return TRUE;
  640. } while (FALSE);
  641. return FALSE;
  642. }
  643. /*----------------------------------------------------------------------------*/
  644. /*!
  645. *
  646. * \brief This routine is called to search the desired
  647. * authentication and key management (AKM) suite from the
  648. * MIB Authentication and Key Management Suites table.
  649. *
  650. * \param[in] u4AkmSuite The desired AKM suite to be searched
  651. * \param[out] pu4Index Pointer to the index of the desired AKM suite in the
  652. * table
  653. *
  654. * \retval TRUE The desired AKM suite is found in the table.
  655. * \retval FALSE The desired AKM suite is not found in the table.
  656. *
  657. * \note
  658. */
  659. /*----------------------------------------------------------------------------*/
  660. BOOLEAN rsnSearchAKMSuite(IN P_ADAPTER_T prAdapter, IN UINT_32 u4AkmSuite, OUT PUINT_32 pu4Index)
  661. {
  662. UINT_8 i;
  663. P_DOT11_RSNA_CONFIG_AUTHENTICATION_SUITES_ENTRY prEntry;
  664. DEBUGFUNC("rsnSearchAKMSuite");
  665. ASSERT(pu4Index);
  666. for (i = 0; i < MAX_NUM_SUPPORTED_AKM_SUITES; i++) {
  667. prEntry = &prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[i];
  668. if (prEntry->dot11RSNAConfigAuthenticationSuite == u4AkmSuite &&
  669. prEntry->dot11RSNAConfigAuthenticationSuiteEnabled) {
  670. *pu4Index = i;
  671. return TRUE;
  672. }
  673. }
  674. return FALSE;
  675. } /* rsnSearchAKMSuite */
  676. /*----------------------------------------------------------------------------*/
  677. /*!
  678. * \brief This routine is called to perform RSNA or TSN policy
  679. * selection for a given BSS.
  680. *
  681. * \param[in] prBss Pointer to the BSS description
  682. *
  683. * \retval TRUE - The RSNA/TSN policy selection for the given BSS is
  684. * successful. The selected pairwise and group cipher suites
  685. * are returned in the BSS description.
  686. * \retval FALSE - The RSNA/TSN policy selection for the given BSS is failed.
  687. * The driver shall not attempt to join the given BSS.
  688. *
  689. * \note The Encrypt status matched score will save to bss for final ap select.
  690. */
  691. /*----------------------------------------------------------------------------*/
  692. BOOLEAN rsnPerformPolicySelection(IN P_ADAPTER_T prAdapter, IN P_BSS_DESC_T prBss)
  693. {
  694. #if CFG_SUPPORT_802_11W
  695. INT_32 i;
  696. UINT_32 j;
  697. #else
  698. UINT_32 i, j;
  699. #endif
  700. BOOLEAN fgSuiteSupported;
  701. UINT_32 u4PairwiseCipher = 0;
  702. UINT_32 u4GroupCipher = 0;
  703. UINT_32 u4AkmSuite = 0;
  704. P_RSN_INFO_T prBssRsnInfo;
  705. ENUM_NETWORK_TYPE_INDEX_T eNetwotkType;
  706. BOOLEAN fgIsWpsActive = (BOOLEAN) FALSE;
  707. DEBUGFUNC("rsnPerformPolicySelection");
  708. ASSERT(prBss);
  709. DBGLOG(RSN, TRACE, "rsnPerformPolicySelection\n");
  710. /* Todo:: */
  711. eNetwotkType = NETWORK_TYPE_AIS_INDEX;
  712. prBss->u4RsnSelectedPairwiseCipher = 0;
  713. prBss->u4RsnSelectedGroupCipher = 0;
  714. prBss->u4RsnSelectedAKMSuite = 0;
  715. prBss->ucEncLevel = 0;
  716. #if CFG_SUPPORT_WPS
  717. fgIsWpsActive = kalWSCGetActiveState(prAdapter->prGlueInfo);
  718. /* CR1640, disable the AP select privacy check */
  719. if (fgIsWpsActive &&
  720. (prAdapter->rWifiVar.rConnSettings.eAuthMode < AUTH_MODE_WPA) &&
  721. (prAdapter->rWifiVar.rConnSettings.eOPMode == NET_TYPE_INFRA)) {
  722. DBGLOG(RSN, TRACE, "-- Skip the Protected BSS check\n");
  723. return TRUE;
  724. }
  725. #endif
  726. /* Protection is not required in this BSS. */
  727. if ((prBss->u2CapInfo & CAP_INFO_PRIVACY) == 0) {
  728. if (secEnabledInAis(prAdapter) == FALSE) {
  729. DBGLOG(RSN, TRACE, "-- No Protected BSS\n");
  730. return TRUE;
  731. }
  732. DBGLOG(RSN, TRACE, "-- Protected BSS\n");
  733. return FALSE;
  734. }
  735. /* Protection is required in this BSS. */
  736. if ((prBss->u2CapInfo & CAP_INFO_PRIVACY) != 0) {
  737. if (secEnabledInAis(prAdapter) == FALSE) {
  738. DBGLOG(RSN, TRACE, "-- Protected BSS\n");
  739. return FALSE;
  740. }
  741. }
  742. if (prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA ||
  743. prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA_PSK ||
  744. prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA_NONE) {
  745. if (prBss->fgIEWPA) {
  746. prBssRsnInfo = &prBss->rWPAInfo;
  747. } else {
  748. DBGLOG(RSN, TRACE, "WPA Information Element does not exist.\n");
  749. return FALSE;
  750. }
  751. } else if (prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA2 ||
  752. prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA2_PSK) {
  753. if (prBss->fgIERSN) {
  754. prBssRsnInfo = &prBss->rRSNInfo;
  755. } else {
  756. DBGLOG(RSN, TRACE, "RSN Information Element does not exist.\n");
  757. return FALSE;
  758. }
  759. } else if (prAdapter->rWifiVar.rConnSettings.eEncStatus != ENUM_ENCRYPTION1_ENABLED) {
  760. /* If the driver is configured to use WEP only, ignore this BSS. */
  761. DBGLOG(RSN, TRACE, "-- Not WEP-only legacy BSS %d\n", prAdapter->rWifiVar.rConnSettings.eEncStatus);
  762. return FALSE;
  763. } else if (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION1_ENABLED) {
  764. /* If the driver is configured to use WEP only, use this BSS. */
  765. DBGLOG(RSN, TRACE, "-- WEP-only legacy BSS, fgIERSN %d, fgIEWPA %d\n",
  766. prBss->fgIERSN, prBss->fgIEWPA);
  767. /* if this BSS was configured to WPA/WPA2, don't select this AP */
  768. return (prBss->fgIERSN || prBss->fgIEWPA) ? FALSE : TRUE;
  769. }
  770. if (!rsnIsSuitableBSS(prAdapter, prBssRsnInfo)) {
  771. DBGLOG(RSN, TRACE, "RSN info check no matched\n");
  772. return FALSE;
  773. }
  774. if (prBssRsnInfo->u4PairwiseKeyCipherSuiteCount == 1 &&
  775. GET_SELECTOR_TYPE(prBssRsnInfo->au4PairwiseKeyCipherSuite[0]) == CIPHER_SUITE_NONE) {
  776. /* Since the pairwise cipher use the same cipher suite as the group
  777. cipher in the BSS, we check the group cipher suite against the
  778. current encryption status. */
  779. fgSuiteSupported = FALSE;
  780. switch (prBssRsnInfo->u4GroupKeyCipherSuite) {
  781. case WPA_CIPHER_SUITE_CCMP:
  782. case RSN_CIPHER_SUITE_CCMP:
  783. if (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION3_ENABLED)
  784. fgSuiteSupported = TRUE;
  785. break;
  786. case WPA_CIPHER_SUITE_TKIP:
  787. case RSN_CIPHER_SUITE_TKIP:
  788. if (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION2_ENABLED)
  789. fgSuiteSupported = TRUE;
  790. break;
  791. case WPA_CIPHER_SUITE_WEP40:
  792. case WPA_CIPHER_SUITE_WEP104:
  793. if (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION1_ENABLED)
  794. fgSuiteSupported = TRUE;
  795. break;
  796. }
  797. if (fgSuiteSupported) {
  798. u4PairwiseCipher = WPA_CIPHER_SUITE_NONE;
  799. u4GroupCipher = prBssRsnInfo->u4GroupKeyCipherSuite;
  800. }
  801. #if DBG
  802. else {
  803. DBGLOG(RSN, TRACE, "Inproper encryption status %d for group-key-only BSS\n",
  804. prAdapter->rWifiVar.rConnSettings.eEncStatus);
  805. }
  806. #endif
  807. } else {
  808. fgSuiteSupported = FALSE;
  809. DBGLOG(RSN, TRACE, "eEncStatus %d %d 0x%x\n", prAdapter->rWifiVar.rConnSettings.eEncStatus,
  810. (UINT_32) prBssRsnInfo->u4PairwiseKeyCipherSuiteCount,
  811. (UINT_32) prBssRsnInfo->au4PairwiseKeyCipherSuite[0]);
  812. /* Select pairwise/group ciphers */
  813. switch (prAdapter->rWifiVar.rConnSettings.eEncStatus) {
  814. case ENUM_ENCRYPTION3_ENABLED:
  815. for (i = 0; i < prBssRsnInfo->u4PairwiseKeyCipherSuiteCount; i++) {
  816. if (GET_SELECTOR_TYPE(prBssRsnInfo->au4PairwiseKeyCipherSuite[i])
  817. == CIPHER_SUITE_CCMP) {
  818. u4PairwiseCipher = prBssRsnInfo->au4PairwiseKeyCipherSuite[i];
  819. }
  820. }
  821. u4GroupCipher = prBssRsnInfo->u4GroupKeyCipherSuite;
  822. break;
  823. case ENUM_ENCRYPTION2_ENABLED:
  824. for (i = 0; i < prBssRsnInfo->u4PairwiseKeyCipherSuiteCount; i++) {
  825. if (GET_SELECTOR_TYPE(prBssRsnInfo->au4PairwiseKeyCipherSuite[i])
  826. == CIPHER_SUITE_TKIP) {
  827. u4PairwiseCipher = prBssRsnInfo->au4PairwiseKeyCipherSuite[i];
  828. }
  829. }
  830. if (GET_SELECTOR_TYPE(prBssRsnInfo->u4GroupKeyCipherSuite) == CIPHER_SUITE_CCMP)
  831. DBGLOG(RSN, TRACE, "Cannot join CCMP BSS\n");
  832. else
  833. u4GroupCipher = prBssRsnInfo->u4GroupKeyCipherSuite;
  834. break;
  835. case ENUM_ENCRYPTION1_ENABLED:
  836. for (i = 0; i < prBssRsnInfo->u4PairwiseKeyCipherSuiteCount; i++) {
  837. if (GET_SELECTOR_TYPE(prBssRsnInfo->au4PairwiseKeyCipherSuite[i])
  838. == CIPHER_SUITE_WEP40 ||
  839. GET_SELECTOR_TYPE(prBssRsnInfo->au4PairwiseKeyCipherSuite[i])
  840. == CIPHER_SUITE_WEP104) {
  841. u4PairwiseCipher = prBssRsnInfo->au4PairwiseKeyCipherSuite[i];
  842. }
  843. }
  844. if (GET_SELECTOR_TYPE(prBssRsnInfo->u4GroupKeyCipherSuite) ==
  845. CIPHER_SUITE_CCMP ||
  846. GET_SELECTOR_TYPE(prBssRsnInfo->u4GroupKeyCipherSuite) == CIPHER_SUITE_TKIP) {
  847. DBGLOG(RSN, TRACE, "Cannot join CCMP/TKIP BSS\n");
  848. } else {
  849. u4GroupCipher = prBssRsnInfo->u4GroupKeyCipherSuite;
  850. }
  851. break;
  852. default:
  853. break;
  854. }
  855. }
  856. /* Exception handler */
  857. /* If we cannot find proper pairwise and group cipher suites to join the
  858. BSS, do not check the supported AKM suites. */
  859. if (u4PairwiseCipher == 0 || u4GroupCipher == 0) {
  860. DBGLOG(RSN, TRACE, "Failed to select pairwise/group cipher (0x%08x/0x%08x)\n",
  861. u4PairwiseCipher, u4GroupCipher);
  862. return FALSE;
  863. }
  864. #if CFG_ENABLE_WIFI_DIRECT
  865. if ((prAdapter->fgIsP2PRegistered) && (eNetwotkType == NETWORK_TYPE_P2P_INDEX)) {
  866. if (u4PairwiseCipher != RSN_CIPHER_SUITE_CCMP ||
  867. u4GroupCipher != RSN_CIPHER_SUITE_CCMP || u4AkmSuite != RSN_AKM_SUITE_PSK) {
  868. DBGLOG(RSN, TRACE, "Failed to select pairwise/group cipher for P2P network (0x%08x/0x%08x)\n",
  869. u4PairwiseCipher, u4GroupCipher);
  870. return FALSE;
  871. }
  872. }
  873. #endif
  874. #if CFG_ENABLE_BT_OVER_WIFI
  875. if (eNetwotkType == NETWORK_TYPE_BOW_INDEX) {
  876. if (u4PairwiseCipher != RSN_CIPHER_SUITE_CCMP ||
  877. u4GroupCipher != RSN_CIPHER_SUITE_CCMP || u4AkmSuite != RSN_AKM_SUITE_PSK) {
  878. /* Do nothing */
  879. }
  880. DBGLOG(RSN, TRACE,
  881. "Failed to select pairwise/group cipher for BT over Wi-Fi network (0x%08x/0x%08x)\n",
  882. u4PairwiseCipher, u4GroupCipher);
  883. return FALSE;
  884. }
  885. #endif
  886. /* Verify if selected pairwisse cipher is supported */
  887. fgSuiteSupported = rsnSearchSupportedCipher(prAdapter, u4PairwiseCipher, &i);
  888. /* Verify if selected group cipher is supported */
  889. if (fgSuiteSupported)
  890. fgSuiteSupported = rsnSearchSupportedCipher(prAdapter, u4GroupCipher, &i);
  891. if (!fgSuiteSupported) {
  892. DBGLOG(RSN, TRACE, "Failed to support selected pairwise/group cipher (0x%08x/0x%08x)\n",
  893. u4PairwiseCipher, u4GroupCipher);
  894. return FALSE;
  895. }
  896. /* Select AKM */
  897. /* If the driver cannot support any authentication suites advertised in
  898. the given BSS, we fail to perform RSNA policy selection. */
  899. /* Attempt to find any overlapping supported AKM suite. */
  900. #if CFG_SUPPORT_802_11W
  901. if (i != 0)
  902. for (i = (prBssRsnInfo->u4AuthKeyMgtSuiteCount - 1); i >= 0; i--) {
  903. #else
  904. for (i = 0; i < prBssRsnInfo->u4AuthKeyMgtSuiteCount; i++) {
  905. #endif
  906. if (rsnSearchAKMSuite(prAdapter, prBssRsnInfo->au4AuthKeyMgtSuite[i], &j)) {
  907. u4AkmSuite = prBssRsnInfo->au4AuthKeyMgtSuite[i];
  908. break;
  909. }
  910. }
  911. if (u4AkmSuite == 0) {
  912. DBGLOG(RSN, TRACE, "Cannot support any AKM suites\n");
  913. return FALSE;
  914. }
  915. DBGLOG(RSN, TRACE, "Selected pairwise/group cipher: %02x-%02x-%02x-%02x/%02x-%02x-%02x-%02x\n",
  916. (UINT_8) (u4PairwiseCipher & 0x000000FF),
  917. (UINT_8) ((u4PairwiseCipher >> 8) & 0x000000FF),
  918. (UINT_8) ((u4PairwiseCipher >> 16) & 0x000000FF),
  919. (UINT_8) ((u4PairwiseCipher >> 24) & 0x000000FF),
  920. (UINT_8) (u4GroupCipher & 0x000000FF),
  921. (UINT_8) ((u4GroupCipher >> 8) & 0x000000FF),
  922. (UINT_8) ((u4GroupCipher >> 16) & 0x000000FF),
  923. (UINT_8) ((u4GroupCipher >> 24) & 0x000000FF));
  924. DBGLOG(RSN, TRACE, "Selected AKM suite: %02x-%02x-%02x-%02x\n",
  925. (UINT_8) (u4AkmSuite & 0x000000FF),
  926. (UINT_8) ((u4AkmSuite >> 8) & 0x000000FF),
  927. (UINT_8) ((u4AkmSuite >> 16) & 0x000000FF), (UINT_8) ((u4AkmSuite >> 24) & 0x000000FF));
  928. #if CFG_SUPPORT_802_11W
  929. DBGLOG(RSN, TRACE, "MFP setting = %d\n ", kalGetMfpSetting(prAdapter->prGlueInfo));
  930. if (kalGetMfpSetting(prAdapter->prGlueInfo) == RSN_AUTH_MFP_REQUIRED) {
  931. if (!prBssRsnInfo->fgRsnCapPresent) {
  932. DBGLOG(RSN, TRACE, "Skip RSN IE, No MFP Required Capability.\n");
  933. return FALSE;
  934. } else if (!(prBssRsnInfo->u2RsnCap & ELEM_WPA_CAP_MFPC)) {
  935. DBGLOG(RSN, TRACE, "Skip RSN IE, No MFP Required\n");
  936. return FALSE;
  937. }
  938. prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection = TRUE;
  939. } else if (kalGetMfpSetting(prAdapter->prGlueInfo) == RSN_AUTH_MFP_OPTIONAL) {
  940. if (prBssRsnInfo->u2RsnCap && ((prBssRsnInfo->u2RsnCap & ELEM_WPA_CAP_MFPR) ||
  941. (prBssRsnInfo->u2RsnCap & ELEM_WPA_CAP_MFPC))) {
  942. prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection = TRUE;
  943. } else {
  944. prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection = FALSE;
  945. }
  946. } else {
  947. if (prBssRsnInfo->fgRsnCapPresent && (prBssRsnInfo->u2RsnCap & ELEM_WPA_CAP_MFPR)) {
  948. DBGLOG(RSN, TRACE, "Skip RSN IE, No MFP Required Capability\n");
  949. return FALSE;
  950. }
  951. prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection = FALSE;
  952. }
  953. DBGLOG(RSN, TRACE, "fgMgmtProtection = %d\n ", prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection);
  954. #endif
  955. if (GET_SELECTOR_TYPE(u4GroupCipher) == CIPHER_SUITE_CCMP) {
  956. prBss->ucEncLevel = 3;
  957. } else if (GET_SELECTOR_TYPE(u4GroupCipher) == CIPHER_SUITE_TKIP) {
  958. prBss->ucEncLevel = 2;
  959. } else if (GET_SELECTOR_TYPE(u4GroupCipher) == CIPHER_SUITE_WEP40 ||
  960. GET_SELECTOR_TYPE(u4GroupCipher) == CIPHER_SUITE_WEP104) {
  961. prBss->ucEncLevel = 1;
  962. } else {
  963. ASSERT(FALSE);
  964. }
  965. prBss->u4RsnSelectedPairwiseCipher = u4PairwiseCipher;
  966. prBss->u4RsnSelectedGroupCipher = u4GroupCipher;
  967. prBss->u4RsnSelectedAKMSuite = u4AkmSuite;
  968. return TRUE;
  969. } /* rsnPerformPolicySelection */
  970. /*----------------------------------------------------------------------------*/
  971. /*!
  972. * \brief This routine is called to generate WPA IE for beacon frame.
  973. *
  974. * \param[in] pucIeStartAddr Pointer to put the generated WPA IE.
  975. *
  976. * \return The append WPA-None IE length
  977. * \note
  978. * Called by: JOIN module, compose beacon IE
  979. */
  980. /*----------------------------------------------------------------------------*/
  981. VOID rsnGenerateWpaNoneIE(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo)
  982. {
  983. UINT_32 i;
  984. P_WPA_INFO_ELEM_T prWpaIE;
  985. UINT_32 u4Suite;
  986. UINT_16 u2SuiteCount;
  987. PUINT_8 cp, cp2;
  988. UINT_8 ucExpendedLen = 0;
  989. PUINT_8 pucBuffer;
  990. ENUM_NETWORK_TYPE_INDEX_T eNetworkId;
  991. DEBUGFUNC("rsnGenerateWpaNoneIE");
  992. ASSERT(prMsduInfo);
  993. if (prAdapter->rWifiVar.rConnSettings.eAuthMode != AUTH_MODE_WPA_NONE)
  994. return;
  995. eNetworkId = (ENUM_NETWORK_TYPE_INDEX_T) prMsduInfo->ucNetworkType;
  996. if (eNetworkId != NETWORK_TYPE_AIS_INDEX)
  997. return;
  998. pucBuffer = (PUINT_8) ((ULONG) prMsduInfo->prPacket + (UINT_32) prMsduInfo->u2FrameLength);
  999. ASSERT(pucBuffer);
  1000. prWpaIE = (P_WPA_INFO_ELEM_T) (pucBuffer);
  1001. /* Start to construct a WPA IE. */
  1002. /* Fill the Element ID field. */
  1003. prWpaIE->ucElemId = ELEM_ID_WPA;
  1004. /* Fill the OUI and OUI Type fields. */
  1005. prWpaIE->aucOui[0] = 0x00;
  1006. prWpaIE->aucOui[1] = 0x50;
  1007. prWpaIE->aucOui[2] = 0xF2;
  1008. prWpaIE->ucOuiType = VENDOR_OUI_TYPE_WPA;
  1009. /* Fill the Version field. */
  1010. WLAN_SET_FIELD_16(&prWpaIE->u2Version, 1); /* version 1 */
  1011. ucExpendedLen = 6;
  1012. /* Fill the Pairwise Key Cipher Suite List field. */
  1013. u2SuiteCount = 0;
  1014. cp = (PUINT_8) &prWpaIE->aucPairwiseKeyCipherSuite1[0];
  1015. if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_CCMP, &i))
  1016. u4Suite = WPA_CIPHER_SUITE_CCMP;
  1017. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_TKIP, &i))
  1018. u4Suite = WPA_CIPHER_SUITE_TKIP;
  1019. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP104, &i))
  1020. u4Suite = WPA_CIPHER_SUITE_WEP104;
  1021. else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP40, &i))
  1022. u4Suite = WPA_CIPHER_SUITE_WEP40;
  1023. else
  1024. u4Suite = WPA_CIPHER_SUITE_TKIP;
  1025. WLAN_SET_FIELD_32(cp, u4Suite);
  1026. u2SuiteCount++;
  1027. ucExpendedLen += 4;
  1028. cp += 4;
  1029. /* Fill the Group Key Cipher Suite field as the same in pair-wise key. */
  1030. WLAN_SET_FIELD_32(&prWpaIE->u4GroupKeyCipherSuite, u4Suite);
  1031. ucExpendedLen += 4;
  1032. /* Fill the Pairwise Key Cipher Suite Count field. */
  1033. WLAN_SET_FIELD_16(&prWpaIE->u2PairwiseKeyCipherSuiteCount, u2SuiteCount);
  1034. ucExpendedLen += 2;
  1035. cp2 = cp;
  1036. /* Fill the Authentication and Key Management Suite List field. */
  1037. u2SuiteCount = 0;
  1038. cp += 2;
  1039. if (rsnSearchAKMSuite(prAdapter, WPA_AKM_SUITE_802_1X, &i))
  1040. u4Suite = WPA_AKM_SUITE_802_1X;
  1041. else if (rsnSearchAKMSuite(prAdapter, WPA_AKM_SUITE_PSK, &i))
  1042. u4Suite = WPA_AKM_SUITE_PSK;
  1043. else
  1044. u4Suite = WPA_AKM_SUITE_NONE;
  1045. /* This shall be the only available value for current implementation */
  1046. ASSERT(u4Suite == WPA_AKM_SUITE_NONE);
  1047. WLAN_SET_FIELD_32(cp, u4Suite);
  1048. u2SuiteCount++;
  1049. ucExpendedLen += 4;
  1050. cp += 4;
  1051. /* Fill the Authentication and Key Management Suite Count field. */
  1052. WLAN_SET_FIELD_16(cp2, u2SuiteCount);
  1053. ucExpendedLen += 2;
  1054. /* Fill the Length field. */
  1055. prWpaIE->ucLength = (UINT_8) ucExpendedLen;
  1056. /* Increment the total IE length for the Element ID and Length fields. */
  1057. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  1058. } /* rsnGenerateWpaNoneIE */
  1059. /*----------------------------------------------------------------------------*/
  1060. /*!
  1061. *
  1062. * \brief This routine is called to generate WPA IE for
  1063. * associate request frame.
  1064. *
  1065. * \param[in] prCurrentBss The Selected BSS description
  1066. *
  1067. * \retval The append WPA IE length
  1068. *
  1069. * \note
  1070. * Called by: AIS module, Associate request
  1071. */
  1072. /*----------------------------------------------------------------------------*/
  1073. VOID rsnGenerateWPAIE(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo)
  1074. {
  1075. PUCHAR cp;
  1076. PUINT_8 pucBuffer;
  1077. ENUM_NETWORK_TYPE_INDEX_T eNetworkId;
  1078. P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo;
  1079. DEBUGFUNC("rsnGenerateWPAIE");
  1080. ASSERT(prMsduInfo);
  1081. pucBuffer = (PUINT_8) ((ULONG) prMsduInfo->prPacket + (UINT_32) prMsduInfo->u2FrameLength);
  1082. ASSERT(pucBuffer);
  1083. eNetworkId = (ENUM_NETWORK_TYPE_INDEX_T) prMsduInfo->ucNetworkType;
  1084. prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
  1085. /* if (eNetworkId != NETWORK_TYPE_AIS_INDEX) */
  1086. /* return; */
  1087. #if CFG_ENABLE_WIFI_DIRECT
  1088. if ((1 /* prCurrentBss->fgIEWPA */ &&
  1089. ((prAdapter->fgIsP2PRegistered) &&
  1090. (eNetworkId == NETWORK_TYPE_P2P_INDEX) &&
  1091. (kalP2PGetTkipCipher(prAdapter->prGlueInfo)))) ||
  1092. ((prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA) ||
  1093. (prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA_PSK))) {
  1094. #else
  1095. if ((1 /* prCurrentBss->fgIEWPA */ &&
  1096. ((prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA) ||
  1097. (prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA_PSK)))) {
  1098. #endif
  1099. if (prP2pSpecificBssInfo->u2WpaIeLen != 0) {
  1100. kalMemCopy(pucBuffer, prP2pSpecificBssInfo->aucWpaIeBuffer, prP2pSpecificBssInfo->u2WpaIeLen);
  1101. prMsduInfo->u2FrameLength += prP2pSpecificBssInfo->u2WpaIeLen;
  1102. return;
  1103. }
  1104. /* Construct a WPA IE for association request frame. */
  1105. WPA_IE(pucBuffer)->ucElemId = ELEM_ID_WPA;
  1106. WPA_IE(pucBuffer)->ucLength = ELEM_ID_WPA_LEN_FIXED;
  1107. WPA_IE(pucBuffer)->aucOui[0] = 0x00;
  1108. WPA_IE(pucBuffer)->aucOui[1] = 0x50;
  1109. WPA_IE(pucBuffer)->aucOui[2] = 0xF2;
  1110. WPA_IE(pucBuffer)->ucOuiType = VENDOR_OUI_TYPE_WPA;
  1111. WLAN_SET_FIELD_16(&WPA_IE(pucBuffer)->u2Version, 1);
  1112. #if CFG_ENABLE_WIFI_DIRECT
  1113. if (prAdapter->fgIsP2PRegistered && eNetworkId == NETWORK_TYPE_P2P_INDEX) {
  1114. WLAN_SET_FIELD_32(&WPA_IE(pucBuffer)->u4GroupKeyCipherSuite, WPA_CIPHER_SUITE_TKIP);
  1115. } else
  1116. #endif
  1117. WLAN_SET_FIELD_32(&WPA_IE(pucBuffer)->u4GroupKeyCipherSuite,
  1118. prAdapter->rWifiVar.
  1119. arBssInfo[NETWORK_TYPE_AIS_INDEX].u4RsnSelectedGroupCipher);
  1120. cp = (PUCHAR) &WPA_IE(pucBuffer)->aucPairwiseKeyCipherSuite1[0];
  1121. WLAN_SET_FIELD_16(&WPA_IE(pucBuffer)->u2PairwiseKeyCipherSuiteCount, 1);
  1122. #if CFG_ENABLE_WIFI_DIRECT
  1123. if (prAdapter->fgIsP2PRegistered && eNetworkId == NETWORK_TYPE_P2P_INDEX) {
  1124. WLAN_SET_FIELD_32(cp, WPA_CIPHER_SUITE_TKIP);
  1125. } else
  1126. #endif
  1127. WLAN_SET_FIELD_32(cp,
  1128. prAdapter->rWifiVar.
  1129. arBssInfo[NETWORK_TYPE_AIS_INDEX].u4RsnSelectedPairwiseCipher);
  1130. cp += 4;
  1131. WLAN_SET_FIELD_16(cp, 1);
  1132. cp += 2;
  1133. #if CFG_ENABLE_WIFI_DIRECT
  1134. if (prAdapter->fgIsP2PRegistered && eNetworkId == NETWORK_TYPE_P2P_INDEX) {
  1135. WLAN_SET_FIELD_32(cp, WPA_AKM_SUITE_PSK);
  1136. } else
  1137. #endif
  1138. WLAN_SET_FIELD_32(cp,
  1139. prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX].u4RsnSelectedAKMSuite);
  1140. cp += 4;
  1141. WPA_IE(pucBuffer)->ucLength = ELEM_ID_WPA_LEN_FIXED;
  1142. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  1143. }
  1144. } /* rsnGenerateWPAIE */
  1145. /*----------------------------------------------------------------------------*/
  1146. /*!
  1147. *
  1148. * \brief This routine is called to generate RSN IE for
  1149. * associate request frame.
  1150. *
  1151. * \param[in] prMsduInfo The Selected BSS description
  1152. *
  1153. * \retval The append RSN IE length
  1154. *
  1155. * \note
  1156. * Called by: AIS module, P2P module, BOW module Associate request
  1157. */
  1158. /*----------------------------------------------------------------------------*/
  1159. VOID rsnGenerateRSNIE(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo)
  1160. {
  1161. UINT_32 u4Entry;
  1162. PUCHAR cp;
  1163. /* UINT_8 ucExpendedLen = 0; */
  1164. PUINT_8 pucBuffer;
  1165. ENUM_NETWORK_TYPE_INDEX_T eNetworkId;
  1166. P_STA_RECORD_T prStaRec;
  1167. DEBUGFUNC("rsnGenerateRSNIE");
  1168. ASSERT(prMsduInfo);
  1169. pucBuffer = (PUINT_8) ((ULONG) prMsduInfo->prPacket + (UINT_32) prMsduInfo->u2FrameLength);
  1170. ASSERT(pucBuffer);
  1171. /* Todo:: network id */
  1172. eNetworkId = (ENUM_NETWORK_TYPE_INDEX_T) prMsduInfo->ucNetworkType;
  1173. if (
  1174. #if CFG_ENABLE_WIFI_DIRECT
  1175. ((prAdapter->fgIsP2PRegistered) &&
  1176. (eNetworkId == NETWORK_TYPE_P2P_INDEX) && (kalP2PGetCcmpCipher(prAdapter->prGlueInfo))) ||
  1177. #endif
  1178. #if CFG_ENABLE_BT_OVER_WIFI
  1179. (eNetworkId == NETWORK_TYPE_BOW_INDEX) ||
  1180. #endif
  1181. (eNetworkId == NETWORK_TYPE_AIS_INDEX /* prCurrentBss->fgIERSN */ &&
  1182. ((prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA2) ||
  1183. (prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA2_PSK)))) {
  1184. /* Construct a RSN IE for association request frame. */
  1185. RSN_IE(pucBuffer)->ucElemId = ELEM_ID_RSN;
  1186. RSN_IE(pucBuffer)->ucLength = ELEM_ID_RSN_LEN_FIXED;
  1187. WLAN_SET_FIELD_16(&RSN_IE(pucBuffer)->u2Version, 1); /* Version */
  1188. WLAN_SET_FIELD_32(&RSN_IE(pucBuffer)->u4GroupKeyCipherSuite,
  1189. prAdapter->rWifiVar.arBssInfo[eNetworkId].u4RsnSelectedGroupCipher); /* Group key suite */
  1190. cp = (PUCHAR) &RSN_IE(pucBuffer)->aucPairwiseKeyCipherSuite1[0];
  1191. WLAN_SET_FIELD_16(&RSN_IE(pucBuffer)->u2PairwiseKeyCipherSuiteCount, 1);
  1192. WLAN_SET_FIELD_32(cp, prAdapter->rWifiVar.arBssInfo[eNetworkId].u4RsnSelectedPairwiseCipher);
  1193. cp += 4;
  1194. WLAN_SET_FIELD_16(cp, 1); /* AKM suite count */
  1195. cp += 2;
  1196. WLAN_SET_FIELD_32(cp, prAdapter->rWifiVar.arBssInfo[eNetworkId].u4RsnSelectedAKMSuite); /* AKM suite */
  1197. cp += 4;
  1198. WLAN_SET_FIELD_16(cp, prAdapter->rWifiVar.arBssInfo[eNetworkId].u2RsnSelectedCapInfo);/* Capabilities */
  1199. #if CFG_SUPPORT_802_11W
  1200. if (eNetworkId == NETWORK_TYPE_AIS_INDEX && prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection) {
  1201. if (kalGetMfpSetting(prAdapter->prGlueInfo) == RSN_AUTH_MFP_REQUIRED)
  1202. WLAN_SET_FIELD_16(cp, ELEM_WPA_CAP_MFPC | ELEM_WPA_CAP_MFPR); /* Capabilities */
  1203. else if (kalGetMfpSetting(prAdapter->prGlueInfo) == RSN_AUTH_MFP_OPTIONAL)
  1204. WLAN_SET_FIELD_16(cp, ELEM_WPA_CAP_MFPC); /* Capabilities */
  1205. }
  1206. #endif
  1207. cp += 2;
  1208. if (eNetworkId == NETWORK_TYPE_AIS_INDEX) {
  1209. prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
  1210. if (!prStaRec) {
  1211. DBGLOG(RSN, TRACE, "rsnGenerateRSNIE: prStaRec is NULL\n");
  1212. return;
  1213. }
  1214. }
  1215. if (eNetworkId == NETWORK_TYPE_AIS_INDEX &&
  1216. rsnSearchPmkidEntry(prAdapter, prStaRec->aucMacAddr, &u4Entry)) {
  1217. /* DBGLOG(RSN, TRACE, ("Add Pmk at assoc req\n")); */
  1218. /* DBGLOG(RSN, TRACE, ("addr %pM PMKID %pM\n", */
  1219. /* (prAdapter->rWifiVar.rAisSpecificBssInfo.arPmkidCache[u4Entry].rBssidInfo.arBSSID),*/
  1220. /* (prAdapter->rWifiVar.rAisSpecificBssInfo.arPmkidCache[u4Entry].rBssidInfo.arPMKID))); */
  1221. if (prAdapter->rWifiVar.rAisSpecificBssInfo.arPmkidCache[u4Entry].fgPmkidExist) {
  1222. RSN_IE(pucBuffer)->ucLength = 38;
  1223. WLAN_SET_FIELD_16(cp, 1); /* PMKID count */
  1224. cp += 2;
  1225. DBGLOG(RSN, TRACE,
  1226. "BSSID %pM ind=%d\n", prStaRec->aucMacAddr, (UINT_32) u4Entry);
  1227. DBGLOG(RSN, TRACE, "use PMKID %pM\n",
  1228. (prAdapter->rWifiVar.rAisSpecificBssInfo.
  1229. arPmkidCache[u4Entry].rBssidInfo.arPMKID));
  1230. kalMemCopy(cp,
  1231. (PVOID) prAdapter->rWifiVar.rAisSpecificBssInfo.
  1232. arPmkidCache[u4Entry].rBssidInfo.arPMKID, sizeof(PARAM_PMKID_VALUE));
  1233. /* ucExpendedLen = 40; */
  1234. } else {
  1235. WLAN_SET_FIELD_16(cp, 0); /* PMKID count */
  1236. /* ucExpendedLen = ELEM_ID_RSN_LEN_FIXED + 2; */
  1237. #if CFG_SUPPORT_802_11W
  1238. cp += 2;
  1239. RSN_IE(pucBuffer)->ucLength += 2;
  1240. #endif
  1241. }
  1242. } else {
  1243. WLAN_SET_FIELD_16(cp, 0); /* PMKID count */
  1244. /* ucExpendedLen = ELEM_ID_RSN_LEN_FIXED + 2; */
  1245. #if CFG_SUPPORT_802_11W
  1246. cp += 2;
  1247. RSN_IE(pucBuffer)->ucLength += 2;
  1248. #endif
  1249. }
  1250. #if CFG_SUPPORT_802_11W
  1251. if ((eNetworkId == NETWORK_TYPE_AIS_INDEX)
  1252. && (kalGetMfpSetting(prAdapter->prGlueInfo) !=
  1253. RSN_AUTH_MFP_DISABLED) /* (mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC) */) {
  1254. WLAN_SET_FIELD_32(cp, RSN_CIPHER_SUITE_AES_128_CMAC);
  1255. cp += 4;
  1256. RSN_IE(pucBuffer)->ucLength += 4;
  1257. }
  1258. #endif
  1259. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  1260. }
  1261. } /* rsnGenerateRSNIE */
  1262. /*----------------------------------------------------------------------------*/
  1263. /*!
  1264. * \brief Parse the given IE buffer and check if it is WFA IE and return Type and
  1265. * SubType for further process.
  1266. *
  1267. * \param[in] pucBuf Pointer to the buffer of WFA Information Element.
  1268. * \param[out] pucOuiType Pointer to the storage of OUI Type.
  1269. * \param[out] pu2SubTypeVersion Pointer to the storage of OUI SubType and Version.
  1270. * \retval TRUE Parse IE ok
  1271. * \retval FALSE Parse IE fail
  1272. */
  1273. /*----------------------------------------------------------------------------*/
  1274. BOOLEAN
  1275. rsnParseCheckForWFAInfoElem(IN P_ADAPTER_T prAdapter,
  1276. IN PUINT_8 pucBuf, OUT PUINT_8 pucOuiType, OUT PUINT_16 pu2SubTypeVersion)
  1277. {
  1278. UINT_8 aucWfaOui[] = VENDOR_OUI_WFA;
  1279. P_IE_WFA_T prWfaIE;
  1280. ASSERT(pucBuf);
  1281. ASSERT(pucOuiType);
  1282. ASSERT(pu2SubTypeVersion);
  1283. prWfaIE = (P_IE_WFA_T) pucBuf;
  1284. do {
  1285. if (IE_LEN(pucBuf) <= ELEM_MIN_LEN_WFA_OUI_TYPE_SUBTYPE) {
  1286. break;
  1287. } else if (prWfaIE->aucOui[0] != aucWfaOui[0] ||
  1288. prWfaIE->aucOui[1] != aucWfaOui[1] || prWfaIE->aucOui[2] != aucWfaOui[2]) {
  1289. break;
  1290. }
  1291. *pucOuiType = prWfaIE->ucOuiType;
  1292. WLAN_GET_FIELD_16(&prWfaIE->aucOuiSubTypeVersion[0], pu2SubTypeVersion);
  1293. return TRUE;
  1294. } while (FALSE);
  1295. return FALSE;
  1296. } /* end of rsnParseCheckForWFAInfoElem() */
  1297. #if CFG_SUPPORT_AAA
  1298. /*----------------------------------------------------------------------------*/
  1299. /*!
  1300. * \brief Parse the given IE buffer and check if it is RSN IE with CCMP PSK
  1301. *
  1302. * \param[in] prAdapter Pointer to Adapter
  1303. * \param[in] prSwRfb Pointer to the rx buffer
  1304. * \param[in] pIE Pointer rthe buffer of Information Element.
  1305. * \param[out] prStatusCode Pointer to the return status code.
  1306. * \retval none
  1307. */
  1308. /*----------------------------------------------------------------------------*/
  1309. void rsnParserCheckForRSNCCMPPSK(P_ADAPTER_T prAdapter, P_RSN_INFO_ELEM_T prIe, PUINT_16 pu2StatusCode)
  1310. {
  1311. RSN_INFO_T rRsnIe;
  1312. ASSERT(prAdapter);
  1313. ASSERT(prIe);
  1314. ASSERT(pu2StatusCode);
  1315. *pu2StatusCode = STATUS_CODE_INVALID_INFO_ELEMENT;
  1316. if (rsnParseRsnIE(prAdapter, prIe, &rRsnIe)) {
  1317. if ((rRsnIe.u4PairwiseKeyCipherSuiteCount != 1)
  1318. || (rRsnIe.au4PairwiseKeyCipherSuite[0] != RSN_CIPHER_SUITE_CCMP)) {
  1319. *pu2StatusCode = STATUS_CODE_INVALID_PAIRWISE_CIPHER;
  1320. return;
  1321. }
  1322. if (rRsnIe.u4GroupKeyCipherSuite != RSN_CIPHER_SUITE_CCMP) {
  1323. *pu2StatusCode = STATUS_CODE_INVALID_GROUP_CIPHER;
  1324. return;
  1325. }
  1326. if ((rRsnIe.u4AuthKeyMgtSuiteCount != 1) || (rRsnIe.au4AuthKeyMgtSuite[0] != RSN_AKM_SUITE_PSK)) {
  1327. *pu2StatusCode = STATUS_CODE_INVALID_AKMP;
  1328. return;
  1329. }
  1330. DBGLOG(RSN, TRACE, "RSN with CCMP-PSK\n");
  1331. *pu2StatusCode = WLAN_STATUS_SUCCESS;
  1332. }
  1333. }
  1334. #endif
  1335. /*----------------------------------------------------------------------------*/
  1336. /*!
  1337. * \brief This routine is called to generate an authentication event to NDIS.
  1338. *
  1339. * \param[in] u4Flags Authentication event: \n
  1340. * PARAM_AUTH_REQUEST_REAUTH 0x01 \n
  1341. * PARAM_AUTH_REQUEST_KEYUPDATE 0x02 \n
  1342. * PARAM_AUTH_REQUEST_PAIRWISE_ERROR 0x06 \n
  1343. * PARAM_AUTH_REQUEST_GROUP_ERROR 0x0E \n
  1344. *
  1345. * \return (none)
  1346. */
  1347. /*----------------------------------------------------------------------------*/
  1348. VOID rsnGenMicErrorEvent(IN P_ADAPTER_T prAdapter, IN BOOLEAN fgFlags)
  1349. {
  1350. P_PARAM_AUTH_EVENT_T prAuthEvent;
  1351. DEBUGFUNC("rsnGenMicErrorEvent");
  1352. prAuthEvent = (P_PARAM_AUTH_EVENT_T) prAdapter->aucIndicationEventBuffer;
  1353. /* Status type: Authentication Event */
  1354. prAuthEvent->rStatus.eStatusType = ENUM_STATUS_TYPE_AUTHENTICATION;
  1355. /* Authentication request */
  1356. prAuthEvent->arRequest[0].u4Length = sizeof(PARAM_AUTH_REQUEST_T);
  1357. kalMemCopy((PVOID) prAuthEvent->arRequest[0].arBssid,
  1358. (PVOID) prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX].aucBSSID, MAC_ADDR_LEN);
  1359. if (fgFlags == TRUE)
  1360. prAuthEvent->arRequest[0].u4Flags = PARAM_AUTH_REQUEST_GROUP_ERROR;
  1361. else
  1362. prAuthEvent->arRequest[0].u4Flags = PARAM_AUTH_REQUEST_PAIRWISE_ERROR;
  1363. kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
  1364. WLAN_STATUS_MEDIA_SPECIFIC_INDICATION,
  1365. (PVOID) prAuthEvent,
  1366. sizeof(PARAM_STATUS_INDICATION_T) + sizeof(PARAM_AUTH_REQUEST_T));
  1367. } /* rsnGenMicErrorEvent */
  1368. /*----------------------------------------------------------------------------*/
  1369. /*!
  1370. * \brief This routine is called to handle TKIP MIC failures.
  1371. *
  1372. * \param[in] adapter_p Pointer to the adapter object data area.
  1373. * \param[in] prSta Pointer to the STA which occur MIC Error
  1374. * \param[in] fgErrorKeyType type of error key
  1375. *
  1376. * \retval none
  1377. */
  1378. /*----------------------------------------------------------------------------*/
  1379. VOID rsnTkipHandleMICFailure(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prSta, IN BOOLEAN fgErrorKeyType)
  1380. {
  1381. /* UINT_32 u4RsnaCurrentMICFailTime; */
  1382. /* P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo; */
  1383. DEBUGFUNC("rsnTkipHandleMICFailure");
  1384. ASSERT(prAdapter);
  1385. #if 1
  1386. rsnGenMicErrorEvent(prAdapter, /* prSta, */ fgErrorKeyType);
  1387. nicConfigPowerSaveProfile(prAdapter, NETWORK_TYPE_AIS_INDEX, Param_PowerModeCAM, FALSE);
  1388. /* Generate authentication request event. */
  1389. DBGLOG(RSN, INFO, "Generate TKIP MIC error event (type: 0%d)\n", fgErrorKeyType);
  1390. #else
  1391. ASSERT(prSta);
  1392. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1393. /* Record the MIC error occur time. */
  1394. GET_CURRENT_SYSTIME(&u4RsnaCurrentMICFailTime);
  1395. /* Generate authentication request event. */
  1396. DBGLOG(RSN, INFO, "Generate TKIP MIC error event (type: 0%d)\n", fgErrorKeyType);
  1397. /* If less than 60 seconds have passed since a previous TKIP MIC failure,
  1398. disassociate from the AP and wait for 60 seconds before (re)associating
  1399. with the same AP. */
  1400. if (prAisSpecBssInfo->u4RsnaLastMICFailTime != 0 &&
  1401. !CHECK_FOR_TIMEOUT(u4RsnaCurrentMICFailTime,
  1402. prAisSpecBssInfo->u4RsnaLastMICFailTime, SEC_TO_SYSTIME(TKIP_COUNTERMEASURE_SEC))) {
  1403. /* If less than 60 seconds expired since last MIC error, we have to
  1404. block traffic. */
  1405. DBGLOG(RSN, INFO, "Start blocking traffic!\n");
  1406. rsnGenMicErrorEvent(prAdapter, /* prSta, */ fgErrorKeyType);
  1407. secFsmEventStartCounterMeasure(prAdapter, prSta);
  1408. } else {
  1409. rsnGenMicErrorEvent(prAdapter, /* prSta, */ fgErrorKeyType);
  1410. DBGLOG(RSN, INFO, "First TKIP MIC error!\n");
  1411. }
  1412. COPY_SYSTIME(prAisSpecBssInfo->u4RsnaLastMICFailTime, u4RsnaCurrentMICFailTime);
  1413. #endif
  1414. } /* rsnTkipHandleMICFailure */
  1415. /*----------------------------------------------------------------------------*/
  1416. /*!
  1417. * \brief This function is called to select a list of BSSID from
  1418. * the scan results for PMKID candidate list.
  1419. *
  1420. * \param[in] prBssDesc the BSS Desc at scan result list
  1421. * \param[out] pu4CandidateCount Pointer to the number of selected candidates.
  1422. * It is set to zero if no BSSID matches our requirement.
  1423. *
  1424. * \retval none
  1425. */
  1426. /*----------------------------------------------------------------------------*/
  1427. VOID rsnSelectPmkidCandidateList(IN P_ADAPTER_T prAdapter, IN P_BSS_DESC_T prBssDesc)
  1428. {
  1429. P_CONNECTION_SETTINGS_T prConnSettings;
  1430. P_AIS_BSS_INFO_T prAisBssInfo;
  1431. DEBUGFUNC("rsnSelectPmkidCandidateList");
  1432. ASSERT(prBssDesc);
  1433. prConnSettings = &prAdapter->rWifiVar.rConnSettings;
  1434. prAisBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX];
  1435. /* Search a BSS with the same SSID from the given BSS description set. */
  1436. /* DBGLOG(RSN, TRACE, ("Check scan result [%pM]\n", */
  1437. /* prBssDesc->aucBSSID)); */
  1438. if (UNEQUAL_SSID(prBssDesc->aucSSID, prBssDesc->ucSSIDLen,
  1439. prConnSettings->aucSSID, prConnSettings->ucSSIDLen)) {
  1440. DBGLOG(RSN, TRACE, "-- SSID not matched\n");
  1441. return;
  1442. }
  1443. #if 0
  1444. if ((prBssDesc->u2BSSBasicRateSet &
  1445. ~(rPhyAttributes[prAisBssInfo->ePhyType].u2SupportedRateSet)) || prBssDesc->fgIsUnknownBssBasicRate) {
  1446. DBGLOG(RSN, TRACE, "-- Rate set not matched\n");
  1447. return;
  1448. }
  1449. if (/* prBssDesc->u4RsnSelectedPairwiseCipher != prAisBssInfo->u4RsnSelectedPairwiseCipher || */
  1450. prBssDesc->u4RsnSelectedGroupCipher != prAisBssInfo->u4RsnSelectedGroupCipher /*||
  1451. prBssDesc->u4RsnSelectedAKMSuite != prAisBssInfo->u4RsnSelectedAKMSuite */) {
  1452. DBGLOG(RSN, TRACE, "-- Encrypt status not matched for PMKID\n");
  1453. return;
  1454. }
  1455. #endif
  1456. rsnUpdatePmkidCandidateList(prAdapter, prBssDesc);
  1457. } /* rsnSelectPmkidCandidateList */
  1458. /*----------------------------------------------------------------------------*/
  1459. /*!
  1460. * \brief This function is called to select a list of BSSID from
  1461. * the scan results for PMKID candidate list.
  1462. *
  1463. * \param[in] prBssDesc the BSS DESC at scan result list
  1464. *
  1465. * \retval none
  1466. */
  1467. /*----------------------------------------------------------------------------*/
  1468. VOID rsnUpdatePmkidCandidateList(IN P_ADAPTER_T prAdapter, IN P_BSS_DESC_T prBssDesc)
  1469. {
  1470. UINT_32 i;
  1471. P_CONNECTION_SETTINGS_T prConnSettings;
  1472. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  1473. DEBUGFUNC("rsnUpdatePmkidCandidateList");
  1474. ASSERT(prBssDesc);
  1475. prConnSettings = &prAdapter->rWifiVar.rConnSettings;
  1476. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1477. if (UNEQUAL_SSID(prBssDesc->aucSSID, prBssDesc->ucSSIDLen,
  1478. prConnSettings->aucSSID, prConnSettings->ucSSIDLen)) {
  1479. DBGLOG(RSN, TRACE, "-- SSID not matched\n");
  1480. return;
  1481. }
  1482. for (i = 0; i < CFG_MAX_PMKID_CACHE; i++) {
  1483. if (EQUAL_MAC_ADDR(prBssDesc->aucBSSID, prAisSpecBssInfo->arPmkidCandicate[i].aucBssid))
  1484. return;
  1485. }
  1486. /* If the number of selected BSSID exceed MAX_NUM_PMKID_CACHE(16),
  1487. then we only store MAX_NUM_PMKID_CACHE(16) in PMKID cache */
  1488. if ((prAisSpecBssInfo->u4PmkidCandicateCount + 1) > CFG_MAX_PMKID_CACHE)
  1489. prAisSpecBssInfo->u4PmkidCandicateCount--;
  1490. i = prAisSpecBssInfo->u4PmkidCandicateCount;
  1491. COPY_MAC_ADDR((PVOID) prAisSpecBssInfo->arPmkidCandicate[i].aucBssid, (PVOID) prBssDesc->aucBSSID);
  1492. if (prBssDesc->u2RsnCap & MASK_RSNIE_CAP_PREAUTH) {
  1493. prAisSpecBssInfo->arPmkidCandicate[i].u4PreAuthFlags = 1;
  1494. DBGLOG(RSN, TRACE, "Add %pM with pre-auth to candidate list\n",
  1495. (prAisSpecBssInfo->arPmkidCandicate[i].aucBssid));
  1496. } else {
  1497. prAisSpecBssInfo->arPmkidCandicate[i].u4PreAuthFlags = 0;
  1498. DBGLOG(RSN, TRACE, "Add %pM without pre-auth to candidate list\n",
  1499. (prAisSpecBssInfo->arPmkidCandicate[i].aucBssid));
  1500. }
  1501. prAisSpecBssInfo->u4PmkidCandicateCount++;
  1502. } /* rsnUpdatePmkidCandidateList */
  1503. /*----------------------------------------------------------------------------*/
  1504. /*!
  1505. * \brief This routine is called to search the desired entry in
  1506. * PMKID cache according to the BSSID
  1507. *
  1508. * \param[in] pucBssid Pointer to the BSSID
  1509. * \param[out] pu4EntryIndex Pointer to place the found entry index
  1510. *
  1511. * \retval TRUE, if found one entry for specified BSSID
  1512. * \retval FALSE, if not found
  1513. */
  1514. /*----------------------------------------------------------------------------*/
  1515. BOOLEAN rsnSearchPmkidEntry(IN P_ADAPTER_T prAdapter, IN PUINT_8 pucBssid, OUT PUINT_32 pu4EntryIndex)
  1516. {
  1517. UINT_32 i;
  1518. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  1519. DEBUGFUNC("rsnSearchPmkidEntry");
  1520. ASSERT(pucBssid);
  1521. ASSERT(pu4EntryIndex);
  1522. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1523. if (prAisSpecBssInfo->u4PmkidCacheCount > CFG_MAX_PMKID_CACHE)
  1524. return FALSE;
  1525. ASSERT(prAisSpecBssInfo->u4PmkidCacheCount <= CFG_MAX_PMKID_CACHE);
  1526. /* Search for desired BSSID */
  1527. for (i = 0; i < prAisSpecBssInfo->u4PmkidCacheCount; i++) {
  1528. if (!kalMemCmp(prAisSpecBssInfo->arPmkidCache[i].rBssidInfo.arBSSID, pucBssid, MAC_ADDR_LEN))
  1529. break;
  1530. }
  1531. /* If desired BSSID is found, then set the PMKID */
  1532. if (i < prAisSpecBssInfo->u4PmkidCacheCount) {
  1533. *pu4EntryIndex = i;
  1534. return TRUE;
  1535. }
  1536. return FALSE;
  1537. } /* rsnSearchPmkidEntry */
  1538. /*----------------------------------------------------------------------------*/
  1539. /*!
  1540. * \brief This routine is called to check if there is difference
  1541. * between PMKID candicate list and PMKID cache. If there
  1542. * is new candicate that no cache entry is available, then
  1543. * add a new entry for the new candicate in the PMKID cache
  1544. * and set the PMKID indication flag to TRUE.
  1545. *
  1546. * \retval TRUE, if new member in the PMKID candicate list
  1547. * \retval FALSe, if no new member in the PMKID candicate list
  1548. */
  1549. /*----------------------------------------------------------------------------*/
  1550. BOOLEAN rsnCheckPmkidCandicate(IN P_ADAPTER_T prAdapter)
  1551. {
  1552. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  1553. UINT_32 i; /* Index for PMKID candicate */
  1554. UINT_32 j; /* Indix for PMKID cache */
  1555. BOOLEAN status = FALSE;
  1556. DEBUGFUNC("rsnCheckPmkidCandicate");
  1557. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1558. /* Check for each candicate */
  1559. for (i = 0; i < prAisSpecBssInfo->u4PmkidCandicateCount; i++) {
  1560. for (j = 0; j < prAisSpecBssInfo->u4PmkidCacheCount; j++) {
  1561. if (!kalMemCmp(prAisSpecBssInfo->arPmkidCache[j].rBssidInfo.arBSSID,
  1562. prAisSpecBssInfo->arPmkidCandicate[i].aucBssid, MAC_ADDR_LEN)) {
  1563. /* DBGLOG(RSN, TRACE, ("%pM at PMKID cache!!\n",
  1564. (prAisSpecBssInfo->arPmkidCandicate[i].aucBssid))); */
  1565. break;
  1566. }
  1567. }
  1568. /* No entry found in PMKID cache for the candicate, add new one */
  1569. if (j == prAisSpecBssInfo->u4PmkidCacheCount
  1570. && prAisSpecBssInfo->u4PmkidCacheCount < CFG_MAX_PMKID_CACHE) {
  1571. DBGLOG(RSN, TRACE,
  1572. "Add %pM to PMKID cache!!\n",
  1573. (prAisSpecBssInfo->arPmkidCandicate[i].aucBssid));
  1574. kalMemCopy((PVOID) prAisSpecBssInfo->
  1575. arPmkidCache[prAisSpecBssInfo->u4PmkidCacheCount].rBssidInfo.arBSSID,
  1576. (PVOID) prAisSpecBssInfo->arPmkidCandicate[i].aucBssid, MAC_ADDR_LEN);
  1577. prAisSpecBssInfo->arPmkidCache[prAisSpecBssInfo->u4PmkidCacheCount].fgPmkidExist = FALSE;
  1578. prAisSpecBssInfo->u4PmkidCacheCount++;
  1579. status = TRUE;
  1580. }
  1581. }
  1582. return status;
  1583. } /* rsnCheckPmkidCandicate */
  1584. /*----------------------------------------------------------------------------*/
  1585. /*!
  1586. * \brief This function is called to wait a duration to indicate the pre-auth AP candicate
  1587. *
  1588. * \return (none)
  1589. */
  1590. /*----------------------------------------------------------------------------*/
  1591. VOID rsnIndicatePmkidCand(IN P_ADAPTER_T prAdapter, IN ULONG ulParm)
  1592. {
  1593. DBGLOG(RSN, EVENT, "Security - Time to indicate the PMKID cand.\n");
  1594. /* If the authentication mode is WPA2 and indication PMKID flag
  1595. is available, then we indicate the PMKID candidate list to NDIS and
  1596. clear the flag, indicatePMKID */
  1597. if (prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX].eConnectionState == PARAM_MEDIA_STATE_CONNECTED &&
  1598. prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA2) {
  1599. rsnGeneratePmkidIndication(prAdapter);
  1600. }
  1601. } /* end of rsnIndicatePmkidCand() */
  1602. /*----------------------------------------------------------------------------*/
  1603. /*!
  1604. * \brief This routine is called to check the BSS Desc at scan result
  1605. * with pre-auth cap at wpa2 mode. If there
  1606. * is candicate that no cache entry is available, then
  1607. * add a new entry for the new candicate in the PMKID cache
  1608. * and set the PMKID indication flag to TRUE.
  1609. *
  1610. * \param[in] prBss The BSS Desc at scan result
  1611. *
  1612. * \return none
  1613. */
  1614. /*----------------------------------------------------------------------------*/
  1615. VOID rsnCheckPmkidCache(IN P_ADAPTER_T prAdapter, IN P_BSS_DESC_T prBss)
  1616. {
  1617. P_AIS_BSS_INFO_T prAisBssInfo;
  1618. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  1619. P_CONNECTION_SETTINGS_T prConnSettings;
  1620. DEBUGFUNC("rsnCheckPmkidCandicate");
  1621. ASSERT(prBss);
  1622. prConnSettings = &prAdapter->rWifiVar.rConnSettings;
  1623. prAisBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX];
  1624. prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1625. if ((prAisBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED) &&
  1626. (prConnSettings->eAuthMode == AUTH_MODE_WPA2)) {
  1627. rsnSelectPmkidCandidateList(prAdapter, prBss);
  1628. /* Set indication flag of PMKID to TRUE, and then connHandleNetworkConnection()
  1629. will indicate this later */
  1630. if (rsnCheckPmkidCandicate(prAdapter)) {
  1631. DBGLOG(RSN, TRACE, "Prepare a timer to indicate candidate PMKID Candidate\n");
  1632. cnmTimerStopTimer(prAdapter, &prAisSpecBssInfo->rPreauthenticationTimer);
  1633. cnmTimerStartTimer(prAdapter, &prAisSpecBssInfo->rPreauthenticationTimer,
  1634. SEC_TO_MSEC(WAIT_TIME_IND_PMKID_CANDICATE_SEC));
  1635. }
  1636. }
  1637. }
  1638. /*----------------------------------------------------------------------------*/
  1639. /*!
  1640. * \brief This routine is called to generate an PMKID candidate list
  1641. * indication to NDIS.
  1642. *
  1643. * \param[in] prAdapter Pointer to the adapter object data area.
  1644. * \param[in] u4Flags PMKID candidate list event:
  1645. * PARAM_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
  1646. *
  1647. * \retval none
  1648. */
  1649. /*----------------------------------------------------------------------------*/
  1650. VOID rsnGeneratePmkidIndication(IN P_ADAPTER_T prAdapter)
  1651. {
  1652. P_PARAM_STATUS_INDICATION_T prStatusEvent;
  1653. P_PARAM_PMKID_CANDIDATE_LIST_T prPmkidEvent;
  1654. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecificBssInfo;
  1655. UINT_8 i, j = 0, count = 0;
  1656. UINT_32 u4LenOfUsedBuffer;
  1657. DEBUGFUNC("rsnGeneratePmkidIndication");
  1658. ASSERT(prAdapter);
  1659. prStatusEvent = (P_PARAM_STATUS_INDICATION_T) prAdapter->aucIndicationEventBuffer;
  1660. /* Status type: PMKID Candidatelist Event */
  1661. prStatusEvent->eStatusType = ENUM_STATUS_TYPE_CANDIDATE_LIST;
  1662. ASSERT(prStatusEvent);
  1663. prPmkidEvent = (P_PARAM_PMKID_CANDIDATE_LIST_T) (&prStatusEvent->eStatusType + 1);
  1664. ASSERT(prPmkidEvent);
  1665. prAisSpecificBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1666. ASSERT(prAisSpecificBssInfo);
  1667. for (i = 0; i < prAisSpecificBssInfo->u4PmkidCandicateCount; i++) {
  1668. for (j = 0; j < prAisSpecificBssInfo->u4PmkidCacheCount; j++) {
  1669. if (EQUAL_MAC_ADDR(prAisSpecificBssInfo->arPmkidCache[j].rBssidInfo.arBSSID,
  1670. prAisSpecificBssInfo->arPmkidCandicate[i].aucBssid) &&
  1671. (prAisSpecificBssInfo->arPmkidCache[j].fgPmkidExist == TRUE)) {
  1672. break;
  1673. }
  1674. }
  1675. if (count >= CFG_MAX_PMKID_CACHE)
  1676. break;
  1677. if (j == prAisSpecificBssInfo->u4PmkidCacheCount) {
  1678. kalMemCopy((PVOID) prPmkidEvent->arCandidateList[count].arBSSID,
  1679. (PVOID) prAisSpecificBssInfo->arPmkidCandicate[i].aucBssid, PARAM_MAC_ADDR_LEN);
  1680. prPmkidEvent->arCandidateList[count].u4Flags =
  1681. prAisSpecificBssInfo->arPmkidCandicate[i].u4PreAuthFlags;
  1682. DBGLOG(RSN, TRACE, "%pM %d\n", (prPmkidEvent->arCandidateList[count].arBSSID),
  1683. (UINT_32) prPmkidEvent->arCandidateList[count].u4Flags);
  1684. count++;
  1685. }
  1686. }
  1687. /* PMKID Candidate List */
  1688. prPmkidEvent->u4Version = 1;
  1689. prPmkidEvent->u4NumCandidates = count;
  1690. DBGLOG(RSN, TRACE, "rsnGeneratePmkidIndication #%d\n", (UINT_32) prPmkidEvent->u4NumCandidates);
  1691. u4LenOfUsedBuffer = sizeof(ENUM_STATUS_TYPE_T) + (2 * sizeof(UINT_32)) +
  1692. (count * sizeof(PARAM_PMKID_CANDIDATE_T));
  1693. /* dumpMemory8((PUINT_8)prAdapter->aucIndicationEventBuffer, u4LenOfUsedBuffer); */
  1694. kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
  1695. WLAN_STATUS_MEDIA_SPECIFIC_INDICATION,
  1696. (PVOID) prAdapter->aucIndicationEventBuffer, u4LenOfUsedBuffer);
  1697. } /* rsnGeneratePmkidIndication */
  1698. #endif
  1699. #if CFG_SUPPORT_WPS2
  1700. /*----------------------------------------------------------------------------*/
  1701. /*!
  1702. *
  1703. * \brief This routine is called to generate WSC IE for
  1704. * associate request frame.
  1705. *
  1706. * \param[in] prCurrentBss The Selected BSS description
  1707. *
  1708. * \retval The append WSC IE length
  1709. *
  1710. * \note
  1711. * Called by: AIS module, Associate request
  1712. */
  1713. /*----------------------------------------------------------------------------*/
  1714. VOID rsnGenerateWSCIE(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo)
  1715. {
  1716. PUINT_8 pucBuffer;
  1717. ASSERT(prAdapter);
  1718. ASSERT(prMsduInfo);
  1719. if (prMsduInfo->ucNetworkType != NETWORK_TYPE_AIS_INDEX)
  1720. return;
  1721. pucBuffer = (PUINT_8) ((ULONG) prMsduInfo->prPacket + (UINT_32) prMsduInfo->u2FrameLength);
  1722. /* ASSOC INFO IE ID: 221 :0xDD */
  1723. if (prAdapter->prGlueInfo->u2WSCAssocInfoIELen) {
  1724. kalMemCopy(pucBuffer, &prAdapter->prGlueInfo->aucWSCAssocInfoIE,
  1725. prAdapter->prGlueInfo->u2WSCAssocInfoIELen);
  1726. prMsduInfo->u2FrameLength += prAdapter->prGlueInfo->u2WSCAssocInfoIELen;
  1727. }
  1728. }
  1729. #endif
  1730. #if CFG_SUPPORT_802_11W
  1731. /*----------------------------------------------------------------------------*/
  1732. /*!
  1733. * \brief to check if the Bip Key installed or not
  1734. *
  1735. * \param[in]
  1736. * prAdapter
  1737. *
  1738. * \return
  1739. * TRUE
  1740. * FALSE
  1741. */
  1742. /*----------------------------------------------------------------------------*/
  1743. UINT_32 rsnCheckBipKeyInstalled(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec)
  1744. {
  1745. if (prStaRec && prStaRec->ucNetTypeIndex == (UINT_8) NETWORK_TYPE_AIS_INDEX)
  1746. return prAdapter->rWifiVar.rAisSpecificBssInfo.fgBipKeyInstalled;
  1747. else
  1748. return FALSE;
  1749. }
  1750. /*----------------------------------------------------------------------------*/
  1751. /*!
  1752. *
  1753. * \brief This routine is called to check the Sa query timeout.
  1754. *
  1755. *
  1756. * \note
  1757. * Called by: AIS module, Handle by Sa Quert timeout
  1758. */
  1759. /*----------------------------------------------------------------------------*/
  1760. UINT_8 rsnCheckSaQueryTimeout(IN P_ADAPTER_T prAdapter)
  1761. {
  1762. P_AIS_SPECIFIC_BSS_INFO_T prBssSpecInfo;
  1763. UINT_32 now;
  1764. prBssSpecInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1765. ASSERT(prBssSpecInfo);
  1766. GET_CURRENT_SYSTIME(&now);
  1767. if (CHECK_FOR_TIMEOUT(now, prBssSpecInfo->u4SaQueryStart, TU_TO_MSEC(1000))) {
  1768. LOG_FUNC("association SA Query timed out\n");
  1769. prBssSpecInfo->ucSaQueryTimedOut = 1;
  1770. kalMemFree(prBssSpecInfo->pucSaQueryTransId, VIR_MEM_TYPE,
  1771. prBssSpecInfo->u4SaQueryCount * ACTION_SA_QUERY_TR_ID_LEN);
  1772. prBssSpecInfo->pucSaQueryTransId = NULL;
  1773. prBssSpecInfo->u4SaQueryCount = 0;
  1774. cnmTimerStopTimer(prAdapter, &prBssSpecInfo->rSaQueryTimer);
  1775. /* Re-connect */
  1776. DBGLOG(RSN, TRACE, "DisBy11w\n");
  1777. kalIndicateStatusAndComplete(prAdapter->prGlueInfo, WLAN_STATUS_MEDIA_DISCONNECT, NULL, 0);
  1778. return 1;
  1779. }
  1780. return 0;
  1781. }
  1782. /*----------------------------------------------------------------------------*/
  1783. /*!
  1784. *
  1785. * \brief This routine is called to start the 802.11w sa query timer.
  1786. *
  1787. *
  1788. * \note
  1789. * Called by: AIS module, Handle Rx mgmt request
  1790. */
  1791. /*----------------------------------------------------------------------------*/
  1792. void rsnStartSaQueryTimer(IN P_ADAPTER_T prAdapter)
  1793. {
  1794. P_BSS_INFO_T prBssInfo;
  1795. P_AIS_SPECIFIC_BSS_INFO_T prBssSpecInfo;
  1796. P_MSDU_INFO_T prMsduInfo;
  1797. P_ACTION_SA_QUERY_FRAME prTxFrame;
  1798. UINT_16 u2PayloadLen;
  1799. PUINT_8 pucTmp = NULL;
  1800. UINT_8 ucTransId[ACTION_SA_QUERY_TR_ID_LEN];
  1801. prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX];
  1802. ASSERT(prBssInfo);
  1803. prBssSpecInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1804. ASSERT(prBssSpecInfo);
  1805. LOG_FUNC("MFP: Start Sa Query\n");
  1806. if (prBssSpecInfo->u4SaQueryCount > 0 && rsnCheckSaQueryTimeout(prAdapter)) {
  1807. LOG_FUNC("MFP: u4SaQueryCount count =%d\n", prBssSpecInfo->u4SaQueryCount);
  1808. return;
  1809. }
  1810. prMsduInfo = (P_MSDU_INFO_T) cnmMgtPktAlloc(prAdapter, MAC_TX_RESERVED_FIELD + PUBLIC_ACTION_MAX_LEN);
  1811. if (!prMsduInfo)
  1812. return;
  1813. prTxFrame = (P_ACTION_SA_QUERY_FRAME)
  1814. ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD);
  1815. prTxFrame->u2FrameCtrl = MAC_FRAME_ACTION;
  1816. prTxFrame->u2FrameCtrl |= MASK_FC_PROTECTED_FRAME;
  1817. COPY_MAC_ADDR(prTxFrame->aucDestAddr, prBssInfo->aucBSSID);
  1818. COPY_MAC_ADDR(prTxFrame->aucSrcAddr, prBssInfo->aucOwnMacAddr);
  1819. COPY_MAC_ADDR(prTxFrame->aucBSSID, prBssInfo->aucBSSID);
  1820. prTxFrame->ucCategory = CATEGORY_SA_QUERT_ACTION;
  1821. prTxFrame->ucAction = ACTION_SA_QUERY_REQUEST;
  1822. if (prBssSpecInfo->u4SaQueryCount == 0)
  1823. GET_CURRENT_SYSTIME(&prBssSpecInfo->u4SaQueryStart);
  1824. if (prBssSpecInfo->u4SaQueryCount) {
  1825. pucTmp = kalMemAlloc(prBssSpecInfo->u4SaQueryCount * ACTION_SA_QUERY_TR_ID_LEN, VIR_MEM_TYPE);
  1826. if (!pucTmp) {
  1827. DBGLOG(RSN, ERROR, "MFP: Fail to alloc tmp buffer for backup sa query id\n");
  1828. return;
  1829. }
  1830. kalMemCopy(pucTmp, prBssSpecInfo->pucSaQueryTransId,
  1831. prBssSpecInfo->u4SaQueryCount * ACTION_SA_QUERY_TR_ID_LEN);
  1832. }
  1833. kalMemFree(prBssSpecInfo->pucSaQueryTransId, VIR_MEM_TYPE,
  1834. prBssSpecInfo->u4SaQueryCount * ACTION_SA_QUERY_TR_ID_LEN);
  1835. ucTransId[0] = (UINT_8) (kalRandomNumber() & 0xFF);
  1836. ucTransId[1] = (UINT_8) (kalRandomNumber() & 0xFF);
  1837. kalMemCopy(prTxFrame->ucTransId, ucTransId, ACTION_SA_QUERY_TR_ID_LEN);
  1838. prBssSpecInfo->u4SaQueryCount++;
  1839. prBssSpecInfo->pucSaQueryTransId =
  1840. kalMemAlloc(prBssSpecInfo->u4SaQueryCount * ACTION_SA_QUERY_TR_ID_LEN, VIR_MEM_TYPE);
  1841. if (!prBssSpecInfo->pucSaQueryTransId) {
  1842. DBGLOG(RSN, ERROR, "MFP: Fail to alloc buffer for sa query id list\n");
  1843. return;
  1844. }
  1845. if (pucTmp) {
  1846. kalMemCopy(prBssSpecInfo->pucSaQueryTransId, pucTmp,
  1847. (prBssSpecInfo->u4SaQueryCount - 1) * ACTION_SA_QUERY_TR_ID_LEN);
  1848. kalMemCopy(&prBssSpecInfo->pucSaQueryTransId
  1849. [(prBssSpecInfo->u4SaQueryCount - 1) * ACTION_SA_QUERY_TR_ID_LEN], ucTransId,
  1850. ACTION_SA_QUERY_TR_ID_LEN);
  1851. kalMemFree(pucTmp, VIR_MEM_TYPE, (prBssSpecInfo->u4SaQueryCount - 1) * ACTION_SA_QUERY_TR_ID_LEN);
  1852. } else {
  1853. kalMemCopy(prBssSpecInfo->pucSaQueryTransId, ucTransId, ACTION_SA_QUERY_TR_ID_LEN);
  1854. }
  1855. u2PayloadLen = 2 + ACTION_SA_QUERY_TR_ID_LEN;
  1856. /* 4 Update information of MSDU_INFO_T */
  1857. prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_MGMT; /* Management frame */
  1858. prMsduInfo->ucStaRecIndex = prBssInfo->prStaRecOfAP->ucIndex;
  1859. prMsduInfo->ucNetworkType = prBssInfo->ucNetTypeIndex;
  1860. prMsduInfo->ucMacHeaderLength = WLAN_MAC_MGMT_HEADER_LEN;
  1861. prMsduInfo->fgIs802_1x = FALSE;
  1862. prMsduInfo->fgIs802_11 = TRUE;
  1863. prMsduInfo->u2FrameLength = WLAN_MAC_MGMT_HEADER_LEN + u2PayloadLen;
  1864. prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
  1865. prMsduInfo->pfTxDoneHandler = NULL;
  1866. prMsduInfo->fgIsBasicRate = FALSE;
  1867. /* 4 Enqueue the frame to send this action frame. */
  1868. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  1869. DBGLOG(RSN, TRACE,
  1870. "Set SA Query timer %d (%d sec)\n", prBssSpecInfo->u4SaQueryCount, prBssInfo->u2ObssScanInterval);
  1871. cnmTimerStartTimer(prAdapter, &prBssSpecInfo->rSaQueryTimer, TU_TO_MSEC(201));
  1872. }
  1873. /*----------------------------------------------------------------------------*/
  1874. /*!
  1875. *
  1876. * \brief This routine is called to start the 802.11w sa query.
  1877. *
  1878. *
  1879. * \note
  1880. * Called by: AIS module, Handle Rx mgmt request
  1881. */
  1882. /*----------------------------------------------------------------------------*/
  1883. void rsnStartSaQuery(IN P_ADAPTER_T prAdapter)
  1884. {
  1885. rsnStartSaQueryTimer(prAdapter);
  1886. }
  1887. /*----------------------------------------------------------------------------*/
  1888. /*!
  1889. *
  1890. * \brief This routine is called to stop the 802.11w sa query.
  1891. *
  1892. *
  1893. * \note
  1894. * Called by: AIS module, Handle Rx mgmt request
  1895. */
  1896. /*----------------------------------------------------------------------------*/
  1897. void rsnStopSaQuery(IN P_ADAPTER_T prAdapter)
  1898. {
  1899. P_AIS_SPECIFIC_BSS_INFO_T prBssSpecInfo;
  1900. prBssSpecInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1901. ASSERT(prBssSpecInfo);
  1902. cnmTimerStopTimer(prAdapter, &prBssSpecInfo->rSaQueryTimer);
  1903. kalMemFree(prBssSpecInfo->pucSaQueryTransId, VIR_MEM_TYPE,
  1904. prBssSpecInfo->u4SaQueryCount * ACTION_SA_QUERY_TR_ID_LEN);
  1905. prBssSpecInfo->pucSaQueryTransId = NULL;
  1906. prBssSpecInfo->u4SaQueryCount = 0;
  1907. }
  1908. /*----------------------------------------------------------------------------*/
  1909. /*!
  1910. *
  1911. * \brief This routine is called to process the 802.11w sa query action frame.
  1912. *
  1913. *
  1914. * \note
  1915. * Called by: AIS module, Handle Rx mgmt request
  1916. */
  1917. /*----------------------------------------------------------------------------*/
  1918. void rsnSaQueryRequest(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  1919. {
  1920. P_BSS_INFO_T prBssInfo;
  1921. P_MSDU_INFO_T prMsduInfo;
  1922. P_ACTION_SA_QUERY_FRAME prRxFrame = NULL;
  1923. UINT_16 u2PayloadLen;
  1924. P_STA_RECORD_T prStaRec;
  1925. P_ACTION_SA_QUERY_FRAME prTxFrame;
  1926. prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX];
  1927. ASSERT(prBssInfo);
  1928. prRxFrame = (P_ACTION_SA_QUERY_FRAME) prSwRfb->pvHeader;
  1929. if (!prRxFrame)
  1930. return;
  1931. prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
  1932. DBGLOG(RSN, TRACE, "IEEE 802.11: Received SA Query Request from %pM\n", prStaRec->aucMacAddr);
  1933. DBGLOG_MEM8(RSN, TRACE, prRxFrame->ucTransId, ACTION_SA_QUERY_TR_ID_LEN);
  1934. if (kalGetMediaStateIndicated(prAdapter->prGlueInfo) == PARAM_MEDIA_STATE_DISCONNECTED) {
  1935. DBGLOG(RSN, TRACE, "IEEE 802.11: Ignore SA Query Request from unassociated STA %pM\n",
  1936. prStaRec->aucMacAddr);
  1937. return;
  1938. }
  1939. DBGLOG(RSN, TRACE, "IEEE 802.11: Sending SA Query Response to %pM\n", prStaRec->aucMacAddr);
  1940. prMsduInfo = (P_MSDU_INFO_T) cnmMgtPktAlloc(prAdapter, MAC_TX_RESERVED_FIELD + PUBLIC_ACTION_MAX_LEN);
  1941. if (!prMsduInfo)
  1942. return;
  1943. prTxFrame = (P_ACTION_SA_QUERY_FRAME)
  1944. ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD);
  1945. prTxFrame->u2FrameCtrl = MAC_FRAME_ACTION;
  1946. /* SA Query always with protected */
  1947. prTxFrame->u2FrameCtrl |= MASK_FC_PROTECTED_FRAME;
  1948. COPY_MAC_ADDR(prTxFrame->aucDestAddr, prBssInfo->aucBSSID);
  1949. COPY_MAC_ADDR(prTxFrame->aucSrcAddr, prBssInfo->aucOwnMacAddr);
  1950. COPY_MAC_ADDR(prTxFrame->aucBSSID, prBssInfo->aucBSSID);
  1951. prTxFrame->ucCategory = CATEGORY_SA_QUERT_ACTION;
  1952. prTxFrame->ucAction = ACTION_SA_QUERY_RESPONSE;
  1953. kalMemCopy(prTxFrame->ucTransId, prRxFrame->ucTransId, ACTION_SA_QUERY_TR_ID_LEN);
  1954. u2PayloadLen = 2 + ACTION_SA_QUERY_TR_ID_LEN;
  1955. /* 4 Update information of MSDU_INFO_T */
  1956. prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_MGMT; /* Management frame */
  1957. prMsduInfo->ucStaRecIndex = prBssInfo->prStaRecOfAP->ucIndex;
  1958. prMsduInfo->ucNetworkType = prBssInfo->ucNetTypeIndex;
  1959. prMsduInfo->ucMacHeaderLength = WLAN_MAC_MGMT_HEADER_LEN;
  1960. prMsduInfo->fgIs802_1x = FALSE;
  1961. prMsduInfo->fgIs802_11 = TRUE;
  1962. prMsduInfo->u2FrameLength = WLAN_MAC_MGMT_HEADER_LEN + u2PayloadLen;
  1963. prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
  1964. prMsduInfo->pfTxDoneHandler = NULL;
  1965. prMsduInfo->fgIsBasicRate = FALSE;
  1966. /* 4 Enqueue the frame to send this action frame. */
  1967. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  1968. }
  1969. /*----------------------------------------------------------------------------*/
  1970. /*!
  1971. *
  1972. * \brief This routine is called to process the 802.11w sa query action frame.
  1973. *
  1974. *
  1975. * \note
  1976. * Called by: AIS module, Handle Rx mgmt request
  1977. */
  1978. /*----------------------------------------------------------------------------*/
  1979. void rsnSaQueryAction(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  1980. {
  1981. P_AIS_SPECIFIC_BSS_INFO_T prBssSpecInfo;
  1982. P_ACTION_SA_QUERY_FRAME prRxFrame;
  1983. P_STA_RECORD_T prStaRec;
  1984. UINT_32 i;
  1985. prBssSpecInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
  1986. ASSERT(prBssSpecInfo);
  1987. prRxFrame = (P_ACTION_SA_QUERY_FRAME) prSwRfb->pvHeader;
  1988. prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
  1989. if (prSwRfb->u2PacketLen < ACTION_SA_QUERY_TR_ID_LEN) {
  1990. DBGLOG(RSN, TRACE, "IEEE 802.11: Too short SA Query Action frame (len=%u)\n",
  1991. prSwRfb->u2PacketLen);
  1992. return;
  1993. }
  1994. if (prRxFrame->ucAction == ACTION_SA_QUERY_REQUEST) {
  1995. rsnSaQueryRequest(prAdapter, prSwRfb);
  1996. return;
  1997. }
  1998. if (prRxFrame->ucAction != ACTION_SA_QUERY_RESPONSE) {
  1999. DBGLOG(RSN, TRACE, "IEEE 802.11: Unexpected SA Query " "Action %d\n", prRxFrame->ucAction);
  2000. return;
  2001. }
  2002. DBGLOG(RSN, TRACE, "IEEE 802.11: Received SA Query Response from %pM\n", prStaRec->aucMacAddr);
  2003. DBGLOG_MEM8(RSN, TRACE, prRxFrame->ucTransId, ACTION_SA_QUERY_TR_ID_LEN);
  2004. /* MLME-SAQuery.confirm */
  2005. for (i = 0; i < prBssSpecInfo->u4SaQueryCount; i++) {
  2006. if (kalMemCmp(prBssSpecInfo->pucSaQueryTransId +
  2007. i * ACTION_SA_QUERY_TR_ID_LEN, prRxFrame->ucTransId, ACTION_SA_QUERY_TR_ID_LEN) == 0)
  2008. break;
  2009. }
  2010. if (i >= prBssSpecInfo->u4SaQueryCount) {
  2011. DBGLOG(RSN, TRACE, "IEEE 802.11: No matching SA Query " "transaction identifier found\n");
  2012. return;
  2013. }
  2014. DBGLOG(RSN, TRACE, "Reply to pending SA Query received\n");
  2015. rsnStopSaQuery(prAdapter);
  2016. }
  2017. /*----------------------------------------------------------------------------*/
  2018. /*!
  2019. *
  2020. * \brief This routine is called to process the 802.11w mgmt frame.
  2021. *
  2022. *
  2023. * \note
  2024. * Called by: AIS module, Handle Rx mgmt request
  2025. */
  2026. /*----------------------------------------------------------------------------*/
  2027. BOOLEAN rsnCheckRxMgmt(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb, IN UINT_8 ucSubtype)
  2028. {
  2029. P_HIF_RX_HEADER_T prHifRxHdr;
  2030. BOOLEAN fgUnicast = TRUE;
  2031. BOOLEAN fgRobustAction = FALSE;
  2032. prHifRxHdr = prSwRfb->prHifRxHdr;
  2033. if ((HIF_RX_HDR_GET_NETWORK_IDX(prHifRxHdr) == NETWORK_TYPE_AIS_INDEX) &&
  2034. prAdapter->rWifiVar.rAisSpecificBssInfo.fgMgmtProtection /* Use MFP */) {
  2035. P_WLAN_ASSOC_REQ_FRAME_T prAssocReqFrame;
  2036. prAssocReqFrame = (P_WLAN_ASSOC_REQ_FRAME_T) prSwRfb->pvHeader;
  2037. if (prAssocReqFrame->aucDestAddr[0] & BIT(0))
  2038. fgUnicast = FALSE;
  2039. LOG_FUNC("QM RX MGT: rsnCheckRxMgmt = %d 0x%x %d ucSubtype=%x\n", fgUnicast, prHifRxHdr->ucReserved,
  2040. (prHifRxHdr->ucReserved & CONTROL_FLAG_UC_MGMT_NO_ENC), ucSubtype);
  2041. if (prHifRxHdr->ucReserved & CONTROL_FLAG_UC_MGMT_NO_ENC) {
  2042. /* "Dropped unprotected Robust Action frame from an MFP STA" */
  2043. /* exclude Public Action */
  2044. if (ucSubtype == 13 /* 0x1011: MAC_FRAME_ACTION */) {
  2045. UINT_8 ucAction = *prSwRfb->pucRecvBuff;
  2046. if (ucAction != CATEGORY_PUBLIC_ACTION && ucAction != CATEGORY_HT_ACTION) {
  2047. #if DBG && CFG_RX_PKTS_DUMP
  2048. LOG_FUNC("QM RX MGT: UnProtected Robust Action frame = %d\n", ucAction);
  2049. #endif
  2050. fgRobustAction = TRUE;
  2051. return TRUE;
  2052. }
  2053. }
  2054. if (fgUnicast && ((ucSubtype == 10 /* 0x1010: MAC_FRAME_DISASSOC */)
  2055. || (ucSubtype == 12 /* 0x1100: MAC_FRAME_DEAUTH */))) {
  2056. LOG_FUNC("QM RX MGT: rsnStartSaQuery\n");
  2057. /* MFP test plan 5.3.3.5 */
  2058. rsnStartSaQuery(prAdapter);
  2059. return TRUE;
  2060. }
  2061. }
  2062. #if 0
  2063. else {
  2064. if (fgUnicast && ((ucSubtype == MAC_FRAME_DISASSOC) || (ucSubtype == MAC_FRAME_DEAUTH))) {
  2065. /* This done by function handler */
  2066. /* kalIndicateStatusAndComplete(prAdapter->prGlueInfo, */
  2067. /* WLAN_STATUS_MEDIA_DISCONNECT, */
  2068. /* NULL, */
  2069. /* 0); */
  2070. }
  2071. }
  2072. #endif
  2073. }
  2074. return FALSE;
  2075. }
  2076. #endif
  2077. #if CFG_SUPPORT_DETECT_SECURITY_MODE_CHANGE
  2078. static BOOLEAN rsnCheckWpaRsnInfo(P_BSS_INFO_T prBss, P_RSN_INFO_T prWpaRsnInfo)
  2079. {
  2080. UINT_32 i = 0;
  2081. if (prWpaRsnInfo->u4GroupKeyCipherSuite != prBss->u4RsnSelectedGroupCipher) {
  2082. DBGLOG(RSN, INFO, "GroupCipherSuite change, old=0x%04x, new=0x%04x\n",
  2083. prBss->u4RsnSelectedGroupCipher, prWpaRsnInfo->u4GroupKeyCipherSuite);
  2084. return TRUE;
  2085. }
  2086. for (; i < prWpaRsnInfo->u4AuthKeyMgtSuiteCount; i++)
  2087. if (prBss->u4RsnSelectedAKMSuite == prWpaRsnInfo->au4AuthKeyMgtSuite[i])
  2088. break;
  2089. if (i == prWpaRsnInfo->u4AuthKeyMgtSuiteCount) {
  2090. DBGLOG(RSN, INFO, "KeyMgmt change, not find 0x%04x in new beacon\n", prBss->u4RsnSelectedAKMSuite);
  2091. return TRUE;
  2092. }
  2093. for (i = 0; i < prWpaRsnInfo->u4PairwiseKeyCipherSuiteCount; i++)
  2094. if (prBss->u4RsnSelectedPairwiseCipher == prWpaRsnInfo->au4PairwiseKeyCipherSuite[i])
  2095. break;
  2096. if (i == prWpaRsnInfo->u4PairwiseKeyCipherSuiteCount) {
  2097. DBGLOG(RSN, INFO, "Pairwise Cipher change, not find 0x%04x in new beacon\n",
  2098. prBss->u4RsnSelectedPairwiseCipher);
  2099. return TRUE;
  2100. }
  2101. return FALSE;
  2102. }
  2103. BOOLEAN rsnCheckSecurityModeChanged(P_ADAPTER_T prAdapter, P_BSS_INFO_T prBssInfo, P_BSS_DESC_T prBssDesc)
  2104. {
  2105. ENUM_PARAM_AUTH_MODE_T eAuthMode = prAdapter->rWifiVar.rConnSettings.eAuthMode;
  2106. switch (eAuthMode) {
  2107. case AUTH_MODE_OPEN: /* original is open system */
  2108. if ((prBssDesc->u2CapInfo & CAP_INFO_PRIVACY) && !prAdapter->prGlueInfo->rWpaInfo.fgPrivacyInvoke) {
  2109. DBGLOG(RSN, INFO, "security change, open->privacy\n");
  2110. return TRUE;
  2111. }
  2112. break;
  2113. case AUTH_MODE_SHARED: /* original is WEP */
  2114. case AUTH_MODE_AUTO_SWITCH:
  2115. if ((prBssDesc->u2CapInfo & CAP_INFO_PRIVACY) == 0) {
  2116. DBGLOG(RSN, INFO, "security change, WEP->open\n");
  2117. return TRUE;
  2118. } else if (prBssDesc->fgIERSN || prBssDesc->fgIEWPA) {
  2119. DBGLOG(RSN, INFO, "security change, WEP->WPA/WPA2\n");
  2120. return TRUE;
  2121. }
  2122. break;
  2123. case AUTH_MODE_WPA: /*original is WPA */
  2124. case AUTH_MODE_WPA_PSK:
  2125. case AUTH_MODE_WPA_NONE:
  2126. if (prBssDesc->fgIEWPA)
  2127. return rsnCheckWpaRsnInfo(prBssInfo, &prBssDesc->rWPAInfo);
  2128. DBGLOG(RSN, INFO, "security change, WPA->%s\n",
  2129. prBssDesc->fgIERSN ? "WPA2" :
  2130. (prBssDesc->u2CapInfo & CAP_INFO_PRIVACY ? "WEP" : "OPEN"));
  2131. return TRUE;
  2132. case AUTH_MODE_WPA2: /*original is WPA2 */
  2133. case AUTH_MODE_WPA2_PSK:
  2134. if (prBssDesc->fgIERSN)
  2135. return rsnCheckWpaRsnInfo(prBssInfo, &prBssDesc->rRSNInfo);
  2136. DBGLOG(RSN, INFO, "security change, WPA2->%s\n",
  2137. prBssDesc->fgIEWPA ? "WPA" :
  2138. (prBssDesc->u2CapInfo & CAP_INFO_PRIVACY ? "WEP" : "OPEN"));
  2139. return TRUE;
  2140. default:
  2141. DBGLOG(RSN, WARN, "unknowned eAuthMode=%d\n", eAuthMode);
  2142. break;
  2143. }
  2144. /*DBGLOG(RSN, INFO, ("rsnCheckSecurityModeChanged, eAuthMode=%d, u2CapInfo=0x%02x, fgIEWPA=%d, fgIERSN=%d\n",
  2145. eAuthMode, prBssDesc->u2CapInfo, prBssDesc->fgIEWPA, prBssDesc->fgIERSN)); */
  2146. return FALSE;
  2147. }
  2148. #endif