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