3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <core/CHIPError.h>
21 #include <inet/InetInterface.h>
22 #include <lib/mdns/Advertiser.h>
23 #include <lib/mdns/Resolver.h>
24 #include <lib/mdns/platform/Mdns.h>
25 #include <platform/CHIPDeviceConfig.h>
30 class DiscoveryImplPlatform : public ServiceAdvertiser, public Resolver
33 CHIP_ERROR Start(Inet::InetLayer * inetLayer, uint16_t port) override;
35 /// Advertises the CHIP node as an operational node
36 CHIP_ERROR Advertise(const OperationalAdvertisingParameters & params) override;
38 /// Advertises the CHIP node as a commisioning/commissionable node
39 CHIP_ERROR Advertise(const CommissionAdvertisingParameters & params) override;
41 /// This function stops publishing the device on mDNS.
42 CHIP_ERROR StopPublishDevice();
44 /// Registers a resolver delegate if none has been registered before
45 CHIP_ERROR SetResolverDelegate(ResolverDelegate * delegate) override;
47 /// Requests resolution of a node ID to its address
48 CHIP_ERROR ResolveNodeId(uint64_t nodeId, uint64_t fabricId, Inet::IPAddressType type) override;
50 static DiscoveryImplPlatform & GetInstance();
53 DiscoveryImplPlatform();
55 DiscoveryImplPlatform(const DiscoveryImplPlatform &) = delete;
56 DiscoveryImplPlatform & operator=(const DiscoveryImplPlatform &) = delete;
58 CHIP_ERROR PublishUnprovisionedDevice(chip::Inet::IPAddressType addressType, chip::Inet::InterfaceId interface);
59 CHIP_ERROR PublishProvisionedDevice(chip::Inet::IPAddressType addressType, chip::Inet::InterfaceId interface);
60 CHIP_ERROR SetupHostname();
62 static void HandleNodeIdResolve(void * context, MdnsService * result, CHIP_ERROR error);
63 static void HandleMdnsInit(void * context, CHIP_ERROR initError);
64 static void HandleMdnsError(void * context, CHIP_ERROR initError);
65 static CHIP_ERROR GenerateRotatingDeviceId(char rotatingDeviceIdHexBuffer[], size_t & rotatingDeviceIdHexBufferSize);
67 OperationalAdvertisingParameters mOperationalAdvertisingParams;
68 bool mIsOperationalPublishing = false;
69 uint64_t mCommissionInstanceName;
70 CommissionAdvertisingParameters mCommissioningdvertisingParams;
71 bool mIsCommissionalPublishing = false;
73 bool mMdnsInitialized = false;
74 ResolverDelegate * mResolverDelegate = nullptr;
76 static DiscoveryImplPlatform sManager;