cfg.c 80 KB

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