wok annotate hardinfo/stuff/usb.patch @ rev 15427

Up: thunderbird-langpack-sl (17.0.9esr)
author Dominique Corbex <domcox@slitaz.org>
date Sun Nov 03 21:52:54 2013 +0100 (2013-11-03)
parents
children
rev   line source
pascal@1773 1 --- util.c
pascal@1773 2 +++ util.c
pascal@1773 3 @@ -1048,3 +1048,55 @@
pascal@1773 4 h_hash_table_remove_all_true,
pascal@1773 5 NULL);
pascal@1773 6 }
pascal@1773 7 +
pascal@1773 8 +gfloat
pascal@1773 9 +h_sysfs_read_float(gchar *endpoint, gchar *entry)
pascal@1773 10 +{
pascal@1773 11 + gchar *tmp, *buffer;
pascal@1773 12 + gfloat return_value = 0.0f;
pascal@1773 13 +
pascal@1773 14 + tmp = g_build_filename(endpoint, entry, NULL);
pascal@1773 15 + if (g_file_get_contents(tmp, &buffer, NULL, NULL))
pascal@1773 16 + return_value = atof(buffer);
pascal@1773 17 +
pascal@1773 18 + g_free(tmp);
pascal@1773 19 + g_free(buffer);
pascal@1773 20 +
pascal@1773 21 + return return_value;
pascal@1773 22 +}
pascal@1773 23 +
pascal@1773 24 +gint
pascal@1773 25 +h_sysfs_read_int(gchar *endpoint, gchar *entry)
pascal@1773 26 +{
pascal@1773 27 + gchar *tmp, *buffer;
pascal@1773 28 + gint return_value = 0.0f;
pascal@1773 29 +
pascal@1773 30 + tmp = g_build_filename(endpoint, entry, NULL);
pascal@1773 31 + if (g_file_get_contents(tmp, &buffer, NULL, NULL))
pascal@1773 32 + return_value = atoi(buffer);
pascal@1773 33 +
pascal@1773 34 + g_free(tmp);
pascal@1773 35 + g_free(buffer);
pascal@1773 36 +
pascal@1773 37 + return return_value;
pascal@1773 38 +}
pascal@1773 39 +
pascal@1773 40 +gchar *
pascal@1773 41 +h_sysfs_read_string(gchar *endpoint, gchar *entry)
pascal@1773 42 +{
pascal@1773 43 + gchar *tmp, *return_value;
pascal@1773 44 +
pascal@1773 45 + tmp = g_build_filename(endpoint, entry, NULL);
pascal@1773 46 + if (!g_file_get_contents(tmp, &return_value, NULL, NULL)) {
pascal@1773 47 + g_free(return_value);
pascal@1773 48 +
pascal@1773 49 + return_value = NULL;
pascal@1773 50 + } else {
pascal@1773 51 + return_value = g_strstrip(return_value);
pascal@1773 52 + }
pascal@1773 53 +
pascal@1773 54 + g_free(tmp);
pascal@1773 55 +
pascal@1773 56 + return return_value;
pascal@1773 57 +}
pascal@1773 58 +
pascal@1773 59
pascal@1773 60 --- arch/linux/common/usb.h
pascal@1773 61 +++ arch/linux/common/usb.h
pascal@1773 62 @@ -15,7 +15,6 @@
pascal@1773 63 * along with this program; if not, write to the Free Software
pascal@1773 64 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
pascal@1773 65 */
pascal@1773 66 -
pascal@1773 67 static gboolean
pascal@1773 68 remove_usb_devices(gpointer key, gpointer value, gpointer data)
pascal@1773 69 {
pascal@1773 70 @@ -23,8 +22,113 @@
pascal@1773 71 }
pascal@1773 72
pascal@1773 73 static gchar *usb_list = NULL;
pascal@1773 74 -void
pascal@1773 75 -__scan_usb(void)
pascal@1773 76 +
pascal@1773 77 +void __scan_usb_sysfs_add_device(gchar * endpoint, int n)
pascal@1773 78 +{
pascal@1773 79 + gchar *manufacturer, *product, *mxpwr, *tmp, *strhash;
pascal@1773 80 + gint bus, classid, vendor, prodid;
pascal@1773 81 + gchar *version, *speed;
pascal@1773 82 +
pascal@1773 83 + classid = h_sysfs_read_int(endpoint, "bDeviceClass");
pascal@1773 84 + vendor = h_sysfs_read_int(endpoint, "idVendor");
pascal@1773 85 + prodid = h_sysfs_read_int(endpoint, "idProduct");
pascal@1773 86 + bus = h_sysfs_read_int(endpoint, "busnum");
pascal@1773 87 + if (!(speed = h_sysfs_read_string(endpoint, "speed"))) {
pascal@1773 88 + speed = g_strdup("12");
pascal@1773 89 + }
pascal@1773 90 +
pascal@1773 91 + if (!(version = h_sysfs_read_string(endpoint, "version"))) {
pascal@1773 92 + version = g_strdup(" 1.0 ");
pascal@1773 93 + }
pascal@1773 94 +
pascal@1773 95 + if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) {
pascal@1773 96 + mxpwr = g_strdup("0 mA");
pascal@1773 97 + }
pascal@1773 98 +
pascal@1773 99 + if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) {
pascal@1773 100 + manufacturer = g_strdup("Unknown");
pascal@1773 101 + }
pascal@1773 102 +
pascal@1773 103 + if (!(product = h_sysfs_read_string(endpoint, "product"))) {
pascal@1773 104 + if (classid == 9) {
pascal@1773 105 + product = g_strdup_printf("USB %.2f Hub", version);
pascal@1773 106 + } else {
pascal@1773 107 + product = g_strdup_printf("Unknown USB %.2f Device (class %d)", version, classid);
pascal@1773 108 + }
pascal@1773 109 + }
pascal@1773 110 +
pascal@1773 111 + const gchar *url = vendor_get_url(manufacturer);
pascal@1773 112 + if (url) {
pascal@1773 113 + tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url);
pascal@1773 114 +
pascal@1773 115 + g_free(manufacturer);
pascal@1773 116 + manufacturer = tmp;
pascal@1773 117 + }
pascal@1773 118 +
pascal@1773 119 + tmp = g_strdup_printf("USB%d", n);
pascal@1773 120 + usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product);
pascal@1773 121 +
pascal@1773 122 + strhash = g_strdup_printf("[Device Information]\n"
pascal@1773 123 + "Product=%s\n"
pascal@1773 124 + "Manufacturer=%s\n"
pascal@1773 125 + "Speed=%sMbit/s\n"
pascal@1773 126 + "Max Current=%s\n"
pascal@1773 127 + "[Misc]\n"
pascal@1773 128 + "USB Version=%s\n"
pascal@1773 129 + "Class=0x%x\n"
pascal@1773 130 + "Vendor=0x%x\n"
pascal@1773 131 + "Product ID=0x%x\n"
pascal@1773 132 + "Bus=%d\n",
pascal@1773 133 + product,
pascal@1773 134 + manufacturer,
pascal@1773 135 + speed,
pascal@1773 136 + mxpwr,
pascal@1773 137 + version, classid, vendor, prodid, bus);
pascal@1773 138 +
pascal@1773 139 + g_hash_table_insert(moreinfo, tmp, strhash);
pascal@1773 140 +
pascal@1773 141 + g_free(manufacturer);
pascal@1773 142 + g_free(product);
pascal@1773 143 + g_free(mxpwr);
pascal@1773 144 + g_free(speed);
pascal@1773 145 + g_free(version);
pascal@1773 146 +}
pascal@1773 147 +
pascal@1773 148 +void __scan_usb_sysfs(void)
pascal@1773 149 +{
pascal@1773 150 + GDir *sysfs;
pascal@1773 151 + gchar *filename;
pascal@1773 152 + const gchar *sysfs_path = "/sys/class/usb_endpoint";
pascal@1773 153 + gint usb_device_number = 0;
pascal@1773 154 +
pascal@1773 155 + if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) {
pascal@1773 156 + return;
pascal@1773 157 + }
pascal@1773 158 +
pascal@1773 159 + if (usb_list) {
pascal@1773 160 + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL);
pascal@1773 161 + g_free(usb_list);
pascal@1773 162 + }
pascal@1773 163 + usb_list = g_strdup("[USB Devices]\n");
pascal@1773 164 +
pascal@1773 165 + while ((filename = (gchar *) g_dir_read_name(sysfs))) {
pascal@1773 166 + gchar *endpoint =
pascal@1773 167 + g_build_filename(sysfs_path, filename, "device", NULL);
pascal@1773 168 + gchar *temp;
pascal@1773 169 +
pascal@1773 170 + temp = g_build_filename(endpoint, "idVendor", NULL);
pascal@1773 171 + if (g_file_test(temp, G_FILE_TEST_EXISTS)) {
pascal@1773 172 + __scan_usb_sysfs_add_device(endpoint, ++usb_device_number);
pascal@1773 173 + }
pascal@1773 174 +
pascal@1773 175 + g_free(temp);
pascal@1773 176 + g_free(endpoint);
pascal@1773 177 + }
pascal@1773 178 +
pascal@1773 179 + g_dir_close(sysfs);
pascal@1773 180 +}
pascal@1773 181 +
pascal@1773 182 +int __scan_usb_procfs(void)
pascal@1773 183 {
pascal@1773 184 FILE *dev;
pascal@1773 185 gchar buffer[128];
pascal@1773 186 @@ -36,13 +140,13 @@
pascal@1773 187
pascal@1773 188 dev = fopen("/proc/bus/usb/devices", "r");
pascal@1773 189 if (!dev)
pascal@1773 190 - return;
pascal@1773 191 + return 0;
pascal@1773 192
pascal@1773 193 if (usb_list) {
pascal@1773 194 g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL);
pascal@1773 195 g_free(usb_list);
pascal@1773 196 }
pascal@1773 197 - usb_list = g_strdup("");
pascal@1773 198 + usb_list = g_strdup("[USB Devices]\n");
pascal@1773 199
pascal@1773 200 while (fgets(buffer, 128, dev)) {
pascal@1773 201 tmp = buffer;
pascal@1773 202 @@ -73,52 +177,60 @@
pascal@1773 203 mxpwr = strstr(buffer, "MxPwr=") + 6;
pascal@1773 204
pascal@1773 205 tmp = g_strdup_printf("USB%d", ++n);
pascal@1773 206 -
pascal@1773 207 +
pascal@1773 208 if (*product == '\0') {
pascal@1773 209 - g_free(product);
pascal@1773 210 - if (classid == 9) {
pascal@1773 211 - product = g_strdup_printf("USB %.2f Hub", ver);
pascal@1773 212 - } else {
pascal@1773 213 - product = g_strdup_printf("Unknown USB %.2f Device (class %d)",
pascal@1773 214 - ver, classid);
pascal@1773 215 - }
pascal@1773 216 + g_free(product);
pascal@1773 217 + if (classid == 9) {
pascal@1773 218 + product = g_strdup_printf("USB %.2f Hub", ver);
pascal@1773 219 + } else {
pascal@1773 220 + product =
pascal@1773 221 + g_strdup_printf
pascal@1773 222 + ("Unknown USB %.2f Device (class %d)", ver,
pascal@1773 223 + classid);
pascal@1773 224 + }
pascal@1773 225 }
pascal@1773 226 -
pascal@1773 227 +
pascal@1773 228
pascal@1773 229 if (classid == 9) { /* hub */
pascal@1773 230 - usb_list = h_strdup_cprintf("[%s#%d]\n",
pascal@1773 231 - usb_list, product, n);
pascal@1773 232 - } else { /* everything else */
pascal@1773 233 - usb_list = h_strdup_cprintf("$%s$%s=\n",
pascal@1773 234 - usb_list, tmp, product);
pascal@1773 235 -
pascal@1773 236 - const gchar *url = vendor_get_url(manuf);
pascal@1773 237 - if (url) {
pascal@1773 238 - gchar *tmp = g_strdup_printf("%s (%s)", manuf, url);
pascal@1773 239 - g_free(manuf);
pascal@1773 240 - manuf = tmp;
pascal@1773 241 - }
pascal@1773 242 -
pascal@1773 243 - gchar *strhash = g_strdup_printf("[Device Information]\n"
pascal@1773 244 - "Product=%s\n"
pascal@1773 245 - "Manufacturer=%s\n"
pascal@1773 246 - "[Port #%d]\n"
pascal@1773 247 - "Speed=%.2fMbit/s\n"
pascal@1773 248 - "Max Current=%s\n"
pascal@1773 249 - "[Misc]\n"
pascal@1773 250 - "USB Version=%.2f\n"
pascal@1773 251 - "Revision=%.2f\n"
pascal@1773 252 - "Class=0x%x\n"
pascal@1773 253 - "Vendor=0x%x\n"
pascal@1773 254 - "Product ID=0x%x\n"
pascal@1773 255 - "Bus=%d\n" "Level=%d\n",
pascal@1773 256 - product, manuf,
pascal@1773 257 - port, speed, mxpwr,
pascal@1773 258 - ver, rev, classid,
pascal@1773 259 - vendor, prodid, bus, level);
pascal@1773 260 + usb_list = h_strdup_cprintf("[%s#%d]\n",
pascal@1773 261 + usb_list, product, n);
pascal@1773 262 + } else { /* everything else */
pascal@1773 263 + usb_list = h_strdup_cprintf("$%s$%s=\n",
pascal@1773 264 + usb_list, tmp, product);
pascal@1773 265 +
pascal@1773 266 + const gchar *url = vendor_get_url(manuf);
pascal@1773 267 + if (url) {
pascal@1773 268 + gchar *tmp =
pascal@1773 269 + g_strdup_printf("%s (%s)", vendor_get_name(manuf),
pascal@1773 270 + url);
pascal@1773 271 + g_free(manuf);
pascal@1773 272 + manuf = tmp;
pascal@1773 273 + }
pascal@1773 274 +
pascal@1773 275 + gchar *strhash = g_strdup_printf("[Device Information]\n"
pascal@1773 276 + "Product=%s\n",
pascal@1773 277 + product);
pascal@1773 278 + if (manuf && strlen(manuf))
pascal@1773 279 + strhash = h_strdup_cprintf("Manufacturer=%s\n",
pascal@1773 280 + strhash, manuf);
pascal@1773 281 +
pascal@1773 282 + strhash = h_strdup_cprintf("[Port #%d]\n"
pascal@1773 283 + "Speed=%.2fMbit/s\n"
pascal@1773 284 + "Max Current=%s\n"
pascal@1773 285 + "[Misc]\n"
pascal@1773 286 + "USB Version=%.2f\n"
pascal@1773 287 + "Revision=%.2f\n"
pascal@1773 288 + "Class=0x%x\n"
pascal@1773 289 + "Vendor=0x%x\n"
pascal@1773 290 + "Product ID=0x%x\n"
pascal@1773 291 + "Bus=%d\n" "Level=%d\n",
pascal@1773 292 + strhash,
pascal@1773 293 + port, speed, mxpwr,
pascal@1773 294 + ver, rev, classid,
pascal@1773 295 + vendor, prodid, bus, level);
pascal@1773 296
pascal@1773 297 - g_hash_table_insert(moreinfo, tmp, strhash);
pascal@1773 298 - }
pascal@1773 299 + g_hash_table_insert(moreinfo, tmp, strhash);
pascal@1773 300 + }
pascal@1773 301
pascal@1773 302 g_free(manuf);
pascal@1773 303 g_free(product);
pascal@1773 304 @@ -128,4 +240,12 @@
pascal@1773 305 }
pascal@1773 306
pascal@1773 307 fclose(dev);
pascal@1773 308 +
pascal@1773 309 + return n;
pascal@1773 310 +}
pascal@1773 311 +
pascal@1773 312 +void __scan_usb(void)
pascal@1773 313 +{
pascal@1773 314 + if (!__scan_usb_procfs())
pascal@1773 315 + __scan_usb_sysfs();
pascal@1773 316 }