2 * EFI device path interface
4 * Copyright (c) 2017 Heinrich Schuchardt
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <efi_loader.h>
12 #define MAC_OUTPUT_LEN 22
13 #define UNKNOWN_OUTPUT_LEN 23
15 const efi_guid_t efi_guid_device_path_to_text_protocol
=
16 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID
;
18 static uint16_t *efi_convert_device_node_to_text(
19 struct efi_device_path_protocol
*device_node
,
23 unsigned long buffer_size
;
25 uint16_t *buffer
= NULL
;
28 switch (device_node
->type
) {
29 case DEVICE_PATH_TYPE_END
:
31 case DEVICE_PATH_TYPE_MESSAGING_DEVICE
:
32 switch (device_node
->sub_type
) {
33 case DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR
: {
34 struct efi_device_path_mac_addr
*dp
=
35 (struct efi_device_path_mac_addr
*)device_node
;
37 if (dp
->if_type
!= 0 && dp
->if_type
!= 1)
39 r
= efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES
,
44 sprintf((char *)buffer
,
45 "MAC(%02x%02x%02x%02x%02x%02x,0x%1x)",
46 dp
->mac
.addr
[0], dp
->mac
.addr
[1],
47 dp
->mac
.addr
[2], dp
->mac
.addr
[3],
48 dp
->mac
.addr
[4], dp
->mac
.addr
[5],
50 for (i
= MAC_OUTPUT_LEN
- 1; i
>= 0; --i
)
51 buffer
[i
] = ((uint8_t *)buffer
)[i
];
56 case DEVICE_PATH_TYPE_MEDIA_DEVICE
:
57 switch (device_node
->sub_type
) {
58 case DEVICE_PATH_SUB_TYPE_FILE_PATH
:
59 buffer_size
= device_node
->length
- 4;
60 r
= efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES
,
61 buffer_size
, (void **) &buffer
);
64 memcpy(buffer
, device_node
->data
, buffer_size
);
71 * For all node types that we do not yet support return
72 * 'UNKNOWN(type,subtype)'.
75 r
= efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES
,
76 2 * UNKNOWN_OUTPUT_LEN
,
80 sprintf((char *)buffer
,
83 device_node
->sub_type
);
84 for (i
= UNKNOWN_OUTPUT_LEN
- 1; i
>= 0; --i
)
85 buffer
[i
] = ((uint8_t *)buffer
)[i
];
91 static uint16_t EFIAPI
*efi_convert_device_node_to_text_ext(
92 struct efi_device_path_protocol
*device_node
,
98 EFI_ENTRY("%p, %d, %d", device_node
, display_only
, allow_shortcuts
);
100 buffer
= efi_convert_device_node_to_text(device_node
, display_only
,
103 EFI_EXIT(EFI_SUCCESS
);
107 static uint16_t EFIAPI
*efi_convert_device_path_to_text(
108 struct efi_device_path_protocol
*device_path
,
110 bool allow_shortcuts
)
114 EFI_ENTRY("%p, %d, %d", device_path
, display_only
, allow_shortcuts
);
117 * Our device paths are all of depth one. So its is sufficient to
118 * to convert the first node.
120 buffer
= efi_convert_device_node_to_text(device_path
, display_only
,
123 EFI_EXIT(EFI_SUCCESS
);
127 const struct efi_device_path_to_text_protocol efi_device_path_to_text
= {
128 .convert_device_node_to_text
= efi_convert_device_node_to_text_ext
,
129 .convert_device_path_to_text
= efi_convert_device_path_to_text
,