Skip to content

Commit

Permalink
feat: rework destructuring of SMBIOS information and added some tests
Browse files Browse the repository at this point in the history
This change reworks how information is extracted from the SMBIOS.
Also includes tests for 4 copied DMIs to verify the decoding.

Signed-off-by: Gerard de Leeuw <gdeleeuw@leeuwit.nl>
Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
lion7 authored and smira committed Feb 2, 2022
1 parent fd5ec8c commit 3f1e775
Show file tree
Hide file tree
Showing 24 changed files with 3,510 additions and 843 deletions.
130 changes: 93 additions & 37 deletions smbios/baseboard_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,104 @@ package smbios

import "github.com/digitalocean/go-smbios/smbios"

// BaseboardInformationStructure represents the SMBIOS baseboard information structure.
type BaseboardInformationStructure struct {
*smbios.Structure
// BaseboardInformation represents the SMBIOS baseboard information.
type BaseboardInformation struct {
// Manufacturer returns the baseboard manufacturer.
Manufacturer string
// Product returns the baseboard product.
Product string
// Version returns the baseboard version.
Version string
// SerialNumber returns the baseboard serial number.
SerialNumber string
// AssetTag returns the baseboard asset tag.
AssetTag string
// LocationInChassis returns the number of a null-terminated string that
// describes this board's location within the chassis referenced by the
// Chassis Handle (described below in this table)
// NOTE: This field supports a CIM_Container class mapping where:
// - LocationWithinContainer is this field.
// - GroupComponent is the chassis referenced by Chassis Handle.
// - PartComponent is this baseboard
LocationInChassis string
// BoardType identifies the type of board. See 7.3.2.
BoardType BoardType
}

// BaseboardInformation returns a `BaseboardInformationStructure`.
func (s *SMBIOS) BaseboardInformation() BaseboardInformationStructure {
return s.BaseboardInformationStructure
// NewBaseboardInformation initializes and returns a new `BaseboardInformation`.
func NewBaseboardInformation(s *smbios.Structure) *BaseboardInformation {
return &BaseboardInformation{
Manufacturer: GetStringOrEmpty(s, 0x04),
Product: GetStringOrEmpty(s, 0x05),
Version: GetStringOrEmpty(s, 0x06),
SerialNumber: GetStringOrEmpty(s, 0x07),
AssetTag: GetStringOrEmpty(s, 0x08),
LocationInChassis: GetStringOrEmpty(s, 0x0A),
BoardType: BoardType(GetByte(s, 0x0D)),
}
}

// Manufacturer returns the baseboard manufacturer.
func (s BaseboardInformationStructure) Manufacturer() string {
return get(s.Structure, 0)
}

// Product returns the baseboard product.
func (s BaseboardInformationStructure) Product() string {
return get(s.Structure, 1)
}
// BoardType defines the board type enum.
type BoardType int

// Version returns the baseboard version.
func (s BaseboardInformationStructure) Version() string {
return get(s.Structure, 2)
}
const (
// BoardTypeUnknown is a board type.
BoardTypeUnknown BoardType = iota
// BoardTypeOther is a board type.
BoardTypeOther
// BoardTypeServerBlade is a board type.
BoardTypeServerBlade
// BoardTypeConnectivitySwitch is a board type.
BoardTypeConnectivitySwitch
// BoardTypeSystemManagementModule is a board type.
BoardTypeSystemManagementModule
// BoardTypeProcessorModule is a board type.
BoardTypeProcessorModule
// BoardTypeIOModule is a board type.
BoardTypeIOModule
// BoardTypeMemoryModule is a board type.
BoardTypeMemoryModule
// BoardTypeDaughterBoard is a board type.
BoardTypeDaughterBoard
// BoardTypeMotherboard is a board type.
BoardTypeMotherboard
// BoardTypeProcessorMemoryModule is a board type.
BoardTypeProcessorMemoryModule
// BoardTypeProcessorIOModule is a board type.
BoardTypeProcessorIOModule
// BoardTypeInterconnectBoard is a board type.
BoardTypeInterconnectBoard
)

// SerialNumber returns the baseboard serial number.
func (s BaseboardInformationStructure) SerialNumber() string {
return get(s.Structure, 3)
}

// AssetTag returns the baseboard asset tag.
func (s BaseboardInformationStructure) AssetTag() string {
return get(s.Structure, 4)
}
func (w BoardType) String() string {
switch w {
case BoardTypeUnknown:
return _Unknown
case BoardTypeOther:
return _Other
case BoardTypeServerBlade:
return "Server Blade"
case BoardTypeConnectivitySwitch:
return "Connectivity Switch"
case BoardTypeSystemManagementModule:
return "System Management Module"
case BoardTypeProcessorModule:
return "Processor Module"
case BoardTypeIOModule:
return "I/O Module"
case BoardTypeMemoryModule:
return "Memory Module"
case BoardTypeDaughterBoard:
return "Daughter board"
case BoardTypeMotherboard:
return "Motherboard (includes processor, memory, and I/O)"
case BoardTypeProcessorMemoryModule:
return "Processor/Memory Module"
case BoardTypeProcessorIOModule:
return "Processor/IO Module"
case BoardTypeInterconnectBoard:
return "Interconnect Board"
}

// LocationInChassis returns the number of a null-terminated string that
// describes this board's location within the chassis referenced by the
// Chassis Handle (described below in this table)
// NOTE: This field supports a CIM_Container class mapping where:
// - LocationWithinContainer is this field.
// - GroupComponent is the chassis referenced by Chassis Handle.
// - PartComponent is this baseboard
func (s BaseboardInformationStructure) LocationInChassis() string {
return get(s.Structure, 5)
return _Unknown
}
36 changes: 15 additions & 21 deletions smbios/bios_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@ package smbios

import "github.com/digitalocean/go-smbios/smbios"

// BIOSInformationStructure represents the BIOS information structure.
type BIOSInformationStructure struct {
*smbios.Structure
// BIOSInformation represents the BIOS information.
type BIOSInformation struct {
// Vendor returns the BIOS vendor.
Vendor string
// Version returns the BIOS version.
Version string
// ReleaseDate returns the BIOS release date.
ReleaseDate string
}

// BIOSInformation returns a `BIOSInformationStructure`.
func (s SMBIOS) BIOSInformation() BIOSInformationStructure {
return s.BIOSInformationStructure
}

// Vendor returns the BIOS vendor.
func (s BIOSInformationStructure) Vendor() string {
return get(s.Structure, 0)
}

// Version returns the BIOS version.
func (s BIOSInformationStructure) Version() string {
return get(s.Structure, 1)
}

// ReleaseDate returns the BIOS release date.
func (s BIOSInformationStructure) ReleaseDate() string {
return get(s.Structure, 2)
// NewBIOSInformation initializes and returns a new `BIOSInformation`.
func NewBIOSInformation(s *smbios.Structure) *BIOSInformation {
return &BIOSInformation{
GetStringOrEmpty(s, 0x04),
GetStringOrEmpty(s, 0x05),
GetStringOrEmpty(s, 0x08),
}
}
23 changes: 12 additions & 11 deletions smbios/bios_language_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ package smbios

import "github.com/digitalocean/go-smbios/smbios"

// BIOSLanguageInformationStructure represents the SMBIOS BIOS language information structure.
type BIOSLanguageInformationStructure struct {
*smbios.Structure
// BIOSLanguageInformation represents the SMBIOS BIOS language information.
type BIOSLanguageInformation struct {
// CurrentLanguage returns the current language.
CurrentLanguage string
// InstallableLanguages returns the installable languages.
InstallableLanguages []string
}

// BIOSLanguageInformation returns a `BIOSLanguageInformationStructure`.
func (s *SMBIOS) BIOSLanguageInformation() BIOSLanguageInformationStructure {
return s.BIOSLanguageInformationStructure
}

// CurrentLanguage returns the current language.
func (s BIOSLanguageInformationStructure) CurrentLanguage() string {
return get(s.Structure, 0)
// NewBIOSLanguageInformation initializes and returns a new `BIOSLanguageInformation`.
func NewBIOSLanguageInformation(s *smbios.Structure) *BIOSLanguageInformation {
return &BIOSLanguageInformation{
CurrentLanguage: GetStringOrEmpty(s, 0x15),
InstallableLanguages: GetStrings(s),
}
}
20 changes: 9 additions & 11 deletions smbios/cache_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ package smbios

import "github.com/digitalocean/go-smbios/smbios"

// CacheInformationStructure represents the SMBIOS cache information structure.
type CacheInformationStructure struct {
*smbios.Structure
// CacheInformation represents the SMBIOS cache information.
type CacheInformation struct {
// SocketDesignation returns the cache socket designation.
SocketDesignation string
}

// CacheInformation returns a `CacheInformationStructure`.
func (s *SMBIOS) CacheInformation() CacheInformationStructure {
return s.CacheInformationStructure
}

// SocketDesignation returns the cache socket designation.
func (s CacheInformationStructure) SocketDesignation() string {
return get(s.Structure, 0)
// NewCacheInformation initializes and returns a new `CacheInformation`.
func NewCacheInformation(s *smbios.Structure) *CacheInformation {
return &CacheInformation{
SocketDesignation: GetStringOrEmpty(s, 0x04),
}
}
20 changes: 9 additions & 11 deletions smbios/group_associations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ package smbios

import "github.com/digitalocean/go-smbios/smbios"

// GroupAssociationsStructure represents the SMBIOS group associations structure.
type GroupAssociationsStructure struct {
*smbios.Structure
// GroupAssociations represents the SMBIOS group associations.
type GroupAssociations struct {
// GroupName returns the group name.
GroupName string
}

// GroupAssociations returns a `GroupAssociationsStructure`.
func (s *SMBIOS) GroupAssociations() GroupAssociationsStructure {
return s.GroupAssociationsStructure
}

// GroupName returns the group name.
func (s GroupAssociationsStructure) GroupName() string {
return get(s.Structure, 0)
// NewGroupAssociations initializes and returns a new `GroupAssociations`.
func NewGroupAssociations(s *smbios.Structure) *GroupAssociations {
return &GroupAssociations{
GroupName: GetStringOrEmpty(s, 0x04),
}
}
Loading

0 comments on commit 3f1e775

Please sign in to comment.