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