cfg80211.c 53 KB

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