cfg.c 98 KB

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