-
Notifications
You must be signed in to change notification settings - Fork 26
/
cmd_get_channel_access.go
83 lines (67 loc) · 2.09 KB
/
cmd_get_channel_access.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
package ipmi
import (
"context"
"fmt"
)
// 22.23 Get Channel Access Command
type GetChannelAccessRequest struct {
ChannelNumber uint8
AccessOption ChannelAccessOption
}
type GetChannelAccessResponse struct {
PEFAlertingDisabled bool
PerMsgAuthDisabled bool
UserLevelAuthDisabled bool
AccessMode ChannelAccessMode
MaxPrivilegeLevel PrivilegeLevel
}
func (req *GetChannelAccessRequest) Pack() []byte {
out := make([]byte, 2)
packUint8(req.ChannelNumber, out, 0)
packUint8(uint8(req.AccessOption)<<6, out, 1)
return out
}
func (req *GetChannelAccessRequest) Command() Command {
return CommandGetChannelAccess
}
func (res *GetChannelAccessResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{
0x82: "set not supported on selected channel (e.g. channel is session-less.)",
0x83: "access mode not supported",
}
}
func (res *GetChannelAccessResponse) Unpack(msg []byte) error {
if len(msg) < 2 {
return ErrUnpackedDataTooShortWith(len(msg), 2)
}
b0, _, _ := unpackUint8(msg, 0)
res.PEFAlertingDisabled = isBit5Set(b0)
res.PerMsgAuthDisabled = isBit4Set(b0)
res.UserLevelAuthDisabled = isBit3Set(b0)
res.AccessMode = ChannelAccessMode(b0 & 0x07)
b1, _, _ := unpackUint8(msg, 1)
res.MaxPrivilegeLevel = PrivilegeLevel(b1 & 0x0f)
return nil
}
func (res *GetChannelAccessResponse) Format() string {
return fmt.Sprintf(` Alerting : %s
Per-message Auth : %s
User Level Auth : %s
Access Mode : %s
Max Privilege Level : %s`,
formatBool(res.PEFAlertingDisabled, "disabled", "enabled"),
formatBool(res.PerMsgAuthDisabled, "disabled", "enabled"),
formatBool(res.UserLevelAuthDisabled, "disabled", "enabled"),
res.AccessMode,
res.MaxPrivilegeLevel.String(),
)
}
func (c *Client) GetChannelAccess(ctx context.Context, channelNumber uint8, accessOption ChannelAccessOption) (response *GetChannelAccessResponse, err error) {
request := &GetChannelAccessRequest{
ChannelNumber: channelNumber,
AccessOption: accessOption,
}
response = &GetChannelAccessResponse{}
err = c.Exchange(ctx, request, response)
return
}