forked from k-sone/ipmigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.go
100 lines (87 loc) · 1.95 KB
/
session.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
package ipmigo
import (
"fmt"
)
// Payload Type (Section 13.27.3)
type payloadType uint8
const (
payloadTypeIPMI payloadType = 0x00
payloadTypeSOL = 0x01
payloadTypeOEM = 0x02
payloadTypeRMCPOpenReq = 0x10
payloadTypeRMCPOpenRes = 0x11
payloadTypeRAKP1 = 0x12
payloadTypeRAKP2 = 0x13
payloadTypeRAKP3 = 0x14
payloadTypeRAKP4 = 0x15
)
// Return a payloadType without encrypt/authenticate flags
func (p payloadType) Pure() payloadType {
return payloadType(byte(p) & 0x3f)
}
func (p *payloadType) SetEncrypted(b bool) {
if b {
*p = payloadType(byte(*p) | 0x80)
} else {
*p = payloadType(byte(*p) & 0x7f)
}
}
func (p payloadType) Encrypted() bool {
return p&0x80 != 0
}
func (p *payloadType) SetAuthenticated(b bool) {
if b {
*p = payloadType(byte(*p) | 0x40)
} else {
*p = payloadType(byte(*p) & 0xbf)
}
}
func (p payloadType) Authenticated() bool {
return p&0x40 != 0
}
// Authentication Type (Section 13.6)
type authType uint8
const (
authTypeNone authType = 0x0
authTypeMD2 = 0x1
authTypeMD5 = 0x2
authTypePassword = 0x4
authTypeOEM = 0x5
authTypeRMCPPlus = 0x6
)
func (a authType) String() string {
switch a {
case authTypeNone:
return "NONE"
case authTypeMD2:
return "MD2"
case authTypeMD5:
return "MD5"
case authTypePassword:
return "PASSWORD"
case authTypeOEM:
return "OEM"
case authTypeRMCPPlus:
return "RMCP+"
default:
return fmt.Sprintf("Reserved(%d)", a)
}
}
type sessionHeader interface {
ID() uint32
AuthType() authType
PayloadType() payloadType
SetEncrypted(bool)
SetAuthenticated(bool)
PayloadLength() int
SetPayloadLength(int)
Marshal() ([]byte, error)
Unmarshal([]byte) ([]byte, error)
String() string
}
type session interface {
Ping() error
Open() error
Close() error
Execute(Command) error
}