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. size_t beacon_ie_len = bss->len_information_elements;
  147. beacon_ie = kmemdup(bss->information_elements, beacon_ie_len,
  148. GFP_KERNEL);
  149. if (!beacon_ie) {
  150. dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
  151. return -ENOMEM;
  152. }
  153. memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
  154. bss_desc->rssi = bss->signal;
  155. bss_desc->beacon_buf = beacon_ie;
  156. bss_desc->beacon_buf_size = beacon_ie_len;
  157. bss_desc->beacon_period = bss->beacon_interval;
  158. bss_desc->cap_info_bitmap = bss->capability;
  159. bss_desc->bss_band = bss_priv->band;
  160. bss_desc->fw_tsf = bss_priv->fw_tsf;
  161. bss_desc->timestamp = bss->tsf;
  162. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
  163. dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
  164. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  165. } else {
  166. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  167. }
  168. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
  169. bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
  170. else
  171. bss_desc->bss_mode = NL80211_IFTYPE_STATION;
  172. ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
  173. kfree(beacon_ie);
  174. return ret;
  175. }
  176. static int mwifiex_process_country_ie(struct mwifiex_private *priv,
  177. struct cfg80211_bss *bss)
  178. {
  179. u8 *country_ie, country_ie_len;
  180. struct mwifiex_802_11d_domain_reg *domain_info =
  181. &priv->adapter->domain_reg;
  182. country_ie = (u8 *)ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
  183. if (!country_ie)
  184. return 0;
  185. country_ie_len = country_ie[1];
  186. if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
  187. return 0;
  188. domain_info->country_code[0] = country_ie[2];
  189. domain_info->country_code[1] = country_ie[3];
  190. domain_info->country_code[2] = ' ';
  191. country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
  192. domain_info->no_of_triplet =
  193. country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
  194. memcpy((u8 *)domain_info->triplet,
  195. &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
  196. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
  197. HostCmd_ACT_GEN_SET, 0, NULL)) {
  198. wiphy_err(priv->adapter->wiphy,
  199. "11D: setting domain info in FW\n");
  200. return -1;
  201. }
  202. return 0;
  203. }
  204. /*
  205. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  206. * In both Ad-Hoc and infra mode, an deauthentication is performed
  207. * first.
  208. */
  209. int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
  210. struct cfg80211_ssid *req_ssid)
  211. {
  212. int ret;
  213. struct mwifiex_adapter *adapter = priv->adapter;
  214. struct mwifiex_bssdescriptor *bss_desc = NULL;
  215. priv->scan_block = false;
  216. if (bss) {
  217. mwifiex_process_country_ie(priv, bss);
  218. /* Allocate and fill new bss descriptor */
  219. bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
  220. GFP_KERNEL);
  221. if (!bss_desc) {
  222. dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
  223. return -ENOMEM;
  224. }
  225. ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
  226. if (ret)
  227. goto done;
  228. }
  229. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  230. /* Infra mode */
  231. ret = mwifiex_deauthenticate(priv, NULL);
  232. if (ret)
  233. goto done;
  234. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  235. if (ret)
  236. goto done;
  237. dev_dbg(adapter->dev, "info: SSID found in scan list ... "
  238. "associating...\n");
  239. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  240. if (netif_carrier_ok(priv->netdev))
  241. netif_carrier_off(priv->netdev);
  242. /* Clear any past association response stored for
  243. * application retrieval */
  244. priv->assoc_rsp_size = 0;
  245. ret = mwifiex_associate(priv, bss_desc);
  246. /* If auth type is auto and association fails using open mode,
  247. * try to connect using shared mode */
  248. if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
  249. priv->sec_info.is_authtype_auto &&
  250. priv->sec_info.wep_enabled) {
  251. priv->sec_info.authentication_mode =
  252. NL80211_AUTHTYPE_SHARED_KEY;
  253. ret = mwifiex_associate(priv, bss_desc);
  254. }
  255. if (bss)
  256. cfg80211_put_bss(bss);
  257. } else {
  258. /* Adhoc mode */
  259. /* If the requested SSID matches current SSID, return */
  260. if (bss_desc && bss_desc->ssid.ssid_len &&
  261. (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
  262. ssid, &bss_desc->ssid))) {
  263. kfree(bss_desc);
  264. return 0;
  265. }
  266. /* Exit Adhoc mode first */
  267. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  268. ret = mwifiex_deauthenticate(priv, NULL);
  269. if (ret)
  270. goto done;
  271. priv->adhoc_is_link_sensed = false;
  272. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  273. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  274. if (netif_carrier_ok(priv->netdev))
  275. netif_carrier_off(priv->netdev);
  276. if (!ret) {
  277. dev_dbg(adapter->dev, "info: network found in scan"
  278. " list. Joining...\n");
  279. ret = mwifiex_adhoc_join(priv, bss_desc);
  280. if (bss)
  281. cfg80211_put_bss(bss);
  282. } else {
  283. dev_dbg(adapter->dev, "info: Network not found in "
  284. "the list, creating adhoc with ssid = %s\n",
  285. req_ssid->ssid);
  286. ret = mwifiex_adhoc_start(priv, req_ssid);
  287. }
  288. }
  289. done:
  290. kfree(bss_desc);
  291. return ret;
  292. }
  293. /*
  294. * IOCTL request handler to set host sleep configuration.
  295. *
  296. * This function prepares the correct firmware command and
  297. * issues it.
  298. */
  299. static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  300. int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
  301. {
  302. struct mwifiex_adapter *adapter = priv->adapter;
  303. int status = 0;
  304. u32 prev_cond = 0;
  305. if (!hs_cfg)
  306. return -ENOMEM;
  307. switch (action) {
  308. case HostCmd_ACT_GEN_SET:
  309. if (adapter->pps_uapsd_mode) {
  310. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  311. " is blocked in UAPSD/PPS mode\n");
  312. status = -1;
  313. break;
  314. }
  315. if (hs_cfg->is_invoke_hostcmd) {
  316. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
  317. if (!adapter->is_hs_configured)
  318. /* Already cancelled */
  319. break;
  320. /* Save previous condition */
  321. prev_cond = le32_to_cpu(adapter->hs_cfg
  322. .conditions);
  323. adapter->hs_cfg.conditions =
  324. cpu_to_le32(hs_cfg->conditions);
  325. } else if (hs_cfg->conditions) {
  326. adapter->hs_cfg.conditions =
  327. cpu_to_le32(hs_cfg->conditions);
  328. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  329. if (hs_cfg->gap)
  330. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  331. } else if (adapter->hs_cfg.conditions
  332. == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
  333. /* Return failure if no parameters for HS
  334. enable */
  335. status = -1;
  336. break;
  337. }
  338. if (cmd_type == MWIFIEX_SYNC_CMD)
  339. status = mwifiex_send_cmd_sync(priv,
  340. HostCmd_CMD_802_11_HS_CFG_ENH,
  341. HostCmd_ACT_GEN_SET, 0,
  342. &adapter->hs_cfg);
  343. else
  344. status = mwifiex_send_cmd_async(priv,
  345. HostCmd_CMD_802_11_HS_CFG_ENH,
  346. HostCmd_ACT_GEN_SET, 0,
  347. &adapter->hs_cfg);
  348. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
  349. /* Restore previous condition */
  350. adapter->hs_cfg.conditions =
  351. cpu_to_le32(prev_cond);
  352. } else {
  353. adapter->hs_cfg.conditions =
  354. cpu_to_le32(hs_cfg->conditions);
  355. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  356. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  357. }
  358. break;
  359. case HostCmd_ACT_GEN_GET:
  360. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  361. hs_cfg->gpio = adapter->hs_cfg.gpio;
  362. hs_cfg->gap = adapter->hs_cfg.gap;
  363. break;
  364. default:
  365. status = -1;
  366. break;
  367. }
  368. return status;
  369. }
  370. /*
  371. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  372. *
  373. * This function allocates the IOCTL request buffer, fills it
  374. * with requisite parameters and calls the IOCTL handler.
  375. */
  376. int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
  377. {
  378. struct mwifiex_ds_hs_cfg hscfg;
  379. hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
  380. hscfg.is_invoke_hostcmd = true;
  381. return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  382. cmd_type, &hscfg);
  383. }
  384. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  385. /*
  386. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  387. *
  388. * This function allocates the IOCTL request buffer, fills it
  389. * with requisite parameters and calls the IOCTL handler.
  390. */
  391. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  392. {
  393. struct mwifiex_ds_hs_cfg hscfg;
  394. struct mwifiex_private *priv;
  395. int i;
  396. if (disconnect_on_suspend) {
  397. for (i = 0; i < adapter->priv_num; i++) {
  398. priv = adapter->priv[i];
  399. if (priv)
  400. mwifiex_deauthenticate(priv, NULL);
  401. }
  402. }
  403. if (adapter->hs_activated) {
  404. dev_dbg(adapter->dev, "cmd: HS Already activated\n");
  405. return true;
  406. }
  407. adapter->hs_activate_wait_q_woken = false;
  408. memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
  409. hscfg.is_invoke_hostcmd = true;
  410. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  411. MWIFIEX_BSS_ROLE_STA),
  412. HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
  413. &hscfg)) {
  414. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  415. return false;
  416. }
  417. wait_event_interruptible(adapter->hs_activate_wait_q,
  418. adapter->hs_activate_wait_q_woken);
  419. return true;
  420. }
  421. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  422. /*
  423. * IOCTL request handler to get BSS information.
  424. *
  425. * This function collates the information from different driver structures
  426. * to send to the user.
  427. */
  428. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  429. struct mwifiex_bss_info *info)
  430. {
  431. struct mwifiex_adapter *adapter = priv->adapter;
  432. struct mwifiex_bssdescriptor *bss_desc;
  433. if (!info)
  434. return -1;
  435. bss_desc = &priv->curr_bss_params.bss_descriptor;
  436. info->bss_mode = priv->bss_mode;
  437. memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
  438. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  439. info->bss_chan = bss_desc->channel;
  440. memcpy(info->country_code, adapter->country_code,
  441. IEEE80211_COUNTRY_STRING_LEN);
  442. info->media_connected = priv->media_connected;
  443. info->max_power_level = priv->max_tx_power_level;
  444. info->min_power_level = priv->min_tx_power_level;
  445. info->adhoc_state = priv->adhoc_state;
  446. info->bcn_nf_last = priv->bcn_nf_last;
  447. if (priv->sec_info.wep_enabled)
  448. info->wep_status = true;
  449. else
  450. info->wep_status = false;
  451. info->is_hs_configured = adapter->is_hs_configured;
  452. info->is_deep_sleep = adapter->is_deep_sleep;
  453. return 0;
  454. }
  455. /*
  456. * The function disables auto deep sleep mode.
  457. */
  458. int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
  459. {
  460. struct mwifiex_ds_auto_ds auto_ds;
  461. auto_ds.auto_ds = DEEP_SLEEP_OFF;
  462. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  463. DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
  464. }
  465. EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
  466. /*
  467. * Sends IOCTL request to get the data rate.
  468. *
  469. * This function allocates the IOCTL request buffer, fills it
  470. * with requisite parameters and calls the IOCTL handler.
  471. */
  472. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
  473. {
  474. int ret;
  475. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  476. HostCmd_ACT_GEN_GET, 0, NULL);
  477. if (!ret) {
  478. if (priv->is_data_rate_auto)
  479. *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
  480. priv->tx_htinfo);
  481. else
  482. *rate = priv->data_rate;
  483. }
  484. return ret;
  485. }
  486. /*
  487. * IOCTL request handler to set tx power configuration.
  488. *
  489. * This function prepares the correct firmware command and
  490. * issues it.
  491. *
  492. * For non-auto power mode, all the following power groups are set -
  493. * - Modulation class HR/DSSS
  494. * - Modulation class OFDM
  495. * - Modulation class HTBW20
  496. * - Modulation class HTBW40
  497. */
  498. int mwifiex_set_tx_power(struct mwifiex_private *priv,
  499. struct mwifiex_power_cfg *power_cfg)
  500. {
  501. int ret;
  502. struct host_cmd_ds_txpwr_cfg *txp_cfg;
  503. struct mwifiex_types_power_group *pg_tlv;
  504. struct mwifiex_power_group *pg;
  505. u8 *buf;
  506. u16 dbm = 0;
  507. if (!power_cfg->is_power_auto) {
  508. dbm = (u16) power_cfg->power_level;
  509. if ((dbm < priv->min_tx_power_level) ||
  510. (dbm > priv->max_tx_power_level)) {
  511. dev_err(priv->adapter->dev, "txpower value %d dBm"
  512. " is out of range (%d dBm-%d dBm)\n",
  513. dbm, priv->min_tx_power_level,
  514. priv->max_tx_power_level);
  515. return -1;
  516. }
  517. }
  518. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  519. if (!buf) {
  520. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  521. __func__);
  522. return -ENOMEM;
  523. }
  524. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  525. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  526. if (!power_cfg->is_power_auto) {
  527. txp_cfg->mode = cpu_to_le32(1);
  528. pg_tlv = (struct mwifiex_types_power_group *)
  529. (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
  530. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  531. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  532. pg = (struct mwifiex_power_group *)
  533. (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
  534. + sizeof(struct mwifiex_types_power_group));
  535. /* Power group for modulation class HR/DSSS */
  536. pg->first_rate_code = 0x00;
  537. pg->last_rate_code = 0x03;
  538. pg->modulation_class = MOD_CLASS_HR_DSSS;
  539. pg->power_step = 0;
  540. pg->power_min = (s8) dbm;
  541. pg->power_max = (s8) dbm;
  542. pg++;
  543. /* Power group for modulation class OFDM */
  544. pg->first_rate_code = 0x00;
  545. pg->last_rate_code = 0x07;
  546. pg->modulation_class = MOD_CLASS_OFDM;
  547. pg->power_step = 0;
  548. pg->power_min = (s8) dbm;
  549. pg->power_max = (s8) dbm;
  550. pg++;
  551. /* Power group for modulation class HTBW20 */
  552. pg->first_rate_code = 0x00;
  553. pg->last_rate_code = 0x20;
  554. pg->modulation_class = MOD_CLASS_HT;
  555. pg->power_step = 0;
  556. pg->power_min = (s8) dbm;
  557. pg->power_max = (s8) dbm;
  558. pg->ht_bandwidth = HT_BW_20;
  559. pg++;
  560. /* Power group for modulation class HTBW40 */
  561. pg->first_rate_code = 0x00;
  562. pg->last_rate_code = 0x20;
  563. pg->modulation_class = MOD_CLASS_HT;
  564. pg->power_step = 0;
  565. pg->power_min = (s8) dbm;
  566. pg->power_max = (s8) dbm;
  567. pg->ht_bandwidth = HT_BW_40;
  568. }
  569. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
  570. HostCmd_ACT_GEN_SET, 0, buf);
  571. kfree(buf);
  572. return ret;
  573. }
  574. /*
  575. * IOCTL request handler to get power save mode.
  576. *
  577. * This function prepares the correct firmware command and
  578. * issues it.
  579. */
  580. int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
  581. {
  582. int ret;
  583. struct mwifiex_adapter *adapter = priv->adapter;
  584. u16 sub_cmd;
  585. if (*ps_mode)
  586. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  587. else
  588. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  589. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  590. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  591. sub_cmd, BITMAP_STA_PS, NULL);
  592. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  593. ret = mwifiex_send_cmd_async(priv,
  594. HostCmd_CMD_802_11_PS_MODE_ENH,
  595. GET_PS, 0, NULL);
  596. return ret;
  597. }
  598. /*
  599. * IOCTL request handler to set/reset WPA IE.
  600. *
  601. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  602. * is checked to determine WPA version. If buffer length is zero, the existing
  603. * WPA IE is reset.
  604. */
  605. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  606. u8 *ie_data_ptr, u16 ie_len)
  607. {
  608. if (ie_len) {
  609. if (ie_len > sizeof(priv->wpa_ie)) {
  610. dev_err(priv->adapter->dev,
  611. "failed to copy WPA IE, too big\n");
  612. return -1;
  613. }
  614. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  615. priv->wpa_ie_len = (u8) ie_len;
  616. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  617. priv->wpa_ie_len, priv->wpa_ie[0]);
  618. if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
  619. priv->sec_info.wpa_enabled = true;
  620. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  621. priv->sec_info.wpa2_enabled = true;
  622. } else {
  623. priv->sec_info.wpa_enabled = false;
  624. priv->sec_info.wpa2_enabled = false;
  625. }
  626. } else {
  627. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  628. priv->wpa_ie_len = 0;
  629. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  630. priv->wpa_ie_len, priv->wpa_ie[0]);
  631. priv->sec_info.wpa_enabled = false;
  632. priv->sec_info.wpa2_enabled = false;
  633. }
  634. return 0;
  635. }
  636. /*
  637. * IOCTL request handler to set/reset WAPI IE.
  638. *
  639. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  640. * is checked to internally enable WAPI. If buffer length is zero, the existing
  641. * WAPI IE is reset.
  642. */
  643. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  644. u8 *ie_data_ptr, u16 ie_len)
  645. {
  646. if (ie_len) {
  647. if (ie_len > sizeof(priv->wapi_ie)) {
  648. dev_dbg(priv->adapter->dev,
  649. "info: failed to copy WAPI IE, too big\n");
  650. return -1;
  651. }
  652. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  653. priv->wapi_ie_len = ie_len;
  654. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  655. priv->wapi_ie_len, priv->wapi_ie[0]);
  656. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  657. priv->sec_info.wapi_enabled = true;
  658. } else {
  659. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  660. priv->wapi_ie_len = ie_len;
  661. dev_dbg(priv->adapter->dev,
  662. "info: Reset wapi_ie_len=%d IE=%#x\n",
  663. priv->wapi_ie_len, priv->wapi_ie[0]);
  664. priv->sec_info.wapi_enabled = false;
  665. }
  666. return 0;
  667. }
  668. /*
  669. * IOCTL request handler to set/reset WPS IE.
  670. *
  671. * The supplied WPS IE is treated as a opaque buffer. Only the first field
  672. * is checked to internally enable WPS. If buffer length is zero, the existing
  673. * WPS IE is reset.
  674. */
  675. static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
  676. u8 *ie_data_ptr, u16 ie_len)
  677. {
  678. if (ie_len) {
  679. priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
  680. if (!priv->wps_ie)
  681. return -ENOMEM;
  682. if (ie_len > sizeof(priv->wps_ie)) {
  683. dev_dbg(priv->adapter->dev,
  684. "info: failed to copy WPS IE, too big\n");
  685. kfree(priv->wps_ie);
  686. return -1;
  687. }
  688. memcpy(priv->wps_ie, ie_data_ptr, ie_len);
  689. priv->wps_ie_len = ie_len;
  690. dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
  691. priv->wps_ie_len, priv->wps_ie[0]);
  692. } else {
  693. kfree(priv->wps_ie);
  694. priv->wps_ie_len = ie_len;
  695. dev_dbg(priv->adapter->dev,
  696. "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
  697. }
  698. return 0;
  699. }
  700. /*
  701. * IOCTL request handler to set WAPI key.
  702. *
  703. * This function prepares the correct firmware command and
  704. * issues it.
  705. */
  706. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
  707. struct mwifiex_ds_encrypt_key *encrypt_key)
  708. {
  709. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  710. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  711. encrypt_key);
  712. }
  713. /*
  714. * IOCTL request handler to set WEP network key.
  715. *
  716. * This function prepares the correct firmware command and
  717. * issues it, after validation checks.
  718. */
  719. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
  720. struct mwifiex_ds_encrypt_key *encrypt_key)
  721. {
  722. int ret;
  723. struct mwifiex_wep_key *wep_key;
  724. int index;
  725. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  726. priv->wep_key_curr_index = 0;
  727. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  728. index = encrypt_key->key_index;
  729. if (encrypt_key->key_disable) {
  730. priv->sec_info.wep_enabled = 0;
  731. } else if (!encrypt_key->key_len) {
  732. /* Copy the required key as the current key */
  733. wep_key = &priv->wep_key[index];
  734. if (!wep_key->key_length) {
  735. dev_err(priv->adapter->dev,
  736. "key not set, so cannot enable it\n");
  737. return -1;
  738. }
  739. priv->wep_key_curr_index = (u16) index;
  740. priv->sec_info.wep_enabled = 1;
  741. } else {
  742. wep_key = &priv->wep_key[index];
  743. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  744. /* Copy the key in the driver */
  745. memcpy(wep_key->key_material,
  746. encrypt_key->key_material,
  747. encrypt_key->key_len);
  748. wep_key->key_index = index;
  749. wep_key->key_length = encrypt_key->key_len;
  750. priv->sec_info.wep_enabled = 1;
  751. }
  752. if (wep_key->key_length) {
  753. /* Send request to firmware */
  754. ret = mwifiex_send_cmd_async(priv,
  755. HostCmd_CMD_802_11_KEY_MATERIAL,
  756. HostCmd_ACT_GEN_SET, 0, NULL);
  757. if (ret)
  758. return ret;
  759. }
  760. if (priv->sec_info.wep_enabled)
  761. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  762. else
  763. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  764. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  765. HostCmd_ACT_GEN_SET, 0,
  766. &priv->curr_pkt_filter);
  767. return ret;
  768. }
  769. /*
  770. * IOCTL request handler to set WPA key.
  771. *
  772. * This function prepares the correct firmware command and
  773. * issues it, after validation checks.
  774. *
  775. * Current driver only supports key length of up to 32 bytes.
  776. *
  777. * This function can also be used to disable a currently set key.
  778. */
  779. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
  780. struct mwifiex_ds_encrypt_key *encrypt_key)
  781. {
  782. int ret;
  783. u8 remove_key = false;
  784. struct host_cmd_ds_802_11_key_material *ibss_key;
  785. /* Current driver only supports key length of up to 32 bytes */
  786. if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
  787. dev_err(priv->adapter->dev, "key length too long\n");
  788. return -1;
  789. }
  790. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  791. /*
  792. * IBSS/WPA-None uses only one key (Group) for both receiving
  793. * and sending unicast and multicast packets.
  794. */
  795. /* Send the key as PTK to firmware */
  796. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  797. ret = mwifiex_send_cmd_async(priv,
  798. HostCmd_CMD_802_11_KEY_MATERIAL,
  799. HostCmd_ACT_GEN_SET,
  800. KEY_INFO_ENABLED, encrypt_key);
  801. if (ret)
  802. return ret;
  803. ibss_key = &priv->aes_key;
  804. memset(ibss_key, 0,
  805. sizeof(struct host_cmd_ds_802_11_key_material));
  806. /* Copy the key in the driver */
  807. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  808. encrypt_key->key_len);
  809. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  810. sizeof(ibss_key->key_param_set.key_len));
  811. ibss_key->key_param_set.key_type_id
  812. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  813. ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
  814. /* Send the key as GTK to firmware */
  815. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  816. }
  817. if (!encrypt_key->key_index)
  818. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  819. if (remove_key)
  820. ret = mwifiex_send_cmd_sync(priv,
  821. HostCmd_CMD_802_11_KEY_MATERIAL,
  822. HostCmd_ACT_GEN_SET,
  823. !KEY_INFO_ENABLED, encrypt_key);
  824. else
  825. ret = mwifiex_send_cmd_sync(priv,
  826. HostCmd_CMD_802_11_KEY_MATERIAL,
  827. HostCmd_ACT_GEN_SET,
  828. KEY_INFO_ENABLED, encrypt_key);
  829. return ret;
  830. }
  831. /*
  832. * IOCTL request handler to set/get network keys.
  833. *
  834. * This is a generic key handling function which supports WEP, WPA
  835. * and WAPI.
  836. */
  837. static int
  838. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  839. struct mwifiex_ds_encrypt_key *encrypt_key)
  840. {
  841. int status;
  842. if (encrypt_key->is_wapi_key)
  843. status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
  844. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  845. status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
  846. else
  847. status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
  848. return status;
  849. }
  850. /*
  851. * This function returns the driver version.
  852. */
  853. int
  854. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  855. int max_len)
  856. {
  857. union {
  858. u32 l;
  859. u8 c[4];
  860. } ver;
  861. char fw_ver[32];
  862. ver.l = adapter->fw_release_number;
  863. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  864. snprintf(version, max_len, driver_version, fw_ver);
  865. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  866. return 0;
  867. }
  868. /*
  869. * Sends IOCTL request to set encoding parameters.
  870. *
  871. * This function allocates the IOCTL request buffer, fills it
  872. * with requisite parameters and calls the IOCTL handler.
  873. */
  874. int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
  875. const u8 *key, int key_len, u8 key_index,
  876. const u8 *mac_addr, int disable)
  877. {
  878. struct mwifiex_ds_encrypt_key encrypt_key;
  879. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  880. encrypt_key.key_len = key_len;
  881. if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
  882. encrypt_key.is_igtk_key = true;
  883. if (!disable) {
  884. encrypt_key.key_index = key_index;
  885. if (key_len)
  886. memcpy(encrypt_key.key_material, key, key_len);
  887. if (mac_addr)
  888. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  889. if (kp && kp->seq && kp->seq_len)
  890. memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
  891. } else {
  892. encrypt_key.key_disable = true;
  893. if (mac_addr)
  894. memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
  895. }
  896. return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
  897. }
  898. /*
  899. * Sends IOCTL request to get extended version.
  900. *
  901. * This function allocates the IOCTL request buffer, fills it
  902. * with requisite parameters and calls the IOCTL handler.
  903. */
  904. int
  905. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  906. {
  907. struct mwifiex_ver_ext ver_ext;
  908. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  909. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
  910. HostCmd_ACT_GEN_GET, 0, &ver_ext))
  911. return -1;
  912. return 0;
  913. }
  914. int
  915. mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
  916. struct ieee80211_channel *chan,
  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(NL80211_CHAN_NO_HT);
  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. }