bluez

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2018 Jonathan Pentecost

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	SDP_SERVER_SVCLASS_ID           = 0x1000
	BROWSE_GRP_DESC_SVCLASS_ID      = 0x1001
	PUBLIC_BROWSE_GROUP             = 0x1002
	SERIAL_PORT_SVCLASS_ID          = 0x1101
	LAN_ACCESS_SVCLASS_ID           = 0x1102
	DIALUP_NET_SVCLASS_ID           = 0x1103
	IRMC_SYNC_SVCLASS_ID            = 0x1104
	OBEX_OBJPUSH_SVCLASS_ID         = 0x1105
	OBEX_FILETRANS_SVCLASS_ID       = 0x1106
	IRMC_SYNC_CMD_SVCLASS_ID        = 0x1107
	HEADSET_SVCLASS_ID              = 0x1108
	CORDLESS_TELEPHONY_SVCLASS_ID   = 0x1109
	AUDIO_SOURCE_SVCLASS_ID         = 0x110a
	AUDIO_SINK_SVCLASS_ID           = 0x110b
	AV_REMOTE_TARGET_SVCLASS_ID     = 0x110c
	ADVANCED_AUDIO_SVCLASS_ID       = 0x110d
	AV_REMOTE_SVCLASS_ID            = 0x110e
	AV_REMOTE_CONTROLLER_SVCLASS_ID = 0x110f
	INTERCOM_SVCLASS_ID             = 0x1110
	FAX_SVCLASS_ID                  = 0x1111
	HEADSET_AGW_SVCLASS_ID          = 0x1112
	WAP_SVCLASS_ID                  = 0x1113
	WAP_CLIENT_SVCLASS_ID           = 0x1114
	PANU_SVCLASS_ID                 = 0x1115
	NAP_SVCLASS_ID                  = 0x1116
	GN_SVCLASS_ID                   = 0x1117
	DIRECT_PRINTING_SVCLASS_ID      = 0x1118
	REFERENCE_PRINTING_SVCLASS_ID   = 0x1119
	IMAGING_SVCLASS_ID              = 0x111a
	IMAGING_RESPONDER_SVCLASS_ID    = 0x111b
	IMAGING_ARCHIVE_SVCLASS_ID      = 0x111c
	IMAGING_REFOBJS_SVCLASS_ID      = 0x111d
	HANDSFREE_SVCLASS_ID            = 0x111e
	HANDSFREE_AGW_SVCLASS_ID        = 0x111f
	DIRECT_PRT_REFOBJS_SVCLASS_ID   = 0x1120
	REFLECTED_UI_SVCLASS_ID         = 0x1121
	BASIC_PRINTING_SVCLASS_ID       = 0x1122
	PRINTING_STATUS_SVCLASS_ID      = 0x1123
	HID_SVCLASS_ID                  = 0x1124
	HCR_SVCLASS_ID                  = 0x1125
	HCR_PRINT_SVCLASS_ID            = 0x1126
	HCR_SCAN_SVCLASS_ID             = 0x1127
	CIP_SVCLASS_ID                  = 0x1128
	VIDEO_CONF_GW_SVCLASS_ID        = 0x1129
	UDI_MT_SVCLASS_ID               = 0x112a
	UDI_TA_SVCLASS_ID               = 0x112b
	AV_SVCLASS_ID                   = 0x112c
	SAP_SVCLASS_ID                  = 0x112d
	PBAP_PCE_SVCLASS_ID             = 0x112e
	PBAP_PSE_SVCLASS_ID             = 0x112f
	PBAP_SVCLASS_ID                 = 0x1130
	MAP_MSE_SVCLASS_ID              = 0x1132
	MAP_MCE_SVCLASS_ID              = 0x1133
	MAP_SVCLASS_ID                  = 0x1134
	GNSS_SVCLASS_ID                 = 0x1135
	GNSS_SERVER_SVCLASS_ID          = 0x1136
	MPS_SC_SVCLASS_ID               = 0x113A
	MPS_SVCLASS_ID                  = 0x113B
	PNP_INFO_SVCLASS_ID             = 0x1200
	GENERIC_NETWORKING_SVCLASS_ID   = 0x1201
	GENERIC_FILETRANS_SVCLASS_ID    = 0x1202
	GENERIC_AUDIO_SVCLASS_ID        = 0x1203
	GENERIC_TELEPHONY_SVCLASS_ID    = 0x1204
	UPNP_SVCLASS_ID                 = 0x1205
	UPNP_IP_SVCLASS_ID              = 0x1206
	UPNP_PAN_SVCLASS_ID             = 0x1300
	UPNP_LAP_SVCLASS_ID             = 0x1301
	UPNP_L2CAP_SVCLASS_ID           = 0x1302
	VIDEO_SOURCE_SVCLASS_ID         = 0x1303
	VIDEO_SINK_SVCLASS_ID           = 0x1304
	VIDEO_DISTRIBUTION_SVCLASS_ID   = 0x1305
	HDP_SVCLASS_ID                  = 0x1400
	HDP_SOURCE_SVCLASS_ID           = 0x1401
	HDP_SINK_SVCLASS_ID             = 0x1402
	GENERIC_ACCESS_SVCLASS_ID       = 0x1800
	GENERIC_ATTRIB_SVCLASS_ID       = 0x1801
	APPLE_AGENT_SVCLASS_ID          = 0x2112
)

