Skip to content

Commit

Permalink
Merge branch 'master' into ethernet_driver
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinCaldeira-eaton authored Aug 26, 2024
2 parents 49590a8 + a296b66 commit d9de09a
Show file tree
Hide file tree
Showing 65 changed files with 2,105 additions and 2,293 deletions.
2 changes: 1 addition & 1 deletion docs/getting_started/first_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ codes, discriminator and passcode from the logs.

Open a new terminal to use chip tool. Commission the device using:

`./out/linux-x64-chip-tool/chip-tool pairing code 0x12344321 MT:-24J0AFN00KA0648G0`
`./out/linux-x64-chip-tool/chip-tool pairing code 0x12344321 MT:-24J0AFN00KA0648G00`

NOTE: pairing is the old name for commissioning. 0x12344321 is the node ID you
want to assign to the node. 0x12344321 is the default for testing.
Expand Down
4 changes: 2 additions & 2 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseTargetsStore.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/energy-evse-mode.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/ElectricalPowerMeasurementDelegate.cpp",
"${chip_root}/examples/thermostat/linux/thermostat-delegate-impl.cpp",
"${chip_root}/examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp",
"AllClustersCommandDelegate.cpp",
"AllClustersCommandDelegate.h",
"AppOptions.cpp",
Expand All @@ -102,7 +102,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/include",
"${chip_root}/examples/thermostat/linux/include",
"${chip_root}/examples/thermostat/thermostat-common/include",
]

