cfg.c 71 KB

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