cfg.c 101 KB

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