cfg.c 102 KB

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