sta_ioctl.c 37 KB

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