Skip to content

Commit

Permalink
Sync with TE9
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesluo11 committed May 9, 2022
1 parent d77202d commit 623951e
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 92 deletions.
3 changes: 3 additions & 0 deletions config/beken/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ group("beken") {
deps = [ "${chip_root}/src/lib" ]

}
group("default") {
deps = [ ":beken" ]
}
1 change: 0 additions & 1 deletion config/beken/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ chip_build_tests = false
chip_inet_config_enable_tcp_endpoint = true
chip_inet_config_enable_udp_endpoint = true

chip_bypass_rendezvous = false
chip_config_network_layer_ble = true
chip_config_memory_management = "platform"
chip_enable_additional_data_advertising = true
Expand Down
57 changes: 39 additions & 18 deletions examples/lighting-app/beken/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>

//#if CONFIG_ENABLE_OTA_REQUESTOR
#include "app/clusters/ota-requestor/BDXDownloader.h"
#include "app/clusters/ota-requestor/OTARequestor.h"
#include "platform/Beken/OTAImageProcessorImpl.h"
#include "platform/GenericOTARequestorDriver.h"
#include "app/clusters/ota-requestor/DefaultOTARequestorStorage.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
//#endif

using chip::OTAImageProcessorImpl;
//using chip::OTAImageProcessorImpl;
using chip::BDXDownloader;
using chip::ByteSpan;
using chip::EndpointId;
Expand All @@ -50,8 +52,8 @@ using chip::NodeId;
using chip::OnDeviceConnected;
using chip::OnDeviceConnectionFailure;
using chip::OTADownloader;
using chip::OTAImageProcessorParams;
using chip::OTARequestor;
//using chip::OTAImageProcessorParams;
//using chip::OTARequestor;
using chip::VendorId;
using chip::Callback::Callback;
using chip::System::Layer;
Expand All @@ -69,10 +71,10 @@ using namespace ::chip::System;
namespace {

static DeviceCallbacks EchoCallbacks;
OTARequestor gRequestorCore;
GenericOTARequestorDriver gRequestorUser;
//OTARequestor gRequestorCore;
//GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
//OTAImageProcessorImpl gImageProcessor;

app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::BekenWiFiDriver::GetInstance()));
Expand All @@ -89,21 +91,21 @@ bool isRendezvousBLE()
extern "C" void QueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling QueryImageCmdHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
//static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
}

extern "C" void ApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling ApplyUpdateCmdHandler");

static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
//static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
}

extern "C" void NotifyUpdateAppliedHandler(uint32_t version)
{
ChipLogProgress(DeviceLayer, "NotifyUpdateApplied");

static_cast<OTARequestor *>(GetRequestorInstance())->NotifyUpdateApplied(version);
//static_cast<OTARequestor *>(GetRequestorInstance())->NotifyUpdateApplied(version);
}

