input: Update virtual input devices with correct info
authorAbhishek Pandit-Subedi <abhishekpandit@chromium.org>
Tue, 3 Dec 2019 01:03:58 +0000 (17:03 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:47 +0000 (14:30 +0530)
Update uhid and uinput devices with lowercase addresses (to match how
kernel prints it via %pMR). Also update uinput to include the phys
attribute and correctly set the vendor/product/version during init.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/audio/avctp.c
profiles/input/device.c
profiles/input/hog-lib.c

index 4ec06b7..14e32a4 100644 (file)
@@ -1219,7 +1219,8 @@ failed:
        return FALSE;
 }
 
-static int uinput_create(char *name)
+static int uinput_create(struct btd_device *device, const char *name,
+                        const char *phys)
 {
        struct uinput_dev dev;
        int fd, err, i;
@@ -1243,9 +1244,9 @@ static int uinput_create(char *name)
                strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE - 1);
 
        dev.id.bustype = BUS_BLUETOOTH;
-       dev.id.vendor  = 0x0000;
-       dev.id.product = 0x0000;
-       dev.id.version = 0x0000;
+       dev.id.vendor  = btd_device_get_vendor(device);
+       dev.id.product = btd_device_get_product(device);
+       dev.id.version = btd_device_get_version(device);
 
        if (write(fd, &dev, sizeof(dev)) < 0) {
                err = -errno;
@@ -1259,6 +1260,10 @@ static int uinput_create(char *name)
        ioctl(fd, UI_SET_EVBIT, EV_REL);
        ioctl(fd, UI_SET_EVBIT, EV_REP);
        ioctl(fd, UI_SET_EVBIT, EV_SYN);
+
+       /* Also set the phys */
+       ioctl(fd, UI_SET_PHYS, phys);
+
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        ioctl(fd, UI_SET_EVBIT, EV_ABS);
 #endif
@@ -1281,7 +1286,7 @@ static int uinput_create(char *name)
 
 static void init_uinput(struct avctp *session)
 {
-       char address[18], name[248 + 1];
+       char address[18], phy[18], name[248 + 1];
 
        device_get_name(session->device, name, sizeof(name));
        if (g_str_equal(name, "Nokia CK-20W")) {
@@ -1291,14 +1296,17 @@ static void init_uinput(struct avctp *session)
                session->key_quirks[AVC_PAUSE] |= QUIRK_NO_RELEASE;
        }
 
-       ba2str(device_get_address(session->device), address);
+       ba2strlc(device_get_address(session->device), address);
+       ba2strlc(btd_adapter_get_address(device_get_adapter(session->device)),
+                phys);
+
        /*
         * Make sucre address to prevent to print privacy log
         */
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        address[6] = address[7] = address[9] = address[10] = 'X';
 #endif
-       session->uinput = uinput_create(address);
+       session->uinput = uinput_create(session->device, address, phys);
        if (session->uinput < 0)
                error("AVRCP: failed to init uinput for %s", address);
        else
index 1625264..8d24b1e 100644 (file)
@@ -861,8 +861,8 @@ static int uhid_connadd(struct input_device *idev, struct hidp_connadd_req *req)
        memset(&ev, 0, sizeof(ev));
        ev.type = UHID_CREATE;
        strncpy((char *) ev.u.create.name, req->name, sizeof(ev.u.create.name));
-       ba2str(&idev->src, (char *) ev.u.create.phys);
-       ba2str(&idev->dst, (char *) ev.u.create.uniq);
+       ba2strlc(&idev->src, (char *) ev.u.create.phys);
+       ba2strlc(&idev->dst, (char *) ev.u.create.uniq);
        ev.u.create.vendor = req->vendor;
        ev.u.create.product = req->product;
        ev.u.create.version = req->version;
index d9ed806..9c5c814 100755 (executable)
@@ -32,6 +32,7 @@
 #include <stdbool.h>
 #include <errno.h>
 #include <unistd.h>
+#include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -992,6 +993,15 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
                        BT_IO_OPT_SOURCE, ev.u.create.phys,
                        BT_IO_OPT_DEST, ev.u.create.uniq,
                        BT_IO_OPT_INVALID);
+
+       /* Phys + uniq are the same size (hw address type) */
+       for (i = 0;
+           i < (int)sizeof(ev.u.create.phys) && ev.u.create.phys[i] != 0;
+           ++i) {
+               ev.u.create.phys[i] = tolower(ev.u.create.phys[i]);
+               ev.u.create.uniq[i] = tolower(ev.u.create.uniq[i]);
+       }
+
        if (gerr) {
                error("Failed to connection details: %s", gerr->message);
                g_error_free(gerr);