cfg.c 70 KB

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