cfg80211.c 41 KB

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