1 /** @file 2 This file defines the EFI HTTP Protocol interface. It is split into 3 the following two main sections: 4 HTTP Service Binding Protocol (HTTPSB) 5 HTTP Protocol (HTTP) 6 7 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> 8 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> 9 This program and the accompanying materials 10 are licensed and made available under the terms and conditions of the BSD License 11 which accompanies this distribution. The full text of the license may be found at 12 http://opensource.org/licenses/bsd-license.php 13 14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 16 17 @par Revision Reference: 18 This Protocol is introduced in UEFI Specification 2.5 19 20 **/ 21 22 #ifndef __EFI_HTTP_PROTOCOL_H__ 23 #define __EFI_HTTP_PROTOCOL_H__ 24 25 #define EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID \ 26 { \ 27 0xbdc8e6af, 0xd9bc, 0x4379, {0xa7, 0x2a, 0xe0, 0xc4, 0xe7, 0x5d, 0xae, 0x1c } \ 28 } 29 30 #define EFI_HTTP_PROTOCOL_GUID \ 31 { \ 32 0x7a59b29b, 0x910b, 0x4171, {0x82, 0x42, 0xa8, 0x5a, 0x0d, 0xf2, 0x5b, 0x5b } \ 33 } 34 35 typedef struct _EFI_HTTP_PROTOCOL EFI_HTTP_PROTOCOL; 36 37 /// 38 /// EFI_HTTP_VERSION 39 /// 40 typedef enum { 41 HttpVersion10, 42 HttpVersion11, 43 HttpVersionUnsupported 44 } EFI_HTTP_VERSION; 45 46 /// 47 /// EFI_HTTP_METHOD 48 /// 49 typedef enum { 50 HttpMethodGet, 51 HttpMethodPost, 52 HttpMethodPatch, 53 HttpMethodOptions, 54 HttpMethodConnect, 55 HttpMethodHead, 56 HttpMethodPut, 57 HttpMethodDelete, 58 HttpMethodTrace, 59 HttpMethodMax 60 } EFI_HTTP_METHOD; 61 62 /// 63 /// EFI_HTTP_STATUS_CODE 64 /// 65 typedef enum { 66 HTTP_STATUS_UNSUPPORTED_STATUS = 0, 67 HTTP_STATUS_100_CONTINUE, 68 HTTP_STATUS_101_SWITCHING_PROTOCOLS, 69 HTTP_STATUS_200_OK, 70 HTTP_STATUS_201_CREATED, 71 HTTP_STATUS_202_ACCEPTED, 72 HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION, 73 HTTP_STATUS_204_NO_CONTENT, 74 HTTP_STATUS_205_RESET_CONTENT, 75 HTTP_STATUS_206_PARTIAL_CONTENT, 76 HTTP_STATUS_300_MULTIPLE_CHIOCES, 77 HTTP_STATUS_301_MOVED_PERMANENTLY, 78 HTTP_STATUS_302_FOUND, 79 HTTP_STATUS_303_SEE_OTHER, 80 HTTP_STATUS_304_NOT_MODIFIED, 81 HTTP_STATUS_305_USE_PROXY, 82 HTTP_STATUS_307_TEMPORARY_REDIRECT, 83 HTTP_STATUS_400_BAD_REQUEST, 84 HTTP_STATUS_401_UNAUTHORIZED, 85 HTTP_STATUS_402_PAYMENT_REQUIRED, 86 HTTP_STATUS_403_FORBIDDEN, 87 HTTP_STATUS_404_NOT_FOUND, 88 HTTP_STATUS_405_METHOD_NOT_ALLOWED, 89 HTTP_STATUS_406_NOT_ACCEPTABLE, 90 HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED, 91 HTTP_STATUS_408_REQUEST_TIME_OUT, 92 HTTP_STATUS_409_CONFLICT, 93 HTTP_STATUS_410_GONE, 94 HTTP_STATUS_411_LENGTH_REQUIRED, 95 HTTP_STATUS_412_PRECONDITION_FAILED, 96 HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE, 97 HTTP_STATUS_414_REQUEST_URI_TOO_LARGE, 98 HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE, 99 HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED, 100 HTTP_STATUS_417_EXPECTATION_FAILED, 101 HTTP_STATUS_500_INTERNAL_SERVER_ERROR, 102 HTTP_STATUS_501_NOT_IMPLEMENTED, 103 HTTP_STATUS_502_BAD_GATEWAY, 104 HTTP_STATUS_503_SERVICE_UNAVAILABLE, 105 HTTP_STATUS_504_GATEWAY_TIME_OUT, 106 HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED 107 } EFI_HTTP_STATUS_CODE; 108 109 /// 110 /// EFI_HTTPv4_ACCESS_POINT 111 /// 112 typedef struct { 113 /// 114 /// Set to TRUE to instruct the EFI HTTP instance to use the default address 115 /// information in every TCP connection made by this instance. In addition, when set 116 /// to TRUE, LocalAddress, LocalSubnet, and LocalPort are ignored. 117 /// 118 BOOLEAN UseDefaultAddress; 119 /// 120 /// If UseDefaultAddress is set to FALSE, this defines the local IP address to be 121 /// used in every TCP connection opened by this instance. 122 /// 123 EFI_IPv4_ADDRESS LocalAddress; 124 /// 125 /// If UseDefaultAddress is set to FALSE, this defines the local subnet to be used 126 /// in every TCP connection opened by this instance. 127 /// 128 EFI_IPv4_ADDRESS LocalSubnet; 129 /// 130 /// If UseDefaultAddress is set to FALSE, this defines the local port to be used in 131 /// every TCP connection opened by this instance. 132 /// 133 UINT16 LocalPort; 134 } EFI_HTTPv4_ACCESS_POINT; 135 136 /// 137 /// EFI_HTTPv6_ACCESS_POINT 138 /// 139 typedef struct { 140 /// 141 /// Local IP address to be used in every TCP connection opened by this instance. 142 /// 143 EFI_IPv6_ADDRESS LocalAddress; 144 /// 145 /// Local port to be used in every TCP connection opened by this instance. 146 /// 147 UINT16 LocalPort; 148 } EFI_HTTPv6_ACCESS_POINT; 149 150 /// 151 /// EFI_HTTP_CONFIG_DATA_ACCESS_POINT 152 /// 153 154 155 typedef struct { 156 /// 157 /// HTTP version that this instance will support. 158 /// 159 EFI_HTTP_VERSION HttpVersion; 160 /// 161 /// Time out (in milliseconds) when blocking for requests. 162 /// 163 UINT32 TimeOutMillisec; 164 /// 165 /// Defines behavior of EFI DNS and TCP protocols consumed by this instance. If 166 /// FALSE, this instance will use EFI_DNS4_PROTOCOL and EFI_TCP4_PROTOCOL. If TRUE, 167 /// this instance will use EFI_DNS6_PROTOCOL and EFI_TCP6_PROTOCOL. 168 /// 169 BOOLEAN LocalAddressIsIPv6; 170 171 union { 172 /// 173 /// When LocalAddressIsIPv6 is FALSE, this points to the local address, subnet, and 174 /// port used by the underlying TCP protocol. 175 /// 176 EFI_HTTPv4_ACCESS_POINT *IPv4Node; 177 /// 178 /// When LocalAddressIsIPv6 is TRUE, this points to the local IPv6 address and port 179 /// used by the underlying TCP protocol. 180 /// 181 EFI_HTTPv6_ACCESS_POINT *IPv6Node; 182 } AccessPoint; 183 } EFI_HTTP_CONFIG_DATA; 184 185 /// 186 /// EFI_HTTP_REQUEST_DATA 187 /// 188 typedef struct { 189 /// 190 /// The HTTP method (e.g. GET, POST) for this HTTP Request. 191 /// 192 EFI_HTTP_METHOD Method; 193 /// 194 /// The URI of a remote host. From the information in this field, the HTTP instance 195 /// will be able to determine whether to use HTTP or HTTPS and will also be able to 196 /// determine the port number to use. If no port number is specified, port 80 (HTTP) 197 /// is assumed. See RFC 3986 for more details on URI syntax. 198 /// 199 CHAR16 *Url; 200 } EFI_HTTP_REQUEST_DATA; 201 202 /// 203 /// EFI_HTTP_RESPONSE_DATA 204 /// 205 typedef struct { 206 /// 207 /// Response status code returned by the remote host. 208 /// 209 EFI_HTTP_STATUS_CODE StatusCode; 210 } EFI_HTTP_RESPONSE_DATA; 211 212 /// 213 /// EFI_HTTP_HEADER 214 /// 215 typedef struct { 216 /// 217 /// Null terminated string which describes a field name. See RFC 2616 Section 14 for 218 /// detailed information about field names. 219 /// 220 CHAR8 *FieldName; 221 /// 222 /// Null terminated string which describes the corresponding field value. See RFC 2616 223 /// Section 14 for detailed information about field values. 224 /// 225 CHAR8 *FieldValue; 226 } EFI_HTTP_HEADER; 227 228 /// 229 /// EFI_HTTP_MESSAGE 230 /// 231 typedef struct { 232 /// 233 /// HTTP message data. 234 /// 235 union { 236 /// 237 /// When the token is used to send a HTTP request, Request is a pointer to storage that 238 /// contains such data as URL and HTTP method. 239 /// 240 EFI_HTTP_REQUEST_DATA *Request; 241 /// 242 /// When used to await a response, Response points to storage containing HTTP response 243 /// status code. 244 /// 245 EFI_HTTP_RESPONSE_DATA *Response; 246 } Data; 247 /// 248 /// Number of HTTP header structures in Headers list. On request, this count is 249 /// provided by the caller. On response, this count is provided by the HTTP driver. 250 /// 251 UINTN HeaderCount; 252 /// 253 /// Array containing list of HTTP headers. On request, this array is populated by the 254 /// caller. On response, this array is allocated and populated by the HTTP driver. It 255 /// is the responsibility of the caller to free this memory on both request and 256 /// response. 257 /// 258 EFI_HTTP_HEADER *Headers; 259 /// 260 /// Length in bytes of the HTTP body. This can be zero depending on the HttpMethod type. 261 /// 262 UINTN BodyLength; 263 /// 264 /// Body associated with the HTTP request or response. This can be NULL depending on 265 /// the HttpMethod type. 266 /// 267 VOID *Body; 268 } EFI_HTTP_MESSAGE; 269 270 271 /// 272 /// EFI_HTTP_TOKEN 273 /// 274 typedef struct { 275 /// 276 /// This Event will be signaled after the Status field is updated by the EFI HTTP 277 /// Protocol driver. The type of Event must be EFI_NOTIFY_SIGNAL. The Task Priority 278 /// Level (TPL) of Event must be lower than or equal to TPL_CALLBACK. 279 /// 280 EFI_EVENT Event; 281 /// 282 /// Status will be set to one of the following value if the HTTP request is 283 /// successfully sent or if an unexpected error occurs: 284 /// EFI_SUCCESS: The HTTP request was successfully sent to the remote host. 285 /// EFI_ABORTED: The HTTP request was cancelled by the caller and removed from 286 /// the transmit queue. 287 /// EFI_TIMEOUT: The HTTP request timed out before reaching the remote host. 288 /// EFI_DEVICE_ERROR: An unexpected system or network error occurred. 289 /// 290 EFI_STATUS Status; 291 /// 292 /// Pointer to storage containing HTTP message data. 293 /// 294 EFI_HTTP_MESSAGE *Message; 295 } EFI_HTTP_TOKEN; 296 297 /** 298 Returns the operational parameters for the current HTTP child instance. 299 300 The GetModeData() function is used to read the current mode data (operational 301 parameters) for this HTTP protocol instance. 302 303 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 304 @param[out] HttpConfigData Point to buffer for operational parameters of this 305 HTTP instance. 306 307 @retval EFI_SUCCESS Operation succeeded. 308 @retval EFI_INVALID_PARAMETER This is NULL. 309 **/ 310 typedef 311 EFI_STATUS 312 (EFIAPI * EFI_HTTP_GET_MODE_DATA)( 313 IN EFI_HTTP_PROTOCOL *This, 314 OUT EFI_HTTP_CONFIG_DATA *HttpConfigData 315 ); 316 317 /** 318 Initialize or brutally reset the operational parameters for this EFI HTTP instance. 319 320 The Configure() function does the following: 321 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring 322 timeout, local address, port, etc. 323 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active 324 connections with remote hosts, canceling all asynchronous tokens, and flush request 325 and response buffers without informing the appropriate hosts. 326 327 Except for GetModeData() and Configure(), No other EFI HTTP function can be executed 328 by this instance until the Configure() function is executed and returns successfully. 329 330 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 331 @param[in] HttpConfigData Pointer to the configure data to configure the instance. 332 333 @retval EFI_SUCCESS Operation succeeded. 334 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: 335 This is NULL. 336 HttpConfigData->LocalAddressIsIPv6 is FALSE and 337 HttpConfigData->IPv4Node is NULL. 338 HttpConfigData->LocalAddressIsIPv6 is TRUE and 339 HttpConfigData->IPv6Node is NULL. 340 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling 341 Configure() with NULL to reset it. 342 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. 343 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when 344 executing Configure(). 345 @retval EFI_UNSUPPORTED One or more options in ConfigData are not supported 346 in the implementation. 347 **/ 348 typedef 349 EFI_STATUS 350 (EFIAPI * EFI_HTTP_CONFIGURE)( 351 IN EFI_HTTP_PROTOCOL *This, 352 IN EFI_HTTP_CONFIG_DATA *HttpConfigData 353 ); 354 355 /** 356 The Request() function queues an HTTP request to this HTTP instance, 357 similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent 358 successfully, or if there is an error, Status in token will be updated and Event will 359 be signaled. 360 361 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 362 @param[in] Token Pointer to storage containing HTTP request token. 363 364 @retval EFI_SUCCESS Outgoing data was processed. 365 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started. 366 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. 367 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue. 368 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: 369 This is NULL. 370 Token->Message is NULL. 371 Token->Message->Body is not NULL, 372 Token->Message->BodyLength is non-zero, and 373 Token->Message->Data is NULL, but a previous call to 374 Request()has not been completed successfully. 375 **/ 376 typedef 377 EFI_STATUS 378 (EFIAPI *EFI_HTTP_REQUEST) ( 379 IN EFI_HTTP_PROTOCOL *This, 380 IN EFI_HTTP_TOKEN *Token 381 ); 382 383 /** 384 Abort an asynchronous HTTP request or response token. 385 386 The Cancel() function aborts a pending HTTP request or response transaction. If 387 Token is not NULL and the token is in transmit or receive queues when it is being 388 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will 389 be signaled. If the token is not in one of the queues, which usually means that the 390 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL, 391 all asynchronous tokens issued by Request() or Response() will be aborted. 392 393 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 394 @param[in] Token Point to storage containing HTTP request or response 395 token. 396 397 @retval EFI_SUCCESS Request and Response queues are successfully flushed. 398 @retval EFI_INVALID_PARAMETER This is NULL. 399 @retval EFI_NOT_STARTED This instance hasn't been configured. 400 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, 401 BOOTP, RARP, etc.) hasn't finished yet. 402 @retval EFI_NOT_FOUND The asynchronous request or response token is not 403 found. 404 @retval EFI_UNSUPPORTED The implementation does not support this function. 405 **/ 406 typedef 407 EFI_STATUS 408 (EFIAPI *EFI_HTTP_CANCEL)( 409 IN EFI_HTTP_PROTOCOL *This, 410 IN EFI_HTTP_TOKEN *Token 411 ); 412 413 /** 414 The Response() function queues an HTTP response to this HTTP instance, similar to 415 Receive() function in the EFI TCP driver. When the HTTP request is sent successfully, 416 or if there is an error, Status in token will be updated and Event will be signaled. 417 418 The HTTP driver will queue a receive token to the underlying TCP instance. When data 419 is received in the underlying TCP instance, the data will be parsed and Token will 420 be populated with the response data. If the data received from the remote host 421 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting 422 (asynchronously) for more data to be sent from the remote host before signaling 423 Event in Token. 424 425 It is the responsibility of the caller to allocate a buffer for Body and specify the 426 size in BodyLength. If the remote host provides a response that contains a content 427 body, up to BodyLength bytes will be copied from the receive buffer into Body and 428 BodyLength will be updated with the amount of bytes received and copied to Body. This 429 allows the client to download a large file in chunks instead of into one contiguous 430 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is 431 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive 432 token to underlying TCP instance. If data arrives in the receive buffer, up to 433 BodyLength bytes of data will be copied to Body. The HTTP driver will then update 434 BodyLength with the amount of bytes received and copied to Body. 435 436 If the HTTP driver does not have an open underlying TCP connection with the host 437 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is 438 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain 439 an open TCP connection between client and host. 440 441 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 442 @param[in] Token Pointer to storage containing HTTP response token. 443 444 @retval EFI_SUCCESS Allocation succeeded. 445 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been 446 initialized. 447 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: 448 This is NULL. 449 Token->Message->Headers is NULL. 450 Token->Message is NULL. 451 Token->Message->Body is not NULL, 452 Token->Message->BodyLength is non-zero, and 453 Token->Message->Data is NULL, but a previous call to 454 Response() has not been completed successfully. 455 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host 456 specified by response URL. 457 **/ 458 typedef 459 EFI_STATUS 460 (EFIAPI *EFI_HTTP_RESPONSE) ( 461 IN EFI_HTTP_PROTOCOL *This, 462 IN EFI_HTTP_TOKEN *Token 463 ); 464 465 /** 466 The Poll() function can be used by network drivers and applications to increase the 467 rate that data packets are moved between the communication devices and the transmit 468 and receive queues. 469 470 In some systems, the periodic timer event in the managed network driver may not poll 471 the underlying communications device fast enough to transmit and/or receive all data 472 packets without missing incoming packets or dropping outgoing packets. Drivers and 473 applications that are experiencing packet loss should try calling the Poll() function 474 more often. 475 476 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 477 478 @retval EFI_SUCCESS Incoming or outgoing data was processed.. 479 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred 480 @retval EFI_INVALID_PARAMETER This is NULL. 481 @retval EFI_NOT_READY No incoming or outgoing data is processed. 482 **/ 483 typedef 484 EFI_STATUS 485 (EFIAPI *EFI_HTTP_POLL) ( 486 IN EFI_HTTP_PROTOCOL *This 487 ); 488 489 /// 490 /// The EFI HTTP protocol is designed to be used by EFI drivers and applications to 491 /// create and transmit HTTP Requests, as well as handle HTTP responses that are 492 /// returned by a remote host. This EFI protocol uses and relies on an underlying EFI 493 /// TCP protocol. 494 /// 495 struct _EFI_HTTP_PROTOCOL { 496 EFI_HTTP_GET_MODE_DATA GetModeData; 497 EFI_HTTP_CONFIGURE Configure; 498 EFI_HTTP_REQUEST Request; 499 EFI_HTTP_CANCEL Cancel; 500 EFI_HTTP_RESPONSE Response; 501 EFI_HTTP_POLL Poll; 502 }; 503 504 extern EFI_GUID gEfiHttpServiceBindingProtocolGuid; 505 extern EFI_GUID gEfiHttpProtocolGuid; 506 507 #endif 508