ComponentName.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /** @file
  2. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include "Udp4Impl.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. UdpComponentNameGetDriverName (
  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. UdpComponentNameGetControllerName (
  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 gUdp4ComponentName = {
  113. UdpComponentNameGetDriverName,
  114. UdpComponentNameGetControllerName,
  115. "eng"
  116. };
  117. //
  118. // EFI Component Name 2 Protocol
  119. //
  120. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUdp4ComponentName2 = {
  121. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)UdpComponentNameGetDriverName,
  122. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)UdpComponentNameGetControllerName,
  123. "en"
  124. };
  125. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUdpDriverNameTable[] = {
  126. {
  127. "eng;en",
  128. L"UDP Network Service Driver"
  129. },
  130. {
  131. NULL,
  132. NULL
  133. }
  134. };
  135. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gUdpControllerNameTable = NULL;
  136. /**
  137. Retrieves a Unicode string that is the user readable name of the driver.
  138. This function retrieves the user readable name of a driver in the form of a
  139. Unicode string. If the driver specified by This has a user readable name in
  140. the language specified by Language, then a pointer to the driver name is
  141. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  142. by This does not support the language specified by Language,
  143. then EFI_UNSUPPORTED is returned.
  144. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  145. EFI_COMPONENT_NAME_PROTOCOL instance.
  146. @param[in] Language A pointer to a Null-terminated ASCII string
  147. array indicating the language. This is the
  148. language of the driver name that the caller is
  149. requesting, and it must match one of the
  150. languages specified in SupportedLanguages. The
  151. number of languages supported by a driver is up
  152. to the driver writer. Language is specified
  153. in RFC 4646 or ISO 639-2 language code format.
  154. @param[out] DriverName A pointer to the Unicode string to return.
  155. This Unicode string is the name of the
  156. driver specified by This in the language
  157. specified by Language.
  158. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  159. This and the language specified by Language was
  160. returned in DriverName.
  161. @retval EFI_INVALID_PARAMETER Language is NULL.
  162. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  163. @retval EFI_UNSUPPORTED The driver specified by This does not support
  164. the language specified by Language.
  165. **/
  166. EFI_STATUS
  167. EFIAPI
  168. UdpComponentNameGetDriverName (
  169. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  170. IN CHAR8 *Language,
  171. OUT CHAR16 **DriverName
  172. )
  173. {
  174. return LookupUnicodeString2 (
  175. Language,
  176. This->SupportedLanguages,
  177. mUdpDriverNameTable,
  178. DriverName,
  179. (BOOLEAN)(This == &gUdp4ComponentName)
  180. );
  181. }
  182. /**
  183. Update the component name for the Udp4 child handle.
  184. @param Udp4[in] A pointer to the EFI_UDP4_PROTOCOL.
  185. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  186. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  187. **/
  188. EFI_STATUS
  189. UpdateName (
  190. EFI_UDP4_PROTOCOL *Udp4
  191. )
  192. {
  193. EFI_STATUS Status;
  194. CHAR16 HandleName[64];
  195. EFI_UDP4_CONFIG_DATA Udp4ConfigData;
  196. if (Udp4 == NULL) {
  197. return EFI_INVALID_PARAMETER;
  198. }
  199. //
  200. // Format the child name into the string buffer as:
  201. // UDPv4 (SrcPort=59, DestPort=60)
  202. //
  203. Status = Udp4->GetModeData (Udp4, &Udp4ConfigData, NULL, NULL, NULL);
  204. if (!EFI_ERROR (Status)) {
  205. UnicodeSPrint (
  206. HandleName,
  207. sizeof (HandleName),
  208. L"UDPv4 (SrcPort=%d, DestPort=%d)",
  209. Udp4ConfigData.StationPort,
  210. Udp4ConfigData.RemotePort
  211. );
  212. } else if (Status == EFI_NOT_STARTED) {
  213. UnicodeSPrint (
  214. HandleName,
  215. sizeof (HandleName),
  216. L"UDPv4 (Not started)"
  217. );
  218. } else {
  219. return Status;
  220. }
  221. if (gUdpControllerNameTable != NULL) {
  222. FreeUnicodeStringTable (gUdpControllerNameTable);
  223. gUdpControllerNameTable = NULL;
  224. }
  225. Status = AddUnicodeString2 (
  226. "eng",
  227. gUdp4ComponentName.SupportedLanguages,
  228. &gUdpControllerNameTable,
  229. HandleName,
  230. TRUE
  231. );
  232. if (EFI_ERROR (Status)) {
  233. return Status;
  234. }
  235. return AddUnicodeString2 (
  236. "en",
  237. gUdp4ComponentName2.SupportedLanguages,
  238. &gUdpControllerNameTable,
  239. HandleName,
  240. FALSE
  241. );
  242. }
  243. /**
  244. Retrieves a Unicode string that is the user readable name of the controller
  245. that is being managed by a driver.
  246. This function retrieves the user readable name of the controller specified by
  247. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  248. driver specified by This has a user readable name in the language specified by
  249. Language, then a pointer to the controller name is returned in ControllerName,
  250. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  251. managing the controller specified by ControllerHandle and ChildHandle,
  252. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  253. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  254. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  255. EFI_COMPONENT_NAME_PROTOCOL instance.
  256. @param[in] ControllerHandle The handle of a controller that the driver
  257. specified by This is managing. This handle
  258. specifies the controller whose name is to be
  259. returned.
  260. @param[in] ChildHandle The handle of the child controller to retrieve
  261. the name of. This is an optional parameter that
  262. may be NULL. It will be NULL for device
  263. drivers. It will also be NULL for a bus drivers
  264. that wish to retrieve the name of the bus
  265. controller. It will not be NULL for a bus
  266. driver that wishes to retrieve the name of a
  267. child controller.
  268. @param[in] Language A pointer to a Null-terminated ASCII string
  269. array indicating the language. This is the
  270. language of the driver name that the caller is
  271. requesting, and it must match one of the
  272. languages specified in SupportedLanguages. The
  273. number of languages supported by a driver is up
  274. to the driver writer. Language is specified in
  275. RFC 4646 or ISO 639-2 language code format.
  276. @param[out] ControllerName A pointer to the Unicode string to return.
  277. This Unicode string is the name of the
  278. controller specified by ControllerHandle and
  279. ChildHandle in the language specified by
  280. Language from the point of view of the driver
  281. specified by This.
  282. @retval EFI_SUCCESS The Unicode string for the user readable name in
  283. the language specified by Language for the
  284. driver specified by This was returned in
  285. DriverName.
  286. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  287. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  288. EFI_HANDLE.
  289. @retval EFI_INVALID_PARAMETER Language is NULL.
  290. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  291. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  292. managing the controller specified by
  293. ControllerHandle and ChildHandle.
  294. @retval EFI_UNSUPPORTED The driver specified by This does not support
  295. the language specified by Language.
  296. **/
  297. EFI_STATUS
  298. EFIAPI
  299. UdpComponentNameGetControllerName (
  300. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  301. IN EFI_HANDLE ControllerHandle,
  302. IN EFI_HANDLE ChildHandle OPTIONAL,
  303. IN CHAR8 *Language,
  304. OUT CHAR16 **ControllerName
  305. )
  306. {
  307. EFI_STATUS Status;
  308. EFI_UDP4_PROTOCOL *Udp4;
  309. //
  310. // Only provide names for child handles.
  311. //
  312. if (ChildHandle == NULL) {
  313. return EFI_UNSUPPORTED;
  314. }
  315. //
  316. // Make sure this driver produced ChildHandle
  317. //
  318. Status = EfiTestChildHandle (
  319. ControllerHandle,
  320. ChildHandle,
  321. &gEfiIp4ProtocolGuid
  322. );
  323. if (EFI_ERROR (Status)) {
  324. return Status;
  325. }
  326. //
  327. // Retrieve an instance of a produced protocol from ChildHandle
  328. //
  329. Status = gBS->OpenProtocol (
  330. ChildHandle,
  331. &gEfiUdp4ProtocolGuid,
  332. (VOID **)&Udp4,
  333. NULL,
  334. NULL,
  335. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  336. );
  337. if (EFI_ERROR (Status)) {
  338. return Status;
  339. }
  340. //
  341. // Update the component name for this child handle.
  342. //
  343. Status = UpdateName (Udp4);
  344. if (EFI_ERROR (Status)) {
  345. return Status;
  346. }
  347. return LookupUnicodeString2 (
  348. Language,
  349. This->SupportedLanguages,
  350. gUdpControllerNameTable,
  351. ControllerName,
  352. (BOOLEAN)(This == &gUdp4ComponentName)
  353. );
  354. }