cfg.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500
  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. i = 0;
  574. ADD_STA_STATS(sta);
  575. }
  576. }
  577. do_survey:
  578. i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
  579. /* Get survey stats for current channel */
  580. survey.filled = 0;
  581. rcu_read_lock();
  582. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  583. if (chanctx_conf)
  584. channel = chanctx_conf->def.chan;
  585. else
  586. channel = NULL;
  587. rcu_read_unlock();
  588. if (channel) {
  589. q = 0;
  590. do {
  591. survey.filled = 0;
  592. if (drv_get_survey(local, q, &survey) != 0) {
  593. survey.filled = 0;
  594. break;
  595. }
  596. q++;
  597. } while (channel != survey.channel);
  598. }
  599. if (survey.filled)
  600. data[i++] = survey.channel->center_freq;
  601. else
  602. data[i++] = 0;
  603. if (survey.filled & SURVEY_INFO_NOISE_DBM)
  604. data[i++] = (u8)survey.noise;
  605. else
  606. data[i++] = -1LL;
  607. if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
  608. data[i++] = survey.channel_time;
  609. else
  610. data[i++] = -1LL;
  611. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
  612. data[i++] = survey.channel_time_busy;
  613. else
  614. data[i++] = -1LL;
  615. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
  616. data[i++] = survey.channel_time_ext_busy;
  617. else
  618. data[i++] = -1LL;
  619. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
  620. data[i++] = survey.channel_time_rx;
  621. else
  622. data[i++] = -1LL;
  623. if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
  624. data[i++] = survey.channel_time_tx;
  625. else
  626. data[i++] = -1LL;
  627. mutex_unlock(&local->sta_mtx);
  628. if (WARN_ON(i != STA_STATS_LEN))
  629. return;
  630. drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
  631. }
  632. static void ieee80211_get_et_strings(struct wiphy *wiphy,
  633. struct net_device *dev,
  634. u32 sset, u8 *data)
  635. {
  636. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  637. int sz_sta_stats = 0;
  638. if (sset == ETH_SS_STATS) {
  639. sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
  640. memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
  641. }
  642. drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
  643. }
  644. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  645. int idx, u8 *mac, struct station_info *sinfo)
  646. {
  647. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  648. struct ieee80211_local *local = sdata->local;
  649. struct sta_info *sta;
  650. int ret = -ENOENT;
  651. mutex_lock(&local->sta_mtx);
  652. sta = sta_info_get_by_idx(sdata, idx);
  653. if (sta) {
  654. ret = 0;
  655. memcpy(mac, sta->sta.addr, ETH_ALEN);
  656. sta_set_sinfo(sta, sinfo);
  657. }
  658. mutex_unlock(&local->sta_mtx);
  659. return ret;
  660. }
  661. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  662. int idx, struct survey_info *survey)
  663. {
  664. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  665. return drv_get_survey(local, idx, survey);
  666. }
  667. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  668. u8 *mac, struct station_info *sinfo)
  669. {
  670. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  671. struct ieee80211_local *local = sdata->local;
  672. struct sta_info *sta;
  673. int ret = -ENOENT;
  674. mutex_lock(&local->sta_mtx);
  675. sta = sta_info_get_bss(sdata, mac);
  676. if (sta) {
  677. ret = 0;
  678. sta_set_sinfo(sta, sinfo);
  679. }
  680. mutex_unlock(&local->sta_mtx);
  681. return ret;
  682. }
  683. static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  684. struct cfg80211_chan_def *chandef)
  685. {
  686. struct ieee80211_local *local = wiphy_priv(wiphy);
  687. struct ieee80211_sub_if_data *sdata;
  688. int ret = 0;
  689. if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
  690. return 0;
  691. mutex_lock(&local->iflist_mtx);
  692. if (local->use_chanctx) {
  693. sdata = rcu_dereference_protected(
  694. local->monitor_sdata,
  695. lockdep_is_held(&local->iflist_mtx));
  696. if (sdata) {
  697. ieee80211_vif_release_channel(sdata);
  698. ret = ieee80211_vif_use_channel(sdata, chandef,
  699. IEEE80211_CHANCTX_EXCLUSIVE);
  700. }
  701. } else if (local->open_count == local->monitors) {
  702. local->_oper_chandef = *chandef;
  703. ieee80211_hw_config(local, 0);
  704. }
  705. if (ret == 0)
  706. local->monitor_chandef = *chandef;
  707. mutex_unlock(&local->iflist_mtx);
  708. return ret;
  709. }
  710. static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
  711. const u8 *resp, size_t resp_len)
  712. {
  713. struct probe_resp *new, *old;
  714. if (!resp || !resp_len)
  715. return 1;
  716. old = rtnl_dereference(sdata->u.ap.probe_resp);
  717. new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
  718. if (!new)
  719. return -ENOMEM;
  720. new->len = resp_len;
  721. memcpy(new->data, resp, resp_len);
  722. rcu_assign_pointer(sdata->u.ap.probe_resp, new);
  723. if (old)
  724. kfree_rcu(old, rcu_head);
  725. return 0;
  726. }
  727. static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
  728. struct cfg80211_beacon_data *params)
  729. {
  730. struct beacon_data *new, *old;
  731. int new_head_len, new_tail_len;
  732. int size, err;
  733. u32 changed = BSS_CHANGED_BEACON;
  734. old = rtnl_dereference(sdata->u.ap.beacon);
  735. /* Need to have a beacon head if we don't have one yet */
  736. if (!params->head && !old)
  737. return -EINVAL;
  738. /* new or old head? */
  739. if (params->head)
  740. new_head_len = params->head_len;
  741. else
  742. new_head_len = old->head_len;
  743. /* new or old tail? */
  744. if (params->tail || !old)
  745. /* params->tail_len will be zero for !params->tail */
  746. new_tail_len = params->tail_len;
  747. else
  748. new_tail_len = old->tail_len;
  749. size = sizeof(*new) + new_head_len + new_tail_len;
  750. new = kzalloc(size, GFP_KERNEL);
  751. if (!new)
  752. return -ENOMEM;
  753. /* start filling the new info now */
  754. /*
  755. * pointers go into the block we allocated,
  756. * memory is | beacon_data | head | tail |
  757. */
  758. new->head = ((u8 *) new) + sizeof(*new);
  759. new->tail = new->head + new_head_len;
  760. new->head_len = new_head_len;
  761. new->tail_len = new_tail_len;
  762. /* copy in head */
  763. if (params->head)
  764. memcpy(new->head, params->head, new_head_len);
  765. else
  766. memcpy(new->head, old->head, new_head_len);
  767. /* copy in optional tail */
  768. if (params->tail)
  769. memcpy(new->tail, params->tail, new_tail_len);
  770. else
  771. if (old)
  772. memcpy(new->tail, old->tail, new_tail_len);
  773. err = ieee80211_set_probe_resp(sdata, params->probe_resp,
  774. params->probe_resp_len);
  775. if (err < 0)
  776. return err;
  777. if (err == 0)
  778. changed |= BSS_CHANGED_AP_PROBE_RESP;
  779. rcu_assign_pointer(sdata->u.ap.beacon, new);
  780. if (old)
  781. kfree_rcu(old, rcu_head);
  782. return changed;
  783. }
  784. static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
  785. struct cfg80211_ap_settings *params)
  786. {
  787. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  788. struct beacon_data *old;
  789. struct ieee80211_sub_if_data *vlan;
  790. u32 changed = BSS_CHANGED_BEACON_INT |
  791. BSS_CHANGED_BEACON_ENABLED |
  792. BSS_CHANGED_BEACON |
  793. BSS_CHANGED_SSID |
  794. BSS_CHANGED_P2P_PS;
  795. int err;
  796. old = rtnl_dereference(sdata->u.ap.beacon);
  797. if (old)
  798. return -EALREADY;
  799. /* TODO: make hostapd tell us what it wants */
  800. sdata->smps_mode = IEEE80211_SMPS_OFF;
  801. sdata->needed_rx_chains = sdata->local->rx_chains;
  802. sdata->radar_required = params->radar_required;
  803. err = ieee80211_vif_use_channel(sdata, &params->chandef,
  804. IEEE80211_CHANCTX_SHARED);
  805. if (err)
  806. return err;
  807. ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
  808. /*
  809. * Apply control port protocol, this allows us to
  810. * not encrypt dynamic WEP control frames.
  811. */
  812. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  813. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  814. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  815. vlan->control_port_protocol =
  816. params->crypto.control_port_ethertype;
  817. vlan->control_port_no_encrypt =
  818. params->crypto.control_port_no_encrypt;
  819. }
  820. sdata->vif.bss_conf.beacon_int = params->beacon_interval;
  821. sdata->vif.bss_conf.dtim_period = params->dtim_period;
  822. sdata->vif.bss_conf.enable_beacon = true;
  823. sdata->vif.bss_conf.ssid_len = params->ssid_len;
  824. if (params->ssid_len)
  825. memcpy(sdata->vif.bss_conf.ssid, params->ssid,
  826. params->ssid_len);
  827. sdata->vif.bss_conf.hidden_ssid =
  828. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  829. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  830. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  831. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
  832. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  833. if (params->p2p_opp_ps)
  834. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  835. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  836. err = ieee80211_assign_beacon(sdata, &params->beacon);
  837. if (err < 0)
  838. return err;
  839. changed |= err;
  840. err = drv_start_ap(sdata->local, sdata);
  841. if (err) {
  842. old = rtnl_dereference(sdata->u.ap.beacon);
  843. if (old)
  844. kfree_rcu(old, rcu_head);
  845. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  846. return err;
  847. }
  848. ieee80211_bss_info_change_notify(sdata, changed);
  849. netif_carrier_on(dev);
  850. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  851. netif_carrier_on(vlan->dev);
  852. return 0;
  853. }
  854. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  855. struct cfg80211_beacon_data *params)
  856. {
  857. struct ieee80211_sub_if_data *sdata;
  858. struct beacon_data *old;
  859. int err;
  860. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  861. old = rtnl_dereference(sdata->u.ap.beacon);
  862. if (!old)
  863. return -ENOENT;
  864. err = ieee80211_assign_beacon(sdata, params);
  865. if (err < 0)
  866. return err;
  867. ieee80211_bss_info_change_notify(sdata, err);
  868. return 0;
  869. }
  870. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  871. {
  872. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  873. struct ieee80211_sub_if_data *vlan;
  874. struct ieee80211_local *local = sdata->local;
  875. struct beacon_data *old_beacon;
  876. struct probe_resp *old_probe_resp;
  877. old_beacon = rtnl_dereference(sdata->u.ap.beacon);
  878. if (!old_beacon)
  879. return -ENOENT;
  880. old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
  881. /* turn off carrier for this interface and dependent VLANs */
  882. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  883. netif_carrier_off(vlan->dev);
  884. netif_carrier_off(dev);
  885. /* remove beacon and probe response */
  886. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  887. RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
  888. kfree_rcu(old_beacon, rcu_head);
  889. if (old_probe_resp)
  890. kfree_rcu(old_probe_resp, rcu_head);
  891. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  892. sta_info_flush_defer(vlan);
  893. sta_info_flush_defer(sdata);
  894. synchronize_net();
  895. rcu_barrier();
  896. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  897. sta_info_flush_cleanup(vlan);
  898. ieee80211_free_keys(vlan);
  899. }
  900. sta_info_flush_cleanup(sdata);
  901. ieee80211_free_keys(sdata);
  902. sdata->vif.bss_conf.enable_beacon = false;
  903. sdata->vif.bss_conf.ssid_len = 0;
  904. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  905. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  906. if (sdata->wdev.cac_started) {
  907. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  908. cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
  909. GFP_KERNEL);
  910. }
  911. drv_stop_ap(sdata->local, sdata);
  912. /* free all potentially still buffered bcast frames */
  913. local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
  914. skb_queue_purge(&sdata->u.ap.ps.bc_buf);
  915. ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
  916. ieee80211_vif_release_channel(sdata);
  917. return 0;
  918. }
  919. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  920. struct iapp_layer2_update {
  921. u8 da[ETH_ALEN]; /* broadcast */
  922. u8 sa[ETH_ALEN]; /* STA addr */
  923. __be16 len; /* 6 */
  924. u8 dsap; /* 0 */
  925. u8 ssap; /* 0 */
  926. u8 control;
  927. u8 xid_info[3];
  928. } __packed;
  929. static void ieee80211_send_layer2_update(struct sta_info *sta)
  930. {
  931. struct iapp_layer2_update *msg;
  932. struct sk_buff *skb;
  933. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  934. * bridge devices */
  935. skb = dev_alloc_skb(sizeof(*msg));
  936. if (!skb)
  937. return;
  938. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  939. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  940. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  941. eth_broadcast_addr(msg->da);
  942. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  943. msg->len = htons(6);
  944. msg->dsap = 0;
  945. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  946. msg->control = 0xaf; /* XID response lsb.1111F101.
  947. * F=0 (no poll command; unsolicited frame) */
  948. msg->xid_info[0] = 0x81; /* XID format identifier */
  949. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  950. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  951. skb->dev = sta->sdata->dev;
  952. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  953. memset(skb->cb, 0, sizeof(skb->cb));
  954. netif_rx_ni(skb);
  955. }
  956. static int sta_apply_auth_flags(struct ieee80211_local *local,
  957. struct sta_info *sta,
  958. u32 mask, u32 set)
  959. {
  960. int ret;
  961. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  962. set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  963. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  964. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  965. if (ret)
  966. return ret;
  967. }
  968. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  969. set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  970. !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  971. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  972. if (ret)
  973. return ret;
  974. }
  975. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  976. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  977. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  978. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  979. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  980. else
  981. ret = 0;
  982. if (ret)
  983. return ret;
  984. }
  985. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  986. !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  987. test_sta_flag(sta, WLAN_STA_ASSOC)) {
  988. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  989. if (ret)
  990. return ret;
  991. }
  992. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  993. !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  994. test_sta_flag(sta, WLAN_STA_AUTH)) {
  995. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  996. if (ret)
  997. return ret;
  998. }
  999. return 0;
  1000. }
  1001. static int sta_apply_parameters(struct ieee80211_local *local,
  1002. struct sta_info *sta,
  1003. struct station_parameters *params)
  1004. {
  1005. int ret = 0;
  1006. u32 rates;
  1007. int i, j;
  1008. struct ieee80211_supported_band *sband;
  1009. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1010. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  1011. u32 mask, set;
  1012. sband = local->hw.wiphy->bands[band];
  1013. mask = params->sta_flags_mask;
  1014. set = params->sta_flags_set;
  1015. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1016. /*
  1017. * In mesh mode, ASSOCIATED isn't part of the nl80211
  1018. * API but must follow AUTHENTICATED for driver state.
  1019. */
  1020. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1021. mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1022. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1023. set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1024. } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1025. /*
  1026. * TDLS -- everything follows authorized, but
  1027. * only becoming authorized is possible, not
  1028. * going back
  1029. */
  1030. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1031. set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1032. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1033. mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1034. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1035. }
  1036. }
  1037. ret = sta_apply_auth_flags(local, sta, mask, set);
  1038. if (ret)
  1039. return ret;
  1040. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  1041. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  1042. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1043. else
  1044. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1045. }
  1046. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  1047. if (set & BIT(NL80211_STA_FLAG_WME)) {
  1048. set_sta_flag(sta, WLAN_STA_WME);
  1049. sta->sta.wme = true;
  1050. } else {
  1051. clear_sta_flag(sta, WLAN_STA_WME);
  1052. sta->sta.wme = false;
  1053. }
  1054. }
  1055. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  1056. if (set & BIT(NL80211_STA_FLAG_MFP))
  1057. set_sta_flag(sta, WLAN_STA_MFP);
  1058. else
  1059. clear_sta_flag(sta, WLAN_STA_MFP);
  1060. }
  1061. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  1062. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1063. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1064. else
  1065. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1066. }
  1067. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  1068. sta->sta.uapsd_queues = params->uapsd_queues;
  1069. sta->sta.max_sp = params->max_sp;
  1070. }
  1071. /*
  1072. * cfg80211 validates this (1-2007) and allows setting the AID
  1073. * only when creating a new station entry
  1074. */
  1075. if (params->aid)
  1076. sta->sta.aid = params->aid;
  1077. /*
  1078. * Some of the following updates would be racy if called on an
  1079. * existing station, via ieee80211_change_station(). However,
  1080. * all such changes are rejected by cfg80211 except for updates
  1081. * changing the supported rates on an existing but not yet used
  1082. * TDLS peer.
  1083. */
  1084. if (params->listen_interval >= 0)
  1085. sta->listen_interval = params->listen_interval;
  1086. if (params->supported_rates) {
  1087. rates = 0;
  1088. for (i = 0; i < params->supported_rates_len; i++) {
  1089. int rate = (params->supported_rates[i] & 0x7f) * 5;
  1090. for (j = 0; j < sband->n_bitrates; j++) {
  1091. if (sband->bitrates[j].bitrate == rate)
  1092. rates |= BIT(j);
  1093. }
  1094. }
  1095. sta->sta.supp_rates[band] = rates;
  1096. }
  1097. if (params->ht_capa)
  1098. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  1099. params->ht_capa, sta);
  1100. if (params->vht_capa)
  1101. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  1102. params->vht_capa, sta);
  1103. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1104. #ifdef CONFIG_MAC80211_MESH
  1105. u32 changed = 0;
  1106. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
  1107. switch (params->plink_state) {
  1108. case NL80211_PLINK_ESTAB:
  1109. if (sta->plink_state != NL80211_PLINK_ESTAB)
  1110. changed = mesh_plink_inc_estab_count(
  1111. sdata);
  1112. sta->plink_state = params->plink_state;
  1113. ieee80211_mps_sta_status_update(sta);
  1114. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1115. sdata->u.mesh.mshcfg.power_mode);
  1116. break;
  1117. case NL80211_PLINK_LISTEN:
  1118. case NL80211_PLINK_BLOCKED:
  1119. case NL80211_PLINK_OPN_SNT:
  1120. case NL80211_PLINK_OPN_RCVD:
  1121. case NL80211_PLINK_CNF_RCVD:
  1122. case NL80211_PLINK_HOLDING:
  1123. if (sta->plink_state == NL80211_PLINK_ESTAB)
  1124. changed = mesh_plink_dec_estab_count(
  1125. sdata);
  1126. sta->plink_state = params->plink_state;
  1127. ieee80211_mps_sta_status_update(sta);
  1128. changed |=
  1129. ieee80211_mps_local_status_update(sdata);
  1130. break;
  1131. default:
  1132. /* nothing */
  1133. break;
  1134. }
  1135. }
  1136. switch (params->plink_action) {
  1137. case NL80211_PLINK_ACTION_NO_ACTION:
  1138. /* nothing */
  1139. break;
  1140. case NL80211_PLINK_ACTION_OPEN:
  1141. changed |= mesh_plink_open(sta);
  1142. break;
  1143. case NL80211_PLINK_ACTION_BLOCK:
  1144. changed |= mesh_plink_block(sta);
  1145. break;
  1146. }
  1147. if (params->local_pm)
  1148. changed |=
  1149. ieee80211_mps_set_sta_local_pm(sta,
  1150. params->local_pm);
  1151. ieee80211_bss_info_change_notify(sdata, changed);
  1152. #endif
  1153. }
  1154. return 0;
  1155. }
  1156. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  1157. u8 *mac, struct station_parameters *params)
  1158. {
  1159. struct ieee80211_local *local = wiphy_priv(wiphy);
  1160. struct sta_info *sta;
  1161. struct ieee80211_sub_if_data *sdata;
  1162. int err;
  1163. int layer2_update;
  1164. if (params->vlan) {
  1165. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1166. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1167. sdata->vif.type != NL80211_IFTYPE_AP)
  1168. return -EINVAL;
  1169. } else
  1170. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1171. if (ether_addr_equal(mac, sdata->vif.addr))
  1172. return -EINVAL;
  1173. if (is_multicast_ether_addr(mac))
  1174. return -EINVAL;
  1175. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  1176. if (!sta)
  1177. return -ENOMEM;
  1178. /*
  1179. * defaults -- if userspace wants something else we'll
  1180. * change it accordingly in sta_apply_parameters()
  1181. */
  1182. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
  1183. sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
  1184. sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
  1185. }
  1186. err = sta_apply_parameters(local, sta, params);
  1187. if (err) {
  1188. sta_info_free(local, sta);
  1189. return err;
  1190. }
  1191. /*
  1192. * for TDLS, rate control should be initialized only when
  1193. * rates are known and station is marked authorized
  1194. */
  1195. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  1196. rate_control_rate_init(sta);
  1197. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1198. sdata->vif.type == NL80211_IFTYPE_AP;
  1199. err = sta_info_insert_rcu(sta);
  1200. if (err) {
  1201. rcu_read_unlock();
  1202. return err;
  1203. }
  1204. if (layer2_update)
  1205. ieee80211_send_layer2_update(sta);
  1206. rcu_read_unlock();
  1207. return 0;
  1208. }
  1209. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1210. u8 *mac)
  1211. {
  1212. struct ieee80211_sub_if_data *sdata;
  1213. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1214. if (mac)
  1215. return sta_info_destroy_addr_bss(sdata, mac);
  1216. sta_info_flush(sdata);
  1217. return 0;
  1218. }
  1219. static int ieee80211_change_station(struct wiphy *wiphy,
  1220. struct net_device *dev, u8 *mac,
  1221. struct station_parameters *params)
  1222. {
  1223. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1224. struct ieee80211_local *local = wiphy_priv(wiphy);
  1225. struct sta_info *sta;
  1226. struct ieee80211_sub_if_data *vlansdata;
  1227. enum cfg80211_station_type statype;
  1228. int err;
  1229. mutex_lock(&local->sta_mtx);
  1230. sta = sta_info_get_bss(sdata, mac);
  1231. if (!sta) {
  1232. err = -ENOENT;
  1233. goto out_err;
  1234. }
  1235. switch (sdata->vif.type) {
  1236. case NL80211_IFTYPE_MESH_POINT:
  1237. if (sdata->u.mesh.user_mpm)
  1238. statype = CFG80211_STA_MESH_PEER_USER;
  1239. else
  1240. statype = CFG80211_STA_MESH_PEER_KERNEL;
  1241. break;
  1242. case NL80211_IFTYPE_ADHOC:
  1243. statype = CFG80211_STA_IBSS;
  1244. break;
  1245. case NL80211_IFTYPE_STATION:
  1246. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1247. statype = CFG80211_STA_AP_STA;
  1248. break;
  1249. }
  1250. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1251. statype = CFG80211_STA_TDLS_PEER_ACTIVE;
  1252. else
  1253. statype = CFG80211_STA_TDLS_PEER_SETUP;
  1254. break;
  1255. case NL80211_IFTYPE_AP:
  1256. case NL80211_IFTYPE_AP_VLAN:
  1257. statype = CFG80211_STA_AP_CLIENT;
  1258. break;
  1259. default:
  1260. err = -EOPNOTSUPP;
  1261. goto out_err;
  1262. }
  1263. err = cfg80211_check_station_change(wiphy, params, statype);
  1264. if (err)
  1265. goto out_err;
  1266. if (params->vlan && params->vlan != sta->sdata->dev) {
  1267. bool prev_4addr = false;
  1268. bool new_4addr = false;
  1269. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1270. if (params->vlan->ieee80211_ptr->use_4addr) {
  1271. if (vlansdata->u.vlan.sta) {
  1272. err = -EBUSY;
  1273. goto out_err;
  1274. }
  1275. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1276. new_4addr = true;
  1277. }
  1278. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1279. sta->sdata->u.vlan.sta) {
  1280. rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
  1281. prev_4addr = true;
  1282. }
  1283. sta->sdata = vlansdata;
  1284. if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
  1285. prev_4addr != new_4addr) {
  1286. if (new_4addr)
  1287. atomic_dec(&sta->sdata->bss->num_mcast_sta);
  1288. else
  1289. atomic_inc(&sta->sdata->bss->num_mcast_sta);
  1290. }
  1291. ieee80211_send_layer2_update(sta);
  1292. }
  1293. err = sta_apply_parameters(local, sta, params);
  1294. if (err)
  1295. goto out_err;
  1296. /* When peer becomes authorized, init rate control as well */
  1297. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1298. test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1299. rate_control_rate_init(sta);
  1300. mutex_unlock(&local->sta_mtx);
  1301. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1302. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1303. ieee80211_recalc_ps(local, -1);
  1304. ieee80211_recalc_ps_vif(sdata);
  1305. }
  1306. return 0;
  1307. out_err:
  1308. mutex_unlock(&local->sta_mtx);
  1309. return err;
  1310. }
  1311. #ifdef CONFIG_MAC80211_MESH
  1312. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1313. u8 *dst, u8 *next_hop)
  1314. {
  1315. struct ieee80211_sub_if_data *sdata;
  1316. struct mesh_path *mpath;
  1317. struct sta_info *sta;
  1318. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1319. rcu_read_lock();
  1320. sta = sta_info_get(sdata, next_hop);
  1321. if (!sta) {
  1322. rcu_read_unlock();
  1323. return -ENOENT;
  1324. }
  1325. mpath = mesh_path_add(sdata, dst);
  1326. if (IS_ERR(mpath)) {
  1327. rcu_read_unlock();
  1328. return PTR_ERR(mpath);
  1329. }
  1330. mesh_path_fix_nexthop(mpath, sta);
  1331. rcu_read_unlock();
  1332. return 0;
  1333. }
  1334. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1335. u8 *dst)
  1336. {
  1337. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1338. if (dst)
  1339. return mesh_path_del(sdata, dst);
  1340. mesh_path_flush_by_iface(sdata);
  1341. return 0;
  1342. }
  1343. static int ieee80211_change_mpath(struct wiphy *wiphy,
  1344. struct net_device *dev,
  1345. u8 *dst, u8 *next_hop)
  1346. {
  1347. struct ieee80211_sub_if_data *sdata;
  1348. struct mesh_path *mpath;
  1349. struct sta_info *sta;
  1350. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1351. rcu_read_lock();
  1352. sta = sta_info_get(sdata, next_hop);
  1353. if (!sta) {
  1354. rcu_read_unlock();
  1355. return -ENOENT;
  1356. }
  1357. mpath = mesh_path_lookup(sdata, dst);
  1358. if (!mpath) {
  1359. rcu_read_unlock();
  1360. return -ENOENT;
  1361. }
  1362. mesh_path_fix_nexthop(mpath, sta);
  1363. rcu_read_unlock();
  1364. return 0;
  1365. }
  1366. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1367. struct mpath_info *pinfo)
  1368. {
  1369. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1370. if (next_hop_sta)
  1371. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1372. else
  1373. memset(next_hop, 0, ETH_ALEN);
  1374. memset(pinfo, 0, sizeof(*pinfo));
  1375. pinfo->generation = mesh_paths_generation;
  1376. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1377. MPATH_INFO_SN |
  1378. MPATH_INFO_METRIC |
  1379. MPATH_INFO_EXPTIME |
  1380. MPATH_INFO_DISCOVERY_TIMEOUT |
  1381. MPATH_INFO_DISCOVERY_RETRIES |
  1382. MPATH_INFO_FLAGS;
  1383. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1384. pinfo->sn = mpath->sn;
  1385. pinfo->metric = mpath->metric;
  1386. if (time_before(jiffies, mpath->exp_time))
  1387. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1388. pinfo->discovery_timeout =
  1389. jiffies_to_msecs(mpath->discovery_timeout);
  1390. pinfo->discovery_retries = mpath->discovery_retries;
  1391. if (mpath->flags & MESH_PATH_ACTIVE)
  1392. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1393. if (mpath->flags & MESH_PATH_RESOLVING)
  1394. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1395. if (mpath->flags & MESH_PATH_SN_VALID)
  1396. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1397. if (mpath->flags & MESH_PATH_FIXED)
  1398. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1399. if (mpath->flags & MESH_PATH_RESOLVED)
  1400. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  1401. }
  1402. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1403. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1404. {
  1405. struct ieee80211_sub_if_data *sdata;
  1406. struct mesh_path *mpath;
  1407. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1408. rcu_read_lock();
  1409. mpath = mesh_path_lookup(sdata, dst);
  1410. if (!mpath) {
  1411. rcu_read_unlock();
  1412. return -ENOENT;
  1413. }
  1414. memcpy(dst, mpath->dst, ETH_ALEN);
  1415. mpath_set_pinfo(mpath, next_hop, pinfo);
  1416. rcu_read_unlock();
  1417. return 0;
  1418. }
  1419. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1420. int idx, u8 *dst, u8 *next_hop,
  1421. struct mpath_info *pinfo)
  1422. {
  1423. struct ieee80211_sub_if_data *sdata;
  1424. struct mesh_path *mpath;
  1425. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1426. rcu_read_lock();
  1427. mpath = mesh_path_lookup_by_idx(sdata, idx);
  1428. if (!mpath) {
  1429. rcu_read_unlock();
  1430. return -ENOENT;
  1431. }
  1432. memcpy(dst, mpath->dst, ETH_ALEN);
  1433. mpath_set_pinfo(mpath, next_hop, pinfo);
  1434. rcu_read_unlock();
  1435. return 0;
  1436. }
  1437. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  1438. struct net_device *dev,
  1439. struct mesh_config *conf)
  1440. {
  1441. struct ieee80211_sub_if_data *sdata;
  1442. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1443. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  1444. return 0;
  1445. }
  1446. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  1447. {
  1448. return (mask >> (parm-1)) & 0x1;
  1449. }
  1450. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  1451. const struct mesh_setup *setup)
  1452. {
  1453. u8 *new_ie;
  1454. const u8 *old_ie;
  1455. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  1456. struct ieee80211_sub_if_data, u.mesh);
  1457. /* allocate information elements */
  1458. new_ie = NULL;
  1459. old_ie = ifmsh->ie;
  1460. if (setup->ie_len) {
  1461. new_ie = kmemdup(setup->ie, setup->ie_len,
  1462. GFP_KERNEL);
  1463. if (!new_ie)
  1464. return -ENOMEM;
  1465. }
  1466. ifmsh->ie_len = setup->ie_len;
  1467. ifmsh->ie = new_ie;
  1468. kfree(old_ie);
  1469. /* now copy the rest of the setup parameters */
  1470. ifmsh->mesh_id_len = setup->mesh_id_len;
  1471. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  1472. ifmsh->mesh_sp_id = setup->sync_method;
  1473. ifmsh->mesh_pp_id = setup->path_sel_proto;
  1474. ifmsh->mesh_pm_id = setup->path_metric;
  1475. ifmsh->user_mpm = setup->user_mpm;
  1476. ifmsh->mesh_auth_id = setup->auth_id;
  1477. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  1478. if (setup->is_authenticated)
  1479. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  1480. if (setup->is_secure)
  1481. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  1482. /* mcast rate setting in Mesh Node */
  1483. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  1484. sizeof(setup->mcast_rate));
  1485. sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
  1486. sdata->vif.bss_conf.dtim_period = setup->dtim_period;
  1487. return 0;
  1488. }
  1489. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  1490. struct net_device *dev, u32 mask,
  1491. const struct mesh_config *nconf)
  1492. {
  1493. struct mesh_config *conf;
  1494. struct ieee80211_sub_if_data *sdata;
  1495. struct ieee80211_if_mesh *ifmsh;
  1496. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1497. ifmsh = &sdata->u.mesh;
  1498. /* Set the config options which we are interested in setting */
  1499. conf = &(sdata->u.mesh.mshcfg);
  1500. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  1501. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  1502. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  1503. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  1504. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  1505. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  1506. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  1507. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  1508. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  1509. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  1510. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  1511. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  1512. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  1513. conf->element_ttl = nconf->element_ttl;
  1514. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
  1515. if (ifmsh->user_mpm)
  1516. return -EBUSY;
  1517. conf->auto_open_plinks = nconf->auto_open_plinks;
  1518. }
  1519. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  1520. conf->dot11MeshNbrOffsetMaxNeighbor =
  1521. nconf->dot11MeshNbrOffsetMaxNeighbor;
  1522. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  1523. conf->dot11MeshHWMPmaxPREQretries =
  1524. nconf->dot11MeshHWMPmaxPREQretries;
  1525. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1526. conf->path_refresh_time = nconf->path_refresh_time;
  1527. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1528. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1529. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1530. conf->dot11MeshHWMPactivePathTimeout =
  1531. nconf->dot11MeshHWMPactivePathTimeout;
  1532. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1533. conf->dot11MeshHWMPpreqMinInterval =
  1534. nconf->dot11MeshHWMPpreqMinInterval;
  1535. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  1536. conf->dot11MeshHWMPperrMinInterval =
  1537. nconf->dot11MeshHWMPperrMinInterval;
  1538. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1539. mask))
  1540. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1541. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1542. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1543. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1544. ieee80211_mesh_root_setup(ifmsh);
  1545. }
  1546. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1547. /* our current gate announcement implementation rides on root
  1548. * announcements, so require this ifmsh to also be a root node
  1549. * */
  1550. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1551. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  1552. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  1553. ieee80211_mesh_root_setup(ifmsh);
  1554. }
  1555. conf->dot11MeshGateAnnouncementProtocol =
  1556. nconf->dot11MeshGateAnnouncementProtocol;
  1557. }
  1558. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  1559. conf->dot11MeshHWMPRannInterval =
  1560. nconf->dot11MeshHWMPRannInterval;
  1561. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  1562. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  1563. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  1564. /* our RSSI threshold implementation is supported only for
  1565. * devices that report signal in dBm.
  1566. */
  1567. if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
  1568. return -ENOTSUPP;
  1569. conf->rssi_threshold = nconf->rssi_threshold;
  1570. }
  1571. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  1572. conf->ht_opmode = nconf->ht_opmode;
  1573. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  1574. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1575. }
  1576. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  1577. conf->dot11MeshHWMPactivePathToRootTimeout =
  1578. nconf->dot11MeshHWMPactivePathToRootTimeout;
  1579. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  1580. conf->dot11MeshHWMProotInterval =
  1581. nconf->dot11MeshHWMProotInterval;
  1582. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  1583. conf->dot11MeshHWMPconfirmationInterval =
  1584. nconf->dot11MeshHWMPconfirmationInterval;
  1585. if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
  1586. conf->power_mode = nconf->power_mode;
  1587. ieee80211_mps_local_status_update(sdata);
  1588. }
  1589. if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
  1590. conf->dot11MeshAwakeWindowDuration =
  1591. nconf->dot11MeshAwakeWindowDuration;
  1592. ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  1593. return 0;
  1594. }
  1595. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1596. const struct mesh_config *conf,
  1597. const struct mesh_setup *setup)
  1598. {
  1599. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1600. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1601. int err;
  1602. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1603. err = copy_mesh_setup(ifmsh, setup);
  1604. if (err)
  1605. return err;
  1606. /* can mesh use other SMPS modes? */
  1607. sdata->smps_mode = IEEE80211_SMPS_OFF;
  1608. sdata->needed_rx_chains = sdata->local->rx_chains;
  1609. err = ieee80211_vif_use_channel(sdata, &setup->chandef,
  1610. IEEE80211_CHANCTX_SHARED);
  1611. if (err)
  1612. return err;
  1613. return ieee80211_start_mesh(sdata);
  1614. }
  1615. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1616. {
  1617. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1618. ieee80211_stop_mesh(sdata);
  1619. ieee80211_vif_release_channel(sdata);
  1620. return 0;
  1621. }
  1622. #endif
  1623. static int ieee80211_change_bss(struct wiphy *wiphy,
  1624. struct net_device *dev,
  1625. struct bss_parameters *params)
  1626. {
  1627. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1628. enum ieee80211_band band;
  1629. u32 changed = 0;
  1630. if (!rtnl_dereference(sdata->u.ap.beacon))
  1631. return -ENOENT;
  1632. band = ieee80211_get_sdata_band(sdata);
  1633. if (params->use_cts_prot >= 0) {
  1634. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1635. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1636. }
  1637. if (params->use_short_preamble >= 0) {
  1638. sdata->vif.bss_conf.use_short_preamble =
  1639. params->use_short_preamble;
  1640. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1641. }
  1642. if (!sdata->vif.bss_conf.use_short_slot &&
  1643. band == IEEE80211_BAND_5GHZ) {
  1644. sdata->vif.bss_conf.use_short_slot = true;
  1645. changed |= BSS_CHANGED_ERP_SLOT;
  1646. }
  1647. if (params->use_short_slot_time >= 0) {
  1648. sdata->vif.bss_conf.use_short_slot =
  1649. params->use_short_slot_time;
  1650. changed |= BSS_CHANGED_ERP_SLOT;
  1651. }
  1652. if (params->basic_rates) {
  1653. int i, j;
  1654. u32 rates = 0;
  1655. struct ieee80211_supported_band *sband = wiphy->bands[band];
  1656. for (i = 0; i < params->basic_rates_len; i++) {
  1657. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1658. for (j = 0; j < sband->n_bitrates; j++) {
  1659. if (sband->bitrates[j].bitrate == rate)
  1660. rates |= BIT(j);
  1661. }
  1662. }
  1663. sdata->vif.bss_conf.basic_rates = rates;
  1664. changed |= BSS_CHANGED_BASIC_RATES;
  1665. }
  1666. if (params->ap_isolate >= 0) {
  1667. if (params->ap_isolate)
  1668. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1669. else
  1670. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1671. }
  1672. if (params->ht_opmode >= 0) {
  1673. sdata->vif.bss_conf.ht_operation_mode =
  1674. (u16) params->ht_opmode;
  1675. changed |= BSS_CHANGED_HT;
  1676. }
  1677. if (params->p2p_ctwindow >= 0) {
  1678. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1679. ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1680. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1681. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1682. changed |= BSS_CHANGED_P2P_PS;
  1683. }
  1684. if (params->p2p_opp_ps > 0) {
  1685. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1686. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1687. changed |= BSS_CHANGED_P2P_PS;
  1688. } else if (params->p2p_opp_ps == 0) {
  1689. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1690. ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1691. changed |= BSS_CHANGED_P2P_PS;
  1692. }
  1693. ieee80211_bss_info_change_notify(sdata, changed);
  1694. return 0;
  1695. }
  1696. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1697. struct net_device *dev,
  1698. struct ieee80211_txq_params *params)
  1699. {
  1700. struct ieee80211_local *local = wiphy_priv(wiphy);
  1701. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1702. struct ieee80211_tx_queue_params p;
  1703. if (!local->ops->conf_tx)
  1704. return -EOPNOTSUPP;
  1705. if (local->hw.queues < IEEE80211_NUM_ACS)
  1706. return -EOPNOTSUPP;
  1707. memset(&p, 0, sizeof(p));
  1708. p.aifs = params->aifs;
  1709. p.cw_max = params->cwmax;
  1710. p.cw_min = params->cwmin;
  1711. p.txop = params->txop;
  1712. /*
  1713. * Setting tx queue params disables u-apsd because it's only
  1714. * called in master mode.
  1715. */
  1716. p.uapsd = false;
  1717. sdata->tx_conf[params->ac] = p;
  1718. if (drv_conf_tx(local, sdata, params->ac, &p)) {
  1719. wiphy_debug(local->hw.wiphy,
  1720. "failed to set TX queue parameters for AC %d\n",
  1721. params->ac);
  1722. return -EINVAL;
  1723. }
  1724. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  1725. return 0;
  1726. }
  1727. #ifdef CONFIG_PM
  1728. static int ieee80211_suspend(struct wiphy *wiphy,
  1729. struct cfg80211_wowlan *wowlan)
  1730. {
  1731. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1732. }
  1733. static int ieee80211_resume(struct wiphy *wiphy)
  1734. {
  1735. return __ieee80211_resume(wiphy_priv(wiphy));
  1736. }
  1737. #else
  1738. #define ieee80211_suspend NULL
  1739. #define ieee80211_resume NULL
  1740. #endif
  1741. static int ieee80211_scan(struct wiphy *wiphy,
  1742. struct cfg80211_scan_request *req)
  1743. {
  1744. struct ieee80211_sub_if_data *sdata;
  1745. sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
  1746. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1747. case NL80211_IFTYPE_STATION:
  1748. case NL80211_IFTYPE_ADHOC:
  1749. case NL80211_IFTYPE_MESH_POINT:
  1750. case NL80211_IFTYPE_P2P_CLIENT:
  1751. case NL80211_IFTYPE_P2P_DEVICE:
  1752. break;
  1753. case NL80211_IFTYPE_P2P_GO:
  1754. if (sdata->local->ops->hw_scan)
  1755. break;
  1756. /*
  1757. * FIXME: implement NoA while scanning in software,
  1758. * for now fall through to allow scanning only when
  1759. * beaconing hasn't been configured yet
  1760. */
  1761. case NL80211_IFTYPE_AP:
  1762. /*
  1763. * If the scan has been forced (and the driver supports
  1764. * forcing), don't care about being beaconing already.
  1765. * This will create problems to the attached stations (e.g. all
  1766. * the frames sent while scanning on other channel will be
  1767. * lost)
  1768. */
  1769. if (sdata->u.ap.beacon &&
  1770. (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
  1771. !(req->flags & NL80211_SCAN_FLAG_AP)))
  1772. return -EOPNOTSUPP;
  1773. break;
  1774. default:
  1775. return -EOPNOTSUPP;
  1776. }
  1777. return ieee80211_request_scan(sdata, req);
  1778. }
  1779. static int
  1780. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1781. struct net_device *dev,
  1782. struct cfg80211_sched_scan_request *req)
  1783. {
  1784. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1785. if (!sdata->local->ops->sched_scan_start)
  1786. return -EOPNOTSUPP;
  1787. return ieee80211_request_sched_scan_start(sdata, req);
  1788. }
  1789. static int
  1790. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1791. {
  1792. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1793. if (!sdata->local->ops->sched_scan_stop)
  1794. return -EOPNOTSUPP;
  1795. return ieee80211_request_sched_scan_stop(sdata);
  1796. }
  1797. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1798. struct cfg80211_auth_request *req)
  1799. {
  1800. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1801. }
  1802. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1803. struct cfg80211_assoc_request *req)
  1804. {
  1805. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1806. }
  1807. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1808. struct cfg80211_deauth_request *req)
  1809. {
  1810. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1811. }
  1812. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1813. struct cfg80211_disassoc_request *req)
  1814. {
  1815. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1816. }
  1817. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1818. struct cfg80211_ibss_params *params)
  1819. {
  1820. return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
  1821. }
  1822. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1823. {
  1824. return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1825. }
  1826. static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
  1827. int rate[IEEE80211_NUM_BANDS])
  1828. {
  1829. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1830. memcpy(sdata->vif.bss_conf.mcast_rate, rate,
  1831. sizeof(int) * IEEE80211_NUM_BANDS);
  1832. return 0;
  1833. }
  1834. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1835. {
  1836. struct ieee80211_local *local = wiphy_priv(wiphy);
  1837. int err;
  1838. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1839. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1840. if (err)
  1841. return err;
  1842. }
  1843. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1844. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1845. if (err)
  1846. return err;
  1847. }
  1848. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1849. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1850. if (err)
  1851. return err;
  1852. }
  1853. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  1854. if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
  1855. return -EINVAL;
  1856. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1857. }
  1858. if (changed & WIPHY_PARAM_RETRY_LONG) {
  1859. if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
  1860. return -EINVAL;
  1861. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1862. }
  1863. if (changed &
  1864. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1865. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1866. return 0;
  1867. }
  1868. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1869. struct wireless_dev *wdev,
  1870. enum nl80211_tx_power_setting type, int mbm)
  1871. {
  1872. struct ieee80211_local *local = wiphy_priv(wiphy);
  1873. struct ieee80211_sub_if_data *sdata;
  1874. if (wdev) {
  1875. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1876. switch (type) {
  1877. case NL80211_TX_POWER_AUTOMATIC:
  1878. sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1879. break;
  1880. case NL80211_TX_POWER_LIMITED:
  1881. case NL80211_TX_POWER_FIXED:
  1882. if (mbm < 0 || (mbm % 100))
  1883. return -EOPNOTSUPP;
  1884. sdata->user_power_level = MBM_TO_DBM(mbm);
  1885. break;
  1886. }
  1887. ieee80211_recalc_txpower(sdata);
  1888. return 0;
  1889. }
  1890. switch (type) {
  1891. case NL80211_TX_POWER_AUTOMATIC:
  1892. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1893. break;
  1894. case NL80211_TX_POWER_LIMITED:
  1895. case NL80211_TX_POWER_FIXED:
  1896. if (mbm < 0 || (mbm % 100))
  1897. return -EOPNOTSUPP;
  1898. local->user_power_level = MBM_TO_DBM(mbm);
  1899. break;
  1900. }
  1901. mutex_lock(&local->iflist_mtx);
  1902. list_for_each_entry(sdata, &local->interfaces, list)
  1903. sdata->user_power_level = local->user_power_level;
  1904. list_for_each_entry(sdata, &local->interfaces, list)
  1905. ieee80211_recalc_txpower(sdata);
  1906. mutex_unlock(&local->iflist_mtx);
  1907. return 0;
  1908. }
  1909. static int ieee80211_get_tx_power(struct wiphy *wiphy,
  1910. struct wireless_dev *wdev,
  1911. int *dbm)
  1912. {
  1913. struct ieee80211_local *local = wiphy_priv(wiphy);
  1914. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1915. if (!local->use_chanctx)
  1916. *dbm = local->hw.conf.power_level;
  1917. else
  1918. *dbm = sdata->vif.bss_conf.txpower;
  1919. return 0;
  1920. }
  1921. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1922. const u8 *addr)
  1923. {
  1924. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1925. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1926. return 0;
  1927. }
  1928. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1929. {
  1930. struct ieee80211_local *local = wiphy_priv(wiphy);
  1931. drv_rfkill_poll(local);
  1932. }
  1933. #ifdef CONFIG_NL80211_TESTMODE
  1934. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1935. {
  1936. struct ieee80211_local *local = wiphy_priv(wiphy);
  1937. if (!local->ops->testmode_cmd)
  1938. return -EOPNOTSUPP;
  1939. return local->ops->testmode_cmd(&local->hw, data, len);
  1940. }
  1941. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1942. struct sk_buff *skb,
  1943. struct netlink_callback *cb,
  1944. void *data, int len)
  1945. {
  1946. struct ieee80211_local *local = wiphy_priv(wiphy);
  1947. if (!local->ops->testmode_dump)
  1948. return -EOPNOTSUPP;
  1949. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1950. }
  1951. #endif
  1952. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1953. enum ieee80211_smps_mode smps_mode)
  1954. {
  1955. const u8 *ap;
  1956. enum ieee80211_smps_mode old_req;
  1957. int err;
  1958. lockdep_assert_held(&sdata->wdev.mtx);
  1959. old_req = sdata->u.mgd.req_smps;
  1960. sdata->u.mgd.req_smps = smps_mode;
  1961. if (old_req == smps_mode &&
  1962. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1963. return 0;
  1964. /*
  1965. * If not associated, or current association is not an HT
  1966. * association, there's no need to do anything, just store
  1967. * the new value until we associate.
  1968. */
  1969. if (!sdata->u.mgd.associated ||
  1970. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  1971. return 0;
  1972. ap = sdata->u.mgd.associated->bssid;
  1973. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1974. if (sdata->u.mgd.powersave)
  1975. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1976. else
  1977. smps_mode = IEEE80211_SMPS_OFF;
  1978. }
  1979. /* send SM PS frame to AP */
  1980. err = ieee80211_send_smps_action(sdata, smps_mode,
  1981. ap, ap);
  1982. if (err)
  1983. sdata->u.mgd.req_smps = old_req;
  1984. return err;
  1985. }
  1986. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1987. bool enabled, int timeout)
  1988. {
  1989. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1990. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1991. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1992. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  1993. return -EOPNOTSUPP;
  1994. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1995. return -EOPNOTSUPP;
  1996. if (enabled == sdata->u.mgd.powersave &&
  1997. timeout == local->dynamic_ps_forced_timeout)
  1998. return 0;
  1999. sdata->u.mgd.powersave = enabled;
  2000. local->dynamic_ps_forced_timeout = timeout;
  2001. /* no change, but if automatic follow powersave */
  2002. sdata_lock(sdata);
  2003. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  2004. sdata_unlock(sdata);
  2005. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  2006. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2007. ieee80211_recalc_ps(local, -1);
  2008. ieee80211_recalc_ps_vif(sdata);
  2009. return 0;
  2010. }
  2011. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  2012. struct net_device *dev,
  2013. s32 rssi_thold, u32 rssi_hyst)
  2014. {
  2015. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2016. struct ieee80211_vif *vif = &sdata->vif;
  2017. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  2018. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  2019. rssi_hyst == bss_conf->cqm_rssi_hyst)
  2020. return 0;
  2021. bss_conf->cqm_rssi_thold = rssi_thold;
  2022. bss_conf->cqm_rssi_hyst = rssi_hyst;
  2023. /* tell the driver upon association, unless already associated */
  2024. if (sdata->u.mgd.associated &&
  2025. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  2026. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  2027. return 0;
  2028. }
  2029. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  2030. struct net_device *dev,
  2031. const u8 *addr,
  2032. const struct cfg80211_bitrate_mask *mask)
  2033. {
  2034. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2035. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2036. int i, ret;
  2037. if (!ieee80211_sdata_running(sdata))
  2038. return -ENETDOWN;
  2039. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  2040. ret = drv_set_bitrate_mask(local, sdata, mask);
  2041. if (ret)
  2042. return ret;
  2043. }
  2044. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  2045. struct ieee80211_supported_band *sband = wiphy->bands[i];
  2046. int j;
  2047. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  2048. memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
  2049. sizeof(mask->control[i].mcs));
  2050. sdata->rc_has_mcs_mask[i] = false;
  2051. if (!sband)
  2052. continue;
  2053. for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
  2054. if (~sdata->rc_rateidx_mcs_mask[i][j]) {
  2055. sdata->rc_has_mcs_mask[i] = true;
  2056. break;
  2057. }
  2058. }
  2059. return 0;
  2060. }
  2061. static int ieee80211_start_roc_work(struct ieee80211_local *local,
  2062. struct ieee80211_sub_if_data *sdata,
  2063. struct ieee80211_channel *channel,
  2064. unsigned int duration, u64 *cookie,
  2065. struct sk_buff *txskb,
  2066. enum ieee80211_roc_type type)
  2067. {
  2068. struct ieee80211_roc_work *roc, *tmp;
  2069. bool queued = false;
  2070. int ret;
  2071. lockdep_assert_held(&local->mtx);
  2072. if (local->use_chanctx && !local->ops->remain_on_channel)
  2073. return -EOPNOTSUPP;
  2074. roc = kzalloc(sizeof(*roc), GFP_KERNEL);
  2075. if (!roc)
  2076. return -ENOMEM;
  2077. roc->chan = channel;
  2078. roc->duration = duration;
  2079. roc->req_duration = duration;
  2080. roc->frame = txskb;
  2081. roc->type = type;
  2082. roc->mgmt_tx_cookie = (unsigned long)txskb;
  2083. roc->sdata = sdata;
  2084. INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
  2085. INIT_LIST_HEAD(&roc->dependents);
  2086. /* if there's one pending or we're scanning, queue this one */
  2087. if (!list_empty(&local->roc_list) ||
  2088. local->scanning || local->radar_detect_enabled)
  2089. goto out_check_combine;
  2090. /* if not HW assist, just queue & schedule work */
  2091. if (!local->ops->remain_on_channel) {
  2092. ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
  2093. goto out_queue;
  2094. }
  2095. /* otherwise actually kick it off here (for error handling) */
  2096. /*
  2097. * If the duration is zero, then the driver
  2098. * wouldn't actually do anything. Set it to
  2099. * 10 for now.
  2100. *
  2101. * TODO: cancel the off-channel operation
  2102. * when we get the SKB's TX status and
  2103. * the wait time was zero before.
  2104. */
  2105. if (!duration)
  2106. duration = 10;
  2107. ret = drv_remain_on_channel(local, sdata, channel, duration, type);
  2108. if (ret) {
  2109. kfree(roc);
  2110. return ret;
  2111. }
  2112. roc->started = true;
  2113. goto out_queue;
  2114. out_check_combine:
  2115. list_for_each_entry(tmp, &local->roc_list, list) {
  2116. if (tmp->chan != channel || tmp->sdata != sdata)
  2117. continue;
  2118. /*
  2119. * Extend this ROC if possible:
  2120. *
  2121. * If it hasn't started yet, just increase the duration
  2122. * and add the new one to the list of dependents.
  2123. * If the type of the new ROC has higher priority, modify the
  2124. * type of the previous one to match that of the new one.
  2125. */
  2126. if (!tmp->started) {
  2127. list_add_tail(&roc->list, &tmp->dependents);
  2128. tmp->duration = max(tmp->duration, roc->duration);
  2129. tmp->type = max(tmp->type, roc->type);
  2130. queued = true;
  2131. break;
  2132. }
  2133. /* If it has already started, it's more difficult ... */
  2134. if (local->ops->remain_on_channel) {
  2135. unsigned long j = jiffies;
  2136. /*
  2137. * In the offloaded ROC case, if it hasn't begun, add
  2138. * this new one to the dependent list to be handled
  2139. * when the master one begins. If it has begun,
  2140. * check that there's still a minimum time left and
  2141. * if so, start this one, transmitting the frame, but
  2142. * add it to the list directly after this one with
  2143. * a reduced time so we'll ask the driver to execute
  2144. * it right after finishing the previous one, in the
  2145. * hope that it'll also be executed right afterwards,
  2146. * effectively extending the old one.
  2147. * If there's no minimum time left, just add it to the
  2148. * normal list.
  2149. * TODO: the ROC type is ignored here, assuming that it
  2150. * is better to immediately use the current ROC.
  2151. */
  2152. if (!tmp->hw_begun) {
  2153. list_add_tail(&roc->list, &tmp->dependents);
  2154. queued = true;
  2155. break;
  2156. }
  2157. if (time_before(j + IEEE80211_ROC_MIN_LEFT,
  2158. tmp->hw_start_time +
  2159. msecs_to_jiffies(tmp->duration))) {
  2160. int new_dur;
  2161. ieee80211_handle_roc_started(roc);
  2162. new_dur = roc->duration -
  2163. jiffies_to_msecs(tmp->hw_start_time +
  2164. msecs_to_jiffies(
  2165. tmp->duration) -
  2166. j);
  2167. if (new_dur > 0) {
  2168. /* add right after tmp */
  2169. list_add(&roc->list, &tmp->list);
  2170. } else {
  2171. list_add_tail(&roc->list,
  2172. &tmp->dependents);
  2173. }
  2174. queued = true;
  2175. }
  2176. } else if (del_timer_sync(&tmp->work.timer)) {
  2177. unsigned long new_end;
  2178. /*
  2179. * In the software ROC case, cancel the timer, if
  2180. * that fails then the finish work is already
  2181. * queued/pending and thus we queue the new ROC
  2182. * normally, if that succeeds then we can extend
  2183. * the timer duration and TX the frame (if any.)
  2184. */
  2185. list_add_tail(&roc->list, &tmp->dependents);
  2186. queued = true;
  2187. new_end = jiffies + msecs_to_jiffies(roc->duration);
  2188. /* ok, it was started & we canceled timer */
  2189. if (time_after(new_end, tmp->work.timer.expires))
  2190. mod_timer(&tmp->work.timer, new_end);
  2191. else
  2192. add_timer(&tmp->work.timer);
  2193. ieee80211_handle_roc_started(roc);
  2194. }
  2195. break;
  2196. }
  2197. out_queue:
  2198. if (!queued)
  2199. list_add_tail(&roc->list, &local->roc_list);
  2200. /*
  2201. * cookie is either the roc cookie (for normal roc)
  2202. * or the SKB (for mgmt TX)
  2203. */
  2204. if (!txskb) {
  2205. /* local->mtx protects this */
  2206. local->roc_cookie_counter++;
  2207. roc->cookie = local->roc_cookie_counter;
  2208. /* wow, you wrapped 64 bits ... more likely a bug */
  2209. if (WARN_ON(roc->cookie == 0)) {
  2210. roc->cookie = 1;
  2211. local->roc_cookie_counter++;
  2212. }
  2213. *cookie = roc->cookie;
  2214. } else {
  2215. *cookie = (unsigned long)txskb;
  2216. }
  2217. return 0;
  2218. }
  2219. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  2220. struct wireless_dev *wdev,
  2221. struct ieee80211_channel *chan,
  2222. unsigned int duration,
  2223. u64 *cookie)
  2224. {
  2225. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2226. struct ieee80211_local *local = sdata->local;
  2227. int ret;
  2228. mutex_lock(&local->mtx);
  2229. ret = ieee80211_start_roc_work(local, sdata, chan,
  2230. duration, cookie, NULL,
  2231. IEEE80211_ROC_TYPE_NORMAL);
  2232. mutex_unlock(&local->mtx);
  2233. return ret;
  2234. }
  2235. static int ieee80211_cancel_roc(struct ieee80211_local *local,
  2236. u64 cookie, bool mgmt_tx)
  2237. {
  2238. struct ieee80211_roc_work *roc, *tmp, *found = NULL;
  2239. int ret;
  2240. mutex_lock(&local->mtx);
  2241. list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
  2242. struct ieee80211_roc_work *dep, *tmp2;
  2243. list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
  2244. if (!mgmt_tx && dep->cookie != cookie)
  2245. continue;
  2246. else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
  2247. continue;
  2248. /* found dependent item -- just remove it */
  2249. list_del(&dep->list);
  2250. mutex_unlock(&local->mtx);
  2251. ieee80211_roc_notify_destroy(dep, true);
  2252. return 0;
  2253. }
  2254. if (!mgmt_tx && roc->cookie != cookie)
  2255. continue;
  2256. else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
  2257. continue;
  2258. found = roc;
  2259. break;
  2260. }
  2261. if (!found) {
  2262. mutex_unlock(&local->mtx);
  2263. return -ENOENT;
  2264. }
  2265. /*
  2266. * We found the item to cancel, so do that. Note that it
  2267. * may have dependents, which we also cancel (and send
  2268. * the expired signal for.) Not doing so would be quite
  2269. * tricky here, but we may need to fix it later.
  2270. */
  2271. if (local->ops->remain_on_channel) {
  2272. if (found->started) {
  2273. ret = drv_cancel_remain_on_channel(local);
  2274. if (WARN_ON_ONCE(ret)) {
  2275. mutex_unlock(&local->mtx);
  2276. return ret;
  2277. }
  2278. }
  2279. list_del(&found->list);
  2280. if (found->started)
  2281. ieee80211_start_next_roc(local);
  2282. mutex_unlock(&local->mtx);
  2283. ieee80211_roc_notify_destroy(found, true);
  2284. } else {
  2285. /* work may be pending so use it all the time */
  2286. found->abort = true;
  2287. ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
  2288. mutex_unlock(&local->mtx);
  2289. /* work will clean up etc */
  2290. flush_delayed_work(&found->work);
  2291. WARN_ON(!found->to_be_freed);
  2292. kfree(found);
  2293. }
  2294. return 0;
  2295. }
  2296. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  2297. struct wireless_dev *wdev,
  2298. u64 cookie)
  2299. {
  2300. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2301. struct ieee80211_local *local = sdata->local;
  2302. return ieee80211_cancel_roc(local, cookie, false);
  2303. }
  2304. static int ieee80211_start_radar_detection(struct wiphy *wiphy,
  2305. struct net_device *dev,
  2306. struct cfg80211_chan_def *chandef)
  2307. {
  2308. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2309. struct ieee80211_local *local = sdata->local;
  2310. unsigned long timeout;
  2311. int err;
  2312. if (!list_empty(&local->roc_list) || local->scanning)
  2313. return -EBUSY;
  2314. /* whatever, but channel contexts should not complain about that one */
  2315. sdata->smps_mode = IEEE80211_SMPS_OFF;
  2316. sdata->needed_rx_chains = local->rx_chains;
  2317. sdata->radar_required = true;
  2318. mutex_lock(&local->iflist_mtx);
  2319. err = ieee80211_vif_use_channel(sdata, chandef,
  2320. IEEE80211_CHANCTX_SHARED);
  2321. mutex_unlock(&local->iflist_mtx);
  2322. if (err)
  2323. return err;
  2324. timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
  2325. ieee80211_queue_delayed_work(&sdata->local->hw,
  2326. &sdata->dfs_cac_timer_work, timeout);
  2327. return 0;
  2328. }
  2329. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  2330. struct ieee80211_channel *chan, bool offchan,
  2331. unsigned int wait, const u8 *buf, size_t len,
  2332. bool no_cck, bool dont_wait_for_ack, u64 *cookie)
  2333. {
  2334. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2335. struct ieee80211_local *local = sdata->local;
  2336. struct sk_buff *skb;
  2337. struct sta_info *sta;
  2338. const struct ieee80211_mgmt *mgmt = (void *)buf;
  2339. bool need_offchan = false;
  2340. u32 flags;
  2341. int ret;
  2342. if (dont_wait_for_ack)
  2343. flags = IEEE80211_TX_CTL_NO_ACK;
  2344. else
  2345. flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  2346. IEEE80211_TX_CTL_REQ_TX_STATUS;
  2347. if (no_cck)
  2348. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  2349. switch (sdata->vif.type) {
  2350. case NL80211_IFTYPE_ADHOC:
  2351. if (!sdata->vif.bss_conf.ibss_joined)
  2352. need_offchan = true;
  2353. /* fall through */
  2354. #ifdef CONFIG_MAC80211_MESH
  2355. case NL80211_IFTYPE_MESH_POINT:
  2356. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  2357. !sdata->u.mesh.mesh_id_len)
  2358. need_offchan = true;
  2359. /* fall through */
  2360. #endif
  2361. case NL80211_IFTYPE_AP:
  2362. case NL80211_IFTYPE_AP_VLAN:
  2363. case NL80211_IFTYPE_P2P_GO:
  2364. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2365. !ieee80211_vif_is_mesh(&sdata->vif) &&
  2366. !rcu_access_pointer(sdata->bss->beacon))
  2367. need_offchan = true;
  2368. if (!ieee80211_is_action(mgmt->frame_control) ||
  2369. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  2370. break;
  2371. rcu_read_lock();
  2372. sta = sta_info_get(sdata, mgmt->da);
  2373. rcu_read_unlock();
  2374. if (!sta)
  2375. return -ENOLINK;
  2376. break;
  2377. case NL80211_IFTYPE_STATION:
  2378. case NL80211_IFTYPE_P2P_CLIENT:
  2379. if (!sdata->u.mgd.associated)
  2380. need_offchan = true;
  2381. break;
  2382. case NL80211_IFTYPE_P2P_DEVICE:
  2383. need_offchan = true;
  2384. break;
  2385. default:
  2386. return -EOPNOTSUPP;
  2387. }
  2388. mutex_lock(&local->mtx);
  2389. /* Check if the operating channel is the requested channel */
  2390. if (!need_offchan) {
  2391. struct ieee80211_chanctx_conf *chanctx_conf;
  2392. rcu_read_lock();
  2393. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2394. if (chanctx_conf)
  2395. need_offchan = chan != chanctx_conf->def.chan;
  2396. else
  2397. need_offchan = true;
  2398. rcu_read_unlock();
  2399. }
  2400. if (need_offchan && !offchan) {
  2401. ret = -EBUSY;
  2402. goto out_unlock;
  2403. }
  2404. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  2405. if (!skb) {
  2406. ret = -ENOMEM;
  2407. goto out_unlock;
  2408. }
  2409. skb_reserve(skb, local->hw.extra_tx_headroom);
  2410. memcpy(skb_put(skb, len), buf, len);
  2411. IEEE80211_SKB_CB(skb)->flags = flags;
  2412. skb->dev = sdata->dev;
  2413. if (!need_offchan) {
  2414. *cookie = (unsigned long) skb;
  2415. ieee80211_tx_skb(sdata, skb);
  2416. ret = 0;
  2417. goto out_unlock;
  2418. }
  2419. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
  2420. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  2421. if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
  2422. IEEE80211_SKB_CB(skb)->hw_queue =
  2423. local->hw.offchannel_tx_hw_queue;
  2424. /* This will handle all kinds of coalescing and immediate TX */
  2425. ret = ieee80211_start_roc_work(local, sdata, chan,
  2426. wait, cookie, skb,
  2427. IEEE80211_ROC_TYPE_MGMT_TX);
  2428. if (ret)
  2429. kfree_skb(skb);
  2430. out_unlock:
  2431. mutex_unlock(&local->mtx);
  2432. return ret;
  2433. }
  2434. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  2435. struct wireless_dev *wdev,
  2436. u64 cookie)
  2437. {
  2438. struct ieee80211_local *local = wiphy_priv(wiphy);
  2439. return ieee80211_cancel_roc(local, cookie, true);
  2440. }
  2441. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  2442. struct wireless_dev *wdev,
  2443. u16 frame_type, bool reg)
  2444. {
  2445. struct ieee80211_local *local = wiphy_priv(wiphy);
  2446. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2447. switch (frame_type) {
  2448. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
  2449. if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  2450. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  2451. if (reg)
  2452. ifibss->auth_frame_registrations++;
  2453. else
  2454. ifibss->auth_frame_registrations--;
  2455. }
  2456. break;
  2457. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
  2458. if (reg)
  2459. local->probe_req_reg++;
  2460. else
  2461. local->probe_req_reg--;
  2462. if (!local->open_count)
  2463. break;
  2464. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  2465. break;
  2466. default:
  2467. break;
  2468. }
  2469. }
  2470. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  2471. {
  2472. struct ieee80211_local *local = wiphy_priv(wiphy);
  2473. if (local->started)
  2474. return -EOPNOTSUPP;
  2475. return drv_set_antenna(local, tx_ant, rx_ant);
  2476. }
  2477. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  2478. {
  2479. struct ieee80211_local *local = wiphy_priv(wiphy);
  2480. return drv_get_antenna(local, tx_ant, rx_ant);
  2481. }
  2482. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  2483. {
  2484. struct ieee80211_local *local = wiphy_priv(wiphy);
  2485. return drv_set_ringparam(local, tx, rx);
  2486. }
  2487. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  2488. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  2489. {
  2490. struct ieee80211_local *local = wiphy_priv(wiphy);
  2491. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  2492. }
  2493. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  2494. struct net_device *dev,
  2495. struct cfg80211_gtk_rekey_data *data)
  2496. {
  2497. struct ieee80211_local *local = wiphy_priv(wiphy);
  2498. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2499. if (!local->ops->set_rekey_data)
  2500. return -EOPNOTSUPP;
  2501. drv_set_rekey_data(local, sdata, data);
  2502. return 0;
  2503. }
  2504. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  2505. {
  2506. u8 *pos = (void *)skb_put(skb, 7);
  2507. *pos++ = WLAN_EID_EXT_CAPABILITY;
  2508. *pos++ = 5; /* len */
  2509. *pos++ = 0x0;
  2510. *pos++ = 0x0;
  2511. *pos++ = 0x0;
  2512. *pos++ = 0x0;
  2513. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  2514. }
  2515. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  2516. {
  2517. struct ieee80211_local *local = sdata->local;
  2518. u16 capab;
  2519. capab = 0;
  2520. if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
  2521. return capab;
  2522. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  2523. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  2524. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  2525. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  2526. return capab;
  2527. }
  2528. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  2529. u8 *peer, u8 *bssid)
  2530. {
  2531. struct ieee80211_tdls_lnkie *lnkid;
  2532. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  2533. lnkid->ie_type = WLAN_EID_LINK_ID;
  2534. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  2535. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  2536. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  2537. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  2538. }
  2539. static int
  2540. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  2541. u8 *peer, u8 action_code, u8 dialog_token,
  2542. u16 status_code, struct sk_buff *skb)
  2543. {
  2544. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2545. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  2546. struct ieee80211_tdls_data *tf;
  2547. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  2548. memcpy(tf->da, peer, ETH_ALEN);
  2549. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  2550. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  2551. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  2552. switch (action_code) {
  2553. case WLAN_TDLS_SETUP_REQUEST:
  2554. tf->category = WLAN_CATEGORY_TDLS;
  2555. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  2556. skb_put(skb, sizeof(tf->u.setup_req));
  2557. tf->u.setup_req.dialog_token = dialog_token;
  2558. tf->u.setup_req.capability =
  2559. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2560. ieee80211_add_srates_ie(sdata, skb, false, band);
  2561. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2562. ieee80211_tdls_add_ext_capab(skb);
  2563. break;
  2564. case WLAN_TDLS_SETUP_RESPONSE:
  2565. tf->category = WLAN_CATEGORY_TDLS;
  2566. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  2567. skb_put(skb, sizeof(tf->u.setup_resp));
  2568. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  2569. tf->u.setup_resp.dialog_token = dialog_token;
  2570. tf->u.setup_resp.capability =
  2571. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2572. ieee80211_add_srates_ie(sdata, skb, false, band);
  2573. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2574. ieee80211_tdls_add_ext_capab(skb);
  2575. break;
  2576. case WLAN_TDLS_SETUP_CONFIRM:
  2577. tf->category = WLAN_CATEGORY_TDLS;
  2578. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  2579. skb_put(skb, sizeof(tf->u.setup_cfm));
  2580. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  2581. tf->u.setup_cfm.dialog_token = dialog_token;
  2582. break;
  2583. case WLAN_TDLS_TEARDOWN:
  2584. tf->category = WLAN_CATEGORY_TDLS;
  2585. tf->action_code = WLAN_TDLS_TEARDOWN;
  2586. skb_put(skb, sizeof(tf->u.teardown));
  2587. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  2588. break;
  2589. case WLAN_TDLS_DISCOVERY_REQUEST:
  2590. tf->category = WLAN_CATEGORY_TDLS;
  2591. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  2592. skb_put(skb, sizeof(tf->u.discover_req));
  2593. tf->u.discover_req.dialog_token = dialog_token;
  2594. break;
  2595. default:
  2596. return -EINVAL;
  2597. }
  2598. return 0;
  2599. }
  2600. static int
  2601. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  2602. u8 *peer, u8 action_code, u8 dialog_token,
  2603. u16 status_code, struct sk_buff *skb)
  2604. {
  2605. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2606. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  2607. struct ieee80211_mgmt *mgmt;
  2608. mgmt = (void *)skb_put(skb, 24);
  2609. memset(mgmt, 0, 24);
  2610. memcpy(mgmt->da, peer, ETH_ALEN);
  2611. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  2612. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  2613. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2614. IEEE80211_STYPE_ACTION);
  2615. switch (action_code) {
  2616. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2617. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  2618. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  2619. mgmt->u.action.u.tdls_discover_resp.action_code =
  2620. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  2621. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  2622. dialog_token;
  2623. mgmt->u.action.u.tdls_discover_resp.capability =
  2624. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2625. ieee80211_add_srates_ie(sdata, skb, false, band);
  2626. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2627. ieee80211_tdls_add_ext_capab(skb);
  2628. break;
  2629. default:
  2630. return -EINVAL;
  2631. }
  2632. return 0;
  2633. }
  2634. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2635. u8 *peer, u8 action_code, u8 dialog_token,
  2636. u16 status_code, const u8 *extra_ies,
  2637. size_t extra_ies_len)
  2638. {
  2639. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2640. struct ieee80211_local *local = sdata->local;
  2641. struct sk_buff *skb = NULL;
  2642. bool send_direct;
  2643. int ret;
  2644. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2645. return -ENOTSUPP;
  2646. /* make sure we are in managed mode, and associated */
  2647. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  2648. !sdata->u.mgd.associated)
  2649. return -EINVAL;
  2650. tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
  2651. action_code, peer);
  2652. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  2653. max(sizeof(struct ieee80211_mgmt),
  2654. sizeof(struct ieee80211_tdls_data)) +
  2655. 50 + /* supported rates */
  2656. 7 + /* ext capab */
  2657. extra_ies_len +
  2658. sizeof(struct ieee80211_tdls_lnkie));
  2659. if (!skb)
  2660. return -ENOMEM;
  2661. skb_reserve(skb, local->hw.extra_tx_headroom);
  2662. switch (action_code) {
  2663. case WLAN_TDLS_SETUP_REQUEST:
  2664. case WLAN_TDLS_SETUP_RESPONSE:
  2665. case WLAN_TDLS_SETUP_CONFIRM:
  2666. case WLAN_TDLS_TEARDOWN:
  2667. case WLAN_TDLS_DISCOVERY_REQUEST:
  2668. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  2669. action_code, dialog_token,
  2670. status_code, skb);
  2671. send_direct = false;
  2672. break;
  2673. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2674. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  2675. dialog_token, status_code,
  2676. skb);
  2677. send_direct = true;
  2678. break;
  2679. default:
  2680. ret = -ENOTSUPP;
  2681. break;
  2682. }
  2683. if (ret < 0)
  2684. goto fail;
  2685. if (extra_ies_len)
  2686. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  2687. /* the TDLS link IE is always added last */
  2688. switch (action_code) {
  2689. case WLAN_TDLS_SETUP_REQUEST:
  2690. case WLAN_TDLS_SETUP_CONFIRM:
  2691. case WLAN_TDLS_TEARDOWN:
  2692. case WLAN_TDLS_DISCOVERY_REQUEST:
  2693. /* we are the initiator */
  2694. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  2695. sdata->u.mgd.bssid);
  2696. break;
  2697. case WLAN_TDLS_SETUP_RESPONSE:
  2698. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2699. /* we are the responder */
  2700. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  2701. sdata->u.mgd.bssid);
  2702. break;
  2703. default:
  2704. ret = -ENOTSUPP;
  2705. goto fail;
  2706. }
  2707. if (send_direct) {
  2708. ieee80211_tx_skb(sdata, skb);
  2709. return 0;
  2710. }
  2711. /*
  2712. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  2713. * we should default to AC_VI.
  2714. */
  2715. switch (action_code) {
  2716. case WLAN_TDLS_SETUP_REQUEST:
  2717. case WLAN_TDLS_SETUP_RESPONSE:
  2718. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  2719. skb->priority = 2;
  2720. break;
  2721. default:
  2722. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  2723. skb->priority = 5;
  2724. break;
  2725. }
  2726. /* disable bottom halves when entering the Tx path */
  2727. local_bh_disable();
  2728. ret = ieee80211_subif_start_xmit(skb, dev);
  2729. local_bh_enable();
  2730. return ret;
  2731. fail:
  2732. dev_kfree_skb(skb);
  2733. return ret;
  2734. }
  2735. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2736. u8 *peer, enum nl80211_tdls_operation oper)
  2737. {
  2738. struct sta_info *sta;
  2739. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2740. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2741. return -ENOTSUPP;
  2742. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2743. return -EINVAL;
  2744. tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
  2745. switch (oper) {
  2746. case NL80211_TDLS_ENABLE_LINK:
  2747. rcu_read_lock();
  2748. sta = sta_info_get(sdata, peer);
  2749. if (!sta) {
  2750. rcu_read_unlock();
  2751. return -ENOLINK;
  2752. }
  2753. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2754. rcu_read_unlock();
  2755. break;
  2756. case NL80211_TDLS_DISABLE_LINK:
  2757. return sta_info_destroy_addr(sdata, peer);
  2758. case NL80211_TDLS_TEARDOWN:
  2759. case NL80211_TDLS_SETUP:
  2760. case NL80211_TDLS_DISCOVERY_REQ:
  2761. /* We don't support in-driver setup/teardown/discovery */
  2762. return -ENOTSUPP;
  2763. default:
  2764. return -ENOTSUPP;
  2765. }
  2766. return 0;
  2767. }
  2768. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2769. const u8 *peer, u64 *cookie)
  2770. {
  2771. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2772. struct ieee80211_local *local = sdata->local;
  2773. struct ieee80211_qos_hdr *nullfunc;
  2774. struct sk_buff *skb;
  2775. int size = sizeof(*nullfunc);
  2776. __le16 fc;
  2777. bool qos;
  2778. struct ieee80211_tx_info *info;
  2779. struct sta_info *sta;
  2780. struct ieee80211_chanctx_conf *chanctx_conf;
  2781. enum ieee80211_band band;
  2782. rcu_read_lock();
  2783. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2784. if (WARN_ON(!chanctx_conf)) {
  2785. rcu_read_unlock();
  2786. return -EINVAL;
  2787. }
  2788. band = chanctx_conf->def.chan->band;
  2789. sta = sta_info_get(sdata, peer);
  2790. if (sta) {
  2791. qos = test_sta_flag(sta, WLAN_STA_WME);
  2792. } else {
  2793. rcu_read_unlock();
  2794. return -ENOLINK;
  2795. }
  2796. if (qos) {
  2797. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2798. IEEE80211_STYPE_QOS_NULLFUNC |
  2799. IEEE80211_FCTL_FROMDS);
  2800. } else {
  2801. size -= 2;
  2802. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2803. IEEE80211_STYPE_NULLFUNC |
  2804. IEEE80211_FCTL_FROMDS);
  2805. }
  2806. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2807. if (!skb) {
  2808. rcu_read_unlock();
  2809. return -ENOMEM;
  2810. }
  2811. skb->dev = dev;
  2812. skb_reserve(skb, local->hw.extra_tx_headroom);
  2813. nullfunc = (void *) skb_put(skb, size);
  2814. nullfunc->frame_control = fc;
  2815. nullfunc->duration_id = 0;
  2816. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2817. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2818. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2819. nullfunc->seq_ctrl = 0;
  2820. info = IEEE80211_SKB_CB(skb);
  2821. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2822. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2823. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2824. skb->priority = 7;
  2825. if (qos)
  2826. nullfunc->qos_ctrl = cpu_to_le16(7);
  2827. local_bh_disable();
  2828. ieee80211_xmit(sdata, skb, band);
  2829. local_bh_enable();
  2830. rcu_read_unlock();
  2831. *cookie = (unsigned long) skb;
  2832. return 0;
  2833. }
  2834. static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  2835. struct wireless_dev *wdev,
  2836. struct cfg80211_chan_def *chandef)
  2837. {
  2838. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2839. struct ieee80211_local *local = wiphy_priv(wiphy);
  2840. struct ieee80211_chanctx_conf *chanctx_conf;
  2841. int ret = -ENODATA;
  2842. rcu_read_lock();
  2843. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2844. if (chanctx_conf) {
  2845. *chandef = chanctx_conf->def;
  2846. ret = 0;
  2847. } else if (local->open_count > 0 &&
  2848. local->open_count == local->monitors &&
  2849. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2850. if (local->use_chanctx)
  2851. *chandef = local->monitor_chandef;
  2852. else
  2853. *chandef = local->_oper_chandef;
  2854. ret = 0;
  2855. }
  2856. rcu_read_unlock();
  2857. return ret;
  2858. }
  2859. #ifdef CONFIG_PM
  2860. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  2861. {
  2862. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  2863. }
  2864. #endif
  2865. struct cfg80211_ops mac80211_config_ops = {
  2866. .add_virtual_intf = ieee80211_add_iface,
  2867. .del_virtual_intf = ieee80211_del_iface,
  2868. .change_virtual_intf = ieee80211_change_iface,
  2869. .start_p2p_device = ieee80211_start_p2p_device,
  2870. .stop_p2p_device = ieee80211_stop_p2p_device,
  2871. .add_key = ieee80211_add_key,
  2872. .del_key = ieee80211_del_key,
  2873. .get_key = ieee80211_get_key,
  2874. .set_default_key = ieee80211_config_default_key,
  2875. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2876. .start_ap = ieee80211_start_ap,
  2877. .change_beacon = ieee80211_change_beacon,
  2878. .stop_ap = ieee80211_stop_ap,
  2879. .add_station = ieee80211_add_station,
  2880. .del_station = ieee80211_del_station,
  2881. .change_station = ieee80211_change_station,
  2882. .get_station = ieee80211_get_station,
  2883. .dump_station = ieee80211_dump_station,
  2884. .dump_survey = ieee80211_dump_survey,
  2885. #ifdef CONFIG_MAC80211_MESH
  2886. .add_mpath = ieee80211_add_mpath,
  2887. .del_mpath = ieee80211_del_mpath,
  2888. .change_mpath = ieee80211_change_mpath,
  2889. .get_mpath = ieee80211_get_mpath,
  2890. .dump_mpath = ieee80211_dump_mpath,
  2891. .update_mesh_config = ieee80211_update_mesh_config,
  2892. .get_mesh_config = ieee80211_get_mesh_config,
  2893. .join_mesh = ieee80211_join_mesh,
  2894. .leave_mesh = ieee80211_leave_mesh,
  2895. #endif
  2896. .change_bss = ieee80211_change_bss,
  2897. .set_txq_params = ieee80211_set_txq_params,
  2898. .set_monitor_channel = ieee80211_set_monitor_channel,
  2899. .suspend = ieee80211_suspend,
  2900. .resume = ieee80211_resume,
  2901. .scan = ieee80211_scan,
  2902. .sched_scan_start = ieee80211_sched_scan_start,
  2903. .sched_scan_stop = ieee80211_sched_scan_stop,
  2904. .auth = ieee80211_auth,
  2905. .assoc = ieee80211_assoc,
  2906. .deauth = ieee80211_deauth,
  2907. .disassoc = ieee80211_disassoc,
  2908. .join_ibss = ieee80211_join_ibss,
  2909. .leave_ibss = ieee80211_leave_ibss,
  2910. .set_mcast_rate = ieee80211_set_mcast_rate,
  2911. .set_wiphy_params = ieee80211_set_wiphy_params,
  2912. .set_tx_power = ieee80211_set_tx_power,
  2913. .get_tx_power = ieee80211_get_tx_power,
  2914. .set_wds_peer = ieee80211_set_wds_peer,
  2915. .rfkill_poll = ieee80211_rfkill_poll,
  2916. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2917. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2918. .set_power_mgmt = ieee80211_set_power_mgmt,
  2919. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2920. .remain_on_channel = ieee80211_remain_on_channel,
  2921. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2922. .mgmt_tx = ieee80211_mgmt_tx,
  2923. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2924. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2925. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2926. .set_antenna = ieee80211_set_antenna,
  2927. .get_antenna = ieee80211_get_antenna,
  2928. .set_ringparam = ieee80211_set_ringparam,
  2929. .get_ringparam = ieee80211_get_ringparam,
  2930. .set_rekey_data = ieee80211_set_rekey_data,
  2931. .tdls_oper = ieee80211_tdls_oper,
  2932. .tdls_mgmt = ieee80211_tdls_mgmt,
  2933. .probe_client = ieee80211_probe_client,
  2934. .set_noack_map = ieee80211_set_noack_map,
  2935. #ifdef CONFIG_PM
  2936. .set_wakeup = ieee80211_set_wakeup,
  2937. #endif
  2938. .get_et_sset_count = ieee80211_get_et_sset_count,
  2939. .get_et_stats = ieee80211_get_et_stats,
  2940. .get_et_strings = ieee80211_get_et_strings,
  2941. .get_channel = ieee80211_cfg_get_channel,
  2942. .start_radar_detection = ieee80211_start_radar_detection,
  2943. };