3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <bluetooth/bluetooth.h>
29 #include <bluetooth/bnep.h>
30 #include <bluetooth/sdp.h>
31 #include <bluetooth/uuid.h>
42 #include "connection.h"
45 static DBusConnection *connection = NULL;
47 static gboolean conf_security = TRUE;
49 static void read_config(const char *file)
54 keyfile = g_key_file_new();
56 if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
61 conf_security = !g_key_file_get_boolean(keyfile, "General",
62 "DisableSecurity", &err);
64 DBG("%s: %s", file, err->message);
69 g_key_file_free(keyfile);
71 DBG("Config options: Security=%s",
72 conf_security ? "true" : "false");
75 static int network_probe(struct btd_device *device, GSList *uuids, uint16_t id)
77 struct btd_adapter *adapter = device_get_adapter(device);
78 const gchar *path = device_get_path(device);
83 adapter_get_address(adapter, &src);
84 device_get_address(device, &dst, NULL);
86 return connection_register(device, path, &src, &dst, id);
89 static void network_remove(struct btd_device *device, uint16_t id)
91 const gchar *path = device_get_path(device);
95 connection_unregister(path, id);
98 static int panu_probe(struct btd_device *device, GSList *uuids)
100 return network_probe(device, uuids, BNEP_SVC_PANU);
103 static void panu_remove(struct btd_device *device)
105 network_remove(device, BNEP_SVC_PANU);
108 static int gn_probe(struct btd_device *device, GSList *uuids)
110 return network_probe(device, uuids, BNEP_SVC_GN);
113 static void gn_remove(struct btd_device *device)
115 network_remove(device, BNEP_SVC_GN);
118 static int nap_probe(struct btd_device *device, GSList *uuids)
120 return network_probe(device, uuids, BNEP_SVC_NAP);
123 static void nap_remove(struct btd_device *device)
125 network_remove(device, BNEP_SVC_NAP);
128 static int network_server_probe(struct btd_adapter *adapter)
130 const gchar *path = adapter_get_path(adapter);
132 DBG("path %s", path);
134 return server_register(adapter);
137 static void network_server_remove(struct btd_adapter *adapter)
139 const gchar *path = adapter_get_path(adapter);
141 DBG("path %s", path);
143 server_unregister(adapter);
146 static struct btd_device_driver network_panu_driver = {
147 .name = "network-panu",
148 .uuids = BTD_UUIDS(PANU_UUID),
150 .remove = panu_remove,
153 static struct btd_device_driver network_gn_driver = {
154 .name = "network-gn",
155 .uuids = BTD_UUIDS(GN_UUID),
160 static struct btd_device_driver network_nap_driver = {
161 .name = "network-nap",
162 .uuids = BTD_UUIDS(NAP_UUID),
164 .remove = nap_remove,
167 static struct btd_adapter_driver network_server_driver = {
168 .name = "network-server",
169 .probe = network_server_probe,
170 .remove = network_server_remove,
173 int network_manager_init(DBusConnection *conn)
175 read_config(CONFIGDIR "/network.conf");
178 error("Can't init bnep module");
183 * There is one socket to handle the incoming connections. NAP,
184 * GN and PANU servers share the same PSM. The initial BNEP message
185 * (setup connection request) contains the destination service
186 * field that defines which service the source is connecting to.
189 if (server_init(conn, conf_security) < 0)
192 /* Register network server if it doesn't exist */
193 btd_register_adapter_driver(&network_server_driver);
195 if (connection_init(conn) < 0)
198 btd_register_device_driver(&network_panu_driver);
199 btd_register_device_driver(&network_gn_driver);
200 btd_register_device_driver(&network_nap_driver);
202 connection = dbus_connection_ref(conn);
207 void network_manager_exit(void)
211 btd_unregister_device_driver(&network_panu_driver);
212 btd_unregister_device_driver(&network_gn_driver);
213 btd_unregister_device_driver(&network_nap_driver);
217 btd_unregister_adapter_driver(&network_server_driver);
219 dbus_connection_unref(connection);