Skip to content

Commit

Permalink
Support keystore using external flash for Infineon P6 board (#14929)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenCY authored Feb 9, 2022
1 parent 5158095 commit 408ff8f
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,6 @@
[submodule "perfetto"]
path = third_party/perfetto/repo
url = https://github.com/google/perfetto
[submodule "p6/serial-flash"]
path = third_party/p6/p6_sdk/libs/serial-flash
url = https://github.com/Infineon/serial-flash
46 changes: 31 additions & 15 deletions examples/all-clusters-app/p6/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@
#ifdef HEAP_MONITORING
#include "MemMonitoring.h"
#endif
#define MAIN_TASK_STACK_SIZE (4096)
#define MAIN_TASK_PRIORITY 2

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;

volatile int apperror_cnt;
static void main_task(void * pvParameters);

// ================================================================================
// App Error
//=================================================================================
Expand All @@ -71,24 +75,17 @@ extern "C" void vApplicationIdleHook(void)
// FreeRTOS Idle callback
}

// ================================================================================
// Main Code
// ================================================================================
int main(void)
extern "C" void vApplicationDaemonTaskStartupHook()
{
init_p6Platform();

#ifdef HEAP_MONITORING
MemMonitoring::startHeapMonitoring();
#endif

P6_LOG("==================================================\r\n");
P6_LOG("chip-p6-all-clusters-example starting\r\n");
P6_LOG("==================================================\r\n");

// Init Chip memory management before the stack
chip::Platform::MemoryInit();

/* Create the Main task. */
xTaskCreate(main_task, "Main task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, NULL);
}

static void main_task(void * pvParameters)
{
CHIP_ERROR ret = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
if (ret != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -123,6 +120,26 @@ int main(void)
P6_LOG("GetAppTask().Init() failed");
appError(ret);
}

/* Delete task */
vTaskDelete(NULL);
}

// ================================================================================
// Main Code
// ================================================================================
int main(void)
{
init_p6Platform();

#ifdef HEAP_MONITORING
MemMonitoring::startHeapMonitoring();
#endif

P6_LOG("==================================================\r\n");
P6_LOG("chip-p6-all-clusters-example starting\r\n");
P6_LOG("==================================================\r\n");

/* Start the FreeRTOS scheduler */
vTaskStartScheduler();

Expand All @@ -132,5 +149,4 @@ int main(void)

// Should never get here.
P6_LOG("vTaskStartScheduler() failed");
appError(ret);
}
46 changes: 31 additions & 15 deletions examples/lighting-app/p6/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
#ifdef HEAP_MONITORING
#include "MemMonitoring.h"
#endif
#define MAIN_TASK_STACK_SIZE (4096)
#define MAIN_TASK_PRIORITY 2

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;

volatile int apperror_cnt;
static void main_task(void * pvParameters);

// ================================================================================
// App Error
//=================================================================================
Expand All @@ -70,24 +74,17 @@ extern "C" void vApplicationIdleHook(void)
// FreeRTOS Idle callback
}

// ================================================================================
// Main Code
// ================================================================================
int main(void)
extern "C" void vApplicationDaemonTaskStartupHook()
{
init_p6Platform();

#ifdef HEAP_MONITORING
MemMonitoring::startHeapMonitoring();
#endif

P6_LOG("==================================================\r\n");
P6_LOG("chip-p6-lighting-example starting\r\n");
P6_LOG("==================================================\r\n");

// Init Chip memory management before the stack
chip::Platform::MemoryInit();

/* Create the Main task. */
xTaskCreate(main_task, "Main task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, NULL);
}

static void main_task(void * pvParameters)
{
CHIP_ERROR ret = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
if (ret != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -115,6 +112,26 @@ int main(void)
P6_LOG("GetAppTask().Init() failed");
appError(ret);
}

/* Delete task */
vTaskDelete(NULL);
}

// ================================================================================
// Main Code
// ================================================================================
int main(void)
{
init_p6Platform();

#ifdef HEAP_MONITORING
MemMonitoring::startHeapMonitoring();
#endif

P6_LOG("==================================================\r\n");
P6_LOG("chip-p6-lighting-example starting\r\n");
P6_LOG("==================================================\r\n");

/* Start the FreeRTOS scheduler */
vTaskStartScheduler();

Expand All @@ -124,5 +141,4 @@ int main(void)

// Should never get here.
P6_LOG("vTaskStartScheduler() failed");
appError(ret);
}
39 changes: 28 additions & 11 deletions examples/lock-app/p6/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@
#include "init_p6Platform.h"
#include <app/server/Server.h>

#define MAIN_TASK_STACK_SIZE (4096)
#define MAIN_TASK_PRIORITY 2

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;

volatile int apperror_cnt;
static void main_task(void * pvParameters);

// ================================================================================
// App Error
//=================================================================================
Expand All @@ -66,20 +71,17 @@ extern "C" void vApplicationIdleHook(void)
// FreeRTOS Idle callback
}

