hal

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package hal defines the Hardware Abstraction Layer interfaces for an IPMI BMC.

Every sub-interface is optional: a HAL implementation may return nil for subsystems that do not exist on the target hardware. Handlers must nil-check sub-interfaces and return an appropriate IPMI completion code when the hardware capability is absent.

Portability

The interfaces in this package are deliberately free of OS-specific types. The only concrete Go packages used in the interface signatures are from the standard library and only primitives (context, error, []byte, basic types). This makes it possible to implement HAL for:

  • Linux via sysfs / hwmon / i2c-dev / libgpiod (not yet implemented in-tree)
  • Bare-metal Go / TinyGo with direct MMIO or SPI/I2C drivers
  • Simulation / test via pkg/hal/mock
  • Bridges to existing daemon APIs (e.g. OpenBMC D-Bus)

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errNotFound{}

ErrNotFound is returned by storage HAL methods when a FRU device ID or SDR record ID is absent. Storage handlers map this to CBh (v2.0§5.2 Table 5-2).

View Source
var ErrNotSupported = errNotSupported{}

ErrNotSupported is returned by HAL methods when the hardware does not support the requested operation. Handlers translate this to an appropriate IPMI completion code: CodeParameterNotSupported 0x80 (v2.0§28.12/§28.13) for parameter-level operations, CodeUnspecifiedError 0xFF (v2.0§5.2 Table 5-2) via codeFromErr for general error paths.

Functions

This section is empty.

Types

type ChassisHAL

type ChassisHAL interface {
	// PowerState returns true when the managed system is powered on.
	PowerState(ctx context.Context) (bool, error)
	// SetPower powers the managed system on or off.
	SetPower(ctx context.Context, on bool) error
	// PowerCycle performs a full power cycle of the managed system
	// (Chassis Control action 0x02, spec Table 28-3). The semantic meaning
	// for a given BMC is defined by the upper-layer HAL implementation.
	PowerCycle(ctx context.Context) error
	// ColdReset performs a hardware cold reset of the managed system.
	ColdReset(ctx context.Context) error
	// WarmReset requests an OS-level warm reboot of the managed system.
	WarmReset(ctx context.Context) error
	// Identify pulses the chassis identification LED for the given duration.
	// seconds == 0 means turn off; [ForcedIdentify] is expressed by the caller
	// passing a large value (e.g., math.MaxUint8).
	Identify(ctx context.Context, seconds uint8) error
	// IntrusionState returns true when the chassis has been opened since last reset.
	// Implementations that lack intrusion detection must return ErrNotSupported.
	IntrusionState(ctx context.Context) (bool, error)
	// SetBootFlags commits the full boot flags structure (spec Table 28-6).
	// The upper layer decides which bits it cares about; HAL implementations
	// must not silently drop fields they ignore. Implementations that do not
	// maintain boot state return ErrNotSupported.
	SetBootFlags(ctx context.Context, flags *types.BootOptionParam_BootFlags) error
	// GetBootFlags reads back the current boot flags, symmetric with
	// [SetBootFlags]. Implementations that cannot read boot flags back must
	// return ErrNotSupported; handlers translate that to the
	// CodeParameterNotSupported completion code.
	GetBootFlags(ctx context.Context) (*types.BootOptionParam_BootFlags, error)
	// SetBootInfoAcknowledge persists the boot initiator acknowledge data
	// (spec Table 28-14, param #4).  The HAL may implement this as a no-op
	// (return nil) if it does not track boot initiator identity.
	SetBootInfoAcknowledge(ctx context.Context, ack *types.BootOptionParam_BootInfoAcknowledge) error
	// GetBootInfoAcknowledge reads back the stored acknowledge data.
	// Implementations that do not persist this return ErrNotSupported.
	GetBootInfoAcknowledge(ctx context.Context) (*types.BootOptionParam_BootInfoAcknowledge, error)
}

ChassisHAL controls physical chassis power, reset, and identity.

type ConsoleConn added in v0.9.1

type ConsoleConn interface {
	io.WriteCloser

	// ReadAvailable copies immediately-pending console output into p and
	// returns (0, nil) when no data is waiting. It must not block.
	ReadAvailable(p []byte) (int, error)

	// SendBreak transmits a ~300 ms serial BREAK to the baseboard (spec
	// v2.0 Table 15-2 operation bit [4]). Implementations whose transport
	// has no BREAK concept (e.g. a websocket) return ErrNotSupported.
	SendBreak(ctx context.Context) error
}

ConsoleConn is a bidirectional byte stream to the system serial console.

ReadAvailable rather than io.Reader: the SOL data plane drains console output synchronously while answering remote-console packets (spec v2.0 §15.9 character accumulation happens at the BMC), so reads must never block. Implementations typically wrap a net.Conn or *os.File with an immediate read deadline.

type ConsoleHAL added in v0.9.1

type ConsoleHAL interface {
	// Open attaches to the system serial console and returns its byte stream.
	// It is called when a remote console activates the SOL payload
	// (Activate Payload command, spec v2.0 §24.1) and the returned conn is
	// closed when the payload is deactivated or the owning session ends.
	//
	// Opening an already-attached console must fail: a shared serial port
	// cannot serve two activations (spec v2.0 §15.3 serial port sharing).
	Open(ctx context.Context) (ConsoleConn, error)
}

