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

Publish last reset event on session resumption #2771

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5b3234e
[proto] update CTRL_REQUEST_GET_PROTECTED_STATE
avtolstoy Jan 29, 2024
c8d8e89
wip
avtolstoy Jan 29, 2024
391ea04
[gen3] [p2] swd/jtag
avtolstoy Jan 30, 2024
7fefce1
minor
avtolstoy Jan 30, 2024
99e7dba
[third_party] nrf5_sdk: update submodule reference
avtolstoy Jan 30, 2024
fed0eb0
fix
avtolstoy Jan 30, 2024
4bf3ad6
minor
avtolstoy Jan 30, 2024
55383c4
[setup] still send proper --serial prompt and then cancel
avtolstoy Jan 30, 2024
af691bf
minor
avtolstoy Jan 30, 2024
e0cf88b
Merge pull request #2734 from particle-iot/feature/protected
avtolstoy Jan 30, 2024
6d47ca6
minor
avtolstoy Jan 30, 2024
8d497c0
minor
avtolstoy Jan 30, 2024
9b7f89f
bump module version to 6.0.0 (6000)
avtolstoy Jan 30, 2024
5addd71
[proto] update CTRL_REQUEST_GET_PROTECTED_STATE
avtolstoy Jan 29, 2024
9bb627b
wip
avtolstoy Jan 29, 2024
7420698
[gen3] [p2] swd/jtag
avtolstoy Jan 30, 2024
77137bd
minor
avtolstoy Jan 30, 2024
abbb4b2
[third_party] nrf5_sdk: update submodule reference
avtolstoy Jan 30, 2024
6d2574f
fix
avtolstoy Jan 30, 2024
bc26c19
minor
avtolstoy Jan 30, 2024
861b327
[setup] still send proper --serial prompt and then cancel
avtolstoy Jan 30, 2024
fe1bd86
minor
avtolstoy Jan 30, 2024
9efff56
Merge branch 'test/6.1.0-merge' into develop-6.x
avtolstoy Apr 29, 2024
e11383d
fix
avtolstoy Apr 29, 2024
ba670d5
fix
avtolstoy Apr 29, 2024
98751bc
merge issues
avtolstoy Apr 29, 2024
a18cb10
minor
avtolstoy Apr 29, 2024
155716f
fix
avtolstoy Apr 30, 2024
16afae7
bump system module version to 6100 (6.1.0)
avtolstoy Apr 29, 2024
9f93184
Publish reset reason when resuming connection
monkbroc May 20, 2024
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
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
## 6.1.0

### FEATURES

