cfg80211.c 48 KB

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