5 * Copyright (C) 2007 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_object(connection, path);
78 static DBusMessage *get_identifier(DBusConnection *conn,
79 DBusMessage *msg, void *data)
81 struct connman_network *network = data;
86 reply = dbus_message_new_method_return(msg);
90 dbus_message_append_args(reply, DBUS_TYPE_STRING, &network->identifier,
96 static DBusMessage *get_passphrase(DBusConnection *conn,
97 DBusMessage *msg, void *data)
99 struct connman_network *network = data;
102 DBG("conn %p", conn);
104 reply = dbus_message_new_method_return(msg);
108 dbus_message_append_args(reply, DBUS_TYPE_STRING, &network->passphrase,
114 static GDBusMethodTable network_methods[] = {
115 { "GetIdentifier", "", "s", get_identifier },
116 { "GetPassphrase", "", "s", get_passphrase },
120 static void network_free(void *data)
122 struct connman_network *network = data;
126 networks = g_slist_remove(networks, network);
128 g_free(network->path);
129 g_free(network->identifier);
130 g_free(network->passphrase);
134 const char *__connman_iface_add_network(struct connman_iface *iface,
135 const char *identifier, const char *passphrase)
137 struct connman_network *network;
140 DBG("iface %p", iface);
142 network = g_try_new0(struct connman_network, 1);
146 path = g_strdup_printf("%s/net_%d", iface->path, index++);
152 network->iface = iface;
154 network->path = path;
155 network->identifier = g_strdup(identifier);
156 network->passphrase = g_strdup(passphrase ? passphrase : "");
158 networks = g_slist_append(networks, network);
160 g_dbus_register_object(connection, path, network, network_free);
162 g_dbus_register_interface(connection, path, CONNMAN_NETWORK_INTERFACE,
163 network_methods, NULL, NULL);
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);