ComponentName.c 17 KB

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