cfg.c 98 KB

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