cfg80211.c 44 KB

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