gsupplicant: WPS credentials signal support
authorTomasz Bursztyka <tomasz.bursztyka@nokia.com>
Wed, 26 Jan 2011 08:09:31 +0000 (10:09 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 27 Jan 2011 11:11:19 +0000 (12:11 +0100)
gsupplicant/gsupplicant.h
gsupplicant/supplicant.c

index 9404402076a39748fe3cdcfa859403bcac44f561..4f507e3bfa4d68bdbcc2b3d314e2452f3d57136d 100644 (file)
@@ -155,6 +155,9 @@ void *g_supplicant_interface_get_data(GSupplicantInterface *interface);
 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface);
 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface);
 GSupplicantState g_supplicant_interface_get_state(GSupplicantInterface *interface);
+const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface);
+const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
+                                                       unsigned int *ssid_len);
 
 /* Network API */
 struct _GSupplicantNetwork;
index ffad4fbdd6bfdf5373cfbdbb4ae53c50b5dc8e25..6cb691ee93868e337ed52db06ea944851d5b8608 100644 (file)
@@ -136,6 +136,12 @@ static struct strvalmap mode_capa_map[] = {
 static GHashTable *interface_table;
 static GHashTable *bss_mapping;
 
+struct _GSupplicantWpsCredentials {
+       unsigned char ssid[32];
+       unsigned int ssid_len;
+       char *key;
+};
+
 struct _GSupplicantInterface {
        char *path;
        char *network_path;
@@ -155,6 +161,7 @@ struct _GSupplicantInterface {
        char *ifname;
        char *driver;
        char *bridge;
+       struct _GSupplicantWpsCredentials wps_cred;
        GHashTable *network_table;
        GHashTable *net_mapping;
        GHashTable *bss_mapping;
@@ -406,6 +413,7 @@ static void remove_interface(gpointer data)
 
        callback_interface_removed(interface);
 
+       g_free(interface->wps_cred.key);
        g_free(interface->path);
        g_free(interface->network_path);
        g_free(interface->ifname);
@@ -645,6 +653,29 @@ GSupplicantState g_supplicant_interface_get_state(
        return interface->state;
 }
 
+const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
+{
+       if (interface == NULL)
+               return NULL;
+
+       return (const char *)interface->wps_cred.key;
+}
+
+const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
+                                                       unsigned int *ssid_len)
+{
+       if (ssid_len == NULL)
+               return NULL;
+
+       if (interface == NULL || interface->wps_cred.ssid == NULL) {
+               *ssid_len = 0;
+               return NULL;
+       }
+
+       *ssid_len = interface->wps_cred.ssid_len;
+       return interface->wps_cred.ssid;
+}
+
 GSupplicantInterface *g_supplicant_network_get_interface(
                                        GSupplicantNetwork *network)
 {
@@ -1777,6 +1808,65 @@ static void signal_bss_changed(const char *path, DBusMessageIter *iter)
        supplicant_dbus_property_foreach(iter, bss_property, bss);
 }
 
+static void wps_credentials(const char *key, DBusMessageIter *iter,
+                       void *user_data)
+{
+       GSupplicantInterface *interface = user_data;
+
+       if (key == NULL)
+               return;
+
+       SUPPLICANT_DBG("key %s", key);
+
+       if (g_strcmp0(key, "Key") == 0) {
+               DBusMessageIter array;
+               unsigned char *key;
+               int key_len;
+
+               dbus_message_iter_recurse(iter, &array);
+               dbus_message_iter_get_fixed_array(&array, &key, &key_len);
+
+               g_free(interface->wps_cred.key);
+               interface->wps_cred.key = g_try_malloc0(
+                                               sizeof(char) * key_len+1);
+
+               if (interface->wps_cred.key == NULL)
+                       return;
+
+               memcpy(interface->wps_cred.key, key, sizeof(char) * key_len);
+
+               SUPPLICANT_DBG("WPS key present");
+       } else if (g_strcmp0(key, "SSID") == 0) {
+               DBusMessageIter array;
+               unsigned char *ssid;
+               int ssid_len;
+
+               dbus_message_iter_recurse(iter, &array);
+               dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
+
+               if (ssid_len > 0 && ssid_len < 33) {
+                       memcpy(interface->wps_cred.ssid, ssid, ssid_len);
+                       interface->wps_cred.ssid_len = ssid_len;
+               } else {
+                       memset(interface->wps_cred.ssid, 0, 32);
+                       interface->wps_cred.ssid_len = 0;
+               }
+       }
+}
+
+static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
+{
+       GSupplicantInterface *interface;
+
+       SUPPLICANT_DBG("");
+
+       interface = g_hash_table_lookup(interface_table, path);
+       if (interface == NULL)
+               return;
+
+       supplicant_dbus_property_foreach(iter, wps_credentials, interface);
+}
+
 static struct {
        const char *interface;
        const char *member;
@@ -1798,6 +1888,8 @@ static struct {
 
        { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed   },
 
+       { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
+
        { }
 };