sta_ioctl.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. /*
  2. * Marvell Wireless LAN device driver: functions for station ioctl
  3. *
  4. * Copyright (C) 2011-2014, 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;
  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. if (!bss_desc)
  246. return -1;
  247. if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
  248. HostCmd_SCAN_RADIO_TYPE_BG) {
  249. config_bands = BAND_B | BAND_G | BAND_GN;
  250. } else {
  251. config_bands = BAND_A | BAND_AN;
  252. if (adapter->fw_bands & BAND_AAC)
  253. config_bands |= BAND_AAC;
  254. }
  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. priv->adhoc_is_link_sensed = false;
  297. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  298. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  299. if (netif_carrier_ok(priv->netdev))
  300. netif_carrier_off(priv->netdev);
  301. if (!ret) {
  302. dev_dbg(adapter->dev, "info: network found in scan"
  303. " list. Joining...\n");
  304. ret = mwifiex_adhoc_join(priv, bss_desc);
  305. if (bss)
  306. cfg80211_put_bss(priv->adapter->wiphy, bss);
  307. } else {
  308. dev_dbg(adapter->dev, "info: Network not found in "
  309. "the list, creating adhoc with ssid = %s\n",
  310. req_ssid->ssid);
  311. ret = mwifiex_adhoc_start(priv, req_ssid);
  312. }
  313. }
  314. done:
  315. /* beacon_ie buffer was allocated in function
  316. * mwifiex_fill_new_bss_desc(). Free it now.
  317. */
  318. if (bss_desc)
  319. kfree(bss_desc->beacon_buf);
  320. kfree(bss_desc);
  321. return ret;
  322. }
  323. /*
  324. * IOCTL request handler to set host sleep configuration.
  325. *
  326. * This function prepares the correct firmware command and
  327. * issues it.
  328. */
  329. int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  330. int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
  331. {
  332. struct mwifiex_adapter *adapter = priv->adapter;
  333. int status = 0;
  334. u32 prev_cond = 0;
  335. if (!hs_cfg)
  336. return -ENOMEM;
  337. switch (action) {
  338. case HostCmd_ACT_GEN_SET:
  339. if (adapter->pps_uapsd_mode) {
  340. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  341. " is blocked in UAPSD/PPS mode\n");
  342. status = -1;
  343. break;
  344. }
  345. if (hs_cfg->is_invoke_hostcmd) {
  346. if (hs_cfg->conditions == HS_CFG_CANCEL) {
  347. if (!adapter->is_hs_configured)
  348. /* Already cancelled */
  349. break;
  350. /* Save previous condition */
  351. prev_cond = le32_to_cpu(adapter->hs_cfg
  352. .conditions);
  353. adapter->hs_cfg.conditions =
  354. cpu_to_le32(hs_cfg->conditions);
  355. } else if (hs_cfg->conditions) {
  356. adapter->hs_cfg.conditions =
  357. cpu_to_le32(hs_cfg->conditions);
  358. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  359. if (hs_cfg->gap)
  360. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  361. } else if (adapter->hs_cfg.conditions ==
  362. cpu_to_le32(HS_CFG_CANCEL)) {
  363. /* Return failure if no parameters for HS
  364. enable */
  365. status = -1;
  366. break;
  367. }
  368. status = mwifiex_send_cmd(priv,
  369. HostCmd_CMD_802_11_HS_CFG_ENH,
  370. HostCmd_ACT_GEN_SET, 0,
  371. &adapter->hs_cfg,
  372. cmd_type == MWIFIEX_SYNC_CMD);
  373. if (hs_cfg->conditions == HS_CFG_CANCEL)
  374. /* Restore previous condition */
  375. adapter->hs_cfg.conditions =
  376. cpu_to_le32(prev_cond);
  377. } else {
  378. adapter->hs_cfg.conditions =
  379. cpu_to_le32(hs_cfg->conditions);
  380. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  381. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  382. }
  383. break;
  384. case HostCmd_ACT_GEN_GET:
  385. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  386. hs_cfg->gpio = adapter->hs_cfg.gpio;
  387. hs_cfg->gap = adapter->hs_cfg.gap;
  388. break;
  389. default:
  390. status = -1;
  391. break;
  392. }
  393. return status;
  394. }
  395. /*
  396. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  397. *
  398. * This function allocates the IOCTL request buffer, fills it
  399. * with requisite parameters and calls the IOCTL handler.
  400. */
  401. int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
  402. {
  403. struct mwifiex_ds_hs_cfg hscfg;
  404. hscfg.conditions = HS_CFG_CANCEL;
  405. hscfg.is_invoke_hostcmd = true;
  406. return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  407. cmd_type, &hscfg);
  408. }
  409. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  410. /*
  411. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  412. *
  413. * This function allocates the IOCTL request buffer, fills it
  414. * with requisite parameters and calls the IOCTL handler.
  415. */
  416. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  417. {
  418. struct mwifiex_ds_hs_cfg hscfg;
  419. struct mwifiex_private *priv;
  420. int i;
  421. if (disconnect_on_suspend) {
  422. for (i = 0; i < adapter->priv_num; i++) {
  423. priv = adapter->priv[i];
  424. if (priv)
  425. mwifiex_deauthenticate(priv, NULL);
  426. }
  427. }
  428. if (adapter->hs_activated) {
  429. dev_dbg(adapter->dev, "cmd: HS Already activated\n");
  430. return true;
  431. }
  432. adapter->hs_activate_wait_q_woken = false;
  433. memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
  434. hscfg.is_invoke_hostcmd = true;
  435. adapter->hs_enabling = true;
  436. mwifiex_cancel_all_pending_cmd(adapter);
  437. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  438. MWIFIEX_BSS_ROLE_STA),
  439. HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
  440. &hscfg)) {
  441. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  442. return false;
  443. }
  444. if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
  445. adapter->hs_activate_wait_q_woken,
  446. (10 * HZ)) <= 0) {
  447. dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
  448. return false;
  449. }
  450. return true;
  451. }
  452. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  453. /*
  454. * IOCTL request handler to get BSS information.
  455. *
  456. * This function collates the information from different driver structures
  457. * to send to the user.
  458. */
  459. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  460. struct mwifiex_bss_info *info)
  461. {
  462. struct mwifiex_adapter *adapter = priv->adapter;
  463. struct mwifiex_bssdescriptor *bss_desc;
  464. if (!info)
  465. return -1;
  466. bss_desc = &priv->curr_bss_params.bss_descriptor;
  467. info->bss_mode = priv->bss_mode;
  468. memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
  469. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  470. info->bss_chan = bss_desc->channel;
  471. memcpy(info->country_code, adapter->country_code,
  472. IEEE80211_COUNTRY_STRING_LEN);
  473. info->media_connected = priv->media_connected;
  474. info->max_power_level = priv->max_tx_power_level;
  475. info->min_power_level = priv->min_tx_power_level;
  476. info->adhoc_state = priv->adhoc_state;
  477. info->bcn_nf_last = priv->bcn_nf_last;
  478. if (priv->sec_info.wep_enabled)
  479. info->wep_status = true;
  480. else
  481. info->wep_status = false;
  482. info->is_hs_configured = adapter->is_hs_configured;
  483. info->is_deep_sleep = adapter->is_deep_sleep;
  484. return 0;
  485. }
  486. /*
  487. * The function disables auto deep sleep mode.
  488. */
  489. int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
  490. {
  491. struct mwifiex_ds_auto_ds auto_ds;
  492. auto_ds.auto_ds = DEEP_SLEEP_OFF;
  493. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  494. DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
  495. }
  496. EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
  497. /*
  498. * Sends IOCTL request to get the data rate.
  499. *
  500. * This function allocates the IOCTL request buffer, fills it
  501. * with requisite parameters and calls the IOCTL handler.
  502. */
  503. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
  504. {
  505. int ret;
  506. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  507. HostCmd_ACT_GEN_GET, 0, NULL, true);
  508. if (!ret) {
  509. if (priv->is_data_rate_auto)
  510. *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
  511. priv->tx_htinfo);
  512. else
  513. *rate = priv->data_rate;
  514. }
  515. return ret;
  516. }
  517. /*
  518. * IOCTL request handler to set tx power configuration.
  519. *
  520. * This function prepares the correct firmware command and
  521. * issues it.
  522. *
  523. * For non-auto power mode, all the following power groups are set -
  524. * - Modulation class HR/DSSS
  525. * - Modulation class OFDM
  526. * - Modulation class HTBW20
  527. * - Modulation class HTBW40
  528. */
  529. int mwifiex_set_tx_power(struct mwifiex_private *priv,
  530. struct mwifiex_power_cfg *power_cfg)
  531. {
  532. int ret;
  533. struct host_cmd_ds_txpwr_cfg *txp_cfg;
  534. struct mwifiex_types_power_group *pg_tlv;
  535. struct mwifiex_power_group *pg;
  536. u8 *buf;
  537. u16 dbm = 0;
  538. if (!power_cfg->is_power_auto) {
  539. dbm = (u16) power_cfg->power_level;
  540. if ((dbm < priv->min_tx_power_level) ||
  541. (dbm > priv->max_tx_power_level)) {
  542. dev_err(priv->adapter->dev, "txpower value %d dBm"
  543. " is out of range (%d dBm-%d dBm)\n",
  544. dbm, priv->min_tx_power_level,
  545. priv->max_tx_power_level);
  546. return -1;
  547. }
  548. }
  549. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  550. if (!buf)
  551. return -ENOMEM;
  552. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  553. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  554. if (!power_cfg->is_power_auto) {
  555. txp_cfg->mode = cpu_to_le32(1);
  556. pg_tlv = (struct mwifiex_types_power_group *)
  557. (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
  558. pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
  559. pg_tlv->length =
  560. cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
  561. pg = (struct mwifiex_power_group *)
  562. (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
  563. + sizeof(struct mwifiex_types_power_group));
  564. /* Power group for modulation class HR/DSSS */
  565. pg->first_rate_code = 0x00;
  566. pg->last_rate_code = 0x03;
  567. pg->modulation_class = MOD_CLASS_HR_DSSS;
  568. pg->power_step = 0;
  569. pg->power_min = (s8) dbm;
  570. pg->power_max = (s8) dbm;
  571. pg++;
  572. /* Power group for modulation class OFDM */
  573. pg->first_rate_code = 0x00;
  574. pg->last_rate_code = 0x07;
  575. pg->modulation_class = MOD_CLASS_OFDM;
  576. pg->power_step = 0;
  577. pg->power_min = (s8) dbm;
  578. pg->power_max = (s8) dbm;
  579. pg++;
  580. /* Power group for modulation class HTBW20 */
  581. pg->first_rate_code = 0x00;
  582. pg->last_rate_code = 0x20;
  583. pg->modulation_class = MOD_CLASS_HT;
  584. pg->power_step = 0;
  585. pg->power_min = (s8) dbm;
  586. pg->power_max = (s8) dbm;
  587. pg->ht_bandwidth = HT_BW_20;
  588. pg++;
  589. /* Power group for modulation class HTBW40 */
  590. pg->first_rate_code = 0x00;
  591. pg->last_rate_code = 0x20;
  592. pg->modulation_class = MOD_CLASS_HT;
  593. pg->power_step = 0;
  594. pg->power_min = (s8) dbm;
  595. pg->power_max = (s8) dbm;
  596. pg->ht_bandwidth = HT_BW_40;
  597. }
  598. ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
  599. HostCmd_ACT_GEN_SET, 0, buf, true);
  600. kfree(buf);
  601. return ret;
  602. }
  603. /*
  604. * IOCTL request handler to get power save mode.
  605. *
  606. * This function prepares the correct firmware command and
  607. * issues it.
  608. */
  609. int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
  610. {
  611. int ret;
  612. struct mwifiex_adapter *adapter = priv->adapter;
  613. u16 sub_cmd;
  614. if (*ps_mode)
  615. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  616. else
  617. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  618. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  619. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  620. sub_cmd, BITMAP_STA_PS, NULL, true);
  621. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  622. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  623. GET_PS, 0, NULL, false);
  624. return ret;
  625. }
  626. /*
  627. * IOCTL request handler to set/reset WPA IE.
  628. *
  629. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  630. * is checked to determine WPA version. If buffer length is zero, the existing
  631. * WPA IE is reset.
  632. */
  633. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  634. u8 *ie_data_ptr, u16 ie_len)
  635. {
  636. if (ie_len) {
  637. if (ie_len > sizeof(priv->wpa_ie)) {
  638. dev_err(priv->adapter->dev,
  639. "failed to copy WPA IE, too big\n");
  640. return -1;
  641. }
  642. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  643. priv->wpa_ie_len = (u8) ie_len;
  644. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  645. priv->wpa_ie_len, priv->wpa_ie[0]);
  646. if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
  647. priv->sec_info.wpa_enabled = true;
  648. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  649. priv->sec_info.wpa2_enabled = true;
  650. } else {
  651. priv->sec_info.wpa_enabled = false;
  652. priv->sec_info.wpa2_enabled = false;
  653. }
  654. } else {
  655. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  656. priv->wpa_ie_len = 0;
  657. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  658. priv->wpa_ie_len, priv->wpa_ie[0]);
  659. priv->sec_info.wpa_enabled = false;
  660. priv->sec_info.wpa2_enabled = false;
  661. }
  662. return 0;
  663. }
  664. /*
  665. * IOCTL request handler to set/reset WAPI IE.
  666. *
  667. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  668. * is checked to internally enable WAPI. If buffer length is zero, the existing
  669. * WAPI IE is reset.
  670. */
  671. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  672. u8 *ie_data_ptr, u16 ie_len)
  673. {
  674. if (ie_len) {
  675. if (ie_len > sizeof(priv->wapi_ie)) {
  676. dev_dbg(priv->adapter->dev,
  677. "info: failed to copy WAPI IE, too big\n");
  678. return -1;
  679. }
  680. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  681. priv->wapi_ie_len = ie_len;
  682. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  683. priv->wapi_ie_len, priv->wapi_ie[0]);
  684. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  685. priv->sec_info.wapi_enabled = true;
  686. } else {
  687. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  688. priv->wapi_ie_len = ie_len;
  689. dev_dbg(priv->adapter->dev,
  690. "info: Reset wapi_ie_len=%d IE=%#x\n",
  691. priv->wapi_ie_len, priv->wapi_ie[0]);
  692. priv->sec_info.wapi_enabled = false;
  693. }
  694. return 0;
  695. }
  696. /*
  697. * IOCTL request handler to set/reset WPS IE.
  698. *
  699. * The supplied WPS IE is treated as a opaque buffer. Only the first field
  700. * is checked to internally enable WPS. If buffer length is zero, the existing
  701. * WPS IE is reset.
  702. */
  703. static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
  704. u8 *ie_data_ptr, u16 ie_len)
  705. {
  706. if (ie_len) {
  707. if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
  708. dev_dbg(priv->adapter->dev,
  709. "info: failed to copy WPS IE, too big\n");
  710. return -1;
  711. }
  712. priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
  713. if (!priv->wps_ie)
  714. return -ENOMEM;
  715. memcpy(priv->wps_ie, ie_data_ptr, ie_len);
  716. priv->wps_ie_len = ie_len;
  717. dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
  718. priv->wps_ie_len, priv->wps_ie[0]);
  719. } else {
  720. kfree(priv->wps_ie);
  721. priv->wps_ie_len = ie_len;
  722. dev_dbg(priv->adapter->dev,
  723. "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
  724. }
  725. return 0;
  726. }
  727. /*
  728. * IOCTL request handler to set WAPI key.
  729. *
  730. * This function prepares the correct firmware command and
  731. * issues it.
  732. */
  733. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
  734. struct mwifiex_ds_encrypt_key *encrypt_key)
  735. {
  736. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  737. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  738. encrypt_key, true);
  739. }
  740. /*
  741. * IOCTL request handler to set WEP network key.
  742. *
  743. * This function prepares the correct firmware command and
  744. * issues it, after validation checks.
  745. */
  746. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
  747. struct mwifiex_ds_encrypt_key *encrypt_key)
  748. {
  749. struct mwifiex_adapter *adapter = priv->adapter;
  750. int ret;
  751. struct mwifiex_wep_key *wep_key;
  752. int index;
  753. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  754. priv->wep_key_curr_index = 0;
  755. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  756. index = encrypt_key->key_index;
  757. if (encrypt_key->key_disable) {
  758. priv->sec_info.wep_enabled = 0;
  759. } else if (!encrypt_key->key_len) {
  760. /* Copy the required key as the current key */
  761. wep_key = &priv->wep_key[index];
  762. if (!wep_key->key_length) {
  763. dev_err(adapter->dev,
  764. "key not set, so cannot enable it\n");
  765. return -1;
  766. }
  767. if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2) {
  768. memcpy(encrypt_key->key_material,
  769. wep_key->key_material, wep_key->key_length);
  770. encrypt_key->key_len = wep_key->key_length;
  771. }
  772. priv->wep_key_curr_index = (u16) index;
  773. priv->sec_info.wep_enabled = 1;
  774. } else {
  775. wep_key = &priv->wep_key[index];
  776. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  777. /* Copy the key in the driver */
  778. memcpy(wep_key->key_material,
  779. encrypt_key->key_material,
  780. encrypt_key->key_len);
  781. wep_key->key_index = index;
  782. wep_key->key_length = encrypt_key->key_len;
  783. priv->sec_info.wep_enabled = 1;
  784. }
  785. if (wep_key->key_length) {
  786. void *enc_key;
  787. if (encrypt_key->key_disable)
  788. memset(&priv->wep_key[index], 0,
  789. sizeof(struct mwifiex_wep_key));
  790. if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
  791. enc_key = encrypt_key;
  792. else
  793. enc_key = NULL;
  794. /* Send request to firmware */
  795. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  796. HostCmd_ACT_GEN_SET, 0, enc_key, false);
  797. if (ret)
  798. return ret;
  799. }
  800. if (priv->sec_info.wep_enabled)
  801. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  802. else
  803. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  804. ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  805. HostCmd_ACT_GEN_SET, 0,
  806. &priv->curr_pkt_filter, true);
  807. return ret;
  808. }
  809. /*
  810. * IOCTL request handler to set WPA key.
  811. *
  812. * This function prepares the correct firmware command and
  813. * issues it, after validation checks.
  814. *
  815. * Current driver only supports key length of up to 32 bytes.
  816. *
  817. * This function can also be used to disable a currently set key.
  818. */
  819. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
  820. struct mwifiex_ds_encrypt_key *encrypt_key)
  821. {
  822. int ret;
  823. u8 remove_key = false;
  824. struct host_cmd_ds_802_11_key_material *ibss_key;
  825. /* Current driver only supports key length of up to 32 bytes */
  826. if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
  827. dev_err(priv->adapter->dev, "key length too long\n");
  828. return -1;
  829. }
  830. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  831. /*
  832. * IBSS/WPA-None uses only one key (Group) for both receiving
  833. * and sending unicast and multicast packets.
  834. */
  835. /* Send the key as PTK to firmware */
  836. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  837. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  838. HostCmd_ACT_GEN_SET,
  839. KEY_INFO_ENABLED, encrypt_key, false);
  840. if (ret)
  841. return ret;
  842. ibss_key = &priv->aes_key;
  843. memset(ibss_key, 0,
  844. sizeof(struct host_cmd_ds_802_11_key_material));
  845. /* Copy the key in the driver */
  846. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  847. encrypt_key->key_len);
  848. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  849. sizeof(ibss_key->key_param_set.key_len));
  850. ibss_key->key_param_set.key_type_id
  851. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  852. ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
  853. /* Send the key as GTK to firmware */
  854. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  855. }
  856. if (!encrypt_key->key_index)
  857. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  858. if (remove_key)
  859. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  860. HostCmd_ACT_GEN_SET,
  861. !KEY_INFO_ENABLED, encrypt_key, true);
  862. else
  863. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  864. HostCmd_ACT_GEN_SET,
  865. KEY_INFO_ENABLED, encrypt_key, true);
  866. return ret;
  867. }
  868. /*
  869. * IOCTL request handler to set/get network keys.
  870. *
  871. * This is a generic key handling function which supports WEP, WPA
  872. * and WAPI.
  873. */
  874. static int
  875. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  876. struct mwifiex_ds_encrypt_key *encrypt_key)
  877. {
  878. int status;
  879. if (encrypt_key->is_wapi_key)
  880. status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
  881. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  882. status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
  883. else
  884. status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
  885. return status;
  886. }
  887. /*
  888. * This function returns the driver version.
  889. */
  890. int
  891. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  892. int max_len)
  893. {
  894. union {
  895. __le32 l;
  896. u8 c[4];
  897. } ver;
  898. char fw_ver[32];
  899. ver.l = cpu_to_le32(adapter->fw_release_number);
  900. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  901. snprintf(version, max_len, driver_version, fw_ver);
  902. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  903. return 0;
  904. }
  905. /*
  906. * Sends IOCTL request to set encoding parameters.
  907. *
  908. * This function allocates the IOCTL request buffer, fills it
  909. * with requisite parameters and calls the IOCTL handler.
  910. */
  911. int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
  912. const u8 *key, int key_len, u8 key_index,
  913. const u8 *mac_addr, int disable)
  914. {
  915. struct mwifiex_ds_encrypt_key encrypt_key;
  916. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  917. encrypt_key.key_len = key_len;
  918. encrypt_key.key_index = key_index;
  919. if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
  920. encrypt_key.is_igtk_key = true;
  921. if (!disable) {
  922. if (key_len)
  923. memcpy(encrypt_key.key_material, key, key_len);
  924. else
  925. encrypt_key.is_current_wep_key = true;
  926. if (mac_addr)
  927. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  928. if (kp && kp->seq && kp->seq_len) {
  929. memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
  930. encrypt_key.pn_len = kp->seq_len;
  931. encrypt_key.is_rx_seq_valid = true;
  932. }
  933. } else {
  934. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
  935. return 0;
  936. encrypt_key.key_disable = true;
  937. if (mac_addr)
  938. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  939. }
  940. return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
  941. }
  942. /*
  943. * Sends IOCTL request to get extended version.
  944. *
  945. * This function allocates the IOCTL request buffer, fills it
  946. * with requisite parameters and calls the IOCTL handler.
  947. */
  948. int
  949. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  950. {
  951. struct mwifiex_ver_ext ver_ext;
  952. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  953. if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
  954. HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
  955. return -1;
  956. return 0;
  957. }
  958. int
  959. mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
  960. struct ieee80211_channel *chan,
  961. unsigned int duration)
  962. {
  963. struct host_cmd_ds_remain_on_chan roc_cfg;
  964. u8 sc;
  965. memset(&roc_cfg, 0, sizeof(roc_cfg));
  966. roc_cfg.action = cpu_to_le16(action);
  967. if (action == HostCmd_ACT_GEN_SET) {
  968. roc_cfg.band_cfg = chan->band;
  969. sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
  970. roc_cfg.band_cfg |= (sc << 2);
  971. roc_cfg.channel =
  972. ieee80211_frequency_to_channel(chan->center_freq);
  973. roc_cfg.duration = cpu_to_le32(duration);
  974. }
  975. if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
  976. action, 0, &roc_cfg, true)) {
  977. dev_err(priv->adapter->dev, "failed to remain on channel\n");
  978. return -1;
  979. }
  980. return roc_cfg.status;
  981. }
  982. int
  983. mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
  984. {
  985. if (GET_BSS_ROLE(priv) == bss_role) {
  986. dev_dbg(priv->adapter->dev,
  987. "info: already in the desired role.\n");
  988. return 0;
  989. }
  990. mwifiex_free_priv(priv);
  991. mwifiex_init_priv(priv);
  992. priv->bss_role = bss_role;
  993. switch (bss_role) {
  994. case MWIFIEX_BSS_ROLE_UAP:
  995. priv->bss_mode = NL80211_IFTYPE_AP;
  996. break;
  997. case MWIFIEX_BSS_ROLE_STA:
  998. case MWIFIEX_BSS_ROLE_ANY:
  999. default:
  1000. priv->bss_mode = NL80211_IFTYPE_STATION;
  1001. break;
  1002. }
  1003. mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  1004. HostCmd_ACT_GEN_SET, 0, NULL, true);
  1005. return mwifiex_sta_init_cmd(priv, false);
  1006. }
  1007. /*
  1008. * Sends IOCTL request to get statistics information.
  1009. *
  1010. * This function allocates the IOCTL request buffer, fills it
  1011. * with requisite parameters and calls the IOCTL handler.
  1012. */
  1013. int
  1014. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1015. struct mwifiex_ds_get_stats *log)
  1016. {
  1017. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
  1018. HostCmd_ACT_GEN_GET, 0, log, true);
  1019. }
  1020. /*
  1021. * IOCTL request handler to read/write register.
  1022. *
  1023. * This function prepares the correct firmware command and
  1024. * issues it.
  1025. *
  1026. * Access to the following registers are supported -
  1027. * - MAC
  1028. * - BBP
  1029. * - RF
  1030. * - PMIC
  1031. * - CAU
  1032. */
  1033. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1034. struct mwifiex_ds_reg_rw *reg_rw,
  1035. u16 action)
  1036. {
  1037. u16 cmd_no;
  1038. switch (le32_to_cpu(reg_rw->type)) {
  1039. case MWIFIEX_REG_MAC:
  1040. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1041. break;
  1042. case MWIFIEX_REG_BBP:
  1043. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1044. break;
  1045. case MWIFIEX_REG_RF:
  1046. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1047. break;
  1048. case MWIFIEX_REG_PMIC:
  1049. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1050. break;
  1051. case MWIFIEX_REG_CAU:
  1052. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1053. break;
  1054. default:
  1055. return -1;
  1056. }
  1057. return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
  1058. }
  1059. /*
  1060. * Sends IOCTL request to write to a register.
  1061. *
  1062. * This function allocates the IOCTL request buffer, fills it
  1063. * with requisite parameters and calls the IOCTL handler.
  1064. */
  1065. int
  1066. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1067. u32 reg_offset, u32 reg_value)
  1068. {
  1069. struct mwifiex_ds_reg_rw reg_rw;
  1070. reg_rw.type = cpu_to_le32(reg_type);
  1071. reg_rw.offset = cpu_to_le32(reg_offset);
  1072. reg_rw.value = cpu_to_le32(reg_value);
  1073. return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
  1074. }
  1075. /*
  1076. * Sends IOCTL request to read from a register.
  1077. *
  1078. * This function allocates the IOCTL request buffer, fills it
  1079. * with requisite parameters and calls the IOCTL handler.
  1080. */
  1081. int
  1082. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1083. u32 reg_offset, u32 *value)
  1084. {
  1085. int ret;
  1086. struct mwifiex_ds_reg_rw reg_rw;
  1087. reg_rw.type = cpu_to_le32(reg_type);
  1088. reg_rw.offset = cpu_to_le32(reg_offset);
  1089. ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
  1090. if (ret)
  1091. goto done;
  1092. *value = le32_to_cpu(reg_rw.value);
  1093. done:
  1094. return ret;
  1095. }
  1096. /*
  1097. * Sends IOCTL request to read from EEPROM.
  1098. *
  1099. * This function allocates the IOCTL request buffer, fills it
  1100. * with requisite parameters and calls the IOCTL handler.
  1101. */
  1102. int
  1103. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1104. u8 *value)
  1105. {
  1106. int ret;
  1107. struct mwifiex_ds_read_eeprom rd_eeprom;
  1108. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1109. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1110. /* Send request to firmware */
  1111. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1112. HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
  1113. if (!ret)
  1114. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1115. return ret;
  1116. }
  1117. /*
  1118. * This function sets a generic IE. In addition to generic IE, it can
  1119. * also handle WPA, WPA2 and WAPI IEs.
  1120. */
  1121. static int
  1122. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1123. u16 ie_len)
  1124. {
  1125. int ret = 0;
  1126. struct ieee_types_vendor_header *pvendor_ie;
  1127. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1128. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1129. /* If the passed length is zero, reset the buffer */
  1130. if (!ie_len) {
  1131. priv->gen_ie_buf_len = 0;
  1132. priv->wps.session_enable = false;
  1133. return 0;
  1134. } else if (!ie_data_ptr) {
  1135. return -1;
  1136. }
  1137. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1138. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1139. if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
  1140. (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
  1141. (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1142. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1143. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1144. priv->wps.session_enable = false;
  1145. return ret;
  1146. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1147. /* IE is a WAPI IE so call set_wapi function */
  1148. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1149. return ret;
  1150. }
  1151. /*
  1152. * Verify that the passed length is not larger than the
  1153. * available space remaining in the buffer
  1154. */
  1155. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1156. /* Test to see if it is a WPS IE, if so, enable
  1157. * wps session flag
  1158. */
  1159. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1160. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
  1161. (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
  1162. priv->wps.session_enable = true;
  1163. dev_dbg(priv->adapter->dev,
  1164. "info: WPS Session Enabled.\n");
  1165. ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
  1166. }
  1167. /* Append the passed data to the end of the
  1168. genIeBuffer */
  1169. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  1170. ie_len);
  1171. /* Increment the stored buffer length by the
  1172. size passed */
  1173. priv->gen_ie_buf_len += ie_len;
  1174. } else {
  1175. /* Passed data does not fit in the remaining
  1176. buffer space */
  1177. ret = -1;
  1178. }
  1179. /* Return 0, or -1 for error case */
  1180. return ret;
  1181. }
  1182. /*
  1183. * IOCTL request handler to set/get generic IE.
  1184. *
  1185. * In addition to various generic IEs, this function can also be
  1186. * used to set the ARP filter.
  1187. */
  1188. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  1189. struct mwifiex_ds_misc_gen_ie *gen_ie,
  1190. u16 action)
  1191. {
  1192. struct mwifiex_adapter *adapter = priv->adapter;
  1193. switch (gen_ie->type) {
  1194. case MWIFIEX_IE_TYPE_GEN_IE:
  1195. if (action == HostCmd_ACT_GEN_GET) {
  1196. gen_ie->len = priv->wpa_ie_len;
  1197. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  1198. } else {
  1199. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  1200. (u16) gen_ie->len);
  1201. }
  1202. break;
  1203. case MWIFIEX_IE_TYPE_ARP_FILTER:
  1204. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  1205. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  1206. adapter->arp_filter_size = 0;
  1207. dev_err(adapter->dev, "invalid ARP filter size\n");
  1208. return -1;
  1209. } else {
  1210. memcpy(adapter->arp_filter, gen_ie->ie_data,
  1211. gen_ie->len);
  1212. adapter->arp_filter_size = gen_ie->len;
  1213. }
  1214. break;
  1215. default:
  1216. dev_err(adapter->dev, "invalid IE type\n");
  1217. return -1;
  1218. }
  1219. return 0;
  1220. }
  1221. /*
  1222. * Sends IOCTL request to set a generic IE.
  1223. *
  1224. * This function allocates the IOCTL request buffer, fills it
  1225. * with requisite parameters and calls the IOCTL handler.
  1226. */
  1227. int
  1228. mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
  1229. {
  1230. struct mwifiex_ds_misc_gen_ie gen_ie;
  1231. if (ie_len > IEEE_MAX_IE_SIZE)
  1232. return -EFAULT;
  1233. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  1234. gen_ie.len = ie_len;
  1235. memcpy(gen_ie.ie_data, ie, ie_len);
  1236. if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
  1237. return -EFAULT;
  1238. return 0;
  1239. }