adapter

package
v0.0.0-...-dfdf79b Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 10 Imported by: 77

Documentation

Overview

BlueZ D-Bus Adapter API description [adapter-api.txt]

Index

Constants

View Source
const (
	DiscoveryFilterTransportAuto  = "auto"
	DiscoveryFilterTransportBrEdr = "bredr"
	DiscoveryFilterTransportLE    = "le"
)

Variables

View Source
var Adapter1Interface = "org.bluez.Adapter1"

Functions

func AdapterExists

func AdapterExists(adapterID string) (bool, error)

AdapterExists checks if an adapter is available

func GetDefaultAdapterID

func GetDefaultAdapterID() string

GetDefaultAdapterID get the default adapter

func ParseAdapterID

func ParseAdapterID(path dbus.ObjectPath) (string, error)

ParseAdapterID read the adapterID from an object path in the form /org/bluez/hci[0-9]*[/...]

func SetDefaultAdapterID

func SetDefaultAdapterID(a string)

SetDefaultAdapterID set the default adapter

Types

type Adapter1

type Adapter1 struct {
	Properties *Adapter1Properties
	// contains filtered or unexported fields
}

Adapter1 Adapter hierarchy

func GetAdapter

func GetAdapter(adapterID string) (*Adapter1, error)

GetAdapter return an adapter object instance

func GetAdapterFromDevicePath

func GetAdapterFromDevicePath(path dbus.ObjectPath) (*Adapter1, error)

GetAdapterFromDevicePath Return an adapter based on a device path

func GetDefaultAdapter

func GetDefaultAdapter() (*Adapter1, error)

func NewAdapter1

func NewAdapter1(objectPath dbus.ObjectPath) (*Adapter1, error)

NewAdapter1 create a new instance of Adapter1

Args: - objectPath: [variable prefix]/{hci0,hci1,...}

func NewAdapter1FromAdapterID

func NewAdapter1FromAdapterID(adapterID string) (*Adapter1, error)

NewAdapter1FromAdapterID create a new instance of Adapter1 adapterID: ID of an adapter eg. hci0

func (*Adapter1) Client

func (a *Adapter1) Client() *bluez.Client

Client return Adapter1 dbus client

func (*Adapter1) Close

func (a *Adapter1) Close()

Close the connection

func (*Adapter1) ConnectDevice

func (a *Adapter1) ConnectDevice(properties map[string]interface{}) (dbus.ObjectPath, error)

ConnectDevice This method connects to device without need of

performing General Discovery. Connection mechanism is
similar to Connect method from Device1 interface with
exception that this method returns success when physical
connection is established. After this method returns,
services discovery will continue and any supported
profile will be connected. There is no need for calling
Connect on Device1 after this call. If connection was
successful this method returns object path to created
device object.
Parameters that may be set in the filter dictionary
include the following:
string Address
	The Bluetooth device address of the remote
	device. This parameter is mandatory.
string AddressType
	The Bluetooth device Address Type. This is
	address type that should be used for initial
	connection. If this parameter is not present
	BR/EDR device is created.
	Possible values:
		"public" - Public address
		"random" - Random address
Possible errors: org.bluez.Error.InvalidArguments
		 org.bluez.Error.AlreadyExists
		 org.bluez.Error.NotSupported
		 org.bluez.Error.NotReady
		 org.bluez.Error.Failed

func (*Adapter1) FlushDevices

func (a *Adapter1) FlushDevices() error

FlushDevices removes device from bluez cache

func (*Adapter1) GetAdapterID

func (a *Adapter1) GetAdapterID() (string, error)

GetAdapterID return the Id of the adapter

func (*Adapter1) GetAddress

func (a *Adapter1) GetAddress() (string, error)

GetAddress get Address value

func (*Adapter1) GetAddressType

func (a *Adapter1) GetAddressType() (string, error)

GetAddressType get AddressType value

func (*Adapter1) GetAlias

func (a *Adapter1) GetAlias() (string, error)

GetAlias get Alias value

func (*Adapter1) GetClass

func (a *Adapter1) GetClass() (uint32, error)

GetClass get Class value

func (*Adapter1) GetDeviceByAddress

func (a *Adapter1) GetDeviceByAddress(address string) (*device.Device1, error)

GetDeviceByAddress return a Device object based on its address

func (*Adapter1) GetDeviceList

func (a *Adapter1) GetDeviceList() ([]dbus.ObjectPath, error)

GetDeviceList returns a list of cached device paths

