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