sta_ioctl.c 37 KB

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