cfg80211.c 52 KB

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