Service Class identifiers. Adapted from: https://github.com/bluez/bluez/blob/master/lib/sdp.h#L64

Variables

View Source
var Services = map[uint32]string{}/* 866 elements not displayed */

Services stores a service UUID and its corresponding description. Adapted from: https://github.com/bluez/bluez/blob/master/src/shared/util.c#L195

Functions

func DecodeVariantMap added in v0.1.9

func DecodeVariantMap(
	variants map[string]dbus.Variant, data interface{},
	checkProps ...string,
) error

DecodeVariantMap decodes a map of variants into the provided data.

func GetAdapterID

func GetAdapterID(adapterPath string) string

GetAdapterID gets the adapter ID from the adapter path.

func GetDeviceType added in v0.0.3

func GetDeviceType(class uint32) string

GetDeviceType parses the device class and returns its type.

func ServiceExists added in v0.0.8

func ServiceExists(uuidList []string, svclass uint32) bool

ServiceExists checks if the service class ID exists in the UUID list.

func ServiceType added in v0.0.8

func ServiceType(serviceUUID string) string

ServiceType returns a service description of the service UUID. Adapted from: https://github.com/bluez/bluez/blob/master/src/shared/util.c#L1189

Types

type Adapter

type Adapter struct {
	Path         string
	Name         string
	Alias        string
	Address      string
	Discoverable bool
	Pairable     bool
	Powered      bool
	Discovering  bool

	Lock *semaphore.Weighted
}

Adapter holds the bluetooth device adapter installed for a system.

type AudioProfile added in v0.0.9

type AudioProfile struct {
	Name        string
	Description string
	Index       uint32
	Active      bool
}

AudioProfile stores the audio profile information.

func ListAudioProfiles added in v0.0.9

func ListAudioProfiles(deviceAddress string) ([]AudioProfile, error)

ListAudioProfiles lists audio profiles of a sound card.

func (AudioProfile) SetAudioProfile added in v0.0.9

func (a AudioProfile) SetAudioProfile() error

SetAudioProfile sets an audio profile for a sound card.

type Bluez

type Bluez struct {
	CurrentAdapter Adapter
	AdapterLock    sync.Mutex

	Store     map[string]StoreObject
	StoreLock sync.Mutex

	CurrentPlayer dbus.ObjectPath
	PlayerLock    sync.Mutex
	// contains filtered or unexported fields
}

Bluez represents an overview of the bluetooth adapters and devices installed and configured on a system. A connection to `bluez` dbus is also used to interact with the bluetooth server on a system.

func NewBluez

func NewBluez() (*Bluez, error)

NewBluez returns a new Bluez.

func (*Bluez) CallAdapter

func (b *Bluez) CallAdapter(adapter, method string, flags dbus.Flags, args ...interface{}) *dbus.Call

CallAdapter is used to interact with the bluez Adapter dbus interface. https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt

func (*Bluez) CallDevice

func (b *Bluez) CallDevice(devicePath, method string, flags dbus.Flags, args ...interface{}) *dbus.Call

CallDevice is used to interact with the bluez Device dbus interface. https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/device-api.txt

func (*Bluez) CallMediaPlayer added in v0.0.9

func (b *Bluez) CallMediaPlayer(command string) error

CallMediaPlayer is used to interact with the bluez MediaPlayer interface.

func (*Bluez) CancelPairing

func (b *Bluez) CancelPairing(devicePath string) error

CancelPairing will cancel a pairing attempt.

func (*Bluez) Close

func (b *Bluez) Close()

Close closes the bluez connection.

func (*Bluez) Conn

func (b *Bluez) Conn() *dbus.Conn

Conn returns the current SystemBus connection.

func (*Bluez) Connect

