From patchwork Mon Feb 21 22:45:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 578791 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1LMjV7F031796 for ; Mon, 21 Feb 2011 22:45:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753550Ab1BUWpO (ORCPT ); Mon, 21 Feb 2011 17:45:14 -0500 Received: from smtp204.alice.it ([82.57.200.100]:55974 "EHLO smtp204.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753445Ab1BUWpL (ORCPT ); Mon, 21 Feb 2011 17:45:11 -0500 Received: from jcn (79.2.139.61) by smtp204.alice.it (8.5.124.08) (authenticated as fospite@alice.it) id 4D498E39019F74B2; Mon, 21 Feb 2011 23:45:09 +0100 Date: Mon, 21 Feb 2011 23:45:02 +0100 From: Antonio Ospite To: linux-hotplug@vger.kernel.org Cc: linux-input@vger.kernel.org, linux-bluetooth@vger.kernel.org Subject: Re: [RESEND] ID_SERIAL for udev bluetooth joystick events Message-Id: <20110221234502.c38a5205.ospite@studenti.unina.it> In-Reply-To: <20110210114204.9639661d.ospite@studenti.unina.it> References: <20110210114204.9639661d.ospite@studenti.unina.it> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.20.1; x86_64-unknown-linux-gnu) X-Face: z*RaLf`X<@C75u6Ig9}{oW$H; 1_\2t5)({*|jhM/Vb; ]yA5\I~93>J<_`<4)A{':UrE Mime-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 21 Feb 2011 22:45:32 +0000 (UTC) diff --git a/extras/usb_id/usb_id.c b/extras/usb_id/usb_id.c index fabd092..8e6e20f 100644 --- a/extras/usb_id/usb_id.c +++ b/extras/usb_id/usb_id.c @@ -56,6 +56,7 @@ static char serial_str[UTIL_NAME_SIZE]; static char packed_if_str[UTIL_NAME_SIZE]; static char revision_str[64]; static char type_str[64]; +static char bustype_str[64]; static char instance_str[64]; static const char *ifnum; static const char *driver; @@ -147,6 +148,29 @@ static int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len return type_num; } +static int set_usb_input_bustype(char *to, const char *from, size_t len) +{ + int bustype_num = 0; + char *eptr; + char *type = "unknown"; + + bustype_num = strtoul(from, &eptr, 0); + if (eptr != from) { + switch (bustype_num) { + case 3: + type = "usb"; + break; + case 5: + type = "bluetooth"; + break; + default: + break; + } + } + util_strscpy(to, len, type); + return bustype_num; +} + static void set_scsi_type(char *to, const char *from, size_t len) { int type_num; @@ -312,8 +336,8 @@ static int usb_id(struct udev_device *dev) set_usb_iftype(type_str, if_class_num, sizeof(type_str)-1); } - info(udev, "%s: if_class %d protocol %d\n", - udev_device_get_syspath(dev_interface), if_class_num, protocol); + info(udev, "%s: if_class %d protocol %d type_str: %s\n", + udev_device_get_syspath(dev_interface), if_class_num, protocol, type_str); /* usb device directory */ dev_usb = udev_device_get_parent_with_subsystem_devtype(dev_interface, "usb", "usb_device"); @@ -326,6 +350,57 @@ static int usb_id(struct udev_device *dev) /* all interfaces of the device in a single string */ dev_if_packed_info(dev_usb, packed_if_str, sizeof(packed_if_str)); + /* input device XXX this check is not right, we might use a dev_input + * as below */ + if ((protocol == 0) && !use_usb_info) { + struct udev_device *dev_input; + const char *input_vendor, *input_model, *input_rev, *input_bustype; + + /* get input device */ + dev_input = udev_device_get_parent_with_subsystem_devtype(dev, "input", NULL); + if (dev_input == NULL) { + info(udev, "unable to find parent 'input' device of '%s'\n", + udev_device_get_syspath(dev)); + goto fallback; + } + + input_vendor = udev_device_get_sysattr_value(dev_input, "id/vendor"); + if (!input_vendor) { + info(udev, "%s: cannot get input vendor attribute\n", + udev_device_get_sysname(dev_input)); + goto fallback; + } + udev_util_encode_string(input_vendor, vendor_str_enc, sizeof(vendor_str_enc)); + udev_util_replace_whitespace(input_vendor, vendor_str, sizeof(vendor_str)-1); + udev_util_replace_chars(vendor_str, NULL); + + vendor_id = input_vendor; + product_id = udev_device_get_sysattr_value(dev_input, "id/product"); + + input_model = udev_device_get_sysattr_value(dev_input, "name"); + if (!input_model) { + info(udev, "%s: cannot get input model attribute\n", + udev_device_get_sysname(dev_input)); + goto fallback; + } + udev_util_encode_string(input_model, model_str_enc, sizeof(model_str_enc)); + udev_util_replace_whitespace(input_model, model_str, sizeof(model_str)-1); + udev_util_replace_chars(model_str, NULL); + + input_rev = udev_device_get_sysattr_value(dev_input, "id/version"); + if (!input_rev) { + info(udev, "%s: cannot get input revision attribute\n", + udev_device_get_sysname(dev_input)); + goto fallback; + } + udev_util_replace_whitespace(input_rev, revision_str, sizeof(revision_str)-1); + udev_util_replace_chars(revision_str, NULL); + + /* get Bus type, see BUS_* in linux/input.h */ + input_bustype = udev_device_get_sysattr_value(dev_input, "id/bustype"); + set_usb_input_bustype(bustype_str, input_bustype, sizeof(bustype_str) - 1 ); + } + /* mass storage : SCSI or ATAPI */ if ((protocol == 6 || protocol == 2) && !use_usb_info) { struct udev_device *dev_scsi; @@ -390,8 +465,12 @@ static int usb_id(struct udev_device *dev) } fallback: - vendor_id = udev_device_get_sysattr_value(dev_usb, "idVendor"); - product_id = udev_device_get_sysattr_value(dev_usb, "idProduct"); + if (vendor_id[0] == '\0') { + vendor_id = udev_device_get_sysattr_value(dev_usb, "idVendor"); + } + if (product_id[0] == '\0') { + product_id = udev_device_get_sysattr_value(dev_usb, "idProduct"); + } /* fallback to USB vendor & device */ if (vendor_str[0] == '\0') { @@ -559,7 +638,7 @@ int main(int argc, char **argv) printf("ID_TYPE=%s\n", type_str); if (instance_str[0] != '\0') printf("ID_INSTANCE=%s\n", instance_str); - printf("ID_BUS=usb\n"); + printf("ID_BUS=%s\n", (bustype_str[0] == '\0') ? "usb" : bustype_str); if (packed_if_str[0] != '\0') printf("ID_USB_INTERFACES=:%s\n", packed_if_str); if (ifnum != NULL)