ComponentName.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /** @file
  2. Implementation of protocols EFI_COMPONENT_NAME_PROTOCOL and
  3. EFI_COMPONENT_NAME2_PROTOCOL.
  4. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "TcpMain.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 or 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. TcpComponentNameGetDriverName (
  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 or 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. TcpComponentNameGetControllerName (
  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 gTcpComponentName = {
  113. TcpComponentNameGetDriverName,
  114. TcpComponentNameGetControllerName,
  115. "eng"
  116. };
  117. ///
  118. /// EFI Component Name 2 Protocol
  119. ///
  120. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gTcpComponentName2 = {
  121. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)TcpComponentNameGetDriverName,
  122. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)TcpComponentNameGetControllerName,
  123. "en"
  124. };
  125. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mTcpDriverNameTable[] = {
  126. {
  127. "eng;en",
  128. L"TCP Network Service Driver"
  129. },
  130. {
  131. NULL,
  132. NULL
  133. }
  134. };
  135. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gTcpControllerNameTable = 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 or DriverName is NULL.
  162. @retval EFI_UNSUPPORTED The driver specified by This does not support
  163. the language specified by Language.
  164. **/
  165. EFI_STATUS
  166. EFIAPI
  167. TcpComponentNameGetDriverName (
  168. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  169. IN CHAR8 *Language,
  170. OUT CHAR16 **DriverName
  171. )
  172. {
  173. return LookupUnicodeString2 (
  174. Language,
  175. This->SupportedLanguages,
  176. mTcpDriverNameTable,
  177. DriverName,
  178. (BOOLEAN)(This == &gTcpComponentName)
  179. );
  180. }
  181. /**
  182. Update the component name for the Tcp4 child handle.
  183. @param Tcp4[in] A pointer to the EFI_TCP4_PROTOCOL.
  184. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  185. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  186. **/
  187. EFI_STATUS
  188. UpdateTcp4Name (
  189. IN EFI_TCP4_PROTOCOL *Tcp4
  190. )
  191. {
  192. EFI_STATUS Status;
  193. CHAR16 HandleName[80];
  194. EFI_TCP4_CONFIG_DATA Tcp4ConfigData;
  195. if (Tcp4 == NULL) {
  196. return EFI_INVALID_PARAMETER;
  197. }
  198. //
  199. // Format the child name into the string buffer as:
  200. // TCPv4 (SrcPort=59, DestPort=60, ActiveFlag=TRUE)
  201. //
  202. ZeroMem (&Tcp4ConfigData, sizeof (Tcp4ConfigData));
  203. Status = Tcp4->GetModeData (Tcp4, NULL, &Tcp4ConfigData, NULL, NULL, NULL);
  204. if (!EFI_ERROR (Status)) {
  205. UnicodeSPrint (
  206. HandleName,
  207. sizeof (HandleName),
  208. L"TCPv4 (SrcPort=%d, DestPort=%d, ActiveFlag=%s)",
  209. Tcp4ConfigData.AccessPoint.StationPort,
  210. Tcp4ConfigData.AccessPoint.RemotePort,
  211. (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE")
  212. );
  213. } else if (Status == EFI_NOT_STARTED) {
  214. UnicodeSPrint (
  215. HandleName,
  216. sizeof (HandleName),
  217. L"TCPv4 (Not started)"
  218. );
  219. } else {
  220. return Status;
  221. }
  222. if (gTcpControllerNameTable != NULL) {
  223. FreeUnicodeStringTable (gTcpControllerNameTable);
  224. gTcpControllerNameTable = NULL;
  225. }
  226. Status = AddUnicodeString2 (
  227. "eng",
  228. gTcpComponentName.SupportedLanguages,
  229. &gTcpControllerNameTable,
  230. HandleName,
  231. TRUE
  232. );
  233. if (EFI_ERROR (Status)) {
  234. return Status;
  235. }
  236. return AddUnicodeString2 (
  237. "en",
  238. gTcpComponentName2.SupportedLanguages,
  239. &gTcpControllerNameTable,
  240. HandleName,
  241. FALSE
  242. );
  243. }
  244. /**
  245. Update the component name for the Tcp6 child handle.
  246. @param Tcp6[in] A pointer to the EFI_TCP6_PROTOCOL.
  247. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  248. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  249. **/
  250. EFI_STATUS
  251. UpdateTcp6Name (
  252. IN EFI_TCP6_PROTOCOL *Tcp6
  253. )
  254. {
  255. EFI_STATUS Status;
  256. CHAR16 HandleName[80];
  257. EFI_TCP6_CONFIG_DATA Tcp6ConfigData;
  258. if (Tcp6 == NULL) {
  259. return EFI_INVALID_PARAMETER;
  260. }
  261. //
  262. // Format the child name into the string buffer.
  263. //
  264. ZeroMem (&Tcp6ConfigData, sizeof (Tcp6ConfigData));
  265. Status = Tcp6->GetModeData (Tcp6, NULL, &Tcp6ConfigData, NULL, NULL, NULL);
  266. if (!EFI_ERROR (Status)) {
  267. UnicodeSPrint (
  268. HandleName,
  269. sizeof (HandleName),
  270. L"TCPv6(SrcPort=%d, DestPort=%d, ActiveFlag=%d)",
  271. Tcp6ConfigData.AccessPoint.StationPort,
  272. Tcp6ConfigData.AccessPoint.RemotePort,
  273. Tcp6ConfigData.AccessPoint.ActiveFlag
  274. );
  275. } else if (Status == EFI_NOT_STARTED) {
  276. UnicodeSPrint (HandleName, sizeof (HandleName), L"TCPv6(Not started)");
  277. } else {
  278. return Status;
  279. }
  280. if (gTcpControllerNameTable != NULL) {
  281. FreeUnicodeStringTable (gTcpControllerNameTable);
  282. gTcpControllerNameTable = NULL;
  283. }
  284. Status = AddUnicodeString2 (
  285. "eng",
  286. gTcpComponentName.SupportedLanguages,
  287. &gTcpControllerNameTable,
  288. HandleName,
  289. TRUE
  290. );
  291. if (EFI_ERROR (Status)) {
  292. return Status;
  293. }
  294. return AddUnicodeString2 (
  295. "en",
  296. gTcpComponentName2.SupportedLanguages,
  297. &gTcpControllerNameTable,
  298. HandleName,
  299. FALSE
  300. );
  301. }
  302. /**
  303. Retrieves a Unicode string that is the user-readable name of the controller
  304. that is being managed by a driver.
  305. This function retrieves the user-readable name of the controller specified by
  306. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  307. driver specified by This has a user-readable name in the language specified by
  308. Language, then a pointer to the controller name is returned in ControllerName,
  309. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  310. managing the controller specified by ControllerHandle and ChildHandle,
  311. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  312. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  313. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  314. EFI_COMPONENT_NAME_PROTOCOL instance.
  315. @param[in] ControllerHandle The handle of a controller that the driver
  316. specified by This is managing. This handle
  317. specifies the controller whose name is to be
  318. returned.
  319. @param[in] ChildHandle The handle of the child controller to retrieve
  320. the name of. This is an optional parameter that
  321. may be NULL. It will be NULL for device
  322. drivers. It will also be NULL for a bus drivers
  323. that wish to retrieve the name of the bus
  324. controller. It will not be NULL for a bus
  325. driver that wishes to retrieve the name of a
  326. child controller.
  327. @param[in] Language A pointer to a Null-terminated ASCII string
  328. array indicating the language. This is the
  329. language of the driver name that the caller is
  330. requesting, and it must match one of the
  331. languages specified in SupportedLanguages. The
  332. number of languages supported by a driver is up
  333. to the driver writer. Language is specified in
  334. RFC 4646 or ISO 639-2 language code format.
  335. @param[out] ControllerName A pointer to the Unicode string to return.
  336. This Unicode string is the name of the
  337. controller specified by ControllerHandle and
  338. ChildHandle in the language specified by
  339. Language, from the point of view of the driver
  340. specified by This.
  341. @retval EFI_SUCCESS The Unicode string for the user-readable name in
  342. the language specified by Language for the
  343. driver specified by This was returned in
  344. DriverName.
  345. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  346. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
  347. EFI_HANDLE.
  348. @retval EFI_INVALID_PARAMETER Language or ControllerName is NULL.
  349. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  350. managing the controller specified by
  351. ControllerHandle and ChildHandle.
  352. @retval EFI_UNSUPPORTED The driver specified by This does not support
  353. the language specified by Language.
  354. **/
  355. EFI_STATUS
  356. EFIAPI
  357. TcpComponentNameGetControllerName (
  358. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  359. IN EFI_HANDLE ControllerHandle,
  360. IN EFI_HANDLE ChildHandle OPTIONAL,
  361. IN CHAR8 *Language,
  362. OUT CHAR16 **ControllerName
  363. )
  364. {
  365. EFI_STATUS Status;
  366. EFI_TCP4_PROTOCOL *Tcp4;
  367. EFI_TCP6_PROTOCOL *Tcp6;
  368. //
  369. // Only provide names for child handles.
  370. //
  371. if (ChildHandle == NULL) {
  372. return EFI_UNSUPPORTED;
  373. }
  374. //
  375. // Make sure this driver produced ChildHandle
  376. //
  377. Status = EfiTestChildHandle (
  378. ControllerHandle,
  379. ChildHandle,
  380. &gEfiIp6ProtocolGuid
  381. );
  382. if (!EFI_ERROR (Status)) {
  383. //
  384. // Retrieve an instance of a produced protocol from ChildHandle
  385. //
  386. Status = gBS->OpenProtocol (
  387. ChildHandle,
  388. &gEfiTcp6ProtocolGuid,
  389. (VOID **)&Tcp6,
  390. NULL,
  391. NULL,
  392. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  393. );
  394. if (EFI_ERROR (Status)) {
  395. return Status;
  396. }
  397. //
  398. // Update the component name for this child handle.
  399. //
  400. Status = UpdateTcp6Name (Tcp6);
  401. if (EFI_ERROR (Status)) {
  402. return Status;
  403. }
  404. }
  405. //
  406. // Make sure this driver is currently managing ControllHandle
  407. //
  408. Status = EfiTestChildHandle (
  409. ControllerHandle,
  410. ChildHandle,
  411. &gEfiIp4ProtocolGuid
  412. );
  413. if (!EFI_ERROR (Status)) {
  414. //
  415. // Retrieve an instance of a produced protocol from ChildHandle
  416. //
  417. Status = gBS->OpenProtocol (
  418. ChildHandle,
  419. &gEfiTcp4ProtocolGuid,
  420. (VOID **)&Tcp4,
  421. NULL,
  422. NULL,
  423. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  424. );
  425. if (EFI_ERROR (Status)) {
  426. return Status;
  427. }
  428. //
  429. // Update the component name for this child handle.
  430. //
  431. Status = UpdateTcp4Name (Tcp4);
  432. if (EFI_ERROR (Status)) {
  433. return Status;
  434. }
  435. }
  436. return LookupUnicodeString2 (
  437. Language,
  438. This->SupportedLanguages,
  439. gTcpControllerNameTable,
  440. ControllerName,
  441. (BOOLEAN)(This == &gTcpComponentName)
  442. );
  443. }