key.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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. * Copyright 2013-2014 Intel Mobile Communications GmbH
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/if_ether.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/list.h>
  15. #include <linux/rcupdate.h>
  16. #include <linux/rtnetlink.h>
  17. #include <linux/slab.h>
  18. #include <linux/export.h>
  19. #include <net/mac80211.h>
  20. #include <asm/unaligned.h>
  21. #include "ieee80211_i.h"
  22. #include "driver-ops.h"
  23. #include "debugfs_key.h"
  24. #include "aes_ccm.h"
  25. #include "aes_cmac.h"
  26. #include "aes_gmac.h"
  27. #include "aes_gcm.h"
  28. /**
  29. * DOC: Key handling basics
  30. *
  31. * Key handling in mac80211 is done based on per-interface (sub_if_data)
  32. * keys and per-station keys. Since each station belongs to an interface,
  33. * each station key also belongs to that interface.
  34. *
  35. * Hardware acceleration is done on a best-effort basis for algorithms
  36. * that are implemented in software, for each key the hardware is asked
  37. * to enable that key for offloading but if it cannot do that the key is
  38. * simply kept for software encryption (unless it is for an algorithm
  39. * that isn't implemented in software).
  40. * There is currently no way of knowing whether a key is handled in SW
  41. * or HW except by looking into debugfs.
  42. *
  43. * All key management is internally protected by a mutex. Within all
  44. * other parts of mac80211, key references are, just as STA structure
  45. * references, protected by RCU. Note, however, that some things are
  46. * unprotected, namely the key->sta dereferences within the hardware
  47. * acceleration functions. This means that sta_info_destroy() must
  48. * remove the key which waits for an RCU grace period.
  49. */
  50. static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  51. static void assert_key_lock(struct ieee80211_local *local)
  52. {
  53. lockdep_assert_held(&local->key_mtx);
  54. }
  55. static void increment_tailroom_need_count(struct ieee80211_sub_if_data *sdata)
  56. {
  57. /*
  58. * When this count is zero, SKB resizing for allocating tailroom
  59. * for IV or MMIC is skipped. But, this check has created two race
  60. * cases in xmit path while transiting from zero count to one:
  61. *
  62. * 1. SKB resize was skipped because no key was added but just before
  63. * the xmit key is added and SW encryption kicks off.
  64. *
  65. * 2. SKB resize was skipped because all the keys were hw planted but
  66. * just before xmit one of the key is deleted and SW encryption kicks
  67. * off.
  68. *
  69. * In both the above case SW encryption will find not enough space for
  70. * tailroom and exits with WARN_ON. (See WARN_ONs at wpa.c)
  71. *
  72. * Solution has been explained at
  73. * http://mid.gmane.org/1308590980.4322.19.camel@jlt3.sipsolutions.net
  74. */
  75. if (!sdata->crypto_tx_tailroom_needed_cnt++) {
  76. /*
  77. * Flush all XMIT packets currently using HW encryption or no
  78. * encryption at all if the count transition is from 0 -> 1.
  79. */
  80. synchronize_net();
  81. }
  82. }
  83. static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
  84. {
  85. struct ieee80211_sub_if_data *sdata;
  86. struct sta_info *sta;
  87. int ret = -EOPNOTSUPP;
  88. might_sleep();
  89. if (key->flags & KEY_FLAG_TAINTED) {
  90. /* If we get here, it's during resume and the key is
  91. * tainted so shouldn't be used/programmed any more.
  92. * However, its flags may still indicate that it was
  93. * programmed into the device (since we're in resume)
  94. * so clear that flag now to avoid trying to remove
  95. * it again later.
  96. */
  97. key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
  98. return -EINVAL;
  99. }
  100. if (!key->local->ops->set_key)
  101. goto out_unsupported;
  102. assert_key_lock(key->local);
  103. sta = key->sta;
  104. /*
  105. * If this is a per-STA GTK, check if it
  106. * is supported; if not, return.
  107. */
  108. if (sta && !(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE) &&
  109. !(key->local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK))
  110. goto out_unsupported;
  111. if (sta && !sta->uploaded)
  112. goto out_unsupported;
  113. sdata = key->sdata;
  114. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  115. /*
  116. * The driver doesn't know anything about VLAN interfaces.
  117. * Hence, don't send GTKs for VLAN interfaces to the driver.
  118. */
  119. if (!(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE))
  120. goto out_unsupported;
  121. }
  122. ret = drv_set_key(key->local, SET_KEY, sdata,
  123. sta ? &sta->sta : NULL, &key->conf);
  124. if (!ret) {
  125. key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
  126. if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
  127. (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
  128. sdata->crypto_tx_tailroom_needed_cnt--;
  129. WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) &&
  130. (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV));
  131. return 0;
  132. }
  133. if (ret != -ENOSPC && ret != -EOPNOTSUPP && ret != 1)
  134. sdata_err(sdata,
  135. "failed to set key (%d, %pM) to hardware (%d)\n",
  136. key->conf.keyidx,
  137. sta ? sta->sta.addr : bcast_addr, ret);
  138. out_unsupported:
  139. switch (key->conf.cipher) {
  140. case WLAN_CIPHER_SUITE_WEP40:
  141. case WLAN_CIPHER_SUITE_WEP104:
  142. case WLAN_CIPHER_SUITE_TKIP:
  143. case WLAN_CIPHER_SUITE_CCMP:
  144. case WLAN_CIPHER_SUITE_CCMP_256:
  145. case WLAN_CIPHER_SUITE_AES_CMAC:
  146. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  147. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  148. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  149. case WLAN_CIPHER_SUITE_GCMP:
  150. case WLAN_CIPHER_SUITE_GCMP_256:
  151. /* all of these we can do in software - if driver can */
  152. if (ret == 1)
  153. return 0;
  154. if (key->local->hw.flags & IEEE80211_HW_SW_CRYPTO_CONTROL)
  155. return -EINVAL;
  156. return 0;
  157. default:
  158. return -EINVAL;
  159. }
  160. }
  161. static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
  162. {
  163. struct ieee80211_sub_if_data *sdata;
  164. struct sta_info *sta;
  165. int ret;
  166. might_sleep();
  167. if (!key || !key->local->ops->set_key)
  168. return;
  169. assert_key_lock(key->local);
  170. if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  171. return;
  172. sta = key->sta;
  173. sdata = key->sdata;
  174. if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
  175. (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
  176. increment_tailroom_need_count(sdata);
  177. ret = drv_set_key(key->local, DISABLE_KEY, sdata,
  178. sta ? &sta->sta : NULL, &key->conf);
  179. if (ret)
  180. sdata_err(sdata,
  181. "failed to remove key (%d, %pM) from hardware (%d)\n",
  182. key->conf.keyidx,
  183. sta ? sta->sta.addr : bcast_addr, ret);
  184. key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
  185. }
  186. static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
  187. int idx, bool uni, bool multi)
  188. {
  189. struct ieee80211_key *key = NULL;
  190. assert_key_lock(sdata->local);
  191. if (idx >= 0 && idx < NUM_DEFAULT_KEYS)
  192. key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
  193. if (uni) {
  194. rcu_assign_pointer(sdata->default_unicast_key, key);
  195. drv_set_default_unicast_key(sdata->local, sdata, idx);
  196. }
  197. if (multi)
  198. rcu_assign_pointer(sdata->default_multicast_key, key);
  199. ieee80211_debugfs_key_update_default(sdata);
  200. }
  201. void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx,
  202. bool uni, bool multi)
  203. {
  204. mutex_lock(&sdata->local->key_mtx);
  205. __ieee80211_set_default_key(sdata, idx, uni, multi);
  206. mutex_unlock(&sdata->local->key_mtx);
  207. }
  208. static void
  209. __ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata, int idx)
  210. {
  211. struct ieee80211_key *key = NULL;
  212. assert_key_lock(sdata->local);
  213. if (idx >= NUM_DEFAULT_KEYS &&
  214. idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  215. key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
  216. rcu_assign_pointer(sdata->default_mgmt_key, key);
  217. ieee80211_debugfs_key_update_default(sdata);
  218. }
  219. void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
  220. int idx)
  221. {
  222. mutex_lock(&sdata->local->key_mtx);
  223. __ieee80211_set_default_mgmt_key(sdata, idx);
  224. mutex_unlock(&sdata->local->key_mtx);
  225. }
  226. static void ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
  227. struct sta_info *sta,
  228. bool pairwise,
  229. struct ieee80211_key *old,
  230. struct ieee80211_key *new)
  231. {
  232. int idx;
  233. bool defunikey, defmultikey, defmgmtkey;
  234. /* caller must provide at least one old/new */
  235. if (WARN_ON(!new && !old))
  236. return;
  237. if (new)
  238. list_add_tail(&new->list, &sdata->key_list);
  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. if (sta) {
  245. if (pairwise) {
  246. rcu_assign_pointer(sta->ptk[idx], new);
  247. sta->ptk_idx = idx;
  248. } else {
  249. rcu_assign_pointer(sta->gtk[idx], new);
  250. sta->gtk_idx = idx;
  251. }
  252. } else {
  253. defunikey = old &&
  254. old == key_mtx_dereference(sdata->local,
  255. sdata->default_unicast_key);
  256. defmultikey = old &&
  257. old == key_mtx_dereference(sdata->local,
  258. sdata->default_multicast_key);
  259. defmgmtkey = old &&
  260. old == key_mtx_dereference(sdata->local,
  261. sdata->default_mgmt_key);
  262. if (defunikey && !new)
  263. __ieee80211_set_default_key(sdata, -1, true, false);
  264. if (defmultikey && !new)
  265. __ieee80211_set_default_key(sdata, -1, false, true);
  266. if (defmgmtkey && !new)
  267. __ieee80211_set_default_mgmt_key(sdata, -1);
  268. rcu_assign_pointer(sdata->keys[idx], new);
  269. if (defunikey && new)
  270. __ieee80211_set_default_key(sdata, new->conf.keyidx,
  271. true, false);
  272. if (defmultikey && new)
  273. __ieee80211_set_default_key(sdata, new->conf.keyidx,
  274. false, true);
  275. if (defmgmtkey && new)
  276. __ieee80211_set_default_mgmt_key(sdata,
  277. new->conf.keyidx);
  278. }
  279. if (old)
  280. list_del(&old->list);
  281. }
  282. struct ieee80211_key *
  283. ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
  284. const u8 *key_data,
  285. size_t seq_len, const u8 *seq,
  286. const struct ieee80211_cipher_scheme *cs)
  287. {
  288. struct ieee80211_key *key;
  289. int i, j, err;
  290. if (WARN_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS))
  291. return ERR_PTR(-EINVAL);
  292. key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL);
  293. if (!key)
  294. return ERR_PTR(-ENOMEM);
  295. /*
  296. * Default to software encryption; we'll later upload the
  297. * key to the hardware if possible.
  298. */
  299. key->conf.flags = 0;
  300. key->flags = 0;
  301. key->conf.cipher = cipher;
  302. key->conf.keyidx = idx;
  303. key->conf.keylen = key_len;
  304. switch (cipher) {
  305. case WLAN_CIPHER_SUITE_WEP40:
  306. case WLAN_CIPHER_SUITE_WEP104:
  307. key->conf.iv_len = IEEE80211_WEP_IV_LEN;
  308. key->conf.icv_len = IEEE80211_WEP_ICV_LEN;
  309. break;
  310. case WLAN_CIPHER_SUITE_TKIP:
  311. key->conf.iv_len = IEEE80211_TKIP_IV_LEN;
  312. key->conf.icv_len = IEEE80211_TKIP_ICV_LEN;
  313. if (seq) {
  314. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  315. key->u.tkip.rx[i].iv32 =
  316. get_unaligned_le32(&seq[2]);
  317. key->u.tkip.rx[i].iv16 =
  318. get_unaligned_le16(seq);
  319. }
  320. }
  321. spin_lock_init(&key->u.tkip.txlock);
  322. break;
  323. case WLAN_CIPHER_SUITE_CCMP:
  324. key->conf.iv_len = IEEE80211_CCMP_HDR_LEN;
  325. key->conf.icv_len = IEEE80211_CCMP_MIC_LEN;
  326. if (seq) {
  327. for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++)
  328. for (j = 0; j < IEEE80211_CCMP_PN_LEN; j++)
  329. key->u.ccmp.rx_pn[i][j] =
  330. seq[IEEE80211_CCMP_PN_LEN - j - 1];
  331. }
  332. /*
  333. * Initialize AES key state here as an optimization so that
  334. * it does not need to be initialized for every packet.
  335. */
  336. key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(
  337. key_data, key_len, IEEE80211_CCMP_MIC_LEN);
  338. if (IS_ERR(key->u.ccmp.tfm)) {
  339. err = PTR_ERR(key->u.ccmp.tfm);
  340. kfree(key);
  341. return ERR_PTR(err);
  342. }
  343. break;
  344. case WLAN_CIPHER_SUITE_CCMP_256:
  345. key->conf.iv_len = IEEE80211_CCMP_256_HDR_LEN;
  346. key->conf.icv_len = IEEE80211_CCMP_256_MIC_LEN;
  347. for (i = 0; seq && i < IEEE80211_NUM_TIDS + 1; i++)
  348. for (j = 0; j < IEEE80211_CCMP_256_PN_LEN; j++)
  349. key->u.ccmp.rx_pn[i][j] =
  350. seq[IEEE80211_CCMP_256_PN_LEN - j - 1];
  351. /* Initialize AES key state here as an optimization so that
  352. * it does not need to be initialized for every packet.
  353. */
  354. key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(
  355. key_data, key_len, IEEE80211_CCMP_256_MIC_LEN);
  356. if (IS_ERR(key->u.ccmp.tfm)) {
  357. err = PTR_ERR(key->u.ccmp.tfm);
  358. kfree(key);
  359. return ERR_PTR(err);
  360. }
  361. break;
  362. case WLAN_CIPHER_SUITE_AES_CMAC:
  363. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  364. key->conf.iv_len = 0;
  365. if (cipher == WLAN_CIPHER_SUITE_AES_CMAC)
  366. key->conf.icv_len = sizeof(struct ieee80211_mmie);
  367. else
  368. key->conf.icv_len = sizeof(struct ieee80211_mmie_16);
  369. if (seq)
  370. for (j = 0; j < IEEE80211_CMAC_PN_LEN; j++)
  371. key->u.aes_cmac.rx_pn[j] =
  372. seq[IEEE80211_CMAC_PN_LEN - j - 1];
  373. /*
  374. * Initialize AES key state here as an optimization so that
  375. * it does not need to be initialized for every packet.
  376. */
  377. key->u.aes_cmac.tfm =
  378. ieee80211_aes_cmac_key_setup(key_data, key_len);
  379. if (IS_ERR(key->u.aes_cmac.tfm)) {
  380. err = PTR_ERR(key->u.aes_cmac.tfm);
  381. kfree(key);
  382. return ERR_PTR(err);
  383. }
  384. break;
  385. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  386. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  387. key->conf.iv_len = 0;
  388. key->conf.icv_len = sizeof(struct ieee80211_mmie_16);
  389. if (seq)
  390. for (j = 0; j < IEEE80211_GMAC_PN_LEN; j++)
  391. key->u.aes_gmac.rx_pn[j] =
  392. seq[IEEE80211_GMAC_PN_LEN - j - 1];
  393. /* Initialize AES key state here as an optimization so that
  394. * it does not need to be initialized for every packet.
  395. */
  396. key->u.aes_gmac.tfm =
  397. ieee80211_aes_gmac_key_setup(key_data, key_len);
  398. if (IS_ERR(key->u.aes_gmac.tfm)) {
  399. err = PTR_ERR(key->u.aes_gmac.tfm);
  400. kfree(key);
  401. return ERR_PTR(err);
  402. }
  403. break;
  404. case WLAN_CIPHER_SUITE_GCMP:
  405. case WLAN_CIPHER_SUITE_GCMP_256:
  406. key->conf.iv_len = IEEE80211_GCMP_HDR_LEN;
  407. key->conf.icv_len = IEEE80211_GCMP_MIC_LEN;
  408. for (i = 0; seq && i < IEEE80211_NUM_TIDS + 1; i++)
  409. for (j = 0; j < IEEE80211_GCMP_PN_LEN; j++)
  410. key->u.gcmp.rx_pn[i][j] =
  411. seq[IEEE80211_GCMP_PN_LEN - j - 1];
  412. /* Initialize AES key state here as an optimization so that
  413. * it does not need to be initialized for every packet.
  414. */
  415. key->u.gcmp.tfm = ieee80211_aes_gcm_key_setup_encrypt(key_data,
  416. key_len);
  417. if (IS_ERR(key->u.gcmp.tfm)) {
  418. err = PTR_ERR(key->u.gcmp.tfm);
  419. kfree(key);
  420. return ERR_PTR(err);
  421. }
  422. break;
  423. default:
  424. if (cs) {
  425. size_t len = (seq_len > MAX_PN_LEN) ?
  426. MAX_PN_LEN : seq_len;
  427. key->conf.iv_len = cs->hdr_len;
  428. key->conf.icv_len = cs->mic_len;
  429. for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++)
  430. for (j = 0; j < len; j++)
  431. key->u.gen.rx_pn[i][j] =
  432. seq[len - j - 1];
  433. key->flags |= KEY_FLAG_CIPHER_SCHEME;
  434. }
  435. }
  436. memcpy(key->conf.key, key_data, key_len);
  437. INIT_LIST_HEAD(&key->list);
  438. return key;
  439. }
  440. static void ieee80211_key_free_common(struct ieee80211_key *key)
  441. {
  442. switch (key->conf.cipher) {
  443. case WLAN_CIPHER_SUITE_CCMP:
  444. case WLAN_CIPHER_SUITE_CCMP_256:
  445. ieee80211_aes_key_free(key->u.ccmp.tfm);
  446. break;
  447. case WLAN_CIPHER_SUITE_AES_CMAC:
  448. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  449. ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm);
  450. break;
  451. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  452. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  453. ieee80211_aes_gmac_key_free(key->u.aes_gmac.tfm);
  454. break;
  455. case WLAN_CIPHER_SUITE_GCMP:
  456. case WLAN_CIPHER_SUITE_GCMP_256:
  457. ieee80211_aes_gcm_key_free(key->u.gcmp.tfm);
  458. break;
  459. }
  460. kzfree(key);
  461. }
  462. static void __ieee80211_key_destroy(struct ieee80211_key *key,
  463. bool delay_tailroom)
  464. {
  465. if (key->local)
  466. ieee80211_key_disable_hw_accel(key);
  467. if (key->local) {
  468. struct ieee80211_sub_if_data *sdata = key->sdata;
  469. ieee80211_debugfs_key_remove(key);
  470. if (delay_tailroom) {
  471. /* see ieee80211_delayed_tailroom_dec */
  472. sdata->crypto_tx_tailroom_pending_dec++;
  473. schedule_delayed_work(&sdata->dec_tailroom_needed_wk,
  474. HZ/2);
  475. } else {
  476. sdata->crypto_tx_tailroom_needed_cnt--;
  477. }
  478. }
  479. ieee80211_key_free_common(key);
  480. }
  481. static void ieee80211_key_destroy(struct ieee80211_key *key,
  482. bool delay_tailroom)
  483. {
  484. if (!key)
  485. return;
  486. /*
  487. * Synchronize so the TX path can no longer be using
  488. * this key before we free/remove it.
  489. */
  490. synchronize_net();
  491. __ieee80211_key_destroy(key, delay_tailroom);
  492. }
  493. void ieee80211_key_free_unused(struct ieee80211_key *key)
  494. {
  495. WARN_ON(key->sdata || key->local);
  496. ieee80211_key_free_common(key);
  497. }
  498. int ieee80211_key_link(struct ieee80211_key *key,
  499. struct ieee80211_sub_if_data *sdata,
  500. struct sta_info *sta)
  501. {
  502. struct ieee80211_local *local = sdata->local;
  503. struct ieee80211_key *old_key;
  504. int idx, ret;
  505. bool pairwise;
  506. pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
  507. idx = key->conf.keyidx;
  508. key->local = sdata->local;
  509. key->sdata = sdata;
  510. key->sta = sta;
  511. mutex_lock(&sdata->local->key_mtx);
  512. if (sta && pairwise)
  513. old_key = key_mtx_dereference(sdata->local, sta->ptk[idx]);
  514. else if (sta)
  515. old_key = key_mtx_dereference(sdata->local, sta->gtk[idx]);
  516. else
  517. old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
  518. increment_tailroom_need_count(sdata);
  519. ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
  520. ieee80211_key_destroy(old_key, true);
  521. ieee80211_debugfs_key_add(key);
  522. if (!local->wowlan) {
  523. ret = ieee80211_key_enable_hw_accel(key);
  524. if (ret)
  525. ieee80211_key_free(key, true);
  526. } else {
  527. ret = 0;
  528. }
  529. mutex_unlock(&sdata->local->key_mtx);
  530. return ret;
  531. }
  532. void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom)
  533. {
  534. if (!key)
  535. return;
  536. /*
  537. * Replace key with nothingness if it was ever used.
  538. */
  539. if (key->sdata)
  540. ieee80211_key_replace(key->sdata, key->sta,
  541. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  542. key, NULL);
  543. ieee80211_key_destroy(key, delay_tailroom);
  544. }
  545. void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
  546. {
  547. struct ieee80211_key *key;
  548. ASSERT_RTNL();
  549. if (WARN_ON(!ieee80211_sdata_running(sdata)))
  550. return;
  551. mutex_lock(&sdata->local->key_mtx);
  552. sdata->crypto_tx_tailroom_needed_cnt = 0;
  553. list_for_each_entry(key, &sdata->key_list, list) {
  554. increment_tailroom_need_count(sdata);
  555. ieee80211_key_enable_hw_accel(key);
  556. }
  557. mutex_unlock(&sdata->local->key_mtx);
  558. }
  559. void ieee80211_iter_keys(struct ieee80211_hw *hw,
  560. struct ieee80211_vif *vif,
  561. void (*iter)(struct ieee80211_hw *hw,
  562. struct ieee80211_vif *vif,
  563. struct ieee80211_sta *sta,
  564. struct ieee80211_key_conf *key,
  565. void *data),
  566. void *iter_data)
  567. {
  568. struct ieee80211_local *local = hw_to_local(hw);
  569. struct ieee80211_key *key, *tmp;
  570. struct ieee80211_sub_if_data *sdata;
  571. ASSERT_RTNL();
  572. mutex_lock(&local->key_mtx);
  573. if (vif) {
  574. sdata = vif_to_sdata(vif);
  575. list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
  576. iter(hw, &sdata->vif,
  577. key->sta ? &key->sta->sta : NULL,
  578. &key->conf, iter_data);
  579. } else {
  580. list_for_each_entry(sdata, &local->interfaces, list)
  581. list_for_each_entry_safe(key, tmp,
  582. &sdata->key_list, list)
  583. iter(hw, &sdata->vif,
  584. key->sta ? &key->sta->sta : NULL,
  585. &key->conf, iter_data);
  586. }
  587. mutex_unlock(&local->key_mtx);
  588. }
  589. EXPORT_SYMBOL(ieee80211_iter_keys);
  590. static void ieee80211_free_keys_iface(struct ieee80211_sub_if_data *sdata,
  591. struct list_head *keys)
  592. {
  593. struct ieee80211_key *key, *tmp;
  594. sdata->crypto_tx_tailroom_needed_cnt -=
  595. sdata->crypto_tx_tailroom_pending_dec;
  596. sdata->crypto_tx_tailroom_pending_dec = 0;
  597. ieee80211_debugfs_key_remove_mgmt_default(sdata);
  598. list_for_each_entry_safe(key, tmp, &sdata->key_list, list) {
  599. ieee80211_key_replace(key->sdata, key->sta,
  600. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  601. key, NULL);
  602. list_add_tail(&key->list, keys);
  603. }
  604. ieee80211_debugfs_key_update_default(sdata);
  605. }
  606. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
  607. bool force_synchronize)
  608. {
  609. struct ieee80211_local *local = sdata->local;
  610. struct ieee80211_sub_if_data *vlan;
  611. struct ieee80211_key *key, *tmp;
  612. LIST_HEAD(keys);
  613. cancel_delayed_work_sync(&sdata->dec_tailroom_needed_wk);
  614. mutex_lock(&local->key_mtx);
  615. ieee80211_free_keys_iface(sdata, &keys);
  616. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  617. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  618. ieee80211_free_keys_iface(vlan, &keys);
  619. }
  620. if (!list_empty(&keys) || force_synchronize)
  621. synchronize_net();
  622. list_for_each_entry_safe(key, tmp, &keys, list)
  623. __ieee80211_key_destroy(key, false);
  624. WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt ||
  625. sdata->crypto_tx_tailroom_pending_dec);
  626. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  627. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  628. WARN_ON_ONCE(vlan->crypto_tx_tailroom_needed_cnt ||
  629. vlan->crypto_tx_tailroom_pending_dec);
  630. }
  631. mutex_unlock(&local->key_mtx);
  632. }
  633. void ieee80211_free_sta_keys(struct ieee80211_local *local,
  634. struct sta_info *sta)
  635. {
  636. struct ieee80211_key *key;
  637. int i;
  638. mutex_lock(&local->key_mtx);
  639. for (i = 0; i < ARRAY_SIZE(sta->gtk); i++) {
  640. key = key_mtx_dereference(local, sta->gtk[i]);
  641. if (!key)
  642. continue;
  643. ieee80211_key_replace(key->sdata, key->sta,
  644. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  645. key, NULL);
  646. __ieee80211_key_destroy(key, true);
  647. }
  648. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  649. key = key_mtx_dereference(local, sta->ptk[i]);
  650. if (!key)
  651. continue;
  652. ieee80211_key_replace(key->sdata, key->sta,
  653. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  654. key, NULL);
  655. __ieee80211_key_destroy(key, true);
  656. }
  657. mutex_unlock(&local->key_mtx);
  658. }
  659. void ieee80211_delayed_tailroom_dec(struct work_struct *wk)
  660. {
  661. struct ieee80211_sub_if_data *sdata;
  662. sdata = container_of(wk, struct ieee80211_sub_if_data,
  663. dec_tailroom_needed_wk.work);
  664. /*
  665. * The reason for the delayed tailroom needed decrementing is to
  666. * make roaming faster: during roaming, all keys are first deleted
  667. * and then new keys are installed. The first new key causes the
  668. * crypto_tx_tailroom_needed_cnt to go from 0 to 1, which invokes
  669. * the cost of synchronize_net() (which can be slow). Avoid this
  670. * by deferring the crypto_tx_tailroom_needed_cnt decrementing on
  671. * key removal for a while, so if we roam the value is larger than
  672. * zero and no 0->1 transition happens.
  673. *
  674. * The cost is that if the AP switching was from an AP with keys
  675. * to one without, we still allocate tailroom while it would no
  676. * longer be needed. However, in the typical (fast) roaming case
  677. * within an ESS this usually won't happen.
  678. */
  679. mutex_lock(&sdata->local->key_mtx);
  680. sdata->crypto_tx_tailroom_needed_cnt -=
  681. sdata->crypto_tx_tailroom_pending_dec;
  682. sdata->crypto_tx_tailroom_pending_dec = 0;
  683. mutex_unlock(&sdata->local->key_mtx);
  684. }
  685. void ieee80211_gtk_rekey_notify(struct ieee80211_vif *vif, const u8 *bssid,
  686. const u8 *replay_ctr, gfp_t gfp)
  687. {
  688. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  689. trace_api_gtk_rekey_notify(sdata, bssid, replay_ctr);
  690. cfg80211_gtk_rekey_notify(sdata->dev, bssid, replay_ctr, gfp);
  691. }
  692. EXPORT_SYMBOL_GPL(ieee80211_gtk_rekey_notify);
  693. void ieee80211_get_key_tx_seq(struct ieee80211_key_conf *keyconf,
  694. struct ieee80211_key_seq *seq)
  695. {
  696. struct ieee80211_key *key;
  697. u64 pn64;
  698. if (WARN_ON(!(keyconf->flags & IEEE80211_KEY_FLAG_GENERATE_IV)))
  699. return;
  700. key = container_of(keyconf, struct ieee80211_key, conf);
  701. switch (key->conf.cipher) {
  702. case WLAN_CIPHER_SUITE_TKIP:
  703. seq->tkip.iv32 = key->u.tkip.tx.iv32;
  704. seq->tkip.iv16 = key->u.tkip.tx.iv16;
  705. break;
  706. case WLAN_CIPHER_SUITE_CCMP:
  707. case WLAN_CIPHER_SUITE_CCMP_256:
  708. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  709. seq->ccmp.pn[5] = pn64;
  710. seq->ccmp.pn[4] = pn64 >> 8;
  711. seq->ccmp.pn[3] = pn64 >> 16;
  712. seq->ccmp.pn[2] = pn64 >> 24;
  713. seq->ccmp.pn[1] = pn64 >> 32;
  714. seq->ccmp.pn[0] = pn64 >> 40;
  715. break;
  716. case WLAN_CIPHER_SUITE_AES_CMAC:
  717. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  718. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  719. seq->ccmp.pn[5] = pn64;
  720. seq->ccmp.pn[4] = pn64 >> 8;
  721. seq->ccmp.pn[3] = pn64 >> 16;
  722. seq->ccmp.pn[2] = pn64 >> 24;
  723. seq->ccmp.pn[1] = pn64 >> 32;
  724. seq->ccmp.pn[0] = pn64 >> 40;
  725. break;
  726. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  727. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  728. pn64 = atomic64_read(&key->u.aes_gmac.tx_pn);
  729. seq->ccmp.pn[5] = pn64;
  730. seq->ccmp.pn[4] = pn64 >> 8;
  731. seq->ccmp.pn[3] = pn64 >> 16;
  732. seq->ccmp.pn[2] = pn64 >> 24;
  733. seq->ccmp.pn[1] = pn64 >> 32;
  734. seq->ccmp.pn[0] = pn64 >> 40;
  735. break;
  736. case WLAN_CIPHER_SUITE_GCMP:
  737. case WLAN_CIPHER_SUITE_GCMP_256:
  738. pn64 = atomic64_read(&key->u.gcmp.tx_pn);
  739. seq->gcmp.pn[5] = pn64;
  740. seq->gcmp.pn[4] = pn64 >> 8;
  741. seq->gcmp.pn[3] = pn64 >> 16;
  742. seq->gcmp.pn[2] = pn64 >> 24;
  743. seq->gcmp.pn[1] = pn64 >> 32;
  744. seq->gcmp.pn[0] = pn64 >> 40;
  745. break;
  746. default:
  747. WARN_ON(1);
  748. }
  749. }
  750. EXPORT_SYMBOL(ieee80211_get_key_tx_seq);
  751. void ieee80211_get_key_rx_seq(struct ieee80211_key_conf *keyconf,
  752. int tid, struct ieee80211_key_seq *seq)
  753. {
  754. struct ieee80211_key *key;
  755. const u8 *pn;
  756. key = container_of(keyconf, struct ieee80211_key, conf);
  757. switch (key->conf.cipher) {
  758. case WLAN_CIPHER_SUITE_TKIP:
  759. if (WARN_ON(tid < 0 || tid >= IEEE80211_NUM_TIDS))
  760. return;
  761. seq->tkip.iv32 = key->u.tkip.rx[tid].iv32;
  762. seq->tkip.iv16 = key->u.tkip.rx[tid].iv16;
  763. break;
  764. case WLAN_CIPHER_SUITE_CCMP:
  765. case WLAN_CIPHER_SUITE_CCMP_256:
  766. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  767. return;
  768. if (tid < 0)
  769. pn = key->u.ccmp.rx_pn[IEEE80211_NUM_TIDS];
  770. else
  771. pn = key->u.ccmp.rx_pn[tid];
  772. memcpy(seq->ccmp.pn, pn, IEEE80211_CCMP_PN_LEN);
  773. break;
  774. case WLAN_CIPHER_SUITE_AES_CMAC:
  775. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  776. if (WARN_ON(tid != 0))
  777. return;
  778. pn = key->u.aes_cmac.rx_pn;
  779. memcpy(seq->aes_cmac.pn, pn, IEEE80211_CMAC_PN_LEN);
  780. break;
  781. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  782. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  783. if (WARN_ON(tid != 0))
  784. return;
  785. pn = key->u.aes_gmac.rx_pn;
  786. memcpy(seq->aes_gmac.pn, pn, IEEE80211_GMAC_PN_LEN);
  787. break;
  788. case WLAN_CIPHER_SUITE_GCMP:
  789. case WLAN_CIPHER_SUITE_GCMP_256:
  790. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  791. return;
  792. if (tid < 0)
  793. pn = key->u.gcmp.rx_pn[IEEE80211_NUM_TIDS];
  794. else
  795. pn = key->u.gcmp.rx_pn[tid];
  796. memcpy(seq->gcmp.pn, pn, IEEE80211_GCMP_PN_LEN);
  797. break;
  798. }
  799. }
  800. EXPORT_SYMBOL(ieee80211_get_key_rx_seq);
  801. void ieee80211_set_key_tx_seq(struct ieee80211_key_conf *keyconf,
  802. struct ieee80211_key_seq *seq)
  803. {
  804. struct ieee80211_key *key;
  805. u64 pn64;
  806. key = container_of(keyconf, struct ieee80211_key, conf);
  807. switch (key->conf.cipher) {
  808. case WLAN_CIPHER_SUITE_TKIP:
  809. key->u.tkip.tx.iv32 = seq->tkip.iv32;
  810. key->u.tkip.tx.iv16 = seq->tkip.iv16;
  811. break;
  812. case WLAN_CIPHER_SUITE_CCMP:
  813. case WLAN_CIPHER_SUITE_CCMP_256:
  814. pn64 = (u64)seq->ccmp.pn[5] |
  815. ((u64)seq->ccmp.pn[4] << 8) |
  816. ((u64)seq->ccmp.pn[3] << 16) |
  817. ((u64)seq->ccmp.pn[2] << 24) |
  818. ((u64)seq->ccmp.pn[1] << 32) |
  819. ((u64)seq->ccmp.pn[0] << 40);
  820. atomic64_set(&key->u.ccmp.tx_pn, pn64);
  821. break;
  822. case WLAN_CIPHER_SUITE_AES_CMAC:
  823. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  824. pn64 = (u64)seq->aes_cmac.pn[5] |
  825. ((u64)seq->aes_cmac.pn[4] << 8) |
  826. ((u64)seq->aes_cmac.pn[3] << 16) |
  827. ((u64)seq->aes_cmac.pn[2] << 24) |
  828. ((u64)seq->aes_cmac.pn[1] << 32) |
  829. ((u64)seq->aes_cmac.pn[0] << 40);
  830. atomic64_set(&key->u.aes_cmac.tx_pn, pn64);
  831. break;
  832. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  833. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  834. pn64 = (u64)seq->aes_gmac.pn[5] |
  835. ((u64)seq->aes_gmac.pn[4] << 8) |
  836. ((u64)seq->aes_gmac.pn[3] << 16) |
  837. ((u64)seq->aes_gmac.pn[2] << 24) |
  838. ((u64)seq->aes_gmac.pn[1] << 32) |
  839. ((u64)seq->aes_gmac.pn[0] << 40);
  840. atomic64_set(&key->u.aes_gmac.tx_pn, pn64);
  841. break;
  842. case WLAN_CIPHER_SUITE_GCMP:
  843. case WLAN_CIPHER_SUITE_GCMP_256:
  844. pn64 = (u64)seq->gcmp.pn[5] |
  845. ((u64)seq->gcmp.pn[4] << 8) |
  846. ((u64)seq->gcmp.pn[3] << 16) |
  847. ((u64)seq->gcmp.pn[2] << 24) |
  848. ((u64)seq->gcmp.pn[1] << 32) |
  849. ((u64)seq->gcmp.pn[0] << 40);
  850. atomic64_set(&key->u.gcmp.tx_pn, pn64);
  851. break;
  852. default:
  853. WARN_ON(1);
  854. break;
  855. }
  856. }
  857. EXPORT_SYMBOL_GPL(ieee80211_set_key_tx_seq);
  858. void ieee80211_set_key_rx_seq(struct ieee80211_key_conf *keyconf,
  859. int tid, struct ieee80211_key_seq *seq)
  860. {
  861. struct ieee80211_key *key;
  862. u8 *pn;
  863. key = container_of(keyconf, struct ieee80211_key, conf);
  864. switch (key->conf.cipher) {
  865. case WLAN_CIPHER_SUITE_TKIP:
  866. if (WARN_ON(tid < 0 || tid >= IEEE80211_NUM_TIDS))
  867. return;
  868. key->u.tkip.rx[tid].iv32 = seq->tkip.iv32;
  869. key->u.tkip.rx[tid].iv16 = seq->tkip.iv16;
  870. break;
  871. case WLAN_CIPHER_SUITE_CCMP:
  872. case WLAN_CIPHER_SUITE_CCMP_256:
  873. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  874. return;
  875. if (tid < 0)
  876. pn = key->u.ccmp.rx_pn[IEEE80211_NUM_TIDS];
  877. else
  878. pn = key->u.ccmp.rx_pn[tid];
  879. memcpy(pn, seq->ccmp.pn, IEEE80211_CCMP_PN_LEN);
  880. break;
  881. case WLAN_CIPHER_SUITE_AES_CMAC:
  882. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  883. if (WARN_ON(tid != 0))
  884. return;
  885. pn = key->u.aes_cmac.rx_pn;
  886. memcpy(pn, seq->aes_cmac.pn, IEEE80211_CMAC_PN_LEN);
  887. break;
  888. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  889. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  890. if (WARN_ON(tid != 0))
  891. return;
  892. pn = key->u.aes_gmac.rx_pn;
  893. memcpy(pn, seq->aes_gmac.pn, IEEE80211_GMAC_PN_LEN);
  894. break;
  895. case WLAN_CIPHER_SUITE_GCMP:
  896. case WLAN_CIPHER_SUITE_GCMP_256:
  897. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  898. return;
  899. if (tid < 0)
  900. pn = key->u.gcmp.rx_pn[IEEE80211_NUM_TIDS];
  901. else
  902. pn = key->u.gcmp.rx_pn[tid];
  903. memcpy(pn, seq->gcmp.pn, IEEE80211_GCMP_PN_LEN);
  904. break;
  905. default:
  906. WARN_ON(1);
  907. break;
  908. }
  909. }
  910. EXPORT_SYMBOL_GPL(ieee80211_set_key_rx_seq);
  911. void ieee80211_remove_key(struct ieee80211_key_conf *keyconf)
  912. {
  913. struct ieee80211_key *key;
  914. key = container_of(keyconf, struct ieee80211_key, conf);
  915. assert_key_lock(key->local);
  916. /*
  917. * if key was uploaded, we assume the driver will/has remove(d)
  918. * it, so adjust bookkeeping accordingly
  919. */
  920. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
  921. key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
  922. if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
  923. (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
  924. increment_tailroom_need_count(key->sdata);
  925. }
  926. ieee80211_key_free(key, false);
  927. }
  928. EXPORT_SYMBOL_GPL(ieee80211_remove_key);
  929. struct ieee80211_key_conf *
  930. ieee80211_gtk_rekey_add(struct ieee80211_vif *vif,
  931. struct ieee80211_key_conf *keyconf)
  932. {
  933. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  934. struct ieee80211_local *local = sdata->local;
  935. struct ieee80211_key *key;
  936. int err;
  937. if (WARN_ON(!local->wowlan))
  938. return ERR_PTR(-EINVAL);
  939. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  940. return ERR_PTR(-EINVAL);
  941. key = ieee80211_key_alloc(keyconf->cipher, keyconf->keyidx,
  942. keyconf->keylen, keyconf->key,
  943. 0, NULL, NULL);
  944. if (IS_ERR(key))
  945. return ERR_CAST(key);
  946. if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
  947. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  948. err = ieee80211_key_link(key, sdata, NULL);
  949. if (err)
  950. return ERR_PTR(err);
  951. return &key->conf;
  952. }
  953. EXPORT_SYMBOL_GPL(ieee80211_gtk_rekey_add);