diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-01-21 01:55:57 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-01-21 01:55:57 +0100 |
commit | 3b6dd9aa9030e27513a4635e7a718feb4eea5ba1 (patch) | |
tree | 74a834d307802b389e36b81a72eda08822341c91 /src | |
parent | acd4243c17aa6a9896e2e7de41deb3369e8144c6 (diff) | |
download | connman-3b6dd9aa9030e27513a4635e7a718feb4eea5ba1.tar.gz connman-3b6dd9aa9030e27513a4635e7a718feb4eea5ba1.tar.bz2 connman-3b6dd9aa9030e27513a4635e7a718feb4eea5ba1.zip |
Add support for disconnecting networks first
Diffstat (limited to 'src')
-rw-r--r-- | src/connman.h | 4 | ||||
-rw-r--r-- | src/device.c | 19 | ||||
-rw-r--r-- | src/network.c | 30 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/connman.h b/src/connman.h index 912aea1a..b007cca5 100644 --- a/src/connman.h +++ b/src/connman.h @@ -163,6 +163,8 @@ void __connman_device_cleanup(void); void __connman_device_increase_connections(struct connman_device *device); void __connman_device_decrease_connections(struct connman_device *device); +void __connman_device_disconnect(struct connman_device *device); + connman_bool_t __connman_device_has_driver(struct connman_device *device); int __connman_device_set_offlinemode(connman_bool_t offlinemode); @@ -175,6 +177,8 @@ void __connman_network_cleanup(void); void __connman_network_set_device(struct connman_network *network, struct connman_device *device); +int __connman_network_disconnect(struct connman_network *network); + connman_bool_t __connman_network_has_driver(struct connman_network *network); #include <connman/rtnl.h> diff --git a/src/device.c b/src/device.c index ea72b251..74196b72 100644 --- a/src/device.c +++ b/src/device.c @@ -996,6 +996,25 @@ int connman_device_set_carrier(struct connman_device *device, return 0; } +void __connman_device_disconnect(struct connman_device *device) +{ + GHashTableIter iter; + gpointer key, value; + + DBG("device %p", device); + + g_hash_table_iter_init(&iter, device->networks); + + while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) { + struct connman_network *network = value; + + if (connman_network_get_connected(network) == FALSE) + continue; + + __connman_network_disconnect(network); + } +} + static void connect_known_network(struct connman_device *device) { struct connman_network *network = NULL; diff --git a/src/network.c b/src/network.c index 3e27e7ef..6571da65 100644 --- a/src/network.c +++ b/src/network.c @@ -233,6 +233,12 @@ static DBusMessage *do_connect(DBusConnection *conn, return __connman_error_failed(msg); if (network->driver && network->driver->connect) { + enum connman_device_mode mode; + + mode = connman_device_get_mode(network->device); + if (mode == CONNMAN_DEVICE_MODE_NETWORK_SINGLE) + __connman_device_disconnect(network->device); + err = network->driver->connect(network); if (err < 0 && err != -EINPROGRESS) return __connman_error_failed(msg); @@ -684,6 +690,17 @@ int connman_network_set_connected(struct connman_network *network, } /** + * connman_network_get_connected: + * @network: network structure + * + * Get network connection status + */ +connman_bool_t connman_network_get_connected(struct connman_network *network) +{ + return network->connected; +} + +/** * connman_network_set_remember: * @network: network structure * @remember: remember state @@ -756,6 +773,19 @@ int connman_network_connect(struct connman_network *network) return 0; } +int __connman_network_disconnect(struct connman_network *network) +{ + if (network->connected == FALSE) + return -ENOTCONN; + + if (network->driver && network->driver->disconnect) + return network->driver->disconnect(network); + + network->connected = FALSE; + + return 0; +} + /** * connman_network_set_string: * @network: network structure |