diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index afa8121b6..1ad1a9578 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -3684,10 +3684,31 @@ static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf, } -static int wpas_go_connected(void *ctx, const u8 *dev_addr) +struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, + const u8 *ssid, size_t ssid_len) { - struct wpa_supplicant *wpa_s = ctx; + for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { + struct wpa_ssid *s = wpa_s->current_ssid; + if (s == NULL) + continue; + if (s->mode != WPAS_MODE_P2P_GO && + s->mode != WPAS_MODE_AP && + s->mode != WPAS_MODE_P2P_GROUP_FORMATION) + continue; + if (s->ssid_len != ssid_len || + os_memcmp(s, s->ssid, ssid_len) != 0) + continue; + return wpa_s; + } + return NULL; + +} + + +struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, + const u8 *peer_dev_addr) +{ for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { struct wpa_ssid *ssid = wpa_s->current_ssid; if (ssid == NULL) @@ -3697,11 +3718,19 @@ static int wpas_go_connected(void *ctx, const u8 *dev_addr) if (wpa_s->wpa_state != WPA_COMPLETED && wpa_s->wpa_state != WPA_GROUP_HANDSHAKE) continue; - if (os_memcmp(wpa_s->go_dev_addr, dev_addr, ETH_ALEN) == 0) - return 1; + if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0) + return wpa_s; } - return 0; + return NULL; +} + + +static int wpas_go_connected(void *ctx, const u8 *dev_addr) +{ + struct wpa_supplicant *wpa_s = ctx; + + return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL; } diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h index cb4bf25a1..841d6df88 100644 --- a/wpa_supplicant/p2p_supplicant.h +++ b/wpa_supplicant/p2p_supplicant.h @@ -17,6 +17,10 @@ struct p2p_channels; struct wps_event_fail; int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s); +struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, + const u8 *ssid, size_t ssid_len); +struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, + const u8 *peer_dev_addr); int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, const char *pin, enum p2p_wps_method wps_method, int persistent_group, int auto_join, int join,