The patch "wext: refactor" by Johannes Berg refactored
wext code so that new kernels no longer get the wext
handlers through struct netdevice, instead they get
it through the struct wiphy which is cfg80211 specific.

For old kernels this means you get not wext handlers
anymore when backporting code, this adds the wext handler
back to the netdevice wireless_handlers to let compat
users use wext again.

We do this for every kernel version because the struct wiphy
is changing from kernel version to version. At least the
struct from kernel 2.6.33 and 2.6.34 are incompatible and
the kernel would dereference some wrong type in the struct
and oops. The old interface is not affected by this. This
will cause that CONFIG_CFG80211_WEXT still depends on
CONFIG_WIRELESS_EXT in compat-drivers.

--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -342,10 +342,6 @@ struct wiphy *wiphy_new(const struct cfg
 	INIT_LIST_HEAD(&rdev->bss_list);
 	INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
 	INIT_WORK(&rdev->sched_scan_results_wk, __cfg80211_sched_scan_results);
-#ifdef CONFIG_CFG80211_WEXT
-	rdev->wiphy.wext = &cfg80211_wext_handler;
-#endif
-
 	device_initialize(&rdev->wiphy.dev);
 	rdev->wiphy.dev.class = &ieee80211_class;
 	rdev->wiphy.dev.platform_data = rdev;
@@ -862,6 +858,15 @@ static int cfg80211_netdev_notifier_call
 		wdev->sme_state = CFG80211_SME_IDLE;
 		mutex_unlock(&rdev->devlist_mtx);
 #ifdef CONFIG_CFG80211_WEXT
+#ifdef CONFIG_WIRELESS_EXT
+		if (!dev->wireless_handlers)
+			dev->wireless_handlers = &cfg80211_wext_handler;
+#else
+		printk_once(KERN_WARNING "cfg80211: wext will not work because "
+			    "kernel was compiled with CONFIG_WIRELESS_EXT=n. "
+			    "Tools using wext interface, like iwconfig will "
+			    "not work.\n");
+#endif
 		wdev->wext.default_key = -1;
 		wdev->wext.default_mgmt_key = -1;
 		wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
