無線LANでAd-hocモードを有効にする

※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

ソースコードから無線LANをAd-hocモードに対応させる方法です。

  • external/wpa_supplicant/ctrl.iface.c
  • external/wpa_supplicant/events.c

の2ファイルに、下記のパッチを当てます。

szym.net/android/wpa_supplicant-ibss.patch


  • diff --git a/ctrl_iface.c b/ctrl_iface.c
+#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_interfaces(struct wpa_global *global,
                                                  char *buf, int len);
@@ -230,6 +237,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);
@@ -574,12 +588,14 @@ static int wpa_supplicant_ctrl_iface_scan_results(
                                return retpos - 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 retpos - buf;
                        pos += ret;
                }
+#endif
                if (!res->wpa_ie_len && !res->rsn_ie_len) {
                        ret = os_snprintf(pos, end - pos, "\t");
                        if (ret < 0 || ret >= end - pos)
@@ -587,6 +603,12 @@ static int wpa_supplicant_ctrl_iface_scan_results(
                        pos += ret;
                }
 
+#ifdef ANDROID_IBSS_HACK
+               if (res->caps & IEEE80211_CAP_IBSS)
+                       ret = os_snprintf(pos, end - pos, "\t%s%s",
+                                 ANDROID_IBSS_PREFIX, wpa_ssid_txt(res->ssid, res->ssid_len));
+               else
+#endif
                ret = os_snprintf(pos, end - pos, "\t%s",
                                  wpa_ssid_txt(res->ssid, res->ssid_len));
                if (ret < 0 || ret >= end - pos)
@@ -792,6 +814,21 @@ static int wpa_supplicant_ctrl_iface_set_network(
                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);
@@ -846,6 +883,11 @@ static int wpa_supplicant_ctrl_iface_get_network(
                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';

 

  • diff --git 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;

情報源:forum.xda-developers.com/showthread.php?t=754961

ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。