Skip to content

Commit

Permalink
Fixed wrong bLength value in USB string descriptor response.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Starke <[email protected]>
  • Loading branch information
daniel-starke committed Oct 3, 2023
1 parent 651abef commit a73189a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Daniel Starke
* @copyright Copyright 2020-2022 Daniel Starke
* @date 2020-05-21
* @version 2023-09-18
* @version 2023-09-25
*
* Control Endpoint:
* @verbatim
Expand Down Expand Up @@ -817,7 +817,7 @@ bool USBDeviceClass::handleStandardSetup(USBSetup & setup) {
case SET_CONFIGURATION:
if ((setup.bmRequestType & REQUEST_RECIPIENT) == REQUEST_DEVICE) {
this->initEndpoints();
_usbConfiguration = setup.wValueL;
_usbConfiguration = setup.wValueL; /* bConfigurationValue */
this->sendZlp(0);
} else {
return false;
Expand Down Expand Up @@ -879,18 +879,18 @@ bool USBDeviceClass::sendDescriptor(USBSetup & setup) {
case ISERIAL:
{
char name[ISERIAL_MAX_LEN] = {0};
uint8_t idx = 0;
uint8_t len = 0;
#ifdef UID_BASE
const uint32_t * uidPtr = reinterpret_cast<const uint32_t *>(UID_BASE);
const uint32_t uid = uidPtr[0] ^ uidPtr[1] ^ uidPtr[2];
for (; idx < 8; idx++) {
name[idx] = "0123456789ABCDEF"[(uid >> (4 * idx)) & 0xF];
for (; len < 8; len++) {
name[len] = "0123456789ABCDEF"[(uid >> (4 * len)) & 0xF];
}
#endif /* UID_BASE */
#ifdef PLUGGABLE_USB_ENABLED
idx = uint8_t(idx + PluggableUSB().getShortName(name + idx));
len = uint8_t(len + PluggableUSB().getShortName(name + len));
#endif /* PLUGGABLE_USB_ENABLED */
if (idx > 0) {
if (len > 0) {
return this->sendStringDescriptor(reinterpret_cast<const uint8_t *>(name), setup.wLength);
}
}
Expand Down Expand Up @@ -986,7 +986,7 @@ bool USBDeviceClass::sendConfiguration(uint32_t maxLen) {
bool USBDeviceClass::sendStringDescriptor(const uint8_t * string, uint32_t maxLen) {
if (maxLen < 2) return false;
if (maxLen == 2) {
ctrlStatBuf[0] = 0; /* bLength */
ctrlStatBuf[0] = 2; /* bLength */
ctrlStatBuf[1] = 0x03; /* bDescriptorType: String */
this->sendControl(ctrlStatBuf, 2);
return true;
Expand Down

0 comments on commit a73189a

Please sign in to comment.