cfg80211.c 87 KB

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