summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-07-29 14:27:16 +0200
committerMarcel Holtmann <marcel@holtmann.org>2009-07-29 14:27:16 +0200
commit53c867d7528e68f23419c9d5c7161f9703b654bf (patch)
tree41dc536fb3c1a250c2c758e4944c073f38355eb3
parentb8885a948923aa78f9d91f309556ea1c8843b050 (diff)
downloadconnman-53c867d7528e68f23419c9d5c7161f9703b654bf.tar.gz
connman-53c867d7528e68f23419c9d5c7161f9703b654bf.tar.bz2
connman-53c867d7528e68f23419c9d5c7161f9703b654bf.zip
Add support for PassphraseRequired property
-rw-r--r--doc/service-api.txt17
-rw-r--r--src/service.c98
2 files changed, 109 insertions, 6 deletions
diff --git a/doc/service-api.txt b/doc/service-api.txt
index dde474f2..7a350eea 100644
--- a/doc/service-api.txt
+++ b/doc/service-api.txt
@@ -170,8 +170,21 @@ Properties string State [readonly]
If the service type is WiFi, then this property
can be used to store a passphrase.
- This property is still experimental and might be
- removed in future version.
+ No PropertyChanged signals will be send for this
+ property. The PassphraseRequired property should
+ be monitored instead.
+
+ This property might also not always be included
+ since it is protected by a different security policy.
+
+ boolean PassphraseRequired [readonly]
+
+ If the service type is WiFi, then this property
+ indicates if a passphrase is required.
+
+ If a passphrase has been set already or if no
+ passphrase is needed, then this property will
+ be set to false.
uint8 Strength [readonly]
diff --git a/src/service.c b/src/service.c
index d688dd18..899212c4 100644
--- a/src/service.c
+++ b/src/service.c
@@ -290,12 +290,64 @@ static void strength_changed(struct connman_service *service)
g_dbus_send_message(connection, signal);
}
+static void passphrase_changed(struct connman_service *service)
+{
+ DBusMessage *signal;
+ DBusMessageIter entry, value;
+ dbus_bool_t required;
+ const char *key = "PassphraseRequired";
+
+ if (service->path == NULL)
+ return;
+
+ switch (service->type) {
+ case CONNMAN_SERVICE_TYPE_UNKNOWN:
+ case CONNMAN_SERVICE_TYPE_ETHERNET:
+ case CONNMAN_SERVICE_TYPE_WIMAX:
+ case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ return;
+ case CONNMAN_SERVICE_TYPE_WIFI:
+ required = FALSE;
+
+ 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)
+ required = TRUE;
+ break;
+ }
+ break;
+ }
+
+ signal = dbus_message_new_signal(service->path,
+ CONNMAN_SERVICE_INTERFACE, "PropertyChanged");
+ if (signal == NULL)
+ return;
+
+ dbus_message_iter_init_append(signal, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+ dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+ DBUS_TYPE_BOOLEAN_AS_STRING, &value);
+ dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &required);
+ dbus_message_iter_close_container(&entry, &value);
+
+ g_dbus_send_message(connection, signal);
+}
+
static DBusMessage *get_properties(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
struct connman_service *service = user_data;
DBusMessage *reply;
DBusMessageIter array, dict;
+ dbus_bool_t required;
const char *str;
DBG("service %p", service);
@@ -347,12 +399,39 @@ static DBusMessage *get_properties(DBusConnection *conn,
connman_dbus_dict_append_variant(&dict, "Name",
DBUS_TYPE_STRING, &service->name);
- if (service->passphrase != NULL &&
- __connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
- connman_dbus_dict_append_variant(&dict, "Passphrase",
+ switch (service->type) {
+ case CONNMAN_SERVICE_TYPE_UNKNOWN:
+ 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:
+ if (service->passphrase != NULL &&
+ __connman_security_check_privilege(msg,
+ CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
+ connman_dbus_dict_append_variant(&dict, "Passphrase",
DBUS_TYPE_STRING, &service->passphrase);
+ required = FALSE;
+
+ 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)
+ required = TRUE;
+ break;
+ }
+
+ connman_dbus_dict_append_variant(&dict, "PassphraseRequired",
+ DBUS_TYPE_BOOLEAN, &required);
+ break;
+ }
+
__connman_ipconfig_append_ipv4(service->ipconfig, &dict, "IPv4.");
dbus_message_iter_close_container(&array, &dict);
@@ -398,6 +477,8 @@ static DBusMessage *set_property(DBusConnection *conn,
g_free(service->passphrase);
service->passphrase = g_strdup(passphrase);
+ passphrase_changed(service);
+
if (service->network != NULL)
connman_network_set_string(service->network,
"WiFi.Passphrase", service->passphrase);
@@ -443,6 +524,13 @@ static DBusMessage *clear_property(DBusConnection *conn,
g_get_current_time(&service->modified);
__connman_storage_save_service(service);
+ } else if (g_str_equal(name, "Passphrase") == TRUE) {
+ g_free(service->passphrase);
+ service->passphrase = NULL;
+
+ passphrase_changed(service);
+
+ __connman_storage_save_service(service);
} else
return __connman_error_invalid_property(msg);
@@ -679,6 +767,8 @@ static DBusMessage *remove_service(DBusConnection *conn,
g_free(service->passphrase);
service->passphrase = NULL;
+ passphrase_changed(service);
+
connman_service_set_favorite(service, FALSE);
__connman_storage_save_service(service);