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