cfg.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648
  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_add_key(struct wiphy *wiphy, struct net_device *dev,
  90. u8 key_idx, bool pairwise, const u8 *mac_addr,
  91. struct key_params *params)
  92. {
  93. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  94. struct sta_info *sta = NULL;
  95. struct ieee80211_key *key;
  96. int err;
  97. if (!ieee80211_sdata_running(sdata))
  98. return -ENETDOWN;
  99. /* reject WEP and TKIP keys if WEP failed to initialize */
  100. switch (params->cipher) {
  101. case WLAN_CIPHER_SUITE_WEP40:
  102. case WLAN_CIPHER_SUITE_TKIP:
  103. case WLAN_CIPHER_SUITE_WEP104:
  104. if (IS_ERR(sdata->local->wep_tx_tfm))
  105. return -EINVAL;
  106. break;
  107. default:
  108. break;
  109. }
  110. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  111. params->key, params->seq_len, params->seq);
  112. if (IS_ERR(key))
  113. return PTR_ERR(key);
  114. if (pairwise)
  115. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  116. mutex_lock(&sdata->local->sta_mtx);
  117. if (mac_addr) {
  118. if (ieee80211_vif_is_mesh(&sdata->vif))
  119. sta = sta_info_get(sdata, mac_addr);
  120. else
  121. sta = sta_info_get_bss(sdata, mac_addr);
  122. if (!sta) {
  123. ieee80211_key_free(sdata->local, key);
  124. err = -ENOENT;
  125. goto out_unlock;
  126. }
  127. }
  128. err = ieee80211_key_link(key, sdata, sta);
  129. if (err)
  130. ieee80211_key_free(sdata->local, key);
  131. out_unlock:
  132. mutex_unlock(&sdata->local->sta_mtx);
  133. return err;
  134. }
  135. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  136. u8 key_idx, bool pairwise, const u8 *mac_addr)
  137. {
  138. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  139. struct ieee80211_local *local = sdata->local;
  140. struct sta_info *sta;
  141. struct ieee80211_key *key = NULL;
  142. int ret;
  143. mutex_lock(&local->sta_mtx);
  144. mutex_lock(&local->key_mtx);
  145. if (mac_addr) {
  146. ret = -ENOENT;
  147. sta = sta_info_get_bss(sdata, mac_addr);
  148. if (!sta)
  149. goto out_unlock;
  150. if (pairwise)
  151. key = key_mtx_dereference(local, sta->ptk);
  152. else
  153. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  154. } else
  155. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  156. if (!key) {
  157. ret = -ENOENT;
  158. goto out_unlock;
  159. }
  160. __ieee80211_key_free(key);
  161. ret = 0;
  162. out_unlock:
  163. mutex_unlock(&local->key_mtx);
  164. mutex_unlock(&local->sta_mtx);
  165. return ret;
  166. }
  167. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  168. u8 key_idx, bool pairwise, const u8 *mac_addr,
  169. void *cookie,
  170. void (*callback)(void *cookie,
  171. struct key_params *params))
  172. {
  173. struct ieee80211_sub_if_data *sdata;
  174. struct sta_info *sta = NULL;
  175. u8 seq[6] = {0};
  176. struct key_params params;
  177. struct ieee80211_key *key = NULL;
  178. u64 pn64;
  179. u32 iv32;
  180. u16 iv16;
  181. int err = -ENOENT;
  182. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  183. rcu_read_lock();
  184. if (mac_addr) {
  185. sta = sta_info_get_bss(sdata, mac_addr);
  186. if (!sta)
  187. goto out;
  188. if (pairwise)
  189. key = rcu_dereference(sta->ptk);
  190. else if (key_idx < NUM_DEFAULT_KEYS)
  191. key = rcu_dereference(sta->gtk[key_idx]);
  192. } else
  193. key = rcu_dereference(sdata->keys[key_idx]);
  194. if (!key)
  195. goto out;
  196. memset(&params, 0, sizeof(params));
  197. params.cipher = key->conf.cipher;
  198. switch (key->conf.cipher) {
  199. case WLAN_CIPHER_SUITE_TKIP:
  200. iv32 = key->u.tkip.tx.iv32;
  201. iv16 = key->u.tkip.tx.iv16;
  202. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  203. drv_get_tkip_seq(sdata->local,
  204. key->conf.hw_key_idx,
  205. &iv32, &iv16);
  206. seq[0] = iv16 & 0xff;
  207. seq[1] = (iv16 >> 8) & 0xff;
  208. seq[2] = iv32 & 0xff;
  209. seq[3] = (iv32 >> 8) & 0xff;
  210. seq[4] = (iv32 >> 16) & 0xff;
  211. seq[5] = (iv32 >> 24) & 0xff;
  212. params.seq = seq;
  213. params.seq_len = 6;
  214. break;
  215. case WLAN_CIPHER_SUITE_CCMP:
  216. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  217. seq[0] = pn64;
  218. seq[1] = pn64 >> 8;
  219. seq[2] = pn64 >> 16;
  220. seq[3] = pn64 >> 24;
  221. seq[4] = pn64 >> 32;
  222. seq[5] = pn64 >> 40;
  223. params.seq = seq;
  224. params.seq_len = 6;
  225. break;
  226. case WLAN_CIPHER_SUITE_AES_CMAC:
  227. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  228. seq[0] = pn64;
  229. seq[1] = pn64 >> 8;
  230. seq[2] = pn64 >> 16;
  231. seq[3] = pn64 >> 24;
  232. seq[4] = pn64 >> 32;
  233. seq[5] = pn64 >> 40;
  234. params.seq = seq;
  235. params.seq_len = 6;
  236. break;
  237. }
  238. params.key = key->conf.key;
  239. params.key_len = key->conf.keylen;
  240. callback(cookie, &params);
  241. err = 0;
  242. out:
  243. rcu_read_unlock();
  244. return err;
  245. }
  246. static int ieee80211_config_default_key(struct wiphy *wiphy,
  247. struct net_device *dev,
  248. u8 key_idx, bool uni,
  249. bool multi)
  250. {
  251. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  252. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  253. return 0;
  254. }
  255. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  256. struct net_device *dev,
  257. u8 key_idx)
  258. {
  259. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  260. ieee80211_set_default_mgmt_key(sdata, key_idx);
  261. return 0;
  262. }
  263. static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
  264. {
  265. if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
  266. struct ieee80211_supported_band *sband;
  267. sband = sta->local->hw.wiphy->bands[
  268. sta->local->hw.conf.channel->band];
  269. rate->legacy = sband->bitrates[idx].bitrate;
  270. } else
  271. rate->mcs = idx;
  272. }
  273. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  274. {
  275. struct ieee80211_sub_if_data *sdata = sta->sdata;
  276. struct timespec uptime;
  277. sinfo->generation = sdata->local->sta_generation;
  278. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  279. STATION_INFO_RX_BYTES |
  280. STATION_INFO_TX_BYTES |
  281. STATION_INFO_RX_PACKETS |
  282. STATION_INFO_TX_PACKETS |
  283. STATION_INFO_TX_RETRIES |
  284. STATION_INFO_TX_FAILED |
  285. STATION_INFO_TX_BITRATE |
  286. STATION_INFO_RX_BITRATE |
  287. STATION_INFO_RX_DROP_MISC |
  288. STATION_INFO_BSS_PARAM |
  289. STATION_INFO_CONNECTED_TIME |
  290. STATION_INFO_STA_FLAGS;
  291. do_posix_clock_monotonic_gettime(&uptime);
  292. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  293. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  294. sinfo->rx_bytes = sta->rx_bytes;
  295. sinfo->tx_bytes = sta->tx_bytes;
  296. sinfo->rx_packets = sta->rx_packets;
  297. sinfo->tx_packets = sta->tx_packets;
  298. sinfo->tx_retries = sta->tx_retry_count;
  299. sinfo->tx_failed = sta->tx_retry_failed;
  300. sinfo->rx_dropped_misc = sta->rx_dropped;
  301. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  302. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  303. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  304. sinfo->signal = (s8)sta->last_signal;
  305. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  306. }
  307. sinfo->txrate.flags = 0;
  308. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  309. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  310. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  311. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  312. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  313. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  314. rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
  315. sinfo->rxrate.flags = 0;
  316. if (sta->last_rx_rate_flag & RX_FLAG_HT)
  317. sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
  318. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  319. sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  320. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  321. sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  322. rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
  323. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  324. #ifdef CONFIG_MAC80211_MESH
  325. sinfo->filled |= STATION_INFO_LLID |
  326. STATION_INFO_PLID |
  327. STATION_INFO_PLINK_STATE;
  328. sinfo->llid = le16_to_cpu(sta->llid);
  329. sinfo->plid = le16_to_cpu(sta->plid);
  330. sinfo->plink_state = sta->plink_state;
  331. #endif
  332. }
  333. sinfo->bss_param.flags = 0;
  334. if (sdata->vif.bss_conf.use_cts_prot)
  335. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  336. if (sdata->vif.bss_conf.use_short_preamble)
  337. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  338. if (sdata->vif.bss_conf.use_short_slot)
  339. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  340. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  341. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  342. sinfo->sta_flags.set = 0;
  343. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  344. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  345. BIT(NL80211_STA_FLAG_WME) |
  346. BIT(NL80211_STA_FLAG_MFP) |
  347. BIT(NL80211_STA_FLAG_AUTHENTICATED);
  348. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  349. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  350. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  351. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  352. if (test_sta_flag(sta, WLAN_STA_WME))
  353. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  354. if (test_sta_flag(sta, WLAN_STA_MFP))
  355. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  356. if (test_sta_flag(sta, WLAN_STA_AUTH))
  357. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  358. }
  359. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  360. int idx, u8 *mac, struct station_info *sinfo)
  361. {
  362. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  363. struct sta_info *sta;
  364. int ret = -ENOENT;
  365. rcu_read_lock();
  366. sta = sta_info_get_by_idx(sdata, idx);
  367. if (sta) {
  368. ret = 0;
  369. memcpy(mac, sta->sta.addr, ETH_ALEN);
  370. sta_set_sinfo(sta, sinfo);
  371. }
  372. rcu_read_unlock();
  373. return ret;
  374. }
  375. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  376. int idx, struct survey_info *survey)
  377. {
  378. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  379. return drv_get_survey(local, idx, survey);
  380. }
  381. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  382. u8 *mac, struct station_info *sinfo)
  383. {
  384. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  385. struct sta_info *sta;
  386. int ret = -ENOENT;
  387. rcu_read_lock();
  388. sta = sta_info_get_bss(sdata, mac);
  389. if (sta) {
  390. ret = 0;
  391. sta_set_sinfo(sta, sinfo);
  392. }
  393. rcu_read_unlock();
  394. return ret;
  395. }
  396. static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata,
  397. struct beacon_parameters *params)
  398. {
  399. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  400. bss_conf->ssid_len = params->ssid_len;
  401. if (params->ssid_len)
  402. memcpy(bss_conf->ssid, params->ssid, params->ssid_len);
  403. bss_conf->hidden_ssid =
  404. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  405. }
  406. /*
  407. * This handles both adding a beacon and setting new beacon info
  408. */
  409. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  410. struct beacon_parameters *params)
  411. {
  412. struct beacon_data *new, *old;
  413. int new_head_len, new_tail_len;
  414. int size;
  415. int err = -EINVAL;
  416. old = rtnl_dereference(sdata->u.ap.beacon);
  417. /* head must not be zero-length */
  418. if (params->head && !params->head_len)
  419. return -EINVAL;
  420. /*
  421. * This is a kludge. beacon interval should really be part
  422. * of the beacon information.
  423. */
  424. if (params->interval &&
  425. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  426. sdata->vif.bss_conf.beacon_int = params->interval;
  427. ieee80211_bss_info_change_notify(sdata,
  428. BSS_CHANGED_BEACON_INT);
  429. }
  430. /* Need to have a beacon head if we don't have one yet */
  431. if (!params->head && !old)
  432. return err;
  433. /* sorry, no way to start beaconing without dtim period */
  434. if (!params->dtim_period && !old)
  435. return err;
  436. /* new or old head? */
  437. if (params->head)
  438. new_head_len = params->head_len;
  439. else
  440. new_head_len = old->head_len;
  441. /* new or old tail? */
  442. if (params->tail || !old)
  443. /* params->tail_len will be zero for !params->tail */
  444. new_tail_len = params->tail_len;
  445. else
  446. new_tail_len = old->tail_len;
  447. size = sizeof(*new) + new_head_len + new_tail_len;
  448. new = kzalloc(size, GFP_KERNEL);
  449. if (!new)
  450. return -ENOMEM;
  451. /* start filling the new info now */
  452. /* new or old dtim period? */
  453. if (params->dtim_period)
  454. new->dtim_period = params->dtim_period;
  455. else
  456. new->dtim_period = old->dtim_period;
  457. /*
  458. * pointers go into the block we allocated,
  459. * memory is | beacon_data | head | tail |
  460. */
  461. new->head = ((u8 *) new) + sizeof(*new);
  462. new->tail = new->head + new_head_len;
  463. new->head_len = new_head_len;
  464. new->tail_len = new_tail_len;
  465. /* copy in head */
  466. if (params->head)
  467. memcpy(new->head, params->head, new_head_len);
  468. else
  469. memcpy(new->head, old->head, new_head_len);
  470. /* copy in optional tail */
  471. if (params->tail)
  472. memcpy(new->tail, params->tail, new_tail_len);
  473. else
  474. if (old)
  475. memcpy(new->tail, old->tail, new_tail_len);
  476. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  477. RCU_INIT_POINTER(sdata->u.ap.beacon, new);
  478. synchronize_rcu();
  479. kfree(old);
  480. ieee80211_config_ap_ssid(sdata, params);
  481. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  482. BSS_CHANGED_BEACON |
  483. BSS_CHANGED_SSID);
  484. return 0;
  485. }
  486. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  487. struct beacon_parameters *params)
  488. {
  489. struct ieee80211_sub_if_data *sdata;
  490. struct beacon_data *old;
  491. struct ieee80211_sub_if_data *vlan;
  492. int ret;
  493. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  494. old = rtnl_dereference(sdata->u.ap.beacon);
  495. if (old)
  496. return -EALREADY;
  497. ret = ieee80211_config_beacon(sdata, params);
  498. if (ret)
  499. return ret;
  500. /*
  501. * Apply control port protocol, this allows us to
  502. * not encrypt dynamic WEP control frames.
  503. */
  504. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  505. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  506. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  507. vlan->control_port_protocol =
  508. params->crypto.control_port_ethertype;
  509. vlan->control_port_no_encrypt =
  510. params->crypto.control_port_no_encrypt;
  511. }
  512. return 0;
  513. }
  514. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  515. struct beacon_parameters *params)
  516. {
  517. struct ieee80211_sub_if_data *sdata;
  518. struct beacon_data *old;
  519. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  520. old = rtnl_dereference(sdata->u.ap.beacon);
  521. if (!old)
  522. return -ENOENT;
  523. return ieee80211_config_beacon(sdata, params);
  524. }
  525. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  526. {
  527. struct ieee80211_sub_if_data *sdata;
  528. struct beacon_data *old;
  529. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  530. old = rtnl_dereference(sdata->u.ap.beacon);
  531. if (!old)
  532. return -ENOENT;
  533. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  534. synchronize_rcu();
  535. kfree(old);
  536. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  537. return 0;
  538. }
  539. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  540. struct iapp_layer2_update {
  541. u8 da[ETH_ALEN]; /* broadcast */
  542. u8 sa[ETH_ALEN]; /* STA addr */
  543. __be16 len; /* 6 */
  544. u8 dsap; /* 0 */
  545. u8 ssap; /* 0 */
  546. u8 control;
  547. u8 xid_info[3];
  548. } __packed;
  549. static void ieee80211_send_layer2_update(struct sta_info *sta)
  550. {
  551. struct iapp_layer2_update *msg;
  552. struct sk_buff *skb;
  553. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  554. * bridge devices */
  555. skb = dev_alloc_skb(sizeof(*msg));
  556. if (!skb)
  557. return;
  558. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  559. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  560. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  561. memset(msg->da, 0xff, ETH_ALEN);
  562. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  563. msg->len = htons(6);
  564. msg->dsap = 0;
  565. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  566. msg->control = 0xaf; /* XID response lsb.1111F101.
  567. * F=0 (no poll command; unsolicited frame) */
  568. msg->xid_info[0] = 0x81; /* XID format identifier */
  569. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  570. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  571. skb->dev = sta->sdata->dev;
  572. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  573. memset(skb->cb, 0, sizeof(skb->cb));
  574. netif_rx_ni(skb);
  575. }
  576. static void sta_apply_parameters(struct ieee80211_local *local,
  577. struct sta_info *sta,
  578. struct station_parameters *params)
  579. {
  580. u32 rates;
  581. int i, j;
  582. struct ieee80211_supported_band *sband;
  583. struct ieee80211_sub_if_data *sdata = sta->sdata;
  584. u32 mask, set;
  585. sband = local->hw.wiphy->bands[local->oper_channel->band];
  586. mask = params->sta_flags_mask;
  587. set = params->sta_flags_set;
  588. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  589. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  590. set_sta_flag(sta, WLAN_STA_AUTHORIZED);
  591. else
  592. clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
  593. }
  594. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  595. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  596. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  597. else
  598. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  599. }
  600. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  601. if (set & BIT(NL80211_STA_FLAG_WME)) {
  602. set_sta_flag(sta, WLAN_STA_WME);
  603. sta->sta.wme = true;
  604. } else {
  605. clear_sta_flag(sta, WLAN_STA_WME);
  606. sta->sta.wme = false;
  607. }
  608. }
  609. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  610. if (set & BIT(NL80211_STA_FLAG_MFP))
  611. set_sta_flag(sta, WLAN_STA_MFP);
  612. else
  613. clear_sta_flag(sta, WLAN_STA_MFP);
  614. }
  615. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  616. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  617. set_sta_flag(sta, WLAN_STA_AUTH);
  618. else
  619. clear_sta_flag(sta, WLAN_STA_AUTH);
  620. }
  621. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  622. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  623. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  624. else
  625. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  626. }
  627. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  628. sta->sta.uapsd_queues = params->uapsd_queues;
  629. sta->sta.max_sp = params->max_sp;
  630. }
  631. /*
  632. * cfg80211 validates this (1-2007) and allows setting the AID
  633. * only when creating a new station entry
  634. */
  635. if (params->aid)
  636. sta->sta.aid = params->aid;
  637. /*
  638. * FIXME: updating the following information is racy when this
  639. * function is called from ieee80211_change_station().
  640. * However, all this information should be static so
  641. * maybe we should just reject attemps to change it.
  642. */
  643. if (params->listen_interval >= 0)
  644. sta->listen_interval = params->listen_interval;
  645. if (params->supported_rates) {
  646. rates = 0;
  647. for (i = 0; i < params->supported_rates_len; i++) {
  648. int rate = (params->supported_rates[i] & 0x7f) * 5;
  649. for (j = 0; j < sband->n_bitrates; j++) {
  650. if (sband->bitrates[j].bitrate == rate)
  651. rates |= BIT(j);
  652. }
  653. }
  654. sta->sta.supp_rates[local->oper_channel->band] = rates;
  655. }
  656. if (params->ht_capa)
  657. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  658. params->ht_capa,
  659. &sta->sta.ht_cap);
  660. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  661. #ifdef CONFIG_MAC80211_MESH
  662. if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
  663. switch (params->plink_state) {
  664. case NL80211_PLINK_LISTEN:
  665. case NL80211_PLINK_ESTAB:
  666. case NL80211_PLINK_BLOCKED:
  667. sta->plink_state = params->plink_state;
  668. break;
  669. default:
  670. /* nothing */
  671. break;
  672. }
  673. else
  674. switch (params->plink_action) {
  675. case PLINK_ACTION_OPEN:
  676. mesh_plink_open(sta);
  677. break;
  678. case PLINK_ACTION_BLOCK:
  679. mesh_plink_block(sta);
  680. break;
  681. }
  682. #endif
  683. }
  684. }
  685. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  686. u8 *mac, struct station_parameters *params)
  687. {
  688. struct ieee80211_local *local = wiphy_priv(wiphy);
  689. struct sta_info *sta;
  690. struct ieee80211_sub_if_data *sdata;
  691. int err;
  692. int layer2_update;
  693. if (params->vlan) {
  694. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  695. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  696. sdata->vif.type != NL80211_IFTYPE_AP)
  697. return -EINVAL;
  698. } else
  699. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  700. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  701. return -EINVAL;
  702. if (is_multicast_ether_addr(mac))
  703. return -EINVAL;
  704. /* Only TDLS-supporting stations can add TDLS peers */
  705. if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  706. !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
  707. sdata->vif.type == NL80211_IFTYPE_STATION))
  708. return -ENOTSUPP;
  709. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  710. if (!sta)
  711. return -ENOMEM;
  712. set_sta_flag(sta, WLAN_STA_AUTH);
  713. set_sta_flag(sta, WLAN_STA_ASSOC);
  714. sta_apply_parameters(local, sta, params);
  715. rate_control_rate_init(sta);
  716. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  717. sdata->vif.type == NL80211_IFTYPE_AP;
  718. err = sta_info_insert_rcu(sta);
  719. if (err) {
  720. rcu_read_unlock();
  721. return err;
  722. }
  723. if (layer2_update)
  724. ieee80211_send_layer2_update(sta);
  725. rcu_read_unlock();
  726. return 0;
  727. }
  728. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  729. u8 *mac)
  730. {
  731. struct ieee80211_local *local = wiphy_priv(wiphy);
  732. struct ieee80211_sub_if_data *sdata;
  733. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  734. if (mac)
  735. return sta_info_destroy_addr_bss(sdata, mac);
  736. sta_info_flush(local, sdata);
  737. return 0;
  738. }
  739. static int ieee80211_change_station(struct wiphy *wiphy,
  740. struct net_device *dev,
  741. u8 *mac,
  742. struct station_parameters *params)
  743. {
  744. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  745. struct ieee80211_local *local = wiphy_priv(wiphy);
  746. struct sta_info *sta;
  747. struct ieee80211_sub_if_data *vlansdata;
  748. rcu_read_lock();
  749. sta = sta_info_get_bss(sdata, mac);
  750. if (!sta) {
  751. rcu_read_unlock();
  752. return -ENOENT;
  753. }
  754. /* The TDLS bit cannot be toggled after the STA was added */
  755. if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  756. !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
  757. !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  758. rcu_read_unlock();
  759. return -EINVAL;
  760. }
  761. if (params->vlan && params->vlan != sta->sdata->dev) {
  762. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  763. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  764. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  765. rcu_read_unlock();
  766. return -EINVAL;
  767. }
  768. if (params->vlan->ieee80211_ptr->use_4addr) {
  769. if (vlansdata->u.vlan.sta) {
  770. rcu_read_unlock();
  771. return -EBUSY;
  772. }
  773. RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
  774. }
  775. sta->sdata = vlansdata;
  776. ieee80211_send_layer2_update(sta);
  777. }
  778. sta_apply_parameters(local, sta, params);
  779. rcu_read_unlock();
  780. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  781. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  782. ieee80211_recalc_ps(local, -1);
  783. return 0;
  784. }
  785. #ifdef CONFIG_MAC80211_MESH
  786. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  787. u8 *dst, u8 *next_hop)
  788. {
  789. struct ieee80211_sub_if_data *sdata;
  790. struct mesh_path *mpath;
  791. struct sta_info *sta;
  792. int err;
  793. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  794. rcu_read_lock();
  795. sta = sta_info_get(sdata, next_hop);
  796. if (!sta) {
  797. rcu_read_unlock();
  798. return -ENOENT;
  799. }
  800. err = mesh_path_add(dst, sdata);
  801. if (err) {
  802. rcu_read_unlock();
  803. return err;
  804. }
  805. mpath = mesh_path_lookup(dst, sdata);
  806. if (!mpath) {
  807. rcu_read_unlock();
  808. return -ENXIO;
  809. }
  810. mesh_path_fix_nexthop(mpath, sta);
  811. rcu_read_unlock();
  812. return 0;
  813. }
  814. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  815. u8 *dst)
  816. {
  817. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  818. if (dst)
  819. return mesh_path_del(dst, sdata);
  820. mesh_path_flush_by_iface(sdata);
  821. return 0;
  822. }
  823. static int ieee80211_change_mpath(struct wiphy *wiphy,
  824. struct net_device *dev,
  825. u8 *dst, u8 *next_hop)
  826. {
  827. struct ieee80211_sub_if_data *sdata;
  828. struct mesh_path *mpath;
  829. struct sta_info *sta;
  830. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  831. rcu_read_lock();
  832. sta = sta_info_get(sdata, next_hop);
  833. if (!sta) {
  834. rcu_read_unlock();
  835. return -ENOENT;
  836. }
  837. mpath = mesh_path_lookup(dst, sdata);
  838. if (!mpath) {
  839. rcu_read_unlock();
  840. return -ENOENT;
  841. }
  842. mesh_path_fix_nexthop(mpath, sta);
  843. rcu_read_unlock();
  844. return 0;
  845. }
  846. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  847. struct mpath_info *pinfo)
  848. {
  849. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  850. if (next_hop_sta)
  851. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  852. else
  853. memset(next_hop, 0, ETH_ALEN);
  854. pinfo->generation = mesh_paths_generation;
  855. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  856. MPATH_INFO_SN |
  857. MPATH_INFO_METRIC |
  858. MPATH_INFO_EXPTIME |
  859. MPATH_INFO_DISCOVERY_TIMEOUT |
  860. MPATH_INFO_DISCOVERY_RETRIES |
  861. MPATH_INFO_FLAGS;
  862. pinfo->frame_qlen = mpath->frame_queue.qlen;
  863. pinfo->sn = mpath->sn;
  864. pinfo->metric = mpath->metric;
  865. if (time_before(jiffies, mpath->exp_time))
  866. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  867. pinfo->discovery_timeout =
  868. jiffies_to_msecs(mpath->discovery_timeout);
  869. pinfo->discovery_retries = mpath->discovery_retries;
  870. pinfo->flags = 0;
  871. if (mpath->flags & MESH_PATH_ACTIVE)
  872. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  873. if (mpath->flags & MESH_PATH_RESOLVING)
  874. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  875. if (mpath->flags & MESH_PATH_SN_VALID)
  876. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  877. if (mpath->flags & MESH_PATH_FIXED)
  878. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  879. if (mpath->flags & MESH_PATH_RESOLVING)
  880. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  881. pinfo->flags = mpath->flags;
  882. }
  883. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  884. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  885. {
  886. struct ieee80211_sub_if_data *sdata;
  887. struct mesh_path *mpath;
  888. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  889. rcu_read_lock();
  890. mpath = mesh_path_lookup(dst, sdata);
  891. if (!mpath) {
  892. rcu_read_unlock();
  893. return -ENOENT;
  894. }
  895. memcpy(dst, mpath->dst, ETH_ALEN);
  896. mpath_set_pinfo(mpath, next_hop, pinfo);
  897. rcu_read_unlock();
  898. return 0;
  899. }
  900. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  901. int idx, u8 *dst, u8 *next_hop,
  902. struct mpath_info *pinfo)
  903. {
  904. struct ieee80211_sub_if_data *sdata;
  905. struct mesh_path *mpath;
  906. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  907. rcu_read_lock();
  908. mpath = mesh_path_lookup_by_idx(idx, sdata);
  909. if (!mpath) {
  910. rcu_read_unlock();
  911. return -ENOENT;
  912. }
  913. memcpy(dst, mpath->dst, ETH_ALEN);
  914. mpath_set_pinfo(mpath, next_hop, pinfo);
  915. rcu_read_unlock();
  916. return 0;
  917. }
  918. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  919. struct net_device *dev,
  920. struct mesh_config *conf)
  921. {
  922. struct ieee80211_sub_if_data *sdata;
  923. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  924. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  925. return 0;
  926. }
  927. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  928. {
  929. return (mask >> (parm-1)) & 0x1;
  930. }
  931. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  932. const struct mesh_setup *setup)
  933. {
  934. u8 *new_ie;
  935. const u8 *old_ie;
  936. /* allocate information elements */
  937. new_ie = NULL;
  938. old_ie = ifmsh->ie;
  939. if (setup->ie_len) {
  940. new_ie = kmemdup(setup->ie, setup->ie_len,
  941. GFP_KERNEL);
  942. if (!new_ie)
  943. return -ENOMEM;
  944. }
  945. ifmsh->ie_len = setup->ie_len;
  946. ifmsh->ie = new_ie;
  947. kfree(old_ie);
  948. /* now copy the rest of the setup parameters */
  949. ifmsh->mesh_id_len = setup->mesh_id_len;
  950. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  951. ifmsh->mesh_pp_id = setup->path_sel_proto;
  952. ifmsh->mesh_pm_id = setup->path_metric;
  953. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  954. if (setup->is_authenticated)
  955. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  956. if (setup->is_secure)
  957. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  958. return 0;
  959. }
  960. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  961. struct net_device *dev, u32 mask,
  962. const struct mesh_config *nconf)
  963. {
  964. struct mesh_config *conf;
  965. struct ieee80211_sub_if_data *sdata;
  966. struct ieee80211_if_mesh *ifmsh;
  967. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  968. ifmsh = &sdata->u.mesh;
  969. /* Set the config options which we are interested in setting */
  970. conf = &(sdata->u.mesh.mshcfg);
  971. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  972. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  973. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  974. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  975. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  976. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  977. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  978. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  979. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  980. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  981. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  982. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  983. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  984. conf->dot11MeshTTL = nconf->element_ttl;
  985. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  986. conf->auto_open_plinks = nconf->auto_open_plinks;
  987. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  988. conf->dot11MeshHWMPmaxPREQretries =
  989. nconf->dot11MeshHWMPmaxPREQretries;
  990. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  991. conf->path_refresh_time = nconf->path_refresh_time;
  992. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  993. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  994. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  995. conf->dot11MeshHWMPactivePathTimeout =
  996. nconf->dot11MeshHWMPactivePathTimeout;
  997. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  998. conf->dot11MeshHWMPpreqMinInterval =
  999. nconf->dot11MeshHWMPpreqMinInterval;
  1000. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1001. mask))
  1002. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1003. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1004. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1005. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1006. ieee80211_mesh_root_setup(ifmsh);
  1007. }
  1008. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1009. /* our current gate announcement implementation rides on root
  1010. * announcements, so require this ifmsh to also be a root node
  1011. * */
  1012. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1013. !conf->dot11MeshHWMPRootMode) {
  1014. conf->dot11MeshHWMPRootMode = 1;
  1015. ieee80211_mesh_root_setup(ifmsh);
  1016. }
  1017. conf->dot11MeshGateAnnouncementProtocol =
  1018. nconf->dot11MeshGateAnnouncementProtocol;
  1019. }
  1020. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
  1021. conf->dot11MeshHWMPRannInterval =
  1022. nconf->dot11MeshHWMPRannInterval;
  1023. }
  1024. return 0;
  1025. }
  1026. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1027. const struct mesh_config *conf,
  1028. const struct mesh_setup *setup)
  1029. {
  1030. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1031. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1032. int err;
  1033. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1034. err = copy_mesh_setup(ifmsh, setup);
  1035. if (err)
  1036. return err;
  1037. ieee80211_start_mesh(sdata);
  1038. return 0;
  1039. }
  1040. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1041. {
  1042. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1043. ieee80211_stop_mesh(sdata);
  1044. return 0;
  1045. }
  1046. #endif
  1047. static int ieee80211_change_bss(struct wiphy *wiphy,
  1048. struct net_device *dev,
  1049. struct bss_parameters *params)
  1050. {
  1051. struct ieee80211_sub_if_data *sdata;
  1052. u32 changed = 0;
  1053. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1054. if (params->use_cts_prot >= 0) {
  1055. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1056. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1057. }
  1058. if (params->use_short_preamble >= 0) {
  1059. sdata->vif.bss_conf.use_short_preamble =
  1060. params->use_short_preamble;
  1061. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1062. }
  1063. if (!sdata->vif.bss_conf.use_short_slot &&
  1064. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  1065. sdata->vif.bss_conf.use_short_slot = true;
  1066. changed |= BSS_CHANGED_ERP_SLOT;
  1067. }
  1068. if (params->use_short_slot_time >= 0) {
  1069. sdata->vif.bss_conf.use_short_slot =
  1070. params->use_short_slot_time;
  1071. changed |= BSS_CHANGED_ERP_SLOT;
  1072. }
  1073. if (params->basic_rates) {
  1074. int i, j;
  1075. u32 rates = 0;
  1076. struct ieee80211_local *local = wiphy_priv(wiphy);
  1077. struct ieee80211_supported_band *sband =
  1078. wiphy->bands[local->oper_channel->band];
  1079. for (i = 0; i < params->basic_rates_len; i++) {
  1080. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1081. for (j = 0; j < sband->n_bitrates; j++) {
  1082. if (sband->bitrates[j].bitrate == rate)
  1083. rates |= BIT(j);
  1084. }
  1085. }
  1086. sdata->vif.bss_conf.basic_rates = rates;
  1087. changed |= BSS_CHANGED_BASIC_RATES;
  1088. }
  1089. if (params->ap_isolate >= 0) {
  1090. if (params->ap_isolate)
  1091. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1092. else
  1093. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1094. }
  1095. if (params->ht_opmode >= 0) {
  1096. sdata->vif.bss_conf.ht_operation_mode =
  1097. (u16) params->ht_opmode;
  1098. changed |= BSS_CHANGED_HT;
  1099. }
  1100. ieee80211_bss_info_change_notify(sdata, changed);
  1101. return 0;
  1102. }
  1103. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1104. struct net_device *dev,
  1105. struct ieee80211_txq_params *params)
  1106. {
  1107. struct ieee80211_local *local = wiphy_priv(wiphy);
  1108. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1109. struct ieee80211_tx_queue_params p;
  1110. if (!local->ops->conf_tx)
  1111. return -EOPNOTSUPP;
  1112. memset(&p, 0, sizeof(p));
  1113. p.aifs = params->aifs;
  1114. p.cw_max = params->cwmax;
  1115. p.cw_min = params->cwmin;
  1116. p.txop = params->txop;
  1117. /*
  1118. * Setting tx queue params disables u-apsd because it's only
  1119. * called in master mode.
  1120. */
  1121. p.uapsd = false;
  1122. if (params->queue >= local->hw.queues)
  1123. return -EINVAL;
  1124. sdata->tx_conf[params->queue] = p;
  1125. if (drv_conf_tx(local, sdata, params->queue, &p)) {
  1126. wiphy_debug(local->hw.wiphy,
  1127. "failed to set TX queue parameters for queue %d\n",
  1128. params->queue);
  1129. return -EINVAL;
  1130. }
  1131. return 0;
  1132. }
  1133. static int ieee80211_set_channel(struct wiphy *wiphy,
  1134. struct net_device *netdev,
  1135. struct ieee80211_channel *chan,
  1136. enum nl80211_channel_type channel_type)
  1137. {
  1138. struct ieee80211_local *local = wiphy_priv(wiphy);
  1139. struct ieee80211_sub_if_data *sdata = NULL;
  1140. struct ieee80211_channel *old_oper;
  1141. enum nl80211_channel_type old_oper_type;
  1142. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1143. if (netdev)
  1144. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1145. switch (ieee80211_get_channel_mode(local, NULL)) {
  1146. case CHAN_MODE_HOPPING:
  1147. return -EBUSY;
  1148. case CHAN_MODE_FIXED:
  1149. if (local->oper_channel != chan)
  1150. return -EBUSY;
  1151. if (!sdata && local->_oper_channel_type == channel_type)
  1152. return 0;
  1153. break;
  1154. case CHAN_MODE_UNDEFINED:
  1155. break;
  1156. }
  1157. if (sdata)
  1158. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1159. old_oper_type = local->_oper_channel_type;
  1160. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1161. return -EBUSY;
  1162. old_oper = local->oper_channel;
  1163. local->oper_channel = chan;
  1164. /* Update driver if changes were actually made. */
  1165. if ((old_oper != local->oper_channel) ||
  1166. (old_oper_type != local->_oper_channel_type))
  1167. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1168. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1169. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1170. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1171. return 0;
  1172. }
  1173. #ifdef CONFIG_PM
  1174. static int ieee80211_suspend(struct wiphy *wiphy,
  1175. struct cfg80211_wowlan *wowlan)
  1176. {
  1177. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1178. }
  1179. static int ieee80211_resume(struct wiphy *wiphy)
  1180. {
  1181. return __ieee80211_resume(wiphy_priv(wiphy));
  1182. }
  1183. #else
  1184. #define ieee80211_suspend NULL
  1185. #define ieee80211_resume NULL
  1186. #endif
  1187. static int ieee80211_scan(struct wiphy *wiphy,
  1188. struct net_device *dev,
  1189. struct cfg80211_scan_request *req)
  1190. {
  1191. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1192. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1193. case NL80211_IFTYPE_STATION:
  1194. case NL80211_IFTYPE_ADHOC:
  1195. case NL80211_IFTYPE_MESH_POINT:
  1196. case NL80211_IFTYPE_P2P_CLIENT:
  1197. break;
  1198. case NL80211_IFTYPE_P2P_GO:
  1199. if (sdata->local->ops->hw_scan)
  1200. break;
  1201. /*
  1202. * FIXME: implement NoA while scanning in software,
  1203. * for now fall through to allow scanning only when
  1204. * beaconing hasn't been configured yet
  1205. */
  1206. case NL80211_IFTYPE_AP:
  1207. if (sdata->u.ap.beacon)
  1208. return -EOPNOTSUPP;
  1209. break;
  1210. default:
  1211. return -EOPNOTSUPP;
  1212. }
  1213. return ieee80211_request_scan(sdata, req);
  1214. }
  1215. static int
  1216. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1217. struct net_device *dev,
  1218. struct cfg80211_sched_scan_request *req)
  1219. {
  1220. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1221. if (!sdata->local->ops->sched_scan_start)
  1222. return -EOPNOTSUPP;
  1223. return ieee80211_request_sched_scan_start(sdata, req);
  1224. }
  1225. static int
  1226. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1227. {
  1228. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1229. if (!sdata->local->ops->sched_scan_stop)
  1230. return -EOPNOTSUPP;
  1231. return ieee80211_request_sched_scan_stop(sdata);
  1232. }
  1233. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1234. struct cfg80211_auth_request *req)
  1235. {
  1236. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1237. }
  1238. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1239. struct cfg80211_assoc_request *req)
  1240. {
  1241. struct ieee80211_local *local = wiphy_priv(wiphy);
  1242. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1243. switch (ieee80211_get_channel_mode(local, sdata)) {
  1244. case CHAN_MODE_HOPPING:
  1245. return -EBUSY;
  1246. case CHAN_MODE_FIXED:
  1247. if (local->oper_channel == req->bss->channel)
  1248. break;
  1249. return -EBUSY;
  1250. case CHAN_MODE_UNDEFINED:
  1251. break;
  1252. }
  1253. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1254. }
  1255. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1256. struct cfg80211_deauth_request *req,
  1257. void *cookie)
  1258. {
  1259. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1260. req, cookie);
  1261. }
  1262. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1263. struct cfg80211_disassoc_request *req,
  1264. void *cookie)
  1265. {
  1266. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1267. req, cookie);
  1268. }
  1269. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1270. struct cfg80211_ibss_params *params)
  1271. {
  1272. struct ieee80211_local *local = wiphy_priv(wiphy);
  1273. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1274. switch (ieee80211_get_channel_mode(local, sdata)) {
  1275. case CHAN_MODE_HOPPING:
  1276. return -EBUSY;
  1277. case CHAN_MODE_FIXED:
  1278. if (!params->channel_fixed)
  1279. return -EBUSY;
  1280. if (local->oper_channel == params->channel)
  1281. break;
  1282. return -EBUSY;
  1283. case CHAN_MODE_UNDEFINED:
  1284. break;
  1285. }
  1286. return ieee80211_ibss_join(sdata, params);
  1287. }
  1288. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1289. {
  1290. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1291. return ieee80211_ibss_leave(sdata);
  1292. }
  1293. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1294. {
  1295. struct ieee80211_local *local = wiphy_priv(wiphy);
  1296. int err;
  1297. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1298. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1299. if (err)
  1300. return err;
  1301. }
  1302. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1303. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1304. if (err)
  1305. return err;
  1306. }
  1307. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1308. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1309. if (err)
  1310. return err;
  1311. }
  1312. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1313. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1314. if (changed & WIPHY_PARAM_RETRY_LONG)
  1315. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1316. if (changed &
  1317. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1318. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1319. return 0;
  1320. }
  1321. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1322. enum nl80211_tx_power_setting type, int mbm)
  1323. {
  1324. struct ieee80211_local *local = wiphy_priv(wiphy);
  1325. struct ieee80211_channel *chan = local->hw.conf.channel;
  1326. u32 changes = 0;
  1327. switch (type) {
  1328. case NL80211_TX_POWER_AUTOMATIC:
  1329. local->user_power_level = -1;
  1330. break;
  1331. case NL80211_TX_POWER_LIMITED:
  1332. if (mbm < 0 || (mbm % 100))
  1333. return -EOPNOTSUPP;
  1334. local->user_power_level = MBM_TO_DBM(mbm);
  1335. break;
  1336. case NL80211_TX_POWER_FIXED:
  1337. if (mbm < 0 || (mbm % 100))
  1338. return -EOPNOTSUPP;
  1339. /* TODO: move to cfg80211 when it knows the channel */
  1340. if (MBM_TO_DBM(mbm) > chan->max_power)
  1341. return -EINVAL;
  1342. local->user_power_level = MBM_TO_DBM(mbm);
  1343. break;
  1344. }
  1345. ieee80211_hw_config(local, changes);
  1346. return 0;
  1347. }
  1348. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1349. {
  1350. struct ieee80211_local *local = wiphy_priv(wiphy);
  1351. *dbm = local->hw.conf.power_level;
  1352. return 0;
  1353. }
  1354. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1355. const u8 *addr)
  1356. {
  1357. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1358. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1359. return 0;
  1360. }
  1361. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1362. {
  1363. struct ieee80211_local *local = wiphy_priv(wiphy);
  1364. drv_rfkill_poll(local);
  1365. }
  1366. #ifdef CONFIG_NL80211_TESTMODE
  1367. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1368. {
  1369. struct ieee80211_local *local = wiphy_priv(wiphy);
  1370. if (!local->ops->testmode_cmd)
  1371. return -EOPNOTSUPP;
  1372. return local->ops->testmode_cmd(&local->hw, data, len);
  1373. }
  1374. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1375. struct sk_buff *skb,
  1376. struct netlink_callback *cb,
  1377. void *data, int len)
  1378. {
  1379. struct ieee80211_local *local = wiphy_priv(wiphy);
  1380. if (!local->ops->testmode_dump)
  1381. return -EOPNOTSUPP;
  1382. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1383. }
  1384. #endif
  1385. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1386. enum ieee80211_smps_mode smps_mode)
  1387. {
  1388. const u8 *ap;
  1389. enum ieee80211_smps_mode old_req;
  1390. int err;
  1391. lockdep_assert_held(&sdata->u.mgd.mtx);
  1392. old_req = sdata->u.mgd.req_smps;
  1393. sdata->u.mgd.req_smps = smps_mode;
  1394. if (old_req == smps_mode &&
  1395. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1396. return 0;
  1397. /*
  1398. * If not associated, or current association is not an HT
  1399. * association, there's no need to send an action frame.
  1400. */
  1401. if (!sdata->u.mgd.associated ||
  1402. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1403. mutex_lock(&sdata->local->iflist_mtx);
  1404. ieee80211_recalc_smps(sdata->local);
  1405. mutex_unlock(&sdata->local->iflist_mtx);
  1406. return 0;
  1407. }
  1408. ap = sdata->u.mgd.associated->bssid;
  1409. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1410. if (sdata->u.mgd.powersave)
  1411. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1412. else
  1413. smps_mode = IEEE80211_SMPS_OFF;
  1414. }
  1415. /* send SM PS frame to AP */
  1416. err = ieee80211_send_smps_action(sdata, smps_mode,
  1417. ap, ap);
  1418. if (err)
  1419. sdata->u.mgd.req_smps = old_req;
  1420. return err;
  1421. }
  1422. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1423. bool enabled, int timeout)
  1424. {
  1425. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1426. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1427. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1428. return -EOPNOTSUPP;
  1429. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1430. return -EOPNOTSUPP;
  1431. if (enabled == sdata->u.mgd.powersave &&
  1432. timeout == local->dynamic_ps_forced_timeout)
  1433. return 0;
  1434. sdata->u.mgd.powersave = enabled;
  1435. local->dynamic_ps_forced_timeout = timeout;
  1436. /* no change, but if automatic follow powersave */
  1437. mutex_lock(&sdata->u.mgd.mtx);
  1438. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1439. mutex_unlock(&sdata->u.mgd.mtx);
  1440. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1441. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1442. ieee80211_recalc_ps(local, -1);
  1443. return 0;
  1444. }
  1445. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1446. struct net_device *dev,
  1447. s32 rssi_thold, u32 rssi_hyst)
  1448. {
  1449. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1450. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1451. struct ieee80211_vif *vif = &sdata->vif;
  1452. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1453. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1454. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1455. return 0;
  1456. bss_conf->cqm_rssi_thold = rssi_thold;
  1457. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1458. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1459. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1460. return -EOPNOTSUPP;
  1461. return 0;
  1462. }
  1463. /* tell the driver upon association, unless already associated */
  1464. if (sdata->u.mgd.associated)
  1465. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1466. return 0;
  1467. }
  1468. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1469. struct net_device *dev,
  1470. const u8 *addr,
  1471. const struct cfg80211_bitrate_mask *mask)
  1472. {
  1473. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1474. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1475. int i, ret;
  1476. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1477. ret = drv_set_bitrate_mask(local, sdata, mask);
  1478. if (ret)
  1479. return ret;
  1480. }
  1481. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1482. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1483. return 0;
  1484. }
  1485. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1486. struct net_device *dev,
  1487. struct ieee80211_channel *chan,
  1488. enum nl80211_channel_type chantype,
  1489. unsigned int duration, u64 *cookie)
  1490. {
  1491. int ret;
  1492. u32 random_cookie;
  1493. lockdep_assert_held(&local->mtx);
  1494. if (local->hw_roc_cookie)
  1495. return -EBUSY;
  1496. /* must be nonzero */
  1497. random_cookie = random32() | 1;
  1498. *cookie = random_cookie;
  1499. local->hw_roc_dev = dev;
  1500. local->hw_roc_cookie = random_cookie;
  1501. local->hw_roc_channel = chan;
  1502. local->hw_roc_channel_type = chantype;
  1503. local->hw_roc_duration = duration;
  1504. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1505. if (ret) {
  1506. local->hw_roc_channel = NULL;
  1507. local->hw_roc_cookie = 0;
  1508. }
  1509. return ret;
  1510. }
  1511. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1512. struct net_device *dev,
  1513. struct ieee80211_channel *chan,
  1514. enum nl80211_channel_type channel_type,
  1515. unsigned int duration,
  1516. u64 *cookie)
  1517. {
  1518. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1519. struct ieee80211_local *local = sdata->local;
  1520. if (local->ops->remain_on_channel) {
  1521. int ret;
  1522. mutex_lock(&local->mtx);
  1523. ret = ieee80211_remain_on_channel_hw(local, dev,
  1524. chan, channel_type,
  1525. duration, cookie);
  1526. local->hw_roc_for_tx = false;
  1527. mutex_unlock(&local->mtx);
  1528. return ret;
  1529. }
  1530. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1531. duration, cookie);
  1532. }
  1533. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1534. u64 cookie)
  1535. {
  1536. int ret;
  1537. lockdep_assert_held(&local->mtx);
  1538. if (local->hw_roc_cookie != cookie)
  1539. return -ENOENT;
  1540. ret = drv_cancel_remain_on_channel(local);
  1541. if (ret)
  1542. return ret;
  1543. local->hw_roc_cookie = 0;
  1544. local->hw_roc_channel = NULL;
  1545. ieee80211_recalc_idle(local);
  1546. return 0;
  1547. }
  1548. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1549. struct net_device *dev,
  1550. u64 cookie)
  1551. {
  1552. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1553. struct ieee80211_local *local = sdata->local;
  1554. if (local->ops->cancel_remain_on_channel) {
  1555. int ret;
  1556. mutex_lock(&local->mtx);
  1557. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1558. mutex_unlock(&local->mtx);
  1559. return ret;
  1560. }
  1561. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1562. }
  1563. static enum work_done_result
  1564. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1565. {
  1566. /*
  1567. * Use the data embedded in the work struct for reporting
  1568. * here so if the driver mangled the SKB before dropping
  1569. * it (which is the only way we really should get here)
  1570. * then we don't report mangled data.
  1571. *
  1572. * If there was no wait time, then by the time we get here
  1573. * the driver will likely not have reported the status yet,
  1574. * so in that case userspace will have to deal with it.
  1575. */
  1576. if (wk->offchan_tx.wait && !wk->offchan_tx.status)
  1577. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1578. (unsigned long) wk->offchan_tx.frame,
  1579. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1580. return WORK_DONE_DESTROY;
  1581. }
  1582. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1583. struct ieee80211_channel *chan, bool offchan,
  1584. enum nl80211_channel_type channel_type,
  1585. bool channel_type_valid, unsigned int wait,
  1586. const u8 *buf, size_t len, bool no_cck,
  1587. bool dont_wait_for_ack, u64 *cookie)
  1588. {
  1589. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1590. struct ieee80211_local *local = sdata->local;
  1591. struct sk_buff *skb;
  1592. struct sta_info *sta;
  1593. struct ieee80211_work *wk;
  1594. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1595. u32 flags;
  1596. bool is_offchan = false;
  1597. if (dont_wait_for_ack)
  1598. flags = IEEE80211_TX_CTL_NO_ACK;
  1599. else
  1600. flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1601. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1602. /* Check that we are on the requested channel for transmission */
  1603. if (chan != local->tmp_channel &&
  1604. chan != local->oper_channel)
  1605. is_offchan = true;
  1606. if (channel_type_valid &&
  1607. (channel_type != local->tmp_channel_type &&
  1608. channel_type != local->_oper_channel_type))
  1609. is_offchan = true;
  1610. if (chan == local->hw_roc_channel) {
  1611. /* TODO: check channel type? */
  1612. is_offchan = false;
  1613. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1614. }
  1615. if (no_cck)
  1616. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  1617. if (is_offchan && !offchan)
  1618. return -EBUSY;
  1619. switch (sdata->vif.type) {
  1620. case NL80211_IFTYPE_ADHOC:
  1621. case NL80211_IFTYPE_AP:
  1622. case NL80211_IFTYPE_AP_VLAN:
  1623. case NL80211_IFTYPE_P2P_GO:
  1624. case NL80211_IFTYPE_MESH_POINT:
  1625. if (!ieee80211_is_action(mgmt->frame_control) ||
  1626. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1627. break;
  1628. rcu_read_lock();
  1629. sta = sta_info_get(sdata, mgmt->da);
  1630. rcu_read_unlock();
  1631. if (!sta)
  1632. return -ENOLINK;
  1633. break;
  1634. case NL80211_IFTYPE_STATION:
  1635. case NL80211_IFTYPE_P2P_CLIENT:
  1636. break;
  1637. default:
  1638. return -EOPNOTSUPP;
  1639. }
  1640. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1641. if (!skb)
  1642. return -ENOMEM;
  1643. skb_reserve(skb, local->hw.extra_tx_headroom);
  1644. memcpy(skb_put(skb, len), buf, len);
  1645. IEEE80211_SKB_CB(skb)->flags = flags;
  1646. skb->dev = sdata->dev;
  1647. *cookie = (unsigned long) skb;
  1648. if (is_offchan && local->ops->remain_on_channel) {
  1649. unsigned int duration;
  1650. int ret;
  1651. mutex_lock(&local->mtx);
  1652. /*
  1653. * If the duration is zero, then the driver
  1654. * wouldn't actually do anything. Set it to
  1655. * 100 for now.
  1656. *
  1657. * TODO: cancel the off-channel operation
  1658. * when we get the SKB's TX status and
  1659. * the wait time was zero before.
  1660. */
  1661. duration = 100;
  1662. if (wait)
  1663. duration = wait;
  1664. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1665. channel_type,
  1666. duration, cookie);
  1667. if (ret) {
  1668. kfree_skb(skb);
  1669. mutex_unlock(&local->mtx);
  1670. return ret;
  1671. }
  1672. local->hw_roc_for_tx = true;
  1673. local->hw_roc_duration = wait;
  1674. /*
  1675. * queue up frame for transmission after
  1676. * ieee80211_ready_on_channel call
  1677. */
  1678. /* modify cookie to prevent API mismatches */
  1679. *cookie ^= 2;
  1680. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1681. local->hw_roc_skb = skb;
  1682. local->hw_roc_skb_for_status = skb;
  1683. mutex_unlock(&local->mtx);
  1684. return 0;
  1685. }
  1686. /*
  1687. * Can transmit right away if the channel was the
  1688. * right one and there's no wait involved... If a
  1689. * wait is involved, we might otherwise not be on
  1690. * the right channel for long enough!
  1691. */
  1692. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1693. ieee80211_tx_skb(sdata, skb);
  1694. return 0;
  1695. }
  1696. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1697. if (!wk) {
  1698. kfree_skb(skb);
  1699. return -ENOMEM;
  1700. }
  1701. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1702. wk->chan = chan;
  1703. wk->chan_type = channel_type;
  1704. wk->sdata = sdata;
  1705. wk->done = ieee80211_offchan_tx_done;
  1706. wk->offchan_tx.frame = skb;
  1707. wk->offchan_tx.wait = wait;
  1708. wk->ie_len = len;
  1709. memcpy(wk->ie, buf, len);
  1710. ieee80211_add_work(wk);
  1711. return 0;
  1712. }
  1713. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1714. struct net_device *dev,
  1715. u64 cookie)
  1716. {
  1717. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1718. struct ieee80211_local *local = sdata->local;
  1719. struct ieee80211_work *wk;
  1720. int ret = -ENOENT;
  1721. mutex_lock(&local->mtx);
  1722. if (local->ops->cancel_remain_on_channel) {
  1723. cookie ^= 2;
  1724. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1725. if (ret == 0) {
  1726. kfree_skb(local->hw_roc_skb);
  1727. local->hw_roc_skb = NULL;
  1728. local->hw_roc_skb_for_status = NULL;
  1729. }
  1730. mutex_unlock(&local->mtx);
  1731. return ret;
  1732. }
  1733. list_for_each_entry(wk, &local->work_list, list) {
  1734. if (wk->sdata != sdata)
  1735. continue;
  1736. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1737. continue;
  1738. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1739. continue;
  1740. wk->timeout = jiffies;
  1741. ieee80211_queue_work(&local->hw, &local->work_work);
  1742. ret = 0;
  1743. break;
  1744. }
  1745. mutex_unlock(&local->mtx);
  1746. return ret;
  1747. }
  1748. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1749. struct net_device *dev,
  1750. u16 frame_type, bool reg)
  1751. {
  1752. struct ieee80211_local *local = wiphy_priv(wiphy);
  1753. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1754. return;
  1755. if (reg)
  1756. local->probe_req_reg++;
  1757. else
  1758. local->probe_req_reg--;
  1759. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1760. }
  1761. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1762. {
  1763. struct ieee80211_local *local = wiphy_priv(wiphy);
  1764. if (local->started)
  1765. return -EOPNOTSUPP;
  1766. return drv_set_antenna(local, tx_ant, rx_ant);
  1767. }
  1768. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1769. {
  1770. struct ieee80211_local *local = wiphy_priv(wiphy);
  1771. return drv_get_antenna(local, tx_ant, rx_ant);
  1772. }
  1773. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1774. {
  1775. struct ieee80211_local *local = wiphy_priv(wiphy);
  1776. return drv_set_ringparam(local, tx, rx);
  1777. }
  1778. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1779. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1780. {
  1781. struct ieee80211_local *local = wiphy_priv(wiphy);
  1782. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1783. }
  1784. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  1785. struct net_device *dev,
  1786. struct cfg80211_gtk_rekey_data *data)
  1787. {
  1788. struct ieee80211_local *local = wiphy_priv(wiphy);
  1789. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1790. if (!local->ops->set_rekey_data)
  1791. return -EOPNOTSUPP;
  1792. drv_set_rekey_data(local, sdata, data);
  1793. return 0;
  1794. }
  1795. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  1796. {
  1797. u8 *pos = (void *)skb_put(skb, 7);
  1798. *pos++ = WLAN_EID_EXT_CAPABILITY;
  1799. *pos++ = 5; /* len */
  1800. *pos++ = 0x0;
  1801. *pos++ = 0x0;
  1802. *pos++ = 0x0;
  1803. *pos++ = 0x0;
  1804. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  1805. }
  1806. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  1807. {
  1808. struct ieee80211_local *local = sdata->local;
  1809. u16 capab;
  1810. capab = 0;
  1811. if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
  1812. return capab;
  1813. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  1814. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  1815. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  1816. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  1817. return capab;
  1818. }
  1819. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  1820. u8 *peer, u8 *bssid)
  1821. {
  1822. struct ieee80211_tdls_lnkie *lnkid;
  1823. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  1824. lnkid->ie_type = WLAN_EID_LINK_ID;
  1825. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  1826. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  1827. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  1828. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  1829. }
  1830. static int
  1831. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  1832. u8 *peer, u8 action_code, u8 dialog_token,
  1833. u16 status_code, struct sk_buff *skb)
  1834. {
  1835. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1836. struct ieee80211_tdls_data *tf;
  1837. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  1838. memcpy(tf->da, peer, ETH_ALEN);
  1839. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  1840. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  1841. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  1842. switch (action_code) {
  1843. case WLAN_TDLS_SETUP_REQUEST:
  1844. tf->category = WLAN_CATEGORY_TDLS;
  1845. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  1846. skb_put(skb, sizeof(tf->u.setup_req));
  1847. tf->u.setup_req.dialog_token = dialog_token;
  1848. tf->u.setup_req.capability =
  1849. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1850. ieee80211_add_srates_ie(&sdata->vif, skb);
  1851. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1852. ieee80211_tdls_add_ext_capab(skb);
  1853. break;
  1854. case WLAN_TDLS_SETUP_RESPONSE:
  1855. tf->category = WLAN_CATEGORY_TDLS;
  1856. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  1857. skb_put(skb, sizeof(tf->u.setup_resp));
  1858. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  1859. tf->u.setup_resp.dialog_token = dialog_token;
  1860. tf->u.setup_resp.capability =
  1861. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1862. ieee80211_add_srates_ie(&sdata->vif, skb);
  1863. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1864. ieee80211_tdls_add_ext_capab(skb);
  1865. break;
  1866. case WLAN_TDLS_SETUP_CONFIRM:
  1867. tf->category = WLAN_CATEGORY_TDLS;
  1868. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  1869. skb_put(skb, sizeof(tf->u.setup_cfm));
  1870. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  1871. tf->u.setup_cfm.dialog_token = dialog_token;
  1872. break;
  1873. case WLAN_TDLS_TEARDOWN:
  1874. tf->category = WLAN_CATEGORY_TDLS;
  1875. tf->action_code = WLAN_TDLS_TEARDOWN;
  1876. skb_put(skb, sizeof(tf->u.teardown));
  1877. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  1878. break;
  1879. case WLAN_TDLS_DISCOVERY_REQUEST:
  1880. tf->category = WLAN_CATEGORY_TDLS;
  1881. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  1882. skb_put(skb, sizeof(tf->u.discover_req));
  1883. tf->u.discover_req.dialog_token = dialog_token;
  1884. break;
  1885. default:
  1886. return -EINVAL;
  1887. }
  1888. return 0;
  1889. }
  1890. static int
  1891. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  1892. u8 *peer, u8 action_code, u8 dialog_token,
  1893. u16 status_code, struct sk_buff *skb)
  1894. {
  1895. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1896. struct ieee80211_mgmt *mgmt;
  1897. mgmt = (void *)skb_put(skb, 24);
  1898. memset(mgmt, 0, 24);
  1899. memcpy(mgmt->da, peer, ETH_ALEN);
  1900. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1901. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1902. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1903. IEEE80211_STYPE_ACTION);
  1904. switch (action_code) {
  1905. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1906. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  1907. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  1908. mgmt->u.action.u.tdls_discover_resp.action_code =
  1909. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  1910. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  1911. dialog_token;
  1912. mgmt->u.action.u.tdls_discover_resp.capability =
  1913. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1914. ieee80211_add_srates_ie(&sdata->vif, skb);
  1915. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1916. ieee80211_tdls_add_ext_capab(skb);
  1917. break;
  1918. default:
  1919. return -EINVAL;
  1920. }
  1921. return 0;
  1922. }
  1923. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1924. u8 *peer, u8 action_code, u8 dialog_token,
  1925. u16 status_code, const u8 *extra_ies,
  1926. size_t extra_ies_len)
  1927. {
  1928. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1929. struct ieee80211_local *local = sdata->local;
  1930. struct ieee80211_tx_info *info;
  1931. struct sk_buff *skb = NULL;
  1932. bool send_direct;
  1933. int ret;
  1934. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  1935. return -ENOTSUPP;
  1936. /* make sure we are in managed mode, and associated */
  1937. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  1938. !sdata->u.mgd.associated)
  1939. return -EINVAL;
  1940. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  1941. printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
  1942. #endif
  1943. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  1944. max(sizeof(struct ieee80211_mgmt),
  1945. sizeof(struct ieee80211_tdls_data)) +
  1946. 50 + /* supported rates */
  1947. 7 + /* ext capab */
  1948. extra_ies_len +
  1949. sizeof(struct ieee80211_tdls_lnkie));
  1950. if (!skb)
  1951. return -ENOMEM;
  1952. info = IEEE80211_SKB_CB(skb);
  1953. skb_reserve(skb, local->hw.extra_tx_headroom);
  1954. switch (action_code) {
  1955. case WLAN_TDLS_SETUP_REQUEST:
  1956. case WLAN_TDLS_SETUP_RESPONSE:
  1957. case WLAN_TDLS_SETUP_CONFIRM:
  1958. case WLAN_TDLS_TEARDOWN:
  1959. case WLAN_TDLS_DISCOVERY_REQUEST:
  1960. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  1961. action_code, dialog_token,
  1962. status_code, skb);
  1963. send_direct = false;
  1964. break;
  1965. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1966. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  1967. dialog_token, status_code,
  1968. skb);
  1969. send_direct = true;
  1970. break;
  1971. default:
  1972. ret = -ENOTSUPP;
  1973. break;
  1974. }
  1975. if (ret < 0)
  1976. goto fail;
  1977. if (extra_ies_len)
  1978. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  1979. /* the TDLS link IE is always added last */
  1980. switch (action_code) {
  1981. case WLAN_TDLS_SETUP_REQUEST:
  1982. case WLAN_TDLS_SETUP_CONFIRM:
  1983. case WLAN_TDLS_TEARDOWN:
  1984. case WLAN_TDLS_DISCOVERY_REQUEST:
  1985. /* we are the initiator */
  1986. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  1987. sdata->u.mgd.bssid);
  1988. break;
  1989. case WLAN_TDLS_SETUP_RESPONSE:
  1990. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1991. /* we are the responder */
  1992. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  1993. sdata->u.mgd.bssid);
  1994. break;
  1995. default:
  1996. ret = -ENOTSUPP;
  1997. goto fail;
  1998. }
  1999. if (send_direct) {
  2000. ieee80211_tx_skb(sdata, skb);
  2001. return 0;
  2002. }
  2003. /*
  2004. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  2005. * we should default to AC_VI.
  2006. */
  2007. switch (action_code) {
  2008. case WLAN_TDLS_SETUP_REQUEST:
  2009. case WLAN_TDLS_SETUP_RESPONSE:
  2010. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  2011. skb->priority = 2;
  2012. break;
  2013. default:
  2014. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  2015. skb->priority = 5;
  2016. break;
  2017. }
  2018. /* disable bottom halves when entering the Tx path */
  2019. local_bh_disable();
  2020. ret = ieee80211_subif_start_xmit(skb, dev);
  2021. local_bh_enable();
  2022. return ret;
  2023. fail:
  2024. dev_kfree_skb(skb);
  2025. return ret;
  2026. }
  2027. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2028. u8 *peer, enum nl80211_tdls_operation oper)
  2029. {
  2030. struct sta_info *sta;
  2031. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2032. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2033. return -ENOTSUPP;
  2034. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2035. return -EINVAL;
  2036. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  2037. printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
  2038. #endif
  2039. switch (oper) {
  2040. case NL80211_TDLS_ENABLE_LINK:
  2041. rcu_read_lock();
  2042. sta = sta_info_get(sdata, peer);
  2043. if (!sta) {
  2044. rcu_read_unlock();
  2045. return -ENOLINK;
  2046. }
  2047. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2048. rcu_read_unlock();
  2049. break;
  2050. case NL80211_TDLS_DISABLE_LINK:
  2051. return sta_info_destroy_addr(sdata, peer);
  2052. case NL80211_TDLS_TEARDOWN:
  2053. case NL80211_TDLS_SETUP:
  2054. case NL80211_TDLS_DISCOVERY_REQ:
  2055. /* We don't support in-driver setup/teardown/discovery */
  2056. return -ENOTSUPP;
  2057. default:
  2058. return -ENOTSUPP;
  2059. }
  2060. return 0;
  2061. }
  2062. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2063. const u8 *peer, u64 *cookie)
  2064. {
  2065. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2066. struct ieee80211_local *local = sdata->local;
  2067. struct ieee80211_qos_hdr *nullfunc;
  2068. struct sk_buff *skb;
  2069. int size = sizeof(*nullfunc);
  2070. __le16 fc;
  2071. bool qos;
  2072. struct ieee80211_tx_info *info;
  2073. struct sta_info *sta;
  2074. rcu_read_lock();
  2075. sta = sta_info_get(sdata, peer);
  2076. if (sta)
  2077. qos = test_sta_flag(sta, WLAN_STA_WME);
  2078. rcu_read_unlock();
  2079. if (!sta)
  2080. return -ENOLINK;
  2081. if (qos) {
  2082. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2083. IEEE80211_STYPE_QOS_NULLFUNC |
  2084. IEEE80211_FCTL_FROMDS);
  2085. } else {
  2086. size -= 2;
  2087. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2088. IEEE80211_STYPE_NULLFUNC |
  2089. IEEE80211_FCTL_FROMDS);
  2090. }
  2091. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2092. if (!skb)
  2093. return -ENOMEM;
  2094. skb->dev = dev;
  2095. skb_reserve(skb, local->hw.extra_tx_headroom);
  2096. nullfunc = (void *) skb_put(skb, size);
  2097. nullfunc->frame_control = fc;
  2098. nullfunc->duration_id = 0;
  2099. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2100. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2101. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2102. nullfunc->seq_ctrl = 0;
  2103. info = IEEE80211_SKB_CB(skb);
  2104. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2105. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2106. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2107. skb->priority = 7;
  2108. if (qos)
  2109. nullfunc->qos_ctrl = cpu_to_le16(7);
  2110. local_bh_disable();
  2111. ieee80211_xmit(sdata, skb);
  2112. local_bh_enable();
  2113. *cookie = (unsigned long) skb;
  2114. return 0;
  2115. }
  2116. struct cfg80211_ops mac80211_config_ops = {
  2117. .add_virtual_intf = ieee80211_add_iface,
  2118. .del_virtual_intf = ieee80211_del_iface,
  2119. .change_virtual_intf = ieee80211_change_iface,
  2120. .add_key = ieee80211_add_key,
  2121. .del_key = ieee80211_del_key,
  2122. .get_key = ieee80211_get_key,
  2123. .set_default_key = ieee80211_config_default_key,
  2124. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2125. .add_beacon = ieee80211_add_beacon,
  2126. .set_beacon = ieee80211_set_beacon,
  2127. .del_beacon = ieee80211_del_beacon,
  2128. .add_station = ieee80211_add_station,
  2129. .del_station = ieee80211_del_station,
  2130. .change_station = ieee80211_change_station,
  2131. .get_station = ieee80211_get_station,
  2132. .dump_station = ieee80211_dump_station,
  2133. .dump_survey = ieee80211_dump_survey,
  2134. #ifdef CONFIG_MAC80211_MESH
  2135. .add_mpath = ieee80211_add_mpath,
  2136. .del_mpath = ieee80211_del_mpath,
  2137. .change_mpath = ieee80211_change_mpath,
  2138. .get_mpath = ieee80211_get_mpath,
  2139. .dump_mpath = ieee80211_dump_mpath,
  2140. .update_mesh_config = ieee80211_update_mesh_config,
  2141. .get_mesh_config = ieee80211_get_mesh_config,
  2142. .join_mesh = ieee80211_join_mesh,
  2143. .leave_mesh = ieee80211_leave_mesh,
  2144. #endif
  2145. .change_bss = ieee80211_change_bss,
  2146. .set_txq_params = ieee80211_set_txq_params,
  2147. .set_channel = ieee80211_set_channel,
  2148. .suspend = ieee80211_suspend,
  2149. .resume = ieee80211_resume,
  2150. .scan = ieee80211_scan,
  2151. .sched_scan_start = ieee80211_sched_scan_start,
  2152. .sched_scan_stop = ieee80211_sched_scan_stop,
  2153. .auth = ieee80211_auth,
  2154. .assoc = ieee80211_assoc,
  2155. .deauth = ieee80211_deauth,
  2156. .disassoc = ieee80211_disassoc,
  2157. .join_ibss = ieee80211_join_ibss,
  2158. .leave_ibss = ieee80211_leave_ibss,
  2159. .set_wiphy_params = ieee80211_set_wiphy_params,
  2160. .set_tx_power = ieee80211_set_tx_power,
  2161. .get_tx_power = ieee80211_get_tx_power,
  2162. .set_wds_peer = ieee80211_set_wds_peer,
  2163. .rfkill_poll = ieee80211_rfkill_poll,
  2164. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2165. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2166. .set_power_mgmt = ieee80211_set_power_mgmt,
  2167. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2168. .remain_on_channel = ieee80211_remain_on_channel,
  2169. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2170. .mgmt_tx = ieee80211_mgmt_tx,
  2171. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2172. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2173. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2174. .set_antenna = ieee80211_set_antenna,
  2175. .get_antenna = ieee80211_get_antenna,
  2176. .set_ringparam = ieee80211_set_ringparam,
  2177. .get_ringparam = ieee80211_get_ringparam,
  2178. .set_rekey_data = ieee80211_set_rekey_data,
  2179. .tdls_oper = ieee80211_tdls_oper,
  2180. .tdls_mgmt = ieee80211_tdls_mgmt,
  2181. .probe_client = ieee80211_probe_client,
  2182. };