Skip to contentSkip to conversation

hog: Use HoG device name as uHID input device name

PATCH Superseded Petri Gynther 2 participants 3 messages Jan 30, 2014 – Feb 14, 2014 Bluetooth drivers

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hog: Use HoG device name as uHID input device name

If HoG BLE device name is known, use it when creating uHID input device. Pass adapter and device addresses to uHID as well.

---
 profiles/input/hog.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
profiles/input/hog.c +9 -1
index ded6303..030dc91 100644
@@ -392,7 +392,15 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
 	/* create uHID device */
 	memset(&ev, 0, sizeof(ev));
 	ev.type = UHID_CREATE;
-	strcpy((char *) ev.u.create.name, "bluez-hog-device");
+	if (device_name_known(hogdev->device)) {
+		device_get_name(hogdev->device, (char *) ev.u.create.name,
+				sizeof(ev.u.create.name) - 1);
+	} else {
+		strcpy((char *) ev.u.create.name, "bluez-hog-device");
+	}
+	ba2str(btd_adapter_get_address(device_get_adapter(hogdev->device)),
+		(char *) ev.u.create.phys);
+	ba2str(device_get_address(hogdev->device), (char *) ev.u.create.uniq);
 	ev.u.create.vendor = vendor;
 	ev.u.create.product = product;
 	ev.u.create.version = version;
Signature · 1 line
1.8.5.3
#1 lore raw

Hi Petri,

Quoted 2 lines · Petri Gynther

If HoG BLE device name is known, use it when creating uHID input device. Pass adapter and device addresses to uHID as well.

Could you perhaps elaborate a bit what exactly the "uniq" and "phys" members are in the request (possibly with a reference to the uHID documentation). That would make it easier to verify that the content you're adding to them makes sense.

profiles/input/hog.c static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen, · line 400

Quoted 6 lines
profiles/input/hog.c +6 -0
+	if (device_name_known(hogdev->device)) {
+		device_get_name(hogdev->device, (char *) ev.u.create.name,
+				sizeof(ev.u.create.name) - 1);
+	} else {
+		strcpy((char *) ev.u.create.name, "bluez-hog-device");
+	}

We don't use { } for single line branches, so you can drop these here.

profiles/input/hog.c static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen, · line 402

Quoted 2 lines
profiles/input/hog.c +2 -0
+	ba2str(btd_adapter_get_address(device_get_adapter(hogdev->device)),
+		(char *) ev.u.create.phys);

This is getting a bit messy with the nested function calls. I'd add separate adapter variable here to make this a bit more readable.

Also note our coding style wrt split lines: indent the continuation lines as much as you can (with tabs) as long as it's under 80 chars.

Also, it might be good to split this up into two patches since you've essentially got two independent improvements here. One is making sure the name member contains something more useful and the other is adding some content to the uniq and phys members.

Johan

#2 lore raw

Hi Johan,

Quoted 6 lines · Johan Hedberg

Hi Petri,

Quoted 2 lines · Petri Gynther

If HoG BLE device name is known, use it when creating uHID input device. Pass adapter and device addresses to uHID as well.

Quoted 7 lines

Could you perhaps elaborate a bit what exactly the "uniq" and "phys" members are in the request (possibly with a reference to the uHID documentation). That would make it easier to verify that the content you're adding to them makes sense.

From linux/include/linux/hid.h:

struct hid_device {
...
char name[128]; /* Device name */
char phys[64]; /* Device physical location */
char uniq[64]; /* Device unique identifier (serial #) */

So, for a Bluetooth HID or HoG device, BT adapter MAC address is good fit for "phys" and device MAC address is good for "uniq". This is what hidp module in kernel already does. But, we can be more descriptive here if we want. These values are readable in sysfs under /sys/devices/virtual/input/<input-device>.

Quoted 9 lines

profiles/input/hog.c static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen, · line 400

Quoted 6 lines
profiles/input/hog.c +6 -0
+     if (device_name_known(hogdev->device)) {
+             device_get_name(hogdev->device, (char *) ev.u.create.name,
+                             sizeof(ev.u.create.name) - 1);
+     } else {
+             strcpy((char *) ev.u.create.name, "bluez-hog-device");
+     }

We don't use { } for single line branches, so you can drop these here.

I'll fix this.

Quoted 6 lines

profiles/input/hog.c static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen, · line 402

Quoted 2 lines
profiles/input/hog.c +2 -0
+     ba2str(btd_adapter_get_address(device_get_adapter(hogdev->device)),
+             (char *) ev.u.create.phys);

This is getting a bit messy with the nested function calls. I'd add separate adapter variable here to make this a bit more readable.

Quoted 7 lines

Also note our coding style wrt split lines: indent the continuation lines as much as you can (with tabs) as long as it's under 80 chars.

Also, it might be good to split this up into two patches since you've essentially got two independent improvements here. One is making sure the name member contains something more useful and the other is adding some content to the uniq and phys members.

I'll add name, phys, and uniq variables in struct hog_device, so that they are easy to pass to uHID when it is time to create the uHID device.

Quoted 2 lines

Johan