cfg.c 33 KB

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