func (b *Bluez) Connect(devicePath string) error

Connect will attempt to connect an already paired bluetooth device to an adapter.

func (*Bluez) ConvertAndStoreObjects added in v0.1.9

func (b *Bluez) ConvertAndStoreObjects(objects map[dbus.ObjectPath]map[string]map[string]dbus.Variant) error

func (*Bluez) ConvertToAdapter added in v0.1.9

func (b *Bluez) ConvertToAdapter(path string, values map[string]dbus.Variant, adapters *[]Adapter) error

ConvertToAdapters converts a map of dbus objects to a common Adapter structure.

func (*Bluez) ConvertToDevice added in v0.1.9

func (b *Bluez) ConvertToDevice(path string, values map[string]dbus.Variant, devices *[]Device) error

ConvertToDevices converts a map of dbus objects to a common Device structure.

func (*Bluez) Disconnect

func (b *Bluez) Disconnect(devicePath string) error

Disconnect will remove the bluetooth device from the adapter.

func (*Bluez) FastForward added in v0.0.9

func (b *Bluez) FastForward() error

FastForward forward-skips the currently playing track.

func (*Bluez) GetAdapterProperties

func (b *Bluez) GetAdapterProperties(adapterPath string) (map[string]dbus.Variant, error)

GetAdapterProperties gathers all the properties for a bluetooth adapter.

func (*Bluez) GetAdapters

func (b *Bluez) GetAdapters() []Adapter

GetAdapters gets the stored adapters.

func (*Bluez) GetBatteryPercentage added in v0.1.0

func (b *Bluez) GetBatteryPercentage(devicePath string) (byte, error)

GetBatteryPercentage gets the battery percentage of a device.

func (*Bluez) GetCurrentAdapter

func (b *Bluez) GetCurrentAdapter() Adapter

GetCurrentAdapter gets the current adapter.

func (*Bluez) GetCurrentAdapterID

func (b *Bluez) GetCurrentAdapterID() string

GetCurrentAdapterID gets the adapter ID from the current adapter's path.

func (*Bluez) GetCurrentPlayer added in v0.0.9

func (b *Bluez) GetCurrentPlayer() dbus.ObjectPath

GetCurrentPlayer gets the currently running player's path.

func (*Bluez) GetDevice

func (b *Bluez) GetDevice(devicePath string) Device

GetDevice returns a Device with the provided device path.

func (*Bluez) GetDeviceProperties

func (b *Bluez) GetDeviceProperties(devicePath string) (map[string]dbus.Variant, error)

GetDeviceProperties gathers all the properties for a bluetooth device.

func (*Bluez) GetDevices

func (b *Bluez) GetDevices() []Device

GetDevices gets the stored devices.

func (*Bluez) GetMediaControlProperties added in v0.0.9

func (b *Bluez) GetMediaControlProperties(devicePath string) (map[string]dbus.Variant, error)

GetMediaControlProperties gets the media control properties.

func (*Bluez) GetMediaPlayerProperties added in v0.0.9

func (b *Bluez) GetMediaPlayerProperties() (map[string]dbus.Variant, error)

GetMediaPlayerProperties gets the media player properties.

func (*Bluez) GetMediaPlayerProperty added in v0.0.9

func (b *Bluez) GetMediaPlayerProperty(property string) (interface{}, error)

GetMediaPlayerProperty gets the specified media player property.

func (*Bluez) GetMediaProperties added in v0.0.9

func (b *Bluez) GetMediaProperties(values ...map[string]dbus.Variant) (MediaProperties, error)

GetMediaProperties gets the media properties of the currently playing track.

func (*Bluez) InitMediaPlayer added in v0.0.9

func (b *Bluez) InitMediaPlayer(devicePath string) error

InitMediaPlayer initializes the media player.

func (*Bluez) ManagedObjects

func (b *Bluez) ManagedObjects() (map[dbus.ObjectPath]map[string]map[string]dbus.Variant, error)

ManagedObjects gets all bluetooth devices and adapters that are currently managed by bluez.

func (*Bluez) Next added in v0.0.9

func (b *Bluez) Next() error

Next switches to the next track.

func (*Bluez) Pair

func (b *Bluez) Pair(devicePath string) error

Pair will attempt to pair a bluetooth device that is in pairing mode.

func (*Bluez) ParseSignalData

func (b *Bluez) ParseSignalData(signal *dbus.Signal) interface{}

ParseSignalData parses bluez DBus signal data.

func (*Bluez) Pause added in v0.0.9

func (b *Bluez) Pause() error

