1 /** @file 2 Implementation of EFI_COMPONENT_NAME_PROTOCOL and 3 EFI_COMPONENT_NAME2_PROTOCOL protocol. 4 5 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<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 #include "Ip6Impl.h" 18 19 // 20 // EFI Component Name Functions 21 // 22 23 /** 24 Retrieves a Unicode string that is the user-readable name of the driver. 25 26 This function retrieves the user-readable name of a driver in the form of a 27 Unicode string. If the driver specified by This has a user-readable name in 28 the language specified by Language, then a pointer to the driver name is 29 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 30 by This does not support the language specified by Language, 31 then EFI_UNSUPPORTED is returned. 32 33 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 34 EFI_COMPONENT_NAME_PROTOCOL instance. 35 36 @param[in] Language A pointer to a Null-terminated ASCII string 37 array indicating the language. This is the 38 language of the driver name that the caller is 39 requesting, and it must match one of the 40 languages specified in SupportedLanguages. The 41 number of languages supported by a driver is up 42 to the driver writer. Language is specified 43 in RFC 4646 or ISO 639-2 language code format. 44 45 @param[out] DriverName A pointer to the Unicode string to return. 46 This Unicode string is the name of the 47 driver specified by This in the language 48 specified by Language. 49 50 @retval EFI_SUCCESS The Unicode string for the Driver specified by 51 This and the language specified by Language was 52 returned in DriverName. 53 54 @retval EFI_INVALID_PARAMETER Language is NULL. 55 56 @retval EFI_INVALID_PARAMETER DriverName is NULL. 57 58 @retval EFI_UNSUPPORTED The driver specified by This does not support 59 the language specified by Language. 60 61 **/ 62 EFI_STATUS 63 EFIAPI 64 Ip6ComponentNameGetDriverName ( 65 IN EFI_COMPONENT_NAME_PROTOCOL *This, 66 IN CHAR8 *Language, 67 OUT CHAR16 **DriverName 68 ); 69 70 /** 71 Retrieves a Unicode string that is the user-readable name of the controller 72 that is managed by a driver. 73 74 This function retrieves the user-readable name of the controller specified by 75 ControllerHandle and ChildHandle in the form of a Unicode string. If the 76 driver specified by This has a user-readable name in the language specified by 77 Language, then a pointer to the controller name is returned in ControllerName, 78 and EFI_SUCCESS is returned. If the driver specified by This is not currently 79 managing the controller specified by ControllerHandle and ChildHandle, 80 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 81 support the language specified by Language, then EFI_UNSUPPORTED is returned. 82 83 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 84 EFI_COMPONENT_NAME_PROTOCOL instance. 85 86 @param[in] ControllerHandle The handle of a controller that the driver 87 specified by This is managing. This handle 88 specifies the controller whose name is to be 89 returned. 90 91 @param[in] ChildHandle The handle of the child controller to retrieve 92 the name of. This is an optional parameter that 93 may be NULL. It will be NULL for device 94 drivers. It will also be NULL for a bus drivers 95 that wish to retrieve the name of the bus 96 controller. It will not be NULL for a bus 97 driver that wishes to retrieve the name of a 98 child controller. 99 100 @param[in] Language A pointer to a Null-terminated ASCII string 101 array indicating the language. This is the 102 language of the driver name that the caller is 103 requesting, and it must match one of the 104 languages specified in SupportedLanguages. The 105 number of languages supported by a driver is up 106 to the driver writer. Language is specified in 107 RFC 4646 or ISO 639-2 language code format. 108 109 @param[out] ControllerName A pointer to the Unicode string to return. 110 This Unicode string is the name of the 111 controller specified by ControllerHandle and 112 ChildHandle in the language specified by 113 Language from the point of view of the driver 114 specified by This. 115 116 @retval EFI_SUCCESS The Unicode string for the user-readable name in 117 the language specified by Language for the 118 driver specified by This was returned in 119 DriverName. 120 121 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 122 123 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid 124 EFI_HANDLE. 125 126 @retval EFI_INVALID_PARAMETER Language is NULL. 127 128 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 129 130 @retval EFI_UNSUPPORTED The driver specified by This is not currently 131 managing the controller specified by 132 ControllerHandle and ChildHandle. 133 134 @retval EFI_UNSUPPORTED The driver specified by This does not support 135 the language specified by Language. 136 137 **/ 138 EFI_STATUS 139 EFIAPI 140 Ip6ComponentNameGetControllerName ( 141 IN EFI_COMPONENT_NAME_PROTOCOL *This, 142 IN EFI_HANDLE ControllerHandle, 143 IN EFI_HANDLE ChildHandle OPTIONAL, 144 IN CHAR8 *Language, 145 OUT CHAR16 **ControllerName 146 ); 147 148 // 149 // EFI Component Name Protocol. 150 // 151 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIp6ComponentName = { 152 Ip6ComponentNameGetDriverName, 153 Ip6ComponentNameGetControllerName, 154 "eng" 155 }; 156 157 // 158 // EFI Component Name 2 Protocol. 159 // 160 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIp6ComponentName2 = { 161 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Ip6ComponentNameGetDriverName, 162 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Ip6ComponentNameGetControllerName, 163 "en" 164 }; 165 166 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIp6DriverNameTable[] = { 167 { 168 "eng;en", 169 L"IP6 Network Service Driver" 170 }, 171 { 172 NULL, 173 NULL 174 } 175 }; 176 177 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIp6ControllerNameTable = NULL; 178 179 /** 180 Retrieves a Unicode string that is the user-readable name of the driver. 181 182 This function retrieves the user-readable name of a driver in the form of a 183 Unicode string. If the driver specified by This has a user-readable name in 184 the language specified by Language, then a pointer to the driver name is 185 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 186 by This does not support the language specified by Language, 187 then EFI_UNSUPPORTED is returned. 188 189 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 190 EFI_COMPONENT_NAME_PROTOCOL instance. 191 192 @param[in] Language A pointer to a Null-terminated ASCII string 193 array indicating the language. This is the 194 language of the driver name that the caller is 195 requesting, and it must match one of the 196 languages specified in SupportedLanguages. The 197 number of languages supported by a driver is up 198 to the driver writer. Language is specified 199 in RFC 4646 or ISO 639-2 language code format. 200 201 @param[out] DriverName A pointer to the Unicode string to return. 202 This Unicode string is the name of the 203 driver specified by This in the language 204 specified by Language. 205 206 @retval EFI_SUCCESS The Unicode string for the Driver specified by 207 This and the language specified by Language was 208 returned in DriverName. 209 210 @retval EFI_INVALID_PARAMETER Language is NULL. 211 212 @retval EFI_INVALID_PARAMETER DriverName is NULL. 213 214 @retval EFI_UNSUPPORTED The driver specified by This does not support 215 the language specified by Language. 216 217 **/ 218 EFI_STATUS 219 EFIAPI 220 Ip6ComponentNameGetDriverName ( 221 IN EFI_COMPONENT_NAME_PROTOCOL *This, 222 IN CHAR8 *Language, 223 OUT CHAR16 **DriverName 224 ) 225 { 226 return LookupUnicodeString2 ( 227 Language, 228 This->SupportedLanguages, 229 mIp6DriverNameTable, 230 DriverName, 231 (BOOLEAN) (This == &gIp6ComponentName) 232 ); 233 234 } 235 236 /** 237 Update the component name for the IP6 child handle. 238 239 @param Ip6[in] A pointer to the EFI_IP6_PROTOCOL. 240 241 242 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully. 243 @retval EFI_INVALID_PARAMETER The input parameter is invalid. 244 245 **/ 246 EFI_STATUS 247 UpdateName ( 248 IN EFI_IP6_PROTOCOL *Ip6 249 ) 250 { 251 EFI_STATUS Status; 252 CHAR16 HandleName[128]; 253 EFI_IP6_MODE_DATA Ip6ModeData; 254 UINTN Offset; 255 CHAR16 Address[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; 256 257 if (Ip6 == NULL) { 258 return EFI_INVALID_PARAMETER; 259 } 260 261 // 262 // Format the child name into the string buffer. 263 // 264 Offset = 0; 265 Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL); 266 if (!EFI_ERROR (Status)) { 267 if (Ip6ModeData.AddressList != NULL) { 268 FreePool (Ip6ModeData.AddressList); 269 } 270 271 if (Ip6ModeData.GroupTable != NULL) { 272 FreePool (Ip6ModeData.GroupTable); 273 } 274 275 if (Ip6ModeData.RouteTable != NULL) { 276 FreePool (Ip6ModeData.RouteTable); 277 } 278 279 if (Ip6ModeData.NeighborCache != NULL) { 280 FreePool (Ip6ModeData.NeighborCache); 281 } 282 283 if (Ip6ModeData.PrefixTable != NULL) { 284 FreePool (Ip6ModeData.PrefixTable); 285 } 286 287 if (Ip6ModeData.IcmpTypeList != NULL) { 288 FreePool (Ip6ModeData.IcmpTypeList); 289 } 290 } 291 292 if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) { 293 Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof(Address)); 294 if (EFI_ERROR (Status)) { 295 return Status; 296 } 297 Offset += UnicodeSPrint ( 298 HandleName, 299 sizeof(HandleName), 300 L"IPv6(StationAddress=%s, ", 301 Address 302 ); 303 Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.DestinationAddress, Address, sizeof(Address)); 304 if (EFI_ERROR (Status)) { 305 return Status; 306 } 307 UnicodeSPrint ( 308 HandleName + Offset, 309 sizeof(HandleName) - Offset * sizeof (CHAR16), 310 L"DestinationAddress=%s)", 311 Address 312 ); 313 } else if (!Ip6ModeData.IsStarted) { 314 UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(Not started)"); 315 } else { 316 UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(%r)", Status); 317 } 318 319 if (gIp6ControllerNameTable != NULL) { 320 FreeUnicodeStringTable (gIp6ControllerNameTable); 321 gIp6ControllerNameTable = NULL; 322 } 323 324 Status = AddUnicodeString2 ( 325 "eng", 326 gIp6ComponentName.SupportedLanguages, 327 &gIp6ControllerNameTable, 328 HandleName, 329 TRUE 330 ); 331 if (EFI_ERROR (Status)) { 332 return Status; 333 } 334 335 return AddUnicodeString2 ( 336 "en", 337 gIp6ComponentName2.SupportedLanguages, 338 &gIp6ControllerNameTable, 339 HandleName, 340 FALSE 341 ); 342 } 343 344 /** 345 Retrieves a Unicode string that is the user-readable name of the controller 346 that is being managed by a driver. 347 348 This function retrieves the user-readable name of the controller specified by 349 ControllerHandle and ChildHandle in the form of a Unicode string. If the 350 driver specified by This has a user-readable name in the language specified by 351 Language, then a pointer to the controller name is returned in ControllerName, 352 and EFI_SUCCESS is returned. If the driver specified by This is not currently 353 managing the controller specified by ControllerHandle and ChildHandle, 354 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 355 support the language specified by Language, then EFI_UNSUPPORTED is returned. 356 357 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 358 EFI_COMPONENT_NAME_PROTOCOL instance. 359 360 @param[in] ControllerHandle The handle of a controller that the driver 361 specified by This is managing. This handle 362 specifies the controller whose name is to be 363 returned. 364 365 @param[in] ChildHandle The handle of the child controller to retrieve 366 the name of. This is an optional parameter that 367 may be NULL. It will be NULL for device 368 drivers. It will also be NULL for a bus drivers 369 that wish to retrieve the name of the bus 370 controller. It will not be NULL for a bus 371 driver that wishes to retrieve the name of a 372 child controller. 373 374 @param[in] Language A pointer to a Null-terminated ASCII string 375 array indicating the language. This is the 376 language of the driver name that the caller is 377 requesting, and it must match one of the 378 languages specified in SupportedLanguages. The 379 number of languages supported by a driver is up 380 to the driver writer. Language is specified in 381 RFC 4646 or ISO 639-2 language code format. 382 383 @param[out] ControllerName A pointer to the Unicode string to return. 384 This Unicode string is the name of the 385 controller specified by ControllerHandle and 386 ChildHandle in the language specified by 387 Language from the point of view of the driver 388 specified by This. 389 390 @retval EFI_SUCCESS The Unicode string for the user-readable name in 391 the language specified by Language for the 392 driver specified by This was returned in 393 DriverName. 394 395 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 396 397 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid 398 EFI_HANDLE. 399 400 @retval EFI_INVALID_PARAMETER Language is NULL. 401 402 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 403 404 @retval EFI_UNSUPPORTED The driver specified by This is not currently 405 managing the controller specified by 406 ControllerHandle and ChildHandle. 407 408 @retval EFI_UNSUPPORTED The driver specified by This does not support 409 the language specified by Language. 410 411 **/ 412 EFI_STATUS 413 EFIAPI 414 Ip6ComponentNameGetControllerName ( 415 IN EFI_COMPONENT_NAME_PROTOCOL *This, 416 IN EFI_HANDLE ControllerHandle, 417 IN EFI_HANDLE ChildHandle OPTIONAL, 418 IN CHAR8 *Language, 419 OUT CHAR16 **ControllerName 420 ) 421 { 422 EFI_STATUS Status; 423 EFI_IP6_PROTOCOL *Ip6; 424 425 // 426 // Only provide names for child handles. 427 // 428 if (ChildHandle == NULL) { 429 return EFI_UNSUPPORTED; 430 } 431 432 // 433 // Make sure this driver produced ChildHandle 434 // 435 Status = EfiTestChildHandle ( 436 ControllerHandle, 437 ChildHandle, 438 &gEfiManagedNetworkProtocolGuid 439 ); 440 if (EFI_ERROR (Status)) { 441 return Status; 442 } 443 444 // 445 // Retrieve an instance of a produced protocol from ChildHandle 446 // 447 Status = gBS->OpenProtocol ( 448 ChildHandle, 449 &gEfiIp6ProtocolGuid, 450 (VOID **)&Ip6, 451 NULL, 452 NULL, 453 EFI_OPEN_PROTOCOL_GET_PROTOCOL 454 ); 455 if (EFI_ERROR (Status)) { 456 return Status; 457 } 458 459 // 460 // Update the component name for this child handle. 461 // 462 Status = UpdateName (Ip6); 463 if (EFI_ERROR (Status)) { 464 return Status; 465 } 466 467 return LookupUnicodeString2 ( 468 Language, 469 This->SupportedLanguages, 470 gIp6ControllerNameTable, 471 ControllerName, 472 (BOOLEAN)(This == &gIp6ComponentName) 473 ); 474 } 475