diff --git a/src/mdns/dnssd_plat.hpp b/src/mdns/dnssd_plat.hpp index 5b09b0b6aee..f075738dd73 100644 --- a/src/mdns/dnssd_plat.hpp +++ b/src/mdns/dnssd_plat.hpp @@ -45,6 +45,46 @@ #include "mdns/mdns.hpp" #include "ncp/ncp_openthread.hpp" +extern "C" otPlatDnssdState otPlatDnssdGetState(otInstance *aInstance); +extern "C" void otPlatDnssdRegisterService(otInstance *aInstance, + const otPlatDnssdService *aService, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); +extern "C" void otPlatDnssdUnregisterService(otInstance *aInstance, + const otPlatDnssdService *aService, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); +extern "C" void otPlatDnssdRegisterHost(otInstance *aInstance, + const otPlatDnssdHost *aHost, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); +extern "C" void otPlatDnssdUnregisterHost(otInstance *aInstance, + const otPlatDnssdHost *aHost, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); +extern "C" void otPlatDnssdRegisterKey(otInstance *aInstance, + const otPlatDnssdKey *aKey, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); +extern "C" void otPlatDnssdUnregisterKey(otInstance *aInstance, + const otPlatDnssdKey *aKey, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); +extern "C" void otPlatDnssdStartServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex); +extern "C" void otPlatDnssdStopServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex); +extern "C" void otPlatDnssdStartServiceResolver(otInstance *aInstance, + const otPlatDnssdServiceInstance *aServiceInstance); +extern "C" void otPlatDnssdStopServiceResolver(otInstance *aInstance, + const otPlatDnssdServiceInstance *aServiceInstance); +extern "C" void otPlatDnssdStartIp6AddressResolver(otInstance *aInstance, + const char *aHostName, + uint32_t aInfraIfIndex); +extern "C" void otPlatDnssdStopIp6AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex); +extern "C" void otPlatDnssdStartIp4AddressResolver(otInstance *aInstance, + const char *aHostName, + uint32_t aInfraIfIndex); +extern "C" void otPlatDnssdStopIp4AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex); + namespace otbr { class BorderAgent; @@ -57,13 +97,53 @@ class DnssdPlatform : private NonCopyable { friend class BorderAgent; + friend otPlatDnssdState otPlatDnssdGetState(otInstance *aInstance); + friend void otPlatDnssdRegisterService(otInstance *aInstance, + const otPlatDnssdService *aService, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); + friend void otPlatDnssdUnregisterService(otInstance *aInstance, + const otPlatDnssdService *aService, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); + friend void otPlatDnssdRegisterHost(otInstance *aInstance, + const otPlatDnssdHost *aHost, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); + friend void otPlatDnssdUnregisterHost(otInstance *aInstance, + const otPlatDnssdHost *aHost, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); + friend void otPlatDnssdRegisterKey(otInstance *aInstance, + const otPlatDnssdKey *aKey, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); + friend void otPlatDnssdUnregisterKey(otInstance *aInstance, + const otPlatDnssdKey *aKey, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback); + friend void otPlatDnssdStartServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex); + friend void otPlatDnssdStopServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex); + friend void otPlatDnssdStartServiceResolver(otInstance *aInstance, + const otPlatDnssdServiceInstance *aServiceInstance); + friend void otPlatDnssdStopServiceResolver(otInstance *aInstance, + const otPlatDnssdServiceInstance *aServiceInstance); + friend void otPlatDnssdStartIp6AddressResolver(otInstance *aInstance, + const char *aHostName, + uint32_t aInfraIfIndex); + friend void otPlatDnssdStopIp6AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex); + friend void otPlatDnssdStartIp4AddressResolver(otInstance *aInstance, + const char *aHostName, + uint32_t aInfraIfIndex); + friend void otPlatDnssdStopIp4AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex); + public: DnssdPlatform(Ncp::ControllerOpenThread &aNcp, Mdns::Publisher &aPublisher); void Start(void); void Stop(void); - //--------------------------------------- +private: typedef otPlatDnssdState State; typedef otPlatDnssdService Service; typedef otPlatDnssdHost Host; @@ -71,22 +151,21 @@ class DnssdPlatform : private NonCopyable typedef otPlatDnssdRequestId RequestId; typedef otPlatDnssdRegisterCallback RegisterCallback; + // `otPlatDnssd` APIs State GetState(void) const { return mState; } + void RegisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback); + void UnregisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback); + void RegisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback); + void UnregisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback); + void RegisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback); + void UnregisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback); - void RegisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback); - void UnregisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback); - void RegisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback); - void UnregisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback); - void RegisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback); - void UnregisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback); + // Callback from BR agent + void HandleMdnsPublisherStateChange(Mdns::Publisher::State aState); -private: static otError ResultToError(otbrError aOtbrError); static std::string KeyNameFor(const Key &aKey); - // Callback from BR agent - void HandleMdnsPublisherStateChange(Mdns::Publisher::State aState); - Mdns::Publisher::ResultCallback MakePublisherCallback(RequestId aRequestId, RegisterCallback aCallback); Ncp::ControllerOpenThread &mNcp;