Pause suspends the media playback.

func (*Bluez) Play added in v0.0.9

func (b *Bluez) Play() error

Play starts the media playback.

func (*Bluez) Power

func (b *Bluez) Power(adapterPath string, enable bool) error

Power sets the powered state of the adapter.

func (*Bluez) Previous added in v0.0.9

func (b *Bluez) Previous() error

Previous switches to the previous track.

func (*Bluez) RefreshStore

func (b *Bluez) RefreshStore() error

RefreshStore will query system for known bluetooth adapters and devices and will store them on the Bluez structure.

func (*Bluez) RemoveDevice

func (b *Bluez) RemoveDevice(devicePath string) error

RemoveDevice will permantently remove the bluetooth device from the adapter. Once a device is removed, it can only be added again by being paired.

func (*Bluez) Rewind added in v0.0.9

func (b *Bluez) Rewind() error

Rewind backward-skips the currently playing track.

func (*Bluez) SetAdapterProperty

func (b *Bluez) SetAdapterProperty(adapterPath, key string, value interface{}) error

SetAdapterProperty can be used to set certain properties for a bluetooth adapter.

func (*Bluez) SetCurrentAdapter

func (b *Bluez) SetCurrentAdapter(adapter ...Adapter) error

SetCurrentAdapter sets the current adapter.

func (*Bluez) SetCurrentPlayer added in v0.0.9

func (b *Bluez) SetCurrentPlayer(playerPath dbus.ObjectPath)

SetCurrentPlayer sets the player path.

func (*Bluez) SetDeviceProperty

func (b *Bluez) SetDeviceProperty(devicePath, key string, value interface{}) error

SetDeviceProperty can be used to set certain properties for a bluetooth device.

func (*Bluez) StartDiscovery

func (b *Bluez) StartDiscovery(adapter string) error

StartDiscovery will put the adapter into "discovering" mode, which means the bluetooth device will be able to discover other bluetooth devices that are in pairing mode.

func (*Bluez) Stop added in v0.0.9

func (b *Bluez) Stop() error

Stop halts the media playback.

func (*Bluez) StopDiscovery

func (b *Bluez) StopDiscovery(adapter string) error

StopDiscovery will stop the "discovering" mode, which means the bluetooth device will no longer be able to discover other bluetooth devices that are in pairing mode.

func (*Bluez) TogglePlayPause added in v0.0.9

func (b *Bluez) TogglePlayPause() error

TogglePlayPause toggles the play/pause states.

func (*Bluez) WatchSignal

func (b *Bluez) WatchSignal() chan *dbus.Signal

WatchSignal will register to receive events form the bluez dbus interface. Any events received are passed along to the returned channel for the caller to use.

type Device

type Device struct {
	Path          string
	Name          string
	Type          string
	Alias         string
	Address       string
	AddressType   string
	Adapter       string
	Modalias      string
	UUIDs         []string
	Paired        bool
	Connected     bool
	Trusted       bool
	Blocked       bool
	Bonded        bool
	LegacyPairing bool
	RSSI          int16
	Class         uint32
	Percentage    int
}

Device holds bluetooth device information.

func (Device) HaveService added in v0.0.8

func (d Device) HaveService(service uint32) bool

HaveService checks if the device has the specified service.

type MediaProperties added in v0.0.9

type MediaProperties struct {
	Status   string
	Position uint32
	Track    TrackProperties
}

MediaProperties holds the media player information.

type Obex added in v0.0.5

type Obex struct {
	Store     map[dbus.ObjectPath]ObexProperties
	StoreLock sync.Mutex
	// contains filtered or unexported fields
}

Obex represents an OBEX connection. It also stores information about the currently running transfers.

func NewObex added in v0.0.5

func NewObex() (*Obex, error)

NewObex returns a new Obex.

func (*Obex) CallClient added in v0.0.5

func (o *Obex) CallClient(method string, args ...interface{}) *dbus.Call

CallClient calls the Client1 interface with the provided method.

func (*Obex) CallClientAsync added in v0.1.7

func (o *Obex) CallClientAsync(ctx context.Context, method string, args ...interface{}) *dbus.Call

CallClientAsync calls the Client1 interface asynchronously with the provided method.

func (*Obex) CallObjectPush added in v0.0.5

func (o *Obex) CallObjectPush(sessionPath dbus.ObjectPath, method string, args ...interface{}) *dbus.Call

CallObjectPush calls the ObjectPush1 interface with the provided method.

func (*Obex) CallTransfer added in v0.0.5

