tcgstorage

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: BSD-3-Clause Imports: 9 Imported by: 0

README

go-tcg-storage

Workflow Go Report Card GoDoc Slack License

Go library for interfacing TCG Storage and Security Subsystem Class (SSC) functions on storage devices.

Supported (or planned) standards:

Need support for another standard? Let us know by filing a feature request!

Supported Transports

The following transports are supported by the library:

  • NVMe
  • SATA
  • SAS

Need another transport? You can do one of two things:

  1. You can implement the drive interface yourself to talk to your device.
  2. You can file a feature request describing your setup and we can discuss implementing it

Usage

TODO

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooLargeComPacket = errors.New("encountered a too large ComPacket")
	ErrTooLargePacket    = errors.New("encountered a too large Packet")
)
View Source
var (
	ErrTPerSyncNotSupported      = errors.New("synchronous operation not supported by TPer")
	ErrInvalidPropertiesResponse = errors.New("response was not the expected properties call")
	ErrPropertiesCallFailed      = errors.New("the properties call returned non-zero")

	InvokeIDSMU InvokingID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}

	// Table 241 - "Session Manager Method UIDs"
	MethodIDSMProperties          MethodID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01}
	MethodIDSMStartSession        MethodID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x02}
	MethodIDSMSyncSession         MethodID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03}
	MethodIDSMStartTrustedSession MethodID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x04}
	MethodIDSMSyncTrustedSession  MethodID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x05}
	MethodIDSMCloseSession        MethodID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x06}
)
View Source
var (
	// Table 168: "Communications Initial Assumptions"
	InitialTPerProperties = TPerProperties{
		MaxSubpackets:    1,
		MaxPacketSize:    1004,
		MaxPackets:       1,
		MaxComPacketSize: 1024,
		MaxIndTokenSize:  968,
		MaxAggTokenSize:  968,
		MaxMethods:       1,
		ContinuedTokens:  false,
		SequenceNumbers:  false,
		AckNak:           false,
		Asynchronous:     false,
	}
	// Increased to match that one of the highest standard we support
	InitialHostProperties = HostProperties{
		MaxSubpackets:    1,
		MaxPacketSize:    2028,
		MaxPackets:       1,
		MaxComPacketSize: 2048,
		MaxIndTokenSize:  1992,
		MaxAggTokenSize:  1992,
		MaxMethods:       1,
		ContinuedTokens:  false,
		SequenceNumbers:  false,
		AckNak:           false,
		Asynchronous:     false,
	}
)
View Source
var (
	ErrNoOpalV2Support = errors.New("device does not support Opal 2.0")
)

Functions

func HandleComIDRequest

func HandleComIDRequest(d DriveIntf, comID ComID, req ComIDRequest) ([]byte, error)

func IsComIDValid

func IsComIDValid(d DriveIntf, comID ComID) (bool, error)

Validate a ComID.

func NewPlainCommunication

func NewPlainCommunication(d DriveIntf, hp HostProperties, tp TPerProperties) *plainCom

Low-level communication used to send/receive packets to a TPer or SP.

Implements Subpacket-Packet-ComPacket packet format.

func StackReset

func StackReset(d DriveIntf, comID ComID) error

Reset the state of the synchronous protocol stack.

Types

type ComID

type ComID int
const (
	ComIDInvalid     ComID = -1
	ComIDDiscoveryL0 ComID = 1
)

func GetComID

func GetComID(d DriveIntf) (ComID, error)

Request an (extended) ComID.

type ComIDRequest

type ComIDRequest [4]byte
var (
	ComIDRequestVerifyComIDValid ComIDRequest = [4]byte{0x00, 0x00, 0x00, 0x01}
	ComIDRequestStackReset       ComIDRequest = [4]byte{0x00, 0x00, 0x00, 0x02}

	ErrNotSupported = errors.New("device does not support TCG Storage Core")
)

type CommunicationIntf

type CommunicationIntf interface {
	Send(proto drive.SecurityProtocol, ses *Session, data []byte) error
	Receive(proto drive.SecurityProtocol, ses *Session) ([]byte, error)
}

NOTE: This is almost io.ReadWriter, but not quite - I couldn't figure out a good interface use that wouldn't result in a lot of extra copying.

type ControlSession

type ControlSession struct {
	Session
	HostProperties HostProperties
	TPerProperties TPerProperties
}

func NewControlSession

