Skip to content

Commit

Permalink
Merge branch 'master' into plauric/add-rvc-tests-to-ci-2
Browse files Browse the repository at this point in the history
  • Loading branch information
plauric committed Aug 14, 2023
2 parents ac0f955 + 3c3e5f5 commit e4f42e4
Show file tree
Hide file tree
Showing 36 changed files with 313 additions and 175 deletions.
1 change: 1 addition & 0 deletions docs/guides/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ example on ESP32 series of SoCs
- [RPC Console and Device Tracing](rpc_console.md)
- [Matter OTA](ota.md)
- [Generating and Using ESP Secure Cert Partition](secure_cert_partition.md)
- [BLE Settings](ble_settings.md)
32 changes: 32 additions & 0 deletions docs/guides/esp32/ble_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Bluetooth Low Energy (BLE)

## Nimble: scan response

The `ConfigureScanResponseData` API is used to configure the scan response data
for advertising in a Bluetooth Low Energy (BLE) application based on the NimBLE
BLE stack. Scan response data is additional data that a BLE peripheral device
can include in its advertising packets to provide more information about itself.
This API allows you to set the scan response data that will be included in the
advertising packets.

### Usage

```
{
uint8_t scanResponse[31]; // 0x05, 0x09, a, b, c, d
scanResponse[0] = 0x05;
scanResponse[1] = 0x09;
scanResponse[2] = 0x61;
scanResponse[3] = 0x62;
scanResponse[4] = 0x63;
scanResponse[5] = 0x64;
chip::ByteSpan data(scanResponse);
CHIP_ERROR err = chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureScanResponseData(data);
if (err != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "Failed to configure scan response, err:%" CHIP_ERROR_FORMAT, err.Format());
}
}
```

Note: Scan response should be configure before `InitServer`.
12 changes: 8 additions & 4 deletions examples/lock-app/silabs/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ class LockManager
typedef void (*Callback_fn_completed)(Action_t);
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);

bool Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err);
bool Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err);
bool Unbolt(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err);
bool Lock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err);
bool Unlock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err);
bool Unbolt(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err);

bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user);
bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier,
Expand Down Expand Up @@ -183,7 +186,8 @@ class LockManager
bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex);
bool IsValidHolidayScheduleIndex(uint8_t scheduleIndex);

bool setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
bool setLockState(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err);
const char * lockStateToString(DlLockState lockState) const;

Expand Down
4 changes: 1 addition & 3 deletions examples/lock-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,9 @@ void AppTask::UpdateClusterState(intptr_t context)
bool unlocked = LockMgr().NextState();
DlLockState newState = unlocked ? DlLockState::kUnlocked : DlLockState::kLocked;

OperationSourceEnum source = OperationSourceEnum::kUnspecified;

// write the new lock value
EmberAfStatus status =
DoorLockServer::Instance().SetLockState(1, newState, source) ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE;
DoorLockServer::Instance().SetLockState(1, newState) ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE;

if (status != EMBER_ZCL_STATUS_SUCCESS)
{
Expand Down
24 changes: 15 additions & 9 deletions examples/lock-app/silabs/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,22 @@ void LockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent)
}
}

bool LockManager::Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err)
bool LockManager::Lock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err)
{
return setLockState(endpointId, DlLockState::kLocked, pin, err);
return setLockState(endpointId, fabricIdx, nodeId, DlLockState::kLocked, pin, err);
}

bool LockManager::Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err)
bool LockManager::Unlock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err)
{
return setLockState(endpointId, DlLockState::kUnlocked, pin, err);
return setLockState(endpointId, fabricIdx, nodeId, DlLockState::kUnlocked, pin, err);
}

bool LockManager::Unbolt(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err)
bool LockManager::Unbolt(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err)
{
return setLockState(endpointId, DlLockState::kUnlocked, pin, err);
return setLockState(endpointId, fabricIdx, nodeId, DlLockState::kUnlocked, pin, err);
}

bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
Expand Down Expand Up @@ -664,7 +667,8 @@ const char * LockManager::lockStateToString(DlLockState lockState) const
return "Unknown";
}

bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err)
{

Expand All @@ -683,7 +687,8 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat
ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState),
endpointId);

DoorLockServer::Instance().SetLockState(endpointId, lockState);
DoorLockServer::Instance().SetLockState(endpointId, lockState, OperationSourceEnum::kRemote, NullNullable, NullNullable,
fabricIdx, nodeId);

return true;
}
Expand All @@ -708,7 +713,8 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat
"Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]",
lockStateToString(lockState), endpointId);

DoorLockServer::Instance().SetLockState(endpointId, lockState);
DoorLockServer::Instance().SetLockState(endpointId, lockState, OperationSourceEnum::kRemote, NullNullable, NullNullable,
fabricIdx, nodeId);

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/lock-app/silabs/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const N
OperationErrorEnum & err)
{
ChipLogProgress(Zcl, "Door Lock App: Lock Command endpoint=%d", endpointId);
bool status = LockMgr().Lock(endpointId, pinCode, err);
bool status = LockMgr().Lock(endpointId, fabricIdx, nodeId, pinCode, err);
if (status == true)
{
LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION);
Expand All @@ -79,7 +79,7 @@ bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const
OperationErrorEnum & err)
{
ChipLogProgress(Zcl, "Door Lock App: Unlock Command endpoint=%d", endpointId);
bool status = LockMgr().Unlock(endpointId, pinCode, err);
bool status = LockMgr().Unlock(endpointId, fabricIdx, nodeId, pinCode, err);
if (status == true)
{
LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::UNLOCK_ACTION);
Expand All @@ -93,7 +93,7 @@ bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const
OperationErrorEnum & err)
{
ChipLogProgress(Zcl, "Door Lock App: Unbolt Command endpoint=%d", endpointId);
bool status = LockMgr().Unlock(endpointId, pinCode, err);
bool status = LockMgr().Unlock(endpointId, fabricIdx, nodeId, pinCode, err);
if (status == true)
{
LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::UNLOCK_ACTION);
Expand Down
47 changes: 29 additions & 18 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,7 @@ CHIP_ERROR BaseApplication::Init()

ConfigurationMgr().LogDeviceConfig();

// Create buffer for QR code that can fit max size and null terminator.
char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1];
chip::MutableCharSpan QRCode(qrCodeBuffer);

if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR)
{
// Print setup info on LCD if available
#ifdef QR_CODE_ENABLED
slLCD.SetQRCode((uint8_t *) QRCode.data(), QRCode.size());
slLCD.ShowQRCode(true, true);
#else
PrintQrCodeURL(QRCode);
#endif // QR_CODE_ENABLED
}
else
{
SILABS_LOG("Getting QR code failed!");
}
OutputQrCode(true /*refreshLCD at init*/);

PlatformMgr().AddEventHandler(OnPlatformEvent, 0);
#ifdef SL_WIFI
Expand Down Expand Up @@ -457,6 +440,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
CancelFunctionTimer();
mFunction = kFunction_NoneSelected;

OutputQrCode(false);
#ifdef QR_CODE_ENABLED
// TOGGLE QRCode/LCD demo UI
slLCD.ToggleQRCode();
Expand Down Expand Up @@ -700,3 +684,30 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
sIsProvisioned = event->ServiceProvisioningChange.IsServiceProvisioned;
}
}

void BaseApplication::OutputQrCode(bool refreshLCD)
{
(void) refreshLCD; // could be unused

// Create buffer for the Qr code setup payload that can fit max size and null terminator.
char setupPayloadBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1];
chip::MutableCharSpan setupPayload(setupPayloadBuffer);

