cfg.c 56 KB

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