codice:
	diff -ur '--exclude=.*' ../cyanogenmod/android_external_wpa_supplicant_8/wpa_supplicant/ctrl_iface.c android_external_wpa_supplicant_8/wpa_supplicant/ctrl_iface.c
--- ../cyanogenmod/android_external_wpa_supplicant_8/wpa_supplicant/ctrl_iface.c	2012-10-08 07:52:08.413153210 +0200
+++ android_external_wpa_supplicant_8/wpa_supplicant/ctrl_iface.c	2012-10-08 08:03:36.573145576 +0200
@@ -36,6 +36,14 @@
 #include "blacklist.h"
 #include "wpas_glue.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
+
 extern struct wpa_driver_ops *wpa_drivers[];
 
 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
@@ -388,7 +396,9 @@
 #ifdef CONFIG_AP
 	u8 *_p2p_dev_addr = NULL;
 #endif /* CONFIG_AP */
-
+#ifdef ANDROID_BRCM_P2P_PATCH	
+	struct wpa_supplicant *iface;
+#endif
 	if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
 		_bssid = NULL;
 #ifdef CONFIG_P2P
@@ -407,7 +417,17 @@
 		return -1;
 	}
 
-#ifdef CONFIG_AP
+#if defined(ANDROID_BRCM_P2P_PATCH) && defined(CONFIG_AP)
+	for (iface = wpa_s->global->ifaces; iface; iface = iface->next)	{
+		if (iface->ap_iface){
+			wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: iface 0x%08x wpa_s->ap_iface %p", (u32)iface, iface->ap_iface);
+			wpa_supplicant_ap_wps_pbc(iface, _bssid, _p2p_dev_addr);
+			return 0;
+		}
+		else
+			wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: ap_iface is not set iface 0x%08x", (u32)iface);
+	}
+#elif defined CONFIG_AP
 	if (wpa_s->ap_iface)
 		return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
 #endif /* CONFIG_AP */
@@ -424,6 +444,10 @@
 	char *pin;
 	int ret;
 
+#if defined(ANDROID_BRCM_P2P_PATCH) && defined(CONFIG_AP)
+	struct wpa_supplicant *iface;
+#endif
+
 	pin = os_strchr(cmd, ' ');
 	if (pin)
 		*pin++ = '\0';
@@ -439,7 +463,19 @@
 		return -1;
 	}
 
-#ifdef CONFIG_AP
+#if defined(ANDROID_BRCM_P2P_PATCH) && defined(CONFIG_AP)
+	for (iface = wpa_s->global->ifaces; iface; iface = iface->next)	{
+		if (iface->ap_iface){
+			wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: iface 0x%08x wpa_s->ap_iface %p", (u32)iface, iface->ap_iface);
+			/* Call the wps registrar for the main interface */
+			wpa_supplicant_ap_wps_pin(iface, _bssid, pin,
+							 buf, buflen);
+			return 0;
+		}
+		else
+			wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: ap_iface is not set iface 0x%08x", (u32)iface);
+	}
+#elif defined CONFIG_AP
 	if (wpa_s->ap_iface)
 		return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
 						 buf, buflen);
@@ -877,6 +913,19 @@
 	char *pos, *end, tmp[30];
 	int res, verbose, wps, ret;
 
+#if defined(ANDROID_BRCM_P2P_PATCH) && defined(CONFIG_P2P)
+	/* We have to send status command to p2p interface if p2p_interface is started 
+	 * otherwise we can send it to primary interface
+	*/
+	struct wpa_supplicant* ifs;
+	for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
+		if ( (ifs->p2p_group_interface == P2P_GROUP_INTERFACE_GO ) ||(ifs->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT )) {
+			wpa_s = ifs;
+			break;
+		}
+	}
+#endif /* defined ANDROID_BRCM_P2P_PATCH && defined CONFIG_P2P */
+
 	verbose = os_strcmp(params, "-VERBOSE") == 0;
 	wps = os_strcmp(params, "-WPS") == 0;
 	pos = buf;
@@ -900,6 +949,12 @@
 					ssid_len = _res;
 				_ssid = ssid_buf;
 			}
+#ifdef ANDROID_IBSS_HACK
+			if (ssid->mode == WPAS_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);
@@ -1489,12 +1544,14 @@
 			return -1;
 		pos += ret;
 	}
+#ifndef ANDROID_IBSS_HACK
 	if (bss->caps & IEEE80211_CAP_IBSS) {
 		ret = os_snprintf(pos, end - pos, "[IBSS]");
 		if (ret < 0 || ret >= end - pos)
 			return -1;
 		pos += ret;
 	}
+#endif
 	if (bss->caps & IEEE80211_CAP_ESS) {
 		ret = os_snprintf(pos, end - pos, "[ESS]");
 		if (ret < 0 || ret >= end - pos)
@@ -1507,6 +1564,12 @@
 			return -1;
 		pos += ret;
 	}
