1
/***************************************************************************
4
* probe-usb2-device.c : USB2 Device poller
6
* Copyright (C) 2009 Joe Marcus Clarke <marcus@FreeBSD.org>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
**************************************************************************/
28
#include <sys/param.h>
29
#include <sys/types.h>
35
#include <libusb20_desc.h>
37
#if __FreeBSD_version >= 800064
38
#include <dev/usb/usb_ioctl.h>
40
#include <dev/usb2/include/usb2_standard.h>
41
#include <dev/usb2/include/usb2_ioctl.h>
44
#include "../libprobe/hfp.h"
47
main(int argc, char **argv)
49
struct libusb20_backend *pbe = NULL;
50
struct libusb20_device *pdev = NULL;
51
char *busstr, *addrstr;
54
if (! hfp_init(argc, argv))
57
pbe = libusb20_be_alloc_default();
61
busstr = getenv("HAL_PROP_USB_DEVICE_BUS_NUMBER");
65
addrstr = getenv("HAL_PROP_USB_DEVICE_PORT_NUMBER");
72
while ((pdev = libusb20_be_device_foreach(pbe, pdev)))
74
struct LIBUSB20_DEVICE_DESC_DECODED *ddesc;
75
struct LIBUSB20_CONFIG_DESC_DECODED *cdesc;
76
#if __FreeBSD_version >= 800092
77
struct usb_device_info di;
79
struct usb2_device_info di;
81
struct libusb20_config *pcfg = NULL;
84
uint8_t temp_string[256];
88
if (libusb20_dev_get_bus_number(pdev) != bus ||
89
libusb20_dev_get_address(pdev) != addr)
92
if (libusb20_dev_open(pdev, 0))
95
ddesc = libusb20_dev_get_device_desc(pdev);
96
curr_config = libusb20_dev_get_config_index(pdev);
97
pcfg = libusb20_dev_alloc_config(pdev, curr_config);
98
cdesc = &(pcfg->desc);
100
if (pcfg == NULL || libusb20_dev_get_info(pdev, &di))
106
memset(temp_string, 0, sizeof(temp_string));
108
if (cdesc->iConfiguration !=0)
109
libusb20_dev_req_string_simple_sync(pdev, cdesc->iConfiguration,
110
temp_string, sizeof(temp_string));
112
libhal_device_set_property_string(hfp_ctx, hfp_udi,
113
"usb_device.configuration", (char *) temp_string, &hfp_error);
114
libhal_device_set_property_int(hfp_ctx, hfp_udi,
115
"usb_device.configuration_value", cdesc->bConfigurationValue,
117
libhal_device_set_property_int(hfp_ctx, hfp_udi,
118
"usb_device.num_configurations", ddesc->bNumConfigurations,
120
libhal_device_set_property_int(hfp_ctx, hfp_udi,
121
"usb_device.device_class", di.udi_class, &hfp_error);
122
libhal_device_set_property_int(hfp_ctx, hfp_udi,
123
"usb_device.device_subclass", di.udi_subclass, &hfp_error);
124
libhal_device_set_property_int(hfp_ctx, hfp_udi,
125
"usb_device.device_protocol", di.udi_protocol, &hfp_error);
126
libhal_device_set_property_bool(hfp_ctx, hfp_udi,
127
"usb_device.is_self_powered",
128
di.udi_power == 0 ? TRUE : FALSE, &hfp_error);
129
libhal_device_set_property_bool(hfp_ctx, hfp_udi,
130
"usb_device.can_wake_up",
131
(cdesc->bmAttributes & UC_REMOTE_WAKEUP) != 0 ? TRUE : FALSE,
133
libhal_device_set_property_int(hfp_ctx, hfp_udi,
134
"usb_device.max_power", di.udi_power, &hfp_error);
135
libhal_device_set_property_int(hfp_ctx, hfp_udi,
136
"usb_device.num_interfaces", pcfg->num_interface, &hfp_error);
137
libhal_device_set_property_int(hfp_ctx, hfp_udi,
138
"usb_device.num_ports", di.udi_nports, &hfp_error);
140
switch (libusb20_dev_get_speed(pdev))
142
case LIBUSB20_SPEED_LOW:
146
case LIBUSB20_SPEED_FULL:
150
case LIBUSB20_SPEED_HIGH:
154
case LIBUSB20_SPEED_SUPER:
162
libhal_device_set_property_double(hfp_ctx, hfp_udi, "usb_device.speed",
164
libhal_device_set_property_int(hfp_ctx, hfp_udi, "usb_device.speed_bcd",
165
bcdspeed, &hfp_error);
167
switch (ddesc->bcdUSB)
180
libhal_device_set_property_double(hfp_ctx, hfp_udi,
181
"usb_device.version", version, &hfp_error);
182
libhal_device_set_property_int(hfp_ctx, hfp_udi,
183
"usb_device.product_id", di.udi_productNo, &hfp_error);
184
libhal_device_set_property_int(hfp_ctx, hfp_udi,
185
"usb_device.vendor_id", di.udi_vendorNo, &hfp_error);
186
libhal_device_set_property_int(hfp_ctx, hfp_udi,
187
"usb_device.device_revision_bcd", ddesc->bcdUSB, &hfp_error);
188
libhal_device_set_property_string(hfp_ctx, hfp_udi,
189
"usb_device.serial", di.udi_serial, &hfp_error);
190
libhal_device_set_property_string(hfp_ctx, hfp_udi,
191
"usb_device.product", di.udi_product, &hfp_error);
192
libhal_device_set_property_string(hfp_ctx, hfp_udi,
193
"usb_device.vendor", di.udi_vendor, &hfp_error);
195
libhal_device_set_property_string(hfp_ctx, hfp_udi,
196
"info.product", di.udi_product, &hfp_error);
197
libhal_device_set_property_string(hfp_ctx, hfp_udi,
198
"info.vendor", di.udi_vendor, &hfp_error);
200
libusb20_dev_close(pdev);
205
libusb20_be_free(pbe);