File: cmd_get_channel_access.go

package info (click to toggle)
golang-github-bougou-go-ipmi 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,880 kB
  • sloc: makefile: 38
file content (78 lines) | stat: -rw-r--r-- 2,218 bytes parent folder | download
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
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\n", formatBool(res.PEFAlertingDisabled, "disabled", "enabled")) +
		fmt.Sprintf("    Per-message Auth    : %s\n", formatBool(res.PerMsgAuthDisabled, "disabled", "enabled")) +
		fmt.Sprintf("    User Level Auth     : %s\n", formatBool(res.UserLevelAuthDisabled, "disabled", "enabled")) +
		fmt.Sprintf("    Access Mode         : %s\n", res.AccessMode) +
		fmt.Sprintf("    Max Privilege Level : %s\n", 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
}