Skip to contentSkip to conversation

Add bluetooth-hid2hci to udev-extras

PATCH In review Mario Limonciello 3 participants 11 messages Jun 10, 2009 – Jun 15, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add bluetooth-hid2hci to udev-extras

Hi:

I wanted to move this tool out of the bluez project, into udev-extras. It seems to make more sense to me there as it's not really meant to be ran by the user.

I'm attaching the patch as my mail server would eat it up otherwise (Exchange).

Thanks,

Signature · 3 lines
Mario Limonciello
*Dell | Linux Engineering*
[email protected]

=== modified file 'Makefile.am'

Makefile.am +2 -1
@@ -7,7 +7,8 @@
 	keymap \
 	v4l_id \
 	udev-acl \
-	gudev
+	gudev \
+	bluetooth-hid2hci
 
 ACLOCAL_AMFLAGS = -I m4
 

=== added directory 'bluetooth-hid2hci'
=== added file 'bluetooth-hid2hci/62-bluetooth-hid2hci.rules'

62-bluetooth-hid2hci.rules +36 -0
@@ -0,0 +1,36 @@
+# Variety of Dell Bluetooth devices
+#
+# it looks like a bit of an odd rule, because it is matching
+# on a mouse device that is self powered, but that is where
+# a HID report needs to be sent to switch modes.
+#
+# Known supported devices:
+#   413c:8154
+#   413c:8158
+#   413c:8162
+ACTION=="add", ENV{ID_VENDOR}=="413c", ENV{ID_CLASS}=="mouse", ATTRS{bmAttributes}=="e0", KERNEL=="mouse*", RUN+="/lib/udev/bluetooth_hid2hci --method dell -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+
+# Logitech devices
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c703" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c704" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c705" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70a" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70b" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70c" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70e" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c713" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c714" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c71b" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c71c" RUN+="/lib/udev/bluetooth_hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+
+# CSR devices (in HID mode)
+ACTION=="add", ENV{ID_VENDOR}=="0a12", ENV{ID_MODEL}=="1000" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="0458", ENV{ID_MODEL}=="1000" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="1000" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+
+# CSR devices (in HCI mode)
+#ACTION=="add", ENV{ID_VENDOR}=="0a12", ENV{ID_MODEL}=="0001" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="0458", ENV{ID_MODEL}=="003f" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8203" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8204" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8207" RUN+="/lib/udev/bluetooth_hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"

=== added file 'bluetooth-hid2hci/Makefile.am'

Makefile.am +10 -0
@@ -0,0 +1,10 @@
+include $(top_srcdir)/Makefile.am.inc
+
+udevhomedir = $(udev_prefix)/lib/udev
+udevhome_PROGRAMS = bluetooth_hid2hci
+
+udevrulesdir = $(udev_prefix)/lib/udev/rules.d
+dist_udevrules_DATA = 62-bluetooth-hid2hci.rules
+
+bluetooth_hid2hci_SOURCES = bluetooth_hid2hci.c
+bluetooth_hid2hci_LDADD = @LIBUSB_LIBS@

=== added file 'bluetooth-hid2hci/bluetooth_hid2hci.c'

bluetooth_hid2hci.c +377 -0

377 lines not on this page · raw message

=== modified file 'configure.ac'

configure.ac +1 -0
@@ -118,6 +118,7 @@
 gudev/gudev-1.0.pc
 gudev/docs/version.xml
 gudev/docs/Makefile
+bluetooth-hid2hci/Makefile
 ])
 
 AC_OUTPUT
#1 lore raw

Hi Mario,

Quoted 3 lines

I wanted to move this tool out of the bluez project, into udev-extras. It seems to make more sense to me there as it's not really meant to be ran by the user.

please call it hid2hci and also name the directory that way since otherwise we confuse the hell out of people when multiple versions are installed.

Regards

Marcel

#2 lore raw
In reply to Mario Limonciello

Hi Marcel:

Quoted 5 lines · Marcel Holtmann

Hi Mario,

