cfg.c 91 KB

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