mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-26 01:08:22 -05:00
nl80211: Replace SIOCSIWSCAN with NL80211_CMD_TRIGGER_SCAN
This is the first step in replacing WEXT-based scan with the new nl80211-based mechanism.
This commit is contained in:
parent
b938903e41
commit
0e75527f7e
@ -1495,38 +1495,42 @@ static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx)
|
|||||||
static int wpa_driver_nl80211_scan(void *priv, const u8 *ssid, size_t ssid_len)
|
static int wpa_driver_nl80211_scan(void *priv, const u8 *ssid, size_t ssid_len)
|
||||||
{
|
{
|
||||||
struct wpa_driver_nl80211_data *drv = priv;
|
struct wpa_driver_nl80211_data *drv = priv;
|
||||||
struct iwreq iwr;
|
|
||||||
int ret = 0, timeout;
|
int ret = 0, timeout;
|
||||||
struct iw_scan_req req;
|
struct nl_msg *msg, *ssids;
|
||||||
|
|
||||||
if (ssid_len > IW_ESSID_MAX_SIZE) {
|
msg = nlmsg_alloc();
|
||||||
wpa_printf(MSG_DEBUG, "%s: too long SSID (%lu)",
|
ssids = nlmsg_alloc();
|
||||||
__FUNCTION__, (unsigned long) ssid_len);
|
if (!msg || !ssids) {
|
||||||
|
nlmsg_free(msg);
|
||||||
|
nlmsg_free(ssids);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
os_memset(&iwr, 0, sizeof(iwr));
|
genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
|
||||||
os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
|
NL80211_CMD_TRIGGER_SCAN, 0);
|
||||||
|
|
||||||
|
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
|
||||||
|
|
||||||
if (ssid && ssid_len) {
|
if (ssid && ssid_len) {
|
||||||
os_memset(&req, 0, sizeof(req));
|
/* Request an active scan for a specific SSID */
|
||||||
req.essid_len = ssid_len;
|
NLA_PUT(ssids, 1, ssid_len, ssid);
|
||||||
req.bssid.sa_family = ARPHRD_ETHER;
|
} else {
|
||||||
os_memset(req.bssid.sa_data, 0xff, ETH_ALEN);
|
/* Request an active scan for wildcard SSID */
|
||||||
os_memcpy(req.essid, ssid, ssid_len);
|
NLA_PUT(ssids, 1, 0, "");
|
||||||
iwr.u.data.pointer = (caddr_t) &req;
|
|
||||||
iwr.u.data.length = sizeof(req);
|
|
||||||
iwr.u.data.flags = IW_SCAN_THIS_ESSID;
|
|
||||||
}
|
}
|
||||||
|
nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
|
||||||
|
|
||||||
if (ioctl(drv->ioctl_sock, SIOCSIWSCAN, &iwr) < 0) {
|
ret = send_and_recv_msgs(drv, msg, NULL, NULL);
|
||||||
perror("ioctl[SIOCSIWSCAN]");
|
msg = NULL;
|
||||||
ret = -1;
|
if (ret) {
|
||||||
|
wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d "
|
||||||
|
"(%s)", ret, strerror(-ret));
|
||||||
|
goto nla_put_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not all drivers generate "scan completed" wireless event, so try to
|
/* Not all drivers generate "scan completed" wireless event, so try to
|
||||||
* read results after a timeout. */
|
* read results after a timeout. */
|
||||||
timeout = 5;
|
timeout = 10;
|
||||||
if (drv->scan_complete_events) {
|
if (drv->scan_complete_events) {
|
||||||
/*
|
/*
|
||||||
* The driver seems to deliver SIOCGIWSCAN events to notify
|
* The driver seems to deliver SIOCGIWSCAN events to notify
|
||||||
@ -1538,9 +1542,12 @@ static int wpa_driver_nl80211_scan(void *priv, const u8 *ssid, size_t ssid_len)
|
|||||||
wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d "
|
wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d "
|
||||||
"seconds", ret, timeout);
|
"seconds", ret, timeout);
|
||||||
eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
|
eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
|
||||||
eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, drv,
|
eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout,
|
||||||
drv->ctx);
|
drv, drv->ctx);
|
||||||
|
|
||||||
|
nla_put_failure:
|
||||||
|
nlmsg_free(ssids);
|
||||||
|
nlmsg_free(msg);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user