Skip to content

Commit

Permalink
mac80211_hwsim: support scanning with random MAC address
Browse files Browse the repository at this point in the history
This adds support for scanning with random MAC address for
both software and hardware scan.

Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed Nov 19, 2014
1 parent a344d67 commit 339467b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions drivers/net/wireless/mac80211_hwsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ struct mac80211_hwsim_data {
struct cfg80211_scan_request *hw_scan_request;
struct ieee80211_vif *hw_scan_vif;
int scan_chan_idx;
u8 scan_addr[ETH_ALEN];

struct ieee80211_channel *channel;
u64 beacon_int /* beacon interval in us */;
Expand Down Expand Up @@ -830,6 +831,9 @@ static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data,
.ret = false,
};

if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0)
return true;

memcpy(md.addr, addr, ETH_ALEN);

ieee80211_iterate_active_interfaces_atomic(data->hw,
Expand Down Expand Up @@ -1802,7 +1806,7 @@ static void hw_scan_work(struct work_struct *work)
struct sk_buff *probe;

probe = ieee80211_probereq_get(hwsim->hw,
hwsim->hw_scan_vif->addr,
hwsim->scan_addr,
req->ssids[i].ssid,
req->ssids[i].ssid_len,
req->ie_len);
Expand Down Expand Up @@ -1840,6 +1844,12 @@ static int mac80211_hwsim_hw_scan(struct ieee80211_hw *hw,
hwsim->hw_scan_request = req;
hwsim->hw_scan_vif = vif;
hwsim->scan_chan_idx = 0;
if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
get_random_mask_addr(hwsim->scan_addr,
hw_req->req.mac_addr,
hw_req->req.mac_addr_mask);
else
memcpy(hwsim->scan_addr, vif->addr, ETH_ALEN);
mutex_unlock(&hwsim->mutex);

wiphy_debug(hw->wiphy, "hwsim hw_scan request\n");
Expand Down Expand Up @@ -1880,6 +1890,8 @@ static void mac80211_hwsim_sw_scan(struct ieee80211_hw *hw,
}

printk(KERN_DEBUG "hwsim sw_scan request, prepping stuff\n");

memcpy(hwsim->scan_addr, mac_addr, ETH_ALEN);
hwsim->scanning = true;

out:
Expand All @@ -1895,6 +1907,7 @@ static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw,

printk(KERN_DEBUG "hwsim sw_scan_complete\n");
hwsim->scanning = false;
memset(hwsim->scan_addr, 0, ETH_ALEN);

mutex_unlock(&hwsim->mutex);
}
Expand Down Expand Up @@ -2320,7 +2333,8 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
NL80211_FEATURE_STATIC_SMPS |
NL80211_FEATURE_DYNAMIC_SMPS;
NL80211_FEATURE_DYNAMIC_SMPS |
NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;

/* ask mac80211 to reserve space for magic */
hw->vif_data_size = sizeof(struct hwsim_vif_priv);
Expand Down

0 comments on commit 339467b

Please sign in to comment.