sta_ioctl.c 38 KB

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