cfg.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006, 2007 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 <net/net_namespace.h>
  12. #include <linux/rcupdate.h>
  13. #include <net/cfg80211.h>
  14. #include "ieee80211_i.h"
  15. #include "driver-ops.h"
  16. #include "cfg.h"
  17. #include "rate.h"
  18. #include "mesh.h"
  19. static bool nl80211_type_check(enum nl80211_iftype type)
  20. {
  21. switch (type) {
  22. case NL80211_IFTYPE_ADHOC:
  23. case NL80211_IFTYPE_STATION:
  24. case NL80211_IFTYPE_MONITOR:
  25. #ifdef CONFIG_MAC80211_MESH
  26. case NL80211_IFTYPE_MESH_POINT:
  27. #endif
  28. case NL80211_IFTYPE_AP:
  29. case NL80211_IFTYPE_AP_VLAN:
  30. case NL80211_IFTYPE_WDS:
  31. return true;
  32. default:
  33. return false;
  34. }
  35. }
  36. static bool nl80211_params_check(enum nl80211_iftype type,
  37. struct vif_params *params)
  38. {
  39. if (!nl80211_type_check(type))
  40. return false;
  41. if (params->use_4addr > 0) {
  42. switch(type) {
  43. case NL80211_IFTYPE_AP_VLAN:
  44. case NL80211_IFTYPE_STATION:
  45. break;
  46. default:
  47. return false;
  48. }
  49. }
  50. return true;
  51. }
  52. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  53. enum nl80211_iftype type, u32 *flags,
  54. struct vif_params *params)
  55. {
  56. struct ieee80211_local *local = wiphy_priv(wiphy);
  57. struct net_device *dev;
  58. struct ieee80211_sub_if_data *sdata;
  59. int err;
  60. if (!nl80211_params_check(type, params))
  61. return -EINVAL;
  62. err = ieee80211_if_add(local, name, &dev, type, params);
  63. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  64. return err;
  65. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  66. sdata->u.mntr_flags = *flags;
  67. return 0;
  68. }
  69. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  70. {
  71. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  72. return 0;
  73. }
  74. static int ieee80211_change_iface(struct wiphy *wiphy,
  75. struct net_device *dev,
  76. enum nl80211_iftype type, u32 *flags,
  77. struct vif_params *params)
  78. {
  79. struct ieee80211_sub_if_data *sdata;
  80. int ret;
  81. if (netif_running(dev))
  82. return -EBUSY;
  83. if (!nl80211_params_check(type, params))
  84. return -EINVAL;
  85. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  86. ret = ieee80211_if_change_type(sdata, type);
  87. if (ret)
  88. return ret;
  89. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  90. ieee80211_sdata_set_mesh_id(sdata,
  91. params->mesh_id_len,
  92. params->mesh_id);
  93. if (params->use_4addr >= 0)
  94. sdata->use_4addr = !!params->use_4addr;
  95. if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
  96. return 0;
  97. sdata->u.mntr_flags = *flags;
  98. return 0;
  99. }
  100. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  101. u8 key_idx, const u8 *mac_addr,
  102. struct key_params *params)
  103. {
  104. struct ieee80211_sub_if_data *sdata;
  105. struct sta_info *sta = NULL;
  106. enum ieee80211_key_alg alg;
  107. struct ieee80211_key *key;
  108. int err;
  109. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  110. switch (params->cipher) {
  111. case WLAN_CIPHER_SUITE_WEP40:
  112. case WLAN_CIPHER_SUITE_WEP104:
  113. alg = ALG_WEP;
  114. break;
  115. case WLAN_CIPHER_SUITE_TKIP:
  116. alg = ALG_TKIP;
  117. break;
  118. case WLAN_CIPHER_SUITE_CCMP:
  119. alg = ALG_CCMP;
  120. break;
  121. case WLAN_CIPHER_SUITE_AES_CMAC:
  122. alg = ALG_AES_CMAC;
  123. break;
  124. default:
  125. return -EINVAL;
  126. }
  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. rcu_read_lock();
  132. if (mac_addr) {
  133. sta = sta_info_get(sdata->local, 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. rcu_read_unlock();
  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. rcu_read_lock();
  154. if (mac_addr) {
  155. ret = -ENOENT;
  156. sta = sta_info_get(sdata->local, 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. rcu_read_unlock();
  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(sdata->local, 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;
  262. rcu_read_lock();
  263. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  264. ieee80211_set_default_key(sdata, key_idx);
  265. rcu_read_unlock();
  266. return 0;
  267. }
  268. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  269. struct net_device *dev,
  270. u8 key_idx)
  271. {
  272. struct ieee80211_sub_if_data *sdata;
  273. rcu_read_lock();
  274. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  275. ieee80211_set_default_mgmt_key(sdata, key_idx);
  276. rcu_read_unlock();
  277. return 0;
  278. }
  279. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  280. {
  281. struct ieee80211_sub_if_data *sdata = sta->sdata;
  282. sinfo->generation = sdata->local->sta_generation;
  283. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  284. STATION_INFO_RX_BYTES |
  285. STATION_INFO_TX_BYTES |
  286. STATION_INFO_RX_PACKETS |
  287. STATION_INFO_TX_PACKETS |
  288. STATION_INFO_TX_BITRATE;
  289. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  290. sinfo->rx_bytes = sta->rx_bytes;
  291. sinfo->tx_bytes = sta->tx_bytes;
  292. sinfo->rx_packets = sta->rx_packets;
  293. sinfo->tx_packets = sta->tx_packets;
  294. if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  295. sinfo->filled |= STATION_INFO_SIGNAL;
  296. sinfo->signal = (s8)sta->last_signal;
  297. }
  298. sinfo->txrate.flags = 0;
  299. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  300. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  301. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  302. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  303. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  304. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  305. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  306. struct ieee80211_supported_band *sband;
  307. sband = sta->local->hw.wiphy->bands[
  308. sta->local->hw.conf.channel->band];
  309. sinfo->txrate.legacy =
  310. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  311. } else
  312. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  313. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  314. #ifdef CONFIG_MAC80211_MESH
  315. sinfo->filled |= STATION_INFO_LLID |
  316. STATION_INFO_PLID |
  317. STATION_INFO_PLINK_STATE;
  318. sinfo->llid = le16_to_cpu(sta->llid);
  319. sinfo->plid = le16_to_cpu(sta->plid);
  320. sinfo->plink_state = sta->plink_state;
  321. #endif
  322. }
  323. }
  324. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  325. int idx, u8 *mac, struct station_info *sinfo)
  326. {
  327. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  328. struct sta_info *sta;
  329. int ret = -ENOENT;
  330. rcu_read_lock();
  331. sta = sta_info_get_by_idx(local, idx, dev);
  332. if (sta) {
  333. ret = 0;
  334. memcpy(mac, sta->sta.addr, ETH_ALEN);
  335. sta_set_sinfo(sta, sinfo);
  336. }
  337. rcu_read_unlock();
  338. return ret;
  339. }
  340. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  341. u8 *mac, struct station_info *sinfo)
  342. {
  343. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  344. struct sta_info *sta;
  345. int ret = -ENOENT;
  346. rcu_read_lock();
  347. /* XXX: verify sta->dev == dev */
  348. sta = sta_info_get(local, mac);
  349. if (sta) {
  350. ret = 0;
  351. sta_set_sinfo(sta, sinfo);
  352. }
  353. rcu_read_unlock();
  354. return ret;
  355. }
  356. /*
  357. * This handles both adding a beacon and setting new beacon info
  358. */
  359. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  360. struct beacon_parameters *params)
  361. {
  362. struct beacon_data *new, *old;
  363. int new_head_len, new_tail_len;
  364. int size;
  365. int err = -EINVAL;
  366. old = sdata->u.ap.beacon;
  367. /* head must not be zero-length */
  368. if (params->head && !params->head_len)
  369. return -EINVAL;
  370. /*
  371. * This is a kludge. beacon interval should really be part
  372. * of the beacon information.
  373. */
  374. if (params->interval &&
  375. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  376. sdata->vif.bss_conf.beacon_int = params->interval;
  377. ieee80211_bss_info_change_notify(sdata,
  378. BSS_CHANGED_BEACON_INT);
  379. }
  380. /* Need to have a beacon head if we don't have one yet */
  381. if (!params->head && !old)
  382. return err;
  383. /* sorry, no way to start beaconing without dtim period */
  384. if (!params->dtim_period && !old)
  385. return err;
  386. /* new or old head? */
  387. if (params->head)
  388. new_head_len = params->head_len;
  389. else
  390. new_head_len = old->head_len;
  391. /* new or old tail? */
  392. if (params->tail || !old)
  393. /* params->tail_len will be zero for !params->tail */
  394. new_tail_len = params->tail_len;
  395. else
  396. new_tail_len = old->tail_len;
  397. size = sizeof(*new) + new_head_len + new_tail_len;
  398. new = kzalloc(size, GFP_KERNEL);
  399. if (!new)
  400. return -ENOMEM;
  401. /* start filling the new info now */
  402. /* new or old dtim period? */
  403. if (params->dtim_period)
  404. new->dtim_period = params->dtim_period;
  405. else
  406. new->dtim_period = old->dtim_period;
  407. /*
  408. * pointers go into the block we allocated,
  409. * memory is | beacon_data | head | tail |
  410. */
  411. new->head = ((u8 *) new) + sizeof(*new);
  412. new->tail = new->head + new_head_len;
  413. new->head_len = new_head_len;
  414. new->tail_len = new_tail_len;
  415. /* copy in head */
  416. if (params->head)
  417. memcpy(new->head, params->head, new_head_len);
  418. else
  419. memcpy(new->head, old->head, new_head_len);
  420. /* copy in optional tail */
  421. if (params->tail)
  422. memcpy(new->tail, params->tail, new_tail_len);
  423. else
  424. if (old)
  425. memcpy(new->tail, old->tail, new_tail_len);
  426. rcu_assign_pointer(sdata->u.ap.beacon, new);
  427. synchronize_rcu();
  428. kfree(old);
  429. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  430. BSS_CHANGED_BEACON);
  431. return 0;
  432. }
  433. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  434. struct beacon_parameters *params)
  435. {
  436. struct ieee80211_sub_if_data *sdata;
  437. struct beacon_data *old;
  438. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  439. old = sdata->u.ap.beacon;
  440. if (old)
  441. return -EALREADY;
  442. return ieee80211_config_beacon(sdata, params);
  443. }
  444. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  445. struct beacon_parameters *params)
  446. {
  447. struct ieee80211_sub_if_data *sdata;
  448. struct beacon_data *old;
  449. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  450. old = sdata->u.ap.beacon;
  451. if (!old)
  452. return -ENOENT;
  453. return ieee80211_config_beacon(sdata, params);
  454. }
  455. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  456. {
  457. struct ieee80211_sub_if_data *sdata;
  458. struct beacon_data *old;
  459. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  460. old = sdata->u.ap.beacon;
  461. if (!old)
  462. return -ENOENT;
  463. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  464. synchronize_rcu();
  465. kfree(old);
  466. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  467. return 0;
  468. }
  469. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  470. struct iapp_layer2_update {
  471. u8 da[ETH_ALEN]; /* broadcast */
  472. u8 sa[ETH_ALEN]; /* STA addr */
  473. __be16 len; /* 6 */
  474. u8 dsap; /* 0 */
  475. u8 ssap; /* 0 */
  476. u8 control;
  477. u8 xid_info[3];
  478. } __attribute__ ((packed));
  479. static void ieee80211_send_layer2_update(struct sta_info *sta)
  480. {
  481. struct iapp_layer2_update *msg;
  482. struct sk_buff *skb;
  483. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  484. * bridge devices */
  485. skb = dev_alloc_skb(sizeof(*msg));
  486. if (!skb)
  487. return;
  488. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  489. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  490. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  491. memset(msg->da, 0xff, ETH_ALEN);
  492. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  493. msg->len = htons(6);
  494. msg->dsap = 0;
  495. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  496. msg->control = 0xaf; /* XID response lsb.1111F101.
  497. * F=0 (no poll command; unsolicited frame) */
  498. msg->xid_info[0] = 0x81; /* XID format identifier */
  499. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  500. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  501. skb->dev = sta->sdata->dev;
  502. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  503. memset(skb->cb, 0, sizeof(skb->cb));
  504. netif_rx(skb);
  505. }
  506. static void sta_apply_parameters(struct ieee80211_local *local,
  507. struct sta_info *sta,
  508. struct station_parameters *params)
  509. {
  510. u32 rates;
  511. int i, j;
  512. struct ieee80211_supported_band *sband;
  513. struct ieee80211_sub_if_data *sdata = sta->sdata;
  514. u32 mask, set;
  515. sband = local->hw.wiphy->bands[local->oper_channel->band];
  516. spin_lock_bh(&sta->lock);
  517. mask = params->sta_flags_mask;
  518. set = params->sta_flags_set;
  519. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  520. sta->flags &= ~WLAN_STA_AUTHORIZED;
  521. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  522. sta->flags |= WLAN_STA_AUTHORIZED;
  523. }
  524. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  525. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  526. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  527. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  528. }
  529. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  530. sta->flags &= ~WLAN_STA_WME;
  531. if (set & BIT(NL80211_STA_FLAG_WME))
  532. sta->flags |= WLAN_STA_WME;
  533. }
  534. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  535. sta->flags &= ~WLAN_STA_MFP;
  536. if (set & BIT(NL80211_STA_FLAG_MFP))
  537. sta->flags |= WLAN_STA_MFP;
  538. }
  539. spin_unlock_bh(&sta->lock);
  540. /*
  541. * cfg80211 validates this (1-2007) and allows setting the AID
  542. * only when creating a new station entry
  543. */
  544. if (params->aid)
  545. sta->sta.aid = params->aid;
  546. /*
  547. * FIXME: updating the following information is racy when this
  548. * function is called from ieee80211_change_station().
  549. * However, all this information should be static so
  550. * maybe we should just reject attemps to change it.
  551. */
  552. if (params->listen_interval >= 0)
  553. sta->listen_interval = params->listen_interval;
  554. if (params->supported_rates) {
  555. rates = 0;
  556. for (i = 0; i < params->supported_rates_len; i++) {
  557. int rate = (params->supported_rates[i] & 0x7f) * 5;
  558. for (j = 0; j < sband->n_bitrates; j++) {
  559. if (sband->bitrates[j].bitrate == rate)
  560. rates |= BIT(j);
  561. }
  562. }
  563. sta->sta.supp_rates[local->oper_channel->band] = rates;
  564. }
  565. if (params->ht_capa)
  566. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  567. params->ht_capa,
  568. &sta->sta.ht_cap);
  569. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  570. switch (params->plink_action) {
  571. case PLINK_ACTION_OPEN:
  572. mesh_plink_open(sta);
  573. break;
  574. case PLINK_ACTION_BLOCK:
  575. mesh_plink_block(sta);
  576. break;
  577. }
  578. }
  579. }
  580. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  581. u8 *mac, struct station_parameters *params)
  582. {
  583. struct ieee80211_local *local = wiphy_priv(wiphy);
  584. struct sta_info *sta;
  585. struct ieee80211_sub_if_data *sdata;
  586. int err;
  587. int layer2_update;
  588. if (params->vlan) {
  589. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  590. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  591. sdata->vif.type != NL80211_IFTYPE_AP)
  592. return -EINVAL;
  593. } else
  594. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  595. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  596. return -EINVAL;
  597. if (is_multicast_ether_addr(mac))
  598. return -EINVAL;
  599. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  600. if (!sta)
  601. return -ENOMEM;
  602. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  603. sta_apply_parameters(local, sta, params);
  604. rate_control_rate_init(sta);
  605. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  606. sdata->vif.type == NL80211_IFTYPE_AP;
  607. rcu_read_lock();
  608. err = sta_info_insert(sta);
  609. if (err) {
  610. rcu_read_unlock();
  611. return err;
  612. }
  613. if (layer2_update)
  614. ieee80211_send_layer2_update(sta);
  615. rcu_read_unlock();
  616. return 0;
  617. }
  618. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  619. u8 *mac)
  620. {
  621. struct ieee80211_local *local = wiphy_priv(wiphy);
  622. struct ieee80211_sub_if_data *sdata;
  623. struct sta_info *sta;
  624. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  625. if (mac) {
  626. rcu_read_lock();
  627. /* XXX: get sta belonging to dev */
  628. sta = sta_info_get(local, mac);
  629. if (!sta) {
  630. rcu_read_unlock();
  631. return -ENOENT;
  632. }
  633. sta_info_unlink(&sta);
  634. rcu_read_unlock();
  635. sta_info_destroy(sta);
  636. } else
  637. sta_info_flush(local, sdata);
  638. return 0;
  639. }
  640. static int ieee80211_change_station(struct wiphy *wiphy,
  641. struct net_device *dev,
  642. u8 *mac,
  643. struct station_parameters *params)
  644. {
  645. struct ieee80211_local *local = wiphy_priv(wiphy);
  646. struct sta_info *sta;
  647. struct ieee80211_sub_if_data *vlansdata;
  648. rcu_read_lock();
  649. /* XXX: get sta belonging to dev */
  650. sta = sta_info_get(local, mac);
  651. if (!sta) {
  652. rcu_read_unlock();
  653. return -ENOENT;
  654. }
  655. if (params->vlan && params->vlan != sta->sdata->dev) {
  656. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  657. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  658. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  659. rcu_read_unlock();
  660. return -EINVAL;
  661. }
  662. if (vlansdata->use_4addr) {
  663. if (vlansdata->u.vlan.sta)
  664. return -EBUSY;
  665. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  666. }
  667. sta->sdata = vlansdata;
  668. ieee80211_send_layer2_update(sta);
  669. }
  670. sta_apply_parameters(local, sta, params);
  671. rcu_read_unlock();
  672. return 0;
  673. }
  674. #ifdef CONFIG_MAC80211_MESH
  675. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  676. u8 *dst, u8 *next_hop)
  677. {
  678. struct ieee80211_local *local = wiphy_priv(wiphy);
  679. struct ieee80211_sub_if_data *sdata;
  680. struct mesh_path *mpath;
  681. struct sta_info *sta;
  682. int err;
  683. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  684. rcu_read_lock();
  685. sta = sta_info_get(local, next_hop);
  686. if (!sta) {
  687. rcu_read_unlock();
  688. return -ENOENT;
  689. }
  690. err = mesh_path_add(dst, sdata);
  691. if (err) {
  692. rcu_read_unlock();
  693. return err;
  694. }
  695. mpath = mesh_path_lookup(dst, sdata);
  696. if (!mpath) {
  697. rcu_read_unlock();
  698. return -ENXIO;
  699. }
  700. mesh_path_fix_nexthop(mpath, sta);
  701. rcu_read_unlock();
  702. return 0;
  703. }
  704. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  705. u8 *dst)
  706. {
  707. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  708. if (dst)
  709. return mesh_path_del(dst, sdata);
  710. mesh_path_flush(sdata);
  711. return 0;
  712. }
  713. static int ieee80211_change_mpath(struct wiphy *wiphy,
  714. struct net_device *dev,
  715. u8 *dst, u8 *next_hop)
  716. {
  717. struct ieee80211_local *local = wiphy_priv(wiphy);
  718. struct ieee80211_sub_if_data *sdata;
  719. struct mesh_path *mpath;
  720. struct sta_info *sta;
  721. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  722. rcu_read_lock();
  723. sta = sta_info_get(local, next_hop);
  724. if (!sta) {
  725. rcu_read_unlock();
  726. return -ENOENT;
  727. }
  728. mpath = mesh_path_lookup(dst, sdata);
  729. if (!mpath) {
  730. rcu_read_unlock();
  731. return -ENOENT;
  732. }
  733. mesh_path_fix_nexthop(mpath, sta);
  734. rcu_read_unlock();
  735. return 0;
  736. }
  737. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  738. struct mpath_info *pinfo)
  739. {
  740. if (mpath->next_hop)
  741. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  742. else
  743. memset(next_hop, 0, ETH_ALEN);
  744. pinfo->generation = mesh_paths_generation;
  745. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  746. MPATH_INFO_SN |
  747. MPATH_INFO_METRIC |
  748. MPATH_INFO_EXPTIME |
  749. MPATH_INFO_DISCOVERY_TIMEOUT |
  750. MPATH_INFO_DISCOVERY_RETRIES |
  751. MPATH_INFO_FLAGS;
  752. pinfo->frame_qlen = mpath->frame_queue.qlen;
  753. pinfo->sn = mpath->sn;
  754. pinfo->metric = mpath->metric;
  755. if (time_before(jiffies, mpath->exp_time))
  756. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  757. pinfo->discovery_timeout =
  758. jiffies_to_msecs(mpath->discovery_timeout);
  759. pinfo->discovery_retries = mpath->discovery_retries;
  760. pinfo->flags = 0;
  761. if (mpath->flags & MESH_PATH_ACTIVE)
  762. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  763. if (mpath->flags & MESH_PATH_RESOLVING)
  764. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  765. if (mpath->flags & MESH_PATH_SN_VALID)
  766. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  767. if (mpath->flags & MESH_PATH_FIXED)
  768. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  769. if (mpath->flags & MESH_PATH_RESOLVING)
  770. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  771. pinfo->flags = mpath->flags;
  772. }
  773. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  774. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  775. {
  776. struct ieee80211_sub_if_data *sdata;
  777. struct mesh_path *mpath;
  778. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  779. rcu_read_lock();
  780. mpath = mesh_path_lookup(dst, sdata);
  781. if (!mpath) {
  782. rcu_read_unlock();
  783. return -ENOENT;
  784. }
  785. memcpy(dst, mpath->dst, ETH_ALEN);
  786. mpath_set_pinfo(mpath, next_hop, pinfo);
  787. rcu_read_unlock();
  788. return 0;
  789. }
  790. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  791. int idx, u8 *dst, u8 *next_hop,
  792. struct mpath_info *pinfo)
  793. {
  794. struct ieee80211_sub_if_data *sdata;
  795. struct mesh_path *mpath;
  796. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  797. rcu_read_lock();
  798. mpath = mesh_path_lookup_by_idx(idx, sdata);
  799. if (!mpath) {
  800. rcu_read_unlock();
  801. return -ENOENT;
  802. }
  803. memcpy(dst, mpath->dst, ETH_ALEN);
  804. mpath_set_pinfo(mpath, next_hop, pinfo);
  805. rcu_read_unlock();
  806. return 0;
  807. }
  808. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  809. struct net_device *dev,
  810. struct mesh_config *conf)
  811. {
  812. struct ieee80211_sub_if_data *sdata;
  813. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  814. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  815. return 0;
  816. }
  817. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  818. {
  819. return (mask >> (parm-1)) & 0x1;
  820. }
  821. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  822. struct net_device *dev,
  823. const struct mesh_config *nconf, u32 mask)
  824. {
  825. struct mesh_config *conf;
  826. struct ieee80211_sub_if_data *sdata;
  827. struct ieee80211_if_mesh *ifmsh;
  828. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  829. ifmsh = &sdata->u.mesh;
  830. /* Set the config options which we are interested in setting */
  831. conf = &(sdata->u.mesh.mshcfg);
  832. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  833. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  834. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  835. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  836. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  837. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  838. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  839. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  840. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  841. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  842. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  843. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  844. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  845. conf->auto_open_plinks = nconf->auto_open_plinks;
  846. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  847. conf->dot11MeshHWMPmaxPREQretries =
  848. nconf->dot11MeshHWMPmaxPREQretries;
  849. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  850. conf->path_refresh_time = nconf->path_refresh_time;
  851. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  852. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  853. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  854. conf->dot11MeshHWMPactivePathTimeout =
  855. nconf->dot11MeshHWMPactivePathTimeout;
  856. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  857. conf->dot11MeshHWMPpreqMinInterval =
  858. nconf->dot11MeshHWMPpreqMinInterval;
  859. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  860. mask))
  861. conf->dot11MeshHWMPnetDiameterTraversalTime =
  862. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  863. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  864. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  865. ieee80211_mesh_root_setup(ifmsh);
  866. }
  867. return 0;
  868. }
  869. #endif
  870. static int ieee80211_change_bss(struct wiphy *wiphy,
  871. struct net_device *dev,
  872. struct bss_parameters *params)
  873. {
  874. struct ieee80211_sub_if_data *sdata;
  875. u32 changed = 0;
  876. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  877. if (params->use_cts_prot >= 0) {
  878. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  879. changed |= BSS_CHANGED_ERP_CTS_PROT;
  880. }
  881. if (params->use_short_preamble >= 0) {
  882. sdata->vif.bss_conf.use_short_preamble =
  883. params->use_short_preamble;
  884. changed |= BSS_CHANGED_ERP_PREAMBLE;
  885. }
  886. if (params->use_short_slot_time >= 0) {
  887. sdata->vif.bss_conf.use_short_slot =
  888. params->use_short_slot_time;
  889. changed |= BSS_CHANGED_ERP_SLOT;
  890. }
  891. if (params->basic_rates) {
  892. int i, j;
  893. u32 rates = 0;
  894. struct ieee80211_local *local = wiphy_priv(wiphy);
  895. struct ieee80211_supported_band *sband =
  896. wiphy->bands[local->oper_channel->band];
  897. for (i = 0; i < params->basic_rates_len; i++) {
  898. int rate = (params->basic_rates[i] & 0x7f) * 5;
  899. for (j = 0; j < sband->n_bitrates; j++) {
  900. if (sband->bitrates[j].bitrate == rate)
  901. rates |= BIT(j);
  902. }
  903. }
  904. sdata->vif.bss_conf.basic_rates = rates;
  905. changed |= BSS_CHANGED_BASIC_RATES;
  906. }
  907. ieee80211_bss_info_change_notify(sdata, changed);
  908. return 0;
  909. }
  910. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  911. struct ieee80211_txq_params *params)
  912. {
  913. struct ieee80211_local *local = wiphy_priv(wiphy);
  914. struct ieee80211_tx_queue_params p;
  915. if (!local->ops->conf_tx)
  916. return -EOPNOTSUPP;
  917. memset(&p, 0, sizeof(p));
  918. p.aifs = params->aifs;
  919. p.cw_max = params->cwmax;
  920. p.cw_min = params->cwmin;
  921. p.txop = params->txop;
  922. if (drv_conf_tx(local, params->queue, &p)) {
  923. printk(KERN_DEBUG "%s: failed to set TX queue "
  924. "parameters for queue %d\n",
  925. wiphy_name(local->hw.wiphy), params->queue);
  926. return -EINVAL;
  927. }
  928. return 0;
  929. }
  930. static int ieee80211_set_channel(struct wiphy *wiphy,
  931. struct ieee80211_channel *chan,
  932. enum nl80211_channel_type channel_type)
  933. {
  934. struct ieee80211_local *local = wiphy_priv(wiphy);
  935. local->oper_channel = chan;
  936. local->oper_channel_type = channel_type;
  937. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  938. }
  939. #ifdef CONFIG_PM
  940. static int ieee80211_suspend(struct wiphy *wiphy)
  941. {
  942. return __ieee80211_suspend(wiphy_priv(wiphy));
  943. }
  944. static int ieee80211_resume(struct wiphy *wiphy)
  945. {
  946. return __ieee80211_resume(wiphy_priv(wiphy));
  947. }
  948. #else
  949. #define ieee80211_suspend NULL
  950. #define ieee80211_resume NULL
  951. #endif
  952. static int ieee80211_scan(struct wiphy *wiphy,
  953. struct net_device *dev,
  954. struct cfg80211_scan_request *req)
  955. {
  956. struct ieee80211_sub_if_data *sdata;
  957. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  958. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  959. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  960. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  961. (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
  962. return -EOPNOTSUPP;
  963. return ieee80211_request_scan(sdata, req);
  964. }
  965. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  966. struct cfg80211_auth_request *req)
  967. {
  968. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  969. }
  970. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  971. struct cfg80211_assoc_request *req)
  972. {
  973. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  974. }
  975. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  976. struct cfg80211_deauth_request *req,
  977. void *cookie)
  978. {
  979. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  980. req, cookie);
  981. }
  982. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  983. struct cfg80211_disassoc_request *req,
  984. void *cookie)
  985. {
  986. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  987. req, cookie);
  988. }
  989. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  990. struct cfg80211_ibss_params *params)
  991. {
  992. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  993. return ieee80211_ibss_join(sdata, params);
  994. }
  995. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  996. {
  997. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  998. return ieee80211_ibss_leave(sdata);
  999. }
  1000. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1001. {
  1002. struct ieee80211_local *local = wiphy_priv(wiphy);
  1003. int err;
  1004. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1005. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1006. if (err)
  1007. return err;
  1008. }
  1009. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1010. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1011. if (changed & WIPHY_PARAM_RETRY_LONG)
  1012. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1013. if (changed &
  1014. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1015. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1016. return 0;
  1017. }
  1018. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1019. enum tx_power_setting type, int dbm)
  1020. {
  1021. struct ieee80211_local *local = wiphy_priv(wiphy);
  1022. struct ieee80211_channel *chan = local->hw.conf.channel;
  1023. u32 changes = 0;
  1024. switch (type) {
  1025. case TX_POWER_AUTOMATIC:
  1026. local->user_power_level = -1;
  1027. break;
  1028. case TX_POWER_LIMITED:
  1029. if (dbm < 0)
  1030. return -EINVAL;
  1031. local->user_power_level = dbm;
  1032. break;
  1033. case TX_POWER_FIXED:
  1034. if (dbm < 0)
  1035. return -EINVAL;
  1036. /* TODO: move to cfg80211 when it knows the channel */
  1037. if (dbm > chan->max_power)
  1038. return -EINVAL;
  1039. local->user_power_level = dbm;
  1040. break;
  1041. }
  1042. ieee80211_hw_config(local, changes);
  1043. return 0;
  1044. }
  1045. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1046. {
  1047. struct ieee80211_local *local = wiphy_priv(wiphy);
  1048. *dbm = local->hw.conf.power_level;
  1049. return 0;
  1050. }
  1051. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1052. u8 *addr)
  1053. {
  1054. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1055. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1056. return 0;
  1057. }
  1058. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1059. {
  1060. struct ieee80211_local *local = wiphy_priv(wiphy);
  1061. drv_rfkill_poll(local);
  1062. }
  1063. #ifdef CONFIG_NL80211_TESTMODE
  1064. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1065. {
  1066. struct ieee80211_local *local = wiphy_priv(wiphy);
  1067. if (!local->ops->testmode_cmd)
  1068. return -EOPNOTSUPP;
  1069. return local->ops->testmode_cmd(&local->hw, data, len);
  1070. }
  1071. #endif
  1072. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1073. bool enabled, int timeout)
  1074. {
  1075. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1076. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1077. struct ieee80211_conf *conf = &local->hw.conf;
  1078. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1079. return -EOPNOTSUPP;
  1080. if (enabled == sdata->u.mgd.powersave &&
  1081. timeout == conf->dynamic_ps_timeout)
  1082. return 0;
  1083. sdata->u.mgd.powersave = enabled;
  1084. conf->dynamic_ps_timeout = timeout;
  1085. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1086. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1087. ieee80211_recalc_ps(local, -1);
  1088. return 0;
  1089. }
  1090. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1091. struct net_device *dev,
  1092. const u8 *addr,
  1093. const struct cfg80211_bitrate_mask *mask)
  1094. {
  1095. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1096. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1097. int i, err = -EINVAL;
  1098. u32 target_rate;
  1099. struct ieee80211_supported_band *sband;
  1100. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1101. /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
  1102. * target_rate = X, rate->fixed = 1 means only rate X
  1103. * target_rate = X, rate->fixed = 0 means all rates <= X */
  1104. sdata->max_ratectrl_rateidx = -1;
  1105. sdata->force_unicast_rateidx = -1;
  1106. if (mask->fixed)
  1107. target_rate = mask->fixed / 100;
  1108. else if (mask->maxrate)
  1109. target_rate = mask->maxrate / 100;
  1110. else
  1111. return 0;
  1112. for (i=0; i< sband->n_bitrates; i++) {
  1113. struct ieee80211_rate *brate = &sband->bitrates[i];
  1114. int this_rate = brate->bitrate;
  1115. if (target_rate == this_rate) {
  1116. sdata->max_ratectrl_rateidx = i;
  1117. if (mask->fixed)
  1118. sdata->force_unicast_rateidx = i;
  1119. err = 0;
  1120. break;
  1121. }
  1122. }
  1123. return err;
  1124. }
  1125. struct cfg80211_ops mac80211_config_ops = {
  1126. .add_virtual_intf = ieee80211_add_iface,
  1127. .del_virtual_intf = ieee80211_del_iface,
  1128. .change_virtual_intf = ieee80211_change_iface,
  1129. .add_key = ieee80211_add_key,
  1130. .del_key = ieee80211_del_key,
  1131. .get_key = ieee80211_get_key,
  1132. .set_default_key = ieee80211_config_default_key,
  1133. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1134. .add_beacon = ieee80211_add_beacon,
  1135. .set_beacon = ieee80211_set_beacon,
  1136. .del_beacon = ieee80211_del_beacon,
  1137. .add_station = ieee80211_add_station,
  1138. .del_station = ieee80211_del_station,
  1139. .change_station = ieee80211_change_station,
  1140. .get_station = ieee80211_get_station,
  1141. .dump_station = ieee80211_dump_station,
  1142. #ifdef CONFIG_MAC80211_MESH
  1143. .add_mpath = ieee80211_add_mpath,
  1144. .del_mpath = ieee80211_del_mpath,
  1145. .change_mpath = ieee80211_change_mpath,
  1146. .get_mpath = ieee80211_get_mpath,
  1147. .dump_mpath = ieee80211_dump_mpath,
  1148. .set_mesh_params = ieee80211_set_mesh_params,
  1149. .get_mesh_params = ieee80211_get_mesh_params,
  1150. #endif
  1151. .change_bss = ieee80211_change_bss,
  1152. .set_txq_params = ieee80211_set_txq_params,
  1153. .set_channel = ieee80211_set_channel,
  1154. .suspend = ieee80211_suspend,
  1155. .resume = ieee80211_resume,
  1156. .scan = ieee80211_scan,
  1157. .auth = ieee80211_auth,
  1158. .assoc = ieee80211_assoc,
  1159. .deauth = ieee80211_deauth,
  1160. .disassoc = ieee80211_disassoc,
  1161. .join_ibss = ieee80211_join_ibss,
  1162. .leave_ibss = ieee80211_leave_ibss,
  1163. .set_wiphy_params = ieee80211_set_wiphy_params,
  1164. .set_tx_power = ieee80211_set_tx_power,
  1165. .get_tx_power = ieee80211_get_tx_power,
  1166. .set_wds_peer = ieee80211_set_wds_peer,
  1167. .rfkill_poll = ieee80211_rfkill_poll,
  1168. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1169. .set_power_mgmt = ieee80211_set_power_mgmt,
  1170. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1171. };