1 /** @file 2 3 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 **/ 13 14 15 #include "Dhcp4Impl.h" 16 17 // 18 // EFI Component Name Functions 19 // 20 /** 21 Retrieves a Unicode string that is the user readable name of the driver. 22 23 This function retrieves the user readable name of a driver in the form of a 24 Unicode string. If the driver specified by This has a user readable name in 25 the language specified by Language, then a pointer to the driver name is 26 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 27 by This does not support the language specified by Language, 28 then EFI_UNSUPPORTED is returned. 29 30 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 31 EFI_COMPONENT_NAME_PROTOCOL instance. 32 33 @param[in] Language A pointer to a Null-terminated ASCII string 34 array indicating the language. This is the 35 language of the driver name that the caller is 36 requesting, and it must match one of the 37 languages specified in SupportedLanguages. The 38 number of languages supported by a driver is up 39 to the driver writer. Language is specified 40 in RFC 4646 or ISO 639-2 language code format. 41 42 @param[out] DriverName A pointer to the Unicode string to return. 43 This Unicode string is the name of the 44 driver specified by This in the language 45 specified by Language. 46 47 @retval EFI_SUCCESS The Unicode string for the Driver specified by 48 This and the language specified by Language was 49 returned in DriverName. 50 51 @retval EFI_INVALID_PARAMETER Language is NULL. 52 53 @retval EFI_INVALID_PARAMETER DriverName is NULL. 54 55 @retval EFI_UNSUPPORTED The driver specified by This does not support 56 the language specified by Language. 57 58 **/ 59 EFI_STATUS 60 EFIAPI 61 DhcpComponentNameGetDriverName ( 62 IN EFI_COMPONENT_NAME_PROTOCOL *This, 63 IN CHAR8 *Language, 64 OUT CHAR16 **DriverName 65 ); 66 67 68 /** 69 Retrieves a Unicode string that is the user readable name of the controller 70 that is being managed by a driver. 71 72 This function retrieves the user readable name of the controller specified by 73 ControllerHandle and ChildHandle in the form of a Unicode string. If the 74 driver specified by This has a user readable name in the language specified by 75 Language, then a pointer to the controller name is returned in ControllerName, 76 and EFI_SUCCESS is returned. If the driver specified by This is not currently 77 managing the controller specified by ControllerHandle and ChildHandle, 78 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 79 support the language specified by Language, then EFI_UNSUPPORTED is returned. 80 81 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 82 EFI_COMPONENT_NAME_PROTOCOL instance. 83 84 @param[in] ControllerHandle The handle of a controller that the driver 85 specified by This is managing. This handle 86 specifies the controller whose name is to be 87 returned. 88 89 @param[in] ChildHandle The handle of the child controller to retrieve 90 the name of. This is an optional parameter that 91 may be NULL. It will be NULL for device 92 drivers. It will also be NULL for a bus drivers 93 that wish to retrieve the name of the bus 94 controller. It will not be NULL for a bus 95 driver that wishes to retrieve the name of a 96 child controller. 97 98 @param[in] Language A pointer to a Null-terminated ASCII string 99 array indicating the language. This is the 100 language of the driver name that the caller is 101 requesting, and it must match one of the 102 languages specified in SupportedLanguages. The 103 number of languages supported by a driver is up 104 to the driver writer. Language is specified in 105 RFC 4646 or ISO 639-2 language code format. 106 107 @param[out] ControllerName A pointer to the Unicode string to return. 108 This Unicode string is the name of the 109 controller specified by ControllerHandle and 110 ChildHandle in the language specified by 111 Language from the point of view of the driver 112 specified by This. 113 114 @retval EFI_SUCCESS The Unicode string for the user readable name in 115 the language specified by Language for the 116 driver specified by This was returned in 117 DriverName. 118 119 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 120 121 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 122 EFI_HANDLE. 123 124 @retval EFI_INVALID_PARAMETER Language is NULL. 125 126 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 127 128 @retval EFI_UNSUPPORTED The driver specified by This is not currently 129 managing the controller specified by 130 ControllerHandle and ChildHandle. 131 132 @retval EFI_UNSUPPORTED The driver specified by This does not support 133 the language specified by Language. 134 135 **/ 136 EFI_STATUS 137 EFIAPI 138 DhcpComponentNameGetControllerName ( 139 IN EFI_COMPONENT_NAME_PROTOCOL *This, 140 IN EFI_HANDLE ControllerHandle, 141 IN EFI_HANDLE ChildHandle OPTIONAL, 142 IN CHAR8 *Language, 143 OUT CHAR16 **ControllerName 144 ); 145 146 147 // 148 // EFI Component Name Protocol 149 // 150 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDhcp4ComponentName = { 151 DhcpComponentNameGetDriverName, 152 DhcpComponentNameGetControllerName, 153 "eng" 154 }; 155 156 // 157 // EFI Component Name 2 Protocol 158 // 159 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDhcp4ComponentName2 = { 160 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) DhcpComponentNameGetDriverName, 161 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) DhcpComponentNameGetControllerName, 162 "en" 163 }; 164 165 166 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDhcpDriverNameTable[] = { 167 { 168 "eng;en", 169 L"DHCP Protocol Driver" 170 }, 171 { 172 NULL, 173 NULL 174 } 175 }; 176 177 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDhcpControllerNameTable = NULL; 178 179 CHAR16 *mDhcp4ControllerName[] = { 180 L"DHCPv4 (State=0, Stopped)", 181 L"DHCPv4 (State=1, Init)", 182 L"DHCPv4 (State=2, Selecting)", 183 L"DHCPv4 (State=3, Requesting)", 184 L"DHCPv4 (State=4, Bound)", 185 L"DHCPv4 (State=5, Renewing)", 186 L"DHCPv4 (State=6, Rebinding)", 187 L"DHCPv4 (State=7, InitReboot)", 188 L"DHCPv4 (State=8, Rebooting)" 189 }; 190 191 /** 192 Retrieves a Unicode string that is the user readable name of the driver. 193 194 This function retrieves the user readable name of a driver in the form of a 195 Unicode string. If the driver specified by This has a user readable name in 196 the language specified by Language, then a pointer to the driver name is 197 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 198 by This does not support the language specified by Language, 199 then EFI_UNSUPPORTED is returned. 200 201 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 202 EFI_COMPONENT_NAME_PROTOCOL instance. 203 204 @param[in] Language A pointer to a Null-terminated ASCII string 205 array indicating the language. This is the 206 language of the driver name that the caller is 207 requesting, and it must match one of the 208 languages specified in SupportedLanguages. The 209 number of languages supported by a driver is up 210 to the driver writer. Language is specified 211 in RFC 4646 or ISO 639-2 language code format. 212 213 @param[out] DriverName A pointer to the Unicode string to return. 214 This Unicode string is the name of the 215 driver specified by This in the language 216 specified by Language. 217 218 @retval EFI_SUCCESS The Unicode string for the Driver specified by 219 This and the language specified by Language was 220 returned in DriverName. 221 222 @retval EFI_INVALID_PARAMETER Language is NULL. 223 224 @retval EFI_INVALID_PARAMETER DriverName is NULL. 225 226 @retval EFI_UNSUPPORTED The driver specified by This does not support 227 the language specified by Language. 228 229 **/ 230 EFI_STATUS 231 EFIAPI 232 DhcpComponentNameGetDriverName ( 233 IN EFI_COMPONENT_NAME_PROTOCOL *This, 234 IN CHAR8 *Language, 235 OUT CHAR16 **DriverName 236 ) 237 { 238 return LookupUnicodeString2 ( 239 Language, 240 This->SupportedLanguages, 241 mDhcpDriverNameTable, 242 DriverName, 243 (BOOLEAN)(This == &gDhcp4ComponentName) 244 ); 245 } 246 247 /** 248 Update the component name for the Dhcp4 child handle. 249 250 @param Dhcp4[in] A pointer to the EFI_DHCP4_PROTOCOL. 251 252 253 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully. 254 @retval EFI_INVALID_PARAMETER The input parameter is invalid. 255 @retval EFI_DEVICE_ERROR DHCP is in unknown state. 256 257 **/ 258 EFI_STATUS 259 UpdateName ( 260 IN EFI_DHCP4_PROTOCOL *Dhcp4 261 ) 262 { 263 EFI_STATUS Status; 264 EFI_DHCP4_MODE_DATA Dhcp4ModeData; 265 266 if (Dhcp4 == NULL) { 267 return EFI_INVALID_PARAMETER; 268 } 269 270 // 271 // Format the child name into the string buffer. 272 // 273 Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4ModeData); 274 if (EFI_ERROR (Status)) { 275 return Status; 276 } 277 278 if (gDhcpControllerNameTable != NULL) { 279 FreeUnicodeStringTable (gDhcpControllerNameTable); 280 gDhcpControllerNameTable = NULL; 281 } 282 283 if (Dhcp4ModeData.State > Dhcp4Rebooting) { 284 return EFI_DEVICE_ERROR; 285 } 286 287 Status = AddUnicodeString2 ( 288 "eng", 289 gDhcp4ComponentName.SupportedLanguages, 290 &gDhcpControllerNameTable, 291 mDhcp4ControllerName[Dhcp4ModeData.State], 292 TRUE 293 ); 294 if (EFI_ERROR (Status)) { 295 return Status; 296 } 297 298 return AddUnicodeString2 ( 299 "en", 300 gDhcp4ComponentName2.SupportedLanguages, 301 &gDhcpControllerNameTable, 302 mDhcp4ControllerName[Dhcp4ModeData.State], 303 FALSE 304 ); 305 } 306 307 /** 308 Retrieves a Unicode string that is the user readable name of the controller 309 that is being managed by a driver. 310 311 This function retrieves the user readable name of the controller specified by 312 ControllerHandle and ChildHandle in the form of a Unicode string. If the 313 driver specified by This has a user readable name in the language specified by 314 Language, then a pointer to the controller name is returned in ControllerName, 315 and EFI_SUCCESS is returned. If the driver specified by This is not currently 316 managing the controller specified by ControllerHandle and ChildHandle, 317 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 318 support the language specified by Language, then EFI_UNSUPPORTED is returned. 319 320 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 321 EFI_COMPONENT_NAME_PROTOCOL instance. 322 323 @param[in] ControllerHandle The handle of a controller that the driver 324 specified by This is managing. This handle 325 specifies the controller whose name is to be 326 returned. 327 328 @param[in] ChildHandle The handle of the child controller to retrieve 329 the name of. This is an optional parameter that 330 may be NULL. It will be NULL for device 331 drivers. It will also be NULL for a bus drivers 332 that wish to retrieve the name of the bus 333 controller. It will not be NULL for a bus 334 driver that wishes to retrieve the name of a 335 child controller. 336 337 @param[in] Language A pointer to a Null-terminated ASCII string 338 array indicating the language. This is the 339 language of the driver name that the caller is 340 requesting, and it must match one of the 341 languages specified in SupportedLanguages. The 342 number of languages supported by a driver is up 343 to the driver writer. Language is specified in 344 RFC 4646 or ISO 639-2 language code format. 345 346 @param[out] ControllerName A pointer to the Unicode string to return. 347 This Unicode string is the name of the 348 controller specified by ControllerHandle and 349 ChildHandle in the language specified by 350 Language from the point of view of the driver 351 specified by This. 352 353 @retval EFI_SUCCESS The Unicode string for the user readable name in 354 the language specified by Language for the 355 driver specified by This was returned in 356 DriverName. 357 358 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 359 360 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 361 EFI_HANDLE. 362 363 @retval EFI_INVALID_PARAMETER Language is NULL. 364 365 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 366 367 @retval EFI_UNSUPPORTED The driver specified by This is not currently 368 managing the controller specified by 369 ControllerHandle and ChildHandle. 370 371 @retval EFI_UNSUPPORTED The driver specified by This does not support 372 the language specified by Language. 373 374 **/ 375 EFI_STATUS 376 EFIAPI 377 DhcpComponentNameGetControllerName ( 378 IN EFI_COMPONENT_NAME_PROTOCOL *This, 379 IN EFI_HANDLE ControllerHandle, 380 IN EFI_HANDLE ChildHandle OPTIONAL, 381 IN CHAR8 *Language, 382 OUT CHAR16 **ControllerName 383 ) 384 { 385 EFI_STATUS Status; 386 EFI_DHCP4_PROTOCOL *Dhcp4; 387 388 // 389 // Only provide names for child handles. 390 // 391 if (ChildHandle == NULL) { 392 return EFI_UNSUPPORTED; 393 } 394 395 // 396 // Make sure this driver produced ChildHandle 397 // 398 Status = EfiTestChildHandle ( 399 ControllerHandle, 400 ChildHandle, 401 &gEfiUdp4ProtocolGuid 402 ); 403 if (EFI_ERROR (Status)) { 404 return Status; 405 } 406 407 // 408 // Retrieve an instance of a produced protocol from ChildHandle 409 // 410 Status = gBS->OpenProtocol ( 411 ChildHandle, 412 &gEfiDhcp4ProtocolGuid, 413 (VOID **)&Dhcp4, 414 NULL, 415 NULL, 416 EFI_OPEN_PROTOCOL_GET_PROTOCOL 417 ); 418 if (EFI_ERROR (Status)) { 419 return Status; 420 } 421 422 // 423 // Update the component name for this child handle. 424 // 425 Status = UpdateName (Dhcp4); 426 if (EFI_ERROR (Status)) { 427 return Status; 428 } 429 430 return LookupUnicodeString2 ( 431 Language, 432 This->SupportedLanguages, 433 gDhcpControllerNameTable, 434 ControllerName, 435 (BOOLEAN)(This == &gDhcp4ComponentName) 436 ); 437 } 438