sta_ioctl.c 37 KB

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