ComponentName.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /** @file
  2. UEFI Component Name(2) protocol implementation for ChaosKey driver.
  3. Copyright (c) 2017, Linaro Ltd. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "ChaosKeyDriver.h"
  7. STATIC EFI_UNICODE_STRING_TABLE mChaosKeyDriverNameTable[] = {
  8. {
  9. "en",
  10. (CHAR16 *)L"ChaosKey RNG USB driver"
  11. },
  12. { }
  13. };
  14. STATIC EFI_UNICODE_STRING_TABLE mChaosKeyControllerNameTable[] = {
  15. {
  16. "en",
  17. (CHAR16 *)L"ChaosKey Random Number Generator (USB)"
  18. },
  19. { }
  20. };
  21. /**
  22. Retrieves a Unicode string that is the user readable name of the driver.
  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. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  30. EFI_COMPONENT_NAME_PROTOCOL instance.
  31. @param Language[in] A pointer to a Null-terminated ASCII string
  32. array indicating the language. This is the
  33. language of the driver name that the caller is
  34. requesting, and it must match one of the
  35. languages specified in SupportedLanguages. The
  36. number of languages supported by a driver is up
  37. to the driver writer. Language is specified
  38. in RFC 4646 or ISO 639-2 language code format.
  39. @param DriverName[out] A pointer to the Unicode string to return.
  40. This Unicode string is the name of the
  41. driver specified by This in the language
  42. specified by Language.
  43. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  44. This and the language specified by Language was
  45. returned in DriverName.
  46. @retval EFI_INVALID_PARAMETER Language is NULL.
  47. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  48. @retval EFI_UNSUPPORTED The driver specified by This does not support
  49. the language specified by Language.
  50. **/
  51. STATIC
  52. EFI_STATUS
  53. EFIAPI
  54. ChaosKeyGetDriverName (
  55. IN EFI_COMPONENT_NAME2_PROTOCOL *This,
  56. IN CHAR8 *Language,
  57. OUT CHAR16 **DriverName
  58. )
  59. {
  60. return LookupUnicodeString2 (Language,
  61. This->SupportedLanguages,
  62. mChaosKeyDriverNameTable,
  63. DriverName,
  64. FALSE);
  65. }
  66. /**
  67. Retrieves a Unicode string that is the user readable name of the controller
  68. that is being managed by a driver.
  69. This function retrieves the user readable name of the controller specified by
  70. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  71. driver specified by This has a user readable name in the language specified by
  72. Language, then a pointer to the controller name is returned in ControllerName,
  73. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  74. managing the controller specified by ControllerHandle and ChildHandle,
  75. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  76. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  77. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  78. EFI_COMPONENT_NAME_PROTOCOL instance.
  79. @param ControllerHandle[in] The handle of a controller that the driver
  80. specified by This is managing. This handle
  81. specifies the controller whose name is to be
  82. returned.
  83. @param ChildHandle[in] The handle of the child controller to retrieve
  84. the name of. This is an optional parameter that
  85. may be NULL. It will be NULL for device
  86. drivers. It will also be NULL for a bus drivers
  87. that wish to retrieve the name of the bus
  88. controller. It will not be NULL for a bus
  89. driver that wishes to retrieve the name of a
  90. child controller.
  91. @param Language[in] A pointer to a Null-terminated ASCII string
  92. array indicating the language. This is the
  93. language of the driver name that the caller is
  94. requesting, and it must match one of the
  95. languages specified in SupportedLanguages. The
  96. number of languages supported by a driver is up
  97. to the driver writer. Language is specified in
  98. RFC 4646 or ISO 639-2 language code format.
  99. @param ControllerName[out] A pointer to the Unicode string to return.
  100. This Unicode string is the name of the
  101. controller specified by ControllerHandle and
  102. ChildHandle in the language specified by
  103. Language from the point of view of the driver
  104. specified by This.
  105. @retval EFI_SUCCESS The Unicode string for the user readable name in
  106. the language specified by Language for the
  107. driver specified by This was returned in
  108. DriverName.
  109. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  110. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  111. EFI_HANDLE.
  112. @retval EFI_INVALID_PARAMETER Language is NULL.
  113. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  114. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  115. managing the controller specified by
  116. ControllerHandle and ChildHandle.
  117. @retval EFI_UNSUPPORTED The driver specified by This does not support
  118. the language specified by Language.
  119. **/
  120. STATIC
  121. EFI_STATUS
  122. EFIAPI
  123. ChaosKeyGetControllerName (
  124. IN EFI_COMPONENT_NAME2_PROTOCOL *This,
  125. IN EFI_HANDLE ControllerHandle,
  126. IN EFI_HANDLE ChildHandle OPTIONAL,
  127. IN CHAR8 *Language,
  128. OUT CHAR16 **ControllerName
  129. )
  130. {
  131. EFI_STATUS Status;
  132. if (!ControllerHandle) {
  133. return EFI_INVALID_PARAMETER;
  134. }
  135. Status = EfiTestManagedDevice (ControllerHandle,
  136. gUsbDriverBinding.DriverBindingHandle,
  137. &gEfiUsbIoProtocolGuid);
  138. if (EFI_ERROR (Status)) {
  139. return Status;
  140. }
  141. if (ChildHandle != NULL) {
  142. return EFI_UNSUPPORTED;
  143. }
  144. return LookupUnicodeString2 (Language,
  145. This->SupportedLanguages,
  146. mChaosKeyControllerNameTable,
  147. ControllerName,
  148. FALSE);
  149. }
  150. //
  151. // EFI Component Name 2 Protocol
  152. //
  153. EFI_COMPONENT_NAME2_PROTOCOL gChaosKeyDriverComponentName2 = {
  154. ChaosKeyGetDriverName,
  155. ChaosKeyGetControllerName,
  156. "en"
  157. };