func NewControlSession(d DriveIntf, tper *FeatureTPer, opts ...ControlSessionOpt) (*ControlSession, error)

Initiate a new control session with a ComID.

func (*ControlSession) Close

func (cs *ControlSession) Close() error

func (*ControlSession) NewSession

func (cs *ControlSession) NewSession(opts ...SessionOpt) (*Session, error)

Initiate a new session with a Security Provider

type ControlSessionOpt

type ControlSessionOpt func(s *ControlSession)

func WithComID

func WithComID(c ComID) ControlSessionOpt

type DriveIntf

type DriveIntf interface {
	IFRecv(proto drive.SecurityProtocol, sps uint16, data *[]byte) error
	IFSend(proto drive.SecurityProtocol, sps uint16, data []byte) error
}

type FeatureBlockSID

type FeatureBlockSID struct {
}

type FeatureCode

type FeatureCode uint16
const (
	FeatureCodeTPer              FeatureCode = 0x0001
	FeatureCodeLocking           FeatureCode = 0x0002
	FeatureCodeGeometry          FeatureCode = 0x0003
	FeatureCodeSecureMsg         FeatureCode = 0x0004
	FeatureCodeEnterprise        FeatureCode = 0x0100
	FeatureCodeOpalV1            FeatureCode = 0x0200
	FeatureCodeSingleUser        FeatureCode = 0x0201
	FeatureCodeDataStore         FeatureCode = 0x0202
	FeatureCodeOpalV2            FeatureCode = 0x0203
	FeatureCodeOpalite           FeatureCode = 0x0301
	FeatureCodePyriteV1          FeatureCode = 0x0302
	FeatureCodePyriteV2          FeatureCode = 0x0303
	FeatureCodeRubyV1            FeatureCode = 0x0304
	FeatureCodeLockingLBA        FeatureCode = 0x0401
	FeatureCodeBlockSID          FeatureCode = 0x0402
	FeatureCodeNamespaceLocking  FeatureCode = 0x0403
	FeatureCodeDataRemoval       FeatureCode = 0x0404
	FeatureCodeNamespaceGeometry FeatureCode = 0x0405
)

type FeatureDataRemoval

type FeatureDataRemoval struct {
}

type FeatureDataStore

type FeatureDataStore struct {
}

type FeatureEnterprise

type FeatureEnterprise struct {
}

type FeatureGeometry

type FeatureGeometry struct {
}

type FeatureLocking

type FeatureLocking struct {
	LockingSupported bool
	LockingEnabled   bool
	Locked           bool
	MediaEncryption  bool
	MBREnabled       bool
	MBRDone          bool
}

type FeatureLockingLBA

type FeatureLockingLBA struct {
}

type FeatureNamespaceGeometry

type FeatureNamespaceGeometry struct {
}

type FeatureNamespaceLocking

type FeatureNamespaceLocking struct {
}

type FeatureOpalV1

type FeatureOpalV1 struct {
}

type FeatureOpalV2

type FeatureOpalV2 struct {
	BaseComID                     uint16
	NumComID                      uint16
	NumLockingSPAdminSupported    uint16
	NumLockingSPUserSupported     uint16
	InitialCPINSIDIndicator       uint8
	BehaviorCPINSIDuponTPerRevert uint8
}

type FeatureOpalite

type FeatureOpalite struct {
}

type FeaturePyriteV1

type FeaturePyriteV1 struct {
	BaseComID                     uint16
	NumComID                      uint16
	InitialCPINSIDIndicator       uint8
	BehaviorCPINSIDuponTPerRevert uint8
}

type FeaturePyriteV2

type FeaturePyriteV2 struct {
	BaseComID                     uint16
	NumComID                      uint16
	InitialCPINSIDIndicator       uint8
	BehaviorCPINSIDuponTPerRevert uint8
}

type FeatureRubyV1

type FeatureRubyV1 struct {
}

type FeatureSecureMsg

type FeatureSecureMsg struct {
}

type FeatureSingleUser

type FeatureSingleUser struct {
}

type FeatureTPer

type FeatureTPer struct {
	SyncSupported       bool
	AsyncSupported      bool
	AckNakSupported     bool
	BufferMgmtSupported bool
	StreamingSupported  bool
	ComIDMgmtSupported  bool
}

type HostProperties

type HostProperties struct {
	MaxMethods               uint
	MaxSubpackets            uint
	MaxPacketSize            uint
	MaxPackets               uint
	MaxComPacketSize         uint
	MaxResponseComPacketSize *uint
	MaxIndTokenSize          uint
	MaxAggTokenSize          uint
	ContinuedTokens          bool
	SequenceNumbers          bool
	AckNak                   bool
	Asynchronous             bool
}

type InvokingID

type InvokingID [8]byte
var (
	InvokeIDNull   InvokingID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
	InvokeIDThisSP InvokingID = [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
)

type Level0Discovery

type Level0Discovery struct {
	MajorVersion      int
	MinorVersion      int
	Vendor            [32]byte
	TPer              *FeatureTPer
	Locking           *FeatureLocking
	Geometry          *FeatureGeometry
	SecureMsg         *FeatureSecureMsg
	Enterprise        *FeatureEnterprise
	OpalV1            *FeatureOpalV1
	SingleUser        *FeatureSingleUser
	DataStore         *FeatureDataStore
	OpalV2            *FeatureOpalV2
	Opalite           *FeatureOpalite
	PyriteV1          *FeaturePyriteV1
	PyriteV2          *FeaturePyriteV2
	RubyV1            *FeatureRubyV1
	LockingLBA        *FeatureLockingLBA
	BlockSID          *FeatureBlockSID
	NamespaceLocking  *FeatureNamespaceLocking
	DataRemoval       *FeatureDataRemoval
	NamespaceGeometry *FeatureNamespaceGeometry
	UnknownFeatures   []uint16
}

func Discovery0

func Discovery0(d DriveIntf) (*Level0Discovery, error)

Perform a Level 0 SSC Discovery.

type MethodCall

type MethodCall struct {
	// contains filtered or unexported fields
}

func NewMethodCall

func NewMethodCall(iid InvokingID, mid MethodID) *MethodCall

Prepare a new method call

func (*MethodCall) EndList

func (m *MethodCall) EndList()

func (*MethodCall) EndOptionalParameter

func (m *MethodCall) EndOptionalParameter()

func (*MethodCall) Execute

func (m *MethodCall) Execute(c CommunicationIntf, proto drive.SecurityProtocol, ses *Session) ([]interface{}, error)

Execute a prepared Method call, returns a list of tokens returned from call.

func (*MethodCall) MarshalBinary

func (mo *MethodCall) MarshalBinary() ([]byte, error)

Marshal the complete method call to the data stream representation

func (*MethodCall) NamedUInt

func (m *MethodCall) NamedUInt(name string, val uint)

func (*MethodCall) PushBytes

func (m *MethodCall) PushBytes(b []byte)

Add bytes to the method call

func (*MethodCall) StartList

func (m *MethodCall) StartList()

func (*MethodCall) StartOptionalParameter

func (m *MethodCall) StartOptionalParameter(id uint)

From "3.2.1.2 Method Signature Pseudo-code" Optional parameters are submitted to the method invocation as Named value pairs. The Name portion of the Named value pair SHALL be a uinteger. Starting at zero, these uinteger values are assigned based on the ordering of the optional parameters as defined in this document.

type MethodID

type MethodID [8]byte

type Session

type Session struct {
	ControlSession *ControlSession

	ComID    ComID
	TSN, HSN int
	// See "3.2.3.3.1.2 SeqNumber"
	SeqLastXmit     int
	SeqLastAcked    int
	SeqNextExpected int
	// contains filtered or unexported fields
}

func (*Session) Close

func (s *Session) Close() error

type SessionOpt

type SessionOpt func(s *Session)

func WithHSN

func WithHSN(hsn int) SessionOpt

type TPerProperties

type TPerProperties struct {
	MaxMethods               uint
	MaxSubpackets            uint
	MaxPacketSize            uint
	MaxPackets               uint
	MaxComPacketSize         uint
	MaxResponseComPacketSize *uint
	MaxSessions              *uint
	MaxReadSessions          *uint
	MaxIndTokenSize          uint
	MaxAggTokenSize          uint
	MaxAuthentications       *uint
	MaxTransactionLimit      *uint
	DefSessionTimeout        *uint
	MaxSessionTimeout        *uint
	MinSessionTimeout        *uint
	DefTransTimeout          *uint
	MaxTransTimeout          *uint
	MinTransTimeout          *uint
	MaxComIDTime             *uint
	ContinuedTokens          bool
	SequenceNumbers          bool
	AckNak                   bool
	Asynchronous             bool
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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