btmgmt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var (
	ErrSocketOpen           = errors.New("Opening socket failed")
	ErrSocketBind           = errors.New("Binding socket failed")
	ErrClosed               = errors.New("Management connection has been closed")
	ErrSocketNotConnected   = errors.New("BtSocket not connected")
	ErrRdLoop               = errors.New("BtSocket error in event read loop")
	ErrEvtRdHdr             = errors.New("BtSocket not able to read event header")
	ErrEvtParseHdr          = errors.New("BtSocket not able to parse event header")
	ErrEvtRdPayload         = errors.New("BtSocket not able to read event payload")
	ErrUnknownCommandStatus = errors.New("Unknown command status for received event")
	ErrPayloadFormat        = errors.New("Unexpected payload format")
	ErrSockClose            = errors.New("Error closing socket")
	ErrCmdTimeout           = errors.New("command reached timeout")
)
View Source
var CmdStatusErrorMap = genCmdStatusErrorMap()
View Source
var (
	ErrMgmtConnFailed = errors.New("BtMgmt socket connection failed")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	Addr net.HardwareAddr
}

func (*Address) String

func (a *Address) String() string

func (*Address) UpdateFromPayload

func (a *Address) UpdateFromPayload(pay []byte) (err error)

type BtMgmt

type BtMgmt struct {
}

Wraps general functionality of mgmtConnection (issue commands) to more specific commands with proper input arguments and result parsing. Additionally tries to assure that there's always a working MgmtConnection (connected socket). A global object is used to assure the latter and shared by all BtMgmt instances (There has been no testing of using more than one BtMgmt instance)

func NewBtMgmt

func NewBtMgmt() (mgmt *BtMgmt, err error)

func (BtMgmt) ReadControllerIndexList

func (bm BtMgmt) ReadControllerIndexList() (res *ControllerIndexList, err error)

func (BtMgmt) ReadControllerInformation

func (bm BtMgmt) ReadControllerInformation(controllerID uint16) (res *ControllerInformation, err error)

func (BtMgmt) ReadManagementSupportedCommands

func (bm BtMgmt) ReadManagementSupportedCommands() (res *SupportedCommands, err error)

func (BtMgmt) ReadManagementVersionInformation

func (bm BtMgmt) ReadManagementVersionInformation() (res *VersionInformation, err error)

func (BtMgmt) SetBondable

func (bm BtMgmt) SetBondable(controllerID uint16, bondable bool) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetConnectable

func (bm BtMgmt) SetConnectable(controllerID uint16, connectable bool) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetDiscoverable

func (bm BtMgmt) SetDiscoverable(controllerID uint16, discoverable Discoverability, timeoutSeconds uint16) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetFastConnectable

func (bm BtMgmt) SetFastConnectable(controllerID uint16, fastConnectable bool) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetHighSpeed

func (bm BtMgmt) SetHighSpeed(controllerID uint16, highspeed bool) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetLinkSecurity

func (bm BtMgmt) SetLinkSecurity(controllerID uint16, linkSecurity bool) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetLowEnergy

func (bm BtMgmt) SetLowEnergy(controllerID uint16, le bool) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetPowered

func (bm BtMgmt) SetPowered(controllerID uint16, powered bool) (currentSettings *ControllerSettings, err error)

func (BtMgmt) SetSecureSimplePairing

func (bm BtMgmt) SetSecureSimplePairing(controllerID uint16, secureSimplePairing bool) (currentSettings *ControllerSettings, err error)

type CmdCode

