[ofono-autoconnect RFC 8/9] Mark service as failed if connect fails

Pekka.Pessi at nokia.com Pekka.Pessi at nokia.com
Tue Jan 18 10:51:02 PST 2011


From: Pekka Pessi <Pekka.Pessi at nokia.com>

The connman_network/provider_connect() could fail in two different ways,
returning an error code or setting the service state to failed.

Ethernet, WiMax, Bluetooth, VPN, Cellular and WiFi services now get
marked as failed if connect() fails with error code, too. This makes
connman_service_clear_error() and the autoconnect procedure to behave in
consistent manner.
---
 src/service.c |   64 +++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/src/service.c b/src/service.c
index 89c4625..8882157 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2420,6 +2420,9 @@ static DBusMessage *connect_service(DBusConnection *conn,
 				return NULL;
 		}
 
+		if (service->pending == NULL)
+			return NULL;
+
 		if (err != -EINPROGRESS) {
 			dbus_message_unref(service->pending);
 			service->pending = NULL;
@@ -3319,18 +3322,10 @@ static void prepare_8021x(struct connman_service *service)
 							service->phase2);
 }
 
-int __connman_service_connect(struct connman_service *service)
+static int service_connect(struct connman_service *service)
 {
 	int err;
 
-	DBG("service %p", service);
-
-	if (is_connected(service) == TRUE)
-		return -EISCONN;
-
-	if (is_connecting(service) == TRUE)
-		return -EALREADY;
-
 	switch (service->type) {
 	case CONNMAN_SERVICE_TYPE_UNKNOWN:
 	case CONNMAN_SERVICE_TYPE_SYSTEM:
@@ -3396,7 +3391,7 @@ int __connman_service_connect(struct connman_service *service)
 		err = __connman_network_connect(service->network);
 	} else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
 					service->provider != NULL)
-		err = __connman_provider_connect(service->provider);
+		return __connman_provider_connect(service->provider);
 	else
 		return -EOPNOTSUPP;
 
@@ -3404,23 +3399,56 @@ int __connman_service_connect(struct connman_service *service)
 		if (err != -EINPROGRESS) {
 			__connman_ipconfig_disable(service->ipconfig_ipv4);
 			__connman_ipconfig_disable(service->ipconfig_ipv6);
-
 			__connman_stats_service_unregister(service);
-			if (service->userconnect == TRUE)
-				return __connman_agent_report_error(service,
-						error2string(service->error),
-						report_error_cb, NULL);
-			else
-				return err;
 		}
+	}
+
+	return err;
+}
+
+
+int __connman_service_connect(struct connman_service *service)
+{
+	int err;
+
+	DBG("service %p", service);
+
+	if (is_connected(service) == TRUE)
+		return -EISCONN;
+
+	if (is_connecting(service) == TRUE)
+		return -EALREADY;
 
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		return -EINVAL;
+	default:
+		err = service_connect(service);
+	}
+
+	if (err >= 0)
+		return 0;
+
+	if (err == -EINPROGRESS) {
 		service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
 						connect_timeout, service);
 
 		return -EINPROGRESS;
 	}
 
-	return 0;
+	if (err == -ENOKEY)
+		return -ENOKEY;
+
+	if (service->userconnect == TRUE)
+		reply_pending(service, err);
+
+	__connman_service_indicate_state(service,
+				CONNMAN_SERVICE_STATE_FAILURE);
+
+	return err;
 }
 
 int __connman_service_disconnect(struct connman_service *service)
-- 
1.7.1




More information about the connman mailing list