1 /** @file
2   This file defines the EFI Domain Name Service Binding Protocol interface. It is split
3   into the following two main sections:
4   DNSv4 Service Binding Protocol (DNSv4SB)
5   DNSv4 Protocol (DNSv4)
6 
7   Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
8   This program and the accompanying materials
9   are licensed and made available under the terms and conditions of the BSD License
10   which accompanies this distribution. The full text of the license may be found at
11   http://opensource.org/licenses/bsd-license.php
12 
13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 
16   @par Revision Reference:
17   This Protocol is introduced in UEFI Specification 2.5
18 
19 **/
20 
21 #ifndef __EFI_DNS4_PROTOCOL_H__
22 #define __EFI_DNS4_PROTOCOL_H__
23 
24 #define EFI_DNS4_SERVICE_BINDING_PROTOCOL_GUID \
25   { \
26     0xb625b186, 0xe063, 0x44f7, {0x89, 0x5, 0x6a, 0x74, 0xdc, 0x6f, 0x52, 0xb4 } \
27   }
28 
29 #define EFI_DNS4_PROTOCOL_GUID \
30   { \
31     0xae3d28cc, 0xe05b, 0x4fa1, {0xa0, 0x11, 0x7e, 0xb5, 0x5a, 0x3f, 0x14, 0x1 } \
32   }
33 
34 typedef struct _EFI_DNS4_PROTOCOL EFI_DNS4_PROTOCOL;
35 
36 ///
37 /// EFI_DNS4_CONFIG_DATA
38 ///
39 typedef struct {
40   ///
41   /// Count of the DNS servers. When used with GetModeData(),
42   /// this field is the count of originally configured servers when
43   /// Configure() was called for this instance. When used with
44   /// Configure() this is the count of caller-supplied servers. If the
45   /// DnsServerListCount is zero, the DNS server configuration
46   /// will be retrieved from DHCP server automatically.
47   ///
48   UINTN                         DnsServerListCount;
49   ///
50   /// Pointer to DNS server list containing DnsServerListCount entries or NULL
51   /// if DnsServerListCountis 0. For Configure(), this will be NULL when there are
52   /// no caller supplied server addresses, and, the DNS instance will retrieve
53   /// DNS server from DHCP Server. The provided DNS server list is
54   /// recommended to be filled up in the sequence of preference. When
55   /// used with GetModeData(), the buffer containing the list will
56   /// be allocated by the driver implementing this protocol and must be
57   /// freed by the caller. When used with Configure(), the buffer
58   /// containing the list will be allocated and released by the caller.
59   ///
60   EFI_IPv4_ADDRESS              *DnsServerList;
61   ///
62   /// Set to TRUE to use the default IP address/subnet mask and default routing table.
63   ///
64   BOOLEAN                       UseDefaultSetting;
65   ///
66   /// If TRUE, enable DNS cache function for this DNS instance. If FALSE, all DNS
67   /// query will not lookup local DNS cache.
68   ///
69   BOOLEAN                       EnableDnsCache;
70   ///
71   /// Use the protocol number defined in "Links to UEFI-Related
72   /// Documents"(http://uefi.org/uefi) under the heading "IANA
73   /// Protocol Numbers". Only TCP or UDP are supported, and other
74   /// protocol values are invalid. An implementation can choose to
75   /// support only UDP, or both TCP and UDP.
76   ///
77   UINT8                         Protocol;
78   ///
79   /// If UseDefaultSetting is FALSE indicates the station address to use.
80   ///
81   EFI_IPv4_ADDRESS              StationIp;
82   ///
83   /// If UseDefaultSetting is FALSE indicates the subnet mask to use.
84   ///
85   EFI_IPv4_ADDRESS              SubnetMask;
86   ///
87   /// Local port number. Set to zero to use the automatically assigned port number.
88   ///
89   UINT16                        LocalPort;
90   ///
91   /// Retry number if no response received after RetryInterval.
92   ///
93   UINT32                        RetryCount;
94   ///
95   /// Minimum interval of retry is 2 second. If the retry interval is less than 2
96   /// seconds, then use the 2 seconds.
97   ///
98   UINT32                        RetryInterval;
99 } EFI_DNS4_CONFIG_DATA;
100 
101 
102 ///
103 /// EFI_DNS4_CACHE_ENTRY
104 ///
105 typedef struct {
106   ///
107   /// Host name.
108   ///
109   CHAR16                        *HostName;
110   ///
111   /// IP address of this host.
112   ///
113   EFI_IPv4_ADDRESS              *IpAddress;
114   ///
115   /// Time in second unit that this entry will remain in DNS cache. A value of zero
116   /// means that this entry is permanent. A nonzero value will override the existing
117   /// one if this entry to be added is dynamic entry. Implementations may set its
118   /// default timeout value for the dynamically created DNS cache entry after one DNS
119   /// resolve succeeds.
120   ///
121   UINT32                        Timeout;
122 } EFI_DNS4_CACHE_ENTRY;
123 
124 ///
125 /// EFI_DNS4_MODE_DATA
126 ///
127 typedef struct {
128   ///
129   /// The configuration data of this instance.
130   ///
131   EFI_DNS4_CONFIG_DATA          DnsConfigData;
132   ///
133   /// Number of configured DNS server. Each DNS instance has its own DNS server
134   /// configuration.
135   ///
136   UINT32                        DnsServerCount;
137   ///
138   /// Pointer to common list of addresses of all configured DNS server
139   /// used by EFI_DNS4_PROTOCOL instances. List will include
140   /// DNS servers configured by this or any other EFI_DNS4_PROTOCOL instance.
141   /// The storage for this list is allocated by the driver publishing this
142   /// protocol, and must be freed by the caller.
143   ///
144   EFI_IPv4_ADDRESS              *DnsServerList;
145   ///
146   /// Number of DNS Cache entries. The DNS Cache is shared among all DNS instances.
147   ///
148   UINT32                        DnsCacheCount;
149   ///
150   /// Pointer to a buffer containing DnsCacheCount DNS Cache
151   /// entry structures. The storage for this list is allocated by the driver
152   /// publishing this protocol and must be freed by caller.
153   ///
154   EFI_DNS4_CACHE_ENTRY          *DnsCacheList;
155 } EFI_DNS4_MODE_DATA;
156 
157 ///
158 /// DNS_HOST_TO_ADDR_DATA
159 ///
160 typedef struct {
161   ///
162   /// Number of the returned IP addresses.
163   ///
164   UINT32                        IpCount;
165   ///
166   /// Pointer to the all the returned IP addresses.
167   ///
168   EFI_IPv4_ADDRESS              *IpList;
169 } DNS_HOST_TO_ADDR_DATA;
170 
171 ///
172 /// DNS_ADDR_TO_HOST_DATA
173 ///
174 typedef struct {
175   ///
176   /// Pointer to the primary name for this host address. It's the caller's
177   /// responsibility to free the response memory.
178   ///
179   CHAR16                        *HostName;
180 } DNS_ADDR_TO_HOST_DATA;
181 
182 ///
183 /// DNS_RESOURCE_RECORD
184 ///
185 typedef struct {
186   ///
187   /// The Owner name.
188   ///
189   CHAR8                         *QName;
190   ///
191   /// The Type Code of this RR.
192   ///
193   UINT16                        QType;
194   ///
195   /// The CLASS code of this RR.
196   ///
197   UINT16                        QClass;
198   ///
199   /// 32 bit integer which specify the time interval that the resource record may be
200   /// cached before the source of the information should again be consulted. Zero means
201   /// this RR can not be cached.
202   ///
203   UINT32                        TTL;
204   ///
205   /// 16 big integer which specify the length of RData.
206   ///
207   UINT16                        DataLength;
208   ///
209   /// A string of octets that describe the resource, the format of this information
210   /// varies according to QType and QClass difference.
211   ///
212   CHAR8                         *RData;
213 } DNS_RESOURCE_RECORD;
214 
215 ///
216 /// DNS_GENERAL_LOOKUP_DATA
217 ///
218 typedef struct {
219   ///
220   /// Number of returned matching RRs.
221   ///
222   UINTN                         RRCount;
223   ///
224   /// Pointer to the all the returned matching RRs. It's caller responsibility to free
225   /// the allocated memory to hold the returned RRs.
226   ///
227   DNS_RESOURCE_RECORD           *RRList;
228 } DNS_GENERAL_LOOKUP_DATA;
229 
230 ///
231 /// EFI_DNS4_COMPLETION_TOKEN
232 ///
233 typedef struct {
234   ///
235   /// This Event will be signaled after the Status field is updated by the EFI DNS
236   /// protocol driver. The type of Event must be EFI_NOTIFY_SIGNAL.
237   ///
238   EFI_EVENT                               Event;
239   ///
240   /// Will be set to one of the following values:
241   ///   EFI_SUCCESS:      The host name to address translation completed successfully.
242   ///   EFI_NOT_FOUND:    No matching Resource Record (RR) is found.
243   ///   EFI_TIMEOUT:      No DNS server reachable, or RetryCount was exhausted without
244   ///                     response from all specified DNS servers.
245   ///   EFI_DEVICE_ERROR: An unexpected system or network error occurred.
246   ///   EFI_NO_MEDIA:     There was a media error.
247   ///
248   EFI_STATUS                              Status;
249   ///
250   /// Retry number if no response received after RetryInterval. If zero, use the
251   /// parameter configured through Dns.Configure() interface.
252   ///
253   UINT32                                  RetryCount;
254   ///
255   /// Minimum interval of retry is 2 second. If the retry interval is less than 2
256   /// seconds, then use the 2 seconds. If zero, use the parameter configured through
257   /// Dns.Configure() interface.
258   UINT32                                  RetryInterval;
259   ///
260   /// DNSv4 completion token data
261   ///
262   union {
263     ///
264     /// When the Token is used for host name to address translation, H2AData is a pointer
265     /// to the DNS_HOST_TO_ADDR_DATA.
266     ///
267     DNS_HOST_TO_ADDR_DATA         *H2AData;
268     ///
269     /// When the Token is used for host address to host name translation, A2HData is a
270     /// pointer to the DNS_ADDR_TO_HOST_DATA.
271     ///
272     DNS_ADDR_TO_HOST_DATA         *A2HData;
273     ///
274     /// When the Token is used for a general lookup function, GLookupDATA is a pointer to
275     /// the DNS_GENERAL_LOOKUP_DATA.
276     ///
277     DNS_GENERAL_LOOKUP_DATA       *GLookupData;
278   } RspData;
279 } EFI_DNS4_COMPLETION_TOKEN;
280 
281 /**
282   Retrieve mode data of this DNS instance.
283 
284   This function is used to retrieve DNS mode data for this DNS instance.
285 
286   @param[in]   This               Pointer to EFI_DNS4_PROTOCOL instance.
287   @param[out]  DnsModeData        Point to the mode data.
288 
289   @retval EFI_SUCCESS             The operation completed successfully.
290   @retval EFI_NOT_STARTED         When DnsConfigData is queried, no configuration data
291                                   is available because this instance has not been
292                                   configured.
293   @retval EFI_INVALID_PARAMETER   This is NULL or DnsModeData is NULL.
294   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
295 **/
296 typedef
297 EFI_STATUS
298 (EFIAPI *EFI_DNS4_GET_MODE_DATA) (
299   IN  EFI_DNS4_PROTOCOL          *This,
300   OUT EFI_DNS4_MODE_DATA         *DnsModeData
301   );
302 
303 /**
304   Configure this DNS instance.
305 
306   This function is used to configure DNS mode data for this DNS instance.
307 
308   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
309   @param[in]  DnsConfigData       Point to the Configuration data.
310 
311   @retval EFI_SUCCESS             The operation completed successfully.
312   @retval EFI_UNSUPPORTED         The designated protocol is not supported.
313   @retval EFI_INVALID_PARAMTER    Thisis NULL.
314                                   The StationIp address provided in DnsConfigData is not a
315                                   valid unicast.
316                                   DnsServerList is NULL while DnsServerListCount
317                                   is not ZERO.
318                                   DnsServerListCount is ZERO while DnsServerList
319                                   is not NULL
320   @retval EFI_OUT_OF_RESOURCES    The DNS instance data or required space could not be
321                                   allocated.
322   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. The
323                                   EFI DNSv4 Protocol instance is not configured.
324   @retval EFI_ALREADY_STARTED     Second call to Configure() with DnsConfigData. To
325                                   reconfigure the instance the caller must call Configure()
326                                   with NULL first to return driver to unconfigured state.
327 **/
328 typedef
329 EFI_STATUS
330 (EFIAPI *EFI_DNS4_CONFIGURE) (
331   IN EFI_DNS4_PROTOCOL          *This,
332   IN EFI_DNS4_CONFIG_DATA       *DnsConfigData
333   );
334 
335 /**
336   Host name to host address translation.
337 
338   The HostNameToIp () function is used to translate the host name to host IP address. A
339   type A query is used to get the one or more IP addresses for this host.
340 
341   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
342   @param[in]  Hostname            Host name.
343   @param[in]  Token               Point to the completion token to translate host name
344                                   to host address.
345 
346   @retval EFI_SUCCESS             The operation completed successfully.
347   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
348                                   This is NULL.
349                                   Token is NULL.
350                                   Token.Event is NULL.
351                                   HostName is NULL. HostName string is unsupported format.
352   @retval EFI_NO_MAPPING          There's no source address is available for use.
353   @retval EFI_NOT_STARTED         This instance has not been started.
354 **/
355 typedef
356 EFI_STATUS
357 (EFIAPI *EFI_DNS4_HOST_NAME_TO_IP) (
358    IN EFI_DNS4_PROTOCOL         *This,
359    IN CHAR16                    *HostName,
360    IN EFI_DNS4_COMPLETION_TOKEN *Token
361   );
362 
363 /**
364   IPv4 address to host name translation also known as Reverse DNS lookup.
365 
366   The IpToHostName() function is used to translate the host address to host name. A type PTR
367   query is used to get the primary name of the host. Support of this function is optional.
368 
369   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
370   @param[in]  IpAddress           Ip Address.
371   @param[in]  Token               Point to the completion token to translate host
372                                   address to host name.
373 
374   @retval EFI_SUCCESS             The operation completed successfully.
375   @retval EFI_UNSUPPORTED         This function is not supported.
376   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
377                                   This is NULL.
378                                   Token is NULL.
379                                   Token.Event is NULL.
380                                   IpAddress is not valid IP address .
381   @retval EFI_NO_MAPPING          There's no source address is available for use.
382   @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.
383   @retval EFI_NOT_STARTED         This instance has not been started.
384   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
385 **/
386 typedef
387 EFI_STATUS
388 (EFIAPI *EFI_DNS4_IP_TO_HOST_NAME) (
389    IN EFI_DNS4_PROTOCOL         *This,
390    IN EFI_IPv4_ADDRESS          IpAddress,
391    IN EFI_DNS4_COMPLETION_TOKEN *Token
392   );
393 
394 /**
395   Retrieve arbitrary information from the DNS server.
396 
397   This GeneralLookup() function retrieves arbitrary information from the DNS. The caller
398   supplies a QNAME, QTYPE, and QCLASS, and all of the matching RRs are returned. All
399   RR content (e.g., TTL) was returned. The caller need parse the returned RR to get
400   required information. The function is optional.
401 
402   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
403   @param[in]  QName               Pointer to Query Name.
404   @param[in]  QType               Query Type.
405   @param[in]  QClass              Query Name.
406   @param[in]  Token               Point to the completion token to retrieve arbitrary
407                                   information.
408 
409   @retval EFI_SUCCESS             The operation completed successfully.
410   @retval EFI_UNSUPPORTED         This function is not supported. Or the requested
411                                   QType is not supported
412   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
413                                   This is NULL.
414                                   Token is NULL.
415                                   Token.Event is NULL.
416                                   QName is NULL.
417   @retval EFI_NO_MAPPING          There's no source address is available for use.
418   @retval EFI_ALREADY_STARTED     This Token is being used in another DNS session.
419   @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.
420 **/
421 typedef
422 EFI_STATUS
423 (EFIAPI *EFI_DNS4_GENERAL_LOOKUP) (
424   IN EFI_DNS4_PROTOCOL          *This,
425   IN CHAR8                      *QName,
426   IN UINT16                     QType,
427   IN UINT16                     QClass,
428   IN EFI_DNS4_COMPLETION_TOKEN  *Token
429   );
430 
431 /**
432   This function is to update the DNS Cache.
433 
434   The UpdateDnsCache() function is used to add/delete/modify DNS cache entry. DNS cache
435   can be normally dynamically updated after the DNS resolve succeeds. This function
436   provided capability to manually add/delete/modify the DNS cache.
437 
438   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
439   @param[in]  DeleteFlag          If FALSE, this function is to add one entry to the
440                                   DNS Cahce. If TRUE, this function will delete
441                                   matching DNS Cache entry.
442   @param[in]  Override            If TRUE, the maching DNS cache entry will be
443                                   overwritten with the supplied parameter. If FALSE,
444                                   EFI_ACCESS_DENIED will be returned if the entry to
445                                   be added is already existed.
446   @param[in]  DnsCacheEntry       Pointer to DNS Cache entry.
447 
448   @retval EFI_SUCCESS             The operation completed successfully.
449   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:
450                                   This is NULL.
451                                   DnsCacheEntry.HostName is NULL.
452                                   DnsCacheEntry.IpAddress is NULL.
453                                   DnsCacheEntry.Timeout is zero.
454   @retval EFI_ACCESS_DENIED       The DNS cache entry already exists and Override is
455                                   not TRUE.
456 **/
457 typedef
458 EFI_STATUS
459 (EFIAPI *EFI_DNS4_UPDATE_DNS_CACHE) (
460   IN EFI_DNS4_PROTOCOL          *This,
461   IN BOOLEAN                    DeleteFlag,
462   IN BOOLEAN                    Override,
463   IN EFI_DNS4_CACHE_ENTRY       DnsCacheEntry
464   );
465 
466 /**
467   Polls for incoming data packets and processes outgoing data packets.
468 
469   The Poll() function can be used by network drivers and applications to increase the
470   rate that data packets are moved between the communications device and the transmit
471   and receive queues.
472   In some systems, the periodic timer event in the managed network driver may not poll
473   the underlying communications device fast enough to transmit and/or receive all data
474   packets without missing incoming packets or dropping outgoing packets. Drivers and
475   applications that are experiencing packet loss should try calling the Poll()
476   function more often.
477 
478   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
479 
480   @retval EFI_SUCCESS             Incoming or outgoing data was processed.
481   @retval EFI_NOT_STARTED         This EFI DNS Protocol instance has not been started.
482   @retval EFI_INVALID_PARAMETER   This is NULL.
483   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred.
484   @retval EFI_TIMEOUT             Data was dropped out of the transmit and/or receive
485                                   queue. Consider increasing the polling rate.
486 **/
487 typedef
488 EFI_STATUS
489 (EFIAPI *EFI_DNS4_POLL) (
490   IN  EFI_DNS4_PROTOCOL         *This
491   );
492 
493 /**
494   Abort an asynchronous DNS operation, including translation between IP and Host, and
495   general look up behavior.
496 
497   The Cancel() function is used to abort a pending resolution request. After calling
498   this function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
499   signaled. If the token is not in one of the queues, which usually means that the
500   asynchronous operation has completed, this function will not signal the token and
501   EFI_NOT_FOUND is returned.
502 
503   @param[in]  This                Pointer to EFI_DNS4_PROTOCOL instance.
504   @param[in]  Token               Pointer to a token that has been issued by
505                                   EFI_DNS4_PROTOCOL.HostNameToIp (),
506                                   EFI_DNS4_PROTOCOL.IpToHostName() or
507                                   EFI_DNS4_PROTOCOL.GeneralLookup().
508                                   If NULL, all pending tokens are aborted.
509 
510   @retval EFI_SUCCESS             Incoming or outgoing data was processed.
511   @retval EFI_NOT_STARTED         This EFI DNS4 Protocol instance has not been started.
512   @retval EFI_INVALID_PARAMETER   This is NULL.
513   @retval EFI_NOT_FOUND           When Token is not NULL, and the asynchronous DNS
514                                   operation was not found in the transmit queue. It
515                                   was either completed or was not issued by
516                                   HostNameToIp(), IpToHostName() or GeneralLookup().
517 **/
518 typedef
519 EFI_STATUS
520 (EFIAPI *EFI_DNS4_CANCEL) (
521   IN  EFI_DNS4_PROTOCOL         *This,
522   IN  EFI_DNS4_COMPLETION_TOKEN *Token
523   );
524 
525 ///
526 /// The EFI_DNS4_Protocol provides the function to get the host name and address
527 /// mapping, also provides pass through interface to retrieve arbitrary information
528 /// from DNS.
529 ///
530 struct _EFI_DNS4_PROTOCOL {
531   EFI_DNS4_GET_MODE_DATA        GetModeData;
532   EFI_DNS4_CONFIGURE            Configure;
533   EFI_DNS4_HOST_NAME_TO_IP      HostNameToIp;
534   EFI_DNS4_IP_TO_HOST_NAME      IpToHostName;
535   EFI_DNS4_GENERAL_LOOKUP       GeneralLookUp;
536   EFI_DNS4_UPDATE_DNS_CACHE     UpdateDnsCache;
537   EFI_DNS4_POLL                 Poll;
538   EFI_DNS4_CANCEL               Cancel;
539 };
540 
541 extern EFI_GUID gEfiDns4ServiceBindingProtocolGuid;
542 extern EFI_GUID gEfiDns4ProtocolGuid;
543 
544 #endif
545