cfg.c 100 KB

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