diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index 572aa2e2a789ff..2cdcaba762e6ff 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -108,37 +108,41 @@ void Instance::InvokeCommand(HandlerContext & ctxt) switch (ctxt.mRequestPath.mCommandId) { case Commands::ScanNetworks::Id: - VerifyOrReturn((mType & kFeatureMapWireless) != 0); + VerifyOrReturn(mFeatureFlags.Has(NetworkCommissioningFeature::kWiFiNetworkInterface) || + mFeatureFlags.Has(NetworkCommissioningFeature::kThreadNetworkInterface)); HandleCommand( ctxt, [this](HandlerContext & ctx, const auto & req) { HandleScanNetworks(ctx, req); }); return; case Commands::AddOrUpdateWiFiNetwork::Id: - VerifyOrReturn(mType == kFeatureMapWiFi); + VerifyOrReturn(mFeatureFlags.Has(NetworkCommissioningFeature::kWiFiNetworkInterface)); HandleCommand( ctxt, [this](HandlerContext & ctx, const auto & req) { HandleAddOrUpdateWiFiNetwork(ctx, req); }); return; case Commands::AddOrUpdateThreadNetwork::Id: - VerifyOrReturn(mType == kFeatureMapThread); + VerifyOrReturn(mFeatureFlags.Has(NetworkCommissioningFeature::kThreadNetworkInterface)); HandleCommand( ctxt, [this](HandlerContext & ctx, const auto & req) { HandleAddOrUpdateThreadNetwork(ctx, req); }); return; case Commands::RemoveNetwork::Id: - VerifyOrReturn((mType & kFeatureMapWireless) != 0); + VerifyOrReturn(mFeatureFlags.Has(NetworkCommissioningFeature::kWiFiNetworkInterface) || + mFeatureFlags.Has(NetworkCommissioningFeature::kThreadNetworkInterface)); HandleCommand( ctxt, [this](HandlerContext & ctx, const auto & req) { HandleRemoveNetwork(ctx, req); }); return; case Commands::ConnectNetwork::Id: - VerifyOrReturn((mType & kFeatureMapWireless) != 0); + VerifyOrReturn(mFeatureFlags.Has(NetworkCommissioningFeature::kWiFiNetworkInterface) || + mFeatureFlags.Has(NetworkCommissioningFeature::kThreadNetworkInterface)); HandleCommand( ctxt, [this](HandlerContext & ctx, const auto & req) { HandleConnectNetwork(ctx, req); }); return; case Commands::ReorderNetwork::Id: - VerifyOrReturn((mType & kFeatureMapWireless) != 0); + VerifyOrReturn(mFeatureFlags.Has(NetworkCommissioningFeature::kWiFiNetworkInterface) || + mFeatureFlags.Has(NetworkCommissioningFeature::kThreadNetworkInterface)); HandleCommand( ctxt, [this](HandlerContext & ctx, const auto & req) { HandleReorderNetwork(ctx, req); }); return; @@ -174,14 +178,14 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu }); case Attributes::ScanMaxTimeSeconds::Id: - if (mType & kFeatureMapWireless) + if (mpWirelessDriver != nullptr) { return aEncoder.Encode(mpWirelessDriver->GetScanNetworkTimeoutSeconds()); } return CHIP_NO_ERROR; case Attributes::ConnectMaxTimeSeconds::Id: - if (mType & kFeatureMapWireless) + if (mpWirelessDriver != nullptr) { return aEncoder.Encode(mpWirelessDriver->GetConnectNetworkTimeoutSeconds()); } @@ -201,7 +205,7 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu return aEncoder.Encode(Attributes::LastConnectErrorValue::TypeInfo::Type(0)); case Attributes::FeatureMap::Id: - return aEncoder.Encode(mType); + return aEncoder.Encode(mFeatureFlags); default: return CHIP_NO_ERROR; @@ -223,19 +227,20 @@ CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeVal void Instance::HandleScanNetworks(HandlerContext & ctx, const Commands::ScanNetworks::DecodableType & req) { - switch (mType) + + if (mFeatureFlags.Has(NetworkCommissioningFeature::kWiFiNetworkInterface)) { - case kFeatureMapWiFi: mAsyncCommandHandle = app::CommandHandler::Handle(&ctx.mCommandHandler); mpDriver.Get()->ScanNetworks(req.ssid, this); - return; - case kFeatureMapThread: + } + else if (mFeatureFlags.Has(NetworkCommissioningFeature::kThreadNetworkInterface)) + { mAsyncCommandHandle = app::CommandHandler::Handle(&ctx.mCommandHandler); mpDriver.Get()->ScanNetworks(this); - return; - default: + } + else + { ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::UnsupportedCommand); - return; } } @@ -414,7 +419,8 @@ void Instance::_OnCommissioningComplete(const DeviceLayer::ChipDeviceEvent * eve void Instance::OnCommissioningComplete(CHIP_ERROR err) { - VerifyOrReturn((mType & kFeatureMapWireless) != 0); + VerifyOrReturn(mpWirelessDriver != nullptr); + if (err == CHIP_NO_ERROR) { ChipLogDetail(Zcl, "Commissioning complete, notify platform driver to persist network credentails."); diff --git a/src/app/clusters/network-commissioning/network-commissioning.h b/src/app/clusters/network-commissioning/network-commissioning.h index 705b3879648f93..10b95a12cbe475 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.h +++ b/src/app/clusters/network-commissioning/network-commissioning.h @@ -66,16 +66,10 @@ class Instance : public CommandHandlerInterface, DeviceLayer::NetworkCommissioning::ThreadScanResponseIterator * networks) override; private: - static constexpr uint32_t kFeatureMapWiFi = 0b0000'0001; - static constexpr uint32_t kFeatureMapThread = 0b0000'0010; - static constexpr uint32_t kFeatureMapEthernet = 0b0000'0100; - - static constexpr uint32_t kFeatureMapWireless = 0b0000'0011; - static void _OnCommissioningComplete(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg); void OnCommissioningComplete(CHIP_ERROR err); - const uint32_t mType; + const BitFlags mFeatureFlags; DeviceLayer::NetworkCommissioning::Internal::WirelessDriver * const mpWirelessDriver; DeviceLayer::NetworkCommissioning::Internal::BaseDriver * const mpBaseDriver; @@ -97,24 +91,24 @@ class Instance : public CommandHandlerInterface, public: Instance(EndpointId aEndpointId, DeviceLayer::NetworkCommissioning::WiFiDriver * apDelegate) : CommandHandlerInterface(Optional(aEndpointId), Id), - AttributeAccessInterface(Optional(aEndpointId), Id), mType(kFeatureMapWiFi), mpWirelessDriver(apDelegate), - mpBaseDriver(apDelegate) + AttributeAccessInterface(Optional(aEndpointId), Id), + mFeatureFlags(NetworkCommissioningFeature::kWiFiNetworkInterface), mpWirelessDriver(apDelegate), mpBaseDriver(apDelegate) { mpDriver.Set(apDelegate); } Instance(EndpointId aEndpointId, DeviceLayer::NetworkCommissioning::ThreadDriver * apDelegate) : CommandHandlerInterface(Optional(aEndpointId), Id), - AttributeAccessInterface(Optional(aEndpointId), Id), mType(kFeatureMapThread), mpWirelessDriver(apDelegate), - mpBaseDriver(apDelegate) + AttributeAccessInterface(Optional(aEndpointId), Id), + mFeatureFlags(NetworkCommissioningFeature::kThreadNetworkInterface), mpWirelessDriver(apDelegate), mpBaseDriver(apDelegate) { mpDriver.Set(apDelegate); } Instance(EndpointId aEndpointId, DeviceLayer::NetworkCommissioning::EthernetDriver * apDelegate) : CommandHandlerInterface(Optional(aEndpointId), Id), - AttributeAccessInterface(Optional(aEndpointId), Id), mType(kFeatureMapEthernet), mpWirelessDriver(nullptr), - mpBaseDriver(apDelegate) + AttributeAccessInterface(Optional(aEndpointId), Id), + mFeatureFlags(NetworkCommissioningFeature::kEthernetNetworkInterface), mpWirelessDriver(nullptr), mpBaseDriver(apDelegate) {} virtual ~Instance() = default;