+ int ret;
+ char cmd[256];
+ DIR *proc;
+ struct dirent *e;
+
+ ret = -1;
+
+ /* We got a wifiX device passed, try to lookup a vap on it */
+ if( madwifi_iswifi(ifname) )
+ {
+ if( (proc = opendir("/proc/sys/net/")) != NULL )
+ {
+ while( (e = readdir(proc)) != NULL )
+ {
+ if( madwifi_isvap(e->d_name, ifname) )
+ {
+ sprintf(cmd, "ifconfig %s up", e->d_name);
+
+ if( ! WEXITSTATUS(system(cmd)) )
+ {
+ ret = wext_get_scanlist(e->d_name, buf, len);
+ break;
+ }
+ }
+ }
+
+ closedir(proc);
+ }
+
+ /* Still nothing found, try to create a vap */
+ if( ret == -1 )
+ {
+ sprintf(cmd, "wlanconfig ath-scan create nounit "
+ "wlandev %s wlanmode sta >/dev/null", ifname);
+
+ if( ! WEXITSTATUS(system(cmd)) && ! WEXITSTATUS(system("ifconfig ath-scan up")) )
+ {
+ ret = wext_get_scanlist("ath-scan", buf, len);
+
+ (void) WEXITSTATUS(system("ifconfig ath-scan down"));
+ (void) WEXITSTATUS(system("wlanconfig ath-scan destroy"));
+ }
+ }
+ }
+
+ /* Got athX device? */
+ else if( madwifi_isvap(ifname, NULL) )
+ {
+ ret = wext_get_scanlist(ifname, buf, len);
+ }
+
+ return ret;