Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Aug 3, 2023
1 parent 7f63a97 commit ced19f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/dfu.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ const DfuseCommand = {

const DfuBmRequestType = {
HOST_TO_DEVICE: 0x21,
DEVICE_TO_HOST: 0xA1
DEVICE_TO_HOST: 0xA1,
DEVICE_TO_HOST_STANDARD: 0x80 // Direction: device-to-host; type: standard; recipient: device
};

const DFU_STATUS_SIZE = 6;
Expand Down Expand Up @@ -632,7 +633,7 @@ class Dfu {
async _getStringDescriptor(index) {
// Read the size of the descriptor
let d = await this._dev.transferIn({
bmRequestType: 0x80, // Direction: device-to-host; type: standard; recipient: device
bmRequestType: DfuBmRequestType.DEVICE_TO_HOST_STANDARD,
bRequest: 0x06, // GET_DESCRIPTOR
wValue: (0x03 /* STRING */ << 8) | (index & 0xff),
wIndex: 0x0409, // English (US)
Expand All @@ -641,7 +642,7 @@ class Dfu {
let len = d.readUInt8(0); // bLength

Check failure on line 642 in src/dfu.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

'len' is never reassigned. Use 'const' instead
// Read the descriptor
d = await this._dev.transferIn({
bmRequestType: 0x80,
bmRequestType: DfuBmRequestType.DEVICE_TO_HOST_STANDARD,
bRequest: 0x06,
wValue: (0x03 << 8) | (index & 0xff),
wIndex: 0x0409,
Expand All @@ -660,7 +661,7 @@ class Dfu {
async _getConfigDescriptor(index) {
// Read the total size of the descriptors
const d = await this._dev.transferIn({
bmRequestType: 0x80, // Direction: device-to-host; type: standard; recipient: device
bmRequestType: DfuBmRequestType.DEVICE_TO_HOST_STANDARD,
bRequest: 0x06, // GET_DESCRIPTOR
wValue: (0x02 /* CONFIGURATION */ << 8) | (index & 0xff),
wIndex: 0,
Expand All @@ -669,7 +670,7 @@ class Dfu {
const len = d.readUInt16LE(2); // wTotalLength
// Read the descriptors
return await this._dev.transferIn({
bmRequestType: 0x80,
bmRequestType: DfuBmRequestType.DEVICE_TO_HOST_STANDARD,
bRequest: 0x06,
wValue: (0x02 << 8) | (index & 0xff),
wIndex: 0,
Expand Down
11 changes: 8 additions & 3 deletions test/support/fake-usb.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Protocol {
}

deviceToHostRequest(setup) {
if (setup.bmRequestType !== proto.BmRequestType.DEVICE_TO_HOST) {
if (setup.bmRequestType !== proto.BmRequestType.DEVICE_TO_HOST && setup.bmRequestType !== dfu.DfuBmRequestType.DEVICE_TO_HOST_STANDARD) {

Check failure on line 53 in test/support/fake-usb.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

This line has a length of 145. Maximum allowed is 120
throw new ProtocolError(`Unsupported device-to-host request: bmRequestType: ${setup.bmRequestType}`);
}
let data = null;
Expand Down Expand Up @@ -82,6 +82,9 @@ class Protocol {
}
break;
}
case 0x06:
// GET_DESCRIPTOR
break;
default: {
throw new ProtocolError(`Unsupported device-to-host request: bRequest: ${setup.bRequest}`);
}
Expand Down Expand Up @@ -346,7 +349,7 @@ class DfuClass {

deviceToHostRequest(setup) {
// Implements DFU_GETSTATUS only
if (setup.bmRequestType !== dfu.DfuBmRequestType.DEVICE_TO_HOST) {
if (setup.bmRequestType !== dfu.DfuBmRequestType.DEVICE_TO_HOST && setup.bmRequestType !== dfu.DfuBmRequestType.DEVICE_TO_HOST_STANDARD) {

Check failure on line 352 in test/support/fake-usb.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

This line has a length of 146. Maximum allowed is 120
throw new UsbError('Unknown bmRequestType');
}

Expand All @@ -358,7 +361,9 @@ class DfuClass {
case dfu.DfuRequestType.DFU_GETSTATUS: {
return this._getStatus(setup);
}

case 0x06:
// Sample from the device (GET_DESCRIPTOR)
return Buffer.from([9,2,36,0,1,1,4,192,50,9,4,0,0,0,254,1,2,5,9,4,0,1,0,254,1,2,6,9,33,11,255,0,0,16,26,1]);

Check failure on line 366 in test/support/fake-usb.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

This line has a length of 124. Maximum allowed is 120
default: {
throw new UsbError('Unknown bRequest');
}
Expand Down

0 comments on commit ced19f8

Please sign in to comment.