Update WiFi plugin for new network helper functions
[framework/connectivity/connman.git] / plugins / wifi.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <dbus/dbus.h>
27
28 #define CONNMAN_API_SUBJECT_TO_CHANGE
29 #include <connman/plugin.h>
30 #include <connman/device.h>
31 #include <connman/log.h>
32
33 #include "inet.h"
34 #include "supplicant.h"
35
36 #define CLEANUP_TIMEOUT   8     /* in seconds */
37 #define INACTIVE_TIMEOUT  12    /* in seconds */
38
39 struct wifi_data {
40         char *identifier;
41         connman_bool_t connected;
42 };
43
44 static int network_probe(struct connman_network *network)
45 {
46         DBG("network %p", network);
47
48         return 0;
49 }
50
51 static void network_remove(struct connman_network *network)
52 {
53         DBG("network %p", network);
54 }
55
56 static struct connman_network_driver network_driver = {
57         .name           = "wifi",
58         .type           = CONNMAN_NETWORK_TYPE_WIFI,
59         .probe          = network_probe,
60         .remove         = network_remove,
61 };
62
63 static int wifi_probe(struct connman_device *device)
64 {
65         struct wifi_data *data;
66
67         DBG("device %p", device);
68
69         data = g_try_new0(struct wifi_data, 1);
70         if (data == NULL)
71                 return -ENOMEM;
72
73         data->connected = FALSE;
74
75         connman_device_set_data(device, data);
76
77         return 0;
78 }
79
80 static void wifi_remove(struct connman_device *device)
81 {
82         struct wifi_data *data = connman_device_get_data(device);
83
84         DBG("device %p", device);
85
86         connman_device_set_data(device, NULL);
87
88         g_free(data->identifier);
89         g_free(data);
90 }
91
92 static int wifi_enable(struct connman_device *device)
93 {
94         DBG("device %p", device);
95
96         return supplicant_start(device);
97 }
98
99 static int wifi_disable(struct connman_device *device)
100 {
101         struct wifi_data *data = connman_device_get_data(device);
102
103         DBG("device %p", device);
104
105         connman_element_unregister_children((struct connman_element *) device);
106
107         data->connected = FALSE;
108
109         return supplicant_stop(device);
110 }
111
112 static int wifi_scan(struct connman_device *device)
113 {
114         DBG("device %p", device);
115
116         return supplicant_scan(device);
117 }
118
119 static struct connman_device_driver wifi_driver = {
120         .name           = "wifi",
121         .type           = CONNMAN_DEVICE_TYPE_WIFI,
122         .probe          = wifi_probe,
123         .remove         = wifi_remove,
124         .enable         = wifi_enable,
125         .disable        = wifi_disable,
126         .scan           = wifi_scan,
127 };
128
129 static void wifi_register(void)
130 {
131         DBG("");
132
133         if (connman_device_driver_register(&wifi_driver) < 0)
134                 connman_error("Failed to register WiFi driver");
135 }
136
137 static void wifi_unregister(void)
138 {
139         DBG("");
140
141         connman_device_driver_unregister(&wifi_driver);
142 }
143
144 static struct supplicant_driver supplicant = {
145         .name           = "wifi",
146         .probe          = wifi_register,
147         .remove         = wifi_unregister,
148 };
149
150 static int wifi_init(void)
151 {
152         int err;
153
154         err = connman_network_driver_register(&network_driver);
155         if (err < 0)
156                 return err;
157
158         err = supplicant_register(&supplicant);
159         if (err < 0) {
160                 connman_network_driver_unregister(&network_driver);
161                 return err;
162         }
163
164         return 0;
165 }
166
167 static void wifi_exit(void)
168 {
169         supplicant_unregister(&supplicant);
170
171         connman_network_driver_unregister(&network_driver);
172 }
173
174 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
175                                                         wifi_init, wifi_exit)