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