sta_ioctl.c 37 KB

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