sta_ioctl.c 43 KB

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