cfg80211.c 42 KB

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