ComponentName.c 18 KB

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