12 #include <linux/if_ether.h>
14 #include <linux/list.h>
16 #include <linux/rtnetlink.h>
17 #include <linux/slab.h>
18 #include <linux/export.h>
20 #include <asm/unaligned.h>
51 static const u8 bcast_addr[
ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
96 if (!key->
local->ops->set_key)
99 assert_key_lock(key->
local);
109 goto out_unsupported;
112 goto out_unsupported;
121 goto out_unsupported;
143 "failed to set key (%d, %pM) to hardware (%d)\n",
145 sta ? sta->
sta.addr : bcast_addr, ret);
148 switch (key->
conf.cipher) {
161 static void ieee80211_key_disable_hw_accel(
struct ieee80211_key *key)
169 if (!key || !key->
local->ops->set_key)
172 assert_key_lock(key->
local);
183 increment_tailroom_need_count(sdata);
190 "failed to remove key (%d, %pM) from hardware (%d)\n",
192 sta ? sta->
sta.addr : bcast_addr, ret);
202 assert_key_lock(sdata->
local);
216 bool uni,
bool multi)
219 __ieee80211_set_default_key(sdata, idx, uni, multi);
228 assert_key_lock(sdata->
local);
243 __ieee80211_set_default_mgmt_key(sdata, idx);
255 bool defunikey, defmultikey, defmgmtkey;
260 if (sta && pairwise) {
264 idx = old->
conf.keyidx;
266 idx =
new->conf.keyidx;
272 idx = old->
conf.keyidx;
274 idx =
new->conf.keyidx;
286 if (defunikey && !
new)
287 __ieee80211_set_default_key(sdata, -1,
true,
false);
288 if (defmultikey && !
new)
289 __ieee80211_set_default_key(sdata, -1,
false,
true);
290 if (defmgmtkey && !
new)
291 __ieee80211_set_default_mgmt_key(sdata, -1);
294 if (defunikey &&
new)
295 __ieee80211_set_default_key(sdata, new->conf.keyidx,
297 if (defmultikey &&
new)
298 __ieee80211_set_default_key(sdata, new->conf.keyidx,
300 if (defmgmtkey &&
new)
301 __ieee80211_set_default_mgmt_key(sdata,
311 size_t seq_len,
const u8 *seq)
346 get_unaligned_le16(seq);
357 key->
u.
ccmp.rx_pn[i][j] =
358 seq[CCMP_PN_LEN - j - 1];
365 if (IS_ERR(key->
u.
ccmp.tfm)) {
366 err = PTR_ERR(key->
u.
ccmp.tfm);
372 key->
conf.iv_len = 0;
375 for (j = 0; j < 6; j++)
376 key->
u.
aes_cmac.rx_pn[j] = seq[6 - j - 1];
391 INIT_LIST_HEAD(&key->
list);
396 static void __ieee80211_key_destroy(
struct ieee80211_key *key)
408 ieee80211_key_disable_hw_accel(key);
416 key->
sdata->crypto_tx_tailroom_needed_cnt--;
434 idx = key->
conf.keyidx;
474 increment_tailroom_need_count(sdata);
476 __ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
477 __ieee80211_key_destroy(old_key);
481 ret = ieee80211_key_enable_hw_accel(key);
497 __ieee80211_key_replace(key->
sdata, key->
sta,
500 __ieee80211_key_destroy(key);
517 if (
WARN_ON(!ieee80211_sdata_running(sdata)))
525 increment_tailroom_need_count(sdata);
526 ieee80211_key_enable_hw_accel(key);
549 sdata = vif_to_sdata(vif);
551 iter(hw, &sdata->
vif,
553 &key->
conf, iter_data);
557 iter(hw, &sdata->
vif,
559 &key->
conf, iter_data);
574 ieee80211_key_disable_hw_accel(key);
597 const u8 *replay_ctr,
gfp_t gfp)
601 trace_api_gtk_rekey_notify(sdata, bssid, replay_ctr);
618 switch (key->
conf.cipher) {
625 seq->
ccmp.pn[5] = pn64;
626 seq->
ccmp.pn[4] = pn64 >> 8;
627 seq->
ccmp.pn[3] = pn64 >> 16;
628 seq->
ccmp.pn[2] = pn64 >> 24;
629 seq->
ccmp.pn[1] = pn64 >> 32;
630 seq->
ccmp.pn[0] = pn64 >> 40;
634 seq->
ccmp.pn[5] = pn64;
635 seq->
ccmp.pn[4] = pn64 >> 8;
636 seq->
ccmp.pn[3] = pn64 >> 16;
637 seq->
ccmp.pn[2] = pn64 >> 24;
638 seq->
ccmp.pn[1] = pn64 >> 32;
639 seq->
ccmp.pn[0] = pn64 >> 40;
655 switch (key->
conf.cipher) {
659 seq->
tkip.iv32 = key->
u.
tkip.rx[tid].iv32;
660 seq->
tkip.iv16 = key->
u.
tkip.rx[tid].iv16;
668 pn = key->
u.
ccmp.rx_pn[tid];