From 4004d0b90cfe35b22b31f73793a9dba9910c21e0 Mon Sep 17 00:00:00 2001 From: zhhyu7 Date: Tue, 26 Mar 2024 21:03:55 +0800 Subject: [PATCH 1/9] [NuttX] Update docker image (#32707) --- integrations/docker/images/base/chip-build/version | 2 +- .../docker/images/stage-2/chip-build-nuttx/Dockerfile | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/integrations/docker/images/base/chip-build/version b/integrations/docker/images/base/chip-build/version index 3e7d598f90dadd..7b465fc96486ad 100644 --- a/integrations/docker/images/base/chip-build/version +++ b/integrations/docker/images/base/chip-build/version @@ -1 +1 @@ -42 : [Ameba] Update Ameba System time +43 : [NuttX] Fix build errors diff --git a/integrations/docker/images/stage-2/chip-build-nuttx/Dockerfile b/integrations/docker/images/stage-2/chip-build-nuttx/Dockerfile index 0912ea49f15477..e5f85857ba82a6 100644 --- a/integrations/docker/images/stage-2/chip-build-nuttx/Dockerfile +++ b/integrations/docker/images/stage-2/chip-build-nuttx/Dockerfile @@ -28,14 +28,16 @@ RUN set -x \ # Download NuttX SDK RUN set -x \ && cd /opt/nuttx \ - && wget -q -O nuttx.zip https://codeload.github.com/apache/nuttx/zip/b8e0423 \ + && rm -rf nuttx \ + && wget -q -O nuttx.zip https://codeload.github.com/apache/nuttx/zip/ce61e866 \ && unzip -q nuttx.zip \ - && mv nuttx-b8e0423 nuttx \ + && mv nuttx-ce61e866 nuttx \ && rm nuttx.zip RUN set -x \ && cd /opt/nuttx \ - && wget -q -O nuttx_app.zip https://codeload.github.com/apache/nuttx-apps/zip/9c48a8d \ + && rm -rf apps \ + && wget -q -O nuttx_app.zip https://codeload.github.com/apache/nuttx-apps/zip/e2805fc9 \ && unzip -q nuttx_app.zip \ - && mv nuttx-apps-9c48a8d apps \ + && mv nuttx-apps-e2805fc9 apps \ && rm nuttx_app.zip From 657fa28e62b258870f3fa700b42d6577c201189f Mon Sep 17 00:00:00 2001 From: Kai Liao <140431279+kliao-csa@users.noreply.github.com> Date: Tue, 26 Mar 2024 07:17:16 -0600 Subject: [PATCH 2/9] Remove some comments from updated spellcheck and move to documentation (#32664) * Update spell.yml * Update index.md * Update index.md * Update index.md * Update .wordlist.txt * Restyled by prettier-markdown * Update index.md * Restyled by prettier-markdown * Update index.md * Update index.md * Update .wordlist.txt * Restyled by prettier-markdown --------- Co-authored-by: Restyled.io --- .github/workflows/spell.yml | 10 ---------- docs/ci-cd/index.md | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/spell.yml b/.github/workflows/spell.yml index 1e8194a9a2075f..84877bf6f8c8bb 100644 --- a/.github/workflows/spell.yml +++ b/.github/workflows/spell.yml @@ -25,16 +25,6 @@ on: - ".github/.wordlist.txt" jobs: -# Seems redundant; removed as pyspelling is customized while this is not -# check-reviewdog: -# name: Check Spelling - reviewdog -# runs-on: ubuntu-latest -# steps: -# - name: Checkout -# uses: actions/checkout@v4 -# - uses: reviewdog/action-misspell@v1 -# with: -# github_token: ${{ secrets.GITHUB_TOKEN }} check-spellcheck: name: Check Spelling - pyspelling runs-on: ubuntu-latest diff --git a/docs/ci-cd/index.md b/docs/ci-cd/index.md index 437120d61f34ca..c2bfc51db6af9e 100644 --- a/docs/ci-cd/index.md +++ b/docs/ci-cd/index.md @@ -35,5 +35,14 @@ Work In Progress ## Tools - [Daily Fail Summary](tools/daily_fail_summary.md) +- Spellcheck + - Uses + [`rojopolis`/spellcheck-github-actions](https://github.com/marketplace/actions/github-spellcheck-action#configuration), + a PySpelling-based spellchecker + - This tool utilizes the definitions in .spellcheck.yml and + .github/`.wordlist.txt` to check all documentation files. + .spellcheck.yml defines the settings while `.wordlist.txt` is a + dictionary of words to skip checking (brand names, technical jargon, + acronyms) ## General Improvement Ideas From 4b26ef4b09f8c9f3033f167af9555ee0a0b2b21d Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:11:06 -0400 Subject: [PATCH 3/9] Migrate our AppTask files to use cmsisos abtraction api rather than freertos (#32690) --- examples/chef/silabs/include/AppTask.h | 3 +-- examples/chef/silabs/src/AppTask.cpp | 8 ++++---- examples/light-switch-app/silabs/include/AppTask.h | 3 +-- examples/light-switch-app/silabs/src/AppTask.cpp | 8 ++++---- examples/lighting-app/silabs/include/AppTask.h | 3 +-- examples/lighting-app/silabs/src/AppTask.cpp | 8 ++++---- examples/lit-icd-app/silabs/include/AppTask.h | 3 +-- examples/lit-icd-app/silabs/src/AppTask.cpp | 8 ++++---- examples/lock-app/silabs/include/AppTask.h | 3 +-- examples/lock-app/silabs/src/AppTask.cpp | 8 ++++---- examples/pump-app/silabs/include/AppTask.h | 3 +-- examples/pump-app/silabs/src/AppTask.cpp | 8 ++++---- examples/smoke-co-alarm-app/silabs/include/AppTask.h | 3 +-- examples/smoke-co-alarm-app/silabs/src/AppTask.cpp | 8 ++++---- examples/thermostat/silabs/include/AppTask.h | 3 +-- examples/thermostat/silabs/src/AppTask.cpp | 8 ++++---- examples/window-app/silabs/include/AppTask.h | 3 +-- examples/window-app/silabs/src/AppTask.cpp | 9 ++++----- 18 files changed, 45 insertions(+), 55 deletions(-) diff --git a/examples/chef/silabs/include/AppTask.h b/examples/chef/silabs/include/AppTask.h index 2aa1b8acaaa847..578d0a17834d29 100644 --- a/examples/chef/silabs/include/AppTask.h +++ b/examples/chef/silabs/include/AppTask.h @@ -28,9 +28,8 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/chef/silabs/src/AppTask.cpp b/examples/chef/silabs/src/AppTask.cpp index 0375f68d542249..aed343e1b3750f 100644 --- a/examples/chef/silabs/src/AppTask.cpp +++ b/examples/chef/silabs/src/AppTask.cpp @@ -81,7 +81,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -94,11 +94,11 @@ void AppTask::AppTaskMain(void * pvParameter) while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, pdMS_TO_TICKS(10)); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/light-switch-app/silabs/include/AppTask.h b/examples/light-switch-app/silabs/include/AppTask.h index 50a04dadf10df5..a6a74b4605f52c 100644 --- a/examples/light-switch-app/silabs/include/AppTask.h +++ b/examples/light-switch-app/silabs/include/AppTask.h @@ -28,9 +28,8 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/light-switch-app/silabs/src/AppTask.cpp b/examples/light-switch-app/silabs/src/AppTask.cpp index c9759d24118fdd..140a99136d6ef3 100644 --- a/examples/light-switch-app/silabs/src/AppTask.cpp +++ b/examples/light-switch-app/silabs/src/AppTask.cpp @@ -105,7 +105,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -121,11 +121,11 @@ void AppTask::AppTaskMain(void * pvParameter) SILABS_LOG("App Task started"); while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/lighting-app/silabs/include/AppTask.h b/examples/lighting-app/silabs/include/AppTask.h index 1f47264349bd51..450d9c61b719b4 100644 --- a/examples/lighting-app/silabs/include/AppTask.h +++ b/examples/lighting-app/silabs/include/AppTask.h @@ -28,10 +28,9 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" #include "LightingManager.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/lighting-app/silabs/src/AppTask.cpp b/examples/lighting-app/silabs/src/AppTask.cpp index 7430bd2828d233..338d6d85e2ef51 100644 --- a/examples/lighting-app/silabs/src/AppTask.cpp +++ b/examples/lighting-app/silabs/src/AppTask.cpp @@ -117,7 +117,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -134,11 +134,11 @@ void AppTask::AppTaskMain(void * pvParameter) while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/lit-icd-app/silabs/include/AppTask.h b/examples/lit-icd-app/silabs/include/AppTask.h index e653f3680defc2..1fc5f2fae5f18c 100644 --- a/examples/lit-icd-app/silabs/include/AppTask.h +++ b/examples/lit-icd-app/silabs/include/AppTask.h @@ -28,9 +28,8 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/lit-icd-app/silabs/src/AppTask.cpp b/examples/lit-icd-app/silabs/src/AppTask.cpp index f960375dab2b16..bb7bf1a77bc17e 100644 --- a/examples/lit-icd-app/silabs/src/AppTask.cpp +++ b/examples/lit-icd-app/silabs/src/AppTask.cpp @@ -94,7 +94,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -110,11 +110,11 @@ void AppTask::AppTaskMain(void * pvParameter) SILABS_LOG("App Task started"); while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/lock-app/silabs/include/AppTask.h b/examples/lock-app/silabs/include/AppTask.h index 01dbee88262543..e1560ac19439b5 100644 --- a/examples/lock-app/silabs/include/AppTask.h +++ b/examples/lock-app/silabs/include/AppTask.h @@ -28,10 +28,9 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" #include "LockManager.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/lock-app/silabs/src/AppTask.cpp b/examples/lock-app/silabs/src/AppTask.cpp index 2510fa7f351c03..6937dbb78e8aa5 100644 --- a/examples/lock-app/silabs/src/AppTask.cpp +++ b/examples/lock-app/silabs/src/AppTask.cpp @@ -210,7 +210,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -230,11 +230,11 @@ void AppTask::AppTaskMain(void * pvParameter) while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/pump-app/silabs/include/AppTask.h b/examples/pump-app/silabs/include/AppTask.h index 84e44d45a4b302..69bf7021bf47dd 100644 --- a/examples/pump-app/silabs/include/AppTask.h +++ b/examples/pump-app/silabs/include/AppTask.h @@ -28,10 +28,9 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" #include "PumpManager.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/pump-app/silabs/src/AppTask.cpp b/examples/pump-app/silabs/src/AppTask.cpp index 365c53fc7a33ac..1b4881ff77db51 100644 --- a/examples/pump-app/silabs/src/AppTask.cpp +++ b/examples/pump-app/silabs/src/AppTask.cpp @@ -125,7 +125,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -142,11 +142,11 @@ void AppTask::AppTaskMain(void * pvParameter) while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/smoke-co-alarm-app/silabs/include/AppTask.h b/examples/smoke-co-alarm-app/silabs/include/AppTask.h index b91ef5e1335a28..9e68505d341a36 100644 --- a/examples/smoke-co-alarm-app/silabs/include/AppTask.h +++ b/examples/smoke-co-alarm-app/silabs/include/AppTask.h @@ -26,10 +26,9 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" #include "SmokeCoAlarmManager.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp b/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp index 0ead0862709abd..9db4af7c127902 100644 --- a/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp +++ b/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp @@ -112,7 +112,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -129,11 +129,11 @@ void AppTask::AppTaskMain(void * pvParameter) while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/thermostat/silabs/include/AppTask.h b/examples/thermostat/silabs/include/AppTask.h index 695b7d5b8ed751..25177b9ab43808 100644 --- a/examples/thermostat/silabs/include/AppTask.h +++ b/examples/thermostat/silabs/include/AppTask.h @@ -32,11 +32,10 @@ #include "AppEvent.h" #include "BaseApplication.h" -#include "FreeRTOS.h" #include "SensorManager.h" #include "TemperatureManager.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/thermostat/silabs/src/AppTask.cpp b/examples/thermostat/silabs/src/AppTask.cpp index b58ad0a288a99e..e033a3fe2b9144 100644 --- a/examples/thermostat/silabs/src/AppTask.cpp +++ b/examples/thermostat/silabs/src/AppTask.cpp @@ -113,7 +113,7 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -129,11 +129,11 @@ void AppTask::AppTaskMain(void * pvParameter) SILABS_LOG("App Task started"); while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } diff --git a/examples/window-app/silabs/include/AppTask.h b/examples/window-app/silabs/include/AppTask.h index bd05d30f85acd1..268e5eea415a06 100644 --- a/examples/window-app/silabs/include/AppTask.h +++ b/examples/window-app/silabs/include/AppTask.h @@ -27,9 +27,8 @@ #include #include "BaseApplication.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include #include diff --git a/examples/window-app/silabs/src/AppTask.cpp b/examples/window-app/silabs/src/AppTask.cpp index e8b5cc332bfc2f..f255beda6851b6 100644 --- a/examples/window-app/silabs/src/AppTask.cpp +++ b/examples/window-app/silabs/src/AppTask.cpp @@ -80,9 +80,8 @@ CHIP_ERROR AppTask::StartAppTask() void AppTask::AppTaskMain(void * pvParameter) { - AppEvent event; - QueueHandle_t sAppEventQueue = *(static_cast(pvParameter)); + osMessageQueueId_t sAppEventQueue = *(static_cast(pvParameter)); CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) @@ -102,11 +101,11 @@ void AppTask::AppTaskMain(void * pvParameter) while (true) { - BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); - while (eventReceived == pdTRUE) + osStatus_t eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, osWaitForever); + while (eventReceived == osOK) { sAppTask.DispatchEvent(&event); - eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + eventReceived = osMessageQueueGet(sAppEventQueue, &event, NULL, 0); } } } From aa9f8e5205ba13fa5ad7633c42301ad81caa6398 Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:11:21 -0400 Subject: [PATCH 4/9] Migrate our Manager from freeRTOS api to CMSIS OS2 Api (#32705) --- .../chef/silabs/include/LightingManager.h | 7 ++- examples/chef/silabs/src/LightingManager.cpp | 47 +++++++------------ .../silabs/include/LightingManager.h | 7 ++- .../silabs/src/LightingManager.cpp | 45 +++++++----------- .../lock-app/silabs/include/LockManager.h | 7 ++- examples/lock-app/silabs/src/LockManager.cpp | 44 +++++++---------- examples/platform/silabs/BaseApplication.cpp | 8 ++-- examples/platform/silabs/BaseApplication.h | 8 ++-- .../pump-app/silabs/include/PumpManager.h | 8 ++-- examples/pump-app/silabs/src/PumpManager.cpp | 12 ++--- .../silabs/include/SmokeCoAlarmManager.h | 7 ++- .../silabs/src/SmokeCoAlarmManager.cpp | 42 ++++++----------- .../thermostat/silabs/include/SensorManager.h | 7 +-- .../thermostat/silabs/src/SensorManager.cpp | 21 +++------ .../window-app/silabs/include/AppConfig.h | 2 +- .../window-app/silabs/include/WindowManager.h | 8 ++-- .../window-app/silabs/src/WindowManager.cpp | 26 +++++----- 17 files changed, 119 insertions(+), 187 deletions(-) diff --git a/examples/chef/silabs/include/LightingManager.h b/examples/chef/silabs/include/LightingManager.h index 3aa9871e919074..6fe2b10813eb34 100644 --- a/examples/chef/silabs/include/LightingManager.h +++ b/examples/chef/silabs/include/LightingManager.h @@ -23,9 +23,7 @@ #include "AppEvent.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support - +#include #include class LightingManager @@ -68,11 +66,12 @@ class LightingManager bool mAutoTurnOff; uint32_t mAutoTurnOffDuration; bool mAutoTurnOffTimerArmed; + osTimerId_t mLightTimer; void CancelTimer(void); void StartTimer(uint32_t aTimeoutMs); - static void TimerEventHandler(TimerHandle_t xTimer); + static void TimerEventHandler(void * timerCbArg); static void AutoTurnOffTimerEventHandler(AppEvent * aEvent); static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); diff --git a/examples/chef/silabs/src/LightingManager.cpp b/examples/chef/silabs/src/LightingManager.cpp index d6684bfa14ff2b..1856f84373db8d 100644 --- a/examples/chef/silabs/src/LightingManager.cpp +++ b/examples/chef/silabs/src/LightingManager.cpp @@ -21,25 +21,20 @@ #include "AppConfig.h" #include "AppTask.h" -#include LightingManager LightingManager::sLight; -TimerHandle_t sLightTimer; - CHIP_ERROR LightingManager::Init() { - // Create FreeRTOS sw timer for light timer. - sLightTimer = xTimerCreate("lightTmr", // Just a text name, not used by the RTOS kernel - 1, // == default timer period (mS) - false, // no timer reload (==one-shot) - (void *) this, // init timer id = light obj context - TimerEventHandler // timer callback handler - ); - - if (sLightTimer == NULL) + // Create cmsis os sw timer for light timer. + mLightTimer = osTimerNew(TimerEventHandler, // timer callback handler + osTimerOnce, // no timer reload (one-shot timer) + (void *) this, // pass the app task obj context + NULL // No osTimerAttr_t to provide. + + if (mLightTimer == NULL) { - SILABS_LOG("sLightTimer timer create failed"); + SILABS_LOG("mLightTimer timer create failed"); return APP_ERROR_CREATE_TIMER_FAILED; } @@ -123,38 +118,30 @@ bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction) void LightingManager::StartTimer(uint32_t aTimeoutMs) { - if (xTimerIsTimerActive(sLightTimer)) - { - SILABS_LOG("app timer already started!"); - CancelTimer(); - } - - // timer is not active, change its period to required value (== restart). - // FreeRTOS- Block for a maximum of 100 ticks if the change period command - // cannot immediately be sent to the timer command queue. - if (xTimerChangePeriod(sLightTimer, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS) + // Starts or restarts the function timer + if (osTimerStart(mLightTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK) { - SILABS_LOG("sLightTimer timer start() failed"); + SILABS_LOG("mLightTimer timer start() failed"); appError(APP_ERROR_START_TIMER_FAILED); } } void LightingManager::CancelTimer(void) { - if (xTimerStop(sLightTimer, 0) == pdFAIL) + if (osTimerStop(mLightTimer) == osError) { - SILABS_LOG("sLightTimer stop() failed"); + SILABS_LOG("mLightTimer stop() failed"); appError(APP_ERROR_STOP_TIMER_FAILED); } } -void LightingManager::TimerEventHandler(TimerHandle_t xTimer) +void LightingManager::TimerEventHandler(void * timerCbArg) { - // Get light obj context from timer id. - LightingManager * light = static_cast(pvTimerGetTimerID(xTimer)); + // The callback argument is the light obj context assigned at timer creation. + LightingManager * light = static_cast(timerCbArg); // The timer event handler will be called in the context of the timer task - // once sLightTimer expires. Post an event to apptask queue with the actual handler + // once mLightTimer expires. Post an event to apptask queue with the actual handler // so that the event can be handled in the context of the apptask. AppEvent event; event.Type = AppEvent::kEventType_Timer; diff --git a/examples/lighting-app/silabs/include/LightingManager.h b/examples/lighting-app/silabs/include/LightingManager.h index 6d286faa30ef96..00a1448001f900 100644 --- a/examples/lighting-app/silabs/include/LightingManager.h +++ b/examples/lighting-app/silabs/include/LightingManager.h @@ -23,10 +23,8 @@ #include "AppEvent.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support #include - +#include #include class LightingManager @@ -72,11 +70,12 @@ class LightingManager uint32_t mAutoTurnOffDuration; bool mAutoTurnOffTimerArmed; bool mOffEffectArmed; + osTimerId_t mLightTimer; void CancelTimer(void); void StartTimer(uint32_t aTimeoutMs); - static void TimerEventHandler(TimerHandle_t xTimer); + static void TimerEventHandler(void * timerCbArg); static void AutoTurnOffTimerEventHandler(AppEvent * aEvent); static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); static void OffEffectTimerEventHandler(AppEvent * aEvent); diff --git a/examples/lighting-app/silabs/src/LightingManager.cpp b/examples/lighting-app/silabs/src/LightingManager.cpp index 769dc0071166d7..d839c52f0d9894 100644 --- a/examples/lighting-app/silabs/src/LightingManager.cpp +++ b/examples/lighting-app/silabs/src/LightingManager.cpp @@ -21,7 +21,6 @@ #include "AppConfig.h" #include "AppTask.h" -#include #include @@ -30,9 +29,6 @@ using namespace ::chip::app::Clusters::OnOff; using namespace ::chip::DeviceLayer; LightingManager LightingManager::sLight; - -TimerHandle_t sLightTimer; - namespace { /********************************************************** @@ -50,17 +46,16 @@ OnOffEffect gEffect = { CHIP_ERROR LightingManager::Init() { - // Create FreeRTOS sw timer for light timer. - sLightTimer = xTimerCreate("lightTmr", // Just a text name, not used by the RTOS kernel - pdMS_TO_TICKS(1), // == default timer period - false, // no timer reload (==one-shot) - (void *) this, // init timer id = light obj context - TimerEventHandler // timer callback handler + // Create cmsis os sw timer for light timer. + mLightTimer = osTimerNew(TimerEventHandler, // timer callback handler + osTimerOnce, // no timer reload (one-shot timer) + (void *) this, // pass the app task obj context + NULL // No osTimerAttr_t to provide. ); - if (sLightTimer == NULL) + if (mLightTimer == NULL) { - SILABS_LOG("sLightTimer timer create failed"); + SILABS_LOG("mLightTimer timer create failed"); return APP_ERROR_CREATE_TIMER_FAILED; } @@ -157,38 +152,30 @@ bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction) void LightingManager::StartTimer(uint32_t aTimeoutMs) { - if (xTimerIsTimerActive(sLightTimer)) - { - SILABS_LOG("app timer already started!"); - CancelTimer(); - } - - // timer is not active, change its period to required value (== restart). - // FreeRTOS- Block for a maximum of 100 ms if the change period command - // cannot immediately be sent to the timer command queue. - if (xTimerChangePeriod(sLightTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS) + // Starts or restarts the function timer + if (osTimerStart(mLightTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK) { - SILABS_LOG("sLightTimer timer start() failed"); + SILABS_LOG("mLightTimer timer start() failed"); appError(APP_ERROR_START_TIMER_FAILED); } } void LightingManager::CancelTimer(void) { - if (xTimerStop(sLightTimer, pdMS_TO_TICKS(0)) == pdFAIL) + if (osTimerStop(mLightTimer) == osError) { - SILABS_LOG("sLightTimer stop() failed"); + SILABS_LOG("mLightTimer stop() failed"); appError(APP_ERROR_STOP_TIMER_FAILED); } } -void LightingManager::TimerEventHandler(TimerHandle_t xTimer) +void LightingManager::TimerEventHandler(void * timerCbArg) { - // Get light obj context from timer id. - LightingManager * light = static_cast(pvTimerGetTimerID(xTimer)); + // The callback argument is the light obj context assigned at timer creation. + LightingManager * light = static_cast(timerCbArg); // The timer event handler will be called in the context of the timer task - // once sLightTimer expires. Post an event to apptask queue with the actual handler + // once mLightTimer expires. Post an event to apptask queue with the actual handler // so that the event can be handled in the context of the apptask. AppEvent event; event.Type = AppEvent::kEventType_Timer; diff --git a/examples/lock-app/silabs/include/LockManager.h b/examples/lock-app/silabs/include/LockManager.h index 9adcc863f0aec7..fb73d1d1218d23 100644 --- a/examples/lock-app/silabs/include/LockManager.h +++ b/examples/lock-app/silabs/include/LockManager.h @@ -24,9 +24,7 @@ #include "AppEvent.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support - +#include #include struct WeekDaysScheduleInfo @@ -203,10 +201,11 @@ class LockManager void CancelTimer(void); void StartTimer(uint32_t aTimeoutMs); - static void TimerEventHandler(TimerHandle_t xTimer); + static void TimerEventHandler(void * timerCbArg); static void AutoLockTimerEventHandler(AppEvent * aEvent); static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); + osTimerId_t mLockTimer; EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers]; EmberAfPluginDoorLockCredentialInfo mLockCredentials[kNumCredentialTypes][kMaxCredentials]; WeekDaysScheduleInfo mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser]; diff --git a/examples/lock-app/silabs/src/LockManager.cpp b/examples/lock-app/silabs/src/LockManager.cpp index 8190dbddd6141e..3c376a237ad81f 100644 --- a/examples/lock-app/silabs/src/LockManager.cpp +++ b/examples/lock-app/silabs/src/LockManager.cpp @@ -21,15 +21,12 @@ #include "AppConfig.h" #include "AppTask.h" -#include #include #include #include LockManager LockManager::sLock; -TimerHandle_t sLockTimer; - using namespace ::chip::DeviceLayer::Internal; using namespace EFR32DoorLock::LockInitParams; @@ -77,17 +74,16 @@ CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable(pvTimerGetTimerID(xTimer)); + // The callback argument is the light obj context assigned at timer creation. + LockManager * lock = static_cast(timerCbArg); // The timer event handler will be called in the context of the timer task - // once sLockTimer expires. Post an event to apptask queue with the actual handler + // once mLockTimer expires. Post an event to apptask queue with the actual handler // so that the event can be handled in the context of the apptask. AppEvent event; event.Type = AppEvent::kEventType_Timer; diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index 391104785b35c8..d8df720686ca4b 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -79,7 +79,9 @@ #define APP_TASK_STACK_SIZE (4096) #endif #define APP_TASK_PRIORITY 2 +#ifndef APP_EVENT_QUEUE_SIZE // Allow apps to define a different app queue size #define APP_EVENT_QUEUE_SIZE 10 +#endif #define EXAMPLE_VENDOR_ID 0xcafe #if (defined(ENABLE_WSTK_LEDS) && (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT))) @@ -298,11 +300,11 @@ CHIP_ERROR BaseApplication::Init() return err; } -void BaseApplication::FunctionTimerEventHandler(osTimerId_t xTimer) +void BaseApplication::FunctionTimerEventHandler(void * timerCbArg) { AppEvent event; event.Type = AppEvent::kEventType_Timer; - event.TimerEvent.Context = (void *) xTimer; + event.TimerEvent.Context = timerCbArg; event.Handler = FunctionEventHandler; PostEvent(&event); } @@ -677,7 +679,7 @@ void BaseApplication::OnTriggerIdentifyEffect(Identify * identify) } #endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER -void BaseApplication::LightTimerEventHandler(osTimerId_t xTimer) +void BaseApplication::LightTimerEventHandler(void * timerCbArg) { LightEventHandler(); } diff --git a/examples/platform/silabs/BaseApplication.h b/examples/platform/silabs/BaseApplication.h index ffb1f24cae2b81..e9ca6bfc950834 100644 --- a/examples/platform/silabs/BaseApplication.h +++ b/examples/platform/silabs/BaseApplication.h @@ -182,9 +182,9 @@ class BaseApplication * @brief Function Timer finished callback function * Post an FunctionEventHandler event * - * @param xTimer timer that finished + * @param timerCbArg argument to the timer callback function assigned at timer creation */ - static void FunctionTimerEventHandler(osTimerId_t xTimer); + static void FunctionTimerEventHandler(void * timerCbArg); /** * @brief Timer Event processing function @@ -207,9 +207,9 @@ class BaseApplication * @brief Light Timer finished callback function * Calls LED processing function * - * @param xTimer timer that finished + * @param timerCbArg argument to the timer callback function assigned at timer creation */ - static void LightTimerEventHandler(osTimerId_t xTimer); + static void LightTimerEventHandler(void * timerCbArg); /** * @brief Updates device LEDs diff --git a/examples/pump-app/silabs/include/PumpManager.h b/examples/pump-app/silabs/include/PumpManager.h index 9a0455dcadc26e..f66a029e5a005f 100644 --- a/examples/pump-app/silabs/include/PumpManager.h +++ b/examples/pump-app/silabs/include/PumpManager.h @@ -23,11 +23,9 @@ #include "AppEvent.h" +#include #include -#include -#include - #define PCC_CLUSTER_ENDPOINT 1 class PumpManager @@ -66,13 +64,13 @@ class PumpManager Callback_fn_initiated mActionInitiated_CB; Callback_fn_completed mActionCompleted_CB; - TimerHandle_t mTimerHandle; + osTimerId_t mTimerHandle; int32_t mCurrentActor; void CancelTimer(void); void PumpTimer(uint32_t aTimeoutMs); - static void TimerEventHandler(TimerHandle_t aTimer); + static void TimerEventHandler(void * timerCbArg); static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); static PumpManager sPump; diff --git a/examples/pump-app/silabs/src/PumpManager.cpp b/examples/pump-app/silabs/src/PumpManager.cpp index 25ef55aeaea3e3..9f404ffaf3c571 100644 --- a/examples/pump-app/silabs/src/PumpManager.cpp +++ b/examples/pump-app/silabs/src/PumpManager.cpp @@ -21,7 +21,6 @@ #include "AppConfig.h" #include "AppTask.h" -#include "FreeRTOS.h" #define ACTUATOR_MOVEMENT_PERIOS_MS 500 @@ -31,7 +30,7 @@ CHIP_ERROR PumpManager::Init() { CHIP_ERROR ret = CHIP_NO_ERROR; - mTimerHandle = xTimerCreate("PumpTmr", pdMS_TO_TICKS(ACTUATOR_MOVEMENT_PERIOS_MS), pdFALSE, this, TimerEventHandler); + mTimerHandle = osTimerNew(TimerEventHandler, osTimerOnce, this, NULL); if (NULL == mTimerHandle) { return CHIP_ERROR_INTERNAL; @@ -95,18 +94,17 @@ bool PumpManager::InitiateAction(int32_t aActor, Action_t aAction) void PumpManager::PumpTimer(uint32_t aTimeoutMs) { - xTimerChangePeriod(mTimerHandle, pdMS_TO_TICKS(aTimeoutMs), 100); - xTimerStart(mTimerHandle, 100); + osTimerStart(mTimerHandle, pdMS_TO_TICKS(aTimeoutMs)); } void PumpManager::CancelTimer(void) { - xTimerStop(mTimerHandle, 100); + osTimerStop(mTimerHandle); } -void PumpManager::TimerEventHandler(TimerHandle_t aTimer) +void PumpManager::TimerEventHandler(void * timerCbArg) { - PumpManager * pump = static_cast(pvTimerGetTimerID(aTimer)); + PumpManager * pump = static_cast(timerCbArg); // The timer event handler will be called in the context of the timer task // once sPumpTimer expires. Post an event to apptask queue with the actual handler diff --git a/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h b/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h index b44bbf102be8b4..423ca1ca7a364f 100644 --- a/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h +++ b/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h @@ -22,10 +22,8 @@ #include "AppEvent.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support #include - +#include #include class SmokeCoAlarmManager @@ -43,11 +41,12 @@ class SmokeCoAlarmManager friend SmokeCoAlarmManager & AlarmMgr(void); bool mEndSelfTesting; + osTimerId_t mAlarmTimer; void CancelTimer(void); void StartTimer(uint32_t aTimeoutMs); - static void TimerEventHandler(TimerHandle_t xTimer); + static void TimerEventHandler(void * timerCbArg); static void EndSelfTestingEventHandler(AppEvent * aEvent); static SmokeCoAlarmManager sAlarm; diff --git a/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp b/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp index 7d64a036371a6f..66eef8a6f188cf 100644 --- a/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp +++ b/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp @@ -19,7 +19,6 @@ #include "AppConfig.h" #include "AppTask.h" -#include #include #include @@ -30,8 +29,6 @@ using namespace chip::DeviceLayer; SmokeCoAlarmManager SmokeCoAlarmManager::sAlarm; -TimerHandle_t sAlarmTimer; - static std::array sPriorityOrder = { ExpressedStateEnum::kSmokeAlarm, ExpressedStateEnum::kInterconnectSmoke, ExpressedStateEnum::kCOAlarm, ExpressedStateEnum::kInterconnectCO, ExpressedStateEnum::kHardwareFault, ExpressedStateEnum::kTesting, @@ -40,17 +37,16 @@ static std::array CHIP_ERROR SmokeCoAlarmManager::Init() { - // Create FreeRTOS sw timer for alarm timer. - sAlarmTimer = xTimerCreate("alarmTmr", // Just a text name, not used by the RTOS kernel - pdMS_TO_TICKS(1), // == default timer period - false, // no timer reload (==one-shot) - (void *) this, // init timer id = alarm obj context - TimerEventHandler // timer callback handler + // Create cmsisos sw timer for alarm timer. + mAlarmTimer = osTimerNew(TimerEventHandler, // timer callback handler + osTimerOnce, // no timer reload (one-shot timer) + this, // pass the app task obj context + NULL // No osTimerAttr_t to provide. ); - if (sAlarmTimer == NULL) + if (mAlarmTimer == NULL) { - SILABS_LOG("sAlarmTimer timer create failed"); + SILABS_LOG("mAlarmTimer timer create failed"); return APP_ERROR_CREATE_TIMER_FAILED; } @@ -66,38 +62,30 @@ CHIP_ERROR SmokeCoAlarmManager::Init() void SmokeCoAlarmManager::StartTimer(uint32_t aTimeoutMs) { - if (xTimerIsTimerActive(sAlarmTimer)) - { - SILABS_LOG("app timer already started!"); - CancelTimer(); - } - - // timer is not active, change its period to required value (== restart). - // FreeRTOS- Block for a maximum of 100 ms if the change period command - // cannot immediately be sent to the timer command queue. - if (xTimerChangePeriod(sAlarmTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS) + // Starts or restarts the function timer + if (osTimerStart(mAlarmTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK) { - SILABS_LOG("sAlarmTimer timer start() failed"); + SILABS_LOG("mAlarmTimer timer start() failed"); appError(APP_ERROR_START_TIMER_FAILED); } } void SmokeCoAlarmManager::CancelTimer(void) { - if (xTimerStop(sAlarmTimer, pdMS_TO_TICKS(0)) == pdFAIL) + if (osTimerStop(mAlarmTimer) == osError) { - SILABS_LOG("sAlarmTimer stop() failed"); + SILABS_LOG("mAlarmTimer stop() failed"); appError(APP_ERROR_STOP_TIMER_FAILED); } } -void SmokeCoAlarmManager::TimerEventHandler(TimerHandle_t xTimer) +void SmokeCoAlarmManager::TimerEventHandler(void * timerCbArg) { // Get alarm obj context from timer id. - SmokeCoAlarmManager * alarm = static_cast(pvTimerGetTimerID(xTimer)); + SmokeCoAlarmManager * alarm = static_cast(timerCbArg); // The timer event handler will be called in the context of the timer task - // once sAlarmTimer expires. Post an event to apptask queue with the actual handler + // once mAlarmTimer expires. Post an event to apptask queue with the actual handler // so that the event can be handled in the context of the apptask. AppEvent event; event.Type = AppEvent::kEventType_Timer; diff --git a/examples/thermostat/silabs/include/SensorManager.h b/examples/thermostat/silabs/include/SensorManager.h index 9c910abb35881e..03b916de699d2b 100644 --- a/examples/thermostat/silabs/include/SensorManager.h +++ b/examples/thermostat/silabs/include/SensorManager.h @@ -23,9 +23,8 @@ #include "AppEvent.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support #include +#include #include class SensorManager @@ -36,8 +35,10 @@ class SensorManager private: friend SensorManager & SensorMgr(); + osTimerId_t mSensorTimer; + // Reads new generated sensor value, stores it, and updates local temperature attribute - static void SensorTimerEventHandler(TimerHandle_t xTimer); + static void SensorTimerEventHandler(void * arg); static SensorManager sSensorManager; }; diff --git a/examples/thermostat/silabs/src/SensorManager.cpp b/examples/thermostat/silabs/src/SensorManager.cpp index 2d2246a44d20eb..abecd899d5370f 100644 --- a/examples/thermostat/silabs/src/SensorManager.cpp +++ b/examples/thermostat/silabs/src/SensorManager.cpp @@ -43,10 +43,6 @@ constexpr uint16_t kMinTemperatureDelta = 50; // 0.5 degree Celcius /********************************************************** * Variable declarations *********************************************************/ - -TimerHandle_t sSensorTimer; -StaticTimer_t sStaticSensorTimerStruct; - SensorManager SensorManager::sSensorManager; #ifndef USE_TEMP_SENSOR @@ -56,13 +52,12 @@ static int16_t mSimulatedTemp[] = { 2300, 2400, 2800, 2550, 2200, CHIP_ERROR SensorManager::Init() { - // Create FreeRTOS sw timer for temp sensor timer. - sSensorTimer = xTimerCreateStatic("sensorTmr", pdMS_TO_TICKS(kSensorTImerPeriodMs), true, nullptr, SensorTimerEventHandler, - &sStaticSensorTimerStruct); + // Create cmsisos sw timer for temp sensor timer. + mSensorTimer = osTimerNew(SensorTimerEventHandler, osTimerPeriodic, nullptr, nullptr); - if (sSensorTimer == NULL) + if (mSensorTimer == NULL) { - SILABS_LOG("sSensorTimer timer create failed"); + SILABS_LOG("mSensorTimer timer create failed"); return APP_ERROR_CREATE_TIMER_FAILED; } @@ -75,15 +70,13 @@ CHIP_ERROR SensorManager::Init() #endif // Update Temp immediatly at bootup - SensorTimerEventHandler(sSensorTimer); - + SensorTimerEventHandler(nullptr); // Trigger periodic update - xTimerStart(sSensorTimer, portMAX_DELAY); - + osTimerStart(mSensorTimer, pdMS_TO_TICKS(kSensorTImerPeriodMs)); return CHIP_NO_ERROR; } -void SensorManager::SensorTimerEventHandler(TimerHandle_t xTimer) +void SensorManager::SensorTimerEventHandler(void * arg) { int16_t temperature = 0; static int16_t lastTemperature = 0; diff --git a/examples/window-app/silabs/include/AppConfig.h b/examples/window-app/silabs/include/AppConfig.h index fce020a6dacb7b..578861f25987a3 100644 --- a/examples/window-app/silabs/include/AppConfig.h +++ b/examples/window-app/silabs/include/AppConfig.h @@ -23,7 +23,7 @@ // ---- Window Example App Config ---- #define APP_TASK_NAME "APP" - +#define APP_EVENT_QUEUE_SIZE 20 #define BLE_DEV_NAME "SiLabs-Window" #define LCD_SIZE 128 diff --git a/examples/window-app/silabs/include/WindowManager.h b/examples/window-app/silabs/include/WindowManager.h index bed448d5895c61..9faf6694238319 100644 --- a/examples/window-app/silabs/include/WindowManager.h +++ b/examples/window-app/silabs/include/WindowManager.h @@ -23,10 +23,8 @@ #include "AppEvent.h" #include "LEDWidget.h" -#include +#include #include -#include -#include #ifdef DISPLAY_ENABLED #include #endif @@ -51,10 +49,10 @@ class WindowManager void * mContext = nullptr; bool mIsActive = false; - TimerHandle_t mHandler = nullptr; + osTimerId_t mHandler = nullptr; private: - static void TimerCallback(TimerHandle_t xTimer); + static void TimerCallback(void * timerCbArg); }; struct Cover diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp index 58716b82af4a52..197836f486a112 100644 --- a/examples/window-app/silabs/src/WindowManager.cpp +++ b/examples/window-app/silabs/src/WindowManager.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -78,13 +79,8 @@ AppEvent CreateNewEvent(AppEvent::AppEventTypes type) void WindowManager::Timer::Start() { - if (xTimerIsTimerActive(mHandler)) - { - Stop(); - } - - // Timer is not active - if (xTimerStart(mHandler, pdMS_TO_TICKS(100)) != pdPASS) + // Starts or restarts the function timer + if (osTimerStart(mHandler, pdMS_TO_TICKS(100)) != osOK) { SILABS_LOG("Timer start() failed"); appError(CHIP_ERROR_INTERNAL); @@ -546,12 +542,12 @@ void WindowManager::Cover::CallbackOperationalStateSet(intptr_t arg) WindowManager::Timer::Timer(uint32_t timeoutInMs, Callback callback, void * context) : mCallback(callback), mContext(context) { - mHandler = xTimerCreate("", // Just a text name, not used by the RTOS kernel - pdMS_TO_TICKS(timeoutInMs), // == default timer period (mS) - false, // no timer reload (==one-shot) - (void *) this, // init timer id = app task obj context - TimerCallback // timer callback handler + mHandler = osTimerNew(TimerCallback, // timer callback handler + osTimerOnce, // no timer reload (one-shot timer) + this, // pass the app task obj context + NULL // No osTimerAttr_t to provide. ); + if (mHandler == NULL) { SILABS_LOG("Timer create failed"); @@ -562,16 +558,16 @@ WindowManager::Timer::Timer(uint32_t timeoutInMs, Callback callback, void * cont void WindowManager::Timer::Stop() { mIsActive = false; - if (xTimerStop(mHandler, pdMS_TO_TICKS(0)) == pdFAIL) + if (osTimerStop(mHandler) == osError) { SILABS_LOG("Timer stop() failed"); appError(CHIP_ERROR_INTERNAL); } } -void WindowManager::Timer::TimerCallback(TimerHandle_t xTimer) +void WindowManager::Timer::TimerCallback(void * timerCbArg) { - Timer * timer = (Timer *) pvTimerGetTimerID(xTimer); + Timer * timer = static_cast(timerCbArg); if (timer) { timer->Timeout(); From cbdba885fcdc4b0d9fad980bf747ecabe50620df Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 26 Mar 2024 11:54:14 -0400 Subject: [PATCH 5/9] Make gn know about ListLargeSystemExtensions.h (#32672) * Make gn know about ListLargeSystemExtensions.h * Fix linter --- .github/workflows/lint.yml | 1 - examples/tv-casting-app/android/BUILD.gn | 1 + src/app/data-model/BUILD.gn | 9 +++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 38c1dac8188b02..c028e0ad018381 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -95,7 +95,6 @@ jobs: --known-failure app/CommandHandler.h \ --known-failure app/CommandHandlerInterface.h \ --known-failure app/CommandSenderLegacyCallback.h \ - --known-failure app/data-model/ListLargeSystemExtensions.h \ --known-failure app/ReadHandler.h \ --known-failure app/reporting/reporting.cpp \ --known-failure app/reporting/tests/MockReportScheduler.cpp \ diff --git a/examples/tv-casting-app/android/BUILD.gn b/examples/tv-casting-app/android/BUILD.gn index 890e2aaec02729..52a3342773175b 100644 --- a/examples/tv-casting-app/android/BUILD.gn +++ b/examples/tv-casting-app/android/BUILD.gn @@ -53,6 +53,7 @@ shared_library("jni") { deps = [ "${chip_root}/examples/tv-casting-app/tv-casting-common", + "${chip_root}/src/app/data-model:heap", "${chip_root}/src/app/server/java:jni", "${chip_root}/src/lib", "${chip_root}/third_party/inipp", diff --git a/src/app/data-model/BUILD.gn b/src/app/data-model/BUILD.gn index 9b04882a60ec9c..3dee98119f6da6 100644 --- a/src/app/data-model/BUILD.gn +++ b/src/app/data-model/BUILD.gn @@ -45,3 +45,12 @@ source_set("data-model") { "${chip_root}/src/protocols/interaction_model", ] } + +# Provides extensions that use heap and should be +# used for systems that are not as constrained as +# embedded systems typically are +source_set("heap") { + sources = [ "ListLargeSystemExtensions.h" ] + + deps = [ ":data-model" ] +} From e2ea7d71768a0a25b6caf3733914ddd35ac8ce34 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 26 Mar 2024 11:59:51 -0400 Subject: [PATCH 6/9] Remove weak-linkage usage for matter callbacks for pre/post attribute read/write and command invocation (#32673) * Move placeholder commands to use actual callback classes * Remove the weak redirects ... they don't seem used --- .../linux/include/MatterCallbacks.h | 40 ----------- examples/placeholder/linux/main.cpp | 40 ++++++++++- src/app/CommandHandler.cpp | 2 +- src/app/util/MatterCallbacks.cpp | 67 +------------------ 4 files changed, 42 insertions(+), 107 deletions(-) delete mode 100644 examples/placeholder/linux/include/MatterCallbacks.h diff --git a/examples/placeholder/linux/include/MatterCallbacks.h b/examples/placeholder/linux/include/MatterCallbacks.h deleted file mode 100644 index d7ba67e2b38200..00000000000000 --- a/examples/placeholder/linux/include/MatterCallbacks.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "InteractiveServer.h" - -#include -#include - -void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath, - const chip::Access::SubjectDescriptor & subjectDescriptor) -{ - VerifyOrReturn(!InteractiveServer::GetInstance().Command(commandPath)); -} - -void MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) -{ - VerifyOrReturn(!InteractiveServer::GetInstance().ReadAttribute(attributePath)); -} - -void MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) -{ - VerifyOrReturn(!InteractiveServer::GetInstance().WriteAttribute(attributePath)); -} diff --git a/examples/placeholder/linux/main.cpp b/examples/placeholder/linux/main.cpp index ab5fa266dd6392..6485044a7ed6d8 100644 --- a/examples/placeholder/linux/main.cpp +++ b/examples/placeholder/linux/main.cpp @@ -18,7 +18,44 @@ #include "AppMain.h" #include "AppOptions.h" -#include "MatterCallbacks.h" +#include "InteractiveServer.h" + +#include + +namespace { +class InteractiveServerRedirectCallbacks : public chip::DataModelCallbacks +{ +public: + void AttributeOperation(OperationType operation, OperationOrder order, const chip::app::ConcreteAttributePath & path) override + { + if (order != OperationOrder::Post) + { + return; + } + + // TODO: is there any value in checking the return of read/write attributes? + // they seem to only return true/false based on isRead (i.e. commissioning complete) + switch (operation) + { + case OperationType::Read: + (void) InteractiveServer::GetInstance().ReadAttribute(path); + break; + case OperationType::Write: + (void) InteractiveServer::GetInstance().WriteAttribute(path); + break; + } + } + + void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath, + const chip::Access::SubjectDescriptor & subjectDescriptor) override + { + (void) InteractiveServer::GetInstance().Command(commandPath); + } +}; + +InteractiveServerRedirectCallbacks gDmCallbacks; + +} // namespace void ApplicationInit() {} @@ -36,6 +73,7 @@ int main(int argc, char * argv[]) server.Run(AppOptions::GetInteractiveModePort()); } + chip::DataModelCallbacks::SetInstance(&gDmCallbacks); ChipLinuxAppMainLoop(); return 0; diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index f80f41e9a63c61..d9bd50251ab250 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -564,7 +564,7 @@ Status CommandHandler::ProcessGroupCommandDataIB(CommandDataIB::Parser & aComman else { ChipLogError(DataManagement, - "Error when calling MatterPreCommandReceivedCallback for Endpoint=%u Cluster=" ChipLogFormatMEI + "Error when calling PreCommandReceived for Endpoint=%u Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI " : %" CHIP_ERROR_FORMAT, mapping.endpoint_id, ChipLogValueMEI(clusterId), ChipLogValueMEI(commandId), err.Format()); continue; diff --git a/src/app/util/MatterCallbacks.cpp b/src/app/util/MatterCallbacks.cpp index 71ab7fdc9df65d..76576c86223242 100644 --- a/src/app/util/MatterCallbacks.cpp +++ b/src/app/util/MatterCallbacks.cpp @@ -15,74 +15,11 @@ */ #include "MatterCallbacks.h" -// The defines below are using link-time callback and should be removed -// -// TODO: applications should be converted to use DataModelCallbacks instead -// of relying on weak linkage -void __attribute__((weak)) MatterPreAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {} -void __attribute__((weak)) MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {} -void __attribute__((weak)) MatterPreAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {} -void __attribute__((weak)) MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {} -CHIP_ERROR __attribute__((weak)) MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath, - const chip::Access::SubjectDescriptor & subjectDescriptor) -{ - return CHIP_NO_ERROR; -} -void __attribute__((weak)) MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath, - const chip::Access::SubjectDescriptor & subjectDescriptor) -{} - namespace chip { namespace { -class WeakRedirectCallbacks : public DataModelCallbacks -{ -public: - void AttributeOperation(OperationType operation, OperationOrder order, const chip::app::ConcreteAttributePath & path) override - { - switch (operation) - { - case OperationType::Read: - switch (order) - { - case OperationOrder::Pre: - MatterPreAttributeReadCallback(path); - break; - case OperationOrder::Post: - MatterPostAttributeReadCallback(path); - break; - } - break; - case OperationType::Write: - switch (order) - { - case OperationOrder::Pre: - MatterPreAttributeWriteCallback(path); - break; - case OperationOrder::Post: - MatterPostAttributeWriteCallback(path); - break; - } - break; - } - } - - CHIP_ERROR PreCommandReceived(const chip::app::ConcreteCommandPath & commandPath, - const chip::Access::SubjectDescriptor & subjectDescriptor) override - { - return MatterPreCommandReceivedCallback(commandPath, subjectDescriptor); - } - - void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath, - const chip::Access::SubjectDescriptor & subjectDescriptor) override - { - - MatterPostCommandReceivedCallback(commandPath, subjectDescriptor); - } -}; - -WeakRedirectCallbacks gWeakCallbacks; -DataModelCallbacks * gInstance = &gWeakCallbacks; +DataModelCallbacks gNoopCallbacks; +DataModelCallbacks * gInstance = &gNoopCallbacks; } // namespace From 9957401099dbf30462bf70ca0921c467a921567a Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 26 Mar 2024 12:27:13 -0400 Subject: [PATCH 7/9] Fix incorrect comment in MatterCallbacks. (#32723) The comment for the Pre callback was fixed, but the one for the Post callback was not. --- src/app/util/MatterCallbacks.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/util/MatterCallbacks.h b/src/app/util/MatterCallbacks.h index 05d1653da84e1f..2b2d0ed1b9a9a8 100644 --- a/src/app/util/MatterCallbacks.h +++ b/src/app/util/MatterCallbacks.h @@ -60,8 +60,12 @@ class DataModelCallbacks return CHIP_NO_ERROR; } - /// This callback is called once the message has been determined to be a command, but - /// after it being dispatched to the receiver. + /// This callback is called once for every command dispatch, after the dispatch is actually + /// done towards the receiver. + /// + /// This method is called once for every CommandDataIB (i.e. it may be called several times + /// in the case of batch invoke, where a single `InvokeRequestMessage` may contain several + /// CommandDataIB entries). virtual void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath, const chip::Access::SubjectDescriptor & subjectDescriptor) {} From 31fa02f7414bc0ac46e34988222b989c237b6925 Mon Sep 17 00:00:00 2001 From: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:38:19 -0700 Subject: [PATCH 8/9] Remove synchronous calls that can block from TV code (#32010) * Remove synchronous calls * move blocking calls to use a (future) separate thread pool * cleanup and fix ci * Restyled by clang-format (#32011) Co-authored-by: Restyled.io * address comments * address comments * Address comments * Fix build * Address comments * cleanup * cleanup * Fix rotating id * address comments * fix CI * Address comments --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io --- .../java/MyUserPrompterResolver-JNI.cpp | 8 +- examples/tv-app/android/java/TVApp-JNI.cpp | 33 +- .../tv-common/include/CHIPProjectAppConfig.h | 3 + examples/tv-app/tv-common/src/AppTv.cpp | 33 +- src/app/server/Server.cpp | 19 +- .../CommissionerDiscoveryController.cpp | 326 +++++++++++++++--- .../CommissionerDiscoveryController.h | 55 ++- src/include/platform/CHIPDeviceConfig.h | 13 + .../UDCClientState.h | 41 ++- .../UserDirectedCommissioning.h | 6 +- .../UserDirectedCommissioningServer.cpp | 9 - 11 files changed, 440 insertions(+), 106 deletions(-) diff --git a/examples/tv-app/android/java/MyUserPrompterResolver-JNI.cpp b/examples/tv-app/android/java/MyUserPrompterResolver-JNI.cpp index 94f56f98e49db5..60f60dc829fde9 100644 --- a/examples/tv-app/android/java/MyUserPrompterResolver-JNI.cpp +++ b/examples/tv-app/android/java/MyUserPrompterResolver-JNI.cpp @@ -30,10 +30,10 @@ using namespace chip; JNI_METHOD(void, OnPinCodeEntered)(JNIEnv *, jobject, jint jPinCode) { -#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE chip::DeviceLayer::StackLock lock; - uint32_t pinCode = (uint32_t) jPinCode; + uint32_t pinCode = static_cast(jPinCode); ChipLogProgress(Zcl, "OnPinCodeEntered %d", pinCode); +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE GetCommissionerDiscoveryController()->CommissionWithPasscode(pinCode); #endif } @@ -67,11 +67,7 @@ JNI_METHOD(void, OnPromptDeclined)(JNIEnv *, jobject) JNI_METHOD(void, OnCommissionerPasscodeOK)(JNIEnv *, jobject) { -#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE - chip::DeviceLayer::StackLock lock; ChipLogProgress(Zcl, "OnCommissionerPasscodeOK"); - // GetCommissionerDiscoveryController()->Ok(); -#endif } JNI_METHOD(void, OnCommissionerPasscodeCancel)(JNIEnv *, jobject) diff --git a/examples/tv-app/android/java/TVApp-JNI.cpp b/examples/tv-app/android/java/TVApp-JNI.cpp index 72279c49dca9d7..4a121658392b3a 100644 --- a/examples/tv-app/android/java/TVApp-JNI.cpp +++ b/examples/tv-app/android/java/TVApp-JNI.cpp @@ -197,10 +197,28 @@ JNI_METHOD(void, setChipDeviceEventProvider)(JNIEnv *, jobject, jobject provider #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED class MyPincodeService : public PasscodeService { - bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId, - chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode) override + void LookupTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId, + chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info) override { - return ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode); + uint32_t passcode; + bool foundApp = ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode); + if (!foundApp) + { + info.checkState = chip::Controller::TargetAppCheckState::kAppNotFound; + } + else if (passcode != 0) + { + info.checkState = chip::Controller::TargetAppCheckState::kAppFoundPasscodeReturned; + } + else + { + info.checkState = chip::Controller::TargetAppCheckState::kAppFoundNoPasscode; + } + CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController(); + if (cdc != nullptr) + { + cdc->HandleTargetContentAppCheck(info, passcode); + } } uint32_t GetCommissionerPasscode(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) override @@ -209,9 +227,14 @@ class MyPincodeService : public PasscodeService return 12345678; } - uint32_t FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override + void FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override { - return ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId); + uint32_t passcode = ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId); + CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController(); + if (cdc != nullptr) + { + cdc->HandleContentAppPasscodeResponse(passcode); + } } }; MyPincodeService gMyPincodeService; diff --git a/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h b/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h index e5ec3f064a2fbf..e0efac4da5003b 100644 --- a/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h +++ b/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h @@ -30,6 +30,9 @@ // TVs need to be commissioners and likely want to be discoverable #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 1 +// TVs can handle the memory impact of supporting a larger list +#define CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS 10 + // TVs will often enable this feature #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_PASSCODE 1 diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 8fd076b227b882..4acb0d61d21f99 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -102,10 +102,28 @@ MyUserPrompter gMyUserPrompter; class MyPasscodeService : public PasscodeService { - bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId, - chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode) override + void LookupTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId, + chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info) override { - return ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode); + uint32_t passcode = 0; + bool foundApp = ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode); + if (!foundApp) + { + info.checkState = TargetAppCheckState::kAppNotFound; + } + else if (passcode != 0) + { + info.checkState = TargetAppCheckState::kAppFoundPasscodeReturned; + } + else + { + info.checkState = TargetAppCheckState::kAppFoundNoPasscode; + } + CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController(); + if (cdc != nullptr) + { + cdc->HandleTargetContentAppCheck(info, passcode); + } } uint32_t GetCommissionerPasscode(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) override @@ -114,9 +132,14 @@ class MyPasscodeService : public PasscodeService return 12345678; } - uint32_t FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override + void FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override { - return ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId); + uint32_t passcode = ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId); + CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController(); + if (cdc != nullptr) + { + cdc->HandleContentAppPasscodeResponse(passcode); + } } }; MyPasscodeService gMyPasscodeService; diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 3d7ceb50890000..d2983636450691 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -645,13 +645,22 @@ CHIP_ERROR Server::SendUserDirectedCommissioningRequest(chip::Transport::PeerAdd #if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) if (id.GetRotatingIdLength() == 0) { - char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength]; + AdditionalDataPayloadGeneratorParams additionalDataPayloadParams; + uint8_t rotatingDeviceIdUniqueId[chip::DeviceLayer::ConfigurationManager::kRotatingDeviceIDUniqueIDLength]; + MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId); + + ReturnErrorOnFailure( + chip::DeviceLayer::GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan)); ReturnErrorOnFailure( - app::DnssdServer::Instance().GenerateRotatingDeviceId(rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer))); + chip::DeviceLayer::ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter)); + additionalDataPayloadParams.rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueIdSpan; + + uint8_t rotatingDeviceIdInternalBuffer[RotatingDeviceId::kMaxLength]; + MutableByteSpan rotatingDeviceIdBufferTemp(rotatingDeviceIdInternalBuffer); + ReturnErrorOnFailure(AdditionalDataPayloadGenerator().generateRotatingDeviceIdAsBinary(additionalDataPayloadParams, + rotatingDeviceIdBufferTemp)); - uint8_t * rotatingId = reinterpret_cast(rotatingDeviceIdHexBuffer); - size_t rotatingIdLen = strlen(rotatingDeviceIdHexBuffer); - id.SetRotatingId(rotatingId, rotatingIdLen); + id.SetRotatingId(rotatingDeviceIdInternalBuffer, RotatingDeviceId::kMaxLength); } #endif diff --git a/src/controller/CommissionerDiscoveryController.cpp b/src/controller/CommissionerDiscoveryController.cpp index ee94bc87b92670..a4d874f0243b2f 100644 --- a/src/controller/CommissionerDiscoveryController.cpp +++ b/src/controller/CommissionerDiscoveryController.cpp @@ -43,8 +43,28 @@ void CommissionerDiscoveryController::ResetState() mReady = true; } +void CommissionerDiscoveryController::ValidateSession() +{ + if (mReady) + { + return; + } + if (mUdcServer != nullptr) + { + UDCClientState * client = mUdcServer->GetUDCClients().FindUDCClientState(mCurrentInstance); + if (client != nullptr) + { + // everything looks good + return; + } + } + ResetState(); +} + void CommissionerDiscoveryController::OnUserDirectedCommissioningRequest(UDCClientState state) { + ValidateSession(); + if (!mReady) { ChipLogDetail(Controller, "CommissionerDiscoveryController not ready. Current instance=%s", mCurrentInstance); @@ -76,14 +96,13 @@ void CommissionerDiscoveryController::OnUserDirectedCommissioningRequest(UDCClie ChipLogError(AppServer, "On UDC: no udc server"); return; } - mUdcServer->SendCDCMessage(cd, - chip::Transport::PeerAddress::UDP(state.GetPeerAddress().GetIPAddress(), state.GetCdPort())); + mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(state.GetPeerAddress().GetIPAddress(), state.GetCdPort())); return; } else { // can only get here is ok() has already been called - ChipLogError(AppServer, "On UDC: commissioner passcode ready with passcode - commissioning"); + ChipLogDetail(AppServer, "On UDC: commissioner passcode ready with passcode - commissioning"); // start commissioning using the cached passcode CommissionWithPasscode(passcode); @@ -94,15 +113,20 @@ void CommissionerDiscoveryController::OnUserDirectedCommissioningRequest(UDCClie mReady = false; Platform::CopyString(mCurrentInstance, state.GetInstanceName()); mPendingConsent = true; - char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength]; - Encoding::BytesToUppercaseHexString(state.GetRotatingId(), state.GetRotatingIdLength(), rotatingDeviceIdHexBuffer, - RotatingDeviceId::kHexMaxLength); + char rotatingIdString[Dnssd::kMaxRotatingIdLen * 2 + 1]; + CHIP_ERROR err = Encoding::BytesToUppercaseHexString(state.GetRotatingId(), state.GetRotatingIdLength(), rotatingIdString, + sizeof(rotatingIdString)); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "On UDC: could not convert rotating id to hex"); + rotatingIdString[0] = '\0'; + } ChipLogDetail(Controller, "------PROMPT USER: %s is requesting permission to cast to this TV, approve? [" ChipLogFormatMEI "," ChipLogFormatMEI ",%s,%s]", state.GetDeviceName(), ChipLogValueMEI(state.GetVendorId()), ChipLogValueMEI(state.GetProductId()), - state.GetInstanceName(), rotatingDeviceIdHexBuffer); + state.GetInstanceName(), rotatingIdString); if (mUserPrompter != nullptr) { mUserPrompter->PromptForCommissionOKPermission(state.GetVendorId(), state.GetProductId(), state.GetDeviceName()); @@ -121,86 +145,243 @@ void CallbackOk(System::Layer * aSystemLayer, void * aAppState) void CommissionerDiscoveryController::Ok() { ChipLogDetail(AppServer, "UX Ok: moving to main thread"); - // need to ensure callback is on main chip thread assertChipStackLockedByCurrentThread(); - DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(0), CallbackOk, this); + if (CHIP_NO_ERROR != DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(0), CallbackOk, this)) + { + ChipLogError(AppServer, "UX Ok: StartTimer returned error"); + } } void CommissionerDiscoveryController::InternalOk() { ChipLogDetail(AppServer, "UX InternalOk"); + assertChipStackLockedByCurrentThread(); + ValidateSession(); + if (!mPendingConsent) { - ChipLogError(AppServer, "UX Ok: no current instance"); + ChipLogError(AppServer, "UX InternalOk: no current instance"); return; } if (mUdcServer == nullptr) { - ChipLogError(AppServer, "UX Ok: no udc server"); + ChipLogError(AppServer, "UX InternalOk: no udc server"); return; } UDCClientState * client = mUdcServer->GetUDCClients().FindUDCClientState(mCurrentInstance); if (client == nullptr) { - ChipLogError(AppServer, "UX Ok: could not find instance=%s", mCurrentInstance); + ChipLogError(AppServer, "UX InternalOk: could not find instance=%s", mCurrentInstance); return; } if (client->GetUDCClientProcessingState() != UDCClientProcessingState::kPromptingUser) { - ChipLogError(AppServer, "UX Ok: invalid state for ok"); + ChipLogError(AppServer, "UX InternalOk: invalid state for ok"); return; } client->SetUDCClientProcessingState(UDCClientProcessingState::kObtainingOnboardingPayload); - if (mPasscodeService != nullptr) + if (mPasscodeService == nullptr) + { + HandleContentAppPasscodeResponse(0); + return; + } + + char rotatingIdBuffer[Dnssd::kMaxRotatingIdLen * 2]; + size_t rotatingIdLength = client->GetRotatingIdLength(); + CHIP_ERROR err = + Encoding::BytesToUppercaseHexBuffer(client->GetRotatingId(), rotatingIdLength, rotatingIdBuffer, sizeof(rotatingIdBuffer)); + if (err != CHIP_NO_ERROR) { - char rotatingIdString[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = ""; - Encoding::BytesToUppercaseHexString(client->GetRotatingId(), client->GetRotatingIdLength(), rotatingIdString, - sizeof(rotatingIdString)); - // Encoding::BytesToUppercaseHexString(client->GetRotatingId(), chip::Dnssd::kMaxRotatingIdLen, rotatingIdString, - // sizeof(rotatingIdString)); + ChipLogError(AppServer, "UX InternalOk: could not convert rotating id to hex"); + return; + } + CharSpan rotatingIdSpan(rotatingIdBuffer, 2 * rotatingIdLength); - CharSpan rotatingIdSpan = chip::CharSpan(rotatingIdString, sizeof(rotatingIdString)); - uint32_t passcode = 0; - uint8_t targetAppCount = client->GetNumTargetAppInfos(); - if (targetAppCount > 0) + uint8_t targetAppCount = client->GetNumTargetAppInfos(); + if (targetAppCount > 0) + { + ChipLogDetail(AppServer, "UX InternalOk: checking for each target app specified"); + + for (uint8_t i = 0; i < targetAppCount; i++) { - bool hasTargetApp = false; - for (uint8_t i = 0; i < targetAppCount; i++) + TargetAppInfo info; + if (client->GetTargetAppInfo(i, info)) { - TargetAppInfo info; - if (client->GetTargetAppInfo(i, info)) + if (mPasscodeService != nullptr) { - if (mPasscodeService->HasTargetContentApp(client->GetVendorId(), client->GetProductId(), rotatingIdSpan, info, - passcode)) - { - // found one - hasTargetApp = true; - } + mPasscodeService->LookupTargetContentApp(client->GetVendorId(), client->GetProductId(), rotatingIdSpan, info); } } - // handle NoAppsFound CDC case - if (!hasTargetApp && client->GetNoPasscode()) + } + return; + } + ChipLogDetail(AppServer, "UX InternalOk: checking target app associated with client"); + + if (mPasscodeService != nullptr) + { + mPasscodeService->FetchCommissionPasscodeFromContentApp(client->GetVendorId(), client->GetProductId(), rotatingIdSpan); + } + + ChipLogDetail(AppServer, "UX Ok: done moving out of main thread"); +} + +void CommissionerDiscoveryController::HandleTargetContentAppCheck(TargetAppInfo target, uint32_t passcode) +{ + assertChipStackLockedByCurrentThread(); + ValidateSession(); + + bool foundTargetApp = false; + bool foundPendingTargets = false; + + /** + * Update our target app list with the status from this target. + * + * If we are the first callback to receive a passcode, + * then complete commissioning with it. + * If we are the last expected callback and none has completed commissioning, + * then advance to the next step for trying to obtain a passcode. + * When iterating through the list of targets, keep track of whether any apps have been found, + * so that if we advance we can do so with that information (may need to send a CDC). + */ + + if (mUdcServer == nullptr) + { + ChipLogError(AppServer, "UX Ok - HandleContentAppCheck: no udc server"); + return; + } + UDCClientState * client = mUdcServer->GetUDCClients().FindUDCClientState(mCurrentInstance); + if (client == nullptr) + { + ChipLogError(AppServer, "UX Ok - HandleContentAppCheck: could not find instance=%s", mCurrentInstance); + return; + } + if (client->GetUDCClientProcessingState() != UDCClientProcessingState::kObtainingOnboardingPayload) + { + ChipLogError(AppServer, "UX Ok - HandleContentAppCheck: invalid state for HandleContentAppPasscodeResponse"); + return; + } + + uint8_t targetAppCount = client->GetNumTargetAppInfos(); + for (uint8_t i = 0; i < targetAppCount; i++) + { + TargetAppInfo info; + if (client->GetTargetAppInfo(i, info)) + { + if (info.checkState == TargetAppCheckState::kAppFoundPasscodeReturned) { - ChipLogError(AppServer, "UX Ok: target apps specified but none found, sending CDC"); - CommissionerDeclaration cd; - cd.SetNoAppsFound(true); - mUdcServer->SendCDCMessage( - cd, chip::Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); + // nothing else to do, complete commissioning has been called return; } + else if (info.checkState == TargetAppCheckState::kAppFoundNoPasscode) + { + foundTargetApp = true; + } + else if (info.checkState == TargetAppCheckState::kNotInitialized) + { + if (target.vendorId == info.vendorId && target.productId == info.productId) + { + client->SetTargetAppInfoState(i, target.checkState); + if (target.checkState != TargetAppCheckState::kAppNotFound) + { + foundTargetApp = true; + } + } + else + { + foundPendingTargets = true; + } + } } - else - { - passcode = mPasscodeService->FetchCommissionPasscodeFromContentApp(client->GetVendorId(), client->GetProductId(), - rotatingIdSpan); - } + } + if (passcode != 0) + { + ChipLogDetail(AppServer, "UX Ok - HandleContentAppCheck: found a passcode"); + // we found a passcode and complete commissioning has not been called + CommissionWithPasscode(passcode); + return; + } + if (foundPendingTargets) + { + ChipLogDetail(AppServer, "UX Ok - HandleContentAppCheck: have not heard from all apps"); + // have not heard from all targets so don't do anything + return; + } + if (!foundTargetApp && client->GetNoPasscode()) + { + // finished iterating through all apps and found none, send CDC + ChipLogDetail(AppServer, "UX Ok - HandleContentAppCheck: target apps specified but none found, sending CDC"); + CommissionerDeclaration cd; + cd.SetNoAppsFound(true); + mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); + } + ChipLogDetail(AppServer, "UX Ok - HandleContentAppCheck: advancing"); + // otherwise, advance to the next step for trying to obtain a passcode. + HandleContentAppPasscodeResponse(0); + return; +} + +/// Callback for getting execution into the main chip thread +void CallbackHandleContentAppPasscodeResponse(System::Layer * aSystemLayer, void * aAppState) +{ + ChipLogDetail(AppServer, "HandleContentAppPasscodeResponse: now on main thread"); + CommissionerDiscoveryController * cdc = static_cast(aAppState); + cdc->InternalHandleContentAppPasscodeResponse(); +} +void CommissionerDiscoveryController::HandleContentAppPasscodeResponse(uint32_t passcode) +{ + assertChipStackLockedByCurrentThread(); + + SetPasscode(passcode); + if (CHIP_NO_ERROR != + DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(0), CallbackHandleContentAppPasscodeResponse, this)) + { + ChipLogError(AppServer, "HandleContentAppPasscodeResponse: StartTimer returned error"); + } +} + +void CommissionerDiscoveryController::InternalHandleContentAppPasscodeResponse() +{ + assertChipStackLockedByCurrentThread(); + ValidateSession(); + uint32_t passcode = mPasscode; + + if (mUdcServer == nullptr) + { + ChipLogError(AppServer, "UX Ok - HandleContentAppPasscodeResponse: no udc server"); + return; + } + UDCClientState * client = mUdcServer->GetUDCClients().FindUDCClientState(mCurrentInstance); + if (client == nullptr) + { + ChipLogError(AppServer, "UX Ok - HandleContentAppPasscodeResponse: could not find instance=%s", mCurrentInstance); + return; + } + if (client->GetUDCClientProcessingState() != UDCClientProcessingState::kObtainingOnboardingPayload) + { + ChipLogError(AppServer, "UX Ok - HandleContentAppPasscodeResponse: invalid state for HandleContentAppPasscodeResponse"); + return; + } + + if (mPasscodeService != nullptr) + { // if CommissionerPasscode // - if CommissionerPasscodeReady, then start commissioning // - if CommissionerPasscode, then call new UX method to show passcode, send CDC if (passcode == 0 && client->GetCommissionerPasscode() && client->GetCdPort() != 0) { + char rotatingIdBuffer[Dnssd::kMaxRotatingIdLen * 2]; + size_t rotatingIdLength = client->GetRotatingIdLength(); + CHIP_ERROR err = Encoding::BytesToUppercaseHexBuffer(client->GetRotatingId(), rotatingIdLength, rotatingIdBuffer, + sizeof(rotatingIdBuffer)); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "UX Ok - HandleContentAppPasscodeResponse: could not convert rotating id to hex"); + return; + } + CharSpan rotatingIdSpan(rotatingIdBuffer, 2 * rotatingIdLength); + // first step of commissioner passcode ChipLogError(AppServer, "UX Ok: commissioner passcode, sending CDC"); // generate a passcode @@ -213,7 +394,7 @@ void CommissionerDiscoveryController::InternalOk() cd.SetErrorCode(CommissionerDeclaration::CdError::kCommissionerPasscodeDisabled); cd.SetNeedsPasscode(true); mUdcServer->SendCDCMessage( - cd, chip::Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); + cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); return; } client->SetCachedCommissionerPasscode(passcode); @@ -224,8 +405,8 @@ void CommissionerDiscoveryController::InternalOk() { cd.SetQRCodeDisplayed(true); } - mUdcServer->SendCDCMessage( - cd, chip::Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); + mUdcServer->SendCDCMessage(cd, + Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); // dialog ChipLogDetail(Controller, @@ -248,23 +429,21 @@ void CommissionerDiscoveryController::InternalOk() // if NoPasscode, send CDC if (client->GetNoPasscode() && client->GetCdPort() != 0) { - ChipLogError(AppServer, "UX Ok: no app passcode and NoPasscode in UDC, sending CDC"); + ChipLogDetail(AppServer, "UX Ok: no app passcode and NoPasscode in UDC, sending CDC"); CommissionerDeclaration cd; cd.SetNeedsPasscode(true); - mUdcServer->SendCDCMessage(cd, - chip::Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); + mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); return; } // if CdUponPasscodeDialog, send CDC if (client->GetCdUponPasscodeDialog() && client->GetCdPort() != 0) { - ChipLogError(AppServer, "UX Ok: no app passcode and GetCdUponPasscodeDialog in UDC, sending CDC"); + ChipLogDetail(AppServer, "UX Ok: no app passcode and GetCdUponPasscodeDialog in UDC, sending CDC"); CommissionerDeclaration cd; cd.SetNeedsPasscode(true); // TODO: should this be set? cd.SetPasscodeDialogDisplayed(true); - mUdcServer->SendCDCMessage(cd, - chip::Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); + mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); } ChipLogDetail(Controller, "------PROMPT USER: please enter passcode displayed in casting app "); @@ -276,8 +455,31 @@ void CommissionerDiscoveryController::InternalOk() ChipLogDetail(Controller, "------Via Shell Enter: controller ux ok [passcode]"); } +/// Callback for getting execution into the main chip thread +void CallbackCommissionWithPasscode(System::Layer * aSystemLayer, void * aAppState) +{ + ChipLogDetail(AppServer, "CallbackCommissionWithPasscode: now on main thread"); + CommissionerDiscoveryController * cdc = static_cast(aAppState); + cdc->InternalCommissionWithPasscode(); +} + void CommissionerDiscoveryController::CommissionWithPasscode(uint32_t passcode) { + assertChipStackLockedByCurrentThread(); + + SetPasscode(passcode); + if (CHIP_NO_ERROR != DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(0), CallbackCommissionWithPasscode, this)) + { + ChipLogError(AppServer, "CommissionWithPasscode: StartTimer returned error"); + } +} + +void CommissionerDiscoveryController::InternalCommissionWithPasscode() +{ + assertChipStackLockedByCurrentThread(); + ValidateSession(); + uint32_t passcode = mPasscode; + if (!mPendingConsent) { ChipLogError(AppServer, "UX Cancel: no current instance"); @@ -315,6 +517,8 @@ void CommissionerDiscoveryController::CommissionWithPasscode(uint32_t passcode) void CommissionerDiscoveryController::Cancel() { + ValidateSession(); + if (!mPendingConsent) { ChipLogError(AppServer, "UX Cancel: no current instance"); @@ -360,6 +564,20 @@ void CommissionerDiscoveryController::CommissioningFailed(CHIP_ERROR error) ChipLogDetail(Controller, "------PROMPT USER: commissioning failed "); mUserPrompter->PromptCommissioningFailed(GetCommissioneeName(), error); } + if (mUdcServer == nullptr) + { + ChipLogError(AppServer, "UX Cancel: no udc server"); + return; + } + UDCClientState * client = mUdcServer->GetUDCClients().FindUDCClientState(mCurrentInstance); + if (client == nullptr || client->GetUDCClientProcessingState() != UDCClientProcessingState::kCommissioningNode) + { + ChipLogError(AppServer, "UX Cancel: invalid state for cancel"); + return; + } + client->SetUDCClientProcessingState(UDCClientProcessingState::kCommissioningFailed); + client->Reset(); + ResetState(); } diff --git a/src/controller/CommissionerDiscoveryController.h b/src/controller/CommissionerDiscoveryController.h index f0dcf6d5f95869..c4c90c32342bc1 100644 --- a/src/controller/CommissionerDiscoveryController.h +++ b/src/controller/CommissionerDiscoveryController.h @@ -153,7 +153,6 @@ class DLL_EXPORT UserPrompter virtual ~UserPrompter() = default; }; -// TODO: rename this to Passcode? class DLL_EXPORT PasscodeService { public: @@ -162,15 +161,18 @@ class DLL_EXPORT PasscodeService * Called to determine if the given target app is available to the commissionee with the given given * vendorId/productId, and if so, return the passcode. * + * This will be called by the main chip thread so any blocking work should be moved to a separate thread. + * + * After lookup and attempting to obtain the passcode, implementor should call HandleContentAppCheck(); + * * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. * @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee. * @param[in] info App info to look for. - * @param[in] passcode Passcode for the given commissionee, or 0 if passcode cannot be obtained. * */ - virtual bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId, - chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode) = 0; + virtual void LookupTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId, + chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info) = 0; /** * @brief @@ -186,18 +188,18 @@ class DLL_EXPORT PasscodeService /** * @brief - * Called to get the setup passcode from the content app corresponding to the given vendorId/productId - * Returns 0 if passcode cannot be obtained + * Called to get the setup passcode from the content app corresponding to the given vendorId/productId. * - * If user responds with OK then implementor should call CommissionerRespondOk(); - * If user responds with Cancel then implementor should call CommissionerRespondCancel(); + * This will be called by the main chip thread so any blocking work should be moved to a separate thread. + * + * After attempting to obtain the passcode, implementor should call HandleContentAppPasscodeResponse(); * * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. * @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee. * */ - virtual uint32_t FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) = 0; + virtual void FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) = 0; virtual ~PasscodeService() = default; }; @@ -259,6 +261,11 @@ class CommissionerDiscoveryController : public chip::Protocols::UserDirectedComm */ void ResetState(); + /** + * Check whether we have a valid session (and reset state if not). + */ + void ValidateSession(); + /** * UserConfirmationProvider callback. * @@ -281,11 +288,39 @@ class CommissionerDiscoveryController : public chip::Protocols::UserDirectedComm */ void Cancel(); + /** + * @brief + * Called with the result of attempting to obtain the passcode from the content app corresponding to the given + * vendorId/productId. + * + * @param[in] passcode Passcode for the given commissionee, or 0 if passcode cannot be obtained. + * + */ + void HandleContentAppPasscodeResponse(uint32_t passcode); + void InternalHandleContentAppPasscodeResponse(); + + /** + * Cache the passcode to use for commissioning + */ + inline void SetPasscode(uint32_t passcode) { mPasscode = passcode; } + + /** + * @brief + * Called with the result of attempting to lookup and obtain the passcode from the content app corresponding to the given + * target. + * + * @param[in] target Target app info for app check. + * @param[in] passcode Passcode for the given commissionee, or 0 if passcode cannot be obtained. + * + */ + void HandleTargetContentAppCheck(chip::Protocols::UserDirectedCommissioning::TargetAppInfo target, uint32_t passcode); + /** * This method should be called with the passcode for the client * indicated in the UserPrompter's PromptForCommissionPasscode callback */ void CommissionWithPasscode(uint32_t passcode); + void InternalCommissionWithPasscode(); /** * This method should be called by the commissioner to indicate that commissioning succeeded. @@ -337,6 +372,7 @@ class CommissionerDiscoveryController : public chip::Protocols::UserDirectedComm * Assign a PasscodeService */ inline void SetPasscodeService(PasscodeService * passcodeService) { mPasscodeService = passcodeService; } + inline PasscodeService * GetPasscodeService() { return mPasscodeService; } /** * Assign a Commissioner Callback to perform commissioning once user consent has been given @@ -371,6 +407,7 @@ class CommissionerDiscoveryController : public chip::Protocols::UserDirectedComm uint16_t mVendorId = 0; uint16_t mProductId = 0; NodeId mNodeId = 0; + uint32_t mPasscode = 0; UserDirectedCommissioningServer * mUdcServer = nullptr; UserPrompter * mUserPrompter = nullptr; diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 9d1f7804da63b4..785b47656dd5a3 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -749,6 +749,19 @@ static_assert(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN <= CHIP_DEVICE #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 0 #endif +/** + * CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS + * + * The number of target apps that a client can include in a UDC message. + * + * Depends upon CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY set to 1 + * + * For Video Players, this value should be set to 10 + */ +#ifndef CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS +#define CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS 3 +#endif + /** * CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE * diff --git a/src/protocols/user_directed_commissioning/UDCClientState.h b/src/protocols/user_directed_commissioning/UDCClientState.h index 587b1e3ff2b64c..e87e303340560c 100644 --- a/src/protocols/user_directed_commissioning/UDCClientState.h +++ b/src/protocols/user_directed_commissioning/UDCClientState.h @@ -43,13 +43,24 @@ enum class UDCClientProcessingState : uint8_t using PeerAddress = ::chip::Transport::PeerAddress; +enum class TargetAppCheckState : uint8_t +{ + kNotInitialized, + kAppNotFound, + kAppFoundPasscodeReturned, + kAppFoundNoPasscode, +}; + /** * Represents information in the TargetAppList of the Identification Declaration message */ struct TargetAppInfo { - uint16_t vendorId = 0; - uint16_t productId = 0; + uint16_t vendorId = 0; + uint16_t productId = 0; + TargetAppCheckState checkState = TargetAppCheckState::kNotInitialized; + uint32_t passcode = 0; + bool foundApp = false; }; /** @@ -112,23 +123,36 @@ class UDCClientState { if (index < mNumTargetAppInfos) { - info.vendorId = mTargetAppInfos[index].vendorId; - info.productId = mTargetAppInfos[index].productId; + info.vendorId = mTargetAppInfos[index].vendorId; + info.productId = mTargetAppInfos[index].productId; + info.checkState = mTargetAppInfos[index].checkState; + info.passcode = mTargetAppInfos[index].passcode; + info.foundApp = mTargetAppInfos[index].foundApp; return true; } return false; } + void SetTargetAppInfoState(uint8_t index, TargetAppCheckState checkState) + { + if (index < mNumTargetAppInfos) + { + mTargetAppInfos[index].checkState = checkState; + } + } uint8_t GetNumTargetAppInfos() const { return mNumTargetAppInfos; } bool AddTargetAppInfo(TargetAppInfo vid) { - if (mNumTargetAppInfos >= sizeof(mTargetAppInfos)) + if (mNumTargetAppInfos >= kMaxTargetAppInfos) { // already at max return false; } - mTargetAppInfos[mNumTargetAppInfos].vendorId = vid.vendorId; - mTargetAppInfos[mNumTargetAppInfos].productId = vid.productId; + mTargetAppInfos[mNumTargetAppInfos].vendorId = vid.vendorId; + mTargetAppInfos[mNumTargetAppInfos].productId = vid.productId; + mTargetAppInfos[mNumTargetAppInfos].checkState = TargetAppCheckState::kNotInitialized; + mTargetAppInfos[mNumTargetAppInfos].passcode = 0; + mTargetAppInfos[mNumTargetAppInfos].foundApp = false; mNumTargetAppInfos++; return true; } @@ -185,6 +209,7 @@ class UDCClientState mExpirationTime = System::Clock::kZero; mUDCClientProcessingState = UDCClientProcessingState::kNotInitialized; mCachedCommissionerPasscode = 0; + mNumTargetAppInfos = 0; } private: @@ -200,7 +225,7 @@ class UDCClientState char mPairingInst[chip::Dnssd::kMaxPairingInstructionLen + 1] = {}; uint16_t mPairingHint = 0; - constexpr static size_t kMaxTargetAppInfos = 10; + constexpr static size_t kMaxTargetAppInfos = CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS; uint8_t mNumTargetAppInfos = 0; // number of vendor Ids TargetAppInfo mTargetAppInfos[kMaxTargetAppInfos]; diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h b/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h index b4b7e90a085611..7f22c92be0b71c 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h @@ -78,11 +78,7 @@ class DLL_EXPORT IdentificationDeclaration const char * GetInstanceName() const { return mInstanceName; } void SetInstanceName(const char * instanceName) { Platform::CopyString(mInstanceName, instanceName); } - bool HasDiscoveryInfo() - { - return mVendorId != 0 || mProductId != 0 || mCdPort != 0 || strlen(mDeviceName) > 0 || GetRotatingIdLength() > 0 || - mNumTargetAppInfos > 0 || mNoPasscode || mCdUponPasscodeDialog || mCommissionerPasscode || mCommissionerPasscodeReady; - } + bool HasDiscoveryInfo() { return mVendorId != 0 && mProductId != 0 && mCdPort != 0 && strlen(mDeviceName) > 0; } const char * GetDeviceName() const { return mDeviceName; } void SetDeviceName(const char * deviceName) { Platform::CopyString(mDeviceName, deviceName); } diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp index 746df853436877..9e787124507536 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp @@ -91,15 +91,6 @@ void UserDirectedCommissioningServer::OnMessageReceived(const Transport::PeerAdd id.UpdateClientState(client); - // TEST: send reply - if (id.GetCdPort() != 0) - { - CommissionerDeclaration cd; - cd.SetErrorCode(CommissionerDeclaration::CdError::kAppInstallConsentPending); - cd.SetNeedsPasscode(true); - SendCDCMessage(cd, chip::Transport::PeerAddress::UDP(source.GetIPAddress(), id.GetCdPort())); - } - // Call the registered mUserConfirmationProvider, if any. if (mUserConfirmationProvider != nullptr) { From 72bd295095da509db58cf765db5df571355b3109 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 26 Mar 2024 13:38:16 -0400 Subject: [PATCH 9/9] Fix documentation about controller creation on Darwin. (#32716) createController does not exist, but the comments have not been updated to reflect that. --- src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h index d1efa99cda14e6..b5ef1ffaa6cf32 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h @@ -158,7 +158,7 @@ MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) * the startupParams. * * This method can only be used if the factory was initialized with storage. - * When using per-controller storage, use createController. + * When using per-controller storage, use [MTRDeviceController initWithParameters:error:]. */ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceControllerStartupParams *)startupParams error:(NSError * __autoreleasing *)error; @@ -172,7 +172,7 @@ MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) * the startupParams. * * This method can only be used if the factory was initialized with storage. - * When using per-controller storage, use createController. + * When using per-controller storage, use [MTRDeviceController initWithParameters:error:]. */ - (MTRDeviceController * _Nullable)createControllerOnNewFabric:(MTRDeviceControllerStartupParams *)startupParams error:(NSError * __autoreleasing *)error;