-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtype_10_onboard.go
85 lines (75 loc) · 1.83 KB
/
type_10_onboard.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
package dmi
import (
"fmt"
)
type OnBoardDeviceTypeOfDevice byte
const (
OnBoardDeviceOther OnBoardDeviceTypeOfDevice = 1 + iota
OnBoardDeviceUnknown
OnBoardDeviceVideo
OnBoardDeviceSCSIController
OnBoardDeviceEthernet
OnBoardDeviceTokenRing
OnBoardDeviceSound
OnBoardDevicePATAController
OnBoardDeviceSATAController
OnBoardDeviceSASController
)
func (t OnBoardDeviceTypeOfDevice) String() string {
types := [...]string{
"Other",
"Unknown",
"Video",
"SCSI Controller",
"Ethernet",
"Token Ring",
"Sound",
"PATA Controller",
"SATA Controller",
"SAS Controller",
}
return types[t-1]
}
type OnBoardDeviceType struct {
status bool
typeOfDevice OnBoardDeviceTypeOfDevice
}
type OnBoardDeviceInformation struct {
infoCommon
Type []OnBoardDeviceType
Description []string
}
func (d OnBoardDeviceInformation) String() string {
var info string
title := "On Board Devices Information"
for i, v := range d.Type {
s := fmt.Sprintf("Device %d: Enabled: %v: Description: %s", i, v.status, v.typeOfDevice, d.Description[i])
info += "\n\t\t" + s
}
return title + "\n\t\t" + info
}
func newOnBoardDeviceInformation(h dmiHeader) dmiTyper {
var d OnBoardDeviceInformation
data := h.data
n := (data[0x01] - 4) / 2
for i := byte(1); i <= n; i++ {
var t OnBoardDeviceType
index := 4 + 2*(i-1)
sindex := 5 + 2*(i-1)
t.status = data[index]&0x80 != 0
t.typeOfDevice = OnBoardDeviceTypeOfDevice(data[index] & 0x7F)
d.Type = append(d.Type, t)
desc := h.FieldString(int(data[sindex]))
d.Description = append(d.Description, desc)
}
return &d
}
func GetOnBoardDeviceInformation() *OnBoardDeviceInformation {
if d, ok := gdmi[SMBIOSStructureTypeOnBoardDevices]; ok {
return d.(*OnBoardDeviceInformation)
}
return nil
}
func init() {
addTypeFunc(SMBIOSStructureTypeOnBoardDevices, newOnBoardDeviceInformation)
}