forked from len0rd/rockbox
Use literal ATA serial number for USB SN descriptor if the string is printable
Change-Id: Ic2c853a0b124d7b590ea36229347c56f96a32f33
This commit is contained in:
parent
9fda39d1ad
commit
9c458bbb0d
1 changed files with 34 additions and 8 deletions
|
@ -359,17 +359,43 @@ static void set_serial_descriptor(void)
|
||||||
{
|
{
|
||||||
short* p = &usb_string_iSerial.wString[1];
|
short* p = &usb_string_iSerial.wString[1];
|
||||||
unsigned short* identify = ata_get_identify();
|
unsigned short* identify = ata_get_identify();
|
||||||
unsigned short x;
|
char sn[20];
|
||||||
|
char length = 20;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 10; i < 20; i++) {
|
for (i = 0; i < length / 2; i++) {
|
||||||
x = identify[i];
|
((unsigned short*)sn)[i] = htobe16(identify[i + 10]);
|
||||||
*p++ = hex[(x >> 12) & 0xF];
|
}
|
||||||
*p++ = hex[(x >> 8) & 0xF];
|
|
||||||
*p++ = hex[(x >> 4) & 0xF];
|
char is_printable = 1;
|
||||||
*p++ = hex[(x >> 0) & 0xF];
|
for (i = 0; i < length; i++) {
|
||||||
|
if (sn[i] < 32 || sn[i] > 126) {
|
||||||
|
is_printable = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_printable) {
|
||||||
|
/* trim trailing spaces */
|
||||||
|
while (length > 0 && sn[length - 1] == ' ') {
|
||||||
|
length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < length; i++) {
|
||||||
|
*p++ = sn[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_string_iSerial.bLength = 2 + 2 * (1 + length);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (i = 0; i < length; i++) {
|
||||||
|
char x = sn[i];
|
||||||
|
*p++ = hex[(x >> 4) & 0xF];
|
||||||
|
*p++ = hex[x & 0xF];
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_string_iSerial.bLength = 2 + 2 * (1 + length * 2);
|
||||||
}
|
}
|
||||||
usb_string_iSerial.bLength = 84;
|
|
||||||
}
|
}
|
||||||
#elif (CONFIG_STORAGE & STORAGE_RAMDISK)
|
#elif (CONFIG_STORAGE & STORAGE_RAMDISK)
|
||||||
/* This "serial number" isn't unique, but it should never actually
|
/* This "serial number" isn't unique, but it should never actually
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue