From e2a99cabdad967cd62cdb903ae439252852df8b5 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Wed, 10 Oct 2018 17:50:34 +0200 Subject: [PATCH] supplicant: Detect P2P and WFD support Add detection for P2P and WFD support in wpa_supplicant and pass the information to the NMSupplicantInterface. --- src/supplicant/nm-supplicant-interface.c | 64 +++++++++++++++++++++++- src/supplicant/nm-supplicant-interface.h | 14 +++++- src/supplicant/nm-supplicant-manager.c | 31 +++++++++++- 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/supplicant/nm-supplicant-interface.c b/src/supplicant/nm-supplicant-interface.c index 562b754d3f..bd7d48a58e 100644 --- a/src/supplicant/nm-supplicant-interface.c +++ b/src/supplicant/nm-supplicant-interface.c @@ -94,6 +94,8 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSupplicantInterface, PROP_AP_SUPPORT, PROP_PMF_SUPPORT, PROP_FILS_SUPPORT, + PROP_P2P_SUPPORT, + PROP_WFD_SUPPORT, ); typedef struct { @@ -104,6 +106,8 @@ typedef struct { NMSupplicantFeature ap_support; /* Lightweight AP mode support */ NMSupplicantFeature pmf_support; NMSupplicantFeature fils_support; + NMSupplicantFeature p2p_support; + NMSupplicantFeature wfd_support; guint32 max_scan_ssids; guint32 ready_count; @@ -573,6 +577,18 @@ nm_supplicant_interface_get_fils_support (NMSupplicantInterface *self) return NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->fils_support; } +NMSupplicantFeature +nm_supplicant_interface_get_p2p_support (NMSupplicantInterface *self) +{ + return NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->p2p_support; +} + +NMSupplicantFeature +nm_supplicant_interface_get_wfd_support (NMSupplicantInterface *self) +{ + return NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->wfd_support; +} + void nm_supplicant_interface_set_ap_support (NMSupplicantInterface *self, NMSupplicantFeature ap_support) @@ -613,6 +629,24 @@ nm_supplicant_interface_set_fils_support (NMSupplicantInterface *self, priv->fils_support = fils_support; } +void +nm_supplicant_interface_set_p2p_support (NMSupplicantInterface *self, + NMSupplicantFeature p2p_support) +{ + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + priv->p2p_support = p2p_support; +} + +void +nm_supplicant_interface_set_wfd_support (NMSupplicantInterface *self, + NMSupplicantFeature wfd_support) +{ + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + priv->wfd_support = wfd_support; +} + /*****************************************************************************/ static void @@ -1953,6 +1987,14 @@ set_property (GObject *object, /* construct-only */ priv->fils_support = g_value_get_int (value); break; + case PROP_P2P_SUPPORT: + /* construct-only */ + priv->p2p_support = g_value_get_int (value); + break; + case PROP_WFD_SUPPORT: + /* construct-only */ + priv->wfd_support = g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1974,7 +2016,9 @@ nm_supplicant_interface_new (const char *ifname, NMSupplicantFeature fast_support, NMSupplicantFeature ap_support, NMSupplicantFeature pmf_support, - NMSupplicantFeature fils_support) + NMSupplicantFeature fils_support, + NMSupplicantFeature p2p_support, + NMSupplicantFeature wfd_support) { g_return_val_if_fail (ifname != NULL, NULL); @@ -1985,6 +2029,8 @@ nm_supplicant_interface_new (const char *ifname, NM_SUPPLICANT_INTERFACE_AP_SUPPORT, (int) ap_support, NM_SUPPLICANT_INTERFACE_PMF_SUPPORT, (int) pmf_support, NM_SUPPLICANT_INTERFACE_FILS_SUPPORT, (int) fils_support, + NM_SUPPLICANT_INTERFACE_P2P_SUPPORT, (int) p2p_support, + NM_SUPPLICANT_INTERFACE_WFD_SUPPORT, (int) wfd_support, NULL); } @@ -2094,6 +2140,22 @@ nm_supplicant_interface_class_init (NMSupplicantInterfaceClass *klass) G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_P2P_SUPPORT] = + g_param_spec_int (NM_SUPPLICANT_INTERFACE_P2P_SUPPORT, "", "", + NM_SUPPLICANT_FEATURE_UNKNOWN, + NM_SUPPLICANT_FEATURE_YES, + NM_SUPPLICANT_FEATURE_UNKNOWN, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + obj_properties[PROP_WFD_SUPPORT] = + g_param_spec_int (NM_SUPPLICANT_INTERFACE_WFD_SUPPORT, "", "", + NM_SUPPLICANT_FEATURE_UNKNOWN, + NM_SUPPLICANT_FEATURE_YES, + NM_SUPPLICANT_FEATURE_UNKNOWN, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/supplicant/nm-supplicant-interface.h b/src/supplicant/nm-supplicant-interface.h index 0365fdcd63..a62f9dadee 100644 --- a/src/supplicant/nm-supplicant-interface.h +++ b/src/supplicant/nm-supplicant-interface.h @@ -62,6 +62,8 @@ typedef enum { #define NM_SUPPLICANT_INTERFACE_AP_SUPPORT "ap-support" #define NM_SUPPLICANT_INTERFACE_PMF_SUPPORT "pmf-support" #define NM_SUPPLICANT_INTERFACE_FILS_SUPPORT "fils-support" +#define NM_SUPPLICANT_INTERFACE_P2P_SUPPORT "p2p-support" +#define NM_SUPPLICANT_INTERFACE_WFD_SUPPORT "wfd-support" /* Signals */ #define NM_SUPPLICANT_INTERFACE_STATE "state" @@ -81,7 +83,9 @@ NMSupplicantInterface * nm_supplicant_interface_new (const char *ifname, NMSupplicantFeature fast_support, NMSupplicantFeature ap_support, NMSupplicantFeature pmf_support, - NMSupplicantFeature fils_support); + NMSupplicantFeature fils_support, + NMSupplicantFeature p2p_support, + NMSupplicantFeature wfd_support); void nm_supplicant_interface_set_supplicant_available (NMSupplicantInterface *self, gboolean available); @@ -128,6 +132,8 @@ gboolean nm_supplicant_interface_credentials_reply (NMSupplicantInterface *self, NMSupplicantFeature nm_supplicant_interface_get_ap_support (NMSupplicantInterface *self); NMSupplicantFeature nm_supplicant_interface_get_pmf_support (NMSupplicantInterface *self); NMSupplicantFeature nm_supplicant_interface_get_fils_support (NMSupplicantInterface *self); +NMSupplicantFeature nm_supplicant_interface_get_p2p_support (NMSupplicantInterface *self); +NMSupplicantFeature nm_supplicant_interface_get_wfd_support (NMSupplicantInterface *self); void nm_supplicant_interface_set_ap_support (NMSupplicantInterface *self, NMSupplicantFeature apmode); @@ -141,6 +147,12 @@ void nm_supplicant_interface_set_pmf_support (NMSupplicantInterface *self, void nm_supplicant_interface_set_fils_support (NMSupplicantInterface *self, NMSupplicantFeature fils_support); +void nm_supplicant_interface_set_p2p_support (NMSupplicantInterface *self, + NMSupplicantFeature p2p_support); + +void nm_supplicant_interface_set_wfd_support (NMSupplicantInterface *self, + NMSupplicantFeature wfd_support); + void nm_supplicant_interface_enroll_wps (NMSupplicantInterface *self, const char *const type, const char *bssid, diff --git a/src/supplicant/nm-supplicant-manager.c b/src/supplicant/nm-supplicant-manager.c index 5ab96f88f1..65cb5e20e7 100644 --- a/src/supplicant/nm-supplicant-manager.c +++ b/src/supplicant/nm-supplicant-manager.c @@ -41,6 +41,8 @@ typedef struct { NMSupplicantFeature ap_support; NMSupplicantFeature pmf_support; NMSupplicantFeature fils_support; + NMSupplicantFeature p2p_support; + NMSupplicantFeature wfd_support; guint die_count_reset_id; guint die_count; } NMSupplicantManagerPrivate; @@ -163,7 +165,9 @@ nm_supplicant_manager_create_interface (NMSupplicantManager *self, priv->fast_support, priv->ap_support, priv->pmf_support, - priv->fils_support); + priv->fils_support, + priv->p2p_support, + priv->wfd_support); priv->ifaces = g_slist_prepend (priv->ifaces, iface); g_object_add_toggle_ref ((GObject *) iface, _sup_iface_last_ref, self); @@ -199,6 +203,8 @@ update_capabilities (NMSupplicantManager *self) priv->ap_support = NM_SUPPLICANT_FEATURE_UNKNOWN; priv->pmf_support = NM_SUPPLICANT_FEATURE_UNKNOWN; priv->fils_support = NM_SUPPLICANT_FEATURE_UNKNOWN; + /* P2P support is newer than the capabilities property */ + priv->p2p_support = NM_SUPPLICANT_FEATURE_NO; value = g_dbus_proxy_get_cached_property (priv->proxy, "Capabilities"); if (value) { @@ -207,6 +213,7 @@ update_capabilities (NMSupplicantManager *self) priv->ap_support = NM_SUPPLICANT_FEATURE_NO; priv->pmf_support = NM_SUPPLICANT_FEATURE_NO; priv->fils_support = NM_SUPPLICANT_FEATURE_NO; + priv->p2p_support = NM_SUPPLICANT_FEATURE_NO; if (array) { if (g_strv_contains (array, "ap")) priv->ap_support = NM_SUPPLICANT_FEATURE_YES; @@ -214,17 +221,20 @@ update_capabilities (NMSupplicantManager *self) priv->pmf_support = NM_SUPPLICANT_FEATURE_YES; if (g_strv_contains (array, "fils")) priv->fils_support = NM_SUPPLICANT_FEATURE_YES; + if (g_strv_contains (array, "p2p")) + priv->p2p_support = NM_SUPPLICANT_FEATURE_YES; g_free (array); } } g_variant_unref (value); } - /* Tell all interfaces about results of the AP/PMF/FILS check */ + /* Tell all interfaces about results of the AP/PMF/FILS/P2P check */ for (ifaces = priv->ifaces; ifaces; ifaces = ifaces->next) { nm_supplicant_interface_set_ap_support (ifaces->data, priv->ap_support); nm_supplicant_interface_set_pmf_support (ifaces->data, priv->pmf_support); nm_supplicant_interface_set_fils_support (ifaces->data, priv->fils_support); + nm_supplicant_interface_set_p2p_support (ifaces->data, priv->p2p_support); } _LOGD ("AP mode is %ssupported", @@ -236,6 +246,9 @@ update_capabilities (NMSupplicantManager *self) _LOGD ("FILS is %ssupported", (priv->fils_support == NM_SUPPLICANT_FEATURE_YES) ? "" : (priv->fils_support == NM_SUPPLICANT_FEATURE_NO) ? "not " : "possibly "); + _LOGD ("P2P is %ssupported", + (priv->p2p_support == NM_SUPPLICANT_FEATURE_YES) ? "" : + (priv->p2p_support == NM_SUPPLICANT_FEATURE_NO) ? "not " : "possibly "); /* EAP-FAST */ priv->fast_support = NM_SUPPLICANT_FEATURE_NO; @@ -264,6 +277,20 @@ update_capabilities (NMSupplicantManager *self) _LOGD ("EAP-FAST is %ssupported", (priv->fast_support == NM_SUPPLICANT_FEATURE_YES) ? "" : (priv->fast_support == NM_SUPPLICANT_FEATURE_NO) ? "not " : "possibly "); + + priv->wfd_support = NM_SUPPLICANT_FEATURE_NO; + value = g_dbus_proxy_get_cached_property (priv->proxy, "WFDIEs"); + if (value) { + priv->wfd_support = NM_SUPPLICANT_FEATURE_YES; + g_variant_unref (value); + } + + for (ifaces = priv->ifaces; ifaces; ifaces = ifaces->next) + nm_supplicant_interface_set_wfd_support (ifaces->data, priv->fast_support); + + _LOGD ("WFD is %ssupported", + (priv->wfd_support == NM_SUPPLICANT_FEATURE_YES) ? "" : + (priv->wfd_support == NM_SUPPLICANT_FEATURE_NO) ? "not " : "possibly "); } static void