key.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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. }
  434. }
  435. memcpy(key->conf.key, key_data, key_len);
  436. INIT_LIST_HEAD(&key->list);
  437. return key;
  438. }
  439. static void ieee80211_key_free_common(struct ieee80211_key *key)
  440. {
  441. switch (key->conf.cipher) {
  442. case WLAN_CIPHER_SUITE_CCMP:
  443. case WLAN_CIPHER_SUITE_CCMP_256:
  444. ieee80211_aes_key_free(key->u.ccmp.tfm);
  445. break;
  446. case WLAN_CIPHER_SUITE_AES_CMAC:
  447. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  448. ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm);
  449. break;
  450. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  451. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  452. ieee80211_aes_gmac_key_free(key->u.aes_gmac.tfm);
  453. break;
  454. case WLAN_CIPHER_SUITE_GCMP:
  455. case WLAN_CIPHER_SUITE_GCMP_256:
  456. ieee80211_aes_gcm_key_free(key->u.gcmp.tfm);
  457. break;
  458. }
  459. kzfree(key);
  460. }
  461. static void __ieee80211_key_destroy(struct ieee80211_key *key,
  462. bool delay_tailroom)
  463. {
  464. if (key->local)
  465. ieee80211_key_disable_hw_accel(key);
  466. if (key->local) {
  467. struct ieee80211_sub_if_data *sdata = key->sdata;
  468. ieee80211_debugfs_key_remove(key);
  469. if (delay_tailroom) {
  470. /* see ieee80211_delayed_tailroom_dec */
  471. sdata->crypto_tx_tailroom_pending_dec++;
  472. schedule_delayed_work(&sdata->dec_tailroom_needed_wk,
  473. HZ/2);
  474. } else {
  475. sdata->crypto_tx_tailroom_needed_cnt--;
  476. }
  477. }
  478. ieee80211_key_free_common(key);
  479. }
  480. static void ieee80211_key_destroy(struct ieee80211_key *key,
  481. bool delay_tailroom)
  482. {
  483. if (!key)
  484. return;
  485. /*
  486. * Synchronize so the TX path can no longer be using
  487. * this key before we free/remove it.
  488. */
  489. synchronize_net();
  490. __ieee80211_key_destroy(key, delay_tailroom);
  491. }
  492. void ieee80211_key_free_unused(struct ieee80211_key *key)
  493. {
  494. WARN_ON(key->sdata || key->local);
  495. ieee80211_key_free_common(key);
  496. }
  497. int ieee80211_key_link(struct ieee80211_key *key,
  498. struct ieee80211_sub_if_data *sdata,
  499. struct sta_info *sta)
  500. {
  501. struct ieee80211_local *local = sdata->local;
  502. struct ieee80211_key *old_key;
  503. int idx, ret;
  504. bool pairwise;
  505. pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
  506. idx = key->conf.keyidx;
  507. key->local = sdata->local;
  508. key->sdata = sdata;
  509. key->sta = sta;
  510. mutex_lock(&sdata->local->key_mtx);
  511. if (sta && pairwise)
  512. old_key = key_mtx_dereference(sdata->local, sta->ptk[idx]);
  513. else if (sta)
  514. old_key = key_mtx_dereference(sdata->local, sta->gtk[idx]);
  515. else
  516. old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
  517. increment_tailroom_need_count(sdata);
  518. ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
  519. ieee80211_key_destroy(old_key, true);
  520. ieee80211_debugfs_key_add(key);
  521. if (!local->wowlan) {
  522. ret = ieee80211_key_enable_hw_accel(key);
  523. if (ret)
  524. ieee80211_key_free(key, true);
  525. } else {
  526. ret = 0;
  527. }
  528. mutex_unlock(&sdata->local->key_mtx);
  529. return ret;
  530. }
  531. void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom)
  532. {
  533. if (!key)
  534. return;
  535. /*
  536. * Replace key with nothingness if it was ever used.
  537. */
  538. if (key->sdata)
  539. ieee80211_key_replace(key->sdata, key->sta,
  540. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  541. key, NULL);
  542. ieee80211_key_destroy(key, delay_tailroom);
  543. }
  544. void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
  545. {
  546. struct ieee80211_key *key;
  547. ASSERT_RTNL();
  548. if (WARN_ON(!ieee80211_sdata_running(sdata)))
  549. return;
  550. mutex_lock(&sdata->local->key_mtx);
  551. sdata->crypto_tx_tailroom_needed_cnt = 0;
  552. list_for_each_entry(key, &sdata->key_list, list) {
  553. increment_tailroom_need_count(sdata);
  554. ieee80211_key_enable_hw_accel(key);
  555. }
  556. mutex_unlock(&sdata->local->key_mtx);
  557. }
  558. void ieee80211_iter_keys(struct ieee80211_hw *hw,
  559. struct ieee80211_vif *vif,
  560. void (*iter)(struct ieee80211_hw *hw,
  561. struct ieee80211_vif *vif,
  562. struct ieee80211_sta *sta,
  563. struct ieee80211_key_conf *key,
  564. void *data),
  565. void *iter_data)
  566. {
  567. struct ieee80211_local *local = hw_to_local(hw);
  568. struct ieee80211_key *key, *tmp;
  569. struct ieee80211_sub_if_data *sdata;
  570. ASSERT_RTNL();
  571. mutex_lock(&local->key_mtx);
  572. if (vif) {
  573. sdata = vif_to_sdata(vif);
  574. list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
  575. iter(hw, &sdata->vif,
  576. key->sta ? &key->sta->sta : NULL,
  577. &key->conf, iter_data);
  578. } else {
  579. list_for_each_entry(sdata, &local->interfaces, list)
  580. list_for_each_entry_safe(key, tmp,
  581. &sdata->key_list, list)
  582. iter(hw, &sdata->vif,
  583. key->sta ? &key->sta->sta : NULL,
  584. &key->conf, iter_data);
  585. }
  586. mutex_unlock(&local->key_mtx);
  587. }
  588. EXPORT_SYMBOL(ieee80211_iter_keys);
  589. static void ieee80211_free_keys_iface(struct ieee80211_sub_if_data *sdata,
  590. struct list_head *keys)
  591. {
  592. struct ieee80211_key *key, *tmp;
  593. sdata->crypto_tx_tailroom_needed_cnt -=
  594. sdata->crypto_tx_tailroom_pending_dec;
  595. sdata->crypto_tx_tailroom_pending_dec = 0;
  596. ieee80211_debugfs_key_remove_mgmt_default(sdata);
  597. list_for_each_entry_safe(key, tmp, &sdata->key_list, list) {
  598. ieee80211_key_replace(key->sdata, key->sta,
  599. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  600. key, NULL);
  601. list_add_tail(&key->list, keys);
  602. }
  603. ieee80211_debugfs_key_update_default(sdata);
  604. }
  605. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
  606. bool force_synchronize)
  607. {
  608. struct ieee80211_local *local = sdata->local;
  609. struct ieee80211_sub_if_data *vlan;
  610. struct ieee80211_key *key, *tmp;
  611. LIST_HEAD(keys);
  612. cancel_delayed_work_sync(&sdata->dec_tailroom_needed_wk);
  613. mutex_lock(&local->key_mtx);
  614. ieee80211_free_keys_iface(sdata, &keys);
  615. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  616. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  617. ieee80211_free_keys_iface(vlan, &keys);
  618. }
  619. if (!list_empty(&keys) || force_synchronize)
  620. synchronize_net();
  621. list_for_each_entry_safe(key, tmp, &keys, list)
  622. __ieee80211_key_destroy(key, false);
  623. WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt ||
  624. sdata->crypto_tx_tailroom_pending_dec);
  625. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  626. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  627. WARN_ON_ONCE(vlan->crypto_tx_tailroom_needed_cnt ||
  628. vlan->crypto_tx_tailroom_pending_dec);
  629. }
  630. mutex_unlock(&local->key_mtx);
  631. }
  632. void ieee80211_free_sta_keys(struct ieee80211_local *local,
  633. struct sta_info *sta)
  634. {
  635. struct ieee80211_key *key;
  636. int i;
  637. mutex_lock(&local->key_mtx);
  638. for (i = 0; i < ARRAY_SIZE(sta->gtk); i++) {
  639. key = key_mtx_dereference(local, sta->gtk[i]);
  640. if (!key)
  641. continue;
  642. ieee80211_key_replace(key->sdata, key->sta,
  643. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  644. key, NULL);
  645. __ieee80211_key_destroy(key, true);
  646. }
  647. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  648. key = key_mtx_dereference(local, sta->ptk[i]);
  649. if (!key)
  650. continue;
  651. ieee80211_key_replace(key->sdata, key->sta,
  652. key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE,
  653. key, NULL);
  654. __ieee80211_key_destroy(key, true);
  655. }
  656. mutex_unlock(&local->key_mtx);
  657. }
  658. void ieee80211_delayed_tailroom_dec(struct work_struct *wk)
  659. {
  660. struct ieee80211_sub_if_data *sdata;
  661. sdata = container_of(wk, struct ieee80211_sub_if_data,
  662. dec_tailroom_needed_wk.work);
  663. /*
  664. * The reason for the delayed tailroom needed decrementing is to
  665. * make roaming faster: during roaming, all keys are first deleted
  666. * and then new keys are installed. The first new key causes the
  667. * crypto_tx_tailroom_needed_cnt to go from 0 to 1, which invokes
  668. * the cost of synchronize_net() (which can be slow). Avoid this
  669. * by deferring the crypto_tx_tailroom_needed_cnt decrementing on
  670. * key removal for a while, so if we roam the value is larger than
  671. * zero and no 0->1 transition happens.
  672. *
  673. * The cost is that if the AP switching was from an AP with keys
  674. * to one without, we still allocate tailroom while it would no
  675. * longer be needed. However, in the typical (fast) roaming case
  676. * within an ESS this usually won't happen.
  677. */
  678. mutex_lock(&sdata->local->key_mtx);
  679. sdata->crypto_tx_tailroom_needed_cnt -=
  680. sdata->crypto_tx_tailroom_pending_dec;
  681. sdata->crypto_tx_tailroom_pending_dec = 0;
  682. mutex_unlock(&sdata->local->key_mtx);
  683. }
  684. void ieee80211_gtk_rekey_notify(struct ieee80211_vif *vif, const u8 *bssid,
  685. const u8 *replay_ctr, gfp_t gfp)
  686. {
  687. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  688. trace_api_gtk_rekey_notify(sdata, bssid, replay_ctr);
  689. cfg80211_gtk_rekey_notify(sdata->dev, bssid, replay_ctr, gfp);
  690. }
  691. EXPORT_SYMBOL_GPL(ieee80211_gtk_rekey_notify);
  692. void ieee80211_get_key_tx_seq(struct ieee80211_key_conf *keyconf,
  693. struct ieee80211_key_seq *seq)
  694. {
  695. struct ieee80211_key *key;
  696. u64 pn64;
  697. if (WARN_ON(!(keyconf->flags & IEEE80211_KEY_FLAG_GENERATE_IV)))
  698. return;
  699. key = container_of(keyconf, struct ieee80211_key, conf);
  700. switch (key->conf.cipher) {
  701. case WLAN_CIPHER_SUITE_TKIP:
  702. seq->tkip.iv32 = key->u.tkip.tx.iv32;
  703. seq->tkip.iv16 = key->u.tkip.tx.iv16;
  704. break;
  705. case WLAN_CIPHER_SUITE_CCMP:
  706. case WLAN_CIPHER_SUITE_CCMP_256:
  707. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  708. seq->ccmp.pn[5] = pn64;
  709. seq->ccmp.pn[4] = pn64 >> 8;
  710. seq->ccmp.pn[3] = pn64 >> 16;
  711. seq->ccmp.pn[2] = pn64 >> 24;
  712. seq->ccmp.pn[1] = pn64 >> 32;
  713. seq->ccmp.pn[0] = pn64 >> 40;
  714. break;
  715. case WLAN_CIPHER_SUITE_AES_CMAC:
  716. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  717. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  718. seq->ccmp.pn[5] = pn64;
  719. seq->ccmp.pn[4] = pn64 >> 8;
  720. seq->ccmp.pn[3] = pn64 >> 16;
  721. seq->ccmp.pn[2] = pn64 >> 24;
  722. seq->ccmp.pn[1] = pn64 >> 32;
  723. seq->ccmp.pn[0] = pn64 >> 40;
  724. break;
  725. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  726. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  727. pn64 = atomic64_read(&key->u.aes_gmac.tx_pn);
  728. seq->ccmp.pn[5] = pn64;
  729. seq->ccmp.pn[4] = pn64 >> 8;
  730. seq->ccmp.pn[3] = pn64 >> 16;
  731. seq->ccmp.pn[2] = pn64 >> 24;
  732. seq->ccmp.pn[1] = pn64 >> 32;
  733. seq->ccmp.pn[0] = pn64 >> 40;
  734. break;
  735. case WLAN_CIPHER_SUITE_GCMP:
  736. case WLAN_CIPHER_SUITE_GCMP_256:
  737. pn64 = atomic64_read(&key->u.gcmp.tx_pn);
  738. seq->gcmp.pn[5] = pn64;
  739. seq->gcmp.pn[4] = pn64 >> 8;
  740. seq->gcmp.pn[3] = pn64 >> 16;
  741. seq->gcmp.pn[2] = pn64 >> 24;
  742. seq->gcmp.pn[1] = pn64 >> 32;
  743. seq->gcmp.pn[0] = pn64 >> 40;
  744. break;
  745. default:
  746. WARN_ON(1);
  747. }
  748. }
  749. EXPORT_SYMBOL(ieee80211_get_key_tx_seq);
  750. void ieee80211_get_key_rx_seq(struct ieee80211_key_conf *keyconf,
  751. int tid, struct ieee80211_key_seq *seq)
  752. {
  753. struct ieee80211_key *key;
  754. const u8 *pn;
  755. key = container_of(keyconf, struct ieee80211_key, conf);
  756. switch (key->conf.cipher) {
  757. case WLAN_CIPHER_SUITE_TKIP:
  758. if (WARN_ON(tid < 0 || tid >= IEEE80211_NUM_TIDS))
  759. return;
  760. seq->tkip.iv32 = key->u.tkip.rx[tid].iv32;
  761. seq->tkip.iv16 = key->u.tkip.rx[tid].iv16;
  762. break;
  763. case WLAN_CIPHER_SUITE_CCMP:
  764. case WLAN_CIPHER_SUITE_CCMP_256:
  765. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  766. return;
  767. if (tid < 0)
  768. pn = key->u.ccmp.rx_pn[IEEE80211_NUM_TIDS];
  769. else
  770. pn = key->u.ccmp.rx_pn[tid];
  771. memcpy(seq->ccmp.pn, pn, IEEE80211_CCMP_PN_LEN);
  772. break;
  773. case WLAN_CIPHER_SUITE_AES_CMAC:
  774. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  775. if (WARN_ON(tid != 0))
  776. return;
  777. pn = key->u.aes_cmac.rx_pn;
  778. memcpy(seq->aes_cmac.pn, pn, IEEE80211_CMAC_PN_LEN);
  779. break;
  780. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  781. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  782. if (WARN_ON(tid != 0))
  783. return;
  784. pn = key->u.aes_gmac.rx_pn;
  785. memcpy(seq->aes_gmac.pn, pn, IEEE80211_GMAC_PN_LEN);
  786. break;
  787. case WLAN_CIPHER_SUITE_GCMP:
  788. case WLAN_CIPHER_SUITE_GCMP_256:
  789. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  790. return;
  791. if (tid < 0)
  792. pn = key->u.gcmp.rx_pn[IEEE80211_NUM_TIDS];
  793. else
  794. pn = key->u.gcmp.rx_pn[tid];
  795. memcpy(seq->gcmp.pn, pn, IEEE80211_GCMP_PN_LEN);
  796. break;
  797. }
  798. }
  799. EXPORT_SYMBOL(ieee80211_get_key_rx_seq);
  800. void ieee80211_set_key_tx_seq(struct ieee80211_key_conf *keyconf,
  801. struct ieee80211_key_seq *seq)
  802. {
  803. struct ieee80211_key *key;
  804. u64 pn64;
  805. key = container_of(keyconf, struct ieee80211_key, conf);
  806. switch (key->conf.cipher) {
  807. case WLAN_CIPHER_SUITE_TKIP:
  808. key->u.tkip.tx.iv32 = seq->tkip.iv32;
  809. key->u.tkip.tx.iv16 = seq->tkip.iv16;
  810. break;
  811. case WLAN_CIPHER_SUITE_CCMP:
  812. case WLAN_CIPHER_SUITE_CCMP_256:
  813. pn64 = (u64)seq->ccmp.pn[5] |
  814. ((u64)seq->ccmp.pn[4] << 8) |
  815. ((u64)seq->ccmp.pn[3] << 16) |
  816. ((u64)seq->ccmp.pn[2] << 24) |
  817. ((u64)seq->ccmp.pn[1] << 32) |
  818. ((u64)seq->ccmp.pn[0] << 40);
  819. atomic64_set(&key->u.ccmp.tx_pn, pn64);
  820. break;
  821. case WLAN_CIPHER_SUITE_AES_CMAC:
  822. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  823. pn64 = (u64)seq->aes_cmac.pn[5] |
  824. ((u64)seq->aes_cmac.pn[4] << 8) |
  825. ((u64)seq->aes_cmac.pn[3] << 16) |
  826. ((u64)seq->aes_cmac.pn[2] << 24) |
  827. ((u64)seq->aes_cmac.pn[1] << 32) |
  828. ((u64)seq->aes_cmac.pn[0] << 40);
  829. atomic64_set(&key->u.aes_cmac.tx_pn, pn64);
  830. break;
  831. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  832. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  833. pn64 = (u64)seq->aes_gmac.pn[5] |
  834. ((u64)seq->aes_gmac.pn[4] << 8) |
  835. ((u64)seq->aes_gmac.pn[3] << 16) |
  836. ((u64)seq->aes_gmac.pn[2] << 24) |
  837. ((u64)seq->aes_gmac.pn[1] << 32) |
  838. ((u64)seq->aes_gmac.pn[0] << 40);
  839. atomic64_set(&key->u.aes_gmac.tx_pn, pn64);
  840. break;
  841. case WLAN_CIPHER_SUITE_GCMP:
  842. case WLAN_CIPHER_SUITE_GCMP_256:
  843. pn64 = (u64)seq->gcmp.pn[5] |
  844. ((u64)seq->gcmp.pn[4] << 8) |
  845. ((u64)seq->gcmp.pn[3] << 16) |
  846. ((u64)seq->gcmp.pn[2] << 24) |
  847. ((u64)seq->gcmp.pn[1] << 32) |
  848. ((u64)seq->gcmp.pn[0] << 40);
  849. atomic64_set(&key->u.gcmp.tx_pn, pn64);
  850. break;
  851. default:
  852. WARN_ON(1);
  853. break;
  854. }
  855. }
  856. EXPORT_SYMBOL_GPL(ieee80211_set_key_tx_seq);
  857. void ieee80211_set_key_rx_seq(struct ieee80211_key_conf *keyconf,
  858. int tid, struct ieee80211_key_seq *seq)
  859. {
  860. struct ieee80211_key *key;
  861. u8 *pn;
  862. key = container_of(keyconf, struct ieee80211_key, conf);
  863. switch (key->conf.cipher) {
  864. case WLAN_CIPHER_SUITE_TKIP:
  865. if (WARN_ON(tid < 0 || tid >= IEEE80211_NUM_TIDS))
  866. return;
  867. key->u.tkip.rx[tid].iv32 = seq->tkip.iv32;
  868. key->u.tkip.rx[tid].iv16 = seq->tkip.iv16;
  869. break;
  870. case WLAN_CIPHER_SUITE_CCMP:
  871. case WLAN_CIPHER_SUITE_CCMP_256:
  872. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  873. return;
  874. if (tid < 0)
  875. pn = key->u.ccmp.rx_pn[IEEE80211_NUM_TIDS];
  876. else
  877. pn = key->u.ccmp.rx_pn[tid];
  878. memcpy(pn, seq->ccmp.pn, IEEE80211_CCMP_PN_LEN);
  879. break;
  880. case WLAN_CIPHER_SUITE_AES_CMAC:
  881. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  882. if (WARN_ON(tid != 0))
  883. return;
  884. pn = key->u.aes_cmac.rx_pn;
  885. memcpy(pn, seq->aes_cmac.pn, IEEE80211_CMAC_PN_LEN);
  886. break;
  887. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  888. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  889. if (WARN_ON(tid != 0))
  890. return;
  891. pn = key->u.aes_gmac.rx_pn;
  892. memcpy(pn, seq->aes_gmac.pn, IEEE80211_GMAC_PN_LEN);
  893. break;
  894. case WLAN_CIPHER_SUITE_GCMP:
  895. case WLAN_CIPHER_SUITE_GCMP_256:
  896. if (WARN_ON(tid < -1 || tid >= IEEE80211_NUM_TIDS))
  897. return;
  898. if (tid < 0)
  899. pn = key->u.gcmp.rx_pn[IEEE80211_NUM_TIDS];
  900. else
  901. pn = key->u.gcmp.rx_pn[tid];
  902. memcpy(pn, seq->gcmp.pn, IEEE80211_GCMP_PN_LEN);
  903. break;
  904. default:
  905. WARN_ON(1);
  906. break;
  907. }
  908. }
  909. EXPORT_SYMBOL_GPL(ieee80211_set_key_rx_seq);
  910. void ieee80211_remove_key(struct ieee80211_key_conf *keyconf)
  911. {
  912. struct ieee80211_key *key;
  913. key = container_of(keyconf, struct ieee80211_key, conf);
  914. assert_key_lock(key->local);
  915. /*
  916. * if key was uploaded, we assume the driver will/has remove(d)
  917. * it, so adjust bookkeeping accordingly
  918. */
  919. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
  920. key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
  921. if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
  922. (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
  923. increment_tailroom_need_count(key->sdata);
  924. }
  925. ieee80211_key_free(key, false);
  926. }
  927. EXPORT_SYMBOL_GPL(ieee80211_remove_key);
  928. struct ieee80211_key_conf *
  929. ieee80211_gtk_rekey_add(struct ieee80211_vif *vif,
  930. struct ieee80211_key_conf *keyconf)
  931. {
  932. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  933. struct ieee80211_local *local = sdata->local;
  934. struct ieee80211_key *key;
  935. int err;
  936. if (WARN_ON(!local->wowlan))
  937. return ERR_PTR(-EINVAL);
  938. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  939. return ERR_PTR(-EINVAL);
  940. key = ieee80211_key_alloc(keyconf->cipher, keyconf->keyidx,
  941. keyconf->keylen, keyconf->key,
  942. 0, NULL, NULL);
  943. if (IS_ERR(key))
  944. return ERR_CAST(key);
  945. if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
  946. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  947. err = ieee80211_key_link(key, sdata, NULL);
  948. if (err)
  949. return ERR_PTR(err);
  950. return &key->conf;
  951. }
  952. EXPORT_SYMBOL_GPL(ieee80211_gtk_rekey_add);