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
)
70 if ((ep
->bmAttributes
& LIBUSB_TRANSFER_TYPE_MASK
)
71 == LIBUSB_TRANSFER_TYPE_INTERRUPT
)
72 in
= ep
->bEndpointAddress
;
76 if ((ep
->bmAttributes
& LIBUSB_TRANSFER_TYPE_MASK
)
77 == LIBUSB_TRANSFER_TYPE_INTERRUPT
)
78 out
= ep
->bEndpointAddress
;
85 if (!libusb_open (dev
, &h
))
87 memset (vendor
, 0, sizeof (vendor
));
88 memset (product
, 0, sizeof (product
));
90 if (libusb_get_string_descriptor_ascii
91 (h
, desc
.iManufacturer
, (unsigned char *) vendor
,
92 sizeof (vendor
) - 1) < 0)
93 strcpy (vendor
, "<Unreadable>");
94 if (libusb_get_string_descriptor_ascii
95 (h
, desc
.iProduct
, (unsigned char *) product
,
96 sizeof (product
) - 1) < 0)
97 strcpy (product
, "<Unreadable>");
99 printf ("device: %d:%d:%d:%d:%d (%s:%s)\n",
100 libusb_get_bus_number (dev
),
101 libusb_get_device_address (dev
),
102 cfg
->bConfigurationValue
,
103 alts
->bAlternateSetting
, alts
->bInterfaceNumber
,
109 libusb_free_config_descriptor (cfg
);
117 libusb_context
*context
;
118 libusb_device
**devs
;
121 if (libusb_init (&context
))
123 fprintf (stderr
, "libusb init failure\n");
126 libusb_set_debug (context
, 0);
127 printf ("Possible addresses for KNX USB devices:\n");
128 count
= libusb_get_device_list (context
, &devs
);
130 for (i
= 0; i
< count
; i
++)
132 check_device (devs
[i
]);
135 libusb_free_device_list (devs
, 1);
136 libusb_exit (context
);