cfg.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506
  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. sband = sta->local->hw.wiphy->bands[
  338. ieee80211_get_sdata_band(sta->sdata)];
  339. rinfo->legacy = sband->bitrates[rate->idx].bitrate;
  340. }
  341. if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  342. rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  343. if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  344. rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
  345. if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  346. rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
  347. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  348. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  349. }
  350. void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
  351. {
  352. rinfo->flags = 0;
  353. if (sta->last_rx_rate_flag & RX_FLAG_HT) {
  354. rinfo->flags |= RATE_INFO_FLAGS_MCS;
  355. rinfo->mcs = sta->last_rx_rate_idx;
  356. } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
  357. rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
  358. rinfo->nss = sta->last_rx_rate_vht_nss;
  359. rinfo->mcs = sta->last_rx_rate_idx;
  360. } else {
  361. struct ieee80211_supported_band *sband;
  362. sband = sta->local->hw.wiphy->bands[
  363. ieee80211_get_sdata_band(sta->sdata)];
  364. rinfo->legacy =
  365. sband->bitrates[sta->last_rx_rate_idx].bitrate;
  366. }
  367. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  368. rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  369. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  370. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  371. if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
  372. rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
  373. if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
  374. rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
  375. if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
  376. rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
  377. }
  378. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  379. {
  380. struct ieee80211_sub_if_data *sdata = sta->sdata;
  381. struct ieee80211_local *local = sdata->local;
  382. struct timespec uptime;
  383. u64 packets = 0;
  384. int i, ac;
  385. sinfo->generation = sdata->local->sta_generation;
  386. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  387. STATION_INFO_RX_BYTES64 |
  388. STATION_INFO_TX_BYTES64 |
  389. STATION_INFO_RX_PACKETS |
  390. STATION_INFO_TX_PACKETS |
  391. STATION_INFO_TX_RETRIES |
  392. STATION_INFO_TX_FAILED |
  393. STATION_INFO_TX_BITRATE |
  394. STATION_INFO_RX_BITRATE |
  395. STATION_INFO_RX_DROP_MISC |
  396. STATION_INFO_BSS_PARAM |
  397. STATION_INFO_CONNECTED_TIME |
  398. STATION_INFO_STA_FLAGS |
  399. STATION_INFO_BEACON_LOSS_COUNT;
  400. do_posix_clock_monotonic_gettime(&uptime);
  401. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  402. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  403. sinfo->tx_bytes = 0;
  404. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  405. sinfo->tx_bytes += sta->tx_bytes[ac];
  406. packets += sta->tx_packets[ac];
  407. }
  408. sinfo->tx_packets = packets;
  409. sinfo->rx_bytes = sta->rx_bytes;
  410. sinfo->rx_packets = sta->rx_packets;
  411. sinfo->tx_retries = sta->tx_retry_count;
  412. sinfo->tx_failed = sta->tx_retry_failed;
  413. sinfo->rx_dropped_misc = sta->rx_dropped;
  414. sinfo->beacon_loss_count = sta->beacon_loss_count;
  415. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  416. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  417. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  418. if (!local->ops->get_rssi ||
  419. drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
  420. sinfo->signal = (s8)sta->last_signal;
  421. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  422. }
  423. if (sta->chains) {
  424. sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
  425. STATION_INFO_CHAIN_SIGNAL_AVG;
  426. sinfo->chains = sta->chains;
  427. for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
  428. sinfo->chain_signal[i] = sta->chain_signal_last[i];
  429. sinfo->chain_signal_avg[i] =
  430. (s8) -ewma_read(&sta->chain_signal_avg[i]);
  431. }
  432. }
  433. sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
  434. sta_set_rate_info_rx(sta, &sinfo->rxrate);
  435. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  436. #ifdef CONFIG_MAC80211_MESH
  437. sinfo->filled |= STATION_INFO_LLID |
  438. STATION_INFO_PLID |
  439. STATION_INFO_PLINK_STATE |
  440. STATION_INFO_LOCAL_PM |
  441. STATION_INFO_PEER_PM |
  442. STATION_INFO_NONPEER_PM;
  443. sinfo->llid = le16_to_cpu(sta->llid);
  444. sinfo->plid = le16_to_cpu(sta->plid);
  445. sinfo->plink_state = sta->plink_state;
  446. if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
  447. sinfo->filled |= STATION_INFO_T_OFFSET;
  448. sinfo->t_offset = sta->t_offset;
  449. }
  450. sinfo->local_pm = sta->local_pm;
  451. sinfo->peer_pm = sta->peer_pm;
  452. sinfo->nonpeer_pm = sta->nonpeer_pm;
  453. #endif
  454. }
  455. sinfo->bss_param.flags = 0;
  456. if (sdata->vif.bss_conf.use_cts_prot)
  457. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  458. if (sdata->vif.bss_conf.use_short_preamble)
  459. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  460. if (sdata->vif.bss_conf.use_short_slot)
  461. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  462. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  463. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  464. sinfo->sta_flags.set = 0;
  465. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  466. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  467. BIT(NL80211_STA_FLAG_WME) |
  468. BIT(NL80211_STA_FLAG_MFP) |
  469. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  470. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  471. BIT(NL80211_STA_FLAG_TDLS_PEER);
  472. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  473. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  474. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  475. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  476. if (test_sta_flag(sta, WLAN_STA_WME))
  477. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  478. if (test_sta_flag(sta, WLAN_STA_MFP))
  479. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  480. if (test_sta_flag(sta, WLAN_STA_AUTH))
  481. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  482. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  483. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  484. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  485. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  486. }
  487. static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
  488. "rx_packets", "rx_bytes", "wep_weak_iv_count",
  489. "rx_duplicates", "rx_fragments", "rx_dropped",
  490. "tx_packets", "tx_bytes", "tx_fragments",
  491. "tx_filtered", "tx_retry_failed", "tx_retries",
  492. "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
  493. "channel", "noise", "ch_time", "ch_time_busy",
  494. "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
  495. };
  496. #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
  497. static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
  498. struct net_device *dev,
  499. int sset)
  500. {
  501. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  502. int rv = 0;
  503. if (sset == ETH_SS_STATS)
  504. rv += STA_STATS_LEN;
  505. rv += drv_get_et_sset_count(sdata, sset);
  506. if (rv == 0)
  507. return -EOPNOTSUPP;
  508. return rv;
  509. }
  510. static void ieee80211_get_et_stats(struct wiphy *wiphy,
  511. struct net_device *dev,
  512. struct ethtool_stats *stats,
  513. u64 *data)
  514. {
  515. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  516. struct ieee80211_chanctx_conf *chanctx_conf;
  517. struct ieee80211_channel *channel;
  518. struct sta_info *sta;
  519. struct ieee80211_local *local = sdata->local;
  520. struct station_info sinfo;
  521. struct survey_info survey;
  522. int i, q;
  523. #define STA_STATS_SURVEY_LEN 7
  524. memset(data, 0, sizeof(u64) * STA_STATS_LEN);
  525. #define ADD_STA_STATS(sta) \
  526. do { \
  527. data[i++] += sta->rx_packets; \
  528. data[i++] += sta->rx_bytes; \
  529. data[i++] += sta->wep_weak_iv_count; \
  530. data[i++] += sta->num_duplicates; \
  531. data[i++] += sta->rx_fragments; \
  532. data[i++] += sta->rx_dropped; \
  533. \
  534. data[i++] += sinfo.tx_packets; \
  535. data[i++] += sinfo.tx_bytes; \
  536. data[i++] += sta->tx_fragments; \
  537. data[i++] += sta->tx_filtered_count; \
  538. data[i++] += sta->tx_retry_failed; \
  539. data[i++] += sta->tx_retry_count; \
  540. data[i++] += sta->beacon_loss_count; \
  541. } while (0)
  542. /* For Managed stations, find the single station based on BSSID
  543. * and use that. For interface types, iterate through all available
  544. * stations and add stats for any station that is assigned to this
  545. * network device.
  546. */
  547. mutex_lock(&local->sta_mtx);
  548. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  549. sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
  550. if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
  551. goto do_survey;
  552. sinfo.filled = 0;
  553. sta_set_sinfo(sta, &sinfo);
  554. i = 0;
  555. ADD_STA_STATS(sta);
  556. data[i++] = sta->sta_state;
  557. if (sinfo.filled & STATION_INFO_TX_BITRATE)
  558. data[i] = 100000 *
  559. cfg80211_calculate_bitrate(&sinfo.txrate);
  560. i++;
  561. if (sinfo.filled & STATION_INFO_RX_BITRATE)
  562. data[i] = 100000 *
  563. cfg80211_calculate_bitrate(&sinfo.rxrate);
  564. i++;
  565. if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
  566. data[i] = (u8)sinfo.signal_avg;
  567. i++;
  568. } else {
  569. list_for_each_entry(sta, &local->sta_list, list) {
  570. /* Make sure this station belongs to the proper dev */
  571. if (sta->sdata->dev != dev)
  572. continue;
  573. sinfo.filled = 0;
  574. sta_set_sinfo(sta, &sinfo);
  575. i = 0;
  576. ADD_STA_STATS(sta);
  577. }
  578. }
  579. do_survey:
  580. i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
  581. /* Get survey stats for current channel */
  582. survey.filled = 0;
  583. rcu_read_lock();
  584. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  585. if (chanctx_conf)
  586. channel = chanctx_conf->def.chan;
  587. else
  588. channel = NULL;
  589. rcu_read_unlock();
  590. if (channel) {
  591. q = 0;
  592. do {
  593. survey.filled = 0;
  594. if (drv_get_survey(local, q, &survey) != 0) {
  595. survey.filled = 0;
  596. break;
  597. }
  598. q++;
  599. } while (channel != survey.channel);
  600. }
  601. if (survey.filled)
  602. data[i++] = survey.channel->center_freq;
  603. else
  604. data[i++] = 0;
  605. if (survey.filled & SURVEY_INFO_NOISE_DBM)
  606. data[i++] = (u8)survey.noise;
  607. else
  608. data[i++] = -1LL;
  609. if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
  610. data[i++] = survey.channel_time;
  611. else
  612. data[i++] = -1LL;
  613. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
  614. data[i++] = survey.channel_time_busy;
  615. else
  616. data[i++] = -1LL;
  617. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
  618. data[i++] = survey.channel_time_ext_busy;
  619. else
  620. data[i++] = -1LL;
  621. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
  622. data[i++] = survey.channel_time_rx;
  623. else
  624. data[i++] = -1LL;
  625. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
  626. data[i++] = survey.channel_time_tx;
  627. else
  628. data[i++] = -1LL;
  629. mutex_unlock(&local->sta_mtx);
  630. if (WARN_ON(i != STA_STATS_LEN))
  631. return;
  632. drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
  633. }
  634. static void ieee80211_get_et_strings(struct wiphy *wiphy,
  635. struct net_device *dev,
  636. u32 sset, u8 *data)
  637. {
  638. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  639. int sz_sta_stats = 0;
  640. if (sset == ETH_SS_STATS) {
  641. sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
  642. memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
  643. }
  644. drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
  645. }
  646. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  647. int idx, u8 *mac, struct station_info *sinfo)
  648. {
  649. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  650. struct ieee80211_local *local = sdata->local;
  651. struct sta_info *sta;
  652. int ret = -ENOENT;
  653. mutex_lock(&local->sta_mtx);
  654. sta = sta_info_get_by_idx(sdata, idx);
  655. if (sta) {
  656. ret = 0;
  657. memcpy(mac, sta->sta.addr, ETH_ALEN);
  658. sta_set_sinfo(sta, sinfo);
  659. }
  660. mutex_unlock(&local->sta_mtx);
  661. return ret;
  662. }
  663. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  664. int idx, struct survey_info *survey)
  665. {
  666. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  667. return drv_get_survey(local, idx, survey);
  668. }
  669. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  670. u8 *mac, struct station_info *sinfo)
  671. {
  672. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  673. struct ieee80211_local *local = sdata->local;
  674. struct sta_info *sta;
  675. int ret = -ENOENT;
  676. mutex_lock(&local->sta_mtx);
  677. sta = sta_info_get_bss(sdata, mac);
  678. if (sta) {
  679. ret = 0;
  680. sta_set_sinfo(sta, sinfo);
  681. }
  682. mutex_unlock(&local->sta_mtx);
  683. return ret;
  684. }
  685. static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  686. struct cfg80211_chan_def *chandef)
  687. {
  688. struct ieee80211_local *local = wiphy_priv(wiphy);
  689. struct ieee80211_sub_if_data *sdata;
  690. int ret = 0;
  691. if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
  692. return 0;
  693. mutex_lock(&local->iflist_mtx);
  694. if (local->use_chanctx) {
  695. sdata = rcu_dereference_protected(
  696. local->monitor_sdata,
  697. lockdep_is_held(&local->iflist_mtx));
  698. if (sdata) {
  699. ieee80211_vif_release_channel(sdata);
  700. ret = ieee80211_vif_use_channel(sdata, chandef,
  701. IEEE80211_CHANCTX_EXCLUSIVE);
  702. }
  703. } else if (local->open_count == local->monitors) {
  704. local->_oper_chandef = *chandef;
  705. ieee80211_hw_config(local, 0);
  706. }
  707. if (ret == 0)
  708. local->monitor_chandef = *chandef;
  709. mutex_unlock(&local->iflist_mtx);
  710. return ret;
  711. }
  712. static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
  713. const u8 *resp, size_t resp_len)
  714. {
  715. struct probe_resp *new, *old;
  716. if (!resp || !resp_len)
  717. return 1;
  718. old = rtnl_dereference(sdata->u.ap.probe_resp);
  719. new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
  720. if (!new)
  721. return -ENOMEM;
  722. new->len = resp_len;
  723. memcpy(new->data, resp, resp_len);
  724. rcu_assign_pointer(sdata->u.ap.probe_resp, new);
  725. if (old)
  726. kfree_rcu(old, rcu_head);
  727. return 0;
  728. }
  729. static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
  730. struct cfg80211_beacon_data *params)
  731. {
  732. struct beacon_data *new, *old;
  733. int new_head_len, new_tail_len;
  734. int size, err;
  735. u32 changed = BSS_CHANGED_BEACON;
  736. old = rtnl_dereference(sdata->u.ap.beacon);
  737. /* Need to have a beacon head if we don't have one yet */
  738. if (!params->head && !old)
  739. return -EINVAL;
  740. /* new or old head? */
  741. if (params->head)
  742. new_head_len = params->head_len;
  743. else
  744. new_head_len = old->head_len;
  745. /* new or old tail? */
  746. if (params->tail || !old)
  747. /* params->tail_len will be zero for !params->tail */
  748. new_tail_len = params->tail_len;
  749. else
  750. new_tail_len = old->tail_len;
  751. size = sizeof(*new) + new_head_len + new_tail_len;
  752. new = kzalloc(size, GFP_KERNEL);
  753. if (!new)
  754. return -ENOMEM;
  755. /* start filling the new info now */
  756. /*
  757. * pointers go into the block we allocated,
  758. * memory is | beacon_data | head | tail |
  759. */
  760. new->head = ((u8 *) new) + sizeof(*new);
  761. new->tail = new->head + new_head_len;
  762. new->head_len = new_head_len;
  763. new->tail_len = new_tail_len;
  764. /* copy in head */
  765. if (params->head)
  766. memcpy(new->head, params->head, new_head_len);
  767. else
  768. memcpy(new->head, old->head, new_head_len);
  769. /* copy in optional tail */
  770. if (params->tail)
  771. memcpy(new->tail, params->tail, new_tail_len);
  772. else
  773. if (old)
  774. memcpy(new->tail, old->tail, new_tail_len);
  775. err = ieee80211_set_probe_resp(sdata, params->probe_resp,
  776. params->probe_resp_len);
  777. if (err < 0)
  778. return err;
  779. if (err == 0)
  780. changed |= BSS_CHANGED_AP_PROBE_RESP;
  781. rcu_assign_pointer(sdata->u.ap.beacon, new);
  782. if (old)
  783. kfree_rcu(old, rcu_head);
  784. return changed;
  785. }
  786. static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
  787. struct cfg80211_ap_settings *params)
  788. {
  789. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  790. struct beacon_data *old;
  791. struct ieee80211_sub_if_data *vlan;
  792. u32 changed = BSS_CHANGED_BEACON_INT |
  793. BSS_CHANGED_BEACON_ENABLED |
  794. BSS_CHANGED_BEACON |
  795. BSS_CHANGED_SSID |
  796. BSS_CHANGED_P2P_PS;
  797. int err;
  798. old = rtnl_dereference(sdata->u.ap.beacon);
  799. if (old)
  800. return -EALREADY;
  801. /* TODO: make hostapd tell us what it wants */
  802. sdata->smps_mode = IEEE80211_SMPS_OFF;
  803. sdata->needed_rx_chains = sdata->local->rx_chains;
  804. sdata->radar_required = params->radar_required;
  805. err = ieee80211_vif_use_channel(sdata, &params->chandef,
  806. IEEE80211_CHANCTX_SHARED);
  807. if (err)
  808. return err;
  809. ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
  810. /*
  811. * Apply control port protocol, this allows us to
  812. * not encrypt dynamic WEP control frames.
  813. */
  814. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  815. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  816. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  817. vlan->control_port_protocol =
  818. params->crypto.control_port_ethertype;
  819. vlan->control_port_no_encrypt =
  820. params->crypto.control_port_no_encrypt;
  821. }
  822. sdata->vif.bss_conf.beacon_int = params->beacon_interval;
  823. sdata->vif.bss_conf.dtim_period = params->dtim_period;
  824. sdata->vif.bss_conf.enable_beacon = true;
  825. sdata->vif.bss_conf.ssid_len = params->ssid_len;
  826. if (params->ssid_len)
  827. memcpy(sdata->vif.bss_conf.ssid, params->ssid,
  828. params->ssid_len);
  829. sdata->vif.bss_conf.hidden_ssid =
  830. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  831. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  832. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  833. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
  834. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  835. if (params->p2p_opp_ps)
  836. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  837. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  838. err = ieee80211_assign_beacon(sdata, &params->beacon);
  839. if (err < 0)
  840. return err;
  841. changed |= err;
  842. err = drv_start_ap(sdata->local, sdata);
  843. if (err) {
  844. old = rtnl_dereference(sdata->u.ap.beacon);
  845. if (old)
  846. kfree_rcu(old, rcu_head);
  847. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  848. return err;
  849. }
  850. ieee80211_bss_info_change_notify(sdata, changed);
  851. netif_carrier_on(dev);
  852. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  853. netif_carrier_on(vlan->dev);
  854. return 0;
  855. }
  856. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  857. struct cfg80211_beacon_data *params)
  858. {
  859. struct ieee80211_sub_if_data *sdata;
  860. struct beacon_data *old;
  861. int err;
  862. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  863. old = rtnl_dereference(sdata->u.ap.beacon);
  864. if (!old)
  865. return -ENOENT;
  866. err = ieee80211_assign_beacon(sdata, params);
  867. if (err < 0)
  868. return err;
  869. ieee80211_bss_info_change_notify(sdata, err);
  870. return 0;
  871. }
  872. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  873. {
  874. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  875. struct ieee80211_sub_if_data *vlan;
  876. struct ieee80211_local *local = sdata->local;
  877. struct beacon_data *old_beacon;
  878. struct probe_resp *old_probe_resp;
  879. old_beacon = rtnl_dereference(sdata->u.ap.beacon);
  880. if (!old_beacon)
  881. return -ENOENT;
  882. old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
  883. /* turn off carrier for this interface and dependent VLANs */
  884. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  885. netif_carrier_off(vlan->dev);
  886. netif_carrier_off(dev);
  887. /* remove beacon and probe response */
  888. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  889. RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
  890. kfree_rcu(old_beacon, rcu_head);
  891. if (old_probe_resp)
  892. kfree_rcu(old_probe_resp, rcu_head);
  893. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  894. sta_info_flush_defer(vlan);
  895. sta_info_flush_defer(sdata);
  896. synchronize_net();
  897. rcu_barrier();
  898. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  899. sta_info_flush_cleanup(vlan);
  900. ieee80211_free_keys(vlan);
  901. }
  902. sta_info_flush_cleanup(sdata);
  903. ieee80211_free_keys(sdata);
  904. sdata->vif.bss_conf.enable_beacon = false;
  905. sdata->vif.bss_conf.ssid_len = 0;
  906. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  907. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  908. if (sdata->wdev.cac_started) {
  909. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  910. cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
  911. GFP_KERNEL);
  912. }
  913. drv_stop_ap(sdata->local, sdata);
  914. /* free all potentially still buffered bcast frames */
  915. local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
  916. skb_queue_purge(&sdata->u.ap.ps.bc_buf);
  917. ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
  918. ieee80211_vif_release_channel(sdata);
  919. return 0;
  920. }
  921. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  922. struct iapp_layer2_update {
  923. u8 da[ETH_ALEN]; /* broadcast */
  924. u8 sa[ETH_ALEN]; /* STA addr */
  925. __be16 len; /* 6 */
  926. u8 dsap; /* 0 */
  927. u8 ssap; /* 0 */
  928. u8 control;
  929. u8 xid_info[3];
  930. } __packed;
  931. static void ieee80211_send_layer2_update(struct sta_info *sta)
  932. {
  933. struct iapp_layer2_update *msg;
  934. struct sk_buff *skb;
  935. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  936. * bridge devices */
  937. skb = dev_alloc_skb(sizeof(*msg));
  938. if (!skb)
  939. return;
  940. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  941. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  942. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  943. eth_broadcast_addr(msg->da);
  944. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  945. msg->len = htons(6);
  946. msg->dsap = 0;
  947. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  948. msg->control = 0xaf; /* XID response lsb.1111F101.
  949. * F=0 (no poll command; unsolicited frame) */
  950. msg->xid_info[0] = 0x81; /* XID format identifier */
  951. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  952. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  953. skb->dev = sta->sdata->dev;
  954. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  955. memset(skb->cb, 0, sizeof(skb->cb));
  956. netif_rx_ni(skb);
  957. }
  958. static int sta_apply_auth_flags(struct ieee80211_local *local,
  959. struct sta_info *sta,
  960. u32 mask, u32 set)
  961. {
  962. int ret;
  963. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  964. set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  965. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  966. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  967. if (ret)
  968. return ret;
  969. }
  970. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  971. set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  972. !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  973. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  974. if (ret)
  975. return ret;
  976. }
  977. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  978. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  979. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  980. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  981. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  982. else
  983. ret = 0;
  984. if (ret)
  985. return ret;
  986. }
  987. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  988. !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  989. test_sta_flag(sta, WLAN_STA_ASSOC)) {
  990. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  991. if (ret)
  992. return ret;
  993. }
  994. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  995. !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  996. test_sta_flag(sta, WLAN_STA_AUTH)) {
  997. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  998. if (ret)
  999. return ret;
  1000. }
  1001. return 0;
  1002. }
  1003. static int sta_apply_parameters(struct ieee80211_local *local,
  1004. struct sta_info *sta,
  1005. struct station_parameters *params)
  1006. {
  1007. int ret = 0;
  1008. u32 rates;
  1009. int i, j;
  1010. struct ieee80211_supported_band *sband;
  1011. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1012. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  1013. u32 mask, set;
  1014. sband = local->hw.wiphy->bands[band];
  1015. mask = params->sta_flags_mask;
  1016. set = params->sta_flags_set;
  1017. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1018. /*
  1019. * In mesh mode, ASSOCIATED isn't part of the nl80211
  1020. * API but must follow AUTHENTICATED for driver state.
  1021. */
  1022. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1023. mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1024. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1025. set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1026. } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1027. /*
  1028. * TDLS -- everything follows authorized, but
  1029. * only becoming authorized is possible, not
  1030. * going back
  1031. */
  1032. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1033. set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1034. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1035. mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1036. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1037. }
  1038. }
  1039. ret = sta_apply_auth_flags(local, sta, mask, set);
  1040. if (ret)
  1041. return ret;
  1042. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  1043. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  1044. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1045. else
  1046. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1047. }
  1048. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  1049. if (set & BIT(NL80211_STA_FLAG_WME)) {
  1050. set_sta_flag(sta, WLAN_STA_WME);
  1051. sta->sta.wme = true;
  1052. } else {
  1053. clear_sta_flag(sta, WLAN_STA_WME);
  1054. sta->sta.wme = false;
  1055. }
  1056. }
  1057. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  1058. if (set & BIT(NL80211_STA_FLAG_MFP))
  1059. set_sta_flag(sta, WLAN_STA_MFP);
  1060. else
  1061. clear_sta_flag(sta, WLAN_STA_MFP);
  1062. }
  1063. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  1064. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1065. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1066. else
  1067. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1068. }
  1069. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  1070. sta->sta.uapsd_queues = params->uapsd_queues;
  1071. sta->sta.max_sp = params->max_sp;
  1072. }
  1073. /*
  1074. * cfg80211 validates this (1-2007) and allows setting the AID
  1075. * only when creating a new station entry
  1076. */
  1077. if (params->aid)
  1078. sta->sta.aid = params->aid;
  1079. /*
  1080. * Some of the following updates would be racy if called on an
  1081. * existing station, via ieee80211_change_station(). However,
  1082. * all such changes are rejected by cfg80211 except for updates
  1083. * changing the supported rates on an existing but not yet used
  1084. * TDLS peer.
  1085. */
  1086. if (params->listen_interval >= 0)
  1087. sta->listen_interval = params->listen_interval;
  1088. if (params->supported_rates) {
  1089. rates = 0;
  1090. for (i = 0; i < params->supported_rates_len; i++) {
  1091. int rate = (params->supported_rates[i] & 0x7f) * 5;
  1092. for (j = 0; j < sband->n_bitrates; j++) {
  1093. if (sband->bitrates[j].bitrate == rate)
  1094. rates |= BIT(j);
  1095. }
  1096. }
  1097. sta->sta.supp_rates[band] = rates;
  1098. }
  1099. if (params->ht_capa)
  1100. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  1101. params->ht_capa, sta);
  1102. if (params->vht_capa)
  1103. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  1104. params->vht_capa, sta);
  1105. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1106. #ifdef CONFIG_MAC80211_MESH
  1107. u32 changed = 0;
  1108. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
  1109. switch (params->plink_state) {
  1110. case NL80211_PLINK_ESTAB:
  1111. if (sta->plink_state != NL80211_PLINK_ESTAB)
  1112. changed = mesh_plink_inc_estab_count(
  1113. sdata);
  1114. sta->plink_state = params->plink_state;
  1115. ieee80211_mps_sta_status_update(sta);
  1116. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1117. sdata->u.mesh.mshcfg.power_mode);
  1118. break;
  1119. case NL80211_PLINK_LISTEN:
  1120. case NL80211_PLINK_BLOCKED:
  1121. case NL80211_PLINK_OPN_SNT:
  1122. case NL80211_PLINK_OPN_RCVD:
  1123. case NL80211_PLINK_CNF_RCVD:
  1124. case NL80211_PLINK_HOLDING:
  1125. if (sta->plink_state == NL80211_PLINK_ESTAB)
  1126. changed = mesh_plink_dec_estab_count(
  1127. sdata);
  1128. sta->plink_state = params->plink_state;
  1129. ieee80211_mps_sta_status_update(sta);
  1130. changed |=
  1131. ieee80211_mps_local_status_update(sdata);
  1132. break;
  1133. default:
  1134. /* nothing */
  1135. break;
  1136. }
  1137. }
  1138. switch (params->plink_action) {
  1139. case NL80211_PLINK_ACTION_NO_ACTION:
  1140. /* nothing */
  1141. break;
  1142. case NL80211_PLINK_ACTION_OPEN:
  1143. changed |= mesh_plink_open(sta);
  1144. break;
  1145. case NL80211_PLINK_ACTION_BLOCK:
  1146. changed |= mesh_plink_block(sta);
  1147. break;
  1148. }
  1149. if (params->local_pm)
  1150. changed |=
  1151. ieee80211_mps_set_sta_local_pm(sta,
  1152. params->local_pm);
  1153. ieee80211_bss_info_change_notify(sdata, changed);
  1154. #endif
  1155. }
  1156. return 0;
  1157. }
  1158. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  1159. u8 *mac, struct station_parameters *params)
  1160. {
  1161. struct ieee80211_local *local = wiphy_priv(wiphy);
  1162. struct sta_info *sta;
  1163. struct ieee80211_sub_if_data *sdata;
  1164. int err;
  1165. int layer2_update;
  1166. if (params->vlan) {
  1167. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1168. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1169. sdata->vif.type != NL80211_IFTYPE_AP)
  1170. return -EINVAL;
  1171. } else
  1172. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1173. if (ether_addr_equal(mac, sdata->vif.addr))
  1174. return -EINVAL;
  1175. if (is_multicast_ether_addr(mac))
  1176. return -EINVAL;
  1177. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  1178. if (!sta)
  1179. return -ENOMEM;
  1180. /*
  1181. * defaults -- if userspace wants something else we'll
  1182. * change it accordingly in sta_apply_parameters()
  1183. */
  1184. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
  1185. sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
  1186. sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
  1187. }
  1188. err = sta_apply_parameters(local, sta, params);
  1189. if (err) {
  1190. sta_info_free(local, sta);
  1191. return err;
  1192. }
  1193. /*
  1194. * for TDLS, rate control should be initialized only when
  1195. * rates are known and station is marked authorized
  1196. */
  1197. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  1198. rate_control_rate_init(sta);
  1199. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1200. sdata->vif.type == NL80211_IFTYPE_AP;
  1201. err = sta_info_insert_rcu(sta);
  1202. if (err) {
  1203. rcu_read_unlock();
  1204. return err;
  1205. }
  1206. if (layer2_update)
  1207. ieee80211_send_layer2_update(sta);
  1208. rcu_read_unlock();
  1209. return 0;
  1210. }
  1211. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1212. u8 *mac)
  1213. {
  1214. struct ieee80211_sub_if_data *sdata;
  1215. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1216. if (mac)
  1217. return sta_info_destroy_addr_bss(sdata, mac);
  1218. sta_info_flush(sdata);
  1219. return 0;
  1220. }
  1221. static int ieee80211_change_station(struct wiphy *wiphy,
  1222. struct net_device *dev, u8 *mac,
  1223. struct station_parameters *params)
  1224. {
  1225. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1226. struct ieee80211_local *local = wiphy_priv(wiphy);
  1227. struct sta_info *sta;
  1228. struct ieee80211_sub_if_data *vlansdata;
  1229. enum cfg80211_station_type statype;
  1230. int err;
  1231. mutex_lock(&local->sta_mtx);
  1232. sta = sta_info_get_bss(sdata, mac);
  1233. if (!sta) {
  1234. err = -ENOENT;
  1235. goto out_err;
  1236. }
  1237. switch (sdata->vif.type) {
  1238. case NL80211_IFTYPE_MESH_POINT:
  1239. if (sdata->u.mesh.user_mpm)
  1240. statype = CFG80211_STA_MESH_PEER_USER;
  1241. else
  1242. statype = CFG80211_STA_MESH_PEER_KERNEL;
  1243. break;
  1244. case NL80211_IFTYPE_ADHOC:
  1245. statype = CFG80211_STA_IBSS;
  1246. break;
  1247. case NL80211_IFTYPE_STATION:
  1248. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1249. statype = CFG80211_STA_AP_STA;
  1250. break;
  1251. }
  1252. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1253. statype = CFG80211_STA_TDLS_PEER_ACTIVE;
  1254. else
  1255. statype = CFG80211_STA_TDLS_PEER_SETUP;
  1256. break;
  1257. case NL80211_IFTYPE_AP:
  1258. case NL80211_IFTYPE_AP_VLAN:
  1259. statype = CFG80211_STA_AP_CLIENT;
  1260. break;
  1261. default:
  1262. err = -EOPNOTSUPP;
  1263. goto out_err;
  1264. }
  1265. err = cfg80211_check_station_change(wiphy, params, statype);
  1266. if (err)
  1267. goto out_err;
  1268. if (params->vlan && params->vlan != sta->sdata->dev) {
  1269. bool prev_4addr = false;
  1270. bool new_4addr = false;
  1271. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1272. if (params->vlan->ieee80211_ptr->use_4addr) {
  1273. if (vlansdata->u.vlan.sta) {
  1274. err = -EBUSY;
  1275. goto out_err;
  1276. }
  1277. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1278. new_4addr = true;
  1279. }
  1280. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1281. sta->sdata->u.vlan.sta) {
  1282. rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
  1283. prev_4addr = true;
  1284. }
  1285. sta->sdata = vlansdata;
  1286. if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
  1287. prev_4addr != new_4addr) {
  1288. if (new_4addr)
  1289. atomic_dec(&sta->sdata->bss->num_mcast_sta);
  1290. else
  1291. atomic_inc(&sta->sdata->bss->num_mcast_sta);
  1292. }
  1293. ieee80211_send_layer2_update(sta);
  1294. }
  1295. err = sta_apply_parameters(local, sta, params);
  1296. if (err)
  1297. goto out_err;
  1298. /* When peer becomes authorized, init rate control as well */
  1299. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1300. test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1301. rate_control_rate_init(sta);
  1302. mutex_unlock(&local->sta_mtx);
  1303. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1304. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1305. ieee80211_recalc_ps(local, -1);
  1306. ieee80211_recalc_ps_vif(sdata);
  1307. }
  1308. return 0;
  1309. out_err:
  1310. mutex_unlock(&local->sta_mtx);
  1311. return err;
  1312. }
  1313. #ifdef CONFIG_MAC80211_MESH
  1314. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1315. u8 *dst, u8 *next_hop)
  1316. {
  1317. struct ieee80211_sub_if_data *sdata;
  1318. struct mesh_path *mpath;
  1319. struct sta_info *sta;
  1320. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1321. rcu_read_lock();
  1322. sta = sta_info_get(sdata, next_hop);
  1323. if (!sta) {
  1324. rcu_read_unlock();
  1325. return -ENOENT;
  1326. }
  1327. mpath = mesh_path_add(sdata, dst);
  1328. if (IS_ERR(mpath)) {
  1329. rcu_read_unlock();
  1330. return PTR_ERR(mpath);
  1331. }
  1332. mesh_path_fix_nexthop(mpath, sta);
  1333. rcu_read_unlock();
  1334. return 0;
  1335. }
  1336. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1337. u8 *dst)
  1338. {
  1339. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1340. if (dst)
  1341. return mesh_path_del(sdata, dst);
  1342. mesh_path_flush_by_iface(sdata);
  1343. return 0;
  1344. }
  1345. static int ieee80211_change_mpath(struct wiphy *wiphy,
  1346. struct net_device *dev,
  1347. u8 *dst, u8 *next_hop)
  1348. {
  1349. struct ieee80211_sub_if_data *sdata;
  1350. struct mesh_path *mpath;
  1351. struct sta_info *sta;
  1352. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1353. rcu_read_lock();
  1354. sta = sta_info_get(sdata, next_hop);
  1355. if (!sta) {
  1356. rcu_read_unlock();
  1357. return -ENOENT;
  1358. }
  1359. mpath = mesh_path_lookup(sdata, dst);
  1360. if (!mpath) {
  1361. rcu_read_unlock();
  1362. return -ENOENT;
  1363. }
  1364. mesh_path_fix_nexthop(mpath, sta);
  1365. rcu_read_unlock();
  1366. return 0;
  1367. }
  1368. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1369. struct mpath_info *pinfo)
  1370. {
  1371. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1372. if (next_hop_sta)
  1373. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1374. else
  1375. memset(next_hop, 0, ETH_ALEN);
  1376. memset(pinfo, 0, sizeof(*pinfo));
  1377. pinfo->generation = mesh_paths_generation;
  1378. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1379. MPATH_INFO_SN |
  1380. MPATH_INFO_METRIC |
  1381. MPATH_INFO_EXPTIME |
  1382. MPATH_INFO_DISCOVERY_TIMEOUT |
  1383. MPATH_INFO_DISCOVERY_RETRIES |
  1384. MPATH_INFO_FLAGS;
  1385. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1386. pinfo->sn = mpath->sn;
  1387. pinfo->metric = mpath->metric;
  1388. if (time_before(jiffies, mpath->exp_time))
  1389. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1390. pinfo->discovery_timeout =
  1391. jiffies_to_msecs(mpath->discovery_timeout);
  1392. pinfo->discovery_retries = mpath->discovery_retries;
  1393. if (mpath->flags & MESH_PATH_ACTIVE)
  1394. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1395. if (mpath->flags & MESH_PATH_RESOLVING)
  1396. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1397. if (mpath->flags & MESH_PATH_SN_VALID)
  1398. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1399. if (mpath->flags & MESH_PATH_FIXED)
  1400. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1401. if (mpath->flags & MESH_PATH_RESOLVED)
  1402. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  1403. }
  1404. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1405. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1406. {
  1407. struct ieee80211_sub_if_data *sdata;
  1408. struct mesh_path *mpath;
  1409. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1410. rcu_read_lock();
  1411. mpath = mesh_path_lookup(sdata, dst);
  1412. if (!mpath) {
  1413. rcu_read_unlock();
  1414. return -ENOENT;
  1415. }
  1416. memcpy(dst, mpath->dst, ETH_ALEN);
  1417. mpath_set_pinfo(mpath, next_hop, pinfo);
  1418. rcu_read_unlock();
  1419. return 0;
  1420. }
  1421. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1422. int idx, u8 *dst, u8 *next_hop,
  1423. struct mpath_info *pinfo)
  1424. {
  1425. struct ieee80211_sub_if_data *sdata;
  1426. struct mesh_path *mpath;
  1427. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1428. rcu_read_lock();
  1429. mpath = mesh_path_lookup_by_idx(sdata, idx);
  1430. if (!mpath) {
  1431. rcu_read_unlock();
  1432. return -ENOENT;
  1433. }
  1434. memcpy(dst, mpath->dst, ETH_ALEN);
  1435. mpath_set_pinfo(mpath, next_hop, pinfo);
  1436. rcu_read_unlock();
  1437. return 0;
  1438. }
  1439. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  1440. struct net_device *dev,
  1441. struct mesh_config *conf)
  1442. {
  1443. struct ieee80211_sub_if_data *sdata;
  1444. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1445. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  1446. return 0;
  1447. }
  1448. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  1449. {
  1450. return (mask >> (parm-1)) & 0x1;
  1451. }
  1452. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  1453. const struct mesh_setup *setup)
  1454. {
  1455. u8 *new_ie;
  1456. const u8 *old_ie;
  1457. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  1458. struct ieee80211_sub_if_data, u.mesh);
  1459. /* allocate information elements */
  1460. new_ie = NULL;
  1461. old_ie = ifmsh->ie;
  1462. if (setup->ie_len) {
  1463. new_ie = kmemdup(setup->ie, setup->ie_len,
  1464. GFP_KERNEL);
  1465. if (!new_ie)
  1466. return -ENOMEM;
  1467. }
  1468. ifmsh->ie_len = setup->ie_len;
  1469. ifmsh->ie = new_ie;
  1470. kfree(old_ie);
  1471. /* now copy the rest of the setup parameters */
  1472. ifmsh->mesh_id_len = setup->mesh_id_len;
  1473. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  1474. ifmsh->mesh_sp_id = setup->sync_method;
  1475. ifmsh->mesh_pp_id = setup->path_sel_proto;
  1476. ifmsh->mesh_pm_id = setup->path_metric;
  1477. ifmsh->user_mpm = setup->user_mpm;
  1478. ifmsh->mesh_auth_id = setup->auth_id;
  1479. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  1480. if (setup->is_authenticated)
  1481. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  1482. if (setup->is_secure)
  1483. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  1484. /* mcast rate setting in Mesh Node */
  1485. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  1486. sizeof(setup->mcast_rate));
  1487. sdata->vif.bss_conf.basic_rates = setup->basic_rates;
  1488. sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
  1489. sdata->vif.bss_conf.dtim_period = setup->dtim_period;
  1490. return 0;
  1491. }
  1492. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  1493. struct net_device *dev, u32 mask,
  1494. const struct mesh_config *nconf)
  1495. {
  1496. struct mesh_config *conf;
  1497. struct ieee80211_sub_if_data *sdata;
  1498. struct ieee80211_if_mesh *ifmsh;
  1499. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1500. ifmsh = &sdata->u.mesh;
  1501. /* Set the config options which we are interested in setting */
  1502. conf = &(sdata->u.mesh.mshcfg);
  1503. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  1504. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  1505. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  1506. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  1507. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  1508. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  1509. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  1510. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  1511. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  1512. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  1513. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  1514. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  1515. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  1516. conf->element_ttl = nconf->element_ttl;
  1517. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
  1518. if (ifmsh->user_mpm)
  1519. return -EBUSY;
  1520. conf->auto_open_plinks = nconf->auto_open_plinks;
  1521. }
  1522. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  1523. conf->dot11MeshNbrOffsetMaxNeighbor =
  1524. nconf->dot11MeshNbrOffsetMaxNeighbor;
  1525. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  1526. conf->dot11MeshHWMPmaxPREQretries =
  1527. nconf->dot11MeshHWMPmaxPREQretries;
  1528. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1529. conf->path_refresh_time = nconf->path_refresh_time;
  1530. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1531. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1532. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1533. conf->dot11MeshHWMPactivePathTimeout =
  1534. nconf->dot11MeshHWMPactivePathTimeout;
  1535. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1536. conf->dot11MeshHWMPpreqMinInterval =
  1537. nconf->dot11MeshHWMPpreqMinInterval;
  1538. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  1539. conf->dot11MeshHWMPperrMinInterval =
  1540. nconf->dot11MeshHWMPperrMinInterval;
  1541. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1542. mask))
  1543. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1544. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1545. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1546. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1547. ieee80211_mesh_root_setup(ifmsh);
  1548. }
  1549. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1550. /* our current gate announcement implementation rides on root
  1551. * announcements, so require this ifmsh to also be a root node
  1552. * */
  1553. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1554. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  1555. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  1556. ieee80211_mesh_root_setup(ifmsh);
  1557. }
  1558. conf->dot11MeshGateAnnouncementProtocol =
  1559. nconf->dot11MeshGateAnnouncementProtocol;
  1560. }
  1561. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  1562. conf->dot11MeshHWMPRannInterval =
  1563. nconf->dot11MeshHWMPRannInterval;
  1564. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  1565. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  1566. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  1567. /* our RSSI threshold implementation is supported only for
  1568. * devices that report signal in dBm.
  1569. */
  1570. if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
  1571. return -ENOTSUPP;
  1572. conf->rssi_threshold = nconf->rssi_threshold;
  1573. }
  1574. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  1575. conf->ht_opmode = nconf->ht_opmode;
  1576. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  1577. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1578. }
  1579. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  1580. conf->dot11MeshHWMPactivePathToRootTimeout =
  1581. nconf->dot11MeshHWMPactivePathToRootTimeout;
  1582. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  1583. conf->dot11MeshHWMProotInterval =
  1584. nconf->dot11MeshHWMProotInterval;
  1585. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  1586. conf->dot11MeshHWMPconfirmationInterval =
  1587. nconf->dot11MeshHWMPconfirmationInterval;
  1588. if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
  1589. conf->power_mode = nconf->power_mode;
  1590. ieee80211_mps_local_status_update(sdata);
  1591. }
  1592. if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
  1593. conf->dot11MeshAwakeWindowDuration =
  1594. nconf->dot11MeshAwakeWindowDuration;
  1595. if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
  1596. conf->plink_timeout = nconf->plink_timeout;
  1597. ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  1598. return 0;
  1599. }
  1600. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1601. const struct mesh_config *conf,
  1602. const struct mesh_setup *setup)
  1603. {
  1604. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1605. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1606. int err;
  1607. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1608. err = copy_mesh_setup(ifmsh, setup);
  1609. if (err)
  1610. return err;
  1611. /* can mesh use other SMPS modes? */
  1612. sdata->smps_mode = IEEE80211_SMPS_OFF;
  1613. sdata->needed_rx_chains = sdata->local->rx_chains;
  1614. err = ieee80211_vif_use_channel(sdata, &setup->chandef,
  1615. IEEE80211_CHANCTX_SHARED);
  1616. if (err)
  1617. return err;
  1618. return ieee80211_start_mesh(sdata);
  1619. }
  1620. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1621. {
  1622. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1623. ieee80211_stop_mesh(sdata);
  1624. ieee80211_vif_release_channel(sdata);
  1625. return 0;
  1626. }
  1627. #endif
  1628. static int ieee80211_change_bss(struct wiphy *wiphy,
  1629. struct net_device *dev,
  1630. struct bss_parameters *params)
  1631. {
  1632. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1633. enum ieee80211_band band;
  1634. u32 changed = 0;
  1635. if (!rtnl_dereference(sdata->u.ap.beacon))
  1636. return -ENOENT;
  1637. band = ieee80211_get_sdata_band(sdata);
  1638. if (params->use_cts_prot >= 0) {
  1639. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1640. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1641. }
  1642. if (params->use_short_preamble >= 0) {
  1643. sdata->vif.bss_conf.use_short_preamble =
  1644. params->use_short_preamble;
  1645. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1646. }
  1647. if (!sdata->vif.bss_conf.use_short_slot &&
  1648. band == IEEE80211_BAND_5GHZ) {
  1649. sdata->vif.bss_conf.use_short_slot = true;
  1650. changed |= BSS_CHANGED_ERP_SLOT;
  1651. }
  1652. if (params->use_short_slot_time >= 0) {
  1653. sdata->vif.bss_conf.use_short_slot =
  1654. params->use_short_slot_time;
  1655. changed |= BSS_CHANGED_ERP_SLOT;
  1656. }
  1657. if (params->basic_rates) {
  1658. int i, j;
  1659. u32 rates = 0;
  1660. struct ieee80211_supported_band *sband = wiphy->bands[band];
  1661. for (i = 0; i < params->basic_rates_len; i++) {
  1662. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1663. for (j = 0; j < sband->n_bitrates; j++) {
  1664. if (sband->bitrates[j].bitrate == rate)
  1665. rates |= BIT(j);
  1666. }
  1667. }
  1668. sdata->vif.bss_conf.basic_rates = rates;
  1669. changed |= BSS_CHANGED_BASIC_RATES;
  1670. }
  1671. if (params->ap_isolate >= 0) {
  1672. if (params->ap_isolate)
  1673. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1674. else
  1675. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1676. }
  1677. if (params->ht_opmode >= 0) {
  1678. sdata->vif.bss_conf.ht_operation_mode =
  1679. (u16) params->ht_opmode;
  1680. changed |= BSS_CHANGED_HT;
  1681. }
  1682. if (params->p2p_ctwindow >= 0) {
  1683. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1684. ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1685. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1686. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1687. changed |= BSS_CHANGED_P2P_PS;
  1688. }
  1689. if (params->p2p_opp_ps > 0) {
  1690. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1691. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1692. changed |= BSS_CHANGED_P2P_PS;
  1693. } else if (params->p2p_opp_ps == 0) {
  1694. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1695. ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1696. changed |= BSS_CHANGED_P2P_PS;
  1697. }
  1698. ieee80211_bss_info_change_notify(sdata, changed);
  1699. return 0;
  1700. }
  1701. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1702. struct net_device *dev,
  1703. struct ieee80211_txq_params *params)
  1704. {
  1705. struct ieee80211_local *local = wiphy_priv(wiphy);
  1706. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1707. struct ieee80211_tx_queue_params p;
  1708. if (!local->ops->conf_tx)
  1709. return -EOPNOTSUPP;
  1710. if (local->hw.queues < IEEE80211_NUM_ACS)
  1711. return -EOPNOTSUPP;
  1712. memset(&p, 0, sizeof(p));
  1713. p.aifs = params->aifs;
  1714. p.cw_max = params->cwmax;
  1715. p.cw_min = params->cwmin;
  1716. p.txop = params->txop;
  1717. /*
  1718. * Setting tx queue params disables u-apsd because it's only
  1719. * called in master mode.
  1720. */
  1721. p.uapsd = false;
  1722. sdata->tx_conf[params->ac] = p;
  1723. if (drv_conf_tx(local, sdata, params->ac, &p)) {
  1724. wiphy_debug(local->hw.wiphy,
  1725. "failed to set TX queue parameters for AC %d\n",
  1726. params->ac);
  1727. return -EINVAL;
  1728. }
  1729. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  1730. return 0;
  1731. }
  1732. #ifdef CONFIG_PM
  1733. static int ieee80211_suspend(struct wiphy *wiphy,
  1734. struct cfg80211_wowlan *wowlan)
  1735. {
  1736. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1737. }
  1738. static int ieee80211_resume(struct wiphy *wiphy)
  1739. {
  1740. return __ieee80211_resume(wiphy_priv(wiphy));
  1741. }
  1742. #else
  1743. #define ieee80211_suspend NULL
  1744. #define ieee80211_resume NULL
  1745. #endif
  1746. static int ieee80211_scan(struct wiphy *wiphy,
  1747. struct cfg80211_scan_request *req)
  1748. {
  1749. struct ieee80211_sub_if_data *sdata;
  1750. sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
  1751. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1752. case NL80211_IFTYPE_STATION:
  1753. case NL80211_IFTYPE_ADHOC:
  1754. case NL80211_IFTYPE_MESH_POINT:
  1755. case NL80211_IFTYPE_P2P_CLIENT:
  1756. case NL80211_IFTYPE_P2P_DEVICE:
  1757. break;
  1758. case NL80211_IFTYPE_P2P_GO:
  1759. if (sdata->local->ops->hw_scan)
  1760. break;
  1761. /*
  1762. * FIXME: implement NoA while scanning in software,
  1763. * for now fall through to allow scanning only when
  1764. * beaconing hasn't been configured yet
  1765. */
  1766. case NL80211_IFTYPE_AP:
  1767. /*
  1768. * If the scan has been forced (and the driver supports
  1769. * forcing), don't care about being beaconing already.
  1770. * This will create problems to the attached stations (e.g. all
  1771. * the frames sent while scanning on other channel will be
  1772. * lost)
  1773. */
  1774. if (sdata->u.ap.beacon &&
  1775. (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
  1776. !(req->flags & NL80211_SCAN_FLAG_AP)))
  1777. return -EOPNOTSUPP;
  1778. break;
  1779. default:
  1780. return -EOPNOTSUPP;
  1781. }
  1782. return ieee80211_request_scan(sdata, req);
  1783. }
  1784. static int
  1785. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1786. struct net_device *dev,
  1787. struct cfg80211_sched_scan_request *req)
  1788. {
  1789. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1790. if (!sdata->local->ops->sched_scan_start)
  1791. return -EOPNOTSUPP;
  1792. return ieee80211_request_sched_scan_start(sdata, req);
  1793. }
  1794. static int
  1795. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1796. {
  1797. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1798. if (!sdata->local->ops->sched_scan_stop)
  1799. return -EOPNOTSUPP;
  1800. return ieee80211_request_sched_scan_stop(sdata);
  1801. }
  1802. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1803. struct cfg80211_auth_request *req)
  1804. {
  1805. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1806. }
  1807. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1808. struct cfg80211_assoc_request *req)
  1809. {
  1810. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1811. }
  1812. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1813. struct cfg80211_deauth_request *req)
  1814. {
  1815. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1816. }
  1817. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1818. struct cfg80211_disassoc_request *req)
  1819. {
  1820. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1821. }
  1822. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1823. struct cfg80211_ibss_params *params)
  1824. {
  1825. return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
  1826. }
  1827. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1828. {
  1829. return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1830. }
  1831. static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
  1832. int rate[IEEE80211_NUM_BANDS])
  1833. {
  1834. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1835. memcpy(sdata->vif.bss_conf.mcast_rate, rate,
  1836. sizeof(int) * IEEE80211_NUM_BANDS);
  1837. return 0;
  1838. }
  1839. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1840. {
  1841. struct ieee80211_local *local = wiphy_priv(wiphy);
  1842. int err;
  1843. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1844. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1845. if (err)
  1846. return err;
  1847. }
  1848. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1849. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1850. if (err)
  1851. return err;
  1852. }
  1853. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1854. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1855. if (err)
  1856. return err;
  1857. }
  1858. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  1859. if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
  1860. return -EINVAL;
  1861. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1862. }
  1863. if (changed & WIPHY_PARAM_RETRY_LONG) {
  1864. if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
  1865. return -EINVAL;
  1866. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1867. }
  1868. if (changed &
  1869. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1870. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1871. return 0;
  1872. }
  1873. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1874. struct wireless_dev *wdev,
  1875. enum nl80211_tx_power_setting type, int mbm)
  1876. {
  1877. struct ieee80211_local *local = wiphy_priv(wiphy);
  1878. struct ieee80211_sub_if_data *sdata;
  1879. if (wdev) {
  1880. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1881. switch (type) {
  1882. case NL80211_TX_POWER_AUTOMATIC:
  1883. sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1884. break;
  1885. case NL80211_TX_POWER_LIMITED:
  1886. case NL80211_TX_POWER_FIXED:
  1887. if (mbm < 0 || (mbm % 100))
  1888. return -EOPNOTSUPP;
  1889. sdata->user_power_level = MBM_TO_DBM(mbm);
  1890. break;
  1891. }
  1892. ieee80211_recalc_txpower(sdata);
  1893. return 0;
  1894. }
  1895. switch (type) {
  1896. case NL80211_TX_POWER_AUTOMATIC:
  1897. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1898. break;
  1899. case NL80211_TX_POWER_LIMITED:
  1900. case NL80211_TX_POWER_FIXED:
  1901. if (mbm < 0 || (mbm % 100))
  1902. return -EOPNOTSUPP;
  1903. local->user_power_level = MBM_TO_DBM(mbm);
  1904. break;
  1905. }
  1906. mutex_lock(&local->iflist_mtx);
  1907. list_for_each_entry(sdata, &local->interfaces, list)
  1908. sdata->user_power_level = local->user_power_level;
  1909. list_for_each_entry(sdata, &local->interfaces, list)
  1910. ieee80211_recalc_txpower(sdata);
  1911. mutex_unlock(&local->iflist_mtx);
  1912. return 0;
  1913. }
  1914. static int ieee80211_get_tx_power(struct wiphy *wiphy,
  1915. struct wireless_dev *wdev,
  1916. int *dbm)
  1917. {
  1918. struct ieee80211_local *local = wiphy_priv(wiphy);
  1919. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1920. if (!local->use_chanctx)
  1921. *dbm = local->hw.conf.power_level;
  1922. else
  1923. *dbm = sdata->vif.bss_conf.txpower;
  1924. return 0;
  1925. }
  1926. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1927. const u8 *addr)
  1928. {
  1929. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1930. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1931. return 0;
  1932. }
  1933. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1934. {
  1935. struct ieee80211_local *local = wiphy_priv(wiphy);
  1936. drv_rfkill_poll(local);
  1937. }
  1938. #ifdef CONFIG_NL80211_TESTMODE
  1939. static int ieee80211_testmode_cmd(struct wiphy *wiphy, 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 int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  2335. struct ieee80211_channel *chan, bool offchan,
  2336. unsigned int wait, const u8 *buf, size_t len,
  2337. bool no_cck, bool dont_wait_for_ack, u64 *cookie)
  2338. {
  2339. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2340. struct ieee80211_local *local = sdata->local;
  2341. struct sk_buff *skb;
  2342. struct sta_info *sta;
  2343. const struct ieee80211_mgmt *mgmt = (void *)buf;
  2344. bool need_offchan = false;
  2345. u32 flags;
  2346. int ret;
  2347. if (dont_wait_for_ack)
  2348. flags = IEEE80211_TX_CTL_NO_ACK;
  2349. else
  2350. flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  2351. IEEE80211_TX_CTL_REQ_TX_STATUS;
  2352. if (no_cck)
  2353. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  2354. switch (sdata->vif.type) {
  2355. case NL80211_IFTYPE_ADHOC:
  2356. if (!sdata->vif.bss_conf.ibss_joined)
  2357. need_offchan = true;
  2358. /* fall through */
  2359. #ifdef CONFIG_MAC80211_MESH
  2360. case NL80211_IFTYPE_MESH_POINT:
  2361. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  2362. !sdata->u.mesh.mesh_id_len)
  2363. need_offchan = true;
  2364. /* fall through */
  2365. #endif
  2366. case NL80211_IFTYPE_AP:
  2367. case NL80211_IFTYPE_AP_VLAN:
  2368. case NL80211_IFTYPE_P2P_GO:
  2369. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2370. !ieee80211_vif_is_mesh(&sdata->vif) &&
  2371. !rcu_access_pointer(sdata->bss->beacon))
  2372. need_offchan = true;
  2373. if (!ieee80211_is_action(mgmt->frame_control) ||
  2374. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
  2375. mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED)
  2376. break;
  2377. rcu_read_lock();
  2378. sta = sta_info_get(sdata, mgmt->da);
  2379. rcu_read_unlock();
  2380. if (!sta)
  2381. return -ENOLINK;
  2382. break;
  2383. case NL80211_IFTYPE_STATION:
  2384. case NL80211_IFTYPE_P2P_CLIENT:
  2385. if (!sdata->u.mgd.associated)
  2386. need_offchan = true;
  2387. break;
  2388. case NL80211_IFTYPE_P2P_DEVICE:
  2389. need_offchan = true;
  2390. break;
  2391. default:
  2392. return -EOPNOTSUPP;
  2393. }
  2394. /* configurations requiring offchan cannot work if no channel has been
  2395. * specified
  2396. */
  2397. if (need_offchan && !chan)
  2398. return -EINVAL;
  2399. mutex_lock(&local->mtx);
  2400. /* Check if the operating channel is the requested channel */
  2401. if (!need_offchan) {
  2402. struct ieee80211_chanctx_conf *chanctx_conf;
  2403. rcu_read_lock();
  2404. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2405. if (chanctx_conf) {
  2406. need_offchan = chan && (chan != chanctx_conf->def.chan);
  2407. } else if (!chan) {
  2408. ret = -EINVAL;
  2409. rcu_read_unlock();
  2410. goto out_unlock;
  2411. } else {
  2412. need_offchan = true;
  2413. }
  2414. rcu_read_unlock();
  2415. }
  2416. if (need_offchan && !offchan) {
  2417. ret = -EBUSY;
  2418. goto out_unlock;
  2419. }
  2420. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  2421. if (!skb) {
  2422. ret = -ENOMEM;
  2423. goto out_unlock;
  2424. }
  2425. skb_reserve(skb, local->hw.extra_tx_headroom);
  2426. memcpy(skb_put(skb, len), buf, len);
  2427. IEEE80211_SKB_CB(skb)->flags = flags;
  2428. skb->dev = sdata->dev;
  2429. if (!need_offchan) {
  2430. *cookie = (unsigned long) skb;
  2431. ieee80211_tx_skb(sdata, skb);
  2432. ret = 0;
  2433. goto out_unlock;
  2434. }
  2435. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
  2436. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  2437. if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
  2438. IEEE80211_SKB_CB(skb)->hw_queue =
  2439. local->hw.offchannel_tx_hw_queue;
  2440. /* This will handle all kinds of coalescing and immediate TX */
  2441. ret = ieee80211_start_roc_work(local, sdata, chan,
  2442. wait, cookie, skb,
  2443. IEEE80211_ROC_TYPE_MGMT_TX);
  2444. if (ret)
  2445. kfree_skb(skb);
  2446. out_unlock:
  2447. mutex_unlock(&local->mtx);
  2448. return ret;
  2449. }
  2450. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  2451. struct wireless_dev *wdev,
  2452. u64 cookie)
  2453. {
  2454. struct ieee80211_local *local = wiphy_priv(wiphy);
  2455. return ieee80211_cancel_roc(local, cookie, true);
  2456. }
  2457. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  2458. struct wireless_dev *wdev,
  2459. u16 frame_type, bool reg)
  2460. {
  2461. struct ieee80211_local *local = wiphy_priv(wiphy);
  2462. switch (frame_type) {
  2463. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
  2464. if (reg)
  2465. local->probe_req_reg++;
  2466. else
  2467. local->probe_req_reg--;
  2468. if (!local->open_count)
  2469. break;
  2470. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  2471. break;
  2472. default:
  2473. break;
  2474. }
  2475. }
  2476. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  2477. {
  2478. struct ieee80211_local *local = wiphy_priv(wiphy);
  2479. if (local->started)
  2480. return -EOPNOTSUPP;
  2481. return drv_set_antenna(local, tx_ant, rx_ant);
  2482. }
  2483. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  2484. {
  2485. struct ieee80211_local *local = wiphy_priv(wiphy);
  2486. return drv_get_antenna(local, tx_ant, rx_ant);
  2487. }
  2488. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  2489. {
  2490. struct ieee80211_local *local = wiphy_priv(wiphy);
  2491. return drv_set_ringparam(local, tx, rx);
  2492. }
  2493. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  2494. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  2495. {
  2496. struct ieee80211_local *local = wiphy_priv(wiphy);
  2497. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  2498. }
  2499. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  2500. struct net_device *dev,
  2501. struct cfg80211_gtk_rekey_data *data)
  2502. {
  2503. struct ieee80211_local *local = wiphy_priv(wiphy);
  2504. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2505. if (!local->ops->set_rekey_data)
  2506. return -EOPNOTSUPP;
  2507. drv_set_rekey_data(local, sdata, data);
  2508. return 0;
  2509. }
  2510. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  2511. {
  2512. u8 *pos = (void *)skb_put(skb, 7);
  2513. *pos++ = WLAN_EID_EXT_CAPABILITY;
  2514. *pos++ = 5; /* len */
  2515. *pos++ = 0x0;
  2516. *pos++ = 0x0;
  2517. *pos++ = 0x0;
  2518. *pos++ = 0x0;
  2519. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  2520. }
  2521. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  2522. {
  2523. struct ieee80211_local *local = sdata->local;
  2524. u16 capab;
  2525. capab = 0;
  2526. if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
  2527. return capab;
  2528. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  2529. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  2530. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  2531. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  2532. return capab;
  2533. }
  2534. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  2535. u8 *peer, u8 *bssid)
  2536. {
  2537. struct ieee80211_tdls_lnkie *lnkid;
  2538. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  2539. lnkid->ie_type = WLAN_EID_LINK_ID;
  2540. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  2541. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  2542. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  2543. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  2544. }
  2545. static int
  2546. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  2547. u8 *peer, u8 action_code, u8 dialog_token,
  2548. u16 status_code, struct sk_buff *skb)
  2549. {
  2550. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2551. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  2552. struct ieee80211_tdls_data *tf;
  2553. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  2554. memcpy(tf->da, peer, ETH_ALEN);
  2555. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  2556. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  2557. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  2558. switch (action_code) {
  2559. case WLAN_TDLS_SETUP_REQUEST:
  2560. tf->category = WLAN_CATEGORY_TDLS;
  2561. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  2562. skb_put(skb, sizeof(tf->u.setup_req));
  2563. tf->u.setup_req.dialog_token = dialog_token;
  2564. tf->u.setup_req.capability =
  2565. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2566. ieee80211_add_srates_ie(sdata, skb, false, band);
  2567. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2568. ieee80211_tdls_add_ext_capab(skb);
  2569. break;
  2570. case WLAN_TDLS_SETUP_RESPONSE:
  2571. tf->category = WLAN_CATEGORY_TDLS;
  2572. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  2573. skb_put(skb, sizeof(tf->u.setup_resp));
  2574. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  2575. tf->u.setup_resp.dialog_token = dialog_token;
  2576. tf->u.setup_resp.capability =
  2577. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2578. ieee80211_add_srates_ie(sdata, skb, false, band);
  2579. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2580. ieee80211_tdls_add_ext_capab(skb);
  2581. break;
  2582. case WLAN_TDLS_SETUP_CONFIRM:
  2583. tf->category = WLAN_CATEGORY_TDLS;
  2584. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  2585. skb_put(skb, sizeof(tf->u.setup_cfm));
  2586. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  2587. tf->u.setup_cfm.dialog_token = dialog_token;
  2588. break;
  2589. case WLAN_TDLS_TEARDOWN:
  2590. tf->category = WLAN_CATEGORY_TDLS;
  2591. tf->action_code = WLAN_TDLS_TEARDOWN;
  2592. skb_put(skb, sizeof(tf->u.teardown));
  2593. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  2594. break;
  2595. case WLAN_TDLS_DISCOVERY_REQUEST:
  2596. tf->category = WLAN_CATEGORY_TDLS;
  2597. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  2598. skb_put(skb, sizeof(tf->u.discover_req));
  2599. tf->u.discover_req.dialog_token = dialog_token;
  2600. break;
  2601. default:
  2602. return -EINVAL;
  2603. }
  2604. return 0;
  2605. }
  2606. static int
  2607. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  2608. u8 *peer, u8 action_code, u8 dialog_token,
  2609. u16 status_code, struct sk_buff *skb)
  2610. {
  2611. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2612. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  2613. struct ieee80211_mgmt *mgmt;
  2614. mgmt = (void *)skb_put(skb, 24);
  2615. memset(mgmt, 0, 24);
  2616. memcpy(mgmt->da, peer, ETH_ALEN);
  2617. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  2618. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  2619. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2620. IEEE80211_STYPE_ACTION);
  2621. switch (action_code) {
  2622. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2623. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  2624. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  2625. mgmt->u.action.u.tdls_discover_resp.action_code =
  2626. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  2627. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  2628. dialog_token;
  2629. mgmt->u.action.u.tdls_discover_resp.capability =
  2630. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2631. ieee80211_add_srates_ie(sdata, skb, false, band);
  2632. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2633. ieee80211_tdls_add_ext_capab(skb);
  2634. break;
  2635. default:
  2636. return -EINVAL;
  2637. }
  2638. return 0;
  2639. }
  2640. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2641. u8 *peer, u8 action_code, u8 dialog_token,
  2642. u16 status_code, const u8 *extra_ies,
  2643. size_t extra_ies_len)
  2644. {
  2645. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2646. struct ieee80211_local *local = sdata->local;
  2647. struct sk_buff *skb = NULL;
  2648. bool send_direct;
  2649. int ret;
  2650. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2651. return -ENOTSUPP;
  2652. /* make sure we are in managed mode, and associated */
  2653. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  2654. !sdata->u.mgd.associated)
  2655. return -EINVAL;
  2656. tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
  2657. action_code, peer);
  2658. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  2659. max(sizeof(struct ieee80211_mgmt),
  2660. sizeof(struct ieee80211_tdls_data)) +
  2661. 50 + /* supported rates */
  2662. 7 + /* ext capab */
  2663. extra_ies_len +
  2664. sizeof(struct ieee80211_tdls_lnkie));
  2665. if (!skb)
  2666. return -ENOMEM;
  2667. skb_reserve(skb, local->hw.extra_tx_headroom);
  2668. switch (action_code) {
  2669. case WLAN_TDLS_SETUP_REQUEST:
  2670. case WLAN_TDLS_SETUP_RESPONSE:
  2671. case WLAN_TDLS_SETUP_CONFIRM:
  2672. case WLAN_TDLS_TEARDOWN:
  2673. case WLAN_TDLS_DISCOVERY_REQUEST:
  2674. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  2675. action_code, dialog_token,
  2676. status_code, skb);
  2677. send_direct = false;
  2678. break;
  2679. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2680. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  2681. dialog_token, status_code,
  2682. skb);
  2683. send_direct = true;
  2684. break;
  2685. default:
  2686. ret = -ENOTSUPP;
  2687. break;
  2688. }
  2689. if (ret < 0)
  2690. goto fail;
  2691. if (extra_ies_len)
  2692. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  2693. /* the TDLS link IE is always added last */
  2694. switch (action_code) {
  2695. case WLAN_TDLS_SETUP_REQUEST:
  2696. case WLAN_TDLS_SETUP_CONFIRM:
  2697. case WLAN_TDLS_TEARDOWN:
  2698. case WLAN_TDLS_DISCOVERY_REQUEST:
  2699. /* we are the initiator */
  2700. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  2701. sdata->u.mgd.bssid);
  2702. break;
  2703. case WLAN_TDLS_SETUP_RESPONSE:
  2704. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2705. /* we are the responder */
  2706. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  2707. sdata->u.mgd.bssid);
  2708. break;
  2709. default:
  2710. ret = -ENOTSUPP;
  2711. goto fail;
  2712. }
  2713. if (send_direct) {
  2714. ieee80211_tx_skb(sdata, skb);
  2715. return 0;
  2716. }
  2717. /*
  2718. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  2719. * we should default to AC_VI.
  2720. */
  2721. switch (action_code) {
  2722. case WLAN_TDLS_SETUP_REQUEST:
  2723. case WLAN_TDLS_SETUP_RESPONSE:
  2724. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  2725. skb->priority = 2;
  2726. break;
  2727. default:
  2728. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  2729. skb->priority = 5;
  2730. break;
  2731. }
  2732. /* disable bottom halves when entering the Tx path */
  2733. local_bh_disable();
  2734. ret = ieee80211_subif_start_xmit(skb, dev);
  2735. local_bh_enable();
  2736. return ret;
  2737. fail:
  2738. dev_kfree_skb(skb);
  2739. return ret;
  2740. }
  2741. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2742. u8 *peer, enum nl80211_tdls_operation oper)
  2743. {
  2744. struct sta_info *sta;
  2745. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2746. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2747. return -ENOTSUPP;
  2748. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2749. return -EINVAL;
  2750. tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
  2751. switch (oper) {
  2752. case NL80211_TDLS_ENABLE_LINK:
  2753. rcu_read_lock();
  2754. sta = sta_info_get(sdata, peer);
  2755. if (!sta) {
  2756. rcu_read_unlock();
  2757. return -ENOLINK;
  2758. }
  2759. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2760. rcu_read_unlock();
  2761. break;
  2762. case NL80211_TDLS_DISABLE_LINK:
  2763. return sta_info_destroy_addr(sdata, peer);
  2764. case NL80211_TDLS_TEARDOWN:
  2765. case NL80211_TDLS_SETUP:
  2766. case NL80211_TDLS_DISCOVERY_REQ:
  2767. /* We don't support in-driver setup/teardown/discovery */
  2768. return -ENOTSUPP;
  2769. default:
  2770. return -ENOTSUPP;
  2771. }
  2772. return 0;
  2773. }
  2774. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2775. const u8 *peer, u64 *cookie)
  2776. {
  2777. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2778. struct ieee80211_local *local = sdata->local;
  2779. struct ieee80211_qos_hdr *nullfunc;
  2780. struct sk_buff *skb;
  2781. int size = sizeof(*nullfunc);
  2782. __le16 fc;
  2783. bool qos;
  2784. struct ieee80211_tx_info *info;
  2785. struct sta_info *sta;
  2786. struct ieee80211_chanctx_conf *chanctx_conf;
  2787. enum ieee80211_band band;
  2788. rcu_read_lock();
  2789. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2790. if (WARN_ON(!chanctx_conf)) {
  2791. rcu_read_unlock();
  2792. return -EINVAL;
  2793. }
  2794. band = chanctx_conf->def.chan->band;
  2795. sta = sta_info_get(sdata, peer);
  2796. if (sta) {
  2797. qos = test_sta_flag(sta, WLAN_STA_WME);
  2798. } else {
  2799. rcu_read_unlock();
  2800. return -ENOLINK;
  2801. }
  2802. if (qos) {
  2803. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2804. IEEE80211_STYPE_QOS_NULLFUNC |
  2805. IEEE80211_FCTL_FROMDS);
  2806. } else {
  2807. size -= 2;
  2808. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2809. IEEE80211_STYPE_NULLFUNC |
  2810. IEEE80211_FCTL_FROMDS);
  2811. }
  2812. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2813. if (!skb) {
  2814. rcu_read_unlock();
  2815. return -ENOMEM;
  2816. }
  2817. skb->dev = dev;
  2818. skb_reserve(skb, local->hw.extra_tx_headroom);
  2819. nullfunc = (void *) skb_put(skb, size);
  2820. nullfunc->frame_control = fc;
  2821. nullfunc->duration_id = 0;
  2822. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2823. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2824. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2825. nullfunc->seq_ctrl = 0;
  2826. info = IEEE80211_SKB_CB(skb);
  2827. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2828. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2829. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2830. skb->priority = 7;
  2831. if (qos)
  2832. nullfunc->qos_ctrl = cpu_to_le16(7);
  2833. local_bh_disable();
  2834. ieee80211_xmit(sdata, skb, band);
  2835. local_bh_enable();
  2836. rcu_read_unlock();
  2837. *cookie = (unsigned long) skb;
  2838. return 0;
  2839. }
  2840. static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  2841. struct wireless_dev *wdev,
  2842. struct cfg80211_chan_def *chandef)
  2843. {
  2844. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2845. struct ieee80211_local *local = wiphy_priv(wiphy);
  2846. struct ieee80211_chanctx_conf *chanctx_conf;
  2847. int ret = -ENODATA;
  2848. rcu_read_lock();
  2849. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2850. if (chanctx_conf) {
  2851. *chandef = chanctx_conf->def;
  2852. ret = 0;
  2853. } else if (local->open_count > 0 &&
  2854. local->open_count == local->monitors &&
  2855. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2856. if (local->use_chanctx)
  2857. *chandef = local->monitor_chandef;
  2858. else
  2859. *chandef = local->_oper_chandef;
  2860. ret = 0;
  2861. }
  2862. rcu_read_unlock();
  2863. return ret;
  2864. }
  2865. #ifdef CONFIG_PM
  2866. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  2867. {
  2868. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  2869. }
  2870. #endif
  2871. struct cfg80211_ops mac80211_config_ops = {
  2872. .add_virtual_intf = ieee80211_add_iface,
  2873. .del_virtual_intf = ieee80211_del_iface,
  2874. .change_virtual_intf = ieee80211_change_iface,
  2875. .start_p2p_device = ieee80211_start_p2p_device,
  2876. .stop_p2p_device = ieee80211_stop_p2p_device,
  2877. .add_key = ieee80211_add_key,
  2878. .del_key = ieee80211_del_key,
  2879. .get_key = ieee80211_get_key,
  2880. .set_default_key = ieee80211_config_default_key,
  2881. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2882. .start_ap = ieee80211_start_ap,
  2883. .change_beacon = ieee80211_change_beacon,
  2884. .stop_ap = ieee80211_stop_ap,
  2885. .add_station = ieee80211_add_station,
  2886. .del_station = ieee80211_del_station,
  2887. .change_station = ieee80211_change_station,
  2888. .get_station = ieee80211_get_station,
  2889. .dump_station = ieee80211_dump_station,
  2890. .dump_survey = ieee80211_dump_survey,
  2891. #ifdef CONFIG_MAC80211_MESH
  2892. .add_mpath = ieee80211_add_mpath,
  2893. .del_mpath = ieee80211_del_mpath,
  2894. .change_mpath = ieee80211_change_mpath,
  2895. .get_mpath = ieee80211_get_mpath,
  2896. .dump_mpath = ieee80211_dump_mpath,
  2897. .update_mesh_config = ieee80211_update_mesh_config,
  2898. .get_mesh_config = ieee80211_get_mesh_config,
  2899. .join_mesh = ieee80211_join_mesh,
  2900. .leave_mesh = ieee80211_leave_mesh,
  2901. #endif
  2902. .change_bss = ieee80211_change_bss,
  2903. .set_txq_params = ieee80211_set_txq_params,
  2904. .set_monitor_channel = ieee80211_set_monitor_channel,
  2905. .suspend = ieee80211_suspend,
  2906. .resume = ieee80211_resume,
  2907. .scan = ieee80211_scan,
  2908. .sched_scan_start = ieee80211_sched_scan_start,
  2909. .sched_scan_stop = ieee80211_sched_scan_stop,
  2910. .auth = ieee80211_auth,
  2911. .assoc = ieee80211_assoc,
  2912. .deauth = ieee80211_deauth,
  2913. .disassoc = ieee80211_disassoc,
  2914. .join_ibss = ieee80211_join_ibss,
  2915. .leave_ibss = ieee80211_leave_ibss,
  2916. .set_mcast_rate = ieee80211_set_mcast_rate,
  2917. .set_wiphy_params = ieee80211_set_wiphy_params,
  2918. .set_tx_power = ieee80211_set_tx_power,
  2919. .get_tx_power = ieee80211_get_tx_power,
  2920. .set_wds_peer = ieee80211_set_wds_peer,
  2921. .rfkill_poll = ieee80211_rfkill_poll,
  2922. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2923. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2924. .set_power_mgmt = ieee80211_set_power_mgmt,
  2925. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2926. .remain_on_channel = ieee80211_remain_on_channel,
  2927. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2928. .mgmt_tx = ieee80211_mgmt_tx,
  2929. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2930. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2931. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2932. .set_antenna = ieee80211_set_antenna,
  2933. .get_antenna = ieee80211_get_antenna,
  2934. .set_ringparam = ieee80211_set_ringparam,
  2935. .get_ringparam = ieee80211_get_ringparam,
  2936. .set_rekey_data = ieee80211_set_rekey_data,
  2937. .tdls_oper = ieee80211_tdls_oper,
  2938. .tdls_mgmt = ieee80211_tdls_mgmt,
  2939. .probe_client = ieee80211_probe_client,
  2940. .set_noack_map = ieee80211_set_noack_map,
  2941. #ifdef CONFIG_PM
  2942. .set_wakeup = ieee80211_set_wakeup,
  2943. #endif
  2944. .get_et_sset_count = ieee80211_get_et_sset_count,
  2945. .get_et_stats = ieee80211_get_et_stats,
  2946. .get_et_strings = ieee80211_get_et_strings,
  2947. .get_channel = ieee80211_cfg_get_channel,
  2948. .start_radar_detection = ieee80211_start_radar_detection,
  2949. };