key.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. * Copyright 2007-2008 Johannes Berg <johannes@sipsolutions.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/if_ether.h>
  12. #include <linux/etherdevice.h>
  13. #include <linux/list.h>
  14. #include <linux/rcupdate.h>
  15. #include <linux/rtnetlink.h>
  16. #include <linux/slab.h>
  17. #include <linux/export.h>
  18. #include <net/mac80211.h>
  19. #include "ieee80211_i.h"
  20. #include "driver-ops.h"
  21. #include "debugfs_key.h"
  22. #include "aes_ccm.h"
  23. #include "aes_cmac.h"
  24. /**
  25. * DOC: Key handling basics
  26. *
  27. * Key handling in mac80211 is done based on per-interface (sub_if_data)
  28. * keys and per-station keys. Since each station belongs to an interface,
  29. * each station key also belongs to that interface.
  30. *
  31. * Hardware acceleration is done on a best-effort basis for algorithms
  32. * that are implemented in software, for each key the hardware is asked
  33. * to enable that key for offloading but if it cannot do that the key is
  34. * simply kept for software encryption (unless it is for an algorithm
  35. * that isn't implemented in software).
  36. * There is currently no way of knowing whether a key is handled in SW
  37. * or HW except by looking into debugfs.
  38. *
  39. * All key management is internally protected by a mutex. Within all
  40. * other parts of mac80211, key references are, just as STA structure
  41. * references, protected by RCU. Note, however, that some things are
  42. * unprotected, namely the key->sta dereferences within the hardware
  43. * acceleration functions. This means that sta_info_destroy() must
  44. * remove the key which waits for an RCU grace period.
  45. */
  46. static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  47. static void assert_key_lock(struct ieee80211_local *local)
  48. {
  49. lockdep_assert_held(&local->key_mtx);
  50. }
  51. static struct ieee80211_sta *get_sta_for_key(struct ieee80211_key *key)
  52. {
  53. if (key->sta)
  54. return &key->sta->sta;
  55. return NULL;
  56. }
  57. static void increment_tailroom_need_count(struct ieee80211_sub_if_data *sdata)
  58. {
  59. /*
  60. * When this count is zero, SKB resizing for allocating tailroom
  61. * for IV or MMIC is skipped. But, this check has created two race
  62. * cases in xmit path while transiting from zero count to one:
  63. *
  64. * 1. SKB resize was skipped because no key was added but just before
  65. * the xmit key is added and SW encryption kicks off.
  66. *
  67. * 2. SKB resize was skipped because all the keys were hw planted but
  68. * just before xmit one of the key is deleted and SW encryption kicks
  69. * off.
  70. *
  71. * In both the above case SW encryption will find not enough space for
  72. * tailroom and exits with WARN_ON. (See WARN_ONs at wpa.c)
  73. *
  74. * Solution has been explained at
  75. * http://mid.gmane.org/1308590980.4322.19.camel@jlt3.sipsolutions.net
  76. */
  77. if (!sdata->crypto_tx_tailroom_needed_cnt++) {
  78. /*
  79. * Flush all XMIT packets currently using HW encryption or no
  80. * encryption at all if the count transition is from 0 -> 1.
  81. */
  82. synchronize_net();
  83. }
  84. }
  85. static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
  86. {
  87. struct ieee80211_sub_if_data *sdata;
  88. struct ieee80211_sta *sta;
  89. int ret;
  90. might_sleep();
  91. if (!key->local->ops->set_key)
  92. goto out_unsupported;
  93. assert_key_lock(key->local);
  94. sta = get_sta_for_key(key);
  95. /*
  96. * If this is a per-STA GTK, check if it
  97. * is supported; if not, return.
  98. */
  99. if (sta && !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE) &&
  100. !(key->local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK))
  101. goto out_unsupported;
  102. sdata = key->sdata;
  103. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  104. /*
  105. * The driver doesn't know anything about VLAN interfaces.
  106. * Hence, don't send GTKs for VLAN interfaces to the driver.
  107. */
  108. if (!(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE))
  109. goto out_unsupported;
  110. sdata = container_of(sdata->bss,
  111. struct ieee80211_sub_if_data,
  112. u.ap);
  113. }
  114. ret = drv_set_key(key->local, SET_KEY, sdata, sta, &key->conf);
  115. if (!ret) {
  116. key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
  117. if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
  118. (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)))
  119. sdata->crypto_tx_tailroom_needed_cnt--;
  120. return 0;
  121. }
  122. if (ret != -ENOSPC && ret != -EOPNOTSUPP)
  123. wiphy_err(key->local->hw.wiphy,
  124. "failed to set key (%d, %pM) to hardware (%d)\n",
  125. key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
  126. out_unsupported:
  127. switch (key->conf.cipher) {
  128. case WLAN_CIPHER_SUITE_WEP40:
  129. case WLAN_CIPHER_SUITE_WEP104:
  130. case WLAN_CIPHER_SUITE_TKIP:
  131. case WLAN_CIPHER_SUITE_CCMP:
  132. case WLAN_CIPHER_SUITE_AES_CMAC:
  133. /* all of these we can do in software */
  134. return 0;
  135. default:
  136. return -EINVAL;
  137. }
  138. }
  139. static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
  140. {
  141. struct ieee80211_sub_if_data *sdata;
  142. struct ieee80211_sta *sta;
  143. int ret;
  144. might_sleep();
  145. if (!key || !key->local->ops->set_key)
  146. return;
  147. assert_key_lock(key->local);
  148. if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  149. return;
  150. sta = get_sta_for_key(key);
  151. sdata = key->sdata;
  152. if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
  153. (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)))
  154. increment_tailroom_need_count(sdata);
  155. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  156. sdata = container_of(sdata->bss,
  157. struct ieee80211_sub_if_data,
  158. u.ap);
  159. ret = drv_set_key(key->local, DISABLE_KEY, sdata,
  160. sta, &key->conf);
  161. if (ret)
  162. wiphy_err(key->local->hw.wiphy,
  163. "failed to remove key (%d, %pM) from hardware (%d)\n",
  164. key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
  165. key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
  166. }
  167. void ieee80211_key_removed(struct ieee80211_key_conf *key_conf)
  168. {
  169. struct ieee80211_key *key;
  170. key = container_of(key_conf, struct ieee80211_key, conf);
  171. might_sleep();
  172. assert_key_lock(key->local);
  173. key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
  174. /*
  175. * Flush TX path to avoid attempts to use this key
  176. * after this function returns. Until then, drivers
  177. * must be prepared to handle the key.
  178. */
  179. synchronize_rcu();
  180. }
  181. EXPORT_SYMBOL_GPL(ieee80211_key_removed);
  182. static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
  183. int idx, bool uni, bool multi)
  184. {
  185. struct ieee80211_key *key = NULL;
  186. assert_key_lock(sdata->local);
  187. if (idx >= 0 && idx < NUM_DEFAULT_KEYS)
  188. key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
  189. if (uni)
  190. rcu_assign_pointer(sdata->default_unicast_key, key);
  191. if (multi)
  192. rcu_assign_pointer(sdata->default_multicast_key, key);
  193. ieee80211_debugfs_key_update_default(sdata);
  194. }
  195. void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx,
  196. bool uni, bool multi)
  197. {
  198. mutex_lock(&sdata->local->key_mtx);
  199. __ieee80211_set_default_key(sdata, idx, uni, multi);
  200. mutex_unlock(&sdata->local->key_mtx);
  201. }
  202. static void
  203. __ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, int idx)
  204. {
  205. struct ieee80211_key *key = NULL;
  206. assert_key_lock(sdata->local);
  207. if (idx >= NUM_DEFAULT_KEYS &&
  208. idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  209. key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
  210. rcu_assign_pointer(sdata->default_mgmt_key, key);
  211. ieee80211_debugfs_key_update_default(sdata);
  212. }
  213. void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
  214. int idx)
  215. {
  216. mutex_lock(&sdata->local->key_mtx);
  217. __ieee80211_set_default_mgmt_key(sdata, idx);
  218. mutex_unlock(&sdata->local->key_mtx);
  219. }
  220. static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
  221. struct sta_info *sta,
  222. bool pairwise,
  223. struct ieee80211_key *old,
  224. struct ieee80211_key *new)
  225. {
  226. int idx;
  227. bool defunikey, defmultikey, defmgmtkey;
  228. if (new)
  229. list_add_tail(&new->list, &sdata->key_list);
  230. if (sta && pairwise) {
  231. rcu_assign_pointer(sta->ptk, new);
  232. } else if (sta) {
  233. if (old)
  234. idx = old->conf.keyidx;
  235. else
  236. idx = new->conf.keyidx;
  237. rcu_assign_pointer(sta->gtk[idx], new);
  238. } else {
  239. WARN_ON(new && old && new->conf.keyidx != old->conf.keyidx);
  240. if (old)
  241. idx = old->conf.keyidx;
  242. else
  243. idx = new->conf.keyidx;
  244. defunikey = old &&
  245. old == key_mtx_dereference(sdata->local,
  246. sdata->default_unicast_key);
  247. defmultikey = old &&
  248. old == key_mtx_dereference(sdata->local,
  249. sdata->default_multicast_key);
  250. defmgmtkey = old &&
  251. old == key_mtx_dereference(sdata->local,
  252. sdata->default_mgmt_key);
  253. if (defunikey && !new)
  254. __ieee80211_set_default_key(sdata, -1, true, false);
  255. if (defmultikey && !new)
  256. __ieee80211_set_default_key(sdata, -1, false, true);
  257. if (defmgmtkey && !new)
  258. __ieee80211_set_default_mgmt_key(sdata, -1);
  259. rcu_assign_pointer(sdata->keys[idx], new);
  260. if (defunikey && new)
  261. __ieee80211_set_default_key(sdata, new->conf.keyidx,
  262. true, false);
  263. if (defmultikey && new)
  264. __ieee80211_set_default_key(sdata, new->conf.keyidx,
  265. false, true);
  266. if (defmgmtkey && new)
  267. __ieee80211_set_default_mgmt_key(sdata,
  268. new->conf.keyidx);
  269. }
  270. if (old)
  271. list_del(&old->list);
  272. }
  273. struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
  274. const u8 *key_data,
  275. size_t seq_len, const u8 *seq)
  276. {
  277. struct ieee80211_key *key;
  278. int i, j, err;
  279. BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS);
  280. key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL);
  281. if (!key)
  282. return ERR_PTR(-ENOMEM);
  283. /*
  284. * Default to software encryption; we'll later upload the
  285. * key to the hardware if possible.
  286. */
  287. key->conf.flags = 0;
  288. key->flags = 0;
  289. key->conf.cipher = cipher;
  290. key->conf.keyidx = idx;
  291. key->conf.keylen = key_len;
  292. switch (cipher) {
  293. case WLAN_CIPHER_SUITE_WEP40:
  294. case WLAN_CIPHER_SUITE_WEP104:
  295. key->conf.iv_len = WEP_IV_LEN;
  296. key->conf.icv_len = WEP_ICV_LEN;
  297. break;
  298. case WLAN_CIPHER_SUITE_TKIP:
  299. key->conf.iv_len = TKIP_IV_LEN;
  300. key->conf.icv_len = TKIP_ICV_LEN;
  301. if (seq) {
  302. for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
  303. key->u.tkip.rx[i].iv32 =
  304. get_unaligned_le32(&seq[2]);
  305. key->u.tkip.rx[i].iv16 =
  306. get_unaligned_le16(seq);
  307. }
  308. }
  309. spin_lock_init(&key->u.tkip.txlock);
  310. break;
  311. case WLAN_CIPHER_SUITE_CCMP:
  312. key->conf.iv_len = CCMP_HDR_LEN;
  313. key->conf.icv_len = CCMP_MIC_LEN;
  314. if (seq) {
  315. for (i = 0; i < NUM_RX_DATA_QUEUES + 1; i++)
  316. for (j = 0; j < CCMP_PN_LEN; j++)
  317. key->u.ccmp.rx_pn[i][j] =
  318. seq[CCMP_PN_LEN - j - 1];
  319. }
  320. /*
  321. * Initialize AES key state here as an optimization so that
  322. * it does not need to be initialized for every packet.
  323. */
  324. key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data);
  325. if (IS_ERR(key->u.ccmp.tfm)) {
  326. err = PTR_ERR(key->u.ccmp.tfm);
  327. kfree(key);
  328. return ERR_PTR(err);
  329. }
  330. break;
  331. case WLAN_CIPHER_SUITE_AES_CMAC:
  332. key->conf.iv_len = 0;
  333. key->conf.icv_len = sizeof(struct ieee80211_mmie);
  334. if (seq)
  335. for (j = 0; j < 6; j++)
  336. key->u.aes_cmac.rx_pn[j] = seq[6 - j - 1];
  337. /*
  338. * Initialize AES key state here as an optimization so that
  339. * it does not need to be initialized for every packet.
  340. */
  341. key->u.aes_cmac.tfm =
  342. ieee80211_aes_cmac_key_setup(key_data);
  343. if (IS_ERR(key->u.aes_cmac.tfm)) {
  344. err = PTR_ERR(key->u.aes_cmac.tfm);
  345. kfree(key);
  346. return ERR_PTR(err);
  347. }
  348. break;
  349. }
  350. memcpy(key->conf.key, key_data, key_len);
  351. INIT_LIST_HEAD(&key->list);
  352. return key;
  353. }
  354. static void __ieee80211_key_destroy(struct ieee80211_key *key)
  355. {
  356. if (!key)
  357. return;
  358. /*
  359. * Synchronize so the TX path can no longer be using
  360. * this key before we free/remove it.
  361. */
  362. synchronize_rcu();
  363. if (key->local)
  364. ieee80211_key_disable_hw_accel(key);
  365. if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP)
  366. ieee80211_aes_key_free(key->u.ccmp.tfm);
  367. if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC)
  368. ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm);
  369. if (key->local) {
  370. ieee80211_debugfs_key_remove(key);
  371. key->sdata->crypto_tx_tailroom_needed_cnt--;
  372. }
  373. kfree(key);
  374. }
  375. int ieee80211_key_link(struct ieee80211_key *key,
  376. struct ieee80211_sub_if_data *sdata,
  377. struct sta_info *sta)
  378. {
  379. struct ieee80211_key *old_key;
  380. int idx, ret;
  381. bool pairwise;
  382. BUG_ON(!sdata);
  383. BUG_ON(!key);
  384. pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
  385. idx = key->conf.keyidx;
  386. key->local = sdata->local;
  387. key->sdata = sdata;
  388. key->sta = sta;
  389. if (sta) {
  390. /*
  391. * some hardware cannot handle TKIP with QoS, so
  392. * we indicate whether QoS could be in use.
  393. */
  394. if (test_sta_flag(sta, WLAN_STA_WME))
  395. key->conf.flags |= IEEE80211_KEY_FLAG_WMM_STA;
  396. } else {
  397. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  398. struct sta_info *ap;
  399. /*
  400. * We're getting a sta pointer in, so must be under
  401. * appropriate locking for sta_info_get().
  402. */
  403. /* same here, the AP could be using QoS */
  404. ap = sta_info_get(key->sdata, key->sdata->u.mgd.bssid);
  405. if (ap) {
  406. if (test_sta_flag(ap, WLAN_STA_WME))
  407. key->conf.flags |=
  408. IEEE80211_KEY_FLAG_WMM_STA;
  409. }
  410. }
  411. }
  412. mutex_lock(&sdata->local->key_mtx);
  413. if (sta && pairwise)
  414. old_key = key_mtx_dereference(sdata->local, sta->ptk);
  415. else if (sta)
  416. old_key = key_mtx_dereference(sdata->local, sta->gtk[idx]);
  417. else
  418. old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
  419. increment_tailroom_need_count(sdata);
  420. __ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
  421. __ieee80211_key_destroy(old_key);
  422. ieee80211_debugfs_key_add(key);
  423. ret = ieee80211_key_enable_hw_accel(key);
  424. mutex_unlock(&sdata->local->key_mtx);
  425. return ret;
  426. }
  427. void __ieee80211_key_free(struct ieee80211_key *key)
  428. {
  429. if (!key)
  430. return;
  431. /*
  432. * Replace key with nothingness if it was ever used.
  433. */
  434. if (key->sdata)
  435. __ieee80211_key_replace(key->sdata, key->sta,
  436. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  437. key, NULL);
  438. __ieee80211_key_destroy(key);
  439. }
  440. void ieee80211_key_free(struct ieee80211_local *local,
  441. struct ieee80211_key *key)
  442. {
  443. mutex_lock(&local->key_mtx);
  444. __ieee80211_key_free(key);
  445. mutex_unlock(&local->key_mtx);
  446. }
  447. void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
  448. {
  449. struct ieee80211_key *key;
  450. ASSERT_RTNL();
  451. if (WARN_ON(!ieee80211_sdata_running(sdata)))
  452. return;
  453. mutex_lock(&sdata->local->key_mtx);
  454. sdata->crypto_tx_tailroom_needed_cnt = 0;
  455. list_for_each_entry(key, &sdata->key_list, list) {
  456. increment_tailroom_need_count(sdata);
  457. ieee80211_key_enable_hw_accel(key);
  458. }
  459. mutex_unlock(&sdata->local->key_mtx);
  460. }
  461. void ieee80211_iter_keys(struct ieee80211_hw *hw,
  462. struct ieee80211_vif *vif,
  463. void (*iter)(struct ieee80211_hw *hw,
  464. struct ieee80211_vif *vif,
  465. struct ieee80211_sta *sta,
  466. struct ieee80211_key_conf *key,
  467. void *data),
  468. void *iter_data)
  469. {
  470. struct ieee80211_local *local = hw_to_local(hw);
  471. struct ieee80211_key *key;
  472. struct ieee80211_sub_if_data *sdata;
  473. ASSERT_RTNL();
  474. mutex_lock(&local->key_mtx);
  475. if (vif) {
  476. sdata = vif_to_sdata(vif);
  477. list_for_each_entry(key, &sdata->key_list, list)
  478. iter(hw, &sdata->vif,
  479. key->sta ? &key->sta->sta : NULL,
  480. &key->conf, iter_data);
  481. } else {
  482. list_for_each_entry(sdata, &local->interfaces, list)
  483. list_for_each_entry(key, &sdata->key_list, list)
  484. iter(hw, &sdata->vif,
  485. key->sta ? &key->sta->sta : NULL,
  486. &key->conf, iter_data);
  487. }
  488. mutex_unlock(&local->key_mtx);
  489. }
  490. EXPORT_SYMBOL(ieee80211_iter_keys);
  491. void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata)
  492. {
  493. struct ieee80211_key *key;
  494. ASSERT_RTNL();
  495. mutex_lock(&sdata->local->key_mtx);
  496. list_for_each_entry(key, &sdata->key_list, list)
  497. ieee80211_key_disable_hw_accel(key);
  498. mutex_unlock(&sdata->local->key_mtx);
  499. }
  500. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata)
  501. {
  502. struct ieee80211_key *key, *tmp;
  503. mutex_lock(&sdata->local->key_mtx);
  504. ieee80211_debugfs_key_remove_mgmt_default(sdata);
  505. list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
  506. __ieee80211_key_free(key);
  507. ieee80211_debugfs_key_update_default(sdata);
  508. mutex_unlock(&sdata->local->key_mtx);
  509. }
  510. void ieee80211_gtk_rekey_notify(struct ieee80211_vif *vif, const u8 *bssid,
  511. const u8 *replay_ctr, gfp_t gfp)
  512. {
  513. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  514. trace_api_gtk_rekey_notify(sdata, bssid, replay_ctr);
  515. cfg80211_gtk_rekey_notify(sdata->dev, bssid, replay_ctr, gfp);
  516. }
  517. EXPORT_SYMBOL_GPL(ieee80211_gtk_rekey_notify);
  518. void ieee80211_get_key_tx_seq(struct ieee80211_key_conf *keyconf,
  519. struct ieee80211_key_seq *seq)
  520. {
  521. struct ieee80211_key *key;
  522. u64 pn64;
  523. if (WARN_ON(!(keyconf->flags & IEEE80211_KEY_FLAG_GENERATE_IV)))
  524. return;
  525. key = container_of(keyconf, struct ieee80211_key, conf);
  526. switch (key->conf.cipher) {
  527. case WLAN_CIPHER_SUITE_TKIP:
  528. seq->tkip.iv32 = key->u.tkip.tx.iv32;
  529. seq->tkip.iv16 = key->u.tkip.tx.iv16;
  530. break;
  531. case WLAN_CIPHER_SUITE_CCMP:
  532. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  533. seq->ccmp.pn[5] = pn64;
  534. seq->ccmp.pn[4] = pn64 >> 8;
  535. seq->ccmp.pn[3] = pn64 >> 16;
  536. seq->ccmp.pn[2] = pn64 >> 24;
  537. seq->ccmp.pn[1] = pn64 >> 32;
  538. seq->ccmp.pn[0] = pn64 >> 40;
  539. break;
  540. case WLAN_CIPHER_SUITE_AES_CMAC:
  541. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  542. seq->ccmp.pn[5] = pn64;
  543. seq->ccmp.pn[4] = pn64 >> 8;
  544. seq->ccmp.pn[3] = pn64 >> 16;
  545. seq->ccmp.pn[2] = pn64 >> 24;
  546. seq->ccmp.pn[1] = pn64 >> 32;
  547. seq->ccmp.pn[0] = pn64 >> 40;
  548. break;
  549. default:
  550. WARN_ON(1);
  551. }
  552. }
  553. EXPORT_SYMBOL(ieee80211_get_key_tx_seq);
  554. void ieee80211_get_key_rx_seq(struct ieee80211_key_conf *keyconf,
  555. int tid, struct ieee80211_key_seq *seq)
  556. {
  557. struct ieee80211_key *key;
  558. const u8 *pn;
  559. key = container_of(keyconf, struct ieee80211_key, conf);
  560. switch (key->conf.cipher) {
  561. case WLAN_CIPHER_SUITE_TKIP:
  562. if (WARN_ON(tid < 0 || tid >= NUM_RX_DATA_QUEUES))
  563. return;
  564. seq->tkip.iv32 = key->u.tkip.rx[tid].iv32;
  565. seq->tkip.iv16 = key->u.tkip.rx[tid].iv16;
  566. break;
  567. case WLAN_CIPHER_SUITE_CCMP:
  568. if (WARN_ON(tid < -1 || tid >= NUM_RX_DATA_QUEUES))
  569. return;
  570. if (tid < 0)
  571. pn = key->u.ccmp.rx_pn[NUM_RX_DATA_QUEUES];
  572. else
  573. pn = key->u.ccmp.rx_pn[tid];
  574. memcpy(seq->ccmp.pn, pn, CCMP_PN_LEN);
  575. break;
  576. case WLAN_CIPHER_SUITE_AES_CMAC:
  577. if (WARN_ON(tid != 0))
  578. return;
  579. pn = key->u.aes_cmac.rx_pn;
  580. memcpy(seq->aes_cmac.pn, pn, CMAC_PN_LEN);
  581. break;
  582. }
  583. }
  584. EXPORT_SYMBOL(ieee80211_get_key_rx_seq);