Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dns_sd.h Source File

dns_sd.h

Go to the documentation of this file.
00001 /**
00002  * @file dns_sd.h
00003  * @brief DNS-SD (DNS-Based Service Discovery)
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _DNS_SD_H
00030 #define _DNS_SD_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 #include "dns/dns_common.h"
00035 #include "mdns/mdns_common.h"
00036 
00037 //DNS-SD support
00038 #ifndef DNS_SD_SUPPORT
00039    #define DNS_SD_SUPPORT DISABLED
00040 #elif (DNS_SD_SUPPORT != ENABLED && DNS_SD_SUPPORT != DISABLED)
00041    #error DNS_SD_SUPPORT parameter is not valid
00042 #endif
00043 
00044 //DNS-SD tick interval
00045 #ifndef DNS_SD_TICK_INTERVAL
00046    #define DNS_SD_TICK_INTERVAL 250
00047 #elif (DNS_SD_TICK_INTERVAL < 10)
00048    #error DNS_SD_TICK_INTERVAL parameter is not valid
00049 #endif
00050 
00051 //Maximum number of registered services
00052 #ifndef DNS_SD_SERVICE_LIST_SIZE
00053    #define DNS_SD_SERVICE_LIST_SIZE 2
00054 #elif (DNS_SD_SERVICE_LIST_SIZE < 1)
00055    #error DNS_SD_SERVICE_LIST_SIZE parameter is not valid
00056 #endif
00057 
00058 //Maximum length of service name
00059 #ifndef DNS_SD_MAX_SERVICE_NAME_LEN
00060    #define DNS_SD_MAX_SERVICE_NAME_LEN 16
00061 #elif (DNS_SD_MAX_SERVICE_NAME_LEN < 1)
00062    #error DNS_SD_MAX_SERVICE_NAME_LEN parameter is not valid
00063 #endif
00064 
00065 //Maximum length of instance name
00066 #ifndef DNS_SD_MAX_INSTANCE_NAME_LEN
00067    #define DNS_SD_MAX_INSTANCE_NAME_LEN 32
00068 #elif (DNS_SD_MAX_INSTANCE_NAME_LEN < 1)
00069    #error DNS_SD_MAX_INSTANCE_NAME_LEN parameter is not valid
00070 #endif
00071 
00072 //Maximum length of the discovery-time metadata (TXT record)
00073 #ifndef DNS_SD_MAX_METADATA_LEN
00074    #define DNS_SD_MAX_METADATA_LEN 128
00075 #elif (DNS_SD_MAX_METADATA_LEN < 1)
00076    #error DNS_SD_MAX_METADATA_LEN parameter is not valid
00077 #endif
00078 
00079 //Default resource record TTL (cache lifetime)
00080 #ifndef DNS_SD_DEFAULT_RR_TTL
00081    #define DNS_SD_DEFAULT_RR_TTL 120
00082 #elif (DNS_SD_DEFAULT_RR_TTL < 1)
00083    #error DNS_SD_DEFAULT_RR_TTL parameter is not valid
00084 #endif
00085 
00086 //Forward declaration of DnsSdContext structure
00087 struct _DnsSdContext;
00088 #define DnsSdContext struct _DnsSdContext
00089 
00090 
00091 /**
00092  * @brief FSM state change callback
00093  **/
00094 
00095 typedef void (*DnsSdStateChangeCallback)(DnsSdContext *context,
00096    NetInterface *interface, MdnsState state);
00097 
00098 
00099 /**
00100  * @brief DNS-SD settings
00101  **/
00102 
00103 typedef struct
00104 {
00105    NetInterface *interface;                   ///<Underlying network interface
00106    uint_t numAnnouncements;                   ///<Number of announcement packets
00107    uint32_t ttl;                              ///<TTL resource record
00108    DnsSdStateChangeCallback stateChangeEvent; ///<FSM state change event
00109 } DnsSdSettings;
00110 
00111 
00112 /**
00113  * @brief DNS-SD service descriptor
00114  **/
00115 
00116 typedef struct
00117 {
00118    char_t name[DNS_SD_MAX_SERVICE_NAME_LEN + 1]; ///<Service name
00119    uint16_t priority;                            ///<Priority of the target host
00120    uint16_t weight;                              ///<Server selection mechanism
00121    uint16_t port;                                ///<Port on the target host of this service
00122    uint8_t metadata[DNS_SD_MAX_METADATA_LEN];    ///<Discovery-time metadata (TXT record)
00123    size_t metadataLength;                        ///<Length of the metadata
00124 } DnsSdService;
00125 
00126 
00127 /**
00128  * @brief DNS-SD context
00129  **/
00130 
00131 struct _DnsSdContext
00132 {
00133    DnsSdSettings settings;                                ///<DNS-SD settings
00134    bool_t running;                                        ///<DNS-SD is currently running
00135    MdnsState state;                                       ///<FSM state
00136    bool_t conflict;                                       ///<Conflict detected
00137    bool_t tieBreakLost;                                   ///<Tie-break lost
00138    systime_t timestamp;                                   ///<Timestamp to manage retransmissions
00139    systime_t timeout;                                     ///<Timeout value
00140    uint_t retransmitCount;                                ///<Retransmission counter
00141    char_t instanceName[DNS_SD_MAX_INSTANCE_NAME_LEN + 1]; ///<Service instance name
00142    DnsSdService serviceList[DNS_SD_SERVICE_LIST_SIZE];    ///<List of registered services
00143 };
00144 
00145 
00146 //Tick counter to handle periodic operations
00147 extern systime_t dnsSdTickCounter;
00148 
00149 //DNS-SD related functions
00150 void dnsSdGetDefaultSettings(DnsSdSettings *settings);
00151 error_t dnsSdInit(DnsSdContext *context, const DnsSdSettings *settings);
00152 error_t dnsSdStart(DnsSdContext *context);
00153 error_t dnsSdStop(DnsSdContext *context);
00154 MdnsState dnsSdGetState(DnsSdContext *context);
00155 
00156 error_t dnsSdSetInstanceName(DnsSdContext *context, const char_t *instanceName);
00157 
00158 error_t dnsSdRegisterService(DnsSdContext *context, const char_t *serviceName,
00159    uint16_t priority, uint16_t weight, uint16_t port, const char_t *metadata);
00160 
00161 error_t dnsSdUnregisterService(DnsSdContext *context, const char_t *serviceName);
00162 
00163 uint_t dnsSdGetNumServices(DnsSdContext *context);
00164 error_t dnsSdStartProbing(DnsSdContext *context);
00165 
00166 void dnsSdTick(DnsSdContext *interface);
00167 void dnsSdLinkChangeEvent(DnsSdContext *interface);
00168 
00169 void dnsSdChangeState(DnsSdContext *context,
00170    MdnsState newState, systime_t delay);
00171 
00172 void dnsSdChangeInstanceName(DnsSdContext *context);
00173 
00174 error_t dnsSdSendProbe(DnsSdContext *context);
00175 error_t dnsSdSendAnnouncement(DnsSdContext *context);
00176 error_t dnsSdSendGoodbye(DnsSdContext *context, const DnsSdService *service);
00177 
00178 error_t dnsSdParseQuestion(NetInterface *interface, const MdnsMessage *query,
00179    size_t offset, const DnsQuestion *question, MdnsMessage *response);
00180 
00181 void dnsSdParseNsRecord(NetInterface *interface, const MdnsMessage *query,
00182    size_t offset, const DnsResourceRecord *record);
00183 
00184 void dnsSdParseAnRecord(NetInterface *interface, const MdnsMessage *response,
00185    size_t offset, const DnsResourceRecord *record);
00186 
00187 void dnsSdGenerateAdditionalRecords(NetInterface *interface,
00188    MdnsMessage *response, bool_t legacyUnicast);
00189 
00190 error_t dnsSdAddServiceEnumPtrRecord(NetInterface *interface,
00191    MdnsMessage *message, const DnsSdService *service, uint32_t ttl);
00192 
00193 error_t dnsSdAddPtrRecord(NetInterface *interface,
00194    MdnsMessage *message, const DnsSdService *service, uint32_t ttl);
00195 
00196 error_t dnsSdAddSrvRecord(NetInterface *interface, MdnsMessage *message,
00197    const DnsSdService *service, bool_t cacheFlush, uint32_t ttl);
00198 
00199 error_t dnsSdAddTxtRecord(NetInterface *interface, MdnsMessage *message,
00200    const DnsSdService *service, bool_t cacheFlush, uint32_t ttl);
00201 
00202 error_t dnsSdAddNsecRecord(NetInterface *interface, MdnsMessage *message,
00203    const DnsSdService *service, bool_t cacheFlush, uint32_t ttl);
00204 
00205 #endif
00206