cfg80211.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. /*
  2. * Marvell Wireless LAN device driver: CFG80211
  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 "cfg80211.h"
  20. #include "main.h"
  21. /*
  22. * This function maps the nl802.11 channel type into driver channel type.
  23. *
  24. * The mapping is as follows -
  25. * NL80211_CHAN_NO_HT -> NO_SEC_CHANNEL
  26. * NL80211_CHAN_HT20 -> NO_SEC_CHANNEL
  27. * NL80211_CHAN_HT40PLUS -> SEC_CHANNEL_ABOVE
  28. * NL80211_CHAN_HT40MINUS -> SEC_CHANNEL_BELOW
  29. * Others -> NO_SEC_CHANNEL
  30. */
  31. static int
  32. mwifiex_cfg80211_channel_type_to_mwifiex_channels(enum nl80211_channel_type
  33. channel_type)
  34. {
  35. int channel;
  36. switch (channel_type) {
  37. case NL80211_CHAN_NO_HT:
  38. case NL80211_CHAN_HT20:
  39. channel = NO_SEC_CHANNEL;
  40. break;
  41. case NL80211_CHAN_HT40PLUS:
  42. channel = SEC_CHANNEL_ABOVE;
  43. break;
  44. case NL80211_CHAN_HT40MINUS:
  45. channel = SEC_CHANNEL_BELOW;
  46. break;
  47. default:
  48. channel = NO_SEC_CHANNEL;
  49. }
  50. return channel;
  51. }
  52. /*
  53. * This function maps the driver channel type into nl802.11 channel type.
  54. *
  55. * The mapping is as follows -
  56. * NO_SEC_CHANNEL -> NL80211_CHAN_HT20
  57. * SEC_CHANNEL_ABOVE -> NL80211_CHAN_HT40PLUS
  58. * SEC_CHANNEL_BELOW -> NL80211_CHAN_HT40MINUS
  59. * Others -> NL80211_CHAN_HT20
  60. */
  61. static enum nl80211_channel_type
  62. mwifiex_channels_to_cfg80211_channel_type(int channel_type)
  63. {
  64. int channel;
  65. switch (channel_type) {
  66. case NO_SEC_CHANNEL:
  67. channel = NL80211_CHAN_HT20;
  68. break;
  69. case SEC_CHANNEL_ABOVE:
  70. channel = NL80211_CHAN_HT40PLUS;
  71. break;
  72. case SEC_CHANNEL_BELOW:
  73. channel = NL80211_CHAN_HT40MINUS;
  74. break;
  75. default:
  76. channel = NL80211_CHAN_HT20;
  77. }
  78. return channel;
  79. }
  80. /*
  81. * This function checks whether WEP is set.
  82. */
  83. static int
  84. mwifiex_is_alg_wep(u32 cipher)
  85. {
  86. int alg = 0;
  87. switch (cipher) {
  88. case WLAN_CIPHER_SUITE_WEP40:
  89. case WLAN_CIPHER_SUITE_WEP104:
  90. alg = 1;
  91. break;
  92. default:
  93. alg = 0;
  94. break;
  95. }
  96. return alg;
  97. }
  98. /*
  99. * This function retrieves the private structure from kernel wiphy structure.
  100. */
  101. static void *mwifiex_cfg80211_get_priv(struct wiphy *wiphy)
  102. {
  103. return (void *) (*(unsigned long *) wiphy_priv(wiphy));
  104. }
  105. /*
  106. * CFG802.11 operation handler to delete a network key.
  107. */
  108. static int
  109. mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
  110. u8 key_index, bool pairwise, const u8 *mac_addr)
  111. {
  112. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  113. int ret = 0;
  114. ret = mwifiex_set_encode(priv, NULL, 0, key_index, 1);
  115. if (ret) {
  116. wiphy_err(wiphy, "deleting the crypto keys\n");
  117. return -EFAULT;
  118. }
  119. wiphy_dbg(wiphy, "info: crypto keys deleted\n");
  120. return 0;
  121. }
  122. /*
  123. * CFG802.11 operation handler to set Tx power.
  124. */
  125. static int
  126. mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
  127. enum nl80211_tx_power_setting type,
  128. int dbm)
  129. {
  130. int ret = 0;
  131. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  132. ret = mwifiex_set_tx_power(priv, type, dbm);
  133. return ret;
  134. }
  135. /*
  136. * CFG802.11 operation handler to set Power Save option.
  137. *
  138. * The timeout value, if provided, is currently ignored.
  139. */
  140. static int
  141. mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  142. struct net_device *dev,
  143. bool enabled, int timeout)
  144. {
  145. int ret = 0;
  146. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  147. if (timeout)
  148. wiphy_dbg(wiphy,
  149. "info: ignoring the timeout value"
  150. " for IEEE power save\n");
  151. ret = mwifiex_drv_set_power(priv, enabled);
  152. return ret;
  153. }
  154. /*
  155. * CFG802.11 operation handler to set the default network key.
  156. */
  157. static int
  158. mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  159. u8 key_index, bool unicast,
  160. bool multicast)
  161. {
  162. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  163. int ret;
  164. /* Return if WEP key not configured */
  165. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED)
  166. return 0;
  167. ret = mwifiex_set_encode(priv, NULL, 0, key_index, 0);
  168. wiphy_dbg(wiphy, "info: set default Tx key index\n");
  169. if (ret)
  170. return -EFAULT;
  171. return 0;
  172. }
  173. /*
  174. * CFG802.11 operation handler to add a network key.
  175. */
  176. static int
  177. mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
  178. u8 key_index, bool pairwise, const u8 *mac_addr,
  179. struct key_params *params)
  180. {
  181. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  182. int ret = 0;
  183. ret = mwifiex_set_encode(priv, params->key, params->key_len,
  184. key_index, 0);
  185. wiphy_dbg(wiphy, "info: crypto keys added\n");
  186. if (ret)
  187. return -EFAULT;
  188. return 0;
  189. }
  190. /*
  191. * This function sends domain information to the firmware.
  192. *
  193. * The following information are passed to the firmware -
  194. * - Country codes
  195. * - Sub bands (first channel, number of channels, maximum Tx power)
  196. */
  197. static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
  198. {
  199. u8 no_of_triplet = 0;
  200. struct ieee80211_country_ie_triplet *t;
  201. u8 no_of_parsed_chan = 0;
  202. u8 first_chan = 0, next_chan = 0, max_pwr = 0;
  203. u8 i, flag = 0;
  204. enum ieee80211_band band;
  205. struct ieee80211_supported_band *sband;
  206. struct ieee80211_channel *ch;
  207. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  208. struct mwifiex_adapter *adapter = priv->adapter;
  209. struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
  210. int ret = 0;
  211. /* Set country code */
  212. domain_info->country_code[0] = priv->country_code[0];
  213. domain_info->country_code[1] = priv->country_code[1];
  214. domain_info->country_code[2] = ' ';
  215. band = mwifiex_band_to_radio_type(adapter->config_bands);
  216. if (!wiphy->bands[band]) {
  217. wiphy_err(wiphy, "11D: setting domain info in FW\n");
  218. return -1;
  219. }
  220. sband = wiphy->bands[band];
  221. for (i = 0; i < sband->n_channels ; i++) {
  222. ch = &sband->channels[i];
  223. if (ch->flags & IEEE80211_CHAN_DISABLED)
  224. continue;
  225. if (!flag) {
  226. flag = 1;
  227. first_chan = (u32) ch->hw_value;
  228. next_chan = first_chan;
  229. max_pwr = ch->max_power;
  230. no_of_parsed_chan = 1;
  231. continue;
  232. }
  233. if (ch->hw_value == next_chan + 1 &&
  234. ch->max_power == max_pwr) {
  235. next_chan++;
  236. no_of_parsed_chan++;
  237. } else {
  238. t = &domain_info->triplet[no_of_triplet];
  239. t->chans.first_channel = first_chan;
  240. t->chans.num_channels = no_of_parsed_chan;
  241. t->chans.max_power = max_pwr;
  242. no_of_triplet++;
  243. first_chan = (u32) ch->hw_value;
  244. next_chan = first_chan;
  245. max_pwr = ch->max_power;
  246. no_of_parsed_chan = 1;
  247. }
  248. }
  249. if (flag) {
  250. t = &domain_info->triplet[no_of_triplet];
  251. t->chans.first_channel = first_chan;
  252. t->chans.num_channels = no_of_parsed_chan;
  253. t->chans.max_power = max_pwr;
  254. no_of_triplet++;
  255. }
  256. domain_info->no_of_triplet = no_of_triplet;
  257. /* Send cmd to FW to set domain info */
  258. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
  259. HostCmd_ACT_GEN_SET, 0, NULL, NULL);
  260. if (ret)
  261. wiphy_err(wiphy, "11D: setting domain info in FW\n");
  262. return ret;
  263. }
  264. /*
  265. * CFG802.11 regulatory domain callback function.
  266. *
  267. * This function is called when the regulatory domain is changed due to the
  268. * following reasons -
  269. * - Set by driver
  270. * - Set by system core
  271. * - Set by user
  272. * - Set bt Country IE
  273. */
  274. static int mwifiex_reg_notifier(struct wiphy *wiphy,
  275. struct regulatory_request *request)
  276. {
  277. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  278. wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for domain"
  279. " %c%c\n", request->alpha2[0], request->alpha2[1]);
  280. memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2));
  281. switch (request->initiator) {
  282. case NL80211_REGDOM_SET_BY_DRIVER:
  283. case NL80211_REGDOM_SET_BY_CORE:
  284. case NL80211_REGDOM_SET_BY_USER:
  285. break;
  286. /* Todo: apply driver specific changes in channel flags based
  287. on the request initiator if necessary. */
  288. case NL80211_REGDOM_SET_BY_COUNTRY_IE:
  289. break;
  290. }
  291. mwifiex_send_domain_info_cmd_fw(wiphy);
  292. return 0;
  293. }
  294. /*
  295. * This function sets the RF channel.
  296. *
  297. * This function creates multiple IOCTL requests, populates them accordingly
  298. * and issues them to set the band/channel and frequency.
  299. */
  300. static int
  301. mwifiex_set_rf_channel(struct mwifiex_private *priv,
  302. struct ieee80211_channel *chan,
  303. enum nl80211_channel_type channel_type)
  304. {
  305. struct mwifiex_chan_freq_power cfp;
  306. int ret = 0;
  307. int status = 0;
  308. struct mwifiex_ds_band_cfg band_cfg;
  309. u32 config_bands = 0;
  310. struct wiphy *wiphy = priv->wdev->wiphy;
  311. if (chan) {
  312. memset(&band_cfg, 0, sizeof(band_cfg));
  313. /* Set appropriate bands */
  314. if (chan->band == IEEE80211_BAND_2GHZ)
  315. config_bands = BAND_B | BAND_G | BAND_GN;
  316. else
  317. config_bands = BAND_AN | BAND_A;
  318. if (priv->bss_mode == NL80211_IFTYPE_STATION
  319. || priv->bss_mode == NL80211_IFTYPE_UNSPECIFIED) {
  320. band_cfg.config_bands = config_bands;
  321. } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  322. band_cfg.config_bands = config_bands;
  323. band_cfg.adhoc_start_band = config_bands;
  324. }
  325. /* Set channel offset */
  326. band_cfg.sec_chan_offset =
  327. mwifiex_cfg80211_channel_type_to_mwifiex_channels
  328. (channel_type);
  329. status = mwifiex_radio_ioctl_band_cfg(priv, HostCmd_ACT_GEN_SET,
  330. &band_cfg);
  331. if (status)
  332. return -EFAULT;
  333. mwifiex_send_domain_info_cmd_fw(wiphy);
  334. }
  335. wiphy_dbg(wiphy, "info: setting band %d, channel offset %d and "
  336. "mode %d\n", config_bands, band_cfg.sec_chan_offset,
  337. priv->bss_mode);
  338. if (!chan)
  339. return ret;
  340. memset(&cfp, 0, sizeof(cfp));
  341. cfp.freq = chan->center_freq;
  342. /* Convert frequency to channel */
  343. cfp.channel = ieee80211_frequency_to_channel(chan->center_freq);
  344. status = mwifiex_bss_ioctl_channel(priv, HostCmd_ACT_GEN_SET, &cfp);
  345. if (status)
  346. return -EFAULT;
  347. ret = mwifiex_drv_change_adhoc_chan(priv, cfp.channel);
  348. return ret;
  349. }
  350. /*
  351. * CFG802.11 operation handler to set channel.
  352. *
  353. * This function can only be used when station is not connected.
  354. */
  355. static int
  356. mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev,
  357. struct ieee80211_channel *chan,
  358. enum nl80211_channel_type channel_type)
  359. {
  360. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  361. if (priv->media_connected) {
  362. wiphy_err(wiphy, "This setting is valid only when station "
  363. "is not connected\n");
  364. return -EINVAL;
  365. }
  366. return mwifiex_set_rf_channel(priv, chan, channel_type);
  367. }
  368. /*
  369. * This function sets the fragmentation threshold.
  370. *
  371. * This function creates an IOCTL request, populates it accordingly
  372. * and issues an IOCTL.
  373. *
  374. * The fragmentation threshold value must lies between MWIFIEX_FRAG_MIN_VALUE
  375. * and MWIFIEX_FRAG_MAX_VALUE.
  376. */
  377. static int
  378. mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
  379. {
  380. int ret = 0;
  381. int status = 0;
  382. struct mwifiex_wait_queue *wait = NULL;
  383. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  384. if (frag_thr < MWIFIEX_FRAG_MIN_VALUE
  385. || frag_thr > MWIFIEX_FRAG_MAX_VALUE)
  386. return -EINVAL;
  387. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  388. if (!wait)
  389. return -ENOMEM;
  390. status = mwifiex_snmp_mib_ioctl(priv, wait, FRAG_THRESH_I,
  391. HostCmd_ACT_GEN_SET, &frag_thr);
  392. if (mwifiex_request_ioctl(priv, wait, status, wait_option))
  393. ret = -EFAULT;
  394. kfree(wait);
  395. return ret;
  396. }
  397. /*
  398. * This function sets the RTS threshold.
  399. *
  400. * This function creates an IOCTL request, populates it accordingly
  401. * and issues an IOCTL.
  402. */
  403. static int
  404. mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
  405. {
  406. int ret = 0;
  407. struct mwifiex_wait_queue *wait = NULL;
  408. int status = 0;
  409. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  410. if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
  411. rts_thr = MWIFIEX_RTS_MAX_VALUE;
  412. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  413. if (!wait)
  414. return -ENOMEM;
  415. status = mwifiex_snmp_mib_ioctl(priv, wait, RTS_THRESH_I,
  416. HostCmd_ACT_GEN_SET, &rts_thr);
  417. if (mwifiex_request_ioctl(priv, wait, status, wait_option))
  418. ret = -EFAULT;
  419. kfree(wait);
  420. return ret;
  421. }
  422. /*
  423. * CFG802.11 operation handler to set wiphy parameters.
  424. *
  425. * This function can be used to set the RTS threshold and the
  426. * Fragmentation threshold of the driver.
  427. */
  428. static int
  429. mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  430. {
  431. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  432. int ret = 0;
  433. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  434. ret = mwifiex_set_rts(priv, wiphy->rts_threshold);
  435. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  436. ret = mwifiex_set_frag(priv, wiphy->frag_threshold);
  437. return ret;
  438. }
  439. /*
  440. * CFG802.11 operation handler to change interface type.
  441. */
  442. static int
  443. mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
  444. struct net_device *dev,
  445. enum nl80211_iftype type, u32 *flags,
  446. struct vif_params *params)
  447. {
  448. int ret = 0;
  449. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  450. struct mwifiex_wait_queue *wait = NULL;
  451. if (priv->bss_mode == type) {
  452. wiphy_warn(wiphy, "already set to required type\n");
  453. return 0;
  454. }
  455. priv->bss_mode = type;
  456. switch (type) {
  457. case NL80211_IFTYPE_ADHOC:
  458. dev->ieee80211_ptr->iftype = NL80211_IFTYPE_ADHOC;
  459. wiphy_dbg(wiphy, "info: setting interface type to adhoc\n");
  460. break;
  461. case NL80211_IFTYPE_STATION:
  462. dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
  463. wiphy_dbg(wiphy, "info: setting interface type to managed\n");
  464. break;
  465. case NL80211_IFTYPE_UNSPECIFIED:
  466. dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
  467. wiphy_dbg(wiphy, "info: setting interface type to auto\n");
  468. return 0;
  469. default:
  470. wiphy_err(wiphy, "unknown interface type: %d\n", type);
  471. return -EINVAL;
  472. }
  473. wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
  474. if (!wait)
  475. return -ENOMEM;
  476. mwifiex_deauthenticate(priv, wait, NULL);
  477. priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
  478. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  479. HostCmd_ACT_GEN_SET, 0, wait, NULL);
  480. if (!ret)
  481. ret = -EINPROGRESS;
  482. ret = mwifiex_request_ioctl(priv, wait, ret, MWIFIEX_IOCTL_WAIT);
  483. if (ret)
  484. ret = -EFAULT;
  485. kfree(wait);
  486. return ret;
  487. }
  488. /*
  489. * This function dumps the station information on a buffer.
  490. *
  491. * The following information are shown -
  492. * - Total bytes transmitted
  493. * - Total bytes received
  494. * - Total packets transmitted
  495. * - Total packets received
  496. * - Signal quality level
  497. * - Transmission rate
  498. */
  499. static int
  500. mwifiex_dump_station_info(struct mwifiex_private *priv,
  501. struct station_info *sinfo)
  502. {
  503. struct mwifiex_ds_get_signal signal;
  504. struct mwifiex_rate_cfg rate;
  505. int ret = 0;
  506. sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
  507. STATION_INFO_RX_PACKETS |
  508. STATION_INFO_TX_PACKETS
  509. | STATION_INFO_SIGNAL | STATION_INFO_TX_BITRATE;
  510. /* Get signal information from the firmware */
  511. memset(&signal, 0, sizeof(struct mwifiex_ds_get_signal));
  512. if (mwifiex_get_signal_info(priv, MWIFIEX_IOCTL_WAIT, &signal)) {
  513. dev_err(priv->adapter->dev, "getting signal information\n");
  514. ret = -EFAULT;
  515. }
  516. if (mwifiex_drv_get_data_rate(priv, &rate)) {
  517. dev_err(priv->adapter->dev, "getting data rate\n");
  518. ret = -EFAULT;
  519. }
  520. sinfo->rx_bytes = priv->stats.rx_bytes;
  521. sinfo->tx_bytes = priv->stats.tx_bytes;
  522. sinfo->rx_packets = priv->stats.rx_packets;
  523. sinfo->tx_packets = priv->stats.tx_packets;
  524. sinfo->signal = priv->w_stats.qual.level;
  525. sinfo->txrate.legacy = rate.rate;
  526. return ret;
  527. }
  528. /*
  529. * CFG802.11 operation handler to get station information.
  530. *
  531. * This function only works in connected mode, and dumps the
  532. * requested station information, if available.
  533. */
  534. static int
  535. mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  536. u8 *mac, struct station_info *sinfo)
  537. {
  538. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  539. int ret = 0;
  540. mwifiex_dump_station_info(priv, sinfo);
  541. if (!priv->media_connected)
  542. return -ENOENT;
  543. if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
  544. return -ENOENT;
  545. ret = mwifiex_dump_station_info(priv, sinfo);
  546. return ret;
  547. }
  548. /* Supported rates to be advertised to the cfg80211 */
  549. static struct ieee80211_rate mwifiex_rates[] = {
  550. {.bitrate = 10, .hw_value = 2, },
  551. {.bitrate = 20, .hw_value = 4, },
  552. {.bitrate = 55, .hw_value = 11, },
  553. {.bitrate = 110, .hw_value = 22, },
  554. {.bitrate = 220, .hw_value = 44, },
  555. {.bitrate = 60, .hw_value = 12, },
  556. {.bitrate = 90, .hw_value = 18, },
  557. {.bitrate = 120, .hw_value = 24, },
  558. {.bitrate = 180, .hw_value = 36, },
  559. {.bitrate = 240, .hw_value = 48, },
  560. {.bitrate = 360, .hw_value = 72, },
  561. {.bitrate = 480, .hw_value = 96, },
  562. {.bitrate = 540, .hw_value = 108, },
  563. {.bitrate = 720, .hw_value = 144, },
  564. };
  565. /* Channel definitions to be advertised to cfg80211 */
  566. static struct ieee80211_channel mwifiex_channels_2ghz[] = {
  567. {.center_freq = 2412, .hw_value = 1, },
  568. {.center_freq = 2417, .hw_value = 2, },
  569. {.center_freq = 2422, .hw_value = 3, },
  570. {.center_freq = 2427, .hw_value = 4, },
  571. {.center_freq = 2432, .hw_value = 5, },
  572. {.center_freq = 2437, .hw_value = 6, },
  573. {.center_freq = 2442, .hw_value = 7, },
  574. {.center_freq = 2447, .hw_value = 8, },
  575. {.center_freq = 2452, .hw_value = 9, },
  576. {.center_freq = 2457, .hw_value = 10, },
  577. {.center_freq = 2462, .hw_value = 11, },
  578. {.center_freq = 2467, .hw_value = 12, },
  579. {.center_freq = 2472, .hw_value = 13, },
  580. {.center_freq = 2484, .hw_value = 14, },
  581. };
  582. static struct ieee80211_supported_band mwifiex_band_2ghz = {
  583. .channels = mwifiex_channels_2ghz,
  584. .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
  585. .bitrates = mwifiex_rates,
  586. .n_bitrates = 14,
  587. };
  588. static struct ieee80211_channel mwifiex_channels_5ghz[] = {
  589. {.center_freq = 5040, .hw_value = 8, },
  590. {.center_freq = 5060, .hw_value = 12, },
  591. {.center_freq = 5080, .hw_value = 16, },
  592. {.center_freq = 5170, .hw_value = 34, },
  593. {.center_freq = 5190, .hw_value = 38, },
  594. {.center_freq = 5210, .hw_value = 42, },
  595. {.center_freq = 5230, .hw_value = 46, },
  596. {.center_freq = 5180, .hw_value = 36, },
  597. {.center_freq = 5200, .hw_value = 40, },
  598. {.center_freq = 5220, .hw_value = 44, },
  599. {.center_freq = 5240, .hw_value = 48, },
  600. {.center_freq = 5260, .hw_value = 52, },
  601. {.center_freq = 5280, .hw_value = 56, },
  602. {.center_freq = 5300, .hw_value = 60, },
  603. {.center_freq = 5320, .hw_value = 64, },
  604. {.center_freq = 5500, .hw_value = 100, },
  605. {.center_freq = 5520, .hw_value = 104, },
  606. {.center_freq = 5540, .hw_value = 108, },
  607. {.center_freq = 5560, .hw_value = 112, },
  608. {.center_freq = 5580, .hw_value = 116, },
  609. {.center_freq = 5600, .hw_value = 120, },
  610. {.center_freq = 5620, .hw_value = 124, },
  611. {.center_freq = 5640, .hw_value = 128, },
  612. {.center_freq = 5660, .hw_value = 132, },
  613. {.center_freq = 5680, .hw_value = 136, },
  614. {.center_freq = 5700, .hw_value = 140, },
  615. {.center_freq = 5745, .hw_value = 149, },
  616. {.center_freq = 5765, .hw_value = 153, },
  617. {.center_freq = 5785, .hw_value = 157, },
  618. {.center_freq = 5805, .hw_value = 161, },
  619. {.center_freq = 5825, .hw_value = 165, },
  620. };
  621. static struct ieee80211_supported_band mwifiex_band_5ghz = {
  622. .channels = mwifiex_channels_5ghz,
  623. .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
  624. .bitrates = mwifiex_rates - 4,
  625. .n_bitrates = ARRAY_SIZE(mwifiex_rates) + 4,
  626. };
  627. /* Supported crypto cipher suits to be advertised to cfg80211 */
  628. static const u32 mwifiex_cipher_suites[] = {
  629. WLAN_CIPHER_SUITE_WEP40,
  630. WLAN_CIPHER_SUITE_WEP104,
  631. WLAN_CIPHER_SUITE_TKIP,
  632. WLAN_CIPHER_SUITE_CCMP,
  633. };
  634. /*
  635. * CFG802.11 operation handler for disconnection request.
  636. *
  637. * This function does not work when there is already a disconnection
  638. * procedure going on.
  639. */
  640. static int
  641. mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
  642. u16 reason_code)
  643. {
  644. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  645. if (priv->disconnect)
  646. return -EBUSY;
  647. priv->disconnect = 1;
  648. if (mwifiex_disconnect(priv, MWIFIEX_IOCTL_WAIT, NULL))
  649. return -EFAULT;
  650. wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
  651. " reason code %d\n", priv->cfg_bssid, reason_code);
  652. queue_work(priv->workqueue, &priv->cfg_workqueue);
  653. return 0;
  654. }
  655. /*
  656. * This function informs the CFG802.11 subsystem of a new IBSS.
  657. *
  658. * The following information are sent to the CFG802.11 subsystem
  659. * to register the new IBSS. If we do not register the new IBSS,
  660. * a kernel panic will result.
  661. * - SSID
  662. * - SSID length
  663. * - BSSID
  664. * - Channel
  665. */
  666. static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
  667. {
  668. int ret = 0;
  669. struct ieee80211_channel *chan;
  670. struct mwifiex_bss_info bss_info;
  671. int ie_len = 0;
  672. u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
  673. ret = mwifiex_get_bss_info(priv, &bss_info);
  674. if (ret)
  675. return ret;
  676. ie_buf[0] = WLAN_EID_SSID;
  677. ie_buf[1] = bss_info.ssid.ssid_len;
  678. memcpy(&ie_buf[sizeof(struct ieee_types_header)],
  679. &bss_info.ssid.ssid,
  680. bss_info.ssid.ssid_len);
  681. ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
  682. chan = __ieee80211_get_channel(priv->wdev->wiphy,
  683. ieee80211_channel_to_frequency(bss_info.bss_chan,
  684. priv->curr_bss_params.band));
  685. cfg80211_inform_bss(priv->wdev->wiphy, chan,
  686. bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
  687. 0, ie_buf, ie_len, 0, GFP_KERNEL);
  688. memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
  689. return ret;
  690. }
  691. /*
  692. * This function informs the CFG802.11 subsystem of a new BSS connection.
  693. *
  694. * The following information are sent to the CFG802.11 subsystem
  695. * to register the new BSS connection. If we do not register the new BSS,
  696. * a kernel panic will result.
  697. * - MAC address
  698. * - Capabilities
  699. * - Beacon period
  700. * - RSSI value
  701. * - Channel
  702. * - Supported rates IE
  703. * - Extended capabilities IE
  704. * - DS parameter set IE
  705. * - HT Capability IE
  706. * - Vendor Specific IE (221)
  707. * - WPA IE
  708. * - RSN IE
  709. */
  710. static int mwifiex_inform_bss_from_scan_result(struct mwifiex_private *priv,
  711. struct mwifiex_802_11_ssid *ssid)
  712. {
  713. struct mwifiex_scan_resp scan_resp;
  714. struct mwifiex_bssdescriptor *scan_table;
  715. int i, j;
  716. struct ieee80211_channel *chan;
  717. u8 *ie, *tmp, *ie_buf;
  718. u32 ie_len;
  719. u64 ts = 0;
  720. u8 *beacon;
  721. int beacon_size;
  722. u8 element_id, element_len;
  723. memset(&scan_resp, 0, sizeof(scan_resp));
  724. if (mwifiex_get_scan_table(priv, MWIFIEX_IOCTL_WAIT, &scan_resp))
  725. return -EFAULT;
  726. #define MAX_IE_BUF 2048
  727. ie_buf = kzalloc(MAX_IE_BUF, GFP_KERNEL);
  728. if (!ie_buf) {
  729. dev_err(priv->adapter->dev, "%s: failed to alloc ie_buf\n",
  730. __func__);
  731. return -ENOMEM;
  732. }
  733. scan_table = (struct mwifiex_bssdescriptor *) scan_resp.scan_table;
  734. for (i = 0; i < scan_resp.num_in_scan_table; i++) {
  735. if (ssid) {
  736. /* Inform specific BSS only */
  737. if (memcmp(ssid->ssid, scan_table[i].ssid.ssid,
  738. ssid->ssid_len))
  739. continue;
  740. }
  741. memset(ie_buf, 0, MAX_IE_BUF);
  742. ie_buf[0] = WLAN_EID_SSID;
  743. ie_buf[1] = scan_table[i].ssid.ssid_len;
  744. memcpy(&ie_buf[sizeof(struct ieee_types_header)],
  745. scan_table[i].ssid.ssid, ie_buf[1]);
  746. ie = ie_buf + ie_buf[1] + sizeof(struct ieee_types_header);
  747. ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
  748. ie[0] = WLAN_EID_SUPP_RATES;
  749. for (j = 0; j < sizeof(scan_table[i].supported_rates); j++) {
  750. if (!scan_table[i].supported_rates[j])
  751. break;
  752. else
  753. ie[j + sizeof(struct ieee_types_header)] =
  754. scan_table[i].supported_rates[j];
  755. }
  756. ie[1] = j;
  757. ie_len += ie[1] + sizeof(struct ieee_types_header);
  758. beacon = scan_table[i].beacon_buf;
  759. beacon_size = scan_table[i].beacon_buf_size;
  760. /* Skip time stamp, beacon interval and capability */
  761. if (beacon) {
  762. beacon += sizeof(scan_table[i].beacon_period)
  763. + sizeof(scan_table[i].time_stamp) +
  764. +sizeof(scan_table[i].cap_info_bitmap);
  765. beacon_size -= sizeof(scan_table[i].beacon_period)
  766. + sizeof(scan_table[i].time_stamp)
  767. + sizeof(scan_table[i].cap_info_bitmap);
  768. }
  769. while (beacon_size >= sizeof(struct ieee_types_header)) {
  770. ie = ie_buf + ie_len;
  771. element_id = *beacon;
  772. element_len = *(beacon + 1);
  773. if (beacon_size < (int) element_len +
  774. sizeof(struct ieee_types_header)) {
  775. dev_err(priv->adapter->dev, "%s: in processing"
  776. " IE, bytes left < IE length\n",
  777. __func__);
  778. break;
  779. }
  780. switch (element_id) {
  781. case WLAN_EID_EXT_CAPABILITY:
  782. case WLAN_EID_DS_PARAMS:
  783. case WLAN_EID_HT_CAPABILITY:
  784. case WLAN_EID_VENDOR_SPECIFIC:
  785. case WLAN_EID_RSN:
  786. case WLAN_EID_BSS_AC_ACCESS_DELAY:
  787. ie[0] = element_id;
  788. ie[1] = element_len;
  789. tmp = (u8 *) beacon;
  790. memcpy(&ie[sizeof(struct ieee_types_header)],
  791. tmp + sizeof(struct ieee_types_header),
  792. element_len);
  793. ie_len += ie[1] +
  794. sizeof(struct ieee_types_header);
  795. break;
  796. default:
  797. break;
  798. }
  799. beacon += element_len +
  800. sizeof(struct ieee_types_header);
  801. beacon_size -= element_len +
  802. sizeof(struct ieee_types_header);
  803. }
  804. chan = ieee80211_get_channel(priv->wdev->wiphy,
  805. scan_table[i].freq);
  806. cfg80211_inform_bss(priv->wdev->wiphy, chan,
  807. scan_table[i].mac_address,
  808. ts, scan_table[i].cap_info_bitmap,
  809. scan_table[i].beacon_period,
  810. ie_buf, ie_len,
  811. scan_table[i].rssi, GFP_KERNEL);
  812. }
  813. kfree(ie_buf);
  814. return 0;
  815. }
  816. /*
  817. * This function connects with a BSS.
  818. *
  819. * This function handles both Infra and Ad-Hoc modes. It also performs
  820. * validity checking on the provided parameters, disconnects from the
  821. * current BSS (if any), sets up the association/scan parameters,
  822. * including security settings, and performs specific SSID scan before
  823. * trying to connect.
  824. *
  825. * For Infra mode, the function returns failure if the specified SSID
  826. * is not found in scan table. However, for Ad-Hoc mode, it can create
  827. * the IBSS if it does not exist. On successful completion in either case,
  828. * the function notifies the CFG802.11 subsystem of the new BSS connection,
  829. * otherwise the kernel will panic.
  830. */
  831. static int
  832. mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
  833. u8 *bssid, int mode, struct ieee80211_channel *channel,
  834. struct cfg80211_connect_params *sme, bool privacy)
  835. {
  836. struct mwifiex_802_11_ssid req_ssid;
  837. struct mwifiex_ssid_bssid ssid_bssid;
  838. int ret = 0;
  839. int auth_type = 0, pairwise_encrypt_mode = 0;
  840. int group_encrypt_mode = 0;
  841. int alg_is_wep = 0;
  842. memset(&req_ssid, 0, sizeof(struct mwifiex_802_11_ssid));
  843. memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
  844. req_ssid.ssid_len = ssid_len;
  845. if (ssid_len > IEEE80211_MAX_SSID_LEN) {
  846. dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
  847. return -EINVAL;
  848. }
  849. memcpy(req_ssid.ssid, ssid, ssid_len);
  850. if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
  851. dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
  852. return -EINVAL;
  853. }
  854. /* disconnect before try to associate */
  855. mwifiex_disconnect(priv, MWIFIEX_IOCTL_WAIT, NULL);
  856. if (channel)
  857. ret = mwifiex_set_rf_channel(priv, channel,
  858. mwifiex_channels_to_cfg80211_channel_type
  859. (priv->adapter->chan_offset));
  860. ret = mwifiex_set_encode(priv, NULL, 0, 0, 1); /* Disable keys */
  861. if (mode == NL80211_IFTYPE_ADHOC) {
  862. /* "privacy" is set only for ad-hoc mode */
  863. if (privacy) {
  864. /*
  865. * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
  866. * the firmware can find a matching network from the
  867. * scan. The cfg80211 does not give us the encryption
  868. * mode at this stage so just setting it to WEP here.
  869. */
  870. priv->sec_info.encryption_mode =
  871. WLAN_CIPHER_SUITE_WEP104;
  872. priv->sec_info.authentication_mode =
  873. NL80211_AUTHTYPE_OPEN_SYSTEM;
  874. }
  875. goto done;
  876. }
  877. /* Now handle infra mode. "sme" is valid for infra mode only */
  878. if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC
  879. || sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
  880. auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  881. else if (sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY)
  882. auth_type = NL80211_AUTHTYPE_SHARED_KEY;
  883. if (sme->crypto.n_ciphers_pairwise) {
  884. priv->sec_info.encryption_mode =
  885. sme->crypto.ciphers_pairwise[0];
  886. priv->sec_info.authentication_mode = auth_type;
  887. }
  888. if (sme->crypto.cipher_group) {
  889. priv->sec_info.encryption_mode = sme->crypto.cipher_group;
  890. priv->sec_info.authentication_mode = auth_type;
  891. }
  892. if (sme->ie)
  893. ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
  894. if (sme->key) {
  895. alg_is_wep = mwifiex_is_alg_wep(pairwise_encrypt_mode)
  896. | mwifiex_is_alg_wep(group_encrypt_mode);
  897. if (alg_is_wep) {
  898. dev_dbg(priv->adapter->dev,
  899. "info: setting wep encryption"
  900. " with key len %d\n", sme->key_len);
  901. ret = mwifiex_set_encode(priv, sme->key, sme->key_len,
  902. sme->key_idx, 0);
  903. }
  904. }
  905. done:
  906. /* Do specific SSID scanning */
  907. if (mwifiex_request_scan(priv, MWIFIEX_IOCTL_WAIT, &req_ssid)) {
  908. dev_err(priv->adapter->dev, "scan error\n");
  909. return -EFAULT;
  910. }
  911. memcpy(&ssid_bssid.ssid, &req_ssid, sizeof(struct mwifiex_802_11_ssid));
  912. if (mode != NL80211_IFTYPE_ADHOC) {
  913. if (mwifiex_find_best_bss(priv, MWIFIEX_IOCTL_WAIT,
  914. &ssid_bssid))
  915. return -EFAULT;
  916. /* Inform the BSS information to kernel, otherwise
  917. * kernel will give a panic after successful assoc */
  918. if (mwifiex_inform_bss_from_scan_result(priv, &req_ssid))
  919. return -EFAULT;
  920. }
  921. dev_dbg(priv->adapter->dev, "info: trying to associate to %s and bssid %pM\n",
  922. (char *) req_ssid.ssid, ssid_bssid.bssid);
  923. memcpy(&priv->cfg_bssid, ssid_bssid.bssid, 6);
  924. /* Connect to BSS by ESSID */
  925. memset(&ssid_bssid.bssid, 0, ETH_ALEN);
  926. if (mwifiex_bss_start(priv, MWIFIEX_IOCTL_WAIT, &ssid_bssid))
  927. return -EFAULT;
  928. if (mode == NL80211_IFTYPE_ADHOC) {
  929. /* Inform the BSS information to kernel, otherwise
  930. * kernel will give a panic after successful assoc */
  931. if (mwifiex_cfg80211_inform_ibss_bss(priv))
  932. return -EFAULT;
  933. }
  934. return ret;
  935. }
  936. /*
  937. * CFG802.11 operation handler for association request.
  938. *
  939. * This function does not work when the current mode is set to Ad-Hoc, or
  940. * when there is already an association procedure going on. The given BSS
  941. * information is used to associate.
  942. */
  943. static int
  944. mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  945. struct cfg80211_connect_params *sme)
  946. {
  947. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  948. int ret = 0;
  949. if (priv->assoc_request)
  950. return -EBUSY;
  951. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  952. wiphy_err(wiphy, "received infra assoc request "
  953. "when station is in ibss mode\n");
  954. goto done;
  955. }
  956. priv->assoc_request = 1;
  957. wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
  958. (char *) sme->ssid, sme->bssid);
  959. ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
  960. priv->bss_mode, sme->channel, sme, 0);
  961. done:
  962. priv->assoc_result = ret;
  963. queue_work(priv->workqueue, &priv->cfg_workqueue);
  964. return ret;
  965. }
  966. /*
  967. * CFG802.11 operation handler to join an IBSS.
  968. *
  969. * This function does not work in any mode other than Ad-Hoc, or if
  970. * a join operation is already in progress.
  971. */
  972. static int
  973. mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  974. struct cfg80211_ibss_params *params)
  975. {
  976. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  977. int ret = 0;
  978. if (priv->ibss_join_request)
  979. return -EBUSY;
  980. if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
  981. wiphy_err(wiphy, "request to join ibss received "
  982. "when station is not in ibss mode\n");
  983. goto done;
  984. }
  985. priv->ibss_join_request = 1;
  986. wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
  987. (char *) params->ssid, params->bssid);
  988. ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
  989. params->bssid, priv->bss_mode,
  990. params->channel, NULL, params->privacy);
  991. done:
  992. priv->ibss_join_result = ret;
  993. queue_work(priv->workqueue, &priv->cfg_workqueue);
  994. return ret;
  995. }
  996. /*
  997. * CFG802.11 operation handler to leave an IBSS.
  998. *
  999. * This function does not work if a leave operation is
  1000. * already in progress.
  1001. */
  1002. static int
  1003. mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1004. {
  1005. struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
  1006. if (priv->disconnect)
  1007. return -EBUSY;
  1008. priv->disconnect = 1;
  1009. wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
  1010. priv->cfg_bssid);
  1011. if (mwifiex_disconnect(priv, MWIFIEX_IOCTL_WAIT, NULL))
  1012. return -EFAULT;
  1013. queue_work(priv->workqueue, &priv->cfg_workqueue);
  1014. return 0;
  1015. }
  1016. /*
  1017. * CFG802.11 operation handler for scan request.
  1018. *
  1019. * This function issues a scan request to the firmware based upon
  1020. * the user specified scan configuration. On successfull completion,
  1021. * it also informs the results.
  1022. */
  1023. static int
  1024. mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
  1025. struct cfg80211_scan_request *request)
  1026. {
  1027. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1028. wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
  1029. if (priv->scan_request && priv->scan_request != request)
  1030. return -EBUSY;
  1031. priv->scan_request = request;
  1032. queue_work(priv->workqueue, &priv->cfg_workqueue);
  1033. return 0;
  1034. }
  1035. /*
  1036. * This function sets up the CFG802.11 specific HT capability fields
  1037. * with default values.
  1038. *
  1039. * The following default values are set -
  1040. * - HT Supported = True
  1041. * - Maximum AMPDU length factor = 0x3
  1042. * - Minimum AMPDU spacing = 0x6
  1043. * - HT Capabilities map = IEEE80211_HT_CAP_SUP_WIDTH_20_40 (0x0002)
  1044. * - MCS information, Rx mask = 0xff
  1045. * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
  1046. */
  1047. static void
  1048. mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
  1049. struct mwifiex_private *priv)
  1050. {
  1051. int rx_mcs_supp;
  1052. struct ieee80211_mcs_info mcs_set;
  1053. u8 *mcs = (u8 *)&mcs_set;
  1054. struct mwifiex_adapter *adapter = priv->adapter;
  1055. ht_info->ht_supported = true;
  1056. ht_info->ampdu_factor = 0x3;
  1057. ht_info->ampdu_density = 0x6;
  1058. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  1059. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1060. rx_mcs_supp = GET_RXMCSSUPP(priv->adapter->hw_dev_mcs_support);
  1061. /* Set MCS for 1x1 */
  1062. memset(mcs, 0xff, rx_mcs_supp);
  1063. /* Clear all the other values */
  1064. memset(&mcs[rx_mcs_supp], 0,
  1065. sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
  1066. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  1067. ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  1068. /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
  1069. SETHT_MCS32(mcs_set.rx_mask);
  1070. memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
  1071. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  1072. }
  1073. /* station cfg80211 operations */
  1074. static struct cfg80211_ops mwifiex_cfg80211_ops = {
  1075. .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
  1076. .scan = mwifiex_cfg80211_scan,
  1077. .connect = mwifiex_cfg80211_connect,
  1078. .disconnect = mwifiex_cfg80211_disconnect,
  1079. .get_station = mwifiex_cfg80211_get_station,
  1080. .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
  1081. .set_channel = mwifiex_cfg80211_set_channel,
  1082. .join_ibss = mwifiex_cfg80211_join_ibss,
  1083. .leave_ibss = mwifiex_cfg80211_leave_ibss,
  1084. .add_key = mwifiex_cfg80211_add_key,
  1085. .del_key = mwifiex_cfg80211_del_key,
  1086. .set_default_key = mwifiex_cfg80211_set_default_key,
  1087. .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
  1088. .set_tx_power = mwifiex_cfg80211_set_tx_power,
  1089. };
  1090. /*
  1091. * This function registers the device with CFG802.11 subsystem.
  1092. *
  1093. * The function creates the wireless device/wiphy, populates it with
  1094. * default parameters and handler function pointers, and finally
  1095. * registers the device.
  1096. */
  1097. int mwifiex_register_cfg80211(struct net_device *dev, u8 *mac,
  1098. struct mwifiex_private *priv)
  1099. {
  1100. int ret = 0;
  1101. void *wdev_priv = NULL;
  1102. struct wireless_dev *wdev;
  1103. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1104. if (!wdev) {
  1105. dev_err(priv->adapter->dev, "%s: allocating wireless device\n",
  1106. __func__);
  1107. return -ENOMEM;
  1108. }
  1109. wdev->wiphy =
  1110. wiphy_new(&mwifiex_cfg80211_ops,
  1111. sizeof(struct mwifiex_private *));
  1112. if (!wdev->wiphy)
  1113. return -ENOMEM;
  1114. wdev->iftype = NL80211_IFTYPE_STATION;
  1115. wdev->wiphy->max_scan_ssids = 10;
  1116. wdev->wiphy->interface_modes =
  1117. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
  1118. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
  1119. wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
  1120. /* Initialize cipher suits */
  1121. wdev->wiphy->cipher_suites = mwifiex_cipher_suites;
  1122. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
  1123. /* Initialize parameters for 2GHz band */
  1124. mwifiex_setup_ht_caps(&wdev->wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap,
  1125. priv);
  1126. mwifiex_setup_ht_caps(&wdev->wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap,
  1127. priv);
  1128. memcpy(wdev->wiphy->perm_addr, mac, 6);
  1129. wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1130. /* We are using custom domains */
  1131. wdev->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
  1132. wdev->wiphy->reg_notifier = mwifiex_reg_notifier;
  1133. /* Set struct mwifiex_private pointer in wiphy_priv */
  1134. wdev_priv = wiphy_priv(wdev->wiphy);
  1135. *(unsigned long *) wdev_priv = (unsigned long) priv;
  1136. ret = wiphy_register(wdev->wiphy);
  1137. if (ret < 0) {
  1138. dev_err(priv->adapter->dev, "%s: registering cfg80211 device\n",
  1139. __func__);
  1140. wiphy_free(wdev->wiphy);
  1141. return ret;
  1142. } else {
  1143. dev_dbg(priv->adapter->dev,
  1144. "info: successfully registered wiphy device\n");
  1145. }
  1146. dev_net_set(dev, wiphy_net(wdev->wiphy));
  1147. dev->ieee80211_ptr = wdev;
  1148. memcpy(dev->dev_addr, wdev->wiphy->perm_addr, 6);
  1149. memcpy(dev->perm_addr, wdev->wiphy->perm_addr, 6);
  1150. SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
  1151. priv->wdev = wdev;
  1152. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  1153. dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
  1154. dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
  1155. return ret;
  1156. }
  1157. /*
  1158. * This function handles the result of different pending network operations.
  1159. *
  1160. * The following operations are handled and CFG802.11 subsystem is
  1161. * notified accordingly -
  1162. * - Scan request completion
  1163. * - Association request completion
  1164. * - IBSS join request completion
  1165. * - Disconnect request completion
  1166. */
  1167. void
  1168. mwifiex_cfg80211_results(struct work_struct *work)
  1169. {
  1170. struct mwifiex_private *priv =
  1171. container_of(work, struct mwifiex_private, cfg_workqueue);
  1172. struct mwifiex_user_scan_cfg *scan_req;
  1173. int ret = 0, i;
  1174. struct ieee80211_channel *chan;
  1175. if (priv->scan_request) {
  1176. scan_req = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
  1177. GFP_KERNEL);
  1178. if (!scan_req) {
  1179. dev_err(priv->adapter->dev, "failed to alloc "
  1180. "scan_req\n");
  1181. return;
  1182. }
  1183. for (i = 0; i < priv->scan_request->n_ssids; i++) {
  1184. memcpy(scan_req->ssid_list[i].ssid,
  1185. priv->scan_request->ssids[i].ssid,
  1186. priv->scan_request->ssids[i].ssid_len);
  1187. scan_req->ssid_list[i].max_len =
  1188. priv->scan_request->ssids[i].ssid_len;
  1189. }
  1190. for (i = 0; i < priv->scan_request->n_channels; i++) {
  1191. chan = priv->scan_request->channels[i];
  1192. scan_req->chan_list[i].chan_number = chan->hw_value;
  1193. scan_req->chan_list[i].radio_type = chan->band;
  1194. if (chan->flags & IEEE80211_CHAN_DISABLED)
  1195. scan_req->chan_list[i].scan_type =
  1196. MWIFIEX_SCAN_TYPE_PASSIVE;
  1197. else
  1198. scan_req->chan_list[i].scan_type =
  1199. MWIFIEX_SCAN_TYPE_ACTIVE;
  1200. scan_req->chan_list[i].scan_time = 0;
  1201. }
  1202. if (mwifiex_set_user_scan_ioctl(priv, scan_req)) {
  1203. ret = -EFAULT;
  1204. goto done;
  1205. }
  1206. if (mwifiex_inform_bss_from_scan_result(priv, NULL))
  1207. ret = -EFAULT;
  1208. done:
  1209. priv->scan_result_status = ret;
  1210. dev_dbg(priv->adapter->dev, "info: %s: sending scan results\n",
  1211. __func__);
  1212. cfg80211_scan_done(priv->scan_request,
  1213. (priv->scan_result_status < 0));
  1214. priv->scan_request = NULL;
  1215. kfree(scan_req);
  1216. }
  1217. if (priv->assoc_request) {
  1218. if (!priv->assoc_result) {
  1219. cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
  1220. NULL, 0, NULL, 0,
  1221. WLAN_STATUS_SUCCESS,
  1222. GFP_KERNEL);
  1223. dev_dbg(priv->adapter->dev,
  1224. "info: associated to bssid %pM successfully\n",
  1225. priv->cfg_bssid);
  1226. } else {
  1227. dev_dbg(priv->adapter->dev,
  1228. "info: association to bssid %pM failed\n",
  1229. priv->cfg_bssid);
  1230. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1231. }
  1232. priv->assoc_request = 0;
  1233. priv->assoc_result = 0;
  1234. }
  1235. if (priv->ibss_join_request) {
  1236. if (!priv->ibss_join_result) {
  1237. cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
  1238. GFP_KERNEL);
  1239. dev_dbg(priv->adapter->dev,
  1240. "info: joined/created adhoc network with bssid"
  1241. " %pM successfully\n", priv->cfg_bssid);
  1242. } else {
  1243. dev_dbg(priv->adapter->dev,
  1244. "info: failed creating/joining adhoc network\n");
  1245. }
  1246. priv->ibss_join_request = 0;
  1247. priv->ibss_join_result = 0;
  1248. }
  1249. if (priv->disconnect) {
  1250. memset(priv->cfg_bssid, 0, ETH_ALEN);
  1251. priv->disconnect = 0;
  1252. }
  1253. return;
  1254. }