cfg80211.c 49 KB

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