iPXE
Udp4.h
Go to the documentation of this file.
00001 /** @file
00002   UDP4 Service Binding Protocol as defined in UEFI specification.
00003 
00004   The EFI UDPv4 Protocol provides simple packet-oriented services
00005   to transmit and receive UDP packets.
00006 
00007 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
00008 This program and the accompanying materials are licensed and made available under
00009 the terms and conditions of the BSD License that accompanies this distribution.
00010 The full text of the license may be found at
00011 http://opensource.org/licenses/bsd-license.php.
00012 
00013 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
00015 
00016   @par Revision Reference:
00017   This Protocol is introduced in UEFI Specification 2.0.
00018 
00019 **/
00020 
00021 #ifndef __EFI_UDP4_PROTOCOL_H__
00022 #define __EFI_UDP4_PROTOCOL_H__
00023 
00024 FILE_LICENCE ( BSD3 );
00025 
00026 #include <ipxe/efi/Protocol/Ip4.h>
00027 //
00028 //GUID definitions
00029 //
00030 #define EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID \
00031   { \
00032     0x83f01464, 0x99bd, 0x45e5, {0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6 } \
00033   }
00034 
00035 #define EFI_UDP4_PROTOCOL_GUID \
00036   { \
00037     0x3ad9df29, 0x4501, 0x478d, {0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3 } \
00038   }
00039 
00040 typedef struct _EFI_UDP4_PROTOCOL EFI_UDP4_PROTOCOL;
00041 
00042 ///
00043 /// EFI_UDP4_SERVICE_POINT is deprecated in the UEFI 2.4B and should not be used any more.
00044 /// The definition in here is only present to provide backwards compatability.
00045 ///
00046 typedef struct {
00047   EFI_HANDLE              InstanceHandle;
00048   EFI_IPv4_ADDRESS        LocalAddress;
00049   UINT16                  LocalPort;
00050   EFI_IPv4_ADDRESS        RemoteAddress;
00051   UINT16                  RemotePort;
00052 } EFI_UDP4_SERVICE_POINT;
00053 
00054 ///
00055 /// EFI_UDP4_VARIABLE_DATA is deprecated in the UEFI 2.4B and should not be used any more.
00056 /// The definition in here is only present to provide backwards compatability.
00057 ///
00058 typedef struct {
00059   EFI_HANDLE              DriverHandle;
00060   UINT32                  ServiceCount;
00061   EFI_UDP4_SERVICE_POINT  Services[1];
00062 } EFI_UDP4_VARIABLE_DATA;
00063 
00064 typedef struct {
00065   UINT32             FragmentLength;
00066   VOID               *FragmentBuffer;
00067 } EFI_UDP4_FRAGMENT_DATA;
00068 
00069 typedef struct {
00070   EFI_IPv4_ADDRESS   SourceAddress;
00071   UINT16             SourcePort;
00072   EFI_IPv4_ADDRESS   DestinationAddress;
00073   UINT16             DestinationPort;
00074 } EFI_UDP4_SESSION_DATA;
00075 typedef struct {
00076   //
00077   // Receiving Filters
00078   //
00079   BOOLEAN            AcceptBroadcast;
00080   BOOLEAN            AcceptPromiscuous;
00081   BOOLEAN            AcceptAnyPort;
00082   BOOLEAN            AllowDuplicatePort;
00083   //
00084   // I/O parameters
00085   //
00086   UINT8              TypeOfService;
00087   UINT8              TimeToLive;
00088   BOOLEAN            DoNotFragment;
00089   UINT32             ReceiveTimeout;
00090   UINT32             TransmitTimeout;
00091   //
00092   // Access Point
00093   //
00094   BOOLEAN            UseDefaultAddress;
00095   EFI_IPv4_ADDRESS   StationAddress;
00096   EFI_IPv4_ADDRESS   SubnetMask;
00097   UINT16             StationPort;
00098   EFI_IPv4_ADDRESS   RemoteAddress;
00099   UINT16             RemotePort;
00100 } EFI_UDP4_CONFIG_DATA;
00101 
00102 typedef struct {
00103   EFI_UDP4_SESSION_DATA     *UdpSessionData;       //OPTIONAL
00104   EFI_IPv4_ADDRESS          *GatewayAddress;       //OPTIONAL
00105   UINT32                    DataLength;
00106   UINT32                    FragmentCount;
00107   EFI_UDP4_FRAGMENT_DATA    FragmentTable[1];
00108 } EFI_UDP4_TRANSMIT_DATA;
00109 
00110 typedef struct {
00111   EFI_TIME                  TimeStamp;
00112   EFI_EVENT                 RecycleSignal;
00113   EFI_UDP4_SESSION_DATA     UdpSession;
00114   UINT32                    DataLength;
00115   UINT32                    FragmentCount;
00116   EFI_UDP4_FRAGMENT_DATA    FragmentTable[1];
00117 } EFI_UDP4_RECEIVE_DATA;
00118 
00119 
00120 typedef struct {
00121   EFI_EVENT                 Event;
00122   EFI_STATUS                Status;
00123   union {
00124     EFI_UDP4_RECEIVE_DATA   *RxData;
00125     EFI_UDP4_TRANSMIT_DATA  *TxData;
00126   } Packet;
00127 } EFI_UDP4_COMPLETION_TOKEN;
00128 
00129 /**
00130   Reads the current operational settings.
00131 
00132   The GetModeData() function copies the current operational settings of this EFI
00133   UDPv4 Protocol instance into user-supplied buffers. This function is used
00134   optionally to retrieve the operational mode data of underlying networks or
00135   drivers.
00136 
00137   @param  This           The pointer to the EFI_UDP4_PROTOCOL instance.
00138   @param  Udp4ConfigData The pointer to the buffer to receive the current configuration data.
00139   @param  Ip4ModeData    The pointer to the EFI IPv4 Protocol mode data structure.
00140   @param  MnpConfigData  The pointer to the managed network configuration data structure.
00141   @param  SnpModeData    The pointer to the simple network mode data structure.
00142 
00143   @retval EFI_SUCCESS           The mode data was read.
00144   @retval EFI_NOT_STARTED       When Udp4ConfigData is queried, no configuration data is
00145                                 available because this instance has not been started.
00146   @retval EFI_INVALID_PARAMETER This is NULL.
00147 
00148 **/
00149 typedef
00150 EFI_STATUS
00151 (EFIAPI *EFI_UDP4_GET_MODE_DATA)(
00152   IN  EFI_UDP4_PROTOCOL                *This,
00153   OUT EFI_UDP4_CONFIG_DATA             *Udp4ConfigData OPTIONAL,
00154   OUT EFI_IP4_MODE_DATA                *Ip4ModeData    OPTIONAL,
00155   OUT EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData  OPTIONAL,
00156   OUT EFI_SIMPLE_NETWORK_MODE          *SnpModeData    OPTIONAL
00157   );
00158 
00159 
00160 /**
00161   Initializes, changes, or resets the operational parameters for this instance of the EFI UDPv4
00162   Protocol.
00163 
00164   The Configure() function is used to do the following:
00165   * Initialize and start this instance of the EFI UDPv4 Protocol.
00166   * Change the filtering rules and operational parameters.
00167   * Reset this instance of the EFI UDPv4 Protocol.
00168   Until these parameters are initialized, no network traffic can be sent or
00169   received by this instance. This instance can be also reset by calling Configure()
00170   with UdpConfigData set to NULL. Once reset, the receiving queue and transmitting
00171   queue are flushed and no traffic is allowed through this instance.
00172   With different parameters in UdpConfigData, Configure() can be used to bind
00173   this instance to specified port.
00174 
00175   @param  This           The pointer to the EFI_UDP4_PROTOCOL instance.
00176   @param  Udp4ConfigData The pointer to the buffer to receive the current configuration data.
00177 
00178   @retval EFI_SUCCESS           The configuration settings were set, changed, or reset successfully.
00179   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
00180                                 RARP, etc.) is not finished yet.
00181   @retval EFI_INVALID_PARAMETER This is NULL.
00182   @retval EFI_INVALID_PARAMETER UdpConfigData.StationAddress is not a valid unicast IPv4 address.
00183   @retval EFI_INVALID_PARAMETER UdpConfigData.SubnetMask is not a valid IPv4 address mask. The subnet
00184                                 mask must be contiguous.
00185   @retval EFI_INVALID_PARAMETER UdpConfigData.RemoteAddress is not a valid unicast IPv4 address if it
00186                                 is not zero.
00187   @retval EFI_ALREADY_STARTED   The EFI UDPv4 Protocol instance is already started/configured
00188                                 and must be stopped/reset before it can be reconfigured.
00189   @retval EFI_ACCESS_DENIED     UdpConfigData. AllowDuplicatePort is FALSE
00190                                 and UdpConfigData.StationPort is already used by
00191                                 other instance.
00192   @retval EFI_OUT_OF_RESOURCES  The EFI UDPv4 Protocol driver cannot allocate memory for this
00193                                 EFI UDPv4 Protocol instance.
00194   @retval EFI_DEVICE_ERROR      An unexpected network or system error occurred and this instance
00195                                  was not opened.
00196 
00197 **/
00198 typedef
00199 EFI_STATUS
00200 (EFIAPI *EFI_UDP4_CONFIGURE)(
00201   IN EFI_UDP4_PROTOCOL      *This,
00202   IN EFI_UDP4_CONFIG_DATA   *UdpConfigData OPTIONAL
00203   );
00204 
00205 /**
00206   Joins and leaves multicast groups.
00207 
00208   The Groups() function is used to enable and disable the multicast group
00209   filtering. If the JoinFlag is FALSE and the MulticastAddress is NULL, then all
00210   currently joined groups are left.
00211 
00212   @param  This             The pointer to the EFI_UDP4_PROTOCOL instance.
00213   @param  JoinFlag         Set to TRUE to join a multicast group. Set to FALSE to leave one
00214                            or all multicast groups.
00215   @param  MulticastAddress The pointer to multicast group address to join or leave.
00216 
00217   @retval EFI_SUCCESS           The operation completed successfully.
00218   @retval EFI_NOT_STARTED       The EFI UDPv4 Protocol instance has not been started.
00219   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
00220                                 RARP, etc.) is not finished yet.
00221   @retval EFI_OUT_OF_RESOURCES  Could not allocate resources to join the group.
00222   @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
00223                                 - This is NULL.
00224                                 - JoinFlag is TRUE and MulticastAddress is NULL.
00225                                 - JoinFlag is TRUE and *MulticastAddress is not
00226                                   a valid multicast address.
00227   @retval EFI_ALREADY_STARTED   The group address is already in the group table (when
00228                                 JoinFlag is TRUE).
00229   @retval EFI_NOT_FOUND         The group address is not in the group table (when JoinFlag is
00230                                 FALSE).
00231   @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.
00232 
00233 **/
00234 typedef
00235 EFI_STATUS
00236 (EFIAPI *EFI_UDP4_GROUPS)(
00237   IN EFI_UDP4_PROTOCOL      *This,
00238   IN BOOLEAN                JoinFlag,
00239   IN EFI_IPv4_ADDRESS       *MulticastAddress    OPTIONAL
00240   );
00241 
00242 /**
00243   Adds and deletes routing table entries.
00244 
00245   The Routes() function adds a route to or deletes a route from the routing table.
00246   Routes are determined by comparing the SubnetAddress with the destination IP
00247   address and arithmetically AND-ing it with the SubnetMask. The gateway address
00248   must be on the same subnet as the configured station address.
00249   The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
00250   The default route matches all destination IP addresses that do not match any
00251   other routes.
00252   A zero GatewayAddress is a nonroute. Packets are sent to the destination IP
00253   address if it can be found in the Address Resolution Protocol (ARP) cache or
00254   on the local subnet. One automatic nonroute entry will be inserted into the
00255   routing table for outgoing packets that are addressed to a local subnet
00256   (gateway address of 0.0.0.0).
00257   Each instance of the EFI UDPv4 Protocol has its own independent routing table.
00258   Instances of the EFI UDPv4 Protocol that use the default IP address will also
00259   have copies of the routing table provided by the EFI_IP4_CONFIG_PROTOCOL. These
00260   copies will be updated automatically whenever the IP driver reconfigures its
00261   instances; as a result, the previous modification to these copies will be lost.
00262 
00263   @param  This           The pointer to the EFI_UDP4_PROTOCOL instance.
00264   @param  DeleteRoute    Set to TRUE to delete this route from the routing table.
00265                          Set to FALSE to add this route to the routing table.
00266   @param  SubnetAddress  The destination network address that needs to be routed.
00267   @param  SubnetMask     The subnet mask of SubnetAddress.
00268   @param  GatewayAddress The gateway IP address for this route.
00269 
00270   @retval EFI_SUCCESS           The operation completed successfully.
00271   @retval EFI_NOT_STARTED       The EFI UDPv4 Protocol instance has not been started.
00272   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
00273                                 - RARP, etc.) is not finished yet.
00274   @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
00275   @retval EFI_OUT_OF_RESOURCES  Could not add the entry to the routing table.
00276   @retval EFI_NOT_FOUND         This route is not in the routing table.
00277   @retval EFI_ACCESS_DENIED     The route is already defined in the routing table.
00278 
00279 **/
00280 typedef
00281 EFI_STATUS
00282 (EFIAPI *EFI_UDP4_ROUTES)(
00283   IN EFI_UDP4_PROTOCOL      *This,
00284   IN BOOLEAN                DeleteRoute,
00285   IN EFI_IPv4_ADDRESS       *SubnetAddress,
00286   IN EFI_IPv4_ADDRESS       *SubnetMask,
00287   IN EFI_IPv4_ADDRESS       *GatewayAddress
00288   );
00289 
00290 /**
00291   Polls for incoming data packets and processes outgoing data packets.
00292 
00293   The Poll() function can be used by network drivers and applications to increase
00294   the rate that data packets are moved between the communications device and the
00295   transmit and receive queues.
00296   In some systems, the periodic timer event in the managed network driver may not
00297   poll the underlying communications device fast enough to transmit and/or receive
00298   all data packets without missing incoming packets or dropping outgoing packets.
00299   Drivers and applications that are experiencing packet loss should try calling
00300   the Poll() function more often.
00301 
00302   @param  This The pointer to the EFI_UDP4_PROTOCOL instance.
00303 
00304   @retval EFI_SUCCESS           Incoming or outgoing data was processed.
00305   @retval EFI_INVALID_PARAMETER This is NULL.
00306   @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.
00307   @retval EFI_TIMEOUT           Data was dropped out of the transmit and/or receive queue.
00308 
00309 **/
00310 typedef
00311 EFI_STATUS
00312 (EFIAPI *EFI_UDP4_POLL)(
00313   IN EFI_UDP4_PROTOCOL      *This
00314   );
00315 
00316 /**
00317   Places an asynchronous receive request into the receiving queue.
00318 
00319   The Receive() function places a completion token into the receive packet queue.
00320   This function is always asynchronous.
00321   The caller must fill in the Token.Event field in the completion token, and this
00322   field cannot be NULL. When the receive operation completes, the EFI UDPv4 Protocol
00323   driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
00324   is signaled. Providing a proper notification function and context for the event
00325   will enable the user to receive the notification and receiving status. That
00326   notification function is guaranteed to not be re-entered.
00327 
00328   @param  This  The pointer to the EFI_UDP4_PROTOCOL instance.
00329   @param  Token The pointer to a token that is associated with the receive data
00330                 descriptor.
00331 
00332   @retval EFI_SUCCESS           The receive completion token was cached.
00333   @retval EFI_NOT_STARTED       This EFI UDPv4 Protocol instance has not been started.
00334   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP, RARP, etc.)
00335                                 is not finished yet.
00336   @retval EFI_INVALID_PARAMETER This is NULL.
00337   @retval EFI_INVALID_PARAMETER Token is NULL.
00338   @retval EFI_INVALID_PARAMETER Token.Event is NULL.
00339   @retval EFI_OUT_OF_RESOURCES  The receive completion token could not be queued due to a lack of system
00340                                 resources (usually memory).
00341   @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.
00342   @retval EFI_ACCESS_DENIED     A receive completion token with the same Token.Event was already in
00343                                 the receive queue.
00344   @retval EFI_NOT_READY         The receive request could not be queued because the receive queue is full.
00345 
00346 **/
00347 typedef
00348 EFI_STATUS
00349 (EFIAPI *EFI_UDP4_RECEIVE)(
00350   IN EFI_UDP4_PROTOCOL          *This,
00351   IN EFI_UDP4_COMPLETION_TOKEN  *Token
00352   );
00353 
00354 /**
00355   Queues outgoing data packets into the transmit queue.
00356 
00357   The Transmit() function places a sending request to this instance of the EFI
00358   UDPv4 Protocol, alongside the transmit data that was filled by the user. Whenever
00359   the packet in the token is sent out or some errors occur, the Token.Event will
00360   be signaled and Token.Status is updated. Providing a proper notification function
00361   and context for the event will enable the user to receive the notification and
00362   transmitting status.
00363 
00364   @param  This  The pointer to the EFI_UDP4_PROTOCOL instance.
00365   @param  Token The pointer to the completion token that will be placed into the
00366                 transmit queue.
00367 
00368   @retval EFI_SUCCESS           The data has been queued for transmission.
00369   @retval EFI_NOT_STARTED       This EFI UDPv4 Protocol instance has not been started.
00370   @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,
00371                                 RARP, etc.) is not finished yet.
00372   @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
00373   @retval EFI_ACCESS_DENIED     The transmit completion token with the same
00374                                 Token.Event was already in the transmit queue.
00375   @retval EFI_NOT_READY         The completion token could not be queued because the
00376                                 transmit queue is full.
00377   @retval EFI_OUT_OF_RESOURCES  Could not queue the transmit data.
00378   @retval EFI_NOT_FOUND         There is no route to the destination network or address.
00379   @retval EFI_BAD_BUFFER_SIZE   The data length is greater than the maximum UDP packet
00380                                 size. Or the length of the IP header + UDP header + data
00381                                 length is greater than MTU if DoNotFragment is TRUE.
00382 
00383 **/
00384 typedef
00385 EFI_STATUS
00386 (EFIAPI *EFI_UDP4_TRANSMIT)(
00387   IN EFI_UDP4_PROTOCOL           *This,
00388   IN EFI_UDP4_COMPLETION_TOKEN   *Token
00389   );
00390 
00391 /**
00392   Aborts an asynchronous transmit or receive request.
00393 
00394   The Cancel() function is used to abort a pending transmit or receive request.
00395   If the token is in the transmit or receive request queues, after calling this
00396   function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
00397   signaled. If the token is not in one of the queues, which usually means that
00398   the asynchronous operation has completed, this function will not signal the
00399   token and EFI_NOT_FOUND is returned.
00400 
00401   @param  This  The pointer to the EFI_UDP4_PROTOCOL instance.
00402   @param  Token The pointer to a token that has been issued by
00403                 EFI_UDP4_PROTOCOL.Transmit() or
00404                 EFI_UDP4_PROTOCOL.Receive().If NULL, all pending
00405                 tokens are aborted.
00406 
00407   @retval  EFI_SUCCESS           The asynchronous I/O request was aborted and Token.Event
00408                                  was signaled. When Token is NULL, all pending requests are
00409                                  aborted and their events are signaled.
00410   @retval  EFI_INVALID_PARAMETER This is NULL.
00411   @retval  EFI_NOT_STARTED       This instance has not been started.
00412   @retval  EFI_NO_MAPPING        When using the default address, configuration (DHCP, BOOTP,
00413                                  RARP, etc.) is not finished yet.
00414   @retval  EFI_NOT_FOUND         When Token is not NULL, the asynchronous I/O request was
00415                                  not found in the transmit or receive queue. It has either completed
00416                                  or was not issued by Transmit() and Receive().
00417 
00418 **/
00419 typedef
00420 EFI_STATUS
00421 (EFIAPI *EFI_UDP4_CANCEL)(
00422   IN EFI_UDP4_PROTOCOL          *This,
00423   IN EFI_UDP4_COMPLETION_TOKEN  *Token  OPTIONAL
00424   );
00425 
00426 ///
00427 /// The EFI_UDP4_PROTOCOL defines an EFI UDPv4 Protocol session that can be used
00428 /// by any network drivers, applications, or daemons to transmit or receive UDP packets.
00429 /// This protocol instance can either be bound to a specified port as a service or
00430 /// connected to some remote peer as an active client. Each instance has its own settings,
00431 /// such as the routing table and group table, which are independent from each other.
00432 ///
00433 struct _EFI_UDP4_PROTOCOL {
00434   EFI_UDP4_GET_MODE_DATA        GetModeData;
00435   EFI_UDP4_CONFIGURE            Configure;
00436   EFI_UDP4_GROUPS               Groups;
00437   EFI_UDP4_ROUTES               Routes;
00438   EFI_UDP4_TRANSMIT             Transmit;
00439   EFI_UDP4_RECEIVE              Receive;
00440   EFI_UDP4_CANCEL               Cancel;
00441   EFI_UDP4_POLL                 Poll;
00442 };
00443 
00444 extern EFI_GUID gEfiUdp4ServiceBindingProtocolGuid;
00445 extern EFI_GUID gEfiUdp4ProtocolGuid;
00446 
00447 #endif