dns_sd_responder.h
Go to the documentation of this file.
1 /**
2  * @file dns_sd_responder.h
3  * @brief DNS-SD responder (DNS-Based Service Discovery)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _DNS_SD_RESPONDER_H
32 #define _DNS_SD_RESPONDER_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "dns/dns_common.h"
37 #include "mdns/mdns_common.h"
38 
39 //DNS-SD responder support
40 #ifndef DNS_SD_RESPONDER_SUPPORT
41  #define DNS_SD_RESPONDER_SUPPORT DISABLED
42 #elif (DNS_SD_RESPONDER_SUPPORT != ENABLED && DNS_SD_RESPONDER_SUPPORT != DISABLED)
43  #error DNS_SD_RESPONDER_SUPPORT parameter is not valid
44 #endif
45 
46 //DNS-SD responder tick interval
47 #ifndef DNS_SD_RESPONDER_TICK_INTERVAL
48  #define DNS_SD_RESPONDER_TICK_INTERVAL 250
49 #elif (DNS_SD_RESPONDER_TICK_INTERVAL < 10)
50  #error DNS_SD_RESPONDER_TICK_INTERVAL parameter is not valid
51 #endif
52 
53 //Maximum length of service name
54 #ifndef DNS_SD_MAX_SERVICE_NAME_LEN
55  #define DNS_SD_MAX_SERVICE_NAME_LEN 32
56 #elif (DNS_SD_MAX_SERVICE_NAME_LEN < 1)
57  #error DNS_SD_MAX_SERVICE_NAME_LEN parameter is not valid
58 #endif
59 
60 //Maximum length of instance name
61 #ifndef DNS_SD_MAX_INSTANCE_NAME_LEN
62  #define DNS_SD_MAX_INSTANCE_NAME_LEN 32
63 #elif (DNS_SD_MAX_INSTANCE_NAME_LEN < 1)
64  #error DNS_SD_MAX_INSTANCE_NAME_LEN parameter is not valid
65 #endif
66 
67 //Maximum length of the discovery-time metadata (TXT record)
68 #ifndef DNS_SD_MAX_METADATA_LEN
69  #define DNS_SD_MAX_METADATA_LEN 128
70 #elif (DNS_SD_MAX_METADATA_LEN < 1)
71  #error DNS_SD_MAX_METADATA_LEN parameter is not valid
72 #endif
73 
74 //Default resource record TTL (cache lifetime)
75 #ifndef DNS_SD_DEFAULT_RR_TTL
76  #define DNS_SD_DEFAULT_RR_TTL 120
77 #elif (DNS_SD_DEFAULT_RR_TTL < 1)
78  #error DNS_SD_DEFAULT_RR_TTL parameter is not valid
79 #endif
80 
81 //Forward declaration of DnsSdResponderContext structure
83 #define DnsSdResponderContext struct _DnsSdResponderContext
84 
85 //Forward declaration of DnsSdResponderService structure
87 #define DnsSdResponderService struct _DnsSdResponderService
88 
89 //C++ guard
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93 
94 
95 /**
96  * @brief FSM state change callback
97  **/
98 
100  NetInterface *interface, MdnsState state);
101 
102 
103 /**
104  * @brief DNS-SD responder settings
105  **/
106 
107 typedef struct
108 {
109  NetInterface *interface; ///<Underlying network interface
110  uint_t numServices; ///<Maximum number of DNS-SD services that can be registered
111  DnsSdResponderService *services; ///<DNS-SD services
112  uint_t numAnnouncements; ///<Number of announcement packets
113  uint32_t ttl; ///<TTL resource record
114  DnsSdStateChangeCallback stateChangeEvent; ///<FSM state change event
116 
117 
118 /**
119  * @brief DNS-SD service descriptor
120  **/
121 
123 {
124  MdnsState state; ///<FSM state
125  DnsSdResponderContext *context; ///<DNS-SD responder context
128  uint16_t priority; ///<Priority of the target host
129  uint16_t weight; ///<Server selection mechanism
130  uint16_t port; ///<Port on the target host of this service
131  uint8_t metadata[DNS_SD_MAX_METADATA_LEN]; ///<Discovery-time metadata (TXT record)
132  size_t metadataLen; ///<Length of the metadata
133  bool_t conflict; ///<Conflict detected
134  bool_t tieBreakLost; ///<Tie-break lost
135  systime_t timestamp; ///<Timestamp to manage retransmissions
136  systime_t timeout; ///<Timeout value
137  uint_t retransmitCount; ///<Retransmission counter
138 };
139 
140 
141 /**
142  * @brief DNS-SD responder context
143  **/
144 
146 {
147  NetInterface *interface; ///<Underlying network interface
148  uint_t numServices; ///<Maximum number of DNS-SD services that can be registered
149  DnsSdResponderService *services; ///<DNS-SD services
150  uint_t numAnnouncements; ///<Number of announcement packets
151  uint32_t ttl; ///<TTL resource record
152  DnsSdStateChangeCallback stateChangeEvent; ///<FSM state change event
153  bool_t running; ///<DNS-SD responder is currently running
154 };
155 
156 
157 //Tick counter to handle periodic operations
159 
160 //DNS-SD responder related functions
162 
164  const DnsSdResponderSettings *settings);
165 
168 
170  uint_t index, const char_t *instanceName, const char_t *serviceName,
171  uint16_t priority, uint16_t weight, uint16_t port, const char_t *metadata);
172 
174  uint_t index);
175 
177 
180 
181 //C++ guard
182 #ifdef __cplusplus
183 }
184 #endif
185 
186 #endif
uint_t retransmitCount
Retransmission counter.
void(* DnsSdStateChangeCallback)(DnsSdResponderService *service, NetInterface *interface, MdnsState state)
FSM state change callback.
int bool_t
Definition: compiler_port.h:53
DNS-SD service descriptor.
error_t dnsSdResponderRegisterService(DnsSdResponderContext *context, uint_t index, const char_t *instanceName, const char_t *serviceName, uint16_t priority, uint16_t weight, uint16_t port, const char_t *metadata)
Register a DNS-SD service.
NetInterface * interface
Underlying network interface.
uint16_t weight
Definition: dns_common.h:266
error_t dnsSdResponderUnregisterService(DnsSdResponderContext *context, uint_t index)
Unregister a DNS-SD service.
#define DNS_SD_MAX_METADATA_LEN
DNS-SD responder context.
DnsSdStateChangeCallback stateChangeEvent
FSM state change event.
uint32_t ttl
TTL resource record.
size_t metadataLen
Length of the metadata.
DnsSdResponderContext * context
DNS-SD responder context.
MdnsState state
FSM state.
uint_t numServices
Maximum number of DNS-SD services that can be registered.
error_t dnsSdResponderStop(DnsSdResponderContext *context)
Stop DNS-SD responder.
MdnsState
mDNS responder states
Definitions common to mDNS client and mDNS responder.
bool_t tieBreakLost
Tie-break lost.
uint_t numServices
Maximum number of DNS-SD services that can be registered.
void dnsSdResponderGetDefaultSettings(DnsSdResponderSettings *settings)
Initialize settings with default values.
error_t
Error codes.
Definition: error.h:43
DnsSdResponderService * services
DNS-SD services.
systime_t timeout
Timeout value.
void dnsSdResponderLinkChangeEvent(DnsSdResponderContext *interface)
Callback function for link change event.
bool_t conflict
Conflict detected.
systime_t dnsSdResponderTickCounter
#define NetInterface
Definition: net.h:36
#define DnsSdResponderContext
error_t dnsSdResponderStartProbing(DnsSdResponderContext *context)
Restart probing process.
systime_t timestamp
Timestamp to manage retransmissions.
uint8_t metadata[DNS_SD_MAX_METADATA_LEN]
Discovery-time metadata (TXT record)
DnsSdStateChangeCallback stateChangeEvent
FSM state change event.
#define DnsSdResponderService
#define DNS_SD_MAX_INSTANCE_NAME_LEN
uint_t numAnnouncements
Number of announcement packets.
DNS-SD responder settings.
uint32_t systime_t
System time.
uint16_t port
Definition: dns_common.h:267
char char_t
Definition: compiler_port.h:48
uint16_t weight
Server selection mechanism.
void dnsSdResponderTick(DnsSdResponderContext *interface)
DNS-SD responder timer handler.
NetInterface * interface
Underlying network interface.
char_t serviceName[DNS_SD_MAX_SERVICE_NAME_LEN+1]
Service name.
uint_t numAnnouncements
Number of announcement packets.
uint16_t priority
Priority of the target host.
bool_t running
DNS-SD responder is currently running.
error_t dnsSdResponderInit(DnsSdResponderContext *context, const DnsSdResponderSettings *settings)
DNS-DS initialization.
uint32_t ttl
TTL resource record.
char_t instanceName[DNS_SD_MAX_INSTANCE_NAME_LEN+1]
Instance name.
unsigned int uint_t
Definition: compiler_port.h:50
#define DNS_SD_MAX_SERVICE_NAME_LEN
TCP/IP stack core.
DnsSdResponderService * services
DNS-SD services.
uint16_t priority
Definition: dns_common.h:265
uint16_t port
Port on the target host of this service.
Common DNS routines.
error_t dnsSdResponderStart(DnsSdResponderContext *context)
Start DNS-SD responder.