3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2004-2008 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
30
#include <bluetooth/bluetooth.h>
31
#include <bluetooth/hci.h>
32
#include <bluetooth/sdp.h>
33
#include <bluetooth/sdp_lib.h>
38
#include "../src/adapter.h"
39
#include "../src/device.h"
44
static int idle_timeout = 0;
46
static DBusConnection *connection = NULL;
48
static void input_remove(struct btd_device *device, const char *uuid)
50
const gchar *path = device_get_path(device);
54
input_device_unregister(path, uuid);
57
static int hid_device_probe(struct btd_device *device, GSList *records)
59
struct btd_adapter *adapter = device_get_adapter(device);
60
const gchar *path = device_get_path(device);
61
sdp_record_t *rec = records->data;
68
adapter_get_address(adapter, &src);
69
device_get_address(device, &dst);
70
pdlist = sdp_data_get(rec, SDP_SERVER_RECORD_HANDLE);
74
handle = pdlist->val.uint32;
76
return input_device_register(connection, path, &src, &dst,
77
HID_UUID, handle, idle_timeout * 60);
80
static void hid_device_remove(struct btd_device *device)
82
input_remove(device, HID_UUID);
85
static int headset_probe(struct btd_device *device, GSList *records)
87
struct btd_adapter *adapter = device_get_adapter(device);
88
const gchar *path = device_get_path(device);
89
sdp_record_t *record = records->data;
96
if (sdp_get_access_protos(record, &protos) < 0) {
97
error("Invalid record");
101
ch = sdp_get_proto_port(protos, RFCOMM_UUID);
102
sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
103
sdp_list_free(protos, NULL);
106
error("Invalid RFCOMM channel");
110
adapter_get_address(adapter, &src);
111
device_get_address(device, &dst);
113
return fake_input_register(connection, path, &src, &dst,
117
static void headset_remove(struct btd_device *device)
119
input_remove(device, HSP_HS_UUID);
122
static int hid_server_probe(struct btd_adapter *adapter)
126
adapter_get_address(adapter, &src);
128
return server_start(&src);
131
static void hid_server_remove(struct btd_adapter *adapter)
135
adapter_get_address(adapter, &src);
140
static struct btd_device_driver input_hid_driver = {
142
.uuids = BTD_UUIDS(HID_UUID),
143
.probe = hid_device_probe,
144
.remove = hid_device_remove,
147
static struct btd_device_driver input_headset_driver = {
148
.name = "input-headset",
149
.uuids = BTD_UUIDS(HSP_HS_UUID),
150
.probe = headset_probe,
151
.remove = headset_remove,
154
static struct btd_adapter_driver input_server_driver = {
155
.name = "input-server",
156
.probe = hid_server_probe,
157
.remove = hid_server_remove,
160
int input_manager_init(DBusConnection *conn, GKeyFile *config)
165
idle_timeout = g_key_file_get_integer(config, "General",
166
"IdleTimeout", &err);
168
debug("input.conf: %s", err->message);
173
connection = dbus_connection_ref(conn);
175
btd_register_adapter_driver(&input_server_driver);
177
btd_register_device_driver(&input_hid_driver);
178
btd_register_device_driver(&input_headset_driver);
183
void input_manager_exit(void)
185
btd_unregister_device_driver(&input_hid_driver);
186
btd_unregister_device_driver(&input_headset_driver);
188
btd_unregister_adapter_driver(&input_server_driver);
190
dbus_connection_unref(connection);