/*********************************************************************
Expand Down Expand Up @@ -145,9 +147,10 @@ extern "C" void BkQueryImageCmdHandler(char *pcWriteBuffer, int xWriteBufferLen,
ChipLogProgress(DeviceLayer,"cmd param error ");
return ;
}
#endif

QueryImageCmdHandler();
ChipLogProgress(DeviceLayer,"QueryImageCmdHandler begin");
#endif

return ;
}
Expand All @@ -162,7 +165,7 @@ extern "C" void BkQueryImageCmdHandler(char *pcWriteBuffer, int xWriteBufferLen,
*******************************************************************/
extern "C" void BkApplyUpdateCmdHandler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv )
{
ApplyUpdateCmdHandler();
//ApplyUpdateCmdHandler();
ChipLogProgress(DeviceLayer,"ApplyUpdateCmdHandler send request");

return ;
Expand All @@ -178,6 +181,7 @@ extern "C" void BkApplyUpdateCmdHandler(char *pcWriteBuffer, int xWriteBufferLen
*******************************************************************/
extern "C" void BkNotifyUpdateApplied(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv )
{
#if 0
uint32_t dwLoop = 0;
uint32_t version = 0;

Expand Down Expand Up @@ -205,12 +209,13 @@ extern "C" void BkNotifyUpdateApplied(char *pcWriteBuffer, int xWriteBufferLen,

NotifyUpdateAppliedHandler( version);
ChipLogProgress(DeviceLayer,"NotifyUpdateApplied send request");

#endif
return ;
}

static void InitOTARequestor(void)
{
#if 0
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);
ChipLogProgress(DeviceLayer,"InitOTARequestor gRequestorCore init");
Expand All @@ -234,7 +239,7 @@ static void InitOTARequestor(void)
// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

#endif
// Initialize and interconnect the Requestor and Image Processor objects -- END
}
//#endif // CONFIG_ENABLE_OTA_REQUESTOR
Expand Down Expand Up @@ -341,14 +346,30 @@ extern "C" bool __sync_bool_compare_and_swap_4(volatile void* ptr, unsigned int
return false;
}
}

extern "C" bool __sync_bool_compare_and_swap_1(volatile void* ptr, unsigned char oldval, unsigned char newval)
{
if (*(unsigned char*)ptr == oldval)
{
*(unsigned char*)ptr = newval;
return true;
}
else
{
return false;
}
}

/* stub for __libc_init_array */
extern "C" void _fini(void) { }
extern "C" void _init(void) {;}

static void InitServer(intptr_t context)
{
// Init ZCL Data Model and CHIP App Server
chip::Server::GetInstance().Init();
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
chip::Server::GetInstance().Init(initParams);

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
Expand Down
21 changes: 13 additions & 8 deletions src/platform/Beken/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
/* this file behaves like a config.h, comes first */
#include <crypto/CHIPCryptoPAL.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/CommissionableDataProvider.h>


#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <ble/CHIPBleServiceData.h>
Expand Down Expand Up @@ -635,7 +637,7 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)

// If the device name is not specified, generate a CHIP-standard name based on the bottom digits of the Chip device id.
uint16_t discriminator;
SuccessOrExit(err = ConfigurationMgr().GetSetupDiscriminator(discriminator));
SuccessOrExit(err = GetCommissionableDataProvider()->GetSetupDiscriminator(discriminator));

if (!mFlags.Has(Flags::kDeviceNameSet))
{
Expand Down Expand Up @@ -1063,20 +1065,23 @@ void BLEManagerImpl::HandleC3CharRead(void * param)
chip::System::PacketBufferHandle bufferHandle;
read_req_t *r_req = (read_req_t *)param;

char serialNumber[ConfigurationManager::kMaxSerialNumberLength + 1];
uint16_t lifetimeCounter = 0;
AdditionalDataPayloadGeneratorParams additionalDataPayloadParams;
BitFlags<AdditionalDataFields> additionalDataFields;

#if CHIP_ENABLE_ROTATING_DEVICE_ID
err = ConfigurationMgr().GetSerialNumber(serialNumber, sizeof(serialNumber));

#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
uint8_t rotatingDeviceIdUniqueId[ConfigurationManager::kRotatingDeviceIDUniqueIDLength] = {};
MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId);

err = ConfigurationMgr().GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan);
SuccessOrExit(err);
err = ConfigurationMgr().GetLifetimeCounter(lifetimeCounter);
err = ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter);
SuccessOrExit(err);

additionalDataPayloadParams.rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueIdSpan;
additionalDataFields.Set(AdditionalDataFields::RotatingDeviceId);
#endif /* CHIP_ENABLE_ROTATING_DEVICE_ID */