if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(setupPayload) == CHIP_NO_ERROR)
{
// Print setup info on LCD if available
#ifdef QR_CODE_ENABLED
if (refreshLCD)
{
slLCD.SetQRCode((uint8_t *) setupPayload.data(), setupPayload.size());
slLCD.ShowQRCode(true, true);
}
#endif // QR_CODE_ENABLED

PrintQrCodeURL(setupPayload);
}
else
{
SILABS_LOG("Getting QR code failed!");
}
}
9 changes: 9 additions & 0 deletions examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ class BaseApplication
static void ScheduleFactoryReset();

static void OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t);

/**
* @brief Outputs the QRcode payload and URL to the QR code in the logs
* and conditionally on the device LCD.
*
* @param refreshLCD When true, The LCD of the device will be refreshed to show the QR code
*/
static void OutputQrCode(bool refreshLCD);

/**********************************************************
* Protected Attributes declaration
*********************************************************/
Expand Down
4 changes: 4 additions & 0 deletions examples/platform/silabs/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ extern "C" {

#include <stdint.h>

#ifdef SIWX_917
extern uint32_t SystemCoreClock;
#else // For EFR32
#include "RTE_Components.h"
#include CMSIS_device_header

#include "em_assert.h"
#include "em_device.h"
#endif

#if defined(SL_COMPONENT_CATALOG_PRESENT)
#include "sl_component_catalog.h"
Expand Down
7 changes: 4 additions & 3 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using namespace ::chip::DeviceLayer;
#include <crypto/CHIPCryptoPAL.h>
// If building with the EFR32-provided crypto backend, we can use the
// opaque keystore
#if CHIP_CRYPTO_PLATFORM
#if CHIP_CRYPTO_PLATFORM && !(defined(SIWX_917))
#include <platform/silabs/efr32/Efr32PsaOperationalKeystore.h>
static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeystore;
#endif
Expand Down Expand Up @@ -215,7 +215,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
initParams.testEventTriggerDelegate = &testEventTriggerDelegate;
#endif // SILABS_TEST_EVENT_TRIGGER_ENABLED

#if CHIP_CRYPTO_PLATFORM
#if CHIP_CRYPTO_PLATFORM && !(defined(SIWX_917))
// When building with EFR32 crypto, use the opaque key store
// instead of the default (insecure) one.
gOperationalKeystore.Init();
Expand Down Expand Up @@ -255,7 +255,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
}

#ifdef SL_WIFI
void SilabsMatterConfig::InitWiFi(void)
CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
{
#ifdef WF200_WIFI
// Start wfx bus communication task.
Expand All @@ -271,6 +271,7 @@ void SilabsMatterConfig::InitWiFi(void)
return CHIP_ERROR_INTERNAL;
}
#endif /* WF200_WIFI */
return CHIP_NO_ERROR;
}
#endif // SL_WIFI

Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/MatterConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SilabsMatterConfig

private:
static CHIP_ERROR InitOpenThread(void);
static void InitWiFi(void);
static CHIP_ERROR InitWiFi(void);
static void ConnectivityEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
static void InitOTARequestorHandler(chip::System::Layer * systemLayer, void * appState);
};
7 changes: 4 additions & 3 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ config("siwx917-common-config") {
defines += [ "QR_CODE_ENABLED" ]
}

if (chip_enable_ota_requestor) {
defines += [ "SILABS_OTA_ENABLED" ]
}
# TODO: Renable once ota is supported
# if (chip_enable_ota_requestor) {
# defines += [ "SILABS_OTA_ENABLED" ]
# }

if (enable_heap_monitoring) {
defines += [ "HEAP_MONITORING" ]
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/SiWx917/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ARM_USART_SignalEvent(uint32_t event)
case ARM_USART_EVENT_RECEIVE_COMPLETE:
#ifdef ENABLE_CHIP_SHELL
chip::NotifyShellProcessFromISR();
#endif;
#endif
case ARM_USART_EVENT_TRANSFER_COMPLETE:
case ARM_USART_EVENT_TX_COMPLETE:
case ARM_USART_EVENT_TX_UNDERFLOW:
Expand Down
Loading

0 comments on commit e4f42e4

Please sign in to comment.