5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #define IFF_LOWER_UP 0x10000
33 #include <dbus/dbus.h>
36 #define CONNMAN_API_SUBJECT_TO_CHANGE
37 #include <connman/plugin.h>
38 #include <connman/device.h>
39 #include <connman/rtnl.h>
40 #include <connman/log.h>
42 #include "supplicant.h"
44 #define CLEANUP_TIMEOUT 8 /* in seconds */
45 #define INACTIVE_TIMEOUT 12 /* in seconds */
49 connman_bool_t connected;
55 static int network_probe(struct connman_network *network)
57 DBG("network %p", network);
62 static void network_remove(struct connman_network *network)
64 DBG("network %p", network);
66 supplicant_remove_network(network);
69 static int network_connect(struct connman_network *network)
71 DBG("network %p", network);
73 return supplicant_connect(network);
76 static int network_disconnect(struct connman_network *network)
78 DBG("network %p", network);
80 connman_network_set_associating(network, FALSE);
82 return supplicant_disconnect(network);
85 static struct connman_network_driver network_driver = {
87 .type = CONNMAN_NETWORK_TYPE_WIFI,
88 .priority = CONNMAN_NETWORK_PRIORITY_HIGH,
89 .probe = network_probe,
90 .remove = network_remove,
91 .connect = network_connect,
92 .disconnect = network_disconnect,
95 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
97 struct connman_device *device = user_data;
98 struct wifi_data *wifi = connman_device_get_data(device);
100 DBG("index %d flags %d change %d", wifi->index, flags, change);
105 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
106 if (flags & IFF_UP) {
109 DBG("interface down");
113 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
114 if (flags & IFF_LOWER_UP) {
124 static int wifi_probe(struct connman_device *device)
126 struct wifi_data *wifi;
128 DBG("device %p", device);
130 wifi = g_try_new0(struct wifi_data, 1);
134 wifi->connected = FALSE;
136 connman_device_set_data(device, wifi);
138 wifi->index = connman_device_get_index(device);
141 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
142 wifi_newlink, device);
147 static void wifi_remove(struct connman_device *device)
149 struct wifi_data *wifi = connman_device_get_data(device);
151 DBG("device %p", device);
153 connman_device_set_data(device, NULL);
155 connman_rtnl_remove_watch(wifi->watch);
157 g_free(wifi->identifier);
161 static int wifi_enable(struct connman_device *device)
163 DBG("device %p", device);
165 return supplicant_start(device);
168 static int wifi_disable(struct connman_device *device)
170 struct wifi_data *wifi = connman_device_get_data(device);
172 DBG("device %p", device);
174 wifi->connected = FALSE;
176 return supplicant_stop(device);
179 static int wifi_scan(struct connman_device *device)
181 DBG("device %p", device);
183 return supplicant_scan(device);
186 static struct connman_device_driver wifi_driver = {
188 .type = CONNMAN_DEVICE_TYPE_WIFI,
189 .priority = CONNMAN_DEVICE_PRIORITY_HIGH,
191 .remove = wifi_remove,
192 .enable = wifi_enable,
193 .disable = wifi_disable,
197 static void wifi_register(void)
201 if (connman_device_driver_register(&wifi_driver) < 0)
202 connman_error("Failed to register WiFi driver");
205 static void wifi_unregister(void)
209 connman_device_driver_unregister(&wifi_driver);
212 static struct supplicant_driver supplicant = {
214 .probe = wifi_register,
215 .remove = wifi_unregister,
218 static int wifi_init(void)
222 err = connman_network_driver_register(&network_driver);
226 err = supplicant_register(&supplicant);
228 connman_network_driver_unregister(&network_driver);
235 static void wifi_exit(void)
237 supplicant_unregister(&supplicant);
239 connman_network_driver_unregister(&network_driver);
242 CONNMAN_PLUGIN_DEFINE(wifi_legacy, "WiFi interface plugin", VERSION,
243 CONNMAN_PLUGIN_PRIORITY_LOW, wifi_init, wifi_exit)