cfg.c 71 KB

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