5 * Copyright (C) 2007-2008 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
28 #include <connman/plugin.h>
29 #include <connman/driver.h>
30 #include <connman/log.h>
32 #include "supplicant.h"
39 static struct connman_element *find_element(struct wifi_data *data,
40 const char *identifier)
44 for (list = data->list; list; list = list->next) {
45 struct connman_element *element = list->data;
47 if (element->network.identifier == NULL)
50 if (g_str_equal(element->network.identifier,
58 static void scan_result(struct connman_element *parent,
59 struct supplicant_network *network)
61 struct wifi_data *data = connman_element_get_data(parent);
62 struct connman_element *element;
66 DBG("network %p identifier %s", network, network->identifier);
71 temp = g_strdup(network->identifier);
73 for (i = 0; i < strlen(temp); i++) {
74 if (temp[i] == ' ' || temp[i] == '.')
76 temp[i] = g_ascii_tolower(temp[i]);
79 g_static_mutex_lock(&data->mutex);
81 element = find_element(data, temp);
82 if (element == NULL) {
83 element = connman_element_create();
85 element->type = CONNMAN_ELEMENT_TYPE_NETWORK;
88 element->network.identifier = g_strdup(temp);
90 data->list = g_slist_append(data->list, element);
92 connman_element_register(element, parent);
96 g_static_mutex_unlock(&data->mutex);
99 static struct supplicant_callback wifi_callback = {
100 .scan_result = scan_result,
103 static int wifi_probe(struct connman_element *element)
105 struct wifi_data *data;
108 DBG("element %p name %s", element, element->name);
110 data = g_try_new0(struct wifi_data, 1);
114 g_static_mutex_init(&data->mutex);
116 connman_element_set_data(element, data);
118 err = __supplicant_start(element, &wifi_callback);
122 __supplicant_scan(element);
127 static void wifi_remove(struct connman_element *element)
129 struct wifi_data *data = connman_element_get_data(element);
132 DBG("element %p name %s", element, element->name);
134 __supplicant_stop(element);
136 connman_element_set_data(element, NULL);
141 g_static_mutex_lock(&data->mutex);
143 for (list = data->list; list; list = list->next) {
144 struct connman_element *network = list->data;
146 connman_element_unregister(network);
147 connman_element_unref(network);
150 g_slist_free(data->list);
152 g_static_mutex_unlock(&data->mutex);
157 static struct connman_driver wifi_driver = {
159 .type = CONNMAN_ELEMENT_TYPE_DEVICE,
160 .subtype = CONNMAN_ELEMENT_SUBTYPE_WIFI,
162 .remove = wifi_remove,
165 static int wifi_init(void)
167 return connman_driver_register(&wifi_driver);
170 static void wifi_exit(void)
172 connman_driver_unregister(&wifi_driver);
175 CONNMAN_PLUGIN_DEFINE("WiFi", "WiFi interface plugin", VERSION,
176 wifi_init, wifi_exit)