cfg.c 32 KB

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