func (*Adapter1) GetDevices

func (a *Adapter1) GetDevices() ([]*device.Device1, error)

GetDevices returns a list of bluetooth discovered Devices

func (*Adapter1) GetDiscoverable

func (a *Adapter1) GetDiscoverable() (bool, error)

GetDiscoverable get Discoverable value

func (*Adapter1) GetDiscoverableTimeout

func (a *Adapter1) GetDiscoverableTimeout() (uint32, error)

GetDiscoverableTimeout get DiscoverableTimeout value

func (*Adapter1) GetDiscovering

func (a *Adapter1) GetDiscovering() (bool, error)

GetDiscovering get Discovering value

func (*Adapter1) GetDiscoveryFilters

func (a *Adapter1) GetDiscoveryFilters() ([]string, error)

GetDiscoveryFilters Return available filters that can be given to

SetDiscoveryFilter.
Possible errors: None

func (*Adapter1) GetExperimentalFeatures

func (a *Adapter1) GetExperimentalFeatures() ([]string, error)

GetExperimentalFeatures get ExperimentalFeatures value

func (*Adapter1) GetGattManager

func (a *Adapter1) GetGattManager() (*gatt.GattManager1, error)

GetGattManager return a GattManager1 instance

func (*Adapter1) GetModalias

func (a *Adapter1) GetModalias() (string, error)

GetModalias get Modalias value

func (*Adapter1) GetName

func (a *Adapter1) GetName() (string, error)

GetName get Name value

func (*Adapter1) GetObjectManagerSignal

func (a *Adapter1) GetObjectManagerSignal() (chan *dbus.Signal, func(), error)

GetObjectManagerSignal return a channel for receiving updates from the ObjectManager

func (*Adapter1) GetPairable

func (a *Adapter1) GetPairable() (bool, error)

GetPairable get Pairable value

func (*Adapter1) GetPairableTimeout

func (a *Adapter1) GetPairableTimeout() (uint32, error)

GetPairableTimeout get PairableTimeout value

func (*Adapter1) GetPowered

func (a *Adapter1) GetPowered() (bool, error)

GetPowered get Powered value

func (*Adapter1) GetProperties

func (a *Adapter1) GetProperties() (*Adapter1Properties, error)

GetProperties load all available properties

func (*Adapter1) GetPropertiesSignal

func (a *Adapter1) GetPropertiesSignal() (chan *dbus.Signal, error)

GetPropertiesSignal return a channel for receiving udpdates on property changes

func (*Adapter1) GetProperty

func (a *Adapter1) GetProperty(name string) (dbus.Variant, error)

GetProperty get a property

func (*Adapter1) GetRoles

func (a *Adapter1) GetRoles() ([]string, error)

GetRoles get Roles value

func (*Adapter1) GetUUIDs

func (a *Adapter1) GetUUIDs() ([]string, error)

GetUUIDs get UUIDs value

func (*Adapter1) GetWatchPropertiesChannel

func (a *Adapter1) GetWatchPropertiesChannel() chan *dbus.Signal

GetWatchPropertiesChannel return the dbus channel to receive properties interface

func (*Adapter1) Interface

func (a *Adapter1) Interface() string

Interface return Adapter1 interface

func (*Adapter1) OnDeviceDiscovered

func (a *Adapter1) OnDeviceDiscovered() (chan *DeviceDiscovered, func(), error)

OnDeviceDiscovered monitor for new devices and send updates via channel. Use cancel to close the monitoring process

func (*Adapter1) Path

func (a *Adapter1) Path() dbus.ObjectPath

Path return Adapter1 object path

func (*Adapter1) RemoveDevice

func (a *Adapter1) RemoveDevice(device dbus.ObjectPath) error

RemoveDevice This removes the remote device object at the given

path. It will remove also the pairing information.
Possible errors: org.bluez.Error.InvalidArguments
		 org.bluez.Error.Failed

func (*Adapter1) SetAddress

func (a *Adapter1) SetAddress(v string) error

SetAddress set Address value

func (*Adapter1) SetAddressType

func (a *Adapter1) SetAddressType(v string) error

SetAddressType set AddressType value

func (*Adapter1) SetAlias

func (a *Adapter1) SetAlias(v string) error

SetAlias set Alias value

func (*Adapter1) SetClass

func (a *Adapter1) SetClass(v uint32) error

SetClass set Class value

func (*Adapter1) SetDiscoverable

func (a *Adapter1) SetDiscoverable(v bool) error

