cfg.c 99 KB

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