/
completion_code.go
76 lines (63 loc) · 2.8 KB
/
completion_code.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
package ipmi
import (
"fmt"
)
// CompletionCode indicates whether a command executed successfully. It is
// analogous to a command status code. It is a 1 byte uint on the wire. Values
// are specified in Table 5-2 of the IPMI v2.0 spec.
//
// N.B. if the completion code is not 0, the rest of the response may be
// truncated, and if it is not, the remaining structure is OEM-dependent, so in
// practice the rest of the message should be uninterpreted.
type CompletionCode uint8
const (
CompletionCodeNormal CompletionCode = 0x0
// CompletionCodeInvalidSessionID is returned by Close Session if the
// specified session ID does not match one the BMC knows about. Whether
// this is also returned if the used doesn't have the required privileges
// is untested.
CompletionCodeInvalidSessionID CompletionCode = 0x87
CompletionCodeNodeBusy CompletionCode = 0xc0
CompletionCodeUnrecognisedCommand CompletionCode = 0xc1
CompletionCodeTimeout CompletionCode = 0xc3
// CompletionCodeReservationCanceledOrInvalid means that either the
// requester's reservation has been canceled or the request's reservation
// ID is invalid.
CompletionCodeReservationCanceledOrInvalid CompletionCode = 0xc5
// CompletionCodeRequestTruncated means the request ended prematurely. Did
// you forget to add the final request data layer?
CompletionCodeRequestTruncated CompletionCode = 0xc6
// CompletionCodeInsufficientPrivileges indicates the channel or effective
// user privilege level is insufficient to execute the command, or the
// request was blocked by the firmware firewall.
CompletionCodeInsufficientPrivileges CompletionCode = 0xd4
CompletionCodeUnspecified CompletionCode = 0xff
)
var (
completionCodeDescriptions = map[CompletionCode]string{
CompletionCodeNormal: "Normal",
CompletionCodeInvalidSessionID: "Invalid Session ID",
CompletionCodeNodeBusy: "Node Busy",
CompletionCodeUnrecognisedCommand: "Unrecognised Command",
CompletionCodeTimeout: "Timeout",
CompletionCodeRequestTruncated: "Request Truncated",
CompletionCodeInsufficientPrivileges: "Insufficient Privileges",
CompletionCodeUnspecified: "Unspecified Error",
}
)
func (c CompletionCode) Description() string {
if description, ok := completionCodeDescriptions[c]; ok {
return description
}
return "Unknown"
}
// IsTemporary returns whether the code indicates a retry may produce a
// successful result, or the error is permanent.
func (c CompletionCode) IsTemporary() bool {
// at some point, will be more efficient implemented as
// map[CompletionCode]struct{}, but this is sufficient for now
return c == CompletionCodeNodeBusy || c == CompletionCodeTimeout
}
func (c CompletionCode) String() string {
return fmt.Sprintf("%#.2x(%v)", uint8(c), c.Description())
}