1#!/usr/bin/python
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 = ['0(base)', '2(platform)', '3(bios)', '4(fru)', '63(oem-ibm)']
16
17VERSION_BASE = {'VALUE': ['f1', 'f0', 'f0', '00'], 'STRING': '1.0.0'}
18VERSION_PLATFORM = {'VALUE': ['f1', 'f2', 'f0', '00'], 'STRING': '1.2.0'}
19VERSION_BIOS = {'VALUE': ['f1', 'f1', 'f1', '00'], 'STRING': '1.0.0'}
20VERSION_FRU = {'VALUE': ['f1', 'f0', 'f0', '00'], 'STRING': '1.0.0'}
21VERSION_OEM = {'VALUE': ['f1', 'f0', 'f0', '00'], 'STRING': '1.0.0'}
22
23
24PLDM_BASE_CMDS = ['2(GetTID)', '3(GetPLDMVersion)', '4(GetPLDMTypes)', '5(GetPLDMCommands)']
25PLDM_PLATFORM_CMDS = ['57(SetStateEffecterStates)', '81(GetPDR)']
26PLDM_BIOS_CMDS = ['1(GetBIOSTable)', '7(SetBIOSAttributeCurrentValue)',
27                  '8(GetBIOSAttributeCurrentValueByHandle)', '12(GetDateTime)',
28                  '13(SetDateTime)']
29PLDM_FRU_CMDS = ['1(GetFRURecordTableMetadata)', '2(GetFRURecordTable)', '4(GetFRURecordByOption)']
30PLDM_OEM_CMDS = ['1(GetFileTable)', '4(ReadFile)', '5(WriteFile)', '6(ReadFileInToMemory)',
31                 '7(WriteFileFromMemory)', '8(ReadFileByTypeIntoMemory)',
32                 '9(WriteFileByTypeFromMemory)', '10(NewFileAvailable)',
33                 '11(ReadFileByType)', '12(WriteFileByType)', '13(FileAck)',
34                 '240(GetAlertStatus)']
35
36# PLDM command format.
37
38'''
39e.g. : GetPLDMVersion usage
40
41pldmtool base GetPLDMVersion -t <pldm_type>
42
43pldm supported types
44
45base->0,platform->2,bios->3,fru->4
46
47'''
48CMD_GETPLDMVERSION = 'base GetPLDMVersion -t %s'
49
50'''
51e.g. : PLDM raw command usage
52
53pldmtool raw -d 0x80 0x00 0x03 0x00 0x00 0x00 0x00 0x01 0x00
54
55pldm raw -d 0x<header> 0x<pldm_type> 0x<pldm_cmd_type> 0x<payload_data>
56'''
57
58CMD_PLDMTOOL_RAW = 'raw -d 0x80' + '0x%s' + ' ' + '0x%s'
59
60
61# PLDM command payload data.
62
63PAYLOAD_GetPLDMVersion = \
64    ' 0x00 0x00 0x00 0x00 0x%s 0x%s'    # %(TransferOperationFlag, PLDMType)
65
66
67'''
68e.g. : SetDateTime usage
69
70pldmtool bios SetDateTime -d <YYYYMMDDHHMMSS>
71
72'''
73CMD_SETDATETIME = 'bios SetDateTime -d %s'
74
75
76CMD_GETPDR = 'platform GetPDR -d %s'
77
78'''
79e.g. : SetStateEffecterStates usage
80
81pldmtool platform GetPDR -i <effter_handle> -c <count> -d <effecterID, effecterState>
82
83pldmtool platform SetStateEffecterStates -i 1 -c 1 -d 1 1
84'''
85
86CMD_SETSTATEEFFECTERSTATES = 'platform SetStateEffecterStates -i %s -c %s -d %s'
87
88# GetPDR parsed response message for record handle.
89# Dictionary value array holds the expected output for record handle 1, 2.
90#
91# Note :
92#      Record handle - 0 is default &  has same behaviour as record handle 1
93#      Only record handle 0, 1, 2 are supported as of now.
94
95RESPONSE_DICT_GETPDR_SETSTATEEFFECTER = {
96    'PDRHeaderVersion': [1],
97    'PDRType': ['State Effecter PDR'],
98    'recordChangeNumber': [0],
99    'PLDMTerminusHandle': [0, 1, 2],
100    'effecterID': [0, 1, 2, 3, 4],
101    'entityType': ['Virtual Machine Manager', 'System chassis (main enclosure)',
102                   'System Firmware', 'Processor Module', '32801(OEM)'],
103    'entityInstanceNumber': [0, 1],
104    'containerID': [0, 1],
105    'effecterSemanticID': [0],
106    'effecterInit': ['noInit'],
107    'effecterDescriptionPDR': [False],
108    'compositeEffecterCount': [1],
109    'stateSetID': ['Boot Progress(196)',
110                   'System Power State(260)', 'Software Termination Status(129)',
111                   'Boot/Restart Cause(192)']}
112
113RESPONSE_DICT_GETPDR_FRURECORDSETIDENTIFIER = {
114    'PDRHeaderVersion': [1],
115    'PDRType': ['FRU Record Set PDR'],
116    'recordChangeNumber': [0],
117    'dataLength': [10],
118    'PLDMTerminusHandle': [0, 2],
119    'entityType': ['System Board', 'Chassis front panel board (control panel)',
120                   'Management Controller', 'OEM', 'Power converter',
121                   'System (logical)', 'System chassis (main enclosure)',
122                   'Chassis front panel board (control panel)',
123                   'Processor Module', 'Memory Module', 'Power Supply',
124                   '24576(OEM)'],
125    'containerID': [0, 1, 2, 3]}
126
127RESPONSE_DICT_GETPDR_PDRENTITYASSOCIATION = {
128    'PDRHeaderVersion': [1],
129    'PDRType': ['Entity Association PDR'],
130    'recordChangeNumber': [0],
131    'containerID': [1, 2, 3],
132    'associationtype': ['Physical'],
133    'containerentityType': ['System Board', 'System (logical)',
134                            'System chassis (main enclosure)']}
135
136RESPONSE_DICT_GETPDR_STATESENSORPDR = {
137    'entityType': ['Communication Channel', 'Connector', 'Processor Module',
138                   '32774(OEM)', '57346(OEM)', '57347(OEM)', '32801(OEM)'],
139    'sensorInit': ['noInit'],
140    'sensorAuxiliaryNamesPDR': [False],
141    'stateSetID': ['Availability(2)', 'Configuration State(15)',
142                   'Operational Running Status(11)', 'Software Termination Status(129)']}
143
144RESPONSE_DICT_GETPDR_TERMINUSLOCATORPDR = {
145    'PDRHeaderVersion': [1],
146    'PDRType': ['Terminus Locator PDR'],
147    'recordChangeNumber': [0],
148    'PLDMTerminusHandle': [1],
149    'validity': ['valid'],
150    'TID': [1, 208],
151    'containerID': [0, 1],
152    'terminusLocatorType': ['MCTP_EID'],
153    'terminusLocatorValueSize': [1]}
154
155RESPONSE_DICT_GETPDR_NUMERICEFFECTERPDR = {
156    'PDRHeaderVersion': [1],
157    'PDRType': ['Numeric Effecter PDR'],
158    'recordChangeNumber': [0],
159    'PLDMTerminusHandle': [0, 1],
160    'entityInstanceNumber': [0, 1],
161    'containerID': [0],
162    'effecterSemanticID': [0],
163    'effecterInit': [0],
164    'effecterAuxiliaryNames': [False],
165    'baseUnit': [0, 72],
166    'unitModifier': [0],
167    'rateUnit': [0],
168    'baseOEMUnitHandle': [0],
169    'auxUnit': [0],
170    'auxUnitModifier': [0],
171    'auxrateUnit': [0],
172    'auxOEMUnitHandle': [0],
173    'resolution': [1, 0],
174    'offset': [0],
175    'accuracy': [0],
176    'plusTolerance': [0],
177    'minusTolerance': [0],
178    'stateTransitionInterval': [0],
179    'TransitionInterval': [0],
180    'minSettable': [0],
181    'rangeFieldSupport': [0],
182    'nominalValue': [0],
183    'normalMax': [0],
184    'normalMin': [0],
185    'ratedMax': [0],
186    'ratedMin': [0]}
187
188PLDM_PDR_TYPES = {
189    'PLDM_STATE_EFFECTER_PDR': 'State Effecter PDR',
190    'PLDM_PDR_FRU_RECORD_SET': 'FRU Record Set PDR',
191    'PLDM_PDR_ENTITY_ASSOCIATION': 'Entity Association PDR',
192    'PLDM_STATE_SENSOR_PDR': 'State Sensor PDR',
193    'PLDM_NUMERIC_EFFECTER_PDR': 'Numeric Effecter PDR',
194    'PLDM_TERMINUS_LOCATOR_PDR': 'Terminus Locator PDR',
195    'PLDM_COMPACT_NUMERIC_SENSOR_PDR': '21'}
196
197RESPONSE_LIST_GETBIOSTABLE_STRTABLE = [
198    'Allowed', 'Disabled', 'Enabled', 'IPv4DHCP', 'IPv4Static', 'Not Allowed',
199    'Perm', 'Temp', 'pvm-fw-boot-side', 'pvm-inband-code-update', 'pvm-os-boot-side',
200    'pvm-pcie-error-inject', 'pvm-surveillance', 'pvm-system-name', 'vmi-hostname',
201    'vmi-if-count', 'vmi-if0-ipv4-ipaddr', 'vmi-if0-ipv4-method',
202    'vmi-if0-ipv4-prefix-length', 'vmi-if1-ipv4-ipaddr', 'vmi-if1-ipv4-method',
203    'vmi-if1-ipv4-prefix-length', 'vmi-ipv4-gateway']
204
205
206RESPONSE_LIST_GETBIOSTABLE_ATTRTABLE = [
207    'pvm-fw-boot-side', 'pvm-inband-code-update', 'pvm-os-boot-side',
208    'pvm-pcie-error-inject', 'pvm-surveillance', 'pvm-system-name', 'vmi-hostname',
209    'vmi-if-count', 'vmi-if0-ipv4-ipaddr', 'vmi-if0-ipv4-method',
210    'vmi-if0-ipv4-prefix-length', 'vmi-if1-ipv4-ipaddr', 'vmi-if1-ipv4-method',
211    'vmi-if1-ipv4-prefix-length', 'vmi-ipv4-gateway']
212
213RESPONSE_LIST_GETBIOSTABLE_ATTRVALTABLE = [
214    'BIOSString', 'BIOSInteger', 'BIOSEnumeration']
215