SetDiscoverable set Discoverable value

func (*Adapter1) SetDiscoverableTimeout

func (a *Adapter1) SetDiscoverableTimeout(v uint32) error

SetDiscoverableTimeout set DiscoverableTimeout value

func (*Adapter1) SetDiscovering

func (a *Adapter1) SetDiscovering(v bool) error

SetDiscovering set Discovering value

func (*Adapter1) SetDiscoveryFilter

func (a *Adapter1) SetDiscoveryFilter(filter map[string]interface{}) error

SetDiscoveryFilter This method sets the device discovery filter for the

caller. When this method is called with no filter
parameter, filter is removed.
Parameters that may be set in the filter dictionary
include the following:
array{string} UUIDs
	Filter by service UUIDs, empty means match
	_any_ UUID.
	When a remote device is found that advertises
	any UUID from UUIDs, it will be reported if:
	- Pathloss and RSSI are both empty.
	- only Pathloss param is set, device advertise
	  TX pwer, and computed pathloss is less than
	  Pathloss param.
	- only RSSI param is set, and received RSSI is
	  higher than RSSI param.
int16 RSSI
	RSSI threshold value.
	PropertiesChanged signals will be emitted
	for already existing Device objects, with
	updated RSSI value. If one or more discovery
	filters have been set, the RSSI delta-threshold,
	that is imposed by StartDiscovery by default,
	will not be applied.
uint16 Pathloss
	Pathloss threshold value.
	PropertiesChanged signals will be emitted
	for already existing Device objects, with
	updated Pathloss value.
string Transport (Default "auto")
	Transport parameter determines the type of
	scan.
	Possible values:
		"auto"	- interleaved scan
		"bredr"	- BR/EDR inquiry
		"le"	- LE scan only
	If "le" or "bredr" Transport is requested,
	and the controller doesn't support it,
	org.bluez.Error.Failed error will be returned.
	If "auto" transport is requested, scan will use
	LE, BREDR, or both, depending on what's
	currently enabled on the controller.
bool DuplicateData (Default: true)
	Disables duplicate detection of advertisement
	data.
	When enabled PropertiesChanged signals will be
	generated for either ManufacturerData and
	ServiceData everytime they are discovered.
bool Discoverable (Default: false)
	Make adapter discoverable while discovering,
	if the adapter is already discoverable setting
	this filter won't do anything.
string Pattern (Default: none)
	Discover devices where the pattern matches
	either the prefix of the address or
	device name which is convenient way to limited
	the number of device objects created during a
	discovery.
	When set disregards device discoverable flags.
	Note: The pattern matching is ignored if there
	are other client that don't set any pattern as
	it work as a logical OR, also setting empty
	string "" pattern will match any device found.
When discovery filter is set, Device objects will be
created as new devices with matching criteria are
discovered regardless of they are connectable or
discoverable which enables listening to
non-connectable and non-discoverable devices.
When multiple clients call SetDiscoveryFilter, their
filters are internally merged, and notifications about
new devices are sent to all clients. Therefore, each
client must check that device updates actually match
its filter.
When SetDiscoveryFilter is called multiple times by the
same client, last filter passed will be active for
given client.
SetDiscoveryFilter can be called before StartDiscovery.
It is useful when client will create first discovery
session, to ensure that proper scan will be started
right after call to StartDiscovery.
Possible errors: org.bluez.Error.NotReady
		 org.bluez.Error.NotSupported
		 org.bluez.Error.Failed

func (*Adapter1) SetExperimentalFeatures

func (a *Adapter1) SetExperimentalFeatures(v []string) error

SetExperimentalFeatures set ExperimentalFeatures value

func (*Adapter1) SetModalias

func (a *Adapter1) SetModalias(v string) error

SetModalias set Modalias value

func (*Adapter1) SetName

func (a *Adapter1) SetName(v string) error

SetName set Name value

func (*Adapter1) SetPairable

func (a *Adapter1) SetPairable(v bool) error

SetPairable set Pairable value

func (*Adapter1) SetPairableTimeout

func (a *Adapter1) SetPairableTimeout(v uint32) error

SetPairableTimeout set PairableTimeout value

func (*Adapter1) SetPowered

func (a *Adapter1) SetPowered(v bool) error

SetPowered set Powered value

func (*Adapter1) SetProperty

func (a *Adapter1) SetProperty(name string, value interface{}) error

SetProperty set a property

func (*Adapter1) SetRoles

func (a *Adapter1) SetRoles(v []string) error

SetRoles set Roles value

func (*Adapter1) SetUUIDs

func (a *Adapter1) SetUUIDs(v []string) error

SetUUIDs set UUIDs value

func (*Adapter1) SetWatchPropertiesChannel

func (a *Adapter1) SetWatchPropertiesChannel(c chan *dbus.Signal)

SetWatchPropertiesChannel set the dbus channel to receive properties interface

func (*Adapter1) StartDiscovery

func (a *Adapter1) StartDiscovery() error

StartDiscovery This method starts the device discovery session. This

includes an inquiry procedure and remote device name
resolving. Use StopDiscovery to release the sessions
acquired.
This process will start creating Device objects as
new devices are discovered.
During discovery RSSI delta-threshold is imposed.
Each client can request a single device discovery session
per adapter.
Possible errors: org.bluez.Error.NotReady
		 org.bluez.Error.Failed
		 org.bluez.Error.InProgress

func (*Adapter1) StopDiscovery

func (a *Adapter1) StopDiscovery() error

StopDiscovery This method will cancel any previous StartDiscovery

transaction.
Note that a discovery procedure is shared between all
discovery sessions thus calling StopDiscovery will only
release a single session and discovery will stop when
all sessions from all clients have finished.
Possible errors: org.bluez.Error.NotReady
		 org.bluez.Error.Failed
		 org.bluez.Error.NotAuthorized

func (*Adapter1) ToProps

func (a *Adapter1) ToProps() bluez.Properties

ToProps return the properties interface

func (*Adapter1) UnwatchProperties

func (a *Adapter1) UnwatchProperties(ch chan *bluez.PropertyChanged) error

func (*Adapter1) WatchProperties

func (a *Adapter1) WatchProperties() (chan *bluez.PropertyChanged, error)

WatchProperties updates on property changes

type Adapter1Properties

type Adapter1Properties struct {

	/*
		Address The Bluetooth device address.
	*/
	Address string

	/*
		AddressType The Bluetooth  Address Type. For dual-mode and BR/EDR
				only adapter this defaults to "public". Single mode LE
				adapters may have either value. With privacy enabled
				this contains type of Identity Address and not type of
				address used for connection.

				Possible values:
					"public" - Public address
					"random" - Random address
	*/
	AddressType string

	/*
		Alias The Bluetooth friendly name. This value can be
				changed.

				In case no alias is set, it will return the system
				provided name. Setting an empty string as alias will
				convert it back to the system provided name.

				When resetting the alias with an empty string, the
				property will default back to system name.

				On a well configured system, this property never
				needs to be changed since it defaults to the system
				name and provides the pretty hostname. Only if the
				local name needs to be different from the pretty
				hostname, this property should be used as last
				resort.
	*/
	Alias string

	/*
		Class The Bluetooth class of device.

				This property represents the value that is either
				automatically configured by DMI/ACPI information
				or provided as static configuration.
	*/
	Class uint32

	/*
		Discoverable Switch an adapter to discoverable or non-discoverable
				to either make it visible or hide it. This is a global
				setting and should only be used by the settings
				application.

				If the DiscoverableTimeout is set to a non-zero
				value then the system will set this value back to
				false after the timer expired.

				In case the adapter is switched off, setting this
				value will fail.

				When changing the Powered property the new state of
				this property will be updated via a PropertiesChanged
				signal.

				For any new adapter this settings defaults to false.
	*/
	Discoverable bool

	/*
		DiscoverableTimeout The discoverable timeout in seconds. A value of zero
				means that the timeout is disabled and it will stay in
				discoverable/limited mode forever.

				The default value for the discoverable timeout should
				be 180 seconds (3 minutes).
	*/
	DiscoverableTimeout uint32

	/*
		Discovering Indicates that a device discovery procedure is active.
	*/
	Discovering bool

	/*
		ExperimentalFeatures List of 128-bit UUIDs that represents the experimental
				features currently enabled.
	*/
	ExperimentalFeatures []string

	/*
		Modalias Local Device ID information in modalias format
				used by the kernel and udev.
	*/
	Modalias string

	/*
		Name The Bluetooth system name (pretty hostname).

				This property is either a static system default
				or controlled by an external daemon providing
				access to the pretty hostname configuration.
	*/
	Name string

	/*
		Pairable Switch an adapter to pairable or non-pairable. This is
				a global setting and should only be used by the
				settings application.

				Note that this property only affects incoming pairing
				requests.

				For any new adapter this settings defaults to true.
	*/
	Pairable bool

	/*
		PairableTimeout The pairable timeout in seconds. A value of zero
				means that the timeout is disabled and it will stay in
				pairable mode forever.

				The default value for pairable timeout should be
				disabled (value 0).
	*/
	PairableTimeout uint32

	/*
		Powered Switch an adapter on or off. This will also set the
				appropriate connectable state of the controller.

				The value of this property is not persistent. After
				restart or unplugging of the adapter it will reset
				back to false.
	*/
	Powered bool

	/*
		Roles List of supported roles. Possible values:
					"central": Supports the central role.
					"peripheral": Supports the peripheral role.
					"central-peripheral": Supports both roles
							      concurrently.
	*/
	Roles []string

	/*
		UUIDs List of 128-bit UUIDs that represents the available
				local services.
	*/
	UUIDs []string
	// contains filtered or unexported fields
}

