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