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) 2016, 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 and LocalSubnet 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 /// 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_HTTP_ERROR: The response message was successfully received but contains a 286 /// HTTP error. The response status code is returned in token. 287 /// EFI_ABORTED: The HTTP request was cancelled by the caller and removed from 288 /// the transmit queue. 289 /// EFI_TIMEOUT: The HTTP request timed out before reaching the remote host. 290 /// EFI_DEVICE_ERROR: An unexpected system or network error occurred. 291 /// 292 EFI_STATUS Status; 293 /// 294 /// Pointer to storage containing HTTP message data. 295 /// 296 EFI_HTTP_MESSAGE *Message; 297 } EFI_HTTP_TOKEN; 298 299 /** 300 Returns the operational parameters for the current HTTP child instance. 301 302 The GetModeData() function is used to read the current mode data (operational 303 parameters) for this HTTP protocol instance. 304 305 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 306 @param[out] HttpConfigData Point to buffer for operational parameters of this 307 HTTP instance. 308 309 @retval EFI_SUCCESS Operation succeeded. 310 @retval EFI_INVALID_PARAMETER This is NULL. 311 HttpConfigData is NULL. 312 HttpInstance->LocalAddressIsIPv6 is FALSE and 313 HttpConfigData->IPv4Node is NULL. 314 HttpInstance->LocalAddressIsIPv6 is TRUE and 315 HttpConfigData->IPv6Node is NULL. 316 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started. 317 **/ 318 typedef 319 EFI_STATUS 320 (EFIAPI * EFI_HTTP_GET_MODE_DATA)( 321 IN EFI_HTTP_PROTOCOL *This, 322 OUT EFI_HTTP_CONFIG_DATA *HttpConfigData 323 ); 324 325 /** 326 Initialize or brutally reset the operational parameters for this EFI HTTP instance. 327 328 The Configure() function does the following: 329 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring 330 timeout, local address, port, etc. 331 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active 332 connections with remote hosts, canceling all asynchronous tokens, and flush request 333 and response buffers without informing the appropriate hosts. 334 335 No other EFI HTTP function can be executed by this instance until the Configure() 336 function is executed and returns successfully. 337 338 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 339 @param[in] HttpConfigData Pointer to the configure data to configure the instance. 340 341 @retval EFI_SUCCESS Operation succeeded. 342 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: 343 This is NULL. 344 HttpConfigData->LocalAddressIsIPv6 is FALSE and 345 HttpConfigData->IPv4Node is NULL. 346 HttpConfigData->LocalAddressIsIPv6 is TRUE and 347 HttpConfigData->IPv6Node is NULL. 348 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling 349 Configure() with NULL to reset it. 350 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. 351 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when 352 executing Configure(). 353 @retval EFI_UNSUPPORTED One or more options in ConfigData are not supported 354 in the implementation. 355 **/ 356 typedef 357 EFI_STATUS 358 (EFIAPI * EFI_HTTP_CONFIGURE)( 359 IN EFI_HTTP_PROTOCOL *This, 360 IN EFI_HTTP_CONFIG_DATA *HttpConfigData 361 ); 362 363 /** 364 The Request() function queues an HTTP request to this HTTP instance, 365 similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent 366 successfully, or if there is an error, Status in token will be updated and Event will 367 be signaled. 368 369 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 370 @param[in] Token Pointer to storage containing HTTP request token. 371 372 @retval EFI_SUCCESS Outgoing data was processed. 373 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started. 374 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. 375 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue. 376 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: 377 This is NULL. 378 Token is NULL. 379 Token->Message is NULL. 380 Token->Message->Body is not NULL, 381 Token->Message->BodyLength is non-zero, and 382 Token->Message->Data is NULL, but a previous call to 383 Request()has not been completed successfully. 384 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources. 385 @retval EFI_UNSUPPORTED The HTTP method is not supported in current implementation. 386 **/ 387 typedef 388 EFI_STATUS 389 (EFIAPI *EFI_HTTP_REQUEST) ( 390 IN EFI_HTTP_PROTOCOL *This, 391 IN EFI_HTTP_TOKEN *Token 392 ); 393 394 /** 395 Abort an asynchronous HTTP request or response token. 396 397 The Cancel() function aborts a pending HTTP request or response transaction. If 398 Token is not NULL and the token is in transmit or receive queues when it is being 399 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will 400 be signaled. If the token is not in one of the queues, which usually means that the 401 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL, 402 all asynchronous tokens issued by Request() or Response() will be aborted. 403 404 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 405 @param[in] Token Point to storage containing HTTP request or response 406 token. 407 408 @retval EFI_SUCCESS Request and Response queues are successfully flushed. 409 @retval EFI_INVALID_PARAMETER This is NULL. 410 @retval EFI_NOT_STARTED This instance hasn't been configured. 411 @retval EFI_NOT_FOUND The asynchronous request or response token is not 412 found. 413 @retval EFI_UNSUPPORTED The implementation does not support this function. 414 **/ 415 typedef 416 EFI_STATUS 417 (EFIAPI *EFI_HTTP_CANCEL)( 418 IN EFI_HTTP_PROTOCOL *This, 419 IN EFI_HTTP_TOKEN *Token 420 ); 421 422 /** 423 The Response() function queues an HTTP response to this HTTP instance, similar to 424 Receive() function in the EFI TCP driver. When the HTTP Response is received successfully, 425 or if there is an error, Status in token will be updated and Event will be signaled. 426 427 The HTTP driver will queue a receive token to the underlying TCP instance. When data 428 is received in the underlying TCP instance, the data will be parsed and Token will 429 be populated with the response data. If the data received from the remote host 430 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting 431 (asynchronously) for more data to be sent from the remote host before signaling 432 Event in Token. 433 434 It is the responsibility of the caller to allocate a buffer for Body and specify the 435 size in BodyLength. If the remote host provides a response that contains a content 436 body, up to BodyLength bytes will be copied from the receive buffer into Body and 437 BodyLength will be updated with the amount of bytes received and copied to Body. This 438 allows the client to download a large file in chunks instead of into one contiguous 439 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is 440 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive 441 token to underlying TCP instance. If data arrives in the receive buffer, up to 442 BodyLength bytes of data will be copied to Body. The HTTP driver will then update 443 BodyLength with the amount of bytes received and copied to Body. 444 445 If the HTTP driver does not have an open underlying TCP connection with the host 446 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is 447 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain 448 an open TCP connection between client and host. 449 450 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 451 @param[in] Token Pointer to storage containing HTTP response token. 452 453 @retval EFI_SUCCESS Allocation succeeded. 454 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been 455 initialized. 456 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: 457 This is NULL. 458 Token is NULL. 459 Token->Message->Headers is NULL. 460 Token->Message is NULL. 461 Token->Message->Body is not NULL, 462 Token->Message->BodyLength is non-zero, and 463 Token->Message->Data is NULL, but a previous call to 464 Response() has not been completed successfully. 465 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources. 466 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host 467 specified by response URL. 468 **/ 469 typedef 470 EFI_STATUS 471 (EFIAPI *EFI_HTTP_RESPONSE) ( 472 IN EFI_HTTP_PROTOCOL *This, 473 IN EFI_HTTP_TOKEN *Token 474 ); 475 476 /** 477 The Poll() function can be used by network drivers and applications to increase the 478 rate that data packets are moved between the communication devices and the transmit 479 and receive queues. 480 481 In some systems, the periodic timer event in the managed network driver may not poll 482 the underlying communications device fast enough to transmit and/or receive all data 483 packets without missing incoming packets or dropping outgoing packets. Drivers and 484 applications that are experiencing packet loss should try calling the Poll() function 485 more often. 486 487 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance. 488 489 @retval EFI_SUCCESS Incoming or outgoing data was processed.. 490 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred 491 @retval EFI_INVALID_PARAMETER This is NULL. 492 @retval EFI_NOT_READY No incoming or outgoing data is processed. 493 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started. 494 **/ 495 typedef 496 EFI_STATUS 497 (EFIAPI *EFI_HTTP_POLL) ( 498 IN EFI_HTTP_PROTOCOL *This 499 ); 500 501 /// 502 /// The EFI HTTP protocol is designed to be used by EFI drivers and applications to 503 /// create and transmit HTTP Requests, as well as handle HTTP responses that are 504 /// returned by a remote host. This EFI protocol uses and relies on an underlying EFI 505 /// TCP protocol. 506 /// 507 struct _EFI_HTTP_PROTOCOL { 508 EFI_HTTP_GET_MODE_DATA GetModeData; 509 EFI_HTTP_CONFIGURE Configure; 510 EFI_HTTP_REQUEST Request; 511 EFI_HTTP_CANCEL Cancel; 512 EFI_HTTP_RESPONSE Response; 513 EFI_HTTP_POLL Poll; 514 }; 515 516 extern EFI_GUID gEfiHttpServiceBindingProtocolGuid; 517 extern EFI_GUID gEfiHttpProtocolGuid; 518 519 #endif 520