sta_ioctl.c 38 KB

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