#include <gdbus.h>
#define CONNMAN_API_SUBJECT_TO_CHANGE
-#include <connman/log.h>
+#include <connman/device.h>
#include <connman/dbus.h>
+#include <connman/log.h>
#include "inet.h"
#include "supplicant.h"
#define IEEE80211_CAP_IBSS 0x0002
#define IEEE80211_CAP_PRIVACY 0x0010
-static GSList *driver_list = NULL;
-
-static void process_state_change(struct connman_device *device,
- enum supplicant_state state)
-{
- GSList *list;
-
- for (list = driver_list; list; list = list->next) {
- struct supplicant_driver *driver = list->data;
-
- if (driver->state_change)
- driver->state_change(device, state);
- }
-}
-
-static void process_clear_results(struct connman_device *device)
-{
- GSList *list;
-
- for (list = driver_list; list; list = list->next) {
- struct supplicant_driver *driver = list->data;
-
- if (driver->clear_results)
- driver->clear_results(device);
- }
-}
-
-static void process_scan_result(struct connman_device *device,
- struct supplicant_network *network)
-{
- GSList *list;
-
- for (list = driver_list; list; list = list->next) {
- struct supplicant_driver *driver = list->data;
+#define SUPPLICANT_NAME "fi.epitest.hostap.WPASupplicant"
+#define SUPPLICANT_INTF "fi.epitest.hostap.WPASupplicant"
+#define SUPPLICANT_PATH "/fi/epitest/hostap/WPASupplicant"
+
+enum supplicant_state {
+ STATE_INACTIVE,
+ STATE_SCANNING,
+ STATE_ASSOCIATING,
+ STATE_ASSOCIATED,
+ STATE_4WAY_HANDSHAKE,
+ STATE_GROUP_HANDSHAKE,
+ STATE_COMPLETED,
+ STATE_DISCONNECTED,
+};
- if (driver->scan_result)
- driver->scan_result(device, network);
- }
-}
+struct supplicant_result {
+ char *identifier;
+ unsigned char *ssid;
+ unsigned int ssid_len;
+ dbus_uint16_t capabilities;
+ gboolean adhoc;
+ gboolean has_wep;
+ gboolean has_wpa;
+ gboolean has_rsn;
+ dbus_int32_t quality;
+ dbus_int32_t noise;
+ dbus_int32_t level;
+ dbus_int32_t maxrate;
+};
struct supplicant_task {
int ifindex;
gboolean created;
gchar *network;
enum supplicant_state state;
+ GSList *scan_results;
};
static GSList *task_list = NULL;
return 0;
}
-static void extract_ssid(struct supplicant_network *network,
- DBusMessageIter *value)
+static void extract_ssid(DBusMessageIter *value,
+ struct supplicant_result *result)
{
DBusMessageIter array;
unsigned char *ssid;
if (ssid_len < 1)
return;
- network->ssid = g_try_malloc(ssid_len);
- if (network->ssid == NULL)
+ result->ssid = g_try_malloc(ssid_len);
+ if (result->ssid == NULL)
return;
- memcpy(network->ssid, ssid, ssid_len);
- network->ssid_len = ssid_len;
+ memcpy(result->ssid, ssid, ssid_len);
+ result->ssid_len = ssid_len;
- network->identifier = g_try_malloc0(ssid_len + 1);
- if (network->identifier == NULL)
+ result->identifier = g_try_malloc0(ssid_len + 1);
+ if (result->identifier == NULL)
return;
- memcpy(network->identifier, ssid, ssid_len);
+ memcpy(result->identifier, ssid, ssid_len);
}
-static void extract_wpaie(struct supplicant_network *network,
- DBusMessageIter *value)
+static void extract_wpaie(DBusMessageIter *value,
+ struct supplicant_result *result)
{
DBusMessageIter array;
unsigned char *ie;
dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
if (ie_len > 0)
- network->has_wpa = TRUE;
+ result->has_wpa = TRUE;
}
-static void extract_rsnie(struct supplicant_network *network,
- DBusMessageIter *value)
+static void extract_rsnie(DBusMessageIter *value,
+ struct supplicant_result *result)
{
DBusMessageIter array;
unsigned char *ie;
dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
if (ie_len > 0)
- network->has_rsn = TRUE;
+ result->has_rsn = TRUE;
}
-static void extract_capabilites(struct supplicant_network *network,
- DBusMessageIter *value)
+static void extract_capabilites(DBusMessageIter *value,
+ struct supplicant_result *result)
{
- dbus_message_iter_get_basic(value, &network->capabilities);
+ dbus_message_iter_get_basic(value, &result->capabilities);
- if (network->capabilities & IEEE80211_CAP_ESS)
- network->adhoc = FALSE;
- else if (network->capabilities & IEEE80211_CAP_IBSS)
- network->adhoc = TRUE;
+ if (result->capabilities & IEEE80211_CAP_ESS)
+ result->adhoc = FALSE;
+ else if (result->capabilities & IEEE80211_CAP_IBSS)
+ result->adhoc = TRUE;
- if (network->capabilities & IEEE80211_CAP_PRIVACY)
- network->has_wep = TRUE;
+ if (result->capabilities & IEEE80211_CAP_PRIVACY)
+ result->has_wep = TRUE;
}
+static int get_properties(struct supplicant_task *task);
+
static void properties_reply(DBusPendingCall *call, void *user_data)
{
struct supplicant_task *task = user_data;
- struct supplicant_network *network;
+ struct supplicant_result result;
+ struct connman_network *network;
DBusMessage *reply;
DBusMessageIter array, dict;
+ char *temp = NULL;
+ unsigned char strength;
+ unsigned int i;
DBG("task %p", task);
reply = dbus_pending_call_steal_reply(call);
+ if (reply == NULL) {
+ get_properties(task);
+ return;
+ }
- network = g_try_new0(struct supplicant_network, 1);
- if (network == NULL)
- goto done;
+ memset(&result, 0, sizeof(result));
dbus_message_iter_init(reply, &array);
*/
if (g_str_equal(key, "ssid") == TRUE)
- extract_ssid(network, &value);
+ extract_ssid(&value, &result);
else if (g_str_equal(key, "wpaie") == TRUE)
- extract_wpaie(network, &value);
+ extract_wpaie(&value, &result);
else if (g_str_equal(key, "rsnie") == TRUE)
- extract_rsnie(network, &value);
+ extract_rsnie(&value, &result);
else if (g_str_equal(key, "capabilities") == TRUE)
- extract_capabilites(network, &value);
+ extract_capabilites(&value, &result);
else if (g_str_equal(key, "quality") == TRUE)
- dbus_message_iter_get_basic(&value, &network->quality);
+ dbus_message_iter_get_basic(&value, &result.quality);
else if (g_str_equal(key, "noise") == TRUE)
- dbus_message_iter_get_basic(&value, &network->noise);
+ dbus_message_iter_get_basic(&value, &result.noise);
else if (g_str_equal(key, "level") == TRUE)
- dbus_message_iter_get_basic(&value, &network->level);
+ dbus_message_iter_get_basic(&value, &result.level);
else if (g_str_equal(key, "maxrate") == TRUE)
- dbus_message_iter_get_basic(&value, &network->maxrate);
-
+ dbus_message_iter_get_basic(&value, &result.maxrate);
dbus_message_iter_next(&dict);
}
- process_scan_result(task->device, network);
+ if (result.identifier == NULL)
+ goto done;
+
+ if (result.identifier[0] == '\0')
+ goto done;
+
+ temp = g_strdup(result.identifier);
+ if (temp == NULL)
+ goto done;
+
+ for (i = 0; i < strlen(temp); i++) {
+ char tmp = temp[i];
+ if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
+ (tmp < 'a' || tmp > 'z'))
+ temp[i] = '_';
+ }
+
+ strength = result.quality;
+
+ network = connman_device_get_network(task->device, temp);
+ if (network == NULL) {
+ const char *mode, *security;
+ unsigned char strength;
+
+ network = connman_network_create(temp,
+ CONNMAN_NETWORK_TYPE_WIFI);
+ if (network == NULL)
+ goto done;
+
+ connman_network_set_string(network, "Name", result.identifier);
+
+ connman_network_set_blob(network, "WiFi.SSID",
+ result.ssid, result.ssid_len);
- g_free(network->identifier);
- g_free(network->ssid);
- g_free(network);
+ mode = (result.adhoc == TRUE) ? "adhoc" : "managed";
+ connman_network_set_string(network, "WiFi.Mode", mode);
+
+ if (result.has_rsn == TRUE)
+ security = "wpa2";
+ else if (result.has_wpa == TRUE)
+ security = "wpa";
+ else if (result.has_wep == TRUE)
+ security = "wep";
+ else
+ security = "none";
+ connman_network_set_string(network, "WiFi.Security", security);
+
+ DBG("%s (%s %s) strength %d", result.identifier, mode,
+ security, strength);
+
+ if (connman_device_add_network(task->device, network) < 0) {
+ connman_network_unref(network);
+ goto done;
+ }
+ }
+
+ connman_network_set_uint8(network, "Strength", strength);
done:
+ g_free(result.identifier);
+ g_free(result.ssid);
+ g_free(temp);
+
dbus_message_unref(reply);
+
+ get_properties(task);
}
-static int get_network_properties(struct supplicant_task *task,
- const char *path)
+static int get_properties(struct supplicant_task *task)
{
DBusMessage *message;
DBusPendingCall *call;
+ char *path;
+
+ path = g_slist_nth_data(task->scan_results, 0);
+ if (path == NULL) {
+ connman_device_set_scanning(task->device, FALSE);
+ return 0;
+ }
message = dbus_message_new_method_call(SUPPLICANT_NAME, path,
SUPPLICANT_INTF ".BSSID",
"properties");
+
+ task->scan_results = g_slist_remove(task->scan_results, path);
+ g_free(path);
+
if (message == NULL)
return -ENOMEM;
DBG("task %p", task);
reply = dbus_pending_call_steal_reply(call);
+ if (reply == NULL) {
+ connman_device_set_scanning(task->device, FALSE);
+ return;
+ }
dbus_error_init(&error);
dbus_error_free(&error);
} else
connman_error("Wrong arguments for scan result");
+ connman_device_set_scanning(task->device, FALSE);
goto done;
}
- process_clear_results(task->device);
+ for (i = 0; i < num_results; i++) {
+ char *path = g_strdup(results[i]);
+ if (path == NULL)
+ continue;
- for (i = 0; i < num_results; i++)
- get_network_properties(task, results[i]);
+ task->scan_results = g_slist_append(task->scan_results, path);
+ }
g_strfreev(results);
+ get_properties(task);
+
done:
dbus_message_unref(reply);
}
return -EIO;
}
+ connman_device_set_scanning(task->device, TRUE);
+
dbus_pending_call_set_notify(call, scan_results_reply, task, NULL);
dbus_message_unref(message);
else if (g_str_equal(state, "DISCONNECTED") == TRUE)
task->state = STATE_DISCONNECTED;
- process_state_change(task->device, task->state);
+ if (task->state == STATE_SCANNING)
+ connman_device_set_scanning(task->device, TRUE);
switch (task->state) {
case STATE_COMPLETED:
dbus_message_unref(message);
}
+static GSList *driver_list = NULL;
+
static void supplicant_probe(DBusConnection *conn, void *user_data)
{
GSList *list;
#include <config.h>
#endif
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <linux/if_arp.h>
-#include <linux/wireless.h>
-
#include <dbus/dbus.h>
#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/plugin.h>
#include <connman/device.h>
-#include <connman/driver.h>
#include <connman/log.h>
#include "inet.h"
#define INACTIVE_TIMEOUT 12 /* in seconds */
struct wifi_data {
- GSList *current;
- GSList *pending;
- guint cleanup_timer;
- guint inactive_timer;
- gchar *identifier;
- gboolean connected;
+ char *identifier;
+ connman_bool_t connected;
};
-static int network_probe(struct connman_element *element)
+static int network_probe(struct connman_network *network)
{
- DBG("element %p name %s", element, element->name);
+ DBG("network %p", network);
return 0;
}
-static void network_remove(struct connman_element *element)
+static void network_remove(struct connman_network *network)
{
- DBG("element %p name %s", element, element->name);
+ DBG("network %p", network);
}
-static int network_enable(struct connman_element *element)
-{
- struct connman_device *device = (struct connman_device *) element->parent;
- char *name, *security = NULL, *passphrase = NULL;
- unsigned char *ssid;
- int ssid_len;
-
- DBG("element %p name %s", element, element->name);
-
- if (connman_element_get_static_property(element,
- "Name", &name) == FALSE)
- return -EIO;
-
- if (connman_element_get_static_array_property(element,
- "WiFi.SSID", &ssid, &ssid_len) == FALSE)
- return -EIO;
-
- if (device != NULL) {
- struct wifi_data *data = connman_device_get_data(device);
-
- if (data != NULL) {
- if (data->connected == TRUE)
- return -EBUSY;
-
- g_free(data->identifier);
- data->identifier = g_strdup(name);
- }
- }
-
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_WIFI_SECURITY, &security);
-
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &passphrase);
-
- DBG("name %s security %s passhprase %s",
- name, security, passphrase);
-
- if (__supplicant_connect(element, ssid, ssid_len,
- security, passphrase) < 0)
- connman_error("Failed to initiate connect");
-
- return 0;
-}
-
-static int network_disable(struct connman_element *element)
-{
- DBG("element %p name %s", element, element->name);
-
- connman_element_unregister_children(element);
-
- __supplicant_disconnect(element);
-
- return 0;
-}
-
-static struct connman_driver network_driver = {
- .name = "wifi-network",
- .type = CONNMAN_ELEMENT_TYPE_NETWORK,
- .subtype = CONNMAN_ELEMENT_SUBTYPE_WIFI,
+static struct connman_network_driver network_driver = {
+ .name = "wifi",
+ .type = CONNMAN_NETWORK_TYPE_WIFI,
.probe = network_probe,
.remove = network_remove,
- .enable = network_enable,
- .disable = network_disable,
};
-static struct connman_element *find_current_element(struct wifi_data *data,
- const char *identifier)
-{
- GSList *list;
-
- for (list = data->current; list; list = list->next) {
- struct connman_element *element = list->data;
-
- if (connman_element_match_static_property(element,
- "Name", &identifier) == TRUE)
- return element;
- }
-
- return NULL;
-}
-
-static struct connman_element *find_pending_element(struct wifi_data *data,
- const char *identifier)
-{
- GSList *list;
-
- for (list = data->pending; list; list = list->next) {
- struct connman_element *element = list->data;
-
- if (connman_element_match_static_property(element,
- "Name", &identifier) == TRUE)
- return element;
- }
-
- return NULL;
-}
-
-static gboolean inactive_scan(gpointer user_data)
-{
- struct connman_device *device = user_data;
- struct wifi_data *data = connman_device_get_data(device);
-
- DBG("device %p", device);
-
- supplicant_scan(device);
-
- data->inactive_timer = 0;
-
- return FALSE;
-}
-
-static void connect_known_networks(struct connman_device *device)
-{
- struct wifi_data *data = connman_device_get_data(device);
- GSList *list;
-
- DBG("device %p", device);
-
- if (data->inactive_timer > 0) {
- g_source_remove(data->inactive_timer);
- data->inactive_timer = 0;
- }
-
- for (list = data->current; list; list = list->next) {
- struct connman_element *element = list->data;
-
- if (element->policy == CONNMAN_ELEMENT_POLICY_AUTO &&
- element->remember == TRUE &&
- element->available == TRUE) {
- if (network_enable(element) == 0)
- return;
- }
- }
-
- data->inactive_timer = g_timeout_add_seconds(INACTIVE_TIMEOUT,
- inactive_scan, device);
-}
-
-static void state_change(struct connman_device *device,
- enum supplicant_state state)
-{
- struct wifi_data *data = connman_device_get_data(device);
- struct connman_element *element;
-
- DBG("device %p state %d", device, state);
-
- if (state == STATE_SCANNING)
- connman_device_set_scanning(device, TRUE);
- else
- connman_device_set_scanning(device, FALSE);
-
- if (data == NULL)
- return;
-
- DBG("identifier %s", data->identifier);
-
- if (data->identifier == NULL)
- goto reconnect;
-
- element = find_current_element(data, data->identifier);
- if (element == NULL)
- goto reconnect;
-
- if (state == STATE_COMPLETED && data->connected == FALSE) {
- struct connman_element *dhcp;
-
- data->connected = TRUE;
- connman_element_set_enabled(element, TRUE);
-
- dhcp = connman_element_create(NULL);
-
- dhcp->type = CONNMAN_ELEMENT_TYPE_DHCP;
- dhcp->index = element->index;
-
- if (connman_element_register(dhcp, element) < 0)
- connman_element_unref(dhcp);
- } else if (state == STATE_INACTIVE || state == STATE_DISCONNECTED) {
- data->connected = FALSE;
- connman_element_set_enabled(element, FALSE);
-
- connman_element_unregister_children(element);
- }
-
-reconnect:
- if (state == STATE_INACTIVE) {
- data->connected = FALSE;
- connect_known_networks(device);
- }
-}
-
-static gboolean cleanup_pending(gpointer user_data)
-{
- struct wifi_data *data = user_data;
- GSList *list;
-
- DBG("");
-
- for (list = data->pending; list; list = list->next) {
- struct connman_element *element = list->data;
-
- DBG("element %p name %s", element, element->name);
-
- connman_element_unregister(element);
- connman_element_unref(element);
- }
-
- g_slist_free(data->pending);
- data->pending = NULL;
-
- data->cleanup_timer = 0;
-
- return FALSE;
-}
-
-static void clear_results(struct connman_device *device)
-{
- struct wifi_data *data = connman_device_get_data(device);
-
- DBG("pending %d", g_slist_length(data->pending));
- DBG("current %d", g_slist_length(data->current));
-
- if (data->cleanup_timer > 0) {
- g_source_remove(data->cleanup_timer);
- cleanup_pending(data);
- }
-
- data->pending = data->current;
- data->current = NULL;
-
- data->cleanup_timer = g_timeout_add_seconds(CLEANUP_TIMEOUT,
- cleanup_pending, data);
-}
-
-static void scan_result(struct connman_device *device,
- struct supplicant_network *network)
-{
- struct wifi_data *data = connman_device_get_data(device);
- struct connman_element *element;
- gchar *temp;
- unsigned int i;
-
- DBG("device %p identifier %s", device, network->identifier);
-
- if (data == NULL)
- return;
-
- if (network->identifier == NULL)
- return;
-
- if (network->identifier[0] == '\0')
- return;
-
- temp = g_strdup(network->identifier);
-
- for (i = 0; i < strlen(temp); i++) {
- char tmp = temp[i];
- if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
- (tmp < 'a' || tmp > 'z'))
- temp[i] = '_';
- }
-
- element = find_pending_element(data, network->identifier);
- if (element == NULL) {
- const char *mode;
-
- element = connman_element_create(temp);
-
- element->type = CONNMAN_ELEMENT_TYPE_NETWORK;
- element->subtype = CONNMAN_ELEMENT_SUBTYPE_WIFI;
- element->index = connman_device_get_index(device);
-
- connman_element_add_static_property(element, "Name",
- DBUS_TYPE_STRING, &network->identifier);
-
- connman_element_add_static_array_property(element, "WiFi.SSID",
- DBUS_TYPE_BYTE, &network->ssid, network->ssid_len);
-
- mode = (network->adhoc == TRUE) ? "adhoc" : "managed";
- connman_element_add_static_property(element, "WiFi.Mode",
- DBUS_TYPE_STRING, &mode);
-
- if (element->wifi.security == NULL) {
- const char *security;
-
- if (network->has_rsn == TRUE)
- security = "wpa2";
- else if (network->has_wpa == TRUE)
- security = "wpa";
- else if (network->has_wep == TRUE)
- security = "wep";
- else
- security = "none";
-
- element->wifi.security = g_strdup(security);
- }
-
- element->strength = network->quality;
-
- connman_element_add_static_property(element, "Strength",
- DBUS_TYPE_BYTE, &element->strength);
-
- DBG("%s (%s %s) strength %d", network->identifier, mode,
- element->wifi.security, element->strength);
-
- if (connman_element_register(element,
- (struct connman_element *) device) < 0) {
- connman_element_unref(element);
- goto done;
- }
- } else {
- data->pending = g_slist_remove(data->pending, element);
-
- if (element->strength != network->quality) {
- element->strength = network->quality;
-
- connman_element_set_static_property(element, "Strength",
- DBUS_TYPE_BYTE, &element->strength);
-
- connman_element_update(element);
- }
- }
-
- data->current = g_slist_append(data->current, element);
-
- element->available = TRUE;
-
-done:
- g_free(temp);
-}
-
static int wifi_probe(struct connman_device *device)
{
struct wifi_data *data;
static int wifi_disable(struct connman_device *device)
{
struct wifi_data *data = connman_device_get_data(device);
- GSList *list;
DBG("device %p", device);
- if (data->cleanup_timer > 0) {
- g_source_remove(data->cleanup_timer);
- cleanup_pending(data);
- }
-
- if (data->inactive_timer > 0) {
- g_source_remove(data->inactive_timer);
- data->inactive_timer = 0;
- }
-
- for (list = data->current; list; list = list->next) {
- struct connman_element *network = list->data;
-
- if (network->enabled == TRUE)
- __supplicant_disconnect(network);
-
- connman_element_unref(network);
- }
-
- g_slist_free(data->current);
- data->current = NULL;
-
connman_element_unregister_children((struct connman_element *) device);
+ data->connected = FALSE;
+
return supplicant_stop(device);
}
.name = "wifi",
.probe = wifi_register,
.remove = wifi_unregister,
-
- .state_change = state_change,
- .clear_results = clear_results,
- .scan_result = scan_result,
};
static int wifi_init(void)
{
int err;
- err = connman_driver_register(&network_driver);
+ err = connman_network_driver_register(&network_driver);
if (err < 0)
return err;
err = supplicant_register(&supplicant);
if (err < 0) {
- connman_driver_unregister(&network_driver);
+ connman_network_driver_unregister(&network_driver);
return err;
}
{
supplicant_unregister(&supplicant);
- connman_driver_unregister(&network_driver);
+ connman_network_driver_unregister(&network_driver);
}
CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,