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