cfg80211.c 64 KB

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