cfg80211.c 70 KB

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