Skip to content
Browse files

fix Ad Hoc connections

  • Loading branch information...
1 parent fb7409a commit 3c5db6db9ffd3e09bade3dd5a090c9c36c57340c @Quarx2k Quarx2k committed with Nov 28, 2012
Showing with 46 additions and 8 deletions.
  1. +46 −8 wpa_supplicant/ctrl_iface.c
View
54 wpa_supplicant/ctrl_iface.c
@@ -31,6 +31,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,
@@ -341,6 +349,13 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
ssid_len = _res;
_ssid = ssid_buf;
}
+#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);
@@ -777,12 +792,14 @@ static int wpa_supplicant_ctrl_iface_scan_result(
return -1;
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 -1;
pos += ret;
}
+#endif
/* Just to make the fields line up nicely when printed */
if (!ie && !ie2) {
ret = os_snprintf(pos, end - pos, "\t");
@@ -791,6 +808,12 @@ static int wpa_supplicant_ctrl_iface_scan_result(
pos += ret;
}
ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
+#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)
@@ -1107,7 +1130,21 @@ static int wpa_supplicant_ctrl_iface_set_network(
"id=%d", id);
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);
@@ -1166,16 +1203,17 @@ static int wpa_supplicant_ctrl_iface_get_network(
"variable '%s'", name);
return -1;
}
-
- res = os_strlcpy(buf, value, buflen);
- if (res >= buflen) {
- os_free(value);
- return -1;
- }
+#ifdef ANDROID_IBSS_HACK
+ if ((os_strcmp(name, "ssid") == 0) && (ssid->mode == IEEE80211_MODE_IBSS))
+ os_snprintf(buf, buflen, "\"%s%s", ANDROID_IBSS_PREFIX, value+1);
+ else
+#endif
+ os_snprintf(buf, buflen, "%s", value);
+ buf[buflen - 1] = '\0';
os_free(value);
- return res;
+ return os_strlen(buf);
}

0 comments on commit 3c5db6d

Please sign in to comment.
Something went wrong with that request. Please try again.