cfg80211.c 39 KB

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