type CmdCode uint16
const (
	CMD_READ_MANAGEMENT_VERSION_INFORMATION CmdCode = 0x01
	CMD_READ_MANAGEMENT_SUPPORTED_COMMANDS  CmdCode = 0x02
	CMD_READ_CONTROLLER_INDEX_LIST          CmdCode = 0x03
	CMD_READ_CONTROLLER_INFORMATION         CmdCode = 0x04
	CMD_SET_POWERED                         CmdCode = 0x05
	CMD_SET_DISCOVERABLE                    CmdCode = 0x06
	CMD_SET_CONNECTABLE                     CmdCode = 0x07
	CMD_SET_FAST_CONNECTABLE                CmdCode = 0x08
	CMD_SET_BONDABLE                        CmdCode = 0x09
	CMD_SET_LINK_SECURITY                   CmdCode = 0x0A
	CMD_SET_SECURE_SIMPLE_PAIRING           CmdCode = 0x0B
	CMD_SET_HIGH_SPEED                      CmdCode = 0x0C
	CMD_SET_LOW_ENERGY                      CmdCode = 0x0D
	CMD_SET_DEVICE_CLASS                    CmdCode = 0x0E
	CMD_SET_LOCAL_NAME                      CmdCode = 0x0F
	CMD_ADD_UUID                            CmdCode = 0x10
	CMD_REMOVE_UUID                         CmdCode = 0x11
	CMD_LOAD_LINK_KEYS                      CmdCode = 0x12
	CMD_LOAD_LONG_TERM_KEYS                 CmdCode = 0x13
	CMD_DISCONNECT                          CmdCode = 0x14
	CMD_GET_CONECTIONS                      CmdCode = 0x15
	CMD_PIN_CODE_REPLY                      CmdCode = 0x16
	CMD_PIN_CODE_NEGATIVE_REPLY             CmdCode = 0x17
	CMD_PIN_SET_IO_CAPABILITY               CmdCode = 0x18
	CMD_PAIR_DEVICE                         CmdCode = 0x19
	CMD_CANCEL_PAIR_DEVICE                  CmdCode = 0x1A
	CMD_UNPAIR_DEVICE                       CmdCode = 0x1B
	CMD_CONFIRM_REPLY                       CmdCode = 0x1C
	CMD_CONFIRM_NEGATIVE_REPLY              CmdCode = 0x1D
	CMD_USER_PASSKEY_REPLY                  CmdCode = 0x1E
	CMD_USER_PASSKEY_NEGATIVE_REPLY         CmdCode = 0x1F
	CMD_READ_LOCAL_OUT_OF_BOUND_DATA        CmdCode = 0x20
	CMD_ADD_REMOTE_OUT_OF_BOUND_DATA        CmdCode = 0x21
	CMD_REMOVE_REMOTE_OUT_OF_BOUND_DATA     CmdCode = 0x22
	CMD_START_DICOVERY                      CmdCode = 0x23
	CMD_STOP_DICOVERY                       CmdCode = 0x24
	CMD_CONFIRM_NAME                        CmdCode = 0x25
	CMD_BLOCK_DEVICE                        CmdCode = 0x26
	CMD_UNBLOCK_DEVICE                      CmdCode = 0x27
	CMD_SET_DEVICE_ID                       CmdCode = 0x28
	CMD_SET_ADVERTISING                     CmdCode = 0x29
	CMD_SET_BR_EDR                          CmdCode = 0x2A
	CMD_SET_STATIC_ADDRESS                  CmdCode = 0x2B
	// ToDo: define missing
	CMD_SET_PHY_CONFIGURATION CmdCode = 0x44
)

type CmdStatus

type CmdStatus uint16
const (
	CMD_STATUS_SUCCESS               CmdStatus = 0x00
	CMD_STATUS_UNKNOWN_COMMAND       CmdStatus = 0x01
	CMD_STATUS_NOT_CONNECTED         CmdStatus = 0x02
	CMD_STATUS_FAILED                CmdStatus = 0x03
	CMD_STATUS_CONNECT_FAILED        CmdStatus = 0x04
	CMD_STATUS_AUTHENTICATION_FAILED CmdStatus = 0x05
	CMD_STATUS_NOT_PAIRED            CmdStatus = 0x06
	CMD_STATUS_NO_RESOURCES          CmdStatus = 0x07
	CMD_STATUS_TIMEOUT               CmdStatus = 0x08
	CMD_STATUS_ALREADY_CONNECTED     CmdStatus = 0x09
	CMD_STATUS_BUSY                  CmdStatus = 0x0A
	CMD_STATUS_REJECTED              CmdStatus = 0x0B
	CMD_STATUS_NOT_SUPPORTED         CmdStatus = 0x0C
	CMD_STATUS_INVALID_PARAMETERS    CmdStatus = 0x0D
	CMD_STATUS_DISCONNECTED          CmdStatus = 0x0E
	CMD_STATUS_NOT_POWERED           CmdStatus = 0x0F
	CMD_STATUS_CANCELLED             CmdStatus = 0x10
	CMD_STATUS_INVALID_INDEX         CmdStatus = 0x11
	CMD_STATUS_RF_KILLED             CmdStatus = 0x12
	CMD_STATUS_ALREADY_PAIRED        CmdStatus = 0x13
	CMD_STATUS_PERMISSION_DENIED     CmdStatus = 0x14
)

