smbios

package
v0.0.0-...-ed07a65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2019 License: BSD-3-Clause Imports: 7 Imported by: 0

README

SMBIOS Information Library

TODO: godoc link

Adding a new type

Types are defined in DMTF DSP0134. As of July 2019, the most recent published version is 3.2.0.

Adding a type largely consists of copy-pasting a bunch of information from the doicument to define a Go struct and its string representation. To make that easier, a set of tools is provided ina Gist here. These are Python scripts that take chunks of data copy-pasted from this document and produce a struct, anum or bit field declaration. These are by no means perfect and do not handle all the cases of weird formatting in the document, and may be broken completely by future formatting changes (but hopefully can be fixed if needed).

So, adding a type should looks omething like this:

  • Create typeXXX_new_information.go with boilerplate from some other type (copyright, imports).
  • Generate the struct: tools/gen_struct.py NewInformation >> typeXXX_new_information.go.
  • Generate enums and bitfields if needed.
  • Examine the generated code and tweak it manually if necessart.
  • Run gofmt on it: gofmt typeXXX_new_information.go.
  • Add new Type and a corresponding constant to table_type.go.
  • Implement the constructor function, NewNewInformation in this case.
    • Most of the parsing can be done by reflection-based parser, see parseStruct.
    • Add data validation and any additional custom parsing code necessary.
  • Implement the String() method for *NewInformation.
  • Add getter to the Info type, GetNewInformation.

Documentation

Index

Constants

View Source
const (
	TableTypeBIOSInformation   TableType = 0
	TableTypeSystemInformation           = 1
	TableTypeInactive                    = 126
	TableTypeEndOfTable                  = 127
)

Supported table types.

View Source
const (
	BIOSCharacteristicsReserved                                                           BIOSCharacteristics = (1 << 0)  // Reserved.
	BIOSCharacteristicsReserved2                                                                              = (1 << 1)  // Reserved.
	BIOSCharacteristicsUnknown                                                                                = (1 << 2)  // Unknown.
	BIOSCharacteristicsBIOSCharacteristicsAreNotSupported                                                     = (1 << 3)  // BIOS Characteristics are not supported.
	BIOSCharacteristicsISAIsSupported                                                                         = (1 << 4)  // ISA is supported.
	BIOSCharacteristicsMCAIsSupported                                                                         = (1 << 5)  // MCA is supported.
	BIOSCharacteristicsEISAIsSupported                                                                        = (1 << 6)  // EISA is supported.
	BIOSCharacteristicsPCIIsSupported                                                                         = (1 << 7)  // PCI is supported.
	BIOSCharacteristicsPCCardPCMCIAIsSupported                                                                = (1 << 8)  // PC card (PCMCIA) is supported.
	BIOSCharacteristicsPlugAndPlayIsSupported                                                                 = (1 << 9)  // Plug and Play is supported.
	BIOSCharacteristicsAPMIsSupported                                                                         = (1 << 10) // APM is supported.
	BIOSCharacteristicsBIOSIsUpgradeableFlash                                                                 = (1 << 11) // BIOS is upgradeable (Flash).
	BIOSCharacteristicsBIOSShadowingIsAllowed                                                                 = (1 << 12) // BIOS shadowing is allowed.
	BIOSCharacteristicsVLVESAIsSupported                                                                      = (1 << 13) // VL-VESA is supported.
	BIOSCharacteristicsESCDSupportIsAvailable                                                                 = (1 << 14) // ESCD support is available.
	BIOSCharacteristicsBootFromCDIsSupported                                                                  = (1 << 15) // Boot from CD is supported.
	BIOSCharacteristicsSelectableBootIsSupported                                                              = (1 << 16) // Selectable boot is supported.
	BIOSCharacteristicsBIOSROMIsSocketed                                                                      = (1 << 17) // BIOS ROM is socketed.
	BIOSCharacteristicsBootFromPCCardPCMCIAIsSupported                                                        = (1 << 18) // Boot from PC card (PCMCIA) is supported.
	BIOSCharacteristicsEDDSpecificationIsSupported                                                            = (1 << 19) // EDD specification is supported.
	BIOSCharacteristicsInt13hJapaneseFloppyForNEC980012MB351KBytessector360RPMIsSupported                     = (1 << 20) // Japanese floppy for NEC 9800 1.2 MB (3.5”, 1K bytes/sector, 360 RPM) is
	BIOSCharacteristicsInt13hJapaneseFloppyForToshiba12MB35360RPMIsSupported                                  = (1 << 21) // Japanese floppy for Toshiba 1.2 MB (3.5”, 360 RPM) is supported.
	BIOSCharacteristicsInt13h525360KBFloppyServicesAreSupported                                               = (1 << 22) // 5.25” / 360 KB floppy services are supported.
	BIOSCharacteristicsInt13h52512MBFloppyServicesAreSupported                                                = (1 << 23) // 5.25” /1.2 MB floppy services are supported.
	BIOSCharacteristicsInt13h35720KBFloppyServicesAreSupported                                                = (1 << 24) // 3.5” / 720 KB floppy services are supported.
	BIOSCharacteristicsInt13h35288MBFloppyServicesAreSupported                                                = (1 << 25) // 3.5” / 2.88 MB floppy services are supported.
	BIOSCharacteristicsInt5hPrintScreenServiceIsSupported                                                     = (1 << 26) // Int 5h, print screen Service is supported.
	BIOSCharacteristicsInt9h8042KeyboardServicesAreSupported                                                  = (1 << 27) // Int 9h, 8042 keyboard services are supported.
	BIOSCharacteristicsInt14hSerialServicesAreSupported                                                       = (1 << 28) // Int 14h, serial services are supported.
	BIOSCharacteristicsInt17hPrinterServicesAreSupported                                                      = (1 << 29) // Int 17h, printer services are supported.
	BIOSCharacteristicsInt10hCGAMonoVideoServicesAreSupported                                                 = (1 << 30) // Int 10h, CGA/Mono Video Services are supported.
	BIOSCharacteristicsNECPC98                                                                                = (1 << 31) // NEC PC-98.
)

BIOSCharacteristics fields are defined in DSP0134 7.1.1.

View Source
const (
	BIOSCharacteristicsExt1ACPIIsSupported               BIOSCharacteristicsExt1 = (1 << 0) // ACPI is supported.
	BIOSCharacteristicsExt1USBLegacyIsSupported                                  = (1 << 1) // USB Legacy is supported.
	BIOSCharacteristicsExt1AGPIsSupported                                        = (1 << 2) // AGP is supported.
	BIOSCharacteristicsExt1I2OBootIsSupported                                    = (1 << 3) // I2O boot is supported.
	BIOSCharacteristicsExt1LS120SuperDiskBootIsSupported                         = (1 << 4) // LS-120 SuperDisk boot is supported.
	BIOSCharacteristicsExt1ATAPIZIPDriveBootIsSupported                          = (1 << 5) // ATAPI ZIP drive boot is supported.
	BIOSCharacteristicsExt11394BootIsSupported                                   = (1 << 6) // 1394 boot is supported.
	BIOSCharacteristicsExt1SmartBatteryIsSupported                               = (1 << 7) // Smart battery is supported.
)

BIOSCharacteristicsExt1 is defined in DSP0134 7.1.2.1.

View Source
const (
	BIOSCharacteristicsExt2BIOSBootSpecificationIsSupported                  BIOSCharacteristicsExt2 = (1 << 0) // BIOS Boot Specification is supported.
	BIOSCharacteristicsExt2FunctionKeyinitiatedNetworkServiceBootIsSupported                         = (1 << 1) // Function key-initiated network service boot is supported.
	BIOSCharacteristicsExt2TargetedContentDistributionIsSupported                                    = (1 << 2) // Enable targeted content distribution.
	BIOSCharacteristicsExt2UEFISpecificationIsSupported                                              = (1 << 3) // UEFI Specification is supported.
	BIOSCharacteristicsExt2SMBIOSTableDescribesAVirtualMachine                                       = (1 << 4) // SMBIOS table describes a virtual machine. (If this bit is not set, no inference can be made
)

BIOSCharacteristicsExt1 is defined in DSP0134 7.1.2.2.

View Source
const (
	WakeupTypeReserved        WakeupType = 0x00 // Reserved
	WakeupTypeOther                      = 0x01 // Other
	WakeupTypeUnknown                    = 0x02 // Unknown
	WakeupTypeAPMTimer                   = 0x03 // APM Timer
	WakeupTypeModemRing                  = 0x04 // Modem Ring
	WakeupTypeLANRemote                  = 0x05 // LAN Remote
	WakeupTypePowerSwitch                = 0x06 // Power Switch
	WakeupTypePCIPME                     = 0x07 // PCI PME#
	WakeupTypeACPowerRestored            = 0x08 // AC Power Restored
)

WakeupType values are defined in DSP0134 7.2.2.

Variables

View Source
var (
	// ErrTableNotFound is retuned if table with specified type is not found.
	ErrTableNotFound = errors.New("table not found")

	// ErrUnsupportedTableType is returned by ParseTypedTable if this table type is not supported and cannot be parsed.
	ErrUnsupportedTableType = errors.New("unsupported table type")
)

Functions

func ParseTypedTable

func ParseTypedTable(t *Table) (fmt.Stringer, error)

ParseTypedTable parses generic Table into a typed struct.

Types

type BIOSCharacteristics

type BIOSCharacteristics uint64

BIOSCharacteristics is defined in DSP0134 7.1.1.

func (BIOSCharacteristics) String

func (v BIOSCharacteristics) String() string

type BIOSCharacteristicsExt1

type BIOSCharacteristicsExt1 uint8

BIOSCharacteristicsExt1 is defined in DSP0134 7.1.2.1.

func (BIOSCharacteristicsExt1) String

func (v BIOSCharacteristicsExt1) String() string

type BIOSCharacteristicsExt2

type BIOSCharacteristicsExt2 uint8

BIOSCharacteristicsExt2 is defined in DSP0134 7.1.2.2.

func (BIOSCharacteristicsExt2) String

func (v BIOSCharacteristicsExt2) String() string

