sta_ioctl.c 42 KB

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