1#!/usr/bin/env python3
2
3r"""
4Contains PLDM-related constants.
5"""
6
7PLDM_SUPPORTED_TYPES = ["base", "platform", "bios", "fru", "oem-ibm"]
8
9# PLDM types.
10PLDM_TYPE_BASE = {"VALUE": "00", "STRING": "base"}
11PLDM_TYPE_PLATFORM = {"VALUE": "02", "STRING": "platform"}
12PLDM_TYPE_BIOS = {"VALUE": "03", "STRING": "bios"}
13PLDM_TYPE_FRU = {"VALUE": "04", "STRING": "fru"}
14PLDM_TYPE_OEM = {"VALUE": "63", "STRING": "oem-ibm"}
15PLDM_SUPPORTED_TYPES = [
16    "0(base)",
17    "2(platform)",
18    "3(bios)",
19    "4(fru)",
20    "63(oem-ibm)",
21]
22
23VERSION_BASE = {"VALUE": ["f1", "f0", "f0", "00"], "STRING": "1.0.0"}
24VERSION_PLATFORM = {"VALUE": ["f1", "f2", "f0", "00"], "STRING": "1.2.0"}
25VERSION_BIOS = {"VALUE": ["f1", "f1", "f1", "00"], "STRING": "1.0.0"}
26VERSION_FRU = {"VALUE": ["f1", "f0", "f0", "00"], "STRING": "1.0.0"}
27VERSION_OEM = {"VALUE": ["f1", "f0", "f0", "00"], "STRING": "1.0.0"}
28
29
30PLDM_BASE_CMDS = [
31    "2(GetTID)",
32    "3(GetPLDMVersion)",
33    "4(GetPLDMTypes)",
34    "5(GetPLDMCommands)",
35]
36PLDM_PLATFORM_CMDS = ["57(SetStateEffecterStates)", "81(GetPDR)"]
37PLDM_BIOS_CMDS = [
38    "1(GetBIOSTable)",
39    "7(SetBIOSAttributeCurrentValue)",
40    "8(GetBIOSAttributeCurrentValueByHandle)",
41    "12(GetDateTime)",
42    "13(SetDateTime)",
43]
44PLDM_FRU_CMDS = [
45    "1(GetFRURecordTableMetadata)",
46    "2(GetFRURecordTable)",
47    "4(GetFRURecordByOption)",
48]
49PLDM_OEM_CMDS = [
50    "1(GetFileTable)",
51    "4(ReadFile)",
52    "5(WriteFile)",
53    "6(ReadFileInToMemory)",
54    "7(WriteFileFromMemory)",
55    "8(ReadFileByTypeIntoMemory)",
56    "9(WriteFileByTypeFromMemory)",
57    "10(NewFileAvailable)",
58    "11(ReadFileByType)",
59    "12(WriteFileByType)",
60    "13(FileAck)",
61    "240(GetAlertStatus)",
62]
63
64# PLDM command format.
65
66"""
67e.g. : GetPLDMVersion usage
68
69pldmtool base GetPLDMVersion -t <pldm_type>
70
71pldm supported types
72
73base->0,platform->2,bios->3,fru->4
74
75"""
76CMD_GETPLDMVERSION = "base GetPLDMVersion -t %s"
77
78"""
79e.g. : PLDM raw command usage
80
81pldmtool raw -d 0x80 0x00 0x03 0x00 0x00 0x00 0x00 0x01 0x00
82
83pldm raw -d 0x<header> 0x<pldm_type> 0x<pldm_cmd_type> 0x<payload_data>
84"""
85
86CMD_PLDMTOOL_RAW = "raw -d 0x80" + "0x%s" + " " + "0x%s"
87
88
89# PLDM command payload data.
90
91PAYLOAD_GetPLDMVersion = (  # %(TransferOperationFlag, PLDMType)
92    " 0x00 0x00 0x00 0x00 0x%s 0x%s"
93)
94
95
96"""
97e.g. : SetDateTime usage
98
99pldmtool bios SetDateTime -d <YYYYMMDDHHMMSS>
100
101"""
102CMD_SETDATETIME = "bios SetDateTime -d %s"
103
104
105CMD_GETPDR = "platform GetPDR -d %s"
106
107"""
108e.g. : SetStateEffecterStates usage
109
110pldmtool platform GetPDR -i <effter_handle> -c <count> -d <effecterID, effecterState>
111
112pldmtool platform SetStateEffecterStates -i 1 -c 1 -d 1 1
113"""
114
115CMD_SETSTATEEFFECTERSTATES = (
116    "platform SetStateEffecterStates -i %s -c %s -d %s"
117)
118
119# GetPDR parsed response message for record handle.
120# Dictionary value array holds the expected output for record handle 1, 2.
121#
122# Note :
123#      Record handle - 0 is default &  has same behaviour as record handle 1
124#      Only record handle 0, 1, 2 are supported as of now.
125
126RESPONSE_DICT_GETPDR_SETSTATEEFFECTER = {
127    "PDRHeaderVersion": [1],
128    "PDRType": ["State Effecter PDR"],
129    "recordChangeNumber": [0],
130    "effecterID": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
131    "entityType": [
132        "Virtual Machine Manager",
133        "System chassis (main enclosure)",
134        "System Firmware",
135        "Processor Module",
136        "32801(OEM)",
137        "Management Controller",
138        "24577(OEM)",
139    ],
140    "entityInstanceNumber": [0, 1, 2, 3, 4],
141    "containerID": [0, 1],
142    "effecterSemanticID": [0],
143    "effecterInit": ["noInit"],
144    "effecterDescriptionPDR": [False],
145    "compositeEffecterCount": [1],
146}
147
148RESPONSE_DICT_GETPDR_FRURECORDSETIDENTIFIER = {
149    "PDRHeaderVersion": [1],
150    "PDRType": ["FRU Record Set PDR"],
151    "recordChangeNumber": [0],
152    "dataLength": [10],
153    "entityType": [
154        "System Board",
155        "Chassis front panel board (control panel)",
156        "Management Controller",
157        "OEM",
158        "Power converter",
159        "System (logical)",
160        "System chassis (main enclosure)",
161        "Chassis front panel board (control panel)",
162        "Processor Module",
163        "Memory Module",
164        "Power Supply",
165        "24576(OEM)",
166        "60(OEM)",
167        "Processor",
168        "142(OEM)",
169    ],
170    "containerID": [0, 1, 2, 3],
171}
172
173RESPONSE_DICT_GETPDR_PDRENTITYASSOCIATION = {
174    "PDRHeaderVersion": [1],
175    "PDRType": ["Entity Association PDR"],
176    "recordChangeNumber": [0],
177    "containerID": [1, 2, 3],
178    "associationtype": ["Physical"],
179    "containerentityType": [
180        "System Board",
181        "System (logical)",
182        "System chassis (main enclosure)",
183    ],
184}
185
186RESPONSE_DICT_GETPDR_STATESENSORPDR = {
187    "entityType": [
188        "Communication Channel",
189        "Connector",
190        "Processor Module",
191        "32774(OEM)",
192        "57346(OEM)",
193        "57347(OEM)",
194        "32801(OEM)",
195        "91(OEM)",
196        "5(OEM)",
197        "24577(OEM)",
198    ],
199    "sensorInit": ["noInit"],
200    "sensorAuxiliaryNamesPDR": [False],
201}
202
203RESPONSE_DICT_GETPDR_TERMINUSLOCATORPDR = {
204    "PDRHeaderVersion": [1],
205    "PDRType": ["Terminus Locator PDR"],
206    "recordChangeNumber": [0],
207    "validity": ["valid"],
208    "TID": [0, 1, 208],
209    "containerID": [0, 1],
210    "terminusLocatorType": ["MCTP_EID"],
211    "terminusLocatorValueSize": [1],
212}
213
214RESPONSE_DICT_GETPDR_NUMERICEFFECTERPDR = {
215    "PDRHeaderVersion": [1],
216    "PDRType": ["Numeric Effecter PDR"],
217    "recordChangeNumber": [0],
218    "entityInstanceNumber": [0, 1],
219    "containerID": [0],
220    "effecterSemanticID": [0],
221    "effecterInit": [0],
222    "effecterAuxiliaryNames": [False],
223    "baseUnit": [0, 72, 21],
224    "unitModifier": [0],
225    "baseOEMUnitHandle": [0],
226    "auxUnit": [0],
227    "auxUnitModifier": [0],
228    "auxrateUnit": [0],
229    "auxOEMUnitHandle": [0],
230    "resolution": [1, 0],
231    "offset": [0],
232    "accuracy": [0],
233    "plusTolerance": [0],
234    "minusTolerance": [0],
235    "stateTransitionInterval": [0],
236    "TransitionInterval": [0],
237    "minSettable": [0],
238    "rangeFieldSupport": [0],
239    "nominalValue": [0],
240    "normalMax": [0],
241    "normalMin": [0],
242    "ratedMax": [0],
243    "ratedMin": [0],
244}
245
246PLDM_PDR_TYPES = {
247    "PLDM_STATE_EFFECTER_PDR": "State Effecter PDR",
248    "PLDM_PDR_FRU_RECORD_SET": "FRU Record Set PDR",
249    "PLDM_PDR_ENTITY_ASSOCIATION": "Entity Association PDR",
250    "PLDM_STATE_SENSOR_PDR": "State Sensor PDR",
251    "PLDM_NUMERIC_EFFECTER_PDR": "Numeric Effecter PDR",
252    "PLDM_TERMINUS_LOCATOR_PDR": "Terminus Locator PDR",
253    "PLDM_COMPACT_NUMERIC_SENSOR_PDR": "21",
254}
255
256RESPONSE_LIST_GETBIOSTABLE_ATTRVALTABLE = [
257    "BIOSString",
258    "BIOSInteger",
259    "BIOSEnumeration",
260]
261