rtw_wapi.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. #ifdef CONFIG_WAPI_SUPPORT
  2. #include <linux/unistd.h>
  3. #include <linux/etherdevice.h>
  4. #include <drv_types.h>
  5. #include <rtw_wapi.h>
  6. u32 wapi_debug_component =
  7. // WAPI_INIT |
  8. // WAPI_API |
  9. // WAPI_TX |
  10. // WAPI_RX |
  11. WAPI_ERR ; //always open err flags on
  12. void WapiFreeAllStaInfo(_adapter *padapter)
  13. {
  14. PRT_WAPI_T pWapiInfo;
  15. PRT_WAPI_STA_INFO pWapiStaInfo;
  16. PRT_WAPI_BKID pWapiBkid;
  17. WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__);
  18. pWapiInfo = &padapter->wapiInfo;
  19. //Pust to Idle List
  20. rtw_wapi_return_all_sta_info(padapter);
  21. //Sta Info List
  22. while(!list_empty(&(pWapiInfo->wapiSTAIdleList)))
  23. {
  24. pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAIdleList.next, RT_WAPI_STA_INFO, list);
  25. list_del_init(&pWapiStaInfo->list);
  26. }
  27. //BKID List
  28. while(!list_empty(&(pWapiInfo->wapiBKIDIdleList)))
  29. {
  30. pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDIdleList.next, RT_WAPI_BKID, list);
  31. list_del_init(&pWapiBkid->list);
  32. }
  33. WAPI_TRACE(WAPI_INIT, "<=========== %s\n", __FUNCTION__);
  34. return;
  35. }
  36. void WapiSetIE(_adapter *padapter)
  37. {
  38. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  39. //PRT_WAPI_BKID pWapiBkid;
  40. u16 protocolVer = 1;
  41. u16 akmCnt = 1;
  42. u16 suiteCnt = 1;
  43. u16 capability = 0;
  44. u8 OUI[3];
  45. OUI[0] = 0x00;
  46. OUI[1] = 0x14;
  47. OUI[2] = 0x72;
  48. pWapiInfo->wapiIELength = 0;
  49. //protocol version
  50. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &protocolVer, 2);
  51. pWapiInfo->wapiIELength +=2;
  52. //akm
  53. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &akmCnt, 2);
  54. pWapiInfo->wapiIELength +=2;
  55. if(pWapiInfo->bWapiPSK){
  56. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3);
  57. pWapiInfo->wapiIELength +=3;
  58. pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x2;
  59. pWapiInfo->wapiIELength +=1;
  60. }else{
  61. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3);
  62. pWapiInfo->wapiIELength +=3;
  63. pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1;
  64. pWapiInfo->wapiIELength +=1;
  65. }
  66. //usk
  67. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &suiteCnt, 2);
  68. pWapiInfo->wapiIELength +=2;
  69. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3);
  70. pWapiInfo->wapiIELength +=3;
  71. pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1;
  72. pWapiInfo->wapiIELength +=1;
  73. //msk
  74. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength,OUI, 3);
  75. pWapiInfo->wapiIELength +=3;
  76. pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1;
  77. pWapiInfo->wapiIELength +=1;
  78. //Capbility
  79. memcpy(pWapiInfo->wapiIE+pWapiInfo->wapiIELength, &capability, 2);
  80. pWapiInfo->wapiIELength +=2;
  81. }
  82. /* PN1 > PN2, return 1,
  83. * else return 0.
  84. */
  85. u32 WapiComparePN(u8 *PN1, u8 *PN2)
  86. {
  87. char i;
  88. if ((NULL == PN1) || (NULL == PN2))
  89. return 1;
  90. // overflow case
  91. if ((PN2[15] - PN1[15]) & 0x80)
  92. return 1;
  93. for (i=16; i>0; i--)
  94. {
  95. if(PN1[i-1] == PN2[i-1])
  96. continue;
  97. else if(PN1[i-1] > PN2[i-1])
  98. return 1;
  99. else
  100. return 0;
  101. }
  102. return 0;
  103. }
  104. u8
  105. WapiGetEntryForCamWrite(_adapter *padapter,u8 *pMacAddr,u8 KID,BOOLEAN IsMsk)
  106. {
  107. PRT_WAPI_T pWapiInfo=NULL;
  108. //PRT_WAPI_CAM_ENTRY pEntry=NULL;
  109. u8 i=0;
  110. u8 ret = 0xff;
  111. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  112. pWapiInfo = &padapter->wapiInfo;
  113. //exist?
  114. for(i=0;i<WAPI_CAM_ENTRY_NUM;i++)
  115. {
  116. if(pWapiInfo->wapiCamEntry[i].IsUsed
  117. && (_rtw_memcmp(pMacAddr, pWapiInfo->wapiCamEntry[i].PeerMacAddr, ETH_ALEN) == _TRUE)
  118. && pWapiInfo->wapiCamEntry[i].keyidx == KID
  119. && pWapiInfo->wapiCamEntry[i].type == IsMsk)
  120. {
  121. ret = pWapiInfo->wapiCamEntry[i].entry_idx; //cover it
  122. break;
  123. }
  124. }
  125. if(i == WAPI_CAM_ENTRY_NUM) //not found
  126. {
  127. for(i=0;i<WAPI_CAM_ENTRY_NUM;i++)
  128. {
  129. if(pWapiInfo->wapiCamEntry[i].IsUsed == 0)
  130. {
  131. pWapiInfo->wapiCamEntry[i].IsUsed = 1;
  132. pWapiInfo->wapiCamEntry[i].type = IsMsk;
  133. pWapiInfo->wapiCamEntry[i].keyidx = KID;
  134. _rtw_memcpy(pWapiInfo->wapiCamEntry[i].PeerMacAddr, pMacAddr,ETH_ALEN);
  135. ret = pWapiInfo->wapiCamEntry[i].entry_idx;
  136. break;
  137. }
  138. }
  139. }
  140. WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__);
  141. return ret;
  142. /*
  143. if(RTIsListEmpty(&pWapiInfo->wapiCamIdleList)){
  144. RT_TRACE(COMP_SEC,DBG_LOUD,("No Entry for wapi!!!\n"));
  145. return 0;
  146. }
  147. pEntry = (PRT_WAPI_CAM_ENTRY)RTRemoveHeadList(&pWapiInfo->wapiCamIdleList);
  148. RTInsertTailList(&pWapiInfo->wapiCamUsedList, &pEntry->list);
  149. RT_TRACE(COMP_SEC,DBG_LOUD,("<====WapiGetCamEntry(),Get Entry Idx:%d.but we just return 4 for test\n",pEntry->entry_idx));
  150. return pEntry->entry_idx;*/
  151. }
  152. u8 WapiGetEntryForCamClear(_adapter *padapter,u8 *pPeerMac,u8 keyid,u8 IsMsk)
  153. {
  154. PRT_WAPI_T pWapiInfo=NULL;
  155. u8 i=0;
  156. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  157. pWapiInfo = &padapter->wapiInfo;
  158. for(i=0;i<WAPI_CAM_ENTRY_NUM;i++)
  159. {
  160. if(pWapiInfo->wapiCamEntry[i].IsUsed
  161. && (_rtw_memcmp(pPeerMac, pWapiInfo->wapiCamEntry[i].PeerMacAddr, ETH_ALEN) == _TRUE)
  162. && pWapiInfo->wapiCamEntry[i].keyidx == keyid
  163. && pWapiInfo->wapiCamEntry[i].type == IsMsk)
  164. {
  165. pWapiInfo->wapiCamEntry[i].IsUsed = 0;
  166. pWapiInfo->wapiCamEntry[i].keyidx = 2;
  167. _rtw_memset(pWapiInfo->wapiCamEntry[i].PeerMacAddr,0,ETH_ALEN);
  168. WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__);
  169. return pWapiInfo->wapiCamEntry[i].entry_idx;
  170. }
  171. }
  172. WAPI_TRACE(WAPI_API,"<====WapiGetReturnCamEntry(), No this cam entry.\n");
  173. return 0xff;
  174. /*
  175. if(RTIsListEmpty(&pWapiInfo->wapiCamUsedList)){
  176. RT_TRACE(COMP_SEC,DBG_LOUD,("No Entry for wapi!!!\n"));
  177. return FALSE;
  178. }
  179. pList = &pWapiInfo->wapiCamUsedList;
  180. while(pList->Flink != &pWapiInfo->wapiCamUsedList)
  181. {
  182. pEntry = (PRT_WAPI_CAM_ENTRY)pList->Flink;
  183. if(PlatformCompareMemory(pPeerMac,pEntry->PeerMacAddr, ETHER_ADDRLEN)== 0
  184. && keyid == pEntry->keyidx)
  185. {
  186. RTRemoveEntryList(pList);
  187. RTInsertHeadList(&pWapiInfo->wapiCamIdleList, pList);
  188. return pEntry->entry_idx;
  189. }
  190. pList = pList->Flink;
  191. }
  192. return 0;
  193. */
  194. }
  195. void
  196. WapiResetAllCamEntry(_adapter *padapter)
  197. {
  198. PRT_WAPI_T pWapiInfo;
  199. int i;
  200. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  201. pWapiInfo = &padapter->wapiInfo;
  202. for (i=0;i<WAPI_CAM_ENTRY_NUM;i++)
  203. {
  204. _rtw_memset(pWapiInfo->wapiCamEntry[i].PeerMacAddr, 0, ETH_ALEN);
  205. pWapiInfo->wapiCamEntry[i].IsUsed = 0;
  206. pWapiInfo->wapiCamEntry[i].keyidx = 2; //invalid
  207. pWapiInfo->wapiCamEntry[i].entry_idx = 4+i*2;
  208. }
  209. WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__);
  210. return;
  211. }
  212. u8 WapiWriteOneCamEntry(
  213. _adapter *padapter,
  214. u8 *pMacAddr,
  215. u8 KeyId,
  216. u8 EntryId,
  217. u8 EncAlg,
  218. u8 bGroupKey,
  219. u8 *pKey
  220. )
  221. {
  222. u8 retVal = 0;
  223. u16 usConfig = 0;
  224. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  225. if(EntryId >= 32)
  226. {
  227. WAPI_TRACE(WAPI_ERR, "<=== CamAddOneEntry(): ulKeyId exceed!\n");
  228. return retVal;
  229. }
  230. usConfig=usConfig|(0x01<<15)|((u16)(EncAlg)<<2)|(KeyId);
  231. if(EncAlg == _SMS4_ )
  232. {
  233. if(bGroupKey == 1)
  234. usConfig |= (0x01<<6);
  235. if((EntryId % 2)==1) // ==0 sec key; == 1mic key
  236. usConfig |= (0x01<<5);
  237. }
  238. write_cam(padapter, EntryId, usConfig, pMacAddr, pKey);
  239. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  240. return 1;
  241. }
  242. void rtw_wapi_init(_adapter *padapter)
  243. {
  244. PRT_WAPI_T pWapiInfo;
  245. int i;
  246. WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__);
  247. RT_ASSERT_RET(padapter);
  248. if (!padapter->WapiSupport)
  249. {
  250. WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __FUNCTION__);
  251. return;
  252. }
  253. pWapiInfo = &padapter->wapiInfo;
  254. pWapiInfo->bWapiEnable = false;
  255. //Init BKID List
  256. INIT_LIST_HEAD(&pWapiInfo->wapiBKIDIdleList);
  257. INIT_LIST_HEAD(&pWapiInfo->wapiBKIDStoreList);
  258. for(i=0;i<WAPI_MAX_BKID_NUM;i++)
  259. {
  260. list_add_tail(&pWapiInfo->wapiBKID[i].list, &pWapiInfo->wapiBKIDIdleList);
  261. }
  262. //Init STA List
  263. INIT_LIST_HEAD(&pWapiInfo->wapiSTAIdleList);
  264. INIT_LIST_HEAD(&pWapiInfo->wapiSTAUsedList);
  265. for(i=0;i<WAPI_MAX_STAINFO_NUM;i++)
  266. {
  267. list_add_tail(&pWapiInfo->wapiSta[i].list, &pWapiInfo->wapiSTAIdleList);
  268. }
  269. for (i=0;i<WAPI_CAM_ENTRY_NUM;i++)
  270. {
  271. pWapiInfo->wapiCamEntry[i].IsUsed = 0;
  272. pWapiInfo->wapiCamEntry[i].keyidx = 2; //invalid
  273. pWapiInfo->wapiCamEntry[i].entry_idx = 4+i*2;
  274. }
  275. WAPI_TRACE(WAPI_INIT, "<========== %s\n", __FUNCTION__);
  276. }
  277. void rtw_wapi_free(_adapter *padapter)
  278. {
  279. WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__);
  280. RT_ASSERT_RET(padapter);
  281. if (!padapter->WapiSupport)
  282. {
  283. WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __FUNCTION__);
  284. return;
  285. }
  286. WapiFreeAllStaInfo(padapter);
  287. WAPI_TRACE(WAPI_INIT, "<========== %s\n", __FUNCTION__);
  288. }
  289. void rtw_wapi_disable_tx(_adapter *padapter)
  290. {
  291. WAPI_TRACE(WAPI_INIT, "===========> %s\n", __FUNCTION__);
  292. RT_ASSERT_RET(padapter);
  293. if (!padapter->WapiSupport)
  294. {
  295. WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __FUNCTION__);
  296. return;
  297. }
  298. padapter->wapiInfo.wapiTxMsk.bTxEnable = false;
  299. padapter->wapiInfo.wapiTxMsk.bSet = false;
  300. WAPI_TRACE(WAPI_INIT, "<========== %s\n", __FUNCTION__);
  301. }
  302. u8 rtw_wapi_is_wai_packet(_adapter* padapter,u8 *pkt_data)
  303. {
  304. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  305. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  306. struct security_priv *psecuritypriv = &padapter->securitypriv;
  307. PRT_WAPI_STA_INFO pWapiSta = NULL;
  308. u8 WaiPkt = 0, *pTaddr, bFind = false;
  309. u8 Offset_TypeWAI = 0 ; // (mac header len + llc length)
  310. WAPI_TRACE(WAPI_TX|WAPI_RX, "===========> %s\n", __FUNCTION__);
  311. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  312. {
  313. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  314. return 0;
  315. }
  316. Offset_TypeWAI = 24 + 6 ;
  317. //YJ,add,091103. Data frame may also have skb->data[30]=0x88 and skb->data[31]=0xb4.
  318. if ((pkt_data[1]&0x40) !=0)
  319. {
  320. DBG_871X("data is privacy \n");
  321. return 0;
  322. }
  323. pTaddr = GetAddr2Ptr(pkt_data);
  324. if(list_empty(&pWapiInfo->wapiSTAUsedList)){
  325. bFind = false;
  326. }else{
  327. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list){
  328. if (_rtw_memcmp(pTaddr, pWapiSta->PeerMacAddr, 6) == _TRUE) {
  329. bFind = true;
  330. break;
  331. }
  332. }
  333. }
  334. WAPI_TRACE(WAPI_TX|WAPI_RX, "%s: bFind=%d pTaddr="MAC_FMT"\n", __FUNCTION__, bFind, MAC_ARG(pTaddr));
  335. if (pkt_data[0] == WIFI_QOS_DATA_TYPE)
  336. {
  337. Offset_TypeWAI += 2;
  338. }
  339. // 88b4?
  340. if( (pkt_data[Offset_TypeWAI]==0x88) && (pkt_data[Offset_TypeWAI+1]==0xb4) ){
  341. WaiPkt = pkt_data[Offset_TypeWAI+5];
  342. psecuritypriv->hw_decrypted = _TRUE;
  343. }else{
  344. WAPI_TRACE(WAPI_TX|WAPI_RX, "%s(): non wai packet\n",__FUNCTION__);
  345. }
  346. WAPI_TRACE(WAPI_TX|WAPI_RX, "%s(): Recvd WAI frame. IsWAIPkt(%d)\n",__FUNCTION__, WaiPkt);
  347. return WaiPkt;
  348. }
  349. void rtw_wapi_update_info(_adapter *padapter, union recv_frame *precv_frame)
  350. {
  351. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  352. struct recv_frame_hdr *precv_hdr;
  353. u8 *ptr;
  354. u8 *pTA;
  355. u8 *pRecvPN;
  356. WAPI_TRACE(WAPI_RX, "===========> %s\n", __FUNCTION__);
  357. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  358. {
  359. WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  360. return;
  361. }
  362. precv_hdr = &precv_frame->u.hdr;
  363. ptr = precv_hdr->rx_data;
  364. if (precv_hdr->attrib.qos == 1)
  365. {
  366. precv_hdr->UserPriority = GetTid(ptr);
  367. }
  368. else
  369. {
  370. precv_hdr->UserPriority = 0;
  371. }
  372. pTA = GetAddr2Ptr(ptr);
  373. _rtw_memcpy((u8 *)precv_hdr->WapiSrcAddr, pTA, 6);
  374. pRecvPN = ptr + precv_hdr->attrib.hdrlen + 2;
  375. _rtw_memcpy((u8 *)precv_hdr->WapiTempPN, pRecvPN, 16);
  376. WAPI_TRACE(WAPI_RX, "<========== %s\n", __FUNCTION__);
  377. }
  378. /****************************************************************************
  379. TRUE-----------------Drop
  380. FALSE---------------- handle
  381. add to support WAPI to N-mode
  382. *****************************************************************************/
  383. u8 rtw_wapi_check_for_drop(
  384. _adapter *padapter,
  385. union recv_frame *precv_frame
  386. )
  387. {
  388. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  389. u8 *pLastRecvPN = NULL;
  390. u8 bFind = false;
  391. PRT_WAPI_STA_INFO pWapiSta = NULL;
  392. u8 bDrop = false;
  393. struct recv_frame_hdr *precv_hdr = &precv_frame->u.hdr;
  394. u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  395. u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  396. u8 *ptr = precv_frame->u.hdr.rx_data;
  397. int i;
  398. WAPI_TRACE(WAPI_RX, "===========> %s\n", __FUNCTION__);
  399. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  400. {
  401. WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  402. return false;
  403. }
  404. if(precv_hdr->bIsWaiPacket !=0)
  405. {
  406. if(precv_hdr->bIsWaiPacket== 0x8)
  407. {
  408. DBG_871X("rtw_wapi_check_for_drop: dump packet \n");
  409. for(i=0;i<50;i++)
  410. {
  411. DBG_871X("%02X ",ptr[i]);
  412. if((i+1) %8 ==0)
  413. DBG_871X("\n");
  414. }
  415. DBG_871X("\n rtw_wapi_check_for_drop: dump packet \n");
  416. for(i=0;i<16;i++)
  417. {
  418. if(ptr[i+27] !=0)
  419. break;
  420. }
  421. if(i== 16)
  422. {
  423. WAPI_TRACE(WAPI_RX,"rtw_wapi_check_for_drop: drop with zero BKID \n");
  424. return true;
  425. }
  426. else
  427. {
  428. return false;
  429. }
  430. }
  431. else
  432. return false;
  433. }
  434. if(list_empty(&pWapiInfo->wapiSTAUsedList)){
  435. bFind = false;
  436. }else{
  437. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
  438. if (_rtw_memcmp(precv_hdr->WapiSrcAddr, pWapiSta->PeerMacAddr, ETH_ALEN) == _TRUE) {
  439. bFind = true;
  440. break;
  441. }
  442. }
  443. }
  444. WAPI_TRACE(WAPI_RX, "%s: bFind=%d prxb->WapiSrcAddr="MAC_FMT"\n", __FUNCTION__, bFind, MAC_ARG(precv_hdr->WapiSrcAddr));
  445. if(bFind)
  446. {
  447. if(IS_MCAST(precv_hdr->attrib.ra))
  448. {
  449. WAPI_TRACE(WAPI_RX,"rtw_wapi_check_for_drop: multicast case \n");
  450. pLastRecvPN = pWapiSta->lastRxMulticastPN;
  451. }
  452. else
  453. {
  454. WAPI_TRACE(WAPI_RX,"rtw_wapi_check_for_drop: unicast case \n");
  455. switch(precv_hdr->UserPriority)
  456. {
  457. case 0:
  458. case 3:
  459. pLastRecvPN = pWapiSta->lastRxUnicastPNBEQueue;
  460. break;
  461. case 1:
  462. case 2:
  463. pLastRecvPN = pWapiSta->lastRxUnicastPNBKQueue;
  464. break;
  465. case 4:
  466. case 5:
  467. pLastRecvPN = pWapiSta->lastRxUnicastPNVIQueue;
  468. break;
  469. case 6:
  470. case 7:
  471. pLastRecvPN = pWapiSta->lastRxUnicastPNVOQueue;
  472. break;
  473. default:
  474. WAPI_TRACE(WAPI_ERR,"%s: Unknown TID \n",__FUNCTION__);
  475. break;
  476. }
  477. }
  478. if(!WapiComparePN(precv_hdr->WapiTempPN,pLastRecvPN))
  479. {
  480. WAPI_TRACE(WAPI_RX,"%s: Equal PN!!\n",__FUNCTION__);
  481. if(IS_MCAST(precv_hdr->attrib.ra))
  482. _rtw_memcpy(pLastRecvPN,WapiAEMultiCastPNInitialValueSrc,16);
  483. else
  484. _rtw_memcpy(pLastRecvPN,WapiAEPNInitialValueSrc,16);
  485. bDrop = true;
  486. }
  487. else
  488. {
  489. _rtw_memcpy(pLastRecvPN,precv_hdr->WapiTempPN,16);
  490. }
  491. }
  492. WAPI_TRACE(WAPI_RX, "<========== %s\n", __FUNCTION__);
  493. return bDrop;
  494. }
  495. void rtw_build_probe_resp_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib)
  496. {
  497. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  498. u8 WapiIELength = 0;
  499. WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__);
  500. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  501. {
  502. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __FUNCTION__);
  503. return;
  504. }
  505. WapiSetIE(padapter);
  506. WapiIELength = pWapiInfo->wapiIELength;
  507. pframe[0] = _WAPI_IE_;
  508. pframe[1] = WapiIELength;
  509. _rtw_memcpy(pframe+2, pWapiInfo->wapiIE, WapiIELength);
  510. pframe += WapiIELength+2;
  511. pattrib->pktlen += WapiIELength+2;
  512. WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__);
  513. }
  514. void rtw_build_beacon_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib)
  515. {
  516. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  517. u8 WapiIELength = 0;
  518. WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__);
  519. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  520. {
  521. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __FUNCTION__);
  522. return;
  523. }
  524. WapiSetIE(padapter);
  525. WapiIELength = pWapiInfo->wapiIELength;
  526. pframe[0] = _WAPI_IE_;
  527. pframe[1] = WapiIELength;
  528. _rtw_memcpy(pframe+2, pWapiInfo->wapiIE, WapiIELength);
  529. pframe += WapiIELength+2;
  530. pattrib->pktlen += WapiIELength+2;
  531. WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__);
  532. }
  533. void rtw_build_assoc_req_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib)
  534. {
  535. PRT_WAPI_BKID pWapiBKID;
  536. u16 bkidNum;
  537. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  538. u8 WapiIELength = 0;
  539. WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__);
  540. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  541. {
  542. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __FUNCTION__);
  543. return;
  544. }
  545. WapiSetIE(padapter);
  546. WapiIELength = pWapiInfo->wapiIELength;
  547. bkidNum = 0;
  548. if(!list_empty(&(pWapiInfo->wapiBKIDStoreList))){
  549. list_for_each_entry(pWapiBKID, &pWapiInfo->wapiBKIDStoreList, list) {
  550. bkidNum ++;
  551. _rtw_memcpy(pWapiInfo->wapiIE+WapiIELength+2, pWapiBKID->bkid,16);
  552. WapiIELength += 16;
  553. }
  554. }
  555. _rtw_memcpy(pWapiInfo->wapiIE+WapiIELength, &bkidNum, 2);
  556. WapiIELength += 2;
  557. pframe[0] = _WAPI_IE_;
  558. pframe[1] = WapiIELength;
  559. _rtw_memcpy(pframe+2, pWapiInfo->wapiIE, WapiIELength);
  560. pframe += WapiIELength+2;
  561. pattrib->pktlen += WapiIELength+2;
  562. WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__);
  563. }
  564. void rtw_wapi_on_assoc_ok(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  565. {
  566. PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo);
  567. PRT_WAPI_STA_INFO pWapiSta;
  568. u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  569. //u8 WapiASUEPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  570. u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  571. WAPI_TRACE(WAPI_MLME, "===========> %s\n", __FUNCTION__);
  572. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  573. {
  574. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  575. return;
  576. }
  577. pWapiSta =(PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAIdleList.next, RT_WAPI_STA_INFO, list);
  578. list_del_init(&pWapiSta->list);
  579. list_add_tail(&pWapiSta->list, &pWapiInfo->wapiSTAUsedList);
  580. _rtw_memcpy(pWapiSta->PeerMacAddr,padapter->mlmeextpriv.mlmext_info.network.MacAddress,6);
  581. _rtw_memcpy(pWapiSta->lastRxMulticastPN, WapiAEMultiCastPNInitialValueSrc, 16);
  582. _rtw_memcpy(pWapiSta->lastRxUnicastPN, WapiAEPNInitialValueSrc, 16);
  583. //For chenk PN error with Qos Data after s3: add by ylb 20111114
  584. _rtw_memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiAEPNInitialValueSrc,16);
  585. _rtw_memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiAEPNInitialValueSrc,16);
  586. _rtw_memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiAEPNInitialValueSrc,16);
  587. _rtw_memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiAEPNInitialValueSrc,16);
  588. WAPI_TRACE(WAPI_MLME, "<========== %s\n", __FUNCTION__);
  589. }
  590. void rtw_wapi_return_one_sta_info(_adapter *padapter, u8 *MacAddr)
  591. {
  592. PRT_WAPI_T pWapiInfo;
  593. PRT_WAPI_STA_INFO pWapiStaInfo = NULL;
  594. PRT_WAPI_BKID pWapiBkid = NULL;
  595. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  596. pWapiInfo = &padapter->wapiInfo;
  597. WAPI_TRACE(WAPI_API, "==========> %s\n", __FUNCTION__);
  598. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  599. {
  600. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  601. return;
  602. }
  603. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE))
  604. {
  605. while(!list_empty(&(pWapiInfo->wapiBKIDStoreList)))
  606. {
  607. pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDStoreList.next, RT_WAPI_BKID, list);
  608. list_del_init(&pWapiBkid->list);
  609. _rtw_memset(pWapiBkid->bkid,0,16);
  610. list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDIdleList);
  611. }
  612. }
  613. WAPI_TRACE(WAPI_API, " %s: after clear bkid \n", __FUNCTION__);
  614. //Remove STA info
  615. if(list_empty(&(pWapiInfo->wapiSTAUsedList))){
  616. WAPI_TRACE(WAPI_API, " %s: wapiSTAUsedList is null \n", __FUNCTION__);
  617. return;
  618. }else{
  619. WAPI_TRACE(WAPI_API, " %s: wapiSTAUsedList is not null \n", __FUNCTION__);
  620. #if 0
  621. pWapiStaInfo=(PRT_WAPI_STA_INFO)list_entry((pWapiInfo->wapiSTAUsedList.next),RT_WAPI_STA_INFO,list);
  622. list_for_each_entry(pWapiStaInfo, &(pWapiInfo->wapiSTAUsedList), list) {
  623. DBG_871X("MAC Addr %02x-%02x-%02x-%02x-%02x-%02x \n",MacAddr[0],MacAddr[1],MacAddr[2],MacAddr[3],MacAddr[4],MacAddr[5]);
  624. DBG_871X("peer Addr %02x-%02x-%02x-%02x-%02x-%02x \n",pWapiStaInfo->PeerMacAddr[0],pWapiStaInfo->PeerMacAddr[1],pWapiStaInfo->PeerMacAddr[2],pWapiStaInfo->PeerMacAddr[3],pWapiStaInfo->PeerMacAddr[4],pWapiStaInfo->PeerMacAddr[5]);
  625. if(pWapiStaInfo == NULL)
  626. {
  627. WAPI_TRACE(WAPI_API, " %s: pWapiStaInfo == NULL Case \n", __FUNCTION__);
  628. return;
  629. }
  630. if(pWapiStaInfo->PeerMacAddr == NULL)
  631. {
  632. WAPI_TRACE(WAPI_API, " %s: pWapiStaInfo->PeerMacAddr == NULL Case \n", __FUNCTION__);
  633. return;
  634. }
  635. if(MacAddr == NULL)
  636. {
  637. WAPI_TRACE(WAPI_API, " %s: MacAddr == NULL Case \n", __FUNCTION__);
  638. return;
  639. }
  640. if (_rtw_memcmp(pWapiStaInfo->PeerMacAddr, MacAddr, ETH_ALEN) == _TRUE) {
  641. pWapiStaInfo->bAuthenticateInProgress = false;
  642. pWapiStaInfo->bSetkeyOk = false;
  643. _rtw_memset(pWapiStaInfo->PeerMacAddr,0,ETH_ALEN);
  644. list_del_init(&pWapiStaInfo->list);
  645. list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList);
  646. break;
  647. }
  648. }
  649. #endif
  650. while(!list_empty(&(pWapiInfo->wapiSTAUsedList)))
  651. {
  652. pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAUsedList.next, RT_WAPI_STA_INFO, list);
  653. DBG_871X("peer Addr %02x-%02x-%02x-%02x-%02x-%02x \n",pWapiStaInfo->PeerMacAddr[0],pWapiStaInfo->PeerMacAddr[1],pWapiStaInfo->PeerMacAddr[2],pWapiStaInfo->PeerMacAddr[3],pWapiStaInfo->PeerMacAddr[4],pWapiStaInfo->PeerMacAddr[5]);
  654. list_del_init(&pWapiStaInfo->list);
  655. memset(pWapiStaInfo->PeerMacAddr,0,ETH_ALEN);
  656. pWapiStaInfo->bSetkeyOk = 0;
  657. list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList);
  658. }
  659. }
  660. WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__);
  661. return;
  662. }
  663. void rtw_wapi_return_all_sta_info(_adapter *padapter)
  664. {
  665. PRT_WAPI_T pWapiInfo;
  666. PRT_WAPI_STA_INFO pWapiStaInfo;
  667. PRT_WAPI_BKID pWapiBkid;
  668. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  669. pWapiInfo = &padapter->wapiInfo;
  670. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  671. {
  672. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  673. return;
  674. }
  675. //Sta Info List
  676. while(!list_empty(&(pWapiInfo->wapiSTAUsedList)))
  677. {
  678. pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAUsedList.next, RT_WAPI_STA_INFO, list);
  679. list_del_init(&pWapiStaInfo->list);
  680. memset(pWapiStaInfo->PeerMacAddr,0,ETH_ALEN);
  681. pWapiStaInfo->bSetkeyOk = 0;
  682. list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList);
  683. }
  684. //BKID List
  685. while(!list_empty(&(pWapiInfo->wapiBKIDStoreList)))
  686. {
  687. pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDStoreList.next, RT_WAPI_BKID, list);
  688. list_del_init(&pWapiBkid->list);
  689. memset(pWapiBkid->bkid,0,16);
  690. list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDIdleList);
  691. }
  692. WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__);
  693. }
  694. void rtw_wapi_clear_cam_entry(_adapter *padapter, u8 *pMacAddr)
  695. {
  696. u8 UcIndex = 0;
  697. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  698. if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable))
  699. {
  700. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  701. return;
  702. }
  703. UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 0, 0);
  704. if(UcIndex != 0xff){
  705. //CAM_mark_invalid(Adapter, UcIndex);
  706. CAM_empty_entry(padapter, UcIndex);
  707. }
  708. UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 1, 0);
  709. if(UcIndex != 0xff){
  710. //CAM_mark_invalid(Adapter, UcIndex);
  711. CAM_empty_entry(padapter, UcIndex);
  712. }
  713. UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 0, 1);
  714. if(UcIndex != 0xff){
  715. //CAM_mark_invalid(Adapter, UcIndex);
  716. CAM_empty_entry(padapter, UcIndex);
  717. }
  718. UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 1, 1);
  719. if(UcIndex != 0xff){
  720. //CAM_mark_invalid(padapter, UcIndex);
  721. CAM_empty_entry(padapter, UcIndex);
  722. }
  723. WAPI_TRACE(WAPI_API, "<========== %s\n", __FUNCTION__);
  724. }
  725. void rtw_wapi_clear_all_cam_entry(_adapter *padapter)
  726. {
  727. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  728. if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable))
  729. {
  730. WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  731. return;
  732. }
  733. invalidate_cam_all(padapter); // is this ok?
  734. WapiResetAllCamEntry(padapter);
  735. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  736. }
  737. void rtw_wapi_set_key(_adapter *padapter, RT_WAPI_KEY *pWapiKey, RT_WAPI_STA_INFO *pWapiSta, u8 bGroupKey, u8 bUseDefaultKey)
  738. {
  739. PRT_WAPI_T pWapiInfo = &padapter->wapiInfo;
  740. u8 *pMacAddr = pWapiSta->PeerMacAddr;
  741. u32 EntryId = 0;
  742. BOOLEAN IsPairWise = false ;
  743. u8 EncAlgo;
  744. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  745. if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable))
  746. {
  747. WAPI_TRACE(WAPI_API, "<========== %s, WAPI not supported or not enabled!\n", __FUNCTION__);
  748. return;
  749. }
  750. EncAlgo = _SMS4_;
  751. //For Tx bc/mc pkt,use defualt key entry
  752. if(bUseDefaultKey)
  753. {
  754. // when WAPI update key, keyid will be 0 or 1 by turns.
  755. if (pWapiKey->keyId == 0)
  756. EntryId = 0;
  757. else
  758. EntryId = 2;
  759. }
  760. else
  761. {
  762. // tx/rx unicast pkt, or rx broadcast, find the key entry by peer's MacAddr
  763. EntryId = WapiGetEntryForCamWrite(padapter,pMacAddr,pWapiKey->keyId,bGroupKey);
  764. }
  765. if(EntryId == 0xff){
  766. WAPI_TRACE(WAPI_API, "===>No entry for WAPI setkey! !!\n");
  767. return;
  768. }
  769. //EntryId is also used to diff Sec key and Mic key
  770. //Sec Key
  771. WapiWriteOneCamEntry(padapter,
  772. pMacAddr,
  773. pWapiKey->keyId, //keyid
  774. EntryId, //entry
  775. EncAlgo, //type
  776. bGroupKey, //pairwise or group key
  777. pWapiKey->dataKey);
  778. //MIC key
  779. WapiWriteOneCamEntry(padapter,
  780. pMacAddr,
  781. pWapiKey->keyId, //keyid
  782. EntryId+1, //entry
  783. EncAlgo, //type
  784. bGroupKey, //pairwise or group key
  785. pWapiKey->micKey);
  786. WAPI_TRACE(WAPI_API, "Set Wapi Key :KeyId:%d,EntryId:%d,PairwiseKey:%d.\n",pWapiKey->keyId,EntryId,!bGroupKey);
  787. WAPI_TRACE(WAPI_API, "===========> %s\n", __FUNCTION__);
  788. }
  789. #if 0
  790. //YJ,test,091013
  791. void wapi_test_set_key(struct _adapter *padapter, u8* buf)
  792. { /*Data: keyType(1) + bTxEnable(1) + bAuthenticator(1) + bUpdate(1) + PeerAddr(6) + DataKey(16) + MicKey(16) + KeyId(1)*/
  793. PRT_WAPI_T pWapiInfo = &padapter->wapiInfo;
  794. PRT_WAPI_BKID pWapiBkid;
  795. PRT_WAPI_STA_INFO pWapiSta;
  796. u8 data[43];
  797. bool bTxEnable;
  798. bool bUpdate;
  799. bool bAuthenticator;
  800. u8 PeerAddr[6];
  801. u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  802. u8 WapiASUEPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  803. u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  804. WAPI_TRACE(WAPI_INIT, "===========>%s\n", __FUNCTION__);
  805. if (!padapter->WapiSupport){
  806. return;
  807. }
  808. copy_from_user(data, buf, 43);
  809. bTxEnable = data[1];
  810. bAuthenticator = data[2];
  811. bUpdate = data[3];
  812. memcpy(PeerAddr,data+4,6);
  813. if(data[0] == 0x3){
  814. if(!list_empty(&(pWapiInfo->wapiBKIDIdleList))){
  815. pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDIdleList.next, RT_WAPI_BKID, list);
  816. list_del_init(&pWapiBkid->list);
  817. memcpy(pWapiBkid->bkid, data+10, 16);
  818. WAPI_DATA(WAPI_INIT, "SetKey - BKID", pWapiBkid->bkid, 16);
  819. list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDStoreList);
  820. }
  821. }else{
  822. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
  823. if(!memcmp(pWapiSta->PeerMacAddr,PeerAddr,6)){
  824. pWapiSta->bAuthenticatorInUpdata = false;
  825. switch(data[0]){
  826. case 1: //usk
  827. if(bAuthenticator){ //authenticator
  828. memcpy(pWapiSta->lastTxUnicastPN,WapiAEPNInitialValueSrc,16);
  829. if(!bUpdate) { //first
  830. WAPI_TRACE(WAPI_INIT,"AE fisrt set usk \n");
  831. pWapiSta->wapiUsk.bSet = true;
  832. memcpy(pWapiSta->wapiUsk.dataKey,data+10,16);
  833. memcpy(pWapiSta->wapiUsk.micKey,data+26,16);
  834. pWapiSta->wapiUsk.keyId = *(data+42);
  835. pWapiSta->wapiUsk.bTxEnable = true;
  836. WAPI_DATA(WAPI_INIT, "SetKey - AE USK Data Key", pWapiSta->wapiUsk.dataKey, 16);
  837. WAPI_DATA(WAPI_INIT, "SetKey - AE USK Mic Key", pWapiSta->wapiUsk.micKey, 16);
  838. }
  839. else //update
  840. {
  841. WAPI_TRACE(WAPI_INIT, "AE update usk \n");
  842. pWapiSta->wapiUskUpdate.bSet = true;
  843. pWapiSta->bAuthenticatorInUpdata = true;
  844. memcpy(pWapiSta->wapiUskUpdate.dataKey,data+10,16);
  845. memcpy(pWapiSta->wapiUskUpdate.micKey,data+26,16);
  846. memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiASUEPNInitialValueSrc,16);
  847. memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiASUEPNInitialValueSrc,16);
  848. memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiASUEPNInitialValueSrc,16);
  849. memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiASUEPNInitialValueSrc,16);
  850. memcpy(pWapiSta->lastRxUnicastPN,WapiASUEPNInitialValueSrc,16);
  851. pWapiSta->wapiUskUpdate.keyId = *(data+42);
  852. pWapiSta->wapiUskUpdate.bTxEnable = true;
  853. }
  854. }
  855. else{
  856. if(!bUpdate){
  857. WAPI_TRACE(WAPI_INIT,"ASUE fisrt set usk \n");
  858. if(bTxEnable){
  859. pWapiSta->wapiUsk.bTxEnable = true;
  860. memcpy(pWapiSta->lastTxUnicastPN,WapiASUEPNInitialValueSrc,16);
  861. }else{
  862. pWapiSta->wapiUsk.bSet = true;
  863. memcpy(pWapiSta->wapiUsk.dataKey,data+10,16);
  864. memcpy(pWapiSta->wapiUsk.micKey,data+26,16);
  865. pWapiSta->wapiUsk.keyId = *(data+42);
  866. pWapiSta->wapiUsk.bTxEnable = false;
  867. }
  868. }else{
  869. WAPI_TRACE(WAPI_INIT,"ASUE update usk \n");
  870. if(bTxEnable){
  871. pWapiSta->wapiUskUpdate.bTxEnable = true;
  872. if(pWapiSta->wapiUskUpdate.bSet){
  873. memcpy(pWapiSta->wapiUsk.dataKey,pWapiSta->wapiUskUpdate.dataKey,16);
  874. memcpy(pWapiSta->wapiUsk.micKey,pWapiSta->wapiUskUpdate.micKey,16);
  875. pWapiSta->wapiUsk.keyId=pWapiSta->wapiUskUpdate.keyId;
  876. memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiASUEPNInitialValueSrc,16);
  877. memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiASUEPNInitialValueSrc,16);
  878. memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiASUEPNInitialValueSrc,16);
  879. memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiASUEPNInitialValueSrc,16);
  880. memcpy(pWapiSta->lastRxUnicastPN,WapiASUEPNInitialValueSrc,16);
  881. pWapiSta->wapiUskUpdate.bTxEnable = false;
  882. pWapiSta->wapiUskUpdate.bSet = false;
  883. }
  884. memcpy(pWapiSta->lastTxUnicastPN,WapiASUEPNInitialValueSrc,16);
  885. }else{
  886. pWapiSta->wapiUskUpdate.bSet = true;
  887. memcpy(pWapiSta->wapiUskUpdate.dataKey,data+10,16);
  888. memcpy(pWapiSta->wapiUskUpdate.micKey,data+26,16);
  889. pWapiSta->wapiUskUpdate.keyId = *(data+42);
  890. pWapiSta->wapiUskUpdate.bTxEnable = false;
  891. }
  892. }
  893. }
  894. break;
  895. case 2: //msk
  896. if(bAuthenticator){ //authenticator
  897. pWapiInfo->wapiTxMsk.bSet = true;
  898. memcpy(pWapiInfo->wapiTxMsk.dataKey,data+10,16);
  899. memcpy(pWapiInfo->wapiTxMsk.micKey,data+26,16);
  900. pWapiInfo->wapiTxMsk.keyId = *(data+42);
  901. pWapiInfo->wapiTxMsk.bTxEnable = true;
  902. memcpy(pWapiInfo->lastTxMulticastPN,WapiAEMultiCastPNInitialValueSrc,16);
  903. if(!bUpdate){ //first
  904. WAPI_TRACE(WAPI_INIT, "AE fisrt set msk \n");
  905. if(!pWapiSta->bSetkeyOk)
  906. pWapiSta->bSetkeyOk = true;
  907. pWapiInfo->bFirstAuthentiateInProgress= false;
  908. }else{ //update
  909. WAPI_TRACE(WAPI_INIT,"AE update msk \n");
  910. }
  911. WAPI_DATA(WAPI_INIT, "SetKey - AE MSK Data Key", pWapiInfo->wapiTxMsk.dataKey, 16);
  912. WAPI_DATA(WAPI_INIT, "SetKey - AE MSK Mic Key", pWapiInfo->wapiTxMsk.micKey, 16);
  913. }
  914. else{
  915. if(!bUpdate){
  916. WAPI_TRACE(WAPI_INIT,"ASUE fisrt set msk \n");
  917. pWapiSta->wapiMsk.bSet = true;
  918. memcpy(pWapiSta->wapiMsk.dataKey,data+10,16);
  919. memcpy(pWapiSta->wapiMsk.micKey,data+26,16);
  920. pWapiSta->wapiMsk.keyId = *(data+42);
  921. pWapiSta->wapiMsk.bTxEnable = false;
  922. if(!pWapiSta->bSetkeyOk)
  923. pWapiSta->bSetkeyOk = true;
  924. pWapiInfo->bFirstAuthentiateInProgress= false;
  925. WAPI_DATA(WAPI_INIT, "SetKey - ASUE MSK Data Key", pWapiSta->wapiMsk.dataKey, 16);
  926. WAPI_DATA(WAPI_INIT, "SetKey - ASUE MSK Mic Key", pWapiSta->wapiMsk.micKey, 16);
  927. }else{
  928. WAPI_TRACE(WAPI_INIT,"ASUE update msk \n");
  929. pWapiSta->wapiMskUpdate.bSet = true;
  930. memcpy(pWapiSta->wapiMskUpdate.dataKey,data+10,16);
  931. memcpy(pWapiSta->wapiMskUpdate.micKey,data+26,16);
  932. pWapiSta->wapiMskUpdate.keyId = *(data+42);
  933. pWapiSta->wapiMskUpdate.bTxEnable = false;
  934. }
  935. }
  936. break;
  937. default:
  938. WAPI_TRACE(WAPI_ERR,"Unknown Flag \n");
  939. break;
  940. }
  941. }
  942. }
  943. }
  944. WAPI_TRACE(WAPI_INIT, "<===========%s\n", __FUNCTION__);
  945. }
  946. void wapi_test_init(struct _adapter *padapter)
  947. {
  948. u8 keybuf[100];
  949. u8 mac_addr[6]={0x00,0xe0,0x4c,0x72,0x04,0x70};
  950. u8 UskDataKey[16]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
  951. u8 UskMicKey[16]={0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f};
  952. u8 UskId = 0;
  953. u8 MskDataKey[16]={0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f};
  954. u8 MskMicKey[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f};
  955. u8 MskId = 0;
  956. WAPI_TRACE(WAPI_INIT, "===========>%s\n", __FUNCTION__);
  957. //Enable Wapi
  958. WAPI_TRACE(WAPI_INIT, "%s: Enable wapi!!!!\n", __FUNCTION__);
  959. padapter->wapiInfo.bWapiEnable = true;
  960. padapter->pairwise_key_type = KEY_TYPE_SMS4;
  961. ieee->group_key_type = KEY_TYPE_SMS4;
  962. padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
  963. padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN;
  964. //set usk
  965. WAPI_TRACE(WAPI_INIT, "%s: Set USK!!!!\n", __FUNCTION__);
  966. memset(keybuf,0,100);
  967. keybuf[0] = 1; //set usk
  968. keybuf[1] = 1; //enable tx
  969. keybuf[2] = 1; //AE
  970. keybuf[3] = 0; //not update
  971. memcpy(keybuf+4,mac_addr,6);
  972. memcpy(keybuf+10,UskDataKey,16);
  973. memcpy(keybuf+26,UskMicKey,16);
  974. keybuf[42]=UskId;
  975. wapi_test_set_key(padapter, keybuf);
  976. memset(keybuf,0,100);
  977. keybuf[0] = 1; //set usk
  978. keybuf[1] = 1; //enable tx
  979. keybuf[2] = 0; //AE
  980. keybuf[3] = 0; //not update
  981. memcpy(keybuf+4,mac_addr,6);
  982. memcpy(keybuf+10,UskDataKey,16);
  983. memcpy(keybuf+26,UskMicKey,16);
  984. keybuf[42]=UskId;
  985. wapi_test_set_key(padapter, keybuf);
  986. //set msk
  987. WAPI_TRACE(WAPI_INIT, "%s: Set MSK!!!!\n", __FUNCTION__);
  988. memset(keybuf,0,100);
  989. keybuf[0] = 2; //set msk
  990. keybuf[1] = 1; //Enable TX
  991. keybuf[2] = 1; //AE
  992. keybuf[3] = 0; //not update
  993. memcpy(keybuf+4,mac_addr,6);
  994. memcpy(keybuf+10,MskDataKey,16);
  995. memcpy(keybuf+26,MskMicKey,16);
  996. keybuf[42] = MskId;
  997. wapi_test_set_key(padapter, keybuf);
  998. memset(keybuf,0,100);
  999. keybuf[0] = 2; //set msk
  1000. keybuf[1] = 1; //Enable TX
  1001. keybuf[2] = 0; //AE
  1002. keybuf[3] = 0; //not update
  1003. memcpy(keybuf+4,mac_addr,6);
  1004. memcpy(keybuf+10,MskDataKey,16);
  1005. memcpy(keybuf+26,MskMicKey,16);
  1006. keybuf[42] = MskId;
  1007. wapi_test_set_key(padapter, keybuf);
  1008. WAPI_TRACE(WAPI_INIT, "<===========%s\n", __FUNCTION__);
  1009. }
  1010. #endif
  1011. void rtw_wapi_get_iv(_adapter *padapter,u8 *pRA, u8*IV)
  1012. {
  1013. PWLAN_HEADER_WAPI_EXTENSION pWapiExt = NULL;
  1014. PRT_WAPI_T pWapiInfo = &padapter->wapiInfo;
  1015. bool bPNOverflow = false;
  1016. bool bFindMatchPeer = false;
  1017. PRT_WAPI_STA_INFO pWapiSta = NULL;
  1018. pWapiExt = (PWLAN_HEADER_WAPI_EXTENSION)IV;
  1019. WAPI_DATA(WAPI_RX,"wapi_get_iv: pra",pRA,6);
  1020. if(IS_MCAST(pRA)){
  1021. if(!pWapiInfo->wapiTxMsk.bTxEnable){
  1022. WAPI_TRACE(WAPI_ERR,"%s: bTxEnable = 0!!\n",__FUNCTION__);
  1023. return;
  1024. }
  1025. if(pWapiInfo->wapiTxMsk.keyId <= 1){
  1026. pWapiExt->KeyIdx = pWapiInfo->wapiTxMsk.keyId;
  1027. pWapiExt->Reserved = 0;
  1028. bPNOverflow = WapiIncreasePN(pWapiInfo->lastTxMulticastPN, 1);
  1029. memcpy(pWapiExt->PN, pWapiInfo->lastTxMulticastPN, 16);
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(list_empty(&pWapiInfo->wapiSTAUsedList)){
  1035. WAPI_TRACE(WAPI_RX,"rtw_wapi_get_iv: list is empty \n");
  1036. _rtw_memset(IV,10,18);
  1037. return;
  1038. }
  1039. else{
  1040. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list){
  1041. WAPI_DATA(WAPI_RX,"rtw_wapi_get_iv: peermacaddr ",pWapiSta->PeerMacAddr,6);
  1042. if (_rtw_memcmp((u8*)pWapiSta->PeerMacAddr, pRA, 6) == _TRUE) {
  1043. bFindMatchPeer = true;
  1044. break;
  1045. }
  1046. }
  1047. WAPI_TRACE(WAPI_RX,"bFindMatchPeer: %d \n",bFindMatchPeer);
  1048. WAPI_DATA(WAPI_RX,"Addr",pRA,6);
  1049. if (bFindMatchPeer){
  1050. if((!pWapiSta->wapiUskUpdate.bTxEnable) && (!pWapiSta->wapiUsk.bTxEnable))
  1051. return;
  1052. if (pWapiSta->wapiUsk.keyId <= 1){
  1053. if(pWapiSta->wapiUskUpdate.bTxEnable)
  1054. pWapiExt->KeyIdx = pWapiSta->wapiUskUpdate.keyId;
  1055. else
  1056. pWapiExt->KeyIdx = pWapiSta->wapiUsk.keyId;
  1057. pWapiExt->Reserved = 0;
  1058. bPNOverflow = WapiIncreasePN(pWapiSta->lastTxUnicastPN, 2);
  1059. _rtw_memcpy(pWapiExt->PN, pWapiSta->lastTxUnicastPN, 16);
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. bool rtw_wapi_drop_for_key_absent(_adapter *padapter,u8 *pRA)
  1066. {
  1067. PRT_WAPI_T pWapiInfo = &padapter->wapiInfo;
  1068. bool bFindMatchPeer = false;
  1069. bool bDrop = false;
  1070. PRT_WAPI_STA_INFO pWapiSta = NULL;
  1071. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1072. WAPI_DATA(WAPI_RX,"rtw_wapi_drop_for_key_absent: ra ",pRA,6);
  1073. if(psecuritypriv->dot11PrivacyAlgrthm == _SMS4_)
  1074. {
  1075. if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable))
  1076. return true;
  1077. if(IS_MCAST(pRA)){
  1078. if(!pWapiInfo->wapiTxMsk.bTxEnable){
  1079. bDrop = true;
  1080. WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: multicast key is absent \n");
  1081. return bDrop;
  1082. }
  1083. }
  1084. else{
  1085. if(!list_empty(&pWapiInfo->wapiSTAUsedList)){
  1086. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list){
  1087. WAPI_DATA(WAPI_RX,"rtw_wapi_drop_for_key_absent: pWapiSta->PeerMacAddr ",pWapiSta->PeerMacAddr,6);
  1088. if (_rtw_memcmp(pRA, pWapiSta->PeerMacAddr, 6) == _TRUE){
  1089. bFindMatchPeer = true;
  1090. break;
  1091. }
  1092. }
  1093. if (bFindMatchPeer) {
  1094. if (!pWapiSta->wapiUsk.bTxEnable){
  1095. bDrop = true;
  1096. WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: unicast key is absent \n");
  1097. return bDrop;
  1098. }
  1099. }
  1100. else{
  1101. bDrop = true;
  1102. WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: no peer find \n");
  1103. return bDrop;
  1104. }
  1105. }
  1106. else{
  1107. bDrop = true;
  1108. WAPI_TRACE(WAPI_RX,"rtw_wapi_drop_for_key_absent: no sta exist \n");
  1109. return bDrop;
  1110. }
  1111. }
  1112. }
  1113. else
  1114. {
  1115. return bDrop;
  1116. }
  1117. return bDrop;
  1118. }
  1119. #endif