sta_ioctl.c 37 KB

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