cfg.c 100 KB

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