Add basics for a supplicant driver and use it
[connman] / plugins / wifi.c
index ca39cec..6459f76 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2008  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2009  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 <linux/if_arp.h>
 #include <linux/wireless.h>
 
-#include <gdbus.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/rtnl.h>
-#include <connman/dbus.h>
 #include <connman/log.h>
 
 #include "inet.h"
@@ -497,7 +497,7 @@ static int wifi_scan(struct connman_device *device)
 }
 
 static struct connman_device_driver wifi_driver = {
-       .name           = "wifi-device",
+       .name           = "wifi",
        .type           = CONNMAN_DEVICE_TYPE_WIFI,
        .probe          = wifi_probe,
        .remove         = wifi_remove,
@@ -506,181 +506,48 @@ static struct connman_device_driver wifi_driver = {
        .scan           = wifi_scan,
 };
 
-static GSList *device_list = NULL;
-
-static void wifi_newlink(unsigned short type, int index,
-                                       unsigned flags, unsigned change)
+static void wifi_register(void)
 {
-       struct connman_device *device;
-       GSList *list;
-       gboolean exists = FALSE;
-       gchar *name, *devname;
-       struct iwreq iwr;
-       int sk;
-
-       DBG("index %d", index);
-
-       if (type != ARPHRD_ETHER)
-               return;
-
-       devname = inet_index2name(index);
-
-       memset(&iwr, 0, sizeof(iwr));
-       strncpy(iwr.ifr_ifrn.ifrn_name, devname, IFNAMSIZ);
-
-       sk = socket(PF_INET, SOCK_DGRAM, 0);
-
-       if (ioctl(sk, SIOCGIWNAME, &iwr) < 0) {
-               g_free(devname);
-               close(sk);
-               return;
-       }
-
-       close(sk);
-
-       for (list = device_list; list; list = list->next) {
-               struct connman_device *device = list->data;
-
-               if (connman_device_get_index(device) == index) {
-                       exists = TRUE;
-                       break;
-               }
-       }
-
-       if (exists == TRUE) {
-               g_free(devname);
-               return;
-       }
-
-       name = inet_index2ident(index, "dev_");
-
-       device = connman_device_create(name, CONNMAN_DEVICE_TYPE_WIFI);
-       if (device == NULL) {
-               g_free(devname);
-               g_free(name);
-               return;
-       }
-
-       connman_device_set_index(device, index);
-       connman_device_set_interface(device, devname);
-
-       g_free(devname);
-       g_free(name);
-
-       connman_device_set_mode(device, CONNMAN_DEVICE_MODE_SINGLE_NETWORK);
-
-       if (connman_device_register(device) < 0) {
-               connman_device_unregister(device);
-               return;
-       }
+       DBG("");
 
-       device_list = g_slist_append(device_list, device);
+       connman_device_driver_register(&wifi_driver);
 }
 
-static void wifi_dellink(unsigned short type, int index,
-                                       unsigned flags, unsigned change)
+static void wifi_unregister(void)
 {
-       GSList *list;
-
-       DBG("index %d", index);
-
-       for (list = device_list; list; list = list->next) {
-               struct connman_device *device = list->data;
+       DBG("");
 
-               if (connman_device_get_index(device) == index) {
-                       device_list = g_slist_remove(device_list, device);
-                       connman_device_unregister(device);
-                       connman_device_unref(device);
-                       break;
-               }
-       }
+       connman_device_driver_unregister(&wifi_driver);
 }
 
-static struct connman_rtnl wifi_rtnl = {
+static struct supplicant_driver supplicant = {
        .name           = "wifi",
-       .newlink        = wifi_newlink,
-       .dellink        = wifi_dellink,
+       .probe          = wifi_register,
+       .remove         = wifi_unregister,
 };
 
-static void supplicant_connect(DBusConnection *connection, void *user_data)
-{
-       DBG("connection %p", connection);
-
-       __supplicant_init(connection);
-
-       if (connman_rtnl_register(&wifi_rtnl) < 0)
-               return;
-
-       connman_rtnl_send_getlink();
-}
-
-static void supplicant_disconnect(DBusConnection *connection, void *user_data)
-{
-       GSList *list;
-
-       DBG("connection %p", connection);
-
-       connman_rtnl_unregister(&wifi_rtnl);
-
-       for (list = device_list; list; list = list->next) {
-               struct connman_device *device = list->data;
-
-               connman_device_unregister(device);
-               connman_device_unref(device);
-       }
-
-       g_slist_free(device_list);
-       device_list = NULL;
-
-       __supplicant_exit();
-}
-
-static DBusConnection *connection;
-static guint watch;
-
 static int wifi_init(void)
 {
        int err;
 
-       connection = connman_dbus_get_connection();
-       if (connection == NULL)
-               return -EIO;
-
        err = connman_driver_register(&network_driver);
-       if (err < 0) {
-               dbus_connection_unref(connection);
+       if (err < 0)
                return err;
-       }
 
-       err = connman_device_driver_register(&wifi_driver);
+       err = supplicant_register(&supplicant);
        if (err < 0) {
                connman_driver_unregister(&network_driver);
-               dbus_connection_unref(connection);
                return err;
        }
 
-       watch = g_dbus_add_service_watch(connection, SUPPLICANT_NAME,
-                       supplicant_connect, supplicant_disconnect, NULL, NULL);
-
-       if (g_dbus_check_service(connection, SUPPLICANT_NAME) == TRUE)
-               supplicant_connect(connection, NULL);
-       else
-               __supplicant_activate(connection);
-
        return 0;
 }
 
 static void wifi_exit(void)
 {
-       connman_driver_unregister(&network_driver);
-       connman_device_driver_unregister(&wifi_driver);
-
-       if (watch > 0)
-               g_dbus_remove_watch(connection, watch);
+       supplicant_unregister(&supplicant);
 
-       supplicant_disconnect(connection, NULL);
-
-       dbus_connection_unref(connection);
+       connman_driver_unregister(&network_driver);
 }
 
 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,