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