sta_ioctl.c 37 KB

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