Skip to content

Commit

Permalink
cfg80211: send events when devices are added/removed
Browse files Browse the repository at this point in the history
We're currently sending NEW_WIPHY events for renames (which
is a bit odd, but now can't be changed), but also send them
for really new devices that register.

Also send DEL_WIPHY events when a device is removed, the
event ID for this was already reserved.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed May 26, 2014
1 parent 34171dc commit 3bb2055
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion net/wireless/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
newname))
pr_err("failed to rename debugfs dir to %s!\n", newname);

nl80211_notify_dev_rename(rdev);
nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);

return 0;
}
Expand Down Expand Up @@ -660,6 +660,8 @@ int wiphy_register(struct wiphy *wiphy)
return res;
}

nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);

return 0;
}
EXPORT_SYMBOL(wiphy_register);
Expand Down Expand Up @@ -698,6 +700,7 @@ void wiphy_unregister(struct wiphy *wiphy)
rfkill_unregister(rdev->rfkill);

rtnl_lock();
nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY);
rdev->wiphy.registered = false;

WARN_ON(!list_empty(&rdev->wdev_list));
Expand Down
21 changes: 16 additions & 5 deletions net/wireless/nl80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,7 @@ struct nl80211_dump_wiphy_state {
};

static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
enum nl80211_commands cmd,
struct sk_buff *msg, u32 portid, u32 seq,
int flags, struct nl80211_dump_wiphy_state *state)
{
Expand All @@ -1240,7 +1241,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
rdev->wiphy.mgmt_stypes;
u32 features;

hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
if (!hdr)
return -ENOBUFS;

Expand All @@ -1254,6 +1255,9 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
cfg80211_rdev_list_generation))
goto nla_put_failure;

if (cmd != NL80211_CMD_NEW_WIPHY)
goto finish;

switch (state->split_start) {
case 0:
if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Expand Down Expand Up @@ -1682,6 +1686,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
state->split_start = 0;
break;
}
finish:
return genlmsg_end(msg, hdr);

nla_put_failure:
Expand Down Expand Up @@ -1756,7 +1761,8 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
continue;
/* attempt to fit multiple wiphy data chunks into the skb */
do {
ret = nl80211_send_wiphy(rdev, skb,
ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
skb,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq,
NLM_F_MULTI, state);
Expand Down Expand Up @@ -1811,7 +1817,8 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
if (!msg)
return -ENOMEM;

if (nl80211_send_wiphy(rdev, msg, info->snd_portid, info->snd_seq, 0,
if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
info->snd_portid, info->snd_seq, 0,
&state) < 0) {
nlmsg_free(msg);
return -ENOBUFS;
Expand Down Expand Up @@ -10101,16 +10108,20 @@ static const struct genl_ops nl80211_ops[] = {

/* notification functions */

void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
enum nl80211_commands cmd)
{
struct sk_buff *msg;
struct nl80211_dump_wiphy_state state = {};

WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
cmd != NL80211_CMD_DEL_WIPHY);

msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg)
return;

if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
nlmsg_free(msg);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion net/wireless/nl80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

int nl80211_init(void);
void nl80211_exit(void);
void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
enum nl80211_commands cmd);
void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
struct wireless_dev *wdev);
struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
Expand Down

0 comments on commit 3bb2055

Please sign in to comment.