- Ledger [#2715](https://github.com/particle-iot/device-os/pull/2715) [#2756](https://github.com/particle-iot/device-os/pull/2756)
- [WiFi] `WiFi.setCredentials()` with credentials validation [#2746](https://github.com/particle-iot/device-os/pull/2746) [#2754](https://github.com/particle-iot/device-os/pull/2754) [#2758](https://github.com/particle-iot/device-os/pull/2758)
- [Gen 4] [rtl872x] [BREAKING CHANGE] Backup RAM is no longer automatically written to flash periodically. Backup RAM will be saved when entering sleep. If users are going to reset, `hal_backup_ram_sync()` should be called first [#2766](https://github.com/particle-iot/device-os/pull/2766)

### ENHANCEMENTS

- [Cellular] Improve BG95 connection speed by only setting `nwscanseq` if needed [#2735](https://github.com/particle-iot/device-os/pull/2735)
- Include IMEI in `CTRL_REQUEST_CELLULAR_GET_ICCID` control request [#2730](https://github.com/particle-iot/device-os/pull/2730)
- Process system tasks while cloud handshake is in progress [#2745](https://github.com/particle-iot/device-os/pull/2745)

### BUGFIXES

- [wiring] Fix incorrect `int` to `bool` conversion in `WiFi.clearCredentials()` [#2736](https://github.com/particle-iot/device-os/pull/2736)
- [Gen 4] [rtl872x] Fix boot loop if system-part module info is corrupted [#2739](https://github.com/particle-iot/device-os/pull/2739)
- [Gen 4] [rtl872x] Fix OTA bounds check, add `ota/min_max_app_size` test [#2742](https://github.com/particle-iot/device-os/pull/2742)
- Fix `std::call_once` re-entrancy problem [#2743](https://github.com/particle-iot/device-os/pull/2743)
- Prevent OTA progress events from blocking system thread [#2741](https://github.com/particle-iot/device-os/pull/2741)
- [Gen 4] [rtl872x] Fix WiFi/BLE coexistence and WiFi/BLE stability issues [#2747](https://github.com/particle-iot/device-os/pull/2747) [#2752](https://github.com/particle-iot/device-os/pull/2752) [#2755](https://github.com/particle-iot/device-os/pull/2755) [#2754](https://github.com/particle-iot/device-os/pull/2754)
- [Gen 4] [rtl872x] Fix USB re-enumeration issues [#2744](https://github.com/particle-iot/device-os/pull/2744) [#2752](https://github.com/particle-iot/device-os/pull/2752) [#2754](https://github.com/particle-iot/device-os/pull/2754)
- [Gen 4] [rtl872x] Fix incorrect timing of SPI TX-only transaction completion notification [#2749](https://github.com/particle-iot/device-os/pull/2749) [#2757](https://github.com/particle-iot/device-os/pull/2757)
- [Gen 4] [rtl872x] Fix an issue with `micros()` and `millis()` occasionally jumping forward after ~37 hours [#2750](https://github.com/particle-iot/device-os/pull/2750)
- [Cellular] [Quectel] Try to force open PPP channel, helps with warm boot PPP session resume in some cases [#2752](https://github.com/particle-iot/device-os/pull/2752)
- [system] Fix sockfd matching in ACM connectivity manager causing a panic [#2755](https://github.com/particle-iot/device-os/pull/2755)
- [Gen 4] [rtl872x] Fix UART initialization issue with non-32-byte-aligned buffers [#2757](https://github.com/particle-iot/device-os/pull/2757)
- [Gen 4] [rtl872x] Reinitialize internal wifi stack if scan or connect fails [#2766](https://github.com/particle-iot/device-os/pull/2766) [#2760](https://github.com/particle-iot/device-os/pull/2760/)
- [Gen 4] [rtl872x] Resolve deadlock with USB serial monitoring on boot in some cases[#2765](https://github.com/particle-iot/device-os/pull/2765)

### INTERNAL

- [Tracker] Disable ESP32 SDIO debug logs [#2740](https://github.com/particle-iot/device-os/pull/2740)
- [GCC] Enable Ledger and filesystem APIs on GCC platform [#2737](https://github.com/particle-iot/device-os/pull/2737)
- Fix monolithic build errors [#2751](https://github.com/particle-iot/device-os/pull/2751)
- [Gen 4] [rtl872x] Upgrade `ambd_sdk` WiFi and BLE subsystems to `6.2_patch_integrated_231211_25b3bc38` [#2752](https://github.com/particle-iot/device-os/pull/2752)
- Update USB/BLE platform names to use hyphenated notation [#2753](https://github.com/particle-iot/device-os/pull/2753)
- [Gen 4] [rtl872x] Prevent M404/BG95M5 modems from connecting on 2G networks for the time being[#2761](https://github.com/particle-iot/device-os/pull/2761)
- [Gen 4] [rtl872x] Query 2G registration status for M404/BG95M5 modems when querying CGMI [#2761](https://github.com/particle-iot/device-os/pull/2761)

## 6.0.0

### FEATURES
Expand Down
1 change: 1 addition & 0 deletions bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#endif // HAL_PLATFORM_LED_THEME

#include "timer_hal.h"
#include "bootloader.h"

extern void DFU_Check_Reset();
extern void HAL_DFU_Process();
Expand Down
3 changes: 3 additions & 0 deletions bootloader/src/nRF52840/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/,pwm
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/,interrupts_hal.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/,dct_hal.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/,nrf_system_error.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/,bootloader.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/,storage_hal.cpp)
CSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/,ota_module_bounds.c)
# FIXME
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/shared/,inflate.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/nRF52840/littlefs/,*.cpp)
Expand Down
44 changes: 42 additions & 2 deletions bootloader/src/nRF52840/usbd_dfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
#include "usbd_dfu.h"
#include <cstring>
#include "hal_irq_flag.h"
#include "security_mode.h"

using namespace particle::usbd;
using namespace particle::usbd::dfu;

constexpr const uint8_t DfuClassDriver::msftExtCompatIdOsDescr_[];
constexpr const uint8_t DfuClassDriver::msftExtPropOsDescr_[];

namespace {

const char PROTECTED_MODE_ERROR[] = "Device is in protected mode";

}

DfuClassDriver::DfuClassDriver(Device* dev)
: dev_(dev) {
dev_->registerClass(this);
Expand Down Expand Up @@ -217,6 +224,11 @@ int DfuClassDriver::handleDfuUpload(SetupRequest* req) {
* - wTransferSize: length of the data buffer sent by the host
* - wBlockNumber: value of the wValue parameter
*/
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
dev_->setupReply(req, transferBuf_, 0);
break;
}
uintptr_t addr = ((req_.wValue - 2) * USBD_DFU_TRANSFER_SIZE) + address_;
auto ret = currentMal()->read(transferBuf_, addr, req_.wLength);
if (ret != detail::OK) {
Expand Down Expand Up @@ -251,6 +263,9 @@ int DfuClassDriver::handleDfuGetStatus(SetupRequest* req) {
* a pending erase request
*/
setState(detail::dfuDNBUSY);
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
}
/* Ask MAL to update bwPollTimeout depending on the current DfuSe command */
currentMal()->getStatus(&status_, dfuseCmd_);
} else {
Expand Down Expand Up @@ -359,18 +374,27 @@ int DfuClassDriver::handleDfuAbort(SetupRequest* req) {
void DfuClassDriver::setState(detail::DfuDeviceState st) {
state_ = st;
status_.bState = state_;
if (state_ != detail::dfuERROR) {
status_.iString = 0;
}
}

void DfuClassDriver::setStatus(detail::DfuDeviceStatus st) {
status_.bStatus = st;
}

void DfuClassDriver::setError(detail::DfuDeviceStatus st, bool stall) {
void DfuClassDriver::setError(detail::DfuDeviceStatus st, bool stall, const char* description) {
setStatus(st);
setState(detail::dfuERROR);
if (stall) {
dev_->setupError(nullptr);
}
if (description) {
status_.iString = (particle::usbd::Device::STRING_IDX_INTERFACE + 1 + USBD_DFU_MAX_CONFIGURATIONS + 1);
strlcpy(errorString_, description, sizeof(errorString_));
} else {
status_.iString = 0;
}
}

DfuMal* DfuClassDriver::currentMal() {
Expand Down Expand Up @@ -444,6 +468,10 @@ int DfuClassDriver::inDone(uint8_t ep, unsigned status) {
}
case detail::DFUSE_COMMAND_ERASE: {
if (req_.wLength == sizeof(uint32_t) + 1) {
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
break;
}
uintptr_t addr = *((uint32_t*)(transferBuf_ + 1));
auto ret = currentMal()->erase(addr, 0);
if (ret != detail::OK) {
Expand Down Expand Up @@ -477,6 +505,10 @@ int DfuClassDriver::inDone(uint8_t ep, unsigned status) {
* - wTransferSize: length of the data buffer sent by the host
* - wBlockNumber: value of the wValue parameter
*/
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
break;
}
uintptr_t addr = ((req_.wValue - 2) * USBD_DFU_TRANSFER_SIZE) + address_;
auto ret = currentMal()->write(transferBuf_, addr, req_.wLength);
if (ret != detail::OK) {
Expand Down Expand Up @@ -510,8 +542,16 @@ const uint8_t* DfuClassDriver::getConfigurationDescriptor(uint16_t* length) {

const uint8_t* DfuClassDriver::getStringDescriptor(unsigned index, uint16_t* length, bool* conv) {
if (index >= (particle::usbd::Device::STRING_IDX_INTERFACE + 1) &&
index <= (particle::usbd::Device::STRING_IDX_INTERFACE + 1 + USBD_DFU_MAX_CONFIGURATIONS)) {
index <= (particle::usbd::Device::STRING_IDX_INTERFACE + 1 + USBD_DFU_MAX_CONFIGURATIONS + 1)) {
const unsigned idx = index - (particle::usbd::Device::STRING_IDX_INTERFACE + 1);
if (idx == (USBD_DFU_MAX_CONFIGURATIONS + 1)) {
*conv = true;
// Error string
if (errorString_) {
*length = strlen(errorString_);
}
return (const uint8_t*)errorString_;
}
auto m = mal_[idx];
if (m) {
*conv = true;
Expand Down
4 changes: 3 additions & 1 deletion bootloader/src/nRF52840/usbd_dfu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "usbd_device.h"

#include "usbd_wcid.h"
#include <climits>

#ifndef USBD_DFU_MAX_CONFIGURATIONS
#define USBD_DFU_MAX_CONFIGURATIONS (3)
Expand Down Expand Up @@ -229,7 +230,7 @@ class DfuClassDriver : public particle::usbd::ClassDriver {
void reset();
void setState(detail::DfuDeviceState st);
void setStatus(detail::DfuDeviceStatus st);
void setError(detail::DfuDeviceStatus st, bool stall = true);
void setError(detail::DfuDeviceStatus st, bool stall = true, const char* description = nullptr);
DfuMal* currentMal();

private:
Expand Down Expand Up @@ -298,6 +299,7 @@ class DfuClassDriver : public particle::usbd::ClassDriver {
#endif
USBD_DFU_FUNCTIONAL_DESCRIPTOR()
};
char errorString_[UCHAR_MAX] = {};
};

} } } /* namespace particle::usbd::dfu */
Expand Down
6 changes: 3 additions & 3 deletions bootloader/src/nRF52840/usbd_dfu_mal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int InternalFlashMal::getStatus(detail::DfuGetStatus* status, dfu::detail::Dfuse
}

const char* InternalFlashMal::getString() {
return INTERNAL_FLASH_IF_STRING;
return security_mode_get(nullptr) != MODULE_INFO_SECURITY_MODE_PROTECTED ? INTERNAL_FLASH_IF_STRING : INTERNAL_FLASH_IF_STRING_PROT;
}

DctMal::DctMal()
Expand Down Expand Up @@ -168,7 +168,7 @@ int DctMal::getStatus(detail::DfuGetStatus* status, dfu::detail::DfuseCommand cm
}

const char* DctMal::getString() {
return DCT_IF_STRING;
return security_mode_get(nullptr) != MODULE_INFO_SECURITY_MODE_PROTECTED ? DCT_IF_STRING : DCT_IF_STRING_PROT;
}

ExternalFlashMal::ExternalFlashMal()
Expand Down Expand Up @@ -241,5 +241,5 @@ int ExternalFlashMal::getStatus(detail::DfuGetStatus* status, dfu::detail::Dfuse
}

const char* ExternalFlashMal::getString() {
return EXTERNAL_FLASH_IF_STRING;
return security_mode_get(nullptr) != MODULE_INFO_SECURITY_MODE_PROTECTED ? EXTERNAL_FLASH_IF_STRING : EXTERNAL_FLASH_IF_STRING_PROT;
}
12 changes: 8 additions & 4 deletions bootloader/src/nRF52840/usbd_dfu_mal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@

#define INTERNAL_FLASH_START_ADD 0x00000000
#define INTERNAL_FLASH_END_ADDR 0x00100000
#define INTERNAL_FLASH_IF_STRING "@Internal Flash /0x00000000/1*004Ka,47*004Kg,192*004Kg,4*004Kg,4*004Kg,8*004Ka";
#define INTERNAL_FLASH_IF_STRING "@Internal Flash /0x00000000/1*004Ka,47*004Kg,192*004Kg,4*004Kg,4*004Kg,8*004Ka"
#define INTERNAL_FLASH_IF_STRING_PROT "@Internal Flash /0x00000000/1*004Kb,47*004Kb,192*004Kb,4*004Kb,4*004Kb,8*004Kb"

#define DCT_START_ADD 0x00000000
#define DCT_END_ADDR 0x00004000
#define DCT_IF_STRING "@DCT Flash /0x00000000/1*016Ke";
#define DCT_IF_STRING "@DCT Flash /0x00000000/1*016Ke"
#define DCT_IF_STRING_PROT "@DCT Flash /0x00000000/1*016Kb"

#define EXTERNAL_FLASH_START_ADD 0x00000000
#if PLATFORM_ID == PLATFORM_B5SOM || PLATFORM_ID == PLATFORM_TRACKER || PLATFORM_ID == PLATFORM_ESOMX
#define EXTERNAL_FLASH_END_ADDR 0x00800000
#define EXTERNAL_FLASH_IF_STRING "@External Flash /0x80000000/2048*004Kg";
#define EXTERNAL_FLASH_IF_STRING "@External Flash /0x80000000/2048*004Kg"
#define EXTERNAL_FLASH_IF_STRING_PROT "@External Flash /0x80000000/2048*004Kb"
#else
#define EXTERNAL_FLASH_END_ADDR 0x00400000
#define EXTERNAL_FLASH_IF_STRING "@External Flash /0x80000000/1024*004Kg";
#define EXTERNAL_FLASH_IF_STRING "@External Flash /0x80000000/1024*004Kg"
#define EXTERNAL_FLASH_IF_STRING_PROT "@External Flash /0x80000000/1024*004Kb"
#endif


Expand Down
4 changes: 4 additions & 0 deletions bootloader/src/rtl872x/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ CSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/littlef
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/shared/,filesystem.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,usbd_device.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,usbd_driver.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,bootloader.cpp)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,storage_hal.cpp)
CSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,ota_module_bounds.c)
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,efuse.cpp)

LDFLAGS += -T$(BOOTLOADER_SRC_PATH)/linker.ld
LINKER_DEPS += $(BOOTLOADER_SRC_PATH)/linker.ld
39 changes: 37 additions & 2 deletions bootloader/src/rtl872x/usbd_dfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@
#include <cstring>
#include "hal_irq_flag.h"
#include <algorithm>
#include "security_mode.h"

using namespace particle::usbd;
using namespace particle::usbd::dfu;

constexpr const uint8_t DfuClassDriver::msftExtCompatIdOsDescr_[];
constexpr const uint8_t DfuClassDriver::msftExtPropOsDescr_[];

namespace {

const char PROTECTED_MODE_ERROR[] = "Device is in protected mode";

}

DfuClassDriver::DfuClassDriver(Device* dev)
: ClassDriver(dev) {
}
Expand Down Expand Up @@ -218,6 +225,11 @@ int DfuClassDriver::handleDfuUpload(SetupRequest* req) {
* - wTransferSize: length of the data buffer sent by the host
* - wBlockNumber: value of the wValue parameter
*/
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
dev_->setupReply(req, transferBuf_, 0);
break;
}
uintptr_t addr = ((req_.wValue - 2) * USBD_DFU_TRANSFER_SIZE) + address_;
auto ret = currentMal()->read(transferBuf_, addr, req_.wLength);
if (ret != detail::OK) {
Expand Down Expand Up @@ -252,6 +264,9 @@ int DfuClassDriver::handleDfuGetStatus(SetupRequest* req) {
* a pending erase request
*/
setState(detail::dfuDNBUSY);
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
}
/* Ask MAL to update bwPollTimeout depending on the current DfuSe command */
currentMal()->getStatus(&status_, dfuseCmd_);
} else {
Expand Down Expand Up @@ -360,18 +375,27 @@ int DfuClassDriver::handleDfuAbort(SetupRequest* req) {
void DfuClassDriver::setState(detail::DfuDeviceState st) {
state_ = st;
status_.bState = state_;
if (state_ != detail::dfuERROR) {
status_.iString = 0;
}
}

void DfuClassDriver::setStatus(detail::DfuDeviceStatus st) {
status_.bStatus = st;
}

void DfuClassDriver::setError(detail::DfuDeviceStatus st, bool stall) {
void DfuClassDriver::setError(detail::DfuDeviceStatus st, bool stall, const char* description) {
setStatus(st);
setState(detail::dfuERROR);
if (stall) {
dev_->setupError(nullptr);
}
if (description) {
status_.iString = stringBase_ + HAL_PLATFORM_USB_DFU_INTERFACES;
strlcpy(errorString_, description, sizeof(errorString_));
} else {
status_.iString = 0;
}
}

DfuMal* DfuClassDriver::currentMal() {
Expand Down Expand Up @@ -429,6 +453,10 @@ int DfuClassDriver::dataIn(unsigned ep, particle::usbd::EndpointEvent ev, size_t
}
case detail::DFUSE_COMMAND_ERASE: {
if (req_.wLength == sizeof(uint32_t) + 1) {
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
break;
}
uintptr_t addr = *((uint32_t*)(transferBuf_ + 1));
auto ret = currentMal()->erase(addr, 0);
if (ret != detail::OK) {
Expand Down Expand Up @@ -462,6 +490,10 @@ int DfuClassDriver::dataIn(unsigned ep, particle::usbd::EndpointEvent ev, size_t
* - wTransferSize: length of the data buffer sent by the host
* - wBlockNumber: value of the wValue parameter
*/
if (security_mode_get(nullptr) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
setError(detail::DfuDeviceStatus::errVENDOR, false /* stall */, PROTECTED_MODE_ERROR);
break;
}
uintptr_t addr = ((req_.wValue - 2) * USBD_DFU_TRANSFER_SIZE) + address_;
auto ret = currentMal()->write(transferBuf_, addr, req_.wLength);
if (ret != detail::OK) {
Expand Down Expand Up @@ -509,6 +541,9 @@ int DfuClassDriver::getString(unsigned id, uint16_t langId, uint8_t* buf, size_t
return -1;
}
const unsigned idx = id - stringBase_;
if (id == status_.iString && status_.iString && state_ == dfu::detail::DfuDeviceState::dfuERROR && strlen(errorString_) ) {
return dev_->getUnicodeString(errorString_, strlen(errorString_), buf, length);
}
if (idx > HAL_PLATFORM_USB_DFU_INTERFACES) {
return -1;
}
Expand All @@ -528,7 +563,7 @@ int DfuClassDriver::getNumInterfaces() const {
}

int DfuClassDriver::getNumStrings() const {
return HAL_PLATFORM_USB_DFU_INTERFACES;
return HAL_PLATFORM_USB_DFU_INTERFACES + 1 /* error string */;
}

unsigned DfuClassDriver::getEndpointMask() const {
Expand Down
Loading