please call it hid2hci and also name the directory that way since otherwise we confuse the hell out of people when multiple versions are installed

Thanks for the feedback. I've made the changes and am resubmitting.

Regards

Signature · 3 lines
Mario Limonciello
*Dell | Linux Engineering*
[email protected]

=== modified file 'Makefile.am'

Makefile.am +2 -1
@@ -7,7 +7,8 @@
 	keymap \
 	v4l_id \
 	udev-acl \
-	gudev
+	gudev \
+	hid2hci
 
 ACLOCAL_AMFLAGS = -I m4
 

=== added directory 'hid2hci'
=== added file 'hid2hci/62-hid2hci.rules'

62-hid2hci.rules +36 -0
@@ -0,0 +1,36 @@
+# Variety of Dell Bluetooth devices
+#
+# it looks like a bit of an odd rule, because it is matching
+# on a mouse device that is self powered, but that is where
+# a HID report needs to be sent to switch modes.
+#
+# Known supported devices:
+#   413c:8154
+#   413c:8158
+#   413c:8162
+ACTION=="add", ENV{ID_VENDOR}=="413c", ENV{ID_CLASS}=="mouse", ATTRS{bmAttributes}=="e0", KERNEL=="mouse*", RUN+="/lib/udev/hid2hci --method dell -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+
+# Logitech devices
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c703" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c704" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c705" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70a" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70b" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70c" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70e" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c713" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c714" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c71b" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c71c" RUN+="/lib/udev/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+
+# CSR devices (in HID mode)
+ACTION=="add", ENV{ID_VENDOR}=="0a12", ENV{ID_MODEL}=="1000" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="0458", ENV{ID_MODEL}=="1000" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="1000" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"
+
+# CSR devices (in HCI mode)
+#ACTION=="add", ENV{ID_VENDOR}=="0a12", ENV{ID_MODEL}=="0001" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="0458", ENV{ID_MODEL}=="003f" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8203" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8204" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
+#ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8207" RUN+="/lib/udev/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"

=== added file 'hid2hci/Makefile.am'

Makefile.am +10 -0
@@ -0,0 +1,10 @@
+include $(top_srcdir)/Makefile.am.inc
+
+udevhomedir = $(udev_prefix)/lib/udev
+udevhome_PROGRAMS = hid2hci
+
+udevrulesdir = $(udev_prefix)/lib/udev/rules.d
+dist_udevrules_DATA = 62-hid2hci.rules
+
+hid2hci_SOURCES = hid2hci.c
+hid2hci_LDADD = @LIBUSB_LIBS@

=== added file 'hid2hci/bluetooth_hid2hci.c'

hid2hci.c +377 -0

377 lines not on this page · raw message

=== modified file 'configure.ac'

configure.ac +1 -0
@@ -118,6 +118,7 @@
 gudev/gudev-1.0.pc
 gudev/docs/version.xml
 gudev/docs/Makefile
+hid2hci/Makefile
 ])
 
 AC_OUTPUT
#3 lore raw
In reply to Mario Limonciello
Quoted 1 line · Mario Limonciello

Thanks for the feedback.  I've made the changes and am resubmitting.

This is all about adding USB devices, right? So the entire rules file should be guarded by:
ACTION="add", ... out
SUBSYSTEM="usb", ... out
ENV{DEVTYPE}="usb_device", ... out

to exclude all other events from trying to match these rules. Also the individual ACTION matches are not needed then.

+ ... ENV{ID_CLASS}="mouse", ..., KERNEL="mouse*", ...

I think the kernel name match is sufficient here, there is no need to rely on earlier rules which set ID_CLASS.

+ ... ENV{ID_VENDOR}="046d",

This is a property of usb_id, and usually a textual string and not a number, I guess you better match against the sysfs attribute with ATTR{}? The current stuff might work, but you should not rely on the implicit fallback to numbers of usb_id.

+ RUN+="/lib/udev/hid2hci ..."

Things in /lib/udev don't need the prefix, just use RUN+="hid2hci ..."

Thanks,
Kay

