cfg80211.c 52 KB

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