Skip to content

Commit

Permalink
nl80211/cfg80211: add 'scan_cancel' command (INTERNAL)
Browse files Browse the repository at this point in the history
Mostly from an energy consumption and cpu load perspective,
it can be useful to stop a triggered scan earlier, when one
finds the desired scan results.
Adding the ability to stop a scan from user space by exposing
new NL80211_CMD_SCAN_CANCEL API.

Signed-off-by: Victor Goldenshtein <victorg@ti.com>
Signed-off-by: Luciano Coelho <coelho@ti.com>
  • Loading branch information
victorgld authored and Luciano Coelho committed May 7, 2013
1 parent 4e1791f commit 4a2a274
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/net/cfg80211.h
Expand Up @@ -1875,6 +1875,7 @@ struct cfg80211_update_ft_ies_params {
* the driver, and will be valid until passed to cfg80211_scan_done().
* For scan results, call cfg80211_inform_bss(); you can call this outside
* the scan/scan_done bracket too.
* @scan_cancel: Stop currently running scan (both sw and hw).
*
* @auth: Request to authenticate with the specified peer
* @assoc: Request to (re)associate with the specified peer
Expand Down Expand Up @@ -2098,6 +2099,7 @@ struct cfg80211_ops {

int (*scan)(struct wiphy *wiphy,
struct cfg80211_scan_request *request);
void (*scan_cancel)(struct wiphy *wiphy, struct net_device *dev);

int (*auth)(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_auth_request *req);
Expand Down
7 changes: 7 additions & 0 deletions include/uapi/linux/nl80211.h
Expand Up @@ -646,6 +646,11 @@
* @NL80211_CMD_CRIT_PROTOCOL_STOP: Indicates the connection reliability can
* return back to normal.
*
* @NL80211_CMD_SCAN_CANCEL: Stop currently running scan (both sw and hw).
* This operation will eventually invoke %NL80211_CMD_SCAN_ABORTED
* event, partial scan results will be available. Returns -ENOENT
* if scan is not running.
*
* @NL80211_CMD_MAX: highest used command number
* @__NL80211_CMD_AFTER_LAST: internal use
*/
Expand Down Expand Up @@ -808,6 +813,8 @@ enum nl80211_commands {
NL80211_CMD_CRIT_PROTOCOL_START,
NL80211_CMD_CRIT_PROTOCOL_STOP,

NL80211_CMD_SCAN_CANCEL,

/* add new commands above here */

/* used to define NL80211_CMD_MAX below */
Expand Down
1 change: 1 addition & 0 deletions net/wireless/core.h
Expand Up @@ -419,6 +419,7 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak);
void __cfg80211_sched_scan_results(struct work_struct *wk);
int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
bool driver_initiated);
int cfg80211_scan_cancel(struct cfg80211_registered_device *rdev);
void cfg80211_upload_connect_keys(struct wireless_dev *wdev);
int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
struct net_device *dev, enum nl80211_iftype ntype,
Expand Down
13 changes: 13 additions & 0 deletions net/wireless/nl80211.c
Expand Up @@ -5560,6 +5560,11 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
return err;
}

static int nl80211_scan_cancel(struct sk_buff *skb, struct genl_info *info)
{
return cfg80211_scan_cancel(info->user_ptr[0]);
}

static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
u32 seq, int flags,
struct cfg80211_registered_device *rdev,
Expand Down Expand Up @@ -8603,6 +8608,14 @@ static struct genl_ops nl80211_ops[] = {
.internal_flags = NL80211_FLAG_NEED_WDEV_UP |
NL80211_FLAG_NEED_RTNL,
},
{
.cmd = NL80211_CMD_SCAN_CANCEL,
.doit = nl80211_scan_cancel,
.policy = nl80211_policy,
.flags = GENL_ADMIN_PERM,
.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
NL80211_FLAG_NEED_RTNL,
},
{
.cmd = NL80211_CMD_GET_SCAN,
.policy = nl80211_policy,
Expand Down
16 changes: 16 additions & 0 deletions net/wireless/scan.c
Expand Up @@ -320,6 +320,22 @@ int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
return err;
}

int cfg80211_scan_cancel(struct cfg80211_registered_device *rdev)
{
struct net_device *dev;

ASSERT_RDEV_LOCK(rdev);

if (!rdev->ops->scan_cancel)
return -EOPNOTSUPP;
if (!rdev->scan_req)
return -ENOENT;

dev = rdev->scan_req->wdev->netdev;
rdev->ops->scan_cancel(&rdev->wiphy, dev);
return 0;
}

void cfg80211_bss_age(struct cfg80211_registered_device *dev,
unsigned long age_secs)
{
Expand Down

0 comments on commit 4a2a274

Please sign in to comment.