File: cmd_get_system_interface_capabilities.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,199 bytes parent folder | download | duplicates (2)
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"

// 22.9 Get System Interface Capabilities Command
type GetSystemInterfaceCapabilitiesRequest struct {
	SystemInterfaceType SystemInterfaceType
}

type GetSystemInterfaceCapabilitiesResponse struct {
	// For System Interface Type = SSIF
	TransactionSupportMask uint8
	PECSupported           bool
	SSIFVersion            uint8
	InputMessageSizeBytes  uint8
	OutputMessageSizeBytes uint8

	// For System Interface Type = KCS or SMIC
	SystemInterfaceVersion       uint8
	InputMaximumMessageSizeBytes uint8
}

type SystemInterfaceType uint8

const (
	SystemInterfaceTypeSSIF SystemInterfaceType = 0x00
	SystemInterfaceTypeKCS  SystemInterfaceType = 0x01
	SystemInterfaceTypeSMIC SystemInterfaceType = 0x02
)

func (req *GetSystemInterfaceCapabilitiesRequest) Command() Command {
	return CommandGetSystemInterfaceCapabilities
}

func (req *GetSystemInterfaceCapabilitiesRequest) Pack() []byte {
	return []byte{uint8(req.SystemInterfaceType)}
}

func (res *GetSystemInterfaceCapabilitiesResponse) Unpack(msg []byte) error {
	// at least 3 bytes
	if len(msg) < 3 {
		return ErrUnpackedDataTooShortWith(len(msg), 3)
	}

	// For System Interface Type = SSIF:
	b, _, _ := unpackUint8(msg, 1)
	res.TransactionSupportMask = b >> 6
	res.PECSupported = isBit3Set(b)
	res.SSIFVersion = b & 0x07
	res.InputMessageSizeBytes, _, _ = unpackUint8(msg, 2)

	// For System Interface Type = KCS or SMIC
	res.SystemInterfaceVersion = b & 0x07
	res.InputMaximumMessageSizeBytes, _, _ = unpackUint8(msg, 2)

	if len(msg) >= 4 {
		res.OutputMessageSizeBytes, _, _ = unpackUint8(msg, 3)
	}
	return nil
}

func (*GetSystemInterfaceCapabilitiesResponse) CompletionCodes() map[uint8]string {
	// no command-specific cc
	return map[uint8]string{}
}

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

func (c *Client) GetSystemInterfaceCapabilities(ctx context.Context, interfaceType SystemInterfaceType) (response *GetSystemInterfaceCapabilitiesResponse, err error) {
	request := &GetSystemInterfaceCapabilitiesRequest{
		SystemInterfaceType: interfaceType,
	}
	response = &GetSystemInterfaceCapabilitiesResponse{}
	err = c.Exchange(ctx, request, response)
	return
}