rtw_ioctl_set.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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. #include <hal_data.h>
  23. extern void indicate_wx_scan_complete_event(_adapter *padapter);
  24. #define IS_MAC_ADDRESS_BROADCAST(addr) \
  25. (\
  26. ((addr[0] == 0xff) && (addr[1] == 0xff) && \
  27. (addr[2] == 0xff) && (addr[3] == 0xff) && \
  28. (addr[4] == 0xff) && (addr[5] == 0xff)) ? _TRUE : _FALSE \
  29. )
  30. u8 rtw_validate_bssid(u8 *bssid)
  31. {
  32. u8 ret = _TRUE;
  33. if (is_zero_mac_addr(bssid)
  34. || is_broadcast_mac_addr(bssid)
  35. || is_multicast_mac_addr(bssid)
  36. )
  37. ret = _FALSE;
  38. return ret;
  39. }
  40. u8 rtw_validate_ssid(NDIS_802_11_SSID *ssid)
  41. {
  42. u8 i;
  43. u8 ret = _TRUE;
  44. if (ssid->SsidLength > 32) {
  45. ret = _FALSE;
  46. goto exit;
  47. }
  48. #ifdef CONFIG_VALIDATE_SSID
  49. for (i = 0; i < ssid->SsidLength; i++) {
  50. /* wifi, printable ascii code must be supported */
  51. if (!((ssid->Ssid[i] >= 0x20) && (ssid->Ssid[i] <= 0x7e))) {
  52. ret = _FALSE;
  53. break;
  54. }
  55. }
  56. #endif /* CONFIG_VALIDATE_SSID */
  57. exit:
  58. return ret;
  59. }
  60. u8 rtw_do_join(_adapter *padapter);
  61. u8 rtw_do_join(_adapter *padapter)
  62. {
  63. _irqL irqL;
  64. _list *plist, *phead;
  65. u8 *pibss = NULL;
  66. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  67. _queue *queue = &(pmlmepriv->scanned_queue);
  68. u8 ret = _SUCCESS;
  69. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  70. phead = get_list_head(queue);
  71. plist = get_next(phead);
  72. pmlmepriv->cur_network.join_res = -2;
  73. set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
  74. pmlmepriv->pscanned = plist;
  75. pmlmepriv->to_join = _TRUE;
  76. if (_rtw_queue_empty(queue) == _TRUE) {
  77. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  78. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  79. /* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */
  80. /* we try to issue sitesurvey firstly */
  81. if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
  82. || rtw_to_roam(padapter) > 0
  83. ) {
  84. /* submit site_survey_cmd */
  85. ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
  86. if (_SUCCESS != ret) {
  87. pmlmepriv->to_join = _FALSE;
  88. }
  89. } else {
  90. pmlmepriv->to_join = _FALSE;
  91. ret = _FAIL;
  92. }
  93. goto exit;
  94. } else {
  95. int select_ret;
  96. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  97. select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
  98. if (select_ret == _SUCCESS) {
  99. pmlmepriv->to_join = _FALSE;
  100. _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
  101. } else {
  102. if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
  103. /* submit createbss_cmd to change to a ADHOC_MASTER */
  104. /* pmlmepriv->lock has been acquired by caller... */
  105. WLAN_BSSID_EX *pdev_network = &(padapter->registrypriv.dev_network);
  106. /*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
  107. init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  108. pibss = padapter->registrypriv.dev_network.MacAddress;
  109. _rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
  110. _rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
  111. rtw_update_registrypriv_dev_network(padapter);
  112. rtw_generate_random_ibss(pibss);
  113. if (rtw_create_ibss_cmd(padapter, 0) != _SUCCESS) {
  114. ret = _FALSE;
  115. goto exit;
  116. }
  117. pmlmepriv->to_join = _FALSE;
  118. } else {
  119. /* can't associate ; reset under-linking */
  120. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  121. #if 0
  122. if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)) {
  123. if (_rtw_memcmp(pmlmepriv->cur_network.network.Ssid.Ssid, pmlmepriv->assoc_ssid.Ssid, pmlmepriv->assoc_ssid.SsidLength)) {
  124. /* for funk to do roaming */
  125. /* funk will reconnect, but funk will not sitesurvey before reconnect */
  126. if (pmlmepriv->sitesurveyctrl.traffic_busy == _FALSE)
  127. rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
  128. }
  129. }
  130. #endif
  131. /* when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue */
  132. /* we try to issue sitesurvey firstly */
  133. if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
  134. || rtw_to_roam(padapter) > 0
  135. ) {
  136. /* RTW_INFO("rtw_do_join() when no desired bss in scanning queue\n"); */
  137. ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
  138. if (_SUCCESS != ret) {
  139. pmlmepriv->to_join = _FALSE;
  140. }
  141. } else {
  142. ret = _FAIL;
  143. pmlmepriv->to_join = _FALSE;
  144. }
  145. }
  146. }
  147. }
  148. exit:
  149. return ret;
  150. }
  151. #ifdef PLATFORM_WINDOWS
  152. u8 rtw_pnp_set_power_wakeup(_adapter *padapter)
  153. {
  154. u8 res = _SUCCESS;
  155. res = rtw_setstandby_cmd(padapter, 0);
  156. return res;
  157. }
  158. u8 rtw_pnp_set_power_sleep(_adapter *padapter)
  159. {
  160. u8 res = _SUCCESS;
  161. /* DbgPrint("+rtw_pnp_set_power_sleep\n"); */
  162. res = rtw_setstandby_cmd(padapter, 1);
  163. return res;
  164. }
  165. u8 rtw_set_802_11_reload_defaults(_adapter *padapter, NDIS_802_11_RELOAD_DEFAULTS reloadDefaults)
  166. {
  167. /* SecClearAllKeys(Adapter); */
  168. /* 8711 CAM was not for En/Decrypt only */
  169. /* so, we can't clear all keys. */
  170. /* should we disable WPAcfg (ox0088) bit 1-2, instead of clear all CAM */
  171. /* TO DO... */
  172. return _TRUE;
  173. }
  174. u8 set_802_11_test(_adapter *padapter, NDIS_802_11_TEST *test)
  175. {
  176. u8 ret = _TRUE;
  177. switch (test->Type) {
  178. case 1:
  179. NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->AuthenticationEvent, test->Length - 8);
  180. NdisMIndicateStatusComplete(padapter->hndis_adapter);
  181. break;
  182. case 2:
  183. NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->RssiTrigger, sizeof(NDIS_802_11_RSSI));
  184. NdisMIndicateStatusComplete(padapter->hndis_adapter);
  185. break;
  186. default:
  187. ret = _FALSE;
  188. break;
  189. }
  190. return ret;
  191. }
  192. u8 rtw_set_802_11_pmkid(_adapter *padapter, NDIS_802_11_PMKID *pmkid)
  193. {
  194. u8 ret = _SUCCESS;
  195. return ret;
  196. }
  197. #endif
  198. u8 rtw_set_802_11_bssid(_adapter *padapter, u8 *bssid)
  199. {
  200. _irqL irqL;
  201. u8 status = _SUCCESS;
  202. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  203. RTW_PRINT("set bssid:%pM\n", bssid);
  204. if ((bssid[0] == 0x00 && bssid[1] == 0x00 && bssid[2] == 0x00 && bssid[3] == 0x00 && bssid[4] == 0x00 && bssid[5] == 0x00) ||
  205. (bssid[0] == 0xFF && bssid[1] == 0xFF && bssid[2] == 0xFF && bssid[3] == 0xFF && bssid[4] == 0xFF && bssid[5] == 0xFF)) {
  206. status = _FAIL;
  207. goto exit;
  208. }
  209. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  210. RTW_INFO("Set BSSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
  211. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
  212. goto handle_tkip_countermeasure;
  213. else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
  214. goto release_mlme_lock;
  215. if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  216. if (_rtw_memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN) == _TRUE) {
  217. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)
  218. goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
  219. } else {
  220. rtw_disassoc_cmd(padapter, 0, 0);
  221. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  222. rtw_indicate_disconnect(padapter, 0, _FALSE);
  223. rtw_free_assoc_resources(padapter, 1);
  224. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
  225. _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  226. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  227. }
  228. }
  229. }
  230. handle_tkip_countermeasure:
  231. if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
  232. status = _FAIL;
  233. goto release_mlme_lock;
  234. }
  235. _rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
  236. _rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
  237. pmlmepriv->assoc_by_bssid = _TRUE;
  238. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
  239. pmlmepriv->to_join = _TRUE;
  240. else
  241. status = rtw_do_join(padapter);
  242. release_mlme_lock:
  243. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  244. exit:
  245. return status;
  246. }
  247. u8 rtw_set_802_11_ssid(_adapter *padapter, NDIS_802_11_SSID *ssid)
  248. {
  249. _irqL irqL;
  250. u8 status = _SUCCESS;
  251. u32 cur_time = 0;
  252. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  253. struct wlan_network *pnetwork = &pmlmepriv->cur_network;
  254. RTW_PRINT("set ssid [%s] fw_state=0x%08x\n",
  255. ssid->Ssid, get_fwstate(pmlmepriv));
  256. if (!rtw_is_hw_init_completed(padapter)) {
  257. status = _FAIL;
  258. goto exit;
  259. }
  260. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  261. RTW_INFO("Set SSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
  262. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
  263. goto handle_tkip_countermeasure;
  264. else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
  265. goto release_mlme_lock;
  266. if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  267. if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
  268. (_rtw_memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength) == _TRUE)) {
  269. if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)) {
  270. if (rtw_is_same_ibss(padapter, pnetwork) == _FALSE) {
  271. /* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */
  272. rtw_disassoc_cmd(padapter, 0, 0);
  273. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  274. rtw_indicate_disconnect(padapter, 0, _FALSE);
  275. rtw_free_assoc_resources(padapter, 1);
  276. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  277. _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  278. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  279. }
  280. } else {
  281. goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
  282. }
  283. }
  284. #ifdef CONFIG_LPS
  285. else
  286. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 1);
  287. #endif
  288. } else {
  289. rtw_disassoc_cmd(padapter, 0, 0);
  290. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  291. rtw_indicate_disconnect(padapter, 0, _FALSE);
  292. rtw_free_assoc_resources(padapter, 1);
  293. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  294. _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  295. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  296. }
  297. }
  298. }
  299. handle_tkip_countermeasure:
  300. if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
  301. status = _FAIL;
  302. goto release_mlme_lock;
  303. }
  304. if (rtw_validate_ssid(ssid) == _FALSE) {
  305. status = _FAIL;
  306. goto release_mlme_lock;
  307. }
  308. _rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
  309. pmlmepriv->assoc_by_bssid = _FALSE;
  310. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
  311. pmlmepriv->to_join = _TRUE;
  312. else
  313. status = rtw_do_join(padapter);
  314. release_mlme_lock:
  315. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  316. exit:
  317. return status;
  318. }
  319. u8 rtw_set_802_11_connect(_adapter *padapter, u8 *bssid, NDIS_802_11_SSID *ssid)
  320. {
  321. _irqL irqL;
  322. u8 status = _SUCCESS;
  323. u32 cur_time = 0;
  324. bool bssid_valid = _TRUE;
  325. bool ssid_valid = _TRUE;
  326. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  327. if (!ssid || rtw_validate_ssid(ssid) == _FALSE)
  328. ssid_valid = _FALSE;
  329. if (!bssid || rtw_validate_bssid(bssid) == _FALSE)
  330. bssid_valid = _FALSE;
  331. if (ssid_valid == _FALSE && bssid_valid == _FALSE) {
  332. RTW_INFO(FUNC_ADPT_FMT" ssid:%p, ssid_valid:%d, bssid:%p, bssid_valid:%d\n",
  333. FUNC_ADPT_ARG(padapter), ssid, ssid_valid, bssid, bssid_valid);
  334. status = _FAIL;
  335. goto exit;
  336. }
  337. if (!rtw_is_hw_init_completed(padapter)) {
  338. status = _FAIL;
  339. goto exit;
  340. }
  341. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  342. RTW_PRINT(FUNC_ADPT_FMT" fw_state=0x%08x\n",
  343. FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
  344. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
  345. goto handle_tkip_countermeasure;
  346. else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
  347. goto release_mlme_lock;
  348. handle_tkip_countermeasure:
  349. if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
  350. status = _FAIL;
  351. goto release_mlme_lock;
  352. }
  353. if (ssid && ssid_valid)
  354. _rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
  355. else
  356. _rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
  357. if (bssid && bssid_valid) {
  358. _rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
  359. pmlmepriv->assoc_by_bssid = _TRUE;
  360. } else
  361. pmlmepriv->assoc_by_bssid = _FALSE;
  362. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
  363. pmlmepriv->to_join = _TRUE;
  364. else
  365. status = rtw_do_join(padapter);
  366. release_mlme_lock:
  367. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  368. exit:
  369. return status;
  370. }
  371. u8 rtw_set_802_11_infrastructure_mode(_adapter *padapter,
  372. NDIS_802_11_NETWORK_INFRASTRUCTURE networktype)
  373. {
  374. _irqL irqL;
  375. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  376. struct wlan_network *cur_network = &pmlmepriv->cur_network;
  377. NDIS_802_11_NETWORK_INFRASTRUCTURE *pold_state = &(cur_network->network.InfrastructureMode);
  378. if (*pold_state != networktype) {
  379. /* RTW_INFO("change mode, old_mode=%d, new_mode=%d, fw_state=0x%x\n", *pold_state, networktype, get_fwstate(pmlmepriv)); */
  380. if (*pold_state == Ndis802_11APMode) {
  381. /* change to other mode from Ndis802_11APMode */
  382. cur_network->join_res = -1;
  383. #ifdef CONFIG_NATIVEAP_MLME
  384. stop_ap_mode(padapter);
  385. #endif
  386. }
  387. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  388. if ((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) || (*pold_state == Ndis802_11IBSS))
  389. rtw_disassoc_cmd(padapter, 0, 0);
  390. if ((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) ||
  391. (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE))
  392. rtw_free_assoc_resources(padapter, 1);
  393. if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
  394. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  395. rtw_indicate_disconnect(padapter, 0, _FALSE); /*will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not*/
  396. }
  397. }
  398. *pold_state = networktype;
  399. _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
  400. switch (networktype) {
  401. case Ndis802_11IBSS:
  402. set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
  403. break;
  404. case Ndis802_11Infrastructure:
  405. set_fwstate(pmlmepriv, WIFI_STATION_STATE);
  406. break;
  407. case Ndis802_11APMode:
  408. set_fwstate(pmlmepriv, WIFI_AP_STATE);
  409. #ifdef CONFIG_NATIVEAP_MLME
  410. start_ap_mode(padapter);
  411. /* rtw_indicate_connect(padapter); */
  412. #endif
  413. break;
  414. case Ndis802_11AutoUnknown:
  415. case Ndis802_11InfrastructureMax:
  416. break;
  417. case Ndis802_11Monitor:
  418. set_fwstate(pmlmepriv, WIFI_MONITOR_STATE);
  419. break;
  420. }
  421. /* SecClearAllKeys(adapter); */
  422. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  423. }
  424. return _TRUE;
  425. }
  426. u8 rtw_set_802_11_disassociate(_adapter *padapter)
  427. {
  428. _irqL irqL;
  429. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  430. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  431. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  432. rtw_disassoc_cmd(padapter, 0, 0);
  433. rtw_indicate_disconnect(padapter, 0, _FALSE);
  434. /* modify for CONFIG_IEEE80211W, none 11w can use it */
  435. rtw_free_assoc_resources_cmd(padapter);
  436. if (_FAIL == rtw_pwr_wakeup(padapter))
  437. RTW_INFO("%s(): rtw_pwr_wakeup fail !!!\n", __FUNCTION__);
  438. }
  439. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  440. return _TRUE;
  441. }
  442. #if 1
  443. u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, NDIS_802_11_SSID *pssid, int ssid_max_num, struct rtw_ieee80211_channel *ch, int ch_num)
  444. {
  445. _irqL irqL;
  446. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  447. u8 res = _TRUE;
  448. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  449. res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, ch, ch_num);
  450. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  451. return res;
  452. }
  453. #else
  454. u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, NDIS_802_11_SSID *pssid, int ssid_max_num, struct rtw_ieee80211_channel *ch, int ch_num)
  455. {
  456. _irqL irqL;
  457. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  458. u8 res = _TRUE;
  459. if (padapter == NULL) {
  460. res = _FALSE;
  461. goto exit;
  462. }
  463. if (!rtw_is_hw_init_completed(padapter)) {
  464. res = _FALSE;
  465. goto exit;
  466. }
  467. if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) ||
  468. (pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)) {
  469. /* Scan or linking is in progress, do nothing. */
  470. res = _TRUE;
  471. } else {
  472. if (rtw_is_scan_deny(padapter)) {
  473. RTW_INFO(FUNC_ADPT_FMT": scan deny\n", FUNC_ADPT_ARG(padapter));
  474. indicate_wx_scan_complete_event(padapter);
  475. return _SUCCESS;
  476. }
  477. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  478. res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, NULL, 0, ch, ch_num);
  479. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  480. }
  481. exit:
  482. return res;
  483. }
  484. #endif
  485. u8 rtw_set_802_11_authentication_mode(_adapter *padapter, NDIS_802_11_AUTHENTICATION_MODE authmode)
  486. {
  487. struct security_priv *psecuritypriv = &padapter->securitypriv;
  488. int res;
  489. u8 ret;
  490. psecuritypriv->ndisauthtype = authmode;
  491. if (psecuritypriv->ndisauthtype > 3)
  492. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  493. #ifdef CONFIG_WAPI_SUPPORT
  494. if (psecuritypriv->ndisauthtype == 6)
  495. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  496. #endif
  497. res = rtw_set_auth(padapter, psecuritypriv);
  498. if (res == _SUCCESS)
  499. ret = _TRUE;
  500. else
  501. ret = _FALSE;
  502. return ret;
  503. }
  504. u8 rtw_set_802_11_add_wep(_adapter *padapter, NDIS_802_11_WEP *wep)
  505. {
  506. u8 bdefaultkey;
  507. u8 btransmitkey;
  508. sint keyid, res;
  509. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  510. u8 ret = _SUCCESS;
  511. bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? _FALSE : _TRUE; /* for ??? */
  512. btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? _TRUE : _FALSE; /* for ??? */
  513. keyid = wep->KeyIndex & 0x3fffffff;
  514. if (keyid >= 4) {
  515. ret = _FALSE;
  516. goto exit;
  517. }
  518. switch (wep->KeyLength) {
  519. case 5:
  520. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  521. break;
  522. case 13:
  523. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  524. break;
  525. default:
  526. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  527. break;
  528. }
  529. _rtw_memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->KeyMaterial), wep->KeyLength);
  530. psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
  531. psecuritypriv->dot11PrivacyKeyIndex = keyid;
  532. res = rtw_set_key(padapter, psecuritypriv, keyid, 1, _TRUE);
  533. if (res == _FAIL)
  534. ret = _FALSE;
  535. exit:
  536. return ret;
  537. }
  538. u8 rtw_set_802_11_remove_wep(_adapter *padapter, u32 keyindex)
  539. {
  540. u8 ret = _SUCCESS;
  541. if (keyindex >= 0x80000000 || padapter == NULL) {
  542. ret = _FALSE;
  543. goto exit;
  544. } else {
  545. int res;
  546. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  547. if (keyindex < 4) {
  548. _rtw_memset(&psecuritypriv->dot11DefKey[keyindex], 0, 16);
  549. res = rtw_set_key(padapter, psecuritypriv, keyindex, 0, _TRUE);
  550. psecuritypriv->dot11DefKeylen[keyindex] = 0;
  551. if (res == _FAIL)
  552. ret = _FAIL;
  553. } else
  554. ret = _FAIL;
  555. }
  556. exit:
  557. return ret;
  558. }
  559. u8 rtw_set_802_11_add_key(_adapter *padapter, NDIS_802_11_KEY *key)
  560. {
  561. uint encryptionalgo;
  562. u8 *pbssid;
  563. struct sta_info *stainfo;
  564. u8 bgroup = _FALSE;
  565. u8 bgrouptkey = _FALSE;/* can be remove later */
  566. u8 ret = _SUCCESS;
  567. if (((key->KeyIndex & 0x80000000) == 0) && ((key->KeyIndex & 0x40000000) > 0)) {
  568. /* It is invalid to clear bit 31 and set bit 30. If the miniport driver encounters this combination, */
  569. /* it must fail the request and return NDIS_STATUS_INVALID_DATA. */
  570. ret = _FAIL;
  571. goto exit;
  572. }
  573. if (key->KeyIndex & 0x40000000) {
  574. /* Pairwise key */
  575. pbssid = get_bssid(&padapter->mlmepriv);
  576. stainfo = rtw_get_stainfo(&padapter->stapriv, pbssid);
  577. if ((stainfo != NULL) && (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)) {
  578. encryptionalgo = stainfo->dot118021XPrivacy;
  579. } else {
  580. encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
  581. }
  582. if (key->KeyIndex & 0x000000FF) {
  583. /* The key index is specified in the lower 8 bits by values of zero to 255. */
  584. /* The key index should be set to zero for a Pairwise key, and the driver should fail with */
  585. /* NDIS_STATUS_INVALID_DATA if the lower 8 bits is not zero */
  586. ret = _FAIL;
  587. goto exit;
  588. }
  589. /* check BSSID */
  590. if (IS_MAC_ADDRESS_BROADCAST(key->BSSID) == _TRUE) {
  591. ret = _FALSE;
  592. goto exit;
  593. }
  594. /* Check key length for TKIP. */
  595. /* if(encryptionAlgorithm == RT_ENC_TKIP_ENCRYPTION && key->KeyLength != 32) */
  596. if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
  597. ret = _FAIL;
  598. goto exit;
  599. }
  600. /* Check key length for AES. */
  601. if ((encryptionalgo == _AES_) && (key->KeyLength != 16)) {
  602. /* For our supplicant, EAPPkt9x.vxd, cannot differentiate TKIP and AES case. */
  603. if (key->KeyLength == 32)
  604. key->KeyLength = 16;
  605. else {
  606. ret = _FAIL;
  607. goto exit;
  608. }
  609. }
  610. /* Check key length for WEP. For NDTEST, 2005.01.27, by rcnjko. -> modify checking condition*/
  611. if (((encryptionalgo == _WEP40_) && (key->KeyLength != 5)) || ((encryptionalgo == _WEP104_) && (key->KeyLength != 13))) {
  612. ret = _FAIL;
  613. goto exit;
  614. }
  615. bgroup = _FALSE;
  616. /* Check the pairwise key. Added by Annie, 2005-07-06. */
  617. } else {
  618. /* Group key - KeyIndex(BIT30==0) */
  619. /* when add wep key through add key and didn't assigned encryption type before */
  620. if ((padapter->securitypriv.ndisauthtype <= 3) && (padapter->securitypriv.dot118021XGrpPrivacy == 0)) {
  621. switch (key->KeyLength) {
  622. case 5:
  623. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
  624. break;
  625. case 13:
  626. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
  627. break;
  628. default:
  629. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  630. break;
  631. }
  632. encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
  633. } else {
  634. encryptionalgo = padapter->securitypriv.dot118021XGrpPrivacy;
  635. }
  636. if ((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE) == _TRUE) && (IS_MAC_ADDRESS_BROADCAST(key->BSSID) == _FALSE)) {
  637. ret = _FAIL;
  638. goto exit;
  639. }
  640. /* Check key length for TKIP */
  641. if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
  642. ret = _FAIL;
  643. goto exit;
  644. } else if (encryptionalgo == _AES_ && (key->KeyLength != 16 && key->KeyLength != 32)) {
  645. /* Check key length for AES */
  646. /* For NDTEST, we allow keylen=32 in this case. 2005.01.27, by rcnjko. */
  647. ret = _FAIL;
  648. goto exit;
  649. }
  650. /* Change the key length for EAPPkt9x.vxd. Added by Annie, 2005-11-03. */
  651. if ((encryptionalgo == _AES_) && (key->KeyLength == 32)) {
  652. key->KeyLength = 16;
  653. }
  654. if (key->KeyIndex & 0x8000000) /* error ??? 0x8000_0000 */
  655. bgrouptkey = _TRUE;
  656. if ((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE) == _TRUE) && (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == _TRUE))
  657. bgrouptkey = _TRUE;
  658. bgroup = _TRUE;
  659. }
  660. /* If WEP encryption algorithm, just call rtw_set_802_11_add_wep(). */
  661. if ((padapter->securitypriv.dot11AuthAlgrthm != dot11AuthAlgrthm_8021X) && (encryptionalgo == _WEP40_ || encryptionalgo == _WEP104_)) {
  662. u8 ret;
  663. u32 keyindex;
  664. u32 len = FIELD_OFFSET(NDIS_802_11_KEY, KeyMaterial) + key->KeyLength;
  665. NDIS_802_11_WEP *wep = &padapter->securitypriv.ndiswep;
  666. wep->Length = len;
  667. keyindex = key->KeyIndex & 0x7fffffff;
  668. wep->KeyIndex = keyindex ;
  669. wep->KeyLength = key->KeyLength;
  670. _rtw_memcpy(wep->KeyMaterial, key->KeyMaterial, key->KeyLength);
  671. _rtw_memcpy(&(padapter->securitypriv.dot11DefKey[keyindex].skey[0]), key->KeyMaterial, key->KeyLength);
  672. padapter->securitypriv.dot11DefKeylen[keyindex] = key->KeyLength;
  673. padapter->securitypriv.dot11PrivacyKeyIndex = keyindex;
  674. ret = rtw_set_802_11_add_wep(padapter, wep);
  675. goto exit;
  676. }
  677. if (key->KeyIndex & 0x20000000) {
  678. /* SetRSC */
  679. if (bgroup == _TRUE) {
  680. NDIS_802_11_KEY_RSC keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
  681. _rtw_memcpy(&padapter->securitypriv.dot11Grprxpn, &keysrc, 8);
  682. } else {
  683. NDIS_802_11_KEY_RSC keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
  684. _rtw_memcpy(&padapter->securitypriv.dot11Grptxpn, &keysrc, 8);
  685. }
  686. }
  687. /* Indicate this key idx is used for TX */
  688. /* Save the key in KeyMaterial */
  689. if (bgroup == _TRUE) { /* Group transmit key */
  690. int res;
  691. if (bgrouptkey == _TRUE)
  692. padapter->securitypriv.dot118021XGrpKeyid = (u8)key->KeyIndex;
  693. if ((key->KeyIndex & 0x3) == 0) {
  694. ret = _FAIL;
  695. goto exit;
  696. }
  697. _rtw_memset(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
  698. _rtw_memset(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
  699. _rtw_memset(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
  700. if ((key->KeyIndex & 0x10000000)) {
  701. _rtw_memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
  702. _rtw_memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
  703. } else {
  704. _rtw_memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
  705. _rtw_memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
  706. }
  707. /* set group key by index */
  708. _rtw_memcpy(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial, key->KeyLength);
  709. key->KeyIndex = key->KeyIndex & 0x03;
  710. padapter->securitypriv.binstallGrpkey = _TRUE;
  711. padapter->securitypriv.bcheck_grpkey = _FALSE;
  712. res = rtw_set_key(padapter, &padapter->securitypriv, key->KeyIndex, 1, _TRUE);
  713. if (res == _FAIL)
  714. ret = _FAIL;
  715. goto exit;
  716. } else { /* Pairwise Key */
  717. u8 res;
  718. pbssid = get_bssid(&padapter->mlmepriv);
  719. stainfo = rtw_get_stainfo(&padapter->stapriv , pbssid);
  720. if (stainfo != NULL) {
  721. _rtw_memset(&stainfo->dot118021x_UncstKey, 0, 16); /* clear keybuffer */
  722. _rtw_memcpy(&stainfo->dot118021x_UncstKey, key->KeyMaterial, 16);
  723. if (encryptionalgo == _TKIP_) {
  724. padapter->securitypriv.busetkipkey = _FALSE;
  725. /* if TKIP, save the Receive/Transmit MIC key in KeyMaterial[128-255] */
  726. if ((key->KeyIndex & 0x10000000)) {
  727. _rtw_memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 16, 8);
  728. _rtw_memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 24, 8);
  729. } else {
  730. _rtw_memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 24, 8);
  731. _rtw_memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 16, 8);
  732. }
  733. } else if (encryptionalgo == _AES_) {
  734. }
  735. /* Set key to CAM through H2C command */
  736. #if 0
  737. if (bgrouptkey) { /* never go to here */
  738. res = rtw_setstakey_cmd(padapter, stainfo, GROUP_KEY, _TRUE);
  739. } else {
  740. res = rtw_setstakey_cmd(padapter, stainfo, UNICAST_KEY, _TRUE);
  741. }
  742. #else
  743. res = rtw_setstakey_cmd(padapter, stainfo, UNICAST_KEY, _TRUE);
  744. #endif
  745. if (res == _FALSE)
  746. ret = _FAIL;
  747. }
  748. }
  749. exit:
  750. return ret;
  751. }
  752. u8 rtw_set_802_11_remove_key(_adapter *padapter, NDIS_802_11_REMOVE_KEY *key)
  753. {
  754. uint encryptionalgo;
  755. u8 *pbssid;
  756. struct sta_info *stainfo;
  757. u8 bgroup = (key->KeyIndex & 0x4000000) > 0 ? _FALSE : _TRUE;
  758. u8 keyIndex = (u8)key->KeyIndex & 0x03;
  759. u8 ret = _SUCCESS;
  760. if ((key->KeyIndex & 0xbffffffc) > 0) {
  761. ret = _FAIL;
  762. goto exit;
  763. }
  764. if (bgroup == _TRUE) {
  765. encryptionalgo = padapter->securitypriv.dot118021XGrpPrivacy;
  766. /* clear group key by index */
  767. /* NdisZeroMemory(Adapter->MgntInfo.SecurityInfo.KeyBuf[keyIndex], MAX_WEP_KEY_LEN); */
  768. /* Adapter->MgntInfo.SecurityInfo.KeyLen[keyIndex] = 0; */
  769. _rtw_memset(&padapter->securitypriv.dot118021XGrpKey[keyIndex], 0, 16);
  770. /* ! \todo Send a H2C Command to Firmware for removing this Key in CAM Entry. */
  771. } else {
  772. pbssid = get_bssid(&padapter->mlmepriv);
  773. stainfo = rtw_get_stainfo(&padapter->stapriv , pbssid);
  774. if (stainfo != NULL) {
  775. encryptionalgo = stainfo->dot118021XPrivacy;
  776. /* clear key by BSSID */
  777. _rtw_memset(&stainfo->dot118021x_UncstKey, 0, 16);
  778. /* ! \todo Send a H2C Command to Firmware for disable this Key in CAM Entry. */
  779. } else {
  780. ret = _FAIL;
  781. goto exit;
  782. }
  783. }
  784. exit:
  785. return _TRUE;
  786. }
  787. /*
  788. * rtw_get_cur_max_rate -
  789. * @adapter: pointer to _adapter structure
  790. *
  791. * Return 0 or 100Kbps
  792. */
  793. u16 rtw_get_cur_max_rate(_adapter *adapter)
  794. {
  795. int i = 0;
  796. u16 rate = 0, max_rate = 0;
  797. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  798. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  799. struct sta_info *psta = NULL;
  800. u8 short_GI = 0;
  801. #ifdef CONFIG_80211N_HT
  802. u8 rf_type = 0;
  803. #endif
  804. #ifdef CONFIG_MP_INCLUDED
  805. if (adapter->registrypriv.mp_mode == 1) {
  806. if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  807. return 0;
  808. }
  809. #endif
  810. if ((check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE)
  811. && (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE))
  812. return 0;
  813. psta = rtw_get_stainfo(&adapter->stapriv, get_bssid(pmlmepriv));
  814. if (psta == NULL)
  815. return 0;
  816. short_GI = query_ra_short_GI(psta, psta->bw_mode);
  817. #ifdef CONFIG_80211N_HT
  818. if (is_supported_ht(psta->wireless_mode)) {
  819. rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  820. max_rate = rtw_mcs_rate(rf_type
  821. , (psta->bw_mode == CHANNEL_WIDTH_40) ? 1 : 0
  822. , short_GI
  823. , psta->htpriv.ht_cap.supp_mcs_set
  824. );
  825. }
  826. #ifdef CONFIG_80211AC_VHT
  827. else if (is_supported_vht(psta->wireless_mode))
  828. max_rate = ((rtw_vht_mcs_to_data_rate(psta->bw_mode, short_GI, pmlmepriv->vhtpriv.vht_highest_rate) + 1) >> 1) * 10;
  829. #endif /* CONFIG_80211AC_VHT */
  830. else
  831. #endif /* CONFIG_80211N_HT */
  832. {
  833. while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) {
  834. rate = pcur_bss->SupportedRates[i] & 0x7F;
  835. if (rate > max_rate)
  836. max_rate = rate;
  837. i++;
  838. }
  839. max_rate = max_rate * 10 / 2;
  840. }
  841. return max_rate;
  842. }
  843. /*
  844. * rtw_set_scan_mode -
  845. * @adapter: pointer to _adapter structure
  846. * @scan_mode:
  847. *
  848. * Return _SUCCESS or _FAIL
  849. */
  850. int rtw_set_scan_mode(_adapter *adapter, RT_SCAN_TYPE scan_mode)
  851. {
  852. if (scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
  853. return _FAIL;
  854. adapter->mlmepriv.scan_mode = scan_mode;
  855. return _SUCCESS;
  856. }
  857. /*
  858. * rtw_set_channel_plan -
  859. * @adapter: pointer to _adapter structure
  860. * @channel_plan:
  861. *
  862. * Return _SUCCESS or _FAIL
  863. */
  864. int rtw_set_channel_plan(_adapter *adapter, u8 channel_plan)
  865. {
  866. struct registry_priv *pregistrypriv = &adapter->registrypriv;
  867. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  868. /* handle by cmd_thread to sync with scan operation */
  869. return rtw_set_chplan_cmd(adapter, RTW_CMDF_WAIT_ACK, channel_plan, 1);
  870. }
  871. /*
  872. * rtw_set_country -
  873. * @adapter: pointer to _adapter structure
  874. * @country_code: string of country code
  875. *
  876. * Return _SUCCESS or _FAIL
  877. */
  878. int rtw_set_country(_adapter *adapter, const char *country_code)
  879. {
  880. #ifdef CONFIG_RTW_IOCTL_SET_COUNTRY
  881. return rtw_set_country_cmd(adapter, RTW_CMDF_WAIT_ACK, country_code, 1);
  882. #else
  883. return _FAIL;
  884. #endif
  885. }
  886. /*
  887. * rtw_set_band -
  888. * @adapter: pointer to _adapter structure
  889. * @band: band to set
  890. *
  891. * Return _SUCCESS or _FAIL
  892. */
  893. int rtw_set_band(_adapter *adapter, u8 band)
  894. {
  895. if (rtw_band_valid(band)) {
  896. RTW_INFO(FUNC_ADPT_FMT" band:%d\n", FUNC_ADPT_ARG(adapter), band);
  897. adapter->setband = band;
  898. return _SUCCESS;
  899. }
  900. RTW_PRINT(FUNC_ADPT_FMT" band:%d fail\n", FUNC_ADPT_ARG(adapter), band);
  901. return _FAIL;
  902. }