+#ifdef ANDROID_IBSS_HACK
+	if (bss->caps & IEEE80211_CAP_IBSS)
+		ret = os_snprintf(pos, end - pos, "\t%s%s",
+			  ANDROID_IBSS_PREFIX, wpa_ssid_txt(bss->ssid, bss->ssid_len));
+	else
+#endif
 
 	ret = os_snprintf(pos, end - pos, "\t%s",
 			  wpa_ssid_txt(bss->ssid, bss->ssid_len));
@@ -1761,6 +1824,21 @@
 			   "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 "
@@ -1820,6 +1898,11 @@
 			   "variable '%s'", name);
 		return -1;
 	}
+#ifdef ANDROID_IBSS_HACK
+	if ((os_strcmp(name, "ssid") == 0) && (ssid->mode == WPAS_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) {
@@ -2750,6 +2833,16 @@
 {
 	struct wpa_ssid *ssid = wpa_s->current_ssid;
 
+#ifdef ANDROID_BRCM_P2P_PATCH
+	struct wpa_supplicant *ifs = NULL;
+	
+	for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
+		if((ifs->ap_iface) && 
+			(ifs->p2p_group_interface == P2P_GROUP_INTERFACE_GO)) {
+			ssid = ifs->current_ssid;
+		}
+	}
+#endif
 	if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
 	    ssid->passphrase == NULL)
 		return -1;
@@ -3229,6 +3322,24 @@
 	return pos - buf;
 }
 
+#ifdef ANDROID_BRCM_P2P_PATCH
+struct wpa_supplicant* p2p_get_apif(struct wpa_supplicant* wpa_s)
+{
+	struct wpa_supplicant* iface;
+	for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
+		if (iface->ap_iface)
+			return iface;
+	return wpa_s;
+}
+struct wpa_supplicant* p2p_get_clientif(struct wpa_supplicant* wpa_s)
+{
+	struct wpa_supplicant* iface;
+	for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
+		if (iface->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT)
+			return iface;
+	return wpa_s;
+}
+#endif
 
 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
 {
@@ -3284,17 +3395,33 @@
 			return -1;
 		wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
 			   "start=%d duration=%d", count, start, duration);
+#ifdef ANDROID_BRCM_P2P_PATCH
+		return wpas_p2p_set_noa(p2p_get_apif(wpa_s), count, start, duration);
+#else
 		return wpas_p2p_set_noa(wpa_s, count, start, duration);
+#endif
 	}
 
 	if (os_strcmp(cmd, "ps") == 0)
+#ifdef ANDROID_BRCM_P2P_PATCH
+		return wpas_drv_set_p2p_powersave(p2p_get_clientif(wpa_s), atoi(param), -1, -1);
+#else
 		return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
+#endif
 
 	if (os_strcmp(cmd, "oppps") == 0)
+#ifdef ANDROID_BRCM_P2P_PATCH
+		return wpas_drv_set_p2p_powersave(p2p_get_apif(wpa_s), -1, atoi(param), -1);
+#else
 		return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
+#endif
 
 	if (os_strcmp(cmd, "ctwindow") == 0)
+#ifdef ANDROID_BRCM_P2P_PATCH
+		return wpa_drv_set_p2p_powersave(p2p_get_apif(wpa_s), -1, -1, atoi(param));
+#else
 		return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
+#endif
 
 	if (os_strcmp(cmd, "disabled") == 0) {
 		wpa_s->global->p2p_disabled = atoi(param);
@@ -3796,6 +3923,18 @@
 		if (wpas_p2p_cancel(wpa_s))
 			reply_len = -1;
 	} else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
+	#if defined(ANDROID_BRCM_P2P_PATCH) && defined(CONFIG_P2P)
+		/* We have to send presence command to p2p interface if p2p_interface is started 
+		 * otherwise we can send it to primary interface
+		*/
+		struct wpa_supplicant* ifs;
+		for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
+			if ( (ifs->p2p_group_interface == P2P_GROUP_INTERFACE_GO ) ||(ifs->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT )) {
+				wpa_s = ifs;
+				break;
+			}
+		}
+	#endif /* defined ANDROID_BRCM_P2P_PATCH && defined CONFIG_P2P */
 		if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
 			reply_len = -1;
 	} else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
diff -ur '--exclude=.*' ../cyanogenmod/android_external_wpa_supplicant_8/wpa_supplicant/events.c android_external_wpa_supplicant_8/wpa_supplicant/events.c
--- ../cyanogenmod/android_external_wpa_supplicant_8/wpa_supplicant/events.c	2012-10-08 07:52:08.421153210 +0200
+++ android_external_wpa_supplicant_8/wpa_supplicant/events.c	2012-10-04 10:40:16.620892328 +0200
@@ -702,7 +702,11 @@
 			continue;
 		}
 
-		if (bss->caps & IEEE80211_CAP_IBSS) {
+		if ((bss->caps & IEEE80211_CAP_IBSS)
+#ifdef ANDROID_IBSS_HACK
+			&& (ssid->mode != WPAS_MODE_IBSS)
+#endif
+			) {
 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - IBSS (adhoc) "
 				"network");
 			continue;
 Questa è la patch che ho applicato al codice originale di CyanogenMod.