cfg.c 82 KB

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