ComponentName.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /** @file
  2. UEFI Component Name(2) protocol implementation for SnpDxe driver.
  3. Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "Snp.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 This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  19. EFI_COMPONENT_NAME_PROTOCOL instance.
  20. @param Language[in] 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 DriverName[out] 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. SimpleNetworkComponentNameGetDriverName (
  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 This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  59. EFI_COMPONENT_NAME_PROTOCOL instance.
  60. @param ControllerHandle[in] 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 ChildHandle[in] 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 Language[in] 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 ControllerName[out] 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. SimpleNetworkComponentNameGetControllerName (
  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 gSimpleNetworkComponentName = {
  114. SimpleNetworkComponentNameGetDriverName,
  115. SimpleNetworkComponentNameGetControllerName,
  116. "eng"
  117. };
  118. //
  119. // EFI Component Name 2 Protocol
  120. //
  121. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gSimpleNetworkComponentName2 = {
  122. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)SimpleNetworkComponentNameGetDriverName,
  123. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)SimpleNetworkComponentNameGetControllerName,
  124. "en"
  125. };
  126. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSimpleNetworkDriverNameTable[] = {
  127. {
  128. "eng;en",
  129. L"Simple Network Protocol Driver"
  130. },
  131. {
  132. NULL,
  133. NULL
  134. }
  135. };
  136. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gSimpleNetworkControllerNameTable = 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 This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  146. EFI_COMPONENT_NAME_PROTOCOL instance.
  147. @param Language[in] 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 DriverName[out] 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. SimpleNetworkComponentNameGetDriverName (
  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. mSimpleNetworkDriverNameTable,
  179. DriverName,
  180. (BOOLEAN)(This == &gSimpleNetworkComponentName)
  181. );
  182. }
  183. /**
  184. Update the component name for the Snp child handle.
  185. @param Snp[in] A pointer to the EFI_SIMPLE_NETWORK_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_SIMPLE_NETWORK_PROTOCOL *Snp
  192. )
  193. {
  194. EFI_STATUS Status;
  195. CHAR16 HandleName[80];
  196. UINTN OffSet;
  197. UINTN Index;
  198. if (Snp == NULL) {
  199. return EFI_INVALID_PARAMETER;
  200. }
  201. OffSet = 0;
  202. OffSet += UnicodeSPrint (
  203. HandleName,
  204. sizeof (HandleName),
  205. L"SNP (MAC="
  206. );
  207. for (Index = 0; Index < Snp->Mode->HwAddressSize; Index++) {
  208. OffSet += UnicodeSPrint (
  209. HandleName + OffSet,
  210. sizeof (HandleName) - OffSet * sizeof (CHAR16),
  211. L"%02X-",
  212. Snp->Mode->CurrentAddress.Addr[Index]
  213. );
  214. }
  215. ASSERT (OffSet > 0);
  216. //
  217. // Remove the last '-'
  218. //
  219. OffSet--;
  220. OffSet += UnicodeSPrint (
  221. HandleName + OffSet,
  222. sizeof (HandleName) - OffSet * sizeof (CHAR16),
  223. L")"
  224. );
  225. if (gSimpleNetworkControllerNameTable != NULL) {
  226. FreeUnicodeStringTable (gSimpleNetworkControllerNameTable);
  227. gSimpleNetworkControllerNameTable = NULL;
  228. }
  229. Status = AddUnicodeString2 (
  230. "eng",
  231. gSimpleNetworkComponentName.SupportedLanguages,
  232. &gSimpleNetworkControllerNameTable,
  233. HandleName,
  234. TRUE
  235. );
  236. if (EFI_ERROR (Status)) {
  237. return Status;
  238. }
  239. return AddUnicodeString2 (
  240. "en",
  241. gSimpleNetworkComponentName2.SupportedLanguages,
  242. &gSimpleNetworkControllerNameTable,
  243. HandleName,
  244. FALSE
  245. );
  246. }
  247. /**
  248. Retrieves a Unicode string that is the user readable name of the controller
  249. that is being managed by a driver.
  250. This function retrieves the user readable name of the controller specified by
  251. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  252. driver specified by This has a user readable name in the language specified by
  253. Language, then a pointer to the controller name is returned in ControllerName,
  254. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  255. managing the controller specified by ControllerHandle and ChildHandle,
  256. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  257. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  258. Currently not implemented.
  259. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  260. EFI_COMPONENT_NAME_PROTOCOL instance.
  261. @param ControllerHandle[in] The handle of a controller that the driver
  262. specified by This is managing. This handle
  263. specifies the controller whose name is to be
  264. returned.
  265. @param ChildHandle[in] The handle of the child controller to retrieve
  266. the name of. This is an optional parameter that
  267. may be NULL. It will be NULL for device
  268. drivers. It will also be NULL for a bus drivers
  269. that wish to retrieve the name of the bus
  270. controller. It will not be NULL for a bus
  271. driver that wishes to retrieve the name of a
  272. child controller.
  273. @param Language[in] A pointer to a Null-terminated ASCII string
  274. array indicating the language. This is the
  275. language of the driver name that the caller is
  276. requesting, and it must match one of the
  277. languages specified in SupportedLanguages. The
  278. number of languages supported by a driver is up
  279. to the driver writer. Language is specified in
  280. RFC 4646 or ISO 639-2 language code format.
  281. @param ControllerName[out] A pointer to the Unicode string to return.
  282. This Unicode string is the name of the
  283. controller specified by ControllerHandle and
  284. ChildHandle in the language specified by
  285. Language from the point of view of the driver
  286. specified by This.
  287. @retval EFI_SUCCESS The Unicode string for the user readable name in
  288. the language specified by Language for the
  289. driver specified by This was returned in
  290. DriverName.
  291. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  292. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  293. EFI_HANDLE.
  294. @retval EFI_INVALID_PARAMETER Language is NULL.
  295. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  296. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  297. managing the controller specified by
  298. ControllerHandle and ChildHandle.
  299. @retval EFI_UNSUPPORTED The driver specified by This does not support
  300. the language specified by Language.
  301. **/
  302. EFI_STATUS
  303. EFIAPI
  304. SimpleNetworkComponentNameGetControllerName (
  305. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  306. IN EFI_HANDLE ControllerHandle,
  307. IN EFI_HANDLE ChildHandle OPTIONAL,
  308. IN CHAR8 *Language,
  309. OUT CHAR16 **ControllerName
  310. )
  311. {
  312. EFI_STATUS Status;
  313. EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
  314. if (ChildHandle != NULL) {
  315. return EFI_UNSUPPORTED;
  316. }
  317. //
  318. // Make sure this driver is currently managing ControllHandle
  319. //
  320. Status = EfiTestManagedDevice (
  321. ControllerHandle,
  322. gSimpleNetworkDriverBinding.DriverBindingHandle,
  323. &gEfiSimpleNetworkProtocolGuid
  324. );
  325. if (EFI_ERROR (Status)) {
  326. return Status;
  327. }
  328. //
  329. // Retrieve an instance of a produced protocol from ControllerHandle
  330. //
  331. Status = gBS->OpenProtocol (
  332. ControllerHandle,
  333. &gEfiSimpleNetworkProtocolGuid,
  334. (VOID **)&Snp,
  335. NULL,
  336. NULL,
  337. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  338. );
  339. if (EFI_ERROR (Status)) {
  340. return Status;
  341. }
  342. //
  343. // Update the component name for this child handle.
  344. //
  345. Status = UpdateName (Snp);
  346. if (EFI_ERROR (Status)) {
  347. return Status;
  348. }
  349. return LookupUnicodeString2 (
  350. Language,
  351. This->SupportedLanguages,
  352. gSimpleNetworkControllerNameTable,
  353. ControllerName,
  354. (BOOLEAN)(This == &gSimpleNetworkComponentName)
  355. );
  356. }