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