core

package
v0.0.0-...-bb9396b Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultMaxComPacketSize uint = 1024 * 1024
	DefaultReceiveRetries        = 100
	DefaultReceiveInterval       = 10 * time.Millisecond
)

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")
	ErrTPerBufferMgmtNotSupported  = errors.New("TPer supports buffer management, but that is not implemented in this library")
	ErrInvalidPropertiesResponse   = errors.New("response was not the expected Properties call format")
	ErrInvalidStartSessionResponse = errors.New("response was not the expected SyncSession format")
	ErrPropertiesCallFailed        = errors.New("the properties call returned non-zero")
	ErrSessionAlreadyClosed        = errors.New("the session has been closed by us")
)
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,
	}
)

Functions

func FindComID

FindComID checks data of Level0Discovery for the particular SSC and reads the standard ComID of requests a ComID if no standard is set.

func HandleComIDRequest

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

func IsComIDValid

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

Validate a ComID.

func NewPlainCommunication

func NewPlainCommunication(d drive.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 drive.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 drive.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(ses *Session, data []byte) error
	Receive(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
	MaxComPacketSizeOverride uint
}

func NewControlSession

func NewControlSession(d drive.DriveIntf, d0 *Level0Discovery, 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(spid uid.SPID, opts ...SessionOpt) (*Session, error)

Initiate a new session with a Security Provider

The session will be a read-write by default, but can be changed by passing a SessionOpt from WithReadOnly() as argument. The session HSN will be random unless passed with WithHSN(x).

type ControlSessionOpt

type ControlSessionOpt func(s *ControlSession)

func WithComID

func WithComID(c ComID) ControlSessionOpt

func WithMaxComPacketSize

func WithMaxComPacketSize(size uint) ControlSessionOpt

func WithReceiveTimeout

func WithReceiveTimeout(retries int, interval time.Duration) ControlSessionOpt

type Core

type Core struct {
	drive.DriveIntf
	DiskInfo
}

Core holds the device interface to access IFSend/IFReceive functions as well as disk information obtained by the Identify and Discovery functions. This struct shall be use to interface the library

func NewCore

func NewCore(device string) (*Core, error)

func (*Core) Close

func (c *Core) Close() error

func (*Core) Discovery0

func (d *Core) Discovery0() error

Perform a Level 0 SSC Discovery.

type DiskInfo

type DiskInfo struct {
	*Level0Discovery
	*drive.Identity
}

diskInfo holds information obtained by Discovery0 and Identify functions.

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 Level0Discovery

type Level0Discovery struct {
	MajorVersion      int
	MinorVersion      int
	Vendor            [32]byte
	TPer              *feature.TPer
	Locking           *feature.Locking
	Geometry          *feature.Geometry
	SecureMsg         *feature.SecureMsg
	Enterprise        *feature.Enterprise
	OpalV1            *feature.OpalV1
	SingleUser        *feature.SingleUser
	DataStore         *feature.DataStore
	OpalV2            *feature.OpalV2
	Opalite           *feature.Opalite
	PyriteV1          *feature.PyriteV1
	PyriteV2          *feature.PyriteV2
	RubyV1            *feature.RubyV1
	LockingLBA        *feature.LockingLBA
	BlockSID          *feature.BlockSID
	NamespaceLocking  *feature.NamespaceLocking
	DataRemoval       *feature.DataRemoval
	NamespaceGeometry *feature.NamespaceGeometry
	SeagatePorts      *feature.SeagatePorts
	UnknownFeatures   []uint16
}

Level0Discovery structure as described in TCG Storage Architecture Core Spec v2.01 rev 1.00 (missing data length field, which is only required for parsing)

type ProtocolLevel

type ProtocolLevel uint
const (
	ProtocolLevelUnknown    ProtocolLevel = 0
	ProtocolLevelEnterprise ProtocolLevel = 1
	ProtocolLevelCore       ProtocolLevel = 2
)

func (*ProtocolLevel) String

func (p *ProtocolLevel) String() string

type Session

type Session struct {
	ControlSession *ControlSession
	MethodFlags    method.MethodFlag
	ProtocolLevel  ProtocolLevel

	ComID    ComID
	TSN, HSN int
	// See "3.2.3.3.1.2 SeqNumber"
	SeqLastXmit     int
	SeqLastAcked    int
	SeqNextExpected int
	ReadOnly        bool // Ignored for Control Sessions
	ReceiveRetries  int
	ReceiveInterval time.Duration
	// contains filtered or unexported fields
}

func (*Session) Close

func (s *Session) Close() error

func (*Session) ExecuteMethod

func (s *Session) ExecuteMethod(mc method.Call) (stream.List, error)

func (*Session) Notify

func (s *Session) Notify(mc *method.MethodCall) error

Execute a prepared Method call but do not expect anything in return.

type SessionOpt

type SessionOpt func(s *Session)

func WithHSN

func WithHSN(hsn int) SessionOpt

func WithReadOnly

func WithReadOnly() 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

Jump to

Keyboard shortcuts

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