summaryrefslogtreecommitdiff
path: root/firmware/usbstack
diff options
context:
space:
mode:
authorVencislav Atanasov <user890104@freemyipod.org>2024-06-23 07:12:47 +0300
committerVencislav Atanasov <user890104@freemyipod.org>2024-06-23 08:00:06 +0300
commit9c458bbb0daa10a39c10ade69d3cc9b37a1267e0 (patch)
tree865bdf9e282fa3ceb617e29e89afaac05200ff67 /firmware/usbstack
parent9fda39d1ad2302a17349c01b5104900468baac31 (diff)
downloadrockbox-9c458bbb0daa10a39c10ade69d3cc9b37a1267e0.tar.gz
rockbox-9c458bbb0daa10a39c10ade69d3cc9b37a1267e0.zip
Use literal ATA serial number for USB SN descriptor if the string is printable
Change-Id: Ic2c853a0b124d7b590ea36229347c56f96a32f33
Diffstat (limited to 'firmware/usbstack')
-rw-r--r--firmware/usbstack/usb_core.c42
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