Add debug output for used domain name server
[connman] / 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 <errno.h>
27
28 #include <dbus/dbus.h>
29 #include <glib.h>
30
31 #define CONNMAN_API_SUBJECT_TO_CHANGE
32 #include <connman/plugin.h>
33 #include <connman/device.h>
34 #include <connman/log.h>
35
36 #include "inet.h"
37 #include "supplicant.h"
38
39 #define CLEANUP_TIMEOUT   8     /* in seconds */
40 #define INACTIVE_TIMEOUT  12    /* in seconds */
41
42 struct wifi_data {
43         char *identifier;
44         connman_bool_t connected;
45 };
46
47 static int network_probe(struct connman_network *network)
48 {
49         DBG("network %p", network);
50
51         return 0;
52 }
53
54 static void network_remove(struct connman_network *network)
55 {
56         DBG("network %p", network);
57 }
58
59 static int network_connect(struct connman_network *network)
60 {
61         DBG("network %p", network);
62
63         return supplicant_connect(network);
64 }
65
66 static int network_disconnect(struct connman_network *network)
67 {
68         DBG("network %p", network);
69
70         return supplicant_disconnect(network);
71 }
72
73 static struct connman_network_driver network_driver = {
74         .name           = "wifi",
75         .type           = CONNMAN_NETWORK_TYPE_WIFI,
76         .probe          = network_probe,
77         .remove         = network_remove,
78         .connect        = network_connect,
79         .disconnect     = network_disconnect,
80 };
81
82 static int wifi_probe(struct connman_device *device)
83 {
84         struct wifi_data *data;
85
86         DBG("device %p", device);
87
88         data = g_try_new0(struct wifi_data, 1);
89         if (data == NULL)
90                 return -ENOMEM;
91
92         data->connected = FALSE;
93
94         connman_device_set_data(device, data);
95
96         return 0;
97 }
98
99 static void wifi_remove(struct connman_device *device)
100 {
101         struct wifi_data *data = connman_device_get_data(device);
102
103         DBG("device %p", device);
104
105         connman_device_set_data(device, NULL);
106
107         g_free(data->identifier);
108         g_free(data);
109 }
110
111 static int wifi_enable(struct connman_device *device)
112 {
113         DBG("device %p", device);
114
115         return supplicant_start(device);
116 }
117
118 static int wifi_disable(struct connman_device *device)
119 {
120         struct wifi_data *data = connman_device_get_data(device);
121
122         DBG("device %p", device);
123
124         data->connected = FALSE;
125
126         return supplicant_stop(device);
127 }
128
129 static int wifi_scan(struct connman_device *device)
130 {
131         DBG("device %p", device);
132
133         return supplicant_scan(device);
134 }
135
136 static int wifi_join(struct connman_device *device,
137                                         struct connman_network *network)
138 {
139         int err;
140
141         DBG("device %p", device);
142
143         err = supplicant_connect(network);
144         if (err < 0)
145                 return err;
146
147         connman_network_ref(network);
148
149         connman_device_add_network(device, network);
150
151         connman_network_set_available(network, TRUE);
152
153         return 0;
154 }
155
156 static struct connman_device_driver wifi_driver = {
157         .name           = "wifi",
158         .type           = CONNMAN_DEVICE_TYPE_WIFI,
159         .probe          = wifi_probe,
160         .remove         = wifi_remove,
161         .enable         = wifi_enable,
162         .disable        = wifi_disable,
163         .scan           = wifi_scan,
164         .join           = wifi_join,
165 };
166
167 static void wifi_register(void)
168 {
169         DBG("");
170
171         if (connman_device_driver_register(&wifi_driver) < 0)
172                 connman_error("Failed to register WiFi driver");
173 }
174
175 static void wifi_unregister(void)
176 {
177         DBG("");
178
179         connman_device_driver_unregister(&wifi_driver);
180 }
181
182 static struct supplicant_driver supplicant = {
183         .name           = "wifi",
184         .probe          = wifi_register,
185         .remove         = wifi_unregister,
186 };
187
188 static int wifi_init(void)
189 {
190         int err;
191
192         err = connman_network_driver_register(&network_driver);
193         if (err < 0)
194                 return err;
195
196         err = supplicant_register(&supplicant);
197         if (err < 0) {
198                 connman_network_driver_unregister(&network_driver);
199                 return err;
200         }
201
202         return 0;
203 }
204
205 static void wifi_exit(void)
206 {
207         supplicant_unregister(&supplicant);
208
209         connman_network_driver_unregister(&network_driver);
210 }
211
212 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
213                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)