sta_ioctl.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  1. /*
  2. * Marvell Wireless LAN device driver: functions for station ioctl
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. #include "cfg80211.h"
  27. static int disconnect_on_suspend = 1;
  28. module_param(disconnect_on_suspend, int, 0644);
  29. /*
  30. * Copies the multicast address list from device to driver.
  31. *
  32. * This function does not validate the destination memory for
  33. * size, and the calling function must ensure enough memory is
  34. * available.
  35. */
  36. int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
  37. struct net_device *dev)
  38. {
  39. int i = 0;
  40. struct netdev_hw_addr *ha;
  41. netdev_for_each_mc_addr(ha, dev)
  42. memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
  43. return i;
  44. }
  45. /*
  46. * Wait queue completion handler.
  47. *
  48. * This function waits on a cmd wait queue. It also cancels the pending
  49. * request after waking up, in case of errors.
  50. */
  51. int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
  52. struct cmd_ctrl_node *cmd_queued)
  53. {
  54. int status;
  55. /* Wait for completion */
  56. status = wait_event_interruptible_timeout(adapter->cmd_wait_q.wait,
  57. *(cmd_queued->condition),
  58. (12 * HZ));
  59. if (status <= 0) {
  60. dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status);
  61. mwifiex_cancel_all_pending_cmd(adapter);
  62. return status;
  63. }
  64. status = adapter->cmd_wait_q.status;
  65. adapter->cmd_wait_q.status = 0;
  66. return status;
  67. }
  68. /*
  69. * This function prepares the correct firmware command and
  70. * issues it to set the multicast list.
  71. *
  72. * This function can be used to enable promiscuous mode, or enable all
  73. * multicast packets, or to enable selective multicast.
  74. */
  75. int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
  76. struct mwifiex_multicast_list *mcast_list)
  77. {
  78. int ret = 0;
  79. u16 old_pkt_filter;
  80. old_pkt_filter = priv->curr_pkt_filter;
  81. if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
  82. dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
  83. priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  84. priv->curr_pkt_filter &=
  85. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  86. } else {
  87. /* Multicast */
  88. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  89. if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
  90. dev_dbg(priv->adapter->dev,
  91. "info: Enabling All Multicast!\n");
  92. priv->curr_pkt_filter |=
  93. HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  94. } else {
  95. priv->curr_pkt_filter &=
  96. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  97. dev_dbg(priv->adapter->dev,
  98. "info: Set multicast list=%d\n",
  99. mcast_list->num_multicast_addr);
  100. /* Send multicast addresses to firmware */
  101. ret = mwifiex_send_cmd(priv,
  102. HostCmd_CMD_MAC_MULTICAST_ADR,
  103. HostCmd_ACT_GEN_SET, 0,
  104. mcast_list, false);
  105. }
  106. }
  107. dev_dbg(priv->adapter->dev,
  108. "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
  109. old_pkt_filter, priv->curr_pkt_filter);
  110. if (old_pkt_filter != priv->curr_pkt_filter) {
  111. ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  112. HostCmd_ACT_GEN_SET,
  113. 0, &priv->curr_pkt_filter, false);
  114. }
  115. return ret;
  116. }
  117. /*
  118. * This function fills bss descriptor structure using provided
  119. * information.
  120. * beacon_ie buffer is allocated in this function. It is caller's
  121. * responsibility to free the memory.
  122. */
  123. int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
  124. struct cfg80211_bss *bss,
  125. struct mwifiex_bssdescriptor *bss_desc)
  126. {
  127. u8 *beacon_ie;
  128. size_t beacon_ie_len;
  129. struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
  130. const struct cfg80211_bss_ies *ies;
  131. rcu_read_lock();
  132. ies = rcu_dereference(bss->ies);
  133. beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
  134. beacon_ie_len = ies->len;
  135. bss_desc->timestamp = ies->tsf;
  136. rcu_read_unlock();
  137. if (!beacon_ie) {
  138. dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
  139. return -ENOMEM;
  140. }
  141. memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
  142. bss_desc->rssi = bss->signal;
  143. /* The caller of this function will free beacon_ie */
  144. bss_desc->beacon_buf = beacon_ie;
  145. bss_desc->beacon_buf_size = beacon_ie_len;
  146. bss_desc->beacon_period = bss->beacon_interval;
  147. bss_desc->cap_info_bitmap = bss->capability;
  148. bss_desc->bss_band = bss_priv->band;
  149. bss_desc->fw_tsf = bss_priv->fw_tsf;
  150. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
  151. dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
  152. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  153. } else {
  154. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  155. }
  156. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
  157. bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
  158. else
  159. bss_desc->bss_mode = NL80211_IFTYPE_STATION;
  160. /* Disable 11ac by default. Enable it only where there
  161. * exist VHT_CAP IE in AP beacon
  162. */
  163. bss_desc->disable_11ac = true;
  164. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
  165. bss_desc->sensed_11h = true;
  166. return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
  167. }
  168. void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv)
  169. {
  170. if (priv->adapter->dt_node) {
  171. char txpwr[] = {"marvell,00_txpwrlimit"};
  172. memcpy(&txpwr[8], priv->adapter->country_code, 2);
  173. mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
  174. }
  175. }
  176. static int mwifiex_process_country_ie(struct mwifiex_private *priv,
  177. struct cfg80211_bss *bss)
  178. {
  179. const u8 *country_ie;
  180. u8 country_ie_len;
  181. struct mwifiex_802_11d_domain_reg *domain_info =
  182. &priv->adapter->domain_reg;
  183. rcu_read_lock();
  184. country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
  185. if (!country_ie) {
  186. rcu_read_unlock();
  187. return 0;
  188. }
  189. country_ie_len = country_ie[1];
  190. if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
  191. rcu_read_unlock();
  192. return 0;
  193. }
  194. if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
  195. rcu_read_unlock();
  196. wiphy_dbg(priv->wdev->wiphy,
  197. "11D: skip setting domain info in FW\n");
  198. return 0;
  199. }
  200. memcpy(priv->adapter->country_code, &country_ie[2], 2);
  201. domain_info->country_code[0] = country_ie[2];
  202. domain_info->country_code[1] = country_ie[3];
  203. domain_info->country_code[2] = ' ';
  204. country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
  205. domain_info->no_of_triplet =
  206. country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
  207. memcpy((u8 *)domain_info->triplet,
  208. &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
  209. rcu_read_unlock();
  210. if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
  211. HostCmd_ACT_GEN_SET, 0, NULL, false)) {
  212. wiphy_err(priv->adapter->wiphy,
  213. "11D: setting domain info in FW\n");
  214. return -1;
  215. }
  216. mwifiex_dnld_txpwr_table(priv);
  217. return 0;
  218. }
  219. /*
  220. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  221. * In both Ad-Hoc and infra mode, an deauthentication is performed
  222. * first.
  223. */
  224. int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
  225. struct cfg80211_ssid *req_ssid)
  226. {
  227. int ret;
  228. struct mwifiex_adapter *adapter = priv->adapter;
  229. struct mwifiex_bssdescriptor *bss_desc = NULL;
  230. priv->scan_block = false;
  231. if (bss) {
  232. mwifiex_process_country_ie(priv, bss);
  233. /* Allocate and fill new bss descriptor */
  234. bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
  235. GFP_KERNEL);
  236. if (!bss_desc)
  237. return -ENOMEM;
  238. ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
  239. if (ret)
  240. goto done;
  241. }
  242. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  243. priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
  244. u8 config_bands;
  245. ret = mwifiex_deauthenticate(priv, NULL);
  246. if (ret)
  247. goto done;
  248. if (!bss_desc)
  249. return -1;
  250. if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
  251. HostCmd_SCAN_RADIO_TYPE_BG)
  252. config_bands = BAND_B | BAND_G | BAND_GN;
  253. else
  254. config_bands = BAND_A | BAND_AN | BAND_AAC;
  255. if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
  256. adapter->config_bands = config_bands;
  257. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  258. if (ret)
  259. goto done;
  260. if (mwifiex_11h_get_csa_closed_channel(priv) ==
  261. (u8)bss_desc->channel) {
  262. dev_err(adapter->dev,
  263. "Attempt to reconnect on csa closed chan(%d)\n",
  264. bss_desc->channel);
  265. goto done;
  266. }
  267. dev_dbg(adapter->dev, "info: SSID found in scan list ... "
  268. "associating...\n");
  269. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  270. if (netif_carrier_ok(priv->netdev))
  271. netif_carrier_off(priv->netdev);
  272. /* Clear any past association response stored for
  273. * application retrieval */
  274. priv->assoc_rsp_size = 0;
  275. ret = mwifiex_associate(priv, bss_desc);
  276. /* If auth type is auto and association fails using open mode,
  277. * try to connect using shared mode */
  278. if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
  279. priv->sec_info.is_authtype_auto &&
  280. priv->sec_info.wep_enabled) {
  281. priv->sec_info.authentication_mode =
  282. NL80211_AUTHTYPE_SHARED_KEY;
  283. ret = mwifiex_associate(priv, bss_desc);
  284. }
  285. if (bss)
  286. cfg80211_put_bss(priv->adapter->wiphy, bss);
  287. } else {
  288. /* Adhoc mode */
  289. /* If the requested SSID matches current SSID, return */
  290. if (bss_desc && bss_desc->ssid.ssid_len &&
  291. (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
  292. ssid, &bss_desc->ssid))) {
  293. ret = 0;
  294. goto done;
  295. }
  296. /* Exit Adhoc mode first */
  297. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  298. ret = mwifiex_deauthenticate(priv, NULL);
  299. if (ret)
  300. goto done;
  301. priv->adhoc_is_link_sensed = false;
  302. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  303. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  304. if (netif_carrier_ok(priv->netdev))
  305. netif_carrier_off(priv->netdev);
  306. if (!ret) {
  307. dev_dbg(adapter->dev, "info: network found in scan"
  308. " list. Joining...\n");
  309. ret = mwifiex_adhoc_join(priv, bss_desc);
  310. if (bss)
  311. cfg80211_put_bss(priv->adapter->wiphy, bss);
  312. } else {
  313. dev_dbg(adapter->dev, "info: Network not found in "
  314. "the list, creating adhoc with ssid = %s\n",
  315. req_ssid->ssid);
  316. ret = mwifiex_adhoc_start(priv, req_ssid);
  317. }
  318. }
  319. done:
  320. /* beacon_ie buffer was allocated in function
  321. * mwifiex_fill_new_bss_desc(). Free it now.
  322. */
  323. if (bss_desc)
  324. kfree(bss_desc->beacon_buf);
  325. kfree(bss_desc);
  326. return ret;
  327. }
  328. /*
  329. * IOCTL request handler to set host sleep configuration.
  330. *
  331. * This function prepares the correct firmware command and
  332. * issues it.
  333. */
  334. static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  335. int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
  336. {
  337. struct mwifiex_adapter *adapter = priv->adapter;
  338. int status = 0;
  339. u32 prev_cond = 0;
  340. if (!hs_cfg)
  341. return -ENOMEM;
  342. switch (action) {
  343. case HostCmd_ACT_GEN_SET:
  344. if (adapter->pps_uapsd_mode) {
  345. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  346. " is blocked in UAPSD/PPS mode\n");
  347. status = -1;
  348. break;
  349. }
  350. if (hs_cfg->is_invoke_hostcmd) {
  351. if (hs_cfg->conditions == HS_CFG_CANCEL) {
  352. if (!adapter->is_hs_configured)
  353. /* Already cancelled */
  354. break;
  355. /* Save previous condition */
  356. prev_cond = le32_to_cpu(adapter->hs_cfg
  357. .conditions);
  358. adapter->hs_cfg.conditions =
  359. cpu_to_le32(hs_cfg->conditions);
  360. } else if (hs_cfg->conditions) {
  361. adapter->hs_cfg.conditions =
  362. cpu_to_le32(hs_cfg->conditions);
  363. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  364. if (hs_cfg->gap)
  365. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  366. } else if (adapter->hs_cfg.conditions ==
  367. cpu_to_le32(HS_CFG_CANCEL)) {
  368. /* Return failure if no parameters for HS
  369. enable */
  370. status = -1;
  371. break;
  372. }
  373. status = mwifiex_send_cmd(priv,
  374. HostCmd_CMD_802_11_HS_CFG_ENH,
  375. HostCmd_ACT_GEN_SET, 0,
  376. &adapter->hs_cfg,
  377. cmd_type == MWIFIEX_SYNC_CMD);
  378. if (hs_cfg->conditions == HS_CFG_CANCEL)
  379. /* Restore previous condition */
  380. adapter->hs_cfg.conditions =
  381. cpu_to_le32(prev_cond);
  382. } else {
  383. adapter->hs_cfg.conditions =
  384. cpu_to_le32(hs_cfg->conditions);
  385. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  386. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  387. }
  388. break;
  389. case HostCmd_ACT_GEN_GET:
  390. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  391. hs_cfg->gpio = adapter->hs_cfg.gpio;
  392. hs_cfg->gap = adapter->hs_cfg.gap;
  393. break;
  394. default:
  395. status = -1;
  396. break;
  397. }
  398. return status;
  399. }
  400. /*
  401. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  402. *
  403. * This function allocates the IOCTL request buffer, fills it
  404. * with requisite parameters and calls the IOCTL handler.
  405. */
  406. int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
  407. {
  408. struct mwifiex_ds_hs_cfg hscfg;
  409. hscfg.conditions = HS_CFG_CANCEL;
  410. hscfg.is_invoke_hostcmd = true;
  411. return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  412. cmd_type, &hscfg);
  413. }
  414. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  415. /*
  416. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  417. *
  418. * This function allocates the IOCTL request buffer, fills it
  419. * with requisite parameters and calls the IOCTL handler.
  420. */
  421. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  422. {
  423. struct mwifiex_ds_hs_cfg hscfg;
  424. struct mwifiex_private *priv;
  425. int i;
  426. if (disconnect_on_suspend) {
  427. for (i = 0; i < adapter->priv_num; i++) {
  428. priv = adapter->priv[i];
  429. if (priv)
  430. mwifiex_deauthenticate(priv, NULL);
  431. }
  432. }
  433. if (adapter->hs_activated) {
  434. dev_dbg(adapter->dev, "cmd: HS Already activated\n");
  435. return true;
  436. }
  437. adapter->hs_activate_wait_q_woken = false;
  438. memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
  439. hscfg.is_invoke_hostcmd = true;
  440. adapter->hs_enabling = true;
  441. mwifiex_cancel_all_pending_cmd(adapter);
  442. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  443. MWIFIEX_BSS_ROLE_STA),
  444. HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
  445. &hscfg)) {
  446. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  447. return false;
  448. }
  449. if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
  450. adapter->hs_activate_wait_q_woken,
  451. (10 * HZ)) <= 0) {
  452. dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
  453. return false;
  454. }
  455. return true;
  456. }
  457. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  458. /*
  459. * IOCTL request handler to get BSS information.
  460. *
  461. * This function collates the information from different driver structures
  462. * to send to the user.
  463. */
  464. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  465. struct mwifiex_bss_info *info)
  466. {
  467. struct mwifiex_adapter *adapter = priv->adapter;
  468. struct mwifiex_bssdescriptor *bss_desc;
  469. if (!info)
  470. return -1;
  471. bss_desc = &priv->curr_bss_params.bss_descriptor;
  472. info->bss_mode = priv->bss_mode;
  473. memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
  474. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  475. info->bss_chan = bss_desc->channel;
  476. memcpy(info->country_code, adapter->country_code,
  477. IEEE80211_COUNTRY_STRING_LEN);
  478. info->media_connected = priv->media_connected;
  479. info->max_power_level = priv->max_tx_power_level;
  480. info->min_power_level = priv->min_tx_power_level;
  481. info->adhoc_state = priv->adhoc_state;
  482. info->bcn_nf_last = priv->bcn_nf_last;
  483. if (priv->sec_info.wep_enabled)
  484. info->wep_status = true;
  485. else
  486. info->wep_status = false;
  487. info->is_hs_configured = adapter->is_hs_configured;
  488. info->is_deep_sleep = adapter->is_deep_sleep;
  489. return 0;
  490. }
  491. /*
  492. * The function disables auto deep sleep mode.
  493. */
  494. int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
  495. {
  496. struct mwifiex_ds_auto_ds auto_ds;
  497. auto_ds.auto_ds = DEEP_SLEEP_OFF;
  498. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  499. DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
  500. }
  501. EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
  502. /*
  503. * Sends IOCTL request to get the data rate.
  504. *
  505. * This function allocates the IOCTL request buffer, fills it
  506. * with requisite parameters and calls the IOCTL handler.
  507. */
  508. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
  509. {
  510. int ret;
  511. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  512. HostCmd_ACT_GEN_GET, 0, NULL, true);
  513. if (!ret) {
  514. if (priv->is_data_rate_auto)
  515. *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
  516. priv->tx_htinfo);
  517. else
  518. *rate = priv->data_rate;
  519. }
  520. return ret;
  521. }
  522. /*
  523. * IOCTL request handler to set tx power configuration.
  524. *
  525. * This function prepares the correct firmware command and
  526. * issues it.
  527. *
  528. * For non-auto power mode, all the following power groups are set -
  529. * - Modulation class HR/DSSS
  530. * - Modulation class OFDM
  531. * - Modulation class HTBW20
  532. * - Modulation class HTBW40
  533. */
  534. int mwifiex_set_tx_power(struct mwifiex_private *priv,
  535. struct mwifiex_power_cfg *power_cfg)
  536. {
  537. int ret;
  538. struct host_cmd_ds_txpwr_cfg *txp_cfg;
  539. struct mwifiex_types_power_group *pg_tlv;
  540. struct mwifiex_power_group *pg;
  541. u8 *buf;
  542. u16 dbm = 0;
  543. if (!power_cfg->is_power_auto) {
  544. dbm = (u16) power_cfg->power_level;
  545. if ((dbm < priv->min_tx_power_level) ||
  546. (dbm > priv->max_tx_power_level)) {
  547. dev_err(priv->adapter->dev, "txpower value %d dBm"
  548. " is out of range (%d dBm-%d dBm)\n",
  549. dbm, priv->min_tx_power_level,
  550. priv->max_tx_power_level);
  551. return -1;
  552. }
  553. }
  554. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  555. if (!buf)
  556. return -ENOMEM;
  557. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  558. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  559. if (!power_cfg->is_power_auto) {
  560. txp_cfg->mode = cpu_to_le32(1);
  561. pg_tlv = (struct mwifiex_types_power_group *)
  562. (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
  563. pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
  564. pg_tlv->length =
  565. cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
  566. pg = (struct mwifiex_power_group *)
  567. (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
  568. + sizeof(struct mwifiex_types_power_group));
  569. /* Power group for modulation class HR/DSSS */
  570. pg->first_rate_code = 0x00;
  571. pg->last_rate_code = 0x03;
  572. pg->modulation_class = MOD_CLASS_HR_DSSS;
  573. pg->power_step = 0;
  574. pg->power_min = (s8) dbm;
  575. pg->power_max = (s8) dbm;
  576. pg++;
  577. /* Power group for modulation class OFDM */
  578. pg->first_rate_code = 0x00;
  579. pg->last_rate_code = 0x07;
  580. pg->modulation_class = MOD_CLASS_OFDM;
  581. pg->power_step = 0;
  582. pg->power_min = (s8) dbm;
  583. pg->power_max = (s8) dbm;
  584. pg++;
  585. /* Power group for modulation class HTBW20 */
  586. pg->first_rate_code = 0x00;
  587. pg->last_rate_code = 0x20;
  588. pg->modulation_class = MOD_CLASS_HT;
  589. pg->power_step = 0;
  590. pg->power_min = (s8) dbm;
  591. pg->power_max = (s8) dbm;
  592. pg->ht_bandwidth = HT_BW_20;
  593. pg++;
  594. /* Power group for modulation class HTBW40 */
  595. pg->first_rate_code = 0x00;
  596. pg->last_rate_code = 0x20;
  597. pg->modulation_class = MOD_CLASS_HT;
  598. pg->power_step = 0;
  599. pg->power_min = (s8) dbm;
  600. pg->power_max = (s8) dbm;
  601. pg->ht_bandwidth = HT_BW_40;
  602. }
  603. ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
  604. HostCmd_ACT_GEN_SET, 0, buf, true);
  605. kfree(buf);
  606. return ret;
  607. }
  608. /*
  609. * IOCTL request handler to get power save mode.
  610. *
  611. * This function prepares the correct firmware command and
  612. * issues it.
  613. */
  614. int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
  615. {
  616. int ret;
  617. struct mwifiex_adapter *adapter = priv->adapter;
  618. u16 sub_cmd;
  619. if (*ps_mode)
  620. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  621. else
  622. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  623. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  624. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  625. sub_cmd, BITMAP_STA_PS, NULL, true);
  626. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  627. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  628. GET_PS, 0, NULL, false);
  629. return ret;
  630. }
  631. /*
  632. * IOCTL request handler to set/reset WPA IE.
  633. *
  634. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  635. * is checked to determine WPA version. If buffer length is zero, the existing
  636. * WPA IE is reset.
  637. */
  638. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  639. u8 *ie_data_ptr, u16 ie_len)
  640. {
  641. if (ie_len) {
  642. if (ie_len > sizeof(priv->wpa_ie)) {
  643. dev_err(priv->adapter->dev,
  644. "failed to copy WPA IE, too big\n");
  645. return -1;
  646. }
  647. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  648. priv->wpa_ie_len = (u8) ie_len;
  649. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  650. priv->wpa_ie_len, priv->wpa_ie[0]);
  651. if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
  652. priv->sec_info.wpa_enabled = true;
  653. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  654. priv->sec_info.wpa2_enabled = true;
  655. } else {
  656. priv->sec_info.wpa_enabled = false;
  657. priv->sec_info.wpa2_enabled = false;
  658. }
  659. } else {
  660. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  661. priv->wpa_ie_len = 0;
  662. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  663. priv->wpa_ie_len, priv->wpa_ie[0]);
  664. priv->sec_info.wpa_enabled = false;
  665. priv->sec_info.wpa2_enabled = false;
  666. }
  667. return 0;
  668. }
  669. /*
  670. * IOCTL request handler to set/reset WAPI IE.
  671. *
  672. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  673. * is checked to internally enable WAPI. If buffer length is zero, the existing
  674. * WAPI IE is reset.
  675. */
  676. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  677. u8 *ie_data_ptr, u16 ie_len)
  678. {
  679. if (ie_len) {
  680. if (ie_len > sizeof(priv->wapi_ie)) {
  681. dev_dbg(priv->adapter->dev,
  682. "info: failed to copy WAPI IE, too big\n");
  683. return -1;
  684. }
  685. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  686. priv->wapi_ie_len = ie_len;
  687. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  688. priv->wapi_ie_len, priv->wapi_ie[0]);
  689. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  690. priv->sec_info.wapi_enabled = true;
  691. } else {
  692. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  693. priv->wapi_ie_len = ie_len;
  694. dev_dbg(priv->adapter->dev,
  695. "info: Reset wapi_ie_len=%d IE=%#x\n",
  696. priv->wapi_ie_len, priv->wapi_ie[0]);
  697. priv->sec_info.wapi_enabled = false;
  698. }
  699. return 0;
  700. }
  701. /*
  702. * IOCTL request handler to set/reset WPS IE.
  703. *
  704. * The supplied WPS IE is treated as a opaque buffer. Only the first field
  705. * is checked to internally enable WPS. If buffer length is zero, the existing
  706. * WPS IE is reset.
  707. */
  708. static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
  709. u8 *ie_data_ptr, u16 ie_len)
  710. {
  711. if (ie_len) {
  712. if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
  713. dev_dbg(priv->adapter->dev,
  714. "info: failed to copy WPS IE, too big\n");
  715. return -1;
  716. }
  717. priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
  718. if (!priv->wps_ie)
  719. return -ENOMEM;
  720. memcpy(priv->wps_ie, ie_data_ptr, ie_len);
  721. priv->wps_ie_len = ie_len;
  722. dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
  723. priv->wps_ie_len, priv->wps_ie[0]);
  724. } else {
  725. kfree(priv->wps_ie);
  726. priv->wps_ie_len = ie_len;
  727. dev_dbg(priv->adapter->dev,
  728. "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
  729. }
  730. return 0;
  731. }
  732. /*
  733. * IOCTL request handler to set WAPI key.
  734. *
  735. * This function prepares the correct firmware command and
  736. * issues it.
  737. */
  738. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
  739. struct mwifiex_ds_encrypt_key *encrypt_key)
  740. {
  741. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  742. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  743. encrypt_key, true);
  744. }
  745. /*
  746. * IOCTL request handler to set WEP network key.
  747. *
  748. * This function prepares the correct firmware command and
  749. * issues it, after validation checks.
  750. */
  751. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
  752. struct mwifiex_ds_encrypt_key *encrypt_key)
  753. {
  754. struct mwifiex_adapter *adapter = priv->adapter;
  755. int ret;
  756. struct mwifiex_wep_key *wep_key;
  757. int index;
  758. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  759. priv->wep_key_curr_index = 0;
  760. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  761. index = encrypt_key->key_index;
  762. if (encrypt_key->key_disable) {
  763. priv->sec_info.wep_enabled = 0;
  764. } else if (!encrypt_key->key_len) {
  765. /* Copy the required key as the current key */
  766. wep_key = &priv->wep_key[index];
  767. if (!wep_key->key_length) {
  768. dev_err(adapter->dev,
  769. "key not set, so cannot enable it\n");
  770. return -1;
  771. }
  772. if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2) {
  773. memcpy(encrypt_key->key_material,
  774. wep_key->key_material, wep_key->key_length);
  775. encrypt_key->key_len = wep_key->key_length;
  776. }
  777. priv->wep_key_curr_index = (u16) index;
  778. priv->sec_info.wep_enabled = 1;
  779. } else {
  780. wep_key = &priv->wep_key[index];
  781. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  782. /* Copy the key in the driver */
  783. memcpy(wep_key->key_material,
  784. encrypt_key->key_material,
  785. encrypt_key->key_len);
  786. wep_key->key_index = index;
  787. wep_key->key_length = encrypt_key->key_len;
  788. priv->sec_info.wep_enabled = 1;
  789. }
  790. if (wep_key->key_length) {
  791. void *enc_key;
  792. if (encrypt_key->key_disable)
  793. memset(&priv->wep_key[index], 0,
  794. sizeof(struct mwifiex_wep_key));
  795. if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2)
  796. enc_key = encrypt_key;
  797. else
  798. enc_key = NULL;
  799. /* Send request to firmware */
  800. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  801. HostCmd_ACT_GEN_SET, 0, enc_key, false);
  802. if (ret)
  803. return ret;
  804. }
  805. if (priv->sec_info.wep_enabled)
  806. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  807. else
  808. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  809. ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  810. HostCmd_ACT_GEN_SET, 0,
  811. &priv->curr_pkt_filter, true);
  812. return ret;
  813. }
  814. /*
  815. * IOCTL request handler to set WPA key.
  816. *
  817. * This function prepares the correct firmware command and
  818. * issues it, after validation checks.
  819. *
  820. * Current driver only supports key length of up to 32 bytes.
  821. *
  822. * This function can also be used to disable a currently set key.
  823. */
  824. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
  825. struct mwifiex_ds_encrypt_key *encrypt_key)
  826. {
  827. int ret;
  828. u8 remove_key = false;
  829. struct host_cmd_ds_802_11_key_material *ibss_key;
  830. /* Current driver only supports key length of up to 32 bytes */
  831. if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
  832. dev_err(priv->adapter->dev, "key length too long\n");
  833. return -1;
  834. }
  835. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  836. /*
  837. * IBSS/WPA-None uses only one key (Group) for both receiving
  838. * and sending unicast and multicast packets.
  839. */
  840. /* Send the key as PTK to firmware */
  841. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  842. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  843. HostCmd_ACT_GEN_SET,
  844. KEY_INFO_ENABLED, encrypt_key, false);
  845. if (ret)
  846. return ret;
  847. ibss_key = &priv->aes_key;
  848. memset(ibss_key, 0,
  849. sizeof(struct host_cmd_ds_802_11_key_material));
  850. /* Copy the key in the driver */
  851. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  852. encrypt_key->key_len);
  853. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  854. sizeof(ibss_key->key_param_set.key_len));
  855. ibss_key->key_param_set.key_type_id
  856. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  857. ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
  858. /* Send the key as GTK to firmware */
  859. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  860. }
  861. if (!encrypt_key->key_index)
  862. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  863. if (remove_key)
  864. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  865. HostCmd_ACT_GEN_SET,
  866. !KEY_INFO_ENABLED, encrypt_key, true);
  867. else
  868. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  869. HostCmd_ACT_GEN_SET,
  870. KEY_INFO_ENABLED, encrypt_key, true);
  871. return ret;
  872. }
  873. /*
  874. * IOCTL request handler to set/get network keys.
  875. *
  876. * This is a generic key handling function which supports WEP, WPA
  877. * and WAPI.
  878. */
  879. static int
  880. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  881. struct mwifiex_ds_encrypt_key *encrypt_key)
  882. {
  883. int status;
  884. if (encrypt_key->is_wapi_key)
  885. status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
  886. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  887. status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
  888. else
  889. status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
  890. return status;
  891. }
  892. /*
  893. * This function returns the driver version.
  894. */
  895. int
  896. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  897. int max_len)
  898. {
  899. union {
  900. u32 l;
  901. u8 c[4];
  902. } ver;
  903. char fw_ver[32];
  904. ver.l = adapter->fw_release_number;
  905. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  906. snprintf(version, max_len, driver_version, fw_ver);
  907. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  908. return 0;
  909. }
  910. /*
  911. * Sends IOCTL request to set encoding parameters.
  912. *
  913. * This function allocates the IOCTL request buffer, fills it
  914. * with requisite parameters and calls the IOCTL handler.
  915. */
  916. int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
  917. const u8 *key, int key_len, u8 key_index,
  918. const u8 *mac_addr, int disable)
  919. {
  920. struct mwifiex_ds_encrypt_key encrypt_key;
  921. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  922. encrypt_key.key_len = key_len;
  923. encrypt_key.key_index = key_index;
  924. if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
  925. encrypt_key.is_igtk_key = true;
  926. if (!disable) {
  927. if (key_len)
  928. memcpy(encrypt_key.key_material, key, key_len);
  929. else
  930. encrypt_key.is_current_wep_key = true;
  931. if (mac_addr)
  932. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  933. if (kp && kp->seq && kp->seq_len) {
  934. memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
  935. encrypt_key.pn_len = kp->seq_len;
  936. encrypt_key.is_rx_seq_valid = true;
  937. }
  938. } else {
  939. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
  940. return 0;
  941. encrypt_key.key_disable = true;
  942. if (mac_addr)
  943. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  944. }
  945. return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
  946. }
  947. /*
  948. * Sends IOCTL request to get extended version.
  949. *
  950. * This function allocates the IOCTL request buffer, fills it
  951. * with requisite parameters and calls the IOCTL handler.
  952. */
  953. int
  954. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  955. {
  956. struct mwifiex_ver_ext ver_ext;
  957. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  958. if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
  959. HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
  960. return -1;
  961. return 0;
  962. }
  963. int
  964. mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
  965. struct ieee80211_channel *chan,
  966. unsigned int duration)
  967. {
  968. struct host_cmd_ds_remain_on_chan roc_cfg;
  969. u8 sc;
  970. memset(&roc_cfg, 0, sizeof(roc_cfg));
  971. roc_cfg.action = cpu_to_le16(action);
  972. if (action == HostCmd_ACT_GEN_SET) {
  973. roc_cfg.band_cfg = chan->band;
  974. sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
  975. roc_cfg.band_cfg |= (sc << 2);
  976. roc_cfg.channel =
  977. ieee80211_frequency_to_channel(chan->center_freq);
  978. roc_cfg.duration = cpu_to_le32(duration);
  979. }
  980. if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
  981. action, 0, &roc_cfg, true)) {
  982. dev_err(priv->adapter->dev, "failed to remain on channel\n");
  983. return -1;
  984. }
  985. return roc_cfg.status;
  986. }
  987. int
  988. mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
  989. {
  990. if (GET_BSS_ROLE(priv) == bss_role) {
  991. dev_dbg(priv->adapter->dev,
  992. "info: already in the desired role.\n");
  993. return 0;
  994. }
  995. mwifiex_free_priv(priv);
  996. mwifiex_init_priv(priv);
  997. priv->bss_role = bss_role;
  998. switch (bss_role) {
  999. case MWIFIEX_BSS_ROLE_UAP:
  1000. priv->bss_mode = NL80211_IFTYPE_AP;
  1001. break;
  1002. case MWIFIEX_BSS_ROLE_STA:
  1003. case MWIFIEX_BSS_ROLE_ANY:
  1004. default:
  1005. priv->bss_mode = NL80211_IFTYPE_STATION;
  1006. break;
  1007. }
  1008. mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  1009. HostCmd_ACT_GEN_SET, 0, NULL, true);
  1010. return mwifiex_sta_init_cmd(priv, false);
  1011. }
  1012. /*
  1013. * Sends IOCTL request to get statistics information.
  1014. *
  1015. * This function allocates the IOCTL request buffer, fills it
  1016. * with requisite parameters and calls the IOCTL handler.
  1017. */
  1018. int
  1019. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1020. struct mwifiex_ds_get_stats *log)
  1021. {
  1022. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
  1023. HostCmd_ACT_GEN_GET, 0, log, true);
  1024. }
  1025. /*
  1026. * IOCTL request handler to read/write register.
  1027. *
  1028. * This function prepares the correct firmware command and
  1029. * issues it.
  1030. *
  1031. * Access to the following registers are supported -
  1032. * - MAC
  1033. * - BBP
  1034. * - RF
  1035. * - PMIC
  1036. * - CAU
  1037. */
  1038. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1039. struct mwifiex_ds_reg_rw *reg_rw,
  1040. u16 action)
  1041. {
  1042. u16 cmd_no;
  1043. switch (le32_to_cpu(reg_rw->type)) {
  1044. case MWIFIEX_REG_MAC:
  1045. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1046. break;
  1047. case MWIFIEX_REG_BBP:
  1048. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1049. break;
  1050. case MWIFIEX_REG_RF:
  1051. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1052. break;
  1053. case MWIFIEX_REG_PMIC:
  1054. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1055. break;
  1056. case MWIFIEX_REG_CAU:
  1057. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1058. break;
  1059. default:
  1060. return -1;
  1061. }
  1062. return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
  1063. }
  1064. /*
  1065. * Sends IOCTL request to write to a register.
  1066. *
  1067. * This function allocates the IOCTL request buffer, fills it
  1068. * with requisite parameters and calls the IOCTL handler.
  1069. */
  1070. int
  1071. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1072. u32 reg_offset, u32 reg_value)
  1073. {
  1074. struct mwifiex_ds_reg_rw reg_rw;
  1075. reg_rw.type = cpu_to_le32(reg_type);
  1076. reg_rw.offset = cpu_to_le32(reg_offset);
  1077. reg_rw.value = cpu_to_le32(reg_value);
  1078. return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
  1079. }
  1080. /*
  1081. * Sends IOCTL request to read from a register.
  1082. *
  1083. * This function allocates the IOCTL request buffer, fills it
  1084. * with requisite parameters and calls the IOCTL handler.
  1085. */
  1086. int
  1087. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1088. u32 reg_offset, u32 *value)
  1089. {
  1090. int ret;
  1091. struct mwifiex_ds_reg_rw reg_rw;
  1092. reg_rw.type = cpu_to_le32(reg_type);
  1093. reg_rw.offset = cpu_to_le32(reg_offset);
  1094. ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
  1095. if (ret)
  1096. goto done;
  1097. *value = le32_to_cpu(reg_rw.value);
  1098. done:
  1099. return ret;
  1100. }
  1101. /*
  1102. * Sends IOCTL request to read from EEPROM.
  1103. *
  1104. * This function allocates the IOCTL request buffer, fills it
  1105. * with requisite parameters and calls the IOCTL handler.
  1106. */
  1107. int
  1108. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1109. u8 *value)
  1110. {
  1111. int ret;
  1112. struct mwifiex_ds_read_eeprom rd_eeprom;
  1113. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1114. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1115. /* Send request to firmware */
  1116. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1117. HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
  1118. if (!ret)
  1119. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1120. return ret;
  1121. }
  1122. /*
  1123. * This function sets a generic IE. In addition to generic IE, it can
  1124. * also handle WPA, WPA2 and WAPI IEs.
  1125. */
  1126. static int
  1127. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1128. u16 ie_len)
  1129. {
  1130. int ret = 0;
  1131. struct ieee_types_vendor_header *pvendor_ie;
  1132. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1133. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1134. /* If the passed length is zero, reset the buffer */
  1135. if (!ie_len) {
  1136. priv->gen_ie_buf_len = 0;
  1137. priv->wps.session_enable = false;
  1138. return 0;
  1139. } else if (!ie_data_ptr) {
  1140. return -1;
  1141. }
  1142. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1143. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1144. if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
  1145. (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
  1146. (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1147. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1148. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1149. priv->wps.session_enable = false;
  1150. return ret;
  1151. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1152. /* IE is a WAPI IE so call set_wapi function */
  1153. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1154. return ret;
  1155. }
  1156. /*
  1157. * Verify that the passed length is not larger than the
  1158. * available space remaining in the buffer
  1159. */
  1160. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1161. /* Test to see if it is a WPS IE, if so, enable
  1162. * wps session flag
  1163. */
  1164. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1165. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
  1166. (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
  1167. priv->wps.session_enable = true;
  1168. dev_dbg(priv->adapter->dev,
  1169. "info: WPS Session Enabled.\n");
  1170. ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
  1171. }
  1172. /* Append the passed data to the end of the
  1173. genIeBuffer */
  1174. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  1175. ie_len);
  1176. /* Increment the stored buffer length by the
  1177. size passed */
  1178. priv->gen_ie_buf_len += ie_len;
  1179. } else {
  1180. /* Passed data does not fit in the remaining
  1181. buffer space */
  1182. ret = -1;
  1183. }
  1184. /* Return 0, or -1 for error case */
  1185. return ret;
  1186. }
  1187. /*
  1188. * IOCTL request handler to set/get generic IE.
  1189. *
  1190. * In addition to various generic IEs, this function can also be
  1191. * used to set the ARP filter.
  1192. */
  1193. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  1194. struct mwifiex_ds_misc_gen_ie *gen_ie,
  1195. u16 action)
  1196. {
  1197. struct mwifiex_adapter *adapter = priv->adapter;
  1198. switch (gen_ie->type) {
  1199. case MWIFIEX_IE_TYPE_GEN_IE:
  1200. if (action == HostCmd_ACT_GEN_GET) {
  1201. gen_ie->len = priv->wpa_ie_len;
  1202. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  1203. } else {
  1204. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  1205. (u16) gen_ie->len);
  1206. }
  1207. break;
  1208. case MWIFIEX_IE_TYPE_ARP_FILTER:
  1209. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  1210. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  1211. adapter->arp_filter_size = 0;
  1212. dev_err(adapter->dev, "invalid ARP filter size\n");
  1213. return -1;
  1214. } else {
  1215. memcpy(adapter->arp_filter, gen_ie->ie_data,
  1216. gen_ie->len);
  1217. adapter->arp_filter_size = gen_ie->len;
  1218. }
  1219. break;
  1220. default:
  1221. dev_err(adapter->dev, "invalid IE type\n");
  1222. return -1;
  1223. }
  1224. return 0;
  1225. }
  1226. /*
  1227. * Sends IOCTL request to set a generic IE.
  1228. *
  1229. * This function allocates the IOCTL request buffer, fills it
  1230. * with requisite parameters and calls the IOCTL handler.
  1231. */
  1232. int
  1233. mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
  1234. {
  1235. struct mwifiex_ds_misc_gen_ie gen_ie;
  1236. if (ie_len > IEEE_MAX_IE_SIZE)
  1237. return -EFAULT;
  1238. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  1239. gen_ie.len = ie_len;
  1240. memcpy(gen_ie.ie_data, ie, ie_len);
  1241. if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
  1242. return -EFAULT;
  1243. return 0;
  1244. }