type CommandCompleteEvent

type CommandCompleteEvent struct {
	CmdCode      CmdCode
	Status       CmdStatus
	ReturnParams []byte
}

func (*CommandCompleteEvent) UpdateFromPayload

func (cc *CommandCompleteEvent) UpdateFromPayload(payload []byte) (err error)

type CommandStatusEvent

type CommandStatusEvent struct {
	CmdCode CmdCode
	Status  CmdStatus
}

func (*CommandStatusEvent) UpdateFromPayload

func (cs *CommandStatusEvent) UpdateFromPayload(payload []byte) (err error)

type ControllerIndexList

type ControllerIndexList struct {
	Indices []uint16
}

func (*ControllerIndexList) String

func (cil *ControllerIndexList) String() string

func (*ControllerIndexList) UpdateFromPayload

func (cil *ControllerIndexList) UpdateFromPayload(p []byte) (err error)

type ControllerInformation

type ControllerInformation struct {
	Address           Address
	BluetoothVersion  byte
	Manufacturer      uint16
	SupportedSettings ControllerSettings
	CurrentSettings   ControllerSettings
	ClassOfDevice     DeviceClass // 3, till clear how to parse
	Name              string      //[249]byte, 0x00 terminated
	ShortName         string      //[11]byte, 0x00 terminated

	ServiceNetworkServerGn   bool
	ServiceNetworkServerNap  bool
	ServiceNetworkServerPanu bool
}

func (ControllerInformation) String

func (ci ControllerInformation) String() string

func (*ControllerInformation) UpdateFromPayload

func (ci *ControllerInformation) UpdateFromPayload(p []byte) (err error)

type ControllerSettings

type ControllerSettings struct {
	Powered                 bool
	Connectable             bool
	FastConnectable         bool
	Discoverable            bool
	Bondable                bool
	LinkLevelSecurity       bool
	SecureSimplePairing     bool
	BrEdr                   bool
	HighSpeed               bool
	LowEnergy               bool
	Advertising             bool
	SecureConnections       bool
	DebugKeys               bool
	Privacy                 bool
	ControllerConfiguration bool
	StaticAddress           bool
}

ToDo: Stringer interface for ControllerSettings (needs map)

func (*ControllerSettings) UpdateFromPayload

func (cd *ControllerSettings) UpdateFromPayload(pay []byte) (err error)

type DeviceClass

type DeviceClass struct {
	Octets []byte
}

func (*DeviceClass) String

func (c *DeviceClass) String() string

func (*DeviceClass) UpdateFromPayload

func (c *DeviceClass) UpdateFromPayload(pay []byte) (err error)

type Discoverability

type Discoverability byte
const (
	NOT_DISCOVERABLE     Discoverability = 0x00
	GENERAL_DISCOVERABLE Discoverability = 0x01
	LIMITED_DISCOVERABLE Discoverability = 0x02
)

type Event

type Event struct {
	EventCode     EvtCode
	ControllerIdx uint16
	ParamLen      uint16
	Payload       []byte
}

type EventListener

type EventListener interface {
	Filter(event Event) (consumeEvent bool)
	Handle(event Event) (listenerFinished bool)
}

type EvtCode

