cfg80211.c 38 KB

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