smp

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// IO Capability Table 3.3. See also section 2.3.2
	IOCapDisplayOnly     = 0x00
	IOCapDisplayYesNo    = 0x01
	IOCapKeyboardOnly    = 0x02
	IOCapNoInputNoOutput = 0x03
	IOCapKeyboardDisplay = 0x04

	// OOBAuthPresent OOB Authentication data not present. [ Section 3.5 Table 3.4 ]
	OOBAuthNotPresent = 0x00

	// OOBAuthPresent OOB Authentication data from remote device present. [ Section 3.5 Table 3.4 ]
	OOBAuthPresent = 0x01

	// BondingFlagBonding [ Section 3.5 Table 3.5 ]
	BondingFlagBonding = 0x01

	// BondingFlagNoBonding [ Section 3.5 Table 3.5 ]
	BondingFlagNoBonding = 0x00

	// ReasonReserved reserved for future use. [ Section 3.5 Table 3.6 ]
	ReasonReserved = 0x00

	// ReasonPassKeyEntyFailed The user input of passkey failed, for example,
	// the user cancelled the operation. [ Section 3.5 Table 3.6 ]
	ReasonPassKeyEntyFailed = 0x01

	// ReasonOOBNotAvailable The OOB data is not available. [ Section 3.5 Table 3.6 ]
	ReasonOOBNotAvailable = 0x02

	// ReasonAuthRequirements The pairing procedure cannot be performed as
	// authentication requirements cannot be met due to IO capabilities of
	// one or both devices. [ Section 3.5 Table 3.6 ]
	ReasonAuthRequirements = 0x03

	// ReasonConfirmValueFailed The confirm value does not match the calculated
	// compare value. [ Section 3.5 Table 3.6 ]
	ReasonConfirmValueFailed = 0x04

	// ReasonPairingNotSupported Pairing is not supported by the device. [ Section 3.5 Table 3.6 ]
	ReasonPairingNotSupported = 0x05

	// ReasonEncryptionKeySize The resultant encryption key size is insufficient
	// for the security requirements of this device. [ Section 3.5 Table 3.6 ]
	ReasonEncryptionKeySize = 0x06

	// ReasonCommandNotSupported The SMP command received is not sup- ported
	// on this device. [ Section 3.5 Table 3.6 ]
	ReasonCommandNotSupported = 0x07

	// ReasonUnspecifiedReason failed due to an unspecified reason. [ Section 3.5 Table 3.6 ]
	ReasonUnspecifiedReason = 0x08

	// ReasonRepeatedAttempts Pairing or authentication procedure is disallowed
	// because too little time has elapsed since last pairing request or security
	// request. [ Section 3.5 Table 3.6 ]
	ReasonRepeatedAttempts = 0x09

	// ReasonInvalidParams indicates the command length is invalid a parameter
	// is outside of the specified rane. [ Section 3.5 Table 3.6 ]
	ReasonInvalidParams = 0x0A

	// AddrTypePublic if the address type if public or BDADDR is set to all zeros [ Section 3.6.5 ]
	AddrTypePublic = 0x00

	// AddTypeRandom if BDADDR is a static random device address [ Section 3.6.5 ]
	AddTypeRandom = 0x01

	// NotificationTypePasskeyEntryStarted Passkey entry started
	NotificationTypePasskeyEntryStarted = 0x00

	// NotificationTypePasskeyDigitEntered Passkey digit entered
	NotificationTypePasskeyDigitEntered = 0x00

	// NotificationTypePasskeyDigitErased Passkey digit erased
	NotificationTypePasskeyDigitErased = 0x00

	// NotificationTypePasskeyCleared Passkey cleared
	NotificationTypePasskeyCleared = 0x00

	// NotificationTypePasskeyEntryCompleted Passkey completed
	NotificationTypePasskeyEntryCompleted = 0x00
)
View Source
const EncryptionInformationCode = 0x06

EncryptionInformationCode is the code of Encryption Information signaling packet.

View Source
const IdentityAddressIdentificationCode = 0x09

IdentityAddressIdentificationCode is the code of Identity Address Identification signaling packet.

View Source
const IdentityIdentificationCode = 0x08

IdentityIdentificationCode is the code of Identity Identification signaling packet.

View Source
const KeypressNotificationCode = 0x0E

KeypressNotificationCode is the code of Keypress Notification signaling packet.

View Source
const MasterIdentificationCode = 0x07

MasterIdentificationCode is the code of Master Identification signaling packet.

View Source
const PairingConfirmCode = 0x03

PairingConfirmCode is the code of Pairing Confirm signaling packet.

View Source
const PairingDHKeyCheckCode = 0x0D

PairingDHKeyCheckCode is the code of Pairing DHKey Check signaling packet.

View Source
const PairingFailedCode = 0x05

PairingFailedCode is the code of Pairing Failed signaling packet.

View Source
const PairingPublicKeyCode = 0x0C

PairingPublicKeyCode is the code of Pairing Public Key signaling packet.

View Source
const PairingRandomCode = 0x04

PairingRandomCode is the code of Pairing Random signaling packet.

View Source
const PairingRequestCode = 0x01

PairingRequestCode is the code of Pairing Request signaling packet.

View Source
const PairingResponseCode = 0x02

PairingResponseCode is the code of Pairing Response signaling packet.

View Source
const SecurityRequestCode = 0x0B

SecurityRequestCode is the code of Security Request signaling packet.

View Source
const SigningInformationCode = 0x0A

SigningInformationCode is the code of Signing Information signaling packet.

Variables

This section is empty.

Functions

func AES_CMAC

func AES_CMAC(k [16]byte, m []byte) (code [16]byte, err error)

func C1

func C1(k, r [16]byte, pres *PairingResponse, preq *PairingRequest, iat byte, ia [6]byte, rat byte, ra [6]byte) ([16]byte, error)

c1 During the LE legacy pairing process confirm values are exchanged. This confirm value generation function c1 is used to generate the confirm values. [ Vol 3, Part H 2.2.3 ]

func F4

func F4(U, V [32]byte, X [16]byte, Z byte) ([16]byte, error)

F4 during the LE Secure Connections pairing process, confirm values are exchanged. These confirm values are computed using the confirm value generation function f4.

Z is zero (i.e. 8 bits of zeros) for Numeric Comparison and OOB protocol. In the Passkey Entry protocol, the most significant bit of Z is set equal to one and the least significant bit is made up from one bit of the passkey e.g. if the passkey bit is 1, then Z = 0x81 and if the passkey bit is 0, then Z = 0x80.

[ Vol 3, Part H 2.2.6]

func F5

func F5(W [32]byte, N1, N2 [16]byte, A1, A2 [7]byte) (out [16]byte, err error)

F5 The LE Secure Connections key generation function f5 is used to generate derived keying material in order to create the LTK and keys for the commitment function f6 during the LE Secure Connections pairing process.

[ Vol 3, Part H 2.2.7]

func F6

func F6(W, N1, N2, R [16]byte, IOcap [3]byte, A1, A2 [7]byte) (out [16]byte, err error)

F6 The LE Secure Connections check value generation function f6 is used to generate check values during authentication stage 2 of the LE Secure Connections pairing process.

[ Vol 3, Part H 2.2.8]

func GeneratePINCode

func GeneratePINCode() string

func GenerateRand

func GenerateRand() (b [16]byte)

func IsLESecureConnection

func IsLESecureConnection(req *PairingRequest, rsp *PairingResponse) bool

func PinCodeToTempKey

func PinCodeToTempKey(pinCode string) (tk [16]byte, err error)

func S1

func S1(k, r1, r2 [16]byte) ([16]byte, error)

S1 is the key generation function s1 for LE Legacy Pairing. The key generation function s1 is used to generate the STK during the LE legacy pairing process. [ Vol 3, Part H 2.2.4]

Types

type AuthReq

type AuthReq struct {
	BondingFlag        uint8
	MITM               uint8
	LESecureConnection uint8
	Keypress           uint8
}

func (*AuthReq) Marshal

func (a *AuthReq) Marshal() byte

func (*AuthReq) Unmarshal

func (a *AuthReq) Unmarshal(b byte) error

type Capabilities

type Capabilities struct {
	Display              Display
	Keyboard             Keyboard
	DisplayYesNo         DisplayYesNo
	OOBAuth              OOBAuth
	ExchangeLongTermKeys ExchangeLongTermKeys
	LESecureConnection   bool
	ManInTheMiddle       bool
}

func (*Capabilities) BondingFlags

func (i *Capabilities) BondingFlags() uint8

func (*Capabilities) GetTemporaryKey

func (i *Capabilities) GetTemporaryKey(method KeyGenMethod, initiator bool) (tk [16]byte, err error)

func (*Capabilities) IOCapability

func (i *Capabilities) IOCapability() uint8

func (*Capabilities) MITM

func (i *Capabilities) MITM() uint8

func (*Capabilities) OOBDataFlag

func (i *Capabilities) OOBDataFlag() uint8

func (*Capabilities) PairingRequest

