cfg80211.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678
  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(NL80211_STA_INFO_RX_BYTES) |
  275. BIT(NL80211_STA_INFO_TX_BYTES) |
  276. BIT(NL80211_STA_INFO_RX_PACKETS) |
  277. BIT(NL80211_STA_INFO_TX_PACKETS) |
  278. BIT(NL80211_STA_INFO_RX_BITRATE) |
  279. BIT(NL80211_STA_INFO_TX_BITRATE) |
  280. BIT(NL80211_STA_INFO_RX_DROP_MISC) |
  281. BIT(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(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. /* check we are client side */
  599. switch (wdev->iftype) {
  600. case NL80211_IFTYPE_STATION:
  601. case NL80211_IFTYPE_P2P_CLIENT:
  602. case NL80211_IFTYPE_P2P_DEVICE:
  603. break;
  604. default:
  605. return -EOPNOTSUPP;
  606. }
  607. /* FW don't support scan after connection attempt */
  608. if (test_bit(wil_status_dontscan, wil->status)) {
  609. wil_err(wil, "Can't scan now\n");
  610. return -EBUSY;
  611. }
  612. mutex_lock(&wil->mutex);
  613. mutex_lock(&wil->vif_mutex);
  614. if (vif->scan_request || vif->p2p.discovery_started) {
  615. wil_err(wil, "Already scanning\n");
  616. mutex_unlock(&wil->vif_mutex);
  617. rc = -EAGAIN;
  618. goto out;
  619. }
  620. mutex_unlock(&wil->vif_mutex);
  621. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
  622. if (!wil->p2p_dev_started) {
  623. wil_err(wil, "P2P search requested on stopped P2P device\n");
  624. rc = -EIO;
  625. goto out;
  626. }
  627. /* social scan on P2P_DEVICE is handled as p2p search */
  628. if (wil_p2p_is_social_scan(request)) {
  629. vif->scan_request = request;
  630. if (vif->mid == 0)
  631. wil->radio_wdev = wdev;
  632. rc = wil_p2p_search(vif, request);
  633. if (rc) {
  634. if (vif->mid == 0)
  635. wil->radio_wdev =
  636. wil->main_ndev->ieee80211_ptr;
  637. vif->scan_request = NULL;
  638. }
  639. goto out;
  640. }
  641. }
  642. (void)wil_p2p_stop_discovery(vif);
  643. wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
  644. wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
  645. for (i = 0; i < request->n_ssids; i++) {
  646. wil_dbg_misc(wil, "SSID[%d]", i);
  647. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  648. request->ssids[i].ssid,
  649. request->ssids[i].ssid_len, true);
  650. }
  651. if (request->n_ssids)
  652. rc = wmi_set_ssid(vif, request->ssids[0].ssid_len,
  653. request->ssids[0].ssid);
  654. else
  655. rc = wmi_set_ssid(vif, 0, NULL);
  656. if (rc) {
  657. wil_err(wil, "set SSID for scan request failed: %d\n", rc);
  658. goto out;
  659. }
  660. vif->scan_request = request;
  661. mod_timer(&vif->scan_timer, jiffies + WIL6210_SCAN_TO);
  662. memset(&cmd, 0, sizeof(cmd));
  663. cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
  664. cmd.cmd.num_channels = 0;
  665. n = min(request->n_channels, 4U);
  666. for (i = 0; i < n; i++) {
  667. int ch = request->channels[i]->hw_value;
  668. if (ch == 0) {
  669. wil_err(wil,
  670. "Scan requested for unknown frequency %dMhz\n",
  671. request->channels[i]->center_freq);
  672. continue;
  673. }
  674. /* 0-based channel indexes */
  675. cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
  676. wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
  677. request->channels[i]->center_freq);
  678. }
  679. if (request->ie_len)
  680. wil_hex_dump_misc("Scan IE ", DUMP_PREFIX_OFFSET, 16, 1,
  681. request->ie, request->ie_len, true);
  682. else
  683. wil_dbg_misc(wil, "Scan has no IE's\n");
  684. rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
  685. request->ie_len, request->ie);
  686. if (rc)
  687. goto out_restore;
  688. if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
  689. cmd.cmd.discovery_mode = 1;
  690. wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
  691. }
  692. if (vif->mid == 0)
  693. wil->radio_wdev = wdev;
  694. rc = wmi_send(wil, WMI_START_SCAN_CMDID, vif->mid,
  695. &cmd, sizeof(cmd.cmd) +
  696. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  697. out_restore:
  698. if (rc) {
  699. del_timer_sync(&vif->scan_timer);
  700. if (vif->mid == 0)
  701. wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
  702. vif->scan_request = NULL;
  703. }
  704. out:
  705. mutex_unlock(&wil->mutex);
  706. return rc;
  707. }
  708. static void wil_cfg80211_abort_scan(struct wiphy *wiphy,
  709. struct wireless_dev *wdev)
  710. {
  711. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  712. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  713. wil_dbg_misc(wil, "wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
  714. mutex_lock(&wil->mutex);
  715. mutex_lock(&wil->vif_mutex);
  716. if (!vif->scan_request)
  717. goto out;
  718. if (wdev != vif->scan_request->wdev) {
  719. wil_dbg_misc(wil, "abort scan was called on the wrong iface\n");
  720. goto out;
  721. }
  722. if (wdev == wil->p2p_wdev && wil->radio_wdev == wil->p2p_wdev)
  723. wil_p2p_stop_radio_operations(wil);
  724. else
  725. wil_abort_scan(vif, true);
  726. out:
  727. mutex_unlock(&wil->vif_mutex);
  728. mutex_unlock(&wil->mutex);
  729. }
  730. static void wil_print_crypto(struct wil6210_priv *wil,
  731. struct cfg80211_crypto_settings *c)
  732. {
  733. int i, n;
  734. wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
  735. c->wpa_versions, c->cipher_group);
  736. wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
  737. n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
  738. for (i = 0; i < n; i++)
  739. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  740. c->ciphers_pairwise[i]);
  741. wil_dbg_misc(wil, "}\n");
  742. wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
  743. n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
  744. for (i = 0; i < n; i++)
  745. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  746. c->akm_suites[i]);
  747. wil_dbg_misc(wil, "}\n");
  748. wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
  749. c->control_port, be16_to_cpu(c->control_port_ethertype),
  750. c->control_port_no_encrypt);
  751. }
  752. static void wil_print_connect_params(struct wil6210_priv *wil,
  753. struct cfg80211_connect_params *sme)
  754. {
  755. wil_info(wil, "Connecting to:\n");
  756. if (sme->channel) {
  757. wil_info(wil, " Channel: %d freq %d\n",
  758. sme->channel->hw_value, sme->channel->center_freq);
  759. }
  760. if (sme->bssid)
  761. wil_info(wil, " BSSID: %pM\n", sme->bssid);
  762. if (sme->ssid)
  763. print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
  764. 16, 1, sme->ssid, sme->ssid_len, true);
  765. wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
  766. wil_info(wil, " PBSS: %d\n", sme->pbss);
  767. wil_print_crypto(wil, &sme->crypto);
  768. }
  769. static int wil_cfg80211_connect(struct wiphy *wiphy,
  770. struct net_device *ndev,
  771. struct cfg80211_connect_params *sme)
  772. {
  773. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  774. struct wil6210_vif *vif = ndev_to_vif(ndev);
  775. struct cfg80211_bss *bss;
  776. struct wmi_connect_cmd conn;
  777. const u8 *ssid_eid;
  778. const u8 *rsn_eid;
  779. int ch;
  780. int rc = 0;
  781. enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
  782. wil_dbg_misc(wil, "connect, mid=%d\n", vif->mid);
  783. wil_print_connect_params(wil, sme);
  784. if (test_bit(wil_vif_fwconnecting, vif->status) ||
  785. test_bit(wil_vif_fwconnected, vif->status))
  786. return -EALREADY;
  787. if (sme->ie_len > WMI_MAX_IE_LEN) {
  788. wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
  789. return -ERANGE;
  790. }
  791. rsn_eid = sme->ie ?
  792. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  793. NULL;
  794. if (sme->privacy && !rsn_eid)
  795. wil_info(wil, "WSC connection\n");
  796. if (sme->pbss)
  797. bss_type = IEEE80211_BSS_TYPE_PBSS;
  798. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  799. sme->ssid, sme->ssid_len,
  800. bss_type, IEEE80211_PRIVACY_ANY);
  801. if (!bss) {
  802. wil_err(wil, "Unable to find BSS\n");
  803. return -ENOENT;
  804. }
  805. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  806. if (!ssid_eid) {
  807. wil_err(wil, "No SSID\n");
  808. rc = -ENOENT;
  809. goto out;
  810. }
  811. vif->privacy = sme->privacy;
  812. vif->pbss = sme->pbss;
  813. if (vif->privacy) {
  814. /* For secure assoc, remove old keys */
  815. rc = wmi_del_cipher_key(vif, 0, bss->bssid,
  816. WMI_KEY_USE_PAIRWISE);
  817. if (rc) {
  818. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
  819. goto out;
  820. }
  821. rc = wmi_del_cipher_key(vif, 0, bss->bssid,
  822. WMI_KEY_USE_RX_GROUP);
  823. if (rc) {
  824. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
  825. goto out;
  826. }
  827. }
  828. /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
  829. * elements. Send it also in case it's empty, to erase previously set
  830. * ies in FW.
  831. */
  832. rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  833. if (rc)
  834. goto out;
  835. /* WMI_CONNECT_CMD */
  836. memset(&conn, 0, sizeof(conn));
  837. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  838. case WLAN_CAPABILITY_DMG_TYPE_AP:
  839. conn.network_type = WMI_NETTYPE_INFRA;
  840. break;
  841. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  842. conn.network_type = WMI_NETTYPE_P2P;
  843. break;
  844. default:
  845. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  846. bss->capability);
  847. goto out;
  848. }
  849. if (vif->privacy) {
  850. if (rsn_eid) { /* regular secure connection */
  851. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  852. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  853. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  854. conn.pairwise_crypto_len = 16;
  855. conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
  856. conn.group_crypto_len = 16;
  857. } else { /* WSC */
  858. conn.dot11_auth_mode = WMI_AUTH11_WSC;
  859. conn.auth_mode = WMI_AUTH_NONE;
  860. }
  861. } else { /* insecure connection */
  862. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  863. conn.auth_mode = WMI_AUTH_NONE;
  864. }
  865. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  866. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  867. ch = bss->channel->hw_value;
  868. if (ch == 0) {
  869. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  870. bss->channel->center_freq);
  871. rc = -EOPNOTSUPP;
  872. goto out;
  873. }
  874. conn.channel = ch - 1;
  875. ether_addr_copy(conn.bssid, bss->bssid);
  876. ether_addr_copy(conn.dst_mac, bss->bssid);
  877. set_bit(wil_vif_fwconnecting, vif->status);
  878. rc = wmi_send(wil, WMI_CONNECT_CMDID, vif->mid, &conn, sizeof(conn));
  879. if (rc == 0) {
  880. netif_carrier_on(ndev);
  881. if (!wil_has_other_active_ifaces(wil, ndev, false, true))
  882. wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
  883. vif->bss = bss;
  884. /* Connect can take lots of time */
  885. mod_timer(&vif->connect_timer,
  886. jiffies + msecs_to_jiffies(5000));
  887. } else {
  888. clear_bit(wil_vif_fwconnecting, vif->status);
  889. }
  890. out:
  891. cfg80211_put_bss(wiphy, bss);
  892. return rc;
  893. }
  894. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  895. struct net_device *ndev,
  896. u16 reason_code)
  897. {
  898. int rc;
  899. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  900. struct wil6210_vif *vif = ndev_to_vif(ndev);
  901. wil_dbg_misc(wil, "disconnect: reason=%d, mid=%d\n",
  902. reason_code, vif->mid);
  903. if (!(test_bit(wil_vif_fwconnecting, vif->status) ||
  904. test_bit(wil_vif_fwconnected, vif->status))) {
  905. wil_err(wil, "Disconnect was called while disconnected\n");
  906. return 0;
  907. }
  908. vif->locally_generated_disc = true;
  909. rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
  910. WMI_DISCONNECT_EVENTID, NULL, 0,
  911. WIL6210_DISCONNECT_TO_MS);
  912. if (rc)
  913. wil_err(wil, "disconnect error %d\n", rc);
  914. return rc;
  915. }
  916. static int wil_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  917. {
  918. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  919. int rc;
  920. /* these parameters are explicitly not supported */
  921. if (changed & (WIPHY_PARAM_RETRY_LONG |
  922. WIPHY_PARAM_FRAG_THRESHOLD |
  923. WIPHY_PARAM_RTS_THRESHOLD))
  924. return -ENOTSUPP;
  925. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  926. rc = wmi_set_mgmt_retry(wil, wiphy->retry_short);
  927. if (rc)
  928. return rc;
  929. }
  930. return 0;
  931. }
  932. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  933. struct cfg80211_mgmt_tx_params *params,
  934. u64 *cookie)
  935. {
  936. const u8 *buf = params->buf;
  937. size_t len = params->len;
  938. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  939. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  940. int rc;
  941. bool tx_status;
  942. /* Note, currently we do not support the "wait" parameter, user-space
  943. * must call remain_on_channel before mgmt_tx or listen on a channel
  944. * another way (AP/PCP or connected station)
  945. * in addition we need to check if specified "chan" argument is
  946. * different from currently "listened" channel and fail if it is.
  947. */
  948. rc = wmi_mgmt_tx(vif, buf, len);
  949. tx_status = (rc == 0);
  950. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  951. tx_status, GFP_KERNEL);
  952. return rc;
  953. }
  954. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  955. struct cfg80211_chan_def *chandef)
  956. {
  957. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  958. wil->monitor_chandef = *chandef;
  959. return 0;
  960. }
  961. static enum wmi_key_usage wil_detect_key_usage(struct wireless_dev *wdev,
  962. bool pairwise)
  963. {
  964. struct wil6210_priv *wil = wdev_to_wil(wdev);
  965. enum wmi_key_usage rc;
  966. if (pairwise) {
  967. rc = WMI_KEY_USE_PAIRWISE;
  968. } else {
  969. switch (wdev->iftype) {
  970. case NL80211_IFTYPE_STATION:
  971. case NL80211_IFTYPE_P2P_CLIENT:
  972. rc = WMI_KEY_USE_RX_GROUP;
  973. break;
  974. case NL80211_IFTYPE_AP:
  975. case NL80211_IFTYPE_P2P_GO:
  976. rc = WMI_KEY_USE_TX_GROUP;
  977. break;
  978. default:
  979. /* TODO: Rx GTK or Tx GTK? */
  980. wil_err(wil, "Can't determine GTK type\n");
  981. rc = WMI_KEY_USE_RX_GROUP;
  982. break;
  983. }
  984. }
  985. wil_dbg_misc(wil, "detect_key_usage: -> %s\n", key_usage_str[rc]);
  986. return rc;
  987. }
  988. static struct wil_sta_info *
  989. wil_find_sta_by_key_usage(struct wil6210_priv *wil, u8 mid,
  990. enum wmi_key_usage key_usage, const u8 *mac_addr)
  991. {
  992. int cid = -EINVAL;
  993. if (key_usage == WMI_KEY_USE_TX_GROUP)
  994. return NULL; /* not needed */
  995. /* supplicant provides Rx group key in STA mode with NULL MAC address */
  996. if (mac_addr)
  997. cid = wil_find_cid(wil, mid, mac_addr);
  998. else if (key_usage == WMI_KEY_USE_RX_GROUP)
  999. cid = wil_find_cid_by_idx(wil, mid, 0);
  1000. if (cid < 0) {
  1001. wil_err(wil, "No CID for %pM %s\n", mac_addr,
  1002. key_usage_str[key_usage]);
  1003. return ERR_PTR(cid);
  1004. }
  1005. return &wil->sta[cid];
  1006. }
  1007. static void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
  1008. struct wil_sta_info *cs,
  1009. struct key_params *params)
  1010. {
  1011. struct wil_tid_crypto_rx_single *cc;
  1012. int tid;
  1013. if (!cs)
  1014. return;
  1015. switch (key_usage) {
  1016. case WMI_KEY_USE_PAIRWISE:
  1017. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1018. cc = &cs->tid_crypto_rx[tid].key_id[key_index];
  1019. if (params->seq)
  1020. memcpy(cc->pn, params->seq,
  1021. IEEE80211_GCMP_PN_LEN);
  1022. else
  1023. memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
  1024. cc->key_set = true;
  1025. }
  1026. break;
  1027. case WMI_KEY_USE_RX_GROUP:
  1028. cc = &cs->group_crypto_rx.key_id[key_index];
  1029. if (params->seq)
  1030. memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
  1031. else
  1032. memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
  1033. cc->key_set = true;
  1034. break;
  1035. default:
  1036. break;
  1037. }
  1038. }
  1039. static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
  1040. struct wil_sta_info *cs)
  1041. {
  1042. struct wil_tid_crypto_rx_single *cc;
  1043. int tid;
  1044. if (!cs)
  1045. return;
  1046. switch (key_usage) {
  1047. case WMI_KEY_USE_PAIRWISE:
  1048. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1049. cc = &cs->tid_crypto_rx[tid].key_id[key_index];
  1050. cc->key_set = false;
  1051. }
  1052. break;
  1053. case WMI_KEY_USE_RX_GROUP:
  1054. cc = &cs->group_crypto_rx.key_id[key_index];
  1055. cc->key_set = false;
  1056. break;
  1057. default:
  1058. break;
  1059. }
  1060. }
  1061. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  1062. struct net_device *ndev,
  1063. u8 key_index, bool pairwise,
  1064. const u8 *mac_addr,
  1065. struct key_params *params)
  1066. {
  1067. int rc;
  1068. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1069. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1070. struct wireless_dev *wdev = vif_to_wdev(vif);
  1071. enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
  1072. struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
  1073. key_usage,
  1074. mac_addr);
  1075. if (!params) {
  1076. wil_err(wil, "NULL params\n");
  1077. return -EINVAL;
  1078. }
  1079. wil_dbg_misc(wil, "add_key: %pM %s[%d] PN %*phN\n",
  1080. mac_addr, key_usage_str[key_usage], key_index,
  1081. params->seq_len, params->seq);
  1082. if (IS_ERR(cs)) {
  1083. wil_err(wil, "Not connected, %pM %s[%d] PN %*phN\n",
  1084. mac_addr, key_usage_str[key_usage], key_index,
  1085. params->seq_len, params->seq);
  1086. return -EINVAL;
  1087. }
  1088. wil_del_rx_key(key_index, key_usage, cs);
  1089. if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
  1090. wil_err(wil,
  1091. "Wrong PN len %d, %pM %s[%d] PN %*phN\n",
  1092. params->seq_len, mac_addr,
  1093. key_usage_str[key_usage], key_index,
  1094. params->seq_len, params->seq);
  1095. return -EINVAL;
  1096. }
  1097. rc = wmi_add_cipher_key(vif, key_index, mac_addr, params->key_len,
  1098. params->key, key_usage);
  1099. if (!rc)
  1100. wil_set_crypto_rx(key_index, key_usage, cs, params);
  1101. return rc;
  1102. }
  1103. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  1104. struct net_device *ndev,
  1105. u8 key_index, bool pairwise,
  1106. const u8 *mac_addr)
  1107. {
  1108. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1109. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1110. struct wireless_dev *wdev = vif_to_wdev(vif);
  1111. enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
  1112. struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
  1113. key_usage,
  1114. mac_addr);
  1115. wil_dbg_misc(wil, "del_key: %pM %s[%d]\n", mac_addr,
  1116. key_usage_str[key_usage], key_index);
  1117. if (IS_ERR(cs))
  1118. wil_info(wil, "Not connected, %pM %s[%d]\n",
  1119. mac_addr, key_usage_str[key_usage], key_index);
  1120. if (!IS_ERR_OR_NULL(cs))
  1121. wil_del_rx_key(key_index, key_usage, cs);
  1122. return wmi_del_cipher_key(vif, key_index, mac_addr, key_usage);
  1123. }
  1124. /* Need to be present or wiphy_new() will WARN */
  1125. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  1126. struct net_device *ndev,
  1127. u8 key_index, bool unicast,
  1128. bool multicast)
  1129. {
  1130. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1131. wil_dbg_misc(wil, "set_default_key: entered\n");
  1132. return 0;
  1133. }
  1134. static int wil_remain_on_channel(struct wiphy *wiphy,
  1135. struct wireless_dev *wdev,
  1136. struct ieee80211_channel *chan,
  1137. unsigned int duration,
  1138. u64 *cookie)
  1139. {
  1140. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1141. int rc;
  1142. wil_dbg_misc(wil,
  1143. "remain_on_channel: center_freq=%d, duration=%d iftype=%d\n",
  1144. chan->center_freq, duration, wdev->iftype);
  1145. rc = wil_p2p_listen(wil, wdev, duration, chan, cookie);
  1146. return rc;
  1147. }
  1148. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  1149. struct wireless_dev *wdev,
  1150. u64 cookie)
  1151. {
  1152. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1153. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  1154. wil_dbg_misc(wil, "cancel_remain_on_channel\n");
  1155. return wil_p2p_cancel_listen(vif, cookie);
  1156. }
  1157. /**
  1158. * find a specific IE in a list of IEs
  1159. * return a pointer to the beginning of IE in the list
  1160. * or NULL if not found
  1161. */
  1162. static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
  1163. u16 ie_len)
  1164. {
  1165. struct ieee80211_vendor_ie *vie;
  1166. u32 oui;
  1167. /* IE tag at offset 0, length at offset 1 */
  1168. if (ie_len < 2 || 2 + ie[1] > ie_len)
  1169. return NULL;
  1170. if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
  1171. return cfg80211_find_ie(ie[0], ies, ies_len);
  1172. /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
  1173. if (ie[1] < 4)
  1174. return NULL;
  1175. vie = (struct ieee80211_vendor_ie *)ie;
  1176. oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
  1177. return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
  1178. ies_len);
  1179. }
  1180. /**
  1181. * merge the IEs in two lists into a single list.
  1182. * do not include IEs from the second list which exist in the first list.
  1183. * add only vendor specific IEs from second list to keep
  1184. * the merged list sorted (since vendor-specific IE has the
  1185. * highest tag number)
  1186. * caller must free the allocated memory for merged IEs
  1187. */
  1188. static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
  1189. const u8 *ies2, u16 ies2_len,
  1190. u8 **merged_ies, u16 *merged_len)
  1191. {
  1192. u8 *buf, *dpos;
  1193. const u8 *spos;
  1194. if (ies1_len == 0 && ies2_len == 0) {
  1195. *merged_ies = NULL;
  1196. *merged_len = 0;
  1197. return 0;
  1198. }
  1199. buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
  1200. if (!buf)
  1201. return -ENOMEM;
  1202. memcpy(buf, ies1, ies1_len);
  1203. dpos = buf + ies1_len;
  1204. spos = ies2;
  1205. while (spos + 1 < ies2 + ies2_len) {
  1206. /* IE tag at offset 0, length at offset 1 */
  1207. u16 ielen = 2 + spos[1];
  1208. if (spos + ielen > ies2 + ies2_len)
  1209. break;
  1210. if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  1211. !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
  1212. memcpy(dpos, spos, ielen);
  1213. dpos += ielen;
  1214. }
  1215. spos += ielen;
  1216. }
  1217. *merged_ies = buf;
  1218. *merged_len = dpos - buf;
  1219. return 0;
  1220. }
  1221. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  1222. {
  1223. wil_hex_dump_misc("head ", DUMP_PREFIX_OFFSET, 16, 1,
  1224. b->head, b->head_len, true);
  1225. wil_hex_dump_misc("tail ", DUMP_PREFIX_OFFSET, 16, 1,
  1226. b->tail, b->tail_len, true);
  1227. wil_hex_dump_misc("BCON IE ", DUMP_PREFIX_OFFSET, 16, 1,
  1228. b->beacon_ies, b->beacon_ies_len, true);
  1229. wil_hex_dump_misc("PROBE ", DUMP_PREFIX_OFFSET, 16, 1,
  1230. b->probe_resp, b->probe_resp_len, true);
  1231. wil_hex_dump_misc("PROBE IE ", DUMP_PREFIX_OFFSET, 16, 1,
  1232. b->proberesp_ies, b->proberesp_ies_len, true);
  1233. wil_hex_dump_misc("ASSOC IE ", DUMP_PREFIX_OFFSET, 16, 1,
  1234. b->assocresp_ies, b->assocresp_ies_len, true);
  1235. }
  1236. /* internal functions for device reset and starting AP */
  1237. static int _wil_cfg80211_set_ies(struct wil6210_vif *vif,
  1238. struct cfg80211_beacon_data *bcon)
  1239. {
  1240. int rc;
  1241. u16 len = 0, proberesp_len = 0;
  1242. u8 *ies = NULL, *proberesp = NULL;
  1243. if (bcon->probe_resp) {
  1244. struct ieee80211_mgmt *f =
  1245. (struct ieee80211_mgmt *)bcon->probe_resp;
  1246. size_t hlen = offsetof(struct ieee80211_mgmt,
  1247. u.probe_resp.variable);
  1248. proberesp = f->u.probe_resp.variable;
  1249. proberesp_len = bcon->probe_resp_len - hlen;
  1250. }
  1251. rc = _wil_cfg80211_merge_extra_ies(proberesp,
  1252. proberesp_len,
  1253. bcon->proberesp_ies,
  1254. bcon->proberesp_ies_len,
  1255. &ies, &len);
  1256. if (rc)
  1257. goto out;
  1258. rc = wmi_set_ie(vif, WMI_FRAME_PROBE_RESP, len, ies);
  1259. if (rc)
  1260. goto out;
  1261. if (bcon->assocresp_ies)
  1262. rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP,
  1263. bcon->assocresp_ies_len, bcon->assocresp_ies);
  1264. else
  1265. rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP, len, ies);
  1266. #if 0 /* to use beacon IE's, remove this #if 0 */
  1267. if (rc)
  1268. goto out;
  1269. rc = wmi_set_ie(vif, WMI_FRAME_BEACON,
  1270. bcon->tail_len, bcon->tail);
  1271. #endif
  1272. out:
  1273. kfree(ies);
  1274. return rc;
  1275. }
  1276. static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
  1277. struct net_device *ndev,
  1278. const u8 *ssid, size_t ssid_len, u32 privacy,
  1279. int bi, u8 chan,
  1280. struct cfg80211_beacon_data *bcon,
  1281. u8 hidden_ssid, u32 pbss)
  1282. {
  1283. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1284. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1285. int rc;
  1286. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  1287. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  1288. u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
  1289. if (pbss)
  1290. wmi_nettype = WMI_NETTYPE_P2P;
  1291. wil_dbg_misc(wil, "start_ap: mid=%d, is_go=%d\n", vif->mid, is_go);
  1292. if (is_go && !pbss) {
  1293. wil_err(wil, "P2P GO must be in PBSS\n");
  1294. return -ENOTSUPP;
  1295. }
  1296. wil_set_recovery_state(wil, fw_recovery_idle);
  1297. mutex_lock(&wil->mutex);
  1298. if (!wil_has_other_active_ifaces(wil, ndev, true, false)) {
  1299. __wil_down(wil);
  1300. rc = __wil_up(wil);
  1301. if (rc)
  1302. goto out;
  1303. }
  1304. rc = wmi_set_ssid(vif, ssid_len, ssid);
  1305. if (rc)
  1306. goto out;
  1307. rc = _wil_cfg80211_set_ies(vif, bcon);
  1308. if (rc)
  1309. goto out;
  1310. vif->privacy = privacy;
  1311. vif->channel = chan;
  1312. vif->hidden_ssid = hidden_ssid;
  1313. vif->pbss = pbss;
  1314. netif_carrier_on(ndev);
  1315. if (!wil_has_other_active_ifaces(wil, ndev, false, true))
  1316. wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
  1317. rc = wmi_pcp_start(vif, bi, wmi_nettype, chan, hidden_ssid, is_go);
  1318. if (rc)
  1319. goto err_pcp_start;
  1320. rc = wil_bcast_init(vif);
  1321. if (rc)
  1322. goto err_bcast;
  1323. goto out; /* success */
  1324. err_bcast:
  1325. wmi_pcp_stop(vif);
  1326. err_pcp_start:
  1327. netif_carrier_off(ndev);
  1328. if (!wil_has_other_active_ifaces(wil, ndev, false, true))
  1329. wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
  1330. out:
  1331. mutex_unlock(&wil->mutex);
  1332. return rc;
  1333. }
  1334. static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
  1335. struct net_device *ndev,
  1336. struct cfg80211_beacon_data *bcon)
  1337. {
  1338. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1339. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1340. int rc;
  1341. u32 privacy = 0;
  1342. wil_dbg_misc(wil, "change_beacon, mid=%d\n", vif->mid);
  1343. wil_print_bcon_data(bcon);
  1344. if (bcon->tail &&
  1345. cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
  1346. bcon->tail_len))
  1347. privacy = 1;
  1348. /* in case privacy has changed, need to restart the AP */
  1349. if (vif->privacy != privacy) {
  1350. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  1351. wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
  1352. vif->privacy, privacy);
  1353. rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
  1354. wdev->ssid_len, privacy,
  1355. wdev->beacon_interval,
  1356. vif->channel, bcon,
  1357. vif->hidden_ssid,
  1358. vif->pbss);
  1359. } else {
  1360. rc = _wil_cfg80211_set_ies(vif, bcon);
  1361. }
  1362. return rc;
  1363. }
  1364. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  1365. struct net_device *ndev,
  1366. struct cfg80211_ap_settings *info)
  1367. {
  1368. int rc;
  1369. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1370. struct ieee80211_channel *channel = info->chandef.chan;
  1371. struct cfg80211_beacon_data *bcon = &info->beacon;
  1372. struct cfg80211_crypto_settings *crypto = &info->crypto;
  1373. u8 hidden_ssid;
  1374. wil_dbg_misc(wil, "start_ap\n");
  1375. if (!channel) {
  1376. wil_err(wil, "AP: No channel???\n");
  1377. return -EINVAL;
  1378. }
  1379. switch (info->hidden_ssid) {
  1380. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  1381. hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
  1382. break;
  1383. case NL80211_HIDDEN_SSID_ZERO_LEN:
  1384. hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
  1385. break;
  1386. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  1387. hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
  1388. break;
  1389. default:
  1390. wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
  1391. return -EOPNOTSUPP;
  1392. }
  1393. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  1394. channel->center_freq, info->privacy ? "secure" : "open");
  1395. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  1396. info->privacy, info->auth_type);
  1397. wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
  1398. info->hidden_ssid);
  1399. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  1400. info->dtim_period);
  1401. wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
  1402. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  1403. info->ssid, info->ssid_len, true);
  1404. wil_print_bcon_data(bcon);
  1405. wil_print_crypto(wil, crypto);
  1406. rc = _wil_cfg80211_start_ap(wiphy, ndev,
  1407. info->ssid, info->ssid_len, info->privacy,
  1408. info->beacon_interval, channel->hw_value,
  1409. bcon, hidden_ssid, info->pbss);
  1410. return rc;
  1411. }
  1412. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  1413. struct net_device *ndev)
  1414. {
  1415. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1416. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1417. bool last;
  1418. wil_dbg_misc(wil, "stop_ap, mid=%d\n", vif->mid);
  1419. netif_carrier_off(ndev);
  1420. last = !wil_has_other_active_ifaces(wil, ndev, false, true);
  1421. if (last) {
  1422. wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
  1423. wil_set_recovery_state(wil, fw_recovery_idle);
  1424. set_bit(wil_status_resetting, wil->status);
  1425. }
  1426. mutex_lock(&wil->mutex);
  1427. wmi_pcp_stop(vif);
  1428. if (last)
  1429. __wil_down(wil);
  1430. else
  1431. wil_bcast_fini(vif);
  1432. mutex_unlock(&wil->mutex);
  1433. return 0;
  1434. }
  1435. static int wil_cfg80211_add_station(struct wiphy *wiphy,
  1436. struct net_device *dev,
  1437. const u8 *mac,
  1438. struct station_parameters *params)
  1439. {
  1440. struct wil6210_vif *vif = ndev_to_vif(dev);
  1441. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1442. wil_dbg_misc(wil, "add station %pM aid %d mid %d\n",
  1443. mac, params->aid, vif->mid);
  1444. if (!disable_ap_sme) {
  1445. wil_err(wil, "not supported with AP SME enabled\n");
  1446. return -EOPNOTSUPP;
  1447. }
  1448. if (params->aid > WIL_MAX_DMG_AID) {
  1449. wil_err(wil, "invalid aid\n");
  1450. return -EINVAL;
  1451. }
  1452. return wmi_new_sta(vif, mac, params->aid);
  1453. }
  1454. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  1455. struct net_device *dev,
  1456. struct station_del_parameters *params)
  1457. {
  1458. struct wil6210_vif *vif = ndev_to_vif(dev);
  1459. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1460. wil_dbg_misc(wil, "del_station: %pM, reason=%d mid=%d\n",
  1461. params->mac, params->reason_code, vif->mid);
  1462. mutex_lock(&wil->mutex);
  1463. wil6210_disconnect(vif, params->mac, params->reason_code, false);
  1464. mutex_unlock(&wil->mutex);
  1465. return 0;
  1466. }
  1467. static int wil_cfg80211_change_station(struct wiphy *wiphy,
  1468. struct net_device *dev,
  1469. const u8 *mac,
  1470. struct station_parameters *params)
  1471. {
  1472. struct wil6210_vif *vif = ndev_to_vif(dev);
  1473. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1474. int authorize;
  1475. int cid, i;
  1476. struct vring_tx_data *txdata = NULL;
  1477. wil_dbg_misc(wil, "change station %pM mask 0x%x set 0x%x mid %d\n",
  1478. mac, params->sta_flags_mask, params->sta_flags_set,
  1479. vif->mid);
  1480. if (!disable_ap_sme) {
  1481. wil_dbg_misc(wil, "not supported with AP SME enabled\n");
  1482. return -EOPNOTSUPP;
  1483. }
  1484. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  1485. return 0;
  1486. cid = wil_find_cid(wil, vif->mid, mac);
  1487. if (cid < 0) {
  1488. wil_err(wil, "station not found\n");
  1489. return -ENOLINK;
  1490. }
  1491. for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++)
  1492. if (wil->vring2cid_tid[i][0] == cid) {
  1493. txdata = &wil->vring_tx_data[i];
  1494. break;
  1495. }
  1496. if (!txdata) {
  1497. wil_err(wil, "vring data not found\n");
  1498. return -ENOLINK;
  1499. }
  1500. authorize = params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED);
  1501. txdata->dot1x_open = authorize ? 1 : 0;
  1502. wil_dbg_misc(wil, "cid %d vring %d authorize %d\n", cid, i,
  1503. txdata->dot1x_open);
  1504. return 0;
  1505. }
  1506. /* probe_client handling */
  1507. static void wil_probe_client_handle(struct wil6210_priv *wil,
  1508. struct wil6210_vif *vif,
  1509. struct wil_probe_client_req *req)
  1510. {
  1511. struct net_device *ndev = vif_to_ndev(vif);
  1512. struct wil_sta_info *sta = &wil->sta[req->cid];
  1513. /* assume STA is alive if it is still connected,
  1514. * else FW will disconnect it
  1515. */
  1516. bool alive = (sta->status == wil_sta_connected);
  1517. cfg80211_probe_status(ndev, sta->addr, req->cookie, alive,
  1518. 0, false, GFP_KERNEL);
  1519. }
  1520. static struct list_head *next_probe_client(struct wil6210_vif *vif)
  1521. {
  1522. struct list_head *ret = NULL;
  1523. mutex_lock(&vif->probe_client_mutex);
  1524. if (!list_empty(&vif->probe_client_pending)) {
  1525. ret = vif->probe_client_pending.next;
  1526. list_del(ret);
  1527. }
  1528. mutex_unlock(&vif->probe_client_mutex);
  1529. return ret;
  1530. }
  1531. void wil_probe_client_worker(struct work_struct *work)
  1532. {
  1533. struct wil6210_vif *vif = container_of(work, struct wil6210_vif,
  1534. probe_client_worker);
  1535. struct wil6210_priv *wil = vif_to_wil(vif);
  1536. struct wil_probe_client_req *req;
  1537. struct list_head *lh;
  1538. while ((lh = next_probe_client(vif)) != NULL) {
  1539. req = list_entry(lh, struct wil_probe_client_req, list);
  1540. wil_probe_client_handle(wil, vif, req);
  1541. kfree(req);
  1542. }
  1543. }
  1544. void wil_probe_client_flush(struct wil6210_vif *vif)
  1545. {
  1546. struct wil_probe_client_req *req, *t;
  1547. struct wil6210_priv *wil = vif_to_wil(vif);
  1548. wil_dbg_misc(wil, "probe_client_flush\n");
  1549. mutex_lock(&vif->probe_client_mutex);
  1550. list_for_each_entry_safe(req, t, &vif->probe_client_pending, list) {
  1551. list_del(&req->list);
  1552. kfree(req);
  1553. }
  1554. mutex_unlock(&vif->probe_client_mutex);
  1555. }
  1556. static int wil_cfg80211_probe_client(struct wiphy *wiphy,
  1557. struct net_device *dev,
  1558. const u8 *peer, u64 *cookie)
  1559. {
  1560. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1561. struct wil6210_vif *vif = ndev_to_vif(dev);
  1562. struct wil_probe_client_req *req;
  1563. int cid = wil_find_cid(wil, vif->mid, peer);
  1564. wil_dbg_misc(wil, "probe_client: %pM => CID %d MID %d\n",
  1565. peer, cid, vif->mid);
  1566. if (cid < 0)
  1567. return -ENOLINK;
  1568. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1569. if (!req)
  1570. return -ENOMEM;
  1571. req->cid = cid;
  1572. req->cookie = cid;
  1573. mutex_lock(&vif->probe_client_mutex);
  1574. list_add_tail(&req->list, &vif->probe_client_pending);
  1575. mutex_unlock(&vif->probe_client_mutex);
  1576. *cookie = req->cookie;
  1577. queue_work(wil->wq_service, &vif->probe_client_worker);
  1578. return 0;
  1579. }
  1580. static int wil_cfg80211_change_bss(struct wiphy *wiphy,
  1581. struct net_device *dev,
  1582. struct bss_parameters *params)
  1583. {
  1584. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1585. struct wil6210_vif *vif = ndev_to_vif(dev);
  1586. if (params->ap_isolate >= 0) {
  1587. wil_dbg_misc(wil, "change_bss: ap_isolate MID %d, %d => %d\n",
  1588. vif->mid, vif->ap_isolate, params->ap_isolate);
  1589. vif->ap_isolate = params->ap_isolate;
  1590. }
  1591. return 0;
  1592. }
  1593. static int wil_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  1594. struct net_device *dev,
  1595. bool enabled, int timeout)
  1596. {
  1597. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1598. enum wmi_ps_profile_type ps_profile;
  1599. wil_dbg_misc(wil, "enabled=%d, timeout=%d\n",
  1600. enabled, timeout);
  1601. if (enabled)
  1602. ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
  1603. else
  1604. ps_profile = WMI_PS_PROFILE_TYPE_PS_DISABLED;
  1605. return wil_ps_update(wil, ps_profile);
  1606. }
  1607. static int wil_cfg80211_suspend(struct wiphy *wiphy,
  1608. struct cfg80211_wowlan *wow)
  1609. {
  1610. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1611. int rc;
  1612. /* Setting the wakeup trigger based on wow is TBD */
  1613. if (test_bit(wil_status_suspended, wil->status)) {
  1614. wil_dbg_pm(wil, "trying to suspend while suspended\n");
  1615. return 0;
  1616. }
  1617. rc = wil_can_suspend(wil, false);
  1618. if (rc)
  1619. goto out;
  1620. wil_dbg_pm(wil, "suspending\n");
  1621. mutex_lock(&wil->mutex);
  1622. mutex_lock(&wil->vif_mutex);
  1623. wil_p2p_stop_radio_operations(wil);
  1624. wil_abort_scan_all_vifs(wil, true);
  1625. mutex_unlock(&wil->vif_mutex);
  1626. mutex_unlock(&wil->mutex);
  1627. out:
  1628. return rc;
  1629. }
  1630. static int wil_cfg80211_resume(struct wiphy *wiphy)
  1631. {
  1632. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1633. wil_dbg_pm(wil, "resuming\n");
  1634. return 0;
  1635. }
  1636. static int
  1637. wil_cfg80211_sched_scan_start(struct wiphy *wiphy,
  1638. struct net_device *dev,
  1639. struct cfg80211_sched_scan_request *request)
  1640. {
  1641. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1642. struct wil6210_vif *vif = ndev_to_vif(dev);
  1643. int i, rc;
  1644. if (vif->mid != 0)
  1645. return -EOPNOTSUPP;
  1646. wil_dbg_misc(wil,
  1647. "sched scan start: n_ssids %d, ie_len %zu, flags 0x%x\n",
  1648. request->n_ssids, request->ie_len, request->flags);
  1649. for (i = 0; i < request->n_ssids; i++) {
  1650. wil_dbg_misc(wil, "SSID[%d]:", i);
  1651. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  1652. request->ssids[i].ssid,
  1653. request->ssids[i].ssid_len, true);
  1654. }
  1655. wil_dbg_misc(wil, "channels:");
  1656. for (i = 0; i < request->n_channels; i++)
  1657. wil_dbg_misc(wil, " %d%s", request->channels[i]->hw_value,
  1658. i == request->n_channels - 1 ? "\n" : "");
  1659. wil_dbg_misc(wil, "n_match_sets %d, min_rssi_thold %d, delay %d\n",
  1660. request->n_match_sets, request->min_rssi_thold,
  1661. request->delay);
  1662. for (i = 0; i < request->n_match_sets; i++) {
  1663. struct cfg80211_match_set *ms = &request->match_sets[i];
  1664. wil_dbg_misc(wil, "MATCHSET[%d]: rssi_thold %d\n",
  1665. i, ms->rssi_thold);
  1666. wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
  1667. ms->ssid.ssid,
  1668. ms->ssid.ssid_len, true);
  1669. }
  1670. wil_dbg_misc(wil, "n_scan_plans %d\n", request->n_scan_plans);
  1671. for (i = 0; i < request->n_scan_plans; i++) {
  1672. struct cfg80211_sched_scan_plan *sp = &request->scan_plans[i];
  1673. wil_dbg_misc(wil, "SCAN PLAN[%d]: interval %d iterations %d\n",
  1674. i, sp->interval, sp->iterations);
  1675. }
  1676. rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
  1677. request->ie_len, request->ie);
  1678. if (rc)
  1679. return rc;
  1680. return wmi_start_sched_scan(wil, request);
  1681. }
  1682. static int
  1683. wil_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
  1684. u64 reqid)
  1685. {
  1686. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  1687. struct wil6210_vif *vif = ndev_to_vif(dev);
  1688. int rc;
  1689. if (vif->mid != 0)
  1690. return -EOPNOTSUPP;
  1691. rc = wmi_stop_sched_scan(wil);
  1692. /* device would return error if it thinks PNO is already stopped.
  1693. * ignore the return code so user space and driver gets back in-sync
  1694. */
  1695. wil_dbg_misc(wil, "sched scan stopped (%d)\n", rc);
  1696. return 0;
  1697. }
  1698. static const struct cfg80211_ops wil_cfg80211_ops = {
  1699. .add_virtual_intf = wil_cfg80211_add_iface,
  1700. .del_virtual_intf = wil_cfg80211_del_iface,
  1701. .scan = wil_cfg80211_scan,
  1702. .abort_scan = wil_cfg80211_abort_scan,
  1703. .connect = wil_cfg80211_connect,
  1704. .disconnect = wil_cfg80211_disconnect,
  1705. .set_wiphy_params = wil_cfg80211_set_wiphy_params,
  1706. .change_virtual_intf = wil_cfg80211_change_iface,
  1707. .get_station = wil_cfg80211_get_station,
  1708. .dump_station = wil_cfg80211_dump_station,
  1709. .remain_on_channel = wil_remain_on_channel,
  1710. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  1711. .mgmt_tx = wil_cfg80211_mgmt_tx,
  1712. .set_monitor_channel = wil_cfg80211_set_channel,
  1713. .add_key = wil_cfg80211_add_key,
  1714. .del_key = wil_cfg80211_del_key,
  1715. .set_default_key = wil_cfg80211_set_default_key,
  1716. /* AP mode */
  1717. .change_beacon = wil_cfg80211_change_beacon,
  1718. .start_ap = wil_cfg80211_start_ap,
  1719. .stop_ap = wil_cfg80211_stop_ap,
  1720. .add_station = wil_cfg80211_add_station,
  1721. .del_station = wil_cfg80211_del_station,
  1722. .change_station = wil_cfg80211_change_station,
  1723. .probe_client = wil_cfg80211_probe_client,
  1724. .change_bss = wil_cfg80211_change_bss,
  1725. /* P2P device */
  1726. .start_p2p_device = wil_cfg80211_start_p2p_device,
  1727. .stop_p2p_device = wil_cfg80211_stop_p2p_device,
  1728. .set_power_mgmt = wil_cfg80211_set_power_mgmt,
  1729. .suspend = wil_cfg80211_suspend,
  1730. .resume = wil_cfg80211_resume,
  1731. .sched_scan_start = wil_cfg80211_sched_scan_start,
  1732. .sched_scan_stop = wil_cfg80211_sched_scan_stop,
  1733. };
  1734. static void wil_wiphy_init(struct wiphy *wiphy)
  1735. {
  1736. wiphy->max_scan_ssids = 1;
  1737. wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
  1738. wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
  1739. wiphy->max_num_pmkids = 0 /* TODO: */;
  1740. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1741. BIT(NL80211_IFTYPE_AP) |
  1742. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  1743. BIT(NL80211_IFTYPE_P2P_GO) |
  1744. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  1745. BIT(NL80211_IFTYPE_MONITOR);
  1746. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  1747. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
  1748. WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1749. if (!disable_ap_sme)
  1750. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
  1751. dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  1752. __func__, wiphy->flags);
  1753. wiphy->probe_resp_offload =
  1754. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  1755. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  1756. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  1757. wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
  1758. /* may change after reading FW capabilities */
  1759. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  1760. wiphy->cipher_suites = wil_cipher_suites;
  1761. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  1762. wiphy->mgmt_stypes = wil_mgmt_stypes;
  1763. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  1764. wiphy->n_vendor_commands = ARRAY_SIZE(wil_nl80211_vendor_commands);
  1765. wiphy->vendor_commands = wil_nl80211_vendor_commands;
  1766. #ifdef CONFIG_PM
  1767. wiphy->wowlan = &wil_wowlan_support;
  1768. #endif
  1769. }
  1770. int wil_cfg80211_iface_combinations_from_fw(
  1771. struct wil6210_priv *wil, const struct wil_fw_record_concurrency *conc)
  1772. {
  1773. struct wiphy *wiphy = wil_to_wiphy(wil);
  1774. u32 total_limits = 0;
  1775. u16 n_combos;
  1776. const struct wil_fw_concurrency_combo *combo;
  1777. const struct wil_fw_concurrency_limit *limit;
  1778. struct ieee80211_iface_combination *iface_combinations;
  1779. struct ieee80211_iface_limit *iface_limit;
  1780. int i, j;
  1781. if (wiphy->iface_combinations) {
  1782. wil_dbg_misc(wil, "iface_combinations already set, skipping\n");
  1783. return 0;
  1784. }
  1785. combo = conc->combos;
  1786. n_combos = le16_to_cpu(conc->n_combos);
  1787. for (i = 0; i < n_combos; i++) {
  1788. total_limits += combo->n_limits;
  1789. limit = combo->limits + combo->n_limits;
  1790. combo = (struct wil_fw_concurrency_combo *)limit;
  1791. }
  1792. iface_combinations =
  1793. kzalloc(n_combos * sizeof(struct ieee80211_iface_combination) +
  1794. total_limits * sizeof(struct ieee80211_iface_limit),
  1795. GFP_KERNEL);
  1796. if (!iface_combinations)
  1797. return -ENOMEM;
  1798. iface_limit = (struct ieee80211_iface_limit *)(iface_combinations +
  1799. n_combos);
  1800. combo = conc->combos;
  1801. for (i = 0; i < n_combos; i++) {
  1802. iface_combinations[i].max_interfaces = combo->max_interfaces;
  1803. iface_combinations[i].num_different_channels =
  1804. combo->n_diff_channels;
  1805. iface_combinations[i].beacon_int_infra_match =
  1806. combo->same_bi;
  1807. iface_combinations[i].n_limits = combo->n_limits;
  1808. wil_dbg_misc(wil,
  1809. "iface_combination %d: max_if %d, num_ch %d, bi_match %d\n",
  1810. i, iface_combinations[i].max_interfaces,
  1811. iface_combinations[i].num_different_channels,
  1812. iface_combinations[i].beacon_int_infra_match);
  1813. limit = combo->limits;
  1814. for (j = 0; j < combo->n_limits; j++) {
  1815. iface_limit[j].max = le16_to_cpu(limit[j].max);
  1816. iface_limit[j].types = le16_to_cpu(limit[j].types);
  1817. wil_dbg_misc(wil,
  1818. "limit %d: max %d types 0x%x\n", j,
  1819. iface_limit[j].max, iface_limit[j].types);
  1820. }
  1821. iface_combinations[i].limits = iface_limit;
  1822. iface_limit += combo->n_limits;
  1823. limit += combo->n_limits;
  1824. combo = (struct wil_fw_concurrency_combo *)limit;
  1825. }
  1826. wil_dbg_misc(wil, "multiple VIFs supported, n_mids %d\n", conc->n_mids);
  1827. wil->max_vifs = conc->n_mids + 1; /* including main interface */
  1828. if (wil->max_vifs > WIL_MAX_VIFS) {
  1829. wil_info(wil, "limited number of VIFs supported(%d, FW %d)\n",
  1830. WIL_MAX_VIFS, wil->max_vifs);
  1831. wil->max_vifs = WIL_MAX_VIFS;
  1832. }
  1833. wiphy->n_iface_combinations = n_combos;
  1834. wiphy->iface_combinations = iface_combinations;
  1835. return 0;
  1836. }
  1837. struct wil6210_priv *wil_cfg80211_init(struct device *dev)
  1838. {
  1839. struct wiphy *wiphy;
  1840. struct wil6210_priv *wil;
  1841. struct ieee80211_channel *ch;
  1842. dev_dbg(dev, "%s()\n", __func__);
  1843. /* Note: the wireless_dev structure is no longer allocated here.
  1844. * Instead, it is allocated as part of the net_device structure
  1845. * for main interface and each VIF.
  1846. */
  1847. wiphy = wiphy_new(&wil_cfg80211_ops, sizeof(struct wil6210_priv));
  1848. if (!wiphy)
  1849. return ERR_PTR(-ENOMEM);
  1850. set_wiphy_dev(wiphy, dev);
  1851. wil_wiphy_init(wiphy);
  1852. wil = wiphy_to_wil(wiphy);
  1853. wil->wiphy = wiphy;
  1854. /* default monitor channel */
  1855. ch = wiphy->bands[NL80211_BAND_60GHZ]->channels;
  1856. cfg80211_chandef_create(&wil->monitor_chandef, ch, NL80211_CHAN_NO_HT);
  1857. return wil;
  1858. }
  1859. void wil_cfg80211_deinit(struct wil6210_priv *wil)
  1860. {
  1861. struct wiphy *wiphy = wil_to_wiphy(wil);
  1862. dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
  1863. if (!wiphy)
  1864. return;
  1865. kfree(wiphy->iface_combinations);
  1866. wiphy->iface_combinations = NULL;
  1867. wiphy_free(wiphy);
  1868. /* do not access wil6210_priv after returning from here */
  1869. }
  1870. void wil_p2p_wdev_free(struct wil6210_priv *wil)
  1871. {
  1872. struct wireless_dev *p2p_wdev;
  1873. mutex_lock(&wil->vif_mutex);
  1874. p2p_wdev = wil->p2p_wdev;
  1875. wil->p2p_wdev = NULL;
  1876. wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
  1877. mutex_unlock(&wil->vif_mutex);
  1878. if (p2p_wdev) {
  1879. cfg80211_unregister_wdev(p2p_wdev);
  1880. kfree(p2p_wdev);
  1881. }
  1882. }
  1883. static int wil_rf_sector_status_to_rc(u8 status)
  1884. {
  1885. switch (status) {
  1886. case WMI_RF_SECTOR_STATUS_SUCCESS:
  1887. return 0;
  1888. case WMI_RF_SECTOR_STATUS_BAD_PARAMETERS_ERROR:
  1889. return -EINVAL;
  1890. case WMI_RF_SECTOR_STATUS_BUSY_ERROR:
  1891. return -EAGAIN;
  1892. case WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR:
  1893. return -EOPNOTSUPP;
  1894. default:
  1895. return -EINVAL;
  1896. }
  1897. }
  1898. static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
  1899. struct wireless_dev *wdev,
  1900. const void *data, int data_len)
  1901. {
  1902. struct wil6210_priv *wil = wdev_to_wil(wdev);
  1903. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  1904. int rc;
  1905. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  1906. u16 sector_index;
  1907. u8 sector_type;
  1908. u32 rf_modules_vec;
  1909. struct wmi_get_rf_sector_params_cmd cmd;
  1910. struct {
  1911. struct wmi_cmd_hdr wmi;
  1912. struct wmi_get_rf_sector_params_done_event evt;
  1913. } __packed reply = {
  1914. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  1915. };
  1916. struct sk_buff *msg;
  1917. struct nlattr *nl_cfgs, *nl_cfg;
  1918. u32 i;
  1919. struct wmi_rf_sector_info *si;
  1920. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  1921. return -EOPNOTSUPP;
  1922. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  1923. wil_rf_sector_policy, NULL);
  1924. if (rc) {
  1925. wil_err(wil, "Invalid rf sector ATTR\n");
  1926. return rc;
  1927. }
  1928. if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
  1929. !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
  1930. !tb[QCA_ATTR_DMG_RF_MODULE_MASK]) {
  1931. wil_err(wil, "Invalid rf sector spec\n");
  1932. return -EINVAL;
  1933. }
  1934. sector_index = nla_get_u16(
  1935. tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
  1936. if (sector_index >= WIL_MAX_RF_SECTORS) {
  1937. wil_err(wil, "Invalid sector index %d\n", sector_index);
  1938. return -EINVAL;
  1939. }
  1940. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  1941. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  1942. wil_err(wil, "Invalid sector type %d\n", sector_type);
  1943. return -EINVAL;
  1944. }
  1945. rf_modules_vec = nla_get_u32(
  1946. tb[QCA_ATTR_DMG_RF_MODULE_MASK]);
  1947. if (rf_modules_vec >= BIT(WMI_MAX_RF_MODULES_NUM)) {
  1948. wil_err(wil, "Invalid rf module mask 0x%x\n", rf_modules_vec);
  1949. return -EINVAL;
  1950. }
  1951. cmd.sector_idx = cpu_to_le16(sector_index);
  1952. cmd.sector_type = sector_type;
  1953. cmd.rf_modules_vec = rf_modules_vec & 0xFF;
  1954. rc = wmi_call(wil, WMI_GET_RF_SECTOR_PARAMS_CMDID, vif->mid,
  1955. &cmd, sizeof(cmd), WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID,
  1956. &reply, sizeof(reply),
  1957. 500);
  1958. if (rc)
  1959. return rc;
  1960. if (reply.evt.status) {
  1961. wil_err(wil, "get rf sector cfg failed with status %d\n",
  1962. reply.evt.status);
  1963. return wil_rf_sector_status_to_rc(reply.evt.status);
  1964. }
  1965. msg = cfg80211_vendor_cmd_alloc_reply_skb(
  1966. wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
  1967. if (!msg)
  1968. return -ENOMEM;
  1969. if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
  1970. le64_to_cpu(reply.evt.tsf),
  1971. QCA_ATTR_PAD))
  1972. goto nla_put_failure;
  1973. nl_cfgs = nla_nest_start(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
  1974. if (!nl_cfgs)
  1975. goto nla_put_failure;
  1976. for (i = 0; i < WMI_MAX_RF_MODULES_NUM; i++) {
  1977. if (!(rf_modules_vec & BIT(i)))
  1978. continue;
  1979. nl_cfg = nla_nest_start(msg, i);
  1980. if (!nl_cfg)
  1981. goto nla_put_failure;
  1982. si = &reply.evt.sectors_info[i];
  1983. if (nla_put_u8(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
  1984. i) ||
  1985. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
  1986. le32_to_cpu(si->etype0)) ||
  1987. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
  1988. le32_to_cpu(si->etype1)) ||
  1989. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
  1990. le32_to_cpu(si->etype2)) ||
  1991. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
  1992. le32_to_cpu(si->psh_hi)) ||
  1993. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
  1994. le32_to_cpu(si->psh_lo)) ||
  1995. nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
  1996. le32_to_cpu(si->dtype_swch_off)))
  1997. goto nla_put_failure;
  1998. nla_nest_end(msg, nl_cfg);
  1999. }
  2000. nla_nest_end(msg, nl_cfgs);
  2001. rc = cfg80211_vendor_cmd_reply(msg);
  2002. return rc;
  2003. nla_put_failure:
  2004. kfree_skb(msg);
  2005. return -ENOBUFS;
  2006. }
  2007. static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
  2008. struct wireless_dev *wdev,
  2009. const void *data, int data_len)
  2010. {
  2011. struct wil6210_priv *wil = wdev_to_wil(wdev);
  2012. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  2013. int rc, tmp;
  2014. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  2015. struct nlattr *tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1];
  2016. u16 sector_index, rf_module_index;
  2017. u8 sector_type;
  2018. u32 rf_modules_vec = 0;
  2019. struct wmi_set_rf_sector_params_cmd cmd;
  2020. struct {
  2021. struct wmi_cmd_hdr wmi;
  2022. struct wmi_set_rf_sector_params_done_event evt;
  2023. } __packed reply = {
  2024. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  2025. };
  2026. struct nlattr *nl_cfg;
  2027. struct wmi_rf_sector_info *si;
  2028. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  2029. return -EOPNOTSUPP;
  2030. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  2031. wil_rf_sector_policy, NULL);
  2032. if (rc) {
  2033. wil_err(wil, "Invalid rf sector ATTR\n");
  2034. return rc;
  2035. }
  2036. if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
  2037. !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
  2038. !tb[QCA_ATTR_DMG_RF_SECTOR_CFG]) {
  2039. wil_err(wil, "Invalid rf sector spec\n");
  2040. return -EINVAL;
  2041. }
  2042. sector_index = nla_get_u16(
  2043. tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
  2044. if (sector_index >= WIL_MAX_RF_SECTORS) {
  2045. wil_err(wil, "Invalid sector index %d\n", sector_index);
  2046. return -EINVAL;
  2047. }
  2048. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  2049. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  2050. wil_err(wil, "Invalid sector type %d\n", sector_type);
  2051. return -EINVAL;
  2052. }
  2053. memset(&cmd, 0, sizeof(cmd));
  2054. cmd.sector_idx = cpu_to_le16(sector_index);
  2055. cmd.sector_type = sector_type;
  2056. nla_for_each_nested(nl_cfg, tb[QCA_ATTR_DMG_RF_SECTOR_CFG],
  2057. tmp) {
  2058. rc = nla_parse_nested(tb2, QCA_ATTR_DMG_RF_SECTOR_CFG_MAX,
  2059. nl_cfg, wil_rf_sector_cfg_policy,
  2060. NULL);
  2061. if (rc) {
  2062. wil_err(wil, "invalid sector cfg\n");
  2063. return -EINVAL;
  2064. }
  2065. if (!tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] ||
  2066. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] ||
  2067. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] ||
  2068. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] ||
  2069. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] ||
  2070. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] ||
  2071. !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]) {
  2072. wil_err(wil, "missing cfg params\n");
  2073. return -EINVAL;
  2074. }
  2075. rf_module_index = nla_get_u8(
  2076. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX]);
  2077. if (rf_module_index >= WMI_MAX_RF_MODULES_NUM) {
  2078. wil_err(wil, "invalid RF module index %d\n",
  2079. rf_module_index);
  2080. return -EINVAL;
  2081. }
  2082. rf_modules_vec |= BIT(rf_module_index);
  2083. si = &cmd.sectors_info[rf_module_index];
  2084. si->etype0 = cpu_to_le32(nla_get_u32(
  2085. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0]));
  2086. si->etype1 = cpu_to_le32(nla_get_u32(
  2087. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1]));
  2088. si->etype2 = cpu_to_le32(nla_get_u32(
  2089. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2]));
  2090. si->psh_hi = cpu_to_le32(nla_get_u32(
  2091. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI]));
  2092. si->psh_lo = cpu_to_le32(nla_get_u32(
  2093. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO]));
  2094. si->dtype_swch_off = cpu_to_le32(nla_get_u32(
  2095. tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]));
  2096. }
  2097. cmd.rf_modules_vec = rf_modules_vec & 0xFF;
  2098. rc = wmi_call(wil, WMI_SET_RF_SECTOR_PARAMS_CMDID, vif->mid,
  2099. &cmd, sizeof(cmd), WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID,
  2100. &reply, sizeof(reply),
  2101. 500);
  2102. if (rc)
  2103. return rc;
  2104. return wil_rf_sector_status_to_rc(reply.evt.status);
  2105. }
  2106. static int wil_rf_sector_get_selected(struct wiphy *wiphy,
  2107. struct wireless_dev *wdev,
  2108. const void *data, int data_len)
  2109. {
  2110. struct wil6210_priv *wil = wdev_to_wil(wdev);
  2111. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  2112. int rc;
  2113. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  2114. u8 sector_type, mac_addr[ETH_ALEN];
  2115. int cid = 0;
  2116. struct wmi_get_selected_rf_sector_index_cmd cmd;
  2117. struct {
  2118. struct wmi_cmd_hdr wmi;
  2119. struct wmi_get_selected_rf_sector_index_done_event evt;
  2120. } __packed reply = {
  2121. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  2122. };
  2123. struct sk_buff *msg;
  2124. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  2125. return -EOPNOTSUPP;
  2126. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  2127. wil_rf_sector_policy, NULL);
  2128. if (rc) {
  2129. wil_err(wil, "Invalid rf sector ATTR\n");
  2130. return rc;
  2131. }
  2132. if (!tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
  2133. wil_err(wil, "Invalid rf sector spec\n");
  2134. return -EINVAL;
  2135. }
  2136. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  2137. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  2138. wil_err(wil, "Invalid sector type %d\n", sector_type);
  2139. return -EINVAL;
  2140. }
  2141. if (tb[QCA_ATTR_MAC_ADDR]) {
  2142. ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
  2143. cid = wil_find_cid(wil, vif->mid, mac_addr);
  2144. if (cid < 0) {
  2145. wil_err(wil, "invalid MAC address %pM\n", mac_addr);
  2146. return -ENOENT;
  2147. }
  2148. } else {
  2149. if (test_bit(wil_vif_fwconnected, vif->status)) {
  2150. wil_err(wil, "must specify MAC address when connected\n");
  2151. return -EINVAL;
  2152. }
  2153. }
  2154. memset(&cmd, 0, sizeof(cmd));
  2155. cmd.cid = (u8)cid;
  2156. cmd.sector_type = sector_type;
  2157. rc = wmi_call(wil, WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID, vif->mid,
  2158. &cmd, sizeof(cmd),
  2159. WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
  2160. &reply, sizeof(reply),
  2161. 500);
  2162. if (rc)
  2163. return rc;
  2164. if (reply.evt.status) {
  2165. wil_err(wil, "get rf selected sector cfg failed with status %d\n",
  2166. reply.evt.status);
  2167. return wil_rf_sector_status_to_rc(reply.evt.status);
  2168. }
  2169. msg = cfg80211_vendor_cmd_alloc_reply_skb(
  2170. wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
  2171. if (!msg)
  2172. return -ENOMEM;
  2173. if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
  2174. le64_to_cpu(reply.evt.tsf),
  2175. QCA_ATTR_PAD) ||
  2176. nla_put_u16(msg, QCA_ATTR_DMG_RF_SECTOR_INDEX,
  2177. le16_to_cpu(reply.evt.sector_idx)))
  2178. goto nla_put_failure;
  2179. rc = cfg80211_vendor_cmd_reply(msg);
  2180. return rc;
  2181. nla_put_failure:
  2182. kfree_skb(msg);
  2183. return -ENOBUFS;
  2184. }
  2185. static int wil_rf_sector_wmi_set_selected(struct wil6210_priv *wil,
  2186. u8 mid, u16 sector_index,
  2187. u8 sector_type, u8 cid)
  2188. {
  2189. struct wmi_set_selected_rf_sector_index_cmd cmd;
  2190. struct {
  2191. struct wmi_cmd_hdr wmi;
  2192. struct wmi_set_selected_rf_sector_index_done_event evt;
  2193. } __packed reply = {
  2194. .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
  2195. };
  2196. int rc;
  2197. memset(&cmd, 0, sizeof(cmd));
  2198. cmd.sector_idx = cpu_to_le16(sector_index);
  2199. cmd.sector_type = sector_type;
  2200. cmd.cid = (u8)cid;
  2201. rc = wmi_call(wil, WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID, mid,
  2202. &cmd, sizeof(cmd),
  2203. WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
  2204. &reply, sizeof(reply),
  2205. 500);
  2206. if (rc)
  2207. return rc;
  2208. return wil_rf_sector_status_to_rc(reply.evt.status);
  2209. }
  2210. static int wil_rf_sector_set_selected(struct wiphy *wiphy,
  2211. struct wireless_dev *wdev,
  2212. const void *data, int data_len)
  2213. {
  2214. struct wil6210_priv *wil = wdev_to_wil(wdev);
  2215. struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
  2216. int rc;
  2217. struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
  2218. u16 sector_index;
  2219. u8 sector_type, mac_addr[ETH_ALEN], i;
  2220. int cid = 0;
  2221. if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
  2222. return -EOPNOTSUPP;
  2223. rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
  2224. wil_rf_sector_policy, NULL);
  2225. if (rc) {
  2226. wil_err(wil, "Invalid rf sector ATTR\n");
  2227. return rc;
  2228. }
  2229. if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
  2230. !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
  2231. wil_err(wil, "Invalid rf sector spec\n");
  2232. return -EINVAL;
  2233. }
  2234. sector_index = nla_get_u16(
  2235. tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
  2236. if (sector_index >= WIL_MAX_RF_SECTORS &&
  2237. sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
  2238. wil_err(wil, "Invalid sector index %d\n", sector_index);
  2239. return -EINVAL;
  2240. }
  2241. sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
  2242. if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
  2243. wil_err(wil, "Invalid sector type %d\n", sector_type);
  2244. return -EINVAL;
  2245. }
  2246. if (tb[QCA_ATTR_MAC_ADDR]) {
  2247. ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
  2248. if (!is_broadcast_ether_addr(mac_addr)) {
  2249. cid = wil_find_cid(wil, vif->mid, mac_addr);
  2250. if (cid < 0) {
  2251. wil_err(wil, "invalid MAC address %pM\n",
  2252. mac_addr);
  2253. return -ENOENT;
  2254. }
  2255. } else {
  2256. if (sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
  2257. wil_err(wil, "broadcast MAC valid only with unlocking\n");
  2258. return -EINVAL;
  2259. }
  2260. cid = -1;
  2261. }
  2262. } else {
  2263. if (test_bit(wil_vif_fwconnected, vif->status)) {
  2264. wil_err(wil, "must specify MAC address when connected\n");
  2265. return -EINVAL;
  2266. }
  2267. /* otherwise, using cid=0 for unassociated station */
  2268. }
  2269. if (cid >= 0) {
  2270. rc = wil_rf_sector_wmi_set_selected(wil, vif->mid, sector_index,
  2271. sector_type, cid);
  2272. } else {
  2273. /* unlock all cids */
  2274. rc = wil_rf_sector_wmi_set_selected(
  2275. wil, vif->mid, WMI_INVALID_RF_SECTOR_INDEX,
  2276. sector_type, WIL_CID_ALL);
  2277. if (rc == -EINVAL) {
  2278. for (i = 0; i < WIL6210_MAX_CID; i++) {
  2279. if (wil->sta[i].mid != vif->mid)
  2280. continue;
  2281. rc = wil_rf_sector_wmi_set_selected(
  2282. wil, vif->mid,
  2283. WMI_INVALID_RF_SECTOR_INDEX,
  2284. sector_type, i);
  2285. /* the FW will silently ignore and return
  2286. * success for unused cid, so abort the loop
  2287. * on any other error
  2288. */
  2289. if (rc) {
  2290. wil_err(wil, "unlock cid %d failed with status %d\n",
  2291. i, rc);
  2292. break;
  2293. }
  2294. }
  2295. }
  2296. }
  2297. return rc;
  2298. }