sta_ioctl.c 36 KB

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