Apple Bluetooth devices: Battery level?
Subsystems (3)
Heya,
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_US
Anyone with an idea? An unparsed HID event? Does it need "poking"?
Cheers
Marcel Holtmann
maintainerHi Bastien,
Quoted 6 lines
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_USAnyone with an idea? An unparsed HID event? Does it need "poking"?
I think that Apple ones used an actually HID HUT conform descriptor for that. I did reverser engineered that a long time ago, but then never got around to do anything with it. Can't find my notes right now. Just run hcidump and eventually you will see the report.
Regards
Marcel
Quoted 7 lines · Marcel Holtmann
Hi Bastien,
Quoted 5 lines
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_US
Quoted 6 lines
Quoted 1 line
Anyone with an idea? An unparsed HID event? Does it need "poking"?
I think that Apple ones used an actually HID HUT conform descriptor for that. I did reverser engineered that a long time ago, but then never got around to do anything with it. Can't find my notes right now. Just run hcidump and eventually you will see the report.
I have a mighty mouse and while I don't use BlueZ or Linux I would be interested in the details of this.. On my (NetBSD) system, the HID descriptor parses as:
Collection page=Generic_Desktop usage=Mouse
Input id=2 size=1 count=1 page=Button usage=Button_1 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_2 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_3 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_4 Variable, logical range 0..1
Input id=2 size=4 count=1 page=0x0000 usage=0x0000 Const Variable, logical range 0..1
Collection page=Generic_Desktop usage=Pointer
Input id=2 size=8 count=1 page=Generic_Desktop usage=X Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Y Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Consumer usage=AC_Pan Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Wheel Variable Relative, logical range -127..127
End collection
Input id=2 size=8 count=1 page=0x00ff usage=0x00c0 Variable, logical range -127..127
Feature id=71 size=8 count=1 page=Device_Controls usage=Battery_Strength Variable NoPref Volatile, logical range 0..100 End collection
But I'm not really sure what the Device_Controls feature is supposed to be. Is it sent from the device, or sent to the device? I've never had one sent from the device in any case that I know of, and I'm not sure what the Vendor_Defined (page 0x00ff) value (usage 0x00c0) is for either, it seems to be zero.
What I know does happen is that a report with id=48 containing a single byte with value=0x01 is sent two or three times just before the battery gives out. That also happens with an older Apple keyboard except that the descriptor does not contain any Vendor or Feature items. I did capture the report once but I don't have it now. (I think it was an input report)
iain
Quoted 45 lines · Iain Hibbert
Quoted 8 lines · Marcel Holtmann
Hi Bastien,
Quoted 5 lines
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_USQuoted 7 lines
Quoted 2 lines
Anyone with an idea? An unparsed HID event? Does it need "poking"?
I think that Apple ones used an actually HID HUT conform descriptor for that. I did reverser engineered that a long time ago, but then never got around to do anything with it. Can't find my notes right now. Just run hcidump and eventually you will see the report.
I have a mighty mouse and while I don't use BlueZ or Linux I would be interested in the details of this.. On my (NetBSD) system, the HID descriptor parses as:
Collection page=Generic_Desktop usage=Mouse
Input id=2 size=1 count=1 page=Button usage=Button_1 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_2 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_3 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_4 Variable, logical range 0..1
Input id=2 size=4 count=1 page=0x0000 usage=0x0000 Const Variable, logical range 0..1
Collection page=Generic_Desktop usage=Pointer
Input id=2 size=8 count=1 page=Generic_Desktop usage=X Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Y Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Consumer usage=AC_Pan Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Wheel Variable Relative, logical range -127..127
End collection
Input id=2 size=8 count=1 page=0x00ff usage=0x00c0 Variable, logical range -127..127
Feature id=71 size=8 count=1 page=Device_Controls usage=Battery_Strength Variable NoPref Volatile, logical range 0..100 End collectionBut I'm not really sure what the
Device_Controlsfeature is supposed to be. Is it sent from the device, or sent to the device? I've never had one sent from the device in any case that I know of, and I'm not sure what theVendor_Defined(page0x00ff) value (usage0x00c0) is for either, it seems to be zero.
Quoted 6 lines
What I know does happen is that a report with id=48 containing a single byte with value=0x01 is sent two or three times just before the battery gives out. That also happens with an older Apple keyboard except that the descriptor does not contain any Vendor or Feature items. I did capture the report once but I don't have it now. (I think it was an input report)
Features are bidirectional (speaking from USB experience, not bluetooth). Presumably it has a battery level value between 0% and 100% on input. You'd expect it to be just an input though (unless you can charge it by slowly setting it to bigger and bigger values :)
Hard to guess what it does with the output value of the feature. Maybe it's just in the feature report to get it out of the input report, which gets sent rather often (I.e. as a power saving measure).
Quoted 6 lines · Bastien Nocera
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_USAnyone with an idea? An unparsed HID event? Does it need "poking"?
If the mouse is standard-compliant, it should be sending the battery level strength in usage 0x20 of device controls page (0x06).
Could you please obtain HID debug dump (CONFIG_HID_DEBUG + modprobe hid module with 'debug=2') and look at this usage both in the report descriptor itself, and also check whether it is present in the received reports?
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 7 lines · Jiri Kosina
Quoted 5 lines · Bastien Nocera
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_US
Quoted 7 lines
Quoted 1 line
Anyone with an idea? An unparsed HID event? Does it need "poking"?
If the mouse is standard-compliant, it should be sending the battery level strength in usage
0x20of device controls page (0x06).Could you please obtain HID debug dump (
CONFIG_HID_DEBUG+ modprobe hid module with 'debug=2')
I found that for pretty much all the input problems, I'd need to do something like that. Problem is:
- enabling CONFIG_HID_DEBUG requires rebuilding the kernel
- most distributions build hid into the kernel
Wouldn't there be a way to enable the debug at run-time without impacting too much on performance or binary size?
Quoted 3 lines
and look at this usage both in the report
descriptor itself, and also check whether it is present in the received reports?
I'll look at it when I get an occasion to rebuild a kernel (which thankfully isn't very often these days).
Cheers
Marcel Holtmann
maintainerHi Bastien,
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_USQuoted 7 lines
Quoted 1 line
Anyone with an idea? An unparsed HID event? Does it need "poking"?
If the mouse is standard-compliant, it should be sending the battery level strength in usage
0x20of device controls page (0x06).Could you please obtain HID debug dump (
CONFIG_HID_DEBUG+ modprobe hid module with 'debug=2')
Quoted 7 lines
I found that for pretty much all the input problems, I'd need to do something like that. Problem is:
- enablingCONFIG_HID_DEBUGrequires rebuilding the kernel
- most distributions build hid into the kernelWouldn't there be a way to enable the debug at run-time without impacting too much on performance or binary size?
there is no real downside in having this all times available since you have to store that binary record somewhere anyway during runtime. We should fix that and put it into debugfs, but nobody bothered so far sending a patch for it. If we worry about code size then the decoding should of the record should be moved into userspace, but in the end it really doesn't matter that much.
Regards
Marcel
Quoted 4 lines · Marcel Holtmann
there is no real downside in having this all times available since you have to store that binary record somewhere anyway during runtime. We should fix that and put it into debugfs, but nobody bothered so far sending a patch for it.
JFYI, I have just pushed super-preliminary version of the code that moves the whole HID-device debugging (report descriptor and report/event dumping) into debugfs. It's 'debugfs' branch of my HID tree, for those who are interested.
Please bear in mind that this is more or less a snapshot of the current code (which is working, though), not production quality yet. Hopefully they will get properly polished for 2.6.31.
I will post the patches as a followup to this mail, if anyone is interested.
Comments and patches welcome, as usual.
Signature · 2 lines
Jiri Kosina SUSE Labs
PATCH 1/2 HID: use debugfs for report dumping descriptor
It is a little bit inconvenient for people who have some non-standard HID hardware (usually violating the HID specification) to have to recompile kernel with CONFIG_HID_DEBUG to be able to see kernel's perspective of the HID report descriptor and observe the parsed events. Plus the messages are then mixed up inconveniently with the rest of the dmesg stuff.
This patch implements /sys/kernel/debug/hid/<device>/rdesc file, which represents the kernel's view of report descriptor (both the raw report descriptor data and parsed contents).
With all the device-specific debug data being available through debugfs, there is no need for keeping CONFIG_HID_DEBUG, as the 'debug' parameter to the hid module will now only output only driver-specific debugging options, which has absolutely minimal memory footprint, just a few error messages and one global flag (hid_debug).
We use the current set of output formatting functions. The ones that need to be used both for one-shot rdesc seq_file and also for continuous flow of data (individual reports, as being sent by the device) distinguish according to the passed seq_file parameter, and if it is NULL, it still output to kernel ringbuffer, otherwise the corresponding seq_file is used for output.
The format of the output is preserved.
--- drivers/hid/Kconfig | 15 --- drivers/hid/Makefile | 5 +- drivers/hid/hid-core.c | 13 ++- drivers/hid/hid-debug.c | 227 ++++++++++++++++++++++++++++------------- drivers/hid/hid-input.c | 13 +-- drivers/hid/usbhid/hid-core.c | 8 +-- include/linux/hid-debug.h | 32 ++++--- include/linux/hid.h | 4 + 8 files changed, 195 insertions(+), 122 deletions(-)
drivers/hid/Kconfig +0 -15
@@ -31,21 +31,6 @@ config HID If unsure, say Y. -config HID_DEBUG - bool "HID debugging support" - default y - depends on HID - ---help--- - This option lets the HID layer output diagnostics about its internal - state, resolve HID usages, dump HID fields, etc. Individual HID drivers - use this debugging facility to output information about individual HID - devices, etc. - - This feature is useful for those who are either debugging the HID parser - or any HID hardware device. - - If unsure, say Y. - config HIDRAW bool "/dev/hidraw raw HID device support" depends on HID
drivers/hid/Makefile +4 -1
@@ -3,9 +3,12 @@ # hid-objs := hid-core.o hid-input.o +ifdef CONFIG_DEBUG_FS + hid-objs += hid-debug.o +endif + obj-$(CONFIG_HID) += hid.o -hid-$(CONFIG_HID_DEBUG) += hid-debug.o hid-$(CONFIG_HIDRAW) += hidraw.o hid-logitech-objs := hid-lg.o
drivers/hid/hid-core.c +10 -3
@@ -44,12 +44,10 @@#define DRIVER_DESC "HID core driver"#define DRIVER_LICENSE "GPL" -#ifdef CONFIG_HID_DEBUG int hid_debug =0 ;module_param_named (debug, hid_debug, int,0600 );MODULE_PARM_DESC (debug,"HID debugging (0=off, 1=probing info, 2=continuous data dumping)" );EXPORT_SYMBOL_GPL (hid_debug); -#endif /* * Register a new report for a device.
@@ -987,7 +985,6 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)if (offset >= field->report_count) {dbg_hid ("offset (%d) exceeds report_count (%d)\n" , offset, field->report_count); -hid_dump_field (field,8 );return -1 ; }if (field->logical_minimum <0 ) {
@@ -1721,6 +1718,8 @@ int hid_add_device(struct hid_device *hdev)if (!ret) hdev->status |=HID_STAT_ADDED ; +hid_debug_register (hdev,dev_name (&hdev->dev)); +return ret; }EXPORT_SYMBOL_GPL (hid_add_device);
@@ -1768,6 +1767,7 @@ static void hid_remove_device(struct hid_device *hdev) {if (hdev->status &HID_STAT_ADDED ) {device_del (&hdev->dev); +hid_debug_unregister (hdev); hdev->status &= ~HID_STAT_ADDED ; } }
@@ -1843,6 +1843,10 @@ static int __init hid_init(void) {int ret; +if (hid_debug) +printk (KERN_WARNING "HID: hid_debug parameter has been deprecated. " +"Debugging data are now provided via debugfs\n" ); + ret =bus_register (&hid_bus_type);if (ret) {printk (KERN_ERR "HID: can't register hid bus\n" );
@@ -1853,6 +1857,8 @@ static int __init hid_init(void)if (ret) goto err_bus; +hid_debug_init (); +return 0 ; err_bus:bus_unregister (&hid_bus_type);
@@ -1862,6 +1868,7 @@ err: static void __exit hid_exit(void) { +hid_debug_exit ();hidraw_exit ();bus_unregister (&hid_bus_type); }
drivers/hid/hid-debug.c +156 -71
342 lines not on this page · raw message
drivers/hid/hid-input.c +1 -12
@@ -159,17 +159,12 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel field->hidinput = hidinput; -dbg_hid ("Mapping: " ); -hid_resolv_usage (usage->hid); -dbg_hid_line (" ---> " ); -if (field->flags &HID_MAIN_ITEM_CONSTANT ) goto ignore;/* only LED usages are supported in output fields */ if (field->report_type ==HID_OUTPUT_REPORT && (usage->hid &HID_USAGE_PAGE ) !=HID_UP_LED ) { -dbg_hid_line (" [non-LED output field] " ); goto ignore; }
@@ -561,15 +556,9 @@ mapped:set_bit (MSC_SCAN , input->mscbit); } -hid_resolv_event (usage->type, usage->code); - -dbg_hid_line ("\n" ); - -return ; - ignore: -dbg_hid_line ("IGNORED\n" );return ; + }void hidinput_hid_event (struct hid_device *hid,struct hid_field *field,struct hid_usage *usage,__s32 value)
drivers/hid/usbhid/hid-core.c +1 -7
@@ -4,8 +4,8 @@* Copyright (c) 1999 Andreas Gal * Copyright (c) 2000-2005 Vojtech Pavlik <[email protected]> * Copyright (c) 2005 Michael Haboustak <[email protected]> for Concept2, Inc -* Copyright (c) 2006-2008 Jiri Kosina * Copyright (c) 2007-2008 Oliver Neukum +* Copyright (c) 2006-2009 Jiri Kosina */ /*
@@ -886,11 +886,6 @@ static int usbhid_parse(struct hid_device *hid) goto err; } -dbg_hid ("report descriptor (size %u, read %d) = " , rsize, n); -for (n =0 ; n < rsize; n++) -dbg_hid_line (" %02x" , (unsigned char ) rdesc[n]); -dbg_hid_line ("\n" ); - ret =hid_parse_report (hid, rdesc, rsize);kfree (rdesc);if (ret) {
@@ -1005,7 +1000,6 @@ static int usbhid_start(struct hid_device *hid) usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP |URB_NO_SETUP_DMA_MAP );usbhid_init_reports (hid); -hid_dump_device (hid);set_bit (HID_STARTED , &usbhid->iofl);
include/linux/hid-debug.h +19 -13
@@ -2,7 +2,7 @@#define __HID_DEBUG_H/* -* Copyright (c) 2007 Jiri Kosina +* Copyright (c) 2007-2009 Jiri Kosina */ /*
@@ -22,24 +22,30 @@* */ -#ifdef CONFIG_HID_DEBUG +#ifdef CONFIG_DEBUG_FS void hid_dump_input (struct hid_usage *,__s32 ); -void hid_dump_device (struct hid_device *); -void hid_dump_field (struct hid_field *,int ); -void hid_resolv_usage (unsigned ); -void hid_resolv_event (__u8 ,__u16 ); +void hid_dump_device (struct hid_device *,struct seq_file *); +void hid_dump_field (struct hid_field *,int ,struct seq_file *); +void hid_resolv_usage (unsigned ,struct seq_file *); +void hid_debug_register (struct hid_device *,const char *); +void hid_debug_unregister (struct hid_device *); +void hid_debug_init (void ); +void hid_debug_exit (void );#else -#define hid_dump_input (a,b) do { } while (0) -#define hid_dump_device (c) do { } while (0) -#define hid_dump_field (a,b) do { } while (0) -#define hid_resolv_usage (a) do { } while (0) -#define hid_resolv_event (a,b) do { } while (0) - -#endif /* CONFIG_HID_DEBUG */ +#define hid_dump_input (a,b) do { } while (0) +#define hid_dump_device (c) do { } while (0) +#define hid_dump_field (a,b) do { } while (0) +#define hid_resolv_usage (a) do { } while (0) +#define hid_resolv_event (a,b) do { } while (0) +#define hid_debug_register (a, b) do { } while (0) +#define hid_debug_unregister (a) do { } while (0) +#define hid_debug_init () do { } while (0) +#define hid_debug_exit () do { } while (0) +#endif #endif
include/linux/hid.h +4 -0
@@ -451,6 +451,10 @@ struct hid_device { /* device report descriptor */char phys[64 ];/* Device physical location */ char uniq[64 ];/* Device unique identifier (serial #) */ +/* debugfs */ +struct dentry *debug_dir; +struct dentry *debug_rdesc; +void *driver_data;/* temporary hid_ff handling (until moved to the drivers) */
Signature · 1 line
1.5.6
PATCH 2/2 HID: use debugfs for events/reports dumping
In reply to Jiri KosinaThis is a followup patch to the one implemeting rdesc representation in debugfs rather than being dependent on compile-time CONFIG_HID_DEBUG setting.
The API of the appropriate formatting functions is slightly modified -- if they are passed seq_file pointer, the one-shot output for 'rdesc' file mode is used, and therefore the message is formatted into the corresponding seq_file immediately.
Otherwise the called function allocated a new buffer, formats the text into the buffer and returns the pointer to it, so that it can be queued into the ring-buffer of the processess blocked waiting on input on 'events' file in debugfs.
'debug' parameter to the 'hid' module is now used solely for the prupose of inetrnal driver state debugging (parser, transport, etc).
--- drivers/hid/hid-core.c | 42 ++++++-- drivers/hid/hid-debug.c | 239 +++++++++++++++++++++++++++++++++++++++++---- include/linux/hid-debug.h | 18 +++- include/linux/hid.h | 26 ++---- 4 files changed, 276 insertions(+), 49 deletions(-)
drivers/hid/hid-core.c +32 -10
@@ -46,7 +46,7 @@int hid_debug =0 ;module_param_named (debug, hid_debug, int,0600 ); -MODULE_PARM_DESC (debug,"HID debugging (0=off, 1=probing info, 2=continuous data dumping)" ); +MODULE_PARM_DESC (debug,"toggle HID debugging messages" );EXPORT_SYMBOL_GPL (hid_debug);/*
@@ -859,7 +859,7 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field,struct hid_driver *hdrv = hid->driver;int ret; -hid_dump_input (usage, value); +hid_dump_input (hid, usage, value);if (hdrv && hdrv->event &&hid_match_usage (hid, usage)) { ret = hdrv->event (hid, field, usage, value);
@@ -981,7 +981,7 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) {unsigned size = field->report_size; -hid_dump_input (field->usage + offset, value); +hid_dump_input (field->report->device, field->usage + offset, value);if (offset >= field->report_count) {dbg_hid ("offset (%d) exceeds report_count (%d)\n" , offset, field->report_count);
@@ -1075,6 +1075,7 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int istruct hid_report_enum *report_enum = hid->report_enum + type;struct hid_driver *hdrv = hid->driver;struct hid_report *report; +char *buf;unsigned int i;int ret;
@@ -1086,18 +1087,36 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int ireturn -1 ; } -dbg_hid ("report (size %u) (%snumbered)\n" , size, report_enum->numbered ?"" :"un" ); + buf =kmalloc (sizeof (char ) *HID_DEBUG_BUFSIZE , + interrupt ?GFP_ATOMIC :GFP_KERNEL ); + +if (!buf) { + report =hid_get_report (report_enum, data); + goto nomem; + } + +snprintf (buf,HID_DEBUG_BUFSIZE -1 , +"\nreport (size %u) (%snumbered)\n" , size, report_enum->numbered ?"" :"un" ); +hid_debug_event (hid, buf); report =hid_get_report (report_enum, data);if (!report)return -1 ;/* dump the report */ -dbg_hid ("report %d (size %u) = " , report->id, size); -for (i =0 ; i < size; i++) -dbg_hid_line (" %02x" , data[i]); -dbg_hid_line ("\n" ); +snprintf (buf,HID_DEBUG_BUFSIZE -1 , +"report %d (size %u) = " , report->id, size); +hid_debug_event (hid, buf); +for (i =0 ; i < size; i++) { +snprintf (buf,HID_DEBUG_BUFSIZE -1 , +" %02x" , data[i]); +hid_debug_event (hid, buf); + } +hid_debug_event (hid,"\n" ); + +kfree (buf); +nomem:if (hdrv && hdrv->raw_event &&hid_match_report (hid, report)) { ret = hdrv->raw_event (hid, report, data, size);if (ret !=0 )
@@ -1756,6 +1775,9 @@ struct hid_device *hid_allocate_device(void)for (i =0 ; i <HID_REPORT_TYPES ; i++)INIT_LIST_HEAD (&hdev->report_enum[i].report_list); +init_waitqueue_head (&hdev->debug_wait); +INIT_LIST_HEAD (&hdev->debug_list); +return hdev; err:put_device (&hdev->dev);
@@ -1844,8 +1866,8 @@ static int __init hid_init(void)int ret;if (hid_debug) -printk (KERN_WARNING "HID: hid_debug parameter has been deprecated. " -"Debugging data are now provided via debugfs\n" ); +printk (KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n" +"HID: debugfs is now used for inspecting the device (report descriptor, reports)\n" ); ret =bus_register (&hid_bus_type);if (ret) {
drivers/hid/hid-debug.c +220 -19
316 lines not on this page · raw message
include/linux/hid-debug.h +16 -2
@@ -24,14 +24,27 @@#ifdef CONFIG_DEBUG_FS -void hid_dump_input (struct hid_usage *,__s32 ); +void hid_dump_input (struct hid_device *,struct hid_usage *,__s32 );void hid_dump_device (struct hid_device *,struct seq_file *);void hid_dump_field (struct hid_field *,int ,struct seq_file *); -void hid_resolv_usage (unsigned ,struct seq_file *); +char *hid_resolv_usage (unsigned ,struct seq_file *);void hid_debug_register (struct hid_device *,const char *);void hid_debug_unregister (struct hid_device *);void hid_debug_init (void );void hid_debug_exit (void ); +void hid_debug_event (struct hid_device *,char *); + +#define HID_DEBUG_BUFSIZE 512 + +struct hid_debug_list { +char *hid_debug_buf; +int head; +int tail; +struct fasync_struct *fasync; +struct hid_device *hdev; +struct list_head node; +struct mutex read_mutex; +};#else
@@ -44,6 +57,7 @@ void hid_debug_exit(void);#define hid_debug_unregister (a) do { } while (0)#define hid_debug_init () do { } while (0)#define hid_debug_exit () do { } while (0) +#define hid_debug_event (a,b) do { } while (0)#endif
include/linux/hid.h +8 -18
@@ -451,10 +451,6 @@ struct hid_device { /* device report descriptor */char phys[64 ];/* Device physical location */ char uniq[64 ];/* Device unique identifier (serial #) */ -/* debugfs */ -struct dentry *debug_dir; -struct dentry *debug_rdesc; -void *driver_data;/* temporary hid_ff handling (until moved to the drivers) */
@@ -468,6 +464,14 @@ struct hid_device { /* device report descriptor *//* handler for raw output data, used by hidraw */ int (*hid_output_raw_report) (struct hid_device *,__u8 *,size_t ); + +/* debugging support via debugfs */ +unsigned short debug; +struct dentry *debug_dir; +struct dentry *debug_rdesc; +struct dentry *debug_events; +struct list_head debug_list; +wait_queue_head_t debug_wait; };static inline void *hid_get_drvdata (struct hid_device *hdev)
@@ -625,9 +629,7 @@ struct hid_ll_driver {/* HID core API */ -#ifdef CONFIG_HID_DEBUG extern int hid_debug; -#endif extern int hid_add_device (struct hid_device *);extern void hid_destroy_device (struct hid_device *);
@@ -783,21 +785,9 @@ int hid_pidff_init(struct hid_device *hid);#define hid_pidff_init NULL#endif -#ifdef CONFIG_HID_DEBUG #define dbg_hid(format, arg...) if (hid_debug) \ printk(KERN_DEBUG "%s: " format ,\ __FILE__ , ## arg) -#define dbg_hid_line(format, arg...) if (hid_debug) \ - printk(format, ## arg) -#else -static inline int __attribute__((format (printf,1 ,2 ))) -dbg_hid (const char *fmt, ...) -{ -return 0 ; -} -#define dbg_hid_line dbg_hid -#endif /* HID_DEBUG */ - #define err_hid(format, arg...) printk(KERN_ERR "%s: " format "\n" , \ __FILE__ , ## arg)#endif /* HID_FF */
Signature · 1 line
1.5.6
Hi!
Kernel rebuilding is pretty easy, for ubuntu/debian it would be:
- sudo apt-get install linux-source build-essential
- tar xf /usr/src/linux-source*
- cd linux-source-uname -r
- cp /boot/config-uname -r .config
- make menuconfig (find and enable HID_DEBUG)
- make bzImage modules deb-pkg
Then after some time you will get deb package, which you need to install and then run:
- sudo update-initramfs -c -k 'new kernel version'
- sudo update-grub
Then you can reboot into new kernel and use "echo 2 > /sys/modules/hid/parameters/debug" instead of debug module parameter.
2009/6/10 Bastien Nocera <[email protected]>:
Quoted 7 lines
I found that for pretty much all the input problems, I'd need to do something like that. Problem is:
- enablingCONFIG_HID_DEBUGrequires rebuilding the kernel
- most distributions build hid into the kernelWouldn't there be a way to enable the debug at run-time without impacting too much on performance or binary size?
Marcel Holtmann
maintainerHi Dimitry,
first of all, no top-posting. I really mean it.
Quoted 12 lines
Kernel rebuilding is pretty easy, for ubuntu/debian it would be:
- sudo apt-get install linux-source build-essential
- tar xf/usr/src/linux-source*
- cd linux-source-uname -r
- cp/boot/config-uname -r.config
- make menuconfig (find and enableHID_DEBUG)
- make bzImage modules deb-pkg
Then after some time you will get deb package, which you need to install and then run:
- sudo update-initramfs -c -k 'new kernel version'
- sudo update-grub
Quoted 2 lines
Then you can reboot into new kernel and use "echo 2 >
/sys/modules/hid/parameters/debug" instead of debug module parameter.
that should be changeable on the fly and we should just export the HID descriptor for users. Putting the burden to boot into a different kernel is painful and we don't want that. Hell, I don't want to boot a new kernel to just get the HID descriptor.
Regards
Marcel
Quoted 3 lines · Dmitriy Geels
Hi!
Kernel rebuilding is pretty easy, for ubuntu/debian it would be:
<snip>
FWIW, I contributed drivers to those two lists, so I do know how to build my own kernels...
Quoted 13 lines
2009/6/10 Bastien Nocera <[email protected]>:
Quoted 7 lines
I found that for pretty much all the input problems, I'd need to do something like that. Problem is:
- enablingCONFIG_HID_DEBUGrequires rebuilding the kernel
- most distributions build hid into the kernelWouldn't there be a way to enable the debug at run-time without impacting too much on performance or binary size?
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · Bastien Nocera
Quoted 5 lines
Quoted 5 lines
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_US
Anyone with an idea? An unparsed HID event? Does it need "poking"?
Quoted 7 lines
Quoted 4 lines
If the mouse is standard-compliant, it should be sending the battery level strength in usage
0x20of device controls page (0x06).
Could you please obtain HID debug dump (CONFIG_HID_DEBUG+ modprobe hid module with 'debug=2')I found that for pretty much all the input problems, I'd need to do something like that. Problem is:
- enablingCONFIG_HID_DEBUGrequires rebuilding the kernel
CONFIG_HID_DEBUG has 'default y' for quite some time, but the defconfigs haven't unfortunately been updated yet.
Quoted 1 line
- most distributions build hid into the kernel
hid.debug=2 on the kernel commandline option does the trick.
Quoted 2 lines
Wouldn't there be a way to enable the debug at run-time without impacting too much on performance or binary size?
Absolutely. I have a migration of all this stuff to debugfs on my TODO list.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 1 line · Jiri Kosina
On Wed, 10 Jun 2009, Bastien Nocera wrote:
<snip>
Quoted 8 lines
Quoted 1 line
- enabling
CONFIG_HID_DEBUGrequires rebuilding the kernel
CONFIG_HID_DEBUGhas 'default y' for quite some time, but the defconfigs haven't unfortunately been updated yet.Quoted 1 line
- most distributions build hid into the kernel
hid.debug=2 on the kernel commandline option does the trick.
Or "echo 2 > /sys/modules/hid/parameters/debug" at run-time.
Seems CONFIG_HID_DEBUG is enabled by default in the builds I use as well, so I'll quit complaining about that :)
Cheers
Quoted 9 lines · Jiri Kosina
Quoted 6 lines · Bastien Nocera
I just got an Apple Bluetooth Mighty Mouse, and was wondering whether anyone had information on how to get the battery level from the device (the keyboard apparently also allows that):
http://support.apple.com/kb/TA27118?viewlocale=en_USAnyone with an idea? An unparsed HID event? Does it need "poking"?
Quoted 7 lines
If the mouse is standard-compliant, it should be sending the battery level strength in usage
0x20of device controls page (0x06).Could you please obtain HID debug dump (
CONFIG_HID_DEBUG+ modprobe hid module with 'debug=2') and look at this usage both in the report descriptor itself, and also check whether it is present in the received reports?
This is the debug output:
http://pastebin.com/m256a4187
Doesn't look very useful, and I have no idea what the 00ff.00c0 part does.
Cheers
Quoted 2 lines · Bastien Nocera
Doesn't look very useful, and I have no idea what the 00ff.00c0 part does.
I found this:
which labels it as "Reserved MouseData" and it seems to be related to the capacitance detectors. Run "hcidump -X" and place your fingers on the mouse top without actually clicking then move the mouse slightly. You will see 0x00 (no touching), 0x01 (left finger), 0x02 (right finger) and 0x03 (both fingers). I didn't see any other values.
I think the battery strength is found by polling with the feature report id#71 but I don't know how you do that, libusb might be able to do it?
as I mentioned before, you will also get an input report id#42 sent before the mouse dies (but that is not listed in the HID descriptor)
iain
Quoted 8 lines · Bastien Nocera
Quoted 4 lines
Could you please obtain HID debug dump (
CONFIG_HID_DEBUG+ modprobe hid module with 'debug=2') and look at this usage both in the report descriptor itself, and also check whether it is present in the received reports?This is the debug output:
http://pastebin.com/m256a4187
Doesn't look very useful, and I have no idea what the 00ff.00c0 part does.
It doesn't seem to be sending the battery level in a standard-compliant way, at least according to these reports.
Could you also please post the report descriptor data? They should appear in a hid debugging mode once the mouse is connected.
Does 00ff.00c0 usage change it's value if you put different batteries into the mouse?
If this is not successful, looking at what the driver in other operating system does on the transport level might be an option.
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 2 lines · Jiri Kosina
It doesn't seem to be sending the battery level in a standard-compliant way, at least according to these reports.
but I wonder what is the standard-compliant way?
Quoted 2 lines
Could you also please post the report descriptor data? They should appear in a hid debugging mode once the mouse is connected.
Sorry, I posted a parsed version of the report descriptor previously though I failed to cross post:
Collection page=Generic_Desktop usage=Mouse
Input id=2 size=1 count=1 page=Button usage=Button_1 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_2 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_3 Variable, logical range 0..1
Input id=2 size=1 count=1 page=Button usage=Button_4 Variable, logical range 0..1
Input id=2 size=4 count=1 page=0x0000 usage=0x0000 Const Variable, logical range 0..1
Collection page=Generic_Desktop usage=Pointer
Input id=2 size=8 count=1 page=Generic_Desktop usage=X Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Y Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Consumer usage=AC_Pan Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Wheel Variable Relative, logical range -127..127
End collection
Input id=2 size=8 count=1 page=0x00ff usage=0x00c0 Variable, logical range -127..127
Feature id=71 size=8 count=1 page=Device_Controls usage=Battery_Strength Variable NoPref Volatile, logical range 0..100 End collection
As you can see, there is a Feature report relating to the Battery Strength, but I do not know what to do with that. I suppose that it is to be polled in order to return a percentage value..
Quoted 2 lines
Does 00ff.00c0 usage change it's value if you put different batteries into the mouse?
The mighty mouse has a single hard shell and detects the difference between left click and right click by a capacitance detector underneath the finger positions. This usage contains bits indicating where the mouse is being touched though I guess it is just for testing as the OS does not really need to know (it generates normal button clicks).
There is one more data point that may be interesting. The mighty mouse (and an old Apple keyboard I have) spits out an input report that is not mentioned in the descriptor with id=48 just before the battery fails. I captured it once and it contained a single byte with value 0x01. I have no idea what that report is for but as I use NiMH batteries which maintain voltage until very near the end, it could be a charge level warning.
regards,
iain
Quoted 13 lines · Iain Hibbert
Sorry, I posted a parsed version of the report descriptor previously though I failed to cross post:
Collection page=Generic_Desktop usage=Mouse
Input id=2 size=1 count=1 page=Button usage=Button_1 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_2 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_3 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_4 Variable, logical range 0..1 Input id=2 size=4 count=1 page=0x0000 usage=0x0000 Const Variable, logical range 0..1
Collection page=Generic_Desktop usage=Pointer
Input id=2 size=8 count=1 page=Generic_Desktop usage=X Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Y Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Consumer usage=AC_Pan Variable Relative, logical range -127..127
Quoted 8 lines
Input id=2 size=8 count=1 page=Generic_Desktop usage=Wheel Variable Relative, logical range -127..127
End collection
Input id=2 size=8 count=1 page=0x00ff usage=0x00c0 Variable, logical range -127..127
Feature id=71 size=8 count=1 page=Device_Controls usage=Battery_Strength Variable NoPref Volatile, logical range 0..100 End collection
As you can see, there is a Feature report relating to the Battery
Strength, but I do not know what to do with that. I suppose that it is
to be polled in order to return a percentage value..
Yes, it has to be polled. But at least the initial value should be retrieved during the very initialization of the device -- both USB and Bluetooth implementations this in usbhid_init_reports()/hidp_start() -- they query INPUT and FEATURE reports during device initialization.
Signature · 2 lines
Jiri Kosina SUSE Labs
Marcel Holtmann
maintainerHi Jiri,
Quoted 22 lines
Quoted 13 lines
Sorry, I posted a parsed version of the report descriptor previously though I failed to cross post:
Collection page=Generic_Desktop usage=Mouse
Input id=2 size=1 count=1 page=Button usage=Button_1 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_2 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_3 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_4 Variable, logical range 0..1 Input id=2 size=4 count=1 page=0x0000 usage=0x0000 Const Variable, logical range 0..1
Collection page=Generic_Desktop usage=Pointer
Input id=2 size=8 count=1 page=Generic_Desktop usage=X Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Y Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Consumer usage=AC_Pan Variable Relative, logical range -127..127Quoted 8 lines
Input id=2 size=8 count=1 page=Generic_Desktop usage=Wheel Variable Relative, logical range -127..127
End collection
Input id=2 size=8 count=1 page=0x00ff usage=0x00c0 Variable, logical range -127..127
Feature id=71 size=8 count=1 page=Device_Controls usage=Battery_Strength Variable NoPref Volatile, logical range 0..100 End collection
As you can see, there is a Feature report relating to the Battery
Strength, but I do not know what to do with that. I suppose that it is
to be polled in order to return a percentage value..
Quoted 4 lines
Yes, it has to be polled. But at least the initial value should be retrieved during the very initialization of the device -- both USB and Bluetooth implementations this in usbhid_init_reports()/hidp_start() -- they query INPUT and FEATURE reports during device initialization.
since the descriptors are the same, can we not do this inside the HID core with a specific quirk setting. And maybe even a timer that polls it every 30 minutes or so.
Regards
Marcel
Quoted 24 lines · Jiri Kosina
Quoted 13 lines · Iain Hibbert
Sorry, I posted a parsed version of the report descriptor previously though I failed to cross post:
Collection page=Generic_Desktop usage=Mouse
Input id=2 size=1 count=1 page=Button usage=Button_1 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_2 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_3 Variable, logical range 0..1 Input id=2 size=1 count=1 page=Button usage=Button_4 Variable, logical range 0..1 Input id=2 size=4 count=1 page=0x0000 usage=0x0000 Const Variable, logical range 0..1
Collection page=Generic_Desktop usage=Pointer
Input id=2 size=8 count=1 page=Generic_Desktop usage=X Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Generic_Desktop usage=Y Variable Relative, logical range -127..127 Input id=2 size=8 count=1 page=Consumer usage=AC_Pan Variable Relative, logical range -127..127Quoted 8 lines
Input id=2 size=8 count=1 page=Generic_Desktop usage=Wheel Variable Relative, logical range -127..127
End collection
Input id=2 size=8 count=1 page=0x00ff usage=0x00c0 Variable, logical range -127..127
Feature id=71 size=8 count=1 page=Device_Controls usage=Battery_Strength Variable NoPref Volatile, logical range 0..100 End collection
As you can see, there is a Feature report relating to the Battery
Strength, but I do not know what to do with that. I suppose that it is
to be polled in order to return a percentage value..
Quoted 4 lines
Yes, it has to be polled. But at least the initial value should be retrieved during the very initialization of the device -- both USB and Bluetooth implementations this in usbhid_init_reports()/hidp_start() -- they query INPUT and FEATURE reports during device initialization.
Any hints/example code on how to do that? Or is this something you'd want to work on?
Cheers