cfg.c 37 KB

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