summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-05-20 14:59:34 -0700
committerMarcel Holtmann <marcel@holtmann.org>2009-05-20 14:59:34 -0700
commitcbd27635e12481b9f3eef2167ec62d111fdb4b70 (patch)
tree85a6eabbd8dae7ad15282bef5436dca5c96a8441 /src
parent047b77e08e636a4ac1d1857effbb2ca409201d5f (diff)
downloadconnman-cbd27635e12481b9f3eef2167ec62d111fdb4b70.tar.gz
connman-cbd27635e12481b9f3eef2167ec62d111fdb4b70.tar.bz2
connman-cbd27635e12481b9f3eef2167ec62d111fdb4b70.zip
Fix transition of network connection state
Diffstat (limited to 'src')
-rw-r--r--src/network.c102
1 files changed, 63 insertions, 39 deletions
diff --git a/src/network.c b/src/network.c
index 3f9b6f93..bffa5504 100644
--- a/src/network.c
+++ b/src/network.c
@@ -655,6 +655,34 @@ connman_bool_t connman_network_get_available(struct connman_network *network)
return network->available;
}
+/**
+ * connman_network_set_associating:
+ * @network: network structure
+ * @associating: associating state
+ *
+ * Change associating state of network
+ */
+int connman_network_set_associating(struct connman_network *network,
+ connman_bool_t associating)
+{
+ DBG("network %p associating %d", network, associating);
+
+ if (network->associating == associating)
+ return -EALREADY;
+
+ network->associating = associating;
+
+ if (associating == TRUE) {
+ struct connman_service *service;
+
+ service = __connman_service_lookup_from_network(network);
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_ASSOCIATION);
+ }
+
+ return 0;
+}
+
static gboolean set_connected(gpointer user_data)
{
struct connman_network *network = user_data;
@@ -710,34 +738,6 @@ static gboolean set_connected(gpointer user_data)
}
/**
- * connman_network_set_associating:
- * @network: network structure
- * @associating: associating state
- *
- * Change associating state of network
- */
-int connman_network_set_associating(struct connman_network *network,
- connman_bool_t associating)
-{
- DBG("network %p associating %d", network, associating);
-
- if (network->associating == associating)
- return -EALREADY;
-
- network->associating = associating;
-
- if (associating == TRUE) {
- struct connman_service *service;
-
- service = __connman_service_lookup_from_network(network);
- __connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_ASSOCIATION);
- }
-
- return 0;
-}
-
-/**
* connman_network_set_connected:
* @network: network structure
* @connected: connected state
@@ -806,32 +806,56 @@ connman_bool_t connman_network_get_connected(struct connman_network *network)
*/
int __connman_network_connect(struct connman_network *network)
{
+ int err;
+
+ DBG("network %p", network);
+
if (network->connected == TRUE)
return -EALREADY;
- if (network->driver && network->driver->connect)
- return network->driver->connect(network);
+ if (network->driver == NULL)
+ return -EUNATCH;
- network->connected = TRUE;
+ if (network->driver->connect == NULL)
+ return -ENOSYS;
- return 0;
+ err = network->driver->connect(network);
+ if (err == 0) {
+ network->connected = TRUE;
+ set_connected(network);
+ }
+
+ return err;
}
+/**
+ * __connman_network_disconnect:
+ * @network: network structure
+ *
+ * Disconnect network
+ */
int __connman_network_disconnect(struct connman_network *network)
{
+ int err;
+
+ DBG("network %p", network);
+
if (network->connected == FALSE)
return -ENOTCONN;
- __connman_device_set_network(network->device, NULL);
-
- connman_element_unregister_children(&network->element);
+ if (network->driver == NULL)
+ return -EUNATCH;
- if (network->driver && network->driver->disconnect)
- return network->driver->disconnect(network);
+ if (network->driver->disconnect == NULL)
+ return -ENOSYS;
- network->connected = FALSE;
+ err = network->driver->disconnect(network);
+ if (err == 0) {
+ network->connected = FALSE;
+ set_connected(network);
+ }
- return 0;
+ return err;
}
/**