cfg.c 77 KB

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