func (o *Obex) CallTransfer(transferPath dbus.ObjectPath, method string, args ...interface{}) *dbus.Call

CallTransfer calls the Transfer1 interface with the provided method.

func (*Obex) CancelTransfer added in v0.0.5

func (o *Obex) CancelTransfer(transferPath dbus.ObjectPath) error

CancelTransfer cancels the transfer.

func (*Obex) Close added in v0.0.5

func (o *Obex) Close()

Close closes the OBEX connection.

func (*Obex) Conn added in v0.0.5

func (o *Obex) Conn() *dbus.Conn

Conn returns the current SessionBus connection.

func (*Obex) CreateSession added in v0.0.5

func (o *Obex) CreateSession(ctx context.Context, address string) (dbus.ObjectPath, error)

CreateSession creates a new OBEX transfer session.

func (*Obex) GetSessionProperties added in v0.0.5

func (o *Obex) GetSessionProperties(sessionPath dbus.ObjectPath, sprop ...map[string]dbus.Variant) (ObexSessionProperties, error)

GetSessionProperties converts a map of OBEX session properties to ObexSessionProperties.

func (*Obex) GetTransferProperties added in v0.0.5

func (o *Obex) GetTransferProperties(props map[string]dbus.Variant) (ObexTransferProperties, error)

GetTransferProperties converts a map of transfer properties to ObexTransferProperties.

func (*Obex) ManagedObjects added in v0.0.5

func (o *Obex) ManagedObjects() (map[dbus.ObjectPath]map[string]map[string]dbus.Variant, error)

ManagedObjects gets the currently managed objects from the OBEX DBus.

func (*Obex) ParseSignalData added in v0.0.5

func (o *Obex) ParseSignalData(signal *dbus.Signal) interface{}

ParseSignalData parses OBEX DBus signal data.

func (*Obex) ReceiveFile added in v0.0.5

func (o *Obex) ReceiveFile(sessionPath, transferPath dbus.ObjectPath) (string, string, ObexTransferProperties, error)

ReceiveFile returns a path where the OBEX daemon (obexd) will receive the file, along with the transfer properties.

func (*Obex) RemoveSession added in v0.0.5

func (o *Obex) RemoveSession(sessionPath dbus.ObjectPath) error

RemoveSession removes the OBEX transfer session and cancels any pending transfers.

func (*Obex) ResumeTransfer added in v0.0.5

func (o *Obex) ResumeTransfer(transferPath dbus.ObjectPath) error

ResumeTransfer resumes the transfer.

func (*Obex) SendFile added in v0.0.5

func (o *Obex) SendFile(sessionPath dbus.ObjectPath, path string) (dbus.ObjectPath, ObexTransferProperties, error)

SendFile sends a file to the target device.

func (*Obex) SuspendTransfer added in v0.0.5

func (o *Obex) SuspendTransfer(transferPath dbus.ObjectPath) error

SuspendTransfer suspends the transfer.

func (*Obex) WatchSignal added in v0.0.5

func (o *Obex) WatchSignal() chan *dbus.Signal

WatchSignal will register a signal and watch for events from the OBEX DBus interface.

type ObexProperties added in v0.0.5

type ObexProperties struct {
	SessionPath       dbus.ObjectPath
	SessionProperties ObexSessionProperties

	TransferPath       dbus.ObjectPath
	TransferProperties ObexTransferProperties
}

ObexProperties stores the session and transfer paths of an OBEX transfer, along with their properties.

type ObexSessionProperties added in v0.0.5

type ObexSessionProperties struct {
	Root        string
	Target      string
	Source      string
	Destination string
}

ObexSessionProperties describes the session properties of an OBEX transfer.

type ObexTransferProperties added in v0.0.5

type ObexTransferProperties struct {
	Name     string
	Type     string
	Status   string
	Filename string

	Size        uint64
	Transferred uint64

	Session string
}

ObexTransferProperties describes the transfer properties of an OBEX transfer.

type Resolver added in v0.1.9

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

Resolver holds an encoder and decoder.

type StoreObject

type StoreObject struct {
	Adapter Adapter
	Devices map[string]Device
}

StoreObject holds an Adapter and the Devices that belong to it. Each device is stored into Devices with the device adapter path (held by (Device).Adapter) as the identifier.

type TrackProperties added in v0.0.9

type TrackProperties struct {
	Title       string
	Album       string
	Artist      string
	Duration    uint32
	TrackNumber uint32
	TotalTracks uint32
}

TrackProperties describes the track properties of the currently playing media.

Jump to

Keyboard shortcuts

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