net/mac80211/key.c
Source file repositories/reference/linux-study-clean/net/mac80211/key.c
File Facts
- System
- Linux kernel
- Corpus path
net/mac80211/key.c- Extension
.c- Size
- 43061 bytes
- Lines
- 1519
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/utils.hlinux/if_ether.hlinux/etherdevice.hlinux/list.hlinux/rcupdate.hlinux/rtnetlink.hlinux/slab.hlinux/export.hnet/mac80211.hlinux/unaligned.hieee80211_i.hdriver-ops.hdebugfs_key.haes_ccm.haes_cmac.haes_gmac.haes_gcm.h
Detected Declarations
function update_vlan_tailroom_need_countfunction increment_tailroom_need_countfunction decrease_tailroom_need_countfunction ieee80211_key_enable_hw_accelfunction ieee80211_key_disable_hw_accelfunction _ieee80211_set_tx_keyfunction ieee80211_set_tx_keyfunction ieee80211_pairwise_rekeyfunction __ieee80211_set_default_keyfunction ieee80211_set_default_keyfunction __ieee80211_set_default_mgmt_keyfunction ieee80211_set_default_mgmt_keyfunction __ieee80211_set_default_beacon_keyfunction ieee80211_set_default_beacon_keyfunction ieee80211_key_replacefunction BITfunction ieee80211_key_allocfunction ieee80211_key_free_commonfunction __ieee80211_key_destroyfunction ieee80211_key_destroyfunction ieee80211_key_free_unusedfunction ieee80211_key_identicalfunction ieee80211_key_linkfunction ieee80211_key_freefunction ieee80211_reenable_keysfunction ieee80211_key_iterfunction ieee80211_iter_keysfunction _ieee80211_iter_keys_rcufunction ieee80211_iter_keys_rcufunction ieee80211_free_keys_ifacefunction list_for_each_entry_safefunction ieee80211_remove_link_keysfunction list_for_each_entry_safefunction ieee80211_free_key_listfunction ieee80211_free_keysfunction ieee80211_free_sta_keysfunction ieee80211_delayed_tailroom_decfunction ieee80211_gtk_rekey_notifyfunction ieee80211_get_key_rx_seqfunction ieee80211_set_key_rx_seqfunction ieee80211_gtk_rekey_addfunction ieee80211_key_mic_failurefunction ieee80211_key_replayfunction ieee80211_key_switch_linksfunction list_for_each_entryfunction list_for_each_entryexport ieee80211_iter_keysexport ieee80211_iter_keys_rcu
Annotated Snippet
if (!(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
ret = 1;
goto out_unsupported;
}
}
if (key->conf.link_id >= 0 && sdata->vif.active_links &&
!(sdata->vif.active_links & BIT(key->conf.link_id)))
return 0;
ret = drv_set_key(key->local, SET_KEY, sdata,
sta ? &sta->sta : NULL, &key->conf);
if (!ret) {
key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
if (!(key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC |
IEEE80211_KEY_FLAG_PUT_MIC_SPACE |
IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
decrease_tailroom_need_count(sdata, 1);
WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) &&
(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV));
WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_MIC_SPACE) &&
(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC));
return 0;
}
if (ret != -ENOSPC && ret != -EOPNOTSUPP && ret != 1)
sdata_err(sdata,
"failed to set key (%d, %pM) to hardware (%d)\n",
key->conf.keyidx,
sta ? sta->sta.addr : bcast_addr, ret);
out_unsupported:
switch (key->conf.cipher) {
case WLAN_CIPHER_SUITE_WEP40:
case WLAN_CIPHER_SUITE_WEP104:
case WLAN_CIPHER_SUITE_TKIP:
case WLAN_CIPHER_SUITE_CCMP:
case WLAN_CIPHER_SUITE_CCMP_256:
case WLAN_CIPHER_SUITE_GCMP:
case WLAN_CIPHER_SUITE_GCMP_256:
case WLAN_CIPHER_SUITE_AES_CMAC:
case WLAN_CIPHER_SUITE_BIP_CMAC_256:
case WLAN_CIPHER_SUITE_BIP_GMAC_128:
case WLAN_CIPHER_SUITE_BIP_GMAC_256:
/* all of these we can do in software - if driver can */
if (ret == 1)
return 0;
if (ieee80211_hw_check(&key->local->hw, SW_CRYPTO_CONTROL))
return -EINVAL;
return 0;
default:
return -EINVAL;
}
}
static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
{
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta;
int ret;
might_sleep();
if (!key || !key->local->ops->set_key)
return;
if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
return;
sta = key->sta;
sdata = key->sdata;
lockdep_assert_wiphy(key->local->hw.wiphy);
if (key->conf.link_id >= 0 && sdata->vif.active_links &&
!(sdata->vif.active_links & BIT(key->conf.link_id)))
return;
if (!(key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC |
IEEE80211_KEY_FLAG_PUT_MIC_SPACE |
IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
increment_tailroom_need_count(sdata);
key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
ret = drv_set_key(key->local, DISABLE_KEY, sdata,
Annotation
- Immediate include surface: `crypto/utils.h`, `linux/if_ether.h`, `linux/etherdevice.h`, `linux/list.h`, `linux/rcupdate.h`, `linux/rtnetlink.h`, `linux/slab.h`, `linux/export.h`.
- Detected declarations: `function update_vlan_tailroom_need_count`, `function increment_tailroom_need_count`, `function decrease_tailroom_need_count`, `function ieee80211_key_enable_hw_accel`, `function ieee80211_key_disable_hw_accel`, `function _ieee80211_set_tx_key`, `function ieee80211_set_tx_key`, `function ieee80211_pairwise_rekey`, `function __ieee80211_set_default_key`, `function ieee80211_set_default_key`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.