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
35 CHIP_ERROR Start(Inet::InetLayer * inetLayer, uint16_t port) override;
37 /// Advertises the CHIP node as an operational node
38 CHIP_ERROR Advertise(const OperationalAdvertisingParameters & params) override;
40 /// Advertises the CHIP node as a commisioning/commissionable node
41 CHIP_ERROR Advertise(const CommissionAdvertisingParameters & params) override;
43 /// This function stops publishing the device on mDNS.
44 CHIP_ERROR StopPublishDevice();
46 /// Registers a resolver delegate if none has been registered before
47 CHIP_ERROR SetResolverDelegate(ResolverDelegate * delegate) override;
49 /// Requests resolution of a node ID to its address
50 CHIP_ERROR ResolveNodeId(uint64_t nodeId, uint64_t fabricId, Inet::IPAddressType type) override;
52 static DiscoveryImplPlatform & GetInstance();
55 DiscoveryImplPlatform();
57 DiscoveryImplPlatform(const DiscoveryImplPlatform &) = delete;
58 DiscoveryImplPlatform & operator=(const DiscoveryImplPlatform &) = delete;
60 CHIP_ERROR PublishUnprovisionedDevice(chip::Inet::IPAddressType addressType, chip::Inet::InterfaceId interface);
61 CHIP_ERROR PublishProvisionedDevice(chip::Inet::IPAddressType addressType, chip::Inet::InterfaceId interface);
62 CHIP_ERROR SetupHostname();
64 static void HandleNodeIdResolve(void * context, MdnsService * result, CHIP_ERROR error);
65 static void HandleMdnsInit(void * context, CHIP_ERROR initError);
66 static void HandleMdnsError(void * context, CHIP_ERROR initError);
67 static CHIP_ERROR GenerateRotatingDeviceId(char rotatingDeviceIdHexBuffer[], size_t & rotatingDeviceIdHexBufferSize);
69 OperationalAdvertisingParameters mOperationalAdvertisingParams;
70 bool mIsOperationalPublishing = false;
71 uint64_t mCommissionInstanceName;
72 CommissionAdvertisingParameters mCommissioningdvertisingParams;
73 bool mIsCommissionalPublishing = false;
75 bool mMdnsInitialized = false;
76 ResolverDelegate * mResolverDelegate = nullptr;
78 static DiscoveryImplPlatform sManager;