key.c 18 KB

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