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