HttpBootClient.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /** @file
  2. Declaration of the boot file download function.
  3. Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
  4. (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef __EFI_HTTP_BOOT_HTTP_H__
  8. #define __EFI_HTTP_BOOT_HTTP_H__
  9. #define HTTP_BOOT_REQUEST_TIMEOUT 5000 // 5 seconds in uints of millisecond.
  10. #define HTTP_BOOT_RESPONSE_TIMEOUT 5000 // 5 seconds in uints of millisecond.
  11. #define HTTP_BOOT_BLOCK_SIZE 1500
  12. #define HTTP_USER_AGENT_EFI_HTTP_BOOT "UefiHttpBoot/1.0"
  13. //
  14. // Record the data length and start address of a data block.
  15. //
  16. typedef struct {
  17. LIST_ENTRY Link; // Link to the EntityDataList in HTTP_BOOT_CACHE_CONTENT
  18. UINT8 *Block; // If NULL, the data is in previous data block.
  19. UINT8 *DataStart; // Point to somewhere in the Block
  20. UINTN DataLength;
  21. } HTTP_BOOT_ENTITY_DATA;
  22. //
  23. // Structure for a cache item
  24. //
  25. typedef struct {
  26. LIST_ENTRY Link; // Link to the CacheList in driver's private data.
  27. EFI_HTTP_REQUEST_DATA *RequestData;
  28. HTTP_IO_RESPONSE_DATA *ResponseData; // Not include any message-body data.
  29. HTTP_BOOT_IMAGE_TYPE ImageType;
  30. UINTN EntityLength;
  31. LIST_ENTRY EntityDataList; // Entity data (message-body)
  32. } HTTP_BOOT_CACHE_CONTENT;
  33. //
  34. // Callback data for HTTP_BODY_PARSER_CALLBACK()
  35. //
  36. typedef struct {
  37. EFI_STATUS Status;
  38. //
  39. // Cache info.
  40. //
  41. HTTP_BOOT_CACHE_CONTENT *Cache;
  42. BOOLEAN NewBlock;
  43. UINT8 *Block;
  44. //
  45. // Caller provided buffer to load the file in.
  46. //
  47. UINTN CopyedSize;
  48. UINTN BufferSize;
  49. UINT8 *Buffer;
  50. HTTP_BOOT_PRIVATE_DATA *Private;
  51. } HTTP_BOOT_CALLBACK_DATA;
  52. /**
  53. Discover all the boot information for boot file.
  54. @param[in, out] Private The pointer to the driver's private data.
  55. @retval EFI_SUCCESS Successfully obtained all the boot information .
  56. @retval Others Failed to retrieve the boot information.
  57. **/
  58. EFI_STATUS
  59. HttpBootDiscoverBootInfo (
  60. IN OUT HTTP_BOOT_PRIVATE_DATA *Private
  61. );
  62. /**
  63. Create a HttpIo instance for the file download.
  64. @param[in] Private The pointer to the driver's private data.
  65. @retval EFI_SUCCESS Successfully created.
  66. @retval Others Failed to create HttpIo.
  67. **/
  68. EFI_STATUS
  69. HttpBootCreateHttpIo (
  70. IN HTTP_BOOT_PRIVATE_DATA *Private
  71. );
  72. /**
  73. This function download the boot file by using UEFI HTTP protocol.
  74. @param[in] Private The pointer to the driver's private data.
  75. @param[in] HeaderOnly Only request the response header, it could save a lot of time if
  76. the caller only want to know the size of the requested file.
  77. @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return
  78. code of EFI_SUCCESS, the amount of data transferred to
  79. Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
  80. the size of Buffer required to retrieve the requested file.
  81. @param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
  82. then the size of the requested file is returned in
  83. BufferSize.
  84. @param[out] ImageType The image type of the downloaded file.
  85. @retval EFI_SUCCESS The file was loaded.
  86. @retval EFI_INVALID_PARAMETER BufferSize is NULL or Buffer Size is not NULL but Buffer is NULL.
  87. @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
  88. @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
  89. BufferSize has been updated with the size needed to complete
  90. the request.
  91. @retval Others Unexpected error happened.
  92. **/
  93. EFI_STATUS
  94. HttpBootGetBootFile (
  95. IN HTTP_BOOT_PRIVATE_DATA *Private,
  96. IN BOOLEAN HeaderOnly,
  97. IN OUT UINTN *BufferSize,
  98. OUT UINT8 *Buffer,
  99. OUT HTTP_BOOT_IMAGE_TYPE *ImageType
  100. );
  101. /**
  102. Clean up all cached data.
  103. @param[in] Private The pointer to the driver's private data.
  104. **/
  105. VOID
  106. HttpBootFreeCacheList (
  107. IN HTTP_BOOT_PRIVATE_DATA *Private
  108. );
  109. #endif