cfg80211.c 57 KB

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