cfg80211.c 39 KB

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