ComponentName.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /** @file
  2. UEFI Component Name(2) protocol implementation for MnpDxe driver.
  3. Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "MnpImpl.h"
  7. //
  8. // EFI Component Name Protocol
  9. //
  10. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName = {
  11. MnpComponentNameGetDriverName,
  12. MnpComponentNameGetControllerName,
  13. "eng"
  14. };
  15. //
  16. // EFI Component Name 2 Protocol
  17. //
  18. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2 = {
  19. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)MnpComponentNameGetDriverName,
  20. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)MnpComponentNameGetControllerName,
  21. "en"
  22. };
  23. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
  24. {
  25. "eng;en",
  26. L"MNP Network Service Driver"
  27. },
  28. {
  29. NULL,
  30. NULL
  31. }
  32. };
  33. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMnpControllerNameTable = NULL;
  34. /**
  35. Retrieves a Unicode string that is the user readable name of the driver.
  36. This function retrieves the user readable name of a driver in the form of a
  37. Unicode string. If the driver specified by This has a user readable name in
  38. the language specified by Language, then a pointer to the driver name is
  39. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  40. by This does not support the language specified by Language,
  41. then EFI_UNSUPPORTED is returned.
  42. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  43. EFI_COMPONENT_NAME_PROTOCOL instance.
  44. @param[in] Language A pointer to a Null-terminated ASCII string
  45. array indicating the language. This is the
  46. language of the driver name that the caller is
  47. requesting, and it must match one of the
  48. languages specified in SupportedLanguages. The
  49. number of languages supported by a driver is up
  50. to the driver writer. Language is specified
  51. in RFC 4646 or ISO 639-2 language code format.
  52. @param[out] DriverName A pointer to the Unicode string to return.
  53. This Unicode string is the name of the
  54. driver specified by This in the language
  55. specified by Language.
  56. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  57. This and the language specified by Language was
  58. returned in DriverName.
  59. @retval EFI_INVALID_PARAMETER Language is NULL.
  60. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  61. @retval EFI_UNSUPPORTED The driver specified by This does not support
  62. the language specified by Language.
  63. **/
  64. EFI_STATUS
  65. EFIAPI
  66. MnpComponentNameGetDriverName (
  67. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  68. IN CHAR8 *Language,
  69. OUT CHAR16 **DriverName
  70. )
  71. {
  72. return LookupUnicodeString2 (
  73. Language,
  74. This->SupportedLanguages,
  75. mMnpDriverNameTable,
  76. DriverName,
  77. (BOOLEAN)(This == &gMnpComponentName)
  78. );
  79. }
  80. /**
  81. Update the component name for the MNP child handle.
  82. @param Mnp[in] A pointer to the EFI_MANAGED_NETWORK_PROTOCOL.
  83. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  84. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  85. **/
  86. EFI_STATUS
  87. UpdateName (
  88. IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp
  89. )
  90. {
  91. EFI_STATUS Status;
  92. MNP_INSTANCE_DATA *Instance;
  93. CHAR16 HandleName[80];
  94. EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;
  95. EFI_SIMPLE_NETWORK_MODE SnpModeData;
  96. UINTN OffSet;
  97. UINTN Index;
  98. if (Mnp == NULL) {
  99. return EFI_INVALID_PARAMETER;
  100. }
  101. Instance = MNP_INSTANCE_DATA_FROM_THIS (Mnp);
  102. //
  103. // Format the child name into the string buffer as:
  104. // MNP (MAC=FF-FF-FF-FF-FF-FF, ProtocolType=0x0800, VlanId=0)
  105. //
  106. Status = Mnp->GetModeData (Mnp, &MnpConfigData, &SnpModeData);
  107. if (!EFI_ERROR (Status)) {
  108. OffSet = 0;
  109. //
  110. // Print the MAC address.
  111. //
  112. OffSet += UnicodeSPrint (
  113. HandleName,
  114. sizeof (HandleName),
  115. L"MNP (MAC="
  116. );
  117. for (Index = 0; Index < SnpModeData.HwAddressSize; Index++) {
  118. OffSet += UnicodeSPrint (
  119. HandleName + OffSet,
  120. sizeof (HandleName) - OffSet * sizeof (CHAR16),
  121. L"%02X-",
  122. SnpModeData.CurrentAddress.Addr[Index]
  123. );
  124. }
  125. ASSERT (OffSet > 0);
  126. //
  127. // Remove the last '-'
  128. //
  129. OffSet--;
  130. //
  131. // Print the ProtocolType and VLAN ID for this instance.
  132. //
  133. OffSet += UnicodeSPrint (
  134. HandleName + OffSet,
  135. sizeof (HandleName) - OffSet * sizeof (CHAR16),
  136. L", ProtocolType=0x%X, VlanId=%d)",
  137. MnpConfigData.ProtocolTypeFilter,
  138. Instance->MnpServiceData->VlanId
  139. );
  140. } else if (Status == EFI_NOT_STARTED) {
  141. UnicodeSPrint (
  142. HandleName,
  143. sizeof (HandleName),
  144. L"MNP (Not started)"
  145. );
  146. } else {
  147. return Status;
  148. }
  149. if (gMnpControllerNameTable != NULL) {
  150. FreeUnicodeStringTable (gMnpControllerNameTable);
  151. gMnpControllerNameTable = NULL;
  152. }
  153. Status = AddUnicodeString2 (
  154. "eng",
  155. gMnpComponentName.SupportedLanguages,
  156. &gMnpControllerNameTable,
  157. HandleName,
  158. TRUE
  159. );
  160. if (EFI_ERROR (Status)) {
  161. return Status;
  162. }
  163. return AddUnicodeString2 (
  164. "en",
  165. gMnpComponentName2.SupportedLanguages,
  166. &gMnpControllerNameTable,
  167. HandleName,
  168. FALSE
  169. );
  170. }
  171. /**
  172. Retrieves a Unicode string that is the user readable name of the controller
  173. that is being managed by a driver.
  174. This function retrieves the user readable name of the controller specified by
  175. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  176. driver specified by This has a user readable name in the language specified by
  177. Language, then a pointer to the controller name is returned in ControllerName,
  178. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  179. managing the controller specified by ControllerHandle and ChildHandle,
  180. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  181. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  182. Currently not implemented.
  183. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  184. EFI_COMPONENT_NAME_PROTOCOL instance.
  185. @param[in] ControllerHandle The handle of a controller that the driver
  186. specified by This is managing. This handle
  187. specifies the controller whose name is to be
  188. returned.
  189. @param[in] ChildHandle The handle of the child controller to retrieve
  190. the name of. This is an optional parameter that
  191. may be NULL. It will be NULL for device
  192. drivers. It will also be NULL for a bus drivers
  193. that wish to retrieve the name of the bus
  194. controller. It will not be NULL for a bus
  195. driver that wishes to retrieve the name of a
  196. child controller.
  197. @param[in] Language A pointer to a Null-terminated ASCII string
  198. array indicating the language. This is the
  199. language of the driver name that the caller is
  200. requesting, and it must match one of the
  201. languages specified in SupportedLanguages. The
  202. number of languages supported by a driver is up
  203. to the driver writer. Language is specified in
  204. RFC 4646 or ISO 639-2 language code format.
  205. @param[out] ControllerName A pointer to the Unicode string to return.
  206. This Unicode string is the name of the
  207. controller specified by ControllerHandle and
  208. ChildHandle in the language specified by
  209. Language from the point of view of the driver
  210. specified by This.
  211. @retval EFI_SUCCESS The Unicode string for the user readable name
  212. specified by This, ControllerHandle, ChildHandle,
  213. and Language was returned in ControllerName.
  214. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  215. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  216. EFI_HANDLE.
  217. @retval EFI_INVALID_PARAMETER Language is NULL.
  218. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  219. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  220. managing the controller specified by
  221. ControllerHandle and ChildHandle.
  222. @retval EFI_UNSUPPORTED The driver specified by This does not support
  223. the language specified by Language.
  224. **/
  225. EFI_STATUS
  226. EFIAPI
  227. MnpComponentNameGetControllerName (
  228. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  229. IN EFI_HANDLE ControllerHandle,
  230. IN EFI_HANDLE ChildHandle OPTIONAL,
  231. IN CHAR8 *Language,
  232. OUT CHAR16 **ControllerName
  233. )
  234. {
  235. EFI_STATUS Status;
  236. EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
  237. //
  238. // Only provide names for MNP child handles.
  239. //
  240. if (ChildHandle == NULL) {
  241. return EFI_UNSUPPORTED;
  242. }
  243. //
  244. // Make sure this driver is currently managing ControllerHandle
  245. //
  246. Status = EfiTestManagedDevice (
  247. ControllerHandle,
  248. gMnpDriverBinding.DriverBindingHandle,
  249. &gEfiSimpleNetworkProtocolGuid
  250. );
  251. if (EFI_ERROR (Status)) {
  252. return Status;
  253. }
  254. //
  255. // Make sure this driver produced ChildHandle
  256. //
  257. Status = EfiTestChildHandle (
  258. ControllerHandle,
  259. ChildHandle,
  260. &gEfiManagedNetworkServiceBindingProtocolGuid
  261. );
  262. if (EFI_ERROR (Status)) {
  263. return Status;
  264. }
  265. //
  266. // Retrieve an instance of a produced protocol from ChildHandle
  267. //
  268. Status = gBS->OpenProtocol (
  269. ChildHandle,
  270. &gEfiManagedNetworkProtocolGuid,
  271. (VOID **)&Mnp,
  272. NULL,
  273. NULL,
  274. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  275. );
  276. if (EFI_ERROR (Status)) {
  277. return Status;
  278. }
  279. //
  280. // Update the component name for this child handle.
  281. //
  282. Status = UpdateName (Mnp);
  283. if (EFI_ERROR (Status)) {
  284. return Status;
  285. }
  286. return LookupUnicodeString2 (
  287. Language,
  288. This->SupportedLanguages,
  289. gMnpControllerNameTable,
  290. ControllerName,
  291. (BOOLEAN)(This == &gMnpComponentName)
  292. );
  293. }