--- old/Makefile	2005-10-28 00:28:30.000000000 -0300
+++ new/Makefile	2005-11-08 17:30:55.000000000 -0300
@@ -84,6 +84,12 @@
 CONFIG_WIRELESS_EXTENSION=y
 endif
 
+ifdef CONFIG_DRIVER_MADWIFI_NG
+CFLAGS += -DCONFIG_DRIVER_MADWIFI -DCONFIG_DRIVER_MADWIFI_NG
+OBJS_d += driver_madwifi.o
+CONFIG_WIRELESS_EXTENSION=y
+endif
+
 ifdef CONFIG_DRIVER_ATMEL
 CFLAGS += -DCONFIG_DRIVER_ATMEL
 OBJS_d += driver_atmel.o
--- old/defconfig	2005-11-08 17:35:05.000000000 -0300
+++ new/defconfig	2005-11-08 17:37:58.000000000 -0300
@@ -44,11 +44,16 @@
 #CFLAGS += -I../../hcf -I../../include -I../../include/hcf
 #CFLAGS += -I../../include/wireless
 
-# Driver interface for madwifi driver
+# Driver interface for obsolete madwifi driver from http://sourceforge.net/projects/madwifi/
 #CONFIG_DRIVER_MADWIFI=y
 # Change include directories to match with the local setup
 #CFLAGS += -I../madwifi/wpa
 
+# Driver interface for new madwifi driver from http://www.madwifi.org
+#CONFIG_DRIVER_MADWIFI_NG=y
+# Change include directories to match with the local setup
+#CFLAGS += -I../madwifi-ng/wpa
+
 # Driver interface for Prism54 driver
 # (Note: Prism54 is not yet supported, i.e., this will not work as-is and is
 # for developers only)
--- old/driver_madwifi.c	2005-10-21 02:25:13.000000000 -0300
+++ new/driver_madwifi.c	2005-11-08 18:07:16.000000000 -0300
@@ -69,6 +69,7 @@
 	}
 
 	if (ioctl(drv->sock, op, &iwr) < 0) {
+#ifndef CONFIG_DRIVER_MADWIFI_NG
 		if (show_err) {
 			static const char *opnames[] = {
 				"ioctl[IEEE80211_IOCTL_SETPARAM]",
@@ -93,6 +94,35 @@
 			else
 				perror("ioctl[unknown???]");
 		}
+#else CONFIG_DRIVER_MADWIFI_NG
+		if (show_err) {
+			static const char *opnames[] = {
+				"ioctl[IEEE80211_IOCTL_SETPARAM]",
+				"ioctl[IEEE80211_IOCTL_GETPARAM]",
+				"ioctl[IEEE80211_IOCTL_SETKEY]",
+				"ioctl[IEEE80211_IOCTL_SETWMMPARAMS]",
+				"ioctl[IEEE80211_IOCTL_DELKEY]",
+				"ioctl[IEEE80211_IOCTL_GETWMMPARAMS]",
+				"ioctl[IEEE80211_IOCTL_SETMLME]",
+				"ioctl[IEEE80211_IOCTL_GETCHANINFO]",
+				"ioctl[IEEE80211_IOCTL_SETOPTIE]",
+				"ioctl[IEEE80211_IOCTL_GETOPTIE]",
+				"ioctl[IEEE80211_IOCTL_ADDMAC]",
+				NULL,
+				"ioctl[IEEE80211_IOCTL_DELMAC]",
+				"ioctl[IEEE80211_IOCTL_GETCHANLIST]",
+				"ioctl[IEEE80211_IOCTL_SETCHANLIST]",
+				NULL,
+				"ioctl[IEEE80211_IOCTL_SETMODE]",
+				"ioctl[IEEE80211_IOCTL_GETMODE]",
+			};
+			if (IEEE80211_IOCTL_SETPARAM <= op &&
+			    op <= IEEE80211_IOCTL_GETMODE)
+				perror(opnames[op - SIOCIWFIRSTPRIV]);
+			else
+				perror("ioctl[unknown???]");
+		}
+#endif
 		return -1;
 	}
 	return 0;
@@ -356,23 +386,7 @@
 wpa_driver_madwifi_scan(void *priv, const u8 *ssid, size_t ssid_len)
 {
 	struct wpa_driver_madwifi_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	strncpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
-
-	/* set desired ssid before scan */
-	/* FIX: scan should not break the current association, so using
-	 * set_ssid may not be the best way of doing this.. */
-	if (wpa_driver_wext_set_ssid(drv->wext, ssid, ssid_len) < 0)
-		return -1;
-
-	if (ioctl(drv->sock, SIOCSIWSCAN, &iwr) < 0) {
-		perror("ioctl[SIOCSIWSCAN]");
-		return -1;
-	}
-	/* NB: madwifi delivers a scan complete event so no need to poll */
-	return 0;
+	return wpa_driver_wext_scan(drv->wext, ssid, ssid_len);
 }
 
 static int wpa_driver_madwifi_get_bssid(void *priv, u8 *bssid)

