mikroSDK Reference Manual
mdns_responder.h
Go to the documentation of this file.
1
31#ifndef _MDNS_RESPONDER_H
32#define _MDNS_RESPONDER_H
33
34//Dependencies
35#include "core/net.h"
36#include "core/udp.h"
37#include "dns/dns_common.h"
38#include "mdns/mdns_common.h"
39
40//mDNS responder support
41#ifndef MDNS_RESPONDER_SUPPORT
42 #define MDNS_RESPONDER_SUPPORT DISABLED
43#elif (MDNS_RESPONDER_SUPPORT != ENABLED && MDNS_RESPONDER_SUPPORT != DISABLED)
44 #error MDNS_RESPONDER_SUPPORT parameter is not valid
45#endif
46
47//mDNS responder tick interval
48#ifndef MDNS_RESPONDER_TICK_INTERVAL
49 #define MDNS_RESPONDER_TICK_INTERVAL 250
50#elif (MDNS_RESPONDER_TICK_INTERVAL < 10)
51 #error MDNS_RESPONDER_TICK_INTERVAL parameter is not valid
52#endif
53
54//Maximum length of host name
55#ifndef MDNS_RESPONDER_MAX_HOSTNAME_LEN
56 #define MDNS_RESPONDER_MAX_HOSTNAME_LEN 32
57#elif (MDNS_RESPONDER_MAX_HOSTNAME_LEN < 1)
58 #error MDNS_RESPONDER_MAX_HOSTNAME_LEN parameter is not valid
59#endif
60
61//Initial delay
62#ifndef MDNS_INIT_DELAY
63 #define MDNS_INIT_DELAY 1000
64#elif (MDNS_INIT_DELAY < 0)
65 #error MDNS_INIT_DELAY parameter is not valid
66#endif
67
68//Initial random delay (minimum value)
69#ifndef MDNS_RAND_DELAY_MIN
70 #define MDNS_RAND_DELAY_MIN 0
71#elif (MDNS_RAND_DELAY_MIN < 0)
72 #error MDNS_RAND_DELAY_MIN parameter is not valid
73#endif
74
75//Initial random delay (maximum value)
76#ifndef MDNS_RAND_DELAY_MAX
77 #define MDNS_RAND_DELAY_MAX 250
78#elif (MDNS_RAND_DELAY_MAX < 0)
79 #error MDNS_RAND_DELAY_MAX parameter is not valid
80#endif
81
82//Number of probe packets
83#ifndef MDNS_PROBE_NUM
84 #define MDNS_PROBE_NUM 3
85#elif (MDNS_PROBE_NUM < 1)
86 #error MDNS_PROBE_NUM parameter is not valid
87#endif
88
89//Time interval between subsequent probe packets
90#ifndef MDNS_PROBE_DELAY
91 #define MDNS_PROBE_DELAY 250
92#elif (MDNS_PROBE_DELAY < 100)
93 #error MDNS_PROBE_DELAY parameter is not valid
94#endif
95
96//Delay before probing again after any failed probe attempt
97#ifndef MDNS_PROBE_CONFLICT_DELAY
98 #define MDNS_PROBE_CONFLICT_DELAY 1000
99#elif (MDNS_PROBE_CONFLICT_DELAY < 100)
100 #error MDNS_PROBE_CONFLICT_DELAY parameter is not valid
101#endif
102
103//Delay before probing again when deferring to the winning host
104#ifndef MDNS_PROBE_DEFER_DELAY
105 #define MDNS_PROBE_DEFER_DELAY 1000
106#elif (MDNS_PROBE_DEFER_DELAY < 100)
107 #error MDNS_PROBE_DEFER_DELAY parameter is not valid
108#endif
109
110//Number of announcement packets
111#ifndef MDNS_ANNOUNCE_NUM
112 #define MDNS_ANNOUNCE_NUM 2
113#elif (MDNS_ANNOUNCE_NUM < 1)
114 #error MDNS_ANNOUNCE_NUM parameter is not valid
115#endif
116
117//Time interval between subsequent announcement packets
118#ifndef MDNS_ANNOUNCE_DELAY
119 #define MDNS_ANNOUNCE_DELAY 1000
120#elif (MDNS_ANNOUNCE_DELAY < 100)
121 #error MDNS_ANNOUNCE_DELAY parameter is not valid
122#endif
123
124//Forward declaration of DnsSdContext structure
126#define MdnsResponderContext struct _MdnsResponderContext
127
128//C++ guard
129#ifdef __cplusplus
130extern "C" {
131#endif
132
133
138typedef enum
139{
140 MDNS_STATE_INIT = 0,
141 MDNS_STATE_WAITING = 1,
142 MDNS_STATE_PROBING = 2,
143 MDNS_STATE_ANNOUNCING = 3,
144 MDNS_STATE_IDLE = 4
145} MdnsState;
146
147
152typedef void (*MdnsResponderStateChangeCallback)(MdnsResponderContext *context,
153 NetInterface *interface, MdnsState state);
154
155
160typedef struct
161{
162 bool_t valid;
163 DnsIpv4AddrResourceRecord record;
164 char_t reverseName[DNS_MAX_IPV4_REVERSE_NAME_LEN + 1];
166
167
172typedef struct
173{
174 bool_t valid;
175 DnsIpv6AddrResourceRecord record;
176 char_t reverseName[DNS_MAX_IPV6_REVERSE_NAME_LEN + 1];
178
179
191
192
198{
200 bool_t running;
202 bool_t conflict;
207 char_t hostname[MDNS_RESPONDER_MAX_HOSTNAME_LEN + 1];
210#if (IPV4_SUPPORT == ENABLED)
211 MdnsIpv4AddrEntry ipv4AddrList[IPV4_ADDR_LIST_SIZE];
213#endif
214#if (IPV6_SUPPORT == ENABLED)
215 MdnsIpv6AddrEntry ipv6AddrList[IPV6_ADDR_LIST_SIZE];
217#endif
218};
219
220
221//Tick counter to handle periodic operations
222extern systime_t mdnsResponderTickCounter;
223
224//mDNS related functions
225void mdnsResponderGetDefaultSettings(MdnsResponderSettings *settings);
226
227error_t mdnsResponderInit(MdnsResponderContext *context,
228 const MdnsResponderSettings *settings);
229
230error_t mdnsResponderStart(MdnsResponderContext *context);
231error_t mdnsResponderStop(MdnsResponderContext *context);
232MdnsState mdnsResponderGetState(MdnsResponderContext *context);
233
234error_t mdnsResponderSetHostname(MdnsResponderContext *context,
235 const char_t *hostname);
236
237error_t mdnsResponderStartProbing(MdnsResponderContext *context);
238
239void mdnsResponderTick(MdnsResponderContext *context);
240void mdnsResponderLinkChangeEvent(MdnsResponderContext *context);
241
242//C++ guard
243#ifdef __cplusplus
244}
245#endif
246
247#endif
Common DNS routines.
error_t
Error codes.
Definition error.h:43
Definitions common to mDNS client and mDNS responder.
void(* MdnsResponderStateChangeCallback)(MdnsResponderContext *context, NetInterface *interface, MdnsState state)
FSM state change callback.
Definition mdns_responder.h:152
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
IPv4 address entry.
Definition mdns_responder.h:161
bool_t valid
Valid entry.
Definition mdns_responder.h:162
DnsIpv4AddrResourceRecord record
A resource record.
Definition mdns_responder.h:163
IPv6 address entry.
Definition mdns_responder.h:173
DnsIpv6AddrResourceRecord record
AAAA resource record.
Definition mdns_responder.h:175
bool_t valid
Valid entry.
Definition mdns_responder.h:174
mDNS message
Definition mdns_common.h:78
mDNS responder settings
Definition mdns_responder.h:185
uint_t numAnnouncements
Number of announcement packets.
Definition mdns_responder.h:187
MdnsResponderStateChangeCallback stateChangeEvent
FSM state change event.
Definition mdns_responder.h:189
NetInterface * interface
Underlying network interface.
Definition mdns_responder.h:186
uint32_t ttl
TTL resource record.
Definition mdns_responder.h:188
mDNS responder context
Definition mdns_responder.h:198
systime_t timestamp
Timestamp to manage retransmissions.
Definition mdns_responder.h:204
MdnsIpv6AddrEntry ipv6AddrList[IPV6_ADDR_LIST_SIZE]
IPv6 address list.
Definition mdns_responder.h:215
bool_t conflict
Conflict detected.
Definition mdns_responder.h:202
bool_t running
mDNS responder is currently running
Definition mdns_responder.h:200
MdnsIpv4AddrEntry ipv4AddrList[IPV4_ADDR_LIST_SIZE]
IPv4 address list.
Definition mdns_responder.h:211
MdnsResponderSettings settings
DNS-SD settings.
Definition mdns_responder.h:199
bool_t ipv4AddrCount
Number of valid IPv4 addresses.
Definition mdns_responder.h:208
systime_t timeout
Timeout value.
Definition mdns_responder.h:205
char_t hostname[MDNS_RESPONDER_MAX_HOSTNAME_LEN+1]
Host name.
Definition mdns_responder.h:207
MdnsMessage ipv4Response
IPv4 response message.
Definition mdns_responder.h:212
uint_t retransmitCount
Retransmission counter.
Definition mdns_responder.h:206
bool_t tieBreakLost
Tie-break lost.
Definition mdns_responder.h:203
bool_t ipv6AddrCount
Number of valid IPv6 addresses.
Definition mdns_responder.h:209
MdnsState state
FSM state.
Definition mdns_responder.h:201
MdnsMessage ipv6Response
IPv6 response message.
Definition mdns_responder.h:216
UDP (User Datagram Protocol)