cfg80211.c 52 KB

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