cfg80211.c 73 KB

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