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
37 #include <arpa/inet.h>
38 #include <sys/param.h>
39 #include <sys/ioctl.h>
41 #include <sys/types.h>
44 #include <bluetooth/bluetooth.h>
45 #include <bluetooth/sdp.h>
46 #include <bluetooth/sdp_lib.h>
47 #include <bluetooth/rfcomm.h>
48 #include <bluetooth/uuid.h>
53 #include "../src/dbus-common.h"
65 #include "glib-helper.h"
67 static DBusConnection *connection = NULL;
69 static int serial_probe(struct btd_device *device, const char *uuid)
71 struct btd_adapter *adapter = device_get_adapter(device);
72 const gchar *path = device_get_path(device);
76 const sdp_record_t *rec;
78 DBG("path %s: %s", path, uuid);
80 rec = btd_device_get_record(device, uuid);
84 if (sdp_get_access_protos(rec, &protos) < 0)
87 ch = sdp_get_proto_port(protos, RFCOMM_UUID);
88 sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
89 sdp_list_free(protos, NULL);
91 if (ch < 1 || ch > 30) {
92 error("Channel out of range: %d", ch);
96 adapter_get_address(adapter, &src);
97 device_get_address(device, &dst, NULL);
99 return port_register(connection, path, &src, &dst, uuid, ch);
102 static void serial_remove(struct btd_device *device)
104 const gchar *path = device_get_path(device);
106 DBG("path %s", path);
108 port_unregister(path);
112 static int port_probe(struct btd_device *device, GSList *uuids)
115 serial_probe(device, uuids->data);
122 static void port_remove(struct btd_device *device)
124 return serial_remove(device);
127 static struct btd_device_driver serial_port_driver = {
128 .name = "serial-port",
129 .uuids = BTD_UUIDS(RFCOMM_UUID_STR),
131 .remove = port_remove,
134 static int proxy_probe(struct btd_adapter *adapter)
136 const char *path = adapter_get_path(adapter);
138 DBG("path %s", path);
140 return proxy_register(connection, adapter);
143 static void proxy_remove(struct btd_adapter *adapter)
145 const char *path = adapter_get_path(adapter);
147 DBG("path %s", path);
149 proxy_unregister(adapter);
152 static struct btd_adapter_driver serial_proxy_driver = {
153 .name = "serial-proxy",
154 .probe = proxy_probe,
155 .remove = proxy_remove,
158 int serial_manager_init(DBusConnection *conn)
160 connection = dbus_connection_ref(conn);
162 btd_register_adapter_driver(&serial_proxy_driver);
163 btd_register_device_driver(&serial_port_driver);
168 void serial_manager_exit(void)
170 btd_unregister_device_driver(&serial_port_driver);
172 dbus_connection_unref(connection);