-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcmd_get_watchdog_timer.go
153 lines (130 loc) · 3.38 KB
/
cmd_get_watchdog_timer.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
package ipmi
import (
"context"
"fmt"
)
// 27.7 Get Watchdog Timer Command
type GetWatchdogTimerRequest struct {
// empty
}
func (req *GetWatchdogTimerRequest) Pack() []byte {
return []byte{}
}
func (req *GetWatchdogTimerRequest) Command() Command {
return CommandGetWatchdogTimer
}
type GetWatchdogTimerResponse struct {
DontLog bool
TimerIsStarted bool
TimerUse TimerUse
PreTimeoutInterrupt PreTimeoutInterrupt
TimeoutAction TimeoutAction
PreTimeoutIntervalSec uint8
ExpirationFlags uint8
InitialCountdown uint16
PresentCountdown uint16
}
func (res *GetWatchdogTimerResponse) Unpack(msg []byte) error {
if len(msg) < 8 {
return ErrUnpackedDataTooShortWith(len(msg), 8)
}
res.DontLog = isBit7Set(msg[0])
res.TimerIsStarted = isBit6Set(msg[0])
res.TimerUse = TimerUse(0x07 & msg[0])
res.PreTimeoutInterrupt = PreTimeoutInterrupt((0x70 & msg[1]) >> 4)
res.TimeoutAction = TimeoutAction(0x07 & msg[1])
res.PreTimeoutIntervalSec = msg[2]
res.ExpirationFlags = msg[3]
res.InitialCountdown, _, _ = unpackUint16L(msg, 4)
res.PresentCountdown, _, _ = unpackUint16L(msg, 6)
return nil
}
func (res *GetWatchdogTimerResponse) CompletionCodes() map[uint8]string {
// no command-specific cc
return map[uint8]string{}
}
func (res *GetWatchdogTimerResponse) Format() string {
return fmt.Sprintf(`Watchdog Timer Use: %s (%#02x)
Watchdog Timer Is: %s
Watchdog Timer Actions: %s (%#02x)
Pre-timeout interval: %d seconds
Timer Expiration Flags: %#02x
Initial Countdown: %d sec
Present Countdown: %d sec`,
res.TimerUse, uint8(res.TimerUse),
formatBool(res.TimerIsStarted, "Started", "Stopped"),
res.TimeoutAction, uint8(res.TimeoutAction),
res.PreTimeoutIntervalSec,
res.ExpirationFlags,
res.InitialCountdown,
res.PresentCountdown,
)
}
func (c *Client) GetWatchdogTimer(ctx context.Context) (response *GetWatchdogTimerResponse, err error) {
request := &GetWatchdogTimerRequest{}
response = &GetWatchdogTimerResponse{}
err = c.Exchange(ctx, request, response)
return
}
type TimerUse uint8
const (
TimerUseBIOSFRB2 TimerUse = 0x01 // BIOS/FRB2
TimerUseBIOSPOST TimerUse = 0x02 // BIOS/POST
TimerUseOSLoad TimerUse = 0x03
TimerUseSMSOS TimerUse = 0x04 // SMS/OS
TimerUseOEM TimerUse = 0x05
)
func (t TimerUse) String() string {
m := map[TimerUse]string{
0x01: "BIOS FRB2",
0x02: "BIOS/POST",
0x03: "OS Load",
0x04: "SMS/OS",
0x05: "OEM",
}
s, ok := m[t]
if ok {
return s
}
return ""
}
type PreTimeoutInterrupt uint8
const (
PreTimeoutInterruptNone PreTimeoutInterrupt = 0x00
PreTimeoutInterruptSMI PreTimeoutInterrupt = 0x01
PreTimeoutInterruptNMI PreTimeoutInterrupt = 0x02
PreTimeoutInterruptMessaging PreTimeoutInterrupt = 0x03
)
func (t PreTimeoutInterrupt) String() string {
m := map[PreTimeoutInterrupt]string{
0x00: "None",
0x01: "SMI",
0x02: "NMI / Diagnostic Interrupt",
0x03: "Messaging Interrupt",
}
s, ok := m[t]
if ok {
return s
}
return ""
}
type TimeoutAction uint8
const (
TimeoutActionNoAction TimeoutAction = 0x00
TimeoutActionHardReset TimeoutAction = 0x01
TimeoutActionPowerDown TimeoutAction = 0x02
TimeoutActionPowerCycle TimeoutAction = 0x03
)
func (t TimeoutAction) String() string {
m := map[TimeoutAction]string{
0x00: "No action",
0x01: "Hard Reset",
0x02: "Power Down",
0x03: "Power Cycle",
}
s, ok := m[t]
if ok {
return s
}
return ""
}