+\r
+/**\r
+ Callback function that is invoked when the HTTP Boot driver is about to transmit or has received a\r
+ packet.\r
+\r
+ This function is invoked when the HTTP Boot driver is about to transmit or has received packet.\r
+ Parameters DataType and Received specify the type of event and the format of the buffer pointed\r
+ to by Data. Due to the polling nature of UEFI device drivers, this callback function should not\r
+ execute for more than 5 ms.\r
+ The returned status code determines the behavior of the HTTP Boot driver.\r
+\r
+ @param[in] This Pointer to the EFI_HTTP_BOOT_CALLBACK_PROTOCOL instance.\r
+ @param[in] DataType The event that occurs in the current state.\r
+ @param[in] Received TRUE if the callback is being invoked due to a receive event.\r
+ FALSE if the callback is being invoked due to a transmit event.\r
+ @param[in] DataLength The length in bytes of the buffer pointed to by Data.\r
+ @param[in] Data A pointer to the buffer of data, the data type is specified by\r
+ DataType.\r
+ \r
+ @retval EFI_SUCCESS Tells the HTTP Boot driver to continue the HTTP Boot process.\r
+ @retval EFI_ABORTED Tells the HTTP Boot driver to abort the current HTTP Boot process.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpBootCallback (\r
+ IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL *This,\r
+ IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE DataType,\r
+ IN BOOLEAN Received,\r
+ IN UINT32 DataLength,\r
+ IN VOID *Data OPTIONAL\r
+ )\r
+{\r
+ EFI_HTTP_MESSAGE *HttpMessage;\r
+ EFI_HTTP_HEADER *HttpHeader;\r
+ HTTP_BOOT_PRIVATE_DATA *Private;\r
+ UINT32 Percentage;\r
+\r
+ Private = HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_PROTOCOL(This);\r
+\r
+ switch (DataType) {\r
+ case HttpBootDhcp4:\r
+ case HttpBootDhcp6:\r
+ Print (L".");\r
+ break;\r
+\r
+ case HttpBootHttpRequest:\r
+ if (Data != NULL) {\r
+ HttpMessage = (EFI_HTTP_MESSAGE *) Data;\r
+ if (HttpMessage->Data.Request->Method == HttpMethodGet &&\r
+ HttpMessage->Data.Request->Url != NULL) {\r
+ Print (L"\n URI: %s\n", HttpMessage->Data.Request->Url);\r
+ }\r
+ }\r
+ break;\r
+\r
+ case HttpBootHttpResponse:\r
+ if (Data != NULL) {\r
+ HttpMessage = (EFI_HTTP_MESSAGE *) Data;\r
+ \r
+ if (HttpMessage->Data.Response != NULL) {\r
+ if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->StatusCode)) {\r
+ //\r
+ // Server indicates the resource has been redirected to a different URL\r
+ // according to the section 6.4 of RFC7231 and the RFC 7538.\r
+ // Display the redirect information on the screen.\r
+ //\r
+ HttpHeader = HttpFindHeader (\r
+ HttpMessage->HeaderCount,\r
+ HttpMessage->Headers,\r
+ HTTP_HEADER_LOCATION\r
+ );\r
+ if (HttpHeader != NULL) {\r
+ Print (L"\n HTTP ERROR: Resource Redirected.\n New Location: %a\n", HttpHeader->FieldValue);\r
+ }\r
+ break; \r
+ }\r
+ }\r
+ \r
+ HttpHeader = HttpFindHeader (\r
+ HttpMessage->HeaderCount,\r
+ HttpMessage->Headers,\r
+ HTTP_HEADER_CONTENT_LENGTH\r
+ );\r
+ if (HttpHeader != NULL) {\r
+ Private->FileSize = AsciiStrDecimalToUintn (HttpHeader->FieldValue);\r
+ Private->ReceivedSize = 0;\r
+ Private->Percentage = 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case HttpBootHttpEntityBody:\r
+ if (DataLength != 0) {\r
+ if (Private->FileSize != 0) {\r
+ //\r
+ // We already know the file size, print in percentage format.\r
+ //\r
+ if (Private->ReceivedSize == 0) {\r
+ Print (L" File Size: %lu Bytes\n", Private->FileSize);\r
+ }\r
+ Private->ReceivedSize += DataLength;\r
+ Percentage = (UINT32) DivU64x64Remainder (MultU64x32 (Private->ReceivedSize, 100), Private->FileSize, NULL);\r
+ if (Private->Percentage != Percentage) {\r
+ Private->Percentage = Percentage;\r
+ Print (L"\r Downloading...%d%%", Percentage);\r
+ }\r
+ } else {\r
+ //\r
+ // In some case we couldn't get the file size from the HTTP header, so we\r
+ // just print the downloaded file size.\r
+ //\r
+ Private->ReceivedSize += DataLength;\r
+ Print (L"\r Downloading...%lu Bytes", Private->ReceivedSize);\r
+ }\r
+ }\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ };\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+///\r
+/// HTTP Boot Callback Protocol instance\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED \r
+EFI_HTTP_BOOT_CALLBACK_PROTOCOL gHttpBootDxeHttpBootCallback = {\r
+ HttpBootCallback\r
+};\r