--- ctrl_iface.c.orig 2011-03-10 19:38:33.788403634 +0100 +++ ctrl_iface.c 2011-03-10 19:57:14.739682085 +0100 @@ -30,6 +30,14 @@ #include "wps_supplicant.h" #include "wps/wps.h" +#define ANDROID_IBSS_HACK + +#ifdef ANDROID_IBSS_HACK +/// NOTE: don't confuse WifiService.parseScanResult +#define ANDROID_IBSS_PREFIX "(*)" +#define ANDROID_IBSS_PREFIX_LEN 3 +#endif + static int wpa_supplicant_global_iface_list(struct wpa_global *global, char *buf, int len); static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, @@ -340,7 +348,14 @@ ssid_len = _res; _ssid = ssid_buf; } - ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", +#ifdef ANDROID_IBSS_HACK + if (ssid->mode == IEEE80211_MODE_IBSS) + ret = os_snprintf(pos, end - pos, "ssid=%s%s\nid=%d\n", + ANDROID_IBSS_PREFIX, wpa_ssid_txt(_ssid, ssid_len), + ssid->id); + else +#endif + ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", wpa_ssid_txt(_ssid, ssid_len), ssid->id); if (ret < 0 || ret >= end - pos) @@ -674,16 +689,24 @@ return pos - buf; pos += ret; } +#ifndef ANDROID_IBSS_HACK if (res->caps & IEEE80211_CAP_IBSS) { ret = os_snprintf(pos, end - pos, "[IBSS]"); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; } - +#endif ie = wpa_scan_get_ie(res, WLAN_EID_SSID); - ret = os_snprintf(pos, end - pos, "\t%s", - ie ? wpa_ssid_txt(ie + 2, ie[1]) : ""); + +#ifdef ANDROID_IBSS_HACK + if (res->caps & IEEE80211_CAP_IBSS) + ret = os_snprintf(pos, end - pos, "\t%s%s", + ANDROID_IBSS_PREFIX, ie ? wpa_ssid_txt(ie + 2, ie[1]) : ""); + else +#endif + ret = os_snprintf(pos, end - pos, "\t%s", + ie ? wpa_ssid_txt(ie + 2, ie[1]) : ""); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; @@ -957,6 +980,21 @@ return -1; } +#ifdef ANDROID_IBSS_HACK + if (os_strcmp(name, "ssid") == 0) { + // check prefix + if ((value[0] == '"') && (os_strncmp(value+1, ANDROID_IBSS_PREFIX, + ANDROID_IBSS_PREFIX_LEN) == 0)) { + if (wpa_config_set(ssid, "mode", "1", 0) < 0) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: failed to set IBSS on '%s'", + value); + return -1; + } + value += ANDROID_IBSS_PREFIX_LEN; + value[0] = '"'; + } + } +#endif if (wpa_config_set(ssid, name, value, 0) < 0) { wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " "variable '%s'", name); @@ -1011,8 +1049,12 @@ "variable '%s'", name); return -1; } - - res = os_strlcpy(buf, value, buflen); +#ifdef ANDROID_IBSS_HACK + if ((os_strcmp(name, "ssid") == 0) && (ssid->mode == IEEE80211_MODE_IBSS)) + res=os_snprintf(buf, buflen, "\"%s%s", ANDROID_IBSS_PREFIX, value+1); + else +#endif + res = os_strlcpy(buf, value, buflen); if (res >= buflen) { os_free(value); return -1; --- a/events.c +++ b/events.c @@ -479,9 +479,12 @@ wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group, } if (bss->caps & IEEE80211_CAP_IBSS) { +//#ifdef ANDROID_IBSS_HACK // FIXME + if (ssid->mode != IEEE80211_MODE_IBSS) { wpa_printf(MSG_DEBUG, " skip - " "IBSS (adhoc) network"); continue; + } } selected = bss;