Commit 9ddd12af authored by Johannes Berg's avatar Johannes Berg

mac80211_hwsim: minor netlink cleanups

Use u8 pointer instead of the struct mac_address and do
some other small cleanups.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 2d68992b
...@@ -298,18 +298,16 @@ static struct genl_family hwsim_genl_family = { ...@@ -298,18 +298,16 @@ static struct genl_family hwsim_genl_family = {
/* MAC80211_HWSIM netlink policy */ /* MAC80211_HWSIM netlink policy */
static struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { static struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = {
[HWSIM_ATTR_ADDR_RECEIVER] = { .type = NLA_UNSPEC, [HWSIM_ATTR_ADDR_RECEIVER] = { .type = NLA_UNSPEC, .len = ETH_ALEN },
.len = 6*sizeof(u8) }, [HWSIM_ATTR_ADDR_TRANSMITTER] = { .type = NLA_UNSPEC, .len = ETH_ALEN },
[HWSIM_ATTR_ADDR_TRANSMITTER] = { .type = NLA_UNSPEC,
.len = 6*sizeof(u8) },
[HWSIM_ATTR_FRAME] = { .type = NLA_BINARY, [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY,
.len = IEEE80211_MAX_DATA_LEN }, .len = IEEE80211_MAX_DATA_LEN },
[HWSIM_ATTR_FLAGS] = { .type = NLA_U32 }, [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 },
[HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 }, [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 },
[HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 }, [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 },
[HWSIM_ATTR_TX_INFO] = { .type = NLA_UNSPEC, [HWSIM_ATTR_TX_INFO] = { .type = NLA_UNSPEC,
.len = IEEE80211_TX_MAX_RATES*sizeof( .len = IEEE80211_TX_MAX_RATES *
struct hwsim_tx_rate)}, sizeof(struct hwsim_tx_rate)},
[HWSIM_ATTR_COOKIE] = { .type = NLA_U64 }, [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 },
}; };
...@@ -536,7 +534,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, ...@@ -536,7 +534,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
} }
if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
sizeof(struct mac_address), data->addresses[1].addr)) ETH_ALEN, data->addresses[1].addr))
goto nla_put_failure; goto nla_put_failure;
/* We get the skb->data */ /* We get the skb->data */
...@@ -1828,16 +1826,14 @@ DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group, ...@@ -1828,16 +1826,14 @@ DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group,
hwsim_fops_group_read, hwsim_fops_group_write, hwsim_fops_group_read, hwsim_fops_group_write,
"%llx\n"); "%llx\n");
static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr( static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr)
struct mac_address *addr)
{ {
struct mac80211_hwsim_data *data; struct mac80211_hwsim_data *data;
bool _found = false; bool _found = false;
spin_lock_bh(&hwsim_radio_lock); spin_lock_bh(&hwsim_radio_lock);
list_for_each_entry(data, &hwsim_radios, list) { list_for_each_entry(data, &hwsim_radios, list) {
if (memcmp(data->addresses[1].addr, addr, if (memcmp(data->addresses[1].addr, addr, ETH_ALEN) == 0) {
sizeof(struct mac_address)) == 0) {
_found = true; _found = true;
break; break;
} }
...@@ -1860,27 +1856,23 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, ...@@ -1860,27 +1856,23 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
struct hwsim_tx_rate *tx_attempts; struct hwsim_tx_rate *tx_attempts;
unsigned long ret_skb_ptr; unsigned long ret_skb_ptr;
struct sk_buff *skb, *tmp; struct sk_buff *skb, *tmp;
struct mac_address *src; const u8 *src;
unsigned int hwsim_flags; unsigned int hwsim_flags;
int i; int i;
bool found = false; bool found = false;
if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] ||
!info->attrs[HWSIM_ATTR_FLAGS] || !info->attrs[HWSIM_ATTR_FLAGS] ||
!info->attrs[HWSIM_ATTR_COOKIE] || !info->attrs[HWSIM_ATTR_COOKIE] ||
!info->attrs[HWSIM_ATTR_TX_INFO]) !info->attrs[HWSIM_ATTR_TX_INFO])
goto out; goto out;
src = (struct mac_address *)nla_data( src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]); hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]);
ret_skb_ptr = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); ret_skb_ptr = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
data2 = get_hwsim_data_ref_from_addr(src); data2 = get_hwsim_data_ref_from_addr(src);
if (!data2)
if (data2 == NULL)
goto out; goto out;
/* look for the skb matching the cookie passed back from user */ /* look for the skb matching the cookie passed back from user */
...@@ -1937,9 +1929,9 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, ...@@ -1937,9 +1929,9 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
struct mac80211_hwsim_data *data2; struct mac80211_hwsim_data *data2;
struct ieee80211_rx_status rx_status; struct ieee80211_rx_status rx_status;
struct mac_address *dst; const u8 *dst;
int frame_data_len; int frame_data_len;
char *frame_data; void *frame_data;
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] || if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] ||
...@@ -1948,27 +1940,23 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, ...@@ -1948,27 +1940,23 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
!info->attrs[HWSIM_ATTR_SIGNAL]) !info->attrs[HWSIM_ATTR_SIGNAL])
goto out; goto out;
dst = (struct mac_address *)nla_data( dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]);
info->attrs[HWSIM_ATTR_ADDR_RECEIVER]);
frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]); frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]);
frame_data = (char *)nla_data(info->attrs[HWSIM_ATTR_FRAME]); frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]);
/* Allocate new skb here */ /* Allocate new skb here */
skb = alloc_skb(frame_data_len, GFP_KERNEL); skb = alloc_skb(frame_data_len, GFP_KERNEL);
if (skb == NULL) if (skb == NULL)
goto err; goto err;
if (frame_data_len <= IEEE80211_MAX_DATA_LEN) { if (frame_data_len > IEEE80211_MAX_DATA_LEN)
/* Copy the data */
memcpy(skb_put(skb, frame_data_len), frame_data,
frame_data_len);
} else
goto err; goto err;
data2 = get_hwsim_data_ref_from_addr(dst); /* Copy the data */
memcpy(skb_put(skb, frame_data_len), frame_data, frame_data_len);
if (data2 == NULL) data2 = get_hwsim_data_ref_from_addr(dst);
if (!data2)
goto out; goto out;
/* check if radio is configured properly */ /* check if radio is configured properly */
...@@ -1976,7 +1964,7 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, ...@@ -1976,7 +1964,7 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
if (data2->idle || !data2->started) if (data2->idle || !data2->started)
goto out; goto out;
/*A frame is received from user space*/ /* A frame is received from user space */
memset(&rx_status, 0, sizeof(rx_status)); memset(&rx_status, 0, sizeof(rx_status));
rx_status.freq = data2->channel->center_freq; rx_status.freq = data2->channel->center_freq;
rx_status.band = data2->channel->band; rx_status.band = data2->channel->band;
...@@ -1998,18 +1986,12 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, ...@@ -1998,18 +1986,12 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
static int hwsim_register_received_nl(struct sk_buff *skb_2, static int hwsim_register_received_nl(struct sk_buff *skb_2,
struct genl_info *info) struct genl_info *info)
{ {
if (info == NULL)
goto out;
wmediumd_portid = info->snd_portid; wmediumd_portid = info->snd_portid;
printk(KERN_DEBUG "mac80211_hwsim: received a REGISTER, " printk(KERN_DEBUG "mac80211_hwsim: received a REGISTER, "
"switching to wmediumd mode with pid %d\n", info->snd_portid); "switching to wmediumd mode with pid %d\n", info->snd_portid);
return 0; return 0;
out:
printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__);
return -EINVAL;
} }
/* Generic Netlink operations array */ /* Generic Netlink operations array */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment