File: cmd_set_command_subfunction_enables.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 (92 lines) | stat: -rw-r--r-- 2,481 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package ipmi

import "context"

// 21.9 Set Configurable Command Sub-function Enables Command
type SetCommandSubfunctionEnablesRequest struct {
	ChannelNumber uint8

	CommandRangeMask CommandRangeMask
	NetFn            NetFn
	LUN              uint8
	Cmd              uint8

	CodeForNetFn2C uint8
	OEMIANA        uint32 // 3 bytes only

	SubfunctionEnables []bool
}

type SetCommandSubfunctionEnablesResponse struct {
}

func (req *SetCommandSubfunctionEnablesRequest) Command() Command {
	return CommandSetCommandSubfunctionEnables
}

func (req *SetCommandSubfunctionEnablesRequest) Pack() []byte {
	var maxLength int = 15
	out := make([]byte, maxLength)

	out[0] = req.ChannelNumber
	out[1] = uint8(req.NetFn) & (uint8(req.CommandRangeMask) << 6)
	out[2] = req.LUN & 0x03
	out[3] = req.Cmd

	var startIndexOfEnables int = 4

	if uint8(req.NetFn) == 0x2c {
		out[4] = req.CodeForNetFn2C
		startIndexOfEnables = 5
	}

	if uint8(req.NetFn) == 0x2e {
		packUint24L(req.OEMIANA, out, 4)
		startIndexOfEnables = 7
	}

	enables := req.SubfunctionEnables
	if len(req.SubfunctionEnables) > 64 {
		enables = enables[:64]
	}
	// Every 8 elements from the enables slice pack into 1 byte.
	enableBytesLength := len(enables)/8 + 1

	for i := 0; i < enableBytesLength; i++ {
		var b uint8
		b = setOrClearBit0(b, req.SubfunctionEnables[i*8+0])
		b = setOrClearBit1(b, req.SubfunctionEnables[i*8+1])
		b = setOrClearBit2(b, req.SubfunctionEnables[i*8+2])
		b = setOrClearBit3(b, req.SubfunctionEnables[i*8+3])
		b = setOrClearBit4(b, req.SubfunctionEnables[i*8+4])
		b = setOrClearBit5(b, req.SubfunctionEnables[i*8+5])
		b = setOrClearBit6(b, req.SubfunctionEnables[i*8+6])
		b = setOrClearBit7(b, req.SubfunctionEnables[i*8+7])

		out[startIndexOfEnables+i] = b
	}

	return out[0 : startIndexOfEnables+enableBytesLength]

}

func (res *SetCommandSubfunctionEnablesResponse) Unpack(msg []byte) error {
	return nil
}

func (*SetCommandSubfunctionEnablesResponse) CompletionCodes() map[uint8]string {
	// no command-specific cc
	return map[uint8]string{
		0x80: "attempt to enable an unsupported or un-configurable sub-function.",
	}
}

func (res *SetCommandSubfunctionEnablesResponse) Format() string {
	return ""
}

func (c *Client) SetCommandSubfunctionEnables(ctx context.Context, request *SetCommandSubfunctionEnablesRequest) (response *SetCommandSubfunctionEnablesResponse, err error) {
	response = &SetCommandSubfunctionEnablesResponse{}
	err = c.Exchange(ctx, request, response)
	return
}