Fix error handling in case when passphrase is required
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 29 Jul 2009 12:33:56 +0000 (14:33 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 29 Jul 2009 12:33:56 +0000 (14:33 +0200)
src/connman.h
src/error.c
src/service.c

index 2bbbf21..38e78ec 100644 (file)
@@ -35,6 +35,7 @@ void __connman_dbus_cleanup(void);
 DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum);
 DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg);
 DBusMessage *__connman_error_permission_denied(DBusMessage *msg);
+DBusMessage *__connman_error_passphrase_required(DBusMessage *msg);
 DBusMessage *__connman_error_not_supported(DBusMessage *msg);
 DBusMessage *__connman_error_not_implemented(DBusMessage *msg);
 DBusMessage *__connman_error_no_carrier(DBusMessage *msg);
index 77a32ab..c250d25 100644 (file)
@@ -55,6 +55,8 @@ DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum)
                return __connman_error_operation_timeout(msg);
        case EALREADY:
                return __connman_error_in_progress(msg);
+       case ENOKEY:
+               return __connman_error_passphrase_required(msg);
        }
 
        return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
@@ -73,6 +75,12 @@ DBusMessage *__connman_error_permission_denied(DBusMessage *msg)
                                ".PermissionDenied", "Permission denied");
 }
 
+DBusMessage *__connman_error_passphrase_required(DBusMessage *msg)
+{
+       return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+                               ".PassphraseRequired", "Passphrase required");
+}
+
 DBusMessage *__connman_error_not_supported(DBusMessage *msg)
 {
        return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
index 899212c..f9cb020 100644 (file)
@@ -1199,6 +1199,29 @@ int __connman_service_connect(struct connman_service *service)
        if (is_connecting(service) == TRUE)
                return -EALREADY;
 
+       switch (service->type) {
+       case CONNMAN_SERVICE_TYPE_UNKNOWN:
+               return -EINVAL;
+       case CONNMAN_SERVICE_TYPE_ETHERNET:
+       case CONNMAN_SERVICE_TYPE_WIMAX:
+       case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+       case CONNMAN_SERVICE_TYPE_CELLULAR:
+               break;
+       case CONNMAN_SERVICE_TYPE_WIFI:
+               switch (service->security) {
+               case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+               case CONNMAN_SERVICE_SECURITY_NONE:
+                       break;
+               case CONNMAN_SERVICE_SECURITY_WEP:
+               case CONNMAN_SERVICE_SECURITY_WPA:
+               case CONNMAN_SERVICE_SECURITY_RSN:
+                       if (service->passphrase == NULL)
+                               return -ENOKEY;
+                       break;
+               }
+               break;
+       }
+
        if (service->network != NULL) {
                if (prepare_network(service) == FALSE)
                        return -EINVAL;