ComponentName.c 17 KB

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