cfg.c 54 KB

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