#4 lore raw
In reply to Mario Limonciello

Hi Kay:

Quoted 9 lines · Kay Sievers

This is all about adding USB devices, right? So the entire rules file should be guarded by:
ACTION=="add", ... out
SUBSYSTEM=="usb", ... out
ENV{DEVTYPE}=="usb_device", ... out

to exclude all other events from trying to match these rules. Also the individual ACTION matches are not needed then.

I added an ACTION guard around the top, but those other two guards break things.

Quoted 5 lines

+ ... ENV{ID_CLASS}=="mouse", ..., KERNEL=="mouse*", ...

I think the kernel name match is sufficient here, there is no need to rely on earlier rules which set ID_CLASS.

Yeah you are right. I removed the extra ENV call, and tested with a device, works fine.
Fixed.

Quoted 7 lines

+ ... ENV{ID_VENDOR}=="046d",

This is a property of usb_id, and usually a textual string and not a number, I guess you better match against the sysfs attribute with ATTR{}? The current stuff might work, but you should not rely on the implicit fallback to numbers of usb_id.

Fixed.

Quoted 7 lines

+ RUN+="/lib/udev/hid2hci ..."

Things in /lib/udev don't need the prefix, just use RUN+="hid2hci ..."

Thanks,
Kay

Fixed.

Thanks,

Signature · 3 lines
Mario Limonciello
*Dell | Linux Engineering*
[email protected]

=== modified file 'Makefile.am'

Makefile.am +2 -1
@@ -7,7 +7,8 @@
 	keymap \
 	v4l_id \
 	udev-acl \
-	gudev
+	gudev \
+	hid2hci
 
 ACLOCAL_AMFLAGS = -I m4
 

=== modified file 'configure.ac'

configure.ac +1 -0
@@ -118,6 +118,7 @@
 gudev/gudev-1.0.pc
 gudev/docs/version.xml
 gudev/docs/Makefile
+hid2hci/Makefile
 ])
 
 AC_OUTPUT

=== added directory 'hid2hci'
=== added file 'hid2hci/62-hid2hci.rules'

62-hid2hci.rules +40 -0
@@ -0,0 +1,40 @@
+ACTION!="add", GOTO="hid2hci_end"
+
+# Variety of Dell Bluetooth devices
+#
+# it looks like a bit of an odd rule, because it is matching
+# on a mouse device that is self powered, but that is where
+# a HID report needs to be sent to switch modes.
+#
+# Known supported devices:
+#   413c:8154
+#   413c:8158
+#   413c:8162
+ATTRS{idVendor}=="413c", ATTRS{bmAttributes}=="e0", KERNEL=="mouse*", RUN+="hid2hci --method dell -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+
+# Logitech devices
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c703" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c704" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c705" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c70a" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c70b" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c70c" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c70e" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c713" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c714" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c71b" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c71c" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+
+# CSR devices (in HID mode)
+ATTRS{idVendor}=="0a12", ATTRS{idProduct}=="1000" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="0458", ATTRS{idProduct}=="1000" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="1000" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hci"
+
+# CSR devices (in HCI mode)
+#ATTRS{idVendor}=="0a12", ATTRS{idProduct}=="0001" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hid"
+#ATTRS{idVendor}=="0458", ATTRS{idProduct}=="003f" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hid"
+#ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="8203" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hid"
+#ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="8204" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hid"
+#ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="8207" RUN+="hid2hci --method csr -v $attr{idVendor} -p $attr{idProduct} --mode hid"
+
+LABEL="hid2hci_end"

=== added file 'hid2hci/Makefile.am'

Makefile.am +10 -0
@@ -0,0 +1,10 @@
+include $(top_srcdir)/Makefile.am.inc
+
+udevhomedir = $(udev_prefix)/lib/udev
+udevhome_PROGRAMS = hid2hci
+
+udevrulesdir = $(udev_prefix)/lib/udev/rules.d
+dist_udevrules_DATA = 62-hid2hci.rules
+
+hid2hci_SOURCES = hid2hci.c
+hid2hci_LDADD = @LIBUSB_LIBS@

