sta_ioctl.c 41 KB

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