Skip to content

Commit

Permalink
Merge branch 'master' into optimze-microwave-oven-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mideayanghui committed Nov 22, 2023
2 parents c025ee6 + 90f36a4 commit 42fe2c7
Show file tree
Hide file tree
Showing 50 changed files with 524 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,7 @@ server cluster AdministratorCommissioning = 60 {
octet_string<32> salt = 4;
}

request struct OpenBasicCommissioningWindowRequest {
int16u commissioningTimeout = 0;
}

timed command access(invoke: administer) OpenCommissioningWindow(OpenCommissioningWindowRequest): DefaultSuccess = 0;
timed command access(invoke: administer) OpenBasicCommissioningWindow(OpenBasicCommissioningWindowRequest): DefaultSuccess = 1;
timed command access(invoke: administer) RevokeCommissioning(): DefaultSuccess = 2;
}

Expand Down Expand Up @@ -1917,7 +1912,6 @@ endpoint 0 {
ram attribute clusterRevision default = 0x0001;

handle command OpenCommissioningWindow;
handle command OpenBasicCommissioningWindow;
handle command RevokeCommissioning;
}

Expand Down Expand Up @@ -1973,7 +1967,7 @@ endpoint 1 {
callback attribute eventList;
callback attribute attributeList default = 0;
ram attribute featureMap default = 0;
ram attribute clusterRevision default = 2;
ram attribute clusterRevision default = 4;

handle command Identify;
handle command TriggerEffect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1633,14 +1633,6 @@
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "OpenBasicCommissioningWindow",
"code": 1,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "RevokeCommissioning",
"code": 2,
Expand Down Expand Up @@ -2302,7 +2294,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "2",
"defaultValue": "4",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5557,7 +5557,7 @@ endpoint 0 {
ram attribute timeZoneDatabase default = 0;
callback attribute timeZoneListMaxSize default = 3;
callback attribute DSTOffsetListMaxSize;
ram attribute supportsDNSResolve default = false;
ram attribute supportsDNSResolve default = true;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4926,7 +4926,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "false",
"defaultValue": "true",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down Expand Up @@ -21724,6 +21724,7 @@
"endpointId": 65534,
"networkId": 0
}

]
}

Expand Down
17 changes: 12 additions & 5 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <platform/PlatformManager.h>

#include "app/clusters/network-commissioning/network-commissioning.h"
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/endpoint-config-api.h>
Expand Down Expand Up @@ -238,15 +239,15 @@ void InitNetworkCommissioning()
using chip::Shell::Engine;
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
#if CHIP_DEVICE_CONFIG_ENABLE_WPA && CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
/*
* The device shall check every kWiFiStartCheckTimeUsec whether Wi-Fi management
* has been fully initialized. If after kWiFiStartCheckAttempts Wi-Fi management
* still hasn't been initialized, the device configuration is reset, and device
* needs to be paired again.
*/
static constexpr useconds_t kWiFiStartCheckTimeUsec = 100 * 1000; // 100 ms
static constexpr uint8_t kWiFiStartCheckAttempts = 5;
static constexpr useconds_t kWiFiStartCheckTimeUsec = WIFI_START_CHECK_TIME_USEC;
static constexpr uint8_t kWiFiStartCheckAttempts = WIFI_START_CHECK_ATTEMPTS;
#endif

namespace {
Expand All @@ -264,6 +265,11 @@ void EventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
{
ChipLogProgress(DeviceLayer, "Receive kCHIPoBLEConnectionEstablished");
}
else if ((event->Type == chip::DeviceLayer::DeviceEventType::kInternetConnectivityChange))
{
// Restart the server on connectivity change
app::DnssdServer::Instance().StartServer();
}
}

void Cleanup()
Expand Down Expand Up @@ -298,7 +304,7 @@ void StopSignalHandler(int signal)

} // namespace

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
#if CHIP_DEVICE_CONFIG_ENABLE_WPA && CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
static bool EnsureWiFiIsStarted()
{
for (int cnt = 0; cnt < kWiFiStartCheckAttempts; cnt++)
Expand Down Expand Up @@ -462,9 +468,10 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true);
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
#if CHIP_DEVICE_CONFIG_ENABLE_WPA && CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
if (LinuxDeviceOptions::GetInstance().mWiFi)
{
// Start WiFi management in Concurrent mode
DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();
if (!EnsureWiFiIsStarted())
{
Expand Down
4 changes: 1 addition & 3 deletions src/app/FailSafeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ void FailSafeContext::SetFailSafeArmed(bool armed)
#if CHIP_CONFIG_ENABLE_ICD_SERVER
if (IsFailSafeArmed() != armed)
{
ICDListener::KeepActiveFlags activeRequest = ICDListener::KeepActiveFlags::kFailSafeArmed;
armed ? ICDNotifier::GetInstance().BroadcastActiveRequestNotification(activeRequest)
: ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(activeRequest);
ICDNotifier::GetInstance().BroadcastActiveRequest(ICDListener::KeepActiveFlag::kFailSafeArmed, armed);
}
#endif
mFailSafeArmed = armed;
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/CommandDataIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Parser : public StructParser
/**
* @brief Get the provided command reference associated with the CommandData
*
* @param [in] apRef A pointer to apRef
* @param [out] apRef A pointer to apRef
*
* @return #CHIP_NO_ERROR on success
* #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
Expand Down
18 changes: 18 additions & 0 deletions src/app/MessageDef/CommandStatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ CHIP_ERROR CommandStatusIB::Parser::PrettyPrint() const
PRETTY_PRINT_DECDEPTH();
}
break;
case to_underlying(Tag::kRef):
VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
{
uint16_t reference;
ReturnErrorOnFailure(reader.Get(reference));
PRETTY_PRINT("\tRef = 0x%x,", reference);
}
break;
default:
PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
break;
Expand Down Expand Up @@ -108,6 +116,11 @@ CHIP_ERROR CommandStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apEr
return apErrorStatus->Init(reader);
}

CHIP_ERROR CommandStatusIB::Parser::GetRef(uint16_t * const apRef) const
{
return GetUnsignedInteger(to_underlying(Tag::kRef), apRef);
}

CommandPathIB::Builder & CommandStatusIB::Builder::CreatePath()
{
if (mError == CHIP_NO_ERROR)
Expand All @@ -126,6 +139,11 @@ StatusIB::Builder & CommandStatusIB::Builder::CreateErrorStatus()
return mErrorStatus;
}

CHIP_ERROR CommandStatusIB::Builder::Ref(const uint16_t aRef)
{
return mpWriter->Put(TLV::ContextTag(Tag::kRef), aRef);
}

CHIP_ERROR CommandStatusIB::Builder::EndOfCommandStatusIB()
{
EndOfContainer();
Expand Down
21 changes: 21 additions & 0 deletions src/app/MessageDef/CommandStatusIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum class Tag : uint8_t
{
kPath = 0,
kErrorStatus = 1,
kRef = 2,
};

class Parser : public StructParser
Expand Down Expand Up @@ -67,6 +68,17 @@ class Parser : public StructParser
* #CHIP_END_OF_TLV if there is no such element
*/
CHIP_ERROR GetErrorStatus(StatusIB::Parser * const apErrorStatus) const;

/**
* @brief Get the provided command reference associated with the CommandStatus
*
* @param [out] apRef A pointer to apRef
*
* @return #CHIP_NO_ERROR on success
* #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
* #CHIP_END_OF_TLV if there is no such element
*/
CHIP_ERROR GetRef(uint16_t * const apRef) const;
};

class Builder : public StructBuilder
Expand All @@ -86,6 +98,15 @@ class Builder : public StructBuilder
*/
StatusIB::Builder & CreateErrorStatus();

/**
* @brief Inject Command Ref into the TLV stream.
*
* @param [in] aRef refer to the CommandRef to set in CommandStatusIB.
*
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR Ref(const uint16_t aRef);

/**
* @brief Mark the end of this CommandStatusIB
*
Expand Down
32 changes: 31 additions & 1 deletion src/app/clusters/network-commissioning/network-commissioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,18 @@ void Instance::InvokeCommand(HandlerContext & ctxt)
ctxt, [this](HandlerContext & ctx, const auto & req) { HandleRemoveNetwork(ctx, req); });
return;

case Commands::ConnectNetwork::Id:
case Commands::ConnectNetwork::Id: {
VerifyOrReturn(mFeatureFlags.Has(Feature::kWiFiNetworkInterface) || mFeatureFlags.Has(Feature::kThreadNetworkInterface));
#if CONFIG_NETWORK_LAYER_BLE && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
// If commissionee does not support Concurrent Connections, request the BLE to be stopped.
// Start the ConnectNetwork, but this will not complete until the BLE is off.
ChipLogProgress(NetworkProvisioning, "Closing BLE connections due to non-concurrent mode");
DeviceLayer::DeviceControlServer::DeviceControlSvr().PostCloseAllBLEConnectionsToOperationalNetworkEvent();
#endif
HandleCommand<Commands::ConnectNetwork::DecodableType>(
ctxt, [this](HandlerContext & ctx, const auto & req) { HandleConnectNetwork(ctx, req); });
return;
}

case Commands::ReorderNetwork::Id:
VerifyOrReturn(mFeatureFlags.Has(Feature::kWiFiNetworkInterface) || mFeatureFlags.Has(Feature::kThreadNetworkInterface));
Expand Down Expand Up @@ -623,7 +630,20 @@ void Instance::HandleConnectNetwork(HandlerContext & ctx, const Commands::Connec
memcpy(mConnectingNetworkID, req.networkID.data(), mConnectingNetworkIDLen);
mAsyncCommandHandle = CommandHandler::Handle(&ctx.mCommandHandler);
mCurrentOperationBreadcrumb = req.breadcrumb;

// In Non-concurrent mode postpone the final execution of ConnectNetwork until the operational
// network has been fully brought up and kWiFiDeviceAvailable is delivered.
// mConnectingNetworkIDLen and mConnectingNetworkID contains the received SSID
#if CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
mpWirelessDriver->ConnectNetwork(req.networkID, this);
#endif
}

void Instance::HandleNonConcurrentConnectNetwork()
{
ByteSpan nonConcurrentNetworkID = ByteSpan(mConnectingNetworkID, mConnectingNetworkIDLen);
ChipLogProgress(NetworkProvisioning, "HandleNonConcurrentConnectNetwork() SSID=%s", mConnectingNetworkID);
mpWirelessDriver->ConnectNetwork(nonConcurrentNetworkID, this);
}

void Instance::HandleReorderNetwork(HandlerContext & ctx, const Commands::ReorderNetwork::DecodableType & req)
Expand Down Expand Up @@ -759,7 +779,13 @@ void Instance::OnResult(Status commissioningError, CharSpan debugText, int32_t i
memcpy(mLastNetworkID, mConnectingNetworkID, mLastNetworkIDLen);
mLastNetworkingStatusValue.SetNonNull(commissioningError);

#if CONFIG_NETWORK_LAYER_BLE && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
ChipLogProgress(NetworkProvisioning, "Non-concurrent mode, ConnectNetworkResponse will NOT be sent");
// Do not send the ConnectNetworkResponse if in non-concurrent mode
// Issue #30576 raised to modify CommandHandler to notify it if no response required
#else
commandHandle->AddResponse(mPath, response);
#endif
if (commissioningError == Status::kSuccess)
{
CommitSavedBreadcrumb();
Expand Down Expand Up @@ -956,6 +982,10 @@ void Instance::OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event
{
this_->OnFailSafeTimerExpired();
}
else if (event->Type == DeviceLayer::DeviceEventType::kWiFiDeviceAvailable)
{
this_->HandleNonConcurrentConnectNetwork();
}
}

void Instance::OnCommissioningComplete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Instance : public CommandHandlerInterface,
void HandleRemoveNetwork(HandlerContext & ctx, const Commands::RemoveNetwork::DecodableType & req);
void HandleConnectNetwork(HandlerContext & ctx, const Commands::ConnectNetwork::DecodableType & req);
void HandleReorderNetwork(HandlerContext & ctx, const Commands::ReorderNetwork::DecodableType & req);
void HandleNonConcurrentConnectNetwork(void);
void HandleQueryIdentity(HandlerContext & ctx, const Commands::QueryIdentity::DecodableType & req);

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ bool DefaultTimeSyncDelegate::IsNTPAddressValid(chip::CharSpan ntp)

bool DefaultTimeSyncDelegate::IsNTPAddressDomain(chip::CharSpan ntp)
{
// placeholder implementation
return false;
// For now, assume anything that includes a . is a domain name.
// Delegates are free to evaluate this properly if they actually HAVE domain
// name resolution, rather than just implementing a dummy for testing.
return !IsNTPAddressValid(ntp) && (memchr(ntp.data(), '.', ntp.size()) != nullptr);
}

CHIP_ERROR DefaultTimeSyncDelegate::UpdateTimeFromPlatformSource(chip::Callback::Callback<OnTimeSyncCompletion> * callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,24 +1284,19 @@ bool emberAfTimeSynchronizationClusterSetDefaultNTPCallback(
commandObj->AddStatus(commandPath, Status::ConstraintError);
return true;
}
if (!GetDelegate()->IsNTPAddressValid(dNtpChar.Value()))
bool dnsResolve;
if (EMBER_ZCL_STATUS_SUCCESS != SupportsDNSResolve::Get(commandPath.mEndpointId, &dnsResolve))
{
commandObj->AddStatus(commandPath, Status::InvalidCommand);
commandObj->AddStatus(commandPath, Status::Failure);
return true;
}
if (GetDelegate()->IsNTPAddressDomain(dNtpChar.Value()))
bool isDomain = GetDelegate()->IsNTPAddressDomain(dNtpChar.Value());
bool isIPv6 = GetDelegate()->IsNTPAddressValid(dNtpChar.Value());
bool useable = isIPv6 || (isDomain && dnsResolve);
if (!useable)
{
bool dnsResolve;
if (EMBER_ZCL_STATUS_SUCCESS != SupportsDNSResolve::Get(commandPath.mEndpointId, &dnsResolve))
{
commandObj->AddStatus(commandPath, Status::Failure);
return true;
}
if (!dnsResolve)
{
commandObj->AddStatus(commandPath, Status::InvalidCommand);
return true;
}
commandObj->AddStatus(commandPath, Status::InvalidCommand);
return true;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/app/icd/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ source_set("sender") {

public_deps = [
":cluster",
":notifier",
"${chip_root}/src/credentials:credentials",
"${chip_root}/src/lib/address_resolve:address_resolve",
"${chip_root}/src/protocols/secure_channel",
Expand Down
Loading

0 comments on commit 42fe2c7

Please sign in to comment.