ble

package
v0.0.0-...-168ccc2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LimitedDisc  = 1 << 0 // LE Limited Discoverable mode.
	GeneralDisc  = 1 << 1 // LE General Discoverable mode.
	OnlyLE       = 1 << 2 // BR/EDR not supported.
	DualModeCtlr = 1 << 3 // LE and BR/EDR capable (controller).
	DualModeHost = 1 << 4 // LE and BR/EDR capable (host).
)

Flags

View Source
const (
	MaxAdvPay      = 37  // Max. advertising payload length in bytes.
	MaxDataPay     = 31  // Max. data payload length in bytes (BLE 4.0, 4.1).
	MaxLongDataPay = 255 // Max. data payload length in bytes (BLE 4.2+).
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ADType

type ADType byte
const (
	Flags ADType = 0x01 // Flags

	MoreServices16 ADType = 0x02 // More 16-bit UUIDs available.
	Services16     ADType = 0x03 // Complete list of 16-bit UUIDs available.
	MoreServices32 ADType = 0x04 // More 32-bit UUIDs available.
	Services32     ADType = 0x05 // Complete list of 32-bit UUIDs available.
	MoreServices   ADType = 0x06 // More 128-bit UUIDs available.
	Services       ADType = 0x07 // Complete list of 128-bit UUIDs available.

	ShortLocalName ADType = 0x08 // Shortened local name.
	LocalName      ADType = 0x09 // Complete local name.

	TxPower ADType = 0x0A // Tx Power Level: -127 to +127 dBm.

	SlaveConnIntRange ADType = 0x12 // Slave Connection Interval Range.

	ManufSpecData ADType = 0xFF // Manufacturer Specific Data.
)

type AdvPDU

type AdvPDU struct {
	PDU
}

AdvPDU represents Advertising Channel PDU. See PDU for more information.

func MakeAdvPDU

func MakeAdvPDU(maxpay int) AdvPDU

MakeAdvPDU is more readable counterpart of AdvPDU{MakePDU(maxpay)}.

func (AdvPDU) AppendAddr

func (pdu AdvPDU) AppendAddr(addr int64) (offset int)

func (AdvPDU) AppendBytes

func (pdu AdvPDU) AppendBytes(typ ADType, s ...byte)

func (AdvPDU) AppendString

func (pdu AdvPDU) AppendString(typ ADType, s string)

func (AdvPDU) AppendUUIDs

func (pdu AdvPDU) AppendUUIDs(typ ADType, uuids ...uuid.UUID)

func (AdvPDU) AppendWords16

func (pdu AdvPDU) AppendWords16(typ ADType, s ...uint16)

func (AdvPDU) AppendWords32

func (pdu AdvPDU) AppendWords32(typ ADType, s ...uint32)

func (AdvPDU) RxAdd

func (pdu AdvPDU) RxAdd() bool

RxAdd returns RxAdd field from header.

func (AdvPDU) SetRxAdd

func (pdu AdvPDU) SetRxAdd(rnda bool)

SetRxAdd sets RxAdd field in header.

func (AdvPDU) SetTxAdd

func (pdu AdvPDU) SetTxAdd(rnda bool)

SetTxAdd sets TxAdd field in header.

func (AdvPDU) SetType

func (pdu AdvPDU) SetType(typ AdvPDUType)

SetType sets pdu type in header.

func (AdvPDU) TxAdd

func (pdu AdvPDU) TxAdd() bool

TxAdd returns TxAdd field from header.

func (AdvPDU) Type

func (pdu AdvPDU) Type() AdvPDUType

Type returns pdu type from header.

func (AdvPDU) UpdateAddr

func (pdu AdvPDU) UpdateAddr(offset int, addr int64)

type AdvPDUType

type AdvPDUType byte

AdvPDUType represents Advertising Channel PDU type.

const (
	AdvInd        AdvPDUType = 0
	AdvDirectInd  AdvPDUType = 1
	AdvNonconnInd AdvPDUType = 2
	ScanReq       AdvPDUType = 3
	ScanRsp       AdvPDUType = 4
	ConnectReq    AdvPDUType = 5
	AdvScanInd    AdvPDUType = 6
)

type DataPDU

type DataPDU struct {
	PDU
}

DataPDU represents Data Channel PDU. See PDU for more information.

func MakeDataPDU

func MakeDataPDU(maxpay int) DataPDU

MakeDataPDU is more readable counterpart of DataPDU{MakePDU(maxpay)}.

func (DataPDU) Header

func (pdu DataPDU) Header() Header

Header returns first byte of header of pdu.

func (DataPDU) SetHeader

func (pdu DataPDU) SetHeader(h Header)

SetHeader sets first byte of header of pdu.

type DataRing

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

func MakeDataRing

func MakeDataRing(maxpay, n int) DataRing

func (DataRing) Get

func (r DataRing) Get() DataPDU

func (*DataRing) Next

func (r *DataRing) Next()

type HCI

type HCI interface {
	// Recv returns next received PDU.
	Recv() (DataPDU, error)

	// GetSend returns current transmit PDU. This PDU is not zeroed (can
	// contain random data in payload and header).
	GetSend() DataPDU

	// Send sends current transmit PDU.
	Send() error
}

HCI defines Host Controller Interface for Bluetooth LE.

type Header byte

Header represents first byte of Data Channel PDU header. Second byte of header is payload length and can be obtained using PayLen method.

const (
	LLID       Header = 0x03 // Mask for L2CAPCont, L2CAPStart, LLControl.
	L2CAPCont  Header = 0x01 // Continuation of L2CAP message or empty PDU.
	L2CAPStart Header = 0x02 // Start of L2CAP message or complete message.
	LLControl  Header = 0x03 // LL Control PDU.

	NESN Header = 1 << 2 // Next Expected Sequence Number.
	SN   Header = 1 << 3 // Sequence Number.
	MD   Header = 1 << 4 // More Data.
)

type PDU

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

PDU represents BLE Protocol Data Unit. It has reference semantic (like slice), so it should be initialized before use.

func MakePDU

func MakePDU(maxpay int) PDU

MakePDU returns ready to use PDU of capacity maxpay.

func (PDU) Bytes

func (pdu PDU) Bytes() []byte

Bytes returns underlying bytes of header and payload part of pdu.

func (PDU) IsZero

func (pdu PDU) IsZero() bool

IsZero reports whether value of pdu is zero.

func (PDU) MaxPay

func (pdu PDU) MaxPay() int

MaxPay returns number of bytes that can be stored in payload part of pdu.

func (PDU) PayLen

func (pdu PDU) PayLen() int

PayLen returns payload length.

func (PDU) Payload

func (pdu PDU) Payload() []byte

Payload returns used payload part of PDU.

func (PDU) Remain

func (pdu PDU) Remain() []byte

Remain returns unused payload part of PDU.

func (PDU) SetPayLen

func (pdu PDU) SetPayLen(n int)

SetPayLen sets payload length to n.

Jump to

Keyboard shortcuts

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