cfg80211.c 52 KB

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