1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*
* HardInfo - Displays System Information
* Copyright (C) 2003-2008 Leandro A. F. Pereira <leandro@hardinfo.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string.h>
#include "hardinfo.h"
#include "devices.h"
#include "usb_util.h"
gchar *usb_list = NULL;
#define UNKIFNULL_AC(f) (f != NULL) ? f : _("(Unknown)");
static void _usb_dev(const usbd *u) {
gchar *name, *key, *v_str, *str;
gchar *product, *vendor, *dev_class_str, *dev_subclass_str; /* don't free */
vendor = UNKIFNULL_AC(u->vendor);
product = UNKIFNULL_AC(u->product);
dev_class_str = UNKIFNULL_AC(u->dev_class_str);
dev_subclass_str = UNKIFNULL_AC(u->dev_subclass_str);
name = g_strdup_printf("%s %s", vendor, product);
key = g_strdup_printf("USB%03d:%03d:%03d", u->bus, u->dev, 0);
usb_list = h_strdup_cprintf("$%s$%03d:%03d=%s\n", usb_list, key, u->bus, u->dev, name);
const gchar *v_url = vendor_get_url(vendor);
const gchar *v_name = vendor_get_name(vendor);
if (v_url != NULL) {
v_str = g_strdup_printf("%s (%s)", v_name, v_url);
} else {
v_str = g_strdup_printf("%s", vendor );
}
str = g_strdup_printf("[%s]\n"
/* Product */ "%s=[0x%04x] %s\n"
/* Manufacturer */ "%s=[0x%04x] %s\n"
/* Max Current */ "%s=%d %s\n"
/* USB Version */ "%s=%s\n"
/* Class */ "%s=[%d] %s\n"
/* Sub-class */ "%s=[%d] %s\n"
/* Dev Version */ "%s=%s\n"
"[%s]\n"
/* Bus */ "%s=%03d\n"
/* Device */ "%s=%03d\n",
_("Device Information"),
_("Product"), u->product_id, product,
_("Vendor"), u->vendor_id, v_str,
_("Max Current"), u->max_curr_ma, _("mA"),
_("USB Version"), u->usb_version,
_("Class"), u->dev_class, dev_class_str,
_("Sub-class"), u->dev_subclass, dev_subclass_str,
_("Device Version"), u->device_version,
_("Connection"),
_("Bus"), u->bus,
_("Device"), u->dev
);
moreinfo_add_with_prefix("DEV", key, str); /* str now owned by morinfo */
g_free(v_str);
g_free(name);
g_free(key);
}
void __scan_usb(void) {
usbd *list = usb_get_device_list();
usbd *curr = list;
int c = usbd_list_count(list);
if (usb_list) {
moreinfo_del_with_prefix("DEV:USB");
g_free(usb_list);
}
usb_list = g_strdup_printf("[%s]\n", _("USB Devices"));
if (c > 0) {
while(curr) {
_usb_dev(curr);
curr=curr->next;
}
usbd_list_free(list);
} else {
/* No USB? */
usb_list = g_strconcat(usb_list, _("No USB devices found."), "=\n", NULL);
}
}
|