=== added file 'hid2hci/hid2hci.c'

hid2hci.c +377 -0

377 lines not on this page · raw message

#5 lore raw
In reply to Mario Limonciello
Quoted 11 lines · Mario Limonciello
Quoted 9 lines

This is all about adding USB devices, right? So the entire rules file should be guarded by:
  ACTION="add", ... out
  SUBSYSTEM="usb", ... out
  ENV{DEVTYPE}="usb_device", ... out

to exclude all other events from trying to match these rules. Also the individual ACTION matches are not needed then.

I added an ACTION guard around the top, but those other two guards break things.

That sounds weird. We match against properties of the usb_device device, so we should only hook into the usb_device events. We can not do the rules that way, they will match on _all_ child events for the usb_device.

Using ATTRS is needlessly expensive because it walks up the chain of parent devices to search for a match. It also does not make sure we run only once per usb_device, it will match all usb_interface and usb_endpoint devices.

The appendend works fine here, care to check what's going wrong on your side?

Thanks,
Kay

ACTION!="add", GOTO="hid2hci_end"
SUBSYSTEM!="usb", GOTO="hid2hci_end"
ENV{DEVTYPE}!="usb_device", GOTO="hid2hci_end"

...
ATTR{idVendor}="046d", ATTR{idProduct}="c703" RUN+="...
...

LABEL="hid2hci_end"

#6 lore raw
In reply to Mario Limonciello

Hi Kay:

Quoted 6 lines · Kay Sievers

That sounds weird. We match against properties of the usb_device device, so we should only hook into the usb_device events. We can not do the rules that way, they will match on _all_ child events for the usb_device.

Quoted 7 lines

Using ATTRS is needlessly expensive because it walks up the chain of parent devices to search for a match. It also does not make sure we run only once per usb_device, it will match all usb_interface and usb_endpoint devices.

The appendend works fine here, care to check what's going wrong on your side?

It looks like since I'm matching as far as the kernel mouse* device, I needed to actually match the input subsystem for the Dell stuff, whereas it's the USB subsystem for everything else.

Here's an updated attached patch that works for me.

Regards

Signature · 3 lines
Mario Limonciello
*Dell | Linux Engineering*
[email protected]

=== modified file 'Makefile.am'

Makefile.am +2 -1
@@ -7,7 +7,8 @@
 	keymap \
 	v4l_id \
 	udev-acl \
-	gudev
+	gudev \
+	hid2hci
 
 ACLOCAL_AMFLAGS = -I m4
 

=== modified file 'configure.ac'

configure.ac +1 -0
@@ -118,6 +118,7 @@
 gudev/gudev-1.0.pc
 gudev/docs/version.xml
 gudev/docs/Makefile
+hid2hci/Makefile
 ])
 
 AC_OUTPUT

=== added directory 'hid2hci'
=== added file 'hid2hci/62-hid2hci.rules'

62-hid2hci.rules +46 -0

46 lines not on this page · raw message

=== added file 'hid2hci/Makefile.am'

Makefile.am +10 -0
@@ -0,0 +1,10 @@
+include $(top_srcdir)/Makefile.am.inc
+
+udevhomedir = $(udev_prefix)/lib/udev
+udevhome_PROGRAMS = hid2hci
+
+udevrulesdir = $(udev_prefix)/lib/udev/rules.d
+dist_udevrules_DATA = 62-hid2hci.rules
+
+hid2hci_SOURCES = hid2hci.c
+hid2hci_LDADD = @LIBUSB_LIBS@

=== added file 'hid2hci/hid2hci.c'

hid2hci.c +377 -0

377 lines not on this page · raw message

#7 lore raw
In reply to Mario Limonciello
Quoted 10 lines · Mario Limonciello
Quoted 7 lines

Using ATTRS is needlessly expensive because it walks up the chain of parent devices to search for a match. It also does not make sure we run only once per usb_device, it will match all usb_interface and usb_endpoint devices.

