Documentation
¶
Overview ¶
Package bluetooth is the BlueZ service, the Go counterpart of crates/wayle-bluetooth: the adapter and device model kept live from the ObjectManager and PropertiesChanged signals, the adapter and device controls, and the org.bluez.Agent1 pairing agent whose requests the UI answers.
Index ¶
- type Adapter
- type AdapterRef
- func (a AdapterRef) ConnectDevice(ctx context.Context, properties map[string]dbus.Variant) (dbus.ObjectPath, error)
- func (a AdapterRef) DiscoveryFilters(ctx context.Context) ([]string, error)
- func (a AdapterRef) RemoveDevice(ctx context.Context, device dbus.ObjectPath) error
- func (a AdapterRef) SetAlias(ctx context.Context, alias string) error
- func (a AdapterRef) SetConnectable(ctx context.Context, connectable bool) error
- func (a AdapterRef) SetDiscoverable(ctx context.Context, discoverable bool) error
- func (a AdapterRef) SetDiscoverableTimeout(ctx context.Context, seconds uint32) error
- func (a AdapterRef) SetDiscoveryFilter(ctx context.Context, options DiscoveryFilterOptions) error
- func (a AdapterRef) SetPairable(ctx context.Context, pairable bool) error
- func (a AdapterRef) SetPairableTimeout(ctx context.Context, seconds uint32) error
- func (a AdapterRef) SetPowered(ctx context.Context, powered bool) error
- func (a AdapterRef) StartDiscovery(ctx context.Context) error
- func (a AdapterRef) StopDiscovery(ctx context.Context) error
- type AdapterRole
- type AddressType
- type AgentCapability
- type Device
- type DeviceRef
- func (d DeviceRef) CancelPairing(ctx context.Context) error
- func (d DeviceRef) Connect(ctx context.Context) error
- func (d DeviceRef) ConnectProfile(ctx context.Context, uuid string) error
- func (d DeviceRef) Disconnect(ctx context.Context) error
- func (d DeviceRef) DisconnectProfile(ctx context.Context, uuid string) error
- func (d DeviceRef) Forget(ctx context.Context) error
- func (d DeviceRef) Pair(ctx context.Context) error
- func (d DeviceRef) ServiceRecords(ctx context.Context) ([][]byte, error)
- func (d DeviceRef) SetAlias(ctx context.Context, alias string) error
- func (d DeviceRef) SetBlocked(ctx context.Context, blocked bool) error
- func (d DeviceRef) SetPreferredBearer(ctx context.Context, bearer PreferredBearer) error
- func (d DeviceRef) SetTrusted(ctx context.Context, trusted bool) error
- func (d DeviceRef) SetWakeAllowed(ctx context.Context, allowed bool) error
- type DeviceSet
- type DisconnectReason
- type DisconnectedEvent
- type DiscoveryFilterOptions
- type DiscoveryTransport
- type DisplayPasskey
- type DisplayPinCode
- type NoPendingRequestError
- type NoPrimaryAdapterError
- type OperationError
- type PairingRequest
- type PowerState
- type PreferredBearer
- type RequestAuthorization
- type RequestConfirmation
- type RequestPasskey
- type RequestPinCode
- type RequestServiceAuthorization
- type Service
- func (s *Service) Adapter(path dbus.ObjectPath) AdapterRef
- func (s *Service) CancelPendingRequest()
- func (s *Service) Close() error
- func (s *Service) Connect(ctx context.Context, device dbus.ObjectPath) error
- func (s *Service) Device(path dbus.ObjectPath) DeviceRef
- func (s *Service) Disable(ctx context.Context) error
- func (s *Service) Disconnect(ctx context.Context, device dbus.ObjectPath) error
- func (s *Service) Disconnected(device dbus.ObjectPath) (<-chan DisconnectedEvent, func())
- func (s *Service) Enable(ctx context.Context) error
- func (s *Service) Forget(ctx context.Context, device dbus.ObjectPath) error
- func (s *Service) ProvideAuthorization(allowed bool) error
- func (s *Service) ProvideConfirmation(confirmed bool) error
- func (s *Service) ProvidePasskey(passkey uint32) error
- func (s *Service) ProvidePin(pin string) error
- func (s *Service) ProvideServiceAuthorization(allowed bool) error
- func (s *Service) SetTrusted(ctx context.Context, device dbus.ObjectPath, trusted bool) error
- func (s *Service) StartDiscovery(ctx context.Context) error
- func (s *Service) StartTimedDiscovery(ctx context.Context, d time.Duration) error
- func (s *Service) State() State
- func (s *Service) StopDiscovery(ctx context.Context) error
- func (s *Service) Subscribe() (<-chan struct{}, func())
- func (s *Service) TrustPaired(ctx context.Context, device dbus.ObjectPath) error
- type Snapshot
- type Source
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
Path dbus.ObjectPath
Address string
AddressType AddressType
Name string
Alias string
Class uint32
Connectable bool
Powered bool
PowerState PowerState
Discoverable bool
DiscoverableTimeout uint32
Discovering bool
Pairable bool
PairableTimeout uint32
UUIDs []string
Modalias *string
Roles []AdapterRole
ExperimentalFeatures []string
Manufacturer uint16
Version uint8
}
Adapter is one org.bluez.Adapter1 (core/adapter). Values handed out by State are snapshots: treat the slices as read-only, the service replaces rather than mutates them.
type AdapterRef ¶
type AdapterRef struct {
// Path is the adapter's object path.
Path dbus.ObjectPath
// contains filtered or unexported fields
}
AdapterRef drives one adapter by path (core/adapter/controls.rs).
func (AdapterRef) ConnectDevice ¶
func (a AdapterRef) ConnectDevice(ctx context.Context, properties map[string]dbus.Variant) (dbus.ObjectPath, error)
ConnectDevice connects to an address without discovery (BlueZ experimental) and returns the device's path.
func (AdapterRef) DiscoveryFilters ¶
func (a AdapterRef) DiscoveryFilters(ctx context.Context) ([]string, error)
DiscoveryFilters lists the filter keys SetDiscoveryFilter accepts.
func (AdapterRef) RemoveDevice ¶
func (a AdapterRef) RemoveDevice(ctx context.Context, device dbus.ObjectPath) error
RemoveDevice removes a device and its bonding.
func (AdapterRef) SetAlias ¶
func (a AdapterRef) SetAlias(ctx context.Context, alias string) error
SetAlias sets the friendly name; empty reverts to the system name.
func (AdapterRef) SetConnectable ¶
func (a AdapterRef) SetConnectable(ctx context.Context, connectable bool) error
SetConnectable sets Connectable (false also clears Discoverable).
func (AdapterRef) SetDiscoverable ¶
func (a AdapterRef) SetDiscoverable(ctx context.Context, discoverable bool) error
SetDiscoverable makes the adapter visible or hidden.
func (AdapterRef) SetDiscoverableTimeout ¶
func (a AdapterRef) SetDiscoverableTimeout(ctx context.Context, seconds uint32) error
SetDiscoverableTimeout sets the discoverable timeout in seconds (0: forever).
func (AdapterRef) SetDiscoveryFilter ¶
func (a AdapterRef) SetDiscoveryFilter(ctx context.Context, options DiscoveryFilterOptions) error
SetDiscoveryFilter sets this client's discovery filter; the zero options clear it.
func (AdapterRef) SetPairable ¶
func (a AdapterRef) SetPairable(ctx context.Context, pairable bool) error
SetPairable sets whether incoming pairing is accepted.
func (AdapterRef) SetPairableTimeout ¶
func (a AdapterRef) SetPairableTimeout(ctx context.Context, seconds uint32) error
SetPairableTimeout sets the pairable timeout in seconds (0: forever).
func (AdapterRef) SetPowered ¶
func (a AdapterRef) SetPowered(ctx context.Context, powered bool) error
SetPowered switches the adapter on or off.
func (AdapterRef) StartDiscovery ¶
func (a AdapterRef) StartDiscovery(ctx context.Context) error
StartDiscovery opens this client's discovery session.
func (AdapterRef) StopDiscovery ¶
func (a AdapterRef) StopDiscovery(ctx context.Context) error
StopDiscovery closes this client's discovery session.
type AdapterRole ¶
type AdapterRole uint8
AdapterRole is one of the adapter's supported roles.
const ( RoleCentral AdapterRole = iota RolePeripheral RoleCentralPeripheral )
The adapter roles.
func ParseAdapterRole ¶
func ParseAdapterRole(s string) AdapterRole
ParseAdapterRole maps BlueZ's role string; unknown reads as central.
type AddressType ¶
type AddressType uint8
AddressType is the Bluetooth address type (types/adapter.rs). BlueZ reports it; unknown values read as public, as in the Rust From<&str>.
const ( AddressPublic AddressType = iota AddressRandom )
The address types.
func ParseAddressType ¶
func ParseAddressType(s string) AddressType
ParseAddressType maps BlueZ's AddressType string, case-insensitively.
type AgentCapability ¶
type AgentCapability uint8
AgentCapability is the IO capability the agent registers with (types/agent.rs).
const ( CapabilityKeyboardDisplay AgentCapability = iota CapabilityDisplayYesNo CapabilityDisplayOnly CapabilityKeyboardOnly CapabilityNoInputNoOutput )
The agent capabilities. KeyboardDisplay is the Rust default.
func ParseAgentCapability ¶
func ParseAgentCapability(s string) AgentCapability
ParseAgentCapability maps the capability name; empty or unknown reads as KeyboardDisplay, as in the Rust From<&str>.
func (AgentCapability) String ¶
func (c AgentCapability) String() string
String is BlueZ's spelling.
type Device ¶
type Device struct {
Path dbus.ObjectPath
Address string
AddressType AddressType
Name *string
Icon *string
BatteryPercentage *uint8
Class *uint32
Appearance *uint16
UUIDs []string
Paired bool
Bonded bool
Connected bool
Trusted bool
Blocked bool
WakeAllowed bool
Alias string
Adapter dbus.ObjectPath
LegacyPairing bool
CablePairing bool
Modalias *string
RSSI *int16
TxPower *int16
ManufacturerData map[uint16][]byte
ServiceData map[string][]byte
ServicesResolved bool
AdvertisingFlags []byte
AdvertisingData map[uint8][]byte
Sets []DeviceSet
PreferredBearer *PreferredBearer
}
Device is one org.bluez.Device1 plus its Battery1 percentage (core/device). Optional BlueZ properties are nil when absent, as the Rust Option fields; a nil map or slice is an absent property.
func (Device) DisplayName ¶
DisplayName is the alias, falling back to the name (the UI's resolve_device_display); empty when BlueZ has neither.
type DeviceRef ¶
type DeviceRef struct {
// Path is the device's object path.
Path dbus.ObjectPath
// contains filtered or unexported fields
}
DeviceRef drives one device by path (core/device/controls.rs).
func (DeviceRef) CancelPairing ¶
CancelPairing aborts a Pair in progress.
func (DeviceRef) ConnectProfile ¶
ConnectProfile connects one profile by UUID.
func (DeviceRef) Disconnect ¶
Disconnect disconnects every profile.
func (DeviceRef) DisconnectProfile ¶
DisconnectProfile disconnects one profile by UUID.
func (DeviceRef) Forget ¶
Forget removes the device through its adapter (RemoveDevice), reading the Adapter property live.
func (DeviceRef) Pair ¶
Pair pairs; BlueZ asks the agent along the way, so this blocks until the pairing prompt is answered.
func (DeviceRef) ServiceRecords ¶
ServiceRecords returns the raw SDP records.
func (DeviceRef) SetBlocked ¶
SetBlocked sets Blocked.
func (DeviceRef) SetPreferredBearer ¶
func (d DeviceRef) SetPreferredBearer(ctx context.Context, bearer PreferredBearer) error
SetPreferredBearer sets PreferredBearer.
func (DeviceRef) SetTrusted ¶
SetTrusted sets Trusted (a trusted device's services need no authorization).
type DeviceSet ¶
type DeviceSet struct {
Path dbus.ObjectPath
// Rank is the device's rank in the set, nil when BlueZ omits it.
Rank *uint8
}
DeviceSet is one Device1.Sets membership.
type DisconnectReason ¶
type DisconnectReason uint8
DisconnectReason is Device1.Disconnected's reason.
const ( DisconnectUnknown DisconnectReason = iota DisconnectTimeout DisconnectLocal DisconnectRemote DisconnectAuthentication DisconnectSuspend )
The disconnect reasons.
func ParseDisconnectReason ¶
func ParseDisconnectReason(s string) DisconnectReason
ParseDisconnectReason maps the org.bluez.Reason.* name.
func (DisconnectReason) String ¶
func (r DisconnectReason) String() string
String is the Rust Display text.
type DisconnectedEvent ¶
type DisconnectedEvent struct {
Reason DisconnectReason
// Message is BlueZ's human-readable text.
Message string
}
DisconnectedEvent is one Device1.Disconnected signal.
type DiscoveryFilterOptions ¶
type DiscoveryFilterOptions struct {
UUIDs []string
RSSI *int16
Pathloss *uint16
Transport *DiscoveryTransport
DuplicateData *bool
Discoverable *bool
Pattern *string
AutoConnect *bool
}
DiscoveryFilterOptions is SetDiscoveryFilter's argument; nil fields are left out of the filter (DiscoveryFilterOptions in types/adapter.rs). The zero value clears the filter.
type DiscoveryTransport ¶
type DiscoveryTransport uint8
DiscoveryTransport is the discovery filter's transport.
const ( TransportAuto DiscoveryTransport = iota TransportBrEdr TransportLE )
The discovery transports.
func ParseDiscoveryTransport ¶
func ParseDiscoveryTransport(s string) DiscoveryTransport
ParseDiscoveryTransport maps the transport name case-insensitively; unknown reads as auto.
func (DiscoveryTransport) String ¶
func (d DiscoveryTransport) String() string
String is BlueZ's spelling.
type DisplayPasskey ¶
type DisplayPasskey struct {
Device dbus.ObjectPath
Passkey uint32
Entered uint16
}
DisplayPasskey shows a passkey to type on the remote device, with the count of digits typed so far; nothing to answer.
func (DisplayPasskey) DevicePath ¶
func (r DisplayPasskey) DevicePath() dbus.ObjectPath
DevicePath implements PairingRequest.
type DisplayPinCode ¶
type DisplayPinCode struct {
Device dbus.ObjectPath
PinCode string
}
DisplayPinCode shows a PIN to type on the remote device; nothing to answer.
func (DisplayPinCode) DevicePath ¶
func (r DisplayPinCode) DevicePath() dbus.ObjectPath
DevicePath implements PairingRequest.
type NoPendingRequestError ¶
type NoPendingRequestError struct{ RequestType string }
NoPendingRequestError is an answer to a pairing request that is not the pending one (Error::NoPendingRequest): a PIN while BlueZ asks for a confirmation, or any answer with nothing pending.
func (*NoPendingRequestError) Error ¶
func (e *NoPendingRequestError) Error() string
type NoPrimaryAdapterError ¶
type NoPrimaryAdapterError struct{ Operation string }
NoPrimaryAdapterError is a service-level operation with no adapter to run on (Error::NoPrimaryAdapter).
func (*NoPrimaryAdapterError) Error ¶
func (e *NoPrimaryAdapterError) Error() string
type OperationError ¶
type OperationError struct {
// Operation names the call, e.g. "start discovery".
Operation string
Err error
}
OperationError is a failed BlueZ call (Error::AdapterOperation, and the device controls' D-Bus errors).
func (*OperationError) Error ¶
func (e *OperationError) Error() string
func (*OperationError) Unwrap ¶
func (e *OperationError) Unwrap() error
type PairingRequest ¶
type PairingRequest interface {
// DevicePath is the device the request is about.
DevicePath() dbus.ObjectPath
// contains filtered or unexported methods
}
PairingRequest is one agent prompt awaiting the user (PairingRequest in types/agent.rs). The concrete types are the seven variants; the interface is sealed.
type PowerState ¶
type PowerState uint8
PowerState is the adapter's power transition state (BlueZ experimental PowerState).
const ( PowerOff PowerState = iota PowerOn PowerOffToOn PowerOnToOff PowerOffBlocked )
The power states.
func ParsePowerState ¶
func ParsePowerState(s string) PowerState
ParsePowerState maps BlueZ's PowerState string; unknown reads as off.
type PreferredBearer ¶
type PreferredBearer uint8
PreferredBearer is the device's preferred bearer (types/device.rs).
const ( BearerLastUsed PreferredBearer = iota BearerBrEdr BearerLE BearerLastSeen )
The preferred bearers.
func ParsePreferredBearer ¶
func ParsePreferredBearer(s string) PreferredBearer
ParsePreferredBearer maps BlueZ's bearer string; unknown reads as last-used.
func (PreferredBearer) String ¶
func (b PreferredBearer) String() string
String is BlueZ's spelling.
type RequestAuthorization ¶
type RequestAuthorization struct{ Device dbus.ObjectPath }
RequestAuthorization asks to allow a just-works pairing (answer with ProvideAuthorization).
func (RequestAuthorization) DevicePath ¶
func (r RequestAuthorization) DevicePath() dbus.ObjectPath
DevicePath implements PairingRequest.
type RequestConfirmation ¶
type RequestConfirmation struct {
Device dbus.ObjectPath
Passkey uint32
}
RequestConfirmation asks whether Passkey matches the remote device's (answer with ProvideConfirmation).
func (RequestConfirmation) DevicePath ¶
func (r RequestConfirmation) DevicePath() dbus.ObjectPath
DevicePath implements PairingRequest.
type RequestPasskey ¶
type RequestPasskey struct{ Device dbus.ObjectPath }
RequestPasskey asks for the numeric passkey shown on the remote device (answer with ProvidePasskey).
func (RequestPasskey) DevicePath ¶
func (r RequestPasskey) DevicePath() dbus.ObjectPath
DevicePath implements PairingRequest.
type RequestPinCode ¶
type RequestPinCode struct{ Device dbus.ObjectPath }
RequestPinCode asks for a legacy PIN (answer with ProvidePin).
func (RequestPinCode) DevicePath ¶
func (r RequestPinCode) DevicePath() dbus.ObjectPath
DevicePath implements PairingRequest.
type RequestServiceAuthorization ¶
type RequestServiceAuthorization struct {
Device dbus.ObjectPath
UUID string
}
RequestServiceAuthorization asks to allow a profile connection (answer with ProvideServiceAuthorization).
func (RequestServiceAuthorization) DevicePath ¶
func (r RequestServiceAuthorization) DevicePath() dbus.ObjectPath
DevicePath implements PairingRequest.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the live BlueZ model plus the pairing agent.
func New ¶
New starts the service on conn, which it owns from here on: it exports and registers the agent, reads the object tree, and follows BlueZ's signals (BluetoothService::new).
func (*Service) Adapter ¶
func (s *Service) Adapter(path dbus.ObjectPath) AdapterRef
Adapter returns the controls for the adapter at path; the path is not checked until a call.
func (*Service) CancelPendingRequest ¶
func (s *Service) CancelPendingRequest()
CancelPendingRequest dismisses whatever is on screen: the yes/no requests are rejected, the PIN/passkey entries cancelled, a display request just cleared (cancel_pending_request).
func (*Service) Close ¶
Close stops following BlueZ, cancels a pending agent request, and drops the connection (which unregisters the agent).
func (*Service) Device ¶
func (s *Service) Device(path dbus.ObjectPath) DeviceRef
Device returns the controls for the device at path; the path is not checked until a call.
func (*Service) Disconnect ¶
Disconnect disconnects the device.
func (*Service) Disconnected ¶
func (s *Service) Disconnected(device dbus.ObjectPath) (<-chan DisconnectedEvent, func())
Disconnected streams the device's Disconnected signals until stop (Device::disconnected_signal).
func (*Service) ProvideAuthorization ¶
ProvideAuthorization answers RequestAuthorization: false rejects.
func (*Service) ProvideConfirmation ¶
ProvideConfirmation answers RequestConfirmation: false rejects.
func (*Service) ProvidePasskey ¶
ProvidePasskey answers RequestPasskey; a passkey above 999999 is an error and the request stays pending.
func (*Service) ProvidePin ¶
ProvidePin answers RequestPinCode. BlueZ takes 1-16 characters; a PIN outside that is an error and the request stays pending.
func (*Service) ProvideServiceAuthorization ¶
ProvideServiceAuthorization answers RequestServiceAuthorization: false rejects.
func (*Service) SetTrusted ¶
SetTrusted sets the device's Trusted.
func (*Service) StartDiscovery ¶
StartDiscovery scans on the primary adapter until StopDiscovery.
func (*Service) StartTimedDiscovery ¶
StartTimedDiscovery scans on the primary adapter and stops that adapter's session after d.
func (*Service) StopDiscovery ¶
StopDiscovery ends the primary adapter's discovery session.
func (*Service) Subscribe ¶
func (s *Service) Subscribe() (<-chan struct{}, func())
Subscribe ticks on every model or pairing change; the channel closes on stop or Close.
func (*Service) TrustPaired ¶
TrustPaired marks a paired, untrusted device trusted, so BlueZ stops asking the agent to authorize its services on every reconnect; an unpaired device is left alone (a stray trust would linger). It reads Paired and Trusted live, as the UI's trust_paired_device does, since the model may not have folded the pairing's signals in yet.
type Snapshot ¶
type Snapshot struct {
// Available reports whether a primary adapter exists.
Available bool
// Enabled is the primary adapter's Powered.
Enabled bool
// Discovering is the primary adapter's Discovering.
Discovering bool
// Connected holds the aliases of connected devices.
Connected []string
}
Snapshot is the bar module's summary of State.
type Source ¶
type Source interface {
// State is the current model.
State() State
// Subscribe ticks (coalesced) on every change until stop.
Subscribe() (ticks <-chan struct{}, stop func())
Enable(ctx context.Context) error
Disable(ctx context.Context) error
StartTimedDiscovery(ctx context.Context, d time.Duration) error
Connect(ctx context.Context, device dbus.ObjectPath) error
Disconnect(ctx context.Context, device dbus.ObjectPath) error
Forget(ctx context.Context, device dbus.ObjectPath) error
SetTrusted(ctx context.Context, device dbus.ObjectPath, trusted bool) error
TrustPaired(ctx context.Context, device dbus.ObjectPath) error
ProvidePin(pin string) error
ProvidePasskey(passkey uint32) error
ProvideConfirmation(confirmed bool) error
ProvideAuthorization(allowed bool) error
ProvideServiceAuthorization(allowed bool) error
CancelPendingRequest()
}
Source is the UI's seam onto the service: the live state, change ticks, and the operations the bar and its dropdown drive.
type State ¶
type State struct {
// Adapters in discovery order.
Adapters []Adapter
// Primary is the adapter the service-level operations use; nil
// when there is none.
Primary *Adapter
// Devices in discovery order, across adapters.
Devices []Device
// Available reports a primary adapter.
Available bool
// Enabled is the primary adapter's Powered.
Enabled bool
// Connected holds the connected devices' addresses.
Connected []string
// Pairing is the agent request on screen, nil when none.
Pairing PairingRequest
}
State is one read of the model (the BluetoothService fields).