2012-10-15 15:28:03

by Antonio Quartulli

[permalink] [raw]
Subject: [PATCHv2 1/2] nl/cfg80211: add the NL80211_CMD_SET_MCAST_RATE command

This command triggers a new callback: set_mcast_rate(). It enables the user to
change the rate used to send multicast frames for vif configured as IBSS or
MESH_POINT

Signed-off-by: Antonio Quartulli <[email protected]>
---

v2:
- added check for !set_mcast_rate in nl80211_set_mcast_rate()
- moved all the changes for cfg80211 in 1/2. 2/2 now contains mac80211 changes
only

include/linux/nl80211.h | 5 +++++
include/net/cfg80211.h | 6 ++++++
net/wireless/nl80211.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+)

diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h
index 0e6277a..9440a2d 100644
--- a/include/linux/nl80211.h
+++ b/include/linux/nl80211.h
@@ -578,6 +578,9 @@
* station, due to particular reason. %NL80211_ATTR_CONN_FAILED_REASON
* is used for this.
*
+ * @NL80211_CMD_SET_MCAST_RATE: Change the rate used to send multicast frames
+ * for IBSS or MESH vif.
+ *
* @NL80211_CMD_MAX: highest used command number
* @__NL80211_CMD_AFTER_LAST: internal use
*/
@@ -726,6 +729,8 @@ enum nl80211_commands {

NL80211_CMD_CONN_FAILED,

+ NL80211_CMD_SET_MCAST_RATE,
+
/* add new commands above here */

/* used to define NL80211_CMD_MAX below */
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 2837994..facbadd 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1544,6 +1544,9 @@ struct cfg80211_gtk_rekey_data {
* to a merge.
* @leave_ibss: Leave the IBSS.
*
+ * @set_mcast_rate: Set the specified multicast rate (only if vif is in ADHOC or
+ * MESH mode)
+ *
* @set_wiphy_params: Notify that wiphy parameters have changed;
* @changed bitfield (see &enum wiphy_params_flags) describes which values
* have changed. The actual parameter values are available in
@@ -1745,6 +1748,9 @@ struct cfg80211_ops {
struct cfg80211_ibss_params *params);
int (*leave_ibss)(struct wiphy *wiphy, struct net_device *dev);

+ int (*set_mcast_rate)(struct wiphy *wiphy, struct net_device *dev,
+ int rate[IEEE80211_NUM_BANDS]);
+
int (*set_wiphy_params)(struct wiphy *wiphy, u32 changed);

int (*set_tx_power)(struct wiphy *wiphy,
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 38a1a57..cd6cd3a 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5435,6 +5435,38 @@ static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
return cfg80211_leave_ibss(rdev, dev, false);
}

+static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
+{
+ struct cfg80211_registered_device *rdev = info->user_ptr[0];
+ struct net_device *dev = info->user_ptr[1];
+ int mcast_rate[IEEE80211_NUM_BANDS];
+ u32 nla_rate;
+ int err;
+
+ if (!rdev->ops->set_mcast_rate)
+ return -EOPNOTSUPP;
+
+ memset(mcast_rate, 0, sizeof(mcast_rate));
+
+ if (!info->attrs[NL80211_ATTR_MCAST_RATE])
+ return -EINVAL;
+
+ nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
+ if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
+ return -EINVAL;
+
+ mutex_lock(&rdev->devlist_mtx);
+ wdev_lock(dev->ieee80211_ptr);
+
+ err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
+
+ wdev_unlock(dev->ieee80211_ptr);
+ mutex_unlock(&rdev->devlist_mtx);
+
+ return err;
+}
+
+
#ifdef CONFIG_NL80211_TESTMODE
static struct genl_multicast_group nl80211_testmode_mcgrp = {
.name = "testmode",
@@ -7620,6 +7652,14 @@ static struct genl_ops nl80211_ops[] = {
.internal_flags = NL80211_FLAG_NEED_WDEV_UP |
NL80211_FLAG_NEED_RTNL,
},
+ {
+ .cmd = NL80211_CMD_SET_MCAST_RATE,
+ .doit = nl80211_set_mcast_rate,
+ .policy = nl80211_policy,
+ .flags = GENL_ADMIN_PERM,
+ .internal_flags = NL80211_FLAG_NEED_NETDEV |
+ NL80211_FLAG_NEED_RTNL,
+ },
};

static struct genl_multicast_group nl80211_mlme_mcgrp = {
--
1.7.12.3



2012-10-15 15:28:02

by Antonio Quartulli

[permalink] [raw]
Subject: [PATCHv2 2/2] mac80211: implement set_mcast_rate() callback

This new callback can be used to tune the rate to be used to send multicast
frames. The callback can be used with vif configured as ADHOC or MESH_POINT
only.

In the current state the multicast rate can be specified on IBSS/MESH joining
only. This makes it impossible to select a custom multicast rate when then join
command is sent by an external program (e.g. wpa_supplicant)

Signed-off-by: Antonio Quartulli <[email protected]>
---
net/mac80211/cfg.c | 7 +++++++
net/mac80211/ieee80211_i.h | 3 +++
net/mac80211/util.c | 12 ++++++++++++
3 files changed, 22 insertions(+)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index ed27988..21461dc 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -1924,6 +1924,12 @@ static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
}

+static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
+ int rate[IEEE80211_NUM_BANDS])
+{
+ return ieee80211_mcast_rate(IEEE80211_DEV_TO_SUB_IF(dev), rate);
+}
+
static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
@@ -3123,6 +3129,7 @@ struct cfg80211_ops mac80211_config_ops = {
.disassoc = ieee80211_disassoc,
.join_ibss = ieee80211_join_ibss,
.leave_ibss = ieee80211_leave_ibss,
+ .set_mcast_rate = ieee80211_set_mcast_rate,
.set_wiphy_params = ieee80211_set_wiphy_params,
.set_tx_power = ieee80211_set_tx_power,
.get_tx_power = ieee80211_get_tx_power,
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 78c4bbb..e3b9eff 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1575,6 +1575,9 @@ void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
struct ieee80211_chanctx *chanctx);

+int ieee80211_mcast_rate(struct ieee80211_sub_if_data *sdata,
+ int rate[IEEE80211_NUM_BANDS]);
+
#ifdef CONFIG_MAC80211_NOINLINE
#define debug_noinline noinline
#else
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 350b7a7..c9f6813 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -1959,3 +1959,15 @@ u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs)
return 2;
return 1;
}
+
+int ieee80211_mcast_rate(struct ieee80211_sub_if_data *sdata,
+ int rate[IEEE80211_NUM_BANDS])
+{
+ if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
+ sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
+ return -EOPNOTSUPP;
+
+ memcpy(sdata->vif.bss_conf.mcast_rate, &rate, sizeof(rate));
+
+ return 0;
+}
--
1.7.12.3


2012-10-19 11:28:55

by Antonio Quartulli

[permalink] [raw]
Subject: Re: [PATCHv2 2/2] mac80211: implement set_mcast_rate() callback

On Fri, Oct 19, 2012 at 07:24:34PM +0800, Yeoh Chun-Yeow wrote:
> Hi, Antonio
>
> > + memcpy(sdata->vif.bss_conf.mcast_rate, &rate, sizeof(rate));
>
> I think that the second argument should be "rate" instead of "&rate".

Hi Yeoh,

correct. Thanks a lot!

>
> ---
> Chun-Yeow

--
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara


Attachments:
(No filename) (363.00 B)
(No filename) (198.00 B)
Download all attachments

2012-10-19 11:24:35

by Chun-Yeow Yeoh

[permalink] [raw]
Subject: Re: [PATCHv2 2/2] mac80211: implement set_mcast_rate() callback

Hi, Antonio

> + memcpy(sdata->vif.bss_conf.mcast_rate, &rate, sizeof(rate));

I think that the second argument should be "rate" instead of "&rate".

---
Chun-Yeow