cfg.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  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. if (sdata->vif.type != NL80211_IFTYPE_AP)
  438. return -EINVAL;
  439. old = sdata->u.ap.beacon;
  440. if (old)
  441. return -EALREADY;
  442. return ieee80211_config_beacon(sdata, params);
  443. }
  444. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  445. struct beacon_parameters *params)
  446. {
  447. struct ieee80211_sub_if_data *sdata;
  448. struct beacon_data *old;
  449. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  450. if (sdata->vif.type != NL80211_IFTYPE_AP)
  451. return -EINVAL;
  452. old = sdata->u.ap.beacon;
  453. if (!old)
  454. return -ENOENT;
  455. return ieee80211_config_beacon(sdata, params);
  456. }
  457. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  458. {
  459. struct ieee80211_sub_if_data *sdata;
  460. struct beacon_data *old;
  461. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  462. if (sdata->vif.type != NL80211_IFTYPE_AP)
  463. return -EINVAL;
  464. old = sdata->u.ap.beacon;
  465. if (!old)
  466. return -ENOENT;
  467. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  468. synchronize_rcu();
  469. kfree(old);
  470. return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED);
  471. }
  472. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  473. struct iapp_layer2_update {
  474. u8 da[ETH_ALEN]; /* broadcast */
  475. u8 sa[ETH_ALEN]; /* STA addr */
  476. __be16 len; /* 6 */
  477. u8 dsap; /* 0 */
  478. u8 ssap; /* 0 */
  479. u8 control;
  480. u8 xid_info[3];
  481. } __attribute__ ((packed));
  482. static void ieee80211_send_layer2_update(struct sta_info *sta)
  483. {
  484. struct iapp_layer2_update *msg;
  485. struct sk_buff *skb;
  486. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  487. * bridge devices */
  488. skb = dev_alloc_skb(sizeof(*msg));
  489. if (!skb)
  490. return;
  491. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  492. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  493. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  494. memset(msg->da, 0xff, ETH_ALEN);
  495. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  496. msg->len = htons(6);
  497. msg->dsap = 0;
  498. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  499. msg->control = 0xaf; /* XID response lsb.1111F101.
  500. * F=0 (no poll command; unsolicited frame) */
  501. msg->xid_info[0] = 0x81; /* XID format identifier */
  502. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  503. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  504. skb->dev = sta->sdata->dev;
  505. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  506. memset(skb->cb, 0, sizeof(skb->cb));
  507. netif_rx(skb);
  508. }
  509. static void sta_apply_parameters(struct ieee80211_local *local,
  510. struct sta_info *sta,
  511. struct station_parameters *params)
  512. {
  513. u32 rates;
  514. int i, j;
  515. struct ieee80211_supported_band *sband;
  516. struct ieee80211_sub_if_data *sdata = sta->sdata;
  517. sband = local->hw.wiphy->bands[local->oper_channel->band];
  518. /*
  519. * FIXME: updating the flags is racy when this function is
  520. * called from ieee80211_change_station(), this will
  521. * be resolved in a future patch.
  522. */
  523. if (params->station_flags & STATION_FLAG_CHANGED) {
  524. spin_lock_bh(&sta->lock);
  525. sta->flags &= ~WLAN_STA_AUTHORIZED;
  526. if (params->station_flags & STATION_FLAG_AUTHORIZED)
  527. sta->flags |= WLAN_STA_AUTHORIZED;
  528. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  529. if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
  530. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  531. sta->flags &= ~WLAN_STA_WME;
  532. if (params->station_flags & STATION_FLAG_WME)
  533. sta->flags |= WLAN_STA_WME;
  534. sta->flags &= ~WLAN_STA_MFP;
  535. if (params->station_flags & STATION_FLAG_MFP)
  536. sta->flags |= WLAN_STA_MFP;
  537. spin_unlock_bh(&sta->lock);
  538. }
  539. /*
  540. * FIXME: updating the following information is racy when this
  541. * function is called from ieee80211_change_station().
  542. * However, all this information should be static so
  543. * maybe we should just reject attemps to change it.
  544. */
  545. if (params->aid) {
  546. sta->sta.aid = params->aid;
  547. if (sta->sta.aid > IEEE80211_MAX_AID)
  548. sta->sta.aid = 0; /* XXX: should this be an error? */
  549. }
  550. if (params->listen_interval >= 0)
  551. sta->listen_interval = params->listen_interval;
  552. if (params->supported_rates) {
  553. rates = 0;
  554. for (i = 0; i < params->supported_rates_len; i++) {
  555. int rate = (params->supported_rates[i] & 0x7f) * 5;
  556. for (j = 0; j < sband->n_bitrates; j++) {
  557. if (sband->bitrates[j].bitrate == rate)
  558. rates |= BIT(j);
  559. }
  560. }
  561. sta->sta.supp_rates[local->oper_channel->band] = rates;
  562. }
  563. if (params->ht_capa)
  564. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  565. params->ht_capa,
  566. &sta->sta.ht_cap);
  567. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  568. switch (params->plink_action) {
  569. case PLINK_ACTION_OPEN:
  570. mesh_plink_open(sta);
  571. break;
  572. case PLINK_ACTION_BLOCK:
  573. mesh_plink_block(sta);
  574. break;
  575. }
  576. }
  577. }
  578. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  579. u8 *mac, struct station_parameters *params)
  580. {
  581. struct ieee80211_local *local = wiphy_priv(wiphy);
  582. struct sta_info *sta;
  583. struct ieee80211_sub_if_data *sdata;
  584. int err;
  585. int layer2_update;
  586. /* Prevent a race with changing the rate control algorithm */
  587. if (!netif_running(dev))
  588. return -ENETDOWN;
  589. if (params->vlan) {
  590. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  591. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  592. sdata->vif.type != NL80211_IFTYPE_AP)
  593. return -EINVAL;
  594. } else
  595. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  596. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  597. return -EINVAL;
  598. if (is_multicast_ether_addr(mac))
  599. return -EINVAL;
  600. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  601. if (!sta)
  602. return -ENOMEM;
  603. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  604. sta_apply_parameters(local, sta, params);
  605. rate_control_rate_init(sta);
  606. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  607. sdata->vif.type == NL80211_IFTYPE_AP;
  608. rcu_read_lock();
  609. err = sta_info_insert(sta);
  610. if (err) {
  611. /* STA has been freed */
  612. if (err == -EEXIST && layer2_update) {
  613. /* Need to update layer 2 devices on reassociation */
  614. sta = sta_info_get(local, mac);
  615. if (sta)
  616. ieee80211_send_layer2_update(sta);
  617. }
  618. rcu_read_unlock();
  619. return err;
  620. }
  621. if (layer2_update)
  622. ieee80211_send_layer2_update(sta);
  623. rcu_read_unlock();
  624. return 0;
  625. }
  626. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  627. u8 *mac)
  628. {
  629. struct ieee80211_local *local = wiphy_priv(wiphy);
  630. struct ieee80211_sub_if_data *sdata;
  631. struct sta_info *sta;
  632. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  633. if (mac) {
  634. rcu_read_lock();
  635. /* XXX: get sta belonging to dev */
  636. sta = sta_info_get(local, mac);
  637. if (!sta) {
  638. rcu_read_unlock();
  639. return -ENOENT;
  640. }
  641. sta_info_unlink(&sta);
  642. rcu_read_unlock();
  643. sta_info_destroy(sta);
  644. } else
  645. sta_info_flush(local, sdata);
  646. return 0;
  647. }
  648. static int ieee80211_change_station(struct wiphy *wiphy,
  649. struct net_device *dev,
  650. u8 *mac,
  651. struct station_parameters *params)
  652. {
  653. struct ieee80211_local *local = wiphy_priv(wiphy);
  654. struct sta_info *sta;
  655. struct ieee80211_sub_if_data *vlansdata;
  656. rcu_read_lock();
  657. /* XXX: get sta belonging to dev */
  658. sta = sta_info_get(local, mac);
  659. if (!sta) {
  660. rcu_read_unlock();
  661. return -ENOENT;
  662. }
  663. if (params->vlan && params->vlan != sta->sdata->dev) {
  664. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  665. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  666. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  667. rcu_read_unlock();
  668. return -EINVAL;
  669. }
  670. sta->sdata = vlansdata;
  671. ieee80211_send_layer2_update(sta);
  672. }
  673. sta_apply_parameters(local, sta, params);
  674. rcu_read_unlock();
  675. return 0;
  676. }
  677. #ifdef CONFIG_MAC80211_MESH
  678. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  679. u8 *dst, u8 *next_hop)
  680. {
  681. struct ieee80211_local *local = wiphy_priv(wiphy);
  682. struct ieee80211_sub_if_data *sdata;
  683. struct mesh_path *mpath;
  684. struct sta_info *sta;
  685. int err;
  686. if (!netif_running(dev))
  687. return -ENETDOWN;
  688. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  689. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  690. return -ENOTSUPP;
  691. rcu_read_lock();
  692. sta = sta_info_get(local, next_hop);
  693. if (!sta) {
  694. rcu_read_unlock();
  695. return -ENOENT;
  696. }
  697. err = mesh_path_add(dst, sdata);
  698. if (err) {
  699. rcu_read_unlock();
  700. return err;
  701. }
  702. mpath = mesh_path_lookup(dst, sdata);
  703. if (!mpath) {
  704. rcu_read_unlock();
  705. return -ENXIO;
  706. }
  707. mesh_path_fix_nexthop(mpath, sta);
  708. rcu_read_unlock();
  709. return 0;
  710. }
  711. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  712. u8 *dst)
  713. {
  714. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  715. if (dst)
  716. return mesh_path_del(dst, sdata);
  717. mesh_path_flush(sdata);
  718. return 0;
  719. }
  720. static int ieee80211_change_mpath(struct wiphy *wiphy,
  721. struct net_device *dev,
  722. u8 *dst, u8 *next_hop)
  723. {
  724. struct ieee80211_local *local = wiphy_priv(wiphy);
  725. struct ieee80211_sub_if_data *sdata;
  726. struct mesh_path *mpath;
  727. struct sta_info *sta;
  728. if (!netif_running(dev))
  729. return -ENETDOWN;
  730. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  731. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  732. return -ENOTSUPP;
  733. rcu_read_lock();
  734. sta = sta_info_get(local, next_hop);
  735. if (!sta) {
  736. rcu_read_unlock();
  737. return -ENOENT;
  738. }
  739. mpath = mesh_path_lookup(dst, sdata);
  740. if (!mpath) {
  741. rcu_read_unlock();
  742. return -ENOENT;
  743. }
  744. mesh_path_fix_nexthop(mpath, sta);
  745. rcu_read_unlock();
  746. return 0;
  747. }
  748. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  749. struct mpath_info *pinfo)
  750. {
  751. if (mpath->next_hop)
  752. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  753. else
  754. memset(next_hop, 0, ETH_ALEN);
  755. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  756. MPATH_INFO_DSN |
  757. MPATH_INFO_METRIC |
  758. MPATH_INFO_EXPTIME |
  759. MPATH_INFO_DISCOVERY_TIMEOUT |
  760. MPATH_INFO_DISCOVERY_RETRIES |
  761. MPATH_INFO_FLAGS;
  762. pinfo->frame_qlen = mpath->frame_queue.qlen;
  763. pinfo->dsn = mpath->dsn;
  764. pinfo->metric = mpath->metric;
  765. if (time_before(jiffies, mpath->exp_time))
  766. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  767. pinfo->discovery_timeout =
  768. jiffies_to_msecs(mpath->discovery_timeout);
  769. pinfo->discovery_retries = mpath->discovery_retries;
  770. pinfo->flags = 0;
  771. if (mpath->flags & MESH_PATH_ACTIVE)
  772. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  773. if (mpath->flags & MESH_PATH_RESOLVING)
  774. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  775. if (mpath->flags & MESH_PATH_DSN_VALID)
  776. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  777. if (mpath->flags & MESH_PATH_FIXED)
  778. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  779. if (mpath->flags & MESH_PATH_RESOLVING)
  780. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  781. pinfo->flags = mpath->flags;
  782. }
  783. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  784. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  785. {
  786. struct ieee80211_sub_if_data *sdata;
  787. struct mesh_path *mpath;
  788. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  789. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  790. return -ENOTSUPP;
  791. rcu_read_lock();
  792. mpath = mesh_path_lookup(dst, sdata);
  793. if (!mpath) {
  794. rcu_read_unlock();
  795. return -ENOENT;
  796. }
  797. memcpy(dst, mpath->dst, ETH_ALEN);
  798. mpath_set_pinfo(mpath, next_hop, pinfo);
  799. rcu_read_unlock();
  800. return 0;
  801. }
  802. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  803. int idx, u8 *dst, u8 *next_hop,
  804. struct mpath_info *pinfo)
  805. {
  806. struct ieee80211_sub_if_data *sdata;
  807. struct mesh_path *mpath;
  808. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  809. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  810. return -ENOTSUPP;
  811. rcu_read_lock();
  812. mpath = mesh_path_lookup_by_idx(idx, sdata);
  813. if (!mpath) {
  814. rcu_read_unlock();
  815. return -ENOENT;
  816. }
  817. memcpy(dst, mpath->dst, ETH_ALEN);
  818. mpath_set_pinfo(mpath, next_hop, pinfo);
  819. rcu_read_unlock();
  820. return 0;
  821. }
  822. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  823. struct net_device *dev,
  824. struct mesh_config *conf)
  825. {
  826. struct ieee80211_sub_if_data *sdata;
  827. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  828. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  829. return -ENOTSUPP;
  830. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  831. return 0;
  832. }
  833. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  834. {
  835. return (mask >> (parm-1)) & 0x1;
  836. }
  837. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  838. struct net_device *dev,
  839. const struct mesh_config *nconf, u32 mask)
  840. {
  841. struct mesh_config *conf;
  842. struct ieee80211_sub_if_data *sdata;
  843. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  844. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  845. return -ENOTSUPP;
  846. /* Set the config options which we are interested in setting */
  847. conf = &(sdata->u.mesh.mshcfg);
  848. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  849. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  850. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  851. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  852. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  853. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  854. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  855. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  856. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  857. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  858. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  859. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  860. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  861. conf->auto_open_plinks = nconf->auto_open_plinks;
  862. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  863. conf->dot11MeshHWMPmaxPREQretries =
  864. nconf->dot11MeshHWMPmaxPREQretries;
  865. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  866. conf->path_refresh_time = nconf->path_refresh_time;
  867. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  868. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  869. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  870. conf->dot11MeshHWMPactivePathTimeout =
  871. nconf->dot11MeshHWMPactivePathTimeout;
  872. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  873. conf->dot11MeshHWMPpreqMinInterval =
  874. nconf->dot11MeshHWMPpreqMinInterval;
  875. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  876. mask))
  877. conf->dot11MeshHWMPnetDiameterTraversalTime =
  878. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  879. return 0;
  880. }
  881. #endif
  882. static int ieee80211_change_bss(struct wiphy *wiphy,
  883. struct net_device *dev,
  884. struct bss_parameters *params)
  885. {
  886. struct ieee80211_sub_if_data *sdata;
  887. u32 changed = 0;
  888. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  889. if (sdata->vif.type != NL80211_IFTYPE_AP)
  890. return -EINVAL;
  891. if (params->use_cts_prot >= 0) {
  892. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  893. changed |= BSS_CHANGED_ERP_CTS_PROT;
  894. }
  895. if (params->use_short_preamble >= 0) {
  896. sdata->vif.bss_conf.use_short_preamble =
  897. params->use_short_preamble;
  898. changed |= BSS_CHANGED_ERP_PREAMBLE;
  899. }
  900. if (params->use_short_slot_time >= 0) {
  901. sdata->vif.bss_conf.use_short_slot =
  902. params->use_short_slot_time;
  903. changed |= BSS_CHANGED_ERP_SLOT;
  904. }
  905. if (params->basic_rates) {
  906. int i, j;
  907. u32 rates = 0;
  908. struct ieee80211_local *local = wiphy_priv(wiphy);
  909. struct ieee80211_supported_band *sband =
  910. wiphy->bands[local->oper_channel->band];
  911. for (i = 0; i < params->basic_rates_len; i++) {
  912. int rate = (params->basic_rates[i] & 0x7f) * 5;
  913. for (j = 0; j < sband->n_bitrates; j++) {
  914. if (sband->bitrates[j].bitrate == rate)
  915. rates |= BIT(j);
  916. }
  917. }
  918. sdata->vif.bss_conf.basic_rates = rates;
  919. changed |= BSS_CHANGED_BASIC_RATES;
  920. }
  921. ieee80211_bss_info_change_notify(sdata, changed);
  922. return 0;
  923. }
  924. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  925. struct ieee80211_txq_params *params)
  926. {
  927. struct ieee80211_local *local = wiphy_priv(wiphy);
  928. struct ieee80211_tx_queue_params p;
  929. if (!local->ops->conf_tx)
  930. return -EOPNOTSUPP;
  931. memset(&p, 0, sizeof(p));
  932. p.aifs = params->aifs;
  933. p.cw_max = params->cwmax;
  934. p.cw_min = params->cwmin;
  935. p.txop = params->txop;
  936. if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
  937. printk(KERN_DEBUG "%s: failed to set TX queue "
  938. "parameters for queue %d\n", local->mdev->name,
  939. params->queue);
  940. return -EINVAL;
  941. }
  942. return 0;
  943. }
  944. static int ieee80211_set_channel(struct wiphy *wiphy,
  945. struct ieee80211_channel *chan,
  946. enum nl80211_channel_type channel_type)
  947. {
  948. struct ieee80211_local *local = wiphy_priv(wiphy);
  949. local->oper_channel = chan;
  950. local->oper_channel_type = channel_type;
  951. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  952. }
  953. static int set_mgmt_extra_ie_sta(struct ieee80211_sub_if_data *sdata,
  954. u8 subtype, u8 *ies, size_t ies_len)
  955. {
  956. struct ieee80211_local *local = sdata->local;
  957. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  958. switch (subtype) {
  959. case IEEE80211_STYPE_PROBE_REQ >> 4:
  960. if (local->ops->hw_scan)
  961. break;
  962. kfree(ifmgd->ie_probereq);
  963. ifmgd->ie_probereq = ies;
  964. ifmgd->ie_probereq_len = ies_len;
  965. return 0;
  966. case IEEE80211_STYPE_PROBE_RESP >> 4:
  967. kfree(ifmgd->ie_proberesp);
  968. ifmgd->ie_proberesp = ies;
  969. ifmgd->ie_proberesp_len = ies_len;
  970. return 0;
  971. case IEEE80211_STYPE_AUTH >> 4:
  972. kfree(ifmgd->ie_auth);
  973. ifmgd->ie_auth = ies;
  974. ifmgd->ie_auth_len = ies_len;
  975. return 0;
  976. case IEEE80211_STYPE_ASSOC_REQ >> 4:
  977. kfree(ifmgd->ie_assocreq);
  978. ifmgd->ie_assocreq = ies;
  979. ifmgd->ie_assocreq_len = ies_len;
  980. return 0;
  981. case IEEE80211_STYPE_REASSOC_REQ >> 4:
  982. kfree(ifmgd->ie_reassocreq);
  983. ifmgd->ie_reassocreq = ies;
  984. ifmgd->ie_reassocreq_len = ies_len;
  985. return 0;
  986. case IEEE80211_STYPE_DEAUTH >> 4:
  987. kfree(ifmgd->ie_deauth);
  988. ifmgd->ie_deauth = ies;
  989. ifmgd->ie_deauth_len = ies_len;
  990. return 0;
  991. case IEEE80211_STYPE_DISASSOC >> 4:
  992. kfree(ifmgd->ie_disassoc);
  993. ifmgd->ie_disassoc = ies;
  994. ifmgd->ie_disassoc_len = ies_len;
  995. return 0;
  996. }
  997. return -EOPNOTSUPP;
  998. }
  999. static int ieee80211_set_mgmt_extra_ie(struct wiphy *wiphy,
  1000. struct net_device *dev,
  1001. struct mgmt_extra_ie_params *params)
  1002. {
  1003. struct ieee80211_sub_if_data *sdata;
  1004. u8 *ies;
  1005. size_t ies_len;
  1006. int ret = -EOPNOTSUPP;
  1007. if (params->ies) {
  1008. ies = kmemdup(params->ies, params->ies_len, GFP_KERNEL);
  1009. if (ies == NULL)
  1010. return -ENOMEM;
  1011. ies_len = params->ies_len;
  1012. } else {
  1013. ies = NULL;
  1014. ies_len = 0;
  1015. }
  1016. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1017. switch (sdata->vif.type) {
  1018. case NL80211_IFTYPE_STATION:
  1019. ret = set_mgmt_extra_ie_sta(sdata, params->subtype,
  1020. ies, ies_len);
  1021. break;
  1022. default:
  1023. ret = -EOPNOTSUPP;
  1024. break;
  1025. }
  1026. if (ret)
  1027. kfree(ies);
  1028. return ret;
  1029. }
  1030. #ifdef CONFIG_PM
  1031. static int ieee80211_suspend(struct wiphy *wiphy)
  1032. {
  1033. return __ieee80211_suspend(wiphy_priv(wiphy));
  1034. }
  1035. static int ieee80211_resume(struct wiphy *wiphy)
  1036. {
  1037. return __ieee80211_resume(wiphy_priv(wiphy));
  1038. }
  1039. #else
  1040. #define ieee80211_suspend NULL
  1041. #define ieee80211_resume NULL
  1042. #endif
  1043. static int ieee80211_scan(struct wiphy *wiphy,
  1044. struct net_device *dev,
  1045. struct cfg80211_scan_request *req)
  1046. {
  1047. struct ieee80211_sub_if_data *sdata;
  1048. if (!netif_running(dev))
  1049. return -ENETDOWN;
  1050. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1051. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1052. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1053. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  1054. return -EOPNOTSUPP;
  1055. return ieee80211_request_scan(sdata, req);
  1056. }
  1057. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1058. struct cfg80211_auth_request *req)
  1059. {
  1060. struct ieee80211_sub_if_data *sdata;
  1061. if (!netif_running(dev))
  1062. return -ENETDOWN;
  1063. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1064. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1065. return -EOPNOTSUPP;
  1066. switch (req->auth_type) {
  1067. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  1068. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
  1069. break;
  1070. case NL80211_AUTHTYPE_SHARED_KEY:
  1071. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
  1072. break;
  1073. case NL80211_AUTHTYPE_FT:
  1074. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
  1075. break;
  1076. case NL80211_AUTHTYPE_NETWORK_EAP:
  1077. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
  1078. break;
  1079. default:
  1080. return -EOPNOTSUPP;
  1081. }
  1082. memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
  1083. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  1084. sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
  1085. /* TODO: req->chan */
  1086. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
  1087. if (req->ssid) {
  1088. sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
  1089. memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
  1090. sdata->u.mgd.ssid_len = req->ssid_len;
  1091. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  1092. }
  1093. kfree(sdata->u.mgd.sme_auth_ie);
  1094. sdata->u.mgd.sme_auth_ie = NULL;
  1095. sdata->u.mgd.sme_auth_ie_len = 0;
  1096. if (req->ie) {
  1097. sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
  1098. if (sdata->u.mgd.sme_auth_ie == NULL)
  1099. return -ENOMEM;
  1100. memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
  1101. sdata->u.mgd.sme_auth_ie_len = req->ie_len;
  1102. }
  1103. sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
  1104. sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1105. ieee80211_sta_req_auth(sdata);
  1106. return 0;
  1107. }
  1108. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1109. struct cfg80211_assoc_request *req)
  1110. {
  1111. struct ieee80211_sub_if_data *sdata;
  1112. int ret;
  1113. if (!netif_running(dev))
  1114. return -ENETDOWN;
  1115. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1116. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1117. return -EOPNOTSUPP;
  1118. if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
  1119. !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
  1120. return -ENOLINK; /* not authenticated */
  1121. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  1122. sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
  1123. /* TODO: req->chan */
  1124. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
  1125. if (req->ssid) {
  1126. sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
  1127. memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
  1128. sdata->u.mgd.ssid_len = req->ssid_len;
  1129. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  1130. } else
  1131. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
  1132. ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
  1133. if (ret)
  1134. return ret;
  1135. sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
  1136. sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
  1137. ieee80211_sta_req_auth(sdata);
  1138. return 0;
  1139. }
  1140. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1141. struct cfg80211_deauth_request *req)
  1142. {
  1143. struct ieee80211_sub_if_data *sdata;
  1144. if (!netif_running(dev))
  1145. return -ENETDOWN;
  1146. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1147. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1148. return -EOPNOTSUPP;
  1149. /* TODO: req->ie */
  1150. return ieee80211_sta_deauthenticate(sdata, req->reason_code);
  1151. }
  1152. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1153. struct cfg80211_disassoc_request *req)
  1154. {
  1155. struct ieee80211_sub_if_data *sdata;
  1156. if (!netif_running(dev))
  1157. return -ENETDOWN;
  1158. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1159. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1160. return -EOPNOTSUPP;
  1161. /* TODO: req->ie */
  1162. return ieee80211_sta_disassociate(sdata, req->reason_code);
  1163. }
  1164. struct cfg80211_ops mac80211_config_ops = {
  1165. .add_virtual_intf = ieee80211_add_iface,
  1166. .del_virtual_intf = ieee80211_del_iface,
  1167. .change_virtual_intf = ieee80211_change_iface,
  1168. .add_key = ieee80211_add_key,
  1169. .del_key = ieee80211_del_key,
  1170. .get_key = ieee80211_get_key,
  1171. .set_default_key = ieee80211_config_default_key,
  1172. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1173. .add_beacon = ieee80211_add_beacon,
  1174. .set_beacon = ieee80211_set_beacon,
  1175. .del_beacon = ieee80211_del_beacon,
  1176. .add_station = ieee80211_add_station,
  1177. .del_station = ieee80211_del_station,
  1178. .change_station = ieee80211_change_station,
  1179. .get_station = ieee80211_get_station,
  1180. .dump_station = ieee80211_dump_station,
  1181. #ifdef CONFIG_MAC80211_MESH
  1182. .add_mpath = ieee80211_add_mpath,
  1183. .del_mpath = ieee80211_del_mpath,
  1184. .change_mpath = ieee80211_change_mpath,
  1185. .get_mpath = ieee80211_get_mpath,
  1186. .dump_mpath = ieee80211_dump_mpath,
  1187. .set_mesh_params = ieee80211_set_mesh_params,
  1188. .get_mesh_params = ieee80211_get_mesh_params,
  1189. #endif
  1190. .change_bss = ieee80211_change_bss,
  1191. .set_txq_params = ieee80211_set_txq_params,
  1192. .set_channel = ieee80211_set_channel,
  1193. .set_mgmt_extra_ie = ieee80211_set_mgmt_extra_ie,
  1194. .suspend = ieee80211_suspend,
  1195. .resume = ieee80211_resume,
  1196. .scan = ieee80211_scan,
  1197. .auth = ieee80211_auth,
  1198. .assoc = ieee80211_assoc,
  1199. .deauth = ieee80211_deauth,
  1200. .disassoc = ieee80211_disassoc,
  1201. };