diff options
Diffstat (limited to 'firmware/usbstack')
-rw-r--r-- | firmware/usbstack/usb_core.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c index d37604f492..b4a117d959 100644 --- a/firmware/usbstack/usb_core.c +++ b/firmware/usbstack/usb_core.c | |||
@@ -359,17 +359,43 @@ static void set_serial_descriptor(void) | |||
359 | { | 359 | { |
360 | short* p = &usb_string_iSerial.wString[1]; | 360 | short* p = &usb_string_iSerial.wString[1]; |
361 | unsigned short* identify = ata_get_identify(); | 361 | unsigned short* identify = ata_get_identify(); |
362 | unsigned short x; | 362 | char sn[20]; |
363 | char length = 20; | ||
363 | int i; | 364 | int i; |
364 | 365 | ||
365 | for(i = 10; i < 20; i++) { | 366 | for (i = 0; i < length / 2; i++) { |
366 | x = identify[i]; | 367 | ((unsigned short*)sn)[i] = htobe16(identify[i + 10]); |
367 | *p++ = hex[(x >> 12) & 0xF]; | 368 | } |
368 | *p++ = hex[(x >> 8) & 0xF]; | 369 | |
369 | *p++ = hex[(x >> 4) & 0xF]; | 370 | char is_printable = 1; |
370 | *p++ = hex[(x >> 0) & 0xF]; | 371 | for (i = 0; i < length; i++) { |
372 | if (sn[i] < 32 || sn[i] > 126) { | ||
373 | is_printable = 0; | ||
374 | break; | ||
375 | } | ||
376 | } | ||
377 | |||
378 | if (is_printable) { | ||
379 | /* trim trailing spaces */ | ||
380 | while (length > 0 && sn[length - 1] == ' ') { | ||
381 | length--; | ||
382 | } | ||
383 | |||
384 | for (i = 0; i < length; i++) { | ||
385 | *p++ = sn[i]; | ||
386 | } | ||
387 | |||
388 | usb_string_iSerial.bLength = 2 + 2 * (1 + length); | ||
389 | } | ||
390 | else { | ||
391 | for (i = 0; i < length; i++) { | ||
392 | char x = sn[i]; | ||
393 | *p++ = hex[(x >> 4) & 0xF]; | ||
394 | *p++ = hex[x & 0xF]; | ||
395 | } | ||
396 | |||
397 | usb_string_iSerial.bLength = 2 + 2 * (1 + length * 2); | ||
371 | } | 398 | } |
372 | usb_string_iSerial.bLength = 84; | ||
373 | } | 399 | } |
374 | #elif (CONFIG_STORAGE & STORAGE_RAMDISK) | 400 | #elif (CONFIG_STORAGE & STORAGE_RAMDISK) |
375 | /* This "serial number" isn't unique, but it should never actually | 401 | /* This "serial number" isn't unique, but it should never actually |