-
Notifications
You must be signed in to change notification settings - Fork 6
/
ipmi_app.go
280 lines (254 loc) · 11.7 KB
/
ipmi_app.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package virtualbmc
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/cybozu-go/log"
)
// port from OpenIPMI
// App Network Function
const (
ipmiCmdGetDeviceID = 0x01
ipmiCmdBroadcastGetDeviceID = 0x01
ipmiCmdColdReset = 0x02
ipmiCmdWarmReset = 0x03
ipmiCmdGetSelfTestResults = 0x04
ipmiCmdManufacturingTestOn = 0x05
ipmiCmdSetACPIPowerState = 0x06
ipmiCmdGetACPIPowerState = 0x07
ipmiCmdGetDeviceGUID = 0x08
ipmiCmdResetWatchdogTimer = 0x22
ipmiCmdSetWatchdogTimer = 0x24
ipmiCmdGetWatchdogTimer = 0x25
ipmiCmdSetBMCGlobalEnables = 0x2e
ipmiCmdGetBMCGlobalEnables = 0x2f
ipmiCmdClearMSGFlags = 0x30
ipmiCmdGetMSGFlags = 0x31
ipmiCmdEnableMessageChannelRCV = 0x32
ipmiCmdGetMSG = 0x33
ipmiCmdSendMSG = 0x34
ipmiCmdReadEventMSGBuffer = 0x35
ipmiCmdGetBTInterfaceCapabilities = 0x36
ipmiCmdGetSystemGUID = 0x37
ipmiCmdGetChannelAuthCapabilities = 0x38
ipmiCmdGetSessionChallenge = 0x39
ipmiCmdActivateSession = 0x3a
ipmiCmdSetSessionPrivilege = 0x3b
ipmiCmdCloseSession = 0x3c
ipmiCmdGetSessionInfo = 0x3d
ipmiCmdGetAuthCode = 0x3f
ipmiCmdSetChannelAccess = 0x40
ipmiCmdGetChannelAccess = 0x41
ipmiCmdGetChannelInfo = 0x42
ipmiCmdSetUserAccess = 0x43
ipmiCmdGetUserAccess = 0x44
ipmiCmdSetUserName = 0x45
ipmiCmdGetUserName = 0x46
ipmiCmdSetUserPassword = 0x47
ipmiCmdActivatePayload = 0x48
ipmiCmdDeactivatePayload = 0x49
ipmiCmdGetPayloadActivationStatus = 0x4a
ipmiCmdGetPayloadInstanceInfo = 0x4b
ipmiCmdSetUserPayloadAccess = 0x4c
ipmiCmdGetUserPayloadAccess = 0x4d
ipmiCmdGetChannelPayloadSupport = 0x4e
ipmiCmdGetChannelPayloadVersion = 0x4f
ipmiCmdGetChannelOEMPayloadInfo = 0x50
ipmiCmdMasterReadWrite = 0x52
ipmiCmdGetChannelCipherSuites = 0x54
ipmiCmdSuspendResumePayloadEncryption = 0x55
ipmiCmdSetChannelSecurityKey = 0x56
ipmiCmdGetSystemInterfaceCapabilities = 0x57
)
const (
authBitmaskNone = 0x01
authBitmaskMD2 = 0x02
authBitmaskMD5 = 0x04
authBitmaskStraightKey = 0x10
authBitmaskOEM = 0x20
authBitmaskIPMIV2 = 0x80
)
const (
authStatusAnonymous = 0x01
authStatusNullUser = 0x02
authStatusNonNullUser = 0x04
authStatusUserLevel = 0x08
authStatusPerMessage = 0x10
authStatusKG = 0x20
)
const (
extendedCapabilitiesChannel15 = 0x01
extendedCapabilitiesChannel20 = 0x02
)
type ipmiAuthenticationCapabilitiesRequest struct {
AutnticationTypeSupport uint8
RequestedPrivilegeLevel uint8
}
type ipmiAuthenticationCapabilitiesResponse struct {
Channel uint8
AuthenticationTypeSupport uint8
AuthenticationStatus uint8
ExtCapabilities uint8 // In ipmi v1.5, 0 is always put here. (Reserved)
OEMID [3]uint8
OEMAuxiliaryData uint8
}
type ipmiSetSessionPrivilegeLevelRequest struct {
RequestPrivilegeLevel uint8
}
type ipmiSetSessionPrivilegeLevelResponse struct {
NewPrivilegeLevel uint8
}
type ipmiCloseSessionRequest struct {
SessionID uint32
}
func (i *ipmi) handleIPMIApp(message *ipmiMessage) ([]byte, error) {
switch message.Command {
case ipmiCmdGetChannelAuthCapabilities:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_CHANNEL_AUTH_CAPABILITIES", map[string]interface{}{})
return handleIPMIAuthenticationCapabilities(message)
case ipmiCmdSetSessionPrivilege:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_SESSION_PRIVILEGE", map[string]interface{}{})
return handleIPMISetSessionPrivilegeLevel(message)
case ipmiCmdCloseSession:
log.Info(" ipmi APP: Command = IPMI_CMD_CLOSE_SESSION", map[string]interface{}{})
return nil, i.handleIPMICloseSession(message)
case ipmiCmdGetDeviceID:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_DEVICE_ID", map[string]interface{}{})
case ipmiCmdColdReset:
log.Info(" ipmi APP: Command = IPMI_CMD_COLD_RESET", map[string]interface{}{})
case ipmiCmdWarmReset:
log.Info(" ipmi APP: Command = IPMI_CMD_WARM_RESET", map[string]interface{}{})
case ipmiCmdGetSelfTestResults:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_SELF_TEST_RESULTS", map[string]interface{}{})
case ipmiCmdManufacturingTestOn:
log.Info(" ipmi APP: Command = IPMI_CMD_MANUFACTURING_TEST_ON", map[string]interface{}{})
case ipmiCmdSetACPIPowerState:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_ACPI_POWER_STATE", map[string]interface{}{})
case ipmiCmdGetACPIPowerState:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_ACPI_POWER_STATE", map[string]interface{}{})
case ipmiCmdGetDeviceGUID:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_DEVICE_GUID", map[string]interface{}{})
case ipmiCmdResetWatchdogTimer:
log.Info(" ipmi APP: Command = IPMI_CMD_RESET_WATCHDOG_TIMER", map[string]interface{}{})
case ipmiCmdSetWatchdogTimer:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_WATCHDOG_TIMER", map[string]interface{}{})
case ipmiCmdGetWatchdogTimer:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_WATCHDOG_TIMER", map[string]interface{}{})
case ipmiCmdSetBMCGlobalEnables:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_BMC_GLOBAL_ENABLES", map[string]interface{}{})
case ipmiCmdGetBMCGlobalEnables:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_BMC_GLOBAL_ENABLES", map[string]interface{}{})
case ipmiCmdClearMSGFlags:
log.Info(" ipmi APP: Command =IPMI_CMD_CLEAR_MSG_FLAGS", map[string]interface{}{})
case ipmiCmdGetMSGFlags:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_MSG_FLAGS", map[string]interface{}{})
case ipmiCmdEnableMessageChannelRCV:
log.Info(" ipmi APP: Command = IPMI_CMD_ENABLE_MESSAGE_CHANNEL_RCV", map[string]interface{}{})
case ipmiCmdGetMSG:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_MSG", map[string]interface{}{})
case ipmiCmdSendMSG:
log.Info(" ipmi APP: Command = IPMI_CMD_SEND_MSG", map[string]interface{}{})
case ipmiCmdReadEventMSGBuffer:
log.Info(" ipmi APP: Command = IPMI_CMD_READ_EVENT_MSG_BUFFER", map[string]interface{}{})
case ipmiCmdGetBTInterfaceCapabilities:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_BT_INTERFACE_CAPABILITIES", map[string]interface{}{})
case ipmiCmdGetSystemGUID:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_SYSTEM_GUID", map[string]interface{}{})
case ipmiCmdGetSessionChallenge:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_SESSION_CHALLENGE", map[string]interface{}{})
case ipmiCmdActivateSession:
log.Info(" ipmi APP: Command = IPMI_CMD_ACTIVATE_SESSION", map[string]interface{}{})
case ipmiCmdGetSessionInfo:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_SESSION_INFO", map[string]interface{}{})
case ipmiCmdGetAuthCode:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_AUTHCODE", map[string]interface{}{})
case ipmiCmdSetChannelAccess:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_CHANNEL_ACCESS", map[string]interface{}{})
case ipmiCmdGetChannelAccess:
log.Info(" ipmi APP: Command =IPMI_CMD_GET_CHANNEL_ACCESS", map[string]interface{}{})
case ipmiCmdGetChannelInfo:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_CHANNEL_INFO", map[string]interface{}{})
case ipmiCmdSetUserAccess:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_USER_ACCESS", map[string]interface{}{})
case ipmiCmdGetUserAccess:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_USER_ACCESS", map[string]interface{}{})
case ipmiCmdSetUserName:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_USER_NAME", map[string]interface{}{})
case ipmiCmdGetUserName:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_USER_NAME", map[string]interface{}{})
case ipmiCmdSetUserPassword:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_USER_PASSWORD", map[string]interface{}{})
case ipmiCmdActivatePayload:
log.Info(" ipmi APP: Command = IPMI_CMD_ACTIVATE_PAYLOAD", map[string]interface{}{})
case ipmiCmdDeactivatePayload:
log.Info(" ipmi APP: Command = IPMI_CMD_DEACTIVATE_PAYLOAD", map[string]interface{}{})
case ipmiCmdGetPayloadActivationStatus:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_PAYLOAD_ACTIVATION_STATUS", map[string]interface{}{})
case ipmiCmdGetPayloadInstanceInfo:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_PAYLOAD_INSTANCE_INFO", map[string]interface{}{})
case ipmiCmdSetUserPayloadAccess:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_USER_PAYLOAD_ACCESS", map[string]interface{}{})
case ipmiCmdGetUserPayloadAccess:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_USER_PAYLOAD_ACCESS", map[string]interface{}{})
case ipmiCmdGetChannelPayloadSupport:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_CHANNEL_PAYLOAD_SUPPORT", map[string]interface{}{})
case ipmiCmdGetChannelPayloadVersion:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_CHANNEL_PAYLOAD_VERSION", map[string]interface{}{})
case ipmiCmdGetChannelOEMPayloadInfo:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_CHANNEL_OEM_PAYLOAD_INFO", map[string]interface{}{})
case ipmiCmdMasterReadWrite:
log.Info(" ipmi APP: Command = IPMI_CMD_MASTER_READ_WRITE", map[string]interface{}{})
case ipmiCmdGetChannelCipherSuites:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_CHANNEL_CIPHER_SUITES", map[string]interface{}{})
case ipmiCmdSuspendResumePayloadEncryption:
log.Info(" ipmi APP: Command = IPMI_CMD_SUSPEND_RESUME_PAYLOAD_ENCRYPTION", map[string]interface{}{})
case ipmiCmdSetChannelSecurityKey:
log.Info(" ipmi APP: Command = IPMI_CMD_SET_CHANNEL_SECURITY_KEY", map[string]interface{}{})
case ipmiCmdGetSystemInterfaceCapabilities:
log.Info(" ipmi APP: Command = IPMI_CMD_GET_SYSTEM_INTERFACE_CAPABILITIES", map[string]interface{}{})
}
return nil, fmt.Errorf("unsupported Command: %x", message.Command)
}
func handleIPMISetSessionPrivilegeLevel(message *ipmiMessage) ([]byte, error) {
buf := bytes.NewBuffer(message.Data)
request := ipmiSetSessionPrivilegeLevelRequest{}
if err := binary.Read(buf, binary.LittleEndian, &request); err != nil {
return nil, fmt.Errorf("failed to read ipmiSetSessionPrivilegeLevelRequest: %w", err)
}
response := ipmiSetSessionPrivilegeLevelResponse{}
response.NewPrivilegeLevel = request.RequestPrivilegeLevel
dataBuf := bytes.Buffer{}
if err := binary.Write(&dataBuf, binary.LittleEndian, response); err != nil {
return nil, err
}
return dataBuf.Bytes(), nil
}
func handleIPMIAuthenticationCapabilities(message *ipmiMessage) ([]byte, error) {
buf := bytes.NewBuffer(message.Data)
request := ipmiAuthenticationCapabilitiesRequest{}
if err := binary.Read(buf, binary.LittleEndian, &request); err != nil {
return nil, fmt.Errorf("failed to read ipmiAuthenticationCapabilitiesRequest: %w", err)
}
// prepare for response data
// We don't simulate OEM related behavior
response := ipmiAuthenticationCapabilitiesResponse{}
response.Channel = 1
response.AuthenticationTypeSupport = authBitmaskIPMIV2 | authBitmaskMD5 | authBitmaskMD2 | authBitmaskNone
response.AuthenticationStatus = authStatusNonNullUser | authStatusNullUser
response.ExtCapabilities = extendedCapabilitiesChannel20
response.OEMAuxiliaryData = 0
dataBuf := bytes.Buffer{}
if err := binary.Write(&dataBuf, binary.LittleEndian, response); err != nil {
return nil, fmt.Errorf("failed to write ipmiAuthenticationCapabilitiesResponse: %w", err)
}
return dataBuf.Bytes(), nil
}
func (i *ipmi) handleIPMICloseSession(message *ipmiMessage) error {
buf := bytes.NewBuffer(message.Data)
request := ipmiCloseSessionRequest{}
if err := binary.Read(buf, binary.LittleEndian, &request); err != nil {
return err
}
i.session.removeRMCPPlusSession(request.SessionID)
return nil
}