Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5875195ybc; Wed, 27 Nov 2019 10:52:42 -0800 (PST) X-Google-Smtp-Source: APXvYqx9Aq37Fqasy+WLtnwW/Xw8weI97Sy3OHxsAc9v3Sg0Ttd73IZTpAOZhie86wDRTR3WzAkk X-Received: by 2002:aa7:d904:: with SMTP id a4mr29164358edr.44.1574880762443; Wed, 27 Nov 2019 10:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574880762; cv=none; d=google.com; s=arc-20160816; b=1CrzNb56UVZX8bYEvEZJWCIqTvzuNMnj20ZQeSy+WtFSXz/JqJAc06SvwijBDaFWkw 9FZmzbbRWuWHym8ruJdcFKZcZW71PdEm6YpDAlcBdKhYgTc56vFlWbistPJDEfsP+mTP wwhnVrpum6OlEkbKHJ++NvmZ6QAfraxbUVGGy2Qe+EFmZ+hExDw/TsBqryp4txoeXdqL OYfsPbAAPkTIGp3zu9ix4Vc36+LYO1JYnBgU3Fv7tEcWUn4f4zE/cxAn6Hx0slnE3pdU l9s5nwQCHfv7ULpK7KF8DOsYOa2dadgsb6QaO7w7o4xHMDg/Rj2c1VokKuP3RmduqukG /u9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YimDLRO44EFdVpsrruJmPdiNyDfnYjYesEmjPbE4iug=; b=Nu325jPmDrWMBGHJn6iQidd0qxuS52LLYPOHGmskty8wyWmDATtWSi80gOvpbtnujv L1l3SztP1m9eL8T55AexXzH7M5Q5FAG90gnJLE4HEByHwlmDmWCIYD3pu5do0vUCwz+N huibPXCIgilgY5Yu9coX3aCyvg4KkSkz5zKzGju+V6DqLRj/lTTpUaLO7ishBAHf7uLn l+PUFNrP1zXRzPXax+ObOUj+bBviHVw3byQN/THb6/SsMDUT/FFzA60EKgmI87myXtYq cFkXmZqka2BLjdMHK8UaBwWBNMJ2q9IE3n+skGFJRfbTHOEVfg1CXuim+Iyc/2K8/WL1 c1DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="D/I1PI3/"; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si10640969edp.357.2019.11.27.10.52.02; Wed, 27 Nov 2019 10:52:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="D/I1PI3/"; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727071AbfK0Sv4 (ORCPT + 99 others); Wed, 27 Nov 2019 13:51:56 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39024 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727345AbfK0Sv4 (ORCPT ); Wed, 27 Nov 2019 13:51:56 -0500 Received: by mail-pl1-f193.google.com with SMTP id o9so10181970plk.6 for ; Wed, 27 Nov 2019 10:51:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YimDLRO44EFdVpsrruJmPdiNyDfnYjYesEmjPbE4iug=; b=D/I1PI3/xRstodfiyXqR1BgtCy/ajR8WN0uJqbYuGeWhpekpVi8hrssvJ6Uej9JgIC OQiXNI3dbKwmTz8Opz4WZIL67/55kCioIxXRa5OrTNIM/kclnAYk1eDIm9peYJE5fqNn LFNTa/mOB4TkrVqFH/GHRejPJk47fxpl9tYV8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YimDLRO44EFdVpsrruJmPdiNyDfnYjYesEmjPbE4iug=; b=kaeDbbwZuxJpR5xC1zSTNWWRkjHr1n1yHBNT6HenzJh4qslLY5uYoB0II8WHLxUgGP I9eClV8Zy0c3ByShneGEsj5hqwp7R1DA5I19HuYkoeT7dfSWUeCbOXtpK6OUdbwOELjN fQNOi3XLFp9t8pBaexeA/5CpjW86jRMstD2IaQtMcxt70kCM+zXnzrrtrINyW8qFVb/A 1fjs87uS6nupJiriuvYSvUzSdkHa/c/PFXFWHqJo70JzBLzY8+SvZPO2iNPFbY4hqJu3 v/VkCd9HuOjwap6Hm6Ue9VenSEyBElytkFC0MDYHN7lBARpJ7oeUIxeHwXStEmt8XmGM bHNQ== X-Gm-Message-State: APjAAAX0VuQy0w/U1Ff3TwF7ElUZ9PopoH07BGnPYcJH9tpM1o4PvBfU Of1I3eEh+n+LWyjHyy7Ld8UOmw== X-Received: by 2002:a17:90a:c68f:: with SMTP id n15mr7977113pjt.20.1574880715835; Wed, 27 Nov 2019 10:51:55 -0800 (PST) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id x2sm17088680pgc.67.2019.11.27.10.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 10:51:55 -0800 (PST) From: Abhishek Pandit-Subedi To: linux-input@vger.kernel.org Cc: =?UTF-8?q?Pali=20Roh=C3=A1r?= , linux-bluetooth@vger.kernel.org, Luiz Augusto von Dentz , Abhishek Pandit-Subedi , Enric Balletbo i Serra , linux-kernel@vger.kernel.org, Thomas Gleixner , Logan Gunthorpe , Dmitry Torokhov , Andrey Smirnov , Kirill Smelkov Subject: [PATCH] Input: uinput - Add UI_SET_UNIQ ioctl handler Date: Wed, 27 Nov 2019 10:51:39 -0800 Message-Id: <20191127185139.65048-1-abhishekpandit@chromium.org> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Support setting the uniq attribute of the input device. The uniq attribute is used as a unique identifier for the connected device. For example, uinput devices created by BlueZ will store the address of the connected device as the uniq property. Signed-off-by: Abhishek Pandit-Subedi --- Hi input maintainers, I added this change to allow BlueZ to display the peer device address in udev. BlueZ has been setting ATTR{name} to the peer address since it isn't possible to set the uniq attribute currently. I've tested this on a Chromebook running kernel v4.19 with this patch. $ uname -r 4.19.85 $ dmesg | grep "input:" | tail -1 [ 69.604752] input: BeatsStudio Wireless as /devices/virtual/input/input17 $ udevadm info -a -p /sys/devices/virtual/input/input17 Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/virtual/input/input17': KERNEL=="input17" SUBSYSTEM=="input" DRIVER=="" ATTR{inhibited}=="0" ATTR{name}=="BeatsStudio Wireless" ATTR{phys}=="00:00:00:6e:d0:74" ATTR{properties}=="0" ATTR{uniq}=="00:00:00:cc:1c:f3" (I zeroed out part of the addresses above. The phys attribute corresponds to the address of the Bluetooth controller on the Chromebook and the uniq is the address of the headphones) drivers/input/misc/uinput.c | 21 ++++++++++++++++++++- include/uapi/linux/uinput.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 84051f20b18a..68319bda41b8 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -280,7 +280,7 @@ static int uinput_dev_flush(struct input_dev *dev, struct file *file) static void uinput_destroy_device(struct uinput_device *udev) { - const char *name, *phys; + const char *name, *phys, *uniq; struct input_dev *dev = udev->dev; enum uinput_state old_state = udev->state; @@ -289,6 +289,7 @@ static void uinput_destroy_device(struct uinput_device *udev) if (dev) { name = dev->name; phys = dev->phys; + uniq = dev->uniq; if (old_state == UIST_CREATED) { uinput_flush_requests(udev); input_unregister_device(dev); @@ -297,6 +298,7 @@ static void uinput_destroy_device(struct uinput_device *udev) } kfree(name); kfree(phys); + kfree(uniq); udev->dev = NULL; } } @@ -840,6 +842,7 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, struct uinput_ff_erase ff_erase; struct uinput_request *req; char *phys; + char *uniq; const char *name; unsigned int size; @@ -931,6 +934,22 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, udev->dev->phys = phys; goto out; + case UI_SET_UNIQ: + if (udev->state == UIST_CREATED) { + retval = -EINVAL; + goto out; + } + + uniq = strndup_user(p, 1024); + if (IS_ERR(uniq)) { + retval = PTR_ERR(uniq); + goto out; + } + + kfree(udev->dev->uniq); + udev->dev->uniq = uniq; + goto out; + case UI_BEGIN_FF_UPLOAD: retval = uinput_ff_upload_from_user(p, &ff_up); if (retval) diff --git a/include/uapi/linux/uinput.h b/include/uapi/linux/uinput.h index c9e677e3af1d..d5b7767c1b02 100644 --- a/include/uapi/linux/uinput.h +++ b/include/uapi/linux/uinput.h @@ -145,6 +145,7 @@ struct uinput_abs_setup { #define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*) #define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int) #define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int) +#define UI_SET_UNIQ _IOW(UINPUT_IOCTL_BASE, 111, char*) #define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload) #define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload) -- 2.24.0.432.g9d3f5f5b63-goog