1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef BLUETOOTHMANAGEMENT_P_H
5#define BLUETOOTHMANAGEMENT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qdatetime.h>
19#include <QtCore/qmutex.h>
20#include <QtCore/qobject.h>
21
22#include <QtBluetooth/qbluetoothaddress.h>
23
24#ifndef QPRIVATELINEARBUFFER_BUFFERSIZE
25#define QPRIVATELINEARBUFFER_BUFFERSIZE qsizetype(16384)
26#endif
27#include "../qprivatelinearbuffer_p.h"
28
29QT_BEGIN_NAMESPACE
30
31class QSocketNotifier;
32
33class BluetoothManagement : public QObject
34{
35 Q_OBJECT
36
37public:
38
39 enum class EventCode {
40 CommandCompleteEvent = 0x0001,
41 CommandStatusEvent = 0x0002,
42 ControllerErrorEvent = 0x0003,
43 IndexAddedEvent = 0x0004,
44 IndexRemovedEvent = 0x0005,
45 NewSettingsEvent = 0x0006,
46 ClassOfDeviceChangedEvent = 0x0007,
47 LocalNameChangedEvent = 0x0008,
48 NewLinkKeyEvent = 0x0009,
49 NewLongTermKeyEvent = 0x000A,
50 DeviceConnectedEvent = 0x000B,
51 DeviceDisconnectedEvent = 0x000C,
52 ConnectFailedEvent = 0x000D,
53 PINCodeRequestEvent = 0x000E,
54 UserConfirmationRequestEvent = 0x000F,
55 UserPasskeyRequestEvent = 0x0010,
56 AuthenticationFailedEvent = 0x0011,
57 DeviceFoundEvent = 0x0012,
58 DiscoveringEvent = 0x0013,
59 DeviceBlockedEvent = 0x0014,
60 DeviceUnblockedEvent = 0x00150,
61 DeviceUnpairedEvent = 0x0016,
62 PasskeyNotifyEvent = 0x0017,
63 NewIdentityResolvingKeyEvent = 0x0018,
64 NewSignatureResolvingKeyEvent = 0x0019,
65 DeviceAddedEvent = 0x001a,
66 DeviceRemovedEvent = 0x001b,
67 NewConnectionParameterEvent = 0x001c,
68 UnconfiguredIndexAddedEvent = 0x001d,
69 UnconfiguredIndexRemovedEvent = 0x001e,
70 NewConfigurationOptionsEvent = 0x001f,
71 ExtendedIndexAddedEvent = 0x0020,
72 ExtendedIndexRemovedEvent = 0x0021,
73 LocalOutOfBandExtendedDataUpdatedEvent = 0x0022,
74 AdvertisingAddedEvent = 0x0023,
75 AdvertisingRemovedEvent = 0x0024,
76 ExtendedControllerInformationChangedEvent = 0x0025,
77 PHYConfigurationChangedEvent = 0x0026,
78 ExperimentalFeatureChangedEvent = 0x0027,
79 DefaultSystemConfigurationChangedEvent = 0x0028,
80 DefaultRuntimeConfigurationChangedEvent = 0x0029,
81 DeviceFlagsChangedEvent = 0x002a,
82 AdvertisementMonitorAddedEvent = 0x002b,
83 AdvertisementMonitorRemovedEvent = 0x002c,
84 ControllerSuspendEvent = 0x002d,
85 ControllerResumeEvent = 0x002e
86 };
87 Q_ENUM(EventCode)
88
89 explicit BluetoothManagement(QObject *parent = nullptr);
90 static BluetoothManagement *instance();
91
92 bool isAddressRandom(const QBluetoothAddress &address) const;
93 bool isMonitoringEnabled() const;
94
95private slots:
96 void _q_readNotifier();
97 void processRandomAddressFlagInformation(const QBluetoothAddress &address);
98 void cleanupOldAddressFlags();
99
100private:
101 void readyRead();
102
103 int fd = -1;
104 QSocketNotifier* notifier;
105 QPrivateLinearBuffer buffer;
106 QHash<QBluetoothAddress, QDateTime> privateFlagAddresses;
107 mutable QMutex accessLock;
108};
109
110
111QT_END_NAMESPACE
112
113#endif // BLUETOOTHMANAGEMENT_P_H
114

source code of qtconnectivity/src/bluetooth/bluez/bluetoothmanagement_p.h