[PATCH] wext: convert wpa_driver_wext_scan() to wpa_driver_wext_scan2()

Holger Schurig hs4233
Wed Sep 9 05:29:30 PDT 2009


The old wpa_driver_wext_scan() function knew how to scan for a specific SSID.
The new wpa_driver_wext_scan2() can do this well, but additionally it also
honors the scanning on specific frequencies ("scan_freq=2412 2437 2462" in
a network block).

Signed-off-by: Holger Schurig <hs4233.mail-mn-solutions.de>

---

The only questionable thing here is if setting iw_freq.e = 1
and iw_freq.m = freq * 100000 is the correct thing. For now, this
patch works at least with the patch that I posted to linux-wireless
(where I add frequency-scanning to the wext-compatibility layer of
cfg80211).

Index: hostap/src/drivers/driver_wext.c
===================================================================
--- hostap.orig/src/drivers/driver_wext.c	2009-09-09 12:39:28.000000000 +0200
+++ hostap/src/drivers/driver_wext.c	2009-09-09 12:39:31.000000000 +0200
@@ -1082,39 +1082,68 @@ void wpa_driver_wext_scan_timeout(void *
 /**
  * wpa_driver_wext_scan - Request the driver to initiate scan
  * @priv: Pointer to private wext data from wpa_driver_wext_init()
- * @ssid: Specific SSID to scan for (ProbeReq) or %NULL to scan for
- *	all SSIDs (either active scan with wildcard SSID or passive
- *	scan)
- * @ssid_len: Length of the SSID
+ * @params: Scan parameters
  * Returns: 0 on success, -1 on failure
  */
-int wpa_driver_wext_scan(void *priv, const u8 *ssid, size_t ssid_len)
+int wpa_driver_wext_scan2(void *priv,
+                          struct wpa_driver_scan_params *params)
 {
 	struct wpa_driver_wext_data *drv = priv;
 	struct iwreq iwr;
 	int ret = 0, timeout;
 	struct iw_scan_req req;
+	int i;
 
-	if (ssid_len > IW_ESSID_MAX_SIZE) {
-		wpa_printf(MSG_DEBUG, "%s: too long SSID (%lu)",
-			   __FUNCTION__, (unsigned long) ssid_len);
-		return -1;
+	if (params->num_ssids) {
+		if (params->ssids[0].ssid_len > IW_ESSID_MAX_SIZE) {
+			wpa_printf(MSG_DEBUG, "%s: too long SSID (%lu)",
+				   __FUNCTION__, (unsigned long) params->ssids[0].ssid_len);
+			return -1;
+		}
+		if (params->num_ssids > 1) {
+			wpa_printf(MSG_INFO, "WEXT: cannot scan for several SSIDs");
+			params->num_ssids = 0;
+		}
 	}
 
 	os_memset(&iwr, 0, sizeof(iwr));
+	os_memset(&req, 0, sizeof(req));
 	os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
 
-	if (ssid && ssid_len) {
-		os_memset(&req, 0, sizeof(req));
-		req.essid_len = ssid_len;
-		req.bssid.sa_family = ARPHRD_ETHER;
-		os_memset(req.bssid.sa_data, 0xff, ETH_ALEN);
-		os_memcpy(req.essid, ssid, ssid_len);
+	wpa_printf(MSG_ERROR, "##HS iwr %p", iwr);
+	if (params->num_ssids || params->freqs) {
 		iwr.u.data.pointer = (caddr_t) &req;
 		iwr.u.data.length = sizeof(req);
+		wpa_printf(MSG_ERROR, "##HS data %p, pointer %p", &iwr.u.data, iwr.u.data.pointer);
+	}
+
+	if (params->num_ssids) {
+		req.essid_len = params->ssids[0].ssid_len;
+		req.bssid.sa_family = ARPHRD_ETHER;
+		os_memset(req.bssid.sa_data, 0xff, ETH_ALEN);
+		os_memcpy(req.essid, params->ssids[0].ssid, params->ssids[0].ssid_len);
 		iwr.u.data.flags = IW_SCAN_THIS_ESSID;
 	}
 
+	if (params->freqs) {
+		// req.num_channels
+		// channel_list[],   struct iw_freq
+		//			.m       mantissa
+		//			.e       exponent
+		//			.i       list index
+		//			.flags   fixed/auto
+		for (i = 0; i < IW_MAX_FREQUENCIES; i++) {
+			if (!params->freqs[i])
+				break;
+			wpa_printf(MSG_ERROR, "##HS TODO freq %d", params->freqs[i]);
+			req.channel_list[i].m = params->freqs[i] * 100000;
+			req.channel_list[i].e = 1;
+			req.channel_list[i].i = i;
+			req.channel_list[i].flags = 0;
+			req.num_channels = i+1;
+		}
+	}
+
 	if (ioctl(drv->ioctl_sock, SIOCSIWSCAN, &iwr) < 0) {
 		perror("ioctl[SIOCSIWSCAN]");
 		ret = -1;
@@ -2371,7 +2400,7 @@ const struct wpa_driver_ops wpa_driver_w
 	.set_key = wpa_driver_wext_set_key,
 	.set_countermeasures = wpa_driver_wext_set_countermeasures,
 	.set_drop_unencrypted = wpa_driver_wext_set_drop_unencrypted,
-	.scan = wpa_driver_wext_scan,
+	.scan2 = wpa_driver_wext_scan2,
 	.get_scan_results2 = wpa_driver_wext_get_scan_results,
 	.deauthenticate = wpa_driver_wext_deauthenticate,
 	.disassociate = wpa_driver_wext_disassociate,

-- 
http://www.holgerschurig.de



More information about the Hostap mailing list