cfg.c 34 KB

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