sta_ioctl.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  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_by_band_and_channel_from_cfg80211
  458. (priv, 0, (u16) chan->channel);
  459. if (!cfp) {
  460. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  461. (priv, BAND_A, (u16) chan->channel);
  462. if (cfp) {
  463. if (adapter->adhoc_11n_enabled)
  464. adapter->adhoc_start_band = BAND_A
  465. | BAND_AN;
  466. else
  467. adapter->adhoc_start_band = BAND_A;
  468. }
  469. }
  470. } else {
  471. if (chan->freq <= MAX_FREQUENCY_BAND_BG)
  472. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
  473. priv, 0, chan->freq);
  474. if (!cfp) {
  475. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
  476. (priv, BAND_A, chan->freq);
  477. if (cfp) {
  478. if (adapter->adhoc_11n_enabled)
  479. adapter->adhoc_start_band = BAND_A
  480. | BAND_AN;
  481. else
  482. adapter->adhoc_start_band = BAND_A;
  483. }
  484. }
  485. }
  486. if (!cfp || !cfp->channel) {
  487. dev_err(adapter->dev, "invalid channel/freq\n");
  488. return -1;
  489. }
  490. priv->adhoc_channel = (u8) cfp->channel;
  491. chan->channel = cfp->channel;
  492. chan->freq = cfp->freq;
  493. return 0;
  494. }
  495. /*
  496. * IOCTL request handler to set/get Ad-Hoc channel.
  497. *
  498. * This function prepares the correct firmware command and
  499. * issues it to set or get the ad-hoc channel.
  500. */
  501. static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
  502. u16 action, u16 *channel)
  503. {
  504. if (action == HostCmd_ACT_GEN_GET) {
  505. if (!priv->media_connected) {
  506. *channel = priv->adhoc_channel;
  507. return 0;
  508. }
  509. } else {
  510. priv->adhoc_channel = (u8) *channel;
  511. }
  512. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
  513. action, 0, channel);
  514. }
  515. /*
  516. * IOCTL request handler to change Ad-Hoc channel.
  517. *
  518. * This function allocates the IOCTL request buffer, fills it
  519. * with requisite parameters and calls the IOCTL handler.
  520. *
  521. * The function follows the following steps to perform the change -
  522. * - Get current IBSS information
  523. * - Get current channel
  524. * - If no change is required, return
  525. * - If not connected, change channel and return
  526. * - If connected,
  527. * - Disconnect
  528. * - Change channel
  529. * - Perform specific SSID scan with same SSID
  530. * - Start/Join the IBSS
  531. */
  532. int
  533. mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
  534. {
  535. int ret;
  536. struct mwifiex_bss_info bss_info;
  537. struct mwifiex_ssid_bssid ssid_bssid;
  538. u16 curr_chan = 0;
  539. struct cfg80211_bss *bss = NULL;
  540. struct ieee80211_channel *chan;
  541. enum ieee80211_band band;
  542. memset(&bss_info, 0, sizeof(bss_info));
  543. /* Get BSS information */
  544. if (mwifiex_get_bss_info(priv, &bss_info))
  545. return -1;
  546. /* Get current channel */
  547. ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
  548. &curr_chan);
  549. if (curr_chan == channel) {
  550. ret = 0;
  551. goto done;
  552. }
  553. dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
  554. curr_chan, channel);
  555. if (!bss_info.media_connected) {
  556. ret = 0;
  557. goto done;
  558. }
  559. /* Do disonnect */
  560. memset(&ssid_bssid, 0, ETH_ALEN);
  561. ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
  562. ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
  563. (u16 *) &channel);
  564. /* Do specific SSID scanning */
  565. if (mwifiex_request_scan(priv, &bss_info.ssid)) {
  566. ret = -1;
  567. goto done;
  568. }
  569. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  570. chan = __ieee80211_get_channel(priv->wdev->wiphy,
  571. ieee80211_channel_to_frequency(channel, band));
  572. /* Find the BSS we want using available scan results */
  573. bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
  574. bss_info.ssid.ssid, bss_info.ssid.ssid_len,
  575. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  576. if (!bss)
  577. wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
  578. bss_info.bssid);
  579. ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
  580. done:
  581. return ret;
  582. }
  583. /*
  584. * IOCTL request handler to get rate.
  585. *
  586. * This function prepares the correct firmware command and
  587. * issues it to get the current rate if it is connected,
  588. * otherwise, the function returns the lowest supported rate
  589. * for the band.
  590. */
  591. static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
  592. struct mwifiex_rate_cfg *rate_cfg)
  593. {
  594. rate_cfg->is_rate_auto = priv->is_data_rate_auto;
  595. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
  596. HostCmd_ACT_GEN_GET, 0, NULL);
  597. }
  598. /*
  599. * IOCTL request handler to set rate.
  600. *
  601. * This function prepares the correct firmware command and
  602. * issues it to set the current rate.
  603. *
  604. * The function also performs validation checking on the supplied value.
  605. */
  606. static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
  607. struct mwifiex_rate_cfg *rate_cfg)
  608. {
  609. u8 rates[MWIFIEX_SUPPORTED_RATES];
  610. u8 *rate;
  611. int rate_index, ret;
  612. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  613. u32 i;
  614. struct mwifiex_adapter *adapter = priv->adapter;
  615. if (rate_cfg->is_rate_auto) {
  616. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  617. /* Support all HR/DSSS rates */
  618. bitmap_rates[0] = 0x000F;
  619. /* Support all OFDM rates */
  620. bitmap_rates[1] = 0x00FF;
  621. /* Support all HT-MCSs rate */
  622. for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
  623. bitmap_rates[i + 2] = 0xFFFF;
  624. bitmap_rates[9] = 0x3FFF;
  625. } else {
  626. memset(rates, 0, sizeof(rates));
  627. mwifiex_get_active_data_rates(priv, rates);
  628. rate = rates;
  629. for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
  630. dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
  631. rate[i], rate_cfg->rate);
  632. if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
  633. break;
  634. }
  635. if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
  636. dev_err(adapter->dev, "fixed data rate %#x is out "
  637. "of range\n", rate_cfg->rate);
  638. return -1;
  639. }
  640. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  641. rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
  642. /* Only allow b/g rates to be set */
  643. if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
  644. rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
  645. bitmap_rates[0] = 1 << rate_index;
  646. } else {
  647. rate_index -= 1; /* There is a 0x00 in the table */
  648. if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
  649. rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
  650. bitmap_rates[1] = 1 << (rate_index -
  651. MWIFIEX_RATE_INDEX_OFDM0);
  652. }
  653. }
  654. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
  655. HostCmd_ACT_GEN_SET, 0, bitmap_rates);
  656. return ret;
  657. }
  658. /*
  659. * IOCTL request handler to set/get rate.
  660. *
  661. * This function can be used to set/get either the rate value or the
  662. * rate index.
  663. */
  664. static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
  665. struct mwifiex_rate_cfg *rate_cfg)
  666. {
  667. int status;
  668. if (!rate_cfg)
  669. return -1;
  670. if (rate_cfg->action == HostCmd_ACT_GEN_GET)
  671. status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
  672. else
  673. status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
  674. return status;
  675. }
  676. /*
  677. * Sends IOCTL request to get the data rate.
  678. *
  679. * This function allocates the IOCTL request buffer, fills it
  680. * with requisite parameters and calls the IOCTL handler.
  681. */
  682. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
  683. struct mwifiex_rate_cfg *rate)
  684. {
  685. int ret;
  686. memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
  687. rate->action = HostCmd_ACT_GEN_GET;
  688. ret = mwifiex_rate_ioctl_cfg(priv, rate);
  689. if (!ret) {
  690. if (rate->is_rate_auto)
  691. rate->rate = mwifiex_index_to_data_rate(priv,
  692. priv->tx_rate, priv->tx_htinfo);
  693. else
  694. rate->rate = priv->data_rate;
  695. } else {
  696. ret = -1;
  697. }
  698. return ret;
  699. }
  700. /*
  701. * IOCTL request handler to set tx power configuration.
  702. *
  703. * This function prepares the correct firmware command and
  704. * issues it.
  705. *
  706. * For non-auto power mode, all the following power groups are set -
  707. * - Modulation class HR/DSSS
  708. * - Modulation class OFDM
  709. * - Modulation class HTBW20
  710. * - Modulation class HTBW40
  711. */
  712. int mwifiex_set_tx_power(struct mwifiex_private *priv,
  713. struct mwifiex_power_cfg *power_cfg)
  714. {
  715. int ret;
  716. struct host_cmd_ds_txpwr_cfg *txp_cfg;
  717. struct mwifiex_types_power_group *pg_tlv;
  718. struct mwifiex_power_group *pg;
  719. u8 *buf;
  720. u16 dbm = 0;
  721. if (!power_cfg->is_power_auto) {
  722. dbm = (u16) power_cfg->power_level;
  723. if ((dbm < priv->min_tx_power_level) ||
  724. (dbm > priv->max_tx_power_level)) {
  725. dev_err(priv->adapter->dev, "txpower value %d dBm"
  726. " is out of range (%d dBm-%d dBm)\n",
  727. dbm, priv->min_tx_power_level,
  728. priv->max_tx_power_level);
  729. return -1;
  730. }
  731. }
  732. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  733. if (!buf) {
  734. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  735. __func__);
  736. return -ENOMEM;
  737. }
  738. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  739. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  740. if (!power_cfg->is_power_auto) {
  741. txp_cfg->mode = cpu_to_le32(1);
  742. pg_tlv = (struct mwifiex_types_power_group *) (buf +
  743. sizeof(struct host_cmd_ds_txpwr_cfg));
  744. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  745. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  746. pg = (struct mwifiex_power_group *) (buf +
  747. sizeof(struct host_cmd_ds_txpwr_cfg) +
  748. sizeof(struct mwifiex_types_power_group));
  749. /* Power group for modulation class HR/DSSS */
  750. pg->first_rate_code = 0x00;
  751. pg->last_rate_code = 0x03;
  752. pg->modulation_class = MOD_CLASS_HR_DSSS;
  753. pg->power_step = 0;
  754. pg->power_min = (s8) dbm;
  755. pg->power_max = (s8) dbm;
  756. pg++;
  757. /* Power group for modulation class OFDM */
  758. pg->first_rate_code = 0x00;
  759. pg->last_rate_code = 0x07;
  760. pg->modulation_class = MOD_CLASS_OFDM;
  761. pg->power_step = 0;
  762. pg->power_min = (s8) dbm;
  763. pg->power_max = (s8) dbm;
  764. pg++;
  765. /* Power group for modulation class HTBW20 */
  766. pg->first_rate_code = 0x00;
  767. pg->last_rate_code = 0x20;
  768. pg->modulation_class = MOD_CLASS_HT;
  769. pg->power_step = 0;
  770. pg->power_min = (s8) dbm;
  771. pg->power_max = (s8) dbm;
  772. pg->ht_bandwidth = HT_BW_20;
  773. pg++;
  774. /* Power group for modulation class HTBW40 */
  775. pg->first_rate_code = 0x00;
  776. pg->last_rate_code = 0x20;
  777. pg->modulation_class = MOD_CLASS_HT;
  778. pg->power_step = 0;
  779. pg->power_min = (s8) dbm;
  780. pg->power_max = (s8) dbm;
  781. pg->ht_bandwidth = HT_BW_40;
  782. }
  783. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
  784. HostCmd_ACT_GEN_SET, 0, buf);
  785. kfree(buf);
  786. return ret;
  787. }
  788. /*
  789. * IOCTL request handler to get power save mode.
  790. *
  791. * This function prepares the correct firmware command and
  792. * issues it.
  793. */
  794. int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
  795. {
  796. int ret;
  797. struct mwifiex_adapter *adapter = priv->adapter;
  798. u16 sub_cmd;
  799. if (*ps_mode)
  800. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  801. else
  802. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  803. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  804. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  805. sub_cmd, BITMAP_STA_PS, NULL);
  806. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  807. ret = mwifiex_send_cmd_async(priv,
  808. HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
  809. 0, NULL);
  810. return ret;
  811. }
  812. /*
  813. * IOCTL request handler to set/reset WPA IE.
  814. *
  815. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  816. * is checked to determine WPA version. If buffer length is zero, the existing
  817. * WPA IE is reset.
  818. */
  819. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  820. u8 *ie_data_ptr, u16 ie_len)
  821. {
  822. if (ie_len) {
  823. if (ie_len > sizeof(priv->wpa_ie)) {
  824. dev_err(priv->adapter->dev,
  825. "failed to copy WPA IE, too big\n");
  826. return -1;
  827. }
  828. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  829. priv->wpa_ie_len = (u8) ie_len;
  830. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  831. priv->wpa_ie_len, priv->wpa_ie[0]);
  832. if (priv->wpa_ie[0] == WLAN_EID_WPA) {
  833. priv->sec_info.wpa_enabled = true;
  834. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  835. priv->sec_info.wpa2_enabled = true;
  836. } else {
  837. priv->sec_info.wpa_enabled = false;
  838. priv->sec_info.wpa2_enabled = false;
  839. }
  840. } else {
  841. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  842. priv->wpa_ie_len = 0;
  843. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  844. priv->wpa_ie_len, priv->wpa_ie[0]);
  845. priv->sec_info.wpa_enabled = false;
  846. priv->sec_info.wpa2_enabled = false;
  847. }
  848. return 0;
  849. }
  850. /*
  851. * IOCTL request handler to set/reset WAPI IE.
  852. *
  853. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  854. * is checked to internally enable WAPI. If buffer length is zero, the existing
  855. * WAPI IE is reset.
  856. */
  857. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  858. u8 *ie_data_ptr, u16 ie_len)
  859. {
  860. if (ie_len) {
  861. if (ie_len > sizeof(priv->wapi_ie)) {
  862. dev_dbg(priv->adapter->dev,
  863. "info: failed to copy WAPI IE, too big\n");
  864. return -1;
  865. }
  866. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  867. priv->wapi_ie_len = ie_len;
  868. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  869. priv->wapi_ie_len, priv->wapi_ie[0]);
  870. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  871. priv->sec_info.wapi_enabled = true;
  872. } else {
  873. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  874. priv->wapi_ie_len = ie_len;
  875. dev_dbg(priv->adapter->dev,
  876. "info: Reset wapi_ie_len=%d IE=%#x\n",
  877. priv->wapi_ie_len, priv->wapi_ie[0]);
  878. priv->sec_info.wapi_enabled = false;
  879. }
  880. return 0;
  881. }
  882. /*
  883. * IOCTL request handler to set WAPI key.
  884. *
  885. * This function prepares the correct firmware command and
  886. * issues it.
  887. */
  888. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
  889. struct mwifiex_ds_encrypt_key *encrypt_key)
  890. {
  891. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  892. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  893. encrypt_key);
  894. }
  895. /*
  896. * IOCTL request handler to set WEP network key.
  897. *
  898. * This function prepares the correct firmware command and
  899. * issues it, after validation checks.
  900. */
  901. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
  902. struct mwifiex_ds_encrypt_key *encrypt_key)
  903. {
  904. int ret;
  905. struct mwifiex_wep_key *wep_key;
  906. int index;
  907. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  908. priv->wep_key_curr_index = 0;
  909. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  910. index = encrypt_key->key_index;
  911. if (encrypt_key->key_disable) {
  912. priv->sec_info.wep_enabled = 0;
  913. } else if (!encrypt_key->key_len) {
  914. /* Copy the required key as the current key */
  915. wep_key = &priv->wep_key[index];
  916. if (!wep_key->key_length) {
  917. dev_err(priv->adapter->dev,
  918. "key not set, so cannot enable it\n");
  919. return -1;
  920. }
  921. priv->wep_key_curr_index = (u16) index;
  922. priv->sec_info.wep_enabled = 1;
  923. } else {
  924. wep_key = &priv->wep_key[index];
  925. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  926. /* Copy the key in the driver */
  927. memcpy(wep_key->key_material,
  928. encrypt_key->key_material,
  929. encrypt_key->key_len);
  930. wep_key->key_index = index;
  931. wep_key->key_length = encrypt_key->key_len;
  932. priv->sec_info.wep_enabled = 1;
  933. }
  934. if (wep_key->key_length) {
  935. /* Send request to firmware */
  936. ret = mwifiex_send_cmd_async(priv,
  937. HostCmd_CMD_802_11_KEY_MATERIAL,
  938. HostCmd_ACT_GEN_SET, 0, NULL);
  939. if (ret)
  940. return ret;
  941. }
  942. if (priv->sec_info.wep_enabled)
  943. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  944. else
  945. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  946. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
  947. HostCmd_ACT_GEN_SET, 0,
  948. &priv->curr_pkt_filter);
  949. return ret;
  950. }
  951. /*
  952. * IOCTL request handler to set WPA key.
  953. *
  954. * This function prepares the correct firmware command and
  955. * issues it, after validation checks.
  956. *
  957. * Current driver only supports key length of up to 32 bytes.
  958. *
  959. * This function can also be used to disable a currently set key.
  960. */
  961. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
  962. struct mwifiex_ds_encrypt_key *encrypt_key)
  963. {
  964. int ret;
  965. u8 remove_key = false;
  966. struct host_cmd_ds_802_11_key_material *ibss_key;
  967. /* Current driver only supports key length of up to 32 bytes */
  968. if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
  969. dev_err(priv->adapter->dev, "key length too long\n");
  970. return -1;
  971. }
  972. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  973. /*
  974. * IBSS/WPA-None uses only one key (Group) for both receiving
  975. * and sending unicast and multicast packets.
  976. */
  977. /* Send the key as PTK to firmware */
  978. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  979. ret = mwifiex_send_cmd_async(priv,
  980. HostCmd_CMD_802_11_KEY_MATERIAL,
  981. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  982. encrypt_key);
  983. if (ret)
  984. return ret;
  985. ibss_key = &priv->aes_key;
  986. memset(ibss_key, 0,
  987. sizeof(struct host_cmd_ds_802_11_key_material));
  988. /* Copy the key in the driver */
  989. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  990. encrypt_key->key_len);
  991. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  992. sizeof(ibss_key->key_param_set.key_len));
  993. ibss_key->key_param_set.key_type_id
  994. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  995. ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
  996. /* Send the key as GTK to firmware */
  997. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  998. }
  999. if (!encrypt_key->key_index)
  1000. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1001. if (remove_key)
  1002. ret = mwifiex_send_cmd_sync(priv,
  1003. HostCmd_CMD_802_11_KEY_MATERIAL,
  1004. HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
  1005. encrypt_key);
  1006. else
  1007. ret = mwifiex_send_cmd_sync(priv,
  1008. HostCmd_CMD_802_11_KEY_MATERIAL,
  1009. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1010. encrypt_key);
  1011. return ret;
  1012. }
  1013. /*
  1014. * IOCTL request handler to set/get network keys.
  1015. *
  1016. * This is a generic key handling function which supports WEP, WPA
  1017. * and WAPI.
  1018. */
  1019. static int
  1020. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  1021. struct mwifiex_ds_encrypt_key *encrypt_key)
  1022. {
  1023. int status;
  1024. if (encrypt_key->is_wapi_key)
  1025. status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
  1026. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  1027. status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
  1028. else
  1029. status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
  1030. return status;
  1031. }
  1032. /*
  1033. * This function returns the driver version.
  1034. */
  1035. int
  1036. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  1037. int max_len)
  1038. {
  1039. union {
  1040. u32 l;
  1041. u8 c[4];
  1042. } ver;
  1043. char fw_ver[32];
  1044. ver.l = adapter->fw_release_number;
  1045. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1046. snprintf(version, max_len, driver_version, fw_ver);
  1047. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  1048. return 0;
  1049. }
  1050. /*
  1051. * Sends IOCTL request to get signal information.
  1052. *
  1053. * This function allocates the IOCTL request buffer, fills it
  1054. * with requisite parameters and calls the IOCTL handler.
  1055. */
  1056. int mwifiex_get_signal_info(struct mwifiex_private *priv,
  1057. struct mwifiex_ds_get_signal *signal)
  1058. {
  1059. int status;
  1060. signal->selector = ALL_RSSI_INFO_MASK;
  1061. /* Signal info can be obtained only if connected */
  1062. if (!priv->media_connected) {
  1063. dev_dbg(priv->adapter->dev,
  1064. "info: Can not get signal in disconnected state\n");
  1065. return -1;
  1066. }
  1067. status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
  1068. HostCmd_ACT_GEN_GET, 0, signal);
  1069. if (!status) {
  1070. if (signal->selector & BCN_RSSI_AVG_MASK)
  1071. priv->qual_level = signal->bcn_rssi_avg;
  1072. if (signal->selector & BCN_NF_AVG_MASK)
  1073. priv->qual_noise = signal->bcn_nf_avg;
  1074. }
  1075. return status;
  1076. }
  1077. /*
  1078. * Sends IOCTL request to set encoding parameters.
  1079. *
  1080. * This function allocates the IOCTL request buffer, fills it
  1081. * with requisite parameters and calls the IOCTL handler.
  1082. */
  1083. int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
  1084. int key_len, u8 key_index, int disable)
  1085. {
  1086. struct mwifiex_ds_encrypt_key encrypt_key;
  1087. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  1088. encrypt_key.key_len = key_len;
  1089. if (!disable) {
  1090. encrypt_key.key_index = key_index;
  1091. if (key_len)
  1092. memcpy(encrypt_key.key_material, key, key_len);
  1093. } else {
  1094. encrypt_key.key_disable = true;
  1095. }
  1096. return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
  1097. }
  1098. /*
  1099. * Sends IOCTL request to get extended version.
  1100. *
  1101. * This function allocates the IOCTL request buffer, fills it
  1102. * with requisite parameters and calls the IOCTL handler.
  1103. */
  1104. int
  1105. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  1106. {
  1107. struct mwifiex_ver_ext ver_ext;
  1108. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  1109. if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
  1110. HostCmd_ACT_GEN_GET, 0, &ver_ext))
  1111. return -1;
  1112. return 0;
  1113. }
  1114. /*
  1115. * Sends IOCTL request to get statistics information.
  1116. *
  1117. * This function allocates the IOCTL request buffer, fills it
  1118. * with requisite parameters and calls the IOCTL handler.
  1119. */
  1120. int
  1121. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1122. struct mwifiex_ds_get_stats *log)
  1123. {
  1124. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
  1125. HostCmd_ACT_GEN_GET, 0, log);
  1126. }
  1127. /*
  1128. * IOCTL request handler to read/write register.
  1129. *
  1130. * This function prepares the correct firmware command and
  1131. * issues it.
  1132. *
  1133. * Access to the following registers are supported -
  1134. * - MAC
  1135. * - BBP
  1136. * - RF
  1137. * - PMIC
  1138. * - CAU
  1139. */
  1140. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1141. struct mwifiex_ds_reg_rw *reg_rw,
  1142. u16 action)
  1143. {
  1144. u16 cmd_no;
  1145. switch (le32_to_cpu(reg_rw->type)) {
  1146. case MWIFIEX_REG_MAC:
  1147. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1148. break;
  1149. case MWIFIEX_REG_BBP:
  1150. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1151. break;
  1152. case MWIFIEX_REG_RF:
  1153. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1154. break;
  1155. case MWIFIEX_REG_PMIC:
  1156. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1157. break;
  1158. case MWIFIEX_REG_CAU:
  1159. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1160. break;
  1161. default:
  1162. return -1;
  1163. }
  1164. return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
  1165. }
  1166. /*
  1167. * Sends IOCTL request to write to a register.
  1168. *
  1169. * This function allocates the IOCTL request buffer, fills it
  1170. * with requisite parameters and calls the IOCTL handler.
  1171. */
  1172. int
  1173. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1174. u32 reg_offset, u32 reg_value)
  1175. {
  1176. struct mwifiex_ds_reg_rw reg_rw;
  1177. reg_rw.type = cpu_to_le32(reg_type);
  1178. reg_rw.offset = cpu_to_le32(reg_offset);
  1179. reg_rw.value = cpu_to_le32(reg_value);
  1180. return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
  1181. }
  1182. /*
  1183. * Sends IOCTL request to read from a register.
  1184. *
  1185. * This function allocates the IOCTL request buffer, fills it
  1186. * with requisite parameters and calls the IOCTL handler.
  1187. */
  1188. int
  1189. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1190. u32 reg_offset, u32 *value)
  1191. {
  1192. int ret;
  1193. struct mwifiex_ds_reg_rw reg_rw;
  1194. reg_rw.type = cpu_to_le32(reg_type);
  1195. reg_rw.offset = cpu_to_le32(reg_offset);
  1196. ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
  1197. if (ret)
  1198. goto done;
  1199. *value = le32_to_cpu(reg_rw.value);
  1200. done:
  1201. return ret;
  1202. }
  1203. /*
  1204. * Sends IOCTL request to read from EEPROM.
  1205. *
  1206. * This function allocates the IOCTL request buffer, fills it
  1207. * with requisite parameters and calls the IOCTL handler.
  1208. */
  1209. int
  1210. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1211. u8 *value)
  1212. {
  1213. int ret;
  1214. struct mwifiex_ds_read_eeprom rd_eeprom;
  1215. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1216. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1217. /* Send request to firmware */
  1218. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1219. HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
  1220. if (!ret)
  1221. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1222. return ret;
  1223. }
  1224. /*
  1225. * This function sets a generic IE. In addition to generic IE, it can
  1226. * also handle WPA, WPA2 and WAPI IEs.
  1227. */
  1228. static int
  1229. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1230. u16 ie_len)
  1231. {
  1232. int ret = 0;
  1233. struct ieee_types_vendor_header *pvendor_ie;
  1234. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1235. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1236. /* If the passed length is zero, reset the buffer */
  1237. if (!ie_len) {
  1238. priv->gen_ie_buf_len = 0;
  1239. priv->wps.session_enable = false;
  1240. return 0;
  1241. } else if (!ie_data_ptr) {
  1242. return -1;
  1243. }
  1244. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1245. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1246. if (((pvendor_ie->element_id == WLAN_EID_WPA)
  1247. && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
  1248. || (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1249. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1250. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1251. priv->wps.session_enable = false;
  1252. return ret;
  1253. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1254. /* IE is a WAPI IE so call set_wapi function */
  1255. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1256. return ret;
  1257. }
  1258. /*
  1259. * Verify that the passed length is not larger than the
  1260. * available space remaining in the buffer
  1261. */
  1262. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1263. /* Test to see if it is a WPS IE, if so, enable
  1264. * wps session flag
  1265. */
  1266. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1267. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
  1268. && (!memcmp(pvendor_ie->oui, wps_oui,
  1269. sizeof(wps_oui)))) {
  1270. priv->wps.session_enable = true;
  1271. dev_dbg(priv->adapter->dev,
  1272. "info: WPS Session Enabled.\n");
  1273. }
  1274. /* Append the passed data to the end of the
  1275. genIeBuffer */
  1276. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  1277. ie_len);
  1278. /* Increment the stored buffer length by the
  1279. size passed */
  1280. priv->gen_ie_buf_len += ie_len;
  1281. } else {
  1282. /* Passed data does not fit in the remaining
  1283. buffer space */
  1284. ret = -1;
  1285. }
  1286. /* Return 0, or -1 for error case */
  1287. return ret;
  1288. }
  1289. /*
  1290. * IOCTL request handler to set/get generic IE.
  1291. *
  1292. * In addition to various generic IEs, this function can also be
  1293. * used to set the ARP filter.
  1294. */
  1295. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  1296. struct mwifiex_ds_misc_gen_ie *gen_ie,
  1297. u16 action)
  1298. {
  1299. struct mwifiex_adapter *adapter = priv->adapter;
  1300. switch (gen_ie->type) {
  1301. case MWIFIEX_IE_TYPE_GEN_IE:
  1302. if (action == HostCmd_ACT_GEN_GET) {
  1303. gen_ie->len = priv->wpa_ie_len;
  1304. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  1305. } else {
  1306. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  1307. (u16) gen_ie->len);
  1308. }
  1309. break;
  1310. case MWIFIEX_IE_TYPE_ARP_FILTER:
  1311. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  1312. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  1313. adapter->arp_filter_size = 0;
  1314. dev_err(adapter->dev, "invalid ARP filter size\n");
  1315. return -1;
  1316. } else {
  1317. memcpy(adapter->arp_filter, gen_ie->ie_data,
  1318. gen_ie->len);
  1319. adapter->arp_filter_size = gen_ie->len;
  1320. }
  1321. break;
  1322. default:
  1323. dev_err(adapter->dev, "invalid IE type\n");
  1324. return -1;
  1325. }
  1326. return 0;
  1327. }
  1328. /*
  1329. * Sends IOCTL request to set a generic IE.
  1330. *
  1331. * This function allocates the IOCTL request buffer, fills it
  1332. * with requisite parameters and calls the IOCTL handler.
  1333. */
  1334. int
  1335. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  1336. {
  1337. struct mwifiex_ds_misc_gen_ie gen_ie;
  1338. if (ie_len > IEEE_MAX_IE_SIZE)
  1339. return -EFAULT;
  1340. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  1341. gen_ie.len = ie_len;
  1342. memcpy(gen_ie.ie_data, ie, ie_len);
  1343. if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
  1344. return -EFAULT;
  1345. return 0;
  1346. }