Commit ad30ca2c authored by Arik Nemtsov's avatar Arik Nemtsov Committed by Johannes Berg

cfg80211: allow usermode to query wiphy specific regdom

If a wiphy-idx is specified, the kernel will return the wiphy specific
regdomain, if such exists. Otherwise return the global regdom.

When no wiphy-idx is specified, return the global regdomain as well as
all wiphy-specific regulatory domains in the system, via a new nested
list of attributes.

Add a new attribute for each wiphy-specific regdomain, for usermode to
identify it as such.
Signed-off-by: default avatarArik Nemtsov <arikx.nemtsov@intel.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 2ae70efc
...@@ -252,7 +252,15 @@ ...@@ -252,7 +252,15 @@
* %NL80211_ATTR_IFINDEX. * %NL80211_ATTR_IFINDEX.
* *
* @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set * @NL80211_CMD_GET_REG: ask the wireless core to send us its currently set
* regulatory domain. * regulatory domain. If %NL80211_ATTR_WIPHY is specified and the device
* has a private regulatory domain, it will be returned. Otherwise, the
* global regdomain will be returned.
* A device will have a private regulatory domain if it uses the
* regulatory_hint() API. Even when a private regdomain is used the channel
* information will still be mended according to further hints from
* the regulatory core to help with compliance. A dump version of this API
* is now available which will returns the global regdomain as well as
* all private regdomains of present wiphys (for those that have it).
* @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command * @NL80211_CMD_SET_REG: Set current regulatory domain. CRDA sends this command
* after being queried by the kernel. CRDA replies by sending a regulatory * after being queried by the kernel. CRDA replies by sending a regulatory
* domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our * domain structure which consists of %NL80211_ATTR_REG_ALPHA set to our
......
...@@ -5327,42 +5327,20 @@ static int nl80211_update_mesh_config(struct sk_buff *skb, ...@@ -5327,42 +5327,20 @@ static int nl80211_update_mesh_config(struct sk_buff *skb,
return err; return err;
} }
static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
struct sk_buff *msg)
{ {
const struct ieee80211_regdomain *regdom;
struct sk_buff *msg;
void *hdr = NULL;
struct nlattr *nl_reg_rules; struct nlattr *nl_reg_rules;
unsigned int i; unsigned int i;
if (!cfg80211_regdomain)
return -EINVAL;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg)
return -ENOBUFS;
hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
NL80211_CMD_GET_REG);
if (!hdr)
goto put_failure;
if (reg_last_request_cell_base() &&
nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
NL80211_USER_REG_HINT_CELL_BASE))
goto nla_put_failure;
rcu_read_lock();
regdom = rcu_dereference(cfg80211_regdomain);
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
(regdom->dfs_region && (regdom->dfs_region &&
nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
goto nla_put_failure_rcu; goto nla_put_failure;
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules) if (!nl_reg_rules)
goto nla_put_failure_rcu; goto nla_put_failure;
for (i = 0; i < regdom->n_reg_rules; i++) { for (i = 0; i < regdom->n_reg_rules; i++) {
struct nlattr *nl_reg_rule; struct nlattr *nl_reg_rule;
...@@ -5377,7 +5355,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -5377,7 +5355,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
nl_reg_rule = nla_nest_start(msg, i); nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule) if (!nl_reg_rule)
goto nla_put_failure_rcu; goto nla_put_failure;
max_bandwidth_khz = freq_range->max_bandwidth_khz; max_bandwidth_khz = freq_range->max_bandwidth_khz;
if (!max_bandwidth_khz) if (!max_bandwidth_khz)
...@@ -5398,13 +5376,64 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -5398,13 +5376,64 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
power_rule->max_eirp) || power_rule->max_eirp) ||
nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
reg_rule->dfs_cac_ms)) reg_rule->dfs_cac_ms))
goto nla_put_failure_rcu; goto nla_put_failure;
nla_nest_end(msg, nl_reg_rule); nla_nest_end(msg, nl_reg_rule);
} }
rcu_read_unlock();
nla_nest_end(msg, nl_reg_rules); nla_nest_end(msg, nl_reg_rules);
return 0;
nla_put_failure:
return -EMSGSIZE;
}
static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
{
const struct ieee80211_regdomain *regdom = NULL;
struct cfg80211_registered_device *rdev;
struct wiphy *wiphy = NULL;
struct sk_buff *msg;
void *hdr;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg)
return -ENOBUFS;
hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
NL80211_CMD_GET_REG);
if (!hdr)
goto put_failure;
if (info->attrs[NL80211_ATTR_WIPHY]) {
rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
if (IS_ERR(rdev)) {
nlmsg_free(msg);
return PTR_ERR(rdev);
}
wiphy = &rdev->wiphy;
regdom = get_wiphy_regdom(wiphy);
if (regdom &&
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
}
if (!wiphy && reg_last_request_cell_base() &&
nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
NL80211_USER_REG_HINT_CELL_BASE))
goto nla_put_failure;
rcu_read_lock();
if (!regdom)
regdom = rcu_dereference(cfg80211_regdomain);
if (nl80211_put_regdom(regdom, msg))
goto nla_put_failure_rcu;
rcu_read_unlock();
genlmsg_end(msg, hdr); genlmsg_end(msg, hdr);
return genlmsg_reply(msg, info); return genlmsg_reply(msg, info);
...@@ -5418,6 +5447,79 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -5418,6 +5447,79 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
return -EMSGSIZE; return -EMSGSIZE;
} }
static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
u32 seq, int flags, struct wiphy *wiphy,
const struct ieee80211_regdomain *regdom)
{
void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
NL80211_CMD_GET_REG);
if (!hdr)
return -1;
genl_dump_check_consistent(cb, hdr, &nl80211_fam);
if (nl80211_put_regdom(regdom, msg))
goto nla_put_failure;
if (!wiphy && reg_last_request_cell_base() &&
nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
NL80211_USER_REG_HINT_CELL_BASE))
goto nla_put_failure;
if (wiphy &&
nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
goto nla_put_failure;
return genlmsg_end(msg, hdr);
nla_put_failure:
genlmsg_cancel(msg, hdr);
return -EMSGSIZE;
}
static int nl80211_get_reg_dump(struct sk_buff *skb,
struct netlink_callback *cb)
{
const struct ieee80211_regdomain *regdom = NULL;
struct cfg80211_registered_device *rdev;
int err, reg_idx, start = cb->args[2];
rtnl_lock();
if (cfg80211_regdomain && start == 0) {
err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
NLM_F_MULTI, NULL,
rtnl_dereference(cfg80211_regdomain));
if (err < 0)
goto out_err;
}
/* the global regdom is idx 0 */
reg_idx = 1;
list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
regdom = get_wiphy_regdom(&rdev->wiphy);
if (!regdom)
continue;
if (++reg_idx <= start)
continue;
err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
NLM_F_MULTI, &rdev->wiphy, regdom);
if (err < 0) {
reg_idx--;
break;
}
}
cb->args[2] = reg_idx;
err = skb->len;
out_err:
rtnl_unlock();
return err;
}
static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
{ {
struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
...@@ -10225,7 +10327,8 @@ static const struct genl_ops nl80211_ops[] = { ...@@ -10225,7 +10327,8 @@ static const struct genl_ops nl80211_ops[] = {
}, },
{ {
.cmd = NL80211_CMD_GET_REG, .cmd = NL80211_CMD_GET_REG,
.doit = nl80211_get_reg, .doit = nl80211_get_reg_do,
.dumpit = nl80211_get_reg_dump,
.policy = nl80211_policy, .policy = nl80211_policy,
.internal_flags = NL80211_FLAG_NEED_RTNL, .internal_flags = NL80211_FLAG_NEED_RTNL,
/* can be retrieved by unprivileged users */ /* can be retrieved by unprivileged users */
...@@ -10983,9 +11086,13 @@ void nl80211_send_reg_change_event(struct regulatory_request *request) ...@@ -10983,9 +11086,13 @@ void nl80211_send_reg_change_event(struct regulatory_request *request)
goto nla_put_failure; goto nla_put_failure;
} }
if (request->wiphy_idx != WIPHY_IDX_INVALID && if (request->wiphy_idx != WIPHY_IDX_INVALID) {
nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
goto nla_put_failure;
if (wiphy &&
nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
goto nla_put_failure;
}
genlmsg_end(msg, hdr); genlmsg_end(msg, hdr);
......
...@@ -142,7 +142,7 @@ static const struct ieee80211_regdomain *get_cfg80211_regdom(void) ...@@ -142,7 +142,7 @@ static const struct ieee80211_regdomain *get_cfg80211_regdom(void)
return rtnl_dereference(cfg80211_regdomain); return rtnl_dereference(cfg80211_regdomain);
} }
static const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy) const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy)
{ {
return rtnl_dereference(wiphy->regd); return rtnl_dereference(wiphy->regd);
} }
......
...@@ -38,6 +38,7 @@ unsigned int reg_get_max_bandwidth(const struct ieee80211_regdomain *rd, ...@@ -38,6 +38,7 @@ unsigned int reg_get_max_bandwidth(const struct ieee80211_regdomain *rd,
const struct ieee80211_reg_rule *rule); const struct ieee80211_reg_rule *rule);
bool reg_last_request_cell_base(void); bool reg_last_request_cell_base(void);
const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy);
/** /**
* regulatory_hint_found_beacon - hints a beacon was found on a channel * regulatory_hint_found_beacon - hints a beacon was found on a channel
......
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