cfg80211.c 43 KB

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