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