2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 check_device (libusb_device
* dev
)
29 struct libusb_device_descriptor desc
;
30 struct libusb_config_descriptor
*cfg
;
31 const struct libusb_interface
*intf
;
32 const struct libusb_interface_descriptor
*alts
;
33 const struct libusb_endpoint_descriptor
*ep
;
34 libusb_device_handle
*h
;
40 if (libusb_get_device_descriptor (dev
, &desc
))
42 fprintf (stderr
, "libusb_get_device_descriptor failed\n");
45 for (j
= 0; j
< desc
.bNumConfigurations
; j
++)
47 if (libusb_get_config_descriptor (dev
, j
, &cfg
))
49 fprintf (stderr
, "libusb_get_config_descriptor failed\n");
52 for (k
= 0; k
< cfg
->bNumInterfaces
; k
++)
54 intf
= &cfg
->interface
[k
];
55 for (l
= 0; l
< intf
->num_altsetting
; l
++)
57 alts
= &intf
->altsetting
[l
];
58 if (alts
->bInterfaceClass
!= LIBUSB_CLASS_HID
)
63 for (m
= 0; m
< alts
->bNumEndpoints
; m
++)
65 ep
= &alts
->endpoint
[m
];
66 if (ep
->wMaxPacketSize
== 64)
68 if (ep
->bEndpointAddress
& LIBUSB_ENDPOINT_IN
)
71 bmAttributes
& LIBUSB_TRANSFER_TYPE_MASK
) ==
72 LIBUSB_TRANSFER_TYPE_INTERRUPT
)
73 in
= ep
->bEndpointAddress
;
78 bmAttributes
& LIBUSB_TRANSFER_TYPE_MASK
) ==
79 LIBUSB_TRANSFER_TYPE_INTERRUPT
)
80 out
= ep
->bEndpointAddress
;
87 if (!libusb_open (dev
, &h
))
89 memset (vendor
, 0, sizeof (vendor
));
90 memset (product
, 0, sizeof (product
));
92 if (libusb_get_string_descriptor_ascii
93 (h
, desc
.iManufacturer
, (unsigned char *) vendor
,
94 sizeof (vendor
) - 1) < 0)
95 strcpy (vendor
, "<Unreadable>");
96 if (libusb_get_string_descriptor_ascii
97 (h
, desc
.iProduct
, (unsigned char *) product
,
98 sizeof (product
) - 1) < 0)
99 strcpy (product
, "<Unreadable>");
101 printf ("device: %d:%d:%d:%d:%d (%s:%s)\n",
102 libusb_get_bus_number (dev
),
103 libusb_get_device_address (dev
),
104 cfg
->bConfigurationValue
,
105 alts
->bAlternateSetting
, alts
->bInterfaceNumber
,
111 libusb_free_config_descriptor (cfg
);
119 libusb_context
*context
;
120 libusb_device
**devs
;
123 if (libusb_init (&context
))
125 fprintf (stderr
, "libusb init failure\n");
128 libusb_set_debug (context
, 0);
129 printf ("Possible addresses for KNX USB devices:\n");
130 count
= libusb_get_device_list (NULL
, &devs
);
132 for (i
= 0; i
< count
; i
++)
134 check_device (devs
[i
]);
137 libusb_free_device_list (devs
, 1);
138 libusb_exit (context
);