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