sta_ioctl.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  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. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  131. * In both Ad-Hoc and infra mode, an deauthentication is performed
  132. * first.
  133. */
  134. int mwifiex_bss_start(struct mwifiex_private *priv,
  135. struct mwifiex_ssid_bssid *ssid_bssid)
  136. {
  137. int ret;
  138. struct mwifiex_adapter *adapter = priv->adapter;
  139. s32 i = -1;
  140. priv->scan_block = false;
  141. if (!ssid_bssid)
  142. return -1;
  143. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  144. /* Infra mode */
  145. ret = mwifiex_deauthenticate(priv, NULL);
  146. if (ret)
  147. return ret;
  148. /* Search for the requested SSID in the scan table */
  149. if (ssid_bssid->ssid.ssid_len)
  150. i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid,
  151. NULL, NL80211_IFTYPE_STATION);
  152. else
  153. i = mwifiex_find_bssid_in_list(priv,
  154. (u8 *) &ssid_bssid->bssid,
  155. NL80211_IFTYPE_STATION);
  156. if (i < 0)
  157. return -1;
  158. dev_dbg(adapter->dev,
  159. "info: SSID found in scan list ... associating...\n");
  160. /* Clear any past association response stored for
  161. * application retrieval */
  162. priv->assoc_rsp_size = 0;
  163. ret = mwifiex_associate(priv, &adapter->scan_table[i]);
  164. if (ret)
  165. return ret;
  166. } else {
  167. /* Adhoc mode */
  168. /* If the requested SSID matches current SSID, return */
  169. if (ssid_bssid->ssid.ssid_len &&
  170. (!mwifiex_ssid_cmp
  171. (&priv->curr_bss_params.bss_descriptor.ssid,
  172. &ssid_bssid->ssid)))
  173. return 0;
  174. /* Exit Adhoc mode first */
  175. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  176. ret = mwifiex_deauthenticate(priv, NULL);
  177. if (ret)
  178. return ret;
  179. priv->adhoc_is_link_sensed = false;
  180. /* Search for the requested network in the scan table */
  181. if (ssid_bssid->ssid.ssid_len)
  182. i = mwifiex_find_ssid_in_list(priv,
  183. &ssid_bssid->ssid, NULL,
  184. NL80211_IFTYPE_ADHOC);
  185. else
  186. i = mwifiex_find_bssid_in_list(priv,
  187. (u8 *)&ssid_bssid->bssid,
  188. NL80211_IFTYPE_ADHOC);
  189. if (i >= 0) {
  190. dev_dbg(adapter->dev, "info: network found in scan"
  191. " list. Joining...\n");
  192. ret = mwifiex_adhoc_join(priv, &adapter->scan_table[i]);
  193. if (ret)
  194. return ret;
  195. } else {
  196. dev_dbg(adapter->dev, "info: Network not found in "
  197. "the list, creating adhoc with ssid = %s\n",
  198. ssid_bssid->ssid.ssid);
  199. ret = mwifiex_adhoc_start(priv, &ssid_bssid->ssid);
  200. if (ret)
  201. return ret;
  202. }
  203. }
  204. return ret;
  205. }
  206. /*
  207. * IOCTL request handler to set host sleep configuration.
  208. *
  209. * This function prepares the correct firmware command and
  210. * issues it.
  211. */
  212. int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  213. int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
  214. {
  215. struct mwifiex_adapter *adapter = priv->adapter;
  216. int status = 0;
  217. u32 prev_cond = 0;
  218. if (!hs_cfg)
  219. return -ENOMEM;
  220. switch (action) {
  221. case HostCmd_ACT_GEN_SET:
  222. if (adapter->pps_uapsd_mode) {
  223. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  224. " is blocked in UAPSD/PPS mode\n");
  225. status = -1;
  226. break;
  227. }
  228. if (hs_cfg->is_invoke_hostcmd) {
  229. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
  230. if (!adapter->is_hs_configured)
  231. /* Already cancelled */
  232. break;
  233. /* Save previous condition */
  234. prev_cond = le32_to_cpu(adapter->hs_cfg
  235. .conditions);
  236. adapter->hs_cfg.conditions =
  237. cpu_to_le32(hs_cfg->conditions);
  238. } else if (hs_cfg->conditions) {
  239. adapter->hs_cfg.conditions =
  240. cpu_to_le32(hs_cfg->conditions);
  241. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  242. if (hs_cfg->gap)
  243. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  244. } else if (adapter->hs_cfg.conditions ==
  245. cpu_to_le32(
  246. HOST_SLEEP_CFG_CANCEL)) {
  247. /* Return failure if no parameters for HS
  248. enable */
  249. status = -1;
  250. break;
  251. }
  252. if (cmd_type == MWIFIEX_SYNC_CMD)
  253. status = mwifiex_send_cmd_sync(priv,
  254. HostCmd_CMD_802_11_HS_CFG_ENH,
  255. HostCmd_ACT_GEN_SET, 0,
  256. &adapter->hs_cfg);
  257. else
  258. status = mwifiex_send_cmd_async(priv,
  259. HostCmd_CMD_802_11_HS_CFG_ENH,
  260. HostCmd_ACT_GEN_SET, 0,
  261. &adapter->hs_cfg);
  262. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
  263. /* Restore previous condition */
  264. adapter->hs_cfg.conditions =
  265. cpu_to_le32(prev_cond);
  266. } else {
  267. adapter->hs_cfg.conditions =
  268. cpu_to_le32(hs_cfg->conditions);
  269. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  270. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  271. }
  272. break;
  273. case HostCmd_ACT_GEN_GET:
  274. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  275. hs_cfg->gpio = adapter->hs_cfg.gpio;
  276. hs_cfg->gap = adapter->hs_cfg.gap;
  277. break;
  278. default:
  279. status = -1;
  280. break;
  281. }
  282. return status;
  283. }
  284. /*
  285. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  286. *
  287. * This function allocates the IOCTL request buffer, fills it
  288. * with requisite parameters and calls the IOCTL handler.
  289. */
  290. int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
  291. {
  292. struct mwifiex_ds_hs_cfg hscfg;
  293. hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
  294. hscfg.is_invoke_hostcmd = true;
  295. return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  296. cmd_type, &hscfg);
  297. }
  298. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  299. /*
  300. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  301. *
  302. * This function allocates the IOCTL request buffer, fills it
  303. * with requisite parameters and calls the IOCTL handler.
  304. */
  305. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  306. {
  307. struct mwifiex_ds_hs_cfg hscfg;
  308. if (adapter->hs_activated) {
  309. dev_dbg(adapter->dev, "cmd: HS Already actived\n");
  310. return true;
  311. }
  312. adapter->hs_activate_wait_q_woken = false;
  313. memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
  314. hscfg.is_invoke_hostcmd = true;
  315. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  316. MWIFIEX_BSS_ROLE_STA),
  317. HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
  318. &hscfg)) {
  319. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  320. return false;
  321. }
  322. wait_event_interruptible(adapter->hs_activate_wait_q,
  323. adapter->hs_activate_wait_q_woken);
  324. return true;
  325. }
  326. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  327. /*
  328. * IOCTL request handler to get BSS information.
  329. *
  330. * This function collates the information from different driver structures
  331. * to send to the user.
  332. */
  333. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  334. struct mwifiex_bss_info *info)
  335. {
  336. struct mwifiex_adapter *adapter = priv->adapter;
  337. struct mwifiex_bssdescriptor *bss_desc;
  338. s32 tbl_idx;
  339. if (!info)
  340. return -1;
  341. bss_desc = &priv->curr_bss_params.bss_descriptor;
  342. info->bss_mode = priv->bss_mode;
  343. memcpy(&info->ssid, &bss_desc->ssid,
  344. sizeof(struct mwifiex_802_11_ssid));
  345. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  346. info->bss_chan = bss_desc->channel;
  347. info->region_code = adapter->region_code;
  348. /* Scan table index if connected */
  349. info->scan_table_idx = 0;
  350. if (priv->media_connected) {
  351. tbl_idx =
  352. mwifiex_find_ssid_in_list(priv, &bss_desc->ssid,
  353. bss_desc->mac_address,
  354. priv->bss_mode);
  355. if (tbl_idx >= 0)
  356. info->scan_table_idx = tbl_idx;
  357. }
  358. info->media_connected = priv->media_connected;
  359. info->max_power_level = priv->max_tx_power_level;
  360. info->min_power_level = priv->min_tx_power_level;
  361. info->adhoc_state = priv->adhoc_state;
  362. info->bcn_nf_last = priv->bcn_nf_last;
  363. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  364. info->wep_status = true;
  365. else
  366. info->wep_status = false;
  367. info->is_hs_configured = adapter->is_hs_configured;
  368. info->is_deep_sleep = adapter->is_deep_sleep;
  369. return 0;
  370. }
  371. /*
  372. * The function sets band configurations.
  373. *
  374. * it performs extra checks to make sure the Ad-Hoc
  375. * band and channel are compatible. Otherwise it returns an error.
  376. *
  377. */
  378. int mwifiex_set_radio_band_cfg(struct mwifiex_private *priv,
  379. struct mwifiex_ds_band_cfg *radio_cfg)
  380. {
  381. struct mwifiex_adapter *adapter = priv->adapter;
  382. u8 infra_band, adhoc_band;
  383. u32 adhoc_channel;
  384. infra_band = (u8) radio_cfg->config_bands;
  385. adhoc_band = (u8) radio_cfg->adhoc_start_band;
  386. adhoc_channel = radio_cfg->adhoc_channel;
  387. /* SET Infra band */
  388. if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
  389. return -1;
  390. adapter->config_bands = infra_band;
  391. /* SET Ad-hoc Band */
  392. if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
  393. return -1;
  394. if (adhoc_band)
  395. adapter->adhoc_start_band = adhoc_band;
  396. adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
  397. /*
  398. * If no adhoc_channel is supplied verify if the existing adhoc
  399. * channel compiles with new adhoc_band
  400. */
  401. if (!adhoc_channel) {
  402. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  403. (priv, adapter->adhoc_start_band,
  404. priv->adhoc_channel)) {
  405. /* Pass back the default channel */
  406. radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  407. if ((adapter->adhoc_start_band & BAND_A)
  408. || (adapter->adhoc_start_band & BAND_AN))
  409. radio_cfg->adhoc_channel =
  410. DEFAULT_AD_HOC_CHANNEL_A;
  411. }
  412. } else { /* Retrurn error if adhoc_band and
  413. adhoc_channel combination is invalid */
  414. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  415. (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
  416. return -1;
  417. priv->adhoc_channel = (u8) adhoc_channel;
  418. }
  419. if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
  420. adapter->adhoc_11n_enabled = true;
  421. else
  422. adapter->adhoc_11n_enabled = false;
  423. return 0;
  424. }
  425. /*
  426. * The function disables auto deep sleep mode.
  427. */
  428. int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
  429. {
  430. struct mwifiex_ds_auto_ds auto_ds;
  431. auto_ds.auto_ds = DEEP_SLEEP_OFF;
  432. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  433. DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
  434. }
  435. EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
  436. /*
  437. * IOCTL request handler to set/get active channel.
  438. *
  439. * This function performs validity checking on channel/frequency
  440. * compatibility and returns failure if not valid.
  441. */
  442. int mwifiex_bss_set_channel(struct mwifiex_private *priv,
  443. struct mwifiex_chan_freq_power *chan)
  444. {
  445. struct mwifiex_adapter *adapter = priv->adapter;
  446. struct mwifiex_chan_freq_power *cfp = NULL;
  447. if (!chan)
  448. return -1;
  449. if (!chan->channel && !chan->freq)
  450. return -1;
  451. if (adapter->adhoc_start_band & BAND_AN)
  452. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  453. else if (adapter->adhoc_start_band & BAND_A)
  454. adapter->adhoc_start_band = BAND_G | BAND_B;
  455. if (chan->channel) {
  456. if (chan->channel <= MAX_CHANNEL_BAND_BG)
  457. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  458. (priv, 0, (u16) chan->channel);
  459. if (!cfp) {
  460. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  461. (priv, BAND_A, (u16) chan->channel);
  462. if (cfp) {
  463. if (adapter->adhoc_11n_enabled)
  464. adapter->adhoc_start_band = BAND_A
  465. | BAND_AN;
  466. else
  467. adapter->adhoc_start_band = BAND_A;
  468. }
  469. }
  470. } else {
  471. if (chan->freq <= MAX_FREQUENCY_BAND_BG)
  472. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
  473. priv, 0, chan->freq);
  474. if (!cfp) {
  475. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
  476. (priv, BAND_A, chan->freq);
  477. if (cfp) {
  478. if (adapter->adhoc_11n_enabled)
  479. adapter->adhoc_start_band = BAND_A
  480. | BAND_AN;
  481. else
  482. adapter->adhoc_start_band = BAND_A;
  483. }
  484. }
  485. }
  486. if (!cfp || !cfp->channel) {
  487. dev_err(adapter->dev, "invalid channel/freq\n");
  488. return -1;
  489. }
  490. priv->adhoc_channel = (u8) cfp->channel;
  491. chan->channel = cfp->channel;
  492. chan->freq = cfp->freq;
  493. return 0;
  494. }
  495. /*
  496. * IOCTL request handler to set/get Ad-Hoc channel.
  497. *
  498. * This function prepares the correct firmware command and
  499. * issues it to set or get the ad-hoc channel.
  500. */
  501. static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
  502. u16 action, u16 *channel)
  503. {
  504. if (action == HostCmd_ACT_GEN_GET) {
  505. if (!priv->media_connected) {
  506. *channel = priv->adhoc_channel;
  507. return 0;
  508. }
  509. } else {
  510. priv->adhoc_channel = (u8) *channel;
  511. }
  512. return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
  513. action, 0, channel);
  514. }
  515. /*
  516. * IOCTL request handler to find a particular BSS.
  517. *
  518. * The BSS can be searched with either a BSSID or a SSID. If none of
  519. * these are provided, just the best BSS (best RSSI) is returned.
  520. */
  521. int mwifiex_bss_ioctl_find_bss(struct mwifiex_private *priv,
  522. struct mwifiex_ssid_bssid *ssid_bssid)
  523. {
  524. struct mwifiex_adapter *adapter = priv->adapter;
  525. struct mwifiex_bssdescriptor *bss_desc;
  526. u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  527. u8 mac[ETH_ALEN];
  528. int i = 0;
  529. if (memcmp(ssid_bssid->bssid, zero_mac, sizeof(zero_mac))) {
  530. i = mwifiex_find_bssid_in_list(priv,
  531. (u8 *) ssid_bssid->bssid,
  532. priv->bss_mode);
  533. if (i < 0) {
  534. memcpy(mac, ssid_bssid->bssid, sizeof(mac));
  535. dev_err(adapter->dev, "cannot find bssid %pM\n", mac);
  536. return -1;
  537. }
  538. bss_desc = &adapter->scan_table[i];
  539. memcpy(&ssid_bssid->ssid, &bss_desc->ssid,
  540. sizeof(struct mwifiex_802_11_ssid));
  541. } else if (ssid_bssid->ssid.ssid_len) {
  542. i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid, NULL,
  543. priv->bss_mode);
  544. if (i < 0) {
  545. dev_err(adapter->dev, "cannot find ssid %s\n",
  546. ssid_bssid->ssid.ssid);
  547. return -1;
  548. }
  549. bss_desc = &adapter->scan_table[i];
  550. memcpy(ssid_bssid->bssid, bss_desc->mac_address, ETH_ALEN);
  551. } else {
  552. return mwifiex_find_best_network(priv, ssid_bssid);
  553. }
  554. return 0;
  555. }
  556. /*
  557. * IOCTL request handler to change Ad-Hoc channel.
  558. *
  559. * This function allocates the IOCTL request buffer, fills it
  560. * with requisite parameters and calls the IOCTL handler.
  561. *
  562. * The function follows the following steps to perform the change -
  563. * - Get current IBSS information
  564. * - Get current channel
  565. * - If no change is required, return
  566. * - If not connected, change channel and return
  567. * - If connected,
  568. * - Disconnect
  569. * - Change channel
  570. * - Perform specific SSID scan with same SSID
  571. * - Start/Join the IBSS
  572. */
  573. int
  574. mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
  575. {
  576. int ret;
  577. struct mwifiex_bss_info bss_info;
  578. struct mwifiex_ssid_bssid ssid_bssid;
  579. u16 curr_chan = 0;
  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. /* Start/Join Adhoc network */
  608. memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
  609. memcpy(&ssid_bssid.ssid, &bss_info.ssid,
  610. sizeof(struct mwifiex_802_11_ssid));
  611. ret = mwifiex_bss_start(priv, &ssid_bssid);
  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->w_stats.qual.level = signal->bcn_rssi_avg;
  1144. if (signal->selector & BCN_NF_AVG_MASK)
  1145. priv->w_stats.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. int ret;
  1197. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
  1198. HostCmd_ACT_GEN_GET, 0, log);
  1199. if (!ret) {
  1200. priv->w_stats.discard.fragment = log->fcs_error;
  1201. priv->w_stats.discard.retries = log->retry;
  1202. priv->w_stats.discard.misc = log->ack_failure;
  1203. }
  1204. return ret;
  1205. }
  1206. /*
  1207. * IOCTL request handler to read/write register.
  1208. *
  1209. * This function prepares the correct firmware command and
  1210. * issues it.
  1211. *
  1212. * Access to the following registers are supported -
  1213. * - MAC
  1214. * - BBP
  1215. * - RF
  1216. * - PMIC
  1217. * - CAU
  1218. */
  1219. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1220. struct mwifiex_ds_reg_rw *reg_rw,
  1221. u16 action)
  1222. {
  1223. u16 cmd_no;
  1224. switch (le32_to_cpu(reg_rw->type)) {
  1225. case MWIFIEX_REG_MAC:
  1226. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1227. break;
  1228. case MWIFIEX_REG_BBP:
  1229. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1230. break;
  1231. case MWIFIEX_REG_RF:
  1232. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1233. break;
  1234. case MWIFIEX_REG_PMIC:
  1235. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1236. break;
  1237. case MWIFIEX_REG_CAU:
  1238. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1239. break;
  1240. default:
  1241. return -1;
  1242. }
  1243. return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
  1244. }
  1245. /*
  1246. * Sends IOCTL request to write to a register.
  1247. *
  1248. * This function allocates the IOCTL request buffer, fills it
  1249. * with requisite parameters and calls the IOCTL handler.
  1250. */
  1251. int
  1252. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1253. u32 reg_offset, u32 reg_value)
  1254. {
  1255. struct mwifiex_ds_reg_rw reg_rw;
  1256. reg_rw.type = cpu_to_le32(reg_type);
  1257. reg_rw.offset = cpu_to_le32(reg_offset);
  1258. reg_rw.value = cpu_to_le32(reg_value);
  1259. return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
  1260. }
  1261. /*
  1262. * Sends IOCTL request to read from a register.
  1263. *
  1264. * This function allocates the IOCTL request buffer, fills it
  1265. * with requisite parameters and calls the IOCTL handler.
  1266. */
  1267. int
  1268. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1269. u32 reg_offset, u32 *value)
  1270. {
  1271. int ret;
  1272. struct mwifiex_ds_reg_rw reg_rw;
  1273. reg_rw.type = cpu_to_le32(reg_type);
  1274. reg_rw.offset = cpu_to_le32(reg_offset);
  1275. ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
  1276. if (ret)
  1277. goto done;
  1278. *value = le32_to_cpu(reg_rw.value);
  1279. done:
  1280. return ret;
  1281. }
  1282. /*
  1283. * Sends IOCTL request to read from EEPROM.
  1284. *
  1285. * This function allocates the IOCTL request buffer, fills it
  1286. * with requisite parameters and calls the IOCTL handler.
  1287. */
  1288. int
  1289. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  1290. u8 *value)
  1291. {
  1292. int ret;
  1293. struct mwifiex_ds_read_eeprom rd_eeprom;
  1294. rd_eeprom.offset = cpu_to_le16((u16) offset);
  1295. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  1296. /* Send request to firmware */
  1297. ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1298. HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
  1299. if (!ret)
  1300. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  1301. return ret;
  1302. }
  1303. /*
  1304. * This function sets a generic IE. In addition to generic IE, it can
  1305. * also handle WPA, WPA2 and WAPI IEs.
  1306. */
  1307. static int
  1308. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  1309. u16 ie_len)
  1310. {
  1311. int ret = 0;
  1312. struct ieee_types_vendor_header *pvendor_ie;
  1313. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  1314. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  1315. /* If the passed length is zero, reset the buffer */
  1316. if (!ie_len) {
  1317. priv->gen_ie_buf_len = 0;
  1318. priv->wps.session_enable = false;
  1319. return 0;
  1320. } else if (!ie_data_ptr) {
  1321. return -1;
  1322. }
  1323. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1324. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  1325. if (((pvendor_ie->element_id == WLAN_EID_WPA)
  1326. && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
  1327. || (pvendor_ie->element_id == WLAN_EID_RSN)) {
  1328. /* IE is a WPA/WPA2 IE so call set_wpa function */
  1329. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  1330. priv->wps.session_enable = false;
  1331. return ret;
  1332. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  1333. /* IE is a WAPI IE so call set_wapi function */
  1334. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  1335. return ret;
  1336. }
  1337. /*
  1338. * Verify that the passed length is not larger than the
  1339. * available space remaining in the buffer
  1340. */
  1341. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  1342. /* Test to see if it is a WPS IE, if so, enable
  1343. * wps session flag
  1344. */
  1345. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  1346. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
  1347. && (!memcmp(pvendor_ie->oui, wps_oui,
  1348. sizeof(wps_oui)))) {
  1349. priv->wps.session_enable = true;
  1350. dev_dbg(priv->adapter->dev,
  1351. "info: WPS Session Enabled.\n");
  1352. }
  1353. /* Append the passed data to the end of the
  1354. genIeBuffer */
  1355. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  1356. ie_len);
  1357. /* Increment the stored buffer length by the
  1358. size passed */
  1359. priv->gen_ie_buf_len += ie_len;
  1360. } else {
  1361. /* Passed data does not fit in the remaining
  1362. buffer space */
  1363. ret = -1;
  1364. }
  1365. /* Return 0, or -1 for error case */
  1366. return ret;
  1367. }
  1368. /*
  1369. * IOCTL request handler to set/get generic IE.
  1370. *
  1371. * In addition to various generic IEs, this function can also be
  1372. * used to set the ARP filter.
  1373. */
  1374. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  1375. struct mwifiex_ds_misc_gen_ie *gen_ie,
  1376. u16 action)
  1377. {
  1378. struct mwifiex_adapter *adapter = priv->adapter;
  1379. switch (gen_ie->type) {
  1380. case MWIFIEX_IE_TYPE_GEN_IE:
  1381. if (action == HostCmd_ACT_GEN_GET) {
  1382. gen_ie->len = priv->wpa_ie_len;
  1383. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  1384. } else {
  1385. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  1386. (u16) gen_ie->len);
  1387. }
  1388. break;
  1389. case MWIFIEX_IE_TYPE_ARP_FILTER:
  1390. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  1391. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  1392. adapter->arp_filter_size = 0;
  1393. dev_err(adapter->dev, "invalid ARP filter size\n");
  1394. return -1;
  1395. } else {
  1396. memcpy(adapter->arp_filter, gen_ie->ie_data,
  1397. gen_ie->len);
  1398. adapter->arp_filter_size = gen_ie->len;
  1399. }
  1400. break;
  1401. default:
  1402. dev_err(adapter->dev, "invalid IE type\n");
  1403. return -1;
  1404. }
  1405. return 0;
  1406. }
  1407. /*
  1408. * Sends IOCTL request to set a generic IE.
  1409. *
  1410. * This function allocates the IOCTL request buffer, fills it
  1411. * with requisite parameters and calls the IOCTL handler.
  1412. */
  1413. int
  1414. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  1415. {
  1416. struct mwifiex_ds_misc_gen_ie gen_ie;
  1417. if (ie_len > IW_CUSTOM_MAX)
  1418. return -EFAULT;
  1419. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  1420. gen_ie.len = ie_len;
  1421. memcpy(gen_ie.ie_data, ie, ie_len);
  1422. if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
  1423. return -EFAULT;
  1424. return 0;
  1425. }