cfg.c 86 KB

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