cfg.c 96 KB

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