]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpDxe/HttpProto.h
NetworkPkg: Avoid memory allocation for each HTTP message exchange.
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpProto.h
CommitLineData
47f51a06
YT
1/** @file\r
2 The header files of miscellaneous routines for HttpDxe driver.\r
3\r
4Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef __EFI_HTTP_PROTO_H__\r
16#define __EFI_HTTP_PROTO_H__\r
17\r
18#define DEF_BUF_LEN 2048\r
19\r
20#define HTTP_SERVICE_SIGNATURE SIGNATURE_32('H', 't', 't', 'S')\r
21\r
22#define HTTP_SERVICE_FROM_PROTOCOL(a) \\r
23 CR ( \\r
24 (a), \\r
25 HTTP_SERVICE, \\r
26 ServiceBinding, \\r
27 HTTP_SERVICE_SIGNATURE \\r
28 )\r
29\r
30//\r
31// The state of HTTP protocol. It starts from UNCONFIGED.\r
32//\r
33#define HTTP_STATE_UNCONFIGED 0\r
34#define HTTP_STATE_HTTP_CONFIGED 1\r
35#define HTTP_STATE_TCP_CONFIGED 2\r
36#define HTTP_STATE_TCP_UNCONFIGED 3\r
37#define HTTP_STATE_TCP_CONNECTED 4\r
38#define HTTP_STATE_TCP_CLOSED 5\r
39\r
40//\r
41// TCP configured data.\r
42//\r
43#define HTTP_TOS_DEAULT 8\r
44#define HTTP_TTL_DEAULT 255\r
45#define HTTP_BUFFER_SIZE_DEAULT 65535\r
46#define HTTP_MAX_SYN_BACK_LOG 5\r
47#define HTTP_CONNECTION_TIMEOUT 60\r
48#define HTTP_DATA_RETRIES 12\r
49#define HTTP_FIN_TIMEOUT 2\r
50#define HTTP_KEEP_ALIVE_PROBES 6\r
51#define HTTP_KEEP_ALIVE_TIME 7200\r
52#define HTTP_KEEP_ALIVE_INTERVAL 30\r
53\r
51b0450e
FS
54#define HTTP_URL_BUFFER_LEN 4096\r
55\r
47f51a06
YT
56typedef struct _HTTP_SERVICE {\r
57 UINT32 Signature;\r
58 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r
59 EFI_HANDLE ImageHandle;\r
60 EFI_HANDLE ControllerHandle;\r
61 LIST_ENTRY ChildrenList;\r
62 UINTN ChildrenNumber;\r
63 EFI_HANDLE TcpChildHandle;\r
64 INTN State;\r
65} HTTP_SERVICE;\r
66\r
67typedef struct {\r
68 EFI_TCP4_IO_TOKEN TxToken;\r
69 EFI_TCP4_TRANSMIT_DATA TxData;\r
70 BOOLEAN IsTxDone;\r
71 EFI_TCP4_IO_TOKEN RxToken;\r
72 EFI_TCP4_RECEIVE_DATA RxData;\r
73 BOOLEAN IsRxDone;\r
74 UINTN BodyLen;\r
75 EFI_HTTP_METHOD Method;\r
76} HTTP_TCP_TOKEN_WRAP;\r
77\r
78typedef struct _HTTP_PROTOCOL {\r
79 UINT32 Signature;\r
80 EFI_HTTP_PROTOCOL Http;\r
81 EFI_HANDLE Handle;\r
82 HTTP_SERVICE *Service;\r
83 LIST_ENTRY Link; // Link to all HTTP instance from the service.\r
84 BOOLEAN InDestroy;\r
85 INTN State;\r
86\r
87 EFI_HANDLE TcpChildHandle;\r
88 EFI_TCP4_PROTOCOL *Tcp4;\r
89 EFI_TCP4_CONFIG_DATA Tcp4CfgData;\r
90 EFI_TCP4_OPTION Tcp4Option;\r
91\r
92 EFI_TCP4_CONNECTION_TOKEN ConnToken;\r
93 BOOLEAN IsConnDone;\r
94 EFI_TCP4_CLOSE_TOKEN CloseToken;\r
95 BOOLEAN IsCloseDone;\r
96\r
97 CHAR8 *RemoteHost;\r
98 UINT16 RemotePort;\r
99 EFI_IPv4_ADDRESS RemoteAddr;\r
100 //\r
101 // RxToken used for receiving HTTP header.\r
102 //\r
103 EFI_TCP4_IO_TOKEN RxToken;\r
104 EFI_TCP4_RECEIVE_DATA RxData;\r
105 BOOLEAN IsRxDone;\r
106\r
107 CHAR8 *CacheBody;\r
108 CHAR8 *NextMsg;\r
109 UINTN CacheLen;\r
110 UINTN CacheOffset;\r
111\r
112 //\r
113 // HTTP message-body parser.\r
114 //\r
115 VOID *MsgParser;\r
116 \r
117 EFI_HTTP_VERSION HttpVersion;\r
118 UINT32 TimeOutMillisec;\r
119 BOOLEAN LocalAddressIsIPv6;\r
120\r
121 EFI_HTTPv4_ACCESS_POINT IPv4Node;\r
122\r
123 NET_MAP TxTokens;\r
124 NET_MAP RxTokens;\r
51b0450e
FS
125\r
126 CHAR8 *Url;\r
47f51a06
YT
127} HTTP_PROTOCOL;\r
128\r
129typedef struct {\r
130 EFI_HTTP_TOKEN *HttpToken;\r
131 HTTP_PROTOCOL *HttpInstance;\r
132 HTTP_TCP_TOKEN_WRAP TcpWrap;\r
133} HTTP_TOKEN_WRAP;\r
134\r
135\r
136#define HTTP_PROTOCOL_SIGNATURE SIGNATURE_32('H', 't', 't', 'P')\r
137\r
138#define HTTP_INSTANCE_FROM_PROTOCOL(a) \\r
139 CR ( \\r
140 (a), \\r
141 HTTP_PROTOCOL, \\r
142 Http, \\r
143 HTTP_PROTOCOL_SIGNATURE \\r
144 )\r
145\r
146/**\r
147 The common notify function used in HTTP driver. \r
148\r
149 @param[in] Event The event signaled.\r
150 @param[in] Context The context.\r
151\r
152**/\r
153VOID\r
154EFIAPI\r
155HttpCommonNotify (\r
156 IN EFI_EVENT Event,\r
157 IN VOID *Context\r
158 );\r
159\r
160/**\r
161 Create events for the TCP4 connection token and TCP4 close token.\r
162\r
163 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
164\r
165 @retval EFI_SUCCESS The events are created successfully.\r
166 @retval others Other error as indicated.\r
167\r
168**/\r
169EFI_STATUS\r
170HttpCreateTcp4ConnCloseEvent (\r
171 IN HTTP_PROTOCOL *HttpInstance\r
172 );\r
173\r
174/**\r
175 Close events in the TCP4 connection token and TCP4 close token.\r
176\r
177 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
178\r
179**/\r
180VOID\r
181HttpCloseTcp4ConnCloseEvent (\r
182 IN HTTP_PROTOCOL *HttpInstance\r
183 );\r
184\r
185/**\r
186 Create event for the TCP4 transmit token.\r
187\r
188 @param[in] Wrap Point to HTTP token's wrap data.\r
189\r
190 @retval EFI_SUCCESS The events is created successfully.\r
191 @retval others Other error as indicated.\r
192\r
193**/\r
194EFI_STATUS\r
195HttpCreateTcp4TxEvent (\r
196 IN HTTP_TOKEN_WRAP *Wrap\r
197 );\r
198\r
199/**\r
200 Create event for the TCP4 receive token which is used to receive HTTP header.\r
201\r
202 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
203\r
204 @retval EFI_SUCCESS The events is created successfully.\r
205 @retval others Other error as indicated.\r
206\r
207**/\r
208EFI_STATUS\r
209HttpCreateTcp4RxEventForHeader (\r
210 IN HTTP_PROTOCOL *HttpInstance\r
211 );\r
212\r
213/**\r
214 Create event for the TCP4 receive token which is used to receive HTTP body.\r
215\r
216 @param[in] Wrap Point to HTTP token's wrap data.\r
217\r
218 @retval EFI_SUCCESS The events is created successfully.\r
219 @retval others Other error as indicated.\r
220\r
221**/\r
222EFI_STATUS\r
223HttpCreateTcp4RxEvent (\r
224 IN HTTP_TOKEN_WRAP *Wrap \r
225 );\r
226\r
227/**\r
228 Intiialize the HTTP_PROTOCOL structure to the unconfigured state.\r
229\r
230 @param[in] HttpSb The HTTP service private instance.\r
231 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
232\r
233 @retval EFI_SUCCESS HTTP_PROTOCOL structure is initialized successfully. \r
234 @retval Others Other error as indicated.\r
235\r
236**/\r
237EFI_STATUS\r
238HttpInitProtocol (\r
239 IN HTTP_SERVICE *HttpSb,\r
240 IN OUT HTTP_PROTOCOL *HttpInstance\r
241 );\r
242\r
243/**\r
244 Clean up the HTTP child, release all the resources used by it.\r
245\r
246 @param[in] HttpInstance The HTTP child to clean up.\r
247\r
248**/\r
249VOID\r
250HttpCleanProtocol (\r
251 IN HTTP_PROTOCOL *HttpInstance\r
252 );\r
253\r
254/**\r
255 Establish TCP connection with HTTP server.\r
256\r
257 @param[in] HttpInstance The HTTP instance private data.\r
258\r
259 @retval EFI_SUCCESS The TCP connection is established.\r
260 @retval Others Other error as indicated.\r
261\r
262**/\r
263EFI_STATUS\r
264HttpCreateConnection (\r
265 IN HTTP_PROTOCOL *HttpInstance\r
266 );\r
267\r
268/**\r
269 Close existing TCP connection.\r
270\r
271 @param[in] HttpInstance The HTTP instance private data.\r
272\r
273 @retval EFI_SUCCESS The TCP connection is closed.\r
274 @retval Others Other error as indicated.\r
275\r
276**/\r
277EFI_STATUS\r
278HttpCloseConnection (\r
279 IN HTTP_PROTOCOL *HttpInstance\r
280 );\r
281\r
282/**\r
283 Configure TCP4 protocol child.\r
284\r
285 @param[in] HttpInstance The HTTP instance private data.\r
286 @param[in] Wrap The HTTP token's wrap data.\r
287\r
288 @retval EFI_SUCCESS The TCP4 protocol child is configured.\r
289 @retval Others Other error as indicated.\r
290\r
291**/\r
292EFI_STATUS\r
293HttpConfigureTcp4 (\r
294 IN HTTP_PROTOCOL *HttpInstance,\r
295 IN HTTP_TOKEN_WRAP *Wrap\r
296 );\r
297\r
298/**\r
299 Check existing TCP connection, if in error state, receover TCP4 connection.\r
300\r
301 @param[in] HttpInstance The HTTP instance private data.\r
302\r
303 @retval EFI_SUCCESS The TCP connection is established.\r
304 @retval EFI_NOT_READY TCP4 protocol child is not created or configured.\r
305 @retval Others Other error as indicated.\r
306\r
307**/\r
308EFI_STATUS\r
309HttpConnectTcp4 (\r
310 IN HTTP_PROTOCOL *HttpInstance\r
311 );\r
312\r
313/**\r
314 Send the HTTP message through TCP4.\r
315\r
316 @param[in] HttpInstance The HTTP instance private data.\r
317 @param[in] Wrap The HTTP token's wrap data.\r
318 @param[in] TxString Buffer containing the HTTP message string.\r
319 @param[in] TxStringLen Length of the HTTP message string in bytes.\r
320\r
321 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit queue.\r
322 @retval Others Other error as indicated.\r
323\r
324**/\r
325EFI_STATUS\r
326HttpTransmitTcp4 (\r
327 IN HTTP_PROTOCOL *HttpInstance,\r
328 IN HTTP_TOKEN_WRAP *Wrap,\r
329 IN UINT8 *TxString,\r
330 IN UINTN TxStringLen\r
331 );\r
332\r
333/**\r
334 Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined \r
335 in UEFI 2.5 specification.\r
336\r
337 @param[in] StatusCode The status code value in HTTP message.\r
338\r
339 @return Value defined in EFI_HTTP_STATUS_CODE .\r
340\r
341**/\r
342EFI_HTTP_STATUS_CODE\r
343HttpMappingToStatusCode (\r
344 IN UINTN StatusCode\r
345 );\r
346\r
347/**\r
348 Check whether the user's token or event has already\r
349 been enqueue on HTTP TxToken or RxToken list.\r
350\r
351 @param[in] Map The container of either user's transmit or receive\r
352 token.\r
353 @param[in] Item Current item to check against.\r
354 @param[in] Context The Token to check againist.\r
355\r
356 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP\r
357 @retval EFI_SUCCESS The current item isn't the same token/event as the\r
358 context.\r
359\r
360**/\r
361EFI_STATUS\r
362EFIAPI\r
363HttpTokenExist (\r
364 IN NET_MAP *Map,\r
365 IN NET_MAP_ITEM *Item,\r
366 IN VOID *Context\r
367 );\r
368\r
369/**\r
370 Check whether the HTTP message associated with TxToken is already sent out.\r
371\r
372 @param[in] Map The container of TxToken.\r
373 @param[in] Item Current item to check against.\r
374 @param[in] Context The Token to check againist.\r
375\r
376 @retval EFI_NOT_READY The HTTP message is still queued in the list.\r
377 @retval EFI_SUCCESS The HTTP message has been sent out.\r
378\r
379**/\r
380EFI_STATUS\r
381EFIAPI\r
382HttpTcpNotReady (\r
383 IN NET_MAP *Map,\r
384 IN NET_MAP_ITEM *Item,\r
385 IN VOID *Context\r
386 );\r
387\r
388/**\r
389 Transmit the HTTP mssage by processing the associated HTTP token.\r
390\r
391 @param[in] Map The container of TxToken.\r
392 @param[in] Item Current item to check against.\r
393 @param[in] Context The Token to check againist.\r
394\r
395 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.\r
396 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit\r
397 queue.\r
398\r
399**/\r
400EFI_STATUS\r
401EFIAPI\r
402HttpTcpTransmit (\r
403 IN NET_MAP *Map,\r
404 IN NET_MAP_ITEM *Item,\r
405 IN VOID *Context\r
406 );\r
407\r
408/**\r
409 Receive the HTTP response by processing the associated HTTP token.\r
410\r
411 @param[in] Map The container of RxToken.\r
412 @param[in] Item Current item to check against.\r
413 @param[in] Context The Token to check againist.\r
414\r
415 @retval EFI_SUCCESS The HTTP response is queued into TCP receive\r
416 queue.\r
417 @retval Others Other error as indicated.\r
418\r
419**/\r
420EFI_STATUS\r
421EFIAPI\r
422HttpTcpReceive (\r
423 IN NET_MAP *Map,\r
424 IN NET_MAP_ITEM *Item,\r
425 IN VOID *Context\r
426 );\r
427\r
428/**\r
429 Generate HTTP request string.\r
430\r
431 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
432 @param[in] Message Pointer to storage containing HTTP message data.\r
433 @param[in] Url The URL of a remote host.\r
434\r
435 @return Pointer to the created HTTP request string.\r
436 @return NULL if any error occured.\r
437\r
438**/\r
439CHAR8 *\r
440HttpGenRequestString (\r
441 IN HTTP_PROTOCOL *HttpInstance,\r
442 IN EFI_HTTP_MESSAGE *Message,\r
443 IN CHAR8 *Url\r
444 );\r
445\r
446/**\r
447 The work function of EfiHttpResponse().\r
448\r
449 @param[in] Wrap Pointer to HTTP token's wrap data.\r
450\r
451 @retval EFI_SUCCESS Allocation succeeded.\r
452 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.\r
453 @retval EFI_NOT_READY Can't find a corresponding TxToken.\r
454\r
455**/\r
456EFI_STATUS\r
457HttpResponseWorker (\r
458 IN HTTP_TOKEN_WRAP *Wrap\r
459 );\r
460\r
461#endif\r