sta_ioctl.c 37 KB

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