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
30 static DBusConnection *connection = NULL;
31 static unsigned int index = 0;
33 static GSList *networks = NULL;
35 void __connman_iface_network_list(struct connman_iface *iface,
36 DBusMessageIter *iter)
42 for (list = networks; list; list = list->next) {
43 struct connman_network *network = list->data;
45 if (network->iface != iface)
48 dbus_message_iter_append_basic(iter,
49 DBUS_TYPE_OBJECT_PATH, &network->path);
53 struct connman_network *__connman_iface_find_network(struct connman_iface *iface,
60 for (list = networks; list; list = list->next) {
61 struct connman_network *network = list->data;
63 if (network->iface == iface &&
64 g_str_equal(network->path, path) == TRUE)
71 int __connman_iface_remove_network(struct connman_iface *iface, const char *path)
73 g_dbus_unregister_interface(connection, path,
74 CONNMAN_NETWORK_INTERFACE);
79 static DBusMessage *get_identifier(DBusConnection *conn,
80 DBusMessage *msg, void *data)
82 struct connman_network *network = data;
87 reply = dbus_message_new_method_return(msg);
91 dbus_message_append_args(reply, DBUS_TYPE_STRING, &network->identifier,
97 static DBusMessage *get_passphrase(DBusConnection *conn,
98 DBusMessage *msg, void *data)
100 struct connman_network *network = data;
103 DBG("conn %p", conn);
105 reply = dbus_message_new_method_return(msg);
109 dbus_message_append_args(reply, DBUS_TYPE_STRING, &network->passphrase,
115 static GDBusMethodTable network_methods[] = {
116 { "GetIdentifier", "", "s", get_identifier },
117 { "GetPassphrase", "", "s", get_passphrase },
121 static void network_free(void *data)
123 struct connman_network *network = data;
127 networks = g_slist_remove(networks, network);
129 g_free(network->path);
130 g_free(network->identifier);
131 g_free(network->passphrase);
135 const char *__connman_iface_add_network(struct connman_iface *iface,
136 const char *identifier, const char *passphrase)
138 struct connman_network *network;
141 DBG("iface %p", iface);
143 network = g_try_new0(struct connman_network, 1);
147 path = g_strdup_printf("%s/net_%d", iface->path, index++);
153 network->iface = iface;
155 network->path = path;
156 network->identifier = g_strdup(identifier);
157 network->passphrase = g_strdup(passphrase ? passphrase : "");
159 networks = g_slist_append(networks, network);
161 g_dbus_register_interface(connection, path, CONNMAN_NETWORK_INTERFACE,
162 network_methods, NULL, NULL,
163 network, network_free);
168 int __connman_network_init(DBusConnection *conn)
170 DBG("conn %p", conn);
172 connection = dbus_connection_ref(conn);
173 if (connection == NULL)
179 void __connman_network_cleanup(void)
181 DBG("conn %p", connection);
183 dbus_connection_unref(connection);