/** @file1This file defines the EFI HTTP Protocol interface. It is split into2the following two main sections:3HTTP Service Binding Protocol (HTTPSB)4HTTP Protocol (HTTP)56Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>7(C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP<BR>8This program and the accompanying materials9are licensed and made available under the terms and conditions of the BSD License10which accompanies this distribution. The full text of the license may be found at11http://opensource.org/licenses/bsd-license.php1213THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.1516@par Revision Reference:17This Protocol is introduced in UEFI Specification 2.51819**/2021#ifndef __EFI_HTTP_PROTOCOL_H__22#define __EFI_HTTP_PROTOCOL_H__2324#define EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID \25{ \260xbdc8e6af, 0xd9bc, 0x4379, {0xa7, 0x2a, 0xe0, 0xc4, 0xe7, 0x5d, 0xae, 0x1c } \27}2829#define EFI_HTTP_PROTOCOL_GUID \30{ \310x7a59b29b, 0x910b, 0x4171, {0x82, 0x42, 0xa8, 0x5a, 0x0d, 0xf2, 0x5b, 0x5b } \32}3334typedef struct _EFI_HTTP_PROTOCOL EFI_HTTP_PROTOCOL;3536///37/// EFI_HTTP_VERSION38///39typedef enum {40HttpVersion10,41HttpVersion11,42HttpVersionUnsupported43} EFI_HTTP_VERSION;4445///46/// EFI_HTTP_METHOD47///48typedef enum {49HttpMethodGet,50HttpMethodPost,51HttpMethodPatch,52HttpMethodOptions,53HttpMethodConnect,54HttpMethodHead,55HttpMethodPut,56HttpMethodDelete,57HttpMethodTrace,58HttpMethodMax59} EFI_HTTP_METHOD;6061///62/// EFI_HTTP_STATUS_CODE63///64typedef enum {65HTTP_STATUS_UNSUPPORTED_STATUS = 0,66HTTP_STATUS_100_CONTINUE,67HTTP_STATUS_101_SWITCHING_PROTOCOLS,68HTTP_STATUS_200_OK,69HTTP_STATUS_201_CREATED,70HTTP_STATUS_202_ACCEPTED,71HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION,72HTTP_STATUS_204_NO_CONTENT,73HTTP_STATUS_205_RESET_CONTENT,74HTTP_STATUS_206_PARTIAL_CONTENT,75HTTP_STATUS_300_MULTIPLE_CHOICES,76HTTP_STATUS_301_MOVED_PERMANENTLY,77HTTP_STATUS_302_FOUND,78HTTP_STATUS_303_SEE_OTHER,79HTTP_STATUS_304_NOT_MODIFIED,80HTTP_STATUS_305_USE_PROXY,81HTTP_STATUS_307_TEMPORARY_REDIRECT,82HTTP_STATUS_400_BAD_REQUEST,83HTTP_STATUS_401_UNAUTHORIZED,84HTTP_STATUS_402_PAYMENT_REQUIRED,85HTTP_STATUS_403_FORBIDDEN,86HTTP_STATUS_404_NOT_FOUND,87HTTP_STATUS_405_METHOD_NOT_ALLOWED,88HTTP_STATUS_406_NOT_ACCEPTABLE,89HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED,90HTTP_STATUS_408_REQUEST_TIME_OUT,91HTTP_STATUS_409_CONFLICT,92HTTP_STATUS_410_GONE,93HTTP_STATUS_411_LENGTH_REQUIRED,94HTTP_STATUS_412_PRECONDITION_FAILED,95HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE,96HTTP_STATUS_414_REQUEST_URI_TOO_LARGE,97HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE,98HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED,99HTTP_STATUS_417_EXPECTATION_FAILED,100HTTP_STATUS_500_INTERNAL_SERVER_ERROR,101HTTP_STATUS_501_NOT_IMPLEMENTED,102HTTP_STATUS_502_BAD_GATEWAY,103HTTP_STATUS_503_SERVICE_UNAVAILABLE,104HTTP_STATUS_504_GATEWAY_TIME_OUT,105HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED,106HTTP_STATUS_308_PERMANENT_REDIRECT107} EFI_HTTP_STATUS_CODE;108109///110/// EFI_HTTPv4_ACCESS_POINT111///112typedef struct {113///114/// Set to TRUE to instruct the EFI HTTP instance to use the default address115/// information in every TCP connection made by this instance. In addition, when set116/// to TRUE, LocalAddress and LocalSubnet are ignored.117///118BOOLEAN UseDefaultAddress;119///120/// If UseDefaultAddress is set to FALSE, this defines the local IP address to be121/// used in every TCP connection opened by this instance.122///123EFI_IPv4_ADDRESS LocalAddress;124///125/// If UseDefaultAddress is set to FALSE, this defines the local subnet to be used126/// in every TCP connection opened by this instance.127///128EFI_IPv4_ADDRESS LocalSubnet;129///130/// This defines the local port to be used in131/// every TCP connection opened by this instance.132///133UINT16 LocalPort;134} EFI_HTTPv4_ACCESS_POINT;135136///137/// EFI_HTTPv6_ACCESS_POINT138///139typedef struct {140///141/// Local IP address to be used in every TCP connection opened by this instance.142///143EFI_IPv6_ADDRESS LocalAddress;144///145/// Local port to be used in every TCP connection opened by this instance.146///147UINT16 LocalPort;148} EFI_HTTPv6_ACCESS_POINT;149150///151/// EFI_HTTP_CONFIG_DATA_ACCESS_POINT152///153154155typedef struct {156///157/// HTTP version that this instance will support.158///159EFI_HTTP_VERSION HttpVersion;160///161/// Time out (in milliseconds) when blocking for requests.162///163UINT32 TimeOutMillisec;164///165/// Defines behavior of EFI DNS and TCP protocols consumed by this instance. If166/// 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///169BOOLEAN LocalAddressIsIPv6;170171union {172///173/// When LocalAddressIsIPv6 is FALSE, this points to the local address, subnet, and174/// port used by the underlying TCP protocol.175///176EFI_HTTPv4_ACCESS_POINT *IPv4Node;177///178/// When LocalAddressIsIPv6 is TRUE, this points to the local IPv6 address and port179/// used by the underlying TCP protocol.180///181EFI_HTTPv6_ACCESS_POINT *IPv6Node;182} AccessPoint;183} EFI_HTTP_CONFIG_DATA;184185///186/// EFI_HTTP_REQUEST_DATA187///188typedef struct {189///190/// The HTTP method (e.g. GET, POST) for this HTTP Request.191///192EFI_HTTP_METHOD Method;193///194/// The URI of a remote host. From the information in this field, the HTTP instance195/// will be able to determine whether to use HTTP or HTTPS and will also be able to196/// 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///199CHAR16 *Url;200} EFI_HTTP_REQUEST_DATA;201202///203/// EFI_HTTP_RESPONSE_DATA204///205typedef struct {206///207/// Response status code returned by the remote host.208///209EFI_HTTP_STATUS_CODE StatusCode;210} EFI_HTTP_RESPONSE_DATA;211212///213/// EFI_HTTP_HEADER214///215typedef struct {216///217/// Null terminated string which describes a field name. See RFC 2616 Section 14 for218/// detailed information about field names.219///220CHAR8 *FieldName;221///222/// Null terminated string which describes the corresponding field value. See RFC 2616223/// Section 14 for detailed information about field values.224///225CHAR8 *FieldValue;226} EFI_HTTP_HEADER;227228///229/// EFI_HTTP_MESSAGE230///231typedef struct {232///233/// HTTP message data.234///235union {236///237/// When the token is used to send a HTTP request, Request is a pointer to storage that238/// contains such data as URL and HTTP method.239///240EFI_HTTP_REQUEST_DATA *Request;241///242/// When used to await a response, Response points to storage containing HTTP response243/// status code.244///245EFI_HTTP_RESPONSE_DATA *Response;246} Data;247///248/// Number of HTTP header structures in Headers list. On request, this count is249/// provided by the caller. On response, this count is provided by the HTTP driver.250///251UINTN HeaderCount;252///253/// Array containing list of HTTP headers. On request, this array is populated by the254/// caller. On response, this array is allocated and populated by the HTTP driver. It255/// is the responsibility of the caller to free this memory on both request and256/// response.257///258EFI_HTTP_HEADER *Headers;259///260/// Length in bytes of the HTTP body. This can be zero depending on the HttpMethod type.261///262UINTN BodyLength;263///264/// Body associated with the HTTP request or response. This can be NULL depending on265/// the HttpMethod type.266///267VOID *Body;268} EFI_HTTP_MESSAGE;269270271///272/// EFI_HTTP_TOKEN273///274typedef struct {275///276/// This Event will be signaled after the Status field is updated by the EFI HTTP277/// Protocol driver. The type of Event must be EFI_NOTIFY_SIGNAL. The Task Priority278/// Level (TPL) of Event must be lower than or equal to TPL_CALLBACK.279///280EFI_EVENT Event;281///282/// Status will be set to one of the following value if the HTTP request is283/// 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 a286/// HTTP error. The response status code is returned in token.287/// EFI_ABORTED: The HTTP request was cancelled by the caller and removed from288/// 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///292EFI_STATUS Status;293///294/// Pointer to storage containing HTTP message data.295///296EFI_HTTP_MESSAGE *Message;297} EFI_HTTP_TOKEN;298299/**300Returns the operational parameters for the current HTTP child instance.301302The GetModeData() function is used to read the current mode data (operational303parameters) for this HTTP protocol instance.304305@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.306@param[out] HttpConfigData Point to buffer for operational parameters of this307HTTP instance. It is the responsibility of the caller308to allocate the memory for HttpConfigData and309HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact,310it is recommended to allocate sufficient memory to record311IPv6Node since it is big enough for all possibilities.312313@retval EFI_SUCCESS Operation succeeded.314@retval EFI_INVALID_PARAMETER This is NULL.315HttpConfigData is NULL.316HttpConfigData->AccessPoint.IPv4Node or317HttpConfigData->AccessPoint.IPv6Node is NULL.318@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.319**/320typedef321EFI_STATUS322(EFIAPI *EFI_HTTP_GET_MODE_DATA)(323IN EFI_HTTP_PROTOCOL *This,324OUT EFI_HTTP_CONFIG_DATA *HttpConfigData325);326327/**328Initialize or brutally reset the operational parameters for this EFI HTTP instance.329330The Configure() function does the following:331When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring332timeout, local address, port, etc.333When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active334connections with remote hosts, canceling all asynchronous tokens, and flush request335and response buffers without informing the appropriate hosts.336337No other EFI HTTP function can be executed by this instance until the Configure()338function is executed and returns successfully.339340@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.341@param[in] HttpConfigData Pointer to the configure data to configure the instance.342343@retval EFI_SUCCESS Operation succeeded.344@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:345This is NULL.346HttpConfigData->LocalAddressIsIPv6 is FALSE and347HttpConfigData->AccessPoint.IPv4Node is NULL.348HttpConfigData->LocalAddressIsIPv6 is TRUE and349HttpConfigData->AccessPoint.IPv6Node is NULL.350@retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling351Configure() with NULL to reset it.352@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.353@retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when354executing Configure().355@retval EFI_UNSUPPORTED One or more options in ConfigData are not supported356in the implementation.357**/358typedef359EFI_STATUS360(EFIAPI *EFI_HTTP_CONFIGURE)(361IN EFI_HTTP_PROTOCOL *This,362IN EFI_HTTP_CONFIG_DATA *HttpConfigData OPTIONAL363);364365/**366The Request() function queues an HTTP request to this HTTP instance,367similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent368successfully, or if there is an error, Status in token will be updated and Event will369be signaled.370371@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.372@param[in] Token Pointer to storage containing HTTP request token.373374@retval EFI_SUCCESS Outgoing data was processed.375@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.376@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.377@retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.378@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:379This is NULL.380Token is NULL.381Token->Message is NULL.382Token->Message->Body is not NULL,383Token->Message->BodyLength is non-zero, and384Token->Message->Data is NULL, but a previous call to385Request()has not been completed successfully.386@retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.387@retval EFI_UNSUPPORTED The HTTP method is not supported in current implementation.388**/389typedef390EFI_STATUS391(EFIAPI *EFI_HTTP_REQUEST) (392IN EFI_HTTP_PROTOCOL *This,393IN EFI_HTTP_TOKEN *Token394);395396/**397Abort an asynchronous HTTP request or response token.398399The Cancel() function aborts a pending HTTP request or response transaction. If400Token is not NULL and the token is in transmit or receive queues when it is being401cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will402be signaled. If the token is not in one of the queues, which usually means that the403asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,404all asynchronous tokens issued by Request() or Response() will be aborted.405406@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.407@param[in] Token Point to storage containing HTTP request or response408token.409410@retval EFI_SUCCESS Request and Response queues are successfully flushed.411@retval EFI_INVALID_PARAMETER This is NULL.412@retval EFI_NOT_STARTED This instance hasn't been configured.413@retval EFI_NOT_FOUND The asynchronous request or response token is not414found.415@retval EFI_UNSUPPORTED The implementation does not support this function.416**/417typedef418EFI_STATUS419(EFIAPI *EFI_HTTP_CANCEL)(420IN EFI_HTTP_PROTOCOL *This,421IN EFI_HTTP_TOKEN *Token422);423424/**425The Response() function queues an HTTP response to this HTTP instance, similar to426Receive() function in the EFI TCP driver. When the HTTP Response is received successfully,427or if there is an error, Status in token will be updated and Event will be signaled.428429The HTTP driver will queue a receive token to the underlying TCP instance. When data430is received in the underlying TCP instance, the data will be parsed and Token will431be populated with the response data. If the data received from the remote host432contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting433(asynchronously) for more data to be sent from the remote host before signaling434Event in Token.435436It is the responsibility of the caller to allocate a buffer for Body and specify the437size in BodyLength. If the remote host provides a response that contains a content438body, up to BodyLength bytes will be copied from the receive buffer into Body and439BodyLength will be updated with the amount of bytes received and copied to Body. This440allows the client to download a large file in chunks instead of into one contiguous441block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is442non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive443token to underlying TCP instance. If data arrives in the receive buffer, up to444BodyLength bytes of data will be copied to Body. The HTTP driver will then update445BodyLength with the amount of bytes received and copied to Body.446447If the HTTP driver does not have an open underlying TCP connection with the host448specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is449consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain450an open TCP connection between client and host.451452@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.453@param[in] Token Pointer to storage containing HTTP response token.454455@retval EFI_SUCCESS Allocation succeeded.456@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been457initialized.458@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:459This is NULL.460Token is NULL.461Token->Message->Headers is NULL.462Token->Message is NULL.463Token->Message->Body is not NULL,464Token->Message->BodyLength is non-zero, and465Token->Message->Data is NULL, but a previous call to466Response() has not been completed successfully.467@retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.468@retval EFI_ACCESS_DENIED An open TCP connection is not present with the host469specified by response URL.470**/471typedef472EFI_STATUS473(EFIAPI *EFI_HTTP_RESPONSE) (474IN EFI_HTTP_PROTOCOL *This,475IN EFI_HTTP_TOKEN *Token476);477478/**479The Poll() function can be used by network drivers and applications to increase the480rate that data packets are moved between the communication devices and the transmit481and receive queues.482483In some systems, the periodic timer event in the managed network driver may not poll484the underlying communications device fast enough to transmit and/or receive all data485packets without missing incoming packets or dropping outgoing packets. Drivers and486applications that are experiencing packet loss should try calling the Poll() function487more often.488489@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.490491@retval EFI_SUCCESS Incoming or outgoing data was processed..492@retval EFI_DEVICE_ERROR An unexpected system or network error occurred493@retval EFI_INVALID_PARAMETER This is NULL.494@retval EFI_NOT_READY No incoming or outgoing data is processed.495@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.496**/497typedef498EFI_STATUS499(EFIAPI *EFI_HTTP_POLL) (500IN EFI_HTTP_PROTOCOL *This501);502503///504/// The EFI HTTP protocol is designed to be used by EFI drivers and applications to505/// create and transmit HTTP Requests, as well as handle HTTP responses that are506/// returned by a remote host. This EFI protocol uses and relies on an underlying EFI507/// TCP protocol.508///509struct _EFI_HTTP_PROTOCOL {510EFI_HTTP_GET_MODE_DATA GetModeData;511EFI_HTTP_CONFIGURE Configure;512EFI_HTTP_REQUEST Request;513EFI_HTTP_CANCEL Cancel;514EFI_HTTP_RESPONSE Response;515EFI_HTTP_POLL Poll;516};517518extern EFI_GUID gEfiHttpServiceBindingProtocolGuid;519extern EFI_GUID gEfiHttpProtocolGuid;520521#endif522523524