From 5de39d35b88b4888d1d15c7710f0065cbf5cd451 Mon Sep 17 00:00:00 2001 From: Karel Tucek Date: Tue, 11 Feb 2025 12:56:57 +0100 Subject: [PATCH] Return only up-to-date module properties. --- .../usb_commands/usb_command_get_device_property.c | 11 ++++++++++- .../usb_commands/usb_command_get_module_property.c | 11 +++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/right/src/usb_commands/usb_command_get_device_property.c b/right/src/usb_commands/usb_command_get_device_property.c index 67825846..bda78c76 100644 --- a/right/src/usb_commands/usb_command_get_device_property.c +++ b/right/src/usb_commands/usb_command_get_device_property.c @@ -85,6 +85,7 @@ void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G checksum = ModuleMD5Checksums[moduleId]; } else { SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidArgument); + return; } break; case DEVICE_ID_UHK80_LEFT: @@ -100,8 +101,16 @@ void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G case ModuleId_Dongle: checksum = DeviceMD5Checksums[DeviceId_Uhk_Dongle]; break; + case ModuleId_TouchpadRight: + // return empty buffer + return; default: - checksum = ModuleMD5Checksums[moduleId]; + if (moduleId < ModuleId_ModuleCount) { + checksum = ModuleMD5Checksums[moduleId]; + } else { + SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidArgument); + return; + } break; } break; diff --git a/right/src/usb_commands/usb_command_get_module_property.c b/right/src/usb_commands/usb_command_get_module_property.c index e5697ec1..03260ebb 100644 --- a/right/src/usb_commands/usb_command_get_module_property.c +++ b/right/src/usb_commands/usb_command_get_module_property.c @@ -14,14 +14,20 @@ void UsbCommand_GetModuleProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G { slot_t slotId = GetUsbRxBufferUint8(1); + uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId); + if (!IS_VALID_MODULE_SLOT(slotId)) { SetUsbTxBufferUint8(0, UsbStatusCode_GetModuleProperty_InvalidModuleSlotId); } + if (!ModuleConnectionStates[moduleDriverId].moduleId || ModuleConnectionStates[moduleDriverId].moduleId == ModuleId_TouchpadRight) { + // return empty buffer + return; + } + module_property_id_t modulePropertyId = GetUsbRxBufferUint8(2); switch (modulePropertyId) { case ModulePropertyId_VersionNumbers: { - uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId); uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId; GenericHidInBuffer[1] = moduleState->moduleId; memcpy(GenericHidInBuffer + 2, &moduleState->moduleProtocolVersion, sizeof(version_t)); @@ -29,19 +35,16 @@ void UsbCommand_GetModuleProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G break; } case ModulePropertyId_GitTag: { - uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId); uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId; Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitTag, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1); break; } case ModulePropertyId_GitRepo: { - uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId); uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId; Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitRepo, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1); break; } case ModulePropertyId_RemoteFirmwareChecksumBySlotId: { - uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId); uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId; Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->firmwareChecksum, MD5_CHECKSUM_LENGTH + 1); break;