]>
Commit | Line | Data |
---|---|---|
cc5faa78 AC |
1 | /** @file\r |
2 | PCI/PCIe network interface instace of RedfishPlatformHostInterfaceLib\r | |
3 | \r | |
4 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r | |
259e1e04 | 6 | Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>\r |
cc5faa78 AC |
7 | \r |
8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
9 | \r | |
10 | **/\r | |
11 | \r | |
12 | #include <Uefi.h>\r | |
13 | #include <Library/BaseLib.h>\r | |
14 | #include <Library/BaseMemoryLib.h>\r | |
15 | #include <Library/DebugLib.h>\r | |
16 | #include <Library/DevicePathLib.h>\r | |
17 | #include <Library/MemoryAllocationLib.h>\r | |
18 | #include <Library/PrintLib.h>\r | |
19 | #include <Library/RedfishHostInterfaceLib.h>\r | |
20 | #include <Library/UefiLib.h>\r | |
21 | #include <Library/UefiBootServicesTableLib.h>\r | |
22 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
23 | \r | |
24 | #include <Pcd/RestExServiceDevicePath.h>\r | |
25 | #include <Guid/GlobalVariable.h>\r | |
26 | \r | |
27 | #define VERBOSE_COLUME_SIZE (16)\r | |
28 | \r | |
29 | REDFISH_OVER_IP_PROTOCOL_DATA *mRedfishOverIpProtocolData;\r | |
a550d468 | 30 | UINT8 mRedfishProtocolDataSize;\r |
cc5faa78 AC |
31 | \r |
32 | /**\r | |
33 | Get the MAC address of NIC.\r | |
34 | \r | |
35 | @param[out] MacAddress Pointer to retrieve MAC address\r | |
36 | \r | |
37 | @retval EFI_SUCCESS MAC address is returned in MacAddress\r | |
38 | \r | |
39 | **/\r | |
40 | EFI_STATUS\r | |
41 | GetMacAddressInformation (\r | |
a550d468 | 42 | OUT EFI_MAC_ADDRESS *MacAddress\r |
cc5faa78 AC |
43 | )\r |
44 | {\r | |
a550d468 MK |
45 | MAC_ADDR_DEVICE_PATH *Mac;\r |
46 | REST_EX_SERVICE_DEVICE_PATH_DATA *RestExServiceDevicePathData;\r | |
47 | EFI_DEVICE_PATH_PROTOCOL *RestExServiceDevicePath;\r | |
48 | MAC_ADDR_DEVICE_PATH *MacAddressDevicePath;\r | |
49 | \r | |
50 | Mac = NULL;\r | |
51 | RestExServiceDevicePathData = NULL;\r | |
52 | RestExServiceDevicePath = NULL;\r | |
53 | \r | |
54 | RestExServiceDevicePathData = (REST_EX_SERVICE_DEVICE_PATH_DATA *)PcdGetPtr (PcdRedfishRestExServiceDevicePath);\r | |
55 | if ((RestExServiceDevicePathData == NULL) ||\r | |
56 | (RestExServiceDevicePathData->DevicePathNum == 0) ||\r | |
57 | !IsDevicePathValid (RestExServiceDevicePathData->DevicePath, 0))\r | |
58 | {\r | |
cc5faa78 AC |
59 | return EFI_NOT_FOUND;\r |
60 | }\r | |
61 | \r | |
62 | RestExServiceDevicePath = RestExServiceDevicePathData->DevicePath;\r | |
63 | if (RestExServiceDevicePathData->DevicePathMatchMode != DEVICE_PATH_MATCH_MAC_NODE) {\r | |
64 | return EFI_NOT_FOUND;\r | |
65 | }\r | |
66 | \r | |
67 | //\r | |
68 | // Find Mac DevicePath Node.\r | |
69 | //\r | |
70 | while (!IsDevicePathEnd (RestExServiceDevicePath) &&\r | |
71 | ((DevicePathType (RestExServiceDevicePath) != MESSAGING_DEVICE_PATH) ||\r | |
a550d468 MK |
72 | (DevicePathSubType (RestExServiceDevicePath) != MSG_MAC_ADDR_DP)))\r |
73 | {\r | |
cc5faa78 AC |
74 | RestExServiceDevicePath = NextDevicePathNode (RestExServiceDevicePath);\r |
75 | }\r | |
76 | \r | |
77 | if (!IsDevicePathEnd (RestExServiceDevicePath)) {\r | |
78 | MacAddressDevicePath = (MAC_ADDR_DEVICE_PATH *)RestExServiceDevicePath;\r | |
79 | CopyMem ((VOID *)MacAddress, (VOID *)&MacAddressDevicePath->MacAddress, sizeof (EFI_MAC_ADDRESS));\r | |
80 | return EFI_SUCCESS;\r | |
81 | }\r | |
a550d468 | 82 | \r |
cc5faa78 AC |
83 | return EFI_NOT_FOUND;\r |
84 | }\r | |
85 | \r | |
86 | /**\r | |
87 | Get platform Redfish host interface device descriptor.\r | |
88 | \r | |
89 | @param[out] DeviceType Pointer to retrieve device type.\r | |
90 | @param[out] DeviceDescriptor Pointer to retrieve REDFISH_INTERFACE_DATA, caller has to free\r | |
91 | this memory using FreePool().\r | |
92 | @retval EFI_SUCCESS Device descriptor is returned successfully in DeviceDescriptor.\r | |
93 | @retval EFI_NOT_FOUND No Redfish host interface descriptor provided on this platform.\r | |
94 | @retval Others Fail to get device descriptor.\r | |
95 | **/\r | |
96 | EFI_STATUS\r | |
97 | RedfishPlatformHostInterfaceDeviceDescriptor (\r | |
a550d468 | 98 | OUT UINT8 *DeviceType,\r |
cc5faa78 | 99 | OUT REDFISH_INTERFACE_DATA **DeviceDescriptor\r |
a550d468 | 100 | )\r |
cc5faa78 | 101 | {\r |
a550d468 MK |
102 | EFI_STATUS Status;\r |
103 | EFI_MAC_ADDRESS MacAddress;\r | |
104 | REDFISH_INTERFACE_DATA *RedfishInterfaceData;\r | |
105 | PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2 *ThisDeviceDescriptor;\r | |
cc5faa78 AC |
106 | \r |
107 | RedfishInterfaceData = AllocateZeroPool (sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);\r | |
108 | if (RedfishInterfaceData == NULL) {\r | |
109 | return EFI_OUT_OF_RESOURCES;\r | |
110 | }\r | |
a550d468 | 111 | \r |
cc5faa78 AC |
112 | RedfishInterfaceData->DeviceType = REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2;\r |
113 | //\r | |
114 | // Fill up device type information.\r | |
115 | //\r | |
a550d468 | 116 | ThisDeviceDescriptor = (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2 *)((UINT8 *)RedfishInterfaceData + 1);\r |
cc5faa78 | 117 | ThisDeviceDescriptor->Length = sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1;\r |
a550d468 | 118 | Status = GetMacAddressInformation (&MacAddress);\r |
cc5faa78 AC |
119 | if (EFI_ERROR (Status)) {\r |
120 | FreePool (RedfishInterfaceData);\r | |
121 | return EFI_NOT_FOUND;\r | |
122 | }\r | |
a550d468 | 123 | \r |
cc5faa78 | 124 | CopyMem ((VOID *)&ThisDeviceDescriptor->MacAddress, (VOID *)&MacAddress, sizeof (ThisDeviceDescriptor->MacAddress));\r |
a550d468 | 125 | *DeviceType = REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2;\r |
cc5faa78 AC |
126 | *DeviceDescriptor = RedfishInterfaceData;\r |
127 | return EFI_SUCCESS;\r | |
128 | }\r | |
a550d468 | 129 | \r |
cc5faa78 AC |
130 | /**\r |
131 | Get platform Redfish host interface protocol data.\r | |
132 | Caller should pass NULL in ProtocolRecord to retrive the first protocol record.\r | |
133 | Then continuously pass previous ProtocolRecord for retrieving the next ProtocolRecord.\r | |
134 | \r | |
135 | @param[out] ProtocolRecord Pointer to retrieve the protocol record.\r | |
136 | caller has to free the new protocol record returned from\r | |
137 | this function using FreePool().\r | |
138 | @param[in] IndexOfProtocolData The index of protocol data.\r | |
139 | \r | |
140 | @retval EFI_SUCCESS Protocol records are all returned.\r | |
141 | @retval EFI_NOT_FOUND No more protocol records.\r | |
142 | @retval Others Fail to get protocol records.\r | |
143 | **/\r | |
144 | EFI_STATUS\r | |
145 | RedfishPlatformHostInterfaceProtocolData (\r | |
a550d468 MK |
146 | OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord,\r |
147 | IN UINT8 IndexOfProtocolData\r | |
148 | )\r | |
cc5faa78 | 149 | {\r |
a550d468 | 150 | MC_HOST_INTERFACE_PROTOCOL_RECORD *ThisProtocolRecord;\r |
cc5faa78 AC |
151 | \r |
152 | if (mRedfishOverIpProtocolData == 0) {\r | |
153 | return EFI_NOT_FOUND;\r | |
154 | }\r | |
a550d468 | 155 | \r |
cc5faa78 AC |
156 | if (IndexOfProtocolData == 0) {\r |
157 | //\r | |
158 | // Return the first Redfish protocol data to caller. We only have\r | |
159 | // one protocol data in this case.\r | |
160 | //\r | |
a550d468 MK |
161 | ThisProtocolRecord = (MC_HOST_INTERFACE_PROTOCOL_RECORD *)AllocatePool (mRedfishProtocolDataSize + sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - 1);\r |
162 | ThisProtocolRecord->ProtocolType = MCHostInterfaceProtocolTypeRedfishOverIP;\r | |
cc5faa78 AC |
163 | ThisProtocolRecord->ProtocolTypeDataLen = mRedfishProtocolDataSize;\r |
164 | CopyMem ((VOID *)&ThisProtocolRecord->ProtocolTypeData, (VOID *)mRedfishOverIpProtocolData, mRedfishProtocolDataSize);\r | |
165 | *ProtocolRecord = ThisProtocolRecord;\r | |
166 | return EFI_SUCCESS;\r | |
167 | }\r | |
a550d468 | 168 | \r |
cc5faa78 AC |
169 | return EFI_NOT_FOUND;\r |
170 | }\r | |
a550d468 | 171 | \r |
cc5faa78 AC |
172 | /**\r |
173 | Dump IPv4 address.\r | |
174 | \r | |
175 | @param[in] Ip IPv4 address\r | |
176 | **/\r | |
177 | VOID\r | |
178 | InternalDumpIp4Addr (\r | |
a550d468 | 179 | IN EFI_IPv4_ADDRESS *Ip\r |
cc5faa78 AC |
180 | )\r |
181 | {\r | |
a550d468 | 182 | UINTN Index;\r |
cc5faa78 AC |
183 | \r |
184 | for (Index = 0; Index < 4; Index++) {\r | |
185 | DEBUG ((DEBUG_VERBOSE, "%d", Ip->Addr[Index]));\r | |
186 | if (Index < 3) {\r | |
187 | DEBUG ((DEBUG_VERBOSE, "."));\r | |
188 | }\r | |
189 | }\r | |
190 | \r | |
191 | DEBUG ((DEBUG_VERBOSE, "\n"));\r | |
192 | }\r | |
a550d468 | 193 | \r |
cc5faa78 AC |
194 | /**\r |
195 | Dump IPv6 address.\r | |
196 | \r | |
197 | @param[in] Ip IPv6 address\r | |
198 | **/\r | |
199 | VOID\r | |
200 | InternalDumpIp6Addr (\r | |
a550d468 | 201 | IN EFI_IPv6_ADDRESS *Ip\r |
cc5faa78 AC |
202 | )\r |
203 | {\r | |
a550d468 | 204 | UINTN Index;\r |
cc5faa78 AC |
205 | \r |
206 | for (Index = 0; Index < 16; Index++) {\r | |
207 | if (Ip->Addr[Index] != 0) {\r | |
208 | DEBUG ((DEBUG_VERBOSE, "%x", Ip->Addr[Index]));\r | |
209 | }\r | |
a550d468 | 210 | \r |
cc5faa78 AC |
211 | Index++;\r |
212 | \r | |
213 | if (Index > 15) {\r | |
214 | return;\r | |
215 | }\r | |
216 | \r | |
217 | if (((Ip->Addr[Index] & 0xf0) == 0) && (Ip->Addr[Index - 1] != 0)) {\r | |
218 | DEBUG ((DEBUG_VERBOSE, "0"));\r | |
219 | }\r | |
a550d468 | 220 | \r |
cc5faa78 AC |
221 | DEBUG ((DEBUG_VERBOSE, "%x", Ip->Addr[Index]));\r |
222 | \r | |
223 | if (Index < 15) {\r | |
224 | DEBUG ((DEBUG_VERBOSE, ":"));\r | |
225 | }\r | |
226 | }\r | |
a550d468 | 227 | \r |
cc5faa78 AC |
228 | DEBUG ((DEBUG_VERBOSE, "\n"));\r |
229 | }\r | |
a550d468 | 230 | \r |
cc5faa78 AC |
231 | /**\r |
232 | Dump data\r | |
233 | \r | |
234 | @param[in] Data Pointer to data.\r | |
235 | @param[in] Size size of data to dump.\r | |
236 | **/\r | |
237 | VOID\r | |
238 | InternalDumpData (\r | |
239 | IN UINT8 *Data,\r | |
240 | IN UINTN Size\r | |
241 | )\r | |
242 | {\r | |
243 | UINTN Index;\r | |
a550d468 | 244 | \r |
cc5faa78 AC |
245 | for (Index = 0; Index < Size; Index++) {\r |
246 | DEBUG ((DEBUG_VERBOSE, "%02x ", (UINTN)Data[Index]));\r | |
247 | }\r | |
248 | }\r | |
a550d468 | 249 | \r |
cc5faa78 AC |
250 | /**\r |
251 | Dump hex data\r | |
252 | \r | |
253 | @param[in] Data Pointer to hex data.\r | |
254 | @param[in] Size size of hex data to dump.\r | |
255 | **/\r | |
256 | VOID\r | |
257 | InternalDumpHex (\r | |
258 | IN UINT8 *Data,\r | |
259 | IN UINTN Size\r | |
260 | )\r | |
261 | {\r | |
a550d468 MK |
262 | UINTN Index;\r |
263 | UINTN Count;\r | |
264 | UINTN Left;\r | |
cc5faa78 AC |
265 | \r |
266 | Count = Size / VERBOSE_COLUME_SIZE;\r | |
267 | Left = Size % VERBOSE_COLUME_SIZE;\r | |
268 | for (Index = 0; Index < Count; Index++) {\r | |
269 | InternalDumpData (Data + Index * VERBOSE_COLUME_SIZE, VERBOSE_COLUME_SIZE);\r | |
270 | DEBUG ((DEBUG_VERBOSE, "\n"));\r | |
271 | }\r | |
272 | \r | |
273 | if (Left != 0) {\r | |
274 | InternalDumpData (Data + Index * VERBOSE_COLUME_SIZE, Left);\r | |
275 | DEBUG ((DEBUG_VERBOSE, "\n"));\r | |
276 | }\r | |
277 | \r | |
278 | DEBUG ((DEBUG_VERBOSE, "\n"));\r | |
279 | }\r | |
a550d468 | 280 | \r |
cc5faa78 AC |
281 | /**\r |
282 | Dump Redfish over IP protocol data\r | |
283 | \r | |
284 | @param[in] RedfishProtocolData Pointer to REDFISH_OVER_IP_PROTOCOL_DATA\r | |
285 | @param[in] RedfishProtocolDataSize size of data to dump.\r | |
286 | **/\r | |
287 | VOID\r | |
288 | DumpRedfishIpProtocolData (\r | |
a550d468 MK |
289 | IN REDFISH_OVER_IP_PROTOCOL_DATA *RedfishProtocolData,\r |
290 | IN UINT8 RedfishProtocolDataSize\r | |
cc5faa78 AC |
291 | )\r |
292 | {\r | |
a550d468 | 293 | CHAR16 Hostname[16];\r |
cc5faa78 AC |
294 | \r |
295 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData: \n"));\r | |
a550d468 | 296 | InternalDumpHex ((UINT8 *)RedfishProtocolData, RedfishProtocolDataSize);\r |
cc5faa78 AC |
297 | \r |
298 | DEBUG ((DEBUG_VERBOSE, "Parsing as below: \n"));\r | |
299 | \r | |
300 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->ServiceUuid - %g\n", &(RedfishProtocolData->ServiceUuid)));\r | |
301 | \r | |
302 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->HostIpAssignmentType - %d\n", RedfishProtocolData->HostIpAssignmentType));\r | |
303 | \r | |
304 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->HostIpAddressFormat - %d\n", RedfishProtocolData->HostIpAddressFormat));\r | |
305 | \r | |
306 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->HostIpAddress: \n"));\r | |
307 | if (RedfishProtocolData->HostIpAddressFormat == 0x01) {\r | |
a550d468 | 308 | InternalDumpIp4Addr ((EFI_IPv4_ADDRESS *)(RedfishProtocolData->HostIpAddress));\r |
cc5faa78 | 309 | } else {\r |
a550d468 | 310 | InternalDumpIp6Addr ((EFI_IPv6_ADDRESS *)(RedfishProtocolData->HostIpAddress));\r |
cc5faa78 AC |
311 | }\r |
312 | \r | |
313 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->HostIpMask: \n"));\r | |
314 | if (RedfishProtocolData->HostIpAddressFormat == 0x01) {\r | |
a550d468 | 315 | InternalDumpIp4Addr ((EFI_IPv4_ADDRESS *)(RedfishProtocolData->HostIpMask));\r |
cc5faa78 | 316 | } else {\r |
a550d468 | 317 | InternalDumpIp6Addr ((EFI_IPv6_ADDRESS *)(RedfishProtocolData->HostIpMask));\r |
cc5faa78 AC |
318 | }\r |
319 | \r | |
320 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceIpDiscoveryType - %d\n", RedfishProtocolData->RedfishServiceIpDiscoveryType));\r | |
321 | \r | |
322 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceIpAddressFormat - %d\n", RedfishProtocolData->RedfishServiceIpAddressFormat));\r | |
323 | \r | |
324 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceIpAddress: \n"));\r | |
325 | if (RedfishProtocolData->RedfishServiceIpAddressFormat == 0x01) {\r | |
a550d468 | 326 | InternalDumpIp4Addr ((EFI_IPv4_ADDRESS *)(RedfishProtocolData->RedfishServiceIpAddress));\r |
cc5faa78 | 327 | } else {\r |
a550d468 | 328 | InternalDumpIp6Addr ((EFI_IPv6_ADDRESS *)(RedfishProtocolData->RedfishServiceIpAddress));\r |
cc5faa78 AC |
329 | }\r |
330 | \r | |
331 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceIpMask: \n"));\r | |
332 | if (RedfishProtocolData->RedfishServiceIpAddressFormat == 0x01) {\r | |
a550d468 | 333 | InternalDumpIp4Addr ((EFI_IPv4_ADDRESS *)(RedfishProtocolData->RedfishServiceIpMask));\r |
cc5faa78 | 334 | } else {\r |
a550d468 | 335 | InternalDumpIp6Addr ((EFI_IPv6_ADDRESS *)(RedfishProtocolData->RedfishServiceIpMask));\r |
cc5faa78 AC |
336 | }\r |
337 | \r | |
338 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceIpPort - %d\n", RedfishProtocolData->RedfishServiceIpPort));\r | |
339 | \r | |
340 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceVlanId - %d\n", RedfishProtocolData->RedfishServiceVlanId));\r | |
341 | \r | |
342 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceHostnameLength - %d\n", RedfishProtocolData->RedfishServiceHostnameLength));\r | |
343 | \r | |
a550d468 | 344 | AsciiStrToUnicodeStrS ((CHAR8 *)RedfishProtocolData->RedfishServiceHostname, Hostname, sizeof (Hostname) / sizeof (Hostname[0]));\r |
cc5faa78 AC |
345 | DEBUG ((DEBUG_VERBOSE, "RedfishProtocolData->RedfishServiceHostname - %s\n", Hostname));\r |
346 | }\r | |
347 | \r | |
348 | /**\r | |
349 | Get Redfish host interface protocol data from variale.\r | |
350 | \r | |
351 | @param[out] RedfishProtocolData Pointer to retrieve REDFISH_OVER_IP_PROTOCOL_DATA.\r | |
352 | @param[out] RedfishProtocolDataSize Size of REDFISH_OVER_IP_PROTOCOL_DATA.\r | |
353 | \r | |
354 | @retval EFI_SUCESS REDFISH_OVER_IP_PROTOCOL_DATA is returned successfully.\r | |
355 | **/\r | |
356 | EFI_STATUS\r | |
357 | GetRedfishRecordFromVariable (\r | |
a550d468 MK |
358 | OUT REDFISH_OVER_IP_PROTOCOL_DATA **RedfishProtocolData,\r |
359 | OUT UINT8 *RedfishProtocolDataSize\r | |
cc5faa78 AC |
360 | )\r |
361 | {\r | |
a550d468 MK |
362 | EFI_STATUS Status;\r |
363 | UINT8 HostIpAssignmentType;\r | |
364 | UINTN HostIpAssignmentTypeSize;\r | |
365 | EFI_IPv4_ADDRESS HostIpAddress;\r | |
366 | UINTN IPv4DataSize;\r | |
367 | EFI_IPv4_ADDRESS HostIpMask;\r | |
368 | EFI_IPv4_ADDRESS RedfishServiceIpAddress;\r | |
369 | EFI_IPv4_ADDRESS RedfishServiceIpMask;\r | |
370 | UINT16 RedfishServiceIpPort;\r | |
371 | UINTN IpPortDataSize;\r | |
372 | UINT8 HostNameSize;\r | |
373 | CHAR8 RedfishHostName[20];\r | |
374 | \r | |
375 | if ((RedfishProtocolData == NULL) || (RedfishProtocolDataSize == NULL)) {\r | |
cc5faa78 AC |
376 | return EFI_INVALID_PARAMETER;\r |
377 | }\r | |
378 | \r | |
379 | //\r | |
380 | // 1. Retrieve Address Information from variable.\r | |
381 | //\r | |
382 | Status = gRT->GetVariable (\r | |
383 | L"HostIpAssignmentType",\r | |
384 | &gEmuRedfishServiceGuid,\r | |
385 | NULL,\r | |
386 | &HostIpAssignmentTypeSize,\r | |
387 | &HostIpAssignmentType\r | |
388 | );\r | |
389 | if (EFI_ERROR (Status)) {\r | |
390 | DEBUG ((DEBUG_ERROR, "RedfishPlatformDxe: GetVariable HostIpAssignmentType - %r\n", Status));\r | |
391 | return Status;\r | |
392 | }\r | |
393 | \r | |
394 | IPv4DataSize = sizeof (EFI_IPv4_ADDRESS);\r | |
395 | if (HostIpAssignmentType == 1 ) {\r | |
396 | Status = gRT->GetVariable (\r | |
397 | L"HostIpAddress",\r | |
398 | &gEmuRedfishServiceGuid,\r | |
399 | NULL,\r | |
400 | &IPv4DataSize,\r | |
401 | &HostIpAddress\r | |
402 | );\r | |
403 | if (EFI_ERROR (Status)) {\r | |
404 | DEBUG ((DEBUG_ERROR, "RedfishPlatformDxe: GetVariable HostIpAddress - %r\n", Status));\r | |
405 | return Status;\r | |
406 | }\r | |
407 | \r | |
408 | Status = gRT->GetVariable (\r | |
409 | L"HostIpMask",\r | |
410 | &gEmuRedfishServiceGuid,\r | |
411 | NULL,\r | |
412 | &IPv4DataSize,\r | |
413 | &HostIpMask\r | |
414 | );\r | |
415 | if (EFI_ERROR (Status)) {\r | |
416 | DEBUG ((DEBUG_ERROR, "RedfishPlatformDxe: GetVariable HostIpMask - %r\n", Status));\r | |
417 | return Status;\r | |
418 | }\r | |
419 | }\r | |
420 | \r | |
421 | Status = gRT->GetVariable (\r | |
422 | L"RedfishServiceIpAddress",\r | |
423 | &gEmuRedfishServiceGuid,\r | |
424 | NULL,\r | |
425 | &IPv4DataSize,\r | |
426 | &RedfishServiceIpAddress\r | |
427 | );\r | |
428 | if (EFI_ERROR (Status)) {\r | |
429 | DEBUG ((DEBUG_ERROR, "RedfishPlatformDxe: GetVariable RedfishServiceIpAddress - %r\n", Status));\r | |
430 | return Status;\r | |
431 | }\r | |
432 | \r | |
433 | Status = gRT->GetVariable (\r | |
434 | L"RedfishServiceIpMask",\r | |
435 | &gEmuRedfishServiceGuid,\r | |
436 | NULL,\r | |
437 | &IPv4DataSize,\r | |
438 | &RedfishServiceIpMask\r | |
439 | );\r | |
440 | if (EFI_ERROR (Status)) {\r | |
441 | DEBUG ((DEBUG_ERROR, "RedfishPlatformDxe: GetVariable RedfishServiceIpMask - %r\n", Status));\r | |
442 | return Status;\r | |
443 | }\r | |
444 | \r | |
445 | Status = gRT->GetVariable (\r | |
446 | L"RedfishServiceIpPort",\r | |
447 | &gEmuRedfishServiceGuid,\r | |
448 | NULL,\r | |
449 | &IpPortDataSize,\r | |
450 | &RedfishServiceIpPort\r | |
451 | );\r | |
452 | if (EFI_ERROR (Status)) {\r | |
453 | DEBUG ((DEBUG_ERROR, "RedfishPlatformDxe: GetVariable RedfishServiceIpPort - %r\n", Status));\r | |
454 | return Status;\r | |
455 | }\r | |
456 | \r | |
457 | AsciiSPrint (\r | |
458 | RedfishHostName,\r | |
459 | sizeof (RedfishHostName),\r | |
460 | "%d.%d.%d.%d",\r | |
461 | RedfishServiceIpAddress.Addr[0],\r | |
462 | RedfishServiceIpAddress.Addr[1],\r | |
463 | RedfishServiceIpAddress.Addr[2],\r | |
464 | RedfishServiceIpAddress.Addr[3]\r | |
465 | );\r | |
466 | \r | |
a550d468 | 467 | HostNameSize = (UINT8)AsciiStrLen (RedfishHostName) + 1;\r |
cc5faa78 AC |
468 | \r |
469 | //\r | |
470 | // 2. Protocol Data Size.\r | |
471 | //\r | |
472 | *RedfishProtocolDataSize = sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1 + HostNameSize;\r | |
473 | \r | |
474 | //\r | |
475 | // 3. Protocol Data.\r | |
476 | //\r | |
a550d468 | 477 | *RedfishProtocolData = (REDFISH_OVER_IP_PROTOCOL_DATA *)AllocateZeroPool (*RedfishProtocolDataSize);\r |
cc5faa78 AC |
478 | if (*RedfishProtocolData == NULL) {\r |
479 | return EFI_OUT_OF_RESOURCES;\r | |
480 | }\r | |
481 | \r | |
482 | CopyGuid (&(*RedfishProtocolData)->ServiceUuid, &gEmuRedfishServiceGuid);\r | |
483 | \r | |
484 | (*RedfishProtocolData)->HostIpAssignmentType = HostIpAssignmentType;\r | |
a550d468 | 485 | (*RedfishProtocolData)->HostIpAddressFormat = 1; // Only support IPv4\r |
cc5faa78 AC |
486 | \r |
487 | if (HostIpAssignmentType == 1 ) {\r | |
488 | (*RedfishProtocolData)->HostIpAddress[0] = HostIpAddress.Addr[0];\r | |
489 | (*RedfishProtocolData)->HostIpAddress[1] = HostIpAddress.Addr[1];\r | |
490 | (*RedfishProtocolData)->HostIpAddress[2] = HostIpAddress.Addr[2];\r | |
491 | (*RedfishProtocolData)->HostIpAddress[3] = HostIpAddress.Addr[3];\r | |
492 | \r | |
493 | (*RedfishProtocolData)->HostIpMask[0] = HostIpMask.Addr[0];\r | |
494 | (*RedfishProtocolData)->HostIpMask[1] = HostIpMask.Addr[1];\r | |
495 | (*RedfishProtocolData)->HostIpMask[2] = HostIpMask.Addr[2];\r | |
496 | (*RedfishProtocolData)->HostIpMask[3] = HostIpMask.Addr[3];\r | |
497 | }\r | |
498 | \r | |
499 | (*RedfishProtocolData)->RedfishServiceIpDiscoveryType = 1; // Use static IP address\r | |
500 | (*RedfishProtocolData)->RedfishServiceIpAddressFormat = 1; // Only support IPv4\r | |
501 | \r | |
502 | (*RedfishProtocolData)->RedfishServiceIpAddress[0] = RedfishServiceIpAddress.Addr[0];\r | |
503 | (*RedfishProtocolData)->RedfishServiceIpAddress[1] = RedfishServiceIpAddress.Addr[1];\r | |
504 | (*RedfishProtocolData)->RedfishServiceIpAddress[2] = RedfishServiceIpAddress.Addr[2];\r | |
505 | (*RedfishProtocolData)->RedfishServiceIpAddress[3] = RedfishServiceIpAddress.Addr[3];\r | |
506 | \r | |
507 | (*RedfishProtocolData)->RedfishServiceIpMask[0] = RedfishServiceIpMask.Addr[0];\r | |
508 | (*RedfishProtocolData)->RedfishServiceIpMask[1] = RedfishServiceIpMask.Addr[1];\r | |
509 | (*RedfishProtocolData)->RedfishServiceIpMask[2] = RedfishServiceIpMask.Addr[2];\r | |
510 | (*RedfishProtocolData)->RedfishServiceIpMask[3] = RedfishServiceIpMask.Addr[3];\r | |
511 | \r | |
512 | (*RedfishProtocolData)->RedfishServiceIpPort = RedfishServiceIpPort;\r | |
513 | (*RedfishProtocolData)->RedfishServiceVlanId = 0xffffffff;\r | |
514 | \r | |
515 | (*RedfishProtocolData)->RedfishServiceHostnameLength = HostNameSize;\r | |
a550d468 | 516 | AsciiStrCpyS ((CHAR8 *)((*RedfishProtocolData)->RedfishServiceHostname), HostNameSize, RedfishHostName);\r |
cc5faa78 AC |
517 | \r |
518 | return Status;\r | |
519 | }\r | |
520 | \r | |
521 | /**\r | |
522 | Construct Redfish host interface protocol data.\r | |
523 | \r | |
524 | @param ImageHandle The image handle.\r | |
525 | @param SystemTable The system table.\r | |
526 | \r | |
527 | @retval EFI_SUCEESS Install Boot manager menu success.\r | |
528 | @retval Other Return error status.\r | |
529 | \r | |
530 | **/\r | |
531 | EFI_STATUS\r | |
532 | EFIAPI\r | |
533 | RedfishPlatformHostInterfaceConstructor (\r | |
a550d468 MK |
534 | IN EFI_HANDLE ImageHandle,\r |
535 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
536 | )\r | |
cc5faa78 | 537 | {\r |
a550d468 | 538 | EFI_STATUS Status;\r |
cc5faa78 AC |
539 | \r |
540 | Status = GetRedfishRecordFromVariable (&mRedfishOverIpProtocolData, &mRedfishProtocolDataSize);\r | |
541 | DEBUG ((DEBUG_INFO, "%a: GetRedfishRecordFromVariable() - %r\n", __FUNCTION__, Status));\r | |
542 | if (!EFI_ERROR (Status)) {\r | |
543 | DumpRedfishIpProtocolData (mRedfishOverIpProtocolData, mRedfishProtocolDataSize);\r | |
544 | }\r | |
a550d468 | 545 | \r |
cc5faa78 AC |
546 | return EFI_SUCCESS;\r |
547 | }\r | |
259e1e04 AC |
548 | \r |
549 | /**\r | |
550 | Get the EFI protocol GUID installed by platform library which\r | |
551 | indicates the necessary information is ready for building\r | |
552 | SMBIOS 42h record.\r | |
553 | \r | |
554 | @param[out] InformationReadinessGuid Pointer to retrive the protocol\r | |
555 | GUID.\r | |
556 | \r | |
557 | @retval EFI_SUCCESS Notification is required for building up\r | |
558 | SMBIOS type 42h record.\r | |
559 | @retval EFI_UNSUPPORTED Notification is not required for building up\r | |
560 | SMBIOS type 42h record.\r | |
561 | @retval EFI_ALREADY_STARTED Platform host information is already ready.\r | |
562 | @retval Others Other errors.\r | |
563 | **/\r | |
564 | EFI_STATUS\r | |
565 | RedfishPlatformHostInterfaceNotification (\r | |
566 | OUT EFI_GUID **InformationReadinessGuid\r | |
567 | )\r | |
568 | {\r | |
569 | return EFI_UNSUPPORTED;\r | |
570 | }\r |