cfg80211.c 42 KB

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