cfg.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  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 int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  21. enum nl80211_iftype type, u32 *flags,
  22. struct vif_params *params)
  23. {
  24. struct ieee80211_local *local = wiphy_priv(wiphy);
  25. struct net_device *dev;
  26. struct ieee80211_sub_if_data *sdata;
  27. int err;
  28. err = ieee80211_if_add(local, name, &dev, type, params);
  29. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  30. return err;
  31. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  32. sdata->u.mntr_flags = *flags;
  33. return 0;
  34. }
  35. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  36. {
  37. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  38. return 0;
  39. }
  40. static int ieee80211_change_iface(struct wiphy *wiphy,
  41. struct net_device *dev,
  42. enum nl80211_iftype type, u32 *flags,
  43. struct vif_params *params)
  44. {
  45. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  46. int ret;
  47. ret = ieee80211_if_change_type(sdata, type);
  48. if (ret)
  49. return ret;
  50. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  51. ieee80211_sdata_set_mesh_id(sdata,
  52. params->mesh_id_len,
  53. params->mesh_id);
  54. if (type == NL80211_IFTYPE_AP_VLAN &&
  55. params && params->use_4addr == 0)
  56. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  57. else if (type == NL80211_IFTYPE_STATION &&
  58. params && params->use_4addr >= 0)
  59. sdata->u.mgd.use_4addr = params->use_4addr;
  60. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
  61. struct ieee80211_local *local = sdata->local;
  62. if (ieee80211_sdata_running(sdata)) {
  63. /*
  64. * Prohibit MONITOR_FLAG_COOK_FRAMES to be
  65. * changed while the interface is up.
  66. * Else we would need to add a lot of cruft
  67. * to update everything:
  68. * cooked_mntrs, monitor and all fif_* counters
  69. * reconfigure hardware
  70. */
  71. if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
  72. (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  73. return -EBUSY;
  74. ieee80211_adjust_monitor_flags(sdata, -1);
  75. sdata->u.mntr_flags = *flags;
  76. ieee80211_adjust_monitor_flags(sdata, 1);
  77. ieee80211_configure_filter(local);
  78. } else {
  79. /*
  80. * Because the interface is down, ieee80211_do_stop
  81. * and ieee80211_do_open take care of "everything"
  82. * mentioned in the comment above.
  83. */
  84. sdata->u.mntr_flags = *flags;
  85. }
  86. }
  87. return 0;
  88. }
  89. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  90. u8 key_idx, bool pairwise, const u8 *mac_addr,
  91. struct key_params *params)
  92. {
  93. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  94. struct sta_info *sta = NULL;
  95. struct ieee80211_key *key;
  96. int err;
  97. if (!ieee80211_sdata_running(sdata))
  98. return -ENETDOWN;
  99. /* reject WEP and TKIP keys if WEP failed to initialize */
  100. switch (params->cipher) {
  101. case WLAN_CIPHER_SUITE_WEP40:
  102. case WLAN_CIPHER_SUITE_TKIP:
  103. case WLAN_CIPHER_SUITE_WEP104:
  104. if (IS_ERR(sdata->local->wep_tx_tfm))
  105. return -EINVAL;
  106. break;
  107. default:
  108. break;
  109. }
  110. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  111. params->key, params->seq_len, params->seq);
  112. if (IS_ERR(key))
  113. return PTR_ERR(key);
  114. if (pairwise)
  115. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  116. mutex_lock(&sdata->local->sta_mtx);
  117. if (mac_addr) {
  118. sta = sta_info_get_bss(sdata, mac_addr);
  119. if (!sta) {
  120. ieee80211_key_free(sdata->local, key);
  121. err = -ENOENT;
  122. goto out_unlock;
  123. }
  124. }
  125. err = ieee80211_key_link(key, sdata, sta);
  126. if (err)
  127. ieee80211_key_free(sdata->local, key);
  128. out_unlock:
  129. mutex_unlock(&sdata->local->sta_mtx);
  130. return err;
  131. }
  132. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  133. u8 key_idx, bool pairwise, const u8 *mac_addr)
  134. {
  135. struct ieee80211_sub_if_data *sdata;
  136. struct sta_info *sta;
  137. int ret;
  138. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  139. mutex_lock(&sdata->local->sta_mtx);
  140. if (mac_addr) {
  141. ret = -ENOENT;
  142. sta = sta_info_get_bss(sdata, mac_addr);
  143. if (!sta)
  144. goto out_unlock;
  145. if (pairwise) {
  146. if (sta->ptk) {
  147. ieee80211_key_free(sdata->local, sta->ptk);
  148. ret = 0;
  149. }
  150. } else {
  151. if (sta->gtk[key_idx]) {
  152. ieee80211_key_free(sdata->local,
  153. sta->gtk[key_idx]);
  154. ret = 0;
  155. }
  156. }
  157. goto out_unlock;
  158. }
  159. if (!sdata->keys[key_idx]) {
  160. ret = -ENOENT;
  161. goto out_unlock;
  162. }
  163. ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
  164. WARN_ON(sdata->keys[key_idx]);
  165. ret = 0;
  166. out_unlock:
  167. mutex_unlock(&sdata->local->sta_mtx);
  168. return ret;
  169. }
  170. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  171. u8 key_idx, bool pairwise, const u8 *mac_addr,
  172. void *cookie,
  173. void (*callback)(void *cookie,
  174. struct key_params *params))
  175. {
  176. struct ieee80211_sub_if_data *sdata;
  177. struct sta_info *sta = NULL;
  178. u8 seq[6] = {0};
  179. struct key_params params;
  180. struct ieee80211_key *key = NULL;
  181. u32 iv32;
  182. u16 iv16;
  183. int err = -ENOENT;
  184. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  185. rcu_read_lock();
  186. if (mac_addr) {
  187. sta = sta_info_get_bss(sdata, mac_addr);
  188. if (!sta)
  189. goto out;
  190. if (pairwise)
  191. key = sta->ptk;
  192. else if (key_idx < NUM_DEFAULT_KEYS)
  193. key = sta->gtk[key_idx];
  194. } else
  195. key = sdata->keys[key_idx];
  196. if (!key)
  197. goto out;
  198. memset(&params, 0, sizeof(params));
  199. params.cipher = key->conf.cipher;
  200. switch (key->conf.cipher) {
  201. case WLAN_CIPHER_SUITE_TKIP:
  202. iv32 = key->u.tkip.tx.iv32;
  203. iv16 = key->u.tkip.tx.iv16;
  204. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  205. drv_get_tkip_seq(sdata->local,
  206. key->conf.hw_key_idx,
  207. &iv32, &iv16);
  208. seq[0] = iv16 & 0xff;
  209. seq[1] = (iv16 >> 8) & 0xff;
  210. seq[2] = iv32 & 0xff;
  211. seq[3] = (iv32 >> 8) & 0xff;
  212. seq[4] = (iv32 >> 16) & 0xff;
  213. seq[5] = (iv32 >> 24) & 0xff;
  214. params.seq = seq;
  215. params.seq_len = 6;
  216. break;
  217. case WLAN_CIPHER_SUITE_CCMP:
  218. seq[0] = key->u.ccmp.tx_pn[5];
  219. seq[1] = key->u.ccmp.tx_pn[4];
  220. seq[2] = key->u.ccmp.tx_pn[3];
  221. seq[3] = key->u.ccmp.tx_pn[2];
  222. seq[4] = key->u.ccmp.tx_pn[1];
  223. seq[5] = key->u.ccmp.tx_pn[0];
  224. params.seq = seq;
  225. params.seq_len = 6;
  226. break;
  227. case WLAN_CIPHER_SUITE_AES_CMAC:
  228. seq[0] = key->u.aes_cmac.tx_pn[5];
  229. seq[1] = key->u.aes_cmac.tx_pn[4];
  230. seq[2] = key->u.aes_cmac.tx_pn[3];
  231. seq[3] = key->u.aes_cmac.tx_pn[2];
  232. seq[4] = key->u.aes_cmac.tx_pn[1];
  233. seq[5] = key->u.aes_cmac.tx_pn[0];
  234. params.seq = seq;
  235. params.seq_len = 6;
  236. break;
  237. }
  238. params.key = key->conf.key;
  239. params.key_len = key->conf.keylen;
  240. callback(cookie, &params);
  241. err = 0;
  242. out:
  243. rcu_read_unlock();
  244. return err;
  245. }
  246. static int ieee80211_config_default_key(struct wiphy *wiphy,
  247. struct net_device *dev,
  248. u8 key_idx)
  249. {
  250. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  251. ieee80211_set_default_key(sdata, key_idx);
  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 sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  263. {
  264. struct ieee80211_sub_if_data *sdata = sta->sdata;
  265. sinfo->generation = sdata->local->sta_generation;
  266. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  267. STATION_INFO_RX_BYTES |
  268. STATION_INFO_TX_BYTES |
  269. STATION_INFO_RX_PACKETS |
  270. STATION_INFO_TX_PACKETS |
  271. STATION_INFO_TX_RETRIES |
  272. STATION_INFO_TX_FAILED |
  273. STATION_INFO_TX_BITRATE |
  274. STATION_INFO_RX_DROP_MISC;
  275. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  276. sinfo->rx_bytes = sta->rx_bytes;
  277. sinfo->tx_bytes = sta->tx_bytes;
  278. sinfo->rx_packets = sta->rx_packets;
  279. sinfo->tx_packets = sta->tx_packets;
  280. sinfo->tx_retries = sta->tx_retry_count;
  281. sinfo->tx_failed = sta->tx_retry_failed;
  282. sinfo->rx_dropped_misc = sta->rx_dropped;
  283. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  284. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  285. sinfo->filled |= STATION_INFO_SIGNAL;
  286. sinfo->signal = (s8)sta->last_signal;
  287. }
  288. sinfo->txrate.flags = 0;
  289. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  290. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  291. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  292. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  293. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  294. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  295. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  296. struct ieee80211_supported_band *sband;
  297. sband = sta->local->hw.wiphy->bands[
  298. sta->local->hw.conf.channel->band];
  299. sinfo->txrate.legacy =
  300. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  301. } else
  302. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  303. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  304. #ifdef CONFIG_MAC80211_MESH
  305. sinfo->filled |= STATION_INFO_LLID |
  306. STATION_INFO_PLID |
  307. STATION_INFO_PLINK_STATE;
  308. sinfo->llid = le16_to_cpu(sta->llid);
  309. sinfo->plid = le16_to_cpu(sta->plid);
  310. sinfo->plink_state = sta->plink_state;
  311. #endif
  312. }
  313. }
  314. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  315. int idx, u8 *mac, struct station_info *sinfo)
  316. {
  317. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  318. struct sta_info *sta;
  319. int ret = -ENOENT;
  320. rcu_read_lock();
  321. sta = sta_info_get_by_idx(sdata, idx);
  322. if (sta) {
  323. ret = 0;
  324. memcpy(mac, sta->sta.addr, ETH_ALEN);
  325. sta_set_sinfo(sta, sinfo);
  326. }
  327. rcu_read_unlock();
  328. return ret;
  329. }
  330. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  331. int idx, struct survey_info *survey)
  332. {
  333. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  334. return drv_get_survey(local, idx, survey);
  335. }
  336. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  337. u8 *mac, struct station_info *sinfo)
  338. {
  339. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  340. struct sta_info *sta;
  341. int ret = -ENOENT;
  342. rcu_read_lock();
  343. sta = sta_info_get_bss(sdata, mac);
  344. if (sta) {
  345. ret = 0;
  346. sta_set_sinfo(sta, sinfo);
  347. }
  348. rcu_read_unlock();
  349. return ret;
  350. }
  351. /*
  352. * This handles both adding a beacon and setting new beacon info
  353. */
  354. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  355. struct beacon_parameters *params)
  356. {
  357. struct beacon_data *new, *old;
  358. int new_head_len, new_tail_len;
  359. int size;
  360. int err = -EINVAL;
  361. old = sdata->u.ap.beacon;
  362. /* head must not be zero-length */
  363. if (params->head && !params->head_len)
  364. return -EINVAL;
  365. /*
  366. * This is a kludge. beacon interval should really be part
  367. * of the beacon information.
  368. */
  369. if (params->interval &&
  370. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  371. sdata->vif.bss_conf.beacon_int = params->interval;
  372. ieee80211_bss_info_change_notify(sdata,
  373. BSS_CHANGED_BEACON_INT);
  374. }
  375. /* Need to have a beacon head if we don't have one yet */
  376. if (!params->head && !old)
  377. return err;
  378. /* sorry, no way to start beaconing without dtim period */
  379. if (!params->dtim_period && !old)
  380. return err;
  381. /* new or old head? */
  382. if (params->head)
  383. new_head_len = params->head_len;
  384. else
  385. new_head_len = old->head_len;
  386. /* new or old tail? */
  387. if (params->tail || !old)
  388. /* params->tail_len will be zero for !params->tail */
  389. new_tail_len = params->tail_len;
  390. else
  391. new_tail_len = old->tail_len;
  392. size = sizeof(*new) + new_head_len + new_tail_len;
  393. new = kzalloc(size, GFP_KERNEL);
  394. if (!new)
  395. return -ENOMEM;
  396. /* start filling the new info now */
  397. /* new or old dtim period? */
  398. if (params->dtim_period)
  399. new->dtim_period = params->dtim_period;
  400. else
  401. new->dtim_period = old->dtim_period;
  402. /*
  403. * pointers go into the block we allocated,
  404. * memory is | beacon_data | head | tail |
  405. */
  406. new->head = ((u8 *) new) + sizeof(*new);
  407. new->tail = new->head + new_head_len;
  408. new->head_len = new_head_len;
  409. new->tail_len = new_tail_len;
  410. /* copy in head */
  411. if (params->head)
  412. memcpy(new->head, params->head, new_head_len);
  413. else
  414. memcpy(new->head, old->head, new_head_len);
  415. /* copy in optional tail */
  416. if (params->tail)
  417. memcpy(new->tail, params->tail, new_tail_len);
  418. else
  419. if (old)
  420. memcpy(new->tail, old->tail, new_tail_len);
  421. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  422. rcu_assign_pointer(sdata->u.ap.beacon, new);
  423. synchronize_rcu();
  424. kfree(old);
  425. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  426. BSS_CHANGED_BEACON);
  427. return 0;
  428. }
  429. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  430. struct beacon_parameters *params)
  431. {
  432. struct ieee80211_sub_if_data *sdata;
  433. struct beacon_data *old;
  434. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  435. old = sdata->u.ap.beacon;
  436. if (old)
  437. return -EALREADY;
  438. return ieee80211_config_beacon(sdata, params);
  439. }
  440. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  441. struct beacon_parameters *params)
  442. {
  443. struct ieee80211_sub_if_data *sdata;
  444. struct beacon_data *old;
  445. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  446. old = sdata->u.ap.beacon;
  447. if (!old)
  448. return -ENOENT;
  449. return ieee80211_config_beacon(sdata, params);
  450. }
  451. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  452. {
  453. struct ieee80211_sub_if_data *sdata;
  454. struct beacon_data *old;
  455. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  456. old = sdata->u.ap.beacon;
  457. if (!old)
  458. return -ENOENT;
  459. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  460. synchronize_rcu();
  461. kfree(old);
  462. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  463. return 0;
  464. }
  465. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  466. struct iapp_layer2_update {
  467. u8 da[ETH_ALEN]; /* broadcast */
  468. u8 sa[ETH_ALEN]; /* STA addr */
  469. __be16 len; /* 6 */
  470. u8 dsap; /* 0 */
  471. u8 ssap; /* 0 */
  472. u8 control;
  473. u8 xid_info[3];
  474. } __packed;
  475. static void ieee80211_send_layer2_update(struct sta_info *sta)
  476. {
  477. struct iapp_layer2_update *msg;
  478. struct sk_buff *skb;
  479. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  480. * bridge devices */
  481. skb = dev_alloc_skb(sizeof(*msg));
  482. if (!skb)
  483. return;
  484. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  485. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  486. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  487. memset(msg->da, 0xff, ETH_ALEN);
  488. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  489. msg->len = htons(6);
  490. msg->dsap = 0;
  491. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  492. msg->control = 0xaf; /* XID response lsb.1111F101.
  493. * F=0 (no poll command; unsolicited frame) */
  494. msg->xid_info[0] = 0x81; /* XID format identifier */
  495. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  496. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  497. skb->dev = sta->sdata->dev;
  498. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  499. memset(skb->cb, 0, sizeof(skb->cb));
  500. netif_rx_ni(skb);
  501. }
  502. static void sta_apply_parameters(struct ieee80211_local *local,
  503. struct sta_info *sta,
  504. struct station_parameters *params)
  505. {
  506. unsigned long flags;
  507. u32 rates;
  508. int i, j;
  509. struct ieee80211_supported_band *sband;
  510. struct ieee80211_sub_if_data *sdata = sta->sdata;
  511. u32 mask, set;
  512. sband = local->hw.wiphy->bands[local->oper_channel->band];
  513. spin_lock_irqsave(&sta->flaglock, flags);
  514. mask = params->sta_flags_mask;
  515. set = params->sta_flags_set;
  516. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  517. sta->flags &= ~WLAN_STA_AUTHORIZED;
  518. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  519. sta->flags |= WLAN_STA_AUTHORIZED;
  520. }
  521. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  522. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  523. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  524. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  525. }
  526. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  527. sta->flags &= ~WLAN_STA_WME;
  528. if (set & BIT(NL80211_STA_FLAG_WME))
  529. sta->flags |= WLAN_STA_WME;
  530. }
  531. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  532. sta->flags &= ~WLAN_STA_MFP;
  533. if (set & BIT(NL80211_STA_FLAG_MFP))
  534. sta->flags |= WLAN_STA_MFP;
  535. }
  536. spin_unlock_irqrestore(&sta->flaglock, flags);
  537. /*
  538. * cfg80211 validates this (1-2007) and allows setting the AID
  539. * only when creating a new station entry
  540. */
  541. if (params->aid)
  542. sta->sta.aid = params->aid;
  543. /*
  544. * FIXME: updating the following information is racy when this
  545. * function is called from ieee80211_change_station().
  546. * However, all this information should be static so
  547. * maybe we should just reject attemps to change it.
  548. */
  549. if (params->listen_interval >= 0)
  550. sta->listen_interval = params->listen_interval;
  551. if (params->supported_rates) {
  552. rates = 0;
  553. for (i = 0; i < params->supported_rates_len; i++) {
  554. int rate = (params->supported_rates[i] & 0x7f) * 5;
  555. for (j = 0; j < sband->n_bitrates; j++) {
  556. if (sband->bitrates[j].bitrate == rate)
  557. rates |= BIT(j);
  558. }
  559. }
  560. sta->sta.supp_rates[local->oper_channel->band] = rates;
  561. }
  562. if (params->ht_capa)
  563. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  564. params->ht_capa,
  565. &sta->sta.ht_cap);
  566. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  567. switch (params->plink_action) {
  568. case PLINK_ACTION_OPEN:
  569. mesh_plink_open(sta);
  570. break;
  571. case PLINK_ACTION_BLOCK:
  572. mesh_plink_block(sta);
  573. break;
  574. }
  575. }
  576. }
  577. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  578. u8 *mac, struct station_parameters *params)
  579. {
  580. struct ieee80211_local *local = wiphy_priv(wiphy);
  581. struct sta_info *sta;
  582. struct ieee80211_sub_if_data *sdata;
  583. int err;
  584. int layer2_update;
  585. if (params->vlan) {
  586. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  587. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  588. sdata->vif.type != NL80211_IFTYPE_AP)
  589. return -EINVAL;
  590. } else
  591. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  592. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  593. return -EINVAL;
  594. if (is_multicast_ether_addr(mac))
  595. return -EINVAL;
  596. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  597. if (!sta)
  598. return -ENOMEM;
  599. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  600. sta_apply_parameters(local, sta, params);
  601. rate_control_rate_init(sta);
  602. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  603. sdata->vif.type == NL80211_IFTYPE_AP;
  604. err = sta_info_insert_rcu(sta);
  605. if (err) {
  606. rcu_read_unlock();
  607. return err;
  608. }
  609. if (layer2_update)
  610. ieee80211_send_layer2_update(sta);
  611. rcu_read_unlock();
  612. return 0;
  613. }
  614. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  615. u8 *mac)
  616. {
  617. struct ieee80211_local *local = wiphy_priv(wiphy);
  618. struct ieee80211_sub_if_data *sdata;
  619. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  620. if (mac)
  621. return sta_info_destroy_addr_bss(sdata, mac);
  622. sta_info_flush(local, sdata);
  623. return 0;
  624. }
  625. static int ieee80211_change_station(struct wiphy *wiphy,
  626. struct net_device *dev,
  627. u8 *mac,
  628. struct station_parameters *params)
  629. {
  630. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  631. struct ieee80211_local *local = wiphy_priv(wiphy);
  632. struct sta_info *sta;
  633. struct ieee80211_sub_if_data *vlansdata;
  634. rcu_read_lock();
  635. sta = sta_info_get_bss(sdata, mac);
  636. if (!sta) {
  637. rcu_read_unlock();
  638. return -ENOENT;
  639. }
  640. if (params->vlan && params->vlan != sta->sdata->dev) {
  641. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  642. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  643. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  644. rcu_read_unlock();
  645. return -EINVAL;
  646. }
  647. if (params->vlan->ieee80211_ptr->use_4addr) {
  648. if (vlansdata->u.vlan.sta) {
  649. rcu_read_unlock();
  650. return -EBUSY;
  651. }
  652. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  653. }
  654. sta->sdata = vlansdata;
  655. ieee80211_send_layer2_update(sta);
  656. }
  657. sta_apply_parameters(local, sta, params);
  658. rcu_read_unlock();
  659. return 0;
  660. }
  661. #ifdef CONFIG_MAC80211_MESH
  662. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  663. u8 *dst, u8 *next_hop)
  664. {
  665. struct ieee80211_sub_if_data *sdata;
  666. struct mesh_path *mpath;
  667. struct sta_info *sta;
  668. int err;
  669. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  670. rcu_read_lock();
  671. sta = sta_info_get(sdata, next_hop);
  672. if (!sta) {
  673. rcu_read_unlock();
  674. return -ENOENT;
  675. }
  676. err = mesh_path_add(dst, sdata);
  677. if (err) {
  678. rcu_read_unlock();
  679. return err;
  680. }
  681. mpath = mesh_path_lookup(dst, sdata);
  682. if (!mpath) {
  683. rcu_read_unlock();
  684. return -ENXIO;
  685. }
  686. mesh_path_fix_nexthop(mpath, sta);
  687. rcu_read_unlock();
  688. return 0;
  689. }
  690. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  691. u8 *dst)
  692. {
  693. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  694. if (dst)
  695. return mesh_path_del(dst, sdata);
  696. mesh_path_flush(sdata);
  697. return 0;
  698. }
  699. static int ieee80211_change_mpath(struct wiphy *wiphy,
  700. struct net_device *dev,
  701. u8 *dst, u8 *next_hop)
  702. {
  703. struct ieee80211_sub_if_data *sdata;
  704. struct mesh_path *mpath;
  705. struct sta_info *sta;
  706. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  707. rcu_read_lock();
  708. sta = sta_info_get(sdata, next_hop);
  709. if (!sta) {
  710. rcu_read_unlock();
  711. return -ENOENT;
  712. }
  713. mpath = mesh_path_lookup(dst, sdata);
  714. if (!mpath) {
  715. rcu_read_unlock();
  716. return -ENOENT;
  717. }
  718. mesh_path_fix_nexthop(mpath, sta);
  719. rcu_read_unlock();
  720. return 0;
  721. }
  722. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  723. struct mpath_info *pinfo)
  724. {
  725. if (mpath->next_hop)
  726. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  727. else
  728. memset(next_hop, 0, ETH_ALEN);
  729. pinfo->generation = mesh_paths_generation;
  730. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  731. MPATH_INFO_SN |
  732. MPATH_INFO_METRIC |
  733. MPATH_INFO_EXPTIME |
  734. MPATH_INFO_DISCOVERY_TIMEOUT |
  735. MPATH_INFO_DISCOVERY_RETRIES |
  736. MPATH_INFO_FLAGS;
  737. pinfo->frame_qlen = mpath->frame_queue.qlen;
  738. pinfo->sn = mpath->sn;
  739. pinfo->metric = mpath->metric;
  740. if (time_before(jiffies, mpath->exp_time))
  741. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  742. pinfo->discovery_timeout =
  743. jiffies_to_msecs(mpath->discovery_timeout);
  744. pinfo->discovery_retries = mpath->discovery_retries;
  745. pinfo->flags = 0;
  746. if (mpath->flags & MESH_PATH_ACTIVE)
  747. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  748. if (mpath->flags & MESH_PATH_RESOLVING)
  749. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  750. if (mpath->flags & MESH_PATH_SN_VALID)
  751. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  752. if (mpath->flags & MESH_PATH_FIXED)
  753. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  754. if (mpath->flags & MESH_PATH_RESOLVING)
  755. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  756. pinfo->flags = mpath->flags;
  757. }
  758. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  759. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  760. {
  761. struct ieee80211_sub_if_data *sdata;
  762. struct mesh_path *mpath;
  763. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  764. rcu_read_lock();
  765. mpath = mesh_path_lookup(dst, sdata);
  766. if (!mpath) {
  767. rcu_read_unlock();
  768. return -ENOENT;
  769. }
  770. memcpy(dst, mpath->dst, ETH_ALEN);
  771. mpath_set_pinfo(mpath, next_hop, pinfo);
  772. rcu_read_unlock();
  773. return 0;
  774. }
  775. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  776. int idx, u8 *dst, u8 *next_hop,
  777. struct mpath_info *pinfo)
  778. {
  779. struct ieee80211_sub_if_data *sdata;
  780. struct mesh_path *mpath;
  781. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  782. rcu_read_lock();
  783. mpath = mesh_path_lookup_by_idx(idx, sdata);
  784. if (!mpath) {
  785. rcu_read_unlock();
  786. return -ENOENT;
  787. }
  788. memcpy(dst, mpath->dst, ETH_ALEN);
  789. mpath_set_pinfo(mpath, next_hop, pinfo);
  790. rcu_read_unlock();
  791. return 0;
  792. }
  793. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  794. struct net_device *dev,
  795. struct mesh_config *conf)
  796. {
  797. struct ieee80211_sub_if_data *sdata;
  798. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  799. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  800. return 0;
  801. }
  802. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  803. {
  804. return (mask >> (parm-1)) & 0x1;
  805. }
  806. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  807. struct net_device *dev,
  808. const struct mesh_config *nconf, u32 mask)
  809. {
  810. struct mesh_config *conf;
  811. struct ieee80211_sub_if_data *sdata;
  812. struct ieee80211_if_mesh *ifmsh;
  813. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  814. ifmsh = &sdata->u.mesh;
  815. /* Set the config options which we are interested in setting */
  816. conf = &(sdata->u.mesh.mshcfg);
  817. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  818. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  819. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  820. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  821. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  822. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  823. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  824. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  825. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  826. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  827. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  828. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  829. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  830. conf->auto_open_plinks = nconf->auto_open_plinks;
  831. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  832. conf->dot11MeshHWMPmaxPREQretries =
  833. nconf->dot11MeshHWMPmaxPREQretries;
  834. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  835. conf->path_refresh_time = nconf->path_refresh_time;
  836. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  837. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  838. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  839. conf->dot11MeshHWMPactivePathTimeout =
  840. nconf->dot11MeshHWMPactivePathTimeout;
  841. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  842. conf->dot11MeshHWMPpreqMinInterval =
  843. nconf->dot11MeshHWMPpreqMinInterval;
  844. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  845. mask))
  846. conf->dot11MeshHWMPnetDiameterTraversalTime =
  847. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  848. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  849. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  850. ieee80211_mesh_root_setup(ifmsh);
  851. }
  852. return 0;
  853. }
  854. #endif
  855. static int ieee80211_change_bss(struct wiphy *wiphy,
  856. struct net_device *dev,
  857. struct bss_parameters *params)
  858. {
  859. struct ieee80211_sub_if_data *sdata;
  860. u32 changed = 0;
  861. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  862. if (params->use_cts_prot >= 0) {
  863. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  864. changed |= BSS_CHANGED_ERP_CTS_PROT;
  865. }
  866. if (params->use_short_preamble >= 0) {
  867. sdata->vif.bss_conf.use_short_preamble =
  868. params->use_short_preamble;
  869. changed |= BSS_CHANGED_ERP_PREAMBLE;
  870. }
  871. if (!sdata->vif.bss_conf.use_short_slot &&
  872. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  873. sdata->vif.bss_conf.use_short_slot = true;
  874. changed |= BSS_CHANGED_ERP_SLOT;
  875. }
  876. if (params->use_short_slot_time >= 0) {
  877. sdata->vif.bss_conf.use_short_slot =
  878. params->use_short_slot_time;
  879. changed |= BSS_CHANGED_ERP_SLOT;
  880. }
  881. if (params->basic_rates) {
  882. int i, j;
  883. u32 rates = 0;
  884. struct ieee80211_local *local = wiphy_priv(wiphy);
  885. struct ieee80211_supported_band *sband =
  886. wiphy->bands[local->oper_channel->band];
  887. for (i = 0; i < params->basic_rates_len; i++) {
  888. int rate = (params->basic_rates[i] & 0x7f) * 5;
  889. for (j = 0; j < sband->n_bitrates; j++) {
  890. if (sband->bitrates[j].bitrate == rate)
  891. rates |= BIT(j);
  892. }
  893. }
  894. sdata->vif.bss_conf.basic_rates = rates;
  895. changed |= BSS_CHANGED_BASIC_RATES;
  896. }
  897. if (params->ap_isolate >= 0) {
  898. if (params->ap_isolate)
  899. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  900. else
  901. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  902. }
  903. ieee80211_bss_info_change_notify(sdata, changed);
  904. return 0;
  905. }
  906. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  907. struct ieee80211_txq_params *params)
  908. {
  909. struct ieee80211_local *local = wiphy_priv(wiphy);
  910. struct ieee80211_tx_queue_params p;
  911. if (!local->ops->conf_tx)
  912. return -EOPNOTSUPP;
  913. memset(&p, 0, sizeof(p));
  914. p.aifs = params->aifs;
  915. p.cw_max = params->cwmax;
  916. p.cw_min = params->cwmin;
  917. p.txop = params->txop;
  918. /*
  919. * Setting tx queue params disables u-apsd because it's only
  920. * called in master mode.
  921. */
  922. p.uapsd = false;
  923. if (drv_conf_tx(local, params->queue, &p)) {
  924. wiphy_debug(local->hw.wiphy,
  925. "failed to set TX queue parameters for queue %d\n",
  926. params->queue);
  927. return -EINVAL;
  928. }
  929. return 0;
  930. }
  931. static int ieee80211_set_channel(struct wiphy *wiphy,
  932. struct net_device *netdev,
  933. struct ieee80211_channel *chan,
  934. enum nl80211_channel_type channel_type)
  935. {
  936. struct ieee80211_local *local = wiphy_priv(wiphy);
  937. struct ieee80211_sub_if_data *sdata = NULL;
  938. if (netdev)
  939. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  940. switch (ieee80211_get_channel_mode(local, NULL)) {
  941. case CHAN_MODE_HOPPING:
  942. return -EBUSY;
  943. case CHAN_MODE_FIXED:
  944. if (local->oper_channel != chan)
  945. return -EBUSY;
  946. if (!sdata && local->_oper_channel_type == channel_type)
  947. return 0;
  948. break;
  949. case CHAN_MODE_UNDEFINED:
  950. break;
  951. }
  952. local->oper_channel = chan;
  953. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  954. return -EBUSY;
  955. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  956. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
  957. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  958. return 0;
  959. }
  960. #ifdef CONFIG_PM
  961. static int ieee80211_suspend(struct wiphy *wiphy)
  962. {
  963. return __ieee80211_suspend(wiphy_priv(wiphy));
  964. }
  965. static int ieee80211_resume(struct wiphy *wiphy)
  966. {
  967. return __ieee80211_resume(wiphy_priv(wiphy));
  968. }
  969. #else
  970. #define ieee80211_suspend NULL
  971. #define ieee80211_resume NULL
  972. #endif
  973. static int ieee80211_scan(struct wiphy *wiphy,
  974. struct net_device *dev,
  975. struct cfg80211_scan_request *req)
  976. {
  977. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  978. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  979. case NL80211_IFTYPE_STATION:
  980. case NL80211_IFTYPE_ADHOC:
  981. case NL80211_IFTYPE_MESH_POINT:
  982. case NL80211_IFTYPE_P2P_CLIENT:
  983. break;
  984. case NL80211_IFTYPE_P2P_GO:
  985. if (sdata->local->ops->hw_scan)
  986. break;
  987. /* FIXME: implement NoA while scanning in software */
  988. return -EOPNOTSUPP;
  989. case NL80211_IFTYPE_AP:
  990. if (sdata->u.ap.beacon)
  991. return -EOPNOTSUPP;
  992. break;
  993. default:
  994. return -EOPNOTSUPP;
  995. }
  996. return ieee80211_request_scan(sdata, req);
  997. }
  998. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  999. struct cfg80211_auth_request *req)
  1000. {
  1001. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1002. }
  1003. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1004. struct cfg80211_assoc_request *req)
  1005. {
  1006. struct ieee80211_local *local = wiphy_priv(wiphy);
  1007. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1008. switch (ieee80211_get_channel_mode(local, sdata)) {
  1009. case CHAN_MODE_HOPPING:
  1010. return -EBUSY;
  1011. case CHAN_MODE_FIXED:
  1012. if (local->oper_channel == req->bss->channel)
  1013. break;
  1014. return -EBUSY;
  1015. case CHAN_MODE_UNDEFINED:
  1016. break;
  1017. }
  1018. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1019. }
  1020. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1021. struct cfg80211_deauth_request *req,
  1022. void *cookie)
  1023. {
  1024. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1025. req, cookie);
  1026. }
  1027. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1028. struct cfg80211_disassoc_request *req,
  1029. void *cookie)
  1030. {
  1031. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1032. req, cookie);
  1033. }
  1034. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1035. struct cfg80211_ibss_params *params)
  1036. {
  1037. struct ieee80211_local *local = wiphy_priv(wiphy);
  1038. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1039. switch (ieee80211_get_channel_mode(local, sdata)) {
  1040. case CHAN_MODE_HOPPING:
  1041. return -EBUSY;
  1042. case CHAN_MODE_FIXED:
  1043. if (!params->channel_fixed)
  1044. return -EBUSY;
  1045. if (local->oper_channel == params->channel)
  1046. break;
  1047. return -EBUSY;
  1048. case CHAN_MODE_UNDEFINED:
  1049. break;
  1050. }
  1051. return ieee80211_ibss_join(sdata, params);
  1052. }
  1053. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1054. {
  1055. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1056. return ieee80211_ibss_leave(sdata);
  1057. }
  1058. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1059. {
  1060. struct ieee80211_local *local = wiphy_priv(wiphy);
  1061. int err;
  1062. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1063. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1064. if (err)
  1065. return err;
  1066. }
  1067. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1068. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1069. if (err)
  1070. return err;
  1071. }
  1072. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1073. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1074. if (changed & WIPHY_PARAM_RETRY_LONG)
  1075. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1076. if (changed &
  1077. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1078. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1079. return 0;
  1080. }
  1081. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1082. enum nl80211_tx_power_setting type, int mbm)
  1083. {
  1084. struct ieee80211_local *local = wiphy_priv(wiphy);
  1085. struct ieee80211_channel *chan = local->hw.conf.channel;
  1086. u32 changes = 0;
  1087. switch (type) {
  1088. case NL80211_TX_POWER_AUTOMATIC:
  1089. local->user_power_level = -1;
  1090. break;
  1091. case NL80211_TX_POWER_LIMITED:
  1092. if (mbm < 0 || (mbm % 100))
  1093. return -EOPNOTSUPP;
  1094. local->user_power_level = MBM_TO_DBM(mbm);
  1095. break;
  1096. case NL80211_TX_POWER_FIXED:
  1097. if (mbm < 0 || (mbm % 100))
  1098. return -EOPNOTSUPP;
  1099. /* TODO: move to cfg80211 when it knows the channel */
  1100. if (MBM_TO_DBM(mbm) > chan->max_power)
  1101. return -EINVAL;
  1102. local->user_power_level = MBM_TO_DBM(mbm);
  1103. break;
  1104. }
  1105. ieee80211_hw_config(local, changes);
  1106. return 0;
  1107. }
  1108. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1109. {
  1110. struct ieee80211_local *local = wiphy_priv(wiphy);
  1111. *dbm = local->hw.conf.power_level;
  1112. return 0;
  1113. }
  1114. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1115. const u8 *addr)
  1116. {
  1117. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1118. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1119. return 0;
  1120. }
  1121. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1122. {
  1123. struct ieee80211_local *local = wiphy_priv(wiphy);
  1124. drv_rfkill_poll(local);
  1125. }
  1126. #ifdef CONFIG_NL80211_TESTMODE
  1127. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1128. {
  1129. struct ieee80211_local *local = wiphy_priv(wiphy);
  1130. if (!local->ops->testmode_cmd)
  1131. return -EOPNOTSUPP;
  1132. return local->ops->testmode_cmd(&local->hw, data, len);
  1133. }
  1134. #endif
  1135. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1136. enum ieee80211_smps_mode smps_mode)
  1137. {
  1138. const u8 *ap;
  1139. enum ieee80211_smps_mode old_req;
  1140. int err;
  1141. old_req = sdata->u.mgd.req_smps;
  1142. sdata->u.mgd.req_smps = smps_mode;
  1143. if (old_req == smps_mode &&
  1144. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1145. return 0;
  1146. /*
  1147. * If not associated, or current association is not an HT
  1148. * association, there's no need to send an action frame.
  1149. */
  1150. if (!sdata->u.mgd.associated ||
  1151. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1152. mutex_lock(&sdata->local->iflist_mtx);
  1153. ieee80211_recalc_smps(sdata->local);
  1154. mutex_unlock(&sdata->local->iflist_mtx);
  1155. return 0;
  1156. }
  1157. ap = sdata->u.mgd.associated->bssid;
  1158. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1159. if (sdata->u.mgd.powersave)
  1160. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1161. else
  1162. smps_mode = IEEE80211_SMPS_OFF;
  1163. }
  1164. /* send SM PS frame to AP */
  1165. err = ieee80211_send_smps_action(sdata, smps_mode,
  1166. ap, ap);
  1167. if (err)
  1168. sdata->u.mgd.req_smps = old_req;
  1169. return err;
  1170. }
  1171. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1172. bool enabled, int timeout)
  1173. {
  1174. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1175. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1176. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1177. return -EOPNOTSUPP;
  1178. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1179. return -EOPNOTSUPP;
  1180. if (enabled == sdata->u.mgd.powersave &&
  1181. timeout == local->dynamic_ps_forced_timeout)
  1182. return 0;
  1183. sdata->u.mgd.powersave = enabled;
  1184. local->dynamic_ps_forced_timeout = timeout;
  1185. /* no change, but if automatic follow powersave */
  1186. mutex_lock(&sdata->u.mgd.mtx);
  1187. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1188. mutex_unlock(&sdata->u.mgd.mtx);
  1189. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1190. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1191. ieee80211_recalc_ps(local, -1);
  1192. return 0;
  1193. }
  1194. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1195. struct net_device *dev,
  1196. s32 rssi_thold, u32 rssi_hyst)
  1197. {
  1198. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1199. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1200. struct ieee80211_vif *vif = &sdata->vif;
  1201. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1202. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1203. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1204. return 0;
  1205. bss_conf->cqm_rssi_thold = rssi_thold;
  1206. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1207. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1208. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1209. return -EOPNOTSUPP;
  1210. return 0;
  1211. }
  1212. /* tell the driver upon association, unless already associated */
  1213. if (sdata->u.mgd.associated)
  1214. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1215. return 0;
  1216. }
  1217. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1218. struct net_device *dev,
  1219. const u8 *addr,
  1220. const struct cfg80211_bitrate_mask *mask)
  1221. {
  1222. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1223. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1224. int i;
  1225. /*
  1226. * This _could_ be supported by providing a hook for
  1227. * drivers for this function, but at this point it
  1228. * doesn't seem worth bothering.
  1229. */
  1230. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  1231. return -EOPNOTSUPP;
  1232. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1233. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1234. return 0;
  1235. }
  1236. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1237. struct net_device *dev,
  1238. struct ieee80211_channel *chan,
  1239. enum nl80211_channel_type channel_type,
  1240. unsigned int duration,
  1241. u64 *cookie)
  1242. {
  1243. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1244. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1245. duration, cookie);
  1246. }
  1247. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1248. struct net_device *dev,
  1249. u64 cookie)
  1250. {
  1251. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1252. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1253. }
  1254. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1255. struct ieee80211_channel *chan,
  1256. enum nl80211_channel_type channel_type,
  1257. bool channel_type_valid,
  1258. const u8 *buf, size_t len, u64 *cookie)
  1259. {
  1260. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1261. struct ieee80211_local *local = sdata->local;
  1262. struct sk_buff *skb;
  1263. struct sta_info *sta;
  1264. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1265. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1266. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1267. /* Check that we are on the requested channel for transmission */
  1268. if (chan != local->tmp_channel &&
  1269. chan != local->oper_channel)
  1270. return -EBUSY;
  1271. if (channel_type_valid &&
  1272. (channel_type != local->tmp_channel_type &&
  1273. channel_type != local->_oper_channel_type))
  1274. return -EBUSY;
  1275. switch (sdata->vif.type) {
  1276. case NL80211_IFTYPE_ADHOC:
  1277. case NL80211_IFTYPE_AP:
  1278. case NL80211_IFTYPE_AP_VLAN:
  1279. case NL80211_IFTYPE_P2P_GO:
  1280. if (!ieee80211_is_action(mgmt->frame_control) ||
  1281. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1282. break;
  1283. rcu_read_lock();
  1284. sta = sta_info_get(sdata, mgmt->da);
  1285. rcu_read_unlock();
  1286. if (!sta)
  1287. return -ENOLINK;
  1288. break;
  1289. case NL80211_IFTYPE_STATION:
  1290. case NL80211_IFTYPE_P2P_CLIENT:
  1291. break;
  1292. default:
  1293. return -EOPNOTSUPP;
  1294. }
  1295. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1296. if (!skb)
  1297. return -ENOMEM;
  1298. skb_reserve(skb, local->hw.extra_tx_headroom);
  1299. memcpy(skb_put(skb, len), buf, len);
  1300. IEEE80211_SKB_CB(skb)->flags = flags;
  1301. skb->dev = sdata->dev;
  1302. ieee80211_tx_skb(sdata, skb);
  1303. *cookie = (unsigned long) skb;
  1304. return 0;
  1305. }
  1306. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1307. struct net_device *dev,
  1308. u16 frame_type, bool reg)
  1309. {
  1310. struct ieee80211_local *local = wiphy_priv(wiphy);
  1311. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1312. return;
  1313. if (reg)
  1314. local->probe_req_reg++;
  1315. else
  1316. local->probe_req_reg--;
  1317. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1318. }
  1319. struct cfg80211_ops mac80211_config_ops = {
  1320. .add_virtual_intf = ieee80211_add_iface,
  1321. .del_virtual_intf = ieee80211_del_iface,
  1322. .change_virtual_intf = ieee80211_change_iface,
  1323. .add_key = ieee80211_add_key,
  1324. .del_key = ieee80211_del_key,
  1325. .get_key = ieee80211_get_key,
  1326. .set_default_key = ieee80211_config_default_key,
  1327. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1328. .add_beacon = ieee80211_add_beacon,
  1329. .set_beacon = ieee80211_set_beacon,
  1330. .del_beacon = ieee80211_del_beacon,
  1331. .add_station = ieee80211_add_station,
  1332. .del_station = ieee80211_del_station,
  1333. .change_station = ieee80211_change_station,
  1334. .get_station = ieee80211_get_station,
  1335. .dump_station = ieee80211_dump_station,
  1336. .dump_survey = ieee80211_dump_survey,
  1337. #ifdef CONFIG_MAC80211_MESH
  1338. .add_mpath = ieee80211_add_mpath,
  1339. .del_mpath = ieee80211_del_mpath,
  1340. .change_mpath = ieee80211_change_mpath,
  1341. .get_mpath = ieee80211_get_mpath,
  1342. .dump_mpath = ieee80211_dump_mpath,
  1343. .set_mesh_params = ieee80211_set_mesh_params,
  1344. .get_mesh_params = ieee80211_get_mesh_params,
  1345. #endif
  1346. .change_bss = ieee80211_change_bss,
  1347. .set_txq_params = ieee80211_set_txq_params,
  1348. .set_channel = ieee80211_set_channel,
  1349. .suspend = ieee80211_suspend,
  1350. .resume = ieee80211_resume,
  1351. .scan = ieee80211_scan,
  1352. .auth = ieee80211_auth,
  1353. .assoc = ieee80211_assoc,
  1354. .deauth = ieee80211_deauth,
  1355. .disassoc = ieee80211_disassoc,
  1356. .join_ibss = ieee80211_join_ibss,
  1357. .leave_ibss = ieee80211_leave_ibss,
  1358. .set_wiphy_params = ieee80211_set_wiphy_params,
  1359. .set_tx_power = ieee80211_set_tx_power,
  1360. .get_tx_power = ieee80211_get_tx_power,
  1361. .set_wds_peer = ieee80211_set_wds_peer,
  1362. .rfkill_poll = ieee80211_rfkill_poll,
  1363. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1364. .set_power_mgmt = ieee80211_set_power_mgmt,
  1365. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1366. .remain_on_channel = ieee80211_remain_on_channel,
  1367. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1368. .mgmt_tx = ieee80211_mgmt_tx,
  1369. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1370. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  1371. };