summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-03-13 23:27:05 +0100
committerMarcel Holtmann <marcel@holtmann.org>2008-03-13 23:27:05 +0100
commit044f4199fa31ff8ec4f9c91c051e05fc3cf14d0f (patch)
tree5b0e0a02030e504dd5fae49eb50e1d225d3d4391
parent7b820de508eeac0f7a38dc795dd224e7f283df52 (diff)
downloadconnman-044f4199fa31ff8ec4f9c91c051e05fc3cf14d0f.tar.gz
connman-044f4199fa31ff8ec4f9c91c051e05fc3cf14d0f.tar.bz2
connman-044f4199fa31ff8ec4f9c91c051e05fc3cf14d0f.zip
Use list of known networks to re-connect to
-rw-r--r--src/connman.h2
-rw-r--r--src/iface-storage.c67
-rw-r--r--src/iface.c11
3 files changed, 75 insertions, 5 deletions
diff --git a/src/connman.h b/src/connman.h
index c253a8e3..f9416d2f 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -70,6 +70,8 @@ int __connman_iface_init_via_inet(struct connman_iface *iface);
int __connman_iface_up(struct connman_iface *iface);
int __connman_iface_down(struct connman_iface *iface);
+char *__connman_iface_find_passphrase(struct connman_iface *iface,
+ const char *network);
int __connman_iface_load(struct connman_iface *iface);
int __connman_iface_store(struct connman_iface *iface);
diff --git a/src/iface-storage.c b/src/iface-storage.c
index a5b57a38..7872f7cc 100644
--- a/src/iface-storage.c
+++ b/src/iface-storage.c
@@ -32,10 +32,62 @@
#define GROUP_CONFIG "Config"
+char *__connman_iface_find_passphrase(struct connman_iface *iface,
+ const char *network)
+{
+ GKeyFile *keyfile;
+ gchar *pathname, *result = NULL;
+ gchar **list;
+ gsize list_len;
+ int i;
+
+ DBG("iface %p", iface);
+
+ if (iface->identifier == NULL)
+ return NULL;
+
+ pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
+ iface->identifier);
+ if (pathname == NULL)
+ return NULL;
+
+ keyfile = g_key_file_new();
+
+ g_key_file_set_list_separator(keyfile, ',');
+
+ if (g_key_file_load_from_file(keyfile, pathname, 0, NULL) == FALSE)
+ goto done;
+
+ if (g_key_file_has_group(keyfile, GROUP_CONFIG) == FALSE)
+ goto done;
+
+ list = g_key_file_get_string_list(keyfile, GROUP_CONFIG,
+ "KnownNetworks", &list_len, NULL);
+ for (i = 0; i < list_len; i++)
+ if (g_str_equal(list[i], network) == TRUE) {
+ result = g_key_file_get_string(keyfile, network,
+ "PSK", NULL);
+ if (result == NULL)
+ result = g_strdup("");
+ break;
+ }
+
+ g_strfreev(list);
+
+done:
+ g_key_file_free(keyfile);
+
+ g_free(pathname);
+
+ return result;
+}
+
int __connman_iface_load(struct connman_iface *iface)
{
GKeyFile *keyfile;
gchar *pathname, *str;
+ gchar **list;
+ gsize list_len;
DBG("iface %p", iface);
@@ -49,6 +101,8 @@ int __connman_iface_load(struct connman_iface *iface)
keyfile = g_key_file_new();
+ g_key_file_set_list_separator(keyfile, ',');
+
if (g_key_file_load_from_file(keyfile, pathname, 0, NULL) == FALSE)
goto done;
@@ -61,7 +115,13 @@ int __connman_iface_load(struct connman_iface *iface)
g_free(str);
}
- str = g_key_file_get_string(keyfile, GROUP_CONFIG, "Network", NULL);
+ list = g_key_file_get_string_list(keyfile, GROUP_CONFIG,
+ "KnownNetworks", &list_len, NULL);
+
+ g_strfreev(list);
+
+ str = g_key_file_get_string(keyfile, GROUP_CONFIG,
+ "LastNetwork", NULL);
if (str != NULL) {
g_free(iface->network.identifier);
iface->network.identifier = str;
@@ -93,9 +153,10 @@ static void do_update(GKeyFile *keyfile, struct connman_iface *iface)
if (iface->network.identifier != NULL) {
g_key_file_set_string(keyfile, GROUP_CONFIG,
- "Network", iface->network.identifier);
+ "LastNetwork", iface->network.identifier);
} else
- g_key_file_remove_key(keyfile, GROUP_CONFIG, "Network", NULL);
+ g_key_file_remove_key(keyfile, GROUP_CONFIG,
+ "LastNetwork", NULL);
if (iface->network.identifier != NULL)
g_key_file_set_string(keyfile, iface->network.identifier,
diff --git a/src/iface.c b/src/iface.c
index b9fe5133..a35d22aa 100644
--- a/src/iface.c
+++ b/src/iface.c
@@ -360,6 +360,7 @@ void connman_iface_indicate_station(struct connman_iface *iface,
const char *name, int strength, int security)
{
DBusMessage *signal;
+ char *passphrase;
DBG("iface %p security %d name %s", iface, security, name);
@@ -376,9 +377,15 @@ void connman_iface_indicate_station(struct connman_iface *iface,
dbus_connection_send(connection, signal, NULL);
dbus_message_unref(signal);
- if (g_str_equal(name, iface->network.identifier) == TRUE &&
- iface->state == CONNMAN_IFACE_STATE_SCANNING) {
+ if (iface->state != CONNMAN_IFACE_STATE_SCANNING)
+ return;
+
+ passphrase = __connman_iface_find_passphrase(iface, name);
+ if (passphrase != NULL) {
+ g_free(iface->network.identifier);
iface->network.identifier = g_strdup(name);
+ g_free(iface->network.passphrase);
+ iface->network.passphrase = passphrase;
if (iface->driver->connect) {
iface->driver->connect(iface, &iface->network);