gsupplicant: Adapt set country callback to return a result
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Wed, 4 Jul 2012 13:48:04 +0000 (16:48 +0300)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 5 Jul 2012 07:04:53 +0000 (09:04 +0200)
This is necessary for the next coming patches, to fix country setting by interface

gsupplicant/gsupplicant.h
gsupplicant/supplicant.c
plugins/wifi.c

index 5dc5364..0f586a1 100644 (file)
@@ -162,7 +162,9 @@ struct _GSupplicantScanParams {
 typedef struct _GSupplicantScanParams GSupplicantScanParams;
 
 /* global API */
-typedef void (*GSupplicantCountryCallback) (void *user_data);
+typedef void (*GSupplicantCountryCallback) (int result,
+                                               const char *alpha2,
+                                                       void *user_data);
 
 int g_supplicant_set_country(const char *alpha2,
                                GSupplicantCountryCallback callback,
index 1a10291..5b09a9d 100644 (file)
@@ -2321,6 +2321,7 @@ static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
 
 struct supplicant_regdom {
        GSupplicantCountryCallback callback;
+       const char *alpha2;
        const void *user_data;
 };
 
@@ -2328,22 +2329,21 @@ static void country_result(const char *error,
                                DBusMessageIter *iter, void *user_data)
 {
        struct supplicant_regdom *regdom = user_data;
-       char *alpha2;
+       int result = 0;
 
        SUPPLICANT_DBG("Country setting result");
 
        if (user_data == NULL)
                return;
 
-       if (error == NULL) {
-               alpha2 = (char *)regdom->user_data;
-       } else {
+       if (error != NULL) {
                SUPPLICANT_DBG("Country setting failure %s", error);
-               alpha2 = NULL;
+               result = -EINVAL;
        }
 
        if (regdom->callback)
-               regdom->callback(alpha2);
+               regdom->callback(result, regdom->alpha2,
+                                       (void *) regdom->user_data);
 
        g_free(regdom);
 }
@@ -2351,11 +2351,9 @@ static void country_result(const char *error,
 static void country_params(DBusMessageIter *iter, void *user_data)
 {
        struct supplicant_regdom *regdom = user_data;
-       const char *country;
-
-       country = regdom->user_data;
 
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &country);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+                                                       &regdom->alpha2);
 }
 
 int g_supplicant_set_country(const char *alpha2,
@@ -2374,6 +2372,7 @@ int g_supplicant_set_country(const char *alpha2,
                return -ENOMEM;
 
        regdom->callback = callback;
+       regdom->alpha2 = alpha2;
        regdom->user_data = user_data;
 
        return supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
index 06604d5..6be5c0c 100644 (file)
@@ -1880,21 +1880,22 @@ static int tech_set_tethering(struct connman_technology *technology,
        return -EOPNOTSUPP;
 }
 
-static void regdom_callback(void *user_data)
+static void regdom_callback(int result, const char *alpha2, void *user_data)
 {
-       char *alpha2 = user_data;
-
        DBG("");
 
        if (wifi_technology == NULL)
                return;
 
+       if (result != 0)
+               alpha2 = NULL;
+
        connman_technology_regdom_notify(wifi_technology, alpha2);
 }
 
 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
 {
-       return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
+       return g_supplicant_set_country(alpha2, regdom_callback, NULL);
 }
 
 static struct connman_technology_driver tech_driver = {