[BlueZ PATCH v2 3/4] input: Change uinput name and add AVRCP suffix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When creating the uinput device, change the name to the peer device
name and add a "(AVRCP)" suffix.

The resulting uinput device will look like this:

$ udevadm info -a -p /sys/devices/virtual/input/input17
...
  looking at device '/devices/virtual/input/input17':
    KERNEL=="input17"
    SUBSYSTEM=="input"
    DRIVER==""
    ATTR{inhibited}=="0"
    ATTR{name}=="BeatsStudio Wireless (AVRCP)"
    ATTR{phys}=="00:00:00:6e:d0:74"
    ATTR{properties}=="0"
    ATTR{uniq}==""

---

Changes in v2:
- Added "(AVRCP)" suffix and moved src address into uinput_create

 profiles/audio/avctp.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index 42136f94b..5116a5cde 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -1162,10 +1162,11 @@ failed:
 }
 
 static int uinput_create(struct btd_device *device, const char *name,
-			 const char *phys)
+			 const char *suffix);
 {
 	struct uinput_dev dev;
 	int fd, err, i;
+	char src[18];
 
 	fd = open("/dev/uinput", O_RDWR);
 	if (fd < 0) {
@@ -1185,6 +1186,23 @@ static int uinput_create(struct btd_device *device, const char *name,
 	if (name)
 		strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE - 1);
 
+	if (suffix) {
+		int len, slen;
+
+		len = strlen(dev.name);
+		slen = strlen(suffix);
+
+		/* If name + suffix don't fit, truncate the name, then add the
+		 * suffix.
+		 */
+		if (len + slen < UINPUT_MAX_NAME_SIZE - 1) {
+			strncpy(dev.name + len, suffix, slen);
+		} else {
+			len = UINPUT_MAX_NAME_SIZE - slen - 1;
+			strncpy(dev.name + len, suffix, slen);
+		}
+	}
+
 	dev.id.bustype = BUS_BLUETOOTH;
 	dev.id.vendor  = btd_device_get_vendor(device);
 	dev.id.product = btd_device_get_product(device);
@@ -1203,8 +1221,8 @@ static int uinput_create(struct btd_device *device, const char *name,
 	ioctl(fd, UI_SET_EVBIT, EV_REP);
 	ioctl(fd, UI_SET_EVBIT, EV_SYN);
 
-	/* Also set the phys */
-	ioctl(fd, UI_SET_PHYS, phys);
+	ba2strlc(btd_adapter_get_address(device_get_adapter(device)), src);
+	ioctl(fd, UI_SET_PHYS, src);
 
 	for (i = 0; key_map[i].name != NULL; i++)
 		ioctl(fd, UI_SET_KEYBIT, key_map[i].uinput);
@@ -1224,7 +1242,7 @@ static int uinput_create(struct btd_device *device, const char *name,
 
 static void init_uinput(struct avctp *session)
 {
-	char address[18], phys[18], name[248 + 1];
+	char name[248 + 1];
 
 	device_get_name(session->device, name, sizeof(name));
 	if (g_str_equal(name, "Nokia CK-20W")) {
@@ -1234,15 +1252,11 @@ static void init_uinput(struct avctp *session)
 		session->key_quirks[AVC_PAUSE] |= QUIRK_NO_RELEASE;
 	}
 
-	ba2strlc(device_get_address(session->device), address);
-	ba2strlc(btd_adapter_get_address(device_get_adapter(session->device)),
-		 phys);
-
-	session->uinput = uinput_create(session->device, address, phys);
+	session->uinput = uinput_create(session->device, name, " (AVRCP)");
 	if (session->uinput < 0)
-		error("AVRCP: failed to init uinput for %s", address);
+		error("AVRCP: failed to init uinput for %s", name);
 	else
-		DBG("AVRCP: uinput initialized for %s", address);
+		DBG("AVRCP: uinput initialized for %s", name);
 }
 
 static struct avctp_queue *avctp_queue_create(struct avctp_channel *chan)
-- 
2.24.0.393.g34dc348eaf-goog




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux