Commit 589dbc4c authored by Johann Fischer's avatar Johann Fischer Committed by Carles Cufi
Browse files

subsys: usb: add function to find and fix USB descriptors



This patch introduces a function to find and correct all string
descriptor.

Signed-off-by: default avatarJohann Fischer <j.fischer@phytec.de>
parent 0fca1644
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -826,18 +826,34 @@ static void ascii7_to_utf16le(void *descriptor)
	}
}

u8_t *usb_get_device_descriptor(void)
static void usb_fix_descriptor(struct usb_desc_header *head)
{
	ascii7_to_utf16le(&common_desc.string_descr.utf16le_mfr);
	u8_t str_descr_idx = 0;

	while (head->bLength) {
		switch (head->bDescriptorType) {
		case USB_STRING_DESC:
			SYS_LOG_DBG("String descriptor %p idx %d",
				    head, str_descr_idx);
			if (str_descr_idx) {
				ascii7_to_utf16le(head);
			}

	ascii7_to_utf16le(&common_desc.string_descr.utf16le_product);
			str_descr_idx += 1;
			break;
		default:
			break;
		}

	ascii7_to_utf16le(&common_desc.string_descr.utf16le_sn);
		/* Move to next descriptor */
		head = (struct usb_desc_header *)((u8_t *)head + head->bLength);
	}
}

#ifdef CONFIG_USB_DEVICE_NETWORK_ECM
	ascii7_to_utf16le(&common_desc.string_descr.utf16le_mac);
#endif

u8_t *usb_get_device_descriptor(void)
{
	usb_fix_descriptor((struct usb_desc_header *)(&common_desc));
	return (u8_t *) &common_desc;
}