ComponentName.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /** @file
  2. UEFI Component Name(2) protocol implementation for Dhcp6 driver.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "Dhcp6Impl.h"
  7. /**
  8. Retrieves a Unicode string that is the user-readable name of the driver.
  9. This function retrieves the user-readable name of a driver in the form of a
  10. Unicode string. If the driver specified by This has a user-readable name in
  11. the language specified by Language, then a pointer to the driver name is
  12. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  13. by This does not support the language specified by Language,
  14. then EFI_UNSUPPORTED is returned.
  15. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  16. EFI_COMPONENT_NAME_PROTOCOL instance.
  17. @param[in] Language A pointer to a Null-terminated ASCII string
  18. array indicating the language. This is the
  19. language of the driver name that the caller is
  20. requesting, and it must match one of the
  21. languages specified in SupportedLanguages. The
  22. number of languages supported by a driver is up
  23. to the driver writer. Language is specified
  24. in RFC 4646 or ISO 639-2 language code format.
  25. @param[out] DriverName A pointer to the Unicode string to return.
  26. This Unicode string is the name of the
  27. driver specified by This in the language
  28. specified by Language.
  29. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  30. This and the language specified by Language was
  31. returned in DriverName.
  32. @retval EFI_INVALID_PARAMETER Language is NULL.
  33. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  34. @retval EFI_UNSUPPORTED The driver specified by This does not support
  35. the language specified by Language.
  36. **/
  37. EFI_STATUS
  38. EFIAPI
  39. Dhcp6ComponentNameGetDriverName (
  40. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  41. IN CHAR8 *Language,
  42. OUT CHAR16 **DriverName
  43. );
  44. /**
  45. Retrieves a Unicode string that is the user-readable name of the controller
  46. that is being managed by a driver.
  47. This function retrieves the user-readable name of the controller specified by
  48. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  49. driver specified by This has a user-readable name in the language specified by
  50. Language, then a pointer to the controller name is returned in ControllerName,
  51. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  52. managing the controller specified by ControllerHandle and ChildHandle,
  53. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  54. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  55. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  56. EFI_COMPONENT_NAME_PROTOCOL instance.
  57. @param[in] ControllerHandle The handle of a controller that the driver
  58. specified by This is managing. This handle
  59. specifies the controller whose name is to be
  60. returned.
  61. @param[in] ChildHandle The handle of the child controller to retrieve
  62. the name of. This is an optional parameter that
  63. may be NULL. It will be NULL for device
  64. drivers. It will also be NULL for a bus drivers
  65. that attempt to retrieve the name of the bus
  66. controller. It will not be NULL for a bus
  67. driver that attempts to retrieve the name of a
  68. child controller.
  69. @param[in] Language A pointer to a Null-terminated ASCII string
  70. array indicating the language. This is the
  71. language of the driver name that the caller is
  72. requesting, and it must match one of the
  73. languages specified in SupportedLanguages. The
  74. number of languages supported by a driver is up
  75. to the driver writer. Language is specified in
  76. RFC 4646 or ISO 639-2 language code format.
  77. @param[out] ControllerName A pointer to the Unicode string to return.
  78. This Unicode string is the name of the
  79. controller specified by ControllerHandle and
  80. ChildHandle in the language specified by
  81. Language, from the point of view of the driver
  82. specified by This.
  83. @retval EFI_SUCCESS The Unicode string for the user-readable name in
  84. the language specified by Language for the
  85. driver specified by This was returned in
  86. DriverName.
  87. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  88. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
  89. EFI_HANDLE.
  90. @retval EFI_INVALID_PARAMETER Language is NULL.
  91. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  92. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  93. managing the controller specified by
  94. ControllerHandle and ChildHandle.
  95. @retval EFI_UNSUPPORTED The driver specified by This does not support
  96. the language specified by Language.
  97. **/
  98. EFI_STATUS
  99. EFIAPI
  100. Dhcp6ComponentNameGetControllerName (
  101. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  102. IN EFI_HANDLE ControllerHandle,
  103. IN EFI_HANDLE ChildHandle OPTIONAL,
  104. IN CHAR8 *Language,
  105. OUT CHAR16 **ControllerName
  106. );
  107. //
  108. // EFI Component Name Protocol
  109. //
  110. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDhcp6ComponentName = {
  111. Dhcp6ComponentNameGetDriverName,
  112. Dhcp6ComponentNameGetControllerName,
  113. "eng"
  114. };
  115. //
  116. // EFI Component Name 2 Protocol
  117. //
  118. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDhcp6ComponentName2 = {
  119. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Dhcp6ComponentNameGetDriverName,
  120. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Dhcp6ComponentNameGetControllerName,
  121. "en"
  122. };
  123. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDhcp6DriverNameTable[] = {
  124. {
  125. "eng;en",
  126. L"DHCP6 Protocol Driver"
  127. },
  128. {
  129. NULL,
  130. NULL
  131. }
  132. };
  133. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDhcp6ControllerNameTable = NULL;
  134. CHAR16 *mDhcp6ControllerName[] = {
  135. L"DHCPv6 (State=0, Init)",
  136. L"DHCPv6 (State=1, Selecting)",
  137. L"DHCPv6 (State=2, Requesting)",
  138. L"DHCPv6 (State=3, Declining)",
  139. L"DHCPv6 (State=4, Confirming)",
  140. L"DHCPv6 (State=5, Releasing)",
  141. L"DHCPv6 (State=6, Bound)",
  142. L"DHCPv6 (State=7, Renewing)",
  143. L"DHCPv6 (State=8, Rebinding)"
  144. };
  145. /**
  146. Retrieves a Unicode string that is the user-readable name of the driver.
  147. This function retrieves the user-readable name of a driver in the form of a
  148. Unicode string. If the driver specified by This has a user-readable name in
  149. the language specified by Language, then a pointer to the driver name is
  150. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  151. by This does not support the language specified by Language,
  152. then EFI_UNSUPPORTED is returned.
  153. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  154. EFI_COMPONENT_NAME_PROTOCOL instance.
  155. @param[in] Language A pointer to a Null-terminated ASCII string
  156. array indicating the language. This is the
  157. language of the driver name that the caller is
  158. requesting, and it must match one of the
  159. languages specified in SupportedLanguages. The
  160. number of languages supported by a driver is up
  161. to the driver writer. Language is specified
  162. in RFC 4646 or ISO 639-2 language code format.
  163. @param[out] DriverName A pointer to the Unicode string to return.
  164. This Unicode string is the name of the
  165. driver specified by This in the language
  166. specified by Language.
  167. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  168. This and the language specified by Language was
  169. returned in DriverName.
  170. @retval EFI_INVALID_PARAMETER Language is NULL.
  171. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  172. @retval EFI_UNSUPPORTED The driver specified by This does not support
  173. the language specified by Language.
  174. **/
  175. EFI_STATUS
  176. EFIAPI
  177. Dhcp6ComponentNameGetDriverName (
  178. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  179. IN CHAR8 *Language,
  180. OUT CHAR16 **DriverName
  181. )
  182. {
  183. return LookupUnicodeString2 (
  184. Language,
  185. This->SupportedLanguages,
  186. mDhcp6DriverNameTable,
  187. DriverName,
  188. (BOOLEAN)(This == &gDhcp6ComponentName)
  189. );
  190. }
  191. /**
  192. Update the component name for the Dhcp6 child handle.
  193. @param Dhcp6[in] A pointer to the EFI_DHCP6_PROTOCOL.
  194. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  195. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  196. **/
  197. EFI_STATUS
  198. UpdateName (
  199. IN EFI_DHCP6_PROTOCOL *Dhcp6
  200. )
  201. {
  202. EFI_STATUS Status;
  203. EFI_DHCP6_MODE_DATA Dhcp6ModeData;
  204. CHAR16 *HandleName;
  205. if (Dhcp6 == NULL) {
  206. return EFI_INVALID_PARAMETER;
  207. }
  208. //
  209. // Format the child name into the string buffer.
  210. //
  211. Status = Dhcp6->GetModeData (Dhcp6, &Dhcp6ModeData, NULL);
  212. if (EFI_ERROR (Status)) {
  213. return Status;
  214. }
  215. if (gDhcp6ControllerNameTable != NULL) {
  216. FreeUnicodeStringTable (gDhcp6ControllerNameTable);
  217. gDhcp6ControllerNameTable = NULL;
  218. }
  219. if (Dhcp6ModeData.Ia == NULL) {
  220. HandleName = L"DHCPv6 (No configured IA)";
  221. } else {
  222. if (Dhcp6ModeData.Ia->State > Dhcp6Rebinding) {
  223. return EFI_DEVICE_ERROR;
  224. }
  225. HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State];
  226. }
  227. if (Dhcp6ModeData.Ia != NULL) {
  228. FreePool (Dhcp6ModeData.Ia);
  229. }
  230. if (Dhcp6ModeData.ClientId != NULL) {
  231. FreePool (Dhcp6ModeData.ClientId);
  232. }
  233. Status = AddUnicodeString2 (
  234. "eng",
  235. gDhcp6ComponentName.SupportedLanguages,
  236. &gDhcp6ControllerNameTable,
  237. HandleName,
  238. TRUE
  239. );
  240. if (EFI_ERROR (Status)) {
  241. return Status;
  242. }
  243. return AddUnicodeString2 (
  244. "en",
  245. gDhcp6ComponentName2.SupportedLanguages,
  246. &gDhcp6ControllerNameTable,
  247. HandleName,
  248. FALSE
  249. );
  250. }
  251. /**
  252. Retrieves a Unicode string that is the user-readable name of the controller
  253. that is being managed by a driver.
  254. This function retrieves the user-readable name of the controller specified by
  255. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  256. driver specified by This has a user-readable name in the language specified by
  257. Language, then a pointer to the controller name is returned in ControllerName,
  258. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  259. managing the controller specified by ControllerHandle and ChildHandle,
  260. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  261. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  262. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  263. EFI_COMPONENT_NAME_PROTOCOL instance.
  264. @param[in] ControllerHandle The handle of a controller that the driver
  265. specified by This is managing. This handle
  266. specifies the controller whose name is to be
  267. returned.
  268. @param[in] ChildHandle The handle of the child controller to retrieve
  269. the name of. This is an optional parameter that
  270. may be NULL. It will be NULL for device
  271. drivers. It will also be NULL for a bus drivers
  272. that wish to retrieve the name of the bus
  273. controller. It will not be NULL for a bus
  274. driver that wishes to retrieve the name of a
  275. child controller.
  276. @param[in] Language A pointer to a Null-terminated ASCII string
  277. array indicating the language. This is the
  278. language of the driver name that the caller is
  279. requesting, and it must match one of the
  280. languages specified in SupportedLanguages. The
  281. number of languages supported by a driver is up
  282. to the driver writer. Language is specified in the
  283. RFC 4646 or ISO 639-2 language code format.
  284. @param[out] ControllerName A pointer to the Unicode string to return.
  285. This Unicode string is the name of the
  286. controller specified by ControllerHandle and
  287. ChildHandle in the language specified by
  288. Language, from the point of view of the driver
  289. specified by This.
  290. @retval EFI_SUCCESS The Unicode string for the user-readable name in
  291. the language specified by Language for the
  292. driver specified by This was returned in
  293. DriverName.
  294. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  295. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
  296. EFI_HANDLE.
  297. @retval EFI_INVALID_PARAMETER Language is NULL.
  298. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  299. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  300. managing the controller specified by
  301. ControllerHandle and ChildHandle.
  302. @retval EFI_UNSUPPORTED The driver specified by This does not support
  303. the language specified by Language.
  304. **/
  305. EFI_STATUS
  306. EFIAPI
  307. Dhcp6ComponentNameGetControllerName (
  308. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  309. IN EFI_HANDLE ControllerHandle,
  310. IN EFI_HANDLE ChildHandle OPTIONAL,
  311. IN CHAR8 *Language,
  312. OUT CHAR16 **ControllerName
  313. )
  314. {
  315. EFI_STATUS Status;
  316. EFI_DHCP6_PROTOCOL *Dhcp6;
  317. //
  318. // Only provide names for child handles.
  319. //
  320. if (ChildHandle == NULL) {
  321. return EFI_UNSUPPORTED;
  322. }
  323. //
  324. // Make sure this driver produced ChildHandle
  325. //
  326. Status = EfiTestChildHandle (
  327. ControllerHandle,
  328. ChildHandle,
  329. &gEfiUdp6ProtocolGuid
  330. );
  331. if (EFI_ERROR (Status)) {
  332. return Status;
  333. }
  334. //
  335. // Retrieve an instance of a produced protocol from ChildHandle
  336. //
  337. Status = gBS->OpenProtocol (
  338. ChildHandle,
  339. &gEfiDhcp6ProtocolGuid,
  340. (VOID **)&Dhcp6,
  341. NULL,
  342. NULL,
  343. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  344. );
  345. if (EFI_ERROR (Status)) {
  346. return Status;
  347. }
  348. //
  349. // Update the component name for this child handle.
  350. //
  351. Status = UpdateName (Dhcp6);
  352. if (EFI_ERROR (Status)) {
  353. return Status;
  354. }
  355. return LookupUnicodeString2 (
  356. Language,
  357. This->SupportedLanguages,
  358. gDhcp6ControllerNameTable,
  359. ControllerName,
  360. (BOOLEAN)(This == &gDhcp6ComponentName)
  361. );
  362. }