cfg80211.c 40 KB

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