mdns.h

Go to the documentation of this file.
00001 /*##############################################################################
00002 
00003 nIP - Testapplication
00004 
00005 File        : mdns.h
00006 
00007 Description : Multicast Domain Name System
00008 
00009 Copyright notice:
00010 
00011 Copyright (C) 2005 -
00012 Andreas Dittrich, dittrich@informatik.hu-berlin.de
00013 Jon Kowal, kowal@informatik.hu-berlin.de
00014 
00015 This program is free software; you can redistribute it and/or
00016 modify it under the terms of the GNU General Public License
00017 as published by the Free Software Foundation; either version 2
00018 of the License, or (at your option) any later version.
00019 
00020 This program is distributed in the hope that it will be useful,
00021 but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00023 GNU General Public License for more details.
00024 
00025 You should have received a copy of the GNU General Public License
00026 along with this program; if not, write to the Free Software
00027 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00028 
00029 ##############################################################################*/
00030 
00031 #ifndef _MDNS_H_
00032  #define _MDNS_H_
00033 
00034 #include "nip_init.h"
00035 #include "nip_types.h"
00036 #include "os_core.h"
00037 #include "mem.h"
00038 #include "net/net_if.h"
00039 #include "app/dns.h"
00040 
00041 #define NIP_MDNS_ADDR0  224
00042 #define NIP_MDNS_ADDR1  0
00043 #define NIP_MDNS_ADDR2  0
00044 #define NIP_MDNS_ADDR3  251
00045 
00046 #ifndef NIP_MDNS_MAX_QUERIES
00047         /** maximum number of open MDNS queries. */
00048         #define NIP_MDNS_MAX_QUERIES    5
00049 #endif
00050 
00051 #ifndef NIP_MDNS_DISCARD_ON_OUT_OF_MEMORY
00052         /** If this is set to 1 we won't wait for memory to become free, but discard
00053          * any incoming packet if we don't have enough memory available to serve it */
00054         #define NIP_MDNS_DISCARD_ON_OUT_OF_MEMORY 1
00055 #endif
00056 
00057 #ifndef NIP_MDNS_MAX_NAMESTRINGS
00058         /** maximum number of cached DNS name strings. The hereby meant name strings
00059          * are the parts in between two dots of a DNS name, not the entire name. */
00060         #define NIP_MDNS_MAX_NAMESTRINGS 20
00061 #endif
00062 
00063 #ifndef NIP_MDNS_MAX_CACHE_SIZE
00064         /** maximum number of entries in MDNS cache */
00065         #define NIP_MDNS_MAX_CACHE_SIZE  20
00066 #endif
00067 
00068 #ifndef NIP_MDNS_DEFEND_HOSTNAME
00069         /** Should mdns-hostname be unique in the network? */
00070         #define NIP_MDNS_DEFEND_HOSTNAME 1
00071 #endif
00072 
00073 #ifndef NIP_MDNS_MAX_NAME_DEPTH
00074         /** The currently used system maximizes the size of MDNS names to 6 dotted
00075          * parts which is the maximum size needed for IPv4 in-addr.arpa pointers.
00076          * More flexible implementations would require a more complexly programmed
00077          * system of name concatenation.
00078          */
00079         #define NIP_MDNS_MAX_NAME_DEPTH 6
00080 #endif
00081 
00082 #ifndef NIP_MDNS_CREATE_IN_ADDR_ARPA_PTR
00083         #define NIP_MDNS_CREATE_IN_ADDR_ARPA_PTR 1
00084 #endif
00085 
00086 // double check: we cannot create in-addr.arpa pointers if max-name-depth < 6
00087 #if ( NIP_MDNS_MAX_NAME_DEPTH < 6 )
00088         #undef NIP_MDNS_CREATE_IN_ADDR_ARPA_PTR
00089         #define NIP_MDNS_CREATE_IN_ADDR_ARPA_PTR 0
00090 #endif
00091 
00092 #ifndef NIP_MDNS_COUNTER_SIZE
00093         /** Byte-Size of temporary query and answer counters for transmission. DNS
00094          * defines these counters to be 16-Bit, but for internal use we can limit
00095          * them to 8-Bit, as we can -- depending on available memory -- assure, that
00096          * a counter value of 255 will never be exceeded.
00097          * If by any chance any query/answer counter might exceed 255 you SHOULD set
00098          * NIP_MDNS_COUNTER_SIZE to 2, as the program does not perform any boundary
00099          * checks. Setting it to 2 will only lead to 4 additional Bytes of RAM being
00100          * used, which will most probbly not hurt, if you feel able to transmit more
00101          * than 255 queries or answers in one packet.
00102          */
00103         #define NIP_MDNS_COUNTER_SIZE  1
00104 #endif
00105 
00106 /** Query timer with this value is disabled until set to a different value. */
00107 #define NIP_MDNS_NO_QUERY_TIMER 255
00108 
00109 /** Maximum number of probes to send until assuming no conflict */
00110 #define NIP_MDNS_PROBE_COUNT    3
00111 
00112 /** Maximum number of announcements to send until assuming no conflict */
00113 #define NIP_MDNS_ANNOUNCE_COUNT 3
00114 
00115 #define NIP_MDNS_DEFAULT_TTL_A 12  /**< default TTL for records with a host name \
00116                                      *in rname or rdata, 2min */
00117 #define NIP_MDNS_DEFAULT_TTL   4500 /**< default TTL for not-A-records, 75min */
00118 
00119 
00120 #if   ( NIP_MDNS_MAX_QUERIES < 0x3F   )
00121         typedef uint8_t nip_mdns_query_id_t;
00122         typedef uint8_t nip_mdns_query_cnt_t;
00123         #define NIP_MDNS_QUERY_ID_MASK       0x3F
00124         #define NIP_MDNS_NO_QUERY            0x3F
00125         #define NIP_MDNS_QUERY_DELETE        0x80
00126         #define NIP_MDNS_QUERY_ACTIVE        0x00
00127         #define NIP_MDNS_NFY_NONE            0x00
00128         #define NIP_MDNS_NFY_LOCAL           0x80
00129         #define NIP_MDNS_NFY_REMOTE          0x40
00130 #elif ( NIP_MDNS_MAX_QUERY < 0x7FFF )
00131         typedef uint8_t nip_mdns_query_id_t;
00132         typedef uint16_t nip_mdns_query_cnt_t;
00133         #define NIP_MDNS_QUERY_ID_MASK       0x3FFF
00134         #define NIP_MDNS_NO_QUERY            0x3FFF
00135         #define NIP_MDNS_QUERY_DELETE        0x8000
00136         #define NIP_MDNS_QUERY_ACTIVE        0x0000
00137         #define NIP_MDNS_NFY_LOCAL           0x8000
00138         #define NIP_MDNS_NFY_REMOTE          0x4000
00139 #else
00140         typedef uint8_t nip_mdns_query_id_t;
00141         typedef uint32_t nip_mdns_query_cnt_t;
00142         #define NIP_MDNS_QUERY_ID_MASK       0x3FFFFFFF
00143         #define NIP_MDNS_NO_QUERY            0x3FFFFFFF
00144         #define NIP_MDNS_QUERY_DELETE        0x80000000
00145         #define NIP_MDNS_QUERY_ACTIVE        0x00000000
00146         #define NIP_MDNS_NFY_LOCAL           0x80000000
00147         #define NIP_MDNS_NFY_REMOTE          0x40000000
00148 #endif
00149 
00150 #define NIP_MDNS_NFY_ALL        (NIP_MDNS_NFY_LOCAL|NIP_MDNS_NFY_REMOTE)
00151 #define NIP_MDNS_NFY_NONE       0x00
00152 
00153 #define NIP_MDNS_NO_NAMESTRING     0
00154 #if   ( NIP_MDNS_MAX_NAMESTRINGS < 0xFF   )
00155         typedef uint8_t nip_mdns_namestring_id_t;
00156         typedef uint8_t nip_mdns_namestring_cnt_t;
00157 #elif ( NIP_MDNS_MAX_NAMESTRINGS < 0xFFFF )
00158         typedef uint16_t nip_mdns_namestring_id_t;
00159         typedef uint16_t nip_mdns_namestring_cnt_t;
00160 #else
00161         typedef uint32_t nip_mdns_namestring_id_t;
00162         typedef uint32_t nip_mdns_namestring_cnt_t;
00163 #endif
00164 
00165 /** Per standard, the size of the name string length is limited to 6 Bit */
00166 typedef uint8_t nip_mdns_namestring_len_t;
00167 
00168 #define NIP_MDNS_NO_CACHE_ID   0
00169 #if   ( NIP_MDNS_MAX_CACHE_SIZE < 0xFF   )
00170         typedef uint8_t nip_mdns_cache_id_t;
00171         typedef uint8_t nip_mdns_cache_cnt_t;
00172 #elif ( NIP_MDNS_MAX_CACHE_SIZE < 0xFFFF )
00173         typedef uint16_t nip_mdns_cache_id_t;
00174         typedef uint16_t nip_mdns_cache_cnt_t;
00175 #else
00176         typedef uint32_t nip_mdns_cache_id_t;
00177         typedef uint32_t nip_mdns_cache_cnt_t;
00178 #endif
00179 
00180 /** Size of usage counter assumes that average usage of a namestring will not
00181  * exceed two occurances per cache entry and one per query. If that assumption
00182  * fails to be true, NIP_E_OUT_OF_MEMORY errors will occur upon registering
00183  * names beyond that point.
00184  */
00185 #define NIP_MDNS_MAX_NAMESTRING_USG (NIP_MDNS_MAX_CACHE_SIZE/2 + NIP_MDNS_MAX_QUERIES)
00186 #if   ( NIP_MDNS_MAX_NAMESTRING_USG < 0xFF   )
00187         typedef uint8_t nip_mdns_namestring_usg_t;
00188 #elif ( NIP_MDNS_MAX_NAMESTRING_USG < 0XFFFF )
00189         typedef uint16_t nip_mdns_namestring_usg_t;
00190 #else
00191         typedef uint32_t nip_mdns_namestring_usg_t;
00192 #endif
00193 
00194 
00195 struct nip_mdns_name
00196 {
00197         nip_mdns_namestring_id_t part[ NIP_MDNS_MAX_NAME_DEPTH ];
00198 }
00199 #ifndef DOXYGEN
00200 __attribute__((packed))
00201 #endif
00202 ;
00203 
00204 struct nip_mdns_rdata_a
00205 {
00206         uint8_t ip_addr[4];
00207 }
00208 #ifndef DOXYGEN
00209 __attribute__((packed))
00210 #endif
00211 ;
00212 /** PTR data entry only holds instance name as app, proto and domain are implicit */
00213 #define NIP_MDNS_RDATA_SRV_SIZE  (3*sizeof(uint16_t)+sizeof(struct nip_mdns_data_a))
00214 struct nip_mdns_rdata_srv
00215 {
00216         uint16_t  priority;
00217         uint16_t  weight;
00218         uint16_t  port;
00219         struct nip_mdns_name target;
00220 }
00221 #ifndef DOXYGEN
00222 __attribute__((packed))
00223 #endif
00224 ;
00225 
00226 /** PTR data entry only holds instance name as app, proto and domain are implicit */
00227 #define NIP_MDNS_RDATA_PTR_SIZE  sizeof(nip_mdns_namestring_id_t)
00228 struct nip_mdns_rdata_ptr
00229 {
00230         struct nip_mdns_name name;
00231 }
00232 #ifndef DOXYGEN
00233 __attribute__((packed))
00234 #endif
00235 ;
00236 
00237 struct nip_mdns_rdata_oth
00238 {
00239         nip_mem_handle_t string;
00240 }
00241 #ifndef DOXYGEN
00242 __attribute__((packed))
00243 #endif
00244 ;
00245 
00246 
00247 typedef union
00248 {
00249         struct nip_mdns_rdata_a   a;
00250         struct nip_mdns_rdata_srv srv;
00251         struct nip_mdns_rdata_ptr ptr;
00252         struct nip_mdns_rdata_oth oth;
00253 }
00254 #ifndef DOXYGEN
00255 __attribute__((packed))
00256 #endif
00257 nip_mdns_rdata_t;
00258 
00259 typedef enum
00260 {
00261         NIP_MDNS_TYPE_A     =  1,
00262         NIP_MDNS_TYPE_NS    =  2, // currently not used
00263         NIP_MDNS_TYPE_CNAME =  5, // currently not used
00264         NIP_MDNS_TYPE_SOA   =  6, // currently not used
00265         NIP_MDNS_TYPE_PTR   = 12,
00266         NIP_MDNS_TYPE_MX    = 15,  // currently not used
00267         NIP_MDNS_TYPE_TXT   = 16,
00268         NIP_MDNS_TYPE_AAAA  = 28,  // currently not used
00269         NIP_MDNS_TYPE_SRV   = 33,
00270         NIP_MDNS_TYPE_ANY   = 255
00271 }
00272 #ifndef DOXYGEN
00273 __attribute__((packed))
00274 #endif
00275 nip_mdns_type_t;
00276 
00277 typedef enum
00278 {
00279         NIP_MDNS_STAT_DOWN = 0, /**< mDNS inactive */
00280         NIP_MDNS_STAT_INIT,     /**< mDNS trying to go up, initialization pending */
00281         NIP_MDNS_STAT_UP,       /**< mDNS up -> statemachines running */
00282         NIP_MDNS_STAT_CACHE_CHECK,
00283         NIP_MDNS_STAT_QUERY_CHECK,
00284         NIP_MDNS_STAT_RESET,    /**< mDNS waiting for reset */
00285         NIP_MDNS_STAT_BYE       /**< mDNS going down */
00286 }
00287 #ifndef DOXYGEN
00288 __attribute__((packed))
00289 #endif
00290 nip_mdns_status_t;
00291 
00292 /** All Cache entries with the NIP_MDNS_CSTAT_AUTHORATIVE_BIT status bit set are
00293  * considered authorative and will be used to reply to remote queries and will
00294  * be defended upon conflicts. */
00295 #define NIP_MDNS_CSTAT_AUTH_BIT    0x01
00296 #define NIP_MDNS_CSTAT_AUTH_MASK   0x0F
00297 /** All Cache entries with the NIP_MDNS_CSTAT_LEARNED_BIT status bit set are
00298  * considered learned and bound to one or more local queries. */
00299 #define NIP_MDNS_CSTAT_LEARNED_BIT        0x80
00300 #define NIP_MDNS_CSTAT_LEARNED_MASK       0xF0
00301 typedef enum
00302 {
00303         NIP_MDNS_CSTAT_PROBING       = 0x02, /**< item is being registered */
00304         NIP_MDNS_CSTAT_PROBECONFLICT = 0x04, /**< probing failed, select new name */
00305         NIP_MDNS_CSTAT_AUTHORATIVE   = 0x01, /**< item has been registered but must
00306                                               * not be defended (need not be unique) */
00307         NIP_MDNS_CSTAT_UNIQUE_AUTH   = 0x09, /**< item has been registered and must
00308                                               * be defended (is unique) */
00309         NIP_MDNS_CSTAT_ANNOUNCING    = 0x03, /**< item is being announced */
00310         NIP_MDNS_CSTAT_CONFLICT      = 0x05, /**< conflict on authorative item */
00311         NIP_MDNS_CSTAT_DELETE        = 0x00, /**< item is scheduled for deletion -> notify
00312                                                * subscribers */
00313         NIP_MDNS_CSTAT_LEARNED   = 0x80, /**< item has been learned through MDNS */
00314         NIP_MDNS_CSTAT_REFRESH   = 0x90, /**< item timed out and we're trying to refresh */
00315         NIP_MDNS_CSTAT_OUTDATED1 = 0xA0, /**< someone else asked for this item */
00316         NIP_MDNS_CSTAT_OUTDATED2 = 0xB0, /**< someone asked for this item again, previous question unanswered */
00317 }
00318 #ifndef DOXYGEN
00319 __attribute__((packed))
00320 #endif
00321 nip_mdns_cache_status_t;
00322 
00323 typedef enum
00324 {
00325         NIP_MDNS_TASK_UNREGISTER = 0x00,  /**< unregister authorative record */
00326         NIP_MDNS_TASK_REGISTER = 0x01,  /**< register authorative record */
00327         NIP_MDNS_TASK_REGUNIQUE= 0x11,  /**< register UNIQUE authorative record */
00328         NIP_MDNS_TASK_LEARN    = 0x20,  /**< learning remote record */
00329         NIP_MDNS_TASK_SEARCH   = 0x30,  /**< search record */
00330         NIP_MDNS_TASK_GET      = 0x80,  /**< return record data for given, learned Cache ID */
00331         NIP_MDNS_TASK_GET_LEARNED=0x90, /**< return record data for given, authorative Cache ID */
00332         NIP_MDNS_TASK_RESET    = 0x40   /**< reset cache */
00333 }
00334 #ifndef DOXYGEN
00335 __attribute__((packed))
00336 #endif
00337 nip_mdns_task_t;
00338 
00339 typedef enum
00340 {
00341         NIP_MDNS_NFYTASK_NOTIFY      = 0x01,/**< notify query about cache change */
00342         NIP_MDNS_NFYTASK_SUBSCRIBE   = 0x11,/**< add cache subscription */
00343         NIP_MDNS_NFYTASK_UNSUBSCRIBE = 0x10,/**< remove subscription    */
00344         NIP_MDNS_NFYTASK_NOTIFIED    = 0x20 /**< remove notification marker */
00345 }
00346 #ifndef DOXYGEN
00347 __attribute__((packed))
00348 #endif
00349 nip_mdns_nfy_task_t;
00350 
00351 typedef enum
00352 {
00353         NIP_MDNS_NTASK_FIND,        /**< check if name from query is in cache */
00354         NIP_MDNS_NTASK_WRITE,       /**< write name to query */
00355 }
00356 #ifndef DOXYGEN
00357 __attribute__((packed))
00358 #endif
00359 nip_mdns_name_task_t;
00360 
00361 #define NIP_MDNS_QTYPE_TX_BIT     0x80
00362 #define NIP_MDNS_QTYPE_LOCAL_BIT  0x01
00363 #define NIP_MDNS_QTYPE_REMOTE_BIT 0x02
00364 
00365 /** Query types. The enumeration values are chosen so that the lower two bits
00366  * decide what packet type will result from the query. That is: LOCAL, PROBE and
00367  * REMLOC queries will result in a Query-Packet being sent when the timer triggers.
00368  * REMOTE and REMLOC queries will result in a Response-Packet being sent, whenever
00369  * there are active Remote-Subscriptions. The High-order Bit indicates Queries
00370  * that are actively transmitted on the network.
00371  */
00372 typedef enum
00373 {
00374         NIP_MDNS_QTYPE_LOCAL    = 0x81, /**< local query that we're caching remote records for */
00375         NIP_MDNS_QTYPE_REMOTE   = 0x02, /**< remote query that we have authorative records for */
00376         NIP_MDNS_QTYPE_REMLOC   = 0x83, /**< query is remote and local */
00377         NIP_MDNS_QTYPE_PROBE    = 0x82, /**< probe query */
00378         NIP_MDNS_QTYPE_ANNOUNCE = 0x12  /**< Fake remote query to collect announcement answers */
00379 }
00380 #ifndef DOXYGEN
00381 __attribute__((packed))
00382 #endif
00383 nip_mdns_query_type_t;
00384 
00385 /** The lower two Bits of Packet type describe wether a Query or a Response
00386  * packet will be sent. The higher Bits are used to code additional information
00387  * that is needed to determine timing and answer coding. */
00388 typedef enum
00389 {
00390         NIP_MDNS_PTYPE_NONE          = 0x00,
00391         NIP_MDNS_PTYPE_QUERY         = 0x01,
00392         NIP_MDNS_PTYPE_RESPONSE      = 0x02,
00393         NIP_MDNS_PTYPE_PROBE         = 0x11,
00394         NIP_MDNS_PTYPE_ANSWCONTINUED = 0x21,/**< continuation of known answers */
00395         NIP_MDNS_PTYPE_PROBERESPONSE = 0x12 /**< special type to signal urgency.*/
00396 }
00397 #ifndef DOXYGEN
00398 __attribute__((packed))
00399 #endif
00400 nip_mdns_packet_type_t;
00401 
00402 struct nip_mdns_query
00403 {
00404         nip_mdns_query_id_t   id;       /**< unique query ID */
00405         nip_mdns_query_type_t type;     /**< query type */
00406         uint8_t               timer;    /**< transmit when timer reaches 0 */
00407         struct nip_mdns_name  rr_name;  /**< resource record name */
00408         nip_mdns_type_t       rr_type;  /**< resource record type */
00409 }
00410 #ifndef DOXYGEN
00411 __attribute__((packed))
00412 #endif
00413 ;
00414 
00415 #define NIP_MDNS_STRINGOFF (sizeof(nip_mdns_namestring_id_t)+sizeof(nip_mdns_namestring_usg_t))
00416 struct nip_mdns_namestring
00417 {
00418         nip_mdns_namestring_id_t   id;   /**< unique namestring ID */
00419         nip_mdns_namestring_usg_t  usg;  /**< namestring usage counter */
00420         struct nip_dns_string      str;  /**< dns string */
00421 }
00422 #ifndef DOXYGEN
00423 __attribute__((packed))
00424 #endif
00425 ;
00426 #define NIP_MDNS_BASE_RECORD_SIZE (sizeof(struct nip_mdns_record)-sizeof(nip_mdns_rdata_t))
00427 #define NIP_MDNS_OTH_RECORD_SIZE (NIP_MDNS_BASE_RECORD_SIZE+sizeof(struct nip_mdns_rdata_oth))
00428 #define NIP_MDNS_A_RECORD_SIZE   (NIP_MDNS_BASE_RECORD_SIZE+sizeof(struct nip_mdns_rdata_a  ))
00429 #define NIP_MDNS_SRV_RECORD_SIZE (NIP_MDNS_BASE_RECORD_SIZE+sizeof(struct nip_mdns_rdata_srv))
00430 #define NIP_MDNS_PTR_RECORD_SIZE (NIP_MDNS_BASE_RECORD_SIZE+sizeof(struct nip_mdns_rdata_ptr))
00431 typedef uint8_t nip_mdns_record_size_t;
00432 
00433 struct nip_mdns_record
00434 {
00435         nip_mdns_type_t       type; /**< DNS type of record */
00436         struct nip_mdns_name  name; /**< DNS name of record, depending on type */
00437         uint16_t              ttl;  /**< time to live */
00438 
00439         // "data" MUST be last attribute of nip_mdns_record
00440         nip_mdns_rdata_t      data; /**< record body, depending on type */
00441 }
00442 #ifndef DOXYGEN
00443 __attribute__((packed))
00444 #endif
00445 ;
00446 
00447 #define NIP_MDNS_BASE_CACHE_SIZE (sizeof(struct nip_mdns_cache)-sizeof(struct nip_mdns_record))
00448 struct nip_mdns_cache
00449 {
00450         nip_mdns_cache_id_t id;
00451         uint16_t            age;  /**< age of entry. entry will be deleted if age
00452                                     * exceeds record.ttl */
00453         nip_mdns_cache_status_t stat;
00454         struct nip_mdns_record record;
00455 }
00456 #ifndef DOXYGEN
00457 __attribute__((packed))
00458 #endif
00459 ;
00460 
00461 struct nip_mdns_cache_subscription
00462 {
00463         nip_mdns_cache_id_t   c_id; /**< cache id */
00464         nip_mdns_query_id_t   q_id; /**< query id */
00465 }
00466 #ifndef DOXYGEN
00467 __attribute__((packed))
00468 #endif
00469 ;
00470 
00471 #if NIP_MDNS_COUNTER_SIZE == 1
00472         typedef uint8_t nip_mdns_qa_counter_t;
00473 #else
00474         typedef uint16_t nip_mdns_qa_counter_t;
00475 #endif
00476 
00477 #define NIP_MDNS_QA_COUNTERS_OFFSET 4 /**< counter offset in dns header */
00478 #define NIP_MDNS_QA_COUNTERS_NUMBER 4 /**< number of query/answer counters */
00479 /** Section types in DNS packet. The values are also used as qa_count-array
00480  * item selectors and as 16-bit offsets in DNS header starting at the
00481  * NIP_MDNS_QA_COUNTERS_OFFSET position of the header. DO NOT ALTER THE VALUES
00482  * unless you change a whole bunch of code along with it. */
00483 typedef enum
00484 {
00485         NIP_MDNS_QDCOUNT_OFFSET = 0,
00486         NIP_MDNS_ANCOUNT_OFFSET = 1,
00487         NIP_MDNS_NSCOUNT_OFFSET = 2,
00488         NIP_MDNS_ARCOUNT_OFFSET = 3
00489 }
00490 #ifndef DOXYGEN
00491 __attribute__((packed))
00492 #endif
00493 nip_mdns_qa_offset_t;
00494 
00495 typedef enum
00496 {
00497         NIP_MDNS_PTASK_INC_COUNTER, /**< increment one of the section counters. */
00498         NIP_MDNS_PTASK_SECTION_PTR, /**< move pointer to specific section */
00499         NIP_MDNS_PTASK_SET_TC,      /**< set truncated flag (TC-flag) in header */
00500         NIP_MDNS_PTASK_NEXT_ITEM    /**< forward pointer to next item in section */
00501 }
00502 #ifndef DOXYGEN
00503 __attribute__((packed))
00504 #endif
00505 nip_mdns_packet_task_t;
00506 
00507 
00508 
00509 struct nip_mdns_check
00510 {
00511         nip_mdns_status_t      stat; /**< state of mdns-check function */
00512         nip_mdns_packet_type_t recv; /**< type of packet in receive queue */
00513         uint16_t               recv_size;
00514         nip_mdns_packet_type_t send; /**< type of packet in send queue */
00515 //      nip_mdns_qa_counter_t  qa_count[ NIP_MDNS_QA_COUNTERS_NUMBER ];
00516 }
00517 #ifndef DOXYGEN
00518 __attribute__((packed))
00519 #endif
00520 ;
00521 
00522 // UNUSED /** mDNS configuration structure */
00523 // struct nip_mdns_config
00524 // {
00525 //      nip_mdns_status_t        stat;
00526 //      nip_mdns_cache_id_t      hostname; /** ID of hostname cachid */
00527 //      nip_mdns_namestring_id_t domain;   /** registration of local domain-name */
00528 //      nip_mem_handle_t         cs;       /** cache subscriptions */
00529 //      nip_mem_handle_t         cache;    /** DNS cache */
00530 //      nip_mem_handle_t         names;    /** DNS name strings */
00531 //      nip_mem_handle_t         queries;  /** DNS queries */
00532 // }
00533 // #ifndef DOXYGEN
00534 // __attribute__((packed))
00535 // #endif
00536 // ;
00537 /** @name Macros for Management of DNS names */
00538 //@{
00539 /** Register name string. That is just one part of a name.
00540  * @return namestring ID */
00541 #define NIP_MDNS_REG_STRING( name_ptr ) nip_mdns_register_name( NULL, 0, name_ptr, 1 )
00542 /** Register dns-encoded name. Name will be decoded from name_ptr. At most idcnt
00543  * part-IDs will be written to idarr.
00544  * @return ID of last part on SUCCESS */
00545 #define NIP_MDNS_REG_NAME( idarr, idcnt, name_ptr ) nip_mdns_register_name( idarr, idcnt, name_ptr, 1 )
00546 
00547 /** Increment name usage. Usage of at most idcnt items in idarr will be increased by 1
00548  * @return NIP_MDNS_NO_NAMESTRING on error*/
00549 #define NIP_MDNS_NAME_USE( idarr, idcnt ) nip_mdns_register_name( idarr, idcnt, NULL, 1 )
00550 /** Unregister name occurence. Usage of at most idcnt items in idarr will be decreased by 1
00551  * @return NIP_MDNS_NO_NAMESTRING on error */
00552 #define NIP_MDNS_UNREG_NAME( idarr, idcnt ) nip_mdns_register_name( idarr, idcnt, NULL, -1 )
00553 /** Does name exist in list?
00554  * @return NIP_MDNS_NO_NAMESTRING on failure*/
00555 #define NIP_MDNS_CHECK_NAME( name_ptr ) nip_mdns_register_name( NULL, 0, name_ptr, 0 )
00556 /** Write mdns-encoded name to buffer. At most idcnt items of idarr will be
00557  * concatenated and written to buffer.
00558  * @todo has yet to be implemented
00559  * @return NIP_MDNS_NO_NAMESTRING on error */
00560 #define NIP_MDNS_WRITE_NAME( idarr, idcnt, buf_ptr ) nip_mdns_register_name( idarr, idcnt, buf_ptr, 0 )
00561 //@}
00562 
00563 /** @name Macros for Management of DNS Queries */
00564 //@{
00565 /** Send PROBE request for record */
00566 #define NIP_MDNS_PROBE( name ) \
00567 nip_mdns_query( NIP_MDNS_QTYPE_PROBE, name, NIP_MDNS_TYPE_ANY )
00568 
00569 /** Send Announcements for record */
00570 #define NIP_MDNS_ANNOUNCE( name ) \
00571 nip_mdns_query( NIP_MDNS_QTYPE_ANNOUNCE, name, NIP_MDNS_TYPE_ANY )
00572 
00573 #define NIP_MDNS_SUBSCRIBE_REMOTE( c_id, q_id ) \
00574 nip_mdns_notify( NIP_MDNS_NFYTASK_SUBSCRIBE, c_id, q_id, NIP_MDNS_NFY_REMOTE )
00575 
00576 #define NIP_MDNS_UNSUBSCRIBE_QUERY( q_id ) \
00577 nip_mdns_notify( NIP_MDNS_NFYTASK_UNSUBSCRIBE, NIP_MDNS_NO_CACHE_ID, q_id, NIP_MDNS_NFY_ALL )
00578 
00579 /** Cache subscriptions for (Remote) Queries will be removed upon notification */
00580 #define NIP_MDNS_QUERY_NOTIFIED( c_id, q_id ) \
00581 nip_mdns_notify( NIP_MDNS_NFYTASK_NOTIFIED, c_id, q_id, NIP_MDNS_NFY_REMOTE )
00582 
00583 //@}
00584 
00585 /** @name Macros for Management of DNS Cache */
00586 //@{
00587 #define NIP_MDNS_REGISTER( cache_id_ptr, record_ptr ) \
00588 nip_mdns_cache_task( NIP_MDNS_TASK_REGISTER, cache_id_ptr, record_ptr )
00589 
00590 #define NIP_MDNS_UNREGISTER( cache_id_ptr ) \
00591 nip_mdns_cache_task( NIP_MDNS_TASK_UNREGISTER, cache_id_ptr, NULL )
00592 
00593 #define NIP_MDNS_REGUNIQUE( cache_id_ptr, record_ptr ) \
00594 nip_mdns_cache_task( NIP_MDNS_TASK_REGUNIQUE, cache_id_ptr, record_ptr )
00595 
00596 #define NIP_MDNS_RESET_CACHE() \
00597 nip_mdns_cache_task( NIP_MDNS_TASK_RESET, NULL, NULL )
00598 
00599 #define NIP_MDNS_GET_RECORD( cache_id_ptr, record_ptr ) \
00600 nip_mdns_cache_task( NIP_MDNS_TASK_GET_LEARNED, cache_id_ptr, record_ptr )
00601 
00602 #define NIP_MDNS_GET_LEARNED_CSTAT( item_ptr ) \
00603 ((item_ptr)->stat & NIP_MDNS_CSTAT_LEARNED_MASK)
00604 
00605 #define NIP_MDNS_GET_AUTH_CSTAT( item_ptr ) \
00606 ((item_ptr)->stat & NIP_MDNS_CSTAT_AUTH_MASK)
00607 
00608 #define NIP_MDNS_SET_LEARNED_CSTAT( item_ptr, newstat ) \
00609 (item_ptr)->stat = ((item_ptr)->stat & ~NIP_MDNS_CSTAT_LEARNED_MASK) | newstat
00610 
00611 #define NIP_MDNS_SET_AUTH_CSTAT( item_ptr, newstat ) \
00612 (item_ptr)->stat = ((item_ptr)->stat & ~NIP_MDNS_CSTAT_LEARNED_MASK) | newstat
00613 
00614 //@}
00615 
00616 
00617 extern nip_mdns_query_id_t      nip_mdns_hostname_queries;
00618 
00619 
00620 nip_error_t nip_mdns_init( void );
00621 
00622 void nip_mdns_interface_up( nip_net_if_id_t if_id );
00623 void nip_mdns_interface_down( void );
00624 
00625 nip_mdns_query_id_t nip_mdns_query( nip_mdns_query_type_t qtype, struct nip_mdns_name *name, nip_mdns_type_t type );
00626 nip_mdns_cache_id_t nip_mdns_fetch_results( nip_mdns_query_id_t r_id );
00627 nip_error_t nip_mdns_close( nip_mdns_query_id_t r_id );
00628 
00629 nip_mdns_namestring_id_t nip_mdns_register_name( nip_mdns_namestring_id_t *id, uint8_t cnt, nip_mem_ptr_t *name_ptr, nip_mdns_namestring_usg_t usg );
00630 
00631 struct nip_mdns_cache *nip_mdns_cache_ptr( nip_mdns_cache_id_t id );
00632 nip_error_t nip_mdns_cache_task( nip_mdns_task_t task, nip_mdns_cache_id_t *id, struct nip_mdns_record *record );
00633 void nip_mdns_disp_check( void );
00634 
00635 #endif /* _MDNS_H_ */

Generated on Thu Jul 10 01:09:29 2008 for NIP by  doxygen 1.5.5