OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
BmBootDescription.c
Go to the documentation of this file.
1
11#include "NetworkBootInternal.h"
12
20CHAR16 *
22 IN EFI_HANDLE Handle
23 )
24{
25 EFI_STATUS Status;
26 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
27 MAC_ADDR_DEVICE_PATH *Mac;
28 VLAN_DEVICE_PATH *Vlan;
29 EFI_DEVICE_PATH_PROTOCOL *Ip;
30 EFI_DEVICE_PATH_PROTOCOL *Uri;
31 CHAR16 *Description;
32 UINTN DescriptionSize;
33
34 Status = gBS->OpenProtocol (
35 Handle,
36 &gEfiLoadFileProtocolGuid,
37 NULL,
39 Handle,
40 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
41 );
42 if (EFI_ERROR (Status)) {
43 return NULL;
44 }
45
46 Status = gBS->OpenProtocol (
47 Handle,
49 (VOID **)&DevicePath,
51 Handle,
52 EFI_OPEN_PROTOCOL_GET_PROTOCOL
53 );
54 if (EFI_ERROR (Status) || (DevicePath == NULL)) {
55 return NULL;
56 }
57
58 //
59 // The PXE device path is like:
60 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]
61 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv4(...)
62 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)
63 //
64 // The HTTP device path is like:
65 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv4(...)[/Dns(...)]/Uri(...)
66 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)[/Dns(...)]/Uri(...)
67 //
68 while (!IsDevicePathEnd (DevicePath) &&
69 ((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) ||
70 (DevicePathSubType (DevicePath) != MSG_MAC_ADDR_DP))
71 )
72 {
73 DevicePath = NextDevicePathNode (DevicePath);
74 }
75
76 if (IsDevicePathEnd (DevicePath)) {
77 return NULL;
78 }
79
80 Mac = (MAC_ADDR_DEVICE_PATH *)DevicePath;
81 DevicePath = NextDevicePathNode (DevicePath);
82
83 //
84 // Locate the optional Vlan node
85 //
86 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
87 (DevicePathSubType (DevicePath) == MSG_VLAN_DP)
88 )
89 {
90 Vlan = (VLAN_DEVICE_PATH *)DevicePath;
91 DevicePath = NextDevicePathNode (DevicePath);
92 } else {
93 Vlan = NULL;
94 }
95
96 //
97 // Skip the optional Wi-Fi node
98 //
99 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
100 (DevicePathSubType (DevicePath) == MSG_WIFI_DP)
101 )
102 {
103 DevicePath = NextDevicePathNode (DevicePath);
104 }
105
106 //
107 // Locate the IP node
108 //
109 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
110 ((DevicePathSubType (DevicePath) == MSG_IPv4_DP) ||
111 (DevicePathSubType (DevicePath) == MSG_IPv6_DP))
112 )
113 {
114 Ip = DevicePath;
115 DevicePath = NextDevicePathNode (DevicePath);
116 } else {
117 Ip = NULL;
118 }
119
120 //
121 // Skip the optional DNS node
122 //
123 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
124 (DevicePathSubType (DevicePath) == MSG_DNS_DP)
125 )
126 {
127 DevicePath = NextDevicePathNode (DevicePath);
128 }
129
130 //
131 // Locate the URI node
132 //
133 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
134 (DevicePathSubType (DevicePath) == MSG_URI_DP)
135 )
136 {
137 Uri = DevicePath;
138 DevicePath = NextDevicePathNode (DevicePath);
139 } else {
140 Uri = NULL;
141 }
142
143 //
144 // Build description like below:
145 // "PXE Boot IPv6 (MAC:11-22-33-44-55-66 VLAN1)"
146 // "HTTP Boot IPv4 (MAC:11-22-33-44-55-66)"
147 //
148 DescriptionSize = sizeof (L"HTTP Boot IPv6 (MAC:11-22-33-44-55-66 VLAN65535)");
149 Description = AllocatePool (DescriptionSize);
150 ASSERT (Description != NULL);
151 UnicodeSPrint (
152 Description,
153 DescriptionSize,
154 (Vlan == NULL) ?
155 L"%s Boot IPv%d (MAC:%02x-%02x-%02x-%02x-%02x-%02x)" :
156 L"%s Boot IPv%d (MAC:%02x-%02x-%02x-%02x-%02x-%02x VLAN%d)",
157 (Uri == NULL) ? L"PXE" : L"HTTP",
158 ((Ip == NULL) || (DevicePathSubType (Ip) == MSG_IPv4_DP)) ? 4 : 6,
159 Mac->MacAddress.Addr[0],
160 Mac->MacAddress.Addr[1],
161 Mac->MacAddress.Addr[2],
162 Mac->MacAddress.Addr[3],
163 Mac->MacAddress.Addr[4],
164 Mac->MacAddress.Addr[5],
165 (Vlan == NULL) ? 0 : Vlan->VlanId
166 );
167 return Description;
168}
CHAR16 * BmGetNetworkDescription(IN EFI_HANDLE Handle)
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
APPLE_EVENT_HANDLE Handle
Definition OcTypingLib.h:45
EFI_GUID gEfiDevicePathProtocolGuid
#define ASSERT(x)
Definition coder.h:55