mikroSDK Reference Manual
dns_sd.h
Go to the documentation of this file.
1
31#ifndef _DNS_SD_H
32#define _DNS_SD_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 support
40#ifndef DNS_SD_SUPPORT
41 #define DNS_SD_SUPPORT DISABLED
42#elif (DNS_SD_SUPPORT != ENABLED && DNS_SD_SUPPORT != DISABLED)
43 #error DNS_SD_SUPPORT parameter is not valid
44#endif
45
46//DNS-SD tick interval
47#ifndef DNS_SD_TICK_INTERVAL
48 #define DNS_SD_TICK_INTERVAL 250
49#elif (DNS_SD_TICK_INTERVAL < 10)
50 #error DNS_SD_TICK_INTERVAL parameter is not valid
51#endif
52
53//Maximum number of registered services
54#ifndef DNS_SD_SERVICE_LIST_SIZE
55 #define DNS_SD_SERVICE_LIST_SIZE 2
56#elif (DNS_SD_SERVICE_LIST_SIZE < 1)
57 #error DNS_SD_SERVICE_LIST_SIZE parameter is not valid
58#endif
59
60//Maximum length of service name
61#ifndef DNS_SD_MAX_SERVICE_NAME_LEN
62 #define DNS_SD_MAX_SERVICE_NAME_LEN 16
63#elif (DNS_SD_MAX_SERVICE_NAME_LEN < 1)
64 #error DNS_SD_MAX_SERVICE_NAME_LEN parameter is not valid
65#endif
66
67//Maximum length of instance name
68#ifndef DNS_SD_MAX_INSTANCE_NAME_LEN
69 #define DNS_SD_MAX_INSTANCE_NAME_LEN 32
70#elif (DNS_SD_MAX_INSTANCE_NAME_LEN < 1)
71 #error DNS_SD_MAX_INSTANCE_NAME_LEN parameter is not valid
72#endif
73
74//Maximum length of the discovery-time metadata (TXT record)
75#ifndef DNS_SD_MAX_METADATA_LEN
76 #define DNS_SD_MAX_METADATA_LEN 128
77#elif (DNS_SD_MAX_METADATA_LEN < 1)
78 #error DNS_SD_MAX_METADATA_LEN parameter is not valid
79#endif
80
81//Default resource record TTL (cache lifetime)
82#ifndef DNS_SD_DEFAULT_RR_TTL
83 #define DNS_SD_DEFAULT_RR_TTL 120
84#elif (DNS_SD_DEFAULT_RR_TTL < 1)
85 #error DNS_SD_DEFAULT_RR_TTL parameter is not valid
86#endif
87
88//Forward declaration of DnsSdContext structure
89struct _DnsSdContext;
90#define DnsSdContext struct _DnsSdContext
91
92//C++ guard
93#ifdef __cplusplus
94extern "C" {
95#endif
96
97
102typedef void (*DnsSdStateChangeCallback)(DnsSdContext *context,
103 NetInterface *interface, MdnsState state);
104
105
117
118
123typedef struct
124{
125 char_t name[DNS_SD_MAX_SERVICE_NAME_LEN + 1];
126 uint16_t priority;
127 uint16_t weight;
128 uint16_t port;
129 uint8_t metadata[DNS_SD_MAX_METADATA_LEN];
132
133
139{
141 bool_t running;
143 bool_t conflict;
148 char_t instanceName[DNS_SD_MAX_INSTANCE_NAME_LEN + 1];
149 DnsSdService serviceList[DNS_SD_SERVICE_LIST_SIZE];
150};
151
152
153//Tick counter to handle periodic operations
154extern systime_t dnsSdTickCounter;
155
156//DNS-SD related functions
157void dnsSdGetDefaultSettings(DnsSdSettings *settings);
158error_t dnsSdInit(DnsSdContext *context, const DnsSdSettings *settings);
159error_t dnsSdStart(DnsSdContext *context);
160error_t dnsSdStop(DnsSdContext *context);
161MdnsState dnsSdGetState(DnsSdContext *context);
162
163error_t dnsSdSetInstanceName(DnsSdContext *context, const char_t *instanceName);
164
165error_t dnsSdRegisterService(DnsSdContext *context, const char_t *serviceName,
166 uint16_t priority, uint16_t weight, uint16_t port, const char_t *metadata);
167
168error_t dnsSdUnregisterService(DnsSdContext *context, const char_t *serviceName);
169
170uint_t dnsSdGetNumServices(DnsSdContext *context);
171error_t dnsSdStartProbing(DnsSdContext *context);
172
173void dnsSdTick(DnsSdContext *interface);
174void dnsSdLinkChangeEvent(DnsSdContext *interface);
175
176//C++ guard
177#ifdef __cplusplus
178}
179#endif
180
181#endif
Common DNS routines.
void(* DnsSdStateChangeCallback)(DnsSdContext *context, NetInterface *interface, MdnsState state)
FSM state change callback.
Definition dns_sd.h:102
error_t
Error codes.
Definition error.h:43
Definitions common to mDNS client and mDNS responder.
MdnsState
mDNS responder states
Definition mdns_responder.h:139
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
DNS-SD service descriptor.
Definition dns_sd.h:124
size_t metadataLength
Length of the metadata.
Definition dns_sd.h:130
uint16_t weight
Server selection mechanism.
Definition dns_sd.h:127
uint16_t port
Port on the target host of this service.
Definition dns_sd.h:128
uint16_t priority
Priority of the target host.
Definition dns_sd.h:126
DNS-SD settings.
Definition dns_sd.h:111
uint_t numAnnouncements
Number of announcement packets.
Definition dns_sd.h:113
NetInterface * interface
Underlying network interface.
Definition dns_sd.h:112
DnsSdStateChangeCallback stateChangeEvent
FSM state change event.
Definition dns_sd.h:115
uint32_t ttl
TTL resource record.
Definition dns_sd.h:114
DNS-SD context.
Definition dns_sd.h:139
char_t instanceName[DNS_SD_MAX_INSTANCE_NAME_LEN+1]
Service instance name.
Definition dns_sd.h:148
bool_t tieBreakLost
Tie-break lost.
Definition dns_sd.h:144
bool_t running
DNS-SD is currently running.
Definition dns_sd.h:141
DnsSdSettings settings
DNS-SD settings.
Definition dns_sd.h:140
uint_t retransmitCount
Retransmission counter.
Definition dns_sd.h:147
DnsSdService serviceList[DNS_SD_SERVICE_LIST_SIZE]
List of registered services.
Definition dns_sd.h:149
systime_t timeout
Timeout value.
Definition dns_sd.h:146
bool_t conflict
Conflict detected.
Definition dns_sd.h:143
systime_t timestamp
Timestamp to manage retransmissions.
Definition dns_sd.h:145
MdnsState state
FSM state.
Definition dns_sd.h:142