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'}
15
16VERSION_BASE = {'VALUE': ['f1', 'f0', 'f0', '00'], 'STRING': '1.0.0'}
17VERSION_PLATFORM = {'VALUE': ['f1', 'f2', 'f0', '00'], 'STRING': '1.2.0'}
18VERSION_BIOS = {'VALUE': ['f1', 'f1', 'f1', '00'], 'STRING': '1.0.0'}
19VERSION_FRU = {'VALUE': ['f1', 'f0', 'f0', '00'], 'STRING': '1.0.0'}
20VERSION_OEM = {'VALUE': ['f1', 'f0', 'f0', '00'], 'STRING': '1.0.0'}
21
22
23PLDM_BASE_CMDS = ['2(GetTID)', '3(GetPLDMVersion)', '4(GetPLDMTypes)', '5(GetPLDMCommands)']
24PLDM_PLATFORM_CMDS = ['57(SetStateEffecterStates)', '81(GetPDR)']
25PLDM_BIOS_CMDS = ['1(GetBIOSTable)', '7(SetBIOSAttributeCurrentValue)',
26                  '8(GetBIOSAttributeCurrentValueByHandle)', '12(GetDateTime)',
27                  '13(SetDateTime)']
28PLDM_FRU_CMDS = ['1(GetFRURecordTableMetadata)', '2(GetFRURecordTable)', '4(GetFRURecordByOption)']
29PLDM_OEM_CMDS = ['1(GetFileTable)', '4(ReadFile)', '5(WriteFile)', '6(ReadFileInToMemory)',
30                 '7(WriteFileFromMemory)', '8(ReadFileByTypeIntoMemory)',
31                 '9(WriteFileByTypeFromMemory)', '10(NewFileAvailable)',
32                 '11(ReadFileByType)', '12(WriteFileByType)', '13(FileAck)',
33                 '240(GetAlertStatus)']
34
35# PLDM command format.
36
37'''
38e.g. : GetPLDMVersion usage
39
40pldmtool base GetPLDMVersion -t <pldm_type>
41
42pldm supported types
43
44base->0,platform->2,bios->3,fru->4
45
46'''
47CMD_GETPLDMVERSION = 'base GetPLDMVersion -t %s'
48
49'''
50e.g. : PLDM raw command usage
51
52pldmtool raw -d 0x80 0x00 0x03 0x00 0x00 0x00 0x00 0x01 0x00
53
54pldm raw -d 0x<header> 0x<pldm_type> 0x<pldm_cmd_type> 0x<payload_data>
55'''
56
57CMD_PLDMTOOL_RAW = 'raw -d 0x80' + '0x%s' + ' ' + '0x%s'
58
59
60# PLDM command payload data.
61
62PAYLOAD_GetPLDMVersion = \
63    ' 0x00 0x00 0x00 0x00 0x%s 0x%s'    # %(TransferOperationFlag, PLDMType)
64
65
66'''
67e.g. : SetDateTime usage
68
69pldmtool bios SetDateTime -d <YYYYMMDDHHMMSS>
70
71'''
72CMD_SETDATETIME = 'bios SetDateTime -d %s'
73
74
75CMD_GETPDR = 'platform GetPDR -d %s'
76
77'''
78e.g. : SetStateEffecterStates usage
79
80pldmtool platform GetPDR -i <effter_handle> -c <count> -d <effecterID, effecterState>
81
82pldmtool platform SetStateEffecterStates -i 1 -c 1 -d 1 1
83'''
84
85CMD_SETSTATEEFFECTERSTATES = 'platform SetStateEffecterStates -i %s -c %s -d %s'
86
87# GetPDR parsed response message for record handle.
88# Dictionary value array holds the expected output for record handle 1, 2.
89#
90# Note :
91#      Record handle - 0 is default &  has same behaviour as record handle 1
92#      Only record handle 0, 1, 2 are supported as of now.
93
94RESPONSE_DICT_GETPDR_SETSTATEEFFECTER = {
95    'responsecount': ['29', '30'],
96    'pdrheaderversion': ['1'],
97    'pdrtype': ['11'],
98    'recordchangenumber': ['0'],
99    'datalength': ['19', '20'],
100    'pldmterminushandle': ['0'],
101    'effecterid': ['1', '2', '3'],
102    'entitytype': ['33', '45', '31'],
103    'entityinstancenumber': ['0'],
104    'containerid': ['0'],
105    'effectersemanticid': ['0'],
106    'effecterinit': ['0'],
107    'effecterdescriptionpdr': ['false'],
108    'compositeeffectercount': ['1'],
109    'statesetid': ['196', '260', '129'],
110    'possiblestatessize': ['1', '2'],
111    'possiblestates': ['6', '0', '64']}
112
113RESPONSE_DICT_GETPDR_FRURECORDSETIDENTIFIER = {
114    'responsecount': ['20'],
115    'pdrheaderversion': ['1'],
116    'pdrtype': ['20'],
117    'recordchangenumber': ['0'],
118    'datalength': ['10'],
119    'pldmterminushandle': ['0', '2'],
120    'entitytype': ['System Board', 'Chassis front panel board (control panel)',
121                   'Management Controller', 'OEM', 'Power converter',
122                   'System (logical)', 'System chassis (main enclosure)',
123                   'Chassis front panel board (control panel)',
124                   'Processor Module', 'Memory Module'],
125    'containerid': ['0', '1', '2', '3']}
126
127RESPONSE_DICT_GETPDR_PDRENTITYASSOCIATION = {
128    'pdrheaderversion': ['1'],
129    'pdrtype': ['15'],
130    'recordchangenumber': ['0'],
131    'containerid': ['1', '2', '3'],
132    'associationtype': ['Physical'],
133    'containerentitytype': ['System Board', 'System (logical)',
134                            'System chassis (main enclosure)']
135}
136
137PLDM_PDR_TYPES = {
138    'PLDM_STATE_EFFECTER_PDR': '11',
139    'PLDM_PDR_FRU_RECORD_SET': '20',
140    'PLDM_PDR_ENTITY_ASSOCIATION': '15',
141    'PLDM_STATE_SENSOR_PDR': '4',
142    'PLDM_NUMERIC_EFFECTER_PDR': '9'}
143
144RESPONSE_LIST_GETBIOSTABLE_STRTABLE = [
145    'Allowed', 'Disabled', 'Enabled', 'IPv4DHCP', 'IPv4Static', 'Not Allowed',
146    'Perm', 'Temp', 'pvm-fw-boot-side', 'pvm-inband-code-update', 'pvm-os-boot-side',
147    'pvm-pcie-error-inject', 'pvm-surveillance', 'pvm-system-name', 'vmi-hostname',
148    'vmi-if-count', 'vmi-if0-ipv4-ipaddr', 'vmi-if0-ipv4-method',
149    'vmi-if0-ipv4-prefix-length', 'vmi-if1-ipv4-ipaddr', 'vmi-if1-ipv4-method',
150    'vmi-if1-ipv4-prefix-length', 'vmi-ipv4-gateway']
151