PxeBcDhcp6.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /** @file
  2. Functions declaration related with DHCPv6 for UefiPxeBc Driver.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_PXEBC_DHCP6_H__
  7. #define __EFI_PXEBC_DHCP6_H__
  8. #define PXEBC_DHCP6_OPTION_MAX_NUM 16
  9. #define PXEBC_DHCP6_OPTION_MAX_SIZE 312
  10. #define PXEBC_DHCP6_PACKET_MAX_SIZE (sizeof (EFI_PXE_BASE_CODE_PACKET))
  11. #define PXEBC_IP6_POLICY_MAX 0xff
  12. #define PXEBC_IP6_ROUTE_TABLE_TIMEOUT 10
  13. #define PXEBC_DHCP6_S_PORT 547
  14. #define PXEBC_DHCP6_C_PORT 546
  15. #define PXEBC_DHCP6_ENTERPRISE_NUM 343 // TODO: IANA TBD: temporarily using Intel's
  16. #define PXEBC_DHCP6_MAX_BOOT_FILE_SIZE 65535 // It's a limitation of bit length, 65535*512 bytes.
  17. #define PXEBC_DHCP6_IDX_IA_NA 0
  18. #define PXEBC_DHCP6_IDX_BOOT_FILE_URL 1
  19. #define PXEBC_DHCP6_IDX_BOOT_FILE_PARAM 2
  20. #define PXEBC_DHCP6_IDX_VENDOR_CLASS 3
  21. #define PXEBC_DHCP6_IDX_DNS_SERVER 4
  22. #define PXEBC_DHCP6_IDX_MAX 5
  23. #define PXEBC_DHCP6_BOOT_FILE_URL_PREFIX "tftp://"
  24. #define PXEBC_TFTP_URL_SEPARATOR '/'
  25. #define PXEBC_ADDR_START_DELIMITER '['
  26. #define PXEBC_ADDR_END_DELIMITER ']'
  27. #define GET_NEXT_DHCP6_OPTION(Opt) \
  28. (EFI_DHCP6_PACKET_OPTION *) ((UINT8 *) (Opt) + \
  29. sizeof (EFI_DHCP6_PACKET_OPTION) + (NTOHS ((Opt)->OpLen)) - 1)
  30. #define GET_DHCP6_OPTION_SIZE(Pkt) \
  31. ((Pkt)->Length - sizeof (EFI_DHCP6_HEADER))
  32. #define IS_PROXY_OFFER(Type) \
  33. ((Type) == PxeOfferTypeProxyBinl || \
  34. (Type) == PxeOfferTypeProxyPxe10 || \
  35. (Type) == PxeOfferTypeProxyWfm11a)
  36. #pragma pack(1)
  37. typedef struct {
  38. UINT16 OpCode[256];
  39. } PXEBC_DHCP6_OPTION_ORO;
  40. typedef struct {
  41. UINT8 Type;
  42. UINT8 MajorVer;
  43. UINT8 MinorVer;
  44. } PXEBC_DHCP6_OPTION_UNDI;
  45. typedef struct {
  46. UINT16 Type;
  47. } PXEBC_DHCP6_OPTION_ARCH;
  48. typedef struct {
  49. UINT8 ClassIdentifier[10];
  50. UINT8 ArchitecturePrefix[5];
  51. UINT8 ArchitectureType[5];
  52. UINT8 Lit3[1];
  53. UINT8 InterfaceName[4];
  54. UINT8 Lit4[1];
  55. UINT8 UndiMajor[3];
  56. UINT8 UndiMinor[3];
  57. } PXEBC_CLASS_ID;
  58. typedef struct {
  59. UINT32 Vendor;
  60. UINT16 ClassLen;
  61. PXEBC_CLASS_ID ClassId;
  62. } PXEBC_DHCP6_OPTION_VENDOR_CLASS;
  63. #pragma pack()
  64. typedef union {
  65. PXEBC_DHCP6_OPTION_ORO *Oro;
  66. PXEBC_DHCP6_OPTION_UNDI *Undi;
  67. PXEBC_DHCP6_OPTION_ARCH *Arch;
  68. PXEBC_DHCP6_OPTION_VENDOR_CLASS *VendorClass;
  69. } PXEBC_DHCP6_OPTION_ENTRY;
  70. typedef struct {
  71. LIST_ENTRY Link;
  72. EFI_DHCP6_PACKET_OPTION *Option;
  73. UINT8 Precedence;
  74. } PXEBC_DHCP6_OPTION_NODE;
  75. #define PXEBC_CACHED_DHCP6_PACKET_MAX_SIZE (OFFSET_OF (EFI_DHCP6_PACKET, Dhcp6) + PXEBC_DHCP6_PACKET_MAX_SIZE)
  76. typedef union {
  77. EFI_DHCP6_PACKET Offer;
  78. EFI_DHCP6_PACKET Ack;
  79. UINT8 Buffer[PXEBC_CACHED_DHCP6_PACKET_MAX_SIZE];
  80. } PXEBC_DHCP6_PACKET;
  81. typedef struct {
  82. PXEBC_DHCP6_PACKET Packet;
  83. PXEBC_OFFER_TYPE OfferType;
  84. EFI_DHCP6_PACKET_OPTION *OptList[PXEBC_DHCP6_IDX_MAX];
  85. } PXEBC_DHCP6_PACKET_CACHE;
  86. /**
  87. Parse the Boot File URL option.
  88. @param[in] Private Pointer to PxeBc private data.
  89. @param[out] FileName The pointer to the boot file name.
  90. @param[in, out] SrvAddr The pointer to the boot server address.
  91. @param[in] BootFile The pointer to the boot file URL option data.
  92. @param[in] Length Length of the boot file URL option data.
  93. @retval EFI_ABORTED User canceled the operation.
  94. @retval EFI_SUCCESS Selected the boot menu successfully.
  95. @retval EFI_NOT_READY Read the input key from the keyboard has not finish.
  96. **/
  97. EFI_STATUS
  98. PxeBcExtractBootFileUrl (
  99. IN PXEBC_PRIVATE_DATA *Private,
  100. OUT UINT8 **FileName,
  101. IN OUT EFI_IPv6_ADDRESS *SrvAddr,
  102. IN CHAR8 *BootFile,
  103. IN UINT16 Length
  104. );
  105. /**
  106. Parse the Boot File Parameter option.
  107. @param[in] BootFilePara The pointer to the boot file parameter option data.
  108. @param[out] BootFileSize The pointer to the parsed boot file size.
  109. @retval EFI_SUCCESS Successfully obtained the boot file size from parameter option.
  110. @retval EFI_NOT_FOUND Failed to extract the boot file size from parameter option.
  111. **/
  112. EFI_STATUS
  113. PxeBcExtractBootFileParam (
  114. IN CHAR8 *BootFilePara,
  115. OUT UINT16 *BootFileSize
  116. );
  117. /**
  118. Parse the cached DHCPv6 packet, including all the options.
  119. @param[in] Cache6 The pointer to a cached DHCPv6 packet.
  120. @retval EFI_SUCCESS Parsed the DHCPv6 packet successfully.
  121. @retval EFI_DEVICE_ERROR Failed to parse and invalid packet.
  122. **/
  123. EFI_STATUS
  124. PxeBcParseDhcp6Packet (
  125. IN PXEBC_DHCP6_PACKET_CACHE *Cache6
  126. );
  127. /**
  128. Register the ready address by Ip6Config protocol.
  129. @param[in] Private The pointer to the PxeBc private data.
  130. @param[in] Address The pointer to the ready address.
  131. @retval EFI_SUCCESS Registered the address successfully.
  132. @retval Others Failed to register the address.
  133. **/
  134. EFI_STATUS
  135. PxeBcRegisterIp6Address (
  136. IN PXEBC_PRIVATE_DATA *Private,
  137. IN EFI_IPv6_ADDRESS *Address
  138. );
  139. /**
  140. Unregister the address by Ip6Config protocol.
  141. @param[in] Private The pointer to the PxeBc private data.
  142. **/
  143. VOID
  144. PxeBcUnregisterIp6Address (
  145. IN PXEBC_PRIVATE_DATA *Private
  146. );
  147. /**
  148. Build and send out the request packet for the bootfile, and parse the reply.
  149. @param[in] Private The pointer to the PxeBc private data.
  150. @param[in] Type PxeBc option boot item type.
  151. @param[in] Layer The pointer to the option boot item layer.
  152. @param[in] UseBis Use BIS or not.
  153. @param[in] DestIp The pointer to the server address.
  154. @retval EFI_SUCCESS Successfully discovered theboot file.
  155. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
  156. @retval EFI_NOT_FOUND Can't get the PXE reply packet.
  157. @retval Others Failed to discover boot file.
  158. **/
  159. EFI_STATUS
  160. PxeBcDhcp6Discover (
  161. IN PXEBC_PRIVATE_DATA *Private,
  162. IN UINT16 Type,
  163. IN UINT16 *Layer,
  164. IN BOOLEAN UseBis,
  165. IN EFI_IP_ADDRESS *DestIp
  166. );
  167. /**
  168. Set the IP6 policy to Automatic.
  169. @param[in] Private The pointer to PXEBC_PRIVATE_DATA.
  170. @retval EFI_SUCCESS Switch the IP policy successfully.
  171. @retval Others Unexpected error happened.
  172. **/
  173. EFI_STATUS
  174. PxeBcSetIp6Policy (
  175. IN PXEBC_PRIVATE_DATA *Private
  176. );
  177. /**
  178. This function will register the station IP address and flush IP instance to start using the new IP address.
  179. @param[in] Private The pointer to PXEBC_PRIVATE_DATA.
  180. @retval EFI_SUCCESS The new IP address has been configured successfully.
  181. @retval Others Failed to configure the address.
  182. **/
  183. EFI_STATUS
  184. PxeBcSetIp6Address (
  185. IN PXEBC_PRIVATE_DATA *Private
  186. );
  187. /**
  188. Start the DHCPv6 S.A.R.R. process to acquire the IPv6 address and other PXE boot information.
  189. @param[in] Private The pointer to the PxeBc private data.
  190. @param[in] Dhcp6 The pointer to EFI_DHCP6_PROTOCOL.
  191. @retval EFI_SUCCESS The S.A.R.R. process successfully finished.
  192. @retval Others Failed to finish the S.A.R.R. process.
  193. **/
  194. EFI_STATUS
  195. PxeBcDhcp6Sarr (
  196. IN PXEBC_PRIVATE_DATA *Private,
  197. IN EFI_DHCP6_PROTOCOL *Dhcp6
  198. );
  199. #endif