Path: blob/main/sys/contrib/edk2/Include/Protocol/Http.h
96339 views
/** @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>8SPDX-License-Identifier: BSD-2-Clause-Patent910@par Revision Reference:11This Protocol is introduced in UEFI Specification 2.51213**/1415#ifndef __EFI_HTTP_PROTOCOL_H__16#define __EFI_HTTP_PROTOCOL_H__1718#define EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID \19{ \200xbdc8e6af, 0xd9bc, 0x4379, {0xa7, 0x2a, 0xe0, 0xc4, 0xe7, 0x5d, 0xae, 0x1c } \21}2223#define EFI_HTTP_PROTOCOL_GUID \24{ \250x7a59b29b, 0x910b, 0x4171, {0x82, 0x42, 0xa8, 0x5a, 0x0d, 0xf2, 0x5b, 0x5b } \26}2728typedef struct _EFI_HTTP_PROTOCOL EFI_HTTP_PROTOCOL;2930///31/// EFI_HTTP_VERSION32///33typedef enum {34HttpVersion10,35HttpVersion11,36HttpVersionUnsupported37} EFI_HTTP_VERSION;3839///40/// EFI_HTTP_METHOD41///42typedef enum {43HttpMethodGet,44HttpMethodPost,45HttpMethodPatch,46HttpMethodOptions,47HttpMethodConnect,48HttpMethodHead,49HttpMethodPut,50HttpMethodDelete,51HttpMethodTrace,52HttpMethodMax53} EFI_HTTP_METHOD;5455///56/// EFI_HTTP_STATUS_CODE57///58typedef enum {59HTTP_STATUS_UNSUPPORTED_STATUS = 0,60HTTP_STATUS_100_CONTINUE,61HTTP_STATUS_101_SWITCHING_PROTOCOLS,62HTTP_STATUS_200_OK,63HTTP_STATUS_201_CREATED,64HTTP_STATUS_202_ACCEPTED,65HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION,66HTTP_STATUS_204_NO_CONTENT,67HTTP_STATUS_205_RESET_CONTENT,68HTTP_STATUS_206_PARTIAL_CONTENT,69HTTP_STATUS_300_MULTIPLE_CHOICES,70HTTP_STATUS_301_MOVED_PERMANENTLY,71HTTP_STATUS_302_FOUND,72HTTP_STATUS_303_SEE_OTHER,73HTTP_STATUS_304_NOT_MODIFIED,74HTTP_STATUS_305_USE_PROXY,75HTTP_STATUS_307_TEMPORARY_REDIRECT,76HTTP_STATUS_400_BAD_REQUEST,77HTTP_STATUS_401_UNAUTHORIZED,78HTTP_STATUS_402_PAYMENT_REQUIRED,79HTTP_STATUS_403_FORBIDDEN,80HTTP_STATUS_404_NOT_FOUND,81HTTP_STATUS_405_METHOD_NOT_ALLOWED,82HTTP_STATUS_406_NOT_ACCEPTABLE,83HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED,84HTTP_STATUS_408_REQUEST_TIME_OUT,85HTTP_STATUS_409_CONFLICT,86HTTP_STATUS_410_GONE,87HTTP_STATUS_411_LENGTH_REQUIRED,88HTTP_STATUS_412_PRECONDITION_FAILED,89HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE,90HTTP_STATUS_414_REQUEST_URI_TOO_LARGE,91HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE,92HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED,93HTTP_STATUS_417_EXPECTATION_FAILED,94HTTP_STATUS_500_INTERNAL_SERVER_ERROR,95HTTP_STATUS_501_NOT_IMPLEMENTED,96HTTP_STATUS_502_BAD_GATEWAY,97HTTP_STATUS_503_SERVICE_UNAVAILABLE,98HTTP_STATUS_504_GATEWAY_TIME_OUT,99HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED,100HTTP_STATUS_308_PERMANENT_REDIRECT,101HTTP_STATUS_429_TOO_MANY_REQUESTS102} EFI_HTTP_STATUS_CODE;103104///105/// EFI_HTTPv4_ACCESS_POINT106///107typedef struct {108///109/// Set to TRUE to instruct the EFI HTTP instance to use the default address110/// information in every TCP connection made by this instance. In addition, when set111/// to TRUE, LocalAddress and LocalSubnet are ignored.112///113BOOLEAN UseDefaultAddress;114///115/// If UseDefaultAddress is set to FALSE, this defines the local IP address to be116/// used in every TCP connection opened by this instance.117///118EFI_IPv4_ADDRESS LocalAddress;119///120/// If UseDefaultAddress is set to FALSE, this defines the local subnet to be used121/// in every TCP connection opened by this instance.122///123EFI_IPv4_ADDRESS LocalSubnet;124///125/// This defines the local port to be used in126/// every TCP connection opened by this instance.127///128UINT16 LocalPort;129} EFI_HTTPv4_ACCESS_POINT;130131///132/// EFI_HTTPv6_ACCESS_POINT133///134typedef struct {135///136/// Local IP address to be used in every TCP connection opened by this instance.137///138EFI_IPv6_ADDRESS LocalAddress;139///140/// Local port to be used in every TCP connection opened by this instance.141///142UINT16 LocalPort;143} EFI_HTTPv6_ACCESS_POINT;144145///146/// EFI_HTTP_CONFIG_DATA_ACCESS_POINT147///148149typedef struct {150///151/// HTTP version that this instance will support.152///153EFI_HTTP_VERSION HttpVersion;154///155/// Time out (in milliseconds) when blocking for requests.156///157UINT32 TimeOutMillisec;158///159/// Defines behavior of EFI DNS and TCP protocols consumed by this instance. If160/// FALSE, this instance will use EFI_DNS4_PROTOCOL and EFI_TCP4_PROTOCOL. If TRUE,161/// this instance will use EFI_DNS6_PROTOCOL and EFI_TCP6_PROTOCOL.162///163BOOLEAN LocalAddressIsIPv6;164165union {166///167/// When LocalAddressIsIPv6 is FALSE, this points to the local address, subnet, and168/// port used by the underlying TCP protocol.169///170EFI_HTTPv4_ACCESS_POINT *IPv4Node;171///172/// When LocalAddressIsIPv6 is TRUE, this points to the local IPv6 address and port173/// used by the underlying TCP protocol.174///175EFI_HTTPv6_ACCESS_POINT *IPv6Node;176} AccessPoint;177} EFI_HTTP_CONFIG_DATA;178179///180/// EFI_HTTP_REQUEST_DATA181///182typedef struct {183///184/// The HTTP method (e.g. GET, POST) for this HTTP Request.185///186EFI_HTTP_METHOD Method;187///188/// The URI of a remote host. From the information in this field, the HTTP instance189/// will be able to determine whether to use HTTP or HTTPS and will also be able to190/// determine the port number to use. If no port number is specified, port 80 (HTTP)191/// is assumed. See RFC 3986 for more details on URI syntax.192///193CHAR16 *Url;194} EFI_HTTP_REQUEST_DATA;195196///197/// EFI_HTTP_RESPONSE_DATA198///199typedef struct {200///201/// Response status code returned by the remote host.202///203EFI_HTTP_STATUS_CODE StatusCode;204} EFI_HTTP_RESPONSE_DATA;205206///207/// EFI_HTTP_HEADER208///209typedef struct {210///211/// Null terminated string which describes a field name. See RFC 2616 Section 14 for212/// detailed information about field names.213///214CHAR8 *FieldName;215///216/// Null terminated string which describes the corresponding field value. See RFC 2616217/// Section 14 for detailed information about field values.218///219CHAR8 *FieldValue;220} EFI_HTTP_HEADER;221222///223/// EFI_HTTP_MESSAGE224///225typedef struct {226///227/// HTTP message data.228///229union {230///231/// When the token is used to send a HTTP request, Request is a pointer to storage that232/// contains such data as URL and HTTP method.233///234EFI_HTTP_REQUEST_DATA *Request;235///236/// When used to await a response, Response points to storage containing HTTP response237/// status code.238///239EFI_HTTP_RESPONSE_DATA *Response;240} Data;241///242/// Number of HTTP header structures in Headers list. On request, this count is243/// provided by the caller. On response, this count is provided by the HTTP driver.244///245UINTN HeaderCount;246///247/// Array containing list of HTTP headers. On request, this array is populated by the248/// caller. On response, this array is allocated and populated by the HTTP driver. It249/// is the responsibility of the caller to free this memory on both request and250/// response.251///252EFI_HTTP_HEADER *Headers;253///254/// Length in bytes of the HTTP body. This can be zero depending on the HttpMethod type.255///256UINTN BodyLength;257///258/// Body associated with the HTTP request or response. This can be NULL depending on259/// the HttpMethod type.260///261VOID *Body;262} EFI_HTTP_MESSAGE;263264///265/// EFI_HTTP_TOKEN266///267typedef struct {268///269/// This Event will be signaled after the Status field is updated by the EFI HTTP270/// Protocol driver. The type of Event must be EFI_NOTIFY_SIGNAL. The Task Priority271/// Level (TPL) of Event must be lower than or equal to TPL_CALLBACK.272///273EFI_EVENT Event;274///275/// Status will be set to one of the following value if the HTTP request is276/// successfully sent or if an unexpected error occurs:277/// EFI_SUCCESS: The HTTP request was successfully sent to the remote host.278/// EFI_HTTP_ERROR: The response message was successfully received but contains a279/// HTTP error. The response status code is returned in token.280/// EFI_ABORTED: The HTTP request was cancelled by the caller and removed from281/// the transmit queue.282/// EFI_TIMEOUT: The HTTP request timed out before reaching the remote host.283/// EFI_DEVICE_ERROR: An unexpected system or network error occurred.284///285EFI_STATUS Status;286///287/// Pointer to storage containing HTTP message data.288///289EFI_HTTP_MESSAGE *Message;290} EFI_HTTP_TOKEN;291292/**293Returns the operational parameters for the current HTTP child instance.294295The GetModeData() function is used to read the current mode data (operational296parameters) for this HTTP protocol instance.297298@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.299@param[out] HttpConfigData Point to buffer for operational parameters of this300HTTP instance. It is the responsibility of the caller301to allocate the memory for HttpConfigData and302HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact,303it is recommended to allocate sufficient memory to record304IPv6Node since it is big enough for all possibilities.305306@retval EFI_SUCCESS Operation succeeded.307@retval EFI_INVALID_PARAMETER This is NULL.308HttpConfigData is NULL.309HttpConfigData->AccessPoint.IPv4Node or310HttpConfigData->AccessPoint.IPv6Node is NULL.311@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.312**/313typedef314EFI_STATUS315(EFIAPI *EFI_HTTP_GET_MODE_DATA)(316IN EFI_HTTP_PROTOCOL *This,317OUT EFI_HTTP_CONFIG_DATA *HttpConfigData318);319320/**321Initialize or brutally reset the operational parameters for this EFI HTTP instance.322323The Configure() function does the following:324When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring325timeout, local address, port, etc.326When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active327connections with remote hosts, canceling all asynchronous tokens, and flush request328and response buffers without informing the appropriate hosts.329330No other EFI HTTP function can be executed by this instance until the Configure()331function is executed and returns successfully.332333@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.334@param[in] HttpConfigData Pointer to the configure data to configure the instance.335336@retval EFI_SUCCESS Operation succeeded.337@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:338This is NULL.339HttpConfigData->LocalAddressIsIPv6 is FALSE and340HttpConfigData->AccessPoint.IPv4Node is NULL.341HttpConfigData->LocalAddressIsIPv6 is TRUE and342HttpConfigData->AccessPoint.IPv6Node is NULL.343@retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling344Configure() with NULL to reset it.345@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.346@retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when347executing Configure().348@retval EFI_UNSUPPORTED One or more options in ConfigData are not supported349in the implementation.350**/351typedef352EFI_STATUS353(EFIAPI *EFI_HTTP_CONFIGURE)(354IN EFI_HTTP_PROTOCOL *This,355IN EFI_HTTP_CONFIG_DATA *HttpConfigData OPTIONAL356);357358/**359The Request() function queues an HTTP request to this HTTP instance,360similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent361successfully, or if there is an error, Status in token will be updated and Event will362be signaled.363364@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.365@param[in] Token Pointer to storage containing HTTP request token.366367@retval EFI_SUCCESS Outgoing data was processed.368@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.369@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.370@retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.371@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:372This is NULL.373Token is NULL.374Token->Message is NULL.375Token->Message->Body is not NULL,376Token->Message->BodyLength is non-zero, and377Token->Message->Data is NULL, but a previous call to378Request()has not been completed successfully.379@retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.380@retval EFI_UNSUPPORTED The HTTP method is not supported in current implementation.381**/382typedef383EFI_STATUS384(EFIAPI *EFI_HTTP_REQUEST)(385IN EFI_HTTP_PROTOCOL *This,386IN EFI_HTTP_TOKEN *Token387);388389/**390Abort an asynchronous HTTP request or response token.391392The Cancel() function aborts a pending HTTP request or response transaction. If393Token is not NULL and the token is in transmit or receive queues when it is being394cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will395be signaled. If the token is not in one of the queues, which usually means that the396asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,397all asynchronous tokens issued by Request() or Response() will be aborted.398399@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.400@param[in] Token Point to storage containing HTTP request or response401token.402403@retval EFI_SUCCESS Request and Response queues are successfully flushed.404@retval EFI_INVALID_PARAMETER This is NULL.405@retval EFI_NOT_STARTED This instance hasn't been configured.406@retval EFI_NOT_FOUND The asynchronous request or response token is not407found.408@retval EFI_UNSUPPORTED The implementation does not support this function.409**/410typedef411EFI_STATUS412(EFIAPI *EFI_HTTP_CANCEL)(413IN EFI_HTTP_PROTOCOL *This,414IN EFI_HTTP_TOKEN *Token415);416417/**418The Response() function queues an HTTP response to this HTTP instance, similar to419Receive() function in the EFI TCP driver. When the HTTP Response is received successfully,420or if there is an error, Status in token will be updated and Event will be signaled.421422The HTTP driver will queue a receive token to the underlying TCP instance. When data423is received in the underlying TCP instance, the data will be parsed and Token will424be populated with the response data. If the data received from the remote host425contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting426(asynchronously) for more data to be sent from the remote host before signaling427Event in Token.428429It is the responsibility of the caller to allocate a buffer for Body and specify the430size in BodyLength. If the remote host provides a response that contains a content431body, up to BodyLength bytes will be copied from the receive buffer into Body and432BodyLength will be updated with the amount of bytes received and copied to Body. This433allows the client to download a large file in chunks instead of into one contiguous434block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is435non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive436token to underlying TCP instance. If data arrives in the receive buffer, up to437BodyLength bytes of data will be copied to Body. The HTTP driver will then update438BodyLength with the amount of bytes received and copied to Body.439440If the HTTP driver does not have an open underlying TCP connection with the host441specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is442consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain443an open TCP connection between client and host.444445@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.446@param[in] Token Pointer to storage containing HTTP response token.447448@retval EFI_SUCCESS Allocation succeeded.449@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been450initialized.451@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:452This is NULL.453Token is NULL.454Token->Message->Headers is NULL.455Token->Message is NULL.456Token->Message->Body is not NULL,457Token->Message->BodyLength is non-zero, and458Token->Message->Data is NULL, but a previous call to459Response() has not been completed successfully.460@retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.461@retval EFI_ACCESS_DENIED An open TCP connection is not present with the host462specified by response URL.463**/464typedef465EFI_STATUS466(EFIAPI *EFI_HTTP_RESPONSE)(467IN EFI_HTTP_PROTOCOL *This,468IN EFI_HTTP_TOKEN *Token469);470471/**472The Poll() function can be used by network drivers and applications to increase the473rate that data packets are moved between the communication devices and the transmit474and receive queues.475476In some systems, the periodic timer event in the managed network driver may not poll477the underlying communications device fast enough to transmit and/or receive all data478packets without missing incoming packets or dropping outgoing packets. Drivers and479applications that are experiencing packet loss should try calling the Poll() function480more often.481482@param[in] This Pointer to EFI_HTTP_PROTOCOL instance.483484@retval EFI_SUCCESS Incoming or outgoing data was processed..485@retval EFI_DEVICE_ERROR An unexpected system or network error occurred486@retval EFI_INVALID_PARAMETER This is NULL.487@retval EFI_NOT_READY No incoming or outgoing data is processed.488@retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.489**/490typedef491EFI_STATUS492(EFIAPI *EFI_HTTP_POLL)(493IN EFI_HTTP_PROTOCOL *This494);495496///497/// The EFI HTTP protocol is designed to be used by EFI drivers and applications to498/// create and transmit HTTP Requests, as well as handle HTTP responses that are499/// returned by a remote host. This EFI protocol uses and relies on an underlying EFI500/// TCP protocol.501///502struct _EFI_HTTP_PROTOCOL {503EFI_HTTP_GET_MODE_DATA GetModeData;504EFI_HTTP_CONFIGURE Configure;505EFI_HTTP_REQUEST Request;506EFI_HTTP_CANCEL Cancel;507EFI_HTTP_RESPONSE Response;508EFI_HTTP_POLL Poll;509};510511extern EFI_GUID gEfiHttpServiceBindingProtocolGuid;512extern EFI_GUID gEfiHttpProtocolGuid;513514#endif515516517