#include "inet.h"
#include "supplicant.h"
-#define CLEANUP_PENDING_TIMEOUT 8 /* in seconds */
+#define CLEANUP_TIMEOUT 8 /* in seconds */
+#define INACTIVE_TIMEOUT 12 /* in seconds */
struct wifi_data {
GSList *current;
GSList *pending;
- guint timer;
+ guint cleanup_timer;
+ guint inactive_timer;
gchar *identifier;
gboolean connected;
};
static int network_enable(struct connman_element *element)
{
+ struct connman_element *device = element->parent;
char *name, *security = NULL, *passphrase = NULL;
unsigned char *ssid;
int ssid_len;
"WiFi.SSID", &ssid, &ssid_len) == FALSE)
return -EIO;
- if (element->parent != NULL) {
- struct wifi_data *data = connman_element_get_data(element->parent);
-
- if (data->connected == TRUE)
- return -EBUSY;
+ if (device != NULL) {
+ struct wifi_data *data = connman_element_get_data(device);
if (data != NULL) {
+ if (data->connected == TRUE)
+ return -EBUSY;
+
g_free(data->identifier);
data->identifier = g_strdup(name);
}
return NULL;
}
-static void state_change(struct connman_element *parent,
+static gboolean inactive_scan(gpointer user_data)
+{
+ struct connman_element *device = user_data;
+ struct wifi_data *data = connman_element_get_data(device);
+
+ DBG("");
+
+ if (data->cleanup_timer > 0) {
+ g_source_remove(data->cleanup_timer);
+ data->cleanup_timer = 0;
+ }
+
+ __supplicant_scan(device);
+
+ data->inactive_timer = 0;
+
+ return FALSE;
+}
+
+static void state_change(struct connman_element *device,
enum supplicant_state state)
{
- struct wifi_data *data = connman_element_get_data(parent);
+ struct wifi_data *data = connman_element_get_data(device);
struct connman_element *element;
DBG("state %d", state);
+ if ((state == STATE_INACTIVE || state == STATE_DISCONNECTED) &&
+ data->inactive_timer == 0)
+ data->inactive_timer = g_timeout_add_seconds(INACTIVE_TIMEOUT,
+ inactive_scan, device);
+
if (data == NULL)
return;
g_slist_free(data->pending);
data->pending = NULL;
- data->timer = 0;
+ data->cleanup_timer = 0;
return FALSE;
}
-static void clear_results(struct connman_element *parent)
+static void clear_results(struct connman_element *device)
{
- struct wifi_data *data = connman_element_get_data(parent);
+ struct wifi_data *data = connman_element_get_data(device);
DBG("pending %d", g_slist_length(data->pending));
DBG("current %d", g_slist_length(data->current));
data->pending = data->current;
data->current = NULL;
- if (data->timer == 0)
- data->timer = g_timeout_add_seconds(CLEANUP_PENDING_TIMEOUT,
+ if (data->cleanup_timer > 0)
+ return;
+
+ data->cleanup_timer = g_timeout_add_seconds(CLEANUP_TIMEOUT,
cleanup_pending, data);
}
-static void scan_result(struct connman_element *parent,
+static void scan_result(struct connman_element *device,
struct supplicant_network *network)
{
- struct wifi_data *data = connman_element_get_data(parent);
+ struct wifi_data *data = connman_element_get_data(device);
struct connman_element *element;
gchar *temp;
int i;
temp = g_strdup(network->identifier);
for (i = 0; i < strlen(temp); i++) {
- if (temp[i] == ' ' || temp[i] == '.')
- temp[i] = '_';
- else if (temp[i] == '-' || temp[i] == '+')
- temp[i] = '_';
- else if (temp[i] == '!' || temp[i] == '?')
- temp[i] = '_';
- else if (temp[i] == '(' || temp[i] == ')')
- temp[i] = '_';
- else if (g_ascii_isprint(temp[i]) == FALSE)
+ gchar tmp = g_ascii_tolower(temp[i]);
+
+ if (tmp < 'a' || tmp > 'z')
temp[i] = '_';
- temp[i] = g_ascii_tolower(temp[i]);
}
element = find_pending_element(data, network->identifier);
element = connman_element_create(temp);
element->type = CONNMAN_ELEMENT_TYPE_NETWORK;
- element->index = parent->index;
+ element->index = device->index;
connman_element_add_static_property(element, "Name",
DBUS_TYPE_STRING, &network->identifier);
DBG("%s (%s) strength %d", network->identifier,
element->wifi.security, strength);
- connman_element_register(element, parent);
+ connman_element_register(element, device);
} else
data->pending = g_slist_remove(data->pending, element);
DBG("element %p name %s", element, element->name);
- if (data->timer > 0) {
- g_source_remove(data->timer);
- data->timer = 0;
+ if (data->cleanup_timer > 0) {
+ g_source_remove(data->cleanup_timer);
+ data->cleanup_timer = 0;
+ }
+
+ if (data->inactive_timer > 0) {
+ g_source_remove(data->inactive_timer);
+ data->inactive_timer = 0;
}
__supplicant_disconnect(element);