type EvtCode uint16
const (
	EVT_COMMAND_COMPLETE                        EvtCode = 0x01
	EVT_COMMAND_STATUS                          EvtCode = 0x02
	EVT_CONTROLLER_ERROR                        EvtCode = 0x03
	EVT_INDEX_ADDED                             EvtCode = 0x04
	EVT_INDEX_REMOVED                           EvtCode = 0x05
	EVT_NEW_SETTINGS                            EvtCode = 0x06
	EVT_CLASS_OF_DEVICE_CHANGED                 EvtCode = 0x07
	EVT_LOCAL_NAME_CHANGED                      EvtCode = 0x08
	EVT_NEW_LINK_KEY                            EvtCode = 0x09
	EVT_NEW_LONG_TERM_KEY                       EvtCode = 0x0A
	EVT_DEVICE_CONNECTED                        EvtCode = 0x0B
	EVT_DEVICE_DISCONNECTED                     EvtCode = 0x0C
	EVT_CONNECT_FAILED                          EvtCode = 0x0D
	EVT_PIN_CODE_REQUEST                        EvtCode = 0x0E
	EVT_USER_CONFIRMATION_REQUEST               EvtCode = 0x0F
	EVT_USER_PASSKEY_REQUEST                    EvtCode = 0x10
	EVT_AUTHENTICATION_FAILED                   EvtCode = 0x11
	EVT_DEVICE_FOUND                            EvtCode = 0x12
	EVT_DISCOVERING                             EvtCode = 0x13
	EVT_DEVICE_BLOCKED                          EvtCode = 0x14
	EVT_DEVICE_UNBLOCKED                        EvtCode = 0x15
	EVT_DEVICE_UNPAIRED                         EvtCode = 0x16
	EVT_PASSKEY_NOTIFY                          EvtCode = 0x17
	EVT_NEW_IDENTITY_RESOLVING_KEY              EvtCode = 0x18
	EVT_NEW_SIGNATURE_RESOLVING_KEY             EvtCode = 0x19
	EVT_DEVICE_ADDED                            EvtCode = 0x1A
	EVT_DEVICE_REMOVED                          EvtCode = 0x1B
	EVT_NEW_CONNECTION_PARAMETER                EvtCode = 0x1C
	EVT_UNCONFIGURED_INDEX_ADDED                EvtCode = 0x1D
	EVT_UNCONFIGURED_INDEX_REMOVED              EvtCode = 0x1E
	EVT_NEW_CONFIGURATION_OPTIONS               EvtCode = 0x1F
	EVT_EXTENDED_INDEX_ADDED                    EvtCode = 0x20
	EVT_EXTENDED_INDEX_REMOVED                  EvtCode = 0x21
	EVT_LOCAL_OUT_OF_BAND_EXTENDED_DATA_UPDATE  EvtCode = 0x22
	EVT_EXTENDED_ADVERTISING_ADDED              EvtCode = 0x23
	EVT_EXTENDED_ADVERTISING_REMOVED            EvtCode = 0x24
	EVT_EXTENDED_CONTROLLER_INFORMATION_CHANGED EvtCode = 0x25
	EVT_PHY_CONFIGURATION_CHANGED               EvtCode = 0x26
)

type MgmtConnection

type MgmtConnection struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

func NewMgmtConnection

func NewMgmtConnection() (mgmtConn *MgmtConnection, err error)

func (*MgmtConnection) AddListener

func (m *MgmtConnection) AddListener(l EventListener) error

func (*MgmtConnection) Close

func (m *MgmtConnection) Close() (err error)

func (*MgmtConnection) Connect

func (m *MgmtConnection) Connect() (err error)

func (*MgmtConnection) Read

func (m *MgmtConnection) Read(p []byte) (n int, err error)

func (*MgmtConnection) RunCmd

func (m *MgmtConnection) RunCmd(controllerId uint16, cmdCode CmdCode, params ...byte) (resultParsams []byte, err error)

func (*MgmtConnection) SendCmd

func (m *MgmtConnection) SendCmd(command command) (err error)

func (*MgmtConnection) Write

func (m *MgmtConnection) Write(p []byte) (n int, err error)

type ParsePayload

type ParsePayload interface {
	UpdateFromPayload(pay []byte) (err error)
}

type SupportedCommands

type SupportedCommands struct {
	Commands []CmdCode
	Events   []EvtCode
}

func (*SupportedCommands) String

func (sc *SupportedCommands) String() string

func (*SupportedCommands) UpdateFromPayload

func (sc *SupportedCommands) UpdateFromPayload(p []byte) (err error)

type VersionInformation

type VersionInformation struct {
	Version  uint8
	Revision uint16
}

func (VersionInformation) String

func (v VersionInformation) String() string

func (*VersionInformation) UpdateFromPayload

func (v *VersionInformation) UpdateFromPayload(pay []byte) (err error)

Jump to

Keyboard shortcuts

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