The appendend works fine here, care to check what's going wrong on your side?

It looks like since I'm matching as far as the kernel mouse* device, I needed to actually match the input subsystem for the Dell stuff, whereas it's the USB subsystem for everything else.

I see, then we just do: "KERNEL="mouse*", SUBSYSTEMS="usb", ..." for this rule, and should be fine.

Quoted 1 line

Here's an updated attached patch that works for me.

Uh, why are the ID_VENDOR matches back? As mentioned in the earlier mail, we should not rely on the numeric fallback values of the usb_id program (happens only when no textual string is available), that is just too fragile. It isn't even guaranteed, that usb_id will even run before these rules.

We should be able to directly use ATTR{} of the device, not a value imported by an earlier program.

Something like the appended should work, and we should also be able to fold all the very similar rules into fewer pattern matches.

Sorry for insisting here, but we need to get this right, people will copy the stuff we ship to other rules, and we need to be careful, because all rules match on all device events on the system, and we need to make sure not to match needlessly on things that will never be executed. And we need to avoid needless dependencies between rules files.

Thanks,
Kay

#################
ACTION!="add", GOTO="hid2hci_end"

KERNEL="mouse*", SUBSYSTEMS="usb", ATTRS{idVendor}="413c", ATTRS{bmAttributes}="e0", \
RUN+="hid2hci --method dell -v $attr{idVendor} -p $attr{idProduct} --mode hci"

SUBSYSTEM!="usb", GOTO="hid2hci_end"
ENV{DEVTYPE}!="usb_device", GOTO="hid2hci_end"

ATTR{idVendor}="046d", ATTR{idProduct}="c70[345abce]" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci" ATTR{idVendor}="046d", ATTR{idProduct}="c71[34bc]" RUN+="hid2hci --method logitech -v $attr{idVendor} -p $attr{idProduct} --mode hci"
...

LABEL="hid2hci_end"
#################

#8 lore raw
In reply to Mario Limonciello
Quoted 1 line · Mario Limonciello

Thanks for tirelessly reviewing and making these recommendations.

I've committed this now, and changed ATTRS{} to ATTR{} for the reason mentioned earlier, and folded some of the rules into a pattern match.

Any reason why the last section in the rules file was completely commented-out? I've removed the comment characters, if these rules should not be in the file, let me know and we will remove them.

http://git.kernel.org/?p=linux/hotplug/udev-extras.git;a=blob;f=hid2hci/62-hid2hci.rules;hb=HEAD

Thanks,
Kay

#9 lore raw
In reply to Mario Limonciello

Hi Kay:

Quoted 7 lines · Kay Sievers

Any reason why the last section in the rules file was completely commented-out? I've removed the comment characters, if these rules should not be in the file, let me know and we will remove them.

http://git.kernel.org/?p=linux/hotplug/udev-extras.git;a=blob;f=hid2hci/62-hid2hci.rules;hb=HEAD

They were actually intentionally commented out. I believe those vid/pid combos should be produced when the above vid/pid combos are ran (eg when the device switches from hid->hci). I don't have that particular hardware so I can't verify that for sure. I was leaving them commented out in the event someone said "I can't get my device out of HCI mode. Help!", but without causing an endless loop of switching modes.

Signature · 3 lines
Mario Limonciello
*Dell | Linux Engineering*
[email protected]
#10 lore raw
In reply to Mario Limonciello
Quoted 10 lines · Mario Limonciello
Quoted 3 lines

Any reason why the last section in the rules file was completely commented-out? I've removed the comment characters, if these rules should not be in the file, let me know and we will remove them.

They were actually intentionally commented out.  I believe those vid/pid combos should be produced when the above vid/pid combos are ran (eg when the device switches from hid->hci).  I don't have that particular hardware so I can't verify that for sure.  I was leaving them commented out in the event someone said "I can't get my device out of HCI mode. Help!", but without causing an endless loop of switching modes.

Ok, fine, I deleted them. We don't want to collect stuff that we are not sure we will need.

Thanks,
Kay