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