*
* Connection Manager
*
- * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <config.h>
#endif
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/if_arp.h>
+#include <linux/wireless.h>
+#include <net/ethernet.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP 0x10000
+#endif
+
#include <dbus/dbus.h>
+#include <glib.h>
+#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/plugin.h>
-#include <connman/driver.h>
+#include <connman/inet.h>
+#include <connman/device.h>
+#include <connman/rtnl.h>
#include <connman/log.h>
-
-static DBusConnection *connection;
-
-#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,
+#include <connman/option.h>
+
+#include <gsupplicant/gsupplicant.h>
+
+#define CLEANUP_TIMEOUT 8 /* in seconds */
+#define INACTIVE_TIMEOUT 12 /* in seconds */
+
+struct wifi_data {
+ char *identifier;
+ struct connman_device *device;
+ struct connman_network *network;
+ GSupplicantInterface *interface;
+ connman_bool_t connected;
+ int index;
+ unsigned flags;
+ unsigned int watch;
};
-struct supplicant_task {
+static int get_bssid(struct connman_device *device,
+ unsigned char *bssid, unsigned int *bssid_len)
+{
+ struct iwreq wrq;
+ char *ifname;
int ifindex;
- gchar *ifname;
- enum supplicant_state state;
- gchar *path;
- gboolean created;
-};
+ int fd, err;
+
+ ifindex = connman_device_get_index(device);
+ if (ifindex < 0)
+ return -EINVAL;
+
+ ifname = connman_inet_ifname(ifindex);
+ if (ifname == NULL)
+ return -EINVAL;
+
+ fd = socket(PF_INET, SOCK_DGRAM, 0);
+ if (fd < 0) {
+ g_free(ifname);
+ return -EINVAL;
+ }
+
+ memset(&wrq, 0, sizeof(wrq));
+ strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
+
+ err = ioctl(fd, SIOCGIWAP, &wrq);
+
+ g_free(ifname);
+ close(fd);
-static GStaticMutex task_mutex = G_STATIC_MUTEX_INIT;
-static GSList *task_list = NULL;
+ if (err < 0)
+ return -EIO;
+
+ memcpy(bssid, wrq.u.ap_addr.sa_data, ETH_ALEN);
+ *bssid_len = ETH_ALEN;
+
+ return 0;
+}
-static struct supplicant_task *find_task_by_index(int index)
+static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
{
- GSList *list;
+ struct connman_device *device = user_data;
+ struct wifi_data *wifi = connman_device_get_data(device);
- for (list = task_list; list; list = list->next) {
- struct supplicant_task *task = list->data;
+ DBG("index %d flags %d change %d", wifi->index, flags, change);
- if (task->ifindex == index)
- return task;
+ if (!change)
+ return;
+
+ if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
+ if (flags & IFF_UP)
+ DBG("interface up");
+ else
+ DBG("interface down");
}
- return NULL;
+ if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
+ if (flags & IFF_LOWER_UP)
+ DBG("carrier on");
+ else
+ DBG("carrier off");
+ }
+
+ wifi->flags = flags;
}
-static int get_interface(struct supplicant_task *task)
+static int wifi_probe(struct connman_device *device)
{
- DBusMessage *message, *reply;
- DBusError error;
- const char *path;
+ struct wifi_data *wifi;
- DBG("task %p", task);
+ DBG("device %p", device);
- message = dbus_message_new_method_call(SUPPLICANT_NAME, SUPPLICANT_PATH,
- SUPPLICANT_INTF, "getInterface");
- if (message == NULL)
+ wifi = g_try_new0(struct wifi_data, 1);
+ if (wifi == NULL)
return -ENOMEM;
- dbus_message_append_args(message, DBUS_TYPE_STRING, &task->ifname,
- DBUS_TYPE_INVALID);
+ wifi->connected = FALSE;
- dbus_error_init(&error);
+ connman_device_set_data(device, wifi);
+ wifi->device = connman_device_ref(device);
- reply = dbus_connection_send_with_reply_and_block(connection,
- message, -1, &error);
- if (reply == NULL) {
- if (dbus_error_is_set(&error) == TRUE) {
- connman_error("%s", error.message);
- dbus_error_free(&error);
- } else
- connman_error("Failed to get interface");
- dbus_message_unref(message);
- return -EIO;
- }
+ wifi->index = connman_device_get_index(device);
+ wifi->flags = 0;
- dbus_message_unref(message);
+ wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
+ wifi_newlink, device);
- dbus_error_init(&error);
+ return 0;
+}
- if (dbus_message_get_args(reply, &error, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID) == FALSE) {
- if (dbus_error_is_set(&error) == TRUE) {
- connman_error("%s", error.message);
- dbus_error_free(&error);
- } else
- connman_error("Wrong arguments for interface");
- dbus_message_unref(reply);
- return -EIO;
- }
+static void wifi_remove(struct connman_device *device)
+{
+ struct wifi_data *wifi = connman_device_get_data(device);
- DBG("path %s", path);
+ DBG("device %p", device);
- task->path = g_strdup(path);
- task->created = FALSE;
+ connman_device_set_data(device, NULL);
+ connman_device_unref(wifi->device);
+ connman_rtnl_remove_watch(wifi->watch);
- dbus_message_unref(reply);
+ g_free(wifi->identifier);
+ g_free(wifi);
+}
- return 0;
+static void interface_create_callback(int result,
+ GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct wifi_data *wifi = user_data;
+
+ DBG("result %d ifname %s", result,
+ g_supplicant_interface_get_ifname(interface));
+
+ if (result < 0)
+ return;
+
+ wifi->interface = interface;
+ g_supplicant_interface_set_data(interface, wifi);
}
-static int add_interface(struct supplicant_task *task)
+static void interface_remove_callback(int result,
+ GSupplicantInterface *interface,
+ void *user_data)
{
- DBusMessage *message, *reply;
- DBusError error;
- const char *path;
+ struct wifi_data *wifi = user_data;
- DBG("task %p", task);
+ DBG("result %d", result);
- message = dbus_message_new_method_call(SUPPLICANT_NAME, SUPPLICANT_PATH,
- SUPPLICANT_INTF, "addInterface");
- if (message == NULL)
- return -ENOMEM;
+ if (result < 0)
+ return;
- dbus_error_init(&error);
+ wifi->interface = NULL;
+}
- dbus_message_append_args(message, DBUS_TYPE_STRING, &task->ifname,
- DBUS_TYPE_INVALID);
- reply = dbus_connection_send_with_reply_and_block(connection,
- message, -1, &error);
- if (reply == NULL) {
- if (dbus_error_is_set(&error) == TRUE) {
- connman_error("%s", error.message);
- dbus_error_free(&error);
- } else
- connman_error("Failed to add interface");
- dbus_message_unref(message);
- return -EIO;
- }
+static int wifi_enable(struct connman_device *device)
+{
+ struct wifi_data *wifi = connman_device_get_data(device);
+ const char *interface = connman_device_get_string(device, "Interface");
+ const char *driver = connman_option_get_string("wifi");
+
+ DBG("device %p %p", device, wifi);
- dbus_message_unref(message);
+ return g_supplicant_interface_create(interface, driver,
+ interface_create_callback,
+ wifi);
+}
- dbus_error_init(&error);
+static int wifi_disable(struct connman_device *device)
+{
+ struct wifi_data *wifi = connman_device_get_data(device);
- if (dbus_message_get_args(reply, &error, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID) == FALSE) {
- if (dbus_error_is_set(&error) == TRUE) {
- connman_error("%s", error.message);
- dbus_error_free(&error);
- } else
- connman_error("Wrong arguments for interface");
- dbus_message_unref(reply);
- return -EIO;
+ DBG("device %p", device);
+
+ wifi->connected = FALSE;
+
+ return g_supplicant_interface_remove(wifi->interface,
+ interface_remove_callback,
+ wifi);
+}
+
+static void scan_callback(int result, GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct connman_device *device = user_data;
+
+ DBG("result %d", result);
+
+ if (result < 0) {
+ connman_device_set_scanning(device, FALSE);
+ return;
}
- DBG("path %s", path);
+ connman_device_set_scanning(device, TRUE);
+}
- task->path = g_strdup(path);
- task->created = TRUE;
+static int wifi_scan(struct connman_device *device)
+{
+ struct wifi_data *wifi = connman_device_get_data(device);
- dbus_message_unref(reply);
+ DBG("device %p %p", device, wifi->interface);
- return 0;
+ return g_supplicant_interface_scan(wifi->interface, scan_callback,
+ device);
}
-static int remove_interface(struct supplicant_task *task)
+static struct connman_device_driver wifi_ng_driver = {
+ .name = "wifi",
+ .type = CONNMAN_DEVICE_TYPE_WIFI,
+ .priority = CONNMAN_DEVICE_PRIORITY_LOW,
+ .probe = wifi_probe,
+ .remove = wifi_remove,
+ .enable = wifi_enable,
+ .disable = wifi_disable,
+ .scan = wifi_scan,
+};
+
+static void system_ready(void)
{
- DBusMessage *message, *reply;
- DBusError error;
+ DBG("");
+
+ if (connman_device_driver_register(&wifi_ng_driver) < 0)
+ connman_error("Failed to register WiFi driver");
+}
- DBG("task %p", task);
+static void system_killed(void)
+{
+ DBG("");
- if (task->created == FALSE)
- return -EINVAL;
+ connman_device_driver_unregister(&wifi_ng_driver);
+}
- message = dbus_message_new_method_call(SUPPLICANT_NAME, SUPPLICANT_PATH,
- SUPPLICANT_INTF, "removeInterface");
- if (message == NULL)
- return -ENOMEM;
+static void interface_added(GSupplicantInterface *interface)
+{
+ const char *ifname = g_supplicant_interface_get_ifname(interface);
+ const char *driver = g_supplicant_interface_get_driver(interface);
+ struct wifi_data *wifi;
- dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &task->path,
- DBUS_TYPE_INVALID);
+ wifi = g_supplicant_interface_get_data(interface);
- dbus_error_init(&error);
+ DBG("ifname %s driver %s wifi %p", ifname, driver, wifi);
- reply = dbus_connection_send_with_reply_and_block(connection,
- message, -1, &error);
- if (reply == NULL) {
- if (dbus_error_is_set(&error) == TRUE) {
- connman_error("%s", error.message);
- dbus_error_free(&error);
- } else
- connman_error("Failed to remove interface");
- dbus_message_unref(message);
- return -EIO;
+ if (wifi == NULL || wifi->device == NULL) {
+ connman_error("Wrong wifi pointer");
+ return;
}
- dbus_message_unref(message);
+ connman_device_set_powered(wifi->device, TRUE);
+ wifi_scan(wifi->device);
+}
+
+static void interface_state(GSupplicantInterface *interface)
+{
+ struct connman_network *network;
+ struct connman_device *device;
+ struct wifi_data *wifi;
+ GSupplicantState state = g_supplicant_interface_get_state(interface);
+ unsigned char bssid[ETH_ALEN];
+ unsigned int bssid_len;
- g_free(task->path);
- task->path = NULL;
+ wifi = g_supplicant_interface_get_data(interface);
- dbus_message_unref(reply);
+ DBG("wifi %p interface state %d", wifi, state);
- return 0;
+ if (wifi == NULL)
+ return;
+
+ network = wifi->network;
+ device = wifi->device;
+
+ if (device == NULL || network == NULL)
+ return;
+
+ switch (state) {
+ case G_SUPPLICANT_STATE_SCANNING:
+ connman_device_set_scanning(device, TRUE);
+ break;
+
+ case G_SUPPLICANT_STATE_AUTHENTICATING:
+ case G_SUPPLICANT_STATE_ASSOCIATING:
+ connman_network_set_associating(network, TRUE);
+ break;
+
+ case G_SUPPLICANT_STATE_COMPLETED:
+ /* reset scan trigger and schedule background scan */
+ connman_device_schedule_scan(device);
+
+ if (get_bssid(device, bssid, &bssid_len) == 0)
+ connman_network_set_address(network,
+ bssid, bssid_len);
+ connman_network_set_connected(network, TRUE);
+ break;
+
+ case G_SUPPLICANT_STATE_DISCONNECTED:
+ connman_network_set_associating(network, FALSE);
+ connman_network_set_connected(network, FALSE);
+ break;
+
+ case G_SUPPLICANT_STATE_INACTIVE:
+ connman_network_set_associating(network, FALSE);
+ break;
+
+ case G_SUPPLICANT_STATE_UNKNOWN:
+ case G_SUPPLICANT_STATE_ASSOCIATED:
+ case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+ case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+ break;
+ }
+
+ DBG("DONE");
}
-static int initiate_scan(struct supplicant_task *task)
+static void interface_removed(GSupplicantInterface *interface)
{
- DBusMessage *message, *reply;
- DBusError error;
+ const char *ifname = g_supplicant_interface_get_ifname(interface);
+ struct wifi_data *wifi;
- DBG("task %p", task);
+ DBG("ifname %s", ifname);
- message = dbus_message_new_method_call(SUPPLICANT_NAME, task->path,
- SUPPLICANT_INTF ".Interface", "scan");
- if (message == NULL)
- return -ENOMEM;
+ wifi = g_supplicant_interface_get_data(interface);
- dbus_error_init(&error);
-
- reply = dbus_connection_send_with_reply_and_block(connection,
- message, -1, &error);
- if (reply == NULL) {
- if (dbus_error_is_set(&error) == TRUE) {
- connman_error("%s", error.message);
- dbus_error_free(&error);
- } else
- connman_error("Failed to initiate scan");
- dbus_message_unref(message);
- return -EIO;
+ if (wifi == NULL || wifi->device == NULL) {
+ connman_error("Wrong wifi pointer");
+ return;
}
- dbus_message_unref(message);
+ connman_device_set_powered(wifi->device, FALSE);
+}
- dbus_message_unref(reply);
+static void scan_started(GSupplicantInterface *interface)
+{
+ struct wifi_data *wifi;
- return 0;
+ DBG("");
+
+ wifi = g_supplicant_interface_get_data(interface);
+
+ if (wifi == NULL)
+ return;
+
+ if (wifi->device)
+ connman_device_set_scanning(wifi->device, TRUE);
}
-static int wifi_probe(struct connman_element *element)
+static void scan_finished(GSupplicantInterface *interface)
{
- struct supplicant_task *task;
- int err;
+ struct wifi_data *wifi;
- DBG("element %p name %s", element, element->name);
+ DBG("");
- task = g_try_new0(struct supplicant_task, 1);
- if (task == NULL)
- return -ENOMEM;
+ wifi = g_supplicant_interface_get_data(interface);
- task->ifindex = element->netdev.index;
- task->ifname = g_strdup(element->netdev.name);
+ if (wifi == NULL)
+ return;
+}
- if (task->ifname == NULL) {
- g_free(task);
- return -ENOMEM;
- }
+static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
+{
+ unsigned char strength;
- task->created = FALSE;
- task->state = STATE_INACTIVE;
+ strength = 120 + g_supplicant_network_get_signal(supplicant_network);
+ if (strength > 100)
+ strength = 100;
- g_static_mutex_lock(&task_mutex);
- task_list = g_slist_append(task_list, task);
- g_static_mutex_unlock(&task_mutex);
+ return strength;
+}
- err = get_interface(task);
- if (err < 0) {
- err = add_interface(task);
- if (err < 0) {
- g_free(task);
- return err;
+static void network_added(GSupplicantNetwork *supplicant_network)
+{
+ struct connman_network *network;
+ GSupplicantInterface *interface;
+ struct wifi_data *wifi;
+ const char *name, *path, *identifier, *mode, *security, *group;
+ const unsigned char *ssid;
+ unsigned int ssid_len;
+
+ DBG("");
+
+ interface = g_supplicant_network_get_interface(supplicant_network);
+ wifi = g_supplicant_interface_get_data(interface);
+ name = g_supplicant_network_get_name(supplicant_network);
+ path = g_supplicant_network_get_path(supplicant_network);
+ identifier = g_supplicant_network_get_identifier(supplicant_network);
+ mode = g_supplicant_network_get_mode(supplicant_network);
+ security = g_supplicant_network_get_security(supplicant_network);
+ group = g_supplicant_network_get_identifier(supplicant_network);
+
+ if (wifi == NULL)
+ return;
+
+ ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
+
+ network = connman_device_get_network(wifi->device, path);
+
+ if (network == NULL) {
+ network = connman_network_create(identifier,
+ CONNMAN_NETWORK_TYPE_WIFI);
+ if (network == NULL)
+ return;
+
+ connman_network_set_index(network, wifi->index);
+
+ connman_network_set_protocol(network,
+ CONNMAN_NETWORK_PROTOCOL_IP);
+
+ if (connman_device_add_network(wifi->device, network) < 0) {
+ connman_network_unref(network);
+ return;
}
}
- initiate_scan(task);
+ if (name != NULL && name[0] != '\0')
+ connman_network_set_name(network, name);
+
+ connman_network_set_blob(network, "WiFi.SSID",
+ ssid, ssid_len);
+ connman_network_set_string(network, "WiFi.Mode", mode);
+ connman_network_set_string(network, "WiFi.Security", security);
+ connman_network_set_strength(network,
+ calculate_strength(supplicant_network));
+
+ connman_network_set_available(network, TRUE);
+
+ if (ssid != NULL)
+ connman_network_set_group(network, group);
+}
+
+static void network_removed(GSupplicantNetwork *network)
+{
+ const char *name = g_supplicant_network_get_name(network);
+
+ DBG("* name %s", name);
+}
+
+static void debug(const char *str)
+{
+ connman_debug("%s", str);
+}
+
+static const GSupplicantCallbacks callbacks = {
+ .system_ready = system_ready,
+ .system_killed = system_killed,
+ .interface_added = interface_added,
+ .interface_state = interface_state,
+ .interface_removed = interface_removed,
+ .scan_started = scan_started,
+ .scan_finished = scan_finished,
+ .network_added = network_added,
+ .network_removed = network_removed,
+ .debug = debug,
+};
+
+
+static int network_probe(struct connman_network *network)
+{
+ DBG("network %p", network);
return 0;
}
-static void wifi_remove(struct connman_element *element)
+static void network_remove(struct connman_network *network)
{
- struct supplicant_task *task;
+ DBG("network %p", network);
+}
- DBG("element %p name %s", element, element->name);
+static void connect_callback(int result, GSupplicantInterface *interface,
+ void *user_data)
+{
+ connman_error("%s", __func__);
+}
- g_static_mutex_lock(&task_mutex);
- task = find_task_by_index(element->netdev.index);
- g_static_mutex_unlock(&task_mutex);
+static void disconnect_callback(int result, GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct wifi_data *wifi = user_data;
- if (task == NULL)
+ if (result < 0) {
+ connman_error("%s", __func__);
return;
+ }
+
+ connman_network_unref(wifi->network);
+
+ wifi->network = NULL;
+}
+
+
+static GSupplicantSecurity network_security(const char *security)
+{
+ if (g_str_equal(security, "none") == TRUE)
+ return G_SUPPLICANT_SECURITY_NONE;
+ else if (g_str_equal(security, "wep") == TRUE)
+ return G_SUPPLICANT_SECURITY_WEP;
+ else if (g_str_equal(security, "psk") == TRUE)
+ return G_SUPPLICANT_SECURITY_PSK;
+ else if (g_str_equal(security, "wpa") == TRUE)
+ return G_SUPPLICANT_SECURITY_PSK;
+ else if (g_str_equal(security, "rsn") == TRUE)
+ return G_SUPPLICANT_SECURITY_PSK;
+ else if (g_str_equal(security, "ieee8021x") == TRUE)
+ return G_SUPPLICANT_SECURITY_IEEE8021X;
+
+ return G_SUPPLICANT_SECURITY_UNKNOWN;
+}
+
+static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
+{
+ const char *security;
+
+ memset(ssid, 0, sizeof(*ssid));
+ ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
+ &ssid->ssid_len);
+ security = connman_network_get_string(network, "WiFi.Security");
+ ssid->security = network_security(security);
+ ssid->passphrase = connman_network_get_string(network,
+ "WiFi.Passphrase");
+ ssid->eap = connman_network_get_string(network, "WiFi.EAP");
+
+ /*
+ * If our private key password is unset,
+ * we use the supplied passphrase. That is needed
+ * for PEAP where 2 passphrases (identity and client
+ * cert may have to be provided.
+ */
+ if (connman_network_get_string(network,
+ "WiFi.PrivateKeyPassphrase") == NULL)
+ connman_network_set_string(network,
+ "WiFi.PrivateKeyPassphrase",
+ ssid->passphrase);
+ /* We must have an identity for both PEAP and TLS */
+ ssid->identity = connman_network_get_string(network, "WiFi.Identity");
+ ssid->ca_cert_path = connman_network_get_string(network,
+ "WiFi.CACertFile");
+ ssid->client_cert_path = connman_network_get_string(network,
+ "WiFi.ClientCertFile");
+ ssid->private_key_path = connman_network_get_string(network,
+ "WiFi.PrivateKeyFile");
+ ssid->private_key_passphrase = connman_network_get_string(network,
+ "WiFi.PrivateKeyPassphrase");
+ ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
+
+}
+
+static int network_connect(struct connman_network *network)
+{
+ struct connman_device *device = connman_network_get_device(network);
+ struct wifi_data *wifi;
+ GSupplicantInterface *interface;
+ GSupplicantSSID ssid;
+
+ DBG("network %p", network);
+
+ if (device == NULL)
+ return -ENODEV;
+
+ wifi = connman_device_get_data(device);
+ if (wifi == NULL)
+ return -ENODEV;
+
+ interface = wifi->interface;
+
+ ssid_init(&ssid, network);
- g_static_mutex_lock(&task_mutex);
- task_list = g_slist_remove(task_list, task);
- g_static_mutex_unlock(&task_mutex);
+ wifi->network = connman_network_ref(network);
- remove_interface(task);
+ return g_supplicant_interface_connect(interface, &ssid,
+ connect_callback, NULL);
+}
+
+static int network_disconnect(struct connman_network *network)
+{
+ struct connman_device *device = connman_network_get_device(network);
+ struct wifi_data *wifi;
+
+ DBG("network %p", network);
+
+ wifi = connman_device_get_data(device);
+ if (wifi == NULL || wifi->interface == NULL)
+ return -ENODEV;
- g_free(task->ifname);
- g_free(task);
+ return g_supplicant_interface_disconnect(wifi->interface,
+ disconnect_callback, wifi);
}
-static struct connman_driver wifi_driver = {
+static struct connman_network_driver network_driver = {
.name = "wifi",
- .type = CONNMAN_ELEMENT_TYPE_DEVICE,
- .subtype = CONNMAN_ELEMENT_SUBTYPE_WIFI,
- .probe = wifi_probe,
- .remove = wifi_remove,
+ .type = CONNMAN_NETWORK_TYPE_WIFI,
+ .priority = CONNMAN_NETWORK_PRIORITY_LOW,
+ .probe = network_probe,
+ .remove = network_remove,
+ .connect = network_connect,
+ .disconnect = network_disconnect,
};
static int wifi_init(void)
{
int err;
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (connection == NULL)
- return -EIO;
+ err = connman_network_driver_register(&network_driver);
+ if (err < 0)
+ return err;
- err = connman_driver_register(&wifi_driver);
+ err = g_supplicant_register(&callbacks);
if (err < 0) {
- dbus_connection_unref(connection);
+ connman_network_driver_unregister(&network_driver);
return err;
}
static void wifi_exit(void)
{
- connman_driver_unregister(&wifi_driver);
+ DBG();
+
+ g_supplicant_unregister(&callbacks);
- dbus_connection_unref(connection);
+ connman_network_driver_unregister(&network_driver);
}
-CONNMAN_PLUGIN_DEFINE("WiFi", "WiFi interface plugin", VERSION,
- wifi_init, wifi_exit)
+CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
+ CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)