sta_ioctl.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
  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. /*
  28. * Copies the multicast address list from device to driver.
  29. *
  30. * This function does not validate the destination memory for
  31. * size, and the calling function must ensure enough memory is
  32. * available.
  33. */
  34. int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
  35. struct net_device *dev)
  36. {
  37. int i = 0;
  38. struct netdev_hw_addr *ha;
  39. netdev_for_each_mc_addr(ha, dev)
  40. memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
  41. return i;
  42. }
  43. /*
  44. * Wait queue completion handler.
  45. *
  46. * This function waits on a cmd wait queue. It also cancels the pending
  47. * request after waking up, in case of errors.
  48. */
  49. int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
  50. {
  51. bool cancel_flag = false;
  52. int status = adapter->cmd_wait_q.status;
  53. struct cmd_ctrl_node *cmd_queued;
  54. if (!adapter->cmd_queued)
  55. return 0;
  56. cmd_queued = adapter->cmd_queued;
  57. adapter->cmd_queued = NULL;
  58. dev_dbg(adapter->dev, "cmd pending\n");
  59. atomic_inc(&adapter->cmd_pending);
  60. /* Status pending, wake up main process */
  61. queue_work(adapter->workqueue, &adapter->main_work);
  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. adapter->cmd_wait_q.status = 0;
  72. return status;
  73. }
  74. /*
  75. * This function prepares the correct firmware command and
  76. * issues it to set the multicast list.
  77. *
  78. * This function can be used to enable promiscuous mode, or enable all
  79. * multicast packets, or to enable selective multicast.
  80. */
  81. int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
  82. struct mwifiex_multicast_list *mcast_list)
  83. {
  84. int ret = 0;
  85. u16 old_pkt_filter;
  86. old_pkt_filter = priv->curr_pkt_filter;
  87. if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
  88. dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
  89. priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  90. priv->curr_pkt_filter &=
  91. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  92. } else {
  93. /* Multicast */
  94. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  95. if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
  96. dev_dbg(priv->adapter->dev,
  97. "info: Enabling All Multicast!\n");
  98. priv->curr_pkt_filter |=
  99. HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  100. } else {
  101. priv->curr_pkt_filter &=
  102. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  103. if (mcast_list->num_multicast_addr) {
  104. dev_dbg(priv->adapter->dev,
  105. "info: Set multicast list=%d\n",
  106. mcast_list->num_multicast_addr);
  107. /* Set multicast addresses to firmware */
  108. if (old_pkt_filter == priv->curr_pkt_filter) {
  109. /* Send request to firmware */
  110. ret = mwifiex_send_cmd_async(priv,
  111. HostCmd_CMD_MAC_MULTICAST_ADR,
  112. HostCmd_ACT_GEN_SET, 0,
  113. mcast_list);
  114. } else {
  115. /* Send request to firmware */
  116. ret = mwifiex_send_cmd_async(priv,
  117. HostCmd_CMD_MAC_MULTICAST_ADR,
  118. HostCmd_ACT_GEN_SET, 0,
  119. mcast_list);
  120. }
  121. }
  122. }
  123. }
  124. dev_dbg(priv->adapter->dev,
  125. "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
  126. old_pkt_filter, priv->curr_pkt_filter);
  127. if (old_pkt_filter != priv->curr_pkt_filter) {
  128. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
  129. HostCmd_ACT_GEN_SET,
  130. 0, &priv->curr_pkt_filter);
  131. }
  132. return ret;
  133. }
  134. /*
  135. * This function fills bss descriptor structure using provided
  136. * information.
  137. */
  138. int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
  139. u8 *bssid, s32 rssi, u8 *ie_buf,
  140. size_t ie_len, u16 beacon_period,
  141. u16 cap_info_bitmap, u8 band,
  142. struct mwifiex_bssdescriptor *bss_desc)
  143. {
  144. int ret;
  145. memcpy(bss_desc->mac_address, bssid, ETH_ALEN);
  146. bss_desc->rssi = rssi;
  147. bss_desc->beacon_buf = ie_buf;
  148. bss_desc->beacon_buf_size = ie_len;
  149. bss_desc->beacon_period = beacon_period;
  150. bss_desc->cap_info_bitmap = cap_info_bitmap;
  151. bss_desc->bss_band = band;
  152. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
  153. dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
  154. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  155. } else {
  156. bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  157. }
  158. if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
  159. bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
  160. else
  161. bss_desc->bss_mode = NL80211_IFTYPE_STATION;
  162. ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
  163. ie_buf, ie_len);
  164. return ret;
  165. }
  166. /*
  167. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  168. * In both Ad-Hoc and infra mode, an deauthentication is performed
  169. * first.
  170. */
  171. int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
  172. struct mwifiex_802_11_ssid *req_ssid)
  173. {
  174. int ret;
  175. struct mwifiex_adapter *adapter = priv->adapter;
  176. struct mwifiex_bssdescriptor *bss_desc = NULL;
  177. u8 *beacon_ie = NULL;
  178. priv->scan_block = false;
  179. if (bss) {
  180. /* Allocate and fill new bss descriptor */
  181. bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
  182. GFP_KERNEL);
  183. if (!bss_desc) {
  184. dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
  185. return -ENOMEM;
  186. }
  187. beacon_ie = kmemdup(bss->information_elements,
  188. bss->len_beacon_ies, GFP_KERNEL);
  189. if (!beacon_ie) {
  190. kfree(bss_desc);
  191. dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
  192. return -ENOMEM;
  193. }
  194. ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
  195. beacon_ie, bss->len_beacon_ies,
  196. bss->beacon_interval,
  197. bss->capability,
  198. *(u8 *)bss->priv, bss_desc);
  199. if (ret)
  200. goto done;
  201. }
  202. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  203. /* Infra mode */
  204. ret = mwifiex_deauthenticate(priv, NULL);
  205. if (ret)
  206. goto done;
  207. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  208. if (ret)
  209. goto done;
  210. dev_dbg(adapter->dev, "info: SSID found in scan list ... "
  211. "associating...\n");
  212. if (!netif_queue_stopped(priv->netdev))
  213. netif_stop_queue(priv->netdev);
  214. /* Clear any past association response stored for
  215. * application retrieval */
  216. priv->assoc_rsp_size = 0;
  217. ret = mwifiex_associate(priv, bss_desc);
  218. if (bss)
  219. cfg80211_put_bss(bss);
  220. } else {
  221. /* Adhoc mode */
  222. /* If the requested SSID matches current SSID, return */
  223. if (bss_desc && bss_desc->ssid.ssid_len &&
  224. (!mwifiex_ssid_cmp
  225. (&priv->curr_bss_params.bss_descriptor.ssid,
  226. &bss_desc->ssid))) {
  227. kfree(bss_desc);
  228. kfree(beacon_ie);
  229. return 0;
  230. }
  231. /* Exit Adhoc mode first */
  232. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  233. ret = mwifiex_deauthenticate(priv, NULL);
  234. if (ret)
  235. goto done;
  236. priv->adhoc_is_link_sensed = false;
  237. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  238. if (!netif_queue_stopped(priv->netdev))
  239. netif_stop_queue(priv->netdev);
  240. if (!ret) {
  241. dev_dbg(adapter->dev, "info: network found in scan"
  242. " list. Joining...\n");
  243. ret = mwifiex_adhoc_join(priv, bss_desc);
  244. if (bss)
  245. cfg80211_put_bss(bss);
  246. } else {
  247. dev_dbg(adapter->dev, "info: Network not found in "
  248. "the list, creating adhoc with ssid = %s\n",
  249. req_ssid->ssid);
  250. ret = mwifiex_adhoc_start(priv, req_ssid);
  251. }
  252. }
  253. done:
  254. kfree(bss_desc);
  255. kfree(beacon_ie);
  256. return ret;
  257. }
  258. /*
  259. * IOCTL request handler to set host sleep configuration.
  260. *
  261. * This function prepares the correct firmware command and
  262. * issues it.
  263. */
  264. static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  265. int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
  266. {
  267. struct mwifiex_adapter *adapter = priv->adapter;
  268. int status = 0;
  269. u32 prev_cond = 0;
  270. if (!hs_cfg)
  271. return -ENOMEM;
  272. switch (action) {
  273. case HostCmd_ACT_GEN_SET:
  274. if (adapter->pps_uapsd_mode) {
  275. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  276. " is blocked in UAPSD/PPS mode\n");
  277. status = -1;
  278. break;
  279. }
  280. if (hs_cfg->is_invoke_hostcmd) {
  281. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
  282. if (!adapter->is_hs_configured)
  283. /* Already cancelled */
  284. break;
  285. /* Save previous condition */
  286. prev_cond = le32_to_cpu(adapter->hs_cfg
  287. .conditions);
  288. adapter->hs_cfg.conditions =
  289. cpu_to_le32(hs_cfg->conditions);
  290. } else if (hs_cfg->conditions) {
  291. adapter->hs_cfg.conditions =
  292. cpu_to_le32(hs_cfg->conditions);
  293. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  294. if (hs_cfg->gap)
  295. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  296. } else if (adapter->hs_cfg.conditions ==
  297. cpu_to_le32(
  298. HOST_SLEEP_CFG_CANCEL)) {
  299. /* Return failure if no parameters for HS
  300. enable */
  301. status = -1;
  302. break;
  303. }
  304. if (cmd_type == MWIFIEX_SYNC_CMD)
  305. status = mwifiex_send_cmd_sync(priv,
  306. HostCmd_CMD_802_11_HS_CFG_ENH,
  307. HostCmd_ACT_GEN_SET, 0,
  308. &adapter->hs_cfg);
  309. else
  310. status = mwifiex_send_cmd_async(priv,
  311. HostCmd_CMD_802_11_HS_CFG_ENH,
  312. HostCmd_ACT_GEN_SET, 0,
  313. &adapter->hs_cfg);
  314. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
  315. /* Restore previous condition */
  316. adapter->hs_cfg.conditions =
  317. cpu_to_le32(prev_cond);
  318. } else {
  319. adapter->hs_cfg.conditions =
  320. cpu_to_le32(hs_cfg->conditions);
  321. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  322. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  323. }
  324. break;
  325. case HostCmd_ACT_GEN_GET:
  326. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  327. hs_cfg->gpio = adapter->hs_cfg.gpio;
  328. hs_cfg->gap = adapter->hs_cfg.gap;
  329. break;
  330. default:
  331. status = -1;
  332. break;
  333. }
  334. return status;
  335. }
  336. /*
  337. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  338. *
  339. * This function allocates the IOCTL request buffer, fills it
  340. * with requisite parameters and calls the IOCTL handler.
  341. */
  342. int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
  343. {
  344. struct mwifiex_ds_hs_cfg hscfg;
  345. hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
  346. hscfg.is_invoke_hostcmd = true;
  347. return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  348. cmd_type, &hscfg);
  349. }
  350. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  351. /*
  352. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  353. *
  354. * This function allocates the IOCTL request buffer, fills it
  355. * with requisite parameters and calls the IOCTL handler.
  356. */
  357. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  358. {
  359. struct mwifiex_ds_hs_cfg hscfg;
  360. if (adapter->hs_activated) {
  361. dev_dbg(adapter->dev, "cmd: HS Already actived\n");
  362. return true;
  363. }
  364. adapter->hs_activate_wait_q_woken = false;
  365. memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
  366. hscfg.is_invoke_hostcmd = true;
  367. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  368. MWIFIEX_BSS_ROLE_STA),
  369. HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
  370. &hscfg)) {
  371. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  372. return false;
  373. }
  374. wait_event_interruptible(adapter->hs_activate_wait_q,
  375. adapter->hs_activate_wait_q_woken);
  376. return true;
  377. }
  378. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  379. /*
  380. * IOCTL request handler to get BSS information.
  381. *
  382. * This function collates the information from different driver structures
  383. * to send to the user.
  384. */
  385. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  386. struct mwifiex_bss_info *info)
  387. {
  388. struct mwifiex_adapter *adapter = priv->adapter;
  389. struct mwifiex_bssdescriptor *bss_desc;
  390. if (!info)
  391. return -1;
  392. bss_desc = &priv->curr_bss_params.bss_descriptor;
  393. info->bss_mode = priv->bss_mode;
  394. memcpy(&info->ssid, &bss_desc->ssid,
  395. sizeof(struct mwifiex_802_11_ssid));
  396. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  397. info->bss_chan = bss_desc->channel;
  398. info->region_code = adapter->region_code;
  399. info->media_connected = priv->media_connected;
  400. info->max_power_level = priv->max_tx_power_level;
  401. info->min_power_level = priv->min_tx_power_level;
  402. info->adhoc_state = priv->adhoc_state;
  403. info->bcn_nf_last = priv->bcn_nf_last;
  404. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  405. info->wep_status = true;
  406. else
  407. info->wep_status = false;
  408. info->is_hs_configured = adapter->is_hs_configured;
  409. info->is_deep_sleep = adapter->is_deep_sleep;
  410. return 0;
  411. }
  412. /*
  413. * The function sets band configurations.
  414. *
  415. * it performs extra checks to make sure the Ad-Hoc
  416. * band and channel are compatible. Otherwise it returns an error.
  417. *
  418. */
  419. int mwifiex_set_radio_band_cfg(struct mwifiex_private *priv,
  420. struct mwifiex_ds_band_cfg *radio_cfg)
  421. {
  422. struct mwifiex_adapter *adapter = priv->adapter;
  423. u8 infra_band, adhoc_band;
  424. u32 adhoc_channel;
  425. infra_band = (u8) radio_cfg->config_bands;
  426. adhoc_band = (u8) radio_cfg->adhoc_start_band;
  427. adhoc_channel = radio_cfg->adhoc_channel;
  428. /* SET Infra band */
  429. if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
  430. return -1;
  431. adapter->config_bands = infra_band;
  432. /* SET Ad-hoc Band */
  433. if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
  434. return -1;
  435. if (adhoc_band)
  436. adapter->adhoc_start_band = adhoc_band;
  437. adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
  438. /*
  439. * If no adhoc_channel is supplied verify if the existing adhoc
  440. * channel compiles with new adhoc_band
  441. */
  442. if (!adhoc_channel) {
  443. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  444. (priv, adapter->adhoc_start_band,
  445. priv->adhoc_channel)) {
  446. /* Pass back the default channel */
  447. radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  448. if ((adapter->adhoc_start_band & BAND_A)
  449. || (adapter->adhoc_start_band & BAND_AN))
  450. radio_cfg->adhoc_channel =
  451. DEFAULT_AD_HOC_CHANNEL_A;
  452. }
  453. } else { /* Retrurn error if adhoc_band and
  454. adhoc_channel combination is invalid */
  455. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  456. (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
  457. return -1;
  458. priv->adhoc_channel = (u8) adhoc_channel;
  459. }
  460. if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
  461. adapter->adhoc_11n_enabled = true;
  462. else
  463. adapter->adhoc_11n_enabled = false;
  464. return 0;
  465. }
  466. /*
  467. * The function disables auto deep sleep mode.
  468. */
  469. int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
  470. {
  471. struct mwifiex_ds_auto_ds auto_ds;
  472. auto_ds.auto_ds = DEEP_SLEEP_OFF;
  473. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  474. DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
  475. }
  476. EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
  477. /*
  478. * IOCTL request handler to set/get active channel.
  479. *
  480. * This function performs validity checking on channel/frequency
  481. * compatibility and returns failure if not valid.
  482. */
  483. int mwifiex_bss_set_channel(struct mwifiex_private *priv,
  484. struct mwifiex_chan_freq_power *chan)
  485. {
  486. struct mwifiex_adapter *adapter = priv->adapter;
  487. struct mwifiex_chan_freq_power *cfp = NULL;
  488. if (!chan)
  489. return -1;
  490. if (!chan->channel && !chan->freq)
  491. return -1;
  492. if (adapter->adhoc_start_band & BAND_AN)
  493. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  494. else if (adapter->adhoc_start_band & BAND_A)
  495. adapter->adhoc_start_band = BAND_G | BAND_B;
  496. if (chan->channel) {
  497. if (chan->channel <= MAX_CHANNEL_BAND_BG)
  498. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  499. (priv, 0, (u16) chan->channel);
  500. if (!cfp) {
  501. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  502. (priv, BAND_A, (u16) chan->channel);
  503. if (cfp) {
  504. if (adapter->adhoc_11n_enabled)
  505. adapter->adhoc_start_band = BAND_A
  506. | BAND_AN;
  507. else
  508. adapter->adhoc_start_band = BAND_A;
  509. }
  510. }
  511. } else {
  512. if (chan->freq <= MAX_FREQUENCY_BAND_BG)
  513. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
  514. priv, 0, chan->freq);
  515. if (!cfp) {
  516. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
  517. (priv, BAND_A, chan->freq);
  518. if (cfp) {
  519. if (adapter->adhoc_11n_enabled)
  520. adapter->adhoc_start_band = BAND_A
  521. | BAND_AN;
  522. else
  523. adapter->adhoc_start_band = BAND_A;
  524. }
  525. }
  526. }
  527. if (!cfp || !cfp->channel) {
  528. dev_err(adapter->dev, "invalid channel/freq\n");
  529. return -1;
  530. }
  531. priv->adhoc_channel = (u8) cfp->channel;
  532. chan->channel = cfp->channel;
  533. chan->freq = cfp->freq;
  534. return 0;
  535. }
  536. /*
  537. * IOCTL request handler to set/get Ad-Hoc channel.
  538. *
  539. * This function prepares the correct firmware command and
  540. * issues it to set or get the ad-hoc channel.
  541. */
  542. static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
  543. u16 action, u16 *channel)
  544. {
  545. if (action == HostCmd_ACT_GEN_GET) {
  546. if (!priv->media_connected) {
  547. *channel = priv->adhoc_channel;
  548. return 0;
  549. }
  550. } else {
  551. priv->adhoc_channel = (u8) *channel;
  552. }
  553. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
  554. action, 0, channel);
  555. }
  556. /*
  557. * IOCTL request handler to change Ad-Hoc channel.
  558. *
  559. * This function allocates the IOCTL request buffer, fills it
  560. * with requisite parameters and calls the IOCTL handler.
  561. *
  562. * The function follows the following steps to perform the change -
  563. * - Get current IBSS information
  564. * - Get current channel
  565. * - If no change is required, return
  566. * - If not connected, change channel and return
  567. * - If connected,
  568. * - Disconnect
  569. * - Change channel
  570. * - Perform specific SSID scan with same SSID
  571. * - Start/Join the IBSS
  572. */
  573. int
  574. mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
  575. {
  576. int ret;
  577. struct mwifiex_bss_info bss_info;
  578. struct mwifiex_ssid_bssid ssid_bssid;
  579. u16 curr_chan = 0;
  580. struct cfg80211_bss *bss = NULL;
  581. struct ieee80211_channel *chan;
  582. enum ieee80211_band band;
  583. memset(&bss_info, 0, sizeof(bss_info));
  584. /* Get BSS information */
  585. if (mwifiex_get_bss_info(priv, &bss_info))
  586. return -1;
  587. /* Get current channel */
  588. ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
  589. &curr_chan);
  590. if (curr_chan == channel) {
  591. ret = 0;
  592. goto done;
  593. }
  594. dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
  595. curr_chan, channel);
  596. if (!bss_info.media_connected) {
  597. ret = 0;
  598. goto done;
  599. }
  600. /* Do disonnect */
  601. memset(&ssid_bssid, 0, ETH_ALEN);
  602. ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
  603. ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
  604. (u16 *) &channel);
  605. /* Do specific SSID scanning */
  606. if (mwifiex_request_scan(priv, &bss_info.ssid)) {
  607. ret = -1;
  608. goto done;
  609. }
  610. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  611. chan = __ieee80211_get_channel(priv->wdev->wiphy,
  612. ieee80211_channel_to_frequency(channel, band));
  613. /* Find the BSS we want using available scan results */
  614. bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
  615. bss_info.ssid.ssid, bss_info.ssid.ssid_len,
  616. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  617. if (!bss)
  618. wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
  619. bss_info.bssid);
  620. ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
  621. done:
  622. return ret;
  623. }
  624. /*
  625. * IOCTL request handler to get rate.
  626. *
  627. * This function prepares the correct firmware command and
  628. * issues it to get the current rate if it is connected,
  629. * otherwise, the function returns the lowest supported rate
  630. * for the band.
  631. */
  632. static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
  633. struct mwifiex_rate_cfg *rate_cfg)
  634. {
  635. rate_cfg->is_rate_auto = priv->is_data_rate_auto;
  636. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  637. HostCmd_ACT_GEN_GET, 0, NULL);
  638. }
  639. /*
  640. * IOCTL request handler to set rate.
  641. *
  642. * This function prepares the correct firmware command and
  643. * issues it to set the current rate.
  644. *
  645. * The function also performs validation checking on the supplied value.
  646. */
  647. static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
  648. struct mwifiex_rate_cfg *rate_cfg)
  649. {
  650. u8 rates[MWIFIEX_SUPPORTED_RATES];
  651. u8 *rate;
  652. int rate_index, ret;
  653. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  654. u32 i;
  655. struct mwifiex_adapter *adapter = priv->adapter;
  656. if (rate_cfg->is_rate_auto) {
  657. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  658. /* Support all HR/DSSS rates */
  659. bitmap_rates[0] = 0x000F;
  660. /* Support all OFDM rates */
  661. bitmap_rates[1] = 0x00FF;
  662. /* Support all HT-MCSs rate */
  663. for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
  664. bitmap_rates[i + 2] = 0xFFFF;
  665. bitmap_rates[9] = 0x3FFF;
  666. } else {
  667. memset(rates, 0, sizeof(rates));
  668. mwifiex_get_active_data_rates(priv, rates);
  669. rate = rates;
  670. for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
  671. dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
  672. rate[i], rate_cfg->rate);
  673. if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
  674. break;
  675. }
  676. if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
  677. dev_err(adapter->dev, "fixed data rate %#x is out "
  678. "of range\n", rate_cfg->rate);
  679. return -1;
  680. }
  681. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  682. rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
  683. /* Only allow b/g rates to be set */
  684. if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
  685. rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
  686. bitmap_rates[0] = 1 << rate_index;
  687. } else {
  688. rate_index -= 1; /* There is a 0x00 in the table */
  689. if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
  690. rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
  691. bitmap_rates[1] = 1 << (rate_index -
  692. MWIFIEX_RATE_INDEX_OFDM0);
  693. }
  694. }
  695. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
  696. HostCmd_ACT_GEN_SET, 0, bitmap_rates);
  697. return ret;
  698. }
  699. /*
  700. * IOCTL request handler to set/get rate.
  701. *
  702. * This function can be used to set/get either the rate value or the
  703. * rate index.
  704. */
  705. static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
  706. struct mwifiex_rate_cfg *rate_cfg)
  707. {
  708. int status;
  709. if (!rate_cfg)
  710. return -1;
  711. if (rate_cfg->action == HostCmd_ACT_GEN_GET)
  712. status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
  713. else
  714. status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
  715. return status;
  716. }
  717. /*
  718. * Sends IOCTL request to get the data rate.
  719. *
  720. * This function allocates the IOCTL request buffer, fills it
  721. * with requisite parameters and calls the IOCTL handler.
  722. */
  723. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
  724. struct mwifiex_rate_cfg *rate)
  725. {
  726. int ret;
  727. memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
  728. rate->action = HostCmd_ACT_GEN_GET;
  729. ret = mwifiex_rate_ioctl_cfg(priv, rate);
  730. if (!ret) {
  731. if (rate->is_rate_auto)
  732. rate->rate = mwifiex_index_to_data_rate(priv->tx_rate,
  733. priv->tx_htinfo);
  734. else
  735. rate->rate = priv->data_rate;
  736. } else {
  737. ret = -1;
  738. }
  739. return ret;
  740. }
  741. /*
  742. * IOCTL request handler to set tx power configuration.
  743. *
  744. * This function prepares the correct firmware command and
  745. * issues it.
  746. *
  747. * For non-auto power mode, all the following power groups are set -
  748. * - Modulation class HR/DSSS
  749. * - Modulation class OFDM
  750. * - Modulation class HTBW20
  751. * - Modulation class HTBW40
  752. */
  753. int mwifiex_set_tx_power(struct mwifiex_private *priv,
  754. struct mwifiex_power_cfg *power_cfg)
  755. {
  756. int ret;
  757. struct host_cmd_ds_txpwr_cfg *txp_cfg;
  758. struct mwifiex_types_power_group *pg_tlv;
  759. struct mwifiex_power_group *pg;
  760. u8 *buf;
  761. u16 dbm = 0;
  762. if (!power_cfg->is_power_auto) {
  763. dbm = (u16) power_cfg->power_level;
  764. if ((dbm < priv->min_tx_power_level) ||
  765. (dbm > priv->max_tx_power_level)) {
  766. dev_err(priv->adapter->dev, "txpower value %d dBm"
  767. " is out of range (%d dBm-%d dBm)\n",
  768. dbm, priv->min_tx_power_level,
  769. priv->max_tx_power_level);
  770. return -1;
  771. }
  772. }
  773. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  774. if (!buf) {
  775. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  776. __func__);
  777. return -ENOMEM;
  778. }
  779. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  780. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  781. if (!power_cfg->is_power_auto) {
  782. txp_cfg->mode = cpu_to_le32(1);
  783. pg_tlv = (struct mwifiex_types_power_group *) (buf +
  784. sizeof(struct host_cmd_ds_txpwr_cfg));
  785. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  786. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  787. pg = (struct mwifiex_power_group *) (buf +
  788. sizeof(struct host_cmd_ds_txpwr_cfg) +
  789. sizeof(struct mwifiex_types_power_group));
  790. /* Power group for modulation class HR/DSSS */
  791. pg->first_rate_code = 0x00;
  792. pg->last_rate_code = 0x03;
  793. pg->modulation_class = MOD_CLASS_HR_DSSS;
  794. pg->power_step = 0;
  795. pg->power_min = (s8) dbm;
  796. pg->power_max = (s8) dbm;
  797. pg++;
  798. /* Power group for modulation class OFDM */
  799. pg->first_rate_code = 0x00;
  800. pg->last_rate_code = 0x07;
  801. pg->modulation_class = MOD_CLASS_OFDM;
  802. pg->power_step = 0;
  803. pg->power_min = (s8) dbm;
  804. pg->power_max = (s8) dbm;
  805. pg++;
  806. /* Power group for modulation class HTBW20 */
  807. pg->first_rate_code = 0x00;
  808. pg->last_rate_code = 0x20;
  809. pg->modulation_class = MOD_CLASS_HT;
  810. pg->power_step = 0;
  811. pg->power_min = (s8) dbm;
  812. pg->power_max = (s8) dbm;
  813. pg->ht_bandwidth = HT_BW_20;
  814. pg++;
  815. /* Power group for modulation class HTBW40 */
  816. pg->first_rate_code = 0x00;
  817. pg->last_rate_code = 0x20;
  818. pg->modulation_class = MOD_CLASS_HT;
  819. pg->power_step = 0;
  820. pg->power_min = (s8) dbm;
  821. pg->power_max = (s8) dbm;
  822. pg->ht_bandwidth = HT_BW_40;
  823. }
  824. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
  825. HostCmd_ACT_GEN_SET, 0, buf);
  826. kfree(buf);
  827. return ret;
  828. }
  829. /*
  830. * IOCTL request handler to get power save mode.
  831. *
  832. * This function prepares the correct firmware command and
  833. * issues it.
  834. */
  835. int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
  836. {
  837. int ret;
  838. struct mwifiex_adapter *adapter = priv->adapter;
  839. u16 sub_cmd;
  840. if (*ps_mode)
  841. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  842. else
  843. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  844. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  845. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  846. sub_cmd, BITMAP_STA_PS, NULL);
  847. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  848. ret = mwifiex_send_cmd_async(priv,
  849. HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
  850. 0, NULL);
  851. return ret;
  852. }
  853. /*
  854. * IOCTL request handler to set/reset WPA IE.
  855. *
  856. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  857. * is checked to determine WPA version. If buffer length is zero, the existing
  858. * WPA IE is reset.
  859. */
  860. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  861. u8 *ie_data_ptr, u16 ie_len)
  862. {
  863. if (ie_len) {
  864. if (ie_len > sizeof(priv->wpa_ie)) {
  865. dev_err(priv->adapter->dev,
  866. "failed to copy WPA IE, too big\n");
  867. return -1;
  868. }
  869. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  870. priv->wpa_ie_len = (u8) ie_len;
  871. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  872. priv->wpa_ie_len, priv->wpa_ie[0]);
  873. if (priv->wpa_ie[0] == WLAN_EID_WPA) {
  874. priv->sec_info.wpa_enabled = true;
  875. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  876. priv->sec_info.wpa2_enabled = true;
  877. } else {
  878. priv->sec_info.wpa_enabled = false;
  879. priv->sec_info.wpa2_enabled = false;
  880. }
  881. } else {
  882. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  883. priv->wpa_ie_len = 0;
  884. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  885. priv->wpa_ie_len, priv->wpa_ie[0]);
  886. priv->sec_info.wpa_enabled = false;
  887. priv->sec_info.wpa2_enabled = false;
  888. }
  889. return 0;
  890. }
  891. /*
  892. * IOCTL request handler to set/reset WAPI IE.
  893. *
  894. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  895. * is checked to internally enable WAPI. If buffer length is zero, the existing
  896. * WAPI IE is reset.
  897. */
  898. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  899. u8 *ie_data_ptr, u16 ie_len)
  900. {
  901. if (ie_len) {
  902. if (ie_len > sizeof(priv->wapi_ie)) {
  903. dev_dbg(priv->adapter->dev,
  904. "info: failed to copy WAPI IE, too big\n");
  905. return -1;
  906. }
  907. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  908. priv->wapi_ie_len = ie_len;
  909. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  910. priv->wapi_ie_len, priv->wapi_ie[0]);
  911. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  912. priv->sec_info.wapi_enabled = true;
  913. } else {
  914. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  915. priv->wapi_ie_len = ie_len;
  916. dev_dbg(priv->adapter->dev,
  917. "info: Reset wapi_ie_len=%d IE=%#x\n",
  918. priv->wapi_ie_len, priv->wapi_ie[0]);
  919. priv->sec_info.wapi_enabled = false;
  920. }
  921. return 0;
  922. }
  923. /*
  924. * IOCTL request handler to set WAPI key.
  925. *
  926. * This function prepares the correct firmware command and
  927. * issues it.
  928. */
  929. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
  930. struct mwifiex_ds_encrypt_key *encrypt_key)
  931. {
  932. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  933. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  934. encrypt_key);
  935. }
  936. /*
  937. * IOCTL request handler to set WEP network key.
  938. *
  939. * This function prepares the correct firmware command and
  940. * issues it, after validation checks.
  941. */
  942. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
  943. struct mwifiex_ds_encrypt_key *encrypt_key)
  944. {
  945. int ret;
  946. struct mwifiex_wep_key *wep_key;
  947. int index;
  948. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  949. priv->wep_key_curr_index = 0;
  950. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  951. index = encrypt_key->key_index;
  952. if (encrypt_key->key_disable) {
  953. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
  954. } else if (!encrypt_key->key_len) {
  955. /* Copy the required key as the current key */
  956. wep_key = &priv->wep_key[index];
  957. if (!wep_key->key_length) {
  958. dev_err(priv->adapter->dev,
  959. "key not set, so cannot enable it\n");
  960. return -1;
  961. }
  962. priv->wep_key_curr_index = (u16) index;
  963. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  964. } else {
  965. wep_key = &priv->wep_key[index];
  966. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  967. /* Copy the key in the driver */
  968. memcpy(wep_key->key_material,
  969. encrypt_key->key_material,
  970. encrypt_key->key_len);
  971. wep_key->key_index = index;
  972. wep_key->key_length = encrypt_key->key_len;
  973. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  974. }
  975. if (wep_key->key_length) {
  976. /* Send request to firmware */
  977. ret = mwifiex_send_cmd_async(priv,
  978. HostCmd_CMD_802_11_KEY_MATERIAL,
  979. HostCmd_ACT_GEN_SET, 0, NULL);
  980. if (ret)
  981. return ret;
  982. }
  983. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  984. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  985. else
  986. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  987. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  988. HostCmd_ACT_GEN_SET, 0,
  989. &priv->curr_pkt_filter);
  990. return ret;
  991. }
  992. /*
  993. * IOCTL request handler to set WPA key.
  994. *
  995. * This function prepares the correct firmware command and
  996. * issues it, after validation checks.
  997. *
  998. * Current driver only supports key length of up to 32 bytes.
  999. *
  1000. * This function can also be used to disable a currently set key.
  1001. */
  1002. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
  1003. struct mwifiex_ds_encrypt_key *encrypt_key)
  1004. {
  1005. int ret;
  1006. u8 remove_key = false;
  1007. struct host_cmd_ds_802_11_key_material *ibss_key;
  1008. /* Current driver only supports key length of up to 32 bytes */
  1009. if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
  1010. dev_err(priv->adapter->dev, "key length too long\n");
  1011. return -1;
  1012. }
  1013. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  1014. /*
  1015. * IBSS/WPA-None uses only one key (Group) for both receiving
  1016. * and sending unicast and multicast packets.
  1017. */
  1018. /* Send the key as PTK to firmware */
  1019. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1020. ret = mwifiex_send_cmd_async(priv,
  1021. HostCmd_CMD_802_11_KEY_MATERIAL,
  1022. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1023. encrypt_key);
  1024. if (ret)
  1025. return ret;
  1026. ibss_key = &priv->aes_key;
  1027. memset(ibss_key, 0,
  1028. sizeof(struct host_cmd_ds_802_11_key_material));
  1029. /* Copy the key in the driver */
  1030. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  1031. encrypt_key->key_len);
  1032. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  1033. sizeof(ibss_key->key_param_set.key_len));
  1034. ibss_key->key_param_set.key_type_id
  1035. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  1036. ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
  1037. /* Send the key as GTK to firmware */
  1038. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  1039. }
  1040. if (!encrypt_key->key_index)
  1041. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1042. if (remove_key)
  1043. ret = mwifiex_send_cmd_sync(priv,
  1044. HostCmd_CMD_802_11_KEY_MATERIAL,
  1045. HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
  1046. encrypt_key);
  1047. else
  1048. ret = mwifiex_send_cmd_sync(priv,
  1049. HostCmd_CMD_802_11_KEY_MATERIAL,
  1050. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1051. encrypt_key);
  1052. return ret;
  1053. }
  1054. /*
  1055. * IOCTL request handler to set/get network keys.
  1056. *
  1057. * This is a generic key handling function which supports WEP, WPA
  1058. * and WAPI.
  1059. */
  1060. static int
  1061. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  1062. struct mwifiex_ds_encrypt_key *encrypt_key)
  1063. {
  1064. int status;
  1065. if (encrypt_key->is_wapi_key)
  1066. status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
  1067. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  1068. status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
  1069. else
  1070. status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
  1071. return status;
  1072. }
  1073. /*
  1074. * This function returns the driver version.
  1075. */
  1076. int
  1077. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  1078. int max_len)
  1079. {
  1080. union {
  1081. u32 l;
  1082. u8 c[4];
  1083. } ver;
  1084. char fw_ver[32];
  1085. ver.l = adapter->fw_release_number;
  1086. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1087. snprintf(version, max_len, driver_version, fw_ver);
  1088. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  1089. return 0;
  1090. }
  1091. /*
  1092. * Sends IOCTL request to get signal information.
  1093. *
  1094. * This function allocates the IOCTL request buffer, fills it
  1095. * with requisite parameters and calls the IOCTL handler.
  1096. */
  1097. int mwifiex_get_signal_info(struct mwifiex_private *priv,
  1098. struct mwifiex_ds_get_signal *signal)
  1099. {
  1100. int status;
  1101. signal->selector = ALL_RSSI_INFO_MASK;
  1102. /* Signal info can be obtained only if connected */
  1103. if (!priv->media_connected) {
  1104. dev_dbg(priv->adapter->dev,
  1105. "info: Can not get signal in disconnected state\n");
  1106. return -1;
  1107. }
  1108. status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
  1109. HostCmd_ACT_GEN_GET, 0, signal);
  1110. if (!status) {
  1111. if (signal->selector & BCN_RSSI_AVG_MASK)
  1112. priv->qual_level = signal->bcn_rssi_avg;
  1113. if (signal->selector & BCN_NF_AVG_MASK)
  1114. priv->qual_noise = signal->bcn_nf_avg;
  1115. }
  1116. return status;
  1117. }
  1118. /*
  1119. * Sends IOCTL request to set encoding parameters.
  1120. *
  1121. * This function allocates the IOCTL request buffer, fills it
  1122. * with requisite parameters and calls the IOCTL handler.
  1123. */
  1124. int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
  1125. int key_len, u8 key_index, int disable)
  1126. {
  1127. struct mwifiex_ds_encrypt_key encrypt_key;
  1128. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  1129. encrypt_key.key_len = key_len;
  1130. if (!disable) {
  1131. encrypt_key.key_index = key_index;
  1132. if (key_len)
  1133. memcpy(encrypt_key.key_material, key, key_len);
  1134. } else {
  1135. encrypt_key.key_disable = true;
  1136. }
  1137. return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
  1138. }
  1139. /*
  1140. * Sends IOCTL request to get extended version.
  1141. *
  1142. * This function allocates the IOCTL request buffer, fills it
  1143. * with requisite parameters and calls the IOCTL handler.
  1144. */
  1145. int
  1146. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  1147. {
  1148. struct mwifiex_ver_ext ver_ext;
  1149. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  1150. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
  1151. HostCmd_ACT_GEN_GET, 0, &ver_ext))
  1152. return -1;
  1153. return 0;
  1154. }
  1155. /*
  1156. * Sends IOCTL request to get statistics information.
  1157. *
  1158. * This function allocates the IOCTL request buffer, fills it
  1159. * with requisite parameters and calls the IOCTL handler.
  1160. */
  1161. int
  1162. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1163. struct mwifiex_ds_get_stats *log)
  1164. {
  1165. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
  1166. HostCmd_ACT_GEN_GET, 0, log);
  1167. }
  1168. /*
  1169. * IOCTL request handler to read/write register.
  1170. *
  1171. * This function prepares the correct firmware command and
  1172. * issues it.
  1173. *
  1174. * Access to the following registers are supported -
  1175. * - MAC
  1176. * - BBP
  1177. * - RF
  1178. * - PMIC
  1179. * - CAU
  1180. */
  1181. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1182. struct mwifiex_ds_reg_rw *reg_rw,
  1183. u16 action)
  1184. {
  1185. u16 cmd_no;
  1186. switch (le32_to_cpu(reg_rw->type)) {
  1187. case MWIFIEX_REG_MAC:
  1188. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1189. break;
  1190. case MWIFIEX_REG_BBP:
  1191. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1192. break;
  1193. case MWIFIEX_REG_RF:
  1194. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1195. break;
  1196. case MWIFIEX_REG_PMIC:
  1197. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1198. break;
  1199. case MWIFIEX_REG_CAU:
  1200. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1201. break;
  1202. default:
  1203. return -1;
  1204. }
  1205. return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
  1206. }
  1207. /*
  1208. * Sends IOCTL request to write to a register.
  1209. *
  1210. * This function allocates the IOCTL request buffer, fills it
  1211. * with requisite parameters and calls the IOCTL handler.
  1212. */
  1213. int
  1214. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1215. u32 reg_offset, u32 reg_value)
  1216. {
  1217. struct mwifiex_ds_reg_rw reg_rw;
  1218. reg_rw.type = cpu_to_le32(reg_type);
  1219. reg_rw.offset = cpu_to_le32(reg_offset);
  1220. reg_rw.value = cpu_to_le32(reg_value);
  1221. return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
  1222. }
  1223. /*
  1224. * Sends IOCTL request to read from a register.
  1225. *
  1226. * This function allocates the IOCTL request buffer, fills it
  1227. * with requisite parameters and calls the IOCTL handler.
  1228. */
  1229. int
  1230. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1231. u32 reg_offset, u32 *value)
  1232. {
  1233. int ret;
  1234. struct mwifiex_ds_reg_rw reg_rw;
  1235. reg_rw.type = cpu_to_le32(reg_type);
  1236. reg_rw.offset = cpu_to_le32(reg_offset);
  1237. ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
  1238. if (ret)
  1239. goto done;
  1240. *value = le32_to_cpu(reg_rw.value);
  1241. done:
  1242. return ret;
  1243. }
  1244. /*
  1245. * Sends IOCTL request to read from EEPROM.
  1246. *
  1247. * This function allocates the IOCTL request buffer, fills it
  1248. * with requisite parameters and calls the IOCTL handler.
  1249. */
  1250. int
  1251. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1252. u8 *value)
  1253. {
  1254. int ret;
  1255. struct mwifiex_ds_read_eeprom rd_eeprom;
  1256. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1257. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1258. /* Send request to firmware */
  1259. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1260. HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
  1261. if (!ret)
  1262. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1263. return ret;
  1264. }
  1265. /*
  1266. * This function sets a generic IE. In addition to generic IE, it can
  1267. * also handle WPA, WPA2 and WAPI IEs.
  1268. */
  1269. static int
  1270. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1271. u16 ie_len)
  1272. {
  1273. int ret = 0;
  1274. struct ieee_types_vendor_header *pvendor_ie;
  1275. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1276. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1277. /* If the passed length is zero, reset the buffer */
  1278. if (!ie_len) {
  1279. priv->gen_ie_buf_len = 0;
  1280. priv->wps.session_enable = false;
  1281. return 0;
  1282. } else if (!ie_data_ptr) {
  1283. return -1;
  1284. }
  1285. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1286. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1287. if (((pvendor_ie->element_id == WLAN_EID_WPA)
  1288. && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
  1289. || (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1290. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1291. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1292. priv->wps.session_enable = false;
  1293. return ret;
  1294. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1295. /* IE is a WAPI IE so call set_wapi function */
  1296. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1297. return ret;
  1298. }
  1299. /*
  1300. * Verify that the passed length is not larger than the
  1301. * available space remaining in the buffer
  1302. */
  1303. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1304. /* Test to see if it is a WPS IE, if so, enable
  1305. * wps session flag
  1306. */
  1307. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1308. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
  1309. && (!memcmp(pvendor_ie->oui, wps_oui,
  1310. sizeof(wps_oui)))) {
  1311. priv->wps.session_enable = true;
  1312. dev_dbg(priv->adapter->dev,
  1313. "info: WPS Session Enabled.\n");
  1314. }
  1315. /* Append the passed data to the end of the
  1316. genIeBuffer */
  1317. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  1318. ie_len);
  1319. /* Increment the stored buffer length by the
  1320. size passed */
  1321. priv->gen_ie_buf_len += ie_len;
  1322. } else {
  1323. /* Passed data does not fit in the remaining
  1324. buffer space */
  1325. ret = -1;
  1326. }
  1327. /* Return 0, or -1 for error case */
  1328. return ret;
  1329. }
  1330. /*
  1331. * IOCTL request handler to set/get generic IE.
  1332. *
  1333. * In addition to various generic IEs, this function can also be
  1334. * used to set the ARP filter.
  1335. */
  1336. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  1337. struct mwifiex_ds_misc_gen_ie *gen_ie,
  1338. u16 action)
  1339. {
  1340. struct mwifiex_adapter *adapter = priv->adapter;
  1341. switch (gen_ie->type) {
  1342. case MWIFIEX_IE_TYPE_GEN_IE:
  1343. if (action == HostCmd_ACT_GEN_GET) {
  1344. gen_ie->len = priv->wpa_ie_len;
  1345. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  1346. } else {
  1347. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  1348. (u16) gen_ie->len);
  1349. }
  1350. break;
  1351. case MWIFIEX_IE_TYPE_ARP_FILTER:
  1352. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  1353. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  1354. adapter->arp_filter_size = 0;
  1355. dev_err(adapter->dev, "invalid ARP filter size\n");
  1356. return -1;
  1357. } else {
  1358. memcpy(adapter->arp_filter, gen_ie->ie_data,
  1359. gen_ie->len);
  1360. adapter->arp_filter_size = gen_ie->len;
  1361. }
  1362. break;
  1363. default:
  1364. dev_err(adapter->dev, "invalid IE type\n");
  1365. return -1;
  1366. }
  1367. return 0;
  1368. }
  1369. /*
  1370. * Sends IOCTL request to set a generic IE.
  1371. *
  1372. * This function allocates the IOCTL request buffer, fills it
  1373. * with requisite parameters and calls the IOCTL handler.
  1374. */
  1375. int
  1376. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  1377. {
  1378. struct mwifiex_ds_misc_gen_ie gen_ie;
  1379. if (ie_len > IEEE_MAX_IE_SIZE)
  1380. return -EFAULT;
  1381. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  1382. gen_ie.len = ie_len;
  1383. memcpy(gen_ie.ie_data, ie, ie_len);
  1384. if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
  1385. return -EFAULT;
  1386. return 0;
  1387. }