cfg.c 68 KB

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