err = AdditionalDataPayloadGenerator().generateAdditionalDataPayload(lifetimeCounter, serialNumber, strlen(serialNumber),
err = AdditionalDataPayloadGenerator().generateAdditionalDataPayload(additionalDataPayloadParams,
bufferHandle, additionalDataFields);
SuccessOrExit(err);
if(r_req->value == NULL)
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Beken/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static_library("Beken") {
"KeyValueStoreManagerImpl.h",
"Logging.cpp",
"LwIPCoreLock.cpp",
"OTAImageProcessorImpl.cpp",
"OTAImageProcessorImpl.h",
#"OTAImageProcessorImpl.cpp",
#"OTAImageProcessorImpl.h",
"PlatformManagerImpl.cpp",
"PlatformManagerImpl.h",
"SoftwareUpdateManagerImpl.h",
Expand Down
11 changes: 2 additions & 9 deletions src/platform/Beken/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <platform/Beken/BekenConfig.h>
#include <platform/ConfigurationManager.h>
#include <platform/DiagnosticDataProvider.h>
#include <platform/internal/GenericConfigurationManagerImpl.cpp>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>

Expand All @@ -48,7 +48,6 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
{
CHIP_ERROR err;
uint32_t rebootCount;
bool failSafeArmed;

ChipLogProgress(DeviceLayer, "ConfigurationManagerImpl::Init");
// Force initialization of NVS namespaces if they doesn't already exist.
Expand Down Expand Up @@ -82,20 +81,14 @@ CHIP_ERROR ConfigurationManagerImpl::Init()

if (!BekenConfig::ConfigValueExists(BekenConfig::kCounterKey_BootReason))
{
err = StoreBootReason(DiagnosticDataProvider::BootReasonType::Unspecified);
err = StoreBootReason(to_underlying(BootReasonType::kUnspecified));
SuccessOrExit(err);
}

// Initialize the generic implementation base class.
err = Internal::GenericConfigurationManagerImpl<BekenConfig>::Init();
SuccessOrExit(err);

// If the fail-safe was armed when the device last shutdown, initiate a factory reset.
if (GetFailSafeArmed(failSafeArmed) == CHIP_NO_ERROR && failSafeArmed)
{
ChipLogProgress(DeviceLayer, "Detected fail-safe armed on reboot; initiating factory reset");
InitiateFactoryReset();
}
err = CHIP_NO_ERROR;

exit:
Expand Down
6 changes: 3 additions & 3 deletions src/platform/Beken/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#include <platform/ConnectivityManager.h>

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <platform/internal/GenericConnectivityManagerImpl_BLE.cpp>
#include <platform/internal/GenericConnectivityManagerImpl_BLE.ipp>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <platform/internal/GenericConnectivityManagerImpl_Thread.cpp>
#include <platform/internal/GenericConnectivityManagerImpl_Thread.ipp>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.cpp>
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.ipp>
#endif

#include <platform/internal/BLEManager.h>
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Beken/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetTotalOperationalHours(uint32_t & total
return CHIP_ERROR_INVALID_TIME;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(uint8_t & bootReason)
CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason)
{
uint32_t reason = 0;

Expand All @@ -113,7 +113,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(uint8_t & bootReason)
if (err == CHIP_NO_ERROR)
{
VerifyOrReturnError(reason <= UINT8_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE);
bootReason = static_cast<uint8_t>(reason);
bootReason = static_cast<BootReasonType>(reason);
}

return err;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Beken/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
CHIP_ERROR GetRebootCount(uint16_t & rebootCount) override;
CHIP_ERROR GetUpTime(uint64_t & upTime) override;
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
CHIP_ERROR GetBootReason(uint8_t & bootReason) override;
CHIP_ERROR GetBootReason(BootReasonType & bootReason) override;

CHIP_ERROR GetNetworkInterfaces(NetworkInterface ** netifpp) override;
void ReleaseNetworkInterfaces(NetworkInterface * netifp) override;
Expand Down
17 changes: 4 additions & 13 deletions src/platform/Beken/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
}
else
{
err = CHIP_ERROR_INTERNAL;
err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
}

return err;
Expand Down Expand Up @@ -99,19 +99,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
{
uint32_t ret = 0;
CHIP_ERROR err = CHIP_NO_ERROR;

ret = bk_clean_data (GetKVNameSpaceName(key), key);

if (kNoErr == ret)
{
err = CHIP_NO_ERROR;
}
else
{
err = CHIP_ERROR_INTERNAL;
}

return err;
bk_clean_data (GetKVNameSpaceName(key), key);

return CHIP_NO_ERROR;
}

const char* KeyValueStoreManagerImpl::GetKVNameSpaceName(const char *key)
Expand Down
Loading

0 comments on commit 623951e

Please sign in to comment.