-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPldmMessage.c
137 lines (124 loc) · 4.75 KB
/
PldmMessage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright (c) 2023, Konstantin Aladyshev <[email protected]>
*
* SPDX-License-Identifier: MIT
*/
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/ManageabilityTransportLib.h>
#include <Library/ManageabilityTransportHelperLib.h>
#include <Library/ManageabilityTransportMctpLib.h>
#include <IndustryStandard/Mctp.h>
#include <IndustryStandard/Pldm.h>
#include <Protocol/MctpProtocol.h>
static const UINT8 PldmType = PLDM_TYPE_MESSAGE_CONTROL_AND_DISCOVERY;
static const UINT8 PldmTypeCommandCode = 0x04;
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EDKII_MCTP_PROTOCOL* MctpProtocol;
Status = gBS->LocateProtocol(&gEdkiiMctpProtocolGuid,
NULL,
(VOID**)&MctpProtocol);
if (EFI_ERROR(Status)) {
Print(L"ERROR: Could not find MCTP protocol: %r\n", Status);
return Status;
}
Print(L"MCTP protocol version %d\n", MctpProtocol->ProtocolVersion);
PLDM_MESSAGE_HEADER PldmHeader;
PldmHeader.RequestBit = PLDM_MESSAGE_HEADER_IS_REQUEST;
PldmHeader.DatagramBit = (!PLDM_MESSAGE_HEADER_IS_DATAGRAM);
PldmHeader.Reserved = 0;
PldmHeader.InstanceId = 0x15;
PldmHeader.HeaderVersion = PLDM_MESSAGE_HEADER_VERSION;
PldmHeader.PldmType = PldmType;
PldmHeader.PldmTypeCommandCode = PldmTypeCommandCode;
MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS AdditionalTransferError;
for (UINT8 i=0; i<sizeof(PldmHeader); i++) {
Print(L"PldmRequestBuffer[%d]=0x%02x\n", i, ((UINT8*)&PldmHeader)[i]);
}
UINT8 Response[50];
UINT32 ResponseDataSize = sizeof(Response);
for (UINT8 i=0; i<ResponseDataSize; i++) {
Response[i]=0xAA; // data poison for debug purposes
}
Status = MctpProtocol->Functions.Version1_0->MctpSubmitCommand(
MctpProtocol,
MCTP_MESSAGE_TYPE_PLDM,
9,
8,
FALSE,
(UINT8*)&PldmHeader,
sizeof(PldmHeader),
10000,
Response,
&ResponseDataSize,
10000,
&AdditionalTransferError
);
if (EFI_ERROR(Status)) {
Print(L"MctpSubmitCommand returned %r, additional status = 0x%08x\n", Status, AdditionalTransferError);
return Status;
}
// // DEBUG
// Print(L"ResponseDataSize=%d\n", ResponseDataSize);
// for (UINT8 i=0; i<ResponseDataSize; i++) {
// Print(L"Response[%d]=0x%02x\n", i, Response[i]);
// }
PLDM_RESPONSE_HEADER* PldmResponseHeader = (PLDM_RESPONSE_HEADER*)Response;
if (ResponseDataSize < sizeof(*PldmResponseHeader)) {
Print(L"Error! ResponseDataSize is less than PLDM_RESPONSE_HEADER\n");
return EFI_DEVICE_ERROR;
}
if (PldmResponseHeader->PldmHeader.RequestBit != (!PLDM_MESSAGE_HEADER_IS_REQUEST)) {
Print(L"Error! PldmHeader.RequestBit = %d, but should be %d\n",
PldmResponseHeader->PldmHeader.RequestBit,
(!PLDM_MESSAGE_HEADER_IS_REQUEST));
return EFI_DEVICE_ERROR;
}
if (PldmResponseHeader->PldmHeader.DatagramBit != (!PLDM_MESSAGE_HEADER_IS_DATAGRAM)) {
Print(L"Error! PldmHeader.DatagramBit = %d, but should be %d\n",
PldmResponseHeader->PldmHeader.DatagramBit,
(!PLDM_MESSAGE_HEADER_IS_DATAGRAM));
return EFI_DEVICE_ERROR;
}
if (PldmResponseHeader->PldmHeader.InstanceId != PldmHeader.InstanceId) {
Print(L"Error! PldmHeader.InstanceId = 0x%02x, but should be 0x%02x\n",
PldmResponseHeader->PldmHeader.InstanceId,
PldmHeader.InstanceId);
return EFI_DEVICE_ERROR;
}
if (PldmResponseHeader->PldmHeader.HeaderVersion != PLDM_MESSAGE_HEADER_VERSION) {
Print(L"Error! PldmHeader.HeaderVersion = %d, but should be %d\n",
PldmResponseHeader->PldmHeader.HeaderVersion,
PLDM_MESSAGE_HEADER_VERSION);
return EFI_DEVICE_ERROR;
}
if (PldmResponseHeader->PldmHeader.PldmType != PldmHeader.PldmType) {
Print(L"Error! PldmHeader.PldmType = %d, but should be %d\n",
PldmResponseHeader->PldmHeader.PldmType,
PldmHeader.PldmType);
return EFI_DEVICE_ERROR;
}
if (PldmResponseHeader->PldmHeader.PldmTypeCommandCode != PldmHeader.PldmTypeCommandCode) {
Print(L"Error! PldmHeader.PldmTypeCommandCode = %d, but should be %d\n",
PldmResponseHeader->PldmHeader.PldmTypeCommandCode,
PldmHeader.PldmTypeCommandCode);
return EFI_DEVICE_ERROR;
}
if (PldmResponseHeader->PldmCompletionCode != PLDM_COMPLETION_CODE_SUCCESS) {
Print(L"Error! PldmCompletionCode = 0x%02x, but should be 0x%02x\n",
PldmResponseHeader->PldmCompletionCode,
PLDM_COMPLETION_CODE_SUCCESS);
return EFI_DEVICE_ERROR;
}
for (UINT8 i=sizeof(*PldmResponseHeader); i<ResponseDataSize; i++) {
Print(L"PldmResponse[%d]=0x%02x\n", i-sizeof(*PldmResponseHeader), Response[i]);
}
return EFI_SUCCESS;
}