From: "Niu,Bing" <[email protected]>

add new boolean ap_create_inprogress for GSupplicantInterface, set this
boolean to 1 when wifi plugin call apscan. if gsupplicant receive interface
state information as disconnected while ap_create_inprogress as 1. then this
indentify there is a ap create fail happen, gsupplicant will callback
interface_ap_create_fail to wifi plugin and let wifi plugin has a chance to fix
it.
---
 gsupplicant/gsupplicant.h |  1 +
 gsupplicant/supplicant.c  | 66 ++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 63 insertions(+), 4 deletions(-)
 mode change 100644 => 100755 gsupplicant/supplicant.c

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 187dc65..2a87f2f 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -341,6 +341,7 @@ struct _GSupplicantCallbacks {
        void (*p2p_support) (GSupplicantInterface *interface);
        void (*scan_started) (GSupplicantInterface *interface);
        void (*scan_finished) (GSupplicantInterface *interface);
+       void (*ap_create_fail) (GSupplicantInterface *interface);
        void (*network_added) (GSupplicantNetwork *network);
        void (*network_removed) (GSupplicantNetwork *network);
        void (*network_changed) (GSupplicantNetwork *network,
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
old mode 100644
new mode 100755
index cd91f95..2fdc7b5
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -163,6 +163,7 @@ struct _GSupplicantInterface {
        unsigned int max_scan_ssids;
        bool p2p_support;
        bool p2p_finding;
+       bool ap_create_in_progress;
        dbus_bool_t ready;
        GSupplicantState state;
        dbus_bool_t scanning;
@@ -432,6 +433,17 @@ static void callback_scan_started(GSupplicantInterface 
*interface)
        callbacks_pointer->scan_started(interface);
 }
 
+static void callback_ap_create_fail(GSupplicantInterface *interface)
+{
+       if (!callbacks_pointer)
+               return;
+
+       if (!callbacks_pointer->scan_started)
+               return;
+
+       callbacks_pointer->ap_create_fail(interface);
+}
+
 static void callback_scan_finished(GSupplicantInterface *interface)
 {
        if (!callbacks_pointer)
@@ -790,20 +802,58 @@ static void interface_capability(const char *key, 
DBusMessageIter *iter,
                                key, dbus_message_iter_get_arg_type(iter));
 }
 
+struct set_apscan_data
+{
+       unsigned int ap_scan;
+       GSupplicantInterface *interface;
+};
+
 static void set_apscan(DBusMessageIter *iter, void *user_data)
 {
-       unsigned int ap_scan = *(unsigned int *)user_data;
+       struct set_apscan_data *data = user_data;
+       unsigned int ap_scan = data->ap_scan;
 
        dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
 }
 
+static void set_apscan_complete(const char *error,
+               DBusMessageIter *iter, void *user_data)
+{
+       struct set_apscan_data *data = user_data;
+       GSupplicantInterface *interface = data->interface;
+
+       if (error) {
+               interface->ap_create_in_progress = false;
+               SUPPLICANT_DBG("Set AP scan error %s", error);
+               goto error;
+       }
+
+       interface->ap_create_in_progress = true;
+error:
+       dbus_free(data);
+}
+
 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
                                                        unsigned int ap_scan)
 {
-       return supplicant_dbus_property_set(interface->path,
+       struct set_apscan_data *data;
+       data = dbus_malloc0(sizeof(*data));
+       int ret;
+
+       if (!data)
+               return -ENOMEM;
+
+       data->ap_scan = ap_scan;
+       data->interface = interface;
+
+       ret = supplicant_dbus_property_set(interface->path,
                        SUPPLICANT_INTERFACE ".Interface",
-                               "ApScan", DBUS_TYPE_UINT32_AS_STRING,
-                                       set_apscan, NULL, &ap_scan, NULL);
+                       "ApScan", DBUS_TYPE_UINT32_AS_STRING,
+                       set_apscan, set_apscan_complete, data, NULL);
+       if (ret < 0)
+               dbus_free(data);
+
+       return ret;
 }
 
 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
@@ -1988,6 +2038,14 @@ static void interface_property(const char *key, 
DBusMessageIter *iter,
                                interface->state = string2state(str);
                                callback_interface_state(interface);
                        }
+
+               if (interface->ap_create_in_progress) {
+                       if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
+                               callback_ap_create_fail(interface);
+
+                       interface->ap_create_in_progress = false;
+               }
+
                if (interface->state == G_SUPPLICANT_STATE_DISABLED)
                        interface->ready = FALSE;
                else
-- 
1.7.11.7

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

Reply via email to