Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new DFU string index to show device state #2807

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bootloader/src/nRF52840/usbd_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "deviceid_hal.h"
#include "bytes2hexbuf.h"
#include "platforms.h"
#include "security_mode.h"

using namespace particle::usbd;

Expand Down Expand Up @@ -194,6 +195,18 @@ char* device_id_as_string(char* buf) {
return buf;
}

char* device_state_as_string(char* buf) {
int mode = security_mode_get(nullptr);

if (mode == MODULE_INFO_SECURITY_MODE_NONE) {
memcpy(buf, security_mode_is_overridden() ? "sm=s" : "sm=o", 4);
} else {
memcpy(buf, "sm=p", 4);
}

return buf;
}

} /* anonymous */

dfu::DfuClassDriver g_dfuInstance(&NrfDevice::instance());
Expand Down Expand Up @@ -753,6 +766,11 @@ const uint8_t* NrfDevice::getString(SetupRequest* r, uint16_t* len) {
/* No conversion to UTF-16 */
return getUnicodeString(USBD_MsftStrDesc, sizeof(USBD_MsftStrDesc), len, true);
}
case STRING_IDX_DEVICE_STATE: {
/* No conversion to UTF-16 */
char deviceStateStr[8] = {0};
return getUnicodeString(device_state_as_string(deviceStateStr), sizeof(deviceStateStr), len, false);
}
default: {
if (drv_) {
bool conv = true;
Expand Down
3 changes: 2 additions & 1 deletion bootloader/src/nRF52840/usbd_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class Device {
STRING_IDX_SERIAL = 0x03,
STRING_IDX_CONFIG = 0x04,
STRING_IDX_INTERFACE = 0x05,
STRING_IDX_MSFT = 0xee
STRING_IDX_MSFT = 0xee,
STRING_IDX_DEVICE_STATE = 0xfa
};

enum Feature {
Expand Down
18 changes: 18 additions & 0 deletions hal/src/rtl872x/usbd_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <algorithm>
#include "appender.h"
#include "device_code.h"
#include "security_mode.h"

using namespace particle::usbd;

Expand All @@ -49,6 +50,18 @@ char* device_id_as_string(char* buf) {
return buf;
}

char* device_state_as_string(char* buf) {
int mode = security_mode_get(nullptr);

if (mode == MODULE_INFO_SECURITY_MODE_NONE) {
memcpy(buf, security_mode_is_overridden() ? "sm=s" : "sm=o", 4);
} else {
memcpy(buf, "sm=p", 4);
}

return buf;
}

/* MS OS String Descriptor */
const uint8_t MSFT_STR_DESC[] = {
USB_WCID_MS_OS_STRING_DESCRIPTOR(
Expand Down Expand Up @@ -358,6 +371,11 @@ int Device::getString(unsigned id, uint16_t langId, uint8_t* buf, size_t len) {
case STRING_IDX_MSFT: {
return getRawString((const char*)MSFT_STR_DESC, sizeof(MSFT_STR_DESC), buf, len);
}
case STRING_IDX_DEVICE_STATE: {
/* No conversion to UTF-16 */
char deviceStateStr[8] = {0};
return getUnicodeString(device_state_as_string(deviceStateStr), sizeof(deviceStateStr), buf, len);
}
default: {
for (auto& cls: classDrivers_) {
if (cls && cls->isEnabled()) {
Expand Down
3 changes: 2 additions & 1 deletion hal/src/rtl872x/usbd_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ enum StringIndex {
STRING_IDX_SERIAL = 0x03,
STRING_IDX_CONFIG = 0x04,
STRING_IDX_INTERFACE = 0x05,
STRING_IDX_MSFT = 0xee
STRING_IDX_MSFT = 0xee,
STRING_IDX_DEVICE_STATE = 0xfa
};

enum DeviceFeature {
Expand Down