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.

Dependency Surface

Detected Declarations

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

Implementation Notes