func (i *Capabilities) PairingRequest() *PairingRequest

func (*Capabilities) PairingResponse

func (i *Capabilities) PairingResponse(req *PairingRequest) *PairingResponse

func (*Capabilities) SecureConnection

func (i *Capabilities) SecureConnection() uint8

type Display

type Display func(code string)

Device can only display a 6 digit decimal number

type DisplayYesNo

type DisplayYesNo func(code string) bool

Device has two buttons that easily map to yes or no and can display a 6 digit decimal number

type EncryptionInformation

type EncryptionInformation struct {
	LongTermKey []byte
}

EncryptionInformation implements Encryption Information (0x06) [Vol 3, Part H, 3.5.2].

func (EncryptionInformation) Code

func (s EncryptionInformation) Code() int

Code returns the event code of the command.

func (*EncryptionInformation) Marshal

func (s *EncryptionInformation) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*EncryptionInformation) Unmarshal

func (s *EncryptionInformation) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type ExchangeLongTermKeys

type ExchangeLongTermKeys func([]byte) ([]byte, error)

sends, receives and stores a long term key for later use

type IdentityAddressIdentification

type IdentityAddressIdentification struct {
	AddrType uint8
	BDADDR   [6]byte
}

IdentityAddressIdentification implements Identity Address Identification (0x09) [Vol 3, Part H, 3.5.5].

func (IdentityAddressIdentification) Code

Code returns the event code of the command.

func (*IdentityAddressIdentification) Marshal

func (s *IdentityAddressIdentification) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*IdentityAddressIdentification) Unmarshal

func (s *IdentityAddressIdentification) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type IdentityIdentification

type IdentityIdentification struct {
	IdentityResolvingKey []byte
}

IdentityIdentification implements Identity Identification (0x08) [Vol 3, Part H, 3.5.4].

func (IdentityIdentification) Code

func (s IdentityIdentification) Code() int

Code returns the event code of the command.

func (*IdentityIdentification) Marshal

func (s *IdentityIdentification) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*IdentityIdentification) Unmarshal

func (s *IdentityIdentification) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type KeyDist

type KeyDist struct {
	EncryptionKey uint8
	IDKey         uint8
	Sign          uint8
	LinkKey       uint8
}

func (*KeyDist) Marshal

func (k *KeyDist) Marshal() byte

func (*KeyDist) Unmarshal

func (k *KeyDist) Unmarshal(b byte) error

type KeyGenMethod

type KeyGenMethod int
const (
	KeyGenMethodOOB KeyGenMethod = iota + 1
	KeyGenMethodJustWorks
	KeyGenMethodNumCompare
	KeyGenMethodPKEntryInitiatorDisplay
	KeyGenMethodPKEntryResponderDisplay
	KeyGenMethodPKEntryBothInput
)

func KeyGenMethodToUse

func KeyGenMethodToUse(req *PairingRequest, rsp *PairingResponse, initiator bool) KeyGenMethod

func KeyGenMethodToUseForIOCap

func KeyGenMethodToUseForIOCap(reqIOCap, rspIOCap uint8, initiator, secure bool) KeyGenMethod

type Keyboard

type Keyboard func() string

Can only input numberic values 0-9 and a confirmation

type KeypressNotification

type KeypressNotification struct {
	NotificationType uint8
}

KeypressNotification implements Keypress Notification (0x0E) [Vol 3, Part H, 3.5.8].

func (KeypressNotification) Code

func (s KeypressNotification) Code() int

Code returns the event code of the command.

func (*KeypressNotification) Marshal

func (s *KeypressNotification) Marshal() []byte

Marshal serializes the command parameters into binary form.

func (*KeypressNotification) Unmarshal

func (s *KeypressNotification) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type MasterIdentification

type MasterIdentification struct {
	EDIV uint16
	Rand uint64
}

MasterIdentification implements Master Identification (0x07) [Vol 3, Part H, 3.5.3].

func (MasterIdentification) Code

func (s MasterIdentification) Code() int

Code returns the event code of the command.

func (*MasterIdentification) Marshal

func (s *MasterIdentification) Marshal() []byte

Marshal serializes the command parameters into binary form.

func (*MasterIdentification) Unmarshal

func (s *MasterIdentification) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type OOBAuth

type OOBAuth func() ([16]byte, error)

sends and returns external information for the pairing process

type PairingConfirm

type PairingConfirm struct {
	ConfirmValue []byte
}

PairingConfirm implements Pairing Confirm (0x03) [Vol 3, Part H, 3.5.3].

func (PairingConfirm) Code

