sta_ioctl.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434
  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. static int
  35. mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
  36. struct net_device *dev)
  37. {
  38. int i = 0;
  39. struct netdev_hw_addr *ha;
  40. netdev_for_each_mc_addr(ha, dev)
  41. memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
  42. return i;
  43. }
  44. /*
  45. * Allocate and fills a wait queue with proper parameters.
  46. *
  47. * This function needs to be called before an IOCTL request can be made.
  48. * It can handle the following wait options:
  49. * MWIFIEX_NO_WAIT - Waiting is disabled
  50. * MWIFIEX_IOCTL_WAIT - Waiting is done on IOCTL wait queue
  51. * MWIFIEX_CMD_WAIT - Waiting is done on command wait queue
  52. * MWIFIEX_WSTATS_WAIT - Waiting is done on stats wait queue
  53. */
  54. struct mwifiex_wait_queue *
  55. mwifiex_alloc_fill_wait_queue(struct mwifiex_private *priv,
  56. u8 wait_option)
  57. {
  58. struct mwifiex_wait_queue *wait = NULL;
  59. wait = (struct mwifiex_wait_queue *)
  60. kzalloc(sizeof(struct mwifiex_wait_queue), GFP_ATOMIC);
  61. if (!wait) {
  62. dev_err(priv->adapter->dev, "%s: fail to alloc buffer\n",
  63. __func__);
  64. return wait;
  65. }
  66. wait->bss_index = priv->bss_index;
  67. switch (wait_option) {
  68. case MWIFIEX_NO_WAIT:
  69. wait->enabled = 0;
  70. break;
  71. case MWIFIEX_IOCTL_WAIT:
  72. priv->ioctl_wait_q_woken = false;
  73. wait->start_time = jiffies;
  74. wait->wait = &priv->ioctl_wait_q;
  75. wait->condition = &priv->ioctl_wait_q_woken;
  76. wait->enabled = 1;
  77. break;
  78. case MWIFIEX_CMD_WAIT:
  79. priv->cmd_wait_q_woken = false;
  80. wait->start_time = jiffies;
  81. wait->wait = &priv->cmd_wait_q;
  82. wait->condition = &priv->cmd_wait_q_woken;
  83. wait->enabled = 1;
  84. break;
  85. case MWIFIEX_WSTATS_WAIT:
  86. priv->w_stats_wait_q_woken = false;
  87. wait->start_time = jiffies;
  88. wait->wait = &priv->w_stats_wait_q;
  89. wait->condition = &priv->w_stats_wait_q_woken;
  90. wait->enabled = 1;
  91. break;
  92. }
  93. return wait;
  94. }
  95. /*
  96. * Wait queue completion handler.
  97. *
  98. * This function waits on a particular wait queue.
  99. * For NO_WAIT option, it returns immediately. It also cancels the
  100. * pending IOCTL request after waking up, in case of errors.
  101. */
  102. static void
  103. mwifiex_wait_ioctl_complete(struct mwifiex_private *priv,
  104. struct mwifiex_wait_queue *wait,
  105. u8 wait_option)
  106. {
  107. bool cancel_flag = false;
  108. switch (wait_option) {
  109. case MWIFIEX_NO_WAIT:
  110. break;
  111. case MWIFIEX_IOCTL_WAIT:
  112. wait_event_interruptible(priv->ioctl_wait_q,
  113. priv->ioctl_wait_q_woken);
  114. if (!priv->ioctl_wait_q_woken)
  115. cancel_flag = true;
  116. break;
  117. case MWIFIEX_CMD_WAIT:
  118. wait_event_interruptible(priv->cmd_wait_q,
  119. priv->cmd_wait_q_woken);
  120. if (!priv->cmd_wait_q_woken)
  121. cancel_flag = true;
  122. break;
  123. case MWIFIEX_WSTATS_WAIT:
  124. wait_event_interruptible(priv->w_stats_wait_q,
  125. priv->w_stats_wait_q_woken);
  126. if (!priv->w_stats_wait_q_woken)
  127. cancel_flag = true;
  128. break;
  129. }
  130. if (cancel_flag) {
  131. mwifiex_cancel_pending_ioctl(priv->adapter, wait);
  132. dev_dbg(priv->adapter->dev, "cmd: IOCTL cancel: wait=%p, wait_option=%d\n",
  133. wait, wait_option);
  134. }
  135. return;
  136. }
  137. /*
  138. * The function waits for the request to complete and issues the
  139. * completion handler, if required.
  140. */
  141. int mwifiex_request_ioctl(struct mwifiex_private *priv,
  142. struct mwifiex_wait_queue *wait,
  143. int status, u8 wait_option)
  144. {
  145. switch (status) {
  146. case -EINPROGRESS:
  147. dev_dbg(priv->adapter->dev, "cmd: IOCTL pending: wait=%p, wait_option=%d\n",
  148. wait, wait_option);
  149. atomic_inc(&priv->adapter->ioctl_pending);
  150. /* Status pending, wake up main process */
  151. queue_work(priv->adapter->workqueue, &priv->adapter->main_work);
  152. /* Wait for completion */
  153. if (wait_option) {
  154. mwifiex_wait_ioctl_complete(priv, wait, wait_option);
  155. status = wait->status;
  156. }
  157. break;
  158. case 0:
  159. case -1:
  160. case -EBUSY:
  161. default:
  162. break;
  163. }
  164. return status;
  165. }
  166. EXPORT_SYMBOL_GPL(mwifiex_request_ioctl);
  167. /*
  168. * IOCTL request handler to set/get MAC address.
  169. *
  170. * This function prepares the correct firmware command and
  171. * issues it to get the extended version information.
  172. */
  173. static int mwifiex_bss_ioctl_mac_address(struct mwifiex_private *priv,
  174. struct mwifiex_wait_queue *wait,
  175. u8 action, u8 *mac)
  176. {
  177. int ret = 0;
  178. if ((action == HostCmd_ACT_GEN_GET) && mac) {
  179. memcpy(mac, priv->curr_addr, ETH_ALEN);
  180. return 0;
  181. }
  182. /* Send request to firmware */
  183. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
  184. action, 0, wait, mac);
  185. if (!ret)
  186. ret = -EINPROGRESS;
  187. return ret;
  188. }
  189. /*
  190. * Sends IOCTL request to set MAC address.
  191. *
  192. * This function allocates the IOCTL request buffer, fills it
  193. * with requisite parameters and calls the IOCTL handler.
  194. */
  195. int mwifiex_request_set_mac_address(struct mwifiex_private *priv)
  196. {
  197. struct mwifiex_wait_queue *wait = NULL;
  198. int status = 0;
  199. u8 wait_option = MWIFIEX_CMD_WAIT;
  200. /* Allocate wait buffer */
  201. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  202. if (!wait)
  203. return -ENOMEM;
  204. status = mwifiex_bss_ioctl_mac_address(priv, wait, HostCmd_ACT_GEN_SET,
  205. NULL);
  206. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  207. if (!status)
  208. memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
  209. else
  210. dev_err(priv->adapter->dev, "set mac address failed: status=%d"
  211. " error_code=%#x\n", status, wait->status);
  212. kfree(wait);
  213. return status;
  214. }
  215. /*
  216. * IOCTL request handler to set multicast list.
  217. *
  218. * This function prepares the correct firmware command and
  219. * issues it to set the multicast list.
  220. *
  221. * This function can be used to enable promiscuous mode, or enable all
  222. * multicast packets, or to enable selective multicast.
  223. */
  224. static int
  225. mwifiex_bss_ioctl_multicast_list(struct mwifiex_private *priv,
  226. struct mwifiex_wait_queue *wait,
  227. u16 action,
  228. struct mwifiex_multicast_list *mcast_list)
  229. {
  230. int ret = 0;
  231. u16 old_pkt_filter;
  232. old_pkt_filter = priv->curr_pkt_filter;
  233. if (action == HostCmd_ACT_GEN_GET)
  234. return -1;
  235. if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
  236. dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
  237. priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  238. priv->curr_pkt_filter &=
  239. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  240. } else {
  241. /* Multicast */
  242. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
  243. if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
  244. dev_dbg(priv->adapter->dev,
  245. "info: Enabling All Multicast!\n");
  246. priv->curr_pkt_filter |=
  247. HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  248. } else {
  249. priv->curr_pkt_filter &=
  250. ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
  251. if (mcast_list->num_multicast_addr) {
  252. dev_dbg(priv->adapter->dev,
  253. "info: Set multicast list=%d\n",
  254. mcast_list->num_multicast_addr);
  255. /* Set multicast addresses to firmware */
  256. if (old_pkt_filter == priv->curr_pkt_filter) {
  257. /* Send request to firmware */
  258. ret = mwifiex_prepare_cmd(priv,
  259. HostCmd_CMD_MAC_MULTICAST_ADR,
  260. action, 0, wait, mcast_list);
  261. if (!ret)
  262. ret = -EINPROGRESS;
  263. } else {
  264. /* Send request to firmware */
  265. ret = mwifiex_prepare_cmd(priv,
  266. HostCmd_CMD_MAC_MULTICAST_ADR,
  267. action, 0, NULL,
  268. mcast_list);
  269. }
  270. }
  271. }
  272. }
  273. dev_dbg(priv->adapter->dev,
  274. "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
  275. old_pkt_filter, priv->curr_pkt_filter);
  276. if (old_pkt_filter != priv->curr_pkt_filter) {
  277. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL, action,
  278. 0, wait, &priv->curr_pkt_filter);
  279. if (!ret)
  280. ret = -EINPROGRESS;
  281. }
  282. return ret;
  283. }
  284. /*
  285. * Sends IOCTL request to set multicast list.
  286. *
  287. * This function allocates the IOCTL request buffer, fills it
  288. * with requisite parameters and calls the IOCTL handler.
  289. */
  290. void
  291. mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
  292. struct net_device *dev)
  293. {
  294. struct mwifiex_wait_queue *wait = NULL;
  295. struct mwifiex_multicast_list mcast_list;
  296. u8 wait_option = MWIFIEX_NO_WAIT;
  297. int status = 0;
  298. /* Allocate wait buffer */
  299. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  300. if (!wait)
  301. return;
  302. if (dev->flags & IFF_PROMISC) {
  303. mcast_list.mode = MWIFIEX_PROMISC_MODE;
  304. } else if (dev->flags & IFF_ALLMULTI ||
  305. netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
  306. mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
  307. } else {
  308. mcast_list.mode = MWIFIEX_MULTICAST_MODE;
  309. if (netdev_mc_count(dev))
  310. mcast_list.num_multicast_addr =
  311. mwifiex_copy_mcast_addr(&mcast_list, dev);
  312. }
  313. status = mwifiex_bss_ioctl_multicast_list(priv, wait,
  314. HostCmd_ACT_GEN_SET,
  315. &mcast_list);
  316. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  317. if (wait && status != -EINPROGRESS)
  318. kfree(wait);
  319. return;
  320. }
  321. /*
  322. * IOCTL request handler to disconnect from a BSS/IBSS.
  323. */
  324. static int mwifiex_bss_ioctl_stop(struct mwifiex_private *priv,
  325. struct mwifiex_wait_queue *wait, u8 *mac)
  326. {
  327. return mwifiex_deauthenticate(priv, wait, mac);
  328. }
  329. /*
  330. * Sends IOCTL request to disconnect from a BSS.
  331. *
  332. * This function allocates the IOCTL request buffer, fills it
  333. * with requisite parameters and calls the IOCTL handler.
  334. */
  335. int mwifiex_disconnect(struct mwifiex_private *priv, u8 wait_option, u8 *mac)
  336. {
  337. struct mwifiex_wait_queue *wait = NULL;
  338. int status = 0;
  339. /* Allocate wait buffer */
  340. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  341. if (!wait)
  342. return -ENOMEM;
  343. status = mwifiex_bss_ioctl_stop(priv, wait, mac);
  344. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  345. kfree(wait);
  346. return status;
  347. }
  348. EXPORT_SYMBOL_GPL(mwifiex_disconnect);
  349. /*
  350. * IOCTL request handler to join a BSS/IBSS.
  351. *
  352. * In Ad-Hoc mode, the IBSS is created if not found in scan list.
  353. * In both Ad-Hoc and infra mode, an deauthentication is performed
  354. * first.
  355. */
  356. static int mwifiex_bss_ioctl_start(struct mwifiex_private *priv,
  357. struct mwifiex_wait_queue *wait,
  358. struct mwifiex_ssid_bssid *ssid_bssid)
  359. {
  360. int ret = 0;
  361. struct mwifiex_adapter *adapter = priv->adapter;
  362. s32 i = -1;
  363. priv->scan_block = false;
  364. if (!ssid_bssid)
  365. return -1;
  366. if (priv->bss_mode == MWIFIEX_BSS_MODE_INFRA) {
  367. /* Infra mode */
  368. ret = mwifiex_deauthenticate(priv, NULL, NULL);
  369. if (ret)
  370. return ret;
  371. /* Search for the requested SSID in the scan table */
  372. if (ssid_bssid->ssid.ssid_len)
  373. i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid,
  374. NULL, MWIFIEX_BSS_MODE_INFRA);
  375. else
  376. i = mwifiex_find_bssid_in_list(priv,
  377. (u8 *) &ssid_bssid->bssid,
  378. MWIFIEX_BSS_MODE_INFRA);
  379. if (i < 0)
  380. return -1;
  381. dev_dbg(adapter->dev,
  382. "info: SSID found in scan list ... associating...\n");
  383. /* Clear any past association response stored for
  384. * application retrieval */
  385. priv->assoc_rsp_size = 0;
  386. ret = mwifiex_associate(priv, wait, &adapter->scan_table[i]);
  387. if (ret)
  388. return ret;
  389. } else {
  390. /* Adhoc mode */
  391. /* If the requested SSID matches current SSID, return */
  392. if (ssid_bssid->ssid.ssid_len &&
  393. (!mwifiex_ssid_cmp
  394. (&priv->curr_bss_params.bss_descriptor.ssid,
  395. &ssid_bssid->ssid)))
  396. return 0;
  397. /* Exit Adhoc mode first */
  398. dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
  399. ret = mwifiex_deauthenticate(priv, NULL, NULL);
  400. if (ret)
  401. return ret;
  402. priv->adhoc_is_link_sensed = false;
  403. /* Search for the requested network in the scan table */
  404. if (ssid_bssid->ssid.ssid_len)
  405. i = mwifiex_find_ssid_in_list(priv,
  406. &ssid_bssid->ssid, NULL,
  407. MWIFIEX_BSS_MODE_IBSS);
  408. else
  409. i = mwifiex_find_bssid_in_list(priv,
  410. (u8 *)&ssid_bssid->bssid,
  411. MWIFIEX_BSS_MODE_IBSS);
  412. if (i >= 0) {
  413. dev_dbg(adapter->dev, "info: network found in scan"
  414. " list. Joining...\n");
  415. ret = mwifiex_adhoc_join(priv, wait,
  416. &adapter->scan_table[i]);
  417. if (ret)
  418. return ret;
  419. } else { /* i >= 0 */
  420. dev_dbg(adapter->dev, "info: Network not found in "
  421. "the list, creating adhoc with ssid = %s\n",
  422. ssid_bssid->ssid.ssid);
  423. ret = mwifiex_adhoc_start(priv, wait,
  424. &ssid_bssid->ssid);
  425. if (ret)
  426. return ret;
  427. }
  428. }
  429. if (!ret)
  430. ret = -EINPROGRESS;
  431. return ret;
  432. }
  433. /*
  434. * Sends IOCTL request to connect with a BSS.
  435. *
  436. * This function allocates the IOCTL request buffer, fills it
  437. * with requisite parameters and calls the IOCTL handler.
  438. */
  439. int mwifiex_bss_start(struct mwifiex_private *priv, u8 wait_option,
  440. struct mwifiex_ssid_bssid *ssid_bssid)
  441. {
  442. struct mwifiex_wait_queue *wait = NULL;
  443. struct mwifiex_ssid_bssid tmp_ssid_bssid;
  444. int status = 0;
  445. /* Stop the O.S. TX queue if needed */
  446. if (!netif_queue_stopped(priv->netdev))
  447. netif_stop_queue(priv->netdev);
  448. /* Allocate wait buffer */
  449. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  450. if (!wait)
  451. return -ENOMEM;
  452. if (ssid_bssid)
  453. memcpy(&tmp_ssid_bssid, ssid_bssid,
  454. sizeof(struct mwifiex_ssid_bssid));
  455. status = mwifiex_bss_ioctl_start(priv, wait, &tmp_ssid_bssid);
  456. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  457. kfree(wait);
  458. return status;
  459. }
  460. /*
  461. * IOCTL request handler to set host sleep configuration.
  462. *
  463. * This function prepares the correct firmware command and
  464. * issues it.
  465. */
  466. static int
  467. mwifiex_pm_ioctl_hs_cfg(struct mwifiex_private *priv,
  468. struct mwifiex_wait_queue *wait,
  469. u16 action, struct mwifiex_ds_hs_cfg *hs_cfg)
  470. {
  471. struct mwifiex_adapter *adapter = priv->adapter;
  472. int status = 0;
  473. u32 prev_cond = 0;
  474. switch (action) {
  475. case HostCmd_ACT_GEN_SET:
  476. if (adapter->pps_uapsd_mode) {
  477. dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
  478. " is blocked in UAPSD/PPS mode\n");
  479. status = -1;
  480. break;
  481. }
  482. if (hs_cfg->is_invoke_hostcmd) {
  483. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
  484. if (!adapter->is_hs_configured)
  485. /* Already cancelled */
  486. break;
  487. /* Save previous condition */
  488. prev_cond = le32_to_cpu(adapter->hs_cfg
  489. .conditions);
  490. adapter->hs_cfg.conditions =
  491. cpu_to_le32(hs_cfg->conditions);
  492. } else if (hs_cfg->conditions) {
  493. adapter->hs_cfg.conditions =
  494. cpu_to_le32(hs_cfg->conditions);
  495. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  496. if (hs_cfg->gap)
  497. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  498. } else if (adapter->hs_cfg.conditions ==
  499. cpu_to_le32(
  500. HOST_SLEEP_CFG_CANCEL)) {
  501. /* Return failure if no parameters for HS
  502. enable */
  503. status = -1;
  504. break;
  505. }
  506. status = mwifiex_prepare_cmd(priv,
  507. HostCmd_CMD_802_11_HS_CFG_ENH,
  508. HostCmd_ACT_GEN_SET,
  509. 0, wait, &adapter->hs_cfg);
  510. if (!status)
  511. status = -EINPROGRESS;
  512. if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
  513. /* Restore previous condition */
  514. adapter->hs_cfg.conditions =
  515. cpu_to_le32(prev_cond);
  516. } else {
  517. adapter->hs_cfg.conditions =
  518. cpu_to_le32(hs_cfg->conditions);
  519. adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
  520. adapter->hs_cfg.gap = (u8)hs_cfg->gap;
  521. }
  522. break;
  523. case HostCmd_ACT_GEN_GET:
  524. hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  525. hs_cfg->gpio = adapter->hs_cfg.gpio;
  526. hs_cfg->gap = adapter->hs_cfg.gap;
  527. break;
  528. default:
  529. status = -1;
  530. break;
  531. }
  532. return status;
  533. }
  534. /*
  535. * Sends IOCTL request to set Host Sleep parameters.
  536. *
  537. * This function allocates the IOCTL request buffer, fills it
  538. * with requisite parameters and calls the IOCTL handler.
  539. */
  540. int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
  541. u8 wait_option,
  542. struct mwifiex_ds_hs_cfg *hscfg)
  543. {
  544. int ret = 0;
  545. struct mwifiex_wait_queue *wait = NULL;
  546. if (!hscfg)
  547. return -ENOMEM;
  548. /* Allocate wait buffer */
  549. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  550. if (!wait)
  551. return -ENOMEM;
  552. ret = mwifiex_pm_ioctl_hs_cfg(priv, wait, action, hscfg);
  553. ret = mwifiex_request_ioctl(priv, wait, ret, wait_option);
  554. if (wait && (ret != -EINPROGRESS))
  555. kfree(wait);
  556. return ret;
  557. }
  558. /*
  559. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  560. *
  561. * This function allocates the IOCTL request buffer, fills it
  562. * with requisite parameters and calls the IOCTL handler.
  563. */
  564. int mwifiex_cancel_hs(struct mwifiex_private *priv, u8 wait_option)
  565. {
  566. int ret = 0;
  567. struct mwifiex_ds_hs_cfg hscfg;
  568. /* Cancel Host Sleep */
  569. hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
  570. hscfg.is_invoke_hostcmd = true;
  571. ret = mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  572. wait_option, &hscfg);
  573. return ret;
  574. }
  575. EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
  576. /*
  577. * Sends IOCTL request to cancel the existing Host Sleep configuration.
  578. *
  579. * This function allocates the IOCTL request buffer, fills it
  580. * with requisite parameters and calls the IOCTL handler.
  581. */
  582. int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
  583. {
  584. struct mwifiex_ds_hs_cfg hscfg;
  585. if (adapter->hs_activated) {
  586. dev_dbg(adapter->dev, "cmd: HS Already actived\n");
  587. return true;
  588. }
  589. /* Enable Host Sleep */
  590. adapter->hs_activate_wait_q_woken = false;
  591. memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
  592. hscfg.is_invoke_hostcmd = true;
  593. if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
  594. MWIFIEX_BSS_ROLE_STA),
  595. HostCmd_ACT_GEN_SET,
  596. MWIFIEX_IOCTL_WAIT, &hscfg)) {
  597. dev_err(adapter->dev, "IOCTL request HS enable failed\n");
  598. return false;
  599. }
  600. wait_event_interruptible(adapter->hs_activate_wait_q,
  601. adapter->hs_activate_wait_q_woken);
  602. return true;
  603. }
  604. EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
  605. /*
  606. * IOCTL request handler to get signal information.
  607. *
  608. * This function prepares the correct firmware command and
  609. * issues it to get the signal (RSSI) information.
  610. *
  611. * This only works in the connected mode.
  612. */
  613. static int mwifiex_get_info_signal(struct mwifiex_private *priv,
  614. struct mwifiex_wait_queue *wait,
  615. struct mwifiex_ds_get_signal *signal)
  616. {
  617. int ret = 0;
  618. if (!wait) {
  619. dev_err(priv->adapter->dev, "WAIT information is not present\n");
  620. return -1;
  621. }
  622. /* Signal info can be obtained only if connected */
  623. if (!priv->media_connected) {
  624. dev_dbg(priv->adapter->dev,
  625. "info: Can not get signal in disconnected state\n");
  626. return -1;
  627. }
  628. /* Send request to firmware */
  629. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_RSSI_INFO,
  630. HostCmd_ACT_GEN_GET, 0, wait, signal);
  631. if (!ret)
  632. ret = -EINPROGRESS;
  633. return ret;
  634. }
  635. /*
  636. * IOCTL request handler to get statistics.
  637. *
  638. * This function prepares the correct firmware command and
  639. * issues it to get the statistics (RSSI) information.
  640. */
  641. static int mwifiex_get_info_stats(struct mwifiex_private *priv,
  642. struct mwifiex_wait_queue *wait,
  643. struct mwifiex_ds_get_stats *log)
  644. {
  645. int ret = 0;
  646. if (!wait) {
  647. dev_err(priv->adapter->dev, "MWIFIEX IOCTL information is not present\n");
  648. return -1;
  649. }
  650. /* Send request to firmware */
  651. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
  652. HostCmd_ACT_GEN_GET, 0, wait, log);
  653. if (!ret)
  654. ret = -EINPROGRESS;
  655. return ret;
  656. }
  657. /*
  658. * IOCTL request handler to get BSS information.
  659. *
  660. * This function collates the information from different driver structures
  661. * to send to the user.
  662. */
  663. int mwifiex_get_bss_info(struct mwifiex_private *priv,
  664. struct mwifiex_bss_info *info)
  665. {
  666. struct mwifiex_adapter *adapter = priv->adapter;
  667. struct mwifiex_bssdescriptor *bss_desc;
  668. s32 tbl_idx = 0;
  669. if (!info)
  670. return -1;
  671. /* Get current BSS info */
  672. bss_desc = &priv->curr_bss_params.bss_descriptor;
  673. /* BSS mode */
  674. info->bss_mode = priv->bss_mode;
  675. /* SSID */
  676. memcpy(&info->ssid, &bss_desc->ssid,
  677. sizeof(struct mwifiex_802_11_ssid));
  678. /* BSSID */
  679. memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
  680. /* Channel */
  681. info->bss_chan = bss_desc->channel;
  682. /* Region code */
  683. info->region_code = adapter->region_code;
  684. /* Scan table index if connected */
  685. info->scan_table_idx = 0;
  686. if (priv->media_connected) {
  687. tbl_idx =
  688. mwifiex_find_ssid_in_list(priv, &bss_desc->ssid,
  689. bss_desc->mac_address,
  690. priv->bss_mode);
  691. if (tbl_idx >= 0)
  692. info->scan_table_idx = tbl_idx;
  693. }
  694. /* Connection status */
  695. info->media_connected = priv->media_connected;
  696. /* Radio status */
  697. info->radio_on = adapter->radio_on;
  698. /* Tx power information */
  699. info->max_power_level = priv->max_tx_power_level;
  700. info->min_power_level = priv->min_tx_power_level;
  701. /* AdHoc state */
  702. info->adhoc_state = priv->adhoc_state;
  703. /* Last beacon NF */
  704. info->bcn_nf_last = priv->bcn_nf_last;
  705. /* wep status */
  706. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  707. info->wep_status = true;
  708. else
  709. info->wep_status = false;
  710. info->is_hs_configured = adapter->is_hs_configured;
  711. info->is_deep_sleep = adapter->is_deep_sleep;
  712. return 0;
  713. }
  714. /*
  715. * IOCTL request handler to get extended version information.
  716. *
  717. * This function prepares the correct firmware command and
  718. * issues it to get the extended version information.
  719. */
  720. static int mwifiex_get_info_ver_ext(struct mwifiex_private *priv,
  721. struct mwifiex_wait_queue *wait,
  722. struct mwifiex_ver_ext *ver_ext)
  723. {
  724. int ret = 0;
  725. /* Send request to firmware */
  726. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_VERSION_EXT,
  727. HostCmd_ACT_GEN_GET, 0, wait, ver_ext);
  728. if (!ret)
  729. ret = -EINPROGRESS;
  730. return ret;
  731. }
  732. /*
  733. * IOCTL request handler to set/get SNMP MIB parameters.
  734. *
  735. * This function prepares the correct firmware command and
  736. * issues it.
  737. *
  738. * Currently the following parameters are supported -
  739. * Set/get RTS Threshold
  740. * Set/get fragmentation threshold
  741. * Set/get retry count
  742. */
  743. int mwifiex_snmp_mib_ioctl(struct mwifiex_private *priv,
  744. struct mwifiex_wait_queue *wait,
  745. u32 cmd_oid, u16 action, u32 *value)
  746. {
  747. int ret = 0;
  748. if (!value)
  749. return -1;
  750. /* Send request to firmware */
  751. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  752. action, cmd_oid, wait, value);
  753. if (!ret)
  754. ret = -EINPROGRESS;
  755. return ret;
  756. }
  757. /*
  758. * IOCTL request handler to set/get band configurations.
  759. *
  760. * For SET operation, it performs extra checks to make sure the Ad-Hoc
  761. * band and channel are compatible. Otherwise it returns an error.
  762. *
  763. * For GET operation, this function retrieves the following information -
  764. * - Infra bands
  765. * - Ad-hoc band
  766. * - Ad-hoc channel
  767. * - Secondary channel offset
  768. */
  769. int mwifiex_radio_ioctl_band_cfg(struct mwifiex_private *priv,
  770. u16 action,
  771. struct mwifiex_ds_band_cfg *radio_cfg)
  772. {
  773. struct mwifiex_adapter *adapter = priv->adapter;
  774. u8 infra_band = 0;
  775. u8 adhoc_band = 0;
  776. u32 adhoc_channel = 0;
  777. if (action == HostCmd_ACT_GEN_GET) {
  778. /* Infra Bands */
  779. radio_cfg->config_bands = adapter->config_bands;
  780. /* Adhoc Band */
  781. radio_cfg->adhoc_start_band = adapter->adhoc_start_band;
  782. /* Adhoc channel */
  783. radio_cfg->adhoc_channel = priv->adhoc_channel;
  784. /* Secondary channel offset */
  785. radio_cfg->sec_chan_offset = adapter->chan_offset;
  786. return 0;
  787. }
  788. /* For action = SET */
  789. infra_band = (u8) radio_cfg->config_bands;
  790. adhoc_band = (u8) radio_cfg->adhoc_start_band;
  791. adhoc_channel = radio_cfg->adhoc_channel;
  792. /* SET Infra band */
  793. if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
  794. return -1;
  795. adapter->config_bands = infra_band;
  796. /* SET Ad-hoc Band */
  797. if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
  798. return -1;
  799. if (adhoc_band)
  800. adapter->adhoc_start_band = adhoc_band;
  801. adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
  802. /*
  803. * If no adhoc_channel is supplied verify if the existing adhoc
  804. * channel compiles with new adhoc_band
  805. */
  806. if (!adhoc_channel) {
  807. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  808. (priv, adapter->adhoc_start_band,
  809. priv->adhoc_channel)) {
  810. /* Pass back the default channel */
  811. radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  812. if ((adapter->adhoc_start_band & BAND_A)
  813. || (adapter->adhoc_start_band & BAND_AN))
  814. radio_cfg->adhoc_channel =
  815. DEFAULT_AD_HOC_CHANNEL_A;
  816. }
  817. } else { /* Retrurn error if adhoc_band and
  818. adhoc_channel combination is invalid */
  819. if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  820. (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
  821. return -1;
  822. priv->adhoc_channel = (u8) adhoc_channel;
  823. }
  824. if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
  825. adapter->adhoc_11n_enabled = true;
  826. else
  827. adapter->adhoc_11n_enabled = false;
  828. return 0;
  829. }
  830. /*
  831. * IOCTL request handler to set/get active channel.
  832. *
  833. * This function performs validity checking on channel/frequency
  834. * compatibility and returns failure if not valid.
  835. */
  836. int mwifiex_bss_ioctl_channel(struct mwifiex_private *priv, u16 action,
  837. struct mwifiex_chan_freq_power *chan)
  838. {
  839. struct mwifiex_adapter *adapter = priv->adapter;
  840. struct mwifiex_chan_freq_power *cfp = NULL;
  841. if (!chan)
  842. return -1;
  843. if (action == HostCmd_ACT_GEN_GET) {
  844. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
  845. priv->curr_bss_params.band,
  846. (u16) priv->curr_bss_params.bss_descriptor.
  847. channel);
  848. chan->channel = cfp->channel;
  849. chan->freq = cfp->freq;
  850. return 0;
  851. }
  852. if (!chan->channel && !chan->freq)
  853. return -1;
  854. if (adapter->adhoc_start_band & BAND_AN)
  855. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  856. else if (adapter->adhoc_start_band & BAND_A)
  857. adapter->adhoc_start_band = BAND_G | BAND_B;
  858. if (chan->channel) {
  859. if (chan->channel <= MAX_CHANNEL_BAND_BG)
  860. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  861. (priv, 0, (u16) chan->channel);
  862. if (!cfp) {
  863. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  864. (priv, BAND_A, (u16) chan->channel);
  865. if (cfp) {
  866. if (adapter->adhoc_11n_enabled)
  867. adapter->adhoc_start_band = BAND_A
  868. | BAND_AN;
  869. else
  870. adapter->adhoc_start_band = BAND_A;
  871. }
  872. }
  873. } else {
  874. if (chan->freq <= MAX_FREQUENCY_BAND_BG)
  875. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
  876. priv, 0, chan->freq);
  877. if (!cfp) {
  878. cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
  879. (priv, BAND_A, chan->freq);
  880. if (cfp) {
  881. if (adapter->adhoc_11n_enabled)
  882. adapter->adhoc_start_band = BAND_A
  883. | BAND_AN;
  884. else
  885. adapter->adhoc_start_band = BAND_A;
  886. }
  887. }
  888. }
  889. if (!cfp || !cfp->channel) {
  890. dev_err(adapter->dev, "invalid channel/freq\n");
  891. return -1;
  892. }
  893. priv->adhoc_channel = (u8) cfp->channel;
  894. chan->channel = cfp->channel;
  895. chan->freq = cfp->freq;
  896. return 0;
  897. }
  898. /*
  899. * IOCTL request handler to set/get BSS mode.
  900. *
  901. * This function prepares the correct firmware command and
  902. * issues it to set or get the BSS mode.
  903. *
  904. * In case the mode is changed, a deauthentication is performed
  905. * first by the function automatically.
  906. */
  907. int mwifiex_bss_ioctl_mode(struct mwifiex_private *priv,
  908. struct mwifiex_wait_queue *wait,
  909. u16 action, int *mode)
  910. {
  911. int ret = 0;
  912. if (!mode)
  913. return -1;
  914. if (action == HostCmd_ACT_GEN_GET) {
  915. *mode = priv->bss_mode;
  916. return 0;
  917. }
  918. if ((priv->bss_mode == *mode) || (*mode == MWIFIEX_BSS_MODE_AUTO)) {
  919. dev_dbg(priv->adapter->dev,
  920. "info: Already set to required mode! No change!\n");
  921. priv->bss_mode = *mode;
  922. return 0;
  923. }
  924. ret = mwifiex_deauthenticate(priv, wait, NULL);
  925. priv->sec_info.authentication_mode = MWIFIEX_AUTH_MODE_OPEN;
  926. priv->bss_mode = *mode;
  927. if (priv->bss_mode != MWIFIEX_BSS_MODE_AUTO) {
  928. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  929. HostCmd_ACT_GEN_SET, 0, wait, NULL);
  930. if (!ret)
  931. ret = -EINPROGRESS;
  932. }
  933. return ret;
  934. }
  935. /*
  936. * IOCTL request handler to set/get Ad-Hoc channel.
  937. *
  938. * This function prepares the correct firmware command and
  939. * issues it to set or get the ad-hoc channel.
  940. */
  941. static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
  942. struct mwifiex_wait_queue *wait,
  943. u16 action, u16 *channel)
  944. {
  945. int ret = 0;
  946. if (action == HostCmd_ACT_GEN_GET) {
  947. if (!priv->media_connected) {
  948. *channel = priv->adhoc_channel;
  949. return ret;
  950. }
  951. } else {
  952. priv->adhoc_channel = (u8) *channel;
  953. }
  954. /* Send request to firmware */
  955. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_RF_CHANNEL,
  956. action, 0, wait, channel);
  957. if (!ret)
  958. ret = -EINPROGRESS;
  959. return ret;
  960. }
  961. /*
  962. * IOCTL request handler to find a particular BSS.
  963. *
  964. * The BSS can be searched with either a BSSID or a SSID. If none of
  965. * these are provided, just the best BSS (best RSSI) is returned.
  966. */
  967. int mwifiex_bss_ioctl_find_bss(struct mwifiex_private *priv,
  968. struct mwifiex_wait_queue *wait,
  969. struct mwifiex_ssid_bssid *ssid_bssid)
  970. {
  971. struct mwifiex_adapter *adapter = priv->adapter;
  972. int ret = 0;
  973. struct mwifiex_bssdescriptor *bss_desc;
  974. u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  975. u8 mac[ETH_ALEN];
  976. int i = 0;
  977. if (memcmp(ssid_bssid->bssid, zero_mac, sizeof(zero_mac))) {
  978. i = mwifiex_find_bssid_in_list(priv,
  979. (u8 *) ssid_bssid->bssid,
  980. priv->bss_mode);
  981. if (i < 0) {
  982. memcpy(mac, ssid_bssid->bssid, sizeof(mac));
  983. dev_err(adapter->dev, "cannot find bssid %pM\n", mac);
  984. return -1;
  985. }
  986. bss_desc = &adapter->scan_table[i];
  987. memcpy(&ssid_bssid->ssid, &bss_desc->ssid,
  988. sizeof(struct mwifiex_802_11_ssid));
  989. } else if (ssid_bssid->ssid.ssid_len) {
  990. i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid, NULL,
  991. priv->bss_mode);
  992. if (i < 0) {
  993. dev_err(adapter->dev, "cannot find ssid %s\n",
  994. ssid_bssid->ssid.ssid);
  995. return -1;
  996. }
  997. bss_desc = &adapter->scan_table[i];
  998. memcpy(ssid_bssid->bssid, bss_desc->mac_address, ETH_ALEN);
  999. } else {
  1000. ret = mwifiex_find_best_network(priv, ssid_bssid);
  1001. }
  1002. return ret;
  1003. }
  1004. /*
  1005. * IOCTL request handler to change Ad-Hoc channel.
  1006. *
  1007. * This function allocates the IOCTL request buffer, fills it
  1008. * with requisite parameters and calls the IOCTL handler.
  1009. *
  1010. * The function follows the following steps to perform the change -
  1011. * - Get current IBSS information
  1012. * - Get current channel
  1013. * - If no change is required, return
  1014. * - If not connected, change channel and return
  1015. * - If connected,
  1016. * - Disconnect
  1017. * - Change channel
  1018. * - Perform specific SSID scan with same SSID
  1019. * - Start/Join the IBSS
  1020. */
  1021. int
  1022. mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
  1023. {
  1024. int ret = 0;
  1025. int status = 0;
  1026. struct mwifiex_bss_info bss_info;
  1027. struct mwifiex_wait_queue *wait = NULL;
  1028. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1029. struct mwifiex_ssid_bssid ssid_bssid;
  1030. u16 curr_chan = 0;
  1031. memset(&bss_info, 0, sizeof(bss_info));
  1032. /* Get BSS information */
  1033. if (mwifiex_get_bss_info(priv, &bss_info))
  1034. return -1;
  1035. /* Allocate wait buffer */
  1036. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1037. if (!wait)
  1038. return -ENOMEM;
  1039. /* Get current channel */
  1040. status = mwifiex_bss_ioctl_ibss_channel(priv, wait, HostCmd_ACT_GEN_GET,
  1041. &curr_chan);
  1042. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1043. ret = -1;
  1044. goto done;
  1045. }
  1046. if (curr_chan == channel) {
  1047. ret = 0;
  1048. goto done;
  1049. }
  1050. dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
  1051. curr_chan, channel);
  1052. if (!bss_info.media_connected) {
  1053. ret = 0;
  1054. goto done;
  1055. }
  1056. /* Do disonnect */
  1057. memset(&ssid_bssid, 0, ETH_ALEN);
  1058. status = mwifiex_bss_ioctl_stop(priv, wait, ssid_bssid.bssid);
  1059. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1060. ret = -1;
  1061. goto done;
  1062. }
  1063. status = mwifiex_bss_ioctl_ibss_channel(priv, wait, HostCmd_ACT_GEN_SET,
  1064. (u16 *) &channel);
  1065. if (mwifiex_request_ioctl(priv, wait, status, wait_option)) {
  1066. ret = -1;
  1067. goto done;
  1068. }
  1069. /* Do specific SSID scanning */
  1070. if (mwifiex_request_scan(priv, wait_option, &bss_info.ssid)) {
  1071. ret = -1;
  1072. goto done;
  1073. }
  1074. /* Start/Join Adhoc network */
  1075. memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
  1076. memcpy(&ssid_bssid.ssid, &bss_info.ssid,
  1077. sizeof(struct mwifiex_802_11_ssid));
  1078. status = mwifiex_bss_ioctl_start(priv, wait, &ssid_bssid);
  1079. if (mwifiex_request_ioctl(priv, wait, status, wait_option))
  1080. ret = -1;
  1081. done:
  1082. kfree(wait);
  1083. return ret;
  1084. }
  1085. /*
  1086. * IOCTL request handler to get current driver mode.
  1087. *
  1088. * This function allocates the IOCTL request buffer, fills it
  1089. * with requisite parameters and calls the IOCTL handler.
  1090. */
  1091. int
  1092. mwifiex_drv_get_mode(struct mwifiex_private *priv, u8 wait_option)
  1093. {
  1094. struct mwifiex_wait_queue *wait = NULL;
  1095. int status = 0;
  1096. int mode = -1;
  1097. /* Allocate wait buffer */
  1098. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1099. if (!wait)
  1100. return -1;
  1101. status = mwifiex_bss_ioctl_mode(priv, wait, HostCmd_ACT_GEN_GET, &mode);
  1102. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1103. if (wait && (status != -EINPROGRESS))
  1104. kfree(wait);
  1105. return mode;
  1106. }
  1107. /*
  1108. * IOCTL request handler to get rate.
  1109. *
  1110. * This function prepares the correct firmware command and
  1111. * issues it to get the current rate if it is connected,
  1112. * otherwise, the function returns the lowest supported rate
  1113. * for the band.
  1114. */
  1115. static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
  1116. struct mwifiex_wait_queue *wait,
  1117. struct mwifiex_rate_cfg *rate_cfg)
  1118. {
  1119. struct mwifiex_adapter *adapter = priv->adapter;
  1120. int ret = 0;
  1121. rate_cfg->is_rate_auto = priv->is_data_rate_auto;
  1122. if (!priv->media_connected) {
  1123. switch (adapter->config_bands) {
  1124. case BAND_B:
  1125. /* Return the lowest supported rate for B band */
  1126. rate_cfg->rate = supported_rates_b[0] & 0x7f;
  1127. break;
  1128. case BAND_G:
  1129. case BAND_G | BAND_GN:
  1130. /* Return the lowest supported rate for G band */
  1131. rate_cfg->rate = supported_rates_g[0] & 0x7f;
  1132. break;
  1133. case BAND_B | BAND_G:
  1134. case BAND_A | BAND_B | BAND_G:
  1135. case BAND_A | BAND_B:
  1136. case BAND_A | BAND_B | BAND_G | BAND_AN | BAND_GN:
  1137. case BAND_B | BAND_G | BAND_GN:
  1138. /* Return the lowest supported rate for BG band */
  1139. rate_cfg->rate = supported_rates_bg[0] & 0x7f;
  1140. break;
  1141. case BAND_A:
  1142. case BAND_A | BAND_G:
  1143. case BAND_A | BAND_G | BAND_AN | BAND_GN:
  1144. case BAND_A | BAND_AN:
  1145. /* Return the lowest supported rate for A band */
  1146. rate_cfg->rate = supported_rates_a[0] & 0x7f;
  1147. break;
  1148. case BAND_GN:
  1149. /* Return the lowest supported rate for N band */
  1150. rate_cfg->rate = supported_rates_n[0] & 0x7f;
  1151. break;
  1152. default:
  1153. dev_warn(adapter->dev, "invalid band %#x\n",
  1154. adapter->config_bands);
  1155. break;
  1156. }
  1157. } else {
  1158. /* Send request to firmware */
  1159. ret = mwifiex_prepare_cmd(priv,
  1160. HostCmd_CMD_802_11_TX_RATE_QUERY,
  1161. HostCmd_ACT_GEN_GET, 0, wait, NULL);
  1162. if (!ret)
  1163. ret = -EINPROGRESS;
  1164. }
  1165. return ret;
  1166. }
  1167. /*
  1168. * IOCTL request handler to set rate.
  1169. *
  1170. * This function prepares the correct firmware command and
  1171. * issues it to set the current rate.
  1172. *
  1173. * The function also performs validation checking on the supplied value.
  1174. */
  1175. static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
  1176. struct mwifiex_wait_queue *wait,
  1177. struct mwifiex_rate_cfg *rate_cfg)
  1178. {
  1179. u8 rates[MWIFIEX_SUPPORTED_RATES];
  1180. u8 *rate = NULL;
  1181. int rate_index = 0;
  1182. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  1183. u32 i = 0;
  1184. int ret = 0;
  1185. struct mwifiex_adapter *adapter = priv->adapter;
  1186. if (rate_cfg->is_rate_auto) {
  1187. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1188. /* Support all HR/DSSS rates */
  1189. bitmap_rates[0] = 0x000F;
  1190. /* Support all OFDM rates */
  1191. bitmap_rates[1] = 0x00FF;
  1192. /* Support all HT-MCSs rate */
  1193. for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
  1194. bitmap_rates[i + 2] = 0xFFFF;
  1195. bitmap_rates[9] = 0x3FFF;
  1196. } else {
  1197. memset(rates, 0, sizeof(rates));
  1198. mwifiex_get_active_data_rates(priv, rates);
  1199. rate = rates;
  1200. for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
  1201. dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
  1202. rate[i], rate_cfg->rate);
  1203. if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
  1204. break;
  1205. }
  1206. if (!rate[i] || (i == MWIFIEX_SUPPORTED_RATES)) {
  1207. dev_err(adapter->dev, "fixed data rate %#x is out "
  1208. "of range\n", rate_cfg->rate);
  1209. return -1;
  1210. }
  1211. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1212. rate_index =
  1213. mwifiex_data_rate_to_index(adapter, rate_cfg->rate);
  1214. /* Only allow b/g rates to be set */
  1215. if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
  1216. rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
  1217. bitmap_rates[0] = 1 << rate_index;
  1218. } else {
  1219. rate_index -= 1; /* There is a 0x00 in the table */
  1220. if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
  1221. rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
  1222. bitmap_rates[1] = 1 << (rate_index -
  1223. MWIFIEX_RATE_INDEX_OFDM0);
  1224. }
  1225. }
  1226. /* Send request to firmware */
  1227. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
  1228. HostCmd_ACT_GEN_SET, 0, wait, bitmap_rates);
  1229. if (!ret)
  1230. ret = -EINPROGRESS;
  1231. return ret;
  1232. }
  1233. /*
  1234. * IOCTL request handler to set/get rate.
  1235. *
  1236. * This function can be used to set/get either the rate value or the
  1237. * rate index.
  1238. */
  1239. static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
  1240. struct mwifiex_wait_queue *wait,
  1241. struct mwifiex_rate_cfg *rate_cfg)
  1242. {
  1243. int status = 0;
  1244. if (!rate_cfg)
  1245. return -1;
  1246. if (rate_cfg->action == HostCmd_ACT_GEN_GET)
  1247. status = mwifiex_rate_ioctl_get_rate_value(
  1248. priv, wait, rate_cfg);
  1249. else
  1250. status = mwifiex_rate_ioctl_set_rate_value(
  1251. priv, wait, rate_cfg);
  1252. return status;
  1253. }
  1254. /*
  1255. * Sends IOCTL request to get the data rate.
  1256. *
  1257. * This function allocates the IOCTL request buffer, fills it
  1258. * with requisite parameters and calls the IOCTL handler.
  1259. */
  1260. int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
  1261. struct mwifiex_rate_cfg *rate)
  1262. {
  1263. int ret = 0;
  1264. struct mwifiex_wait_queue *wait = NULL;
  1265. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1266. /* Allocate wait buffer */
  1267. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1268. if (!wait)
  1269. return -ENOMEM;
  1270. memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
  1271. rate->action = HostCmd_ACT_GEN_GET;
  1272. ret = mwifiex_rate_ioctl_cfg(priv, wait, rate);
  1273. ret = mwifiex_request_ioctl(priv, wait, ret, wait_option);
  1274. if (!ret) {
  1275. if (rate && rate->is_rate_auto)
  1276. rate->rate = mwifiex_index_to_data_rate(priv->adapter,
  1277. priv->tx_rate, priv->tx_htinfo);
  1278. else if (rate)
  1279. rate->rate = priv->data_rate;
  1280. } else {
  1281. ret = -1;
  1282. }
  1283. kfree(wait);
  1284. return ret;
  1285. }
  1286. /*
  1287. * IOCTL request handler to set tx power configuration.
  1288. *
  1289. * This function prepares the correct firmware command and
  1290. * issues it.
  1291. *
  1292. * For non-auto power mode, all the following power groups are set -
  1293. * - Modulation class HR/DSSS
  1294. * - Modulation class OFDM
  1295. * - Modulation class HTBW20
  1296. * - Modulation class HTBW40
  1297. */
  1298. static int mwifiex_power_ioctl_set_power(struct mwifiex_private *priv,
  1299. struct mwifiex_wait_queue *wait,
  1300. struct mwifiex_power_cfg *power_cfg)
  1301. {
  1302. int ret = 0;
  1303. struct host_cmd_ds_txpwr_cfg *txp_cfg = NULL;
  1304. struct mwifiex_types_power_group *pg_tlv = NULL;
  1305. struct mwifiex_power_group *pg = NULL;
  1306. u8 *buf = NULL;
  1307. u16 dbm = 0;
  1308. if (!power_cfg->is_power_auto) {
  1309. dbm = (u16) power_cfg->power_level;
  1310. if ((dbm < priv->min_tx_power_level) ||
  1311. (dbm > priv->max_tx_power_level)) {
  1312. dev_err(priv->adapter->dev, "txpower value %d dBm"
  1313. " is out of range (%d dBm-%d dBm)\n",
  1314. dbm, priv->min_tx_power_level,
  1315. priv->max_tx_power_level);
  1316. return -1;
  1317. }
  1318. }
  1319. buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
  1320. if (!buf) {
  1321. dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
  1322. __func__);
  1323. return -1;
  1324. }
  1325. txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
  1326. txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
  1327. if (!power_cfg->is_power_auto) {
  1328. txp_cfg->mode = cpu_to_le32(1);
  1329. pg_tlv = (struct mwifiex_types_power_group *) (buf +
  1330. sizeof(struct host_cmd_ds_txpwr_cfg));
  1331. pg_tlv->type = TLV_TYPE_POWER_GROUP;
  1332. pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
  1333. pg = (struct mwifiex_power_group *) (buf +
  1334. sizeof(struct host_cmd_ds_txpwr_cfg) +
  1335. sizeof(struct mwifiex_types_power_group));
  1336. /* Power group for modulation class HR/DSSS */
  1337. pg->first_rate_code = 0x00;
  1338. pg->last_rate_code = 0x03;
  1339. pg->modulation_class = MOD_CLASS_HR_DSSS;
  1340. pg->power_step = 0;
  1341. pg->power_min = (s8) dbm;
  1342. pg->power_max = (s8) dbm;
  1343. pg++;
  1344. /* Power group for modulation class OFDM */
  1345. pg->first_rate_code = 0x00;
  1346. pg->last_rate_code = 0x07;
  1347. pg->modulation_class = MOD_CLASS_OFDM;
  1348. pg->power_step = 0;
  1349. pg->power_min = (s8) dbm;
  1350. pg->power_max = (s8) dbm;
  1351. pg++;
  1352. /* Power group for modulation class HTBW20 */
  1353. pg->first_rate_code = 0x00;
  1354. pg->last_rate_code = 0x20;
  1355. pg->modulation_class = MOD_CLASS_HT;
  1356. pg->power_step = 0;
  1357. pg->power_min = (s8) dbm;
  1358. pg->power_max = (s8) dbm;
  1359. pg->ht_bandwidth = HT_BW_20;
  1360. pg++;
  1361. /* Power group for modulation class HTBW40 */
  1362. pg->first_rate_code = 0x00;
  1363. pg->last_rate_code = 0x20;
  1364. pg->modulation_class = MOD_CLASS_HT;
  1365. pg->power_step = 0;
  1366. pg->power_min = (s8) dbm;
  1367. pg->power_max = (s8) dbm;
  1368. pg->ht_bandwidth = HT_BW_40;
  1369. }
  1370. /* Send request to firmware */
  1371. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_TXPWR_CFG,
  1372. HostCmd_ACT_GEN_SET, 0, wait, buf);
  1373. if (!ret)
  1374. ret = -EINPROGRESS;
  1375. kfree(buf);
  1376. return ret;
  1377. }
  1378. /*
  1379. * IOCTL request handler to get power save mode.
  1380. *
  1381. * This function prepares the correct firmware command and
  1382. * issues it.
  1383. */
  1384. static int mwifiex_pm_ioctl_ps_mode(struct mwifiex_private *priv,
  1385. struct mwifiex_wait_queue *wait,
  1386. u32 *ps_mode, u16 action)
  1387. {
  1388. int ret = 0;
  1389. struct mwifiex_adapter *adapter = priv->adapter;
  1390. u16 sub_cmd;
  1391. if (action == HostCmd_ACT_GEN_SET) {
  1392. if (*ps_mode)
  1393. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1394. else
  1395. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  1396. sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
  1397. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1398. sub_cmd, BITMAP_STA_PS, wait, NULL);
  1399. if ((!ret) && (sub_cmd == DIS_AUTO_PS))
  1400. ret = mwifiex_prepare_cmd(priv,
  1401. HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
  1402. 0, NULL, NULL);
  1403. } else {
  1404. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  1405. GET_PS, 0, wait, NULL);
  1406. }
  1407. if (!ret)
  1408. ret = -EINPROGRESS;
  1409. return ret;
  1410. }
  1411. /*
  1412. * IOCTL request handler to set/reset WPA IE.
  1413. *
  1414. * The supplied WPA IE is treated as a opaque buffer. Only the first field
  1415. * is checked to determine WPA version. If buffer length is zero, the existing
  1416. * WPA IE is reset.
  1417. */
  1418. static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
  1419. u8 *ie_data_ptr, u16 ie_len)
  1420. {
  1421. if (ie_len) {
  1422. if (ie_len > sizeof(priv->wpa_ie)) {
  1423. dev_err(priv->adapter->dev,
  1424. "failed to copy WPA IE, too big\n");
  1425. return -1;
  1426. }
  1427. memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
  1428. priv->wpa_ie_len = (u8) ie_len;
  1429. dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
  1430. priv->wpa_ie_len, priv->wpa_ie[0]);
  1431. if (priv->wpa_ie[0] == WLAN_EID_WPA) {
  1432. priv->sec_info.wpa_enabled = true;
  1433. } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
  1434. priv->sec_info.wpa2_enabled = true;
  1435. } else {
  1436. priv->sec_info.wpa_enabled = false;
  1437. priv->sec_info.wpa2_enabled = false;
  1438. }
  1439. } else {
  1440. memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
  1441. priv->wpa_ie_len = 0;
  1442. dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
  1443. priv->wpa_ie_len, priv->wpa_ie[0]);
  1444. priv->sec_info.wpa_enabled = false;
  1445. priv->sec_info.wpa2_enabled = false;
  1446. }
  1447. return 0;
  1448. }
  1449. /*
  1450. * IOCTL request handler to set/reset WAPI IE.
  1451. *
  1452. * The supplied WAPI IE is treated as a opaque buffer. Only the first field
  1453. * is checked to internally enable WAPI. If buffer length is zero, the existing
  1454. * WAPI IE is reset.
  1455. */
  1456. static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
  1457. u8 *ie_data_ptr, u16 ie_len)
  1458. {
  1459. if (ie_len) {
  1460. if (ie_len > sizeof(priv->wapi_ie)) {
  1461. dev_dbg(priv->adapter->dev,
  1462. "info: failed to copy WAPI IE, too big\n");
  1463. return -1;
  1464. }
  1465. memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
  1466. priv->wapi_ie_len = ie_len;
  1467. dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
  1468. priv->wapi_ie_len, priv->wapi_ie[0]);
  1469. if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
  1470. priv->sec_info.wapi_enabled = true;
  1471. } else {
  1472. memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
  1473. priv->wapi_ie_len = ie_len;
  1474. dev_dbg(priv->adapter->dev,
  1475. "info: Reset wapi_ie_len=%d IE=%#x\n",
  1476. priv->wapi_ie_len, priv->wapi_ie[0]);
  1477. priv->sec_info.wapi_enabled = false;
  1478. }
  1479. return 0;
  1480. }
  1481. /*
  1482. * IOCTL request handler to set WAPI key.
  1483. *
  1484. * This function prepares the correct firmware command and
  1485. * issues it.
  1486. */
  1487. static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_adapter *adapter,
  1488. struct mwifiex_wait_queue *wait,
  1489. struct mwifiex_ds_encrypt_key *encrypt_key)
  1490. {
  1491. int ret = 0;
  1492. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1493. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1494. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1495. wait, encrypt_key);
  1496. if (!ret)
  1497. ret = -EINPROGRESS;
  1498. return ret;
  1499. }
  1500. /*
  1501. * IOCTL request handler to set WEP network key.
  1502. *
  1503. * This function prepares the correct firmware command and
  1504. * issues it, after validation checks.
  1505. */
  1506. static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_adapter *adapter,
  1507. struct mwifiex_wait_queue *wait,
  1508. struct mwifiex_ds_encrypt_key *encrypt_key)
  1509. {
  1510. int ret = 0;
  1511. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1512. struct mwifiex_wep_key *wep_key = NULL;
  1513. int index;
  1514. if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
  1515. priv->wep_key_curr_index = 0;
  1516. wep_key = &priv->wep_key[priv->wep_key_curr_index];
  1517. index = encrypt_key->key_index;
  1518. if (encrypt_key->key_disable) {
  1519. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
  1520. } else if (!encrypt_key->key_len) {
  1521. /* Copy the required key as the current key */
  1522. wep_key = &priv->wep_key[index];
  1523. if (!wep_key->key_length) {
  1524. dev_err(adapter->dev,
  1525. "key not set, so cannot enable it\n");
  1526. return -1;
  1527. }
  1528. priv->wep_key_curr_index = (u16) index;
  1529. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  1530. } else {
  1531. wep_key = &priv->wep_key[index];
  1532. /* Cleanup */
  1533. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  1534. /* Copy the key in the driver */
  1535. memcpy(wep_key->key_material,
  1536. encrypt_key->key_material,
  1537. encrypt_key->key_len);
  1538. wep_key->key_index = index;
  1539. wep_key->key_length = encrypt_key->key_len;
  1540. priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
  1541. }
  1542. if (wep_key->key_length) {
  1543. /* Send request to firmware */
  1544. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1545. HostCmd_ACT_GEN_SET, 0, NULL, NULL);
  1546. if (ret)
  1547. return ret;
  1548. }
  1549. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
  1550. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  1551. else
  1552. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  1553. /* Send request to firmware */
  1554. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  1555. HostCmd_ACT_GEN_SET, 0, wait,
  1556. &priv->curr_pkt_filter);
  1557. if (!ret)
  1558. ret = -EINPROGRESS;
  1559. return ret;
  1560. }
  1561. /*
  1562. * IOCTL request handler to set WPA key.
  1563. *
  1564. * This function prepares the correct firmware command and
  1565. * issues it, after validation checks.
  1566. *
  1567. * Current driver only supports key length of up to 32 bytes.
  1568. *
  1569. * This function can also be used to disable a currently set key.
  1570. */
  1571. static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_adapter *adapter,
  1572. struct mwifiex_wait_queue *wait,
  1573. struct mwifiex_ds_encrypt_key *encrypt_key)
  1574. {
  1575. int ret = 0;
  1576. struct mwifiex_private *priv = adapter->priv[wait->bss_index];
  1577. u8 remove_key = false;
  1578. struct host_cmd_ds_802_11_key_material *ibss_key;
  1579. /* Current driver only supports key length of up to 32 bytes */
  1580. if (encrypt_key->key_len > MWIFIEX_MAX_KEY_LENGTH) {
  1581. dev_err(adapter->dev, "key length too long\n");
  1582. return -1;
  1583. }
  1584. if (priv->bss_mode == MWIFIEX_BSS_MODE_IBSS) {
  1585. /*
  1586. * IBSS/WPA-None uses only one key (Group) for both receiving
  1587. * and sending unicast and multicast packets.
  1588. */
  1589. /* Send the key as PTK to firmware */
  1590. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1591. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1592. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1593. NULL, encrypt_key);
  1594. if (ret)
  1595. return ret;
  1596. ibss_key = &priv->aes_key;
  1597. memset(ibss_key, 0,
  1598. sizeof(struct host_cmd_ds_802_11_key_material));
  1599. /* Copy the key in the driver */
  1600. memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
  1601. encrypt_key->key_len);
  1602. memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
  1603. sizeof(ibss_key->key_param_set.key_len));
  1604. ibss_key->key_param_set.key_type_id
  1605. = cpu_to_le16(KEY_TYPE_ID_TKIP);
  1606. ibss_key->key_param_set.key_info
  1607. = cpu_to_le16(KEY_INFO_TKIP_ENABLED);
  1608. /* Send the key as GTK to firmware */
  1609. encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
  1610. }
  1611. if (!encrypt_key->key_index)
  1612. encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
  1613. if (remove_key)
  1614. /* Send request to firmware */
  1615. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1616. HostCmd_ACT_GEN_SET,
  1617. !(KEY_INFO_ENABLED),
  1618. wait, encrypt_key);
  1619. else
  1620. /* Send request to firmware */
  1621. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  1622. HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
  1623. wait, encrypt_key);
  1624. if (!ret)
  1625. ret = -EINPROGRESS;
  1626. return ret;
  1627. }
  1628. /*
  1629. * IOCTL request handler to set/get network keys.
  1630. *
  1631. * This is a generic key handling function which supports WEP, WPA
  1632. * and WAPI.
  1633. */
  1634. static int
  1635. mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
  1636. struct mwifiex_wait_queue *wait,
  1637. struct mwifiex_ds_encrypt_key *encrypt_key)
  1638. {
  1639. int status = 0;
  1640. struct mwifiex_adapter *adapter = priv->adapter;
  1641. if (encrypt_key->is_wapi_key)
  1642. status = mwifiex_sec_ioctl_set_wapi_key(adapter, wait,
  1643. encrypt_key);
  1644. else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
  1645. status = mwifiex_sec_ioctl_set_wpa_key(adapter, wait,
  1646. encrypt_key);
  1647. else
  1648. status = mwifiex_sec_ioctl_set_wep_key(adapter, wait,
  1649. encrypt_key);
  1650. return status;
  1651. }
  1652. /*
  1653. * This function returns the driver version.
  1654. */
  1655. int
  1656. mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
  1657. int max_len)
  1658. {
  1659. union {
  1660. u32 l;
  1661. u8 c[4];
  1662. } ver;
  1663. char fw_ver[32];
  1664. ver.l = adapter->fw_release_number;
  1665. sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1666. snprintf(version, max_len, driver_version, fw_ver);
  1667. dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
  1668. return 0;
  1669. }
  1670. /*
  1671. * Sends IOCTL request to set Tx power. It can be set to either auto
  1672. * or a fixed value.
  1673. *
  1674. * This function allocates the IOCTL request buffer, fills it
  1675. * with requisite parameters and calls the IOCTL handler.
  1676. */
  1677. int
  1678. mwifiex_set_tx_power(struct mwifiex_private *priv, int type, int dbm)
  1679. {
  1680. struct mwifiex_power_cfg power_cfg;
  1681. struct mwifiex_wait_queue *wait = NULL;
  1682. int status = 0;
  1683. int ret = 0;
  1684. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1685. if (!wait)
  1686. return -ENOMEM;
  1687. if (type == NL80211_TX_POWER_FIXED) {
  1688. power_cfg.is_power_auto = 0;
  1689. power_cfg.power_level = dbm;
  1690. } else {
  1691. power_cfg.is_power_auto = 1;
  1692. }
  1693. status = mwifiex_power_ioctl_set_power(priv, wait, &power_cfg);
  1694. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1695. kfree(wait);
  1696. return ret;
  1697. }
  1698. /*
  1699. * Sends IOCTL request to get scan table.
  1700. *
  1701. * This function allocates the IOCTL request buffer, fills it
  1702. * with requisite parameters and calls the IOCTL handler.
  1703. */
  1704. int mwifiex_get_scan_table(struct mwifiex_private *priv, u8 wait_option,
  1705. struct mwifiex_scan_resp *scan_resp)
  1706. {
  1707. struct mwifiex_wait_queue *wait = NULL;
  1708. struct mwifiex_scan_resp scan;
  1709. int status = 0;
  1710. /* Allocate wait buffer */
  1711. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1712. if (!wait)
  1713. return -ENOMEM;
  1714. status = mwifiex_scan_networks(priv, wait, HostCmd_ACT_GEN_GET,
  1715. NULL, &scan);
  1716. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1717. if (!status) {
  1718. if (scan_resp)
  1719. memcpy(scan_resp, &scan,
  1720. sizeof(struct mwifiex_scan_resp));
  1721. }
  1722. if (wait && (status != -EINPROGRESS))
  1723. kfree(wait);
  1724. return status;
  1725. }
  1726. /*
  1727. * Sends IOCTL request to get signal information.
  1728. *
  1729. * This function allocates the IOCTL request buffer, fills it
  1730. * with requisite parameters and calls the IOCTL handler.
  1731. */
  1732. int mwifiex_get_signal_info(struct mwifiex_private *priv, u8 wait_option,
  1733. struct mwifiex_ds_get_signal *signal)
  1734. {
  1735. struct mwifiex_ds_get_signal info;
  1736. struct mwifiex_wait_queue *wait = NULL;
  1737. int status = 0;
  1738. /* Allocate wait buffer */
  1739. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1740. if (!wait)
  1741. return -ENOMEM;
  1742. info.selector = ALL_RSSI_INFO_MASK;
  1743. status = mwifiex_get_info_signal(priv, wait, &info);
  1744. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1745. if (!status) {
  1746. if (signal)
  1747. memcpy(signal, &info,
  1748. sizeof(struct mwifiex_ds_get_signal));
  1749. if (info.selector & BCN_RSSI_AVG_MASK)
  1750. priv->w_stats.qual.level = info.bcn_rssi_avg;
  1751. if (info.selector & BCN_NF_AVG_MASK)
  1752. priv->w_stats.qual.noise = info.bcn_nf_avg;
  1753. }
  1754. if (wait && (status != -EINPROGRESS))
  1755. kfree(wait);
  1756. return status;
  1757. }
  1758. /*
  1759. * Sends IOCTL request to set encoding parameters.
  1760. *
  1761. * This function allocates the IOCTL request buffer, fills it
  1762. * with requisite parameters and calls the IOCTL handler.
  1763. */
  1764. int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
  1765. int key_len, u8 key_index, int disable)
  1766. {
  1767. struct mwifiex_wait_queue *wait = NULL;
  1768. struct mwifiex_ds_encrypt_key encrypt_key;
  1769. int status = 0;
  1770. int ret = 0;
  1771. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1772. if (!wait)
  1773. return -ENOMEM;
  1774. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  1775. encrypt_key.key_len = key_len;
  1776. if (!disable) {
  1777. encrypt_key.key_index = key_index;
  1778. if (key_len)
  1779. memcpy(encrypt_key.key_material, key, key_len);
  1780. } else {
  1781. encrypt_key.key_disable = true;
  1782. }
  1783. status = mwifiex_sec_ioctl_encrypt_key(priv, wait, &encrypt_key);
  1784. if (mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT))
  1785. ret = -EFAULT;
  1786. kfree(wait);
  1787. return ret;
  1788. }
  1789. /*
  1790. * Sends IOCTL request to set power management parameters.
  1791. *
  1792. * This function allocates the IOCTL request buffer, fills it
  1793. * with requisite parameters and calls the IOCTL handler.
  1794. */
  1795. int
  1796. mwifiex_drv_set_power(struct mwifiex_private *priv, bool power_on)
  1797. {
  1798. int ret = 0;
  1799. int status = 0;
  1800. struct mwifiex_wait_queue *wait = NULL;
  1801. u32 ps_mode;
  1802. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1803. if (!wait)
  1804. return -ENOMEM;
  1805. ps_mode = power_on;
  1806. status = mwifiex_pm_ioctl_ps_mode(priv, wait, &ps_mode,
  1807. HostCmd_ACT_GEN_SET);
  1808. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1809. kfree(wait);
  1810. return ret;
  1811. }
  1812. /*
  1813. * Sends IOCTL request to get extended version.
  1814. *
  1815. * This function allocates the IOCTL request buffer, fills it
  1816. * with requisite parameters and calls the IOCTL handler.
  1817. */
  1818. int
  1819. mwifiex_get_ver_ext(struct mwifiex_private *priv)
  1820. {
  1821. struct mwifiex_ver_ext ver_ext;
  1822. struct mwifiex_wait_queue *wait = NULL;
  1823. int status = 0;
  1824. int ret = 0;
  1825. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1826. /* Allocate wait buffer */
  1827. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1828. if (!wait)
  1829. return -ENOMEM;
  1830. /* get fw version */
  1831. memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
  1832. status = mwifiex_get_info_ver_ext(priv, wait, &ver_ext);
  1833. ret = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1834. if (ret)
  1835. ret = -1;
  1836. kfree(wait);
  1837. return ret;
  1838. }
  1839. /*
  1840. * Sends IOCTL request to get statistics information.
  1841. *
  1842. * This function allocates the IOCTL request buffer, fills it
  1843. * with requisite parameters and calls the IOCTL handler.
  1844. */
  1845. int
  1846. mwifiex_get_stats_info(struct mwifiex_private *priv,
  1847. struct mwifiex_ds_get_stats *log)
  1848. {
  1849. int ret = 0;
  1850. int status = 0;
  1851. struct mwifiex_wait_queue *wait = NULL;
  1852. struct mwifiex_ds_get_stats get_log;
  1853. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  1854. /* Allocate wait buffer */
  1855. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  1856. if (!wait)
  1857. return -ENOMEM;
  1858. memset(&get_log, 0, sizeof(struct mwifiex_ds_get_stats));
  1859. status = mwifiex_get_info_stats(priv, wait, &get_log);
  1860. /* Send IOCTL request to MWIFIEX */
  1861. ret = mwifiex_request_ioctl(priv, wait, status, wait_option);
  1862. if (!ret) {
  1863. if (log)
  1864. memcpy(log, &get_log, sizeof(struct
  1865. mwifiex_ds_get_stats));
  1866. priv->w_stats.discard.fragment = get_log.fcs_error;
  1867. priv->w_stats.discard.retries = get_log.retry;
  1868. priv->w_stats.discard.misc = get_log.ack_failure;
  1869. }
  1870. kfree(wait);
  1871. return ret;
  1872. }
  1873. /*
  1874. * IOCTL request handler to read/write register.
  1875. *
  1876. * This function prepares the correct firmware command and
  1877. * issues it.
  1878. *
  1879. * Access to the following registers are supported -
  1880. * - MAC
  1881. * - BBP
  1882. * - RF
  1883. * - PMIC
  1884. * - CAU
  1885. */
  1886. static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
  1887. struct mwifiex_wait_queue *wait,
  1888. struct mwifiex_ds_reg_rw *reg_rw,
  1889. u16 action)
  1890. {
  1891. int ret = 0;
  1892. u16 cmd_no;
  1893. switch (le32_to_cpu(reg_rw->type)) {
  1894. case MWIFIEX_REG_MAC:
  1895. cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
  1896. break;
  1897. case MWIFIEX_REG_BBP:
  1898. cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
  1899. break;
  1900. case MWIFIEX_REG_RF:
  1901. cmd_no = HostCmd_CMD_RF_REG_ACCESS;
  1902. break;
  1903. case MWIFIEX_REG_PMIC:
  1904. cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
  1905. break;
  1906. case MWIFIEX_REG_CAU:
  1907. cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
  1908. break;
  1909. default:
  1910. return -1;
  1911. }
  1912. /* Send request to firmware */
  1913. ret = mwifiex_prepare_cmd(priv, cmd_no, action, 0, wait, reg_rw);
  1914. if (!ret)
  1915. ret = -EINPROGRESS;
  1916. return ret;
  1917. }
  1918. /*
  1919. * Sends IOCTL request to write to a register.
  1920. *
  1921. * This function allocates the IOCTL request buffer, fills it
  1922. * with requisite parameters and calls the IOCTL handler.
  1923. */
  1924. int
  1925. mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
  1926. u32 reg_offset, u32 reg_value)
  1927. {
  1928. int ret = 0;
  1929. int status = 0;
  1930. struct mwifiex_wait_queue *wait = NULL;
  1931. struct mwifiex_ds_reg_rw reg_rw;
  1932. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1933. if (!wait)
  1934. return -ENOMEM;
  1935. reg_rw.type = cpu_to_le32(reg_type);
  1936. reg_rw.offset = cpu_to_le32(reg_offset);
  1937. reg_rw.value = cpu_to_le32(reg_value);
  1938. status = mwifiex_reg_mem_ioctl_reg_rw(priv, wait, &reg_rw,
  1939. HostCmd_ACT_GEN_SET);
  1940. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1941. kfree(wait);
  1942. return ret;
  1943. }
  1944. /*
  1945. * Sends IOCTL request to read from a register.
  1946. *
  1947. * This function allocates the IOCTL request buffer, fills it
  1948. * with requisite parameters and calls the IOCTL handler.
  1949. */
  1950. int
  1951. mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
  1952. u32 reg_offset, u32 *value)
  1953. {
  1954. int ret = 0;
  1955. int status = 0;
  1956. struct mwifiex_wait_queue *wait = NULL;
  1957. struct mwifiex_ds_reg_rw reg_rw;
  1958. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  1959. if (!wait)
  1960. return -ENOMEM;
  1961. reg_rw.type = cpu_to_le32(reg_type);
  1962. reg_rw.offset = cpu_to_le32(reg_offset);
  1963. status = mwifiex_reg_mem_ioctl_reg_rw(priv, wait, &reg_rw,
  1964. HostCmd_ACT_GEN_GET);
  1965. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  1966. if (ret)
  1967. goto done;
  1968. *value = le32_to_cpu(reg_rw.value);
  1969. done:
  1970. kfree(wait);
  1971. return ret;
  1972. }
  1973. /*
  1974. * IOCTL request handler to read EEPROM.
  1975. *
  1976. * This function prepares the correct firmware command and
  1977. * issues it.
  1978. */
  1979. static int
  1980. mwifiex_reg_mem_ioctl_read_eeprom(struct mwifiex_private *priv,
  1981. struct mwifiex_wait_queue *wait,
  1982. struct mwifiex_ds_read_eeprom *rd_eeprom)
  1983. {
  1984. int ret = 0;
  1985. /* Send request to firmware */
  1986. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
  1987. HostCmd_ACT_GEN_GET, 0, wait, rd_eeprom);
  1988. if (!ret)
  1989. ret = -EINPROGRESS;
  1990. return ret;
  1991. }
  1992. /*
  1993. * Sends IOCTL request to read from EEPROM.
  1994. *
  1995. * This function allocates the IOCTL request buffer, fills it
  1996. * with requisite parameters and calls the IOCTL handler.
  1997. */
  1998. int
  1999. mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
  2000. u8 *value)
  2001. {
  2002. int ret = 0;
  2003. int status = 0;
  2004. struct mwifiex_wait_queue *wait = NULL;
  2005. struct mwifiex_ds_read_eeprom rd_eeprom;
  2006. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  2007. if (!wait)
  2008. return -ENOMEM;
  2009. rd_eeprom.offset = cpu_to_le16((u16) offset);
  2010. rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
  2011. status = mwifiex_reg_mem_ioctl_read_eeprom(priv, wait, &rd_eeprom);
  2012. ret = mwifiex_request_ioctl(priv, wait, status, MWIFIEX_IOCTL_WAIT);
  2013. if (ret)
  2014. goto done;
  2015. memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
  2016. done:
  2017. kfree(wait);
  2018. return ret;
  2019. }
  2020. /*
  2021. * This function sets a generic IE. In addition to generic IE, it can
  2022. * also handle WPA, WPA2 and WAPI IEs.
  2023. */
  2024. static int
  2025. mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
  2026. u16 ie_len)
  2027. {
  2028. int ret = 0;
  2029. struct ieee_types_vendor_header *pvendor_ie;
  2030. const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
  2031. const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
  2032. /* If the passed length is zero, reset the buffer */
  2033. if (!ie_len) {
  2034. priv->gen_ie_buf_len = 0;
  2035. priv->wps.session_enable = false;
  2036. return 0;
  2037. } else if (!ie_data_ptr) {
  2038. return -1;
  2039. }
  2040. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  2041. /* Test to see if it is a WPA IE, if not, then it is a gen IE */
  2042. if (((pvendor_ie->element_id == WLAN_EID_WPA)
  2043. && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
  2044. || (pvendor_ie->element_id == WLAN_EID_RSN)) {
  2045. /* IE is a WPA/WPA2 IE so call set_wpa function */
  2046. ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
  2047. priv->wps.session_enable = false;
  2048. return ret;
  2049. } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
  2050. /* IE is a WAPI IE so call set_wapi function */
  2051. ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
  2052. return ret;
  2053. }
  2054. /*
  2055. * Verify that the passed length is not larger than the
  2056. * available space remaining in the buffer
  2057. */
  2058. if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
  2059. /* Test to see if it is a WPS IE, if so, enable
  2060. * wps session flag
  2061. */
  2062. pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
  2063. if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
  2064. && (!memcmp(pvendor_ie->oui, wps_oui,
  2065. sizeof(wps_oui)))) {
  2066. priv->wps.session_enable = true;
  2067. dev_dbg(priv->adapter->dev,
  2068. "info: WPS Session Enabled.\n");
  2069. }
  2070. /* Append the passed data to the end of the
  2071. genIeBuffer */
  2072. memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
  2073. ie_len);
  2074. /* Increment the stored buffer length by the
  2075. size passed */
  2076. priv->gen_ie_buf_len += ie_len;
  2077. } else {
  2078. /* Passed data does not fit in the remaining
  2079. buffer space */
  2080. ret = -1;
  2081. }
  2082. /* Return 0, or -1 for error case */
  2083. return ret;
  2084. }
  2085. /*
  2086. * IOCTL request handler to set/get generic IE.
  2087. *
  2088. * In addition to various generic IEs, this function can also be
  2089. * used to set the ARP filter.
  2090. */
  2091. static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
  2092. struct mwifiex_ds_misc_gen_ie *gen_ie,
  2093. u16 action)
  2094. {
  2095. struct mwifiex_adapter *adapter = priv->adapter;
  2096. switch (gen_ie->type) {
  2097. case MWIFIEX_IE_TYPE_GEN_IE:
  2098. if (action == HostCmd_ACT_GEN_GET) {
  2099. gen_ie->len = priv->wpa_ie_len;
  2100. memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
  2101. } else {
  2102. mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
  2103. (u16) gen_ie->len);
  2104. }
  2105. break;
  2106. case MWIFIEX_IE_TYPE_ARP_FILTER:
  2107. memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
  2108. if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
  2109. adapter->arp_filter_size = 0;
  2110. dev_err(adapter->dev, "invalid ARP filter size\n");
  2111. return -1;
  2112. } else {
  2113. memcpy(adapter->arp_filter, gen_ie->ie_data,
  2114. gen_ie->len);
  2115. adapter->arp_filter_size = gen_ie->len;
  2116. }
  2117. break;
  2118. default:
  2119. dev_err(adapter->dev, "invalid IE type\n");
  2120. return -1;
  2121. }
  2122. return 0;
  2123. }
  2124. /*
  2125. * Sends IOCTL request to set a generic IE.
  2126. *
  2127. * This function allocates the IOCTL request buffer, fills it
  2128. * with requisite parameters and calls the IOCTL handler.
  2129. */
  2130. int
  2131. mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
  2132. {
  2133. struct mwifiex_ds_misc_gen_ie gen_ie;
  2134. int status = 0;
  2135. if (ie_len > IW_CUSTOM_MAX)
  2136. return -EFAULT;
  2137. gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
  2138. gen_ie.len = ie_len;
  2139. memcpy(gen_ie.ie_data, ie, ie_len);
  2140. status = mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET);
  2141. if (status)
  2142. return -EFAULT;
  2143. return 0;
  2144. }