// ================================================================================
// Main Code
// ================================================================================
int main(void)
extern "C" void vApplicationDaemonTaskStartupHook()
{
init_p6Platform();

P6_LOG("==================================================\r\n");
P6_LOG("chip-p6-lock-example starting\r\n");
P6_LOG("==================================================\r\n");

// Init Chip memory management before the stack
chip::Platform::MemoryInit();

/* Create the Main task. */
xTaskCreate(main_task, "Main task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, NULL);
}

static void main_task(void * pvParameters)
{
CHIP_ERROR ret = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
if (ret != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -107,6 +109,22 @@ int main(void)
P6_LOG("GetAppTask().Init() failed");
appError(ret);
}

/* Delete task */
vTaskDelete(NULL);
}

// ================================================================================
// Main Code
// ================================================================================
int main(void)
{
init_p6Platform();

P6_LOG("==================================================\r\n");
P6_LOG("chip-p6-lock-example starting\r\n");
P6_LOG("==================================================\r\n");

/* Start the FreeRTOS scheduler */
vTaskStartScheduler();

Expand All @@ -116,5 +134,4 @@ int main(void)

// Should never get here.
P6_LOG("vTaskStartScheduler() failed");
appError(ret);
}
65 changes: 42 additions & 23 deletions src/platform/P6/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,22 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(WiFiStationMode val)
CHIP_ERROR err = CHIP_NO_ERROR;
VerifyOrExit(val != kWiFiStationMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT);
if (val != kWiFiStationMode_ApplicationControlled)
{
mWiFiStationMode = val;
DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL);
}
if (mWiFiStationMode != val)
{
ChipLogProgress(DeviceLayer, "WiFi station mode change: %s -> %s", WiFiStationModeToStr(mWiFiStationMode),
WiFiStationModeToStr(val));
mWiFiStationMode = val;
/* Schedule work for disabled case causes station mode not getting enabled */
if (mWiFiStationMode != kWiFiStationMode_Disabled)
{
DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL);
}
else
{
/* Call Drive Station directly to disable directly instead of scheduling */
DriveStationState();
}
}

mWiFiStationMode = val;
exit:
return err;
}
Expand Down Expand Up @@ -200,21 +205,38 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
// Ensure that P6 station mode is enabled.
err = Internal::P6Utils::EnableStationMode();
SuccessOrExit(err);
// If the code has been compiled with a default WiFi station provision, configure that now.
if (CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID[0] != 0)
// If there is no persistent station provision...
if (!IsWiFiStationProvisioned())
{
ChipLogProgress(DeviceLayer, "Setting default WiFi station configuration (SSID: %s)", CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID);

// Set a default station configuration.
wifi_config_t wifiConfig;
memset(&wifiConfig, 0, sizeof(wifiConfig));
memcpy(wifiConfig.sta.ssid, CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID,
min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID), sizeof(wifiConfig.sta.ssid)));
memcpy(wifiConfig.sta.password, CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD,
min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD), sizeof(wifiConfig.sta.password)));
wifiConfig.sta.security = CHIP_DEVICE_CONFIG_DEFAULT_STA_SECURITY;
err = Internal::P6Utils::p6_wifi_set_config(WIFI_IF_STA, &wifiConfig);
SuccessOrExit(err);
// If the code has been compiled with a default WiFi station provision, configure that now.
if (CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID[0] != 0)
{
ChipLogProgress(DeviceLayer, "Setting default WiFi station configuration (SSID: %s)",
CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID);

// Set a default station configuration.
wifi_config_t wifiConfig;
memset(&wifiConfig, 0, sizeof(wifiConfig));
memcpy(wifiConfig.sta.ssid, CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID,
min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID), sizeof(wifiConfig.sta.ssid)));
memcpy(wifiConfig.sta.password, CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD,
min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD), sizeof(wifiConfig.sta.password)));
wifiConfig.sta.security = CHIP_DEVICE_CONFIG_DEFAULT_STA_SECURITY;
err = Internal::P6Utils::p6_wifi_set_config(WIFI_IF_STA, &wifiConfig);
SuccessOrExit(err);

// Enable WiFi station mode.
ReturnErrorOnFailure(SetWiFiStationMode(kWiFiStationMode_Enabled));
}
else
{
ReturnErrorOnFailure(SetWiFiStationMode(kWiFiStationMode_Disabled));
}
}
else
{
// Enable WiFi station mode.
ReturnErrorOnFailure(SetWiFiStationMode(kWiFiStationMode_Enabled));
}
// Force AP mode off for now.
err = Internal::P6Utils::SetAPMode(false);
Expand Down Expand Up @@ -474,9 +496,6 @@ void ConnectivityManagerImpl::DriveStationState()
CHIP_ERROR err = CHIP_NO_ERROR;
bool stationConnected;

// Refresh the current station mode by reading the configuration from storage.
GetWiFiStationMode();

// If the station interface is NOT under application control...
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled)
{
Expand Down
Loading

0 comments on commit 408ff8f

Please sign in to comment.