summaryrefslogtreecommitdiffstats
path: root/input/device.c
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-08-03 13:32:58 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-08-03 13:32:58 +0000
commitebd3c8b3a8fe0ec8050077e7739dba0b25aec2a1 (patch)
tree984d22b13cc354d2ba9df0f88ec9e45972586dc9 /input/device.c
parent5ea00148915097d22d3d612623e95b0cf5fbd938 (diff)
input: fixed invalid D-Bus path when the remote device class is unknown
Diffstat (limited to 'input/device.c')
-rw-r--r--input/device.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/input/device.c b/input/device.c
index 5c022ae6..4f983d99 100644
--- a/input/device.c
+++ b/input/device.c
@@ -85,10 +85,22 @@ struct device {
GSList *devices = NULL;
-static struct device *device_new(bdaddr_t *src, bdaddr_t *dst)
+static struct device *device_new(bdaddr_t *src, bdaddr_t *dst, uint8_t subclass)
{
struct device *idev;
uint32_t cls;
+ uint8_t major, minor;
+
+ if (!subclass) {
+ if (read_device_class(src, dst, &cls) < 0)
+ return NULL;
+
+ major = (cls >> 8) & 0x1f;
+ minor = (cls >> 2) & 0x3f;
+ } else {
+ major = 0x05; /* Peripheral */
+ minor = (subclass >> 2) & 0x3f;
+ }
idev = g_new0(struct device, 1);
@@ -96,10 +108,9 @@ static struct device *device_new(bdaddr_t *src, bdaddr_t *dst)
bacpy(&idev->dst, dst);
read_device_name(src, dst, &idev->name);
- read_device_class(src, dst, &cls);
- idev->major = (cls >> 8) & 0x1f;
- idev->minor = (cls >> 2) & 0x3f;
+ idev->major = major;
+ idev->minor = minor;
idev->ctrl_sk = -1;
idev->intr_sk = -1;
@@ -1055,8 +1066,16 @@ int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst,
const char *path;
int err;
- idev = device_new(src, dst);
+ idev = device_new(src, dst, hid->subclass);
+ if (!idev)
+ return -EINVAL;
+
path = create_input_path(idev->major, idev->minor);
+ if (!path) {
+ device_free(idev);
+ return -EINVAL;
+ }
+
idev->path = g_strdup(path);
idev->product = hid->product;
idev->vendor = hid->vendor;
@@ -1077,8 +1096,16 @@ int fake_input_register(DBusConnection *conn, bdaddr_t *src,
const char *path;
int err;
- idev = device_new(src, dst);
+ idev = device_new(src, dst, 0);
+ if (!idev)
+ return -EINVAL;
+
path = create_input_path(idev->major, idev->minor);
+ if (!path) {
+ device_free(idev);
+ return -EINVAL;
+ }
+
idev->path = g_strdup(path);
idev->conn = dbus_connection_ref(conn);