cfg80211.c 42 KB

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