Ip4Config2Impl.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /** @file
  2. Definitions for EFI IPv4 Configuration II Protocol implementation.
  3. Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
  4. (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef __IP4_CONFIG2_IMPL_H__
  8. #define __IP4_CONFIG2_IMPL_H__
  9. #define IP4_CONFIG2_INSTANCE_SIGNATURE SIGNATURE_32 ('I', 'P', 'C', '2')
  10. #define IP4_FORM_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('I', 'F', 'C', 'I')
  11. #define IP4_CONFIG2_VARIABLE_ATTRIBUTE (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
  12. #define DATA_ATTRIB_SIZE_FIXED 0x1
  13. #define DATA_ATTRIB_VOLATILE 0x2
  14. #define DATA_ATTRIB_SET(Attrib, Bits) (BOOLEAN)((Attrib) & (Bits))
  15. #define SET_DATA_ATTRIB(Attrib, Bits) ((Attrib) |= (Bits))
  16. #define REMOVE_DATA_ATTRIB(Attrib, Bits) ((Attrib) &= (~Bits))
  17. typedef struct _IP4_CONFIG2_INSTANCE IP4_CONFIG2_INSTANCE;
  18. #define IP4_CONFIG2_INSTANCE_FROM_PROTOCOL(Proto) \
  19. CR ((Proto), \
  20. IP4_CONFIG2_INSTANCE, \
  21. Ip4Config2, \
  22. IP4_CONFIG2_INSTANCE_SIGNATURE \
  23. )
  24. #define IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE(Instance) \
  25. CR ((Instance), \
  26. IP4_SERVICE, \
  27. Ip4Config2Instance, \
  28. IP4_SERVICE_SIGNATURE \
  29. )
  30. #define IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Callback) \
  31. CR ((Callback), \
  32. IP4_CONFIG2_INSTANCE, \
  33. CallbackInfo, \
  34. IP4_CONFIG2_INSTANCE_SIGNATURE \
  35. )
  36. #define IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(ConfigAccess) \
  37. CR ((ConfigAccess), \
  38. IP4_FORM_CALLBACK_INFO, \
  39. HiiConfigAccessProtocol, \
  40. IP4_FORM_CALLBACK_INFO_SIGNATURE \
  41. )
  42. /**
  43. The prototype of work function for EfiIp4Config2SetData().
  44. @param[in] Instance The pointer to the IP4 config2 instance data.
  45. @param[in] DataSize In bytes, the size of the buffer pointed to by Data.
  46. @param[in] Data The data buffer to set.
  47. @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
  48. 8 bytes.
  49. @retval EFI_SUCCESS The specified configuration data for the EFI IPv4
  50. network stack was set successfully.
  51. **/
  52. typedef
  53. EFI_STATUS
  54. (*IP4_CONFIG2_SET_DATA) (
  55. IN IP4_CONFIG2_INSTANCE *Instance,
  56. IN UINTN DataSize,
  57. IN VOID *Data
  58. );
  59. /**
  60. The prototype of work function for EfiIp4Config2GetData().
  61. @param[in] Instance The pointer to the IP4 config2 instance data.
  62. @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
  63. bytes, the size of buffer required to store the specified
  64. configuration data.
  65. @param[in] Data The data buffer in which the configuration data is returned.
  66. Ignored if DataSize is ZERO.
  67. @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
  68. configuration data, and the required size is
  69. returned in DataSize.
  70. @retval EFI_SUCCESS The specified configuration data was obtained successfully.
  71. **/
  72. typedef
  73. EFI_STATUS
  74. (*IP4_CONFIG2_GET_DATA) (
  75. IN IP4_CONFIG2_INSTANCE *Instance,
  76. IN OUT UINTN *DataSize,
  77. IN VOID *Data OPTIONAL
  78. );
  79. typedef union {
  80. VOID *Ptr;
  81. EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
  82. EFI_IP4_CONFIG2_POLICY *Policy;
  83. EFI_IP4_CONFIG2_MANUAL_ADDRESS *ManualAddress;
  84. EFI_IPv4_ADDRESS *Gateway;
  85. EFI_IPv4_ADDRESS *DnsServers;
  86. } IP4_CONFIG2_DATA;
  87. typedef struct {
  88. IP4_CONFIG2_SET_DATA SetData;
  89. IP4_CONFIG2_GET_DATA GetData;
  90. EFI_STATUS Status;
  91. UINT8 Attribute;
  92. NET_MAP EventMap;
  93. IP4_CONFIG2_DATA Data;
  94. UINTN DataSize;
  95. } IP4_CONFIG2_DATA_ITEM;
  96. typedef struct {
  97. UINT16 Offset;
  98. UINT32 DataSize;
  99. EFI_IP4_CONFIG2_DATA_TYPE DataType;
  100. } IP4_CONFIG2_DATA_RECORD;
  101. #pragma pack(1)
  102. //
  103. // heap data that contains the data for each data record.
  104. //
  105. // EFI_IP4_CONFIG2_POLICY Policy;
  106. // UINT32 ManualaddressCount;
  107. // UINT32 GatewayCount;
  108. // UINT32 DnsServersCount;
  109. // EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress[];
  110. // EFI_IPv4_ADDRESS Gateway[];
  111. // EFI_IPv4_ADDRESS DnsServers[];
  112. //
  113. typedef struct {
  114. UINT16 Checksum;
  115. UINT16 DataRecordCount;
  116. IP4_CONFIG2_DATA_RECORD DataRecord[1];
  117. } IP4_CONFIG2_VARIABLE;
  118. #pragma pack()
  119. typedef struct {
  120. EFI_IP4_CONFIG2_POLICY Policy; ///< manual or automatic
  121. EFI_IP4_CONFIG2_MANUAL_ADDRESS *ManualAddress; ///< IP addresses
  122. UINT32 ManualAddressCount; ///< IP addresses count
  123. EFI_IPv4_ADDRESS *GatewayAddress; ///< Gateway address
  124. UINT32 GatewayAddressCount; ///< Gateway address count
  125. EFI_IPv4_ADDRESS *DnsAddress; ///< DNS server address
  126. UINT32 DnsAddressCount; ///< DNS server address count
  127. } IP4_CONFIG2_NVDATA;
  128. typedef struct _IP4_FORM_CALLBACK_INFO {
  129. UINT32 Signature;
  130. EFI_HANDLE ChildHandle;
  131. EFI_HII_CONFIG_ACCESS_PROTOCOL HiiConfigAccessProtocol;
  132. EFI_DEVICE_PATH_PROTOCOL *HiiVendorDevicePath;
  133. EFI_HII_HANDLE RegisteredHandle;
  134. } IP4_FORM_CALLBACK_INFO;
  135. struct _IP4_CONFIG2_INSTANCE {
  136. UINT32 Signature;
  137. BOOLEAN Configured;
  138. LIST_ENTRY Link;
  139. UINT16 IfIndex;
  140. EFI_IP4_CONFIG2_PROTOCOL Ip4Config2;
  141. EFI_IP4_CONFIG2_INTERFACE_INFO InterfaceInfo;
  142. EFI_IP4_CONFIG2_POLICY Policy;
  143. IP4_CONFIG2_DATA_ITEM DataItem[Ip4Config2DataTypeMaximum];
  144. EFI_EVENT Dhcp4SbNotifyEvent;
  145. VOID *Registration;
  146. EFI_HANDLE Dhcp4Handle;
  147. EFI_DHCP4_PROTOCOL *Dhcp4;
  148. BOOLEAN DhcpSuccess;
  149. BOOLEAN OtherInfoOnly;
  150. EFI_EVENT Dhcp4Event;
  151. UINT32 FailedIaAddressCount;
  152. EFI_IPv4_ADDRESS *DeclineAddress;
  153. UINT32 DeclineAddressCount;
  154. IP4_FORM_CALLBACK_INFO CallbackInfo;
  155. IP4_CONFIG2_NVDATA Ip4NvData;
  156. };
  157. //
  158. // Configure the DHCP to request the routers and netmask
  159. // from server. The DHCP4_TAG_NETMASK is included in Head.
  160. //
  161. #pragma pack(1)
  162. typedef struct {
  163. EFI_DHCP4_PACKET_OPTION Head;
  164. UINT8 Route;
  165. UINT8 Dns;
  166. } IP4_CONFIG2_DHCP4_OPTION;
  167. #pragma pack()
  168. /**
  169. Read the configuration data from variable storage according to the VarName and
  170. gEfiIp4Config2ProtocolGuid. It checks the integrity of variable data. If the
  171. data is corrupted, it clears the variable data to ZERO. Otherwise, it outputs the
  172. configuration data to IP4_CONFIG2_INSTANCE.
  173. @param[in] VarName The pointer to the variable name
  174. @param[in, out] Instance The pointer to the IP4 config2 instance data.
  175. @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
  176. @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
  177. @retval EFI_SUCCESS The configuration data was retrieved successfully.
  178. **/
  179. EFI_STATUS
  180. Ip4Config2ReadConfigData (
  181. IN CHAR16 *VarName,
  182. IN OUT IP4_CONFIG2_INSTANCE *Instance
  183. );
  184. /**
  185. Start the DHCP configuration for this IP service instance.
  186. It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the
  187. DHCP configuration.
  188. @param[in] Instance The IP4 config2 instance to configure.
  189. @retval EFI_SUCCESS The auto configuration is successfully started.
  190. @retval Others Failed to start auto configuration.
  191. **/
  192. EFI_STATUS
  193. Ip4StartAutoConfig (
  194. IN IP4_CONFIG2_INSTANCE *Instance
  195. );
  196. /**
  197. Initialize an IP4_CONFIG2_INSTANCE.
  198. @param[out] Instance The buffer of IP4_CONFIG2_INSTANCE to be initialized.
  199. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
  200. @retval EFI_SUCCESS The IP4_CONFIG2_INSTANCE initialized successfully.
  201. **/
  202. EFI_STATUS
  203. Ip4Config2InitInstance (
  204. OUT IP4_CONFIG2_INSTANCE *Instance
  205. );
  206. /**
  207. Release an IP4_CONFIG2_INSTANCE.
  208. @param[in, out] Instance The buffer of IP4_CONFIG2_INSTANCE to be freed.
  209. **/
  210. VOID
  211. Ip4Config2CleanInstance (
  212. IN OUT IP4_CONFIG2_INSTANCE *Instance
  213. );
  214. /**
  215. Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK.
  216. @param Event The event that is signalled.
  217. @param Context The IP4 service binding instance.
  218. **/
  219. VOID
  220. EFIAPI
  221. Ip4AutoReconfigCallBack (
  222. IN EFI_EVENT Event,
  223. IN VOID *Context
  224. );
  225. /**
  226. Destroy the Dhcp4 child in IP4_CONFIG2_INSTANCE and release the resources.
  227. @param[in, out] Instance The buffer of IP4 config2 instance to be freed.
  228. @retval EFI_SUCCESS The child was successfully destroyed.
  229. @retval Others Failed to destroy the child.
  230. **/
  231. EFI_STATUS
  232. Ip4Config2DestroyDhcp4 (
  233. IN OUT IP4_CONFIG2_INSTANCE *Instance
  234. );
  235. #endif