diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index f1e5a2c9b9c8d8..26f9168b4937a5 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -32,7 +32,6 @@ executable("chip-tool") { "commands/discover/DiscoverCommand.cpp", "commands/discover/DiscoverCommissionersCommand.cpp", "commands/pairing/PairingCommand.cpp", - "commands/pairing/RequestCommissioningCommand.cpp", "commands/payload/AdditionalDataParseCommand.cpp", "commands/payload/SetupPayloadParseCommand.cpp", "commands/reporting/ReportingCommand.cpp", diff --git a/examples/chip-tool/commands/pairing/Commands.h b/examples/chip-tool/commands/pairing/Commands.h index aa0f85f5bf1941..70008a924a0a8c 100644 --- a/examples/chip-tool/commands/pairing/Commands.h +++ b/examples/chip-tool/commands/pairing/Commands.h @@ -19,7 +19,7 @@ #pragma once #include "PairingCommand.h" -#include "RequestCommissioningCommand.h" + class Unpair : public PairingCommand { public: @@ -67,10 +67,8 @@ void registerCommandsPairing(Commands & commands) const char * clusterName = "Pairing"; commands_list clusterCommands = { - make_unique(), make_unique(), - make_unique(), make_unique(), - make_unique(), make_unique(), - make_unique(), make_unique(), + make_unique(), make_unique(), make_unique(), make_unique(), + make_unique(), make_unique(), make_unique(), }; commands.Register(clusterName, clusterCommands); diff --git a/examples/chip-tool/commands/pairing/RequestCommissioningCommand.cpp b/examples/chip-tool/commands/pairing/RequestCommissioningCommand.cpp deleted file mode 100644 index 8f56d09e988ddb..00000000000000 --- a/examples/chip-tool/commands/pairing/RequestCommissioningCommand.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "RequestCommissioningCommand.h" - -using namespace ::chip; - -CHIP_ERROR RequestCommissioningCommand::Run() -{ - ChipLogProgress(chipTool, "Announcing commissionable node for %d sec", GetWaitDurationInSeconds()); - return mCommissionableNodeController.AdvertiseCommissionableNode(); -} diff --git a/examples/chip-tool/commands/pairing/RequestCommissioningCommand.h b/examples/chip-tool/commands/pairing/RequestCommissioningCommand.h deleted file mode 100644 index 86c3efb5c26afa..00000000000000 --- a/examples/chip-tool/commands/pairing/RequestCommissioningCommand.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once - -#include "../common/Command.h" -#include - -/** - * @brief - * RequestCommissioningCommand, when issued by the user, will request a - * user selected Commissioner to begin commissioning the requesting device - * (i.e. a Commissionee). This will involve the Commissionee entering - * commissioning mode, displaying an onboarding payload to the user, - * initiating a User directed commissioning request and Advertising itself - * as a Commissionable Node over DNS-SD. - */ -class RequestCommissioningCommand : public Command -{ -public: - RequestCommissioningCommand() : Command("request-commissioning") {} - CHIP_ERROR Run() override; - uint16_t GetWaitDurationInSeconds() const override { return 3 * 60; } - -private: - chip::Controller::CommissionableNodeController mCommissionableNodeController; -}; diff --git a/src/app/server/Mdns.cpp b/src/app/server/Mdns.cpp index cba43450896688..6a62056246da49 100644 --- a/src/app/server/Mdns.cpp +++ b/src/app/server/Mdns.cpp @@ -23,10 +23,8 @@ #include #include #include -#if CONFIG_DEVICE_LAYER #include #include -#endif #include #include #include @@ -73,13 +71,11 @@ chip::ByteSpan FillMAC(uint8_t (&mac)[8]) return chip::ByteSpan(mac, 8); } #endif -#if CONFIG_DEVICE_LAYER if (DeviceLayer::ConfigurationMgr().GetPrimaryWiFiMACAddress(mac) == CHIP_NO_ERROR) { ChipLogDetail(Discovery, "Using wifi MAC for hostname"); return chip::ByteSpan(mac, 6); } -#endif ChipLogError(Discovery, "Wifi mac not known. Using a default."); uint8_t temp[6] = { 0xEE, 0xAA, 0xBA, 0xDA, 0xBA, 0xD0 }; memcpy(mac, temp, 6); @@ -97,14 +93,13 @@ CHIP_ERROR GetCommissionableInstanceName(char * buffer, size_t bufferLen) /// Set MDNS operational advertisement CHIP_ERROR AdvertiseOperational() { - uint64_t fabricId = 5544332211; // default value + uint64_t fabricId; -#if CONFIG_DEVICE_LAYER if (DeviceLayer::ConfigurationMgr().GetFabricId(fabricId) != CHIP_NO_ERROR) { ChipLogError(Discovery, "Fabric ID not known. Using a default"); + fabricId = 5544332211; } -#endif uint8_t mac[8]; @@ -144,16 +139,6 @@ CHIP_ERROR Advertise(bool commissionableNode) advertiseParameters.SetCommissionAdvertiseMode(commissionableNode ? chip::Mdns::CommssionAdvertiseMode::kCommissionableNode : chip::Mdns::CommssionAdvertiseMode::kCommissioner); - uint8_t mac[8]; - advertiseParameters.SetMac(FillMAC(mac)); - -#if CHIP_ENABLE_ROTATING_DEVICE_ID - char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength]; - ReturnErrorOnFailure(GenerateRotatingDeviceId(rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer))); - advertiseParameters.SetRotatingId(chip::Optional::Value(rotatingDeviceIdHexBuffer)); -#endif - -#if CONFIG_DEVICE_LAYER // TODO: device can re-enter commissioning mode after being fully provisioned // (additionalPairing == true) bool notYetCommissioned = !DeviceLayer::ConfigurationMgr().IsFullyProvisioned(); @@ -162,6 +147,9 @@ CHIP_ERROR Advertise(bool commissionableNode) char pairingInst[chip::Mdns::kKeyPairingInstructionMaxLength + 1]; + uint8_t mac[8]; + advertiseParameters.SetMac(FillMAC(mac)); + uint16_t value; if (DeviceLayer::ConfigurationMgr().GetVendorId(value) != CHIP_NO_ERROR) { @@ -201,6 +189,12 @@ CHIP_ERROR Advertise(bool commissionableNode) advertiseParameters.SetDeviceName(chip::Optional::Value(deviceName)); } +#if CHIP_ENABLE_ROTATING_DEVICE_ID + char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength]; + ReturnErrorOnFailure(GenerateRotatingDeviceId(rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer))); + advertiseParameters.SetRotatingId(chip::Optional::Value(rotatingDeviceIdHexBuffer)); +#endif + if (notYetCommissioned) { if (DeviceLayer::ConfigurationMgr().GetInitialPairingHint(value) != CHIP_NO_ERROR) @@ -241,7 +235,7 @@ CHIP_ERROR Advertise(bool commissionableNode) advertiseParameters.SetPairingInstr(chip::Optional::Value(pairingInst)); } } -#endif + auto & mdnsAdvertiser = chip::Mdns::ServiceAdvertiser::Instance(); ChipLogProgress(Discovery, "Advertise commission parameter vendorID=%u productID=%u discriminator=%04u/%02u", @@ -254,9 +248,8 @@ CHIP_ERROR Advertise(bool commissionableNode) void StartServer() { ChipLogProgress(Discovery, "Start dns-sd server"); - CHIP_ERROR err = CHIP_NO_ERROR; -#if CONFIG_DEVICE_LAYER - err = chip::Mdns::ServiceAdvertiser::Instance().Start(&chip::DeviceLayer::InetLayer, chip::Mdns::kMdnsPort); + CHIP_ERROR err = chip::Mdns::ServiceAdvertiser::Instance().Start(&chip::DeviceLayer::InetLayer, chip::Mdns::kMdnsPort); + // TODO: advertise this only when really operational once we support both // operational and commisioning advertising is supported. if (DeviceLayer::ConfigurationMgr().IsFullyProvisioned()) @@ -275,7 +268,7 @@ void StartServer() err = app::Mdns::AdvertiseCommissionableNode(); #endif } -#endif + #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY err = app::Mdns::AdvertiseCommisioner(); #endif @@ -294,16 +287,12 @@ CHIP_ERROR GenerateRotatingDeviceId(char rotatingDeviceIdHexBuffer[], size_t rot uint16_t lifetimeCounter = 0; size_t rotatingDeviceIdValueOutputSize = 0; -#if CONFIG_DEVICE_LAYER ReturnErrorOnFailure( chip::DeviceLayer::ConfigurationMgr().GetSerialNumber(serialNumber, sizeof(serialNumber), serialNumberSize)); ReturnErrorOnFailure(chip::DeviceLayer::ConfigurationMgr().GetLifetimeCounter(lifetimeCounter)); return AdditionalDataPayloadGenerator().generateRotatingDeviceId(lifetimeCounter, serialNumber, serialNumberSize, rotatingDeviceIdHexBuffer, rotatingDeviceIdHexBufferSize, rotatingDeviceIdValueOutputSize); -#else - error = CHIP_ERROR_NOT_IMPLEMENTED; -#endif } #endif diff --git a/src/controller/BUILD.gn b/src/controller/BUILD.gn index 766756f19c5c06..4281c341d8336f 100644 --- a/src/controller/BUILD.gn +++ b/src/controller/BUILD.gn @@ -18,9 +18,6 @@ static_library("controller") { output_name = "libChipController" sources = [ - "${chip_root}/src/app/server/Mdns.cpp", - "${chip_root}/src/app/server/Mdns.h", - "${chip_root}/src/app/server/Server.h", "AbstractMdnsDiscoveryController.cpp", "CHIPCluster.cpp", "CHIPCluster.h", diff --git a/src/controller/CHIPCommissionableNodeController.cpp b/src/controller/CHIPCommissionableNodeController.cpp index 6cf313cf81d243..a817428afb2a33 100644 --- a/src/controller/CHIPCommissionableNodeController.cpp +++ b/src/controller/CHIPCommissionableNodeController.cpp @@ -19,11 +19,6 @@ // module header, comes first #include -#include -#if CONFIG_DEVICE_LAYER -#include -#endif -#include #include namespace chip { @@ -40,22 +35,5 @@ const Mdns::DiscoveredNodeData * CommissionableNodeController::GetDiscoveredComm return GetDiscoveredNode(idx); } -CHIP_ERROR CommissionableNodeController::AdvertiseCommissionableNode() -{ -#if CONFIG_DEVICE_LAYER - ReturnErrorOnFailure(chip::Mdns::ServiceAdvertiser::Instance().Start(&chip::DeviceLayer::InetLayer, chip::Mdns::kMdnsPort)); - return app::Mdns::AdvertiseCommissionableNode(); -#else - return CHIP_ERROR_NOT_IMPLEMENTED; -#endif -} - -CHIP_ERROR CommissionableNodeController::SendUserDirectedCommissioningRequest(chip::Inet::IPAddress commissioner, uint16_t port) -{ - // TODO: integrate with Server:SendUserDirectedCommissioningRequest() - ChipLogError(Controller, "Unsupported operation CommissionableNodeController::SendUserDirectedCommissioningRequest"); - return CHIP_ERROR_NOT_IMPLEMENTED; -} - } // namespace Controller } // namespace chip diff --git a/src/controller/CHIPCommissionableNodeController.h b/src/controller/CHIPCommissionableNodeController.h index b5d07f99d2a62b..ef2c56685afa34 100644 --- a/src/controller/CHIPCommissionableNodeController.h +++ b/src/controller/CHIPCommissionableNodeController.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace chip { @@ -53,10 +54,6 @@ class DLL_EXPORT CommissionableNodeController : public AbstractMdnsDiscoveryCont ChipLogError(Controller, "Unsupported operation CommissionableNodeController::OnNodeIdResolutionFailed"); } - CHIP_ERROR AdvertiseCommissionableNode(); - - CHIP_ERROR SendUserDirectedCommissioningRequest(chip::Inet::IPAddress commissioner, uint16_t port); - protected: Mdns::DiscoveredNodeData * GetDiscoveredNodes() override { return mDiscoveredCommissioners; }