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