2007-03-14 02:13:28 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
2010-01-02 09:08:17 +08:00
|
|
|
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
|
2007-03-14 02:13:28 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2007-04-17 21:22:58 +08:00
|
|
|
#include <errno.h>
|
2007-03-19 22:58:44 +08:00
|
|
|
|
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/hci.h>
|
|
|
|
#include <bluetooth/sdp.h>
|
|
|
|
#include <bluetooth/sdp_lib.h>
|
|
|
|
|
2008-05-09 06:19:14 +08:00
|
|
|
#include <gdbus.h>
|
2007-03-19 22:58:44 +08:00
|
|
|
|
2010-05-21 20:26:15 +08:00
|
|
|
#include "log.h"
|
2008-07-30 02:35:12 +08:00
|
|
|
#include "../src/adapter.h"
|
|
|
|
#include "../src/device.h"
|
2007-03-19 22:58:44 +08:00
|
|
|
|
|
|
|
#include "device.h"
|
2007-04-05 05:36:45 +08:00
|
|
|
#include "server.h"
|
2008-12-23 11:32:20 +08:00
|
|
|
#include "manager.h"
|
2007-03-19 22:58:44 +08:00
|
|
|
|
2008-05-15 05:49:07 +08:00
|
|
|
static int idle_timeout = 0;
|
|
|
|
|
2007-03-19 22:58:44 +08:00
|
|
|
static DBusConnection *connection = NULL;
|
2009-08-10 05:35:39 +08:00
|
|
|
static GSList *adapters = NULL;
|
2007-03-19 22:58:44 +08:00
|
|
|
|
2008-09-03 04:32:40 +08:00
|
|
|
static void input_remove(struct btd_device *device, const char *uuid)
|
2008-08-14 02:04:56 +08:00
|
|
|
{
|
|
|
|
const gchar *path = device_get_path(device);
|
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
|
|
|
input_device_unregister(path, uuid);
|
|
|
|
}
|
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
static int hid_device_probe(struct btd_device *device, GSList *uuids)
|
2007-04-17 21:22:58 +08:00
|
|
|
{
|
2008-09-04 18:33:43 +08:00
|
|
|
struct btd_adapter *adapter = device_get_adapter(device);
|
2008-07-19 04:45:39 +08:00
|
|
|
const gchar *path = device_get_path(device);
|
2008-10-09 20:11:16 +08:00
|
|
|
const sdp_record_t *rec = btd_device_get_record(device, uuids->data);
|
2008-07-19 04:45:39 +08:00
|
|
|
bdaddr_t src, dst;
|
|
|
|
|
|
|
|
DBG("path %s", path);
|
2007-04-17 21:22:58 +08:00
|
|
|
|
Fix possible crash on startup
0 0x0000000000a5cf71 in sdp_data_get (rec=0x0, attrId=0) at sdp.c:1444
1 0x000000008c704721 in hid_device_probe (device=0x7f1bed2a80b0, uuids=0x7f1bed29fa90) at manager.c:70
2 0x00007f1becb5bc33 in device_probe_drivers (device=0x7f1bed2a80b0, uuids=0x7f1bed2a2980) at device.c:647
3 0x00007f1becb58a23 in create_stored_device_from_profiles (key=0x7f1bed2a7360 "00:1E:45:AD:F1:96",
value=0x7f1bed2a7aa0 "00000002-0000-1000-8000-0002ee000002 00001101-0000-1000-8000-00805f9b34fb 00001103-0000-1000-8000-00805f9b34fb 00001104-0000-1000-8000-00805f9b34fb 00001105-0000-1000-8000-00805f9b34fb 00001106-0000-1"..., user_data=0x7f1bed29edd0) at adapter.c:2296
4 0x00007f1becb61d12 in textfile_foreach (pathname=0x7ffff4b6f2a0 "/var/lib/bluetooth/00:13:EF:F1:42:B7/profiles", func=0x7f1becb58955 <create_stored_device_from_profiles>, data=0x7f1bed29edd0) at textfile.c:447
5 0x00007f1becb58b36 in load_devices (adapter=0x7f1bed29edd0) at adapter.c:2327
6 0x00007f1becb58fa0 in adapter_up (adapter=0x7f1bed29edd0, dd=18) at adapter.c:2462
7 0x00007f1becb59479 in adapter_start (adapter=0x7f1bed29edd0) at adapter.c:2569
8 0x00007f1becb5427f in manager_start_adapter (id=0) at manager.c:424
9 0x00007f1becb48e02 in device_devup_setup (dev_id=0) at main.c:481
10 0x00007f1becb48f35 in init_all_devices (ctl=7) at main.c:512
11 0x00007f1becb496d0 in main (argc=1, argv=0x7ffff4b70788) at main.c:748
The HID device's SDP record can be NULL, so don't crash when that happens
2008-10-12 07:01:43 +08:00
|
|
|
if (!rec)
|
|
|
|
return -1;
|
|
|
|
|
2008-09-08 16:09:38 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
2008-09-08 20:25:14 +08:00
|
|
|
device_get_address(device, &dst);
|
2007-04-17 21:22:58 +08:00
|
|
|
|
2009-04-23 02:41:56 +08:00
|
|
|
return input_device_register(connection, device, path, &src, &dst,
|
2008-10-15 04:15:14 +08:00
|
|
|
HID_UUID, rec->handle, idle_timeout * 60);
|
2007-04-17 21:22:58 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 23:18:28 +08:00
|
|
|
static void hid_device_remove(struct btd_device *device)
|
2007-10-04 23:48:32 +08:00
|
|
|
{
|
2008-08-14 02:04:56 +08:00
|
|
|
input_remove(device, HID_UUID);
|
2007-10-04 23:48:32 +08:00
|
|
|
}
|
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
static int headset_probe(struct btd_device *device, GSList *uuids)
|
2007-03-19 22:58:44 +08:00
|
|
|
{
|
2008-09-04 18:33:43 +08:00
|
|
|
struct btd_adapter *adapter = device_get_adapter(device);
|
2008-07-19 04:45:39 +08:00
|
|
|
const gchar *path = device_get_path(device);
|
2008-11-09 04:33:29 +08:00
|
|
|
const sdp_record_t *record;
|
2007-03-19 22:58:44 +08:00
|
|
|
sdp_list_t *protos;
|
|
|
|
uint8_t ch;
|
2008-07-19 04:45:39 +08:00
|
|
|
bdaddr_t src, dst;
|
2007-03-19 22:58:44 +08:00
|
|
|
|
2008-07-19 04:45:39 +08:00
|
|
|
DBG("path %s", path);
|
2007-03-19 22:58:44 +08:00
|
|
|
|
2008-11-09 04:31:22 +08:00
|
|
|
if (!g_slist_find_custom(uuids, HSP_HS_UUID,
|
|
|
|
(GCompareFunc) strcasecmp))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
record = btd_device_get_record(device, uuids->data);
|
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
if (!record || sdp_get_access_protos(record, &protos) < 0) {
|
2008-07-19 04:45:39 +08:00
|
|
|
error("Invalid record");
|
|
|
|
return -EINVAL;
|
2007-03-19 22:58:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ch = sdp_get_proto_port(protos, RFCOMM_UUID);
|
2007-04-12 04:25:40 +08:00
|
|
|
sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
|
2007-03-19 22:58:44 +08:00
|
|
|
sdp_list_free(protos, NULL);
|
|
|
|
|
|
|
|
if (ch <= 0) {
|
|
|
|
error("Invalid RFCOMM channel");
|
2008-07-19 04:45:39 +08:00
|
|
|
return -EINVAL;
|
2007-03-19 22:58:44 +08:00
|
|
|
}
|
|
|
|
|
2008-09-08 16:09:38 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
2008-09-08 20:25:14 +08:00
|
|
|
device_get_address(device, &dst);
|
2007-03-19 22:58:44 +08:00
|
|
|
|
2009-04-23 02:41:56 +08:00
|
|
|
return fake_input_register(connection, device, path, &src, &dst,
|
2008-08-14 02:04:56 +08:00
|
|
|
HSP_HS_UUID, ch);
|
|
|
|
}
|
|
|
|
|
2008-09-03 04:32:40 +08:00
|
|
|
static void headset_remove(struct btd_device *device)
|
2008-08-14 02:04:56 +08:00
|
|
|
{
|
|
|
|
input_remove(device, HSP_HS_UUID);
|
2007-03-19 22:58:44 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 23:18:28 +08:00
|
|
|
static int hid_server_probe(struct btd_adapter *adapter)
|
|
|
|
{
|
|
|
|
bdaddr_t src;
|
2009-05-27 03:21:10 +08:00
|
|
|
int ret;
|
2008-09-04 23:18:28 +08:00
|
|
|
|
2008-09-08 16:09:38 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
2008-09-04 23:18:28 +08:00
|
|
|
|
2009-05-27 03:21:10 +08:00
|
|
|
ret = server_start(&src);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
adapters = g_slist_append(adapters, btd_adapter_ref(adapter));
|
|
|
|
|
|
|
|
return 0;
|
2008-09-04 23:18:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hid_server_remove(struct btd_adapter *adapter)
|
|
|
|
{
|
|
|
|
bdaddr_t src;
|
|
|
|
|
2008-09-08 16:09:38 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
2008-09-04 23:18:28 +08:00
|
|
|
|
|
|
|
server_stop(&src);
|
2009-05-27 03:21:10 +08:00
|
|
|
|
|
|
|
adapters = g_slist_remove(adapters, adapter);
|
|
|
|
btd_adapter_unref(adapter);
|
2008-09-04 23:18:28 +08:00
|
|
|
}
|
|
|
|
|
2008-08-14 02:04:56 +08:00
|
|
|
static struct btd_device_driver input_hid_driver = {
|
|
|
|
.name = "input-hid",
|
2008-07-19 04:45:39 +08:00
|
|
|
.uuids = BTD_UUIDS(HID_UUID),
|
2008-09-04 23:18:28 +08:00
|
|
|
.probe = hid_device_probe,
|
|
|
|
.remove = hid_device_remove,
|
2007-05-09 22:53:34 +08:00
|
|
|
};
|
|
|
|
|
2008-07-19 04:45:39 +08:00
|
|
|
static struct btd_device_driver input_headset_driver = {
|
|
|
|
.name = "input-headset",
|
|
|
|
.uuids = BTD_UUIDS(HSP_HS_UUID),
|
2008-08-14 02:04:56 +08:00
|
|
|
.probe = headset_probe,
|
|
|
|
.remove = headset_remove,
|
2007-05-09 22:53:34 +08:00
|
|
|
};
|
|
|
|
|
2008-09-04 23:18:28 +08:00
|
|
|
static struct btd_adapter_driver input_server_driver = {
|
|
|
|
.name = "input-server",
|
|
|
|
.probe = hid_server_probe,
|
|
|
|
.remove = hid_server_remove,
|
|
|
|
};
|
|
|
|
|
2008-05-15 05:49:07 +08:00
|
|
|
int input_manager_init(DBusConnection *conn, GKeyFile *config)
|
2007-03-14 02:13:28 +08:00
|
|
|
{
|
2008-05-15 05:49:07 +08:00
|
|
|
GError *err = NULL;
|
2008-07-19 04:45:39 +08:00
|
|
|
|
2008-05-15 05:49:07 +08:00
|
|
|
if (config) {
|
|
|
|
idle_timeout = g_key_file_get_integer(config, "General",
|
|
|
|
"IdleTimeout", &err);
|
|
|
|
if (err) {
|
2010-05-21 23:54:54 +08:00
|
|
|
DBG("input.conf: %s", err->message);
|
2008-05-15 05:49:07 +08:00
|
|
|
g_error_free(err);
|
|
|
|
}
|
|
|
|
}
|
2007-03-19 22:58:44 +08:00
|
|
|
|
2007-05-09 22:53:34 +08:00
|
|
|
connection = dbus_connection_ref(conn);
|
|
|
|
|
2008-09-04 23:18:28 +08:00
|
|
|
btd_register_adapter_driver(&input_server_driver);
|
2007-04-05 05:36:45 +08:00
|
|
|
|
2008-08-14 02:04:56 +08:00
|
|
|
btd_register_device_driver(&input_hid_driver);
|
2008-07-19 04:45:39 +08:00
|
|
|
btd_register_device_driver(&input_headset_driver);
|
|
|
|
|
2007-03-14 02:13:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-22 23:37:36 +08:00
|
|
|
void input_manager_exit(void)
|
2007-03-14 02:13:28 +08:00
|
|
|
{
|
2008-08-14 02:04:56 +08:00
|
|
|
btd_unregister_device_driver(&input_hid_driver);
|
2008-07-19 04:45:39 +08:00
|
|
|
btd_unregister_device_driver(&input_headset_driver);
|
|
|
|
|
2008-09-05 04:40:41 +08:00
|
|
|
btd_unregister_adapter_driver(&input_server_driver);
|
|
|
|
|
2007-03-19 22:58:44 +08:00
|
|
|
dbus_connection_unref(connection);
|
|
|
|
|
2007-03-27 18:27:01 +08:00
|
|
|
connection = NULL;
|
2007-03-14 02:13:28 +08:00
|
|
|
}
|