e1fd785b2cefe2d01c0f70c05e5cacefa8fe8f60
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpProto.h
1 /** @file
2 The header files of miscellaneous routines for HttpDxe driver.
3
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __EFI_HTTP_PROTO_H__
17 #define __EFI_HTTP_PROTO_H__
18
19 #define DEF_BUF_LEN 2048
20
21 #define HTTP_SERVICE_SIGNATURE SIGNATURE_32('H', 't', 't', 'S')
22
23 #define HTTP_SERVICE_FROM_PROTOCOL(a) \
24 CR ( \
25 (a), \
26 HTTP_SERVICE, \
27 ServiceBinding, \
28 HTTP_SERVICE_SIGNATURE \
29 )
30
31
32 //
33 // The state of HTTP protocol. It starts from UNCONFIGED.
34 //
35 #define HTTP_STATE_UNCONFIGED 0
36 #define HTTP_STATE_HTTP_CONFIGED 1
37 #define HTTP_STATE_TCP_CONFIGED 2
38 #define HTTP_STATE_TCP_UNCONFIGED 3
39 #define HTTP_STATE_TCP_CONNECTED 4
40 #define HTTP_STATE_TCP_CLOSED 5
41
42 //
43 // TCP configured data.
44 //
45 #define HTTP_TOS_DEAULT 8
46 #define HTTP_TTL_DEAULT 255
47 #define HTTP_BUFFER_SIZE_DEAULT 65535
48 #define HTTP_MAX_SYN_BACK_LOG 5
49 #define HTTP_CONNECTION_TIMEOUT 60
50 #define HTTP_RESPONSE_TIMEOUT 5
51 #define HTTP_DATA_RETRIES 12
52 #define HTTP_FIN_TIMEOUT 2
53 #define HTTP_KEEP_ALIVE_PROBES 6
54 #define HTTP_KEEP_ALIVE_TIME 7200
55 #define HTTP_KEEP_ALIVE_INTERVAL 30
56
57 #define HTTP_URL_BUFFER_LEN 4096
58
59 typedef struct _HTTP_SERVICE {
60 UINT32 Signature;
61 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
62 EFI_HANDLE ImageHandle;
63 EFI_HANDLE ControllerHandle;
64 EFI_HANDLE Tcp4ChildHandle;
65 EFI_HANDLE Tcp6ChildHandle;
66 LIST_ENTRY ChildrenList;
67 UINTN ChildrenNumber;
68 INTN State;
69 } HTTP_SERVICE;
70
71 typedef struct {
72 EFI_TCP4_IO_TOKEN Tx4Token;
73 EFI_TCP4_TRANSMIT_DATA Tx4Data;
74 EFI_TCP6_IO_TOKEN Tx6Token;
75 EFI_TCP6_TRANSMIT_DATA Tx6Data;
76 EFI_TCP4_IO_TOKEN Rx4Token;
77 EFI_TCP4_RECEIVE_DATA Rx4Data;
78 EFI_TCP6_IO_TOKEN Rx6Token;
79 EFI_TCP6_RECEIVE_DATA Rx6Data;
80 BOOLEAN IsTxDone;
81 BOOLEAN IsRxDone;
82 UINTN BodyLen;
83 EFI_HTTP_METHOD Method;
84 } HTTP_TCP_TOKEN_WRAP;
85
86 typedef struct _HTTP_PROTOCOL {
87 UINT32 Signature;
88 EFI_HTTP_PROTOCOL Http;
89 EFI_HANDLE Handle;
90 HTTP_SERVICE *Service;
91 LIST_ENTRY Link; // Link to all HTTP instance from the service.
92 BOOLEAN InDestroy;
93 INTN State;
94 EFI_HTTP_METHOD Method;
95
96 UINTN StatusCode;
97
98 EFI_EVENT TimeoutEvent;
99
100 EFI_HANDLE Tcp4ChildHandle;
101 EFI_TCP4_PROTOCOL *Tcp4;
102 EFI_TCP4_CONFIG_DATA Tcp4CfgData;
103 EFI_TCP4_OPTION Tcp4Option;
104
105 EFI_TCP4_CONNECTION_TOKEN Tcp4ConnToken;
106 BOOLEAN IsTcp4ConnDone;
107 EFI_TCP4_CLOSE_TOKEN Tcp4CloseToken;
108 BOOLEAN IsTcp4CloseDone;
109 CHAR8 *RemoteHost;
110 UINT16 RemotePort;
111 EFI_IPv4_ADDRESS RemoteAddr;
112
113 EFI_HANDLE Tcp6ChildHandle;
114 EFI_TCP6_PROTOCOL *Tcp6;
115 EFI_TCP6_CONFIG_DATA Tcp6CfgData;
116 EFI_TCP6_OPTION Tcp6Option;
117
118 EFI_TCP6_CONNECTION_TOKEN Tcp6ConnToken;
119 BOOLEAN IsTcp6ConnDone;
120 EFI_TCP6_CLOSE_TOKEN Tcp6CloseToken;
121 BOOLEAN IsTcp6CloseDone;
122 EFI_IPv6_ADDRESS RemoteIpv6Addr;
123
124 //
125 // Rx4Token or Rx6Token used for receiving HTTP header.
126 //
127 EFI_TCP4_IO_TOKEN Rx4Token;
128 EFI_TCP4_RECEIVE_DATA Rx4Data;
129 EFI_TCP6_IO_TOKEN Rx6Token;
130 EFI_TCP6_RECEIVE_DATA Rx6Data;
131 BOOLEAN IsRxDone;
132
133 CHAR8 **EndofHeader;
134 CHAR8 **HttpHeaders;
135 CHAR8 *CacheBody;
136 CHAR8 *NextMsg;
137 UINTN CacheLen;
138 UINTN CacheOffset;
139
140 //
141 // HTTP message-body parser.
142 //
143 VOID *MsgParser;
144
145 EFI_HTTP_VERSION HttpVersion;
146 UINT32 TimeOutMillisec;
147 BOOLEAN LocalAddressIsIPv6;
148
149 EFI_HTTPv4_ACCESS_POINT IPv4Node;
150 EFI_HTTPv6_ACCESS_POINT Ipv6Node;
151
152 NET_MAP TxTokens;
153 NET_MAP RxTokens;
154
155 CHAR8 *Url;
156 } HTTP_PROTOCOL;
157
158 typedef struct {
159 EFI_HTTP_TOKEN *HttpToken;
160 HTTP_PROTOCOL *HttpInstance;
161 HTTP_TCP_TOKEN_WRAP TcpWrap;
162 } HTTP_TOKEN_WRAP;
163
164
165 #define HTTP_PROTOCOL_SIGNATURE SIGNATURE_32('H', 't', 't', 'P')
166
167 #define HTTP_INSTANCE_FROM_PROTOCOL(a) \
168 CR ( \
169 (a), \
170 HTTP_PROTOCOL, \
171 Http, \
172 HTTP_PROTOCOL_SIGNATURE \
173 )
174
175 /**
176 The common notify function used in HTTP driver.
177
178 @param[in] Event The event signaled.
179 @param[in] Context The context.
180
181 **/
182 VOID
183 EFIAPI
184 HttpCommonNotify (
185 IN EFI_EVENT Event,
186 IN VOID *Context
187 );
188
189 /**
190 Create events for the TCP connection token and TCP close token.
191
192 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
193
194 @retval EFI_SUCCESS The events are created successfully.
195 @retval others Other error as indicated.
196
197 **/
198 EFI_STATUS
199 HttpCreateTcpConnCloseEvent (
200 IN HTTP_PROTOCOL *HttpInstance
201 );
202
203 /**
204 Close events in the TCP connection token and TCP close token.
205
206 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
207
208 **/
209 VOID
210 HttpCloseTcpConnCloseEvent (
211 IN HTTP_PROTOCOL *HttpInstance
212 );
213
214 /**
215 Create event for the TCP transmit token.
216
217 @param[in] Wrap Point to HTTP token's wrap data.
218
219 @retval EFI_SUCCESS The events is created successfully.
220 @retval others Other error as indicated.
221
222 **/
223 EFI_STATUS
224 HttpCreateTcpTxEvent (
225 IN HTTP_TOKEN_WRAP *Wrap
226 );
227
228 /**
229 Create event for the TCP receive token which is used to receive HTTP header.
230
231 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
232
233 @retval EFI_SUCCESS The events is created successfully.
234 @retval others Other error as indicated.
235
236 **/
237 EFI_STATUS
238 HttpCreateTcpRxEventForHeader (
239 IN HTTP_PROTOCOL *HttpInstance
240 );
241
242 /**
243 Create event for the TCP receive token which is used to receive HTTP body.
244
245 @param[in] Wrap Point to HTTP token's wrap data.
246
247 @retval EFI_SUCCESS The events is created successfully.
248 @retval others Other error as indicated.
249
250 **/
251 EFI_STATUS
252 HttpCreateTcpRxEvent (
253 IN HTTP_TOKEN_WRAP *Wrap
254 );
255
256 /**
257 Close Events for Tcp Receive Tokens for HTTP body and HTTP header.
258
259 @param[in] Wrap Pointer to HTTP token's wrap data.
260
261 **/
262 VOID
263 HttpCloseTcpRxEvent (
264 IN HTTP_TOKEN_WRAP *Wrap
265 );
266
267 /**
268 Intiialize the HTTP_PROTOCOL structure to the unconfigured state.
269
270 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
271 @param[in] IpVersion Indicate us TCP4 protocol or TCP6 protocol.
272
273 @retval EFI_SUCCESS HTTP_PROTOCOL structure is initialized successfully.
274 @retval Others Other error as indicated.
275
276 **/
277 EFI_STATUS
278 HttpInitProtocol (
279 IN OUT HTTP_PROTOCOL *HttpInstance,
280 IN BOOLEAN IpVersion
281 );
282
283 /**
284 Clean up the HTTP child, release all the resources used by it.
285
286 @param[in] HttpInstance The HTTP child to clean up.
287
288 **/
289 VOID
290 HttpCleanProtocol (
291 IN HTTP_PROTOCOL *HttpInstance
292 );
293
294 /**
295 Establish TCP connection with HTTP server.
296
297 @param[in] HttpInstance The HTTP instance private data.
298
299 @retval EFI_SUCCESS The TCP connection is established.
300 @retval Others Other error as indicated.
301
302 **/
303 EFI_STATUS
304 HttpCreateConnection (
305 IN HTTP_PROTOCOL *HttpInstance
306 );
307
308 /**
309 Close existing TCP connection.
310
311 @param[in] HttpInstance The HTTP instance private data.
312
313 @retval EFI_SUCCESS The TCP connection is closed.
314 @retval Others Other error as indicated.
315
316 **/
317 EFI_STATUS
318 HttpCloseConnection (
319 IN HTTP_PROTOCOL *HttpInstance
320 );
321
322 /**
323 Configure TCP4 protocol child.
324
325 @param[in] HttpInstance The HTTP instance private data.
326 @param[in] Wrap The HTTP token's wrap data.
327
328 @retval EFI_SUCCESS The TCP4 protocol child is configured.
329 @retval Others Other error as indicated.
330
331 **/
332 EFI_STATUS
333 HttpConfigureTcp4 (
334 IN HTTP_PROTOCOL *HttpInstance,
335 IN HTTP_TOKEN_WRAP *Wrap
336 );
337
338 /**
339 Configure TCP6 protocol child.
340
341 @param[in] HttpInstance The HTTP instance private data.
342 @param[in] Wrap The HTTP token's wrap data.
343
344 @retval EFI_SUCCESS The TCP6 protocol child is configured.
345 @retval Others Other error as indicated.
346
347 **/
348 EFI_STATUS
349 HttpConfigureTcp6 (
350 IN HTTP_PROTOCOL *HttpInstance,
351 IN HTTP_TOKEN_WRAP *Wrap
352 );
353
354 /**
355 Check existing TCP connection, if in error state, receover TCP4 connection.
356
357 @param[in] HttpInstance The HTTP instance private data.
358
359 @retval EFI_SUCCESS The TCP connection is established.
360 @retval EFI_NOT_READY TCP4 protocol child is not created or configured.
361 @retval Others Other error as indicated.
362
363 **/
364 EFI_STATUS
365 HttpConnectTcp4 (
366 IN HTTP_PROTOCOL *HttpInstance
367 );
368
369 /**
370 Check existing TCP connection, if in error state, recover TCP6 connection.
371
372 @param[in] HttpInstance The HTTP instance private data.
373
374 @retval EFI_SUCCESS The TCP connection is established.
375 @retval EFI_NOT_READY TCP6 protocol child is not created or configured.
376 @retval Others Other error as indicated.
377
378 **/
379 EFI_STATUS
380 HttpConnectTcp6 (
381 IN HTTP_PROTOCOL *HttpInstance
382 );
383
384 /**
385 Send the HTTP message through TCP4 or TCP6.
386
387 @param[in] HttpInstance The HTTP instance private data.
388 @param[in] Wrap The HTTP token's wrap data.
389 @param[in] TxString Buffer containing the HTTP message string.
390 @param[in] TxStringLen Length of the HTTP message string in bytes.
391
392 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit queue.
393 @retval Others Other error as indicated.
394
395 **/
396 EFI_STATUS
397 HttpTransmitTcp (
398 IN HTTP_PROTOCOL *HttpInstance,
399 IN HTTP_TOKEN_WRAP *Wrap,
400 IN UINT8 *TxString,
401 IN UINTN TxStringLen
402 );
403
404 /**
405 Check whether the user's token or event has already
406 been enqueue on HTTP Tx or Rx Token list.
407
408 @param[in] Map The container of either user's transmit or receive
409 token.
410 @param[in] Item Current item to check against.
411 @param[in] Context The Token to check againist.
412
413 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
414 @retval EFI_SUCCESS The current item isn't the same token/event as the
415 context.
416
417 **/
418 EFI_STATUS
419 EFIAPI
420 HttpTokenExist (
421 IN NET_MAP *Map,
422 IN NET_MAP_ITEM *Item,
423 IN VOID *Context
424 );
425
426 /**
427 Check whether the HTTP message associated with TxToken or Tx6Token is already sent out.
428
429 @param[in] Map The container of TxToken.
430 @param[in] Item Current item to check against.
431 @param[in] Context The Token to check againist.
432
433 @retval EFI_NOT_READY The HTTP message is still queued in the list.
434 @retval EFI_SUCCESS The HTTP message has been sent out.
435
436 **/
437 EFI_STATUS
438 EFIAPI
439 HttpTcpNotReady (
440 IN NET_MAP *Map,
441 IN NET_MAP_ITEM *Item,
442 IN VOID *Context
443 );
444
445 /**
446 Initialize TCP related data.
447
448 @param[in] HttpInstance The HTTP instance private data.
449 @param[in] Wrap The HTTP token's wrap data.
450 @param[in] Configure The Flag indicates whether the first time to initialize Tcp.
451
452 @retval EFI_SUCCESS The initialization of TCP instance is done.
453 @retval Others Other error as indicated.
454
455 **/
456 EFI_STATUS
457 HttpInitTcp (
458 IN HTTP_PROTOCOL *HttpInstance,
459 IN HTTP_TOKEN_WRAP *Wrap,
460 IN BOOLEAN Configure
461 );
462
463 /**
464 Transmit the HTTP mssage by processing the associated HTTP token.
465
466 @param[in] Map The container of TxToken or Tx6Token.
467 @param[in] Item Current item to check against.
468 @param[in] Context The Token to check againist.
469
470 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
471 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit
472 queue.
473
474 **/
475 EFI_STATUS
476 EFIAPI
477 HttpTcpTransmit (
478 IN NET_MAP *Map,
479 IN NET_MAP_ITEM *Item,
480 IN VOID *Context
481 );
482
483 /**
484 Receive the HTTP response by processing the associated HTTP token.
485
486 @param[in] Map The container of Rx4Token or Rx6Token.
487 @param[in] Item Current item to check against.
488 @param[in] Context The Token to check againist.
489
490 @retval EFI_SUCCESS The HTTP response is queued into TCP receive
491 queue.
492 @retval Others Other error as indicated.
493
494 **/
495 EFI_STATUS
496 EFIAPI
497 HttpTcpReceive (
498 IN NET_MAP *Map,
499 IN NET_MAP_ITEM *Item,
500 IN VOID *Context
501 );
502
503 /**
504 Receive the HTTP header by processing the associated HTTP token.
505
506 @param[in] HttpInstance The HTTP instance private data.
507 @param[in, out] SizeofHeaders The HTTP header length.
508 @param[in, out] BufferSize The size of buffer to cacahe the header message.
509 @param[in] Timeout The time to wait for receiving the header packet.
510
511 @retval EFI_SUCCESS The HTTP header is received.
512 @retval Others Other errors as indicated.
513
514 **/
515 EFI_STATUS
516 HttpTcpReceiveHeader (
517 IN HTTP_PROTOCOL *HttpInstance,
518 IN OUT UINTN *SizeofHeaders,
519 IN OUT UINTN *BufferSize,
520 IN EFI_EVENT Timeout
521 );
522
523 /**
524 Receive the HTTP body by processing the associated HTTP token.
525
526 @param[in] Wrap The HTTP token's wrap data.
527 @param[in] HttpMsg The HTTP message data.
528
529 @retval EFI_SUCCESS The HTTP body is received.
530 @retval Others Other error as indicated.
531
532 **/
533 EFI_STATUS
534 HttpTcpReceiveBody (
535 IN HTTP_TOKEN_WRAP *Wrap,
536 IN EFI_HTTP_MESSAGE *HttpMsg
537 );
538
539 /**
540 Clean up Tcp Tokens while the Tcp transmission error occurs.
541
542 @param[in] Wrap Pointer to HTTP token's wrap data.
543
544 **/
545 VOID
546 HttpTcpTokenCleanup (
547 IN HTTP_TOKEN_WRAP *Wrap
548 );
549
550 /**
551 The work function of EfiHttpResponse().
552
553 @param[in] Wrap Pointer to HTTP token's wrap data.
554
555 @retval EFI_SUCCESS Allocation succeeded.
556 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
557 @retval EFI_NOT_READY Can't find a corresponding TxToken.
558
559 **/
560 EFI_STATUS
561 HttpResponseWorker (
562 IN HTTP_TOKEN_WRAP *Wrap
563 );
564
565 #endif