cfg.c 92 KB

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