diff --git a/src/core/devices/wifi/nm-device-wifi-p2p.c b/src/core/devices/wifi/nm-device-wifi-p2p.c index 0d27017..df287bd 100644 --- a/src/core/devices/wifi/nm-device-wifi-p2p.c +++ b/src/core/devices/wifi/nm-device-wifi-p2p.c @@ -601,6 +601,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) NMSettingWirelessSecurityWpsMethod wps_method; const char *wps_pin; const char *wps_method_str; + gboolean join; if (nm_clear_g_source_inst(&priv->find_peer_timeout_source)) nm_assert_not_reached(); @@ -677,10 +678,20 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) break; } + /* A peer that already runs a group, such as a Miracast sink operating as + * an autonomous or persistent GO, may answer GO negotiation without ever + * enabling its WPS registrar, so the connection would time out. Join its + * group instead: wpa_supplicant sends a Provision Discovery Request and + * then connects to the GO, which is what such peers expect. */ + join = nm_wifi_p2p_peer_get_is_group_owner(peer); + if (join) + _LOGD(LOGD_WIFI, "Activation: (wifi-p2p) peer is a group owner, joining its group"); + nm_supplicant_interface_p2p_connect(priv->mgmt_iface, nm_wifi_p2p_peer_get_supplicant_path(peer), wps_method_str, - wps_pin); + wps_pin, + join); /* Set up a timeout on the connect attempt */ if (!priv->sup_timeout_source) { diff --git a/src/core/devices/wifi/nm-wifi-p2p-peer.c b/src/core/devices/wifi/nm-wifi-p2p-peer.c index f4d2409..0c2abe1 100644 --- a/src/core/devices/wifi/nm-wifi-p2p-peer.c +++ b/src/core/devices/wifi/nm-wifi-p2p-peer.c @@ -55,6 +55,8 @@ struct _NMWifiP2PPeerPrivate { guint16 wps_config_methods; + guint8 group_capab; + guint8 strength; NM80211ApFlags flags; /* General flags */ @@ -311,6 +313,15 @@ nm_wifi_p2p_peer_set_wps_config_methods(NMWifiP2PPeer *peer, guint16 wps_config_ return TRUE; } +gboolean +nm_wifi_p2p_peer_get_is_group_owner(const NMWifiP2PPeer *peer) +{ + g_return_val_if_fail(NM_IS_WIFI_P2P_PEER(peer), FALSE); + + /* Group Capability bit 0: "P2P Group Owner" */ + return NM_FLAGS_HAS(NM_WIFI_P2P_PEER_GET_PRIVATE(peer)->group_capab, 0x01); +} + const char *const * nm_wifi_p2p_peer_get_groups(const NMWifiP2PPeer *peer) { @@ -440,6 +451,9 @@ nm_wifi_p2p_peer_update_from_properties(NMWifiP2PPeer *peer, const NMSupplicantP changed |= nm_wifi_p2p_peer_set_wps_config_methods(peer, peer_info->config_methods); changed |= nm_wifi_p2p_peer_set_last_seen(peer, peer_info->last_seen_msec / 1000u); + /* Only used internally, to join a group that the peer already runs. */ + priv->group_capab = peer_info->group_capab; + /* We currently only use the groups information internally to check if * the peer is still joined. */ if (!nm_strv_equal(priv->groups, peer_info->groups)) { diff --git a/src/core/devices/wifi/nm-wifi-p2p-peer.h b/src/core/devices/wifi/nm-wifi-p2p-peer.h index dc7178f..b83450f 100644 --- a/src/core/devices/wifi/nm-wifi-p2p-peer.h +++ b/src/core/devices/wifi/nm-wifi-p2p-peer.h @@ -77,6 +77,8 @@ gboolean nm_wifi_p2p_peer_set_wps_config_methods(NMWifiP2PPeer *peer, guint16 wp const char *const *nm_wifi_p2p_peer_get_groups(const NMWifiP2PPeer *peer); +gboolean nm_wifi_p2p_peer_get_is_group_owner(const NMWifiP2PPeer *peer); + const char *nm_wifi_p2p_peer_get_address(const NMWifiP2PPeer *peer); gboolean nm_wifi_p2p_peer_set_address(NMWifiP2PPeer *peer, const char *addr); gint8 nm_wifi_p2p_peer_get_strength(NMWifiP2PPeer *peer); diff --git a/src/core/supplicant/nm-supplicant-interface.c b/src/core/supplicant/nm-supplicant-interface.c index 3b85979..1f0d75e 100644 --- a/src/core/supplicant/nm-supplicant-interface.c +++ b/src/core/supplicant/nm-supplicant-interface.c @@ -1009,6 +1009,13 @@ _peer_info_properties_changed(NMSupplicantInterface *self, peer_info->config_methods = v_u16; } + { + guint8 v_u8; + + if (nm_g_variant_lookup(properties, "groupcapability", "y", &v_u8)) + peer_info->group_capab = v_u8; + } + _peer_info_changed_emit(self, peer_info, TRUE); } @@ -3072,7 +3079,8 @@ void nm_supplicant_interface_p2p_connect(NMSupplicantInterface *self, const char *peer, const char *wps_method, - const char *wps_pin) + const char *wps_pin, + gboolean join) { GVariantBuilder builder; @@ -3084,7 +3092,7 @@ nm_supplicant_interface_p2p_connect(NMSupplicantInterface *self, if (wps_pin) g_variant_builder_add(&builder, "{sv}", "pin", g_variant_new_string(wps_pin)); g_variant_builder_add(&builder, "{sv}", "peer", g_variant_new_object_path(peer)); - g_variant_builder_add(&builder, "{sv}", "join", g_variant_new_boolean(FALSE)); + g_variant_builder_add(&builder, "{sv}", "join", g_variant_new_boolean(join)); g_variant_builder_add(&builder, "{sv}", "persistent", g_variant_new_boolean(FALSE)); g_variant_builder_add(&builder, "{sv}", "go_intent", g_variant_new_int32(7)); diff --git a/src/core/supplicant/nm-supplicant-interface.h b/src/core/supplicant/nm-supplicant-interface.h index 0a51a61..66f9130 100644 --- a/src/core/supplicant/nm-supplicant-interface.h +++ b/src/core/supplicant/nm-supplicant-interface.h @@ -188,7 +188,8 @@ void nm_supplicant_interface_p2p_set_device_name(NMSupplicantInterface *self, co void nm_supplicant_interface_p2p_connect(NMSupplicantInterface *self, const char *peer, const char *wps_method, - const char *wps_pin); + const char *wps_pin, + gboolean join); void nm_supplicant_interface_p2p_cancel_connect(NMSupplicantInterface *self); void nm_supplicant_interface_p2p_disconnect(NMSupplicantInterface *self); diff --git a/src/core/supplicant/nm-supplicant-types.h b/src/core/supplicant/nm-supplicant-types.h index 585dcfb..b17bdcb 100644 --- a/src/core/supplicant/nm-supplicant-types.h +++ b/src/core/supplicant/nm-supplicant-types.h @@ -225,6 +225,10 @@ typedef struct _NMSupplicantPeerInfo { guint16 config_methods; + /* P2P Group Capability bitmap (Wi-Fi P2P spec, 4.1.4); bit 0 is + * "P2P Group Owner", set while the peer runs a group. */ + guint8 group_capab; + guint8 address[6 /* ETH_ALEN */]; gint8 signal_percent;