func (s PairingConfirm) Code() int

Code returns the event code of the command.

func (*PairingConfirm) Marshal

func (s *PairingConfirm) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*PairingConfirm) Unmarshal

func (s *PairingConfirm) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type PairingDHKeyCheck

type PairingDHKeyCheck struct {
	DHKeyCheck [16]byte
}

PairingDHKeyCheck implements Pairing DHKey Check (0x0D) [Vol 3, Part H, 3.5.7].

func (PairingDHKeyCheck) Code

func (s PairingDHKeyCheck) Code() int

Code returns the event code of the command.

func (*PairingDHKeyCheck) Marshal

func (s *PairingDHKeyCheck) Marshal() []byte

Marshal serializes the command parameters into binary form.

func (*PairingDHKeyCheck) Unmarshal

func (s *PairingDHKeyCheck) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type PairingFailed

type PairingFailed struct {
	Reason uint8
}

PairingFailed implements Pairing Failed (0x05) [Vol 3, Part H, 3.5.5].

func (PairingFailed) Code

func (s PairingFailed) Code() int

Code returns the event code of the command.

func (*PairingFailed) Marshal

func (s *PairingFailed) Marshal() []byte

Marshal serializes the command parameters into binary form.

func (*PairingFailed) Unmarshal

func (s *PairingFailed) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type PairingPublicKey

type PairingPublicKey struct {
	KeyX [32]byte
	KeyY [32]byte
}

PairingPublicKey implements Pairing Public Key (0x0C) [Vol 3, Part H, 3.5.6].

func (PairingPublicKey) Code

func (s PairingPublicKey) Code() int

Code returns the event code of the command.

func (*PairingPublicKey) Marshal

func (s *PairingPublicKey) Marshal() []byte

Marshal serializes the command parameters into binary form.

func (*PairingPublicKey) Unmarshal

func (s *PairingPublicKey) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type PairingRandom

type PairingRandom struct {
	RandomValue []byte
}

PairingRandom implements Pairing Random (0x04) [Vol 3, Part H, 3.5.4].

func (PairingRandom) Code

func (s PairingRandom) Code() int

Code returns the event code of the command.

func (*PairingRandom) Marshal

func (s *PairingRandom) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*PairingRandom) Unmarshal

func (s *PairingRandom) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type PairingRequest

type PairingRequest struct {
	IOCapability         uint8
	OOBDataFlag          uint8
	MaxEncryptionKeySize uint8

	AuthReq AuthReq

	InitiatorKeyDist KeyDist
	ResponderKeyDist KeyDist
}

PairingRequest implements Pairing Request (0x01) [Vol 3, Part H, 3.5.1].

func (PairingRequest) Code

func (s PairingRequest) Code() int

Code returns the event code of the command.

func (*PairingRequest) Marshal

func (s *PairingRequest) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*PairingRequest) Unmarshal

func (s *PairingRequest) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type PairingResponse

type PairingResponse struct {
	IOCapability         uint8
	OOBDataFlag          uint8
	MaxEncryptionKeySize uint8

	AuthReq AuthReq

	InitiatorKeyDist KeyDist
	ResponderKeyDist KeyDist
}

PairingResponse implements Pairing Response (0x02) [Vol 3, Part H, 3.5.2].

func (PairingResponse) Code

func (s PairingResponse) Code() int

Code returns the event code of the command.

func (*PairingResponse) Marshal

func (s *PairingResponse) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*PairingResponse) Unmarshal

func (s *PairingResponse) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type SecurityRequest

type SecurityRequest struct {
	AuthReq AuthReq
}

SecurityRequest implements Security Request (0x0B) [Vol 3, Part H, 3.5.6].

func (SecurityRequest) Code

func (s SecurityRequest) Code() int

Code returns the event code of the command.

func (*SecurityRequest) Marshal

func (s *SecurityRequest) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*SecurityRequest) Unmarshal

func (s *SecurityRequest) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

type SigningInformation

type SigningInformation struct {
	SignatureKey []byte
}

SigningInformation implements Signing Information (0x0A) [Vol 3, Part H, 3.5.6].

func (SigningInformation) Code

func (s SigningInformation) Code() int

Code returns the event code of the command.

func (*SigningInformation) Marshal

func (s *SigningInformation) Marshal() []byte

Marshal Serializes the struct into binary data int LittleEndian order

func (*SigningInformation) Unmarshal

func (s *SigningInformation) Unmarshal(b []byte) error

Unmarshal de-serializes the binary data and stores the result in the receiver.

Jump to

Keyboard shortcuts

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