Imported Upstream version 1.41
[platform/upstream/connman.git] / plugins / iwd.c
index 4ba107f..ac3d1e1 100644 (file)
@@ -209,18 +209,13 @@ static int cm_network_probe(struct connman_network *network)
 static void update_network_connected(struct iwd_network *iwdn)
 {
        struct iwd_device *iwdd;
-       int index;
 
        iwdd = g_hash_table_lookup(devices, iwdn->device);
        if (!iwdd)
                return;
 
-       index = connman_inet_ifindex(iwdd->name);
-       if (index < 0)
-               return;
-
-       DBG("interface name %s index %d", iwdd->name, index);
-       connman_network_set_index(iwdn->network, index);
+       DBG("interface name %s index %d", iwdd->name,
+               connman_network_get_index(iwdn->network));
        connman_network_set_connected(iwdn->network, true);
 }
 
@@ -316,11 +311,13 @@ static int cm_network_disconnect(struct connman_network *network)
        if (!iwds)
                return -EIO;
 
+       connman_network_set_associating(network, false);
+
        if (!g_dbus_proxy_method_call(iwds->proxy, "Disconnect",
                        NULL, cm_network_disconnect_cb, g_strdup(iwdn->path), g_free))
                return -EIO;
 
-       return -EINPROGRESS;
+       return 0;
 }
 
 struct auto_connect_cb_data {
@@ -558,7 +555,7 @@ static void cm_device_scan_cb(DBusMessage *message, void *user_data)
        const char *path = user_data;
        struct iwd_station *iwds;
 
-       iwds = g_hash_table_lookup(networks, path);
+       iwds = g_hash_table_lookup(stations, path);
        if (!iwds)
                return;
 
@@ -818,12 +815,16 @@ static int cm_change_tethering(struct iwd_device *iwdd,
 }
 
 static int cm_tech_tethering(struct connman_technology *technology,
-                       const char *identifier, const char *passphrase,
                        const char *bridge, bool enabled)
 {
        GHashTableIter iter;
        gpointer key, value;
        int err = 0, res;
+       const char *ssid;
+       const char *psk;
+       int freq;
+
+       connman_technology_get_wifi_tethering(technology, &ssid, &psk, &freq);
 
        g_hash_table_iter_init(&iter, devices);
 
@@ -840,8 +841,8 @@ static int cm_tech_tethering(struct connman_technology *technology,
                        continue;
 
                if (!enabled && !g_strcmp0("ap", iwdd->mode)) {
-                       res = cm_change_tethering(iwdd, technology, identifier,
-                                               passphrase, bridge, enabled);
+                       res = cm_change_tethering(iwdd, technology, ssid,
+                                               psk, bridge, enabled);
                        if (res)
                                connman_warn("%s switching to Station mode failed",
                                        iwdd->path);
@@ -851,8 +852,8 @@ static int cm_tech_tethering(struct connman_technology *technology,
                }
 
                if (enabled && !g_strcmp0("station", iwdd->mode)) {
-                       err = cm_change_tethering(iwdd, technology, identifier,
-                                       passphrase, bridge, enabled);
+                       err = cm_change_tethering(iwdd, technology, ssid,
+                                       psk, bridge, enabled);
                        if (err)
                                connman_warn("%s switching to AccessPoint mode failed",
                                        iwdd->path);
@@ -912,6 +913,7 @@ static void add_network(const char *path, struct iwd_network *iwdn)
 {
        struct iwd_device *iwdd;
        char *identifier;
+       int index;
 
        iwdd = g_hash_table_lookup(devices, iwdn->device);
        if (!iwdd)
@@ -920,6 +922,11 @@ static void add_network(const char *path, struct iwd_network *iwdn)
        identifier = create_identifier(path, iwdn->type);
        iwdn->network = connman_network_create(identifier,
                                        CONNMAN_NETWORK_TYPE_WIFI);
+
+       index = connman_inet_ifindex(iwdd->name);
+       if (index >= 0)
+               connman_network_set_index(iwdn->network, index);
+
        connman_network_set_data(iwdn->network, iwdn);
 
        connman_network_set_name(iwdn->network, iwdn->name);
@@ -936,7 +943,9 @@ static void add_network(const char *path, struct iwd_network *iwdn)
        }
        iwdn->iwdd = iwdd;
 
-       connman_network_set_available(iwdn->network, true);
+       if (connman_network_get_strength(iwdn->network))
+               connman_network_set_available(iwdn->network, true);
+
        connman_network_set_group(iwdn->network, identifier);
 
        g_free(identifier);
@@ -1372,13 +1381,7 @@ static void create_adapter(GDBusProxy *proxy)
        struct iwd_adapter *iwda;
        GSList *modes, *list;
 
-       iwda = g_try_new0(struct iwd_adapter, 1);
-
-       if (!iwda) {
-               connman_error("Out of memory creating IWD adapter");
-               return;
-       }
-
+       iwda = g_new0(struct iwd_adapter, 1);
        iwda->path = g_strdup(path);
        g_hash_table_replace(adapters, iwda->path, iwda);
 
@@ -1423,13 +1426,7 @@ static void create_device(GDBusProxy *proxy)
        const char *path = g_dbus_proxy_get_path(proxy);
        struct iwd_device *iwdd;
 
-       iwdd = g_try_new0(struct iwd_device, 1);
-
-       if (!iwdd) {
-               connman_error("Out of memory creating IWD device");
-               return;
-       }
-
+       iwdd = g_new0(struct iwd_device, 1);
        iwdd->path = g_strdup(path);
        g_hash_table_replace(devices, iwdd->path, iwdd);
 
@@ -1494,6 +1491,8 @@ static DBusMessage *agent_request_passphrase(DBusConnection *dbus_conn,
                return get_reply_on_error(message, EINVAL);
 
        passwd = connman_network_get_string(iwdn->network, "WiFi.Passphrase");
+       if (!passwd)
+               return get_reply_on_error(message, ENOKEY);
 
        return g_dbus_create_reply(message, DBUS_TYPE_STRING, &passwd,
                                        DBUS_TYPE_INVALID);
@@ -1596,13 +1595,7 @@ static void create_network(GDBusProxy *proxy)
        const char *path = g_dbus_proxy_get_path(proxy);
        struct iwd_network *iwdn;
 
-       iwdn = g_try_new0(struct iwd_network, 1);
-
-       if (!iwdn) {
-               connman_error("Out of memory creating IWD network");
-               return;
-       }
-
+       iwdn = g_new0(struct iwd_network, 1);
        iwdn->path = g_strdup(path);
        g_hash_table_replace(networks, iwdn->path, iwdn);
 
@@ -1682,12 +1675,7 @@ static void create_know_network(GDBusProxy *proxy)
        const char *path = g_dbus_proxy_get_path(proxy);
        struct iwd_known_network *iwdkn;
 
-       iwdkn = g_try_new0(struct iwd_known_network, 1);
-       if (!iwdkn) {
-               connman_error("Out of memory creating IWD known network");
-               return;
-       }
-
+       iwdkn = g_new0(struct iwd_known_network, 1);
        iwdkn->path = g_strdup(path);
        g_hash_table_replace(known_networks, iwdkn->path, iwdkn);
 
@@ -1721,12 +1709,7 @@ static void create_station(GDBusProxy *proxy)
        const char *path = g_dbus_proxy_get_path(proxy);
        struct iwd_station *iwds;
 
-       iwds = g_try_new0(struct iwd_station, 1);
-       if (!iwds) {
-               connman_error("Out of memory creating IWD station");
-               return;
-       }
-
+       iwds = g_new0(struct iwd_station, 1);
        iwds->path = g_strdup(path);
        g_hash_table_replace(stations, iwds->path, iwds);
 
@@ -1754,11 +1737,7 @@ static void create_ap(GDBusProxy *proxy)
        const char *path = g_dbus_proxy_get_path(proxy);
        struct iwd_ap *iwdap;
 
-       iwdap = g_try_new0(struct iwd_ap, 1);
-       if (!iwdap) {
-               connman_error("Out of memory creating IWD access point");
-               return;
-       }
+       iwdap = g_new0(struct iwd_ap, 1);
        iwdap->index = -1;
 
        iwdap->path = g_strdup(path);