/
table_type.go
94 lines (88 loc) · 2.49 KB
/
table_type.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
// Copyright 2016-2019 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package smbios
import (
"fmt"
)
// TableType specifies the DMI type of the table.
// Types are defined in DMTF DSP0134.
type TableType uint8
// Supported table types.
const (
TableTypeBIOSInfo TableType = 0
TableTypeSystemInfo TableType = 1
TableTypeBaseboardInfo TableType = 2
TableTypeChassisInfo TableType = 3
TableTypeProcessorInfo TableType = 4
TableTypeCacheInfo TableType = 7
TableTypeSystemSlots TableType = 9
TableTypeMemoryDevice TableType = 17
TableTypeIPMIDeviceInfo TableType = 38
TableTypeTPMDevice TableType = 43
TableTypeInactive TableType = 126
TableTypeEndOfTable TableType = 127
)
func (t TableType) String() string {
switch t {
case TableTypeBIOSInfo:
return "BIOS Information"
case TableTypeSystemInfo:
return "System Information"
case TableTypeBaseboardInfo:
return "Base Board Information"
case TableTypeChassisInfo:
return "Chassis Information"
case TableTypeProcessorInfo:
return "Processor Information"
case TableTypeCacheInfo:
return "Cache Information"
case TableTypeSystemSlots:
return "System Slots"
case TableTypeMemoryDevice:
return "Memory Device"
case TableTypeIPMIDeviceInfo:
return "IPMI Device Information"
case TableTypeTPMDevice:
return "TPM Device"
case TableTypeInactive:
return "Inactive"
case TableTypeEndOfTable:
return "End Of Table"
default:
if t >= 0x80 {
return "OEM-specific Type"
}
return "Unsupported"
}
}
// ParseTypedTable parses generic Table into a typed struct.
func ParseTypedTable(t *Table) (fmt.Stringer, error) {
switch t.Type {
case TableTypeBIOSInfo: // 0
return ParseBIOSInfo(t)
case TableTypeSystemInfo: // 1
return ParseSystemInfo(t)
case TableTypeBaseboardInfo: // 2
return ParseBaseboardInfo(t)
case TableTypeChassisInfo: // 3
return ParseChassisInfo(t)
case TableTypeProcessorInfo: // 4
return ParseProcessorInfo(t)
case TableTypeCacheInfo: // 7
return ParseCacheInfo(t)
case TableTypeSystemSlots: // 9
return ParseSystemSlots(t)
case TableTypeMemoryDevice: // 17
return NewMemoryDevice(t)
case TableTypeIPMIDeviceInfo: // 38
return ParseIPMIDeviceInfo(t)
case TableTypeTPMDevice: // 43
return NewTPMDevice(t)
case TableTypeInactive: // 126
return NewInactiveTable(t)
case TableTypeEndOfTable: // 127
return NewEndOfTable(t)
}
return nil, ErrUnsupportedTableType
}