ComponentName.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /** @file
  2. Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.
  3. Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "DnsImpl.h"
  7. //
  8. // EFI Component Name Functions
  9. //
  10. /**
  11. Retrieves a Unicode string that is the user-readable name of the EFI Driver.
  12. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
  13. @param Language A pointer to a three-character ISO 639-2 language identifier.
  14. This is the language of the driver name that that the caller
  15. is requesting, and it must match one of the languages specified
  16. in SupportedLanguages. The number of languages supported by a
  17. driver is up to the driver writer.
  18. @param DriverName A pointer to the Unicode string to return. This Unicode string
  19. is the name of the driver specified by This in the language
  20. specified by Language.
  21. @retval EFI_SUCCESS The Unicode string for the Driver specified by This
  22. and the language specified by Language was returned
  23. in DriverName.
  24. @retval EFI_INVALID_PARAMETER Language is NULL.
  25. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  26. @retval EFI_UNSUPPORTED The driver specified by This does not support the
  27. language specified by Language.
  28. **/
  29. EFI_STATUS
  30. EFIAPI
  31. DnsComponentNameGetDriverName (
  32. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  33. IN CHAR8 *Language,
  34. OUT CHAR16 **DriverName
  35. );
  36. /**
  37. Retrieves a Unicode string that is the user readable name of the controller
  38. that is being managed by an EFI Driver.
  39. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
  40. @param ControllerHandle The handle of a controller that the driver specified by
  41. This is managing. This handle specifies the controller
  42. whose name is to be returned.
  43. @param ChildHandle The handle of the child controller to retrieve the name
  44. of. This is an optional parameter that may be NULL. It
  45. will be NULL for device drivers. It will also be NULL
  46. for a bus drivers that wish to retrieve the name of the
  47. bus controller. It will not be NULL for a bus driver
  48. that wishes to retrieve the name of a child controller.
  49. @param Language A pointer to a three character ISO 639-2 language
  50. identifier. This is the language of the controller name
  51. that the caller is requesting, and it must match one
  52. of the languages specified in SupportedLanguages. The
  53. number of languages supported by a driver is up to the
  54. driver writer.
  55. @param ControllerName A pointer to the Unicode string to return. This Unicode
  56. string is the name of the controller specified by
  57. ControllerHandle and ChildHandle in the language specified
  58. by Language, from the point of view of the driver specified
  59. by This.
  60. @retval EFI_SUCCESS The Unicode string for the user-readable name in the
  61. language specified by Language for the driver
  62. specified by This was returned in DriverName.
  63. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  64. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
  65. @retval EFI_INVALID_PARAMETER Language is NULL.
  66. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  67. @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
  68. the controller specified by ControllerHandle and
  69. ChildHandle.
  70. @retval EFI_UNSUPPORTED The driver specified by This does not support the
  71. language specified by Language.
  72. **/
  73. EFI_STATUS
  74. EFIAPI
  75. DnsComponentNameGetControllerName (
  76. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  77. IN EFI_HANDLE ControllerHandle,
  78. IN EFI_HANDLE ChildHandle OPTIONAL,
  79. IN CHAR8 *Language,
  80. OUT CHAR16 **ControllerName
  81. );
  82. ///
  83. /// Component Name Protocol instance
  84. ///
  85. GLOBAL_REMOVE_IF_UNREFERENCED
  86. EFI_COMPONENT_NAME_PROTOCOL gDnsComponentName = {
  87. DnsComponentNameGetDriverName,
  88. DnsComponentNameGetControllerName,
  89. "eng"
  90. };
  91. ///
  92. /// Component Name 2 Protocol instance
  93. ///
  94. GLOBAL_REMOVE_IF_UNREFERENCED
  95. EFI_COMPONENT_NAME2_PROTOCOL gDnsComponentName2 = {
  96. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)DnsComponentNameGetDriverName,
  97. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)DnsComponentNameGetControllerName,
  98. "en"
  99. };
  100. ///
  101. /// Table of driver names
  102. ///
  103. GLOBAL_REMOVE_IF_UNREFERENCED
  104. EFI_UNICODE_STRING_TABLE mDnsDriverNameTable[] = {
  105. { "eng;en", (CHAR16 *)L"DNS Network Service Driver" },
  106. { NULL, NULL }
  107. };
  108. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDnsControllerNameTable = NULL;
  109. /**
  110. Retrieves a Unicode string that is the user-readable name of the EFI Driver.
  111. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
  112. @param Language A pointer to a three-character ISO 639-2 language identifier.
  113. This is the language of the driver name that that the caller
  114. is requesting, and it must match one of the languages specified
  115. in SupportedLanguages. The number of languages supported by a
  116. driver is up to the driver writer.
  117. @param DriverName A pointer to the Unicode string to return. This Unicode string
  118. is the name of the driver specified by This in the language
  119. specified by Language.
  120. @retval EFI_SUCCESS The Unicode string for the Driver specified by This
  121. and the language specified by Language was returned
  122. in DriverName.
  123. @retval EFI_INVALID_PARAMETER Language is NULL.
  124. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  125. @retval EFI_UNSUPPORTED The driver specified by This does not support the
  126. language specified by Language.
  127. **/
  128. EFI_STATUS
  129. EFIAPI
  130. DnsComponentNameGetDriverName (
  131. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  132. IN CHAR8 *Language,
  133. OUT CHAR16 **DriverName
  134. )
  135. {
  136. return LookupUnicodeString2 (
  137. Language,
  138. This->SupportedLanguages,
  139. mDnsDriverNameTable,
  140. DriverName,
  141. (BOOLEAN)(This == &gDnsComponentName)
  142. );
  143. }
  144. /**
  145. Update the component name for the Dns4 child handle.
  146. @param Dns4 A pointer to the EFI_DNS4_PROTOCOL.
  147. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  148. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  149. **/
  150. EFI_STATUS
  151. UpdateDns4Name (
  152. EFI_DNS4_PROTOCOL *Dns4
  153. )
  154. {
  155. EFI_STATUS Status;
  156. CHAR16 HandleName[80];
  157. EFI_DNS4_MODE_DATA ModeData;
  158. if (Dns4 == NULL) {
  159. return EFI_INVALID_PARAMETER;
  160. }
  161. //
  162. // Format the child name into the string buffer as:
  163. // DNSv4 (StationIp=?, LocalPort=?)
  164. //
  165. Status = Dns4->GetModeData (Dns4, &ModeData);
  166. if (EFI_ERROR (Status)) {
  167. return Status;
  168. }
  169. UnicodeSPrint (
  170. HandleName,
  171. sizeof (HandleName),
  172. L"DNSv4 (StationIp=%d.%d.%d.%d, LocalPort=%d)",
  173. ModeData.DnsConfigData.StationIp.Addr[0],
  174. ModeData.DnsConfigData.StationIp.Addr[1],
  175. ModeData.DnsConfigData.StationIp.Addr[2],
  176. ModeData.DnsConfigData.StationIp.Addr[3],
  177. ModeData.DnsConfigData.LocalPort
  178. );
  179. if (ModeData.DnsCacheList != NULL) {
  180. FreePool (ModeData.DnsCacheList);
  181. }
  182. if (ModeData.DnsServerList != NULL) {
  183. FreePool (ModeData.DnsServerList);
  184. }
  185. if (gDnsControllerNameTable != NULL) {
  186. FreeUnicodeStringTable (gDnsControllerNameTable);
  187. gDnsControllerNameTable = NULL;
  188. }
  189. Status = AddUnicodeString2 (
  190. "eng",
  191. gDnsComponentName.SupportedLanguages,
  192. &gDnsControllerNameTable,
  193. HandleName,
  194. TRUE
  195. );
  196. if (EFI_ERROR (Status)) {
  197. return Status;
  198. }
  199. return AddUnicodeString2 (
  200. "en",
  201. gDnsComponentName2.SupportedLanguages,
  202. &gDnsControllerNameTable,
  203. HandleName,
  204. FALSE
  205. );
  206. }
  207. /**
  208. Update the component name for the Dns6 child handle.
  209. @param Dns6 A pointer to the EFI_DNS6_PROTOCOL.
  210. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  211. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  212. **/
  213. EFI_STATUS
  214. UpdateDns6Name (
  215. EFI_DNS6_PROTOCOL *Dns6
  216. )
  217. {
  218. EFI_STATUS Status;
  219. CHAR16 HandleName[128];
  220. EFI_DNS6_MODE_DATA ModeData;
  221. CHAR16 Address[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  222. if (Dns6 == NULL) {
  223. return EFI_INVALID_PARAMETER;
  224. }
  225. //
  226. // Format the child name into the string buffer as:
  227. // DNSv6 (StationIp=?, LocalPort=?)
  228. //
  229. Status = Dns6->GetModeData (Dns6, &ModeData);
  230. if (EFI_ERROR (Status)) {
  231. return Status;
  232. }
  233. Status = NetLibIp6ToStr (&ModeData.DnsConfigData.StationIp, Address, sizeof (Address));
  234. if (EFI_ERROR (Status)) {
  235. return Status;
  236. }
  237. UnicodeSPrint (
  238. HandleName,
  239. sizeof (HandleName),
  240. L"DNSv6 (StationIp=%s, LocalPort=%d)",
  241. Address,
  242. ModeData.DnsConfigData.LocalPort
  243. );
  244. if (ModeData.DnsCacheList != NULL) {
  245. FreePool (ModeData.DnsCacheList);
  246. }
  247. if (ModeData.DnsServerList != NULL) {
  248. FreePool (ModeData.DnsServerList);
  249. }
  250. if (gDnsControllerNameTable != NULL) {
  251. FreeUnicodeStringTable (gDnsControllerNameTable);
  252. gDnsControllerNameTable = NULL;
  253. }
  254. Status = AddUnicodeString2 (
  255. "eng",
  256. gDnsComponentName.SupportedLanguages,
  257. &gDnsControllerNameTable,
  258. HandleName,
  259. TRUE
  260. );
  261. if (EFI_ERROR (Status)) {
  262. return Status;
  263. }
  264. return AddUnicodeString2 (
  265. "en",
  266. gDnsComponentName2.SupportedLanguages,
  267. &gDnsControllerNameTable,
  268. HandleName,
  269. FALSE
  270. );
  271. }
  272. /**
  273. Retrieves a Unicode string that is the user readable name of the controller
  274. that is being managed by an EFI Driver.
  275. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
  276. @param ControllerHandle The handle of a controller that the driver specified by
  277. This is managing. This handle specifies the controller
  278. whose name is to be returned.
  279. @param ChildHandle The handle of the child controller to retrieve the name
  280. of. This is an optional parameter that may be NULL. It
  281. will be NULL for device drivers. It will also be NULL
  282. for a bus drivers that wish to retrieve the name of the
  283. bus controller. It will not be NULL for a bus driver
  284. that wishes to retrieve the name of a child controller.
  285. @param Language A pointer to a three character ISO 639-2 language
  286. identifier. This is the language of the controller name
  287. that the caller is requesting, and it must match one
  288. of the languages specified in SupportedLanguages. The
  289. number of languages supported by a driver is up to the
  290. driver writer.
  291. @param ControllerName A pointer to the Unicode string to return. This Unicode
  292. string is the name of the controller specified by
  293. ControllerHandle and ChildHandle in the language specified
  294. by Language, from the point of view of the driver specified
  295. by This.
  296. @retval EFI_SUCCESS The Unicode string for the user-readable name in the
  297. language specified by Language for the driver
  298. specified by This was returned in DriverName.
  299. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  300. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
  301. @retval EFI_INVALID_PARAMETER Language is NULL.
  302. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  303. @retval EFI_UNSUPPORTED The driver specified by This is not currently managing
  304. the controller specified by ControllerHandle and
  305. ChildHandle.
  306. @retval EFI_UNSUPPORTED The driver specified by This does not support the
  307. language specified by Language.
  308. **/
  309. EFI_STATUS
  310. EFIAPI
  311. DnsComponentNameGetControllerName (
  312. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  313. IN EFI_HANDLE ControllerHandle,
  314. IN EFI_HANDLE ChildHandle OPTIONAL,
  315. IN CHAR8 *Language,
  316. OUT CHAR16 **ControllerName
  317. )
  318. {
  319. EFI_STATUS Status;
  320. EFI_DNS4_PROTOCOL *Dns4;
  321. EFI_DNS6_PROTOCOL *Dns6;
  322. //
  323. // ChildHandle must be NULL for a Device Driver
  324. //
  325. if (ChildHandle == NULL) {
  326. return EFI_UNSUPPORTED;
  327. }
  328. //
  329. // Make sure this driver produced ChildHandle
  330. //
  331. Status = EfiTestChildHandle (
  332. ControllerHandle,
  333. ChildHandle,
  334. &gEfiUdp6ProtocolGuid
  335. );
  336. if (!EFI_ERROR (Status)) {
  337. //
  338. // Retrieve an instance of a produced protocol from ChildHandle
  339. //
  340. Status = gBS->OpenProtocol (
  341. ChildHandle,
  342. &gEfiDns6ProtocolGuid,
  343. (VOID **)&Dns6,
  344. NULL,
  345. NULL,
  346. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  347. );
  348. if (EFI_ERROR (Status)) {
  349. return Status;
  350. }
  351. //
  352. // Update the component name for this child handle.
  353. //
  354. Status = UpdateDns6Name (Dns6);
  355. if (EFI_ERROR (Status)) {
  356. return Status;
  357. }
  358. }
  359. //
  360. // Make sure this driver produced ChildHandle
  361. //
  362. Status = EfiTestChildHandle (
  363. ControllerHandle,
  364. ChildHandle,
  365. &gEfiUdp4ProtocolGuid
  366. );
  367. if (!EFI_ERROR (Status)) {
  368. //
  369. // Retrieve an instance of a produced protocol from ChildHandle
  370. //
  371. Status = gBS->OpenProtocol (
  372. ChildHandle,
  373. &gEfiDns4ProtocolGuid,
  374. (VOID **)&Dns4,
  375. NULL,
  376. NULL,
  377. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  378. );
  379. if (EFI_ERROR (Status)) {
  380. return Status;
  381. }
  382. //
  383. // Update the component name for this child handle.
  384. //
  385. Status = UpdateDns4Name (Dns4);
  386. if (EFI_ERROR (Status)) {
  387. return Status;
  388. }
  389. }
  390. return LookupUnicodeString2 (
  391. Language,
  392. This->SupportedLanguages,
  393. gDnsControllerNameTable,
  394. ControllerName,
  395. (BOOLEAN)(This == &gDnsComponentName)
  396. );
  397. }