if (chip_enable_pw_rpc) {
Expand Down
67 changes: 58 additions & 9 deletions examples/fabric-bridge-app/linux/CommissionerControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,33 @@ namespace app {
namespace Clusters {
namespace CommissionerControl {

void CommissionerControlDelegate::ResetDelegateState()
{
// Reset the step to the initial state
mNextStep = Step::kIdle;

// Reset identifiers and product information
mRequestId = 0;
mClientNodeId = kUndefinedNodeId;
mVendorId = VendorId::Unspecified;
mProductId = 0;

// Clear the label buffer and optional label
memset(mLabelBuffer, 0, sizeof(mLabelBuffer));
mLabel.ClearValue();

// Reset PBKDF salt and PAKE passcode verifier buffers
mPBKDFSalt = ByteSpan();
memset(mPBKDFSaltBuffer, 0, sizeof(mPBKDFSaltBuffer));

mPAKEPasscodeVerifier = ByteSpan();
memset(mPAKEPasscodeVerifierBuffer, 0, sizeof(mPAKEPasscodeVerifierBuffer));
}

CHIP_ERROR CommissionerControlDelegate::HandleCommissioningApprovalRequest(const CommissioningApprovalRequest & request)
{
VerifyOrReturnError(mNextStep == Step::kIdle, CHIP_ERROR_INCORRECT_STATE);

CommissionerControl::Events::CommissioningRequestResult::Type result;
result.requestId = request.requestId;
result.clientNodeId = request.clientNodeId;
Expand Down Expand Up @@ -86,19 +111,34 @@ CHIP_ERROR CommissionerControlDelegate::HandleCommissioningApprovalRequest(const
mLabel.ClearValue();
}

return CommissionerControlServer::Instance().GenerateCommissioningRequestResultEvent(result);
CHIP_ERROR err = CommissionerControlServer::Instance().GenerateCommissioningRequestResultEvent(result);

if (err == CHIP_NO_ERROR)
{
mNextStep = Step::kWaitCommissionNodeRequest;
}
else
{
ResetDelegateState();
}

return err;
}

CHIP_ERROR CommissionerControlDelegate::ValidateCommissionNodeCommand(NodeId clientNodeId, uint64_t requestId)
{
CHIP_ERROR err = CHIP_NO_ERROR;

VerifyOrReturnError(mNextStep == Step::kWaitCommissionNodeRequest, CHIP_ERROR_INCORRECT_STATE);

// Verify if the CommissionNode command is sent from the same NodeId as the RequestCommissioningApproval.
VerifyOrExit(mClientNodeId == clientNodeId, err = CHIP_ERROR_WRONG_NODE_ID);

// Verify if the provided RequestId matches the value provided to the RequestCommissioningApproval.
VerifyOrExit(mRequestId == requestId, err = CHIP_ERROR_INCORRECT_STATE);

mNextStep = Step::kStartCommissionNode;

exit:
return err;
}
Expand Down Expand Up @@ -129,20 +169,29 @@ CHIP_ERROR CommissionerControlDelegate::GetCommissioningWindowParams(Commissioni
CHIP_ERROR CommissionerControlDelegate::HandleCommissionNode(const CommissioningWindowParams & params,
const Optional<ByteSpan> & ipAddress, const Optional<uint16_t> & port)
{
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogProgress(NotSpecified, "CommissionerControlDelegate::HandleCommissionNode");

VerifyOrReturnError(mNextStep == Step::kStartCommissionNode, CHIP_ERROR_INCORRECT_STATE);

#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
return CommissionNode(Controller::CommissioningWindowPasscodeParams()
.SetSetupPIN(kSetupPinCode)
.SetTimeout(params.commissioningTimeout)
.SetDiscriminator(params.discriminator)
.SetIteration(params.iterations)
.SetSalt(params.salt),
mVendorId, mProductId);
err = CommissionNode(Controller::CommissioningWindowPasscodeParams()
.SetSetupPIN(kSetupPinCode)
.SetTimeout(params.commissioningTimeout)
.SetDiscriminator(params.discriminator)
.SetIteration(params.iterations)
.SetSalt(params.salt),
mVendorId, mProductId);
#else
ChipLogProgress(NotSpecified, "Failed to reverse commission bridge: PW_RPC_FABRIC_BRIDGE_SERVICE not defined");
return CHIP_ERROR_NOT_IMPLEMENTED;
err = CHIP_ERROR_NOT_IMPLEMENTED;
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE

// Reset the delegate's state to prepare for a new commissioning sequence.
ResetDelegateState();

return err;
}

} // namespace CommissionerControl
Expand Down
13 changes: 13 additions & 0 deletions examples/fabric-bridge-app/linux/include/CommissionerControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,21 @@ class CommissionerControlDelegate : public Delegate
~CommissionerControlDelegate() = default;

private:
enum class Step : uint8_t
{
// Ready to start reverse commissioning.
kIdle,
// Wait for the commission node command.
kWaitCommissionNodeRequest,
// Need to commission node.
kStartCommissionNode,
};

void ResetDelegateState();

static constexpr size_t kLabelBufferSize = 64;

Step mNextStep = Step::kIdle;
uint64_t mRequestId = 0;
NodeId mClientNodeId = kUndefinedNodeId;
VendorId mVendorId = VendorId::Unspecified;
Expand Down
3 changes: 3 additions & 0 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
if (BaseApplication::GetProvisionStatus())
{
// After the device is provisioned and the commissioning passed
// resetting the isCommissioningStarted to false
isComissioningStarted = false;
#ifdef DISPLAY_ENABLED
#ifdef QR_CODE_ENABLED
SilabsLCD::Screen_e screen;
Expand Down
5 changes: 4 additions & 1 deletion examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@

class BaseApplicationDelegate : public AppDelegate, public chip::FabricTable::Delegate
{
public:
bool isCommissioningInProgress() { return isComissioningStarted; }

private:
// AppDelegate
bool isComissioningStarted;
bool isComissioningStarted = false;
void OnCommissioningSessionStarted() override;
void OnCommissioningSessionStopped() override;
void OnCommissioningWindowClosed() override;
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ extern uint32_t SystemCoreClock;
#include "RTE_Components.h"
#include CMSIS_device_header

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

#if defined(SL_COMPONENT_CATALOG_PRESENT)
Expand Down
4 changes: 1 addition & 3 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ declare_args() {

# Sanity check
assert(chip_enable_wifi)

silabs_common_plat_dir = "${chip_root}/examples/platform/silabs"
silabs_plat_si91x_wifi_dir = "${chip_root}/src/platform/silabs/SiWx917/wifi"
import("${silabs_common_plat_dir}/args.gni")

Expand Down Expand Up @@ -193,10 +191,10 @@ source_set("siwx917-common") {
"${silabs_common_plat_dir}/SoftwareFaultReports.cpp",
"${silabs_common_plat_dir}/silabs_utils.cpp",
"${silabs_common_plat_dir}/syscalls_stubs.cpp",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
"${silabs_plat_si91x_wifi_dir}/dhcp_client.cpp",
"${silabs_plat_si91x_wifi_dir}/ethernetif.cpp",
"${silabs_plat_si91x_wifi_dir}/lwip_netif.cpp",
"${silabs_plat_si91x_wifi_dir}/wfx_notify.cpp",
"SiWx917/sl_wifi_if.cpp",
"SiWx917/wfx_rsi_host.cpp",
]
Expand Down
22 changes: 4 additions & 18 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ bool hasNotifiedIPV4 = false;
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
bool hasNotifiedWifiConnectivity = false;

/* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
bool is_wifi_disconnection_event = false;

/* Declare a variable to hold connection time intervals */
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;
volatile bool scan_results_complete = false;
volatile bool bg_scan_results_complete = false;
extern osSemaphoreId_t sl_rs_ble_init_sem;
Expand Down Expand Up @@ -247,12 +242,7 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
callback_status = *(sl_status_t *) result;
ChipLogError(DeviceLayer, "join_callback_handler: failed: 0x%lx", static_cast<uint32_t>(callback_status));
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTED);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
{
WfxEvent.eventType = WFX_EVT_STA_START_JOIN;
WfxPostEvent(&WfxEvent);
}
wfx_retry_connection(++wfx_rsi.join_retries);
return SL_STATUS_FAIL;
}
/*
Expand All @@ -264,10 +254,7 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
WfxEvent.eventType = WFX_EVT_STA_CONN;
WfxPostEvent(&WfxEvent);
wfx_rsi.join_retries = 0;
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
// Once the join passes setting the disconnection event to true to differentiate between the first connection and reconnection
is_wifi_disconnection_event = true;
callback_status = SL_STATUS_OK;
callback_status = SL_STATUS_OK;
return SL_STATUS_OK;
}

Expand Down Expand Up @@ -693,12 +680,11 @@ static sl_status_t wfx_rsi_do_join(void)

// failure only happens when the firmware returns an error
ChipLogError(DeviceLayer, "wfx_rsi_do_join: sl_wifi_connect failed: 0x%lx", static_cast<uint32_t>(status));
VerifyOrReturnError((is_wifi_disconnection_event || wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status);
VerifyOrReturnError((wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status);

wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: retry attempt %d", wfx_rsi.join_retries);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
wfx_rsi.join_retries++;
wfx_retry_connection(++wfx_rsi.join_retries);
event.eventType = WFX_EVT_STA_START_JOIN;
WfxPostEvent(&event);
return status;
Expand Down
2 changes: 0 additions & 2 deletions examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ declare_args() {
sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF"
}

silabs_common_plat_dir = "${chip_root}/examples/platform/silabs"

import("${silabs_common_plat_dir}/args.gni")

# Sanity check
Expand Down
3 changes: 3 additions & 0 deletions examples/platform/silabs/efr32/rs911x/hal/efx32_ncp_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
#include "sl_power_manager.h"
#endif

#ifdef SL_BOARD_NAME
#include "sl_board_control.h"
#endif // SL_BOARD_NAME

#include "sl_si91x_ncp_utility.h"
#include "spi_multiplex.h"

Expand Down
19 changes: 5 additions & 14 deletions examples/platform/silabs/efr32/rs911x/hal/efx_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "em_gpio.h"
#include "em_ldma.h"
#include "gpiointerrupt.h"
#include "sl_board_control.h"
#include "sl_device_init_clocks.h"
#include "sl_device_init_hfxo.h"
#include "sl_spidrv_instances.h"
Expand All @@ -47,6 +46,10 @@
#include "wfx_host_events.h"
#include "wfx_rsi.h"

#ifdef SL_BOARD_NAME
#include "sl_board_control.h"
#endif // SL_BOARD_NAME

#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#include "sl_power_manager.h"
#endif
Expand All @@ -65,18 +68,12 @@
#include "sl_mx25_flash_shutdown_usart_config.h"
#endif // SL_MX25CTRL_MUX

#if defined(EFR32MG24)
#include "em_eusart.h"
#include "sl_spidrv_eusart_exp_config.h"
#include "spi_multiplex.h"
#else
#error "Unknown platform"
#endif

#if defined(EFR32MG24)
#define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle
#define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE
#endif

#define CONCAT(A, B) (A##B)
#define SPI_CLOCK(N) CONCAT(cmuClock_USART, N)
Expand Down Expand Up @@ -113,10 +110,8 @@ void sl_wfx_host_gpio_init(void)
// Enable GPIO clock.
CMU_ClockEnable(cmuClock_GPIO, true);

#if defined(EFR32MG24)
// Set CS pin to high/inactive
GPIO_PinModeSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN, gpioModePushPull, PINOUT_SET);
#endif // EFR32MG24

GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, PINOUT_SET);
GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModePushPull, PINOUT_CLEAR);
Expand Down Expand Up @@ -195,9 +190,7 @@ sl_status_t sl_wfx_host_spi_cs_assert(void)
if (!spi_enabled) // Reduce sl_spidrv_init_instances
{
sl_spidrv_init_instances();
#if defined(EFR32MG24)
GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN);
#endif // EFR32MG24
spi_enabled = true;
}
return SL_STATUS_OK;
Expand All @@ -211,11 +204,9 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void)
status = SPIDRV_DeInit(SL_SPIDRV_HANDLE);
if (SL_STATUS_OK == status)
{
#if defined(EFR32MG24)
GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN);
GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR;
#endif // EFR32MG24
spi_enabled = false;
spi_enabled = false;
}
}
#if SL_SPICTRL_MUX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ typedef struct
#elif defined(EFR32MG24_BRD4187C) || defined(BRD4187C)
#include "brd4187c.h"
#else
#error "Need SPI Pins"
#include "sl_custom_board.h"
#warning "Modify sl_custom_board.h configuration file to match your hardware SPIDRV USART peripheral"
#endif /* EFR32MG24_BRD4186C */

#endif /* _RSI_BOARD_CONFIGURATION_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ typedef struct
#elif defined(EFR32MG24_BRD4187C) || defined(BRD4187C)
#include "brd4187c.h"
#else
#error "Need SPI Pins"
#include "sl_custom_board.h"
#warning "Modify sl_custom_board.h configuration file to match your hardware SPIDRV USART peripheral"
#endif
#if EXP_BOARD
#define RESET_PIN PIN(A, 6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#include "spidrv.h"
#include "task.h"

#ifdef SL_BOARD_NAME
#include "sl_board_control.h"
#endif // SL_BOARD_NAME

#include "sl_device_init_clocks.h"
#include "sl_device_init_hfxo.h"
Expand Down Expand Up @@ -242,4 +244,4 @@ sl_status_t sl_wfx_host_spiflash_cs_deassert(void)
GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN);
return SL_STATUS_OK;
}
#endif // SL_MX25CTRL_MUX
#endif // SL_MX25CTRL_MUX
Loading

0 comments on commit d9de09a

Please sign in to comment.