type BIOSInformation

type BIOSInformation struct {
	Table
	Vendor                                 string                  // 04h
	Version                                string                  // 05h
	StartingAddressSegment                 uint16                  // 06h
	ReleaseDate                            string                  // 08h
	ROMSize                                uint8                   // 09h
	Characteristics                        BIOSCharacteristics     // 0Ah
	CharacteristicsExt1                    BIOSCharacteristicsExt1 // 12h
	CharacteristicsExt2                    BIOSCharacteristicsExt2 // 13h
	SystemBIOSMajorRelease                 uint8                   // 14h
	SystemBIOSMinorRelease                 uint8                   // 15h
	EmbeddedControllerFirmwareMajorRelease uint8                   // 16h
	EmbeddedControllerFirmwareMinorRelease uint8                   // 17h
	ExtendedROMSize                        uint16                  // 18h
}

BIOSInformation is Defined in DSP0134 7.1.

func NewBIOSInformation

func NewBIOSInformation(t *Table) (*BIOSInformation, error)

NewBIOSInformation parses a generic Table into BIOSInformation.

func (*BIOSInformation) GetROMSizeBytes

func (bi *BIOSInformation) GetROMSizeBytes() uint

GetROMSizeBytes returns ROM size in bytes.

func (*BIOSInformation) String

func (bi *BIOSInformation) String() string
type Header struct {
	Type   TableType
	Length uint8
	Handle uint16
}

Header is the header common to all table types.

func (*Header) Parse

func (h *Header) Parse(data []byte) error

Parse parses the header from the binary data.

func (*Header) String

func (h *Header) String() string

String returns string representation os the header.

type Info

type Info struct {
	// TODO(rojer): Add entrypoint information.
	Tables []*Table
}

Info contains the SMBIOS information.

func ParseInfo

func ParseInfo(entry, data []byte) (*Info, error)

ParseInfo parses SMBIOS information from binary data.

func (*Info) GetBIOSInformation

func (i *Info) GetBIOSInformation() (*BIOSInformation, error)

GetBIOSInformation returns the Bios Information (type 0) table, if present.

func (*Info) GetSystemInformation

func (i *Info) GetSystemInformation() (*SystemInformation, error)

GetSystemInformation returns the System Information (type 1) table, if present.

func (*Info) GetTablesByType

func (i *Info) GetTablesByType(tt TableType) []*Table

GetTablesByType returns tables of specific type.

type SystemInformation

type SystemInformation struct {
	Table
	Manufacturer string     // 04h
	ProductName  string     // 05h
	Version      string     // 06h
	SerialNumber string     // 07h
	UUID         UUID       // 08h
	WakeupType   WakeupType // 18h
	SKUNumber    string     // 19h
	Family       string     // 1Ah
}

SystemInformation is defined in DSP0134 7.2.

func NewSystemInformation

func NewSystemInformation(t *Table) (*SystemInformation, error)

NewSystemInformation parses a generic Table into SystemInformation.

func (*SystemInformation) String

func (si *SystemInformation) String() string

type Table

type Table struct {
	Header
	// contains filtered or unexported fields
}

Table is a generic type of table that does not parsed fields, it only allows access to its contents by offset.

func ParseTable

func ParseTable(data []byte) (*Table, []byte, error)

ParseTable parses a table from byte stream. Returns the parsed table and remaining data.

func (*Table) GetByteAt

func (t *Table) GetByteAt(offset int) (uint8, error)

GetByteAt returns a byte from the structured part at the specified offset.

func (*Table) GetBytesAt

func (t *Table) GetBytesAt(offset, length int) ([]byte, error)

GetBytesAt returns a number of bytes from the structured part at the specified offset.

func (*Table) GetDWordAt

func (t *Table) GetDWordAt(offset int) (res uint32, err error)

GetDWordAt returns a 32-bit word from the structured part at the specified offset.

func (*Table) GetQWordAt

func (t *Table) GetQWordAt(offset int) (res uint64, err error)

GetQWordAt returns a 64-bit word from the structured part at the specified offset.

func (*Table) GetStringAt

func (t *Table) GetStringAt(offset int) (string, error)

GetStringAt returns a string pointed to by the byte at the specified offset in the structured part. NB: offset is not the string index.

func (*Table) GetWordAt

func (t *Table) GetWordAt(offset int) (res uint16, err error)

GetWordAt returns a 16-bit word from the structured part at the specified offset.

func (*Table) Len

func (t *Table) Len() int

Len returns length of the structured part of the table.

func (*Table) String

func (t *Table) String() string

type TableType

type TableType uint8

TableType specifies the DMI type of the table. Types are defined in DMTF DSP0134.

func (TableType) String

func (t TableType) String() string

type UUID

type UUID [16]byte

UUID is defined in DSP0134 7.2.1.

func (*UUID) ParseField

func (u *UUID) ParseField(t *Table, off int) (int, error)

ParseField parses UUD field within a table.

func (UUID) String

func (u UUID) String() string

type WakeupType

type WakeupType uint8

WakeupType is defined in DSP0134 7.2.2.

func (WakeupType) String

func (v WakeupType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL