1 /** @file 2 UDP4 Service Binding Protocol as defined in UEFI specification. 3 4 The EFI UDPv4 Protocol provides simple packet-oriented services 5 to transmit and receive UDP packets. 6 7 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> 8 This program and the accompanying materials are licensed and made available under 9 the terms and conditions of the BSD License that accompanies this distribution. 10 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.0. 18 19 **/ 20 21 #ifndef __EFI_UDP4_PROTOCOL_H__ 22 #define __EFI_UDP4_PROTOCOL_H__ 23 24 #include <Protocol/Ip4.h> 25 // 26 //GUID definitions 27 // 28 #define EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID \ 29 { \ 30 0x83f01464, 0x99bd, 0x45e5, {0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6 } \ 31 } 32 33 #define EFI_UDP4_PROTOCOL_GUID \ 34 { \ 35 0x3ad9df29, 0x4501, 0x478d, {0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3 } \ 36 } 37 38 typedef struct _EFI_UDP4_PROTOCOL EFI_UDP4_PROTOCOL; 39 40 /// 41 /// EFI_UDP4_SERVICE_POINT is deprecated in the UEFI 2.4B and should not be used any more. 42 /// The definition in here is only present to provide backwards compatability. 43 /// 44 typedef struct { 45 EFI_HANDLE InstanceHandle; 46 EFI_IPv4_ADDRESS LocalAddress; 47 UINT16 LocalPort; 48 EFI_IPv4_ADDRESS RemoteAddress; 49 UINT16 RemotePort; 50 } EFI_UDP4_SERVICE_POINT; 51 52 /// 53 /// EFI_UDP4_VARIABLE_DATA is deprecated in the UEFI 2.4B and should not be used any more. 54 /// The definition in here is only present to provide backwards compatability. 55 /// 56 typedef struct { 57 EFI_HANDLE DriverHandle; 58 UINT32 ServiceCount; 59 EFI_UDP4_SERVICE_POINT Services[1]; 60 } EFI_UDP4_VARIABLE_DATA; 61 62 typedef struct { 63 UINT32 FragmentLength; 64 VOID *FragmentBuffer; 65 } EFI_UDP4_FRAGMENT_DATA; 66 67 typedef struct { 68 EFI_IPv4_ADDRESS SourceAddress; 69 UINT16 SourcePort; 70 EFI_IPv4_ADDRESS DestinationAddress; 71 UINT16 DestinationPort; 72 } EFI_UDP4_SESSION_DATA; 73 typedef struct { 74 // 75 // Receiving Filters 76 // 77 BOOLEAN AcceptBroadcast; 78 BOOLEAN AcceptPromiscuous; 79 BOOLEAN AcceptAnyPort; 80 BOOLEAN AllowDuplicatePort; 81 // 82 // I/O parameters 83 // 84 UINT8 TypeOfService; 85 UINT8 TimeToLive; 86 BOOLEAN DoNotFragment; 87 UINT32 ReceiveTimeout; 88 UINT32 TransmitTimeout; 89 // 90 // Access Point 91 // 92 BOOLEAN UseDefaultAddress; 93 EFI_IPv4_ADDRESS StationAddress; 94 EFI_IPv4_ADDRESS SubnetMask; 95 UINT16 StationPort; 96 EFI_IPv4_ADDRESS RemoteAddress; 97 UINT16 RemotePort; 98 } EFI_UDP4_CONFIG_DATA; 99 100 typedef struct { 101 EFI_UDP4_SESSION_DATA *UdpSessionData; //OPTIONAL 102 EFI_IPv4_ADDRESS *GatewayAddress; //OPTIONAL 103 UINT32 DataLength; 104 UINT32 FragmentCount; 105 EFI_UDP4_FRAGMENT_DATA FragmentTable[1]; 106 } EFI_UDP4_TRANSMIT_DATA; 107 108 typedef struct { 109 EFI_TIME TimeStamp; 110 EFI_EVENT RecycleSignal; 111 EFI_UDP4_SESSION_DATA UdpSession; 112 UINT32 DataLength; 113 UINT32 FragmentCount; 114 EFI_UDP4_FRAGMENT_DATA FragmentTable[1]; 115 } EFI_UDP4_RECEIVE_DATA; 116 117 118 typedef struct { 119 EFI_EVENT Event; 120 EFI_STATUS Status; 121 union { 122 EFI_UDP4_RECEIVE_DATA *RxData; 123 EFI_UDP4_TRANSMIT_DATA *TxData; 124 } Packet; 125 } EFI_UDP4_COMPLETION_TOKEN; 126 127 /** 128 Reads the current operational settings. 129 130 The GetModeData() function copies the current operational settings of this EFI 131 UDPv4 Protocol instance into user-supplied buffers. This function is used 132 optionally to retrieve the operational mode data of underlying networks or 133 drivers. 134 135 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 136 @param Udp4ConfigData The pointer to the buffer to receive the current configuration data. 137 @param Ip4ModeData The pointer to the EFI IPv4 Protocol mode data structure. 138 @param MnpConfigData The pointer to the managed network configuration data structure. 139 @param SnpModeData The pointer to the simple network mode data structure. 140 141 @retval EFI_SUCCESS The mode data was read. 142 @retval EFI_NOT_STARTED When Udp4ConfigData is queried, no configuration data is 143 available because this instance has not been started. 144 @retval EFI_INVALID_PARAMETER This is NULL. 145 146 **/ 147 typedef 148 EFI_STATUS 149 (EFIAPI *EFI_UDP4_GET_MODE_DATA)( 150 IN EFI_UDP4_PROTOCOL *This, 151 OUT EFI_UDP4_CONFIG_DATA *Udp4ConfigData OPTIONAL, 152 OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL, 153 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, 154 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL 155 ); 156 157 158 /** 159 Initializes, changes, or resets the operational parameters for this instance of the EFI UDPv4 160 Protocol. 161 162 The Configure() function is used to do the following: 163 * Initialize and start this instance of the EFI UDPv4 Protocol. 164 * Change the filtering rules and operational parameters. 165 * Reset this instance of the EFI UDPv4 Protocol. 166 Until these parameters are initialized, no network traffic can be sent or 167 received by this instance. This instance can be also reset by calling Configure() 168 with UdpConfigData set to NULL. Once reset, the receiving queue and transmitting 169 queue are flushed and no traffic is allowed through this instance. 170 With different parameters in UdpConfigData, Configure() can be used to bind 171 this instance to specified port. 172 173 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 174 @param Udp4ConfigData The pointer to the buffer to receive the current configuration data. 175 176 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully. 177 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, 178 RARP, etc.) is not finished yet. 179 @retval EFI_INVALID_PARAMETER This is NULL. 180 @retval EFI_INVALID_PARAMETER UdpConfigData.StationAddress is not a valid unicast IPv4 address. 181 @retval EFI_INVALID_PARAMETER UdpConfigData.SubnetMask is not a valid IPv4 address mask. The subnet 182 mask must be contiguous. 183 @retval EFI_INVALID_PARAMETER UdpConfigData.RemoteAddress is not a valid unicast IPv4 address if it 184 is not zero. 185 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured 186 and must be stopped/reset before it can be reconfigured. 187 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE 188 and UdpConfigData.StationPort is already used by 189 other instance. 190 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this 191 EFI UDPv4 Protocol instance. 192 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance 193 was not opened. 194 195 **/ 196 typedef 197 EFI_STATUS 198 (EFIAPI *EFI_UDP4_CONFIGURE)( 199 IN EFI_UDP4_PROTOCOL *This, 200 IN EFI_UDP4_CONFIG_DATA *UdpConfigData OPTIONAL 201 ); 202 203 /** 204 Joins and leaves multicast groups. 205 206 The Groups() function is used to enable and disable the multicast group 207 filtering. If the JoinFlag is FALSE and the MulticastAddress is NULL, then all 208 currently joined groups are left. 209 210 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 211 @param JoinFlag Set to TRUE to join a multicast group. Set to FALSE to leave one 212 or all multicast groups. 213 @param MulticastAddress The pointer to multicast group address to join or leave. 214 215 @retval EFI_SUCCESS The operation completed successfully. 216 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started. 217 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, 218 RARP, etc.) is not finished yet. 219 @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group. 220 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: 221 - This is NULL. 222 - JoinFlag is TRUE and MulticastAddress is NULL. 223 - JoinFlag is TRUE and *MulticastAddress is not 224 a valid multicast address. 225 @retval EFI_ALREADY_STARTED The group address is already in the group table (when 226 JoinFlag is TRUE). 227 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is 228 FALSE). 229 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. 230 231 **/ 232 typedef 233 EFI_STATUS 234 (EFIAPI *EFI_UDP4_GROUPS)( 235 IN EFI_UDP4_PROTOCOL *This, 236 IN BOOLEAN JoinFlag, 237 IN EFI_IPv4_ADDRESS *MulticastAddress OPTIONAL 238 ); 239 240 /** 241 Adds and deletes routing table entries. 242 243 The Routes() function adds a route to or deletes a route from the routing table. 244 Routes are determined by comparing the SubnetAddress with the destination IP 245 address and arithmetically AND-ing it with the SubnetMask. The gateway address 246 must be on the same subnet as the configured station address. 247 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0. 248 The default route matches all destination IP addresses that do not match any 249 other routes. 250 A zero GatewayAddress is a nonroute. Packets are sent to the destination IP 251 address if it can be found in the Address Resolution Protocol (ARP) cache or 252 on the local subnet. One automatic nonroute entry will be inserted into the 253 routing table for outgoing packets that are addressed to a local subnet 254 (gateway address of 0.0.0.0). 255 Each instance of the EFI UDPv4 Protocol has its own independent routing table. 256 Instances of the EFI UDPv4 Protocol that use the default IP address will also 257 have copies of the routing table provided by the EFI_IP4_CONFIG_PROTOCOL. These 258 copies will be updated automatically whenever the IP driver reconfigures its 259 instances; as a result, the previous modification to these copies will be lost. 260 261 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 262 @param DeleteRoute Set to TRUE to delete this route from the routing table. 263 Set to FALSE to add this route to the routing table. 264 @param SubnetAddress The destination network address that needs to be routed. 265 @param SubnetMask The subnet mask of SubnetAddress. 266 @param GatewayAddress The gateway IP address for this route. 267 268 @retval EFI_SUCCESS The operation completed successfully. 269 @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started. 270 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, 271 - RARP, etc.) is not finished yet. 272 @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 273 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table. 274 @retval EFI_NOT_FOUND This route is not in the routing table. 275 @retval EFI_ACCESS_DENIED The route is already defined in the routing table. 276 277 **/ 278 typedef 279 EFI_STATUS 280 (EFIAPI *EFI_UDP4_ROUTES)( 281 IN EFI_UDP4_PROTOCOL *This, 282 IN BOOLEAN DeleteRoute, 283 IN EFI_IPv4_ADDRESS *SubnetAddress, 284 IN EFI_IPv4_ADDRESS *SubnetMask, 285 IN EFI_IPv4_ADDRESS *GatewayAddress 286 ); 287 288 /** 289 Polls for incoming data packets and processes outgoing data packets. 290 291 The Poll() function can be used by network drivers and applications to increase 292 the rate that data packets are moved between the communications device and the 293 transmit and receive queues. 294 In some systems, the periodic timer event in the managed network driver may not 295 poll the underlying communications device fast enough to transmit and/or receive 296 all data packets without missing incoming packets or dropping outgoing packets. 297 Drivers and applications that are experiencing packet loss should try calling 298 the Poll() function more often. 299 300 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 301 302 @retval EFI_SUCCESS Incoming or outgoing data was processed. 303 @retval EFI_INVALID_PARAMETER This is NULL. 304 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. 305 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue. 306 307 **/ 308 typedef 309 EFI_STATUS 310 (EFIAPI *EFI_UDP4_POLL)( 311 IN EFI_UDP4_PROTOCOL *This 312 ); 313 314 /** 315 Places an asynchronous receive request into the receiving queue. 316 317 The Receive() function places a completion token into the receive packet queue. 318 This function is always asynchronous. 319 The caller must fill in the Token.Event field in the completion token, and this 320 field cannot be NULL. When the receive operation completes, the EFI UDPv4 Protocol 321 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event 322 is signaled. Providing a proper notification function and context for the event 323 will enable the user to receive the notification and receiving status. That 324 notification function is guaranteed to not be re-entered. 325 326 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 327 @param Token The pointer to a token that is associated with the receive data 328 descriptor. 329 330 @retval EFI_SUCCESS The receive completion token was cached. 331 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started. 332 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, RARP, etc.) 333 is not finished yet. 334 @retval EFI_INVALID_PARAMETER This is NULL. 335 @retval EFI_INVALID_PARAMETER Token is NULL. 336 @retval EFI_INVALID_PARAMETER Token.Event is NULL. 337 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system 338 resources (usually memory). 339 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. 340 @retval EFI_ACCESS_DENIED A receive completion token with the same Token.Event was already in 341 the receive queue. 342 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full. 343 344 **/ 345 typedef 346 EFI_STATUS 347 (EFIAPI *EFI_UDP4_RECEIVE)( 348 IN EFI_UDP4_PROTOCOL *This, 349 IN EFI_UDP4_COMPLETION_TOKEN *Token 350 ); 351 352 /** 353 Queues outgoing data packets into the transmit queue. 354 355 The Transmit() function places a sending request to this instance of the EFI 356 UDPv4 Protocol, alongside the transmit data that was filled by the user. Whenever 357 the packet in the token is sent out or some errors occur, the Token.Event will 358 be signaled and Token.Status is updated. Providing a proper notification function 359 and context for the event will enable the user to receive the notification and 360 transmitting status. 361 362 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 363 @param Token The pointer to the completion token that will be placed into the 364 transmit queue. 365 366 @retval EFI_SUCCESS The data has been queued for transmission. 367 @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started. 368 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, 369 RARP, etc.) is not finished yet. 370 @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 371 @retval EFI_ACCESS_DENIED The transmit completion token with the same 372 Token.Event was already in the transmit queue. 373 @retval EFI_NOT_READY The completion token could not be queued because the 374 transmit queue is full. 375 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data. 376 @retval EFI_NOT_FOUND There is no route to the destination network or address. 377 @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP packet 378 size. Or the length of the IP header + UDP header + data 379 length is greater than MTU if DoNotFragment is TRUE. 380 381 **/ 382 typedef 383 EFI_STATUS 384 (EFIAPI *EFI_UDP4_TRANSMIT)( 385 IN EFI_UDP4_PROTOCOL *This, 386 IN EFI_UDP4_COMPLETION_TOKEN *Token 387 ); 388 389 /** 390 Aborts an asynchronous transmit or receive request. 391 392 The Cancel() function is used to abort a pending transmit or receive request. 393 If the token is in the transmit or receive request queues, after calling this 394 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be 395 signaled. If the token is not in one of the queues, which usually means that 396 the asynchronous operation has completed, this function will not signal the 397 token and EFI_NOT_FOUND is returned. 398 399 @param This The pointer to the EFI_UDP4_PROTOCOL instance. 400 @param Token The pointer to a token that has been issued by 401 EFI_UDP4_PROTOCOL.Transmit() or 402 EFI_UDP4_PROTOCOL.Receive().If NULL, all pending 403 tokens are aborted. 404 405 @retval EFI_SUCCESS The asynchronous I/O request was aborted and Token.Event 406 was signaled. When Token is NULL, all pending requests are 407 aborted and their events are signaled. 408 @retval EFI_INVALID_PARAMETER This is NULL. 409 @retval EFI_NOT_STARTED This instance has not been started. 410 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, 411 RARP, etc.) is not finished yet. 412 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was 413 not found in the transmit or receive queue. It has either completed 414 or was not issued by Transmit() and Receive(). 415 416 **/ 417 typedef 418 EFI_STATUS 419 (EFIAPI *EFI_UDP4_CANCEL)( 420 IN EFI_UDP4_PROTOCOL *This, 421 IN EFI_UDP4_COMPLETION_TOKEN *Token OPTIONAL 422 ); 423 424 /// 425 /// The EFI_UDP4_PROTOCOL defines an EFI UDPv4 Protocol session that can be used 426 /// by any network drivers, applications, or daemons to transmit or receive UDP packets. 427 /// This protocol instance can either be bound to a specified port as a service or 428 /// connected to some remote peer as an active client. Each instance has its own settings, 429 /// such as the routing table and group table, which are independent from each other. 430 /// 431 struct _EFI_UDP4_PROTOCOL { 432 EFI_UDP4_GET_MODE_DATA GetModeData; 433 EFI_UDP4_CONFIGURE Configure; 434 EFI_UDP4_GROUPS Groups; 435 EFI_UDP4_ROUTES Routes; 436 EFI_UDP4_TRANSMIT Transmit; 437 EFI_UDP4_RECEIVE Receive; 438 EFI_UDP4_CANCEL Cancel; 439 EFI_UDP4_POLL Poll; 440 }; 441 442 extern EFI_GUID gEfiUdp4ServiceBindingProtocolGuid; 443 extern EFI_GUID gEfiUdp4ProtocolGuid; 444 445 #endif 446