Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
BluetoothAgent.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceBluetooth/phosphorservicebluetooth_export.h>
7
8#include <QDBusContext>
9#include <QObject>
10#include <QString>
11
12#include <memory>
13
14class QDBusObjectPath;
15
17
38class PHOSPHORSERVICEBLUETOOTH_EXPORT BluetoothAgent : public QObject, protected QDBusContext
39{
40 Q_OBJECT
41 Q_PROPERTY(bool available READ available NOTIFY availableChanged)
42 Q_CLASSINFO("D-Bus Interface", "org.bluez.Agent1")
43
44public:
45 explicit BluetoothAgent(QObject* parent = nullptr);
46 ~BluetoothAgent() override;
47 [[nodiscard]] bool available() const;
50
53 [[nodiscard]] static QString agentPath();
54
57 [[nodiscard]] int pendingRequestCount() const;
58
59 // Consumer responses to the request signals below. Q_INVOKABLE (not slots)
60 // so they are callable from QML/CLI but NOT exported on the Agent1
61 // interface. A mismatched id or request kind is ignored.
62 Q_INVOKABLE void respondPinCode(quint64 requestId, const QString& pinCode);
63 Q_INVOKABLE void respondPasskey(quint64 requestId, quint32 passkey);
66 Q_INVOKABLE void respondConfirmation(quint64 requestId, bool accept);
68 Q_INVOKABLE void rejectRequest(quint64 requestId);
69
70public Q_SLOTS:
71 // org.bluez.Agent1, exported to BlueZ via ExportAllSlots. Signatures
72 // mirror the BlueZ spec exactly; the interactive ones defer their reply.
73 //
74 // SECURITY: ONLY org.bluez.Agent1 methods may live in this slot block.
75 // ExportAllSlots publishes every public slot on the Agent1 interface, so
76 // adding an unrelated slot here would expose it to any bus peer. The
77 // consumer-facing respond*/rejectRequest methods are deliberately
78 // Q_INVOKABLE (above), NOT slots, so a remote can never answer its own
79 // pairing prompt. Every interactive request MUST be answered (respond* /
80 // rejectRequest) or BlueZ's Pair() blocks until its own timeout; the
81 // host's consumer wires all of the request signals below.
82 void Release();
83 QString RequestPinCode(const QDBusObjectPath& device);
84 void DisplayPinCode(const QDBusObjectPath& device, const QString& pincode);
85 uint RequestPasskey(const QDBusObjectPath& device);
86 void DisplayPasskey(const QDBusObjectPath& device, uint passkey, ushort entered);
87 void RequestConfirmation(const QDBusObjectPath& device, uint passkey);
88 void RequestAuthorization(const QDBusObjectPath& device);
89 void AuthorizeService(const QDBusObjectPath& device, const QString& uuid);
90 void Cancel();
91
92Q_SIGNALS:
96 void pinCodeRequested(const QString& devicePath, quint64 requestId);
98 void passkeyRequested(const QString& devicePath, quint64 requestId);
101 void confirmationRequested(const QString& devicePath, quint32 passkey, quint64 requestId);
104 void authorizationRequested(const QString& devicePath, quint64 requestId);
107 void serviceAuthorizationRequested(const QString& devicePath, const QString& uuid, quint64 requestId);
108
110 void pinCodeDisplayed(const QString& devicePath, const QString& pinCode);
111 void passkeyDisplayed(const QString& devicePath, quint32 passkey, quint16 entered);
112
116 void released();
117
118private:
119 Q_DISABLE_COPY_MOVE(BluetoothAgent)
120 class Private;
121 std::unique_ptr<Private> d;
122};
123
124} // namespace PhosphorServiceBluetooth
QString RequestPinCode(const QDBusObjectPath &device)
void confirmationRequested(const QString &devicePath, quint32 passkey, quint64 requestId)
Confirm that passkey matches the one shown on devicePath.
void RequestAuthorization(const QDBusObjectPath &device)
static QString agentPath()
Object path the agent is exported at and registered under with org.bluez.AgentManager1.
void authorizationRequested(const QString &devicePath, quint64 requestId)
Authorize an incoming pairing with no MITM protection.
BluetoothAgent(QObject *parent=nullptr)
void respondPinCode(quint64 requestId, const QString &pinCode)
void pinCodeRequested(const QString &devicePath, quint64 requestId)
A PIN code (legacy) is required for devicePath.
void serviceAuthorizationRequested(const QString &devicePath, const QString &uuid, quint64 requestId)
Authorize uuid on devicePath.
void passkeyRequested(const QString &devicePath, quint64 requestId)
A numeric passkey is required. Answer with respondPasskey / rejectRequest.
void DisplayPasskey(const QDBusObjectPath &device, uint passkey, ushort entered)
void released()
BlueZ released the agent (Release); it is no longer registered.
void RequestConfirmation(const QDBusObjectPath &device, uint passkey)
void DisplayPinCode(const QDBusObjectPath &device, const QString &pincode)
void respondPasskey(quint64 requestId, quint32 passkey)
void pinCodeDisplayed(const QString &devicePath, const QString &pinCode)
Display-only: show pinCode / passkey to the user (no response).
void passkeyDisplayed(const QString &devicePath, quint32 passkey, quint16 entered)
int pendingRequestCount() const
Number of requests awaiting a consumer response.
void requestCancelled()
BlueZ withdrew the in-flight request (Cancel); any prompt should close.
void AuthorizeService(const QDBusObjectPath &device, const QString &uuid)
void respondConfirmation(quint64 requestId, bool accept)
Accept (or, with accept false, reject) a confirmation / authorization / service-authorization request...
void rejectRequest(quint64 requestId)
Reject any pending request with org.bluez.Error.Rejected.
void setAvailable(bool available)
Internal registration state, updated by BluetoothHost.
uint RequestPasskey(const QDBusObjectPath &device)
Definition BluetoothAdapter.h:16