From 0ebfa46648f633da5d933af0c67277ad49ae4376 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 8 Jan 2008 12:48:05 +0100 Subject: [PATCH] Add support for storing the network identifier --- include/iface.h | 2 ++ src/iface-storage.c | 16 ++++++++++++++++ src/iface.c | 12 ++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/iface.h b/include/iface.h index 4e2a30c..a7c9f09 100644 --- a/include/iface.h +++ b/include/iface.h @@ -80,6 +80,7 @@ struct connman_ipv4 { }; struct connman_network { + char *essid; }; struct connman_iface { @@ -93,6 +94,7 @@ struct connman_iface { enum connman_iface_flags flags; enum connman_iface_state state; enum connman_iface_policy policy; + struct connman_network network; struct connman_ipv4 ipv4; struct connman_iface_driver *driver; diff --git a/src/iface-storage.c b/src/iface-storage.c index b7c84c3..ad2cfc5 100644 --- a/src/iface-storage.c +++ b/src/iface-storage.c @@ -60,6 +60,15 @@ int __connman_iface_load(struct connman_iface *iface) } str = g_key_file_get_string(keyfile, iface->identifier, + "Network.ESSID", NULL); + if (str != NULL) { + g_free(iface->network.essid); + iface->network.essid = str; + if (iface->driver->set_network) + iface->driver->set_network(iface, str); + } + + str = g_key_file_get_string(keyfile, iface->identifier, "IPv4.Method", NULL); if (str != NULL) { iface->ipv4.method = __connman_ipv4_string2method(str); @@ -114,6 +123,13 @@ static void do_update(GKeyFile *keyfile, struct connman_iface *iface) str = __connman_iface_policy2string(iface->policy); g_key_file_set_string(keyfile, iface->identifier, "Policy", str); + if (iface->network.essid != NULL) { + g_key_file_set_string(keyfile, iface->identifier, + "Network.ESSID", iface->network.essid); + } else + g_key_file_remove_key(keyfile, iface->identifier, + "Network.ESSID", NULL); + if (iface->ipv4.method != CONNMAN_IPV4_METHOD_UNKNOWN) { str = __connman_ipv4_method2string(iface->ipv4.method); g_key_file_set_string(keyfile, iface->identifier, diff --git a/src/iface.c b/src/iface.c index df020a3..b440d52 100644 --- a/src/iface.c +++ b/src/iface.c @@ -663,6 +663,7 @@ static DBusMessage *set_network(DBusConnection *conn, struct connman_iface *iface = data; DBusMessage *reply; DBusMessageIter array, dict; + gboolean changed = FALSE; DBG("conn %p", conn); @@ -685,8 +686,11 @@ static DBusMessage *set_network(DBusConnection *conn, dbus_message_iter_get_basic(&value, &val); if (g_strcasecmp(key, "ESSID") == 0) { + g_free(iface->network.essid); + iface->network.essid = g_strdup(val); if (iface->driver->set_network) iface->driver->set_network(iface, val); + changed = TRUE; } if (g_strcasecmp(key, "PSK") == 0) { @@ -703,6 +707,9 @@ static DBusMessage *set_network(DBusConnection *conn, dbus_message_append_args(reply, DBUS_TYPE_INVALID); + if (changed == TRUE) + __connman_iface_store(iface); + return reply; } @@ -743,6 +750,7 @@ static void device_free(void *data) g_free(iface->udi); g_free(iface->sysfs); g_free(iface->identifier); + g_free(iface->network.essid); g_free(iface->device.driver); g_free(iface->device.vendor); g_free(iface->device.product); @@ -834,10 +842,10 @@ static int probe_device(LibHalContext *ctx, __connman_iface_init_via_inet(iface); - __connman_iface_load(iface); - iface->driver = driver; + __connman_iface_load(iface); + conn = libhal_ctx_get_dbus_connection(ctx); g_dbus_register_object(conn, iface->path, iface, device_free); -- 2.7.4