cfg80211.c 44 KB

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