By default, support is false but if P2P "Flush()" method gets a
non-erroneous reply: it will be set to true.

This tests at once if:
- wpa_supplicant has been built with p2p support, then Flush() should
  exist so no error should come as a reply.
- the device supports p2p, then Flush() should not reply with an error.

Whatever comes as a result will be notified through a callback to the
upper wifi plugin (which has to provide one) then it will be able to get
the value through a getter.
---
 gsupplicant/gsupplicant.h |  2 ++
 gsupplicant/supplicant.c  | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index a279cd8..d0775c3 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -222,6 +222,7 @@ int g_supplicant_interface_set_country(GSupplicantInterface 
*interface,
                                        GSupplicantCountryCallback callback,
                                                        const char *alpha2,
                                                        void *user_data);
+bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface);
 
 /* Network API */
 struct _GSupplicantNetwork;
@@ -249,6 +250,7 @@ struct _GSupplicantCallbacks {
        void (*interface_added) (GSupplicantInterface *interface);
        void (*interface_state) (GSupplicantInterface *interface);
        void (*interface_removed) (GSupplicantInterface *interface);
+       void (*p2p_support) (GSupplicantInterface *interface);
        void (*scan_started) (GSupplicantInterface *interface);
        void (*scan_finished) (GSupplicantInterface *interface);
        void (*network_added) (GSupplicantNetwork *network);
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index ab6462f..b43defb 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -153,6 +153,8 @@ struct _GSupplicantInterface {
        unsigned int scan_capa;
        unsigned int mode_capa;
        unsigned int max_scan_ssids;
+       bool p2p_checked;
+       bool p2p_support;
        dbus_bool_t ready;
        GSupplicantState state;
        dbus_bool_t scanning;
@@ -376,6 +378,19 @@ static void 
callback_interface_removed(GSupplicantInterface *interface)
        callbacks_pointer->interface_removed(interface);
 }
 
+static void callback_p2p_support(GSupplicantInterface *interface)
+{
+       SUPPLICANT_DBG("");
+
+       if (interface->p2p_checked)
+               return;
+
+       interface->p2p_checked = true;
+
+       if (callbacks_pointer && callbacks_pointer->p2p_support)
+               callbacks_pointer->p2p_support(interface);
+}
+
 static void callback_scan_started(GSupplicantInterface *interface)
 {
        if (!callbacks_pointer)
@@ -1828,6 +1843,17 @@ static GSupplicantInterface *interface_alloc(const char 
*path)
        return interface;
 }
 
+static void interface_p2p_flush(const char *error,
+                               DBusMessageIter *iter, void *user_data)
+{
+       GSupplicantInterface *interface = user_data;
+
+       if (!error)
+               interface->p2p_support = true;
+
+       callback_p2p_support(interface);
+}
+
 static void interface_added(DBusMessageIter *iter, void *user_data)
 {
        GSupplicantInterface *interface;
@@ -1850,6 +1876,10 @@ static void interface_added(DBusMessageIter *iter, void 
*user_data)
        if (!interface)
                return;
 
+       supplicant_dbus_method_call(path,
+                       SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Flush",
+                       NULL, interface_p2p_flush, interface, NULL, NULL);
+
        dbus_message_iter_next(iter);
        if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
                supplicant_dbus_property_foreach(iter, interface_property,
@@ -2430,6 +2460,11 @@ int 
g_supplicant_interface_set_country(GSupplicantInterface *interface,
                                        regdom);
 }
 
+bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
+{
+       return interface->p2p_support;
+}
+
 struct interface_data {
        GSupplicantInterface *interface;
        char *path; /* Interface path cannot be taken from interface (above) as
-- 
1.8.3.2

_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman

Reply via email to