rtw_ioctl_set.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_IOCTL_SET_C_
  21. #include <drv_types.h>
  22. extern void indicate_wx_scan_complete_event(_adapter *padapter);
  23. #define IS_MAC_ADDRESS_BROADCAST(addr) \
  24. ( \
  25. ( (addr[0] == 0xff) && (addr[1] == 0xff) && \
  26. (addr[2] == 0xff) && (addr[3] == 0xff) && \
  27. (addr[4] == 0xff) && (addr[5] == 0xff) ) ? _TRUE : _FALSE \
  28. )
  29. u8 rtw_validate_ssid(NDIS_802_11_SSID *ssid)
  30. {
  31. u8 i;
  32. u8 ret=_TRUE;
  33. _func_enter_;
  34. if (ssid->SsidLength > 32) {
  35. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("ssid length >32\n"));
  36. ret= _FALSE;
  37. goto exit;
  38. }
  39. for(i = 0; i < ssid->SsidLength; i++)
  40. {
  41. //wifi, printable ascii code must be supported
  42. if(!( (ssid->Ssid[i] >= 0x20) && (ssid->Ssid[i] <= 0x7e) )){
  43. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("ssid has nonprintabl ascii\n"));
  44. ret= _FALSE;
  45. break;
  46. }
  47. }
  48. exit:
  49. _func_exit_;
  50. return ret;
  51. }
  52. u8 rtw_do_join(_adapter * padapter);
  53. u8 rtw_do_join(_adapter * padapter)
  54. {
  55. _irqL irqL;
  56. _list *plist, *phead;
  57. u8* pibss = NULL;
  58. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  59. _queue *queue = &(pmlmepriv->scanned_queue);
  60. u8 ret=_SUCCESS;
  61. _func_enter_;
  62. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  63. phead = get_list_head(queue);
  64. plist = get_next(phead);
  65. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("\n rtw_do_join: phead = %p; plist = %p \n\n\n", phead, plist));
  66. pmlmepriv->cur_network.join_res = -2;
  67. set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
  68. pmlmepriv->pscanned = plist;
  69. pmlmepriv->to_join = _TRUE;
  70. if(_rtw_queue_empty(queue)== _TRUE)
  71. {
  72. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  73. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  74. //when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty
  75. //we try to issue sitesurvey firstly
  76. if (pmlmepriv->LinkDetectInfo.bBusyTraffic ==_FALSE
  77. || rtw_to_roaming(padapter) > 0
  78. )
  79. {
  80. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("rtw_do_join(): site survey if scanned_queue is empty\n."));
  81. // submit site_survey_cmd
  82. if(_SUCCESS!=(ret=rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0)) ) {
  83. pmlmepriv->to_join = _FALSE;
  84. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("rtw_do_join(): site survey return error\n."));
  85. }
  86. }
  87. else
  88. {
  89. pmlmepriv->to_join = _FALSE;
  90. ret = _FAIL;
  91. }
  92. goto exit;
  93. }
  94. else
  95. {
  96. int select_ret;
  97. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  98. if((select_ret=rtw_select_and_join_from_scanned_queue(pmlmepriv))==_SUCCESS)
  99. {
  100. pmlmepriv->to_join = _FALSE;
  101. _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
  102. }
  103. else
  104. {
  105. if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)==_TRUE)
  106. {
  107. // submit createbss_cmd to change to a ADHOC_MASTER
  108. //pmlmepriv->lock has been acquired by caller...
  109. WLAN_BSSID_EX *pdev_network = &(padapter->registrypriv.dev_network);
  110. pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
  111. pibss = padapter->registrypriv.dev_network.MacAddress;
  112. _rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
  113. _rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
  114. rtw_update_registrypriv_dev_network(padapter);
  115. rtw_generate_random_ibss(pibss);
  116. if(rtw_createbss_cmd(padapter)!=_SUCCESS)
  117. {
  118. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("***Error=>do_goin: rtw_createbss_cmd status FAIL*** \n "));
  119. ret = _FALSE;
  120. goto exit;
  121. }
  122. pmlmepriv->to_join = _FALSE;
  123. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("***Error=> rtw_select_and_join_from_scanned_queue FAIL under STA_Mode*** \n "));
  124. }
  125. else
  126. {
  127. // can't associate ; reset under-linking
  128. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  129. #if 0
  130. if((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE))
  131. {
  132. if(_rtw_memcmp(pmlmepriv->cur_network.network.Ssid.Ssid, pmlmepriv->assoc_ssid.Ssid, pmlmepriv->assoc_ssid.SsidLength))
  133. {
  134. // for funk to do roaming
  135. // funk will reconnect, but funk will not sitesurvey before reconnect
  136. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("for funk to do roaming"));
  137. if(pmlmepriv->sitesurveyctrl.traffic_busy==_FALSE)
  138. rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
  139. }
  140. }
  141. #endif
  142. //when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue
  143. //we try to issue sitesurvey firstly
  144. if(pmlmepriv->LinkDetectInfo.bBusyTraffic==_FALSE
  145. || rtw_to_roaming(padapter) > 0
  146. )
  147. {
  148. //DBG_871X("rtw_do_join() when no desired bss in scanning queue \n");
  149. if( _SUCCESS!=(ret=rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0)) ){
  150. pmlmepriv->to_join = _FALSE;
  151. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("do_join(): site survey return error\n."));
  152. }
  153. }
  154. else
  155. {
  156. ret = _FAIL;
  157. pmlmepriv->to_join = _FALSE;
  158. }
  159. }
  160. }
  161. }
  162. exit:
  163. _func_exit_;
  164. return ret;
  165. }
  166. #ifdef PLATFORM_WINDOWS
  167. u8 rtw_pnp_set_power_wakeup(_adapter* padapter)
  168. {
  169. u8 res=_SUCCESS;
  170. _func_enter_;
  171. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("==>rtw_pnp_set_power_wakeup!!!\n"));
  172. res = rtw_setstandby_cmd(padapter, 0);
  173. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("<==rtw_pnp_set_power_wakeup!!!\n"));
  174. _func_exit_;
  175. return res;
  176. }
  177. u8 rtw_pnp_set_power_sleep(_adapter* padapter)
  178. {
  179. u8 res=_SUCCESS;
  180. _func_enter_;
  181. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("==>rtw_pnp_set_power_sleep!!!\n"));
  182. //DbgPrint("+rtw_pnp_set_power_sleep\n");
  183. res = rtw_setstandby_cmd(padapter, 1);
  184. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("<==rtw_pnp_set_power_sleep!!!\n"));
  185. _func_exit_;
  186. return res;
  187. }
  188. u8 rtw_set_802_11_reload_defaults(_adapter * padapter, NDIS_802_11_RELOAD_DEFAULTS reloadDefaults)
  189. {
  190. _func_enter_;
  191. switch( reloadDefaults)
  192. {
  193. case Ndis802_11ReloadWEPKeys:
  194. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("SetInfo OID_802_11_RELOAD_DEFAULTS : Ndis802_11ReloadWEPKeys\n"));
  195. break;
  196. }
  197. // SecClearAllKeys(Adapter);
  198. // 8711 CAM was not for En/Decrypt only
  199. // so, we can't clear all keys.
  200. // should we disable WPAcfg (ox0088) bit 1-2, instead of clear all CAM
  201. //TO DO...
  202. _func_exit_;
  203. return _TRUE;
  204. }
  205. u8 set_802_11_test(_adapter* padapter, NDIS_802_11_TEST *test)
  206. {
  207. u8 ret=_TRUE;
  208. _func_enter_;
  209. switch(test->Type)
  210. {
  211. case 1:
  212. NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->AuthenticationEvent, test->Length - 8);
  213. NdisMIndicateStatusComplete(padapter->hndis_adapter);
  214. break;
  215. case 2:
  216. NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->RssiTrigger, sizeof(NDIS_802_11_RSSI));
  217. NdisMIndicateStatusComplete(padapter->hndis_adapter);
  218. break;
  219. default:
  220. ret=_FALSE;
  221. break;
  222. }
  223. _func_exit_;
  224. return ret;
  225. }
  226. u8 rtw_set_802_11_pmkid(_adapter* padapter, NDIS_802_11_PMKID *pmkid)
  227. {
  228. u8 ret=_SUCCESS;
  229. return ret;
  230. }
  231. #endif
  232. u8 rtw_set_802_11_bssid(_adapter* padapter, u8 *bssid)
  233. {
  234. _irqL irqL;
  235. u8 status=_SUCCESS;
  236. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  237. _func_enter_;
  238. DBG_871X_LEVEL(_drv_always_, "set bssid:%pM\n", bssid);
  239. if ((bssid[0]==0x00 && bssid[1]==0x00 && bssid[2]==0x00 && bssid[3]==0x00 && bssid[4]==0x00 &&bssid[5]==0x00) ||
  240. (bssid[0]==0xFF && bssid[1]==0xFF && bssid[2]==0xFF && bssid[3]==0xFF && bssid[4]==0xFF &&bssid[5]==0xFF))
  241. {
  242. status = _FAIL;
  243. goto exit;
  244. }
  245. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  246. DBG_871X("Set BSSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
  247. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  248. goto handle_tkip_countermeasure;
  249. } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
  250. goto release_mlme_lock;
  251. }
  252. if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == _TRUE)
  253. {
  254. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("set_bssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
  255. if (_rtw_memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN) == _TRUE)
  256. {
  257. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)
  258. goto release_mlme_lock;//it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again.
  259. } else {
  260. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("Set BSSID not the same bssid\n"));
  261. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("set_bssid="MAC_FMT"\n", MAC_ARG(bssid) ));
  262. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("cur_bssid="MAC_FMT"\n", MAC_ARG(pmlmepriv->cur_network.network.MacAddress) ));
  263. rtw_disassoc_cmd(padapter, 0, _TRUE);
  264. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  265. rtw_indicate_disconnect(padapter);
  266. rtw_free_assoc_resources(padapter, 1);
  267. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
  268. _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  269. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  270. }
  271. }
  272. }
  273. handle_tkip_countermeasure:
  274. //should we add something here...?
  275. if((status=rtw_handle_tkip_countermeasure(padapter)) == _FAIL)
  276. goto release_mlme_lock;
  277. _rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
  278. pmlmepriv->assoc_by_bssid=_TRUE;
  279. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  280. pmlmepriv->to_join = _TRUE;
  281. }
  282. else {
  283. status = rtw_do_join(padapter);
  284. }
  285. release_mlme_lock:
  286. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  287. exit:
  288. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
  289. ("rtw_set_802_11_bssid: status=%d\n", status));
  290. _func_exit_;
  291. return status;
  292. }
  293. u8 rtw_set_802_11_ssid(_adapter* padapter, NDIS_802_11_SSID *ssid)
  294. {
  295. _irqL irqL;
  296. u8 status = _SUCCESS;
  297. u32 cur_time = 0;
  298. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  299. struct wlan_network *pnetwork = &pmlmepriv->cur_network;
  300. _func_enter_;
  301. DBG_871X_LEVEL(_drv_always_, "set ssid [%s] fw_state=0x%08x\n",
  302. ssid->Ssid, get_fwstate(pmlmepriv));
  303. if(padapter->hw_init_completed==_FALSE){
  304. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
  305. ("set_ssid: hw_init_completed==_FALSE=>exit!!!\n"));
  306. status = _FAIL;
  307. goto exit;
  308. }
  309. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  310. DBG_871X("Set SSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
  311. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  312. goto handle_tkip_countermeasure;
  313. } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
  314. goto release_mlme_lock;
  315. }
  316. if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == _TRUE)
  317. {
  318. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
  319. ("set_ssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
  320. if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
  321. (_rtw_memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength) == _TRUE))
  322. {
  323. if((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE))
  324. {
  325. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
  326. ("Set SSID is the same ssid, fw_state=0x%08x\n",
  327. get_fwstate(pmlmepriv)));
  328. if(rtw_is_same_ibss(padapter, pnetwork) == _FALSE)
  329. {
  330. //if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again
  331. rtw_disassoc_cmd(padapter, 0, _TRUE);
  332. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  333. rtw_indicate_disconnect(padapter);
  334. rtw_free_assoc_resources(padapter, 1);
  335. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  336. _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  337. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  338. }
  339. }
  340. else
  341. {
  342. goto release_mlme_lock;//it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again.
  343. }
  344. }
  345. #ifdef CONFIG_LPS
  346. else {
  347. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 1);
  348. }
  349. #endif
  350. }
  351. else
  352. {
  353. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("Set SSID not the same ssid\n"));
  354. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("set_ssid=[%s] len=0x%x\n", ssid->Ssid, (unsigned int)ssid->SsidLength));
  355. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("assoc_ssid=[%s] len=0x%x\n", pmlmepriv->assoc_ssid.Ssid, (unsigned int)pmlmepriv->assoc_ssid.SsidLength));
  356. rtw_disassoc_cmd(padapter, 0, _TRUE);
  357. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  358. rtw_indicate_disconnect(padapter);
  359. rtw_free_assoc_resources(padapter, 1);
  360. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  361. _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  362. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  363. }
  364. }
  365. }
  366. handle_tkip_countermeasure:
  367. if((status=rtw_handle_tkip_countermeasure(padapter)) == _FAIL)
  368. goto release_mlme_lock;
  369. #ifdef CONFIG_VALIDATE_SSID
  370. if (rtw_validate_ssid(ssid) == _FALSE) {
  371. status = _FAIL;
  372. goto release_mlme_lock;
  373. }
  374. #endif
  375. _rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
  376. pmlmepriv->assoc_by_bssid=_FALSE;
  377. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  378. pmlmepriv->to_join = _TRUE;
  379. }
  380. else {
  381. status = rtw_do_join(padapter);
  382. }
  383. release_mlme_lock:
  384. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  385. exit:
  386. RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
  387. ("-rtw_set_802_11_ssid: status=%d\n", status));
  388. _func_exit_;
  389. return status;
  390. }
  391. u8 rtw_set_802_11_infrastructure_mode(_adapter* padapter,
  392. NDIS_802_11_NETWORK_INFRASTRUCTURE networktype)
  393. {
  394. _irqL irqL;
  395. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  396. struct wlan_network *cur_network = &pmlmepriv->cur_network;
  397. NDIS_802_11_NETWORK_INFRASTRUCTURE* pold_state = &(cur_network->network.InfrastructureMode);
  398. _func_enter_;
  399. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_notice_,
  400. ("+rtw_set_802_11_infrastructure_mode: old=%d new=%d fw_state=0x%08x\n",
  401. *pold_state, networktype, get_fwstate(pmlmepriv)));
  402. if(*pold_state != networktype)
  403. {
  404. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  405. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,(" change mode!"));
  406. //DBG_871X("change mode, old_mode=%d, new_mode=%d, fw_state=0x%x\n", *pold_state, networktype, get_fwstate(pmlmepriv));
  407. if(*pold_state==Ndis802_11APMode)
  408. {
  409. //change to other mode from Ndis802_11APMode
  410. cur_network->join_res = -1;
  411. #ifdef CONFIG_NATIVEAP_MLME
  412. stop_ap_mode(padapter);
  413. #endif
  414. }
  415. if((check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE) ||(*pold_state==Ndis802_11IBSS))
  416. rtw_disassoc_cmd(padapter, 0, _TRUE);
  417. if((check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE) ||
  418. (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)== _TRUE) )
  419. rtw_free_assoc_resources(padapter, 1);
  420. if((*pold_state == Ndis802_11Infrastructure) ||(*pold_state == Ndis802_11IBSS))
  421. {
  422. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  423. {
  424. rtw_indicate_disconnect(padapter); //will clr Linked_state; before this function, we must have chked whether issue dis-assoc_cmd or not
  425. }
  426. }
  427. *pold_state = networktype;
  428. _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
  429. switch(networktype)
  430. {
  431. case Ndis802_11IBSS:
  432. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  433. break;
  434. case Ndis802_11Infrastructure:
  435. set_fwstate(pmlmepriv, WIFI_STATION_STATE);
  436. break;
  437. case Ndis802_11APMode:
  438. set_fwstate(pmlmepriv, WIFI_AP_STATE);
  439. #ifdef CONFIG_NATIVEAP_MLME
  440. start_ap_mode(padapter);
  441. //rtw_indicate_connect(padapter);
  442. #endif
  443. break;
  444. case Ndis802_11AutoUnknown:
  445. case Ndis802_11InfrastructureMax:
  446. break;
  447. }
  448. //SecClearAllKeys(adapter);
  449. //RT_TRACE(COMP_OID_SET, DBG_LOUD, ("set_infrastructure: fw_state:%x after changing mode\n",
  450. // get_fwstate(pmlmepriv) ));
  451. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  452. }
  453. _func_exit_;
  454. return _TRUE;
  455. }
  456. u8 rtw_set_802_11_disassociate(_adapter *padapter)
  457. {
  458. _irqL irqL;
  459. struct mlme_priv * pmlmepriv = &padapter->mlmepriv;
  460. _func_enter_;
  461. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  462. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  463. {
  464. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActrtw_set_802_11_disassociate: rtw_indicate_disconnect\n"));
  465. rtw_disassoc_cmd(padapter, 0, _TRUE);
  466. rtw_indicate_disconnect(padapter);
  467. rtw_free_assoc_resources(padapter, 1);
  468. rtw_pwr_wakeup(padapter);
  469. }
  470. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  471. _func_exit_;
  472. return _TRUE;
  473. }
  474. u8 rtw_set_802_11_bssid_list_scan(_adapter* padapter, NDIS_802_11_SSID *pssid, int ssid_max_num)
  475. {
  476. _irqL irqL;
  477. struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
  478. u8 res=_TRUE;
  479. _func_enter_;
  480. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("+rtw_set_802_11_bssid_list_scan(), fw_state=%x\n", get_fwstate(pmlmepriv)));
  481. if (padapter == NULL) {
  482. res=_FALSE;
  483. goto exit;
  484. }
  485. if (padapter->hw_init_completed==_FALSE){
  486. res = _FALSE;
  487. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n===rtw_set_802_11_bssid_list_scan:hw_init_completed==_FALSE===\n"));
  488. goto exit;
  489. }
  490. if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE) ||
  491. (pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE))
  492. {
  493. // Scan or linking is in progress, do nothing.
  494. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("rtw_set_802_11_bssid_list_scan fail since fw_state = %x\n", get_fwstate(pmlmepriv)));
  495. res = _TRUE;
  496. if(check_fwstate(pmlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))== _TRUE){
  497. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n###_FW_UNDER_SURVEY|_FW_UNDER_LINKING\n\n"));
  498. } else {
  499. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n###pmlmepriv->sitesurveyctrl.traffic_busy==_TRUE\n\n"));
  500. }
  501. } else {
  502. if (rtw_is_scan_deny(padapter)) {
  503. DBG_871X(FUNC_ADPT_FMT": scan deny\n", FUNC_ADPT_ARG(padapter));
  504. indicate_wx_scan_complete_event(padapter);
  505. return _SUCCESS;
  506. }
  507. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  508. res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, NULL, 0);
  509. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  510. }
  511. exit:
  512. _func_exit_;
  513. return res;
  514. }
  515. u8 rtw_set_802_11_authentication_mode(_adapter* padapter, NDIS_802_11_AUTHENTICATION_MODE authmode)
  516. {
  517. struct security_priv *psecuritypriv = &padapter->securitypriv;
  518. int res;
  519. u8 ret;
  520. _func_enter_;
  521. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("set_802_11_auth.mode(): mode=%x\n", authmode));
  522. psecuritypriv->ndisauthtype=authmode;
  523. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("rtw_set_802_11_authentication_mode:psecuritypriv->ndisauthtype=%d", psecuritypriv->ndisauthtype));
  524. if(psecuritypriv->ndisauthtype>3)
  525. psecuritypriv->dot11AuthAlgrthm=dot11AuthAlgrthm_8021X;
  526. #ifdef CONFIG_WAPI_SUPPORT
  527. if(psecuritypriv->ndisauthtype == 6)
  528. psecuritypriv->dot11AuthAlgrthm=dot11AuthAlgrthm_WAPI;
  529. #endif
  530. res=rtw_set_auth(padapter,psecuritypriv);
  531. if(res==_SUCCESS)
  532. ret=_TRUE;
  533. else
  534. ret=_FALSE;
  535. _func_exit_;
  536. return ret;
  537. }
  538. u8 rtw_set_802_11_add_wep(_adapter* padapter, NDIS_802_11_WEP *wep){
  539. u8 bdefaultkey;
  540. u8 btransmitkey;
  541. sint keyid,res;
  542. struct security_priv* psecuritypriv=&(padapter->securitypriv);
  543. u8 ret=_SUCCESS;
  544. _func_enter_;
  545. bdefaultkey=(wep->KeyIndex & 0x40000000) > 0 ? _FALSE : _TRUE; //for ???
  546. btransmitkey= (wep->KeyIndex & 0x80000000) > 0 ? _TRUE : _FALSE; //for ???
  547. keyid=wep->KeyIndex & 0x3fffffff;
  548. if(keyid>4)
  549. {
  550. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("MgntActrtw_set_802_11_add_wep:keyid>4=>fail\n"));
  551. ret=_FALSE;
  552. goto exit;
  553. }
  554. switch(wep->KeyLength)
  555. {
  556. case 5:
  557. psecuritypriv->dot11PrivacyAlgrthm=_WEP40_;
  558. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActrtw_set_802_11_add_wep:wep->KeyLength=5\n"));
  559. break;
  560. case 13:
  561. psecuritypriv->dot11PrivacyAlgrthm=_WEP104_;
  562. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActrtw_set_802_11_add_wep:wep->KeyLength=13\n"));
  563. break;
  564. default:
  565. psecuritypriv->dot11PrivacyAlgrthm=_NO_PRIVACY_;
  566. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("MgntActrtw_set_802_11_add_wep:wep->KeyLength!=5 or 13\n"));
  567. break;
  568. }
  569. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("rtw_set_802_11_add_wep:befor memcpy, wep->KeyLength=0x%x wep->KeyIndex=0x%x keyid =%x\n",wep->KeyLength,wep->KeyIndex,keyid));
  570. _rtw_memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]),&(wep->KeyMaterial),wep->KeyLength);
  571. psecuritypriv->dot11DefKeylen[keyid]=wep->KeyLength;
  572. psecuritypriv->dot11PrivacyKeyIndex=keyid;
  573. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("rtw_set_802_11_add_wep:security key material : %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
  574. psecuritypriv->dot11DefKey[keyid].skey[0],psecuritypriv->dot11DefKey[keyid].skey[1],psecuritypriv->dot11DefKey[keyid].skey[2],
  575. psecuritypriv->dot11DefKey[keyid].skey[3],psecuritypriv->dot11DefKey[keyid].skey[4],psecuritypriv->dot11DefKey[keyid].skey[5],
  576. psecuritypriv->dot11DefKey[keyid].skey[6],psecuritypriv->dot11DefKey[keyid].skey[7],psecuritypriv->dot11DefKey[keyid].skey[8],
  577. psecuritypriv->dot11DefKey[keyid].skey[9],psecuritypriv->dot11DefKey[keyid].skey[10],psecuritypriv->dot11DefKey[keyid].skey[11],
  578. psecuritypriv->dot11DefKey[keyid].skey[12]));
  579. res=rtw_set_key(padapter,psecuritypriv, keyid, 1);
  580. if(res==_FAIL)
  581. ret= _FALSE;
  582. exit:
  583. _func_exit_;
  584. return ret;
  585. }
  586. u8 rtw_set_802_11_remove_wep(_adapter* padapter, u32 keyindex){
  587. u8 ret=_SUCCESS;
  588. _func_enter_;
  589. if (keyindex >= 0x80000000 || padapter == NULL){
  590. ret=_FALSE;
  591. goto exit;
  592. }
  593. else
  594. {
  595. int res;
  596. struct security_priv* psecuritypriv=&(padapter->securitypriv);
  597. if( keyindex < 4 ){
  598. _rtw_memset(&psecuritypriv->dot11DefKey[keyindex], 0, 16);
  599. res=rtw_set_key(padapter,psecuritypriv,keyindex, 0);
  600. psecuritypriv->dot11DefKeylen[keyindex]=0;
  601. if(res==_FAIL)
  602. ret=_FAIL;
  603. }
  604. else
  605. {
  606. ret=_FAIL;
  607. }
  608. }
  609. exit:
  610. _func_exit_;
  611. return ret;
  612. }
  613. u8 rtw_set_802_11_add_key(_adapter* padapter, NDIS_802_11_KEY *key){
  614. uint encryptionalgo;
  615. u8 * pbssid;
  616. struct sta_info *stainfo;
  617. u8 bgroup = _FALSE;
  618. u8 bgrouptkey = _FALSE;//can be remove later
  619. u8 ret=_SUCCESS;
  620. _func_enter_;
  621. if (((key->KeyIndex & 0x80000000) == 0) && ((key->KeyIndex & 0x40000000) > 0)){
  622. // It is invalid to clear bit 31 and set bit 30. If the miniport driver encounters this combination,
  623. // it must fail the request and return NDIS_STATUS_INVALID_DATA.
  624. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("rtw_set_802_11_add_key: ((key->KeyIndex & 0x80000000) == 0)[=%d] ",(int)(key->KeyIndex & 0x80000000) == 0));
  625. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("rtw_set_802_11_add_key:((key->KeyIndex & 0x40000000) > 0)[=%d]" , (int)(key->KeyIndex & 0x40000000) > 0));
  626. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_info_,("rtw_set_802_11_add_key: key->KeyIndex=%d \n" ,(int)key->KeyIndex));
  627. ret= _FAIL;
  628. goto exit;
  629. }
  630. if(key->KeyIndex & 0x40000000)
  631. {
  632. // Pairwise key
  633. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("OID_802_11_ADD_KEY: +++++ Pairwise key +++++\n"));
  634. pbssid=get_bssid(&padapter->mlmepriv);
  635. stainfo=rtw_get_stainfo(&padapter->stapriv, pbssid);
  636. if((stainfo!=NULL)&&(padapter->securitypriv.dot11AuthAlgrthm==dot11AuthAlgrthm_8021X)){
  637. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("OID_802_11_ADD_KEY:( stainfo!=NULL)&&(Adapter->securitypriv.dot11AuthAlgrthm==dot11AuthAlgrthm_8021X)\n"));
  638. encryptionalgo=stainfo->dot118021XPrivacy;
  639. }
  640. else{
  641. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("OID_802_11_ADD_KEY: stainfo==NULL)||(Adapter->securitypriv.dot11AuthAlgrthm!=dot11AuthAlgrthm_8021X)\n"));
  642. encryptionalgo=padapter->securitypriv.dot11PrivacyAlgrthm;
  643. }
  644. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("rtw_set_802_11_add_key: (encryptionalgo ==%d)!\n",encryptionalgo ));
  645. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("rtw_set_802_11_add_key: (Adapter->securitypriv.dot11PrivacyAlgrthm ==%d)!\n",padapter->securitypriv.dot11PrivacyAlgrthm));
  646. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("rtw_set_802_11_add_key: (Adapter->securitypriv.dot11AuthAlgrthm ==%d)!\n",padapter->securitypriv.dot11AuthAlgrthm));
  647. if((stainfo!=NULL)){
  648. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("rtw_set_802_11_add_key: (stainfo->dot118021XPrivacy ==%d)!\n", stainfo->dot118021XPrivacy));
  649. }
  650. if(key->KeyIndex & 0x000000FF){
  651. // The key index is specified in the lower 8 bits by values of zero to 255.
  652. // The key index should be set to zero for a Pairwise key, and the driver should fail with
  653. // NDIS_STATUS_INVALID_DATA if the lower 8 bits is not zero
  654. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,(" key->KeyIndex & 0x000000FF.\n"));
  655. ret= _FAIL;
  656. goto exit;
  657. }
  658. // check BSSID
  659. if (IS_MAC_ADDRESS_BROADCAST(key->BSSID) == _TRUE){
  660. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("MacAddr_isBcst(key->BSSID)\n"));
  661. ret= _FALSE;
  662. goto exit;
  663. }
  664. // Check key length for TKIP.
  665. //if(encryptionAlgorithm == RT_ENC_TKIP_ENCRYPTION && key->KeyLength != 32)
  666. if((encryptionalgo== _TKIP_)&& (key->KeyLength != 32)){
  667. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("TKIP KeyLength:0x%x != 32\n", key->KeyLength));
  668. ret=_FAIL;
  669. goto exit;
  670. }
  671. // Check key length for AES.
  672. if((encryptionalgo== _AES_)&& (key->KeyLength != 16)) {
  673. // For our supplicant, EAPPkt9x.vxd, cannot differentiate TKIP and AES case.
  674. if(key->KeyLength == 32) {
  675. key->KeyLength = 16;
  676. } else {
  677. ret= _FAIL;
  678. goto exit;
  679. }
  680. }
  681. // Check key length for WEP. For NDTEST, 2005.01.27, by rcnjko.
  682. if( (encryptionalgo== _WEP40_|| encryptionalgo== _WEP104_) && (key->KeyLength != 5 || key->KeyLength != 13)) {
  683. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("WEP KeyLength:0x%x != 5 or 13\n", key->KeyLength));
  684. ret=_FAIL;
  685. goto exit;
  686. }
  687. bgroup = _FALSE;
  688. // Check the pairwise key. Added by Annie, 2005-07-06.
  689. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("------------------------------------------\n"));
  690. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("[Pairwise Key set]\n"));
  691. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("------------------------------------------\n"));
  692. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("key index: 0x%8x(0x%8x)\n", key->KeyIndex,(key->KeyIndex&0x3)));
  693. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("key Length: %d\n", key->KeyLength));
  694. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("------------------------------------------\n"));
  695. }
  696. else
  697. {
  698. // Group key - KeyIndex(BIT30==0)
  699. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("OID_802_11_ADD_KEY: +++++ Group key +++++\n"));
  700. // when add wep key through add key and didn't assigned encryption type before
  701. if((padapter->securitypriv.ndisauthtype<=3)&&(padapter->securitypriv.dot118021XGrpPrivacy==0))
  702. {
  703. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("keylen=%d( Adapter->securitypriv.dot11PrivacyAlgrthm=%x )padapter->securitypriv.dot118021XGrpPrivacy(%x)\n", key->KeyLength,padapter->securitypriv.dot11PrivacyAlgrthm,padapter->securitypriv.dot118021XGrpPrivacy));
  704. switch(key->KeyLength)
  705. {
  706. case 5:
  707. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP40_;
  708. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("Adapter->securitypriv.dot11PrivacyAlgrthm= %x key->KeyLength=%u\n", padapter->securitypriv.dot11PrivacyAlgrthm,key->KeyLength));
  709. break;
  710. case 13:
  711. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP104_;
  712. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("Adapter->securitypriv.dot11PrivacyAlgrthm= %x key->KeyLength=%u\n", padapter->securitypriv.dot11PrivacyAlgrthm,key->KeyLength));
  713. break;
  714. default:
  715. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  716. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("Adapter->securitypriv.dot11PrivacyAlgrthm= %x key->KeyLength=%u \n", padapter->securitypriv.dot11PrivacyAlgrthm,key->KeyLength));
  717. break;
  718. }
  719. encryptionalgo=padapter->securitypriv.dot11PrivacyAlgrthm;
  720. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,(" Adapter->securitypriv.dot11PrivacyAlgrthm=%x\n", padapter->securitypriv.dot11PrivacyAlgrthm));
  721. }
  722. else
  723. {
  724. encryptionalgo=padapter->securitypriv.dot118021XGrpPrivacy;
  725. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("( Adapter->securitypriv.dot11PrivacyAlgrthm=%x )encryptionalgo(%x)=padapter->securitypriv.dot118021XGrpPrivacy(%x)keylen=%d\n", padapter->securitypriv.dot11PrivacyAlgrthm,encryptionalgo,padapter->securitypriv.dot118021XGrpPrivacy,key->KeyLength));
  726. }
  727. if((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE)==_TRUE) && (IS_MAC_ADDRESS_BROADCAST(key->BSSID) == _FALSE)) {
  728. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,(" IBSS but BSSID is not Broadcast Address.\n"));
  729. ret= _FAIL;
  730. goto exit;
  731. }
  732. // Check key length for TKIP
  733. if((encryptionalgo== _TKIP_) && (key->KeyLength != 32)) {
  734. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,(" TKIP GTK KeyLength:%u != 32\n", key->KeyLength));
  735. ret= _FAIL;
  736. goto exit;
  737. } else if(encryptionalgo== _AES_ && (key->KeyLength != 16 && key->KeyLength != 32) ) {
  738. // Check key length for AES
  739. // For NDTEST, we allow keylen=32 in this case. 2005.01.27, by rcnjko.
  740. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("<=== SetInfo, OID_802_11_ADD_KEY: AES GTK KeyLength:%u != 16 or 32\n", key->KeyLength));
  741. ret= _FAIL;
  742. goto exit;
  743. }
  744. // Change the key length for EAPPkt9x.vxd. Added by Annie, 2005-11-03.
  745. if((encryptionalgo== _AES_) && (key->KeyLength == 32) ) {
  746. key->KeyLength = 16;
  747. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("AES key length changed: %u\n", key->KeyLength) );
  748. }
  749. if(key->KeyIndex & 0x8000000) {//error ??? 0x8000_0000
  750. bgrouptkey = _TRUE;
  751. }
  752. if((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE)==_TRUE)&&(check_fwstate(&padapter->mlmepriv, _FW_LINKED)==_TRUE))
  753. {
  754. bgrouptkey = _TRUE;
  755. }
  756. bgroup = _TRUE;
  757. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("------------------------------------------\n") );
  758. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("[Group Key set]\n") );
  759. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("------------------------------------------\n")) ;
  760. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("key index: 0x%8x(0x%8x)\n", key->KeyIndex,(key->KeyIndex&0x3)));
  761. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("key Length: %d\n", key->KeyLength)) ;
  762. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("------------------------------------------\n"));
  763. }
  764. // If WEP encryption algorithm, just call rtw_set_802_11_add_wep().
  765. if((padapter->securitypriv.dot11AuthAlgrthm !=dot11AuthAlgrthm_8021X)&&(encryptionalgo== _WEP40_ || encryptionalgo== _WEP104_))
  766. {
  767. u8 ret;
  768. u32 keyindex;
  769. u32 len = FIELD_OFFSET(NDIS_802_11_KEY, KeyMaterial) + key->KeyLength;
  770. NDIS_802_11_WEP *wep = &padapter->securitypriv.ndiswep;
  771. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("OID_802_11_ADD_KEY: +++++ WEP key +++++\n"));
  772. wep->Length = len;
  773. keyindex = key->KeyIndex&0x7fffffff;
  774. wep->KeyIndex = keyindex ;
  775. wep->KeyLength = key->KeyLength;
  776. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("OID_802_11_ADD_KEY:Before memcpy \n"));
  777. _rtw_memcpy(wep->KeyMaterial, key->KeyMaterial, key->KeyLength);
  778. _rtw_memcpy(&(padapter->securitypriv.dot11DefKey[keyindex].skey[0]), key->KeyMaterial, key->KeyLength);
  779. padapter->securitypriv.dot11DefKeylen[keyindex]=key->KeyLength;
  780. padapter->securitypriv.dot11PrivacyKeyIndex=keyindex;
  781. ret = rtw_set_802_11_add_wep(padapter, wep);
  782. goto exit;
  783. }
  784. if(key->KeyIndex & 0x20000000){
  785. // SetRSC
  786. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("OID_802_11_ADD_KEY: +++++ SetRSC+++++\n"));
  787. if(bgroup == _TRUE)
  788. {
  789. NDIS_802_11_KEY_RSC keysrc=key->KeyRSC & 0x00FFFFFFFFFFFFULL;
  790. _rtw_memcpy(&padapter->securitypriv.dot11Grprxpn, &keysrc, 8);
  791. }
  792. else
  793. {
  794. NDIS_802_11_KEY_RSC keysrc=key->KeyRSC & 0x00FFFFFFFFFFFFULL;
  795. _rtw_memcpy(&padapter->securitypriv.dot11Grptxpn, &keysrc, 8);
  796. }
  797. }
  798. // Indicate this key idx is used for TX
  799. // Save the key in KeyMaterial
  800. if(bgroup == _TRUE) // Group transmit key
  801. {
  802. int res;
  803. if(bgrouptkey == _TRUE)
  804. {
  805. padapter->securitypriv.dot118021XGrpKeyid=(u8)key->KeyIndex;
  806. }
  807. if((key->KeyIndex&0x3) == 0){
  808. ret = _FAIL;
  809. goto exit;
  810. }
  811. _rtw_memset(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
  812. _rtw_memset(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
  813. _rtw_memset(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
  814. if((key->KeyIndex & 0x10000000))
  815. {
  816. _rtw_memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
  817. _rtw_memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
  818. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n rtw_set_802_11_add_key:rx mic :0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
  819. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[0],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[1],
  820. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[2],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[3],
  821. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[4],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[5],
  822. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[6],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[7]));
  823. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n rtw_set_802_11_add_key:set Group mic key!!!!!!!!\n"));
  824. }
  825. else
  826. {
  827. _rtw_memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
  828. _rtw_memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
  829. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n rtw_set_802_11_add_key:rx mic :0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
  830. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[0],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[1],
  831. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[2],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[3],
  832. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[4],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[5],
  833. padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)].skey[6],padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex-1) & 0x03)].skey[7]));
  834. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n rtw_set_802_11_add_key:set Group mic key!!!!!!!!\n"));
  835. }
  836. //set group key by index
  837. _rtw_memcpy(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial, key->KeyLength);
  838. key->KeyIndex=key->KeyIndex & 0x03;
  839. padapter->securitypriv.binstallGrpkey=_TRUE;
  840. padapter->securitypriv.bcheck_grpkey=_FALSE;
  841. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("reset group key"));
  842. res=rtw_set_key(padapter,&padapter->securitypriv, key->KeyIndex, 1);
  843. if(res==_FAIL)
  844. ret= _FAIL;
  845. goto exit;
  846. }
  847. else // Pairwise Key
  848. {
  849. u8 res;
  850. pbssid=get_bssid(&padapter->mlmepriv);
  851. stainfo=rtw_get_stainfo(&padapter->stapriv , pbssid );
  852. if(stainfo!=NULL)
  853. {
  854. _rtw_memset( &stainfo->dot118021x_UncstKey, 0, 16);// clear keybuffer
  855. _rtw_memcpy(&stainfo->dot118021x_UncstKey, key->KeyMaterial, 16);
  856. if(encryptionalgo== _TKIP_)
  857. {
  858. padapter->securitypriv.busetkipkey=_FALSE;
  859. //_set_timer(&padapter->securitypriv.tkip_timer, 50);
  860. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n ==========_set_timer\n"));
  861. // if TKIP, save the Receive/Transmit MIC key in KeyMaterial[128-255]
  862. if((key->KeyIndex & 0x10000000)){
  863. _rtw_memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 16, 8);
  864. _rtw_memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 24, 8);
  865. } else {
  866. _rtw_memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 24, 8);
  867. _rtw_memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 16, 8);
  868. }
  869. }
  870. else if(encryptionalgo == _AES_)
  871. {
  872. }
  873. //Set key to CAM through H2C command
  874. if(bgrouptkey)//never go to here
  875. {
  876. res=rtw_setstakey_cmd(padapter, (unsigned char *)stainfo, _FALSE);
  877. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n rtw_set_802_11_add_key:rtw_setstakey_cmd(group)\n"));
  878. }
  879. else{
  880. res=rtw_setstakey_cmd(padapter, (unsigned char *)stainfo, _TRUE);
  881. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("\n rtw_set_802_11_add_key:rtw_setstakey_cmd(unicast)\n"));
  882. }
  883. if(res ==_FALSE)
  884. ret= _FAIL;
  885. }
  886. }
  887. exit:
  888. _func_exit_;
  889. return ret;
  890. }
  891. u8 rtw_set_802_11_remove_key(_adapter* padapter, NDIS_802_11_REMOVE_KEY *key){
  892. uint encryptionalgo;
  893. u8 * pbssid;
  894. struct sta_info *stainfo;
  895. u8 bgroup = (key->KeyIndex & 0x4000000) > 0 ? _FALSE: _TRUE;
  896. u8 keyIndex = (u8)key->KeyIndex & 0x03;
  897. u8 ret=_SUCCESS;
  898. _func_enter_;
  899. if ((key->KeyIndex & 0xbffffffc) > 0) {
  900. ret=_FAIL;
  901. goto exit;
  902. }
  903. if (bgroup == _TRUE) {
  904. encryptionalgo= padapter->securitypriv.dot118021XGrpPrivacy;
  905. // clear group key by index
  906. //NdisZeroMemory(Adapter->MgntInfo.SecurityInfo.KeyBuf[keyIndex], MAX_WEP_KEY_LEN);
  907. //Adapter->MgntInfo.SecurityInfo.KeyLen[keyIndex] = 0;
  908. _rtw_memset(&padapter->securitypriv.dot118021XGrpKey[keyIndex], 0, 16);
  909. //! \todo Send a H2C Command to Firmware for removing this Key in CAM Entry.
  910. } else {
  911. pbssid=get_bssid(&padapter->mlmepriv);
  912. stainfo=rtw_get_stainfo(&padapter->stapriv , pbssid );
  913. if(stainfo !=NULL){
  914. encryptionalgo=stainfo->dot118021XPrivacy;
  915. // clear key by BSSID
  916. _rtw_memset(&stainfo->dot118021x_UncstKey, 0, 16);
  917. //! \todo Send a H2C Command to Firmware for disable this Key in CAM Entry.
  918. }
  919. else{
  920. ret= _FAIL;
  921. goto exit;
  922. }
  923. }
  924. exit:
  925. _func_exit_;
  926. return _TRUE;
  927. }
  928. /*
  929. * rtw_get_cur_max_rate -
  930. * @adapter: pointer to _adapter structure
  931. *
  932. * Return 0 or 100Kbps
  933. */
  934. u16 rtw_get_cur_max_rate(_adapter *adapter)
  935. {
  936. int i = 0;
  937. u8 *p;
  938. u16 rate = 0, max_rate = 0;
  939. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  940. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  941. struct registry_priv *pregistrypriv = &adapter->registrypriv;
  942. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  943. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  944. #ifdef CONFIG_80211N_HT
  945. struct rtw_ieee80211_ht_cap *pht_capie;
  946. u8 rf_type = 0;
  947. u8 bw_40MHz=0, short_GI_20=0, short_GI_40=0, cbw40_enable=0;
  948. u16 mcs_rate=0;
  949. u32 ht_ielen = 0;
  950. #endif
  951. #ifdef CONFIG_80211AC_VHT
  952. struct vht_priv *pvhtpriv = &pmlmepriv->vhtpriv;
  953. #endif
  954. #ifdef CONFIG_MP_INCLUDED
  955. if (adapter->registrypriv.mp_mode == 1)
  956. {
  957. if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  958. return 0;
  959. }
  960. #endif
  961. if((check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE)
  962. && (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE))
  963. return 0;
  964. #ifdef CONFIG_80211N_HT
  965. if (IsSupportedTxHT(pmlmeext->cur_wireless_mode)) {
  966. p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength-12);
  967. if(p && ht_ielen>0)
  968. {
  969. pht_capie = (struct rtw_ieee80211_ht_cap *)(p+2);
  970. _rtw_memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2);
  971. //bw_40MHz = (pht_capie->cap_info&IEEE80211_HT_CAP_SUP_WIDTH) ? 1:0;
  972. //cur_bwmod is updated by beacon, pmlmeinfo is updated by association response
  973. bw_40MHz = (pmlmeext->cur_bwmode && (HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH & pmlmeinfo->HT_info.infos[0])) ? 1:0;
  974. //short_GI = (pht_capie->cap_info&(IEEE80211_HT_CAP_SGI_20|IEEE80211_HT_CAP_SGI_40)) ? 1:0;
  975. short_GI_20 = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info&IEEE80211_HT_CAP_SGI_20) ? 1:0;
  976. short_GI_40 = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info&IEEE80211_HT_CAP_SGI_40) ? 1:0;
  977. rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  978. if (pmlmeext->cur_channel > 14) {
  979. if ((pregistrypriv->bw_mode & 0xf0) > 0)
  980. cbw40_enable = 1;
  981. } else {
  982. if ((pregistrypriv->bw_mode & 0x0f) > 0)
  983. cbw40_enable = 1;
  984. }
  985. max_rate = rtw_mcs_rate(
  986. rf_type,
  987. bw_40MHz & cbw40_enable,
  988. short_GI_20,
  989. short_GI_40,
  990. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate
  991. );
  992. }
  993. }
  994. #ifdef CONFIG_80211AC_VHT
  995. else if (IsSupportedVHT(pmlmeext->cur_wireless_mode)) {
  996. max_rate = ((rtw_vht_data_rate(pvhtpriv->bwmode, pvhtpriv->sgi, pvhtpriv->vht_highest_rate) + 1) >> 1) * 10;
  997. }
  998. #endif //CONFIG_80211AC_VHT
  999. else
  1000. #endif //CONFIG_80211N_HT
  1001. {
  1002. while( (pcur_bss->SupportedRates[i]!=0) && (pcur_bss->SupportedRates[i]!=0xFF))
  1003. {
  1004. rate = pcur_bss->SupportedRates[i]&0x7F;
  1005. if(rate>max_rate)
  1006. max_rate = rate;
  1007. i++;
  1008. }
  1009. max_rate = max_rate*10/2;
  1010. }
  1011. return max_rate;
  1012. }
  1013. /*
  1014. * rtw_set_scan_mode -
  1015. * @adapter: pointer to _adapter structure
  1016. * @scan_mode:
  1017. *
  1018. * Return _SUCCESS or _FAIL
  1019. */
  1020. int rtw_set_scan_mode(_adapter *adapter, RT_SCAN_TYPE scan_mode)
  1021. {
  1022. if(scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
  1023. return _FAIL;
  1024. adapter->mlmepriv.scan_mode = scan_mode;
  1025. return _SUCCESS;
  1026. }
  1027. /*
  1028. * rtw_set_channel_plan -
  1029. * @adapter: pointer to _adapter structure
  1030. * @channel_plan:
  1031. *
  1032. * Return _SUCCESS or _FAIL
  1033. */
  1034. int rtw_set_channel_plan(_adapter *adapter, u8 channel_plan)
  1035. {
  1036. struct registry_priv *pregistrypriv = &adapter->registrypriv;
  1037. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1038. //handle by cmd_thread to sync with scan operation
  1039. return rtw_set_chplan_cmd(adapter, channel_plan, 1);
  1040. }
  1041. /*
  1042. * rtw_set_country -
  1043. * @adapter: pointer to _adapter structure
  1044. * @country_code: string of country code
  1045. *
  1046. * Return _SUCCESS or _FAIL
  1047. */
  1048. int rtw_set_country(_adapter *adapter, const char *country_code)
  1049. {
  1050. int channel_plan = RT_CHANNEL_DOMAIN_WORLD_WIDE_5G;
  1051. DBG_871X("%s country_code:%s\n", __func__, country_code);
  1052. //TODO: should have a table to match country code and RT_CHANNEL_DOMAIN
  1053. //TODO: should consider 2-character and 3-character country code
  1054. if(0 == strcmp(country_code, "US"))
  1055. channel_plan = RT_CHANNEL_DOMAIN_FCC;
  1056. else if(0 == strcmp(country_code, "EU"))
  1057. channel_plan = RT_CHANNEL_DOMAIN_ETSI;
  1058. else if(0 == strcmp(country_code, "JP"))
  1059. channel_plan = RT_CHANNEL_DOMAIN_MKK;
  1060. else if(0 == strcmp(country_code, "CN"))
  1061. channel_plan = RT_CHANNEL_DOMAIN_CHINA;
  1062. else
  1063. DBG_871X("%s unknown country_code:%s\n", __FUNCTION__, country_code);
  1064. return rtw_set_channel_plan(adapter, channel_plan);
  1065. }