ConsoleHAL exposes the managed system's serial console for SOL (Serial over LAN) payload redirection (spec v2.0 §15).

type FRUStore

type FRUStore interface {
	Read(ctx context.Context, deviceID uint8) ([]byte, error)
	Write(ctx context.Context, deviceID uint8, data []byte) error
	Delete(ctx context.Context, deviceID uint8) error
	DeviceIDs(ctx context.Context) ([]uint8, error)
}

FRUStore holds wire-format FRU inventory blobs (v2.0§34). DeviceID 0 is the builtin MC FRU at LUN 00b.

type GPIOHAL

type GPIOHAL interface {
	// Set drives an output GPIO high (true) or low (false).
	Set(ctx context.Context, pin string, high bool) error
	// Get reads the current level of an input GPIO.
	Get(ctx context.Context, pin string) (bool, error)
	// Watch calls callback whenever the input level changes.
	// The returned cancel function stops watching.
	Watch(ctx context.Context, pin string, callback func(high bool)) (cancel func(), err error)
}

GPIOHAL provides access to discrete GPIO lines (status LEDs, front-panel buttons).

type HAL

type HAL interface {
	// Chassis returns chassis power and identification controls, or nil.
	Chassis() ChassisHAL
	// Sensors returns the sensor reading interface, or nil.
	Sensors() SensorHAL
	// Storage returns FRU/SDR blob stores for Storage NetFn handlers, or nil.
	Storage() StorageHAL
	// Network returns BMC NIC configuration, or nil.
	Network() NetworkHAL
	// GPIO returns discrete GPIO control (LEDs, buttons), or nil.
	GPIO() GPIOHAL
	// I2C returns raw I2C bus access for sensors or EEPROMs, or nil.
	I2C() I2CHAL
	// Console returns the system serial console used by SOL payloads
	// (spec v2.0 §15), or nil when the target has no redirectable console.
	Console() ConsoleHAL
	// Close releases all hardware resources.
	Close() error
}

HAL is the top-level hardware abstraction. Implementations may return nil for sub-interfaces that are not available on the target.

type I2CHAL

type I2CHAL interface {
	// Read performs a register read from an I2C device.
	Read(ctx context.Context, bus int, addr uint8, reg uint8, length int) ([]byte, error)
	// Write performs a register write to an I2C device.
	Write(ctx context.Context, bus int, addr uint8, reg uint8, data []byte) error
}

I2CHAL provides raw I2C bus access for sensors or EEPROM-backed FRU devices.

type IPConfig

type IPConfig struct {
	IP      [4]byte
	Mask    [4]byte
	Gateway [4]byte
	MAC     [6]byte
	DHCP    bool
	// Port is the primary RMCP port the BMC listens on (Get LAN Configuration
	// Parameters param #8). Zero means the standard 623; a non-zero value lets a
	// BMC that listens on a non-standard port advertise it to in-band software.
	Port uint16
}

IPConfig holds the BMC network interface configuration.

type NetworkHAL

type NetworkHAL interface {
	GetConfig(ctx context.Context) (*IPConfig, error)
	SetConfig(ctx context.Context, cfg *IPConfig) error
}

NetworkHAL configures the BMC's own network interface. This is separate from [transport.PacketConn]: transport is how packets arrive; NetworkHAL is how the LAN configuration commands read/write NIC parameters.

type SDRStore

type SDRStore interface {
	Read(ctx context.Context, recordID uint16) ([]byte, error)
	Write(ctx context.Context, recordID uint16, data []byte) error
	Delete(ctx context.Context, recordID uint16) error
	RecordIDs(ctx context.Context) ([]uint16, error)
}

SDRStore holds wire-format SDR repository records (v2.0§33). RecordID 0 is not a valid stored ID; [bmc.SDRRepository.GetRecord] maps Get SDR(0000h) to the first record and Get SDR(FFFFh) to the last (v2.0§33.12).

type SensorDescriptor

type SensorDescriptor struct {
	ID   uint8
	Type uint8 // IPMI sensor type code (section 42 of IPMI spec)
	Name string
}

SensorDescriptor describes a sensor exposed by the hardware.

type SensorHAL

type SensorHAL interface {
	// ReadRaw returns the raw sensor byte that the BMC formula maps to a real value.
	ReadRaw(ctx context.Context, sensorID uint8) (uint8, error)
	// List returns all sensors available on the hardware.
	List(ctx context.Context) ([]SensorDescriptor, error)
}

SensorHAL reads hardware sensor values.

type StorageHAL

type StorageHAL interface {
	FRU() FRUStore
	SDR() SDRStore
}

StorageHAL groups persistent blob stores for Storage NetFn data (v2.0§33–§34). Each sub-store may be nil when the backing hardware is absent.

Directories

Path Synopsis
Package mock provides in-memory hal.HAL implementations for use in tests and simulation environments.
Package mock provides in-memory hal.HAL implementations for use in tests and simulation environments.

Jump to

Keyboard shortcuts

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