Skip to content

Commit

Permalink
Adding config checks for fucntions specific to only wifi and thread i…
Browse files Browse the repository at this point in the history
…n NetworkCommissioning
  • Loading branch information
shripad621git committed May 3, 2024
1 parent f6b3594 commit 3867202
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/app/clusters/network-commissioning/network-commissioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ using namespace DeviceLayer::NetworkCommissioning;
namespace {

// For WiFi and Thread scan results, each item will cost ~60 bytes in TLV, thus 15 is a safe upper bound of scan results.
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP || CHIP_DEVICE_CONFIG_ENABLE_THREAD
constexpr size_t kMaxNetworksInScanResponse = 15;
#endif

constexpr uint16_t kCurrentClusterRevision = 2;

Expand Down Expand Up @@ -230,17 +232,21 @@ void Instance::InvokeCommand(HandlerContext & ctxt)
ctxt, [this](HandlerContext & ctx, const auto & req) { HandleScanNetworks(ctx, req); });
return;

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
case Commands::AddOrUpdateWiFiNetwork::Id:
VerifyOrReturn(mFeatureFlags.Has(Feature::kWiFiNetworkInterface));
HandleCommand<Commands::AddOrUpdateWiFiNetwork::DecodableType>(
ctxt, [this](HandlerContext & ctx, const auto & req) { HandleAddOrUpdateWiFiNetwork(ctx, req); });
return;
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
case Commands::AddOrUpdateThreadNetwork::Id:
VerifyOrReturn(mFeatureFlags.Has(Feature::kThreadNetworkInterface));
HandleCommand<Commands::AddOrUpdateThreadNetwork::DecodableType>(
ctxt, [this](HandlerContext & ctx, const auto & req) { HandleAddOrUpdateThreadNetwork(ctx, req); });
return;
#endif

case Commands::RemoveNetwork::Id:
VerifyOrReturn(mFeatureFlags.Has(Feature::kWiFiNetworkInterface) || mFeatureFlags.Has(Feature::kThreadNetworkInterface));
Expand Down Expand Up @@ -543,6 +549,7 @@ bool CheckFailSafeArmed(CommandHandlerInterface::HandlerContext & ctx)

} // namespace

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
void Instance::HandleAddOrUpdateWiFiNetwork(HandlerContext & ctx, const Commands::AddOrUpdateWiFiNetwork::DecodableType & req)
{
MATTER_TRACE_SCOPE("HandleAddOrUpdateWiFiNetwork", "NetworkCommissioning");
Expand Down Expand Up @@ -618,6 +625,7 @@ void Instance::HandleAddOrUpdateWiFiNetwork(HandlerContext & ctx, const Commands
ReportNetworksListChanged();
}
}
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_PDC
void Instance::HandleAddOrUpdateWiFiNetworkWithPDC(HandlerContext & ctx,
Expand Down Expand Up @@ -725,6 +733,7 @@ void Instance::HandleAddOrUpdateWiFiNetworkWithPDC(HandlerContext & ctx,
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_PDC

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
void Instance::HandleAddOrUpdateThreadNetwork(HandlerContext & ctx, const Commands::AddOrUpdateThreadNetwork::DecodableType & req)
{
MATTER_TRACE_SCOPE("HandleAddOrUpdateThreadNetwork", "NetworkCommissioning");
Expand All @@ -745,6 +754,7 @@ void Instance::HandleAddOrUpdateThreadNetwork(HandlerContext & ctx, const Comman
UpdateBreadcrumb(req.breadcrumb);
}
}
#endif

void Instance::UpdateBreadcrumb(const Optional<uint64_t> & breadcrumb)
{
Expand Down Expand Up @@ -977,6 +987,7 @@ void Instance::OnResult(Status commissioningError, CharSpan debugText, int32_t i
}
}

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
void Instance::OnFinished(Status status, CharSpan debugText, ThreadScanResponseIterator * networks)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -1090,7 +1101,9 @@ void Instance::OnFinished(Status status, CharSpan debugText, ThreadScanResponseI
}
networks->Release();
}
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
void Instance::OnFinished(Status status, CharSpan debugText, WiFiScanResponseIterator * networks)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -1170,6 +1183,7 @@ void Instance::OnFinished(Status status, CharSpan debugText, WiFiScanResponseIte
networks->Release();
}
}
#endif

void Instance::OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
{
Expand Down
12 changes: 12 additions & 0 deletions src/app/clusters/network-commissioning/network-commissioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ class Instance : public CommandHandlerInterface,
void OnResult(DeviceLayer::NetworkCommissioning::Status commissioningError, CharSpan errorText,
int32_t interfaceStatus) override;

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
// WiFiDriver::ScanCallback
void OnFinished(DeviceLayer::NetworkCommissioning::Status err, CharSpan debugText,
DeviceLayer::NetworkCommissioning::WiFiScanResponseIterator * networks) override;
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
// ThreadDriver::ScanCallback
void OnFinished(DeviceLayer::NetworkCommissioning::Status err, CharSpan debugText,
DeviceLayer::NetworkCommissioning::ThreadScanResponseIterator * networks) override;
#endif

private:
static void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
Expand Down Expand Up @@ -120,9 +124,17 @@ class Instance : public CommandHandlerInterface,

// Actual handlers of the commands
void HandleScanNetworks(HandlerContext & ctx, const Commands::ScanNetworks::DecodableType & req);

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
void HandleAddOrUpdateWiFiNetwork(HandlerContext & ctx, const Commands::AddOrUpdateWiFiNetwork::DecodableType & req);
#endif

void HandleAddOrUpdateWiFiNetworkWithPDC(HandlerContext & ctx, const Commands::AddOrUpdateWiFiNetwork::DecodableType & req);

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
void HandleAddOrUpdateThreadNetwork(HandlerContext & ctx, const Commands::AddOrUpdateThreadNetwork::DecodableType & req);
#endif

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);
Expand Down
6 changes: 6 additions & 0 deletions src/include/platform/NetworkCommissioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class WirelessDriver : public Internal::BaseDriver
class WiFiDriver : public Internal::WirelessDriver
{
public:
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
class ScanCallback
{
public:
Expand All @@ -264,10 +265,12 @@ class WiFiDriver : public Internal::WirelessDriver
* iterator might be not fully consumed (i.e. There are too many networks scanned to fit in the buffer for scan response
* message.)
*/

virtual void OnFinished(Status status, CharSpan debugText, WiFiScanResponseIterator * networks) = 0;

virtual ~ScanCallback() = default;
};
#endif

/**
* @brief Adds or updates a WiFi network on the device. The driver should fill the outDebugText field to pass any human-readable
Expand Down Expand Up @@ -387,6 +390,8 @@ class WiFiDriver : public Internal::WirelessDriver
class ThreadDriver : public Internal::WirelessDriver
{
public:
*/
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
class ScanCallback
{
public:
Expand All @@ -402,6 +407,7 @@ class ThreadDriver : public Internal::WirelessDriver

virtual ~ScanCallback() = default;
};
#endif

/**
* @brief Adds or updates a Thread network on the device. The driver should fill the outDebugText field to pass any
Expand Down

0 comments on commit 3867202

Please sign in to comment.