cfg.c 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2015 Intel Mobile Communications GmbH
  6. * Copyright (C) 2015-2017 Intel Deutschland GmbH
  7. * Copyright (C) 2018 Intel Corporation
  8. *
  9. * This file is GPLv2 as found in COPYING.
  10. */
  11. #include <linux/ieee80211.h>
  12. #include <linux/nl80211.h>
  13. #include <linux/rtnetlink.h>
  14. #include <linux/slab.h>
  15. #include <net/net_namespace.h>
  16. #include <linux/rcupdate.h>
  17. #include <linux/if_ether.h>
  18. #include <net/cfg80211.h>
  19. #include "ieee80211_i.h"
  20. #include "driver-ops.h"
  21. #include "rate.h"
  22. #include "mesh.h"
  23. #include "wme.h"
  24. static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
  25. struct vif_params *params)
  26. {
  27. bool mu_mimo_groups = false;
  28. bool mu_mimo_follow = false;
  29. if (params->vht_mumimo_groups) {
  30. u64 membership;
  31. BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
  32. memcpy(sdata->vif.bss_conf.mu_group.membership,
  33. params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
  34. memcpy(sdata->vif.bss_conf.mu_group.position,
  35. params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
  36. WLAN_USER_POSITION_LEN);
  37. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
  38. /* don't care about endianness - just check for 0 */
  39. memcpy(&membership, params->vht_mumimo_groups,
  40. WLAN_MEMBERSHIP_LEN);
  41. mu_mimo_groups = membership != 0;
  42. }
  43. if (params->vht_mumimo_follow_addr) {
  44. mu_mimo_follow =
  45. is_valid_ether_addr(params->vht_mumimo_follow_addr);
  46. ether_addr_copy(sdata->u.mntr.mu_follow_addr,
  47. params->vht_mumimo_follow_addr);
  48. }
  49. sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
  50. }
  51. static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
  52. struct vif_params *params)
  53. {
  54. struct ieee80211_local *local = sdata->local;
  55. struct ieee80211_sub_if_data *monitor_sdata;
  56. /* check flags first */
  57. if (params->flags && ieee80211_sdata_running(sdata)) {
  58. u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
  59. /*
  60. * Prohibit MONITOR_FLAG_COOK_FRAMES and
  61. * MONITOR_FLAG_ACTIVE to be changed while the
  62. * interface is up.
  63. * Else we would need to add a lot of cruft
  64. * to update everything:
  65. * cooked_mntrs, monitor and all fif_* counters
  66. * reconfigure hardware
  67. */
  68. if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
  69. return -EBUSY;
  70. }
  71. /* also validate MU-MIMO change */
  72. monitor_sdata = rtnl_dereference(local->monitor_sdata);
  73. if (!monitor_sdata &&
  74. (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
  75. return -EOPNOTSUPP;
  76. /* apply all changes now - no failures allowed */
  77. if (monitor_sdata)
  78. ieee80211_set_mu_mimo_follow(monitor_sdata, params);
  79. if (params->flags) {
  80. if (ieee80211_sdata_running(sdata)) {
  81. ieee80211_adjust_monitor_flags(sdata, -1);
  82. sdata->u.mntr.flags = params->flags;
  83. ieee80211_adjust_monitor_flags(sdata, 1);
  84. ieee80211_configure_filter(local);
  85. } else {
  86. /*
  87. * Because the interface is down, ieee80211_do_stop
  88. * and ieee80211_do_open take care of "everything"
  89. * mentioned in the comment above.
  90. */
  91. sdata->u.mntr.flags = params->flags;
  92. }
  93. }
  94. return 0;
  95. }
  96. static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
  97. const char *name,
  98. unsigned char name_assign_type,
  99. enum nl80211_iftype type,
  100. struct vif_params *params)
  101. {
  102. struct ieee80211_local *local = wiphy_priv(wiphy);
  103. struct wireless_dev *wdev;
  104. struct ieee80211_sub_if_data *sdata;
  105. int err;
  106. err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
  107. if (err)
  108. return ERR_PTR(err);
  109. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  110. if (type == NL80211_IFTYPE_MONITOR) {
  111. err = ieee80211_set_mon_options(sdata, params);
  112. if (err) {
  113. ieee80211_if_remove(sdata);
  114. return NULL;
  115. }
  116. }
  117. return wdev;
  118. }
  119. static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
  120. {
  121. ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
  122. return 0;
  123. }
  124. static int ieee80211_change_iface(struct wiphy *wiphy,
  125. struct net_device *dev,
  126. enum nl80211_iftype type,
  127. struct vif_params *params)
  128. {
  129. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  130. int ret;
  131. ret = ieee80211_if_change_type(sdata, type);
  132. if (ret)
  133. return ret;
  134. if (type == NL80211_IFTYPE_AP_VLAN &&
  135. params && params->use_4addr == 0) {
  136. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  137. ieee80211_check_fast_rx_iface(sdata);
  138. } else if (type == NL80211_IFTYPE_STATION &&
  139. params && params->use_4addr >= 0) {
  140. sdata->u.mgd.use_4addr = params->use_4addr;
  141. }
  142. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  143. ret = ieee80211_set_mon_options(sdata, params);
  144. if (ret)
  145. return ret;
  146. }
  147. return 0;
  148. }
  149. static int ieee80211_start_p2p_device(struct wiphy *wiphy,
  150. struct wireless_dev *wdev)
  151. {
  152. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  153. int ret;
  154. mutex_lock(&sdata->local->chanctx_mtx);
  155. ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
  156. mutex_unlock(&sdata->local->chanctx_mtx);
  157. if (ret < 0)
  158. return ret;
  159. return ieee80211_do_open(wdev, true);
  160. }
  161. static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
  162. struct wireless_dev *wdev)
  163. {
  164. ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
  165. }
  166. static int ieee80211_start_nan(struct wiphy *wiphy,
  167. struct wireless_dev *wdev,
  168. struct cfg80211_nan_conf *conf)
  169. {
  170. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  171. int ret;
  172. mutex_lock(&sdata->local->chanctx_mtx);
  173. ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
  174. mutex_unlock(&sdata->local->chanctx_mtx);
  175. if (ret < 0)
  176. return ret;
  177. ret = ieee80211_do_open(wdev, true);
  178. if (ret)
  179. return ret;
  180. ret = drv_start_nan(sdata->local, sdata, conf);
  181. if (ret)
  182. ieee80211_sdata_stop(sdata);
  183. sdata->u.nan.conf = *conf;
  184. return ret;
  185. }
  186. static void ieee80211_stop_nan(struct wiphy *wiphy,
  187. struct wireless_dev *wdev)
  188. {
  189. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  190. drv_stop_nan(sdata->local, sdata);
  191. ieee80211_sdata_stop(sdata);
  192. }
  193. static int ieee80211_nan_change_conf(struct wiphy *wiphy,
  194. struct wireless_dev *wdev,
  195. struct cfg80211_nan_conf *conf,
  196. u32 changes)
  197. {
  198. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  199. struct cfg80211_nan_conf new_conf;
  200. int ret = 0;
  201. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  202. return -EOPNOTSUPP;
  203. if (!ieee80211_sdata_running(sdata))
  204. return -ENETDOWN;
  205. new_conf = sdata->u.nan.conf;
  206. if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
  207. new_conf.master_pref = conf->master_pref;
  208. if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
  209. new_conf.bands = conf->bands;
  210. ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
  211. if (!ret)
  212. sdata->u.nan.conf = new_conf;
  213. return ret;
  214. }
  215. static int ieee80211_add_nan_func(struct wiphy *wiphy,
  216. struct wireless_dev *wdev,
  217. struct cfg80211_nan_func *nan_func)
  218. {
  219. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  220. int ret;
  221. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  222. return -EOPNOTSUPP;
  223. if (!ieee80211_sdata_running(sdata))
  224. return -ENETDOWN;
  225. spin_lock_bh(&sdata->u.nan.func_lock);
  226. ret = idr_alloc(&sdata->u.nan.function_inst_ids,
  227. nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
  228. GFP_ATOMIC);
  229. spin_unlock_bh(&sdata->u.nan.func_lock);
  230. if (ret < 0)
  231. return ret;
  232. nan_func->instance_id = ret;
  233. WARN_ON(nan_func->instance_id == 0);
  234. ret = drv_add_nan_func(sdata->local, sdata, nan_func);
  235. if (ret) {
  236. spin_lock_bh(&sdata->u.nan.func_lock);
  237. idr_remove(&sdata->u.nan.function_inst_ids,
  238. nan_func->instance_id);
  239. spin_unlock_bh(&sdata->u.nan.func_lock);
  240. }
  241. return ret;
  242. }
  243. static struct cfg80211_nan_func *
  244. ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
  245. u64 cookie)
  246. {
  247. struct cfg80211_nan_func *func;
  248. int id;
  249. lockdep_assert_held(&sdata->u.nan.func_lock);
  250. idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
  251. if (func->cookie == cookie)
  252. return func;
  253. }
  254. return NULL;
  255. }
  256. static void ieee80211_del_nan_func(struct wiphy *wiphy,
  257. struct wireless_dev *wdev, u64 cookie)
  258. {
  259. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  260. struct cfg80211_nan_func *func;
  261. u8 instance_id = 0;
  262. if (sdata->vif.type != NL80211_IFTYPE_NAN ||
  263. !ieee80211_sdata_running(sdata))
  264. return;
  265. spin_lock_bh(&sdata->u.nan.func_lock);
  266. func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
  267. if (func)
  268. instance_id = func->instance_id;
  269. spin_unlock_bh(&sdata->u.nan.func_lock);
  270. if (instance_id)
  271. drv_del_nan_func(sdata->local, sdata, instance_id);
  272. }
  273. static int ieee80211_set_noack_map(struct wiphy *wiphy,
  274. struct net_device *dev,
  275. u16 noack_map)
  276. {
  277. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  278. sdata->noack_map = noack_map;
  279. ieee80211_check_fast_xmit_iface(sdata);
  280. return 0;
  281. }
  282. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  283. u8 key_idx, bool pairwise, const u8 *mac_addr,
  284. struct key_params *params)
  285. {
  286. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  287. struct ieee80211_local *local = sdata->local;
  288. struct sta_info *sta = NULL;
  289. const struct ieee80211_cipher_scheme *cs = NULL;
  290. struct ieee80211_key *key;
  291. int err;
  292. if (!ieee80211_sdata_running(sdata))
  293. return -ENETDOWN;
  294. /* reject WEP and TKIP keys if WEP failed to initialize */
  295. switch (params->cipher) {
  296. case WLAN_CIPHER_SUITE_WEP40:
  297. case WLAN_CIPHER_SUITE_TKIP:
  298. case WLAN_CIPHER_SUITE_WEP104:
  299. if (IS_ERR(local->wep_tx_tfm))
  300. return -EINVAL;
  301. break;
  302. case WLAN_CIPHER_SUITE_CCMP:
  303. case WLAN_CIPHER_SUITE_CCMP_256:
  304. case WLAN_CIPHER_SUITE_AES_CMAC:
  305. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  306. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  307. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  308. case WLAN_CIPHER_SUITE_GCMP:
  309. case WLAN_CIPHER_SUITE_GCMP_256:
  310. break;
  311. default:
  312. cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
  313. break;
  314. }
  315. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  316. params->key, params->seq_len, params->seq,
  317. cs);
  318. if (IS_ERR(key))
  319. return PTR_ERR(key);
  320. if (pairwise)
  321. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  322. mutex_lock(&local->sta_mtx);
  323. if (mac_addr) {
  324. sta = sta_info_get_bss(sdata, mac_addr);
  325. /*
  326. * The ASSOC test makes sure the driver is ready to
  327. * receive the key. When wpa_supplicant has roamed
  328. * using FT, it attempts to set the key before
  329. * association has completed, this rejects that attempt
  330. * so it will set the key again after association.
  331. *
  332. * TODO: accept the key if we have a station entry and
  333. * add it to the device after the station.
  334. */
  335. if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  336. ieee80211_key_free_unused(key);
  337. err = -ENOENT;
  338. goto out_unlock;
  339. }
  340. }
  341. switch (sdata->vif.type) {
  342. case NL80211_IFTYPE_STATION:
  343. if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
  344. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  345. break;
  346. case NL80211_IFTYPE_AP:
  347. case NL80211_IFTYPE_AP_VLAN:
  348. /* Keys without a station are used for TX only */
  349. if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
  350. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  351. break;
  352. case NL80211_IFTYPE_ADHOC:
  353. /* no MFP (yet) */
  354. break;
  355. case NL80211_IFTYPE_MESH_POINT:
  356. #ifdef CONFIG_MAC80211_MESH
  357. if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
  358. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  359. break;
  360. #endif
  361. case NL80211_IFTYPE_WDS:
  362. case NL80211_IFTYPE_MONITOR:
  363. case NL80211_IFTYPE_P2P_DEVICE:
  364. case NL80211_IFTYPE_NAN:
  365. case NL80211_IFTYPE_UNSPECIFIED:
  366. case NUM_NL80211_IFTYPES:
  367. case NL80211_IFTYPE_P2P_CLIENT:
  368. case NL80211_IFTYPE_P2P_GO:
  369. case NL80211_IFTYPE_OCB:
  370. /* shouldn't happen */
  371. WARN_ON_ONCE(1);
  372. break;
  373. }
  374. if (sta)
  375. sta->cipher_scheme = cs;
  376. err = ieee80211_key_link(key, sdata, sta);
  377. out_unlock:
  378. mutex_unlock(&local->sta_mtx);
  379. return err;
  380. }
  381. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  382. u8 key_idx, bool pairwise, const u8 *mac_addr)
  383. {
  384. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  385. struct ieee80211_local *local = sdata->local;
  386. struct sta_info *sta;
  387. struct ieee80211_key *key = NULL;
  388. int ret;
  389. mutex_lock(&local->sta_mtx);
  390. mutex_lock(&local->key_mtx);
  391. if (mac_addr) {
  392. ret = -ENOENT;
  393. sta = sta_info_get_bss(sdata, mac_addr);
  394. if (!sta)
  395. goto out_unlock;
  396. if (pairwise)
  397. key = key_mtx_dereference(local, sta->ptk[key_idx]);
  398. else
  399. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  400. } else
  401. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  402. if (!key) {
  403. ret = -ENOENT;
  404. goto out_unlock;
  405. }
  406. ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
  407. ret = 0;
  408. out_unlock:
  409. mutex_unlock(&local->key_mtx);
  410. mutex_unlock(&local->sta_mtx);
  411. return ret;
  412. }
  413. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  414. u8 key_idx, bool pairwise, const u8 *mac_addr,
  415. void *cookie,
  416. void (*callback)(void *cookie,
  417. struct key_params *params))
  418. {
  419. struct ieee80211_sub_if_data *sdata;
  420. struct sta_info *sta = NULL;
  421. u8 seq[6] = {0};
  422. struct key_params params;
  423. struct ieee80211_key *key = NULL;
  424. u64 pn64;
  425. u32 iv32;
  426. u16 iv16;
  427. int err = -ENOENT;
  428. struct ieee80211_key_seq kseq = {};
  429. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  430. rcu_read_lock();
  431. if (mac_addr) {
  432. sta = sta_info_get_bss(sdata, mac_addr);
  433. if (!sta)
  434. goto out;
  435. if (pairwise && key_idx < NUM_DEFAULT_KEYS)
  436. key = rcu_dereference(sta->ptk[key_idx]);
  437. else if (!pairwise &&
  438. key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  439. key = rcu_dereference(sta->gtk[key_idx]);
  440. } else
  441. key = rcu_dereference(sdata->keys[key_idx]);
  442. if (!key)
  443. goto out;
  444. memset(&params, 0, sizeof(params));
  445. params.cipher = key->conf.cipher;
  446. switch (key->conf.cipher) {
  447. case WLAN_CIPHER_SUITE_TKIP:
  448. pn64 = atomic64_read(&key->conf.tx_pn);
  449. iv32 = TKIP_PN_TO_IV32(pn64);
  450. iv16 = TKIP_PN_TO_IV16(pn64);
  451. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  452. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  453. drv_get_key_seq(sdata->local, key, &kseq);
  454. iv32 = kseq.tkip.iv32;
  455. iv16 = kseq.tkip.iv16;
  456. }
  457. seq[0] = iv16 & 0xff;
  458. seq[1] = (iv16 >> 8) & 0xff;
  459. seq[2] = iv32 & 0xff;
  460. seq[3] = (iv32 >> 8) & 0xff;
  461. seq[4] = (iv32 >> 16) & 0xff;
  462. seq[5] = (iv32 >> 24) & 0xff;
  463. params.seq = seq;
  464. params.seq_len = 6;
  465. break;
  466. case WLAN_CIPHER_SUITE_CCMP:
  467. case WLAN_CIPHER_SUITE_CCMP_256:
  468. case WLAN_CIPHER_SUITE_AES_CMAC:
  469. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  470. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  471. offsetof(typeof(kseq), aes_cmac));
  472. /* fall through */
  473. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  474. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  475. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  476. offsetof(typeof(kseq), aes_gmac));
  477. /* fall through */
  478. case WLAN_CIPHER_SUITE_GCMP:
  479. case WLAN_CIPHER_SUITE_GCMP_256:
  480. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  481. offsetof(typeof(kseq), gcmp));
  482. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  483. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  484. drv_get_key_seq(sdata->local, key, &kseq);
  485. memcpy(seq, kseq.ccmp.pn, 6);
  486. } else {
  487. pn64 = atomic64_read(&key->conf.tx_pn);
  488. seq[0] = pn64;
  489. seq[1] = pn64 >> 8;
  490. seq[2] = pn64 >> 16;
  491. seq[3] = pn64 >> 24;
  492. seq[4] = pn64 >> 32;
  493. seq[5] = pn64 >> 40;
  494. }
  495. params.seq = seq;
  496. params.seq_len = 6;
  497. break;
  498. default:
  499. if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  500. break;
  501. if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
  502. break;
  503. drv_get_key_seq(sdata->local, key, &kseq);
  504. params.seq = kseq.hw.seq;
  505. params.seq_len = kseq.hw.seq_len;
  506. break;
  507. }
  508. params.key = key->conf.key;
  509. params.key_len = key->conf.keylen;
  510. callback(cookie, &params);
  511. err = 0;
  512. out:
  513. rcu_read_unlock();
  514. return err;
  515. }
  516. static int ieee80211_config_default_key(struct wiphy *wiphy,
  517. struct net_device *dev,
  518. u8 key_idx, bool uni,
  519. bool multi)
  520. {
  521. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  522. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  523. return 0;
  524. }
  525. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  526. struct net_device *dev,
  527. u8 key_idx)
  528. {
  529. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  530. ieee80211_set_default_mgmt_key(sdata, key_idx);
  531. return 0;
  532. }
  533. void sta_set_rate_info_tx(struct sta_info *sta,
  534. const struct ieee80211_tx_rate *rate,
  535. struct rate_info *rinfo)
  536. {
  537. rinfo->flags = 0;
  538. if (rate->flags & IEEE80211_TX_RC_MCS) {
  539. rinfo->flags |= RATE_INFO_FLAGS_MCS;
  540. rinfo->mcs = rate->idx;
  541. } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
  542. rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
  543. rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
  544. rinfo->nss = ieee80211_rate_get_vht_nss(rate);
  545. } else {
  546. struct ieee80211_supported_band *sband;
  547. int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
  548. u16 brate;
  549. sband = ieee80211_get_sband(sta->sdata);
  550. if (sband) {
  551. brate = sband->bitrates[rate->idx].bitrate;
  552. rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
  553. }
  554. }
  555. if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  556. rinfo->bw = RATE_INFO_BW_40;
  557. else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  558. rinfo->bw = RATE_INFO_BW_80;
  559. else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  560. rinfo->bw = RATE_INFO_BW_160;
  561. else
  562. rinfo->bw = RATE_INFO_BW_20;
  563. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  564. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  565. }
  566. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  567. int idx, u8 *mac, struct station_info *sinfo)
  568. {
  569. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  570. struct ieee80211_local *local = sdata->local;
  571. struct sta_info *sta;
  572. int ret = -ENOENT;
  573. mutex_lock(&local->sta_mtx);
  574. sta = sta_info_get_by_idx(sdata, idx);
  575. if (sta) {
  576. ret = 0;
  577. memcpy(mac, sta->sta.addr, ETH_ALEN);
  578. sta_set_sinfo(sta, sinfo, true);
  579. }
  580. mutex_unlock(&local->sta_mtx);
  581. return ret;
  582. }
  583. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  584. int idx, struct survey_info *survey)
  585. {
  586. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  587. return drv_get_survey(local, idx, survey);
  588. }
  589. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  590. const u8 *mac, struct station_info *sinfo)
  591. {
  592. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  593. struct ieee80211_local *local = sdata->local;
  594. struct sta_info *sta;
  595. int ret = -ENOENT;
  596. mutex_lock(&local->sta_mtx);
  597. sta = sta_info_get_bss(sdata, mac);
  598. if (sta) {
  599. ret = 0;
  600. sta_set_sinfo(sta, sinfo, true);
  601. }
  602. mutex_unlock(&local->sta_mtx);
  603. return ret;
  604. }
  605. static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  606. struct cfg80211_chan_def *chandef)
  607. {
  608. struct ieee80211_local *local = wiphy_priv(wiphy);
  609. struct ieee80211_sub_if_data *sdata;
  610. int ret = 0;
  611. if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
  612. return 0;
  613. mutex_lock(&local->mtx);
  614. if (local->use_chanctx) {
  615. sdata = rtnl_dereference(local->monitor_sdata);
  616. if (sdata) {
  617. ieee80211_vif_release_channel(sdata);
  618. ret = ieee80211_vif_use_channel(sdata, chandef,
  619. IEEE80211_CHANCTX_EXCLUSIVE);
  620. }
  621. } else if (local->open_count == local->monitors) {
  622. local->_oper_chandef = *chandef;
  623. ieee80211_hw_config(local, 0);
  624. }
  625. if (ret == 0)
  626. local->monitor_chandef = *chandef;
  627. mutex_unlock(&local->mtx);
  628. return ret;
  629. }
  630. static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
  631. const u8 *resp, size_t resp_len,
  632. const struct ieee80211_csa_settings *csa)
  633. {
  634. struct probe_resp *new, *old;
  635. if (!resp || !resp_len)
  636. return 1;
  637. old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
  638. new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
  639. if (!new)
  640. return -ENOMEM;
  641. new->len = resp_len;
  642. memcpy(new->data, resp, resp_len);
  643. if (csa)
  644. memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
  645. csa->n_counter_offsets_presp *
  646. sizeof(new->csa_counter_offsets[0]));
  647. rcu_assign_pointer(sdata->u.ap.probe_resp, new);
  648. if (old)
  649. kfree_rcu(old, rcu_head);
  650. return 0;
  651. }
  652. static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
  653. struct cfg80211_beacon_data *params,
  654. const struct ieee80211_csa_settings *csa)
  655. {
  656. struct beacon_data *new, *old;
  657. int new_head_len, new_tail_len;
  658. int size, err;
  659. u32 changed = BSS_CHANGED_BEACON;
  660. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  661. /* Need to have a beacon head if we don't have one yet */
  662. if (!params->head && !old)
  663. return -EINVAL;
  664. /* new or old head? */
  665. if (params->head)
  666. new_head_len = params->head_len;
  667. else
  668. new_head_len = old->head_len;
  669. /* new or old tail? */
  670. if (params->tail || !old)
  671. /* params->tail_len will be zero for !params->tail */
  672. new_tail_len = params->tail_len;
  673. else
  674. new_tail_len = old->tail_len;
  675. size = sizeof(*new) + new_head_len + new_tail_len;
  676. new = kzalloc(size, GFP_KERNEL);
  677. if (!new)
  678. return -ENOMEM;
  679. /* start filling the new info now */
  680. /*
  681. * pointers go into the block we allocated,
  682. * memory is | beacon_data | head | tail |
  683. */
  684. new->head = ((u8 *) new) + sizeof(*new);
  685. new->tail = new->head + new_head_len;
  686. new->head_len = new_head_len;
  687. new->tail_len = new_tail_len;
  688. if (csa) {
  689. new->csa_current_counter = csa->count;
  690. memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
  691. csa->n_counter_offsets_beacon *
  692. sizeof(new->csa_counter_offsets[0]));
  693. }
  694. /* copy in head */
  695. if (params->head)
  696. memcpy(new->head, params->head, new_head_len);
  697. else
  698. memcpy(new->head, old->head, new_head_len);
  699. /* copy in optional tail */
  700. if (params->tail)
  701. memcpy(new->tail, params->tail, new_tail_len);
  702. else
  703. if (old)
  704. memcpy(new->tail, old->tail, new_tail_len);
  705. err = ieee80211_set_probe_resp(sdata, params->probe_resp,
  706. params->probe_resp_len, csa);
  707. if (err < 0)
  708. return err;
  709. if (err == 0)
  710. changed |= BSS_CHANGED_AP_PROBE_RESP;
  711. rcu_assign_pointer(sdata->u.ap.beacon, new);
  712. if (old)
  713. kfree_rcu(old, rcu_head);
  714. return changed;
  715. }
  716. static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
  717. struct cfg80211_ap_settings *params)
  718. {
  719. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  720. struct ieee80211_local *local = sdata->local;
  721. struct beacon_data *old;
  722. struct ieee80211_sub_if_data *vlan;
  723. u32 changed = BSS_CHANGED_BEACON_INT |
  724. BSS_CHANGED_BEACON_ENABLED |
  725. BSS_CHANGED_BEACON |
  726. BSS_CHANGED_SSID |
  727. BSS_CHANGED_P2P_PS |
  728. BSS_CHANGED_TXPOWER;
  729. int err;
  730. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  731. if (old)
  732. return -EALREADY;
  733. switch (params->smps_mode) {
  734. case NL80211_SMPS_OFF:
  735. sdata->smps_mode = IEEE80211_SMPS_OFF;
  736. break;
  737. case NL80211_SMPS_STATIC:
  738. sdata->smps_mode = IEEE80211_SMPS_STATIC;
  739. break;
  740. case NL80211_SMPS_DYNAMIC:
  741. sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
  742. break;
  743. default:
  744. return -EINVAL;
  745. }
  746. sdata->u.ap.req_smps = sdata->smps_mode;
  747. sdata->needed_rx_chains = sdata->local->rx_chains;
  748. sdata->vif.bss_conf.beacon_int = params->beacon_interval;
  749. mutex_lock(&local->mtx);
  750. err = ieee80211_vif_use_channel(sdata, &params->chandef,
  751. IEEE80211_CHANCTX_SHARED);
  752. if (!err)
  753. ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
  754. mutex_unlock(&local->mtx);
  755. if (err)
  756. return err;
  757. /*
  758. * Apply control port protocol, this allows us to
  759. * not encrypt dynamic WEP control frames.
  760. */
  761. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  762. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  763. sdata->control_port_over_nl80211 =
  764. params->crypto.control_port_over_nl80211;
  765. sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
  766. &params->crypto,
  767. sdata->vif.type);
  768. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  769. vlan->control_port_protocol =
  770. params->crypto.control_port_ethertype;
  771. vlan->control_port_no_encrypt =
  772. params->crypto.control_port_no_encrypt;
  773. vlan->control_port_over_nl80211 =
  774. params->crypto.control_port_over_nl80211;
  775. vlan->encrypt_headroom =
  776. ieee80211_cs_headroom(sdata->local,
  777. &params->crypto,
  778. vlan->vif.type);
  779. }
  780. sdata->vif.bss_conf.dtim_period = params->dtim_period;
  781. sdata->vif.bss_conf.enable_beacon = true;
  782. sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
  783. sdata->vif.bss_conf.ssid_len = params->ssid_len;
  784. if (params->ssid_len)
  785. memcpy(sdata->vif.bss_conf.ssid, params->ssid,
  786. params->ssid_len);
  787. sdata->vif.bss_conf.hidden_ssid =
  788. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  789. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  790. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  791. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
  792. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  793. if (params->p2p_opp_ps)
  794. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  795. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  796. err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
  797. if (err < 0) {
  798. ieee80211_vif_release_channel(sdata);
  799. return err;
  800. }
  801. changed |= err;
  802. err = drv_start_ap(sdata->local, sdata);
  803. if (err) {
  804. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  805. if (old)
  806. kfree_rcu(old, rcu_head);
  807. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  808. ieee80211_vif_release_channel(sdata);
  809. return err;
  810. }
  811. ieee80211_recalc_dtim(local, sdata);
  812. ieee80211_bss_info_change_notify(sdata, changed);
  813. netif_carrier_on(dev);
  814. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  815. netif_carrier_on(vlan->dev);
  816. return 0;
  817. }
  818. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  819. struct cfg80211_beacon_data *params)
  820. {
  821. struct ieee80211_sub_if_data *sdata;
  822. struct beacon_data *old;
  823. int err;
  824. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  825. sdata_assert_lock(sdata);
  826. /* don't allow changing the beacon while CSA is in place - offset
  827. * of channel switch counter may change
  828. */
  829. if (sdata->vif.csa_active)
  830. return -EBUSY;
  831. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  832. if (!old)
  833. return -ENOENT;
  834. err = ieee80211_assign_beacon(sdata, params, NULL);
  835. if (err < 0)
  836. return err;
  837. ieee80211_bss_info_change_notify(sdata, err);
  838. return 0;
  839. }
  840. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  841. {
  842. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  843. struct ieee80211_sub_if_data *vlan;
  844. struct ieee80211_local *local = sdata->local;
  845. struct beacon_data *old_beacon;
  846. struct probe_resp *old_probe_resp;
  847. struct cfg80211_chan_def chandef;
  848. sdata_assert_lock(sdata);
  849. old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
  850. if (!old_beacon)
  851. return -ENOENT;
  852. old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
  853. /* abort any running channel switch */
  854. mutex_lock(&local->mtx);
  855. sdata->vif.csa_active = false;
  856. if (sdata->csa_block_tx) {
  857. ieee80211_wake_vif_queues(local, sdata,
  858. IEEE80211_QUEUE_STOP_REASON_CSA);
  859. sdata->csa_block_tx = false;
  860. }
  861. mutex_unlock(&local->mtx);
  862. kfree(sdata->u.ap.next_beacon);
  863. sdata->u.ap.next_beacon = NULL;
  864. /* turn off carrier for this interface and dependent VLANs */
  865. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  866. netif_carrier_off(vlan->dev);
  867. netif_carrier_off(dev);
  868. /* remove beacon and probe response */
  869. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  870. RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
  871. kfree_rcu(old_beacon, rcu_head);
  872. if (old_probe_resp)
  873. kfree_rcu(old_probe_resp, rcu_head);
  874. sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
  875. __sta_info_flush(sdata, true);
  876. ieee80211_free_keys(sdata, true);
  877. sdata->vif.bss_conf.enable_beacon = false;
  878. sdata->vif.bss_conf.ssid_len = 0;
  879. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  880. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  881. if (sdata->wdev.cac_started) {
  882. chandef = sdata->vif.bss_conf.chandef;
  883. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  884. cfg80211_cac_event(sdata->dev, &chandef,
  885. NL80211_RADAR_CAC_ABORTED,
  886. GFP_KERNEL);
  887. }
  888. drv_stop_ap(sdata->local, sdata);
  889. /* free all potentially still buffered bcast frames */
  890. local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
  891. ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
  892. mutex_lock(&local->mtx);
  893. ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
  894. ieee80211_vif_release_channel(sdata);
  895. mutex_unlock(&local->mtx);
  896. return 0;
  897. }
  898. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  899. struct iapp_layer2_update {
  900. u8 da[ETH_ALEN]; /* broadcast */
  901. u8 sa[ETH_ALEN]; /* STA addr */
  902. __be16 len; /* 6 */
  903. u8 dsap; /* 0 */
  904. u8 ssap; /* 0 */
  905. u8 control;
  906. u8 xid_info[3];
  907. } __packed;
  908. static void ieee80211_send_layer2_update(struct sta_info *sta)
  909. {
  910. struct iapp_layer2_update *msg;
  911. struct sk_buff *skb;
  912. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  913. * bridge devices */
  914. skb = dev_alloc_skb(sizeof(*msg));
  915. if (!skb)
  916. return;
  917. msg = skb_put(skb, sizeof(*msg));
  918. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  919. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  920. eth_broadcast_addr(msg->da);
  921. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  922. msg->len = htons(6);
  923. msg->dsap = 0;
  924. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  925. msg->control = 0xaf; /* XID response lsb.1111F101.
  926. * F=0 (no poll command; unsolicited frame) */
  927. msg->xid_info[0] = 0x81; /* XID format identifier */
  928. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  929. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  930. skb->dev = sta->sdata->dev;
  931. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  932. memset(skb->cb, 0, sizeof(skb->cb));
  933. netif_rx_ni(skb);
  934. }
  935. static int sta_apply_auth_flags(struct ieee80211_local *local,
  936. struct sta_info *sta,
  937. u32 mask, u32 set)
  938. {
  939. int ret;
  940. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  941. set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  942. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  943. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  944. if (ret)
  945. return ret;
  946. }
  947. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  948. set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  949. !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  950. /*
  951. * When peer becomes associated, init rate control as
  952. * well. Some drivers require rate control initialized
  953. * before drv_sta_state() is called.
  954. */
  955. if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  956. rate_control_rate_init(sta);
  957. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  958. if (ret)
  959. return ret;
  960. }
  961. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  962. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  963. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  964. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  965. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  966. else
  967. ret = 0;
  968. if (ret)
  969. return ret;
  970. }
  971. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  972. !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  973. test_sta_flag(sta, WLAN_STA_ASSOC)) {
  974. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  975. if (ret)
  976. return ret;
  977. }
  978. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  979. !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  980. test_sta_flag(sta, WLAN_STA_AUTH)) {
  981. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  982. if (ret)
  983. return ret;
  984. }
  985. return 0;
  986. }
  987. static void sta_apply_mesh_params(struct ieee80211_local *local,
  988. struct sta_info *sta,
  989. struct station_parameters *params)
  990. {
  991. #ifdef CONFIG_MAC80211_MESH
  992. struct ieee80211_sub_if_data *sdata = sta->sdata;
  993. u32 changed = 0;
  994. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
  995. switch (params->plink_state) {
  996. case NL80211_PLINK_ESTAB:
  997. if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
  998. changed = mesh_plink_inc_estab_count(sdata);
  999. sta->mesh->plink_state = params->plink_state;
  1000. sta->mesh->aid = params->peer_aid;
  1001. ieee80211_mps_sta_status_update(sta);
  1002. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1003. sdata->u.mesh.mshcfg.power_mode);
  1004. break;
  1005. case NL80211_PLINK_LISTEN:
  1006. case NL80211_PLINK_BLOCKED:
  1007. case NL80211_PLINK_OPN_SNT:
  1008. case NL80211_PLINK_OPN_RCVD:
  1009. case NL80211_PLINK_CNF_RCVD:
  1010. case NL80211_PLINK_HOLDING:
  1011. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  1012. changed = mesh_plink_dec_estab_count(sdata);
  1013. sta->mesh->plink_state = params->plink_state;
  1014. ieee80211_mps_sta_status_update(sta);
  1015. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1016. NL80211_MESH_POWER_UNKNOWN);
  1017. break;
  1018. default:
  1019. /* nothing */
  1020. break;
  1021. }
  1022. }
  1023. switch (params->plink_action) {
  1024. case NL80211_PLINK_ACTION_NO_ACTION:
  1025. /* nothing */
  1026. break;
  1027. case NL80211_PLINK_ACTION_OPEN:
  1028. changed |= mesh_plink_open(sta);
  1029. break;
  1030. case NL80211_PLINK_ACTION_BLOCK:
  1031. changed |= mesh_plink_block(sta);
  1032. break;
  1033. }
  1034. if (params->local_pm)
  1035. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1036. params->local_pm);
  1037. ieee80211_mbss_info_change_notify(sdata, changed);
  1038. #endif
  1039. }
  1040. static int sta_apply_parameters(struct ieee80211_local *local,
  1041. struct sta_info *sta,
  1042. struct station_parameters *params)
  1043. {
  1044. int ret = 0;
  1045. struct ieee80211_supported_band *sband;
  1046. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1047. u32 mask, set;
  1048. sband = ieee80211_get_sband(sdata);
  1049. if (!sband)
  1050. return -EINVAL;
  1051. mask = params->sta_flags_mask;
  1052. set = params->sta_flags_set;
  1053. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1054. /*
  1055. * In mesh mode, ASSOCIATED isn't part of the nl80211
  1056. * API but must follow AUTHENTICATED for driver state.
  1057. */
  1058. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1059. mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1060. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1061. set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1062. } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1063. /*
  1064. * TDLS -- everything follows authorized, but
  1065. * only becoming authorized is possible, not
  1066. * going back
  1067. */
  1068. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1069. set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1070. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1071. mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1072. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1073. }
  1074. }
  1075. if (mask & BIT(NL80211_STA_FLAG_WME) &&
  1076. local->hw.queues >= IEEE80211_NUM_ACS)
  1077. sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
  1078. /* auth flags will be set later for TDLS,
  1079. * and for unassociated stations that move to assocaited */
  1080. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1081. !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  1082. (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
  1083. ret = sta_apply_auth_flags(local, sta, mask, set);
  1084. if (ret)
  1085. return ret;
  1086. }
  1087. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  1088. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  1089. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1090. else
  1091. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1092. }
  1093. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  1094. sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
  1095. if (set & BIT(NL80211_STA_FLAG_MFP))
  1096. set_sta_flag(sta, WLAN_STA_MFP);
  1097. else
  1098. clear_sta_flag(sta, WLAN_STA_MFP);
  1099. }
  1100. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  1101. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1102. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1103. else
  1104. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1105. }
  1106. /* mark TDLS channel switch support, if the AP allows it */
  1107. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1108. !sdata->u.mgd.tdls_chan_switch_prohibited &&
  1109. params->ext_capab_len >= 4 &&
  1110. params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
  1111. set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
  1112. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1113. !sdata->u.mgd.tdls_wider_bw_prohibited &&
  1114. ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
  1115. params->ext_capab_len >= 8 &&
  1116. params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
  1117. set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
  1118. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  1119. sta->sta.uapsd_queues = params->uapsd_queues;
  1120. sta->sta.max_sp = params->max_sp;
  1121. }
  1122. /* The sender might not have sent the last bit, consider it to be 0 */
  1123. if (params->ext_capab_len >= 8) {
  1124. u8 val = (params->ext_capab[7] &
  1125. WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
  1126. /* we did get all the bits, take the MSB as well */
  1127. if (params->ext_capab_len >= 9) {
  1128. u8 val_msb = params->ext_capab[8] &
  1129. WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
  1130. val_msb <<= 1;
  1131. val |= val_msb;
  1132. }
  1133. switch (val) {
  1134. case 1:
  1135. sta->sta.max_amsdu_subframes = 32;
  1136. break;
  1137. case 2:
  1138. sta->sta.max_amsdu_subframes = 16;
  1139. break;
  1140. case 3:
  1141. sta->sta.max_amsdu_subframes = 8;
  1142. break;
  1143. default:
  1144. sta->sta.max_amsdu_subframes = 0;
  1145. }
  1146. }
  1147. /*
  1148. * cfg80211 validates this (1-2007) and allows setting the AID
  1149. * only when creating a new station entry
  1150. */
  1151. if (params->aid)
  1152. sta->sta.aid = params->aid;
  1153. /*
  1154. * Some of the following updates would be racy if called on an
  1155. * existing station, via ieee80211_change_station(). However,
  1156. * all such changes are rejected by cfg80211 except for updates
  1157. * changing the supported rates on an existing but not yet used
  1158. * TDLS peer.
  1159. */
  1160. if (params->listen_interval >= 0)
  1161. sta->listen_interval = params->listen_interval;
  1162. if (params->supported_rates) {
  1163. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1164. sband, params->supported_rates,
  1165. params->supported_rates_len,
  1166. &sta->sta.supp_rates[sband->band]);
  1167. }
  1168. if (params->ht_capa)
  1169. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  1170. params->ht_capa, sta);
  1171. /* VHT can override some HT caps such as the A-MSDU max length */
  1172. if (params->vht_capa)
  1173. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  1174. params->vht_capa, sta);
  1175. if (params->he_capa)
  1176. ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
  1177. (void *)params->he_capa,
  1178. params->he_capa_len, sta);
  1179. if (params->opmode_notif_used) {
  1180. /* returned value is only needed for rc update, but the
  1181. * rc isn't initialized here yet, so ignore it
  1182. */
  1183. __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
  1184. sband->band);
  1185. }
  1186. if (params->support_p2p_ps >= 0)
  1187. sta->sta.support_p2p_ps = params->support_p2p_ps;
  1188. if (ieee80211_vif_is_mesh(&sdata->vif))
  1189. sta_apply_mesh_params(local, sta, params);
  1190. /* set the STA state after all sta info from usermode has been set */
  1191. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
  1192. set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
  1193. ret = sta_apply_auth_flags(local, sta, mask, set);
  1194. if (ret)
  1195. return ret;
  1196. }
  1197. return 0;
  1198. }
  1199. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  1200. const u8 *mac,
  1201. struct station_parameters *params)
  1202. {
  1203. struct ieee80211_local *local = wiphy_priv(wiphy);
  1204. struct sta_info *sta;
  1205. struct ieee80211_sub_if_data *sdata;
  1206. int err;
  1207. int layer2_update;
  1208. if (params->vlan) {
  1209. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1210. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1211. sdata->vif.type != NL80211_IFTYPE_AP)
  1212. return -EINVAL;
  1213. } else
  1214. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1215. if (ether_addr_equal(mac, sdata->vif.addr))
  1216. return -EINVAL;
  1217. if (is_multicast_ether_addr(mac))
  1218. return -EINVAL;
  1219. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  1220. if (!sta)
  1221. return -ENOMEM;
  1222. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1223. sta->sta.tdls = true;
  1224. err = sta_apply_parameters(local, sta, params);
  1225. if (err) {
  1226. sta_info_free(local, sta);
  1227. return err;
  1228. }
  1229. /*
  1230. * for TDLS and for unassociated station, rate control should be
  1231. * initialized only when rates are known and station is marked
  1232. * authorized/associated
  1233. */
  1234. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1235. test_sta_flag(sta, WLAN_STA_ASSOC))
  1236. rate_control_rate_init(sta);
  1237. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1238. sdata->vif.type == NL80211_IFTYPE_AP;
  1239. err = sta_info_insert_rcu(sta);
  1240. if (err) {
  1241. rcu_read_unlock();
  1242. return err;
  1243. }
  1244. if (layer2_update)
  1245. ieee80211_send_layer2_update(sta);
  1246. rcu_read_unlock();
  1247. return 0;
  1248. }
  1249. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1250. struct station_del_parameters *params)
  1251. {
  1252. struct ieee80211_sub_if_data *sdata;
  1253. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1254. if (params->mac)
  1255. return sta_info_destroy_addr_bss(sdata, params->mac);
  1256. sta_info_flush(sdata);
  1257. return 0;
  1258. }
  1259. static int ieee80211_change_station(struct wiphy *wiphy,
  1260. struct net_device *dev, const u8 *mac,
  1261. struct station_parameters *params)
  1262. {
  1263. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1264. struct ieee80211_local *local = wiphy_priv(wiphy);
  1265. struct sta_info *sta;
  1266. struct ieee80211_sub_if_data *vlansdata;
  1267. enum cfg80211_station_type statype;
  1268. int err;
  1269. mutex_lock(&local->sta_mtx);
  1270. sta = sta_info_get_bss(sdata, mac);
  1271. if (!sta) {
  1272. err = -ENOENT;
  1273. goto out_err;
  1274. }
  1275. switch (sdata->vif.type) {
  1276. case NL80211_IFTYPE_MESH_POINT:
  1277. if (sdata->u.mesh.user_mpm)
  1278. statype = CFG80211_STA_MESH_PEER_USER;
  1279. else
  1280. statype = CFG80211_STA_MESH_PEER_KERNEL;
  1281. break;
  1282. case NL80211_IFTYPE_ADHOC:
  1283. statype = CFG80211_STA_IBSS;
  1284. break;
  1285. case NL80211_IFTYPE_STATION:
  1286. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1287. statype = CFG80211_STA_AP_STA;
  1288. break;
  1289. }
  1290. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1291. statype = CFG80211_STA_TDLS_PEER_ACTIVE;
  1292. else
  1293. statype = CFG80211_STA_TDLS_PEER_SETUP;
  1294. break;
  1295. case NL80211_IFTYPE_AP:
  1296. case NL80211_IFTYPE_AP_VLAN:
  1297. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  1298. statype = CFG80211_STA_AP_CLIENT;
  1299. else
  1300. statype = CFG80211_STA_AP_CLIENT_UNASSOC;
  1301. break;
  1302. default:
  1303. err = -EOPNOTSUPP;
  1304. goto out_err;
  1305. }
  1306. err = cfg80211_check_station_change(wiphy, params, statype);
  1307. if (err)
  1308. goto out_err;
  1309. if (params->vlan && params->vlan != sta->sdata->dev) {
  1310. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1311. if (params->vlan->ieee80211_ptr->use_4addr) {
  1312. if (vlansdata->u.vlan.sta) {
  1313. err = -EBUSY;
  1314. goto out_err;
  1315. }
  1316. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1317. __ieee80211_check_fast_rx_iface(vlansdata);
  1318. }
  1319. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1320. sta->sdata->u.vlan.sta)
  1321. RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
  1322. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1323. ieee80211_vif_dec_num_mcast(sta->sdata);
  1324. sta->sdata = vlansdata;
  1325. ieee80211_check_fast_xmit(sta);
  1326. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1327. ieee80211_vif_inc_num_mcast(sta->sdata);
  1328. ieee80211_send_layer2_update(sta);
  1329. }
  1330. err = sta_apply_parameters(local, sta, params);
  1331. if (err)
  1332. goto out_err;
  1333. mutex_unlock(&local->sta_mtx);
  1334. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1335. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1336. sta->known_smps_mode != sta->sdata->bss->req_smps &&
  1337. test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
  1338. sta_info_tx_streams(sta) != 1) {
  1339. ht_dbg(sta->sdata,
  1340. "%pM just authorized and MIMO capable - update SMPS\n",
  1341. sta->sta.addr);
  1342. ieee80211_send_smps_action(sta->sdata,
  1343. sta->sdata->bss->req_smps,
  1344. sta->sta.addr,
  1345. sta->sdata->vif.bss_conf.bssid);
  1346. }
  1347. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1348. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1349. ieee80211_recalc_ps(local);
  1350. ieee80211_recalc_ps_vif(sdata);
  1351. }
  1352. return 0;
  1353. out_err:
  1354. mutex_unlock(&local->sta_mtx);
  1355. return err;
  1356. }
  1357. #ifdef CONFIG_MAC80211_MESH
  1358. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1359. const u8 *dst, const u8 *next_hop)
  1360. {
  1361. struct ieee80211_sub_if_data *sdata;
  1362. struct mesh_path *mpath;
  1363. struct sta_info *sta;
  1364. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1365. rcu_read_lock();
  1366. sta = sta_info_get(sdata, next_hop);
  1367. if (!sta) {
  1368. rcu_read_unlock();
  1369. return -ENOENT;
  1370. }
  1371. mpath = mesh_path_add(sdata, dst);
  1372. if (IS_ERR(mpath)) {
  1373. rcu_read_unlock();
  1374. return PTR_ERR(mpath);
  1375. }
  1376. mesh_path_fix_nexthop(mpath, sta);
  1377. rcu_read_unlock();
  1378. return 0;
  1379. }
  1380. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1381. const u8 *dst)
  1382. {
  1383. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1384. if (dst)
  1385. return mesh_path_del(sdata, dst);
  1386. mesh_path_flush_by_iface(sdata);
  1387. return 0;
  1388. }
  1389. static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
  1390. const u8 *dst, const u8 *next_hop)
  1391. {
  1392. struct ieee80211_sub_if_data *sdata;
  1393. struct mesh_path *mpath;
  1394. struct sta_info *sta;
  1395. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1396. rcu_read_lock();
  1397. sta = sta_info_get(sdata, next_hop);
  1398. if (!sta) {
  1399. rcu_read_unlock();
  1400. return -ENOENT;
  1401. }
  1402. mpath = mesh_path_lookup(sdata, dst);
  1403. if (!mpath) {
  1404. rcu_read_unlock();
  1405. return -ENOENT;
  1406. }
  1407. mesh_path_fix_nexthop(mpath, sta);
  1408. rcu_read_unlock();
  1409. return 0;
  1410. }
  1411. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1412. struct mpath_info *pinfo)
  1413. {
  1414. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1415. if (next_hop_sta)
  1416. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1417. else
  1418. eth_zero_addr(next_hop);
  1419. memset(pinfo, 0, sizeof(*pinfo));
  1420. pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
  1421. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1422. MPATH_INFO_SN |
  1423. MPATH_INFO_METRIC |
  1424. MPATH_INFO_EXPTIME |
  1425. MPATH_INFO_DISCOVERY_TIMEOUT |
  1426. MPATH_INFO_DISCOVERY_RETRIES |
  1427. MPATH_INFO_FLAGS;
  1428. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1429. pinfo->sn = mpath->sn;
  1430. pinfo->metric = mpath->metric;
  1431. if (time_before(jiffies, mpath->exp_time))
  1432. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1433. pinfo->discovery_timeout =
  1434. jiffies_to_msecs(mpath->discovery_timeout);
  1435. pinfo->discovery_retries = mpath->discovery_retries;
  1436. if (mpath->flags & MESH_PATH_ACTIVE)
  1437. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1438. if (mpath->flags & MESH_PATH_RESOLVING)
  1439. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1440. if (mpath->flags & MESH_PATH_SN_VALID)
  1441. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1442. if (mpath->flags & MESH_PATH_FIXED)
  1443. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1444. if (mpath->flags & MESH_PATH_RESOLVED)
  1445. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  1446. }
  1447. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1448. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1449. {
  1450. struct ieee80211_sub_if_data *sdata;
  1451. struct mesh_path *mpath;
  1452. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1453. rcu_read_lock();
  1454. mpath = mesh_path_lookup(sdata, dst);
  1455. if (!mpath) {
  1456. rcu_read_unlock();
  1457. return -ENOENT;
  1458. }
  1459. memcpy(dst, mpath->dst, ETH_ALEN);
  1460. mpath_set_pinfo(mpath, next_hop, pinfo);
  1461. rcu_read_unlock();
  1462. return 0;
  1463. }
  1464. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1465. int idx, u8 *dst, u8 *next_hop,
  1466. struct mpath_info *pinfo)
  1467. {
  1468. struct ieee80211_sub_if_data *sdata;
  1469. struct mesh_path *mpath;
  1470. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1471. rcu_read_lock();
  1472. mpath = mesh_path_lookup_by_idx(sdata, idx);
  1473. if (!mpath) {
  1474. rcu_read_unlock();
  1475. return -ENOENT;
  1476. }
  1477. memcpy(dst, mpath->dst, ETH_ALEN);
  1478. mpath_set_pinfo(mpath, next_hop, pinfo);
  1479. rcu_read_unlock();
  1480. return 0;
  1481. }
  1482. static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
  1483. struct mpath_info *pinfo)
  1484. {
  1485. memset(pinfo, 0, sizeof(*pinfo));
  1486. memcpy(mpp, mpath->mpp, ETH_ALEN);
  1487. pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
  1488. }
  1489. static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
  1490. u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  1491. {
  1492. struct ieee80211_sub_if_data *sdata;
  1493. struct mesh_path *mpath;
  1494. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1495. rcu_read_lock();
  1496. mpath = mpp_path_lookup(sdata, dst);
  1497. if (!mpath) {
  1498. rcu_read_unlock();
  1499. return -ENOENT;
  1500. }
  1501. memcpy(dst, mpath->dst, ETH_ALEN);
  1502. mpp_set_pinfo(mpath, mpp, pinfo);
  1503. rcu_read_unlock();
  1504. return 0;
  1505. }
  1506. static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
  1507. int idx, u8 *dst, u8 *mpp,
  1508. struct mpath_info *pinfo)
  1509. {
  1510. struct ieee80211_sub_if_data *sdata;
  1511. struct mesh_path *mpath;
  1512. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1513. rcu_read_lock();
  1514. mpath = mpp_path_lookup_by_idx(sdata, idx);
  1515. if (!mpath) {
  1516. rcu_read_unlock();
  1517. return -ENOENT;
  1518. }
  1519. memcpy(dst, mpath->dst, ETH_ALEN);
  1520. mpp_set_pinfo(mpath, mpp, pinfo);
  1521. rcu_read_unlock();
  1522. return 0;
  1523. }
  1524. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  1525. struct net_device *dev,
  1526. struct mesh_config *conf)
  1527. {
  1528. struct ieee80211_sub_if_data *sdata;
  1529. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1530. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  1531. return 0;
  1532. }
  1533. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  1534. {
  1535. return (mask >> (parm-1)) & 0x1;
  1536. }
  1537. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  1538. const struct mesh_setup *setup)
  1539. {
  1540. u8 *new_ie;
  1541. const u8 *old_ie;
  1542. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  1543. struct ieee80211_sub_if_data, u.mesh);
  1544. /* allocate information elements */
  1545. new_ie = NULL;
  1546. old_ie = ifmsh->ie;
  1547. if (setup->ie_len) {
  1548. new_ie = kmemdup(setup->ie, setup->ie_len,
  1549. GFP_KERNEL);
  1550. if (!new_ie)
  1551. return -ENOMEM;
  1552. }
  1553. ifmsh->ie_len = setup->ie_len;
  1554. ifmsh->ie = new_ie;
  1555. kfree(old_ie);
  1556. /* now copy the rest of the setup parameters */
  1557. ifmsh->mesh_id_len = setup->mesh_id_len;
  1558. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  1559. ifmsh->mesh_sp_id = setup->sync_method;
  1560. ifmsh->mesh_pp_id = setup->path_sel_proto;
  1561. ifmsh->mesh_pm_id = setup->path_metric;
  1562. ifmsh->user_mpm = setup->user_mpm;
  1563. ifmsh->mesh_auth_id = setup->auth_id;
  1564. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  1565. ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
  1566. if (setup->is_authenticated)
  1567. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  1568. if (setup->is_secure)
  1569. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  1570. /* mcast rate setting in Mesh Node */
  1571. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  1572. sizeof(setup->mcast_rate));
  1573. sdata->vif.bss_conf.basic_rates = setup->basic_rates;
  1574. sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
  1575. sdata->vif.bss_conf.dtim_period = setup->dtim_period;
  1576. return 0;
  1577. }
  1578. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  1579. struct net_device *dev, u32 mask,
  1580. const struct mesh_config *nconf)
  1581. {
  1582. struct mesh_config *conf;
  1583. struct ieee80211_sub_if_data *sdata;
  1584. struct ieee80211_if_mesh *ifmsh;
  1585. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1586. ifmsh = &sdata->u.mesh;
  1587. /* Set the config options which we are interested in setting */
  1588. conf = &(sdata->u.mesh.mshcfg);
  1589. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  1590. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  1591. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  1592. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  1593. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  1594. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  1595. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  1596. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  1597. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  1598. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  1599. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  1600. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  1601. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  1602. conf->element_ttl = nconf->element_ttl;
  1603. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
  1604. if (ifmsh->user_mpm)
  1605. return -EBUSY;
  1606. conf->auto_open_plinks = nconf->auto_open_plinks;
  1607. }
  1608. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  1609. conf->dot11MeshNbrOffsetMaxNeighbor =
  1610. nconf->dot11MeshNbrOffsetMaxNeighbor;
  1611. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  1612. conf->dot11MeshHWMPmaxPREQretries =
  1613. nconf->dot11MeshHWMPmaxPREQretries;
  1614. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1615. conf->path_refresh_time = nconf->path_refresh_time;
  1616. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1617. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1618. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1619. conf->dot11MeshHWMPactivePathTimeout =
  1620. nconf->dot11MeshHWMPactivePathTimeout;
  1621. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1622. conf->dot11MeshHWMPpreqMinInterval =
  1623. nconf->dot11MeshHWMPpreqMinInterval;
  1624. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  1625. conf->dot11MeshHWMPperrMinInterval =
  1626. nconf->dot11MeshHWMPperrMinInterval;
  1627. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1628. mask))
  1629. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1630. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1631. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1632. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1633. ieee80211_mesh_root_setup(ifmsh);
  1634. }
  1635. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1636. /* our current gate announcement implementation rides on root
  1637. * announcements, so require this ifmsh to also be a root node
  1638. * */
  1639. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1640. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  1641. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  1642. ieee80211_mesh_root_setup(ifmsh);
  1643. }
  1644. conf->dot11MeshGateAnnouncementProtocol =
  1645. nconf->dot11MeshGateAnnouncementProtocol;
  1646. }
  1647. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  1648. conf->dot11MeshHWMPRannInterval =
  1649. nconf->dot11MeshHWMPRannInterval;
  1650. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  1651. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  1652. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  1653. /* our RSSI threshold implementation is supported only for
  1654. * devices that report signal in dBm.
  1655. */
  1656. if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
  1657. return -ENOTSUPP;
  1658. conf->rssi_threshold = nconf->rssi_threshold;
  1659. }
  1660. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  1661. conf->ht_opmode = nconf->ht_opmode;
  1662. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  1663. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1664. }
  1665. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  1666. conf->dot11MeshHWMPactivePathToRootTimeout =
  1667. nconf->dot11MeshHWMPactivePathToRootTimeout;
  1668. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  1669. conf->dot11MeshHWMProotInterval =
  1670. nconf->dot11MeshHWMProotInterval;
  1671. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  1672. conf->dot11MeshHWMPconfirmationInterval =
  1673. nconf->dot11MeshHWMPconfirmationInterval;
  1674. if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
  1675. conf->power_mode = nconf->power_mode;
  1676. ieee80211_mps_local_status_update(sdata);
  1677. }
  1678. if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
  1679. conf->dot11MeshAwakeWindowDuration =
  1680. nconf->dot11MeshAwakeWindowDuration;
  1681. if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
  1682. conf->plink_timeout = nconf->plink_timeout;
  1683. ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  1684. return 0;
  1685. }
  1686. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1687. const struct mesh_config *conf,
  1688. const struct mesh_setup *setup)
  1689. {
  1690. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1691. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1692. int err;
  1693. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1694. err = copy_mesh_setup(ifmsh, setup);
  1695. if (err)
  1696. return err;
  1697. sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
  1698. /* can mesh use other SMPS modes? */
  1699. sdata->smps_mode = IEEE80211_SMPS_OFF;
  1700. sdata->needed_rx_chains = sdata->local->rx_chains;
  1701. mutex_lock(&sdata->local->mtx);
  1702. err = ieee80211_vif_use_channel(sdata, &setup->chandef,
  1703. IEEE80211_CHANCTX_SHARED);
  1704. mutex_unlock(&sdata->local->mtx);
  1705. if (err)
  1706. return err;
  1707. return ieee80211_start_mesh(sdata);
  1708. }
  1709. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1710. {
  1711. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1712. ieee80211_stop_mesh(sdata);
  1713. mutex_lock(&sdata->local->mtx);
  1714. ieee80211_vif_release_channel(sdata);
  1715. mutex_unlock(&sdata->local->mtx);
  1716. return 0;
  1717. }
  1718. #endif
  1719. static int ieee80211_change_bss(struct wiphy *wiphy,
  1720. struct net_device *dev,
  1721. struct bss_parameters *params)
  1722. {
  1723. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1724. struct ieee80211_supported_band *sband;
  1725. u32 changed = 0;
  1726. if (!sdata_dereference(sdata->u.ap.beacon, sdata))
  1727. return -ENOENT;
  1728. sband = ieee80211_get_sband(sdata);
  1729. if (!sband)
  1730. return -EINVAL;
  1731. if (params->use_cts_prot >= 0) {
  1732. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1733. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1734. }
  1735. if (params->use_short_preamble >= 0) {
  1736. sdata->vif.bss_conf.use_short_preamble =
  1737. params->use_short_preamble;
  1738. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1739. }
  1740. if (!sdata->vif.bss_conf.use_short_slot &&
  1741. sband->band == NL80211_BAND_5GHZ) {
  1742. sdata->vif.bss_conf.use_short_slot = true;
  1743. changed |= BSS_CHANGED_ERP_SLOT;
  1744. }
  1745. if (params->use_short_slot_time >= 0) {
  1746. sdata->vif.bss_conf.use_short_slot =
  1747. params->use_short_slot_time;
  1748. changed |= BSS_CHANGED_ERP_SLOT;
  1749. }
  1750. if (params->basic_rates) {
  1751. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1752. wiphy->bands[sband->band],
  1753. params->basic_rates,
  1754. params->basic_rates_len,
  1755. &sdata->vif.bss_conf.basic_rates);
  1756. changed |= BSS_CHANGED_BASIC_RATES;
  1757. ieee80211_check_rate_mask(sdata);
  1758. }
  1759. if (params->ap_isolate >= 0) {
  1760. if (params->ap_isolate)
  1761. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1762. else
  1763. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1764. ieee80211_check_fast_rx_iface(sdata);
  1765. }
  1766. if (params->ht_opmode >= 0) {
  1767. sdata->vif.bss_conf.ht_operation_mode =
  1768. (u16) params->ht_opmode;
  1769. changed |= BSS_CHANGED_HT;
  1770. }
  1771. if (params->p2p_ctwindow >= 0) {
  1772. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1773. ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1774. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1775. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1776. changed |= BSS_CHANGED_P2P_PS;
  1777. }
  1778. if (params->p2p_opp_ps > 0) {
  1779. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1780. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1781. changed |= BSS_CHANGED_P2P_PS;
  1782. } else if (params->p2p_opp_ps == 0) {
  1783. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1784. ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1785. changed |= BSS_CHANGED_P2P_PS;
  1786. }
  1787. ieee80211_bss_info_change_notify(sdata, changed);
  1788. return 0;
  1789. }
  1790. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1791. struct net_device *dev,
  1792. struct ieee80211_txq_params *params)
  1793. {
  1794. struct ieee80211_local *local = wiphy_priv(wiphy);
  1795. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1796. struct ieee80211_tx_queue_params p;
  1797. if (!local->ops->conf_tx)
  1798. return -EOPNOTSUPP;
  1799. if (local->hw.queues < IEEE80211_NUM_ACS)
  1800. return -EOPNOTSUPP;
  1801. memset(&p, 0, sizeof(p));
  1802. p.aifs = params->aifs;
  1803. p.cw_max = params->cwmax;
  1804. p.cw_min = params->cwmin;
  1805. p.txop = params->txop;
  1806. /*
  1807. * Setting tx queue params disables u-apsd because it's only
  1808. * called in master mode.
  1809. */
  1810. p.uapsd = false;
  1811. ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
  1812. sdata->tx_conf[params->ac] = p;
  1813. if (drv_conf_tx(local, sdata, params->ac, &p)) {
  1814. wiphy_debug(local->hw.wiphy,
  1815. "failed to set TX queue parameters for AC %d\n",
  1816. params->ac);
  1817. return -EINVAL;
  1818. }
  1819. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  1820. return 0;
  1821. }
  1822. #ifdef CONFIG_PM
  1823. static int ieee80211_suspend(struct wiphy *wiphy,
  1824. struct cfg80211_wowlan *wowlan)
  1825. {
  1826. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1827. }
  1828. static int ieee80211_resume(struct wiphy *wiphy)
  1829. {
  1830. return __ieee80211_resume(wiphy_priv(wiphy));
  1831. }
  1832. #else
  1833. #define ieee80211_suspend NULL
  1834. #define ieee80211_resume NULL
  1835. #endif
  1836. static int ieee80211_scan(struct wiphy *wiphy,
  1837. struct cfg80211_scan_request *req)
  1838. {
  1839. struct ieee80211_sub_if_data *sdata;
  1840. sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
  1841. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1842. case NL80211_IFTYPE_STATION:
  1843. case NL80211_IFTYPE_ADHOC:
  1844. case NL80211_IFTYPE_MESH_POINT:
  1845. case NL80211_IFTYPE_P2P_CLIENT:
  1846. case NL80211_IFTYPE_P2P_DEVICE:
  1847. break;
  1848. case NL80211_IFTYPE_P2P_GO:
  1849. if (sdata->local->ops->hw_scan)
  1850. break;
  1851. /*
  1852. * FIXME: implement NoA while scanning in software,
  1853. * for now fall through to allow scanning only when
  1854. * beaconing hasn't been configured yet
  1855. */
  1856. /* fall through */
  1857. case NL80211_IFTYPE_AP:
  1858. /*
  1859. * If the scan has been forced (and the driver supports
  1860. * forcing), don't care about being beaconing already.
  1861. * This will create problems to the attached stations (e.g. all
  1862. * the frames sent while scanning on other channel will be
  1863. * lost)
  1864. */
  1865. if (sdata->u.ap.beacon &&
  1866. (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
  1867. !(req->flags & NL80211_SCAN_FLAG_AP)))
  1868. return -EOPNOTSUPP;
  1869. break;
  1870. case NL80211_IFTYPE_NAN:
  1871. default:
  1872. return -EOPNOTSUPP;
  1873. }
  1874. return ieee80211_request_scan(sdata, req);
  1875. }
  1876. static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
  1877. {
  1878. ieee80211_scan_cancel(wiphy_priv(wiphy));
  1879. }
  1880. static int
  1881. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1882. struct net_device *dev,
  1883. struct cfg80211_sched_scan_request *req)
  1884. {
  1885. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1886. if (!sdata->local->ops->sched_scan_start)
  1887. return -EOPNOTSUPP;
  1888. return ieee80211_request_sched_scan_start(sdata, req);
  1889. }
  1890. static int
  1891. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
  1892. u64 reqid)
  1893. {
  1894. struct ieee80211_local *local = wiphy_priv(wiphy);
  1895. if (!local->ops->sched_scan_stop)
  1896. return -EOPNOTSUPP;
  1897. return ieee80211_request_sched_scan_stop(local);
  1898. }
  1899. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1900. struct cfg80211_auth_request *req)
  1901. {
  1902. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1903. }
  1904. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1905. struct cfg80211_assoc_request *req)
  1906. {
  1907. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1908. }
  1909. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1910. struct cfg80211_deauth_request *req)
  1911. {
  1912. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1913. }
  1914. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1915. struct cfg80211_disassoc_request *req)
  1916. {
  1917. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1918. }
  1919. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1920. struct cfg80211_ibss_params *params)
  1921. {
  1922. return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
  1923. }
  1924. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1925. {
  1926. return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1927. }
  1928. static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
  1929. struct ocb_setup *setup)
  1930. {
  1931. return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
  1932. }
  1933. static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
  1934. {
  1935. return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1936. }
  1937. static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
  1938. int rate[NUM_NL80211_BANDS])
  1939. {
  1940. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1941. memcpy(sdata->vif.bss_conf.mcast_rate, rate,
  1942. sizeof(int) * NUM_NL80211_BANDS);
  1943. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
  1944. return 0;
  1945. }
  1946. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1947. {
  1948. struct ieee80211_local *local = wiphy_priv(wiphy);
  1949. int err;
  1950. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1951. ieee80211_check_fast_xmit_all(local);
  1952. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1953. if (err) {
  1954. ieee80211_check_fast_xmit_all(local);
  1955. return err;
  1956. }
  1957. }
  1958. if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
  1959. (changed & WIPHY_PARAM_DYN_ACK)) {
  1960. s16 coverage_class;
  1961. coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
  1962. wiphy->coverage_class : -1;
  1963. err = drv_set_coverage_class(local, coverage_class);
  1964. if (err)
  1965. return err;
  1966. }
  1967. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1968. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1969. if (err)
  1970. return err;
  1971. }
  1972. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  1973. if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
  1974. return -EINVAL;
  1975. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1976. }
  1977. if (changed & WIPHY_PARAM_RETRY_LONG) {
  1978. if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
  1979. return -EINVAL;
  1980. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1981. }
  1982. if (changed &
  1983. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1984. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1985. if (changed & (WIPHY_PARAM_TXQ_LIMIT |
  1986. WIPHY_PARAM_TXQ_MEMORY_LIMIT |
  1987. WIPHY_PARAM_TXQ_QUANTUM))
  1988. ieee80211_txq_set_params(local);
  1989. return 0;
  1990. }
  1991. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1992. struct wireless_dev *wdev,
  1993. enum nl80211_tx_power_setting type, int mbm)
  1994. {
  1995. struct ieee80211_local *local = wiphy_priv(wiphy);
  1996. struct ieee80211_sub_if_data *sdata;
  1997. enum nl80211_tx_power_setting txp_type = type;
  1998. bool update_txp_type = false;
  1999. bool has_monitor = false;
  2000. if (wdev) {
  2001. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2002. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2003. sdata = rtnl_dereference(local->monitor_sdata);
  2004. if (!sdata)
  2005. return -EOPNOTSUPP;
  2006. }
  2007. switch (type) {
  2008. case NL80211_TX_POWER_AUTOMATIC:
  2009. sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  2010. txp_type = NL80211_TX_POWER_LIMITED;
  2011. break;
  2012. case NL80211_TX_POWER_LIMITED:
  2013. case NL80211_TX_POWER_FIXED:
  2014. if (mbm < 0 || (mbm % 100))
  2015. return -EOPNOTSUPP;
  2016. sdata->user_power_level = MBM_TO_DBM(mbm);
  2017. break;
  2018. }
  2019. if (txp_type != sdata->vif.bss_conf.txpower_type) {
  2020. update_txp_type = true;
  2021. sdata->vif.bss_conf.txpower_type = txp_type;
  2022. }
  2023. ieee80211_recalc_txpower(sdata, update_txp_type);
  2024. return 0;
  2025. }
  2026. switch (type) {
  2027. case NL80211_TX_POWER_AUTOMATIC:
  2028. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  2029. txp_type = NL80211_TX_POWER_LIMITED;
  2030. break;
  2031. case NL80211_TX_POWER_LIMITED:
  2032. case NL80211_TX_POWER_FIXED:
  2033. if (mbm < 0 || (mbm % 100))
  2034. return -EOPNOTSUPP;
  2035. local->user_power_level = MBM_TO_DBM(mbm);
  2036. break;
  2037. }
  2038. mutex_lock(&local->iflist_mtx);
  2039. list_for_each_entry(sdata, &local->interfaces, list) {
  2040. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2041. has_monitor = true;
  2042. continue;
  2043. }
  2044. sdata->user_power_level = local->user_power_level;
  2045. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2046. update_txp_type = true;
  2047. sdata->vif.bss_conf.txpower_type = txp_type;
  2048. }
  2049. list_for_each_entry(sdata, &local->interfaces, list) {
  2050. if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
  2051. continue;
  2052. ieee80211_recalc_txpower(sdata, update_txp_type);
  2053. }
  2054. mutex_unlock(&local->iflist_mtx);
  2055. if (has_monitor) {
  2056. sdata = rtnl_dereference(local->monitor_sdata);
  2057. if (sdata) {
  2058. sdata->user_power_level = local->user_power_level;
  2059. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2060. update_txp_type = true;
  2061. sdata->vif.bss_conf.txpower_type = txp_type;
  2062. ieee80211_recalc_txpower(sdata, update_txp_type);
  2063. }
  2064. }
  2065. return 0;
  2066. }
  2067. static int ieee80211_get_tx_power(struct wiphy *wiphy,
  2068. struct wireless_dev *wdev,
  2069. int *dbm)
  2070. {
  2071. struct ieee80211_local *local = wiphy_priv(wiphy);
  2072. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2073. if (local->ops->get_txpower)
  2074. return drv_get_txpower(local, sdata, dbm);
  2075. if (!local->use_chanctx)
  2076. *dbm = local->hw.conf.power_level;
  2077. else
  2078. *dbm = sdata->vif.bss_conf.txpower;
  2079. return 0;
  2080. }
  2081. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  2082. const u8 *addr)
  2083. {
  2084. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2085. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  2086. return 0;
  2087. }
  2088. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  2089. {
  2090. struct ieee80211_local *local = wiphy_priv(wiphy);
  2091. drv_rfkill_poll(local);
  2092. }
  2093. #ifdef CONFIG_NL80211_TESTMODE
  2094. static int ieee80211_testmode_cmd(struct wiphy *wiphy,
  2095. struct wireless_dev *wdev,
  2096. void *data, int len)
  2097. {
  2098. struct ieee80211_local *local = wiphy_priv(wiphy);
  2099. struct ieee80211_vif *vif = NULL;
  2100. if (!local->ops->testmode_cmd)
  2101. return -EOPNOTSUPP;
  2102. if (wdev) {
  2103. struct ieee80211_sub_if_data *sdata;
  2104. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2105. if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
  2106. vif = &sdata->vif;
  2107. }
  2108. return local->ops->testmode_cmd(&local->hw, vif, data, len);
  2109. }
  2110. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  2111. struct sk_buff *skb,
  2112. struct netlink_callback *cb,
  2113. void *data, int len)
  2114. {
  2115. struct ieee80211_local *local = wiphy_priv(wiphy);
  2116. if (!local->ops->testmode_dump)
  2117. return -EOPNOTSUPP;
  2118. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  2119. }
  2120. #endif
  2121. int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
  2122. enum ieee80211_smps_mode smps_mode)
  2123. {
  2124. struct sta_info *sta;
  2125. enum ieee80211_smps_mode old_req;
  2126. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
  2127. return -EINVAL;
  2128. if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2129. return 0;
  2130. old_req = sdata->u.ap.req_smps;
  2131. sdata->u.ap.req_smps = smps_mode;
  2132. /* AUTOMATIC doesn't mean much for AP - don't allow it */
  2133. if (old_req == smps_mode ||
  2134. smps_mode == IEEE80211_SMPS_AUTOMATIC)
  2135. return 0;
  2136. ht_dbg(sdata,
  2137. "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
  2138. smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
  2139. mutex_lock(&sdata->local->sta_mtx);
  2140. list_for_each_entry(sta, &sdata->local->sta_list, list) {
  2141. /*
  2142. * Only stations associated to our AP and
  2143. * associated VLANs
  2144. */
  2145. if (sta->sdata->bss != &sdata->u.ap)
  2146. continue;
  2147. /* This station doesn't support MIMO - skip it */
  2148. if (sta_info_tx_streams(sta) == 1)
  2149. continue;
  2150. /*
  2151. * Don't wake up a STA just to send the action frame
  2152. * unless we are getting more restrictive.
  2153. */
  2154. if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
  2155. !ieee80211_smps_is_restrictive(sta->known_smps_mode,
  2156. smps_mode)) {
  2157. ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
  2158. sta->sta.addr);
  2159. continue;
  2160. }
  2161. /*
  2162. * If the STA is not authorized, wait until it gets
  2163. * authorized and the action frame will be sent then.
  2164. */
  2165. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2166. continue;
  2167. ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
  2168. ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
  2169. sdata->vif.bss_conf.bssid);
  2170. }
  2171. mutex_unlock(&sdata->local->sta_mtx);
  2172. sdata->smps_mode = smps_mode;
  2173. ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
  2174. return 0;
  2175. }
  2176. int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
  2177. enum ieee80211_smps_mode smps_mode)
  2178. {
  2179. const u8 *ap;
  2180. enum ieee80211_smps_mode old_req;
  2181. int err;
  2182. struct sta_info *sta;
  2183. bool tdls_peer_found = false;
  2184. lockdep_assert_held(&sdata->wdev.mtx);
  2185. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
  2186. return -EINVAL;
  2187. old_req = sdata->u.mgd.req_smps;
  2188. sdata->u.mgd.req_smps = smps_mode;
  2189. if (old_req == smps_mode &&
  2190. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  2191. return 0;
  2192. /*
  2193. * If not associated, or current association is not an HT
  2194. * association, there's no need to do anything, just store
  2195. * the new value until we associate.
  2196. */
  2197. if (!sdata->u.mgd.associated ||
  2198. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2199. return 0;
  2200. ap = sdata->u.mgd.associated->bssid;
  2201. rcu_read_lock();
  2202. list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
  2203. if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
  2204. !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2205. continue;
  2206. tdls_peer_found = true;
  2207. break;
  2208. }
  2209. rcu_read_unlock();
  2210. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  2211. if (tdls_peer_found || !sdata->u.mgd.powersave)
  2212. smps_mode = IEEE80211_SMPS_OFF;
  2213. else
  2214. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2215. }
  2216. /* send SM PS frame to AP */
  2217. err = ieee80211_send_smps_action(sdata, smps_mode,
  2218. ap, ap);
  2219. if (err)
  2220. sdata->u.mgd.req_smps = old_req;
  2221. else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
  2222. ieee80211_teardown_tdls_peers(sdata);
  2223. return err;
  2224. }
  2225. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2226. bool enabled, int timeout)
  2227. {
  2228. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2229. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2230. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2231. return -EOPNOTSUPP;
  2232. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
  2233. return -EOPNOTSUPP;
  2234. if (enabled == sdata->u.mgd.powersave &&
  2235. timeout == local->dynamic_ps_forced_timeout)
  2236. return 0;
  2237. sdata->u.mgd.powersave = enabled;
  2238. local->dynamic_ps_forced_timeout = timeout;
  2239. /* no change, but if automatic follow powersave */
  2240. sdata_lock(sdata);
  2241. __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
  2242. sdata_unlock(sdata);
  2243. if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  2244. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2245. ieee80211_recalc_ps(local);
  2246. ieee80211_recalc_ps_vif(sdata);
  2247. ieee80211_check_fast_rx_iface(sdata);
  2248. return 0;
  2249. }
  2250. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  2251. struct net_device *dev,
  2252. s32 rssi_thold, u32 rssi_hyst)
  2253. {
  2254. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2255. struct ieee80211_vif *vif = &sdata->vif;
  2256. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  2257. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  2258. rssi_hyst == bss_conf->cqm_rssi_hyst)
  2259. return 0;
  2260. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
  2261. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
  2262. return -EOPNOTSUPP;
  2263. bss_conf->cqm_rssi_thold = rssi_thold;
  2264. bss_conf->cqm_rssi_hyst = rssi_hyst;
  2265. bss_conf->cqm_rssi_low = 0;
  2266. bss_conf->cqm_rssi_high = 0;
  2267. sdata->u.mgd.last_cqm_event_signal = 0;
  2268. /* tell the driver upon association, unless already associated */
  2269. if (sdata->u.mgd.associated &&
  2270. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  2271. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  2272. return 0;
  2273. }
  2274. static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
  2275. struct net_device *dev,
  2276. s32 rssi_low, s32 rssi_high)
  2277. {
  2278. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2279. struct ieee80211_vif *vif = &sdata->vif;
  2280. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  2281. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  2282. return -EOPNOTSUPP;
  2283. bss_conf->cqm_rssi_low = rssi_low;
  2284. bss_conf->cqm_rssi_high = rssi_high;
  2285. bss_conf->cqm_rssi_thold = 0;
  2286. bss_conf->cqm_rssi_hyst = 0;
  2287. sdata->u.mgd.last_cqm_event_signal = 0;
  2288. /* tell the driver upon association, unless already associated */
  2289. if (sdata->u.mgd.associated &&
  2290. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  2291. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  2292. return 0;
  2293. }
  2294. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  2295. struct net_device *dev,
  2296. const u8 *addr,
  2297. const struct cfg80211_bitrate_mask *mask)
  2298. {
  2299. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2300. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2301. int i, ret;
  2302. if (!ieee80211_sdata_running(sdata))
  2303. return -ENETDOWN;
  2304. /*
  2305. * If active validate the setting and reject it if it doesn't leave
  2306. * at least one basic rate usable, since we really have to be able
  2307. * to send something, and if we're an AP we have to be able to do
  2308. * so at a basic rate so that all clients can receive it.
  2309. */
  2310. if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
  2311. sdata->vif.bss_conf.chandef.chan) {
  2312. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  2313. enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
  2314. if (!(mask->control[band].legacy & basic_rates))
  2315. return -EINVAL;
  2316. }
  2317. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
  2318. ret = drv_set_bitrate_mask(local, sdata, mask);
  2319. if (ret)
  2320. return ret;
  2321. }
  2322. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  2323. struct ieee80211_supported_band *sband = wiphy->bands[i];
  2324. int j;
  2325. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  2326. memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
  2327. sizeof(mask->control[i].ht_mcs));
  2328. memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
  2329. mask->control[i].vht_mcs,
  2330. sizeof(mask->control[i].vht_mcs));
  2331. sdata->rc_has_mcs_mask[i] = false;
  2332. sdata->rc_has_vht_mcs_mask[i] = false;
  2333. if (!sband)
  2334. continue;
  2335. for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
  2336. if (~sdata->rc_rateidx_mcs_mask[i][j]) {
  2337. sdata->rc_has_mcs_mask[i] = true;
  2338. break;
  2339. }
  2340. }
  2341. for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
  2342. if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
  2343. sdata->rc_has_vht_mcs_mask[i] = true;
  2344. break;
  2345. }
  2346. }
  2347. }
  2348. return 0;
  2349. }
  2350. static int ieee80211_start_radar_detection(struct wiphy *wiphy,
  2351. struct net_device *dev,
  2352. struct cfg80211_chan_def *chandef,
  2353. u32 cac_time_ms)
  2354. {
  2355. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2356. struct ieee80211_local *local = sdata->local;
  2357. int err;
  2358. mutex_lock(&local->mtx);
  2359. if (!list_empty(&local->roc_list) || local->scanning) {
  2360. err = -EBUSY;
  2361. goto out_unlock;
  2362. }
  2363. /* whatever, but channel contexts should not complain about that one */
  2364. sdata->smps_mode = IEEE80211_SMPS_OFF;
  2365. sdata->needed_rx_chains = local->rx_chains;
  2366. err = ieee80211_vif_use_channel(sdata, chandef,
  2367. IEEE80211_CHANCTX_SHARED);
  2368. if (err)
  2369. goto out_unlock;
  2370. ieee80211_queue_delayed_work(&sdata->local->hw,
  2371. &sdata->dfs_cac_timer_work,
  2372. msecs_to_jiffies(cac_time_ms));
  2373. out_unlock:
  2374. mutex_unlock(&local->mtx);
  2375. return err;
  2376. }
  2377. static struct cfg80211_beacon_data *
  2378. cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
  2379. {
  2380. struct cfg80211_beacon_data *new_beacon;
  2381. u8 *pos;
  2382. int len;
  2383. len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
  2384. beacon->proberesp_ies_len + beacon->assocresp_ies_len +
  2385. beacon->probe_resp_len;
  2386. new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
  2387. if (!new_beacon)
  2388. return NULL;
  2389. pos = (u8 *)(new_beacon + 1);
  2390. if (beacon->head_len) {
  2391. new_beacon->head_len = beacon->head_len;
  2392. new_beacon->head = pos;
  2393. memcpy(pos, beacon->head, beacon->head_len);
  2394. pos += beacon->head_len;
  2395. }
  2396. if (beacon->tail_len) {
  2397. new_beacon->tail_len = beacon->tail_len;
  2398. new_beacon->tail = pos;
  2399. memcpy(pos, beacon->tail, beacon->tail_len);
  2400. pos += beacon->tail_len;
  2401. }
  2402. if (beacon->beacon_ies_len) {
  2403. new_beacon->beacon_ies_len = beacon->beacon_ies_len;
  2404. new_beacon->beacon_ies = pos;
  2405. memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
  2406. pos += beacon->beacon_ies_len;
  2407. }
  2408. if (beacon->proberesp_ies_len) {
  2409. new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
  2410. new_beacon->proberesp_ies = pos;
  2411. memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
  2412. pos += beacon->proberesp_ies_len;
  2413. }
  2414. if (beacon->assocresp_ies_len) {
  2415. new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
  2416. new_beacon->assocresp_ies = pos;
  2417. memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
  2418. pos += beacon->assocresp_ies_len;
  2419. }
  2420. if (beacon->probe_resp_len) {
  2421. new_beacon->probe_resp_len = beacon->probe_resp_len;
  2422. new_beacon->probe_resp = pos;
  2423. memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
  2424. pos += beacon->probe_resp_len;
  2425. }
  2426. return new_beacon;
  2427. }
  2428. void ieee80211_csa_finish(struct ieee80211_vif *vif)
  2429. {
  2430. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2431. ieee80211_queue_work(&sdata->local->hw,
  2432. &sdata->csa_finalize_work);
  2433. }
  2434. EXPORT_SYMBOL(ieee80211_csa_finish);
  2435. static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
  2436. u32 *changed)
  2437. {
  2438. int err;
  2439. switch (sdata->vif.type) {
  2440. case NL80211_IFTYPE_AP:
  2441. err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
  2442. NULL);
  2443. kfree(sdata->u.ap.next_beacon);
  2444. sdata->u.ap.next_beacon = NULL;
  2445. if (err < 0)
  2446. return err;
  2447. *changed |= err;
  2448. break;
  2449. case NL80211_IFTYPE_ADHOC:
  2450. err = ieee80211_ibss_finish_csa(sdata);
  2451. if (err < 0)
  2452. return err;
  2453. *changed |= err;
  2454. break;
  2455. #ifdef CONFIG_MAC80211_MESH
  2456. case NL80211_IFTYPE_MESH_POINT:
  2457. err = ieee80211_mesh_finish_csa(sdata);
  2458. if (err < 0)
  2459. return err;
  2460. *changed |= err;
  2461. break;
  2462. #endif
  2463. default:
  2464. WARN_ON(1);
  2465. return -EINVAL;
  2466. }
  2467. return 0;
  2468. }
  2469. static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
  2470. {
  2471. struct ieee80211_local *local = sdata->local;
  2472. u32 changed = 0;
  2473. int err;
  2474. sdata_assert_lock(sdata);
  2475. lockdep_assert_held(&local->mtx);
  2476. lockdep_assert_held(&local->chanctx_mtx);
  2477. /*
  2478. * using reservation isn't immediate as it may be deferred until later
  2479. * with multi-vif. once reservation is complete it will re-schedule the
  2480. * work with no reserved_chanctx so verify chandef to check if it
  2481. * completed successfully
  2482. */
  2483. if (sdata->reserved_chanctx) {
  2484. /*
  2485. * with multi-vif csa driver may call ieee80211_csa_finish()
  2486. * many times while waiting for other interfaces to use their
  2487. * reservations
  2488. */
  2489. if (sdata->reserved_ready)
  2490. return 0;
  2491. return ieee80211_vif_use_reserved_context(sdata);
  2492. }
  2493. if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
  2494. &sdata->csa_chandef))
  2495. return -EINVAL;
  2496. sdata->vif.csa_active = false;
  2497. err = ieee80211_set_after_csa_beacon(sdata, &changed);
  2498. if (err)
  2499. return err;
  2500. ieee80211_bss_info_change_notify(sdata, changed);
  2501. if (sdata->csa_block_tx) {
  2502. ieee80211_wake_vif_queues(local, sdata,
  2503. IEEE80211_QUEUE_STOP_REASON_CSA);
  2504. sdata->csa_block_tx = false;
  2505. }
  2506. err = drv_post_channel_switch(sdata);
  2507. if (err)
  2508. return err;
  2509. cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
  2510. return 0;
  2511. }
  2512. static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
  2513. {
  2514. if (__ieee80211_csa_finalize(sdata)) {
  2515. sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
  2516. cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
  2517. GFP_KERNEL);
  2518. }
  2519. }
  2520. void ieee80211_csa_finalize_work(struct work_struct *work)
  2521. {
  2522. struct ieee80211_sub_if_data *sdata =
  2523. container_of(work, struct ieee80211_sub_if_data,
  2524. csa_finalize_work);
  2525. struct ieee80211_local *local = sdata->local;
  2526. sdata_lock(sdata);
  2527. mutex_lock(&local->mtx);
  2528. mutex_lock(&local->chanctx_mtx);
  2529. /* AP might have been stopped while waiting for the lock. */
  2530. if (!sdata->vif.csa_active)
  2531. goto unlock;
  2532. if (!ieee80211_sdata_running(sdata))
  2533. goto unlock;
  2534. ieee80211_csa_finalize(sdata);
  2535. unlock:
  2536. mutex_unlock(&local->chanctx_mtx);
  2537. mutex_unlock(&local->mtx);
  2538. sdata_unlock(sdata);
  2539. }
  2540. static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
  2541. struct cfg80211_csa_settings *params,
  2542. u32 *changed)
  2543. {
  2544. struct ieee80211_csa_settings csa = {};
  2545. int err;
  2546. switch (sdata->vif.type) {
  2547. case NL80211_IFTYPE_AP:
  2548. sdata->u.ap.next_beacon =
  2549. cfg80211_beacon_dup(&params->beacon_after);
  2550. if (!sdata->u.ap.next_beacon)
  2551. return -ENOMEM;
  2552. /*
  2553. * With a count of 0, we don't have to wait for any
  2554. * TBTT before switching, so complete the CSA
  2555. * immediately. In theory, with a count == 1 we
  2556. * should delay the switch until just before the next
  2557. * TBTT, but that would complicate things so we switch
  2558. * immediately too. If we would delay the switch
  2559. * until the next TBTT, we would have to set the probe
  2560. * response here.
  2561. *
  2562. * TODO: A channel switch with count <= 1 without
  2563. * sending a CSA action frame is kind of useless,
  2564. * because the clients won't know we're changing
  2565. * channels. The action frame must be implemented
  2566. * either here or in the userspace.
  2567. */
  2568. if (params->count <= 1)
  2569. break;
  2570. if ((params->n_counter_offsets_beacon >
  2571. IEEE80211_MAX_CSA_COUNTERS_NUM) ||
  2572. (params->n_counter_offsets_presp >
  2573. IEEE80211_MAX_CSA_COUNTERS_NUM))
  2574. return -EINVAL;
  2575. csa.counter_offsets_beacon = params->counter_offsets_beacon;
  2576. csa.counter_offsets_presp = params->counter_offsets_presp;
  2577. csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
  2578. csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
  2579. csa.count = params->count;
  2580. err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
  2581. if (err < 0) {
  2582. kfree(sdata->u.ap.next_beacon);
  2583. return err;
  2584. }
  2585. *changed |= err;
  2586. break;
  2587. case NL80211_IFTYPE_ADHOC:
  2588. if (!sdata->vif.bss_conf.ibss_joined)
  2589. return -EINVAL;
  2590. if (params->chandef.width != sdata->u.ibss.chandef.width)
  2591. return -EINVAL;
  2592. switch (params->chandef.width) {
  2593. case NL80211_CHAN_WIDTH_40:
  2594. if (cfg80211_get_chandef_type(&params->chandef) !=
  2595. cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
  2596. return -EINVAL;
  2597. case NL80211_CHAN_WIDTH_5:
  2598. case NL80211_CHAN_WIDTH_10:
  2599. case NL80211_CHAN_WIDTH_20_NOHT:
  2600. case NL80211_CHAN_WIDTH_20:
  2601. break;
  2602. default:
  2603. return -EINVAL;
  2604. }
  2605. /* changes into another band are not supported */
  2606. if (sdata->u.ibss.chandef.chan->band !=
  2607. params->chandef.chan->band)
  2608. return -EINVAL;
  2609. /* see comments in the NL80211_IFTYPE_AP block */
  2610. if (params->count > 1) {
  2611. err = ieee80211_ibss_csa_beacon(sdata, params);
  2612. if (err < 0)
  2613. return err;
  2614. *changed |= err;
  2615. }
  2616. ieee80211_send_action_csa(sdata, params);
  2617. break;
  2618. #ifdef CONFIG_MAC80211_MESH
  2619. case NL80211_IFTYPE_MESH_POINT: {
  2620. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2621. if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
  2622. return -EINVAL;
  2623. /* changes into another band are not supported */
  2624. if (sdata->vif.bss_conf.chandef.chan->band !=
  2625. params->chandef.chan->band)
  2626. return -EINVAL;
  2627. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
  2628. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
  2629. if (!ifmsh->pre_value)
  2630. ifmsh->pre_value = 1;
  2631. else
  2632. ifmsh->pre_value++;
  2633. }
  2634. /* see comments in the NL80211_IFTYPE_AP block */
  2635. if (params->count > 1) {
  2636. err = ieee80211_mesh_csa_beacon(sdata, params);
  2637. if (err < 0) {
  2638. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
  2639. return err;
  2640. }
  2641. *changed |= err;
  2642. }
  2643. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
  2644. ieee80211_send_action_csa(sdata, params);
  2645. break;
  2646. }
  2647. #endif
  2648. default:
  2649. return -EOPNOTSUPP;
  2650. }
  2651. return 0;
  2652. }
  2653. static int
  2654. __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  2655. struct cfg80211_csa_settings *params)
  2656. {
  2657. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2658. struct ieee80211_local *local = sdata->local;
  2659. struct ieee80211_channel_switch ch_switch;
  2660. struct ieee80211_chanctx_conf *conf;
  2661. struct ieee80211_chanctx *chanctx;
  2662. u32 changed = 0;
  2663. int err;
  2664. sdata_assert_lock(sdata);
  2665. lockdep_assert_held(&local->mtx);
  2666. if (!list_empty(&local->roc_list) || local->scanning)
  2667. return -EBUSY;
  2668. if (sdata->wdev.cac_started)
  2669. return -EBUSY;
  2670. if (cfg80211_chandef_identical(&params->chandef,
  2671. &sdata->vif.bss_conf.chandef))
  2672. return -EINVAL;
  2673. /* don't allow another channel switch if one is already active. */
  2674. if (sdata->vif.csa_active)
  2675. return -EBUSY;
  2676. mutex_lock(&local->chanctx_mtx);
  2677. conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  2678. lockdep_is_held(&local->chanctx_mtx));
  2679. if (!conf) {
  2680. err = -EBUSY;
  2681. goto out;
  2682. }
  2683. chanctx = container_of(conf, struct ieee80211_chanctx, conf);
  2684. ch_switch.timestamp = 0;
  2685. ch_switch.device_timestamp = 0;
  2686. ch_switch.block_tx = params->block_tx;
  2687. ch_switch.chandef = params->chandef;
  2688. ch_switch.count = params->count;
  2689. err = drv_pre_channel_switch(sdata, &ch_switch);
  2690. if (err)
  2691. goto out;
  2692. err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
  2693. chanctx->mode,
  2694. params->radar_required);
  2695. if (err)
  2696. goto out;
  2697. /* if reservation is invalid then this will fail */
  2698. err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
  2699. if (err) {
  2700. ieee80211_vif_unreserve_chanctx(sdata);
  2701. goto out;
  2702. }
  2703. err = ieee80211_set_csa_beacon(sdata, params, &changed);
  2704. if (err) {
  2705. ieee80211_vif_unreserve_chanctx(sdata);
  2706. goto out;
  2707. }
  2708. sdata->csa_chandef = params->chandef;
  2709. sdata->csa_block_tx = params->block_tx;
  2710. sdata->vif.csa_active = true;
  2711. if (sdata->csa_block_tx)
  2712. ieee80211_stop_vif_queues(local, sdata,
  2713. IEEE80211_QUEUE_STOP_REASON_CSA);
  2714. cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
  2715. params->count);
  2716. if (changed) {
  2717. ieee80211_bss_info_change_notify(sdata, changed);
  2718. drv_channel_switch_beacon(sdata, &params->chandef);
  2719. } else {
  2720. /* if the beacon didn't change, we can finalize immediately */
  2721. ieee80211_csa_finalize(sdata);
  2722. }
  2723. out:
  2724. mutex_unlock(&local->chanctx_mtx);
  2725. return err;
  2726. }
  2727. int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  2728. struct cfg80211_csa_settings *params)
  2729. {
  2730. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2731. struct ieee80211_local *local = sdata->local;
  2732. int err;
  2733. mutex_lock(&local->mtx);
  2734. err = __ieee80211_channel_switch(wiphy, dev, params);
  2735. mutex_unlock(&local->mtx);
  2736. return err;
  2737. }
  2738. u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
  2739. {
  2740. lockdep_assert_held(&local->mtx);
  2741. local->roc_cookie_counter++;
  2742. /* wow, you wrapped 64 bits ... more likely a bug */
  2743. if (WARN_ON(local->roc_cookie_counter == 0))
  2744. local->roc_cookie_counter++;
  2745. return local->roc_cookie_counter;
  2746. }
  2747. int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
  2748. u64 *cookie, gfp_t gfp)
  2749. {
  2750. unsigned long spin_flags;
  2751. struct sk_buff *ack_skb;
  2752. int id;
  2753. ack_skb = skb_copy(skb, gfp);
  2754. if (!ack_skb)
  2755. return -ENOMEM;
  2756. spin_lock_irqsave(&local->ack_status_lock, spin_flags);
  2757. id = idr_alloc(&local->ack_status_frames, ack_skb,
  2758. 1, 0x10000, GFP_ATOMIC);
  2759. spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
  2760. if (id < 0) {
  2761. kfree_skb(ack_skb);
  2762. return -ENOMEM;
  2763. }
  2764. IEEE80211_SKB_CB(skb)->ack_frame_id = id;
  2765. *cookie = ieee80211_mgmt_tx_cookie(local);
  2766. IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
  2767. return 0;
  2768. }
  2769. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  2770. struct wireless_dev *wdev,
  2771. u16 frame_type, bool reg)
  2772. {
  2773. struct ieee80211_local *local = wiphy_priv(wiphy);
  2774. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2775. switch (frame_type) {
  2776. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
  2777. if (reg) {
  2778. local->probe_req_reg++;
  2779. sdata->vif.probe_req_reg++;
  2780. } else {
  2781. if (local->probe_req_reg)
  2782. local->probe_req_reg--;
  2783. if (sdata->vif.probe_req_reg)
  2784. sdata->vif.probe_req_reg--;
  2785. }
  2786. if (!local->open_count)
  2787. break;
  2788. if (sdata->vif.probe_req_reg == 1)
  2789. drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
  2790. FIF_PROBE_REQ);
  2791. else if (sdata->vif.probe_req_reg == 0)
  2792. drv_config_iface_filter(local, sdata, 0,
  2793. FIF_PROBE_REQ);
  2794. ieee80211_configure_filter(local);
  2795. break;
  2796. default:
  2797. break;
  2798. }
  2799. }
  2800. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  2801. {
  2802. struct ieee80211_local *local = wiphy_priv(wiphy);
  2803. if (local->started)
  2804. return -EOPNOTSUPP;
  2805. return drv_set_antenna(local, tx_ant, rx_ant);
  2806. }
  2807. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  2808. {
  2809. struct ieee80211_local *local = wiphy_priv(wiphy);
  2810. return drv_get_antenna(local, tx_ant, rx_ant);
  2811. }
  2812. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  2813. struct net_device *dev,
  2814. struct cfg80211_gtk_rekey_data *data)
  2815. {
  2816. struct ieee80211_local *local = wiphy_priv(wiphy);
  2817. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2818. if (!local->ops->set_rekey_data)
  2819. return -EOPNOTSUPP;
  2820. drv_set_rekey_data(local, sdata, data);
  2821. return 0;
  2822. }
  2823. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2824. const u8 *peer, u64 *cookie)
  2825. {
  2826. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2827. struct ieee80211_local *local = sdata->local;
  2828. struct ieee80211_qos_hdr *nullfunc;
  2829. struct sk_buff *skb;
  2830. int size = sizeof(*nullfunc);
  2831. __le16 fc;
  2832. bool qos;
  2833. struct ieee80211_tx_info *info;
  2834. struct sta_info *sta;
  2835. struct ieee80211_chanctx_conf *chanctx_conf;
  2836. enum nl80211_band band;
  2837. int ret;
  2838. /* the lock is needed to assign the cookie later */
  2839. mutex_lock(&local->mtx);
  2840. rcu_read_lock();
  2841. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2842. if (WARN_ON(!chanctx_conf)) {
  2843. ret = -EINVAL;
  2844. goto unlock;
  2845. }
  2846. band = chanctx_conf->def.chan->band;
  2847. sta = sta_info_get_bss(sdata, peer);
  2848. if (sta) {
  2849. qos = sta->sta.wme;
  2850. } else {
  2851. ret = -ENOLINK;
  2852. goto unlock;
  2853. }
  2854. if (qos) {
  2855. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2856. IEEE80211_STYPE_QOS_NULLFUNC |
  2857. IEEE80211_FCTL_FROMDS);
  2858. } else {
  2859. size -= 2;
  2860. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2861. IEEE80211_STYPE_NULLFUNC |
  2862. IEEE80211_FCTL_FROMDS);
  2863. }
  2864. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2865. if (!skb) {
  2866. ret = -ENOMEM;
  2867. goto unlock;
  2868. }
  2869. skb->dev = dev;
  2870. skb_reserve(skb, local->hw.extra_tx_headroom);
  2871. nullfunc = skb_put(skb, size);
  2872. nullfunc->frame_control = fc;
  2873. nullfunc->duration_id = 0;
  2874. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2875. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2876. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2877. nullfunc->seq_ctrl = 0;
  2878. info = IEEE80211_SKB_CB(skb);
  2879. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2880. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2881. info->band = band;
  2882. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2883. skb->priority = 7;
  2884. if (qos)
  2885. nullfunc->qos_ctrl = cpu_to_le16(7);
  2886. ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
  2887. if (ret) {
  2888. kfree_skb(skb);
  2889. goto unlock;
  2890. }
  2891. local_bh_disable();
  2892. ieee80211_xmit(sdata, sta, skb, 0);
  2893. local_bh_enable();
  2894. ret = 0;
  2895. unlock:
  2896. rcu_read_unlock();
  2897. mutex_unlock(&local->mtx);
  2898. return ret;
  2899. }
  2900. static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  2901. struct wireless_dev *wdev,
  2902. struct cfg80211_chan_def *chandef)
  2903. {
  2904. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2905. struct ieee80211_local *local = wiphy_priv(wiphy);
  2906. struct ieee80211_chanctx_conf *chanctx_conf;
  2907. int ret = -ENODATA;
  2908. rcu_read_lock();
  2909. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2910. if (chanctx_conf) {
  2911. *chandef = sdata->vif.bss_conf.chandef;
  2912. ret = 0;
  2913. } else if (local->open_count > 0 &&
  2914. local->open_count == local->monitors &&
  2915. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2916. if (local->use_chanctx)
  2917. *chandef = local->monitor_chandef;
  2918. else
  2919. *chandef = local->_oper_chandef;
  2920. ret = 0;
  2921. }
  2922. rcu_read_unlock();
  2923. return ret;
  2924. }
  2925. #ifdef CONFIG_PM
  2926. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  2927. {
  2928. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  2929. }
  2930. #endif
  2931. static int ieee80211_set_qos_map(struct wiphy *wiphy,
  2932. struct net_device *dev,
  2933. struct cfg80211_qos_map *qos_map)
  2934. {
  2935. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2936. struct mac80211_qos_map *new_qos_map, *old_qos_map;
  2937. if (qos_map) {
  2938. new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
  2939. if (!new_qos_map)
  2940. return -ENOMEM;
  2941. memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
  2942. } else {
  2943. /* A NULL qos_map was passed to disable QoS mapping */
  2944. new_qos_map = NULL;
  2945. }
  2946. old_qos_map = sdata_dereference(sdata->qos_map, sdata);
  2947. rcu_assign_pointer(sdata->qos_map, new_qos_map);
  2948. if (old_qos_map)
  2949. kfree_rcu(old_qos_map, rcu_head);
  2950. return 0;
  2951. }
  2952. static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
  2953. struct net_device *dev,
  2954. struct cfg80211_chan_def *chandef)
  2955. {
  2956. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2957. int ret;
  2958. u32 changed = 0;
  2959. ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
  2960. if (ret == 0)
  2961. ieee80211_bss_info_change_notify(sdata, changed);
  2962. return ret;
  2963. }
  2964. static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  2965. u8 tsid, const u8 *peer, u8 up,
  2966. u16 admitted_time)
  2967. {
  2968. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2969. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2970. int ac = ieee802_1d_to_ac[up];
  2971. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2972. return -EOPNOTSUPP;
  2973. if (!(sdata->wmm_acm & BIT(up)))
  2974. return -EINVAL;
  2975. if (ifmgd->tx_tspec[ac].admitted_time)
  2976. return -EBUSY;
  2977. if (admitted_time) {
  2978. ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
  2979. ifmgd->tx_tspec[ac].tsid = tsid;
  2980. ifmgd->tx_tspec[ac].up = up;
  2981. }
  2982. return 0;
  2983. }
  2984. static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  2985. u8 tsid, const u8 *peer)
  2986. {
  2987. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2988. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2989. struct ieee80211_local *local = wiphy_priv(wiphy);
  2990. int ac;
  2991. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  2992. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  2993. /* skip unused entries */
  2994. if (!tx_tspec->admitted_time)
  2995. continue;
  2996. if (tx_tspec->tsid != tsid)
  2997. continue;
  2998. /* due to this new packets will be reassigned to non-ACM ACs */
  2999. tx_tspec->up = -1;
  3000. /* Make sure that all packets have been sent to avoid to
  3001. * restore the QoS params on packets that are still on the
  3002. * queues.
  3003. */
  3004. synchronize_net();
  3005. ieee80211_flush_queues(local, sdata, false);
  3006. /* restore the normal QoS parameters
  3007. * (unconditionally to avoid races)
  3008. */
  3009. tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
  3010. tx_tspec->downgraded = false;
  3011. ieee80211_sta_handle_tspec_ac_params(sdata);
  3012. /* finally clear all the data */
  3013. memset(tx_tspec, 0, sizeof(*tx_tspec));
  3014. return 0;
  3015. }
  3016. return -ENOENT;
  3017. }
  3018. void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
  3019. u8 inst_id,
  3020. enum nl80211_nan_func_term_reason reason,
  3021. gfp_t gfp)
  3022. {
  3023. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3024. struct cfg80211_nan_func *func;
  3025. u64 cookie;
  3026. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  3027. return;
  3028. spin_lock_bh(&sdata->u.nan.func_lock);
  3029. func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
  3030. if (WARN_ON(!func)) {
  3031. spin_unlock_bh(&sdata->u.nan.func_lock);
  3032. return;
  3033. }
  3034. cookie = func->cookie;
  3035. idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
  3036. spin_unlock_bh(&sdata->u.nan.func_lock);
  3037. cfg80211_free_nan_func(func);
  3038. cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
  3039. reason, cookie, gfp);
  3040. }
  3041. EXPORT_SYMBOL(ieee80211_nan_func_terminated);
  3042. void ieee80211_nan_func_match(struct ieee80211_vif *vif,
  3043. struct cfg80211_nan_match_params *match,
  3044. gfp_t gfp)
  3045. {
  3046. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3047. struct cfg80211_nan_func *func;
  3048. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  3049. return;
  3050. spin_lock_bh(&sdata->u.nan.func_lock);
  3051. func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
  3052. if (WARN_ON(!func)) {
  3053. spin_unlock_bh(&sdata->u.nan.func_lock);
  3054. return;
  3055. }
  3056. match->cookie = func->cookie;
  3057. spin_unlock_bh(&sdata->u.nan.func_lock);
  3058. cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
  3059. }
  3060. EXPORT_SYMBOL(ieee80211_nan_func_match);
  3061. static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
  3062. struct net_device *dev,
  3063. const bool enabled)
  3064. {
  3065. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3066. sdata->u.ap.multicast_to_unicast = enabled;
  3067. return 0;
  3068. }
  3069. void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
  3070. struct txq_info *txqi)
  3071. {
  3072. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
  3073. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
  3074. txqstats->backlog_bytes = txqi->tin.backlog_bytes;
  3075. }
  3076. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
  3077. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
  3078. txqstats->backlog_packets = txqi->tin.backlog_packets;
  3079. }
  3080. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
  3081. txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
  3082. txqstats->flows = txqi->tin.flows;
  3083. }
  3084. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
  3085. txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
  3086. txqstats->drops = txqi->cstats.drop_count;
  3087. }
  3088. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
  3089. txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
  3090. txqstats->ecn_marks = txqi->cstats.ecn_mark;
  3091. }
  3092. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
  3093. txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
  3094. txqstats->overlimit = txqi->tin.overlimit;
  3095. }
  3096. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
  3097. txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
  3098. txqstats->collisions = txqi->tin.collisions;
  3099. }
  3100. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
  3101. txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
  3102. txqstats->tx_bytes = txqi->tin.tx_bytes;
  3103. }
  3104. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
  3105. txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
  3106. txqstats->tx_packets = txqi->tin.tx_packets;
  3107. }
  3108. }
  3109. static int ieee80211_get_txq_stats(struct wiphy *wiphy,
  3110. struct wireless_dev *wdev,
  3111. struct cfg80211_txq_stats *txqstats)
  3112. {
  3113. struct ieee80211_local *local = wiphy_priv(wiphy);
  3114. struct ieee80211_sub_if_data *sdata;
  3115. int ret = 0;
  3116. if (!local->ops->wake_tx_queue)
  3117. return 1;
  3118. spin_lock_bh(&local->fq.lock);
  3119. rcu_read_lock();
  3120. if (wdev) {
  3121. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  3122. if (!sdata->vif.txq) {
  3123. ret = 1;
  3124. goto out;
  3125. }
  3126. ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
  3127. } else {
  3128. /* phy stats */
  3129. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
  3130. BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
  3131. BIT(NL80211_TXQ_STATS_OVERLIMIT) |
  3132. BIT(NL80211_TXQ_STATS_OVERMEMORY) |
  3133. BIT(NL80211_TXQ_STATS_COLLISIONS) |
  3134. BIT(NL80211_TXQ_STATS_MAX_FLOWS);
  3135. txqstats->backlog_packets = local->fq.backlog;
  3136. txqstats->backlog_bytes = local->fq.memory_usage;
  3137. txqstats->overlimit = local->fq.overlimit;
  3138. txqstats->overmemory = local->fq.overmemory;
  3139. txqstats->collisions = local->fq.collisions;
  3140. txqstats->max_flows = local->fq.flows_cnt;
  3141. }
  3142. out:
  3143. rcu_read_unlock();
  3144. spin_unlock_bh(&local->fq.lock);
  3145. return ret;
  3146. }
  3147. const struct cfg80211_ops mac80211_config_ops = {
  3148. .add_virtual_intf = ieee80211_add_iface,
  3149. .del_virtual_intf = ieee80211_del_iface,
  3150. .change_virtual_intf = ieee80211_change_iface,
  3151. .start_p2p_device = ieee80211_start_p2p_device,
  3152. .stop_p2p_device = ieee80211_stop_p2p_device,
  3153. .add_key = ieee80211_add_key,
  3154. .del_key = ieee80211_del_key,
  3155. .get_key = ieee80211_get_key,
  3156. .set_default_key = ieee80211_config_default_key,
  3157. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  3158. .start_ap = ieee80211_start_ap,
  3159. .change_beacon = ieee80211_change_beacon,
  3160. .stop_ap = ieee80211_stop_ap,
  3161. .add_station = ieee80211_add_station,
  3162. .del_station = ieee80211_del_station,
  3163. .change_station = ieee80211_change_station,
  3164. .get_station = ieee80211_get_station,
  3165. .dump_station = ieee80211_dump_station,
  3166. .dump_survey = ieee80211_dump_survey,
  3167. #ifdef CONFIG_MAC80211_MESH
  3168. .add_mpath = ieee80211_add_mpath,
  3169. .del_mpath = ieee80211_del_mpath,
  3170. .change_mpath = ieee80211_change_mpath,
  3171. .get_mpath = ieee80211_get_mpath,
  3172. .dump_mpath = ieee80211_dump_mpath,
  3173. .get_mpp = ieee80211_get_mpp,
  3174. .dump_mpp = ieee80211_dump_mpp,
  3175. .update_mesh_config = ieee80211_update_mesh_config,
  3176. .get_mesh_config = ieee80211_get_mesh_config,
  3177. .join_mesh = ieee80211_join_mesh,
  3178. .leave_mesh = ieee80211_leave_mesh,
  3179. #endif
  3180. .join_ocb = ieee80211_join_ocb,
  3181. .leave_ocb = ieee80211_leave_ocb,
  3182. .change_bss = ieee80211_change_bss,
  3183. .set_txq_params = ieee80211_set_txq_params,
  3184. .set_monitor_channel = ieee80211_set_monitor_channel,
  3185. .suspend = ieee80211_suspend,
  3186. .resume = ieee80211_resume,
  3187. .scan = ieee80211_scan,
  3188. .abort_scan = ieee80211_abort_scan,
  3189. .sched_scan_start = ieee80211_sched_scan_start,
  3190. .sched_scan_stop = ieee80211_sched_scan_stop,
  3191. .auth = ieee80211_auth,
  3192. .assoc = ieee80211_assoc,
  3193. .deauth = ieee80211_deauth,
  3194. .disassoc = ieee80211_disassoc,
  3195. .join_ibss = ieee80211_join_ibss,
  3196. .leave_ibss = ieee80211_leave_ibss,
  3197. .set_mcast_rate = ieee80211_set_mcast_rate,
  3198. .set_wiphy_params = ieee80211_set_wiphy_params,
  3199. .set_tx_power = ieee80211_set_tx_power,
  3200. .get_tx_power = ieee80211_get_tx_power,
  3201. .set_wds_peer = ieee80211_set_wds_peer,
  3202. .rfkill_poll = ieee80211_rfkill_poll,
  3203. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  3204. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  3205. .set_power_mgmt = ieee80211_set_power_mgmt,
  3206. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  3207. .remain_on_channel = ieee80211_remain_on_channel,
  3208. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  3209. .mgmt_tx = ieee80211_mgmt_tx,
  3210. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  3211. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  3212. .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
  3213. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  3214. .set_antenna = ieee80211_set_antenna,
  3215. .get_antenna = ieee80211_get_antenna,
  3216. .set_rekey_data = ieee80211_set_rekey_data,
  3217. .tdls_oper = ieee80211_tdls_oper,
  3218. .tdls_mgmt = ieee80211_tdls_mgmt,
  3219. .tdls_channel_switch = ieee80211_tdls_channel_switch,
  3220. .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
  3221. .probe_client = ieee80211_probe_client,
  3222. .set_noack_map = ieee80211_set_noack_map,
  3223. #ifdef CONFIG_PM
  3224. .set_wakeup = ieee80211_set_wakeup,
  3225. #endif
  3226. .get_channel = ieee80211_cfg_get_channel,
  3227. .start_radar_detection = ieee80211_start_radar_detection,
  3228. .channel_switch = ieee80211_channel_switch,
  3229. .set_qos_map = ieee80211_set_qos_map,
  3230. .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
  3231. .add_tx_ts = ieee80211_add_tx_ts,
  3232. .del_tx_ts = ieee80211_del_tx_ts,
  3233. .start_nan = ieee80211_start_nan,
  3234. .stop_nan = ieee80211_stop_nan,
  3235. .nan_change_conf = ieee80211_nan_change_conf,
  3236. .add_nan_func = ieee80211_add_nan_func,
  3237. .del_nan_func = ieee80211_del_nan_func,
  3238. .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
  3239. .tx_control_port = ieee80211_tx_control_port,
  3240. .get_txq_stats = ieee80211_get_txq_stats,
  3241. };