cfg.c 41 KB

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