ComponentName.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /** @file
  2. UEFI Component Name(2) protocol implementation for iSCSI.
  3. Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "IScsiImpl.h"
  7. //
  8. // EFI Component Name Protocol
  9. //
  10. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIScsiComponentName = {
  11. IScsiComponentNameGetDriverName,
  12. IScsiComponentNameGetControllerName,
  13. "eng"
  14. };
  15. //
  16. // EFI Component Name 2 Protocol
  17. //
  18. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIScsiComponentName2 = {
  19. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)IScsiComponentNameGetDriverName,
  20. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)IScsiComponentNameGetControllerName,
  21. "en"
  22. };
  23. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTable[] = {
  24. {
  25. "eng;en",
  26. L"iSCSI Driver"
  27. },
  28. {
  29. NULL,
  30. NULL
  31. }
  32. };
  33. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIScsiControllerNameTable = 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. IScsiComponentNameGetDriverName (
  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. mIScsiDriverNameTable,
  76. DriverName,
  77. (BOOLEAN)(This == &gIScsiComponentName)
  78. );
  79. }
  80. /**
  81. Update the component name for the iSCSI instance.
  82. @param[in] IScsiExtScsiPassThru A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
  83. @param[in] Ipv6Flag TRUE if IP6 network stack is used.
  84. @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
  85. @retval EFI_INVALID_PARAMETER The input parameter is invalid.
  86. @retval EFI_UNSUPPORTED Can't get the corresponding NIC info from the Controller handle.
  87. **/
  88. EFI_STATUS
  89. UpdateName (
  90. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru,
  91. IN BOOLEAN Ipv6Flag
  92. )
  93. {
  94. EFI_STATUS Status;
  95. CHAR16 HandleName[80];
  96. ISCSI_DRIVER_DATA *Private;
  97. UINT8 NicIndex;
  98. if (IScsiExtScsiPassThru == NULL) {
  99. return EFI_INVALID_PARAMETER;
  100. }
  101. Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (IScsiExtScsiPassThru);
  102. NicIndex = Private->Session->ConfigData->NicIndex;
  103. UnicodeSPrint (
  104. HandleName,
  105. sizeof (HandleName),
  106. L"iSCSI (%s, NicIndex=%d)",
  107. Ipv6Flag ? L"IPv6" : L"IPv4",
  108. NicIndex
  109. );
  110. if (gIScsiControllerNameTable != NULL) {
  111. FreeUnicodeStringTable (gIScsiControllerNameTable);
  112. gIScsiControllerNameTable = NULL;
  113. }
  114. Status = AddUnicodeString2 (
  115. "eng",
  116. gIScsiComponentName.SupportedLanguages,
  117. &gIScsiControllerNameTable,
  118. HandleName,
  119. TRUE
  120. );
  121. if (EFI_ERROR (Status)) {
  122. return Status;
  123. }
  124. return AddUnicodeString2 (
  125. "en",
  126. gIScsiComponentName2.SupportedLanguages,
  127. &gIScsiControllerNameTable,
  128. HandleName,
  129. FALSE
  130. );
  131. }
  132. /**
  133. Retrieves a Unicode string that is the user readable name of the controller
  134. that is being managed by a driver.
  135. This function retrieves the user readable name of the controller specified by
  136. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  137. driver specified by This has a user readable name in the language specified by
  138. Language, then a pointer to the controller name is returned in ControllerName,
  139. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  140. managing the controller specified by ControllerHandle and ChildHandle,
  141. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  142. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  143. @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  144. EFI_COMPONENT_NAME_PROTOCOL instance.
  145. @param[in] ControllerHandle The handle of a controller that the driver
  146. specified by This is managing. This handle
  147. specifies the controller whose name is to be
  148. returned.
  149. @param[in] ChildHandle The handle of the child controller to retrieve
  150. the name of. This is an optional parameter that
  151. may be NULL. It will be NULL for device
  152. drivers. It will also be NULL for a bus drivers
  153. that wish to retrieve the name of the bus
  154. controller. It will not be NULL for a bus
  155. driver that wishes to retrieve the name of a
  156. child controller.
  157. @param[in] Language A pointer to a Null-terminated ASCII string
  158. array indicating the language. This is the
  159. language of the driver name that the caller is
  160. requesting, and it must match one of the
  161. languages specified in SupportedLanguages. The
  162. number of languages supported by a driver is up
  163. to the driver writer. Language is specified in
  164. RFC 4646 or ISO 639-2 language code format.
  165. @param[out] ControllerName A pointer to the Unicode string to return.
  166. This Unicode string is the name of the
  167. controller specified by ControllerHandle and
  168. ChildHandle in the language specified by
  169. Language, from the point of view of the driver
  170. specified by This.
  171. @retval EFI_SUCCESS The Unicode string for the user readable name in
  172. the language specified by Language for the
  173. driver specified by This was returned in
  174. DriverName.
  175. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  176. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
  177. EFI_HANDLE.
  178. @retval EFI_INVALID_PARAMETER Language is NULL.
  179. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  180. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  181. managing the controller specified by
  182. ControllerHandle and ChildHandle.
  183. @retval EFI_UNSUPPORTED The driver specified by This does not support
  184. the language specified by Language.
  185. **/
  186. EFI_STATUS
  187. EFIAPI
  188. IScsiComponentNameGetControllerName (
  189. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  190. IN EFI_HANDLE ControllerHandle,
  191. IN EFI_HANDLE ChildHandle OPTIONAL,
  192. IN CHAR8 *Language,
  193. OUT CHAR16 **ControllerName
  194. )
  195. {
  196. EFI_STATUS Status;
  197. EFI_HANDLE IScsiController;
  198. BOOLEAN Ipv6Flag;
  199. EFI_GUID *IScsiPrivateGuid;
  200. ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
  201. EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru;
  202. if (ControllerHandle == NULL) {
  203. return EFI_UNSUPPORTED;
  204. }
  205. //
  206. // Get the handle of the controller we are controlling.
  207. //
  208. IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);
  209. if (IScsiController != NULL) {
  210. IScsiPrivateGuid = &gIScsiV4PrivateGuid;
  211. Ipv6Flag = FALSE;
  212. } else {
  213. IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);
  214. if (IScsiController != NULL) {
  215. IScsiPrivateGuid = &gIScsiV6PrivateGuid;
  216. Ipv6Flag = TRUE;
  217. } else {
  218. return EFI_UNSUPPORTED;
  219. }
  220. }
  221. Status = gBS->OpenProtocol (
  222. IScsiController,
  223. IScsiPrivateGuid,
  224. (VOID **)&IScsiIdentifier,
  225. NULL,
  226. NULL,
  227. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  228. );
  229. if (EFI_ERROR (Status)) {
  230. return Status;
  231. }
  232. if (ChildHandle != NULL) {
  233. if (!Ipv6Flag) {
  234. //
  235. // Make sure this driver produced ChildHandle
  236. //
  237. Status = EfiTestChildHandle (
  238. ControllerHandle,
  239. ChildHandle,
  240. &gEfiTcp4ProtocolGuid
  241. );
  242. if (EFI_ERROR (Status)) {
  243. return Status;
  244. }
  245. } else {
  246. //
  247. // Make sure this driver produced ChildHandle
  248. //
  249. Status = EfiTestChildHandle (
  250. ControllerHandle,
  251. ChildHandle,
  252. &gEfiTcp6ProtocolGuid
  253. );
  254. if (EFI_ERROR (Status)) {
  255. return Status;
  256. }
  257. }
  258. //
  259. // Retrieve an instance of a produced protocol from ChildHandle
  260. //
  261. Status = gBS->OpenProtocol (
  262. ChildHandle,
  263. &gEfiExtScsiPassThruProtocolGuid,
  264. (VOID **)&IScsiExtScsiPassThru,
  265. NULL,
  266. NULL,
  267. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  268. );
  269. if (EFI_ERROR (Status)) {
  270. return Status;
  271. }
  272. //
  273. // Update the component name for this child handle.
  274. //
  275. Status = UpdateName (IScsiExtScsiPassThru, Ipv6Flag);
  276. if (EFI_ERROR (Status)) {
  277. return Status;
  278. }
  279. }
  280. return LookupUnicodeString2 (
  281. Language,
  282. This->SupportedLanguages,
  283. gIScsiControllerNameTable,
  284. ControllerName,
  285. (BOOLEAN)(This == &gIScsiComponentName)
  286. );
  287. }