-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcmd_get_device_id.go
221 lines (191 loc) · 7.1 KB
/
cmd_get_device_id.go
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package ipmi
import (
"context"
"fmt"
"strings"
)
// 20.1 Get Device ID Command
type GetDeviceIDRequest struct {
// empty
}
type GetDeviceIDResponse struct {
DeviceID uint8
// [7] 1 = device provides Device SDRs
// 0 = device does not provide Device SDRs
// [6:4] reserved. Return as 0.
ProvideDeviceSDRs bool
// [3:0] Device Revision, binary encoded
DeviceRevision uint8
// [7] Device available: 0=normal operation, 1= device firmware, SDR
// Repository update or self-initialization in progress. [Firmware / SDR
// Repository updates can be differentiated by issuing a Get SDR
// command and checking the completion code.]
DeviceAvailable bool
// [6:0] Major Firmware Revision, binary encoded
MajorFirmwareRevision uint8
// BCD encoded
MinorFirmwareRevision uint8
// Holds IPMI Command Specification Version. BCD encoded.
// 00h = reserved.
// Bits 7:4 hold the Least Significant digit of the revision, while
// bits 3:0 hold the Most Significant bits.
// E.g. a value of 51h indicates revision 1.5 functionality.
// 02h for implementations that provide IPMI v2.0 capabilities
// per this specification.
MajorIPMIVersion uint8
MinorIPMIVersion uint8
AdditionalDeviceSupport
// Manufacturer ID, LS Byte first. The manufacturer ID is a 20-bit value that is
// derived from the IANA Private Enterprise ID (see below).
// Most significant four bits = reserved (0000b).
// 000000h = unspecified. 0FFFFFh = reserved. This value is binary encoded.
// E.g. the ID for the IPMI forum is 7154 decimal, which is 1BF2h, which would
// be stored in this record as F2h, 1Bh, 00h for bytes 8 through 10, respectively
ManufacturerID uint32 // only 3 bytes used
// Product ID, LS Byte first. This field can be used to provide a number that
// identifies a particular system, module, add-in card, or board set. The number
// is specified according to the manufacturer given by Manufacturer ID (see
// below).
// 0000h = unspecified. FFFFh = reserved.
ProductID uint16
// Auxiliary Firmware Revision Information. This field is optional. If present, it
// holds additional information about the firmware revision, such as boot block or
// internal data structure version numbers. The meanings of the numbers are
// specific to the vendor identified by Manufacturer ID (see below). When the
// vendor-specific definition is not known, generic utilities should display each
// byte as 2-digit hexadecimal numbers, with byte 13 displayed first as the most-significant byte.
AuxiliaryFirmwareRevision []byte // 4 bytes
}
// Additional Device Support (formerly called IPM Device Support). Lists the
// IPMI 'logical device' commands and functions that the controller supports that
// are in addition to the mandatory IPM and Application commands.
// [7] Chassis Device (device functions as chassis device per ICMB spec.)
// [6] Bridge (device responds to Bridge NetFn commands)
// [5] IPMB Event Generator (device generates event messages [platform
// event request messages] onto the IPMB)
// [4] IPMB Event Receiver (device accepts event messages [platform event
// request messages] from the IPMB)
// [3] FRU Inventory Device
// [2] SEL Device
// [1] SDR Repository Device
// [0] Sensor Device
type AdditionalDeviceSupport struct {
SupportChassis bool
SupportBridge bool
SupportIPMBEventGenerator bool
SupportIPMBEventReceiver bool
SupportFRUInventory bool
SupportSEL bool
SupportSDRRepo bool
SupportSensor bool
}
func (req *GetDeviceIDRequest) Command() Command {
return CommandGetDeviceID
}
func (req *GetDeviceIDRequest) Pack() []byte {
return []byte{}
}
func (res *GetDeviceIDResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetDeviceIDResponse) Unpack(msg []byte) error {
if len(msg) < 11 {
return ErrUnpackedDataTooShortWith(len(msg), 11)
}
res.DeviceID, _, _ = unpackUint8(msg, 0)
b2, _, _ := unpackUint8(msg, 1)
res.ProvideDeviceSDRs = isBit7Set(b2)
res.DeviceRevision = b2 & 0x0f
b3, _, _ := unpackUint8(msg, 2)
res.DeviceAvailable = !isBit7Set(b3)
res.MajorFirmwareRevision = b3 & 0x7f // binary encoded
b4, _, _ := unpackUint8(msg, 3) // BCD encoded
res.MinorFirmwareRevision = bcdUint8(b4)
ipmiVersionBCD, _, _ := unpackUint8(msg, 4) // BCD encoded
res.MajorIPMIVersion = ipmiVersionBCD & 0x0f
res.MinorIPMIVersion = ipmiVersionBCD >> 4
b6, _, _ := unpackUint8(msg, 5)
res.SupportChassis = isBit7Set(b6)
res.SupportBridge = isBit6Set(b6)
res.SupportIPMBEventGenerator = isBit5Set(b6)
res.SupportIPMBEventReceiver = isBit4Set(b6)
res.SupportFRUInventory = isBit3Set(b6)
res.SupportSEL = isBit2Set(b6)
res.SupportSDRRepo = isBit1Set(b6)
res.SupportSensor = isBit0Set(b6)
res.ManufacturerID, _, _ = unpackUint24L(msg, 6)
res.ProductID, _, _ = unpackUint16L(msg, 9)
if len(msg) > 11 && len(msg) < 15 {
return ErrUnpackedDataTooShortWith(len(msg), 15)
} else {
res.AuxiliaryFirmwareRevision, _, _ = unpackBytes(msg, 11, 4)
}
return nil
}
func (res *GetDeviceIDResponse) FirmwareVersionStr() string {
return fmt.Sprintf("%d.%d", res.MajorFirmwareRevision, res.MinorFirmwareRevision)
}
func (res *GetDeviceIDResponse) Format() string {
deviceSupport := []string{}
if res.SupportChassis {
deviceSupport = append(deviceSupport, " Chassis Device")
}
if res.SupportBridge {
deviceSupport = append(deviceSupport, " Bridge Device")
}
if res.SupportIPMBEventGenerator {
deviceSupport = append(deviceSupport, " IPMB Event Generator")
}
if res.SupportIPMBEventReceiver {
deviceSupport = append(deviceSupport, " IPMB Event Receiver")
}
if res.SupportFRUInventory {
deviceSupport = append(deviceSupport, " FRU Inventory Device")
}
if res.SupportSEL {
deviceSupport = append(deviceSupport, " SEL Device")
}
if res.SupportSDRRepo {
deviceSupport = append(deviceSupport, " SDR Repo Device")
}
if res.SupportSensor {
deviceSupport = append(deviceSupport, " Sensor Device")
}
auxFirmwareInfo := []string{}
for _, v := range res.AuxiliaryFirmwareRevision {
auxFirmwareInfo = append(auxFirmwareInfo, fmt.Sprintf(" %#02x", v))
}
return fmt.Sprintf(`Device ID : %d
Device Revision : %d
Firmware Revision : %d.%d
IPMI Version : %d.%d
Manufacturer ID : %d (%#02x)
Manufacturer Name : %s
Product ID : %d (%#04x)
Product Name : %#02x
Device Available : %s
Provides Device SDRs : %s
Additional Device Support :
%s
Aux Firmware Rev Info :
%s`,
res.DeviceID,
res.DeviceRevision,
res.MajorFirmwareRevision, res.MinorFirmwareRevision,
res.MajorIPMIVersion, res.MinorIPMIVersion,
res.ManufacturerID, res.ManufacturerID,
OEM(res.ManufacturerID),
res.ProductID, res.ProductID,
res.ProductID,
formatBool(res.DeviceAvailable, "yes", "no"),
formatBool(res.ProvideDeviceSDRs, "yes", "no"),
strings.Join(deviceSupport, " \n"),
strings.Join(auxFirmwareInfo, " \n"),
)
}
func (c *Client) GetDeviceID(ctx context.Context) (response *GetDeviceIDResponse, err error) {
request := &GetDeviceIDRequest{}
response = &GetDeviceIDResponse{}
err = c.Exchange(ctx, request, response)
return
}