Adapter1Properties contains the exposed properties of an interface

func (*Adapter1Properties) FromDBusMap

func (a *Adapter1Properties) FromDBusMap(props map[string]dbus.Variant) (*Adapter1Properties, error)

FromDBusMap convert a map to an Adapter1Properties

func (*Adapter1Properties) FromMap

func (a *Adapter1Properties) FromMap(props map[string]interface{}) (*Adapter1Properties, error)

FromMap convert a map to an Adapter1Properties

func (*Adapter1Properties) Lock

func (p *Adapter1Properties) Lock()

Lock access to properties

func (*Adapter1Properties) ToMap

func (a *Adapter1Properties) ToMap() (map[string]interface{}, error)

ToMap convert a Adapter1Properties to map

func (*Adapter1Properties) Unlock

func (p *Adapter1Properties) Unlock()

Unlock access to properties

type DeviceActions

type DeviceActions uint8
const (
	// DeviceRemoved a device has been removed from local cache
	DeviceRemoved DeviceActions = iota
	// DeviceAdded new device found, eg. via discovery
	DeviceAdded
)

type DeviceDiscovered

type DeviceDiscovered struct {
	Path dbus.ObjectPath
	Type DeviceActions
}

DeviceDiscovered event emitted when a device is added or removed from Object Manager

type DiscoveryFilter

type DiscoveryFilter struct {

	// Filter by service UUIDs, empty means match
	// _any_ UUID.
	//
	// When a remote device is found that advertises
	// any UUID from UUIDs, it will be reported if:
	// - Pathloss and RSSI are both empty.
	// - only Pathloss param is set, device advertise
	// 	TX pwer, and computed pathloss is less than
	// 	Pathloss param.
	// - only RSSI param is set, and received RSSI is
	// 	higher than RSSI param.
	UUIDs []string

	// RSSI threshold value.
	//
	// PropertiesChanged signals will be emitted
	// for already existing Device objects, with
	// updated RSSI value. If one or more discovery
	// filters have been set, the RSSI delta-threshold,
	// that is imposed by StartDiscovery by default,
	// will not be applied.
	RSSI int16

	// Pathloss threshold value.
	//
	// PropertiesChanged signals will be emitted
	// for already existing Device objects, with
	// updated Pathloss value.
	Pathloss uint16

	// Transport parameter determines the type of
	// scan.
	//
	// Possible values:
	// 	"auto"	- interleaved scan
	// 	"bredr"	- BR/EDR inquiry
	// 	"le"	- LE scan only
	//
	// If "le" or "bredr" Transport is requested,
	// and the controller doesn't support it,
	// org.bluez.Error.Failed error will be returned.
	// If "auto" transport is requested, scan will use
	// LE, BREDR, or both, depending on what's
	// currently enabled on the controller.
	Transport string

	// Disables duplicate detection of advertisement
	// data.
	//
	// When enabled PropertiesChanged signals will be
	// generated for either ManufacturerData and
	// ServiceData everytime they are discovered.
	DuplicateData bool
}

Filter applied to discovery

func NewDiscoveryFilter

func NewDiscoveryFilter() DiscoveryFilter

initialize a new DiscoveryFilter

func (*DiscoveryFilter) AddUUIDs

func (a *DiscoveryFilter) AddUUIDs(uuids ...string)

Add an UUID to filter if it does not exists

func (*DiscoveryFilter) ToMap

func (a *DiscoveryFilter) ToMap() map[string]interface{}

ToMap convert to a format compatible with SetDiscoveryFilter method call

Jump to

Keyboard shortcuts

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