cfg80211.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726
  1. /*
  2. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/etherdevice.h>
  18. #include <linux/moduleparam.h>
  19. #include <net/netlink.h>
  20. #include <net/cfg80211.h>
  21. #include "wil6210.h"
  22. #include "wmi.h"
  23. #include "fw.h"
  24. #define WIL_MAX_ROC_DURATION_MS 5000
  25. bool disable_ap_sme;
  26. module_param(disable_ap_sme, bool, 0444);
  27. MODULE_PARM_DESC(disable_ap_sme, " let user space handle AP mode SME");
  28. #ifdef CONFIG_PM
  29. static struct wiphy_wowlan_support wil_wowlan_support = {
  30. .flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_DISCONNECT,
  31. };
  32. #endif
  33. #define CHAN60G(_channel, _flags) { \
  34. .band = NL80211_BAND_60GHZ, \
  35. .center_freq = 56160 + (2160 * (_channel)), \
  36. .hw_value = (_channel), \
  37. .flags = (_flags), \
  38. .max_antenna_gain = 0, \
  39. .max_power = 40, \
  40. }
  41. static struct ieee80211_channel wil_60ghz_channels[] = {
  42. CHAN60G(1, 0),
  43. CHAN60G(2, 0),
  44. CHAN60G(3, 0),
  45. /* channel 4 not supported yet */
  46. };
  47. /* Vendor id to be used in vendor specific command and events
  48. * to user space.
  49. * NOTE: The authoritative place for definition of QCA_NL80211_VENDOR_ID,
  50. * vendor subcmd definitions prefixed with QCA_NL80211_VENDOR_SUBCMD, and
  51. * qca_wlan_vendor_attr is open source file src/common/qca-vendor.h in
  52. * git://w1.fi/srv/git/hostap.git; the values here are just a copy of that
  53. */
  54. #define QCA_NL80211_VENDOR_ID 0x001374
  55. #define WIL_MAX_RF_SECTORS (128)
  56. #define WIL_CID_ALL (0xff)
  57. enum qca_wlan_vendor_attr_rf_sector {
  58. QCA_ATTR_MAC_ADDR = 6,
  59. QCA_ATTR_PAD = 13,
  60. QCA_ATTR_TSF = 29,
  61. QCA_ATTR_DMG_RF_SECTOR_INDEX = 30,
  62. QCA_ATTR_DMG_RF_SECTOR_TYPE = 31,
  63. QCA_ATTR_DMG_RF_MODULE_MASK = 32,
  64. QCA_ATTR_DMG_RF_SECTOR_CFG = 33,
  65. QCA_ATTR_DMG_RF_SECTOR_MAX,
  66. };
  67. enum qca_wlan_vendor_attr_dmg_rf_sector_type {
  68. QCA_ATTR_DMG_RF_SECTOR_TYPE_RX,
  69. QCA_ATTR_DMG_RF_SECTOR_TYPE_TX,
  70. QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX
  71. };
  72. enum qca_wlan_vendor_attr_dmg_rf_sector_cfg {
  73. QCA_ATTR_DMG_RF_SECTOR_CFG_INVALID = 0,
  74. QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
  75. QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
  76. QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
  77. QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
  78. QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
  79. QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
  80. QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
  81. /* keep last */
  82. QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST,
  83. QCA_ATTR_DMG_RF_SECTOR_CFG_MAX =
  84. QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST - 1
  85. };
  86. static const struct
  87. nla_policy wil_rf_sector_policy[QCA_ATTR_DMG_RF_SECTOR_MAX + 1] = {
  88. [QCA_ATTR_MAC_ADDR] = { .len = ETH_ALEN },
  89. [QCA_ATTR_DMG_RF_SECTOR_INDEX] = { .type = NLA_U16 },
  90. [QCA_ATTR_DMG_RF_SECTOR_TYPE] = { .type = NLA_U8 },
  91. [QCA_ATTR_DMG_RF_MODULE_MASK] = { .type = NLA_U32 },
  92. [QCA_ATTR_DMG_RF_SECTOR_CFG] = { .type = NLA_NESTED },
  93. };
  94. static const struct
  95. nla_policy wil_rf_sector_cfg_policy[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1] = {
  96. [QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] = { .type = NLA_U8 },
  97. [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] = { .type = NLA_U32 },
  98. [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] = { .type = NLA_U32 },
  99. [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] = { .type = NLA_U32 },
  100. [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] = { .type = NLA_U32 },
  101. [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] = { .type = NLA_U32 },
  102. [QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16] = { .type = NLA_U32 },
  103. };
  104. enum qca_nl80211_vendor_subcmds {
  105. QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG = 139,
  106. QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG = 140,
  107. QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR = 141,
  108. QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR = 142,
  109. };
  110. static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
  111. struct wireless_dev *wdev,
  112. const void *data, int data_len);
  113. static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
  114. struct wireless_dev *wdev,
  115. const void *data, int data_len);
  116. static int wil_rf_sector_get_selected(struct wiphy *wiphy,
  117. struct wireless_dev *wdev,
  118. const void *data, int data_len);
  119. static int wil_rf_sector_set_selected(struct wiphy *wiphy,
  120. struct wireless_dev *wdev,
  121. const void *data, int data_len);
  122. /* vendor specific commands */
  123. static const struct wiphy_vendor_command wil_nl80211_vendor_commands[] = {
  124. {
  125. .info.vendor_id = QCA_NL80211_VENDOR_ID,
  126. .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG,
  127. .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
  128. WIPHY_VENDOR_CMD_NEED_RUNNING,
  129. .doit = wil_rf_sector_get_cfg
  130. },
  131. {
  132. .info.vendor_id = QCA_NL80211_VENDOR_ID,
  133. .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG,
  134. .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
  135. WIPHY_VENDOR_CMD_NEED_RUNNING,
  136. .doit = wil_rf_sector_set_cfg
  137. },
  138. {
  139. .info.vendor_id = QCA_NL80211_VENDOR_ID,
  140. .info.subcmd =
  141. QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR,
  142. .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
  143. WIPHY_VENDOR_CMD_NEED_RUNNING,
  144. .doit = wil_rf_sector_get_selected
  145. },
  146. {
  147. .info.vendor_id = QCA_NL80211_VENDOR_ID,
  148. .info.subcmd =
  149. QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR,
  150. .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
  151. WIPHY_VENDOR_CMD_NEED_RUNNING,
  152. .doit = wil_rf_sector_set_selected
  153. },
  154. };
  155. static struct ieee80211_supported_band wil_band_60ghz = {
  156. .channels = wil_60ghz_channels,
  157. .n_channels = ARRAY_SIZE(wil_60ghz_channels),
  158. .ht_cap = {
  159. .ht_supported = true,
  160. .cap = 0, /* TODO */
  161. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
  162. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
  163. .mcs = {
  164. /* MCS 1..12 - SC PHY */
  165. .rx_mask = {0xfe, 0x1f}, /* 1..12 */
  166. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
  167. },
  168. },
  169. };
  170. static const struct ieee80211_txrx_stypes
  171. wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  172. [NL80211_IFTYPE_STATION] = {
  173. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  174. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  175. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  176. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  177. },
  178. [NL80211_IFTYPE_AP] = {
  179. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  180. BIT(IEEE80211_STYPE_PROBE_RESP >> 4) |
  181. BIT(IEEE80211_STYPE_ASSOC_RESP >> 4) |
  182. BIT(IEEE80211_STYPE_DISASSOC >> 4),
  183. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  184. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  185. BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  186. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  187. BIT(IEEE80211_STYPE_AUTH >> 4) |
  188. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  189. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4)
  190. },
  191. [NL80211_IFTYPE_P2P_CLIENT] = {
  192. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  193. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  194. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  195. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  196. },
  197. [NL80211_IFTYPE_P2P_GO] = {
  198. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  199. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  200. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  201. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  202. },
  203. [NL80211_IFTYPE_P2P_DEVICE] = {
  204. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  205. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  206. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  207. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  208. },
  209. };
  210. static const u32 wil_cipher_suites[] = {
  211. WLAN_CIPHER_SUITE_GCMP,
  212. };
  213. static const char * const key_usage_str[] = {
  214. [WMI_KEY_USE_PAIRWISE] = "PTK",
  215. [WMI_KEY_USE_RX_GROUP] = "RX_GTK",
  216. [WMI_KEY_USE_TX_GROUP] = "TX_GTK",
  217. };
  218. int wil_iftype_nl2wmi(enum nl80211_iftype type)
  219. {
  220. static const struct {
  221. enum nl80211_iftype nl;
  222. enum wmi_network_type wmi;
  223. } __nl2wmi[] = {
  224. {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
  225. {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
  226. {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
  227. {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
  228. {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
  229. {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
  230. };
  231. uint i;
  232. for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
  233. if (__nl2wmi[i].nl == type)
  234. return __nl2wmi[i].wmi;
  235. }
  236. return -EOPNOTSUPP;
  237. }
  238. int wil_cid_fill_sinfo(struct wil6210_vif *vif, int cid,
  239. struct station_info *sinfo)
  240. {
  241. struct wil6210_priv *wil = vif_to_wil(vif);
  242. struct wmi_notify_req_cmd cmd = {
  243. .cid = cid,
  244. .interval_usec = 0,
  245. };
  246. struct {
  247. struct wmi_cmd_hdr wmi;
  248. struct wmi_notify_req_done_event evt;
  249. } __packed reply;
  250. struct wil_net_stats *stats = &wil->sta[cid].stats;
  251. int rc;
  252. memset(&reply, 0, sizeof(reply));
  253. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, &cmd, sizeof(cmd),
  254. WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
  255. if (rc)
  256. return rc;
  257. wil_dbg_wmi(wil, "Link status for CID %d MID %d: {\n"
  258. " MCS %d TSF 0x%016llx\n"
  259. " BF status 0x%08x RSSI %d SQI %d%%\n"
  260. " Tx Tpt %d goodput %d Rx goodput %d\n"
  261. " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
  262. cid, vif->mid, le16_to_cpu(reply.evt.bf_mcs),
  263. le64_to_cpu(reply.evt.tsf), reply.evt.status,
  264. reply.evt.rssi,
  265. reply.evt.sqi,
  266. le32_to_cpu(reply.evt.tx_tpt),
  267. le32_to_cpu(reply.evt.tx_goodput),
  268. le32_to_cpu(reply.evt.rx_goodput),
  269. le16_to_cpu(reply.evt.my_rx_sector),
  270. le16_to_cpu(reply.evt.my_tx_sector),
  271. le16_to_cpu(reply.evt.other_rx_sector),
  272. le16_to_cpu(reply.evt.other_tx_sector));
  273. sinfo->generation = wil->sinfo_gen;
  274. sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
  275. BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
  276. BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
  277. BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
  278. BIT_ULL(NL80211_STA_INFO_RX_BITRATE) |
  279. BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
  280. BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC) |
  281. BIT_ULL(NL80211_STA_INFO_TX_FAILED);
  282. sinfo->txrate.flags = RATE_INFO_FLAGS_60G;
  283. sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
  284. sinfo->rxrate.mcs = stats->last_mcs_rx;
  285. sinfo->rx_bytes = stats->rx_bytes;
  286. sinfo->rx_packets = stats->rx_packets;
  287. sinfo->rx_dropped_misc = stats->rx_dropped;
  288. sinfo->tx_bytes = stats->tx_bytes;
  289. sinfo->tx_packets = stats->tx_packets;
  290. sinfo->tx_failed = stats->tx_errors;
  291. if (test_bit(wil_vif_fwconnected, vif->status)) {
  292. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
  293. if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING,
  294. wil->fw_capabilities))
  295. sinfo->signal = reply.evt.rssi;
  296. else
  297. sinfo->signal = reply.evt.sqi;
  298. }
  299. return rc;
  300. }
  301. static int wil_cfg80211_get_station(struct wiphy *wiphy,
  302. struct net_device *ndev,
  303. const u8 *mac, struct station_info *sinfo)
  304. {
  305. struct wil6210_vif *vif = ndev_to_vif(ndev);
  306. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  307. int rc;
  308. int cid = wil_find_cid(wil, vif->mid, mac);
  309. wil_dbg_misc(wil, "get_station: %pM CID %d MID %d\n", mac, cid,
  310. vif->mid);
  311. if (cid < 0)
  312. return cid;
  313. rc = wil_cid_fill_sinfo(vif, cid, sinfo);
  314. return rc;
  315. }
  316. /*
  317. * Find @idx-th active STA for specific MID for station dump.
  318. */
  319. static int wil_find_cid_by_idx(struct wil6210_priv *wil, u8 mid, int idx)
  320. {
  321. int i;
  322. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  323. if (wil->sta[i].status == wil_sta_unused)
  324. continue;
  325. if (wil->sta[i].mid != mid)
  326. continue;
  327. if (idx == 0)
  328. return i;
  329. idx--;
  330. }
  331. return -ENOENT;
  332. }
  333. static int wil_cfg80211_dump_station(struct wiphy *wiphy,
  334. struct net_device *dev, int idx,
  335. u8 *mac, struct station_info *sinfo)
  336. {
  337. struct wil6210_vif *vif = ndev_to_vif(dev);
  338. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  339. int rc;
  340. int cid = wil_find_cid_by_idx(wil, vif->mid, idx);
  341. if (cid < 0)
  342. return -ENOENT;
  343. ether_addr_copy(mac, wil->sta[cid].addr);
  344. wil_dbg_misc(wil, "dump_station: %pM CID %d MID %d\n", mac, cid,
  345. vif->mid);
  346. rc = wil_cid_fill_sinfo(vif, cid, sinfo);
  347. return rc;
  348. }
  349. static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
  350. struct wireless_dev *wdev)
  351. {
  352. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  353. wil_dbg_misc(wil, "start_p2p_device: entered\n");
  354. wil->p2p_dev_started = 1;
  355. return 0;
  356. }
  357. static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
  358. struct wireless_dev *wdev)
  359. {
  360. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  361. if (!wil->p2p_dev_started)
  362. return;
  363. wil_dbg_misc(wil, "stop_p2p_device: entered\n");
  364. mutex_lock(&wil->mutex);
  365. mutex_lock(&wil->vif_mutex);
  366. wil_p2p_stop_radio_operations(wil);
  367. wil->p2p_dev_started = 0;
  368. mutex_unlock(&wil->vif_mutex);
  369. mutex_unlock(&wil->mutex);
  370. }
  371. static int wil_cfg80211_validate_add_iface(struct wil6210_priv *wil,
  372. enum nl80211_iftype new_type)
  373. {
  374. int i;
  375. struct wireless_dev *wdev;
  376. struct iface_combination_params params = {
  377. .num_different_channels = 1,
  378. };
  379. for (i = 0; i < wil->max_vifs; i++) {
  380. if (wil->vifs[i]) {
  381. wdev = vif_to_wdev(wil->vifs[i]);
  382. params.iftype_num[wdev->iftype]++;
  383. }
  384. }
  385. params.iftype_num[new_type]++;
  386. return cfg80211_check_combinations(wil->wiphy, &params);
  387. }
  388. static int wil_cfg80211_validate_change_iface(struct wil6210_priv *wil,
  389. struct wil6210_vif *vif,
  390. enum nl80211_iftype new_type)
  391. {
  392. int i, ret = 0;
  393. struct wireless_dev *wdev;
  394. struct iface_combination_params params = {
  395. .num_different_channels = 1,
  396. };
  397. bool check_combos = false;
  398. for (i = 0; i < wil->max_vifs; i++) {
  399. struct wil6210_vif *vif_pos = wil->vifs[i];
  400. if (vif_pos && vif != vif_pos) {
  401. wdev = vif_to_wdev(vif_pos);
  402. params.iftype_num[wdev->iftype]++;
  403. check_combos = true;
  404. }
  405. }
  406. if (check_combos) {
  407. params.iftype_num[new_type]++;
  408. ret = cfg80211_check_combinations(wil->wiphy, &params);
  409. }
  410. return ret;
  411. }
  412. static struct wireless_dev *
  413. wil_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
  414. unsigned char name_assign_type,
  415. enum nl80211_iftype type,
  416. struct vif_params *params)
  417. {
  418. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  419. struct net_device *ndev_main = wil->main_ndev, *ndev;
  420. struct wil6210_vif *vif;
  421. struct wireless_dev *p2p_wdev, *wdev;
  422. int rc;
  423. wil_dbg_misc(wil, "add_iface, type %d\n", type);
  424. /* P2P device is not a real virtual interface, it is a management-only
  425. * interface that shares the main interface.
  426. * Skip concurrency checks here.
  427. */
  428. if (type == NL80211_IFTYPE_P2P_DEVICE) {
  429. if (wil->p2p_wdev) {
  430. wil_err(wil, "P2P_DEVICE interface already created\n");
  431. return ERR_PTR(-EINVAL);
  432. }
  433. p2p_wdev = kzalloc(sizeof(*p2p_wdev), GFP_KERNEL);
  434. if (!p2p_wdev)
  435. return ERR_PTR(-ENOMEM);
  436. p2p_wdev->iftype = type;
  437. p2p_wdev->wiphy = wiphy;
  438. /* use our primary ethernet address */
  439. ether_addr_copy(p2p_wdev->address, ndev_main->perm_addr);
  440. wil->p2p_wdev = p2p_wdev;
  441. return p2p_wdev;
  442. }
  443. if (!wil->wiphy->n_iface_combinations) {
  444. wil_err(wil, "virtual interfaces not supported\n");
  445. return ERR_PTR(-EINVAL);
  446. }
  447. rc = wil_cfg80211_validate_add_iface(wil, type);
  448. if (rc) {
  449. wil_err(wil, "iface validation failed, err=%d\n", rc);
  450. return ERR_PTR(rc);
  451. }
  452. vif = wil_vif_alloc(wil, name, name_assign_type, type);
  453. if (IS_ERR(vif))
  454. return ERR_CAST(vif);
  455. ndev = vif_to_ndev(vif);
  456. ether_addr_copy(ndev->perm_addr, ndev_main->perm_addr);
  457. if (is_valid_ether_addr(params->macaddr)) {
  458. ether_addr_copy(ndev->dev_addr, params->macaddr);
  459. } else {
  460. ether_addr_copy(ndev->dev_addr, ndev_main->perm_addr);
  461. ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << vif->mid)) |
  462. 0x2; /* locally administered */
  463. }
  464. wdev = vif_to_wdev(vif);
  465. ether_addr_copy(wdev->address, ndev->dev_addr);
  466. rc = wil_vif_add(wil, vif);
  467. if (rc)
  468. goto out;
  469. wil_info(wil, "added VIF, mid %d iftype %d MAC %pM\n",
  470. vif->mid, type, wdev->address);
  471. return wdev;
  472. out:
  473. wil_vif_free(vif);
  474. return ERR_PTR(rc);
  475. }
  476. int wil_vif_prepare_stop(struct wil6210_vif *vif)
  477. {
  478. struct wil6210_priv *wil = vif_to_wil(vif);
  479. struct wireless_dev *wdev = vif_to_wdev(vif);
  480. struct net_device *ndev;
  481. int rc;
  482. if (wdev->iftype != NL80211_IFTYPE_AP)
  483. return 0;
  484. ndev = vif_to_ndev(vif);
  485. if (netif_carrier_ok(ndev)) {
  486. rc = wmi_pcp_stop(vif);
  487. if (rc) {
  488. wil_info(wil, "failed to stop AP, status %d\n",
  489. rc);
  490. /* continue */
  491. }
  492. wil_bcast_fini(vif);
  493. netif_carrier_off(ndev);
  494. }
  495. return 0;
  496. }
  497. static int wil_cfg80211_del_iface(struct wiphy *wiphy,
  498. struct wireless_dev *wdev)
  499. {
  500. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  501. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  502. int rc;
  503. wil_dbg_misc(wil, "del_iface\n");
  504. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
  505. if (wdev != wil->p2p_wdev) {
  506. wil_err(wil, "delete of incorrect interface 0x%p\n",
  507. wdev);
  508. return -EINVAL;
  509. }
  510. wil_cfg80211_stop_p2p_device(wiphy, wdev);
  511. wil_p2p_wdev_free(wil);
  512. return 0;
  513. }
  514. if (vif->mid == 0) {
  515. wil_err(wil, "cannot remove the main interface\n");
  516. return -EINVAL;
  517. }
  518. rc = wil_vif_prepare_stop(vif);
  519. if (rc)
  520. goto out;
  521. wil_info(wil, "deleted VIF, mid %d iftype %d MAC %pM\n",
  522. vif->mid, wdev->iftype, wdev->address);
  523. wil_vif_remove(wil, vif->mid);
  524. out:
  525. return rc;
  526. }
  527. static int wil_cfg80211_change_iface(struct wiphy *wiphy,
  528. struct net_device *ndev,
  529. enum nl80211_iftype type,
  530. struct vif_params *params)
  531. {
  532. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  533. struct wil6210_vif *vif = ndev_to_vif(ndev);
  534. struct wireless_dev *wdev = vif_to_wdev(vif);
  535. int rc;
  536. bool fw_reset = false;
  537. wil_dbg_misc(wil, "change_iface: type=%d\n", type);
  538. if (wiphy->n_iface_combinations) {
  539. rc = wil_cfg80211_validate_change_iface(wil, vif, type);
  540. if (rc) {
  541. wil_err(wil, "iface validation failed, err=%d\n", rc);
  542. return rc;
  543. }
  544. }
  545. /* do not reset FW when there are active VIFs,
  546. * because it can cause significant disruption
  547. */
  548. if (!wil_has_other_active_ifaces(wil, ndev, true, false) &&
  549. netif_running(ndev) && !wil_is_recovery_blocked(wil)) {
  550. wil_dbg_misc(wil, "interface is up. resetting...\n");
  551. mutex_lock(&wil->mutex);
  552. __wil_down(wil);
  553. rc = __wil_up(wil);
  554. mutex_unlock(&wil->mutex);
  555. if (rc)
  556. return rc;
  557. fw_reset = true;
  558. }
  559. switch (type) {
  560. case NL80211_IFTYPE_STATION:
  561. case NL80211_IFTYPE_AP:
  562. case NL80211_IFTYPE_P2P_CLIENT:
  563. case NL80211_IFTYPE_P2P_GO:
  564. break;
  565. case NL80211_IFTYPE_MONITOR:
  566. if (params->flags)
  567. wil->monitor_flags = params->flags;
  568. break;
  569. default:
  570. return -EOPNOTSUPP;
  571. }
  572. if (vif->mid != 0 && wil_has_active_ifaces(wil, true, false)) {
  573. if (!fw_reset)
  574. wil_vif_prepare_stop(vif);
  575. rc = wmi_port_delete(wil, vif->mid);
  576. if (rc)
  577. return rc;
  578. rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr, type);
  579. if (rc)
  580. return rc;
  581. }
  582. wdev->iftype = type;
  583. return 0;
  584. }
  585. static int wil_cfg80211_scan(struct wiphy *wiphy,
  586. struct cfg80211_scan_request *request)
  587. {
  588. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  589. struct wireless_dev *wdev = request->wdev;
  590. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  591. struct {
  592. struct wmi_start_scan_cmd cmd;
  593. u16 chnl[4];
  594. } __packed cmd;
  595. uint i, n;
  596. int rc;
  597. wil_dbg_misc(wil, "scan: wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
  598. /* scan is supported on client interfaces and on AP interface */
  599. switch (wdev->iftype) {
  600. case NL80211_IFTYPE_STATION:
  601. case NL80211_IFTYPE_P2P_CLIENT:
  602. case NL80211_IFTYPE_P2P_DEVICE:
  603. case NL80211_IFTYPE_AP:
  604. break;
  605. default:
  606. return -EOPNOTSUPP;
  607. }
  608. /* FW don't support scan after connection attempt */
  609. if (test_bit(wil_status_dontscan, wil->status)) {
  610. wil_err(wil, "Can't scan now\n");
  611. return -EBUSY;
  612. }
  613. mutex_lock(&wil->mutex);
  614. mutex_lock(&wil->vif_mutex);
  615. if (vif->scan_request || vif->p2p.discovery_started) {
  616. wil_err(wil, "Already scanning\n");
  617. mutex_unlock(&wil->vif_mutex);
  618. rc = -EAGAIN;
  619. goto out;
  620. }
  621. mutex_unlock(&wil->vif_mutex);
  622. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
  623. if (!wil->p2p_dev_started) {
  624. wil_err(wil, "P2P search requested on stopped P2P device\n");
  625. rc = -EIO;
  626. goto out;
  627. }
  628. /* social scan on P2P_DEVICE is handled as p2p search */
  629. if (wil_p2p_is_social_scan(request)) {
  630. vif->scan_request = request;
  631. if (vif->mid == 0)
  632. wil->radio_wdev = wdev;
  633. rc = wil_p2p_search(vif, request);
  634. if (rc) {
  635. if (vif->mid == 0)
  636. wil->radio_wdev =
  637. wil->main_ndev->ieee80211_ptr;
  638. vif->scan_request = NULL;
  639. }
  640. goto out;
  641. }
  642. }
  643. (void)wil_p2p_stop_discovery(vif);
  644. wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
  645. wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
  646. for (i = 0; i < request->n_ssids; i++) {
  647. wil_dbg_misc(wil, "SSID[%d]", i);
  648. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  649. request->ssids[i].ssid,
  650. request->ssids[i].ssid_len, true);
  651. }
  652. if (request->n_ssids)
  653. rc = wmi_set_ssid(vif, request->ssids[0].ssid_len,
  654. request->ssids[0].ssid);
  655. else
  656. rc = wmi_set_ssid(vif, 0, NULL);
  657. if (rc) {
  658. wil_err(wil, "set SSID for scan request failed: %d\n", rc);
  659. goto out;
  660. }
  661. vif->scan_request = request;
  662. mod_timer(&vif->scan_timer, jiffies + WIL6210_SCAN_TO);
  663. memset(&cmd, 0, sizeof(cmd));
  664. cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
  665. cmd.cmd.num_channels = 0;
  666. n = min(request->n_channels, 4U);
  667. for (i = 0; i < n; i++) {
  668. int ch = request->channels[i]->hw_value;
  669. if (ch == 0) {
  670. wil_err(wil,
  671. "Scan requested for unknown frequency %dMhz\n",
  672. request->channels[i]->center_freq);
  673. continue;
  674. }
  675. /* 0-based channel indexes */
  676. cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
  677. wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
  678. request->channels[i]->center_freq);
  679. }
  680. if (request->ie_len)
  681. wil_hex_dump_misc("Scan IE ", DUMP_PREFIX_OFFSET, 16, 1,
  682. request->ie, request->ie_len, true);
  683. else
  684. wil_dbg_misc(wil, "Scan has no IE's\n");
  685. rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
  686. request->ie_len, request->ie);
  687. if (rc)
  688. goto out_restore;
  689. if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
  690. cmd.cmd.discovery_mode = 1;
  691. wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
  692. }
  693. if (vif->mid == 0)
  694. wil->radio_wdev = wdev;
  695. rc = wmi_send(wil, WMI_START_SCAN_CMDID, vif->mid,
  696. &cmd, sizeof(cmd.cmd) +
  697. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  698. out_restore:
  699. if (rc) {
  700. del_timer_sync(&vif->scan_timer);
  701. if (vif->mid == 0)
  702. wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
  703. vif->scan_request = NULL;
  704. }
  705. out:
  706. mutex_unlock(&wil->mutex);
  707. return rc;
  708. }
  709. static void wil_cfg80211_abort_scan(struct wiphy *wiphy,
  710. struct wireless_dev *wdev)
  711. {
  712. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  713. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  714. wil_dbg_misc(wil, "wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
  715. mutex_lock(&wil->mutex);
  716. mutex_lock(&wil->vif_mutex);
  717. if (!vif->scan_request)
  718. goto out;
  719. if (wdev != vif->scan_request->wdev) {
  720. wil_dbg_misc(wil, "abort scan was called on the wrong iface\n");
  721. goto out;
  722. }
  723. if (wdev == wil->p2p_wdev && wil->radio_wdev == wil->p2p_wdev)
  724. wil_p2p_stop_radio_operations(wil);
  725. else
  726. wil_abort_scan(vif, true);
  727. out:
  728. mutex_unlock(&wil->vif_mutex);
  729. mutex_unlock(&wil->mutex);
  730. }
  731. static void wil_print_crypto(struct wil6210_priv *wil,
  732. struct cfg80211_crypto_settings *c)
  733. {
  734. int i, n;
  735. wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
  736. c->wpa_versions, c->cipher_group);
  737. wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
  738. n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
  739. for (i = 0; i < n; i++)
  740. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  741. c->ciphers_pairwise[i]);
  742. wil_dbg_misc(wil, "}\n");
  743. wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
  744. n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
  745. for (i = 0; i < n; i++)
  746. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  747. c->akm_suites[i]);
  748. wil_dbg_misc(wil, "}\n");
  749. wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
  750. c->control_port, be16_to_cpu(c->control_port_ethertype),
  751. c->control_port_no_encrypt);
  752. }
  753. static void wil_print_connect_params(struct wil6210_priv *wil,
  754. struct cfg80211_connect_params *sme)
  755. {
  756. wil_info(wil, "Connecting to:\n");
  757. if (sme->channel) {
  758. wil_info(wil, " Channel: %d freq %d\n",
  759. sme->channel->hw_value, sme->channel->center_freq);
  760. }
  761. if (sme->bssid)
  762. wil_info(wil, " BSSID: %pM\n", sme->bssid);
  763. if (sme->ssid)
  764. print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
  765. 16, 1, sme->ssid, sme->ssid_len, true);
  766. wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
  767. wil_info(wil, " PBSS: %d\n", sme->pbss);
  768. wil_print_crypto(wil, &sme->crypto);
  769. }
  770. static int wil_cfg80211_connect(struct wiphy *wiphy,
  771. struct net_device *ndev,
  772. struct cfg80211_connect_params *sme)
  773. {
  774. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  775. struct wil6210_vif *vif = ndev_to_vif(ndev);
  776. struct cfg80211_bss *bss;
  777. struct wmi_connect_cmd conn;
  778. const u8 *ssid_eid;
  779. const u8 *rsn_eid;
  780. int ch;
  781. int rc = 0;
  782. enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
  783. wil_dbg_misc(wil, "connect, mid=%d\n", vif->mid);
  784. wil_print_connect_params(wil, sme);
  785. if (test_bit(wil_vif_fwconnecting, vif->status) ||
  786. test_bit(wil_vif_fwconnected, vif->status))
  787. return -EALREADY;
  788. if (sme->ie_len > WMI_MAX_IE_LEN) {
  789. wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
  790. return -ERANGE;
  791. }
  792. rsn_eid = sme->ie ?
  793. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  794. NULL;
  795. if (sme->privacy && !rsn_eid)
  796. wil_info(wil, "WSC connection\n");
  797. if (sme->pbss)
  798. bss_type = IEEE80211_BSS_TYPE_PBSS;
  799. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  800. sme->ssid, sme->ssid_len,
  801. bss_type, IEEE80211_PRIVACY_ANY);
  802. if (!bss) {
  803. wil_err(wil, "Unable to find BSS\n");
  804. return -ENOENT;
  805. }
  806. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  807. if (!ssid_eid) {
  808. wil_err(wil, "No SSID\n");
  809. rc = -ENOENT;
  810. goto out;
  811. }
  812. vif->privacy = sme->privacy;
  813. vif->pbss = sme->pbss;
  814. if (vif->privacy) {
  815. /* For secure assoc, remove old keys */
  816. rc = wmi_del_cipher_key(vif, 0, bss->bssid,
  817. WMI_KEY_USE_PAIRWISE);
  818. if (rc) {
  819. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
  820. goto out;
  821. }
  822. rc = wmi_del_cipher_key(vif, 0, bss->bssid,
  823. WMI_KEY_USE_RX_GROUP);
  824. if (rc) {
  825. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
  826. goto out;
  827. }
  828. }
  829. /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
  830. * elements. Send it also in case it's empty, to erase previously set
  831. * ies in FW.
  832. */
  833. rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  834. if (rc)
  835. goto out;
  836. /* WMI_CONNECT_CMD */
  837. memset(&conn, 0, sizeof(conn));
  838. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  839. case WLAN_CAPABILITY_DMG_TYPE_AP:
  840. conn.network_type = WMI_NETTYPE_INFRA;
  841. break;
  842. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  843. conn.network_type = WMI_NETTYPE_P2P;
  844. break;
  845. default:
  846. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  847. bss->capability);
  848. goto out;
  849. }
  850. if (vif->privacy) {
  851. if (rsn_eid) { /* regular secure connection */
  852. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  853. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  854. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  855. conn.pairwise_crypto_len = 16;
  856. conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
  857. conn.group_crypto_len = 16;
  858. } else { /* WSC */
  859. conn.dot11_auth_mode = WMI_AUTH11_WSC;
  860. conn.auth_mode = WMI_AUTH_NONE;
  861. }
  862. } else { /* insecure connection */
  863. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  864. conn.auth_mode = WMI_AUTH_NONE;
  865. }
  866. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  867. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  868. ch = bss->channel->hw_value;
  869. if (ch == 0) {
  870. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  871. bss->channel->center_freq);
  872. rc = -EOPNOTSUPP;
  873. goto out;
  874. }
  875. conn.channel = ch - 1;
  876. ether_addr_copy(conn.bssid, bss->bssid);
  877. ether_addr_copy(conn.dst_mac, bss->bssid);
  878. set_bit(wil_vif_fwconnecting, vif->status);
  879. rc = wmi_send(wil, WMI_CONNECT_CMDID, vif->mid, &conn, sizeof(conn));
  880. if (rc == 0) {
  881. netif_carrier_on(ndev);
  882. if (!wil_has_other_active_ifaces(wil, ndev, false, true))
  883. wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
  884. vif->bss = bss;
  885. /* Connect can take lots of time */
  886. mod_timer(&vif->connect_timer,
  887. jiffies + msecs_to_jiffies(5000));
  888. } else {
  889. clear_bit(wil_vif_fwconnecting, vif->status);
  890. }
  891. out:
  892. cfg80211_put_bss(wiphy, bss);
  893. return rc;
  894. }
  895. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  896. struct net_device *ndev,
  897. u16 reason_code)
  898. {
  899. int rc;
  900. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  901. struct wil6210_vif *vif = ndev_to_vif(ndev);
  902. wil_dbg_misc(wil, "disconnect: reason=%d, mid=%d\n",
  903. reason_code, vif->mid);
  904. if (!(test_bit(wil_vif_fwconnecting, vif->status) ||
  905. test_bit(wil_vif_fwconnected, vif->status))) {
  906. wil_err(wil, "Disconnect was called while disconnected\n");
  907. return 0;
  908. }
  909. vif->locally_generated_disc = true;
  910. rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
  911. WMI_DISCONNECT_EVENTID, NULL, 0,
  912. WIL6210_DISCONNECT_TO_MS);
  913. if (rc)
  914. wil_err(wil, "disconnect error %d\n", rc);
  915. return rc;
  916. }
  917. static int wil_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  918. {
  919. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  920. int rc;
  921. /* these parameters are explicitly not supported */
  922. if (changed & (WIPHY_PARAM_RETRY_LONG |
  923. WIPHY_PARAM_FRAG_THRESHOLD |
  924. WIPHY_PARAM_RTS_THRESHOLD))
  925. return -ENOTSUPP;
  926. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  927. rc = wmi_set_mgmt_retry(wil, wiphy->retry_short);
  928. if (rc)
  929. return rc;
  930. }
  931. return 0;
  932. }
  933. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  934. struct cfg80211_mgmt_tx_params *params,
  935. u64 *cookie)
  936. {
  937. const u8 *buf = params->buf;
  938. size_t len = params->len;
  939. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  940. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  941. int rc;
  942. bool tx_status;
  943. wil_dbg_misc(wil, "mgmt_tx: channel %d offchan %d, wait %d\n",
  944. params->chan ? params->chan->hw_value : -1,
  945. params->offchan,
  946. params->wait);
  947. /* Note, currently we support the "wait" parameter only on AP mode.
  948. * In other modes, user-space must call remain_on_channel before
  949. * mgmt_tx or listen on a channel other than active one.
  950. */
  951. if (params->chan && params->chan->hw_value == 0) {
  952. wil_err(wil, "invalid channel\n");
  953. return -EINVAL;
  954. }
  955. if (wdev->iftype != NL80211_IFTYPE_AP) {
  956. wil_dbg_misc(wil,
  957. "send WMI_SW_TX_REQ_CMDID on non-AP interfaces\n");
  958. rc = wmi_mgmt_tx(vif, buf, len);
  959. goto out;
  960. }
  961. if (!params->chan || params->chan->hw_value == vif->channel) {
  962. wil_dbg_misc(wil,
  963. "send WMI_SW_TX_REQ_CMDID for on-channel\n");
  964. rc = wmi_mgmt_tx(vif, buf, len);
  965. goto out;
  966. }
  967. if (params->offchan == 0) {
  968. wil_err(wil,
  969. "invalid channel params: current %d requested %d, off-channel not allowed\n",
  970. vif->channel, params->chan->hw_value);
  971. return -EBUSY;
  972. }
  973. /* use the wmi_mgmt_tx_ext only on AP mode and off-channel */
  974. rc = wmi_mgmt_tx_ext(vif, buf, len, params->chan->hw_value,
  975. params->wait);
  976. out:
  977. /* when the sent packet was not acked by receiver(ACK=0), rc will
  978. * be -EAGAIN. In this case this function needs to return success,
  979. * the ACK=0 will be reflected in tx_status.
  980. */
  981. tx_status = (rc == 0);
  982. rc = (rc == -EAGAIN) ? 0 : rc;
  983. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  984. tx_status, GFP_KERNEL);
  985. return rc;
  986. }
  987. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  988. struct cfg80211_chan_def *chandef)
  989. {
  990. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  991. wil->monitor_chandef = *chandef;
  992. return 0;
  993. }
  994. static enum wmi_key_usage wil_detect_key_usage(struct wireless_dev *wdev,
  995. bool pairwise)
  996. {
  997. struct wil6210_priv *wil = wdev_to_wil(wdev);
  998. enum wmi_key_usage rc;
  999. if (pairwise) {
  1000. rc = WMI_KEY_USE_PAIRWISE;
  1001. } else {
  1002. switch (wdev->iftype) {
  1003. case NL80211_IFTYPE_STATION:
  1004. case NL80211_IFTYPE_P2P_CLIENT:
  1005. rc = WMI_KEY_USE_RX_GROUP;
  1006. break;
  1007. case NL80211_IFTYPE_AP:
  1008. case NL80211_IFTYPE_P2P_GO:
  1009. rc = WMI_KEY_USE_TX_GROUP;
  1010. break;
  1011. default:
  1012. /* TODO: Rx GTK or Tx GTK? */
  1013. wil_err(wil, "Can't determine GTK type\n");
  1014. rc = WMI_KEY_USE_RX_GROUP;
  1015. break;
  1016. }
  1017. }
  1018. wil_dbg_misc(wil, "detect_key_usage: -> %s\n", key_usage_str[rc]);
  1019. return rc;
  1020. }
  1021. static struct wil_sta_info *
  1022. wil_find_sta_by_key_usage(struct wil6210_priv *wil, u8 mid,
  1023. enum wmi_key_usage key_usage, const u8 *mac_addr)
  1024. {
  1025. int cid = -EINVAL;
  1026. if (key_usage == WMI_KEY_USE_TX_GROUP)
  1027. return NULL; /* not needed */
  1028. /* supplicant provides Rx group key in STA mode with NULL MAC address */
  1029. if (mac_addr)
  1030. cid = wil_find_cid(wil, mid, mac_addr);
  1031. else if (key_usage == WMI_KEY_USE_RX_GROUP)
  1032. cid = wil_find_cid_by_idx(wil, mid, 0);
  1033. if (cid < 0) {
  1034. wil_err(wil, "No CID for %pM %s\n", mac_addr,
  1035. key_usage_str[key_usage]);
  1036. return ERR_PTR(cid);
  1037. }
  1038. return &wil->sta[cid];
  1039. }
  1040. static void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
  1041. struct wil_sta_info *cs,
  1042. struct key_params *params)
  1043. {
  1044. struct wil_tid_crypto_rx_single *cc;
  1045. int tid;
  1046. if (!cs)
  1047. return;
  1048. switch (key_usage) {
  1049. case WMI_KEY_USE_PAIRWISE:
  1050. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1051. cc = &cs->tid_crypto_rx[tid].key_id[key_index];
  1052. if (params->seq)
  1053. memcpy(cc->pn, params->seq,
  1054. IEEE80211_GCMP_PN_LEN);
  1055. else
  1056. memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
  1057. cc->key_set = true;
  1058. }
  1059. break;
  1060. case WMI_KEY_USE_RX_GROUP:
  1061. cc = &cs->group_crypto_rx.key_id[key_index];
  1062. if (params->seq)
  1063. memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
  1064. else
  1065. memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
  1066. cc->key_set = true;
  1067. break;
  1068. default:
  1069. break;
  1070. }
  1071. }
  1072. static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
  1073. struct wil_sta_info *cs)
  1074. {
  1075. struct wil_tid_crypto_rx_single *cc;
  1076. int tid;
  1077. if (!cs)
  1078. return;
  1079. switch (key_usage) {
  1080. case WMI_KEY_USE_PAIRWISE:
  1081. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1082. cc = &cs->tid_crypto_rx[tid].key_id[key_index];
  1083. cc->key_set = false;
  1084. }
  1085. break;
  1086. case WMI_KEY_USE_RX_GROUP:
  1087. cc = &cs->group_crypto_rx.key_id[key_index];
  1088. cc->key_set = false;
  1089. break;
  1090. default:
  1091. break;
  1092. }
  1093. }
  1094. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  1095. struct net_device *ndev,
  1096. u8 key_index, bool pairwise,
  1097. const u8 *mac_addr,
  1098. struct key_params *params)
  1099. {
  1100. int rc;
  1101. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1102. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1103. struct wireless_dev *wdev = vif_to_wdev(vif);
  1104. enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
  1105. struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
  1106. key_usage,
  1107. mac_addr);
  1108. if (!params) {
  1109. wil_err(wil, "NULL params\n");
  1110. return -EINVAL;
  1111. }
  1112. wil_dbg_misc(wil, "add_key: %pM %s[%d] PN %*phN\n",
  1113. mac_addr, key_usage_str[key_usage], key_index,
  1114. params->seq_len, params->seq);
  1115. if (IS_ERR(cs)) {
  1116. wil_err(wil, "Not connected, %pM %s[%d] PN %*phN\n",
  1117. mac_addr, key_usage_str[key_usage], key_index,
  1118. params->seq_len, params->seq);
  1119. return -EINVAL;
  1120. }
  1121. wil_del_rx_key(key_index, key_usage, cs);
  1122. if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
  1123. wil_err(wil,
  1124. "Wrong PN len %d, %pM %s[%d] PN %*phN\n",
  1125. params->seq_len, mac_addr,
  1126. key_usage_str[key_usage], key_index,
  1127. params->seq_len, params->seq);
  1128. return -EINVAL;
  1129. }
  1130. rc = wmi_add_cipher_key(vif, key_index, mac_addr, params->key_len,
  1131. params->key, key_usage);
  1132. if (!rc)
  1133. wil_set_crypto_rx(key_index, key_usage, cs, params);
  1134. return rc;
  1135. }
  1136. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  1137. struct net_device *ndev,
  1138. u8 key_index, bool pairwise,
  1139. const u8 *mac_addr)
  1140. {
  1141. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1142. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1143. struct wireless_dev *wdev = vif_to_wdev(vif);
  1144. enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
  1145. struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
  1146. key_usage,
  1147. mac_addr);
  1148. wil_dbg_misc(wil, "del_key: %pM %s[%d]\n", mac_addr,
  1149. key_usage_str[key_usage], key_index);
  1150. if (IS_ERR(cs))
  1151. wil_info(wil, "Not connected, %pM %s[%d]\n",
  1152. mac_addr, key_usage_str[key_usage], key_index);
  1153. if (!IS_ERR_OR_NULL(cs))
  1154. wil_del_rx_key(key_index, key_usage, cs);
  1155. return wmi_del_cipher_key(vif, key_index, mac_addr, key_usage);
  1156. }
  1157. /* Need to be present or wiphy_new() will WARN */
  1158. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  1159. struct net_device *ndev,
  1160. u8 key_index, bool unicast,
  1161. bool multicast)
  1162. {
  1163. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1164. wil_dbg_misc(wil, "set_default_key: entered\n");
  1165. return 0;
  1166. }
  1167. static int wil_remain_on_channel(struct wiphy *wiphy,
  1168. struct wireless_dev *wdev,
  1169. struct ieee80211_channel *chan,
  1170. unsigned int duration,
  1171. u64 *cookie)
  1172. {
  1173. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1174. int rc;
  1175. wil_dbg_misc(wil,
  1176. "remain_on_channel: center_freq=%d, duration=%d iftype=%d\n",
  1177. chan->center_freq, duration, wdev->iftype);
  1178. rc = wil_p2p_listen(wil, wdev, duration, chan, cookie);
  1179. return rc;
  1180. }
  1181. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  1182. struct wireless_dev *wdev,
  1183. u64 cookie)
  1184. {
  1185. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1186. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  1187. wil_dbg_misc(wil, "cancel_remain_on_channel\n");
  1188. return wil_p2p_cancel_listen(vif, cookie);
  1189. }
  1190. /**
  1191. * find a specific IE in a list of IEs
  1192. * return a pointer to the beginning of IE in the list
  1193. * or NULL if not found
  1194. */
  1195. static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
  1196. u16 ie_len)
  1197. {
  1198. struct ieee80211_vendor_ie *vie;
  1199. u32 oui;
  1200. /* IE tag at offset 0, length at offset 1 */
  1201. if (ie_len < 2 || 2 + ie[1] > ie_len)
  1202. return NULL;
  1203. if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
  1204. return cfg80211_find_ie(ie[0], ies, ies_len);
  1205. /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
  1206. if (ie[1] < 4)
  1207. return NULL;
  1208. vie = (struct ieee80211_vendor_ie *)ie;
  1209. oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
  1210. return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
  1211. ies_len);
  1212. }
  1213. /**
  1214. * merge the IEs in two lists into a single list.
  1215. * do not include IEs from the second list which exist in the first list.
  1216. * add only vendor specific IEs from second list to keep
  1217. * the merged list sorted (since vendor-specific IE has the
  1218. * highest tag number)
  1219. * caller must free the allocated memory for merged IEs
  1220. */
  1221. static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
  1222. const u8 *ies2, u16 ies2_len,
  1223. u8 **merged_ies, u16 *merged_len)
  1224. {
  1225. u8 *buf, *dpos;
  1226. const u8 *spos;
  1227. if (!ies1)
  1228. ies1_len = 0;
  1229. if (!ies2)
  1230. ies2_len = 0;
  1231. if (ies1_len == 0 && ies2_len == 0) {
  1232. *merged_ies = NULL;
  1233. *merged_len = 0;
  1234. return 0;
  1235. }
  1236. buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
  1237. if (!buf)
  1238. return -ENOMEM;
  1239. if (ies1)
  1240. memcpy(buf, ies1, ies1_len);
  1241. dpos = buf + ies1_len;
  1242. spos = ies2;
  1243. while (spos && (spos + 1 < ies2 + ies2_len)) {
  1244. /* IE tag at offset 0, length at offset 1 */
  1245. u16 ielen = 2 + spos[1];
  1246. if (spos + ielen > ies2 + ies2_len)
  1247. break;
  1248. if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  1249. (!ies1 || !_wil_cfg80211_find_ie(ies1, ies1_len,
  1250. spos, ielen))) {
  1251. memcpy(dpos, spos, ielen);
  1252. dpos += ielen;
  1253. }
  1254. spos += ielen;
  1255. }
  1256. *merged_ies = buf;
  1257. *merged_len = dpos - buf;
  1258. return 0;
  1259. }
  1260. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  1261. {
  1262. wil_hex_dump_misc("head ", DUMP_PREFIX_OFFSET, 16, 1,
  1263. b->head, b->head_len, true);
  1264. wil_hex_dump_misc("tail ", DUMP_PREFIX_OFFSET, 16, 1,
  1265. b->tail, b->tail_len, true);
  1266. wil_hex_dump_misc("BCON IE ", DUMP_PREFIX_OFFSET, 16, 1,
  1267. b->beacon_ies, b->beacon_ies_len, true);
  1268. wil_hex_dump_misc("PROBE ", DUMP_PREFIX_OFFSET, 16, 1,
  1269. b->probe_resp, b->probe_resp_len, true);
  1270. wil_hex_dump_misc("PROBE IE ", DUMP_PREFIX_OFFSET, 16, 1,
  1271. b->proberesp_ies, b->proberesp_ies_len, true);
  1272. wil_hex_dump_misc("ASSOC IE ", DUMP_PREFIX_OFFSET, 16, 1,
  1273. b->assocresp_ies, b->assocresp_ies_len, true);
  1274. }
  1275. /* internal functions for device reset and starting AP */
  1276. static int _wil_cfg80211_set_ies(struct wil6210_vif *vif,
  1277. struct cfg80211_beacon_data *bcon)
  1278. {
  1279. int rc;
  1280. u16 len = 0, proberesp_len = 0;
  1281. u8 *ies = NULL, *proberesp = NULL;
  1282. if (bcon->probe_resp) {
  1283. struct ieee80211_mgmt *f =
  1284. (struct ieee80211_mgmt *)bcon->probe_resp;
  1285. size_t hlen = offsetof(struct ieee80211_mgmt,
  1286. u.probe_resp.variable);
  1287. proberesp = f->u.probe_resp.variable;
  1288. proberesp_len = bcon->probe_resp_len - hlen;
  1289. }
  1290. rc = _wil_cfg80211_merge_extra_ies(proberesp,
  1291. proberesp_len,
  1292. bcon->proberesp_ies,
  1293. bcon->proberesp_ies_len,
  1294. &ies, &len);
  1295. if (rc)
  1296. goto out;
  1297. rc = wmi_set_ie(vif, WMI_FRAME_PROBE_RESP, len, ies);
  1298. if (rc)
  1299. goto out;
  1300. if (bcon->assocresp_ies)
  1301. rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP,
  1302. bcon->assocresp_ies_len, bcon->assocresp_ies);
  1303. else
  1304. rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP, len, ies);
  1305. #if 0 /* to use beacon IE's, remove this #if 0 */
  1306. if (rc)
  1307. goto out;
  1308. rc = wmi_set_ie(vif, WMI_FRAME_BEACON,
  1309. bcon->tail_len, bcon->tail);
  1310. #endif
  1311. out:
  1312. kfree(ies);
  1313. return rc;
  1314. }
  1315. static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
  1316. struct net_device *ndev,
  1317. const u8 *ssid, size_t ssid_len, u32 privacy,
  1318. int bi, u8 chan,
  1319. struct cfg80211_beacon_data *bcon,
  1320. u8 hidden_ssid, u32 pbss)
  1321. {
  1322. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1323. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1324. int rc;
  1325. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  1326. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  1327. u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
  1328. if (pbss)
  1329. wmi_nettype = WMI_NETTYPE_P2P;
  1330. wil_dbg_misc(wil, "start_ap: mid=%d, is_go=%d\n", vif->mid, is_go);
  1331. if (is_go && !pbss) {
  1332. wil_err(wil, "P2P GO must be in PBSS\n");
  1333. return -ENOTSUPP;
  1334. }
  1335. wil_set_recovery_state(wil, fw_recovery_idle);
  1336. mutex_lock(&wil->mutex);
  1337. if (!wil_has_other_active_ifaces(wil, ndev, true, false)) {
  1338. __wil_down(wil);
  1339. rc = __wil_up(wil);
  1340. if (rc)
  1341. goto out;
  1342. }
  1343. rc = wmi_set_ssid(vif, ssid_len, ssid);
  1344. if (rc)
  1345. goto out;
  1346. rc = _wil_cfg80211_set_ies(vif, bcon);
  1347. if (rc)
  1348. goto out;
  1349. vif->privacy = privacy;
  1350. vif->channel = chan;
  1351. vif->hidden_ssid = hidden_ssid;
  1352. vif->pbss = pbss;
  1353. netif_carrier_on(ndev);
  1354. if (!wil_has_other_active_ifaces(wil, ndev, false, true))
  1355. wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
  1356. rc = wmi_pcp_start(vif, bi, wmi_nettype, chan, hidden_ssid, is_go);
  1357. if (rc)
  1358. goto err_pcp_start;
  1359. rc = wil_bcast_init(vif);
  1360. if (rc)
  1361. goto err_bcast;
  1362. goto out; /* success */
  1363. err_bcast:
  1364. wmi_pcp_stop(vif);
  1365. err_pcp_start:
  1366. netif_carrier_off(ndev);
  1367. if (!wil_has_other_active_ifaces(wil, ndev, false, true))
  1368. wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
  1369. out:
  1370. mutex_unlock(&wil->mutex);
  1371. return rc;
  1372. }
  1373. static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
  1374. struct net_device *ndev,
  1375. struct cfg80211_beacon_data *bcon)
  1376. {
  1377. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1378. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1379. int rc;
  1380. u32 privacy = 0;
  1381. wil_dbg_misc(wil, "change_beacon, mid=%d\n", vif->mid);
  1382. wil_print_bcon_data(bcon);
  1383. if (bcon->tail &&
  1384. cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
  1385. bcon->tail_len))
  1386. privacy = 1;
  1387. /* in case privacy has changed, need to restart the AP */
  1388. if (vif->privacy != privacy) {
  1389. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  1390. wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
  1391. vif->privacy, privacy);
  1392. rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
  1393. wdev->ssid_len, privacy,
  1394. wdev->beacon_interval,
  1395. vif->channel, bcon,
  1396. vif->hidden_ssid,
  1397. vif->pbss);
  1398. } else {
  1399. rc = _wil_cfg80211_set_ies(vif, bcon);
  1400. }
  1401. return rc;
  1402. }
  1403. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  1404. struct net_device *ndev,
  1405. struct cfg80211_ap_settings *info)
  1406. {
  1407. int rc;
  1408. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1409. struct ieee80211_channel *channel = info->chandef.chan;
  1410. struct cfg80211_beacon_data *bcon = &info->beacon;
  1411. struct cfg80211_crypto_settings *crypto = &info->crypto;
  1412. u8 hidden_ssid;
  1413. wil_dbg_misc(wil, "start_ap\n");
  1414. if (!channel) {
  1415. wil_err(wil, "AP: No channel???\n");
  1416. return -EINVAL;
  1417. }
  1418. switch (info->hidden_ssid) {
  1419. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  1420. hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
  1421. break;
  1422. case NL80211_HIDDEN_SSID_ZERO_LEN:
  1423. hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
  1424. break;
  1425. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  1426. hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
  1427. break;
  1428. default:
  1429. wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
  1430. return -EOPNOTSUPP;
  1431. }
  1432. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  1433. channel->center_freq, info->privacy ? "secure" : "open");
  1434. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  1435. info->privacy, info->auth_type);
  1436. wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
  1437. info->hidden_ssid);
  1438. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  1439. info->dtim_period);
  1440. wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
  1441. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  1442. info->ssid, info->ssid_len, true);
  1443. wil_print_bcon_data(bcon);
  1444. wil_print_crypto(wil, crypto);
  1445. rc = _wil_cfg80211_start_ap(wiphy, ndev,
  1446. info->ssid, info->ssid_len, info->privacy,
  1447. info->beacon_interval, channel->hw_value,
  1448. bcon, hidden_ssid, info->pbss);
  1449. return rc;
  1450. }
  1451. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  1452. struct net_device *ndev)
  1453. {
  1454. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1455. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1456. bool last;
  1457. wil_dbg_misc(wil, "stop_ap, mid=%d\n", vif->mid);
  1458. netif_carrier_off(ndev);
  1459. last = !wil_has_other_active_ifaces(wil, ndev, false, true);
  1460. if (last) {
  1461. wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
  1462. wil_set_recovery_state(wil, fw_recovery_idle);
  1463. set_bit(wil_status_resetting, wil->status);
  1464. }
  1465. mutex_lock(&wil->mutex);
  1466. wmi_pcp_stop(vif);
  1467. if (last)
  1468. __wil_down(wil);
  1469. else
  1470. wil_bcast_fini(vif);
  1471. mutex_unlock(&wil->mutex);
  1472. return 0;
  1473. }
  1474. static int wil_cfg80211_add_station(struct wiphy *wiphy,
  1475. struct net_device *dev,
  1476. const u8 *mac,
  1477. struct station_parameters *params)
  1478. {
  1479. struct wil6210_vif *vif = ndev_to_vif(dev);
  1480. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1481. wil_dbg_misc(wil, "add station %pM aid %d mid %d\n",
  1482. mac, params->aid, vif->mid);
  1483. if (!disable_ap_sme) {
  1484. wil_err(wil, "not supported with AP SME enabled\n");
  1485. return -EOPNOTSUPP;
  1486. }
  1487. if (params->aid > WIL_MAX_DMG_AID) {
  1488. wil_err(wil, "invalid aid\n");
  1489. return -EINVAL;
  1490. }
  1491. return wmi_new_sta(vif, mac, params->aid);
  1492. }
  1493. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  1494. struct net_device *dev,
  1495. struct station_del_parameters *params)
  1496. {
  1497. struct wil6210_vif *vif = ndev_to_vif(dev);
  1498. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1499. wil_dbg_misc(wil, "del_station: %pM, reason=%d mid=%d\n",
  1500. params->mac, params->reason_code, vif->mid);
  1501. mutex_lock(&wil->mutex);
  1502. wil6210_disconnect(vif, params->mac, params->reason_code, false);
  1503. mutex_unlock(&wil->mutex);
  1504. return 0;
  1505. }
  1506. static int wil_cfg80211_change_station(struct wiphy *wiphy,
  1507. struct net_device *dev,
  1508. const u8 *mac,
  1509. struct station_parameters *params)
  1510. {
  1511. struct wil6210_vif *vif = ndev_to_vif(dev);
  1512. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1513. int authorize;
  1514. int cid, i;
  1515. struct wil_ring_tx_data *txdata = NULL;
  1516. wil_dbg_misc(wil, "change station %pM mask 0x%x set 0x%x mid %d\n",
  1517. mac, params->sta_flags_mask, params->sta_flags_set,
  1518. vif->mid);
  1519. if (!disable_ap_sme) {
  1520. wil_dbg_misc(wil, "not supported with AP SME enabled\n");
  1521. return -EOPNOTSUPP;
  1522. }
  1523. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  1524. return 0;
  1525. cid = wil_find_cid(wil, vif->mid, mac);
  1526. if (cid < 0) {
  1527. wil_err(wil, "station not found\n");
  1528. return -ENOLINK;
  1529. }
  1530. for (i = 0; i < ARRAY_SIZE(wil->ring2cid_tid); i++)
  1531. if (wil->ring2cid_tid[i][0] == cid) {
  1532. txdata = &wil->ring_tx_data[i];
  1533. break;
  1534. }
  1535. if (!txdata) {
  1536. wil_err(wil, "ring data not found\n");
  1537. return -ENOLINK;
  1538. }
  1539. authorize = params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED);
  1540. txdata->dot1x_open = authorize ? 1 : 0;
  1541. wil_dbg_misc(wil, "cid %d ring %d authorize %d\n", cid, i,
  1542. txdata->dot1x_open);
  1543. return 0;
  1544. }
  1545. /* probe_client handling */
  1546. static void wil_probe_client_handle(struct wil6210_priv *wil,
  1547. struct wil6210_vif *vif,
  1548. struct wil_probe_client_req *req)
  1549. {
  1550. struct net_device *ndev = vif_to_ndev(vif);
  1551. struct wil_sta_info *sta = &wil->sta[req->cid];
  1552. /* assume STA is alive if it is still connected,
  1553. * else FW will disconnect it
  1554. */
  1555. bool alive = (sta->status == wil_sta_connected);
  1556. cfg80211_probe_status(ndev, sta->addr, req->cookie, alive,
  1557. 0, false, GFP_KERNEL);
  1558. }
  1559. static struct list_head *next_probe_client(struct wil6210_vif *vif)
  1560. {
  1561. struct list_head *ret = NULL;
  1562. mutex_lock(&vif->probe_client_mutex);
  1563. if (!list_empty(&vif->probe_client_pending)) {
  1564. ret = vif->probe_client_pending.next;
  1565. list_del(ret);
  1566. }
  1567. mutex_unlock(&vif->probe_client_mutex);
  1568. return ret;
  1569. }
  1570. void wil_probe_client_worker(struct work_struct *work)
  1571. {
  1572. struct wil6210_vif *vif = container_of(work, struct wil6210_vif,
  1573. probe_client_worker);
  1574. struct wil6210_priv *wil = vif_to_wil(vif);
  1575. struct wil_probe_client_req *req;
  1576. struct list_head *lh;
  1577. while ((lh = next_probe_client(vif)) != NULL) {
  1578. req = list_entry(lh, struct wil_probe_client_req, list);
  1579. wil_probe_client_handle(wil, vif, req);
  1580. kfree(req);
  1581. }
  1582. }
  1583. void wil_probe_client_flush(struct wil6210_vif *vif)
  1584. {
  1585. struct wil_probe_client_req *req, *t;
  1586. struct wil6210_priv *wil = vif_to_wil(vif);
  1587. wil_dbg_misc(wil, "probe_client_flush\n");
  1588. mutex_lock(&vif->probe_client_mutex);
  1589. list_for_each_entry_safe(req, t, &vif->probe_client_pending, list) {
  1590. list_del(&req->list);
  1591. kfree(req);
  1592. }
  1593. mutex_unlock(&vif->probe_client_mutex);
  1594. }
  1595. static int wil_cfg80211_probe_client(struct wiphy *wiphy,
  1596. struct net_device *dev,
  1597. const u8 *peer, u64 *cookie)
  1598. {
  1599. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1600. struct wil6210_vif *vif = ndev_to_vif(dev);
  1601. struct wil_probe_client_req *req;
  1602. int cid = wil_find_cid(wil, vif->mid, peer);
  1603. wil_dbg_misc(wil, "probe_client: %pM => CID %d MID %d\n",
  1604. peer, cid, vif->mid);
  1605. if (cid < 0)
  1606. return -ENOLINK;
  1607. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1608. if (!req)
  1609. return -ENOMEM;
  1610. req->cid = cid;
  1611. req->cookie = cid;
  1612. mutex_lock(&vif->probe_client_mutex);
  1613. list_add_tail(&req->list, &vif->probe_client_pending);
  1614. mutex_unlock(&vif->probe_client_mutex);
  1615. *cookie = req->cookie;
  1616. queue_work(wil->wq_service, &vif->probe_client_worker);
  1617. return 0;
  1618. }
  1619. static int wil_cfg80211_change_bss(struct wiphy *wiphy,
  1620. struct net_device *dev,
  1621. struct bss_parameters *params)
  1622. {
  1623. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1624. struct wil6210_vif *vif = ndev_to_vif(dev);
  1625. if (params->ap_isolate >= 0) {
  1626. wil_dbg_misc(wil, "change_bss: ap_isolate MID %d, %d => %d\n",
  1627. vif->mid, vif->ap_isolate, params->ap_isolate);
  1628. vif->ap_isolate = params->ap_isolate;
  1629. }
  1630. return 0;
  1631. }
  1632. static int wil_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  1633. struct net_device *dev,
  1634. bool enabled, int timeout)
  1635. {
  1636. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1637. enum wmi_ps_profile_type ps_profile;
  1638. wil_dbg_misc(wil, "enabled=%d, timeout=%d\n",
  1639. enabled, timeout);
  1640. if (enabled)
  1641. ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
  1642. else
  1643. ps_profile = WMI_PS_PROFILE_TYPE_PS_DISABLED;
  1644. return wil_ps_update(wil, ps_profile);
  1645. }
  1646. static int wil_cfg80211_suspend(struct wiphy *wiphy,
  1647. struct cfg80211_wowlan *wow)
  1648. {
  1649. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1650. int rc;
  1651. /* Setting the wakeup trigger based on wow is TBD */
  1652. if (test_bit(wil_status_suspended, wil->status)) {
  1653. wil_dbg_pm(wil, "trying to suspend while suspended\n");
  1654. return 0;
  1655. }
  1656. rc = wil_can_suspend(wil, false);
  1657. if (rc)
  1658. goto out;
  1659. wil_dbg_pm(wil, "suspending\n");
  1660. mutex_lock(&wil->mutex);
  1661. mutex_lock(&wil->vif_mutex);
  1662. wil_p2p_stop_radio_operations(wil);
  1663. wil_abort_scan_all_vifs(wil, true);
  1664. mutex_unlock(&wil->vif_mutex);
  1665. mutex_unlock(&wil->mutex);
  1666. out:
  1667. return rc;
  1668. }
  1669. static int wil_cfg80211_resume(struct wiphy *wiphy)
  1670. {
  1671. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1672. wil_dbg_pm(wil, "resuming\n");
  1673. return 0;
  1674. }
  1675. static int
  1676. wil_cfg80211_sched_scan_start(struct wiphy *wiphy,
  1677. struct net_device *dev,
  1678. struct cfg80211_sched_scan_request *request)
  1679. {
  1680. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1681. struct wil6210_vif *vif = ndev_to_vif(dev);
  1682. int i, rc;
  1683. if (vif->mid != 0)
  1684. return -EOPNOTSUPP;
  1685. wil_dbg_misc(wil,
  1686. "sched scan start: n_ssids %d, ie_len %zu, flags 0x%x\n",
  1687. request->n_ssids, request->ie_len, request->flags);
  1688. for (i = 0; i < request->n_ssids; i++) {
  1689. wil_dbg_misc(wil, "SSID[%d]:", i);
  1690. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  1691. request->ssids[i].ssid,
  1692. request->ssids[i].ssid_len, true);
  1693. }
  1694. wil_dbg_misc(wil, "channels:");
  1695. for (i = 0; i < request->n_channels; i++)
  1696. wil_dbg_misc(wil, " %d%s", request->channels[i]->hw_value,
  1697. i == request->n_channels - 1 ? "\n" : "");
  1698. wil_dbg_misc(wil, "n_match_sets %d, min_rssi_thold %d, delay %d\n",
  1699. request->n_match_sets, request->min_rssi_thold,
  1700. request->delay);
  1701. for (i = 0; i < request->n_match_sets; i++) {
  1702. struct cfg80211_match_set *ms = &request->match_sets[i];
  1703. wil_dbg_misc(wil, "MATCHSET[%d]: rssi_thold %d\n",
  1704. i, ms->rssi_thold);
  1705. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  1706. ms->ssid.ssid,
  1707. ms->ssid.ssid_len, true);
  1708. }
  1709. wil_dbg_misc(wil, "n_scan_plans %d\n", request->n_scan_plans);
  1710. for (i = 0; i < request->n_scan_plans; i++) {
  1711. struct cfg80211_sched_scan_plan *sp = &request->scan_plans[i];
  1712. wil_dbg_misc(wil, "SCAN PLAN[%d]: interval %d iterations %d\n",
  1713. i, sp->interval, sp->iterations);
  1714. }
  1715. rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
  1716. request->ie_len, request->ie);
  1717. if (rc)
  1718. return rc;
  1719. return wmi_start_sched_scan(wil, request);
  1720. }
  1721. static int
  1722. wil_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
  1723. u64 reqid)
  1724. {
  1725. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1726. struct wil6210_vif *vif = ndev_to_vif(dev);
  1727. int rc;
  1728. if (vif->mid != 0)
  1729. return -EOPNOTSUPP;
  1730. rc = wmi_stop_sched_scan(wil);
  1731. /* device would return error if it thinks PNO is already stopped.
  1732. * ignore the return code so user space and driver gets back in-sync
  1733. */
  1734. wil_dbg_misc(wil, "sched scan stopped (%d)\n", rc);
  1735. return 0;
  1736. }
  1737. static const struct cfg80211_ops wil_cfg80211_ops = {
  1738. .add_virtual_intf = wil_cfg80211_add_iface,
  1739. .del_virtual_intf = wil_cfg80211_del_iface,
  1740. .scan = wil_cfg80211_scan,
  1741. .abort_scan = wil_cfg80211_abort_scan,
  1742. .connect = wil_cfg80211_connect,
  1743. .disconnect = wil_cfg80211_disconnect,
  1744. .set_wiphy_params = wil_cfg80211_set_wiphy_params,
  1745. .change_virtual_intf = wil_cfg80211_change_iface,
  1746. .get_station = wil_cfg80211_get_station,
  1747. .dump_station = wil_cfg80211_dump_station,
  1748. .remain_on_channel = wil_remain_on_channel,
  1749. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  1750. .mgmt_tx = wil_cfg80211_mgmt_tx,
  1751. .set_monitor_channel = wil_cfg80211_set_channel,
  1752. .add_key = wil_cfg80211_add_key,
  1753. .del_key = wil_cfg80211_del_key,
  1754. .set_default_key = wil_cfg80211_set_default_key,
  1755. /* AP mode */
  1756. .change_beacon = wil_cfg80211_change_beacon,
  1757. .start_ap = wil_cfg80211_start_ap,
  1758. .stop_ap = wil_cfg80211_stop_ap,
  1759. .add_station = wil_cfg80211_add_station,
  1760. .del_station = wil_cfg80211_del_station,
  1761. .change_station = wil_cfg80211_change_station,
  1762. .probe_client = wil_cfg80211_probe_client,
  1763. .change_bss = wil_cfg80211_change_bss,
  1764. /* P2P device */
  1765. .start_p2p_device = wil_cfg80211_start_p2p_device,
  1766. .stop_p2p_device = wil_cfg80211_stop_p2p_device,
  1767. .set_power_mgmt = wil_cfg80211_set_power_mgmt,
  1768. .suspend = wil_cfg80211_suspend,
  1769. .resume = wil_cfg80211_resume,
  1770. .sched_scan_start = wil_cfg80211_sched_scan_start,
  1771. .sched_scan_stop = wil_cfg80211_sched_scan_stop,
  1772. };
  1773. static void wil_wiphy_init(struct wiphy *wiphy)
  1774. {
  1775. wiphy->max_scan_ssids = 1;
  1776. wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
  1777. wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
  1778. wiphy->max_num_pmkids = 0 /* TODO: */;
  1779. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1780. BIT(NL80211_IFTYPE_AP) |
  1781. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  1782. BIT(NL80211_IFTYPE_P2P_GO) |
  1783. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  1784. BIT(NL80211_IFTYPE_MONITOR);
  1785. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  1786. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
  1787. WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1788. if (!disable_ap_sme)
  1789. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
  1790. dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  1791. __func__, wiphy->flags);
  1792. wiphy->probe_resp_offload =
  1793. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  1794. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  1795. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  1796. wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
  1797. /* may change after reading FW capabilities */
  1798. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  1799. wiphy->cipher_suites = wil_cipher_suites;
  1800. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  1801. wiphy->mgmt_stypes = wil_mgmt_stypes;
  1802. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  1803. wiphy->n_vendor_commands = ARRAY_SIZE(wil_nl80211_vendor_commands);
  1804. wiphy->vendor_commands = wil_nl80211_vendor_commands;
  1805. #ifdef CONFIG_PM
  1806. wiphy->wowlan = &wil_wowlan_support;
  1807. #endif
  1808. }
  1809. int wil_cfg80211_iface_combinations_from_fw(
  1810. struct wil6210_priv *wil, const struct wil_fw_record_concurrency *conc)
  1811. {
  1812. struct wiphy *wiphy = wil_to_wiphy(wil);
  1813. u32 total_limits = 0;
  1814. u16 n_combos;
  1815. const struct wil_fw_concurrency_combo *combo;
  1816. const struct wil_fw_concurrency_limit *limit;
  1817. struct ieee80211_iface_combination *iface_combinations;
  1818. struct ieee80211_iface_limit *iface_limit;
  1819. int i, j;
  1820. if (wiphy->iface_combinations) {
  1821. wil_dbg_misc(wil, "iface_combinations already set, skipping\n");
  1822. return 0;
  1823. }
  1824. combo = conc->combos;
  1825. n_combos = le16_to_cpu(conc->n_combos);
  1826. for (i = 0; i < n_combos; i++) {
  1827. total_limits += combo->n_limits;
  1828. limit = combo->limits + combo->n_limits;
  1829. combo = (struct wil_fw_concurrency_combo *)limit;
  1830. }
  1831. iface_combinations =
  1832. kzalloc(n_combos * sizeof(struct ieee80211_iface_combination) +
  1833. total_limits * sizeof(struct ieee80211_iface_limit),
  1834. GFP_KERNEL);
  1835. if (!iface_combinations)
  1836. return -ENOMEM;
  1837. iface_limit = (struct ieee80211_iface_limit *)(iface_combinations +
  1838. n_combos);
  1839. combo = conc->combos;
  1840. for (i = 0; i < n_combos; i++) {
  1841. iface_combinations[i].max_interfaces = combo->max_interfaces;
  1842. iface_combinations[i].num_different_channels =
  1843. combo->n_diff_channels;
  1844. iface_combinations[i].beacon_int_infra_match =
  1845. combo->same_bi;
  1846. iface_combinations[i].n_limits = combo->n_limits;
  1847. wil_dbg_misc(wil,
  1848. "iface_combination %d: max_if %d, num_ch %d, bi_match %d\n",
  1849. i, iface_combinations[i].max_interfaces,
  1850. iface_combinations[i].num_different_channels,
  1851. iface_combinations[i].beacon_int_infra_match);
  1852. limit = combo->limits;
  1853. for (j = 0; j < combo->n_limits; j++) {
  1854. iface_limit[j].max = le16_to_cpu(limit[j].max);
  1855. iface_limit[j].types = le16_to_cpu(limit[j].types);
  1856. wil_dbg_misc(wil,
  1857. "limit %d: max %d types 0x%x\n", j,
  1858. iface_limit[j].max, iface_limit[j].types);
  1859. }
  1860. iface_combinations[i].limits = iface_limit;
  1861. iface_limit += combo->n_limits;
  1862. limit += combo->n_limits;
  1863. combo = (struct wil_fw_concurrency_combo *)limit;
  1864. }
  1865. wil_dbg_misc(wil, "multiple VIFs supported, n_mids %d\n", conc->n_mids);
  1866. wil->max_vifs = conc->n_mids + 1; /* including main interface */
  1867. if (wil->max_vifs > WIL_MAX_VIFS) {
  1868. wil_info(wil, "limited number of VIFs supported(%d, FW %d)\n",
  1869. WIL_MAX_VIFS, wil->max_vifs);
  1870. wil->max_vifs = WIL_MAX_VIFS;
  1871. }
  1872. wiphy->n_iface_combinations = n_combos;
  1873. wiphy->iface_combinations = iface_combinations;
  1874. return 0;
  1875. }
  1876. struct wil6210_priv *wil_cfg80211_init(struct device *dev)
  1877. {
  1878. struct wiphy *wiphy;
  1879. struct wil6210_priv *wil;
  1880. struct ieee80211_channel *ch;
  1881. dev_dbg(dev, "%s()\n", __func__);
  1882. /* Note: the wireless_dev structure is no longer allocated here.
  1883. * Instead, it is allocated as part of the net_device structure
  1884. * for main interface and each VIF.
  1885. */
  1886. wiphy = wiphy_new(&wil_cfg80211_ops, sizeof(struct wil6210_priv));
  1887. if (!wiphy)
  1888. return ERR_PTR(-ENOMEM);
  1889. set_wiphy_dev(wiphy, dev);
  1890. wil_wiphy_init(wiphy);
  1891. wil = wiphy_to_wil(wiphy);
  1892. wil->wiphy = wiphy;
  1893. /* default monitor channel */
  1894. ch = wiphy->bands[NL80211_BAND_60GHZ]->channels;
  1895. cfg80211_chandef_create(&wil->monitor_chandef, ch, NL80211_CHAN_NO_HT);
  1896. return wil;
  1897. }
  1898. void wil_cfg80211_deinit(struct wil6210_priv *wil)
  1899. {
  1900. struct wiphy *wiphy = wil_to_wiphy(wil);
  1901. dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
  1902. if (!wiphy)
  1903. return;
  1904. kfree(wiphy->iface_combinations);
  1905. wiphy->iface_combinations = NULL;
  1906. wiphy_free(wiphy);
  1907. /* do not access wil6210_priv after returning from here */
  1908. }
  1909. void wil_p2p_wdev_free(struct wil6210_priv *wil)
  1910. {
  1911. struct wireless_dev *p2p_wdev;
  1912. mutex_lock(&wil->vif_mutex);
  1913. p2p_wdev = wil->p2p_wdev;
  1914. wil->p2p_wdev = NULL;
  1915. wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
  1916. mutex_unlock(&wil->vif_mutex);
  1917. if (p2p_wdev) {
  1918. cfg80211_unregister_wdev(p2p_wdev);
  1919. kfree(p2p_wdev);
  1920. }
  1921. }
  1922. static int wil_rf_sector_status_to_rc(u8 status)
  1923. {
  1924. switch (status) {
  1925. case WMI_RF_SECTOR_STATUS_SUCCESS:
  1926. return 0;
  1927. case WMI_RF_SECTOR_STATUS_BAD_PARAMETERS_ERROR:
  1928. return -EINVAL;
  1929. case WMI_RF_SECTOR_STATUS_BUSY_ERROR:
  1930. return -EAGAIN;
  1931. case WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR:
  1932. return -EOPNOTSUPP;
  1933. default:
  1934. return -EINVAL;
  1935. }
  1936. }
  1937. static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
  1938. struct wireless_dev *wdev,
  1939. const void *data, int data_len)
  1940. {
  1941. struct wil6210_priv *wil = wdev_to_wil(wdev);
  1942. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  1943. int rc;
  1944. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  1945. u16 sector_index;
  1946. u8 sector_type;
  1947. u32 rf_modules_vec;
  1948. struct wmi_get_rf_sector_params_cmd cmd;
  1949. struct {
  1950. struct wmi_cmd_hdr wmi;
  1951. struct wmi_get_rf_sector_params_done_event evt;
  1952. } __packed reply = {
  1953. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  1954. };
  1955. struct sk_buff *msg;
  1956. struct nlattr *nl_cfgs, *nl_cfg;
  1957. u32 i;
  1958. struct wmi_rf_sector_info *si;
  1959. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  1960. return -EOPNOTSUPP;
  1961. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  1962. wil_rf_sector_policy, NULL);
  1963. if (rc) {
  1964. wil_err(wil, "Invalid rf sector ATTR\n");
  1965. return rc;
  1966. }
  1967. if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
  1968. !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
  1969. !tb[QCA_ATTR_DMG_RF_MODULE_MASK]) {
  1970. wil_err(wil, "Invalid rf sector spec\n");
  1971. return -EINVAL;
  1972. }
  1973. sector_index = nla_get_u16(
  1974. tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
  1975. if (sector_index >= WIL_MAX_RF_SECTORS) {
  1976. wil_err(wil, "Invalid sector index %d\n", sector_index);
  1977. return -EINVAL;
  1978. }
  1979. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  1980. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  1981. wil_err(wil, "Invalid sector type %d\n", sector_type);
  1982. return -EINVAL;
  1983. }
  1984. rf_modules_vec = nla_get_u32(
  1985. tb[QCA_ATTR_DMG_RF_MODULE_MASK]);
  1986. if (rf_modules_vec >= BIT(WMI_MAX_RF_MODULES_NUM)) {
  1987. wil_err(wil, "Invalid rf module mask 0x%x\n", rf_modules_vec);
  1988. return -EINVAL;
  1989. }
  1990. cmd.sector_idx = cpu_to_le16(sector_index);
  1991. cmd.sector_type = sector_type;
  1992. cmd.rf_modules_vec = rf_modules_vec & 0xFF;
  1993. rc = wmi_call(wil, WMI_GET_RF_SECTOR_PARAMS_CMDID, vif->mid,
  1994. &cmd, sizeof(cmd), WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID,
  1995. &reply, sizeof(reply),
  1996. 500);
  1997. if (rc)
  1998. return rc;
  1999. if (reply.evt.status) {
  2000. wil_err(wil, "get rf sector cfg failed with status %d\n",
  2001. reply.evt.status);
  2002. return wil_rf_sector_status_to_rc(reply.evt.status);
  2003. }
  2004. msg = cfg80211_vendor_cmd_alloc_reply_skb(
  2005. wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
  2006. if (!msg)
  2007. return -ENOMEM;
  2008. if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
  2009. le64_to_cpu(reply.evt.tsf),
  2010. QCA_ATTR_PAD))
  2011. goto nla_put_failure;
  2012. nl_cfgs = nla_nest_start(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
  2013. if (!nl_cfgs)
  2014. goto nla_put_failure;
  2015. for (i = 0; i < WMI_MAX_RF_MODULES_NUM; i++) {
  2016. if (!(rf_modules_vec & BIT(i)))
  2017. continue;
  2018. nl_cfg = nla_nest_start(msg, i);
  2019. if (!nl_cfg)
  2020. goto nla_put_failure;
  2021. si = &reply.evt.sectors_info[i];
  2022. if (nla_put_u8(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
  2023. i) ||
  2024. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
  2025. le32_to_cpu(si->etype0)) ||
  2026. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
  2027. le32_to_cpu(si->etype1)) ||
  2028. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
  2029. le32_to_cpu(si->etype2)) ||
  2030. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
  2031. le32_to_cpu(si->psh_hi)) ||
  2032. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
  2033. le32_to_cpu(si->psh_lo)) ||
  2034. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
  2035. le32_to_cpu(si->dtype_swch_off)))
  2036. goto nla_put_failure;
  2037. nla_nest_end(msg, nl_cfg);
  2038. }
  2039. nla_nest_end(msg, nl_cfgs);
  2040. rc = cfg80211_vendor_cmd_reply(msg);
  2041. return rc;
  2042. nla_put_failure:
  2043. kfree_skb(msg);
  2044. return -ENOBUFS;
  2045. }
  2046. static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
  2047. struct wireless_dev *wdev,
  2048. const void *data, int data_len)
  2049. {
  2050. struct wil6210_priv *wil = wdev_to_wil(wdev);
  2051. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  2052. int rc, tmp;
  2053. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  2054. struct nlattr *tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1];
  2055. u16 sector_index, rf_module_index;
  2056. u8 sector_type;
  2057. u32 rf_modules_vec = 0;
  2058. struct wmi_set_rf_sector_params_cmd cmd;
  2059. struct {
  2060. struct wmi_cmd_hdr wmi;
  2061. struct wmi_set_rf_sector_params_done_event evt;
  2062. } __packed reply = {
  2063. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  2064. };
  2065. struct nlattr *nl_cfg;
  2066. struct wmi_rf_sector_info *si;
  2067. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  2068. return -EOPNOTSUPP;
  2069. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  2070. wil_rf_sector_policy, NULL);
  2071. if (rc) {
  2072. wil_err(wil, "Invalid rf sector ATTR\n");
  2073. return rc;
  2074. }
  2075. if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
  2076. !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
  2077. !tb[QCA_ATTR_DMG_RF_SECTOR_CFG]) {
  2078. wil_err(wil, "Invalid rf sector spec\n");
  2079. return -EINVAL;
  2080. }
  2081. sector_index = nla_get_u16(
  2082. tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
  2083. if (sector_index >= WIL_MAX_RF_SECTORS) {
  2084. wil_err(wil, "Invalid sector index %d\n", sector_index);
  2085. return -EINVAL;
  2086. }
  2087. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  2088. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  2089. wil_err(wil, "Invalid sector type %d\n", sector_type);
  2090. return -EINVAL;
  2091. }
  2092. memset(&cmd, 0, sizeof(cmd));
  2093. cmd.sector_idx = cpu_to_le16(sector_index);
  2094. cmd.sector_type = sector_type;
  2095. nla_for_each_nested(nl_cfg, tb[QCA_ATTR_DMG_RF_SECTOR_CFG],
  2096. tmp) {
  2097. rc = nla_parse_nested(tb2, QCA_ATTR_DMG_RF_SECTOR_CFG_MAX,
  2098. nl_cfg, wil_rf_sector_cfg_policy,
  2099. NULL);
  2100. if (rc) {
  2101. wil_err(wil, "invalid sector cfg\n");
  2102. return -EINVAL;
  2103. }
  2104. if (!tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] ||
  2105. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] ||
  2106. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] ||
  2107. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] ||
  2108. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] ||
  2109. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] ||
  2110. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]) {
  2111. wil_err(wil, "missing cfg params\n");
  2112. return -EINVAL;
  2113. }
  2114. rf_module_index = nla_get_u8(
  2115. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX]);
  2116. if (rf_module_index >= WMI_MAX_RF_MODULES_NUM) {
  2117. wil_err(wil, "invalid RF module index %d\n",
  2118. rf_module_index);
  2119. return -EINVAL;
  2120. }
  2121. rf_modules_vec |= BIT(rf_module_index);
  2122. si = &cmd.sectors_info[rf_module_index];
  2123. si->etype0 = cpu_to_le32(nla_get_u32(
  2124. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0]));
  2125. si->etype1 = cpu_to_le32(nla_get_u32(
  2126. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1]));
  2127. si->etype2 = cpu_to_le32(nla_get_u32(
  2128. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2]));
  2129. si->psh_hi = cpu_to_le32(nla_get_u32(
  2130. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI]));
  2131. si->psh_lo = cpu_to_le32(nla_get_u32(
  2132. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO]));
  2133. si->dtype_swch_off = cpu_to_le32(nla_get_u32(
  2134. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]));
  2135. }
  2136. cmd.rf_modules_vec = rf_modules_vec & 0xFF;
  2137. rc = wmi_call(wil, WMI_SET_RF_SECTOR_PARAMS_CMDID, vif->mid,
  2138. &cmd, sizeof(cmd), WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID,
  2139. &reply, sizeof(reply),
  2140. 500);
  2141. if (rc)
  2142. return rc;
  2143. return wil_rf_sector_status_to_rc(reply.evt.status);
  2144. }
  2145. static int wil_rf_sector_get_selected(struct wiphy *wiphy,
  2146. struct wireless_dev *wdev,
  2147. const void *data, int data_len)
  2148. {
  2149. struct wil6210_priv *wil = wdev_to_wil(wdev);
  2150. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  2151. int rc;
  2152. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  2153. u8 sector_type, mac_addr[ETH_ALEN];
  2154. int cid = 0;
  2155. struct wmi_get_selected_rf_sector_index_cmd cmd;
  2156. struct {
  2157. struct wmi_cmd_hdr wmi;
  2158. struct wmi_get_selected_rf_sector_index_done_event evt;
  2159. } __packed reply = {
  2160. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  2161. };
  2162. struct sk_buff *msg;
  2163. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  2164. return -EOPNOTSUPP;
  2165. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  2166. wil_rf_sector_policy, NULL);
  2167. if (rc) {
  2168. wil_err(wil, "Invalid rf sector ATTR\n");
  2169. return rc;
  2170. }
  2171. if (!tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
  2172. wil_err(wil, "Invalid rf sector spec\n");
  2173. return -EINVAL;
  2174. }
  2175. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  2176. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  2177. wil_err(wil, "Invalid sector type %d\n", sector_type);
  2178. return -EINVAL;
  2179. }
  2180. if (tb[QCA_ATTR_MAC_ADDR]) {
  2181. ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
  2182. cid = wil_find_cid(wil, vif->mid, mac_addr);
  2183. if (cid < 0) {
  2184. wil_err(wil, "invalid MAC address %pM\n", mac_addr);
  2185. return -ENOENT;
  2186. }
  2187. } else {
  2188. if (test_bit(wil_vif_fwconnected, vif->status)) {
  2189. wil_err(wil, "must specify MAC address when connected\n");
  2190. return -EINVAL;
  2191. }
  2192. }
  2193. memset(&cmd, 0, sizeof(cmd));
  2194. cmd.cid = (u8)cid;
  2195. cmd.sector_type = sector_type;
  2196. rc = wmi_call(wil, WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID, vif->mid,
  2197. &cmd, sizeof(cmd),
  2198. WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
  2199. &reply, sizeof(reply),
  2200. 500);
  2201. if (rc)
  2202. return rc;
  2203. if (reply.evt.status) {
  2204. wil_err(wil, "get rf selected sector cfg failed with status %d\n",
  2205. reply.evt.status);
  2206. return wil_rf_sector_status_to_rc(reply.evt.status);
  2207. }
  2208. msg = cfg80211_vendor_cmd_alloc_reply_skb(
  2209. wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
  2210. if (!msg)
  2211. return -ENOMEM;
  2212. if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
  2213. le64_to_cpu(reply.evt.tsf),
  2214. QCA_ATTR_PAD) ||
  2215. nla_put_u16(msg, QCA_ATTR_DMG_RF_SECTOR_INDEX,
  2216. le16_to_cpu(reply.evt.sector_idx)))
  2217. goto nla_put_failure;
  2218. rc = cfg80211_vendor_cmd_reply(msg);
  2219. return rc;
  2220. nla_put_failure:
  2221. kfree_skb(msg);
  2222. return -ENOBUFS;
  2223. }
  2224. static int wil_rf_sector_wmi_set_selected(struct wil6210_priv *wil,
  2225. u8 mid, u16 sector_index,
  2226. u8 sector_type, u8 cid)
  2227. {
  2228. struct wmi_set_selected_rf_sector_index_cmd cmd;
  2229. struct {
  2230. struct wmi_cmd_hdr wmi;
  2231. struct wmi_set_selected_rf_sector_index_done_event evt;
  2232. } __packed reply = {
  2233. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  2234. };
  2235. int rc;
  2236. memset(&cmd, 0, sizeof(cmd));
  2237. cmd.sector_idx = cpu_to_le16(sector_index);
  2238. cmd.sector_type = sector_type;
  2239. cmd.cid = (u8)cid;
  2240. rc = wmi_call(wil, WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID, mid,
  2241. &cmd, sizeof(cmd),
  2242. WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
  2243. &reply, sizeof(reply),
  2244. 500);
  2245. if (rc)
  2246. return rc;
  2247. return wil_rf_sector_status_to_rc(reply.evt.status);
  2248. }
  2249. static int wil_rf_sector_set_selected(struct wiphy *wiphy,
  2250. struct wireless_dev *wdev,
  2251. const void *data, int data_len)
  2252. {
  2253. struct wil6210_priv *wil = wdev_to_wil(wdev);
  2254. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  2255. int rc;
  2256. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  2257. u16 sector_index;
  2258. u8 sector_type, mac_addr[ETH_ALEN], i;
  2259. int cid = 0;
  2260. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  2261. return -EOPNOTSUPP;
  2262. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  2263. wil_rf_sector_policy, NULL);
  2264. if (rc) {
  2265. wil_err(wil, "Invalid rf sector ATTR\n");
  2266. return rc;
  2267. }
  2268. if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
  2269. !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
  2270. wil_err(wil, "Invalid rf sector spec\n");
  2271. return -EINVAL;
  2272. }
  2273. sector_index = nla_get_u16(
  2274. tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
  2275. if (sector_index >= WIL_MAX_RF_SECTORS &&
  2276. sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
  2277. wil_err(wil, "Invalid sector index %d\n", sector_index);
  2278. return -EINVAL;
  2279. }
  2280. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  2281. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  2282. wil_err(wil, "Invalid sector type %d\n", sector_type);
  2283. return -EINVAL;
  2284. }
  2285. if (tb[QCA_ATTR_MAC_ADDR]) {
  2286. ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
  2287. if (!is_broadcast_ether_addr(mac_addr)) {
  2288. cid = wil_find_cid(wil, vif->mid, mac_addr);
  2289. if (cid < 0) {
  2290. wil_err(wil, "invalid MAC address %pM\n",
  2291. mac_addr);
  2292. return -ENOENT;
  2293. }
  2294. } else {
  2295. if (sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
  2296. wil_err(wil, "broadcast MAC valid only with unlocking\n");
  2297. return -EINVAL;
  2298. }
  2299. cid = -1;
  2300. }
  2301. } else {
  2302. if (test_bit(wil_vif_fwconnected, vif->status)) {
  2303. wil_err(wil, "must specify MAC address when connected\n");
  2304. return -EINVAL;
  2305. }
  2306. /* otherwise, using cid=0 for unassociated station */
  2307. }
  2308. if (cid >= 0) {
  2309. rc = wil_rf_sector_wmi_set_selected(wil, vif->mid, sector_index,
  2310. sector_type, cid);
  2311. } else {
  2312. /* unlock all cids */
  2313. rc = wil_rf_sector_wmi_set_selected(
  2314. wil, vif->mid, WMI_INVALID_RF_SECTOR_INDEX,
  2315. sector_type, WIL_CID_ALL);
  2316. if (rc == -EINVAL) {
  2317. for (i = 0; i < WIL6210_MAX_CID; i++) {
  2318. if (wil->sta[i].mid != vif->mid)
  2319. continue;
  2320. rc = wil_rf_sector_wmi_set_selected(
  2321. wil, vif->mid,
  2322. WMI_INVALID_RF_SECTOR_INDEX,
  2323. sector_type, i);
  2324. /* the FW will silently ignore and return
  2325. * success for unused cid, so abort the loop
  2326. * on any other error
  2327. */
  2328. if (rc) {
  2329. wil_err(wil, "unlock cid %d failed with status %d\n",
  2330. i, rc);
  2331. break;
  2332. }
  2333. }
  2334. }
  2335. }
  2336. return rc;
  2337. }