3030#include <unistd.h>
3131#include <fcntl.h>
3232#include <iconv.h>
33+ #ifndef ICONV_CONST
34+ #define ICONV_CONST
35+ #endif
36+
3337#include <poll.h>
3438
3539/* NetBSD */
@@ -724,6 +728,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
724728 for (size_t i = 0 ; i < len ; i ++ ) {
725729 char devpath [USB_MAX_DEVNAMELEN ];
726730 int bus ;
731+ struct hid_device_info * prev_end ;
727732
728733 strlcpy (devpath , "/dev/" , sizeof (devpath ));
729734 strlcat (devpath , arr [i ], sizeof (devpath ));
@@ -732,7 +737,17 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
732737 if (bus == -1 )
733738 continue ;
734739
740+ /*
741+ * ehci/ohci/uhci/dwctwo etc. use 'addr 1' for root hubs
742+ * but xhci uses 'addr 0' on NetBSD.
743+ * Check addr 0 (that would be unused on other than xhci)
744+ * and then check addr 1 if there is no device at addr 0.
745+ */
746+ prev_end = hed .end ;
735747 enumerate_usb_devices (bus , 0 , hid_enumerate_callback , & hed );
748+ if (hed .end == prev_end )
749+ enumerate_usb_devices (bus , 1 ,
750+ hid_enumerate_callback , & hed );
736751
737752 close (bus );
738753 }
@@ -1087,7 +1102,7 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
10871102 struct usb_string_desc usd ;
10881103 usb_string_descriptor_t * str ;
10891104 iconv_t ic ;
1090- const char * src ;
1105+ ICONV_CONST char * src ;
10911106 size_t srcleft ;
10921107 char * dst ;
10931108 size_t dstleft ;
@@ -1131,7 +1146,7 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
11311146 return -1 ;
11321147 }
11331148
1134- src = (const char * ) str -> bString ;
1149+ src = (ICONV_CONST char * )str -> bString ;
11351150 srcleft = str -> bLength - 2 ;
11361151 dst = (char * ) string ;
11371152 dstleft = sizeof (wchar_t [maxlen ]);
0 commit comments