drivers/net/wireless/virtual/mac80211_hwsim_main.c
Source file repositories/reference/linux-study-clean/drivers/net/wireless/virtual/mac80211_hwsim_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/wireless/virtual/mac80211_hwsim_main.c- Extension
.c- Size
- 220863 bytes
- Lines
- 7620
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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
linux/list.hlinux/slab.hlinux/spinlock.hnet/dst.hnet/xfrm.hnet/mac80211.hnet/ieee80211_radiotap.hlinux/if_arp.hlinux/rtnetlink.hlinux/etherdevice.hlinux/platform_device.hlinux/debugfs.hlinux/module.hlinux/ktime.hnet/genetlink.hnet/net_namespace.hnet/netns/generic.hlinux/rhashtable.hlinux/nospec.hlinux/virtio.hlinux/virtio_ids.hlinux/virtio_config.hlinux/uaccess.hlinux/string.hmac80211_hwsim.hmac80211_hwsim_i.h
Detected Declarations
struct hwsim_vif_privstruct hwsim_chanctx_privstruct hwsim_netstruct hwsim_radiotap_hdrstruct hwsim_radiotap_ack_hdrstruct hwsim_chanctx_iter_argstruct mac80211_hwsim_addr_match_datastruct tx_iter_datastruct hwsim_new_radio_paramsenum hwsim_regtestenum qca_nl80211_vendor_subcmdsenum hwsim_multicast_groupsenum hwsim_testmode_attrenum hwsim_testmode_cmdfunction hwsim_check_magicfunction hwsim_set_magicfunction hwsim_clear_magicfunction hwsim_check_sta_magicfunction hwsim_set_sta_magicfunction hwsim_clear_sta_magicfunction hwsim_check_chanctx_magicfunction hwsim_set_chanctx_magicfunction hwsim_clear_chanctx_magicfunction hwsim_net_get_netgroupfunction hwsim_net_set_netgroupfunction hwsim_net_get_wmediumdfunction hwsim_net_set_wmediumdfunction mac80211_hwsim_vendor_cmd_testfunction hwsim_tx_virtiofunction hwsim_get_chanwidthfunction hwsim_send_ps_pollfunction hwsim_send_nullfuncfunction hwsim_send_nullfunc_psfunction hwsim_send_nullfunc_no_psfunction hwsim_fops_ps_readfunction hwsim_fops_ps_writefunction hwsim_write_simulate_radarfunction hwsim_background_cac_writefunction hwsim_6ghz_chanctx_iterfunction hwsim_simulate_incumbent_signal_writefunction hwsim_fops_group_readfunction hwsim_fops_group_writefunction hwsim_fops_rx_rssi_readfunction hwsim_fops_rx_rssi_writefunction hwsim_mon_xmitfunction mac80211_hwsim_get_sim_tsffunction mac80211_hwsim_tsf_to_boottimefunction mac80211_hwsim_boottime_to_tsf
Annotated Snippet
static const struct file_operations hwsim_background_cac_ops = {
.write = hwsim_background_cac_write,
.open = simple_open,
.llseek = default_llseek,
};
struct hwsim_chanctx_iter_arg {
struct ieee80211_chanctx_conf *conf;
u32 freq_mhz;
};
static void hwsim_6ghz_chanctx_iter(struct ieee80211_hw *hw,
struct ieee80211_chanctx_conf *conf,
void *data)
{
struct hwsim_chanctx_iter_arg *arg = data;
if (conf->def.chan &&
conf->def.chan->band == NL80211_BAND_6GHZ &&
conf->def.chan->center_freq == arg->freq_mhz)
arg->conf = conf;
}
static ssize_t hwsim_simulate_incumbent_signal_write(struct file *file,
const char __user *ubuf,
size_t len, loff_t *ppos)
{
struct mac80211_hwsim_data *data = file->private_data;
struct hwsim_chanctx_iter_arg arg = {};
u32 bitmap;
char buf[64];
if (!len || len > sizeof(buf) - 1)
return -EINVAL;
if (copy_from_user(buf, ubuf, len))
return -EFAULT;
buf[len] = '\0';
if (sscanf(buf, "%u %i", &arg.freq_mhz, &bitmap) != 2)
return -EINVAL;
if (!arg.freq_mhz)
return -EINVAL;
ieee80211_iter_chan_contexts_atomic(data->hw,
hwsim_6ghz_chanctx_iter,
&arg);
if (!arg.conf)
return -EINVAL;
cfg80211_incumbent_signal_notify(data->hw->wiphy,
&arg.conf->def,
bitmap,
GFP_KERNEL);
return len;
}
static const struct file_operations hwsim_simulate_incumbent_signal_fops = {
.open = simple_open,
.write = hwsim_simulate_incumbent_signal_write,
};
static int hwsim_fops_group_read(void *dat, u64 *val)
{
struct mac80211_hwsim_data *data = dat;
*val = data->group;
return 0;
}
static int hwsim_fops_group_write(void *dat, u64 val)
{
struct mac80211_hwsim_data *data = dat;
data->group = val;
return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_group,
hwsim_fops_group_read, hwsim_fops_group_write,
"%llx\n");
static int hwsim_fops_rx_rssi_read(void *dat, u64 *val)
{
struct mac80211_hwsim_data *data = dat;
*val = data->rx_rssi;
return 0;
}
Annotation
- Immediate include surface: `linux/list.h`, `linux/slab.h`, `linux/spinlock.h`, `net/dst.h`, `net/xfrm.h`, `net/mac80211.h`, `net/ieee80211_radiotap.h`, `linux/if_arp.h`.
- Detected declarations: `struct hwsim_vif_priv`, `struct hwsim_chanctx_priv`, `struct hwsim_net`, `struct hwsim_radiotap_hdr`, `struct hwsim_radiotap_ack_hdr`, `struct hwsim_chanctx_iter_arg`, `struct mac80211_hwsim_addr_match_data`, `struct tx_iter_data`, `struct hwsim_new_radio_params`, `enum hwsim_regtest`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.