cfg80211.c 44 KB

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