summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/bluetooth.pro48
-rw-r--r--src/bluetooth/bluez/bluez.pri6
-rw-r--r--src/bluetooth/bluez/characteristic.cpp54
-rw-r--r--src/bluetooth/bluez/characteristic_p.h111
-rw-r--r--src/bluetooth/doc/src/bluetooth-index.qdoc2
-rw-r--r--src/bluetooth/doc/src/bluetooth-overview.qdoc105
-rw-r--r--src/bluetooth/doc/src/examples.qdoc7
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp10
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp23
-rw-r--r--src/bluetooth/qbluetoothdeviceinfo.cpp60
-rw-r--r--src/bluetooth/qbluetoothdeviceinfo.h9
-rw-r--r--src/bluetooth/qbluetoothdeviceinfo_p.h1
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp1
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.h2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp250
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_p.h17
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp99
-rw-r--r--src/bluetooth/qbluetoothuuid.cpp352
-rw-r--r--src/bluetooth/qbluetoothuuid.h121
-rw-r--r--src/bluetooth/qlowenergycharacteristicinfo.cpp298
-rw-r--r--src/bluetooth/qlowenergycharacteristicinfo.h105
-rw-r--r--src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp101
-rw-r--r--src/bluetooth/qlowenergycharacteristicinfo_p.cpp85
-rw-r--r--src/bluetooth/qlowenergycharacteristicinfo_p.h117
-rw-r--r--src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp332
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp222
-rw-r--r--src/bluetooth/qlowenergycontroller.h97
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp518
-rw-r--r--src/bluetooth/qlowenergycontroller_p.cpp120
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h94
-rw-r--r--src/bluetooth/qlowenergydescriptorinfo.cpp175
-rw-r--r--src/bluetooth/qlowenergydescriptorinfo.h79
-rw-r--r--src/bluetooth/qlowenergydescriptorinfo_p.h59
-rw-r--r--src/bluetooth/qlowenergyprocess_bluez.cpp145
-rw-r--r--src/bluetooth/qlowenergyprocess_p.cpp68
-rw-r--r--src/bluetooth/qlowenergyprocess_p.h98
-rw-r--r--src/bluetooth/qlowenergyprocess_qnx.cpp96
-rw-r--r--src/bluetooth/qlowenergyserviceinfo.cpp242
-rw-r--r--src/bluetooth/qlowenergyserviceinfo.h98
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_bluez.cpp86
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_p.cpp70
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_p.h118
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_qnx.cpp268
-rw-r--r--src/nfc/qnx/qnxnfcmanager.cpp1
44 files changed, 4834 insertions, 136 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 44d2444c..bb4e6266 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -2,6 +2,7 @@ TARGET = QtBluetooth
QT = core
QT_PRIVATE = concurrent
+
QMAKE_DOCS = $$PWD/doc/qtbluetooth.qdocconf
OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator
@@ -22,7 +23,11 @@ PUBLIC_HEADERS += \
qbluetoothlocaldevice.h \
qbluetoothtransfermanager.h \
qbluetoothtransferrequest.h \
- qbluetoothtransferreply.h
+ qlowenergyserviceinfo.h \
+ qlowenergycharacteristicinfo.h \
+ qlowenergydescriptorinfo.h \
+ qbluetoothtransferreply.h \
+ qlowenergycontroller.h
PRIVATE_HEADERS += \
qbluetoothaddress_p.h\
@@ -36,7 +41,12 @@ PRIVATE_HEADERS += \
qbluetoothtransferreply_p.h \
qbluetoothtransferrequest_p.h \
qprivatelinearbuffer_p.h \
- qbluetoothlocaldevice_p.h
+ qbluetoothlocaldevice_p.h \
+ qlowenergyserviceinfo_p.h \
+ qlowenergycharacteristicinfo_p.h \
+ qlowenergyprocess_p.h \
+ qlowenergydescriptorinfo_p.h \
+ qlowenergycontroller_p.h
SOURCES += \
qbluetoothaddress.cpp\
@@ -52,7 +62,11 @@ SOURCES += \
qbluetooth.cpp \
qbluetoothtransfermanager.cpp \
qbluetoothtransferrequest.cpp \
- qbluetoothtransferreply.cpp
+ qbluetoothtransferreply.cpp \
+ qlowenergyserviceinfo.cpp \
+ qlowenergycharacteristicinfo.cpp \
+ qlowenergydescriptorinfo.cpp \
+ qlowenergycontroller.cpp
config_bluez:qtHaveModule(dbus) {
QT *= dbus
@@ -70,16 +84,20 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothsocket_bluez.cpp \
qbluetoothserver_bluez.cpp \
qbluetoothlocaldevice_bluez.cpp \
- qbluetoothtransferreply_bluez.cpp
+ qbluetoothtransferreply_bluez.cpp \
+ qlowenergyprocess_bluez.cpp \
+ qlowenergyserviceinfo_bluez.cpp \
+ qlowenergycharacteristicinfo_bluez.cpp \
+ qlowenergycontroller_bluez.cpp
} else:CONFIG(blackberry) {
DEFINES += QT_QNX_BLUETOOTH
include(qnx/qnx.pri)
+ LIBS += -lbtapi
config_btapi10_2_1 {
DEFINES += QT_QNX_BT_BLUETOOTH
- LIBS += -lbtapi
}
PRIVATE_HEADERS += \
@@ -92,7 +110,10 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothservicediscoveryagent_qnx.cpp \
qbluetoothsocket_qnx.cpp \
qbluetoothserver_qnx.cpp \
- qbluetoothtransferreply_qnx.cpp
+ qbluetoothtransferreply_qnx.cpp \
+ qlowenergycharacteristicinfo_qnx.cpp \
+ qlowenergyserviceinfo_qnx.cpp \
+ qlowenergyprocess_qnx.cpp
} else:android:!android-no-sdk {
include(android/android.pri)
@@ -113,7 +134,11 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothserviceinfo_android.cpp \
qbluetoothservicediscoveryagent_android.cpp \
qbluetoothsocket_android.cpp \
- qbluetoothserver_android.cpp
+ qbluetoothserver_android.cpp \
+ qlowenergyserviceinfo_p.cpp \
+ qlowenergycharacteristicinfo_p.cpp \
+ qlowenergyprocess_p.cpp \
+ qlowenergycontroller_p.cpp
} else {
message("Unsupported bluetooth platform, will not build a working QBluetooth library")
@@ -124,12 +149,13 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothserviceinfo_p.cpp \
qbluetoothservicediscoveryagent_p.cpp \
qbluetoothsocket_p.cpp \
- qbluetoothserver_p.cpp
-
+ qbluetoothserver_p.cpp \
+ qlowenergyserviceinfo_p.cpp \
+ qlowenergycharacteristicinfo_p.cpp \
+ qlowenergyprocess_p.cpp \
+ qlowenergycontroller_p.cpp
}
OTHER_FILES +=
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
-
-
diff --git a/src/bluetooth/bluez/bluez.pri b/src/bluetooth/bluez/bluez.pri
index 5a679091..a4b597a0 100644
--- a/src/bluetooth/bluez/bluez.pri
+++ b/src/bluetooth/bluez/bluez.pri
@@ -20,7 +20,8 @@ HEADERS += bluez/manager_p.h \
bluez/obex_client_p.h \
bluez/obex_agent_p.h \
bluez/obex_transfer_p.h \
- bluez/obex_manager_p.h
+ bluez/obex_manager_p.h \
+ bluez/characteristic_p.h
SOURCES += bluez/manager.cpp \
@@ -32,4 +33,5 @@ SOURCES += bluez/manager.cpp \
bluez/obex_client.cpp \
bluez/obex_agent.cpp \
bluez/obex_transfer.cpp \
- bluez/obex_manager.cpp
+ bluez/obex_manager.cpp \
+ bluez/characteristic.cpp
diff --git a/src/bluetooth/bluez/characteristic.cpp b/src/bluetooth/bluez/characteristic.cpp
new file mode 100644
index 00000000..ed4b8485
--- /dev/null
+++ b/src/bluetooth/bluez/characteristic.cpp
@@ -0,0 +1,54 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "characteristic_p.h"
+
+/*
+ * Implementation of interface class OrgBluezCharacteristicInterface
+ */
+
+OrgBluezCharacteristicInterface::OrgBluezCharacteristicInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+OrgBluezCharacteristicInterface::~OrgBluezCharacteristicInterface()
+{
+}
diff --git a/src/bluetooth/bluez/characteristic_p.h b/src/bluetooth/bluez/characteristic_p.h
new file mode 100644
index 00000000..ef510ab2
--- /dev/null
+++ b/src/bluetooth/bluez/characteristic_p.h
@@ -0,0 +1,111 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CHARACTERISTIC_P_H
+#define CHARACTERISTIC_P_H
+
+#endif // CHARACTERISTIC_P_H
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * Proxy class for interface org.bluez.Device
+ */
+class OrgBluezCharacteristicInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "org.bluez.Characteristic"; }
+
+public:
+ OrgBluezCharacteristicInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+ ~OrgBluezCharacteristicInterface();
+
+public Q_SLOTS:
+ inline QDBusPendingReply<QVariantMap> GetProperties()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
+ }
+
+ inline QDBusPendingReply<> SetProperty(const QString &in0, const QDBusVariant &in1)
+ {
+ QList<QVariant> argumentList;
+ argumentList << qVariantFromValue(in0) << qVariantFromValue(in1);
+ return asyncCallWithArgumentList(QLatin1String("SetProperty"), argumentList);
+ }
+ inline QDBusPendingReply<QList<QDBusObjectPath> > DiscoverCharacteristics()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("DiscoverCharacteristics"), argumentList);
+ }
+
+ inline QDBusPendingReply<> RegisterCharacteristicsWatcher(const QDBusObjectPath &in0)
+ {
+ QList<QVariant> argumentList;
+ argumentList << qVariantFromValue(in0);
+ return asyncCallWithArgumentList(QLatin1String("RegisterCharacteristicsWatcher"), argumentList);
+ }
+
+ inline QDBusPendingReply<> UnregisterCharacteristicsWatcher(const QDBusObjectPath &in0)
+ {
+ QList<QVariant> argumentList;
+ argumentList << qVariantFromValue(in0);
+ return asyncCallWithArgumentList(QLatin1String("UnregisterCharacteristicsWatcher"), argumentList);
+ }
+
+Q_SIGNALS:
+ void PropertyChanged(const QString &in0, const QDBusVariant &in1);
+};
+
+namespace org {
+ namespace bluez {
+ typedef ::OrgBluezCharacteristicInterface Characteristic;
+ }
+}
diff --git a/src/bluetooth/doc/src/bluetooth-index.qdoc b/src/bluetooth/doc/src/bluetooth-index.qdoc
index cde64891..e9575db1 100644
--- a/src/bluetooth/doc/src/bluetooth-index.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-index.qdoc
@@ -70,6 +70,8 @@ import statement in your \c .qml file:
\list
\li \l {scanner}{QML Bluetooth Scanner}
\li \l {picturetransfer}{QML Bluetooth Picture Push}
+ \li \l {lowenergyscanner}{Bluetooth Low Energy Scanner}
+ \li \l {heartlistener}{Heart Listener}
\endlist
\li C++
\list
diff --git a/src/bluetooth/doc/src/bluetooth-overview.qdoc b/src/bluetooth/doc/src/bluetooth-overview.qdoc
index 2afd2bd8..bc8a9543 100644
--- a/src/bluetooth/doc/src/bluetooth-overview.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-overview.qdoc
@@ -29,7 +29,8 @@
\ingroup technology-apis
\title Qt Bluetooth Overview
\page qtbluetooth-overview.html
-\brief The Qt Bluetooth API enables connectivity with other Bluetooth enabled devices.
+\brief The Qt Bluetooth API enables connectivity with other regular Bluetooth
+ and Bluetooth Low Energy enabled devices.
\tableofcontents
@@ -41,6 +42,9 @@
\li Push files to remote devices using the OBEX Object Push Profile (OPP)
\li Connect to remote devices through a RFCOMM channel using the Serial Port Profile (SPP).
\li Create a RFCOMM server that allows incoming connections using SPP.
+ \li Retrieve specification about Bluetooth Low Energy device.
+ \li Connect to Bluetooth Low Energy device.
+ \li Receive advertisement from Bluetooth Low Energy device.
\endlist
Note that the Object Push Profile is not supported on Android.
@@ -103,4 +107,103 @@
\l QBluetoothSocket classes. A good example to start with SPP is the \l{btchat}{Bluetooth Chat}
example.
+ \section1 Bluetooth Low Energy
+
+ Bluetooth Low Energy (in later text BLE), also known as Bluetooth Smart is a wireless computer
+ network technology, which was officially introduced in 2011. It works at the same,
+ 2,4HGz frequency, as ”classic” Bluetooth. The main difference is, as stated by its technology name,
+ low energy consumption. It provides an opportunity for BLE devices to operate for months,
+ even years, on coin-cell batteries. This technology was introduced with Bluetooth v 4.0
+ and devices which support this technology are called Bluetooth Smart Ready Devices.
+ The key features of technology are:
+ \list
+ \li Ultra-low peak, average and idle mode power consumption
+ \li Ability to run for years on standard, coin-cell batteries
+ \li Low cost
+ \li Multi-vendor interoperability
+ \li Enhanced range
+ \endlist
+
+ BLE uses a client-server architecture. The server (BLE device) offers services (temperature,
+ heart rate or any other measurements) and advertises them. The client (PC, smartphone
+ or any other Bluetooth Smart Ready device) connects to the server and reads the values
+ advertised by the server. The BLE API is based on GATT (Generic Attribute Profile) concepts.
+ GATT commands are initiated by the client, as mentioned above, and the server is receiving
+ GATT commands and sends replies.
+
+ These GATT commands initiate the services, which consist of characteristics. A characteristic
+ is data that is being transferred. Each characteristic has descriptors, which give additional
+ information about the characteristic. Services, characteristics and descriptors are recognized
+ by their 128bits UUIDs.
+
+ To be able to get and read characteristics, it is required to connect to the LE device service.
+
+ \code
+ QObject::connect(m_serviceDiscoveryAgent, SIGNAL(serviceDiscovered(const QLowEnergyServiceInfo&)),
+ this, SLOT(addLowEnergyService(const QLowEnergyServiceInfo&)));
+ QObject::connect(m_serviceDiscoveryAgent, SIGNAL(finished()), this, SLOT(serviceScanDone()));
+ m_serviceDiscoveryAgent->setRemoteAddress(device.address());
+ m_serviceDiscoveryAgent->start();
+ lowEnergyController = new QLowEnergyController();
+ QObject::connect(lowEnergyController, SIGNAL(connected(QLowEnergyServiceInfo)),
+ this, SLOT(serviceConnected(QLowEnergyServiceInfo)));
+ QObject::connect(lowEnergyController, SIGNAL(error(QLowEnergyServiceInfo)),
+ this, SLOT(errorReceived(QLowEnergyServiceInfo)));
+ QObject::connect(lowEnergyController, SIGNAL(valueChanged(QLowEnergyCharacteristicInfo)),
+ this, SLOT(receiveMeasurement(QLowEnergyCharacteristicInfo)));
+ QObject::connect(lowEnergyController, SIGNAL(disconnected(QLowEnergyServiceInfo)),
+ this, SLOT(serviceDisconnected(QLowEnergyServiceInfo)));
+
+ \endcode
+
+ We start a service discovery with a \l QBluetoothServiceDiscoveryAgent class and connect its
+ signal \l serviceDiscovered(QLowEnergyServiceInfo) to our slot
+ \l addLowEnergyService(QLowEnergyServiceInfo). This way, it is possible to store all LE services
+ or connect to the desired one. \l QLowEnergyController is used for connecting to service,
+ receiving emitted errors from the service and disconnecting from the service.
+
+ Even though it is possible to connect to an LE service before the service scan is done,
+ it is advisable to do it after the service scan is done.
+
+ \code
+ void serviceScanDone()
+ {
+ lowEnergyController->connectToService(wantedLowEnergyService);
+ }
+ \endcode
+
+ Here, the \c wantedLowEnergyService can be one service or you can pick more or all services
+ to connect. Some LE devices, become available one or two seconds after service scan.
+
+ \code
+ void serviceConnected(const QLowEnergyServiceInfo &leService)
+ {
+ QList<QLowEnergyCharacteristicInfo> lowEnergyCharacteristics = leService.getCharacteristics();
+ for (int i = 0; i<lowEnergyCharacteristics.size(); i++) {
+ QLowEnergyCharacteristicInfo wantedCharacteristic =
+ QLowEnergyCharacteristicInfo(lowEnergyCharacteristics.at(i));
+ lowEnergyController->enableNotifications(wantedCharacteristic);
+ }
+ }
+ \endcode
+
+ In the code example above all characteristics will be enabled for the notifications, but not
+ all of them have that option as explained in \l QLowEnergyController documentation. It is possible
+ to select only one characteristic, for instance \l QBluetoothUuid::HeartRateMeasurement.
+
+ Finally, to receive updates, the receiveMeasurement(QLowEnergyCharacteristicInfo) slot was defined.
+
+ \code
+ void HeartRate::receiveMeasurement(const QLowEnergyCharacteristicInfo &characteristic)
+ {
+ wantedCharacteristic = QLowEnergyCharacteristicInfo(characteristic);
+ wantedCharacteristic.value();
+ }
+ \endcode
+
+ The returned value is the hexadecimal value. The procedure of reading and converting hexadecimal
+ value properly depends on the BLE devices that is sending updates since every device has a different
+ value structure.
+
+
*/
diff --git a/src/bluetooth/doc/src/examples.qdoc b/src/bluetooth/doc/src/examples.qdoc
index d6b73ae8..08759874 100644
--- a/src/bluetooth/doc/src/examples.qdoc
+++ b/src/bluetooth/doc/src/examples.qdoc
@@ -71,6 +71,13 @@
\row
\li \l{picturetransfer}{QML Picture Push Example}
\li A QML application that transfers pictures between Bluetooth devices.
+ \row
+ \li \l{lowenergyscanner}{QML Bluetooth Low Energy Scanner}
+ \li Scan for Bluetooth Low Energy devices, services and characteristics.
+ \row
+ \li \l{heartlistener}{QML Bluetooth Low Energy Heart Listener}
+ \li Connect to the Bluetooth Low Energy heart belt and receive
+ measurements.
\endtable
*/
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index 83b83fbd..f866b477 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -183,6 +183,16 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres
}
device.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete);
device.setCached(dict.value(QLatin1String("Cached")).toBool());
+
+ /*
+ * Bluez v4.1 does not have extra bit which gives information if device is Bluetooth
+ * Low Energy device and the way to discover it is with Class property of the Bluetooth device.
+ * Low Energy devices do not have property Class.
+ */
+ if (btClass == 0)
+ device.setCoreConfiguration(QBluetoothDeviceInfo::LowEnergyCoreConfiguration);
+ else
+ device.setCoreConfiguration(QBluetoothDeviceInfo::BaseRateCoreConfiguration);
for(int i = 0; i < discoveredDevices.size(); i++){
if(discoveredDevices[i].address() == device.address()) {
if(discoveredDevices[i] == device) {
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
index 390faf50..42b6ceff 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
@@ -168,11 +168,18 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
int cod = 0;
int dev_type = 0;
int rssi = 0;
-
+ bool hasGatt = false;
pps_decoder_get_bool(&ppsDecoder, "paired", &paired);
pps_decoder_get_int(&ppsDecoder, "cod", &cod);
pps_decoder_get_int(&ppsDecoder, "dev_type", &dev_type);
pps_decoder_get_int(&ppsDecoder, "rssi", &rssi);
+ pps_decoder_push(&ppsDecoder, "gatt_available_services");
+ const char *next_service = 0;
+
+ for (int service_count=0; pps_decoder_get_string(&ppsDecoder, 0, &next_service ) == PPS_DECODER_OK; service_count++) {
+ hasGatt = true;
+ //qBluetoothDebug() << next_service;
+ }
pps_decoder_cleanup(&ppsDecoder);
QBluetoothDeviceInfo deviceInfo(deviceAddr, deviceName, cod);
@@ -195,6 +202,20 @@ void QBluetoothDeviceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
m_finishedTimer.start(7000);
if (!deviceAddr.isNull()) {
qCDebug(QT_BT_QNX) << "Device discovered: " << deviceName << deviceAddr.toString();
+ /* Looking for device type. Only Low energy devices will be added
+ * BT_DEVICE_TYPE_LE_PUBLIC is 0 --->LE device
+ * BT_DEVICE_TYPE_LE_PRIVATE is 1 ---> LE device
+ * BT_DEVICE_TYPE_REGULAR is 32
+ * BT_DEVICE_TYPE_UNKNOWN is 255
+ */
+ if (dev_type == 0 || dev_type == 1)
+ deviceInfo.setCoreConfiguration(QBluetoothDeviceInfo::LowEnergyCoreConfiguration);
+ else{
+ if (hasGatt)
+ deviceInfo.setCoreConfiguration(QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration);
+ else
+ deviceInfo.setCoreConfiguration(QBluetoothDeviceInfo::BaseRateCoreConfiguration);
+ }
discoveredDevices.append(deviceInfo);
if (!updated)//We are not allowed to emit a signal with the updated version
emit q_ptr->deviceDiscovered(discoveredDevices.last());
diff --git a/src/bluetooth/qbluetoothdeviceinfo.cpp b/src/bluetooth/qbluetoothdeviceinfo.cpp
index f10ec133..58d45e3b 100644
--- a/src/bluetooth/qbluetoothdeviceinfo.cpp
+++ b/src/bluetooth/qbluetoothdeviceinfo.cpp
@@ -247,12 +247,24 @@ QT_BEGIN_NAMESPACE
\value DataUnavailable No data is available.
*/
+/*!
+ \enum QBluetoothDeviceInfo::CoreConfiguration
+
+ This enum describes the configuration of the device.
+
+ \value BaseRateCoreConfiguration The device is a standard Bluetooth device.
+ \value BaseRateAndLowEnergyConfiguration The device is a Bluetooth Smart device with support
+ for standard and Low Energy device.
+ \value LowEnergyCoreCOnfiguration The device is a Bluetooth Low Energy device.
+*/
+
QBluetoothDeviceInfoPrivate::QBluetoothDeviceInfoPrivate()
: valid(false), cached(false), rssi(1),
serviceClasses(QBluetoothDeviceInfo::NoService),
majorDeviceClass(QBluetoothDeviceInfo::MiscellaneousDevice),
minorDeviceClass(0),
- serviceUuidsCompleteness(QBluetoothDeviceInfo::DataUnavailable)
+ serviceUuidsCompleteness(QBluetoothDeviceInfo::DataUnavailable),
+ deviceCoreConfiguration(QBluetoothDeviceInfo::BaseRateCoreConfiguration)
{
}
@@ -359,6 +371,7 @@ QBluetoothDeviceInfo &QBluetoothDeviceInfo::operator=(const QBluetoothDeviceInfo
d->serviceUuidsCompleteness = other.d_func()->serviceUuidsCompleteness;
d->serviceUuids = other.d_func()->serviceUuids;
d->rssi = other.d_func()->rssi;
+ d->deviceCoreConfiguration = other.d_func()->deviceCoreConfiguration;
return *this;
}
@@ -370,25 +383,27 @@ bool QBluetoothDeviceInfo::operator==(const QBluetoothDeviceInfo &other) const
{
Q_D(const QBluetoothDeviceInfo);
- if(d->cached != other.d_func()->cached)
+ if (d->cached != other.d_func()->cached)
return false;
- if(d->valid != other.d_func()->valid)
+ if (d->valid != other.d_func()->valid)
return false;
- if(d->majorDeviceClass != other.d_func()->majorDeviceClass)
+ if (d->majorDeviceClass != other.d_func()->majorDeviceClass)
return false;
- if(d->minorDeviceClass != other.d_func()->minorDeviceClass)
+ if (d->minorDeviceClass != other.d_func()->minorDeviceClass)
return false;
- if(d->serviceClasses != other.d_func()->serviceClasses)
+ if (d->serviceClasses != other.d_func()->serviceClasses)
return false;
- if(d->name != other.d_func()->name)
+ if (d->name != other.d_func()->name)
return false;
- if(d->address != other.d_func()->address)
+ if (d->address != other.d_func()->address)
return false;
- if(d->serviceUuidsCompleteness != other.d_func()->serviceUuidsCompleteness)
+ if (d->serviceUuidsCompleteness != other.d_func()->serviceUuidsCompleteness)
return false;
- if(d->serviceUuids.count() != other.d_func()->serviceUuids.count())
+ if (d->serviceUuids.count() != other.d_func()->serviceUuids.count())
return false;
- if(d->serviceUuids != other.d_func()->serviceUuids)
+ if (d->serviceUuids != other.d_func()->serviceUuids)
+ return false;
+ if (d->deviceCoreConfiguration != other.d_func()->deviceCoreConfiguration)
return false;
return true;
@@ -498,6 +513,29 @@ QBluetoothDeviceInfo::DataCompleteness QBluetoothDeviceInfo::serviceUuidsComplet
}
/*!
+ Sets the CoreConfiguration of the device to a \a coreConfig. This will help to make a difference
+ between regular and Low Energy devices.
+*/
+void QBluetoothDeviceInfo::setCoreConfiguration(const CoreConfiguration &coreConfig)
+{
+ Q_D(QBluetoothDeviceInfo);
+
+ d->deviceCoreConfiguration = coreConfig;
+}
+
+/*!
+ Returns the configuration of the device. If device configuration is not set,
+ basic rate device configuration will be returned.
+ \sa setCoreConfiguration
+*/
+QBluetoothDeviceInfo::CoreConfiguration QBluetoothDeviceInfo::coreConfiguration() const
+{
+ Q_D(const QBluetoothDeviceInfo);
+
+ return d->deviceCoreConfiguration;
+}
+
+/*!
Returns true if the QBluetoothDeviceInfo object is created from cached data.
*/
bool QBluetoothDeviceInfo::isCached() const
diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h
index be605f8d..a9aad493 100644
--- a/src/bluetooth/qbluetoothdeviceinfo.h
+++ b/src/bluetooth/qbluetoothdeviceinfo.h
@@ -196,6 +196,13 @@ public:
DataUnavailable
};
+ enum CoreConfiguration {
+ LowEnergyCoreConfiguration = 0x01,
+ BaseRateCoreConfiguration = 0x02,
+ BaseRateAndLowEnergyCoreConfiguration = 0x03
+ };
+ Q_DECLARE_FLAGS(CoreConfigurations, CoreConfiguration)
+
QBluetoothDeviceInfo();
QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, quint32 classOfDevice);
QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other);
@@ -223,6 +230,8 @@ public:
void setServiceUuids(const QList<QBluetoothUuid> &uuids, DataCompleteness completeness);
QList<QBluetoothUuid> serviceUuids(DataCompleteness *completeness = 0) const;
DataCompleteness serviceUuidsCompleteness() const;
+ void setCoreConfiguration(const CoreConfiguration &coreConfig);
+ CoreConfiguration coreConfiguration() const;
protected:
QBluetoothDeviceInfoPrivate *d_ptr;
diff --git a/src/bluetooth/qbluetoothdeviceinfo_p.h b/src/bluetooth/qbluetoothdeviceinfo_p.h
index b08a8fec..d6c63a24 100644
--- a/src/bluetooth/qbluetoothdeviceinfo_p.h
+++ b/src/bluetooth/qbluetoothdeviceinfo_p.h
@@ -69,6 +69,7 @@ public:
QBluetoothDeviceInfo::DataCompleteness serviceUuidsCompleteness;
QList<QBluetoothUuid> serviceUuids;
+ QBluetoothDeviceInfo::CoreConfiguration deviceCoreConfiguration;
};
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 7e0e701d..615d0f4a 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -246,7 +246,6 @@ bool QBluetoothServiceDiscoveryAgent::setRemoteAddress(const QBluetoothAddress &
if (!address.isNull())
d_ptr->singleDevice = true;
d_ptr->deviceAddress = address;
-
return true;
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h
index 59c7b74b..90482048 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.h
@@ -49,6 +49,7 @@
#include <QtBluetooth/QBluetoothServiceInfo>
#include <QtBluetooth/QBluetoothUuid>
#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
+#include <QtBluetooth/QLowEnergyServiceInfo>
QT_BEGIN_NAMESPACE
@@ -100,6 +101,7 @@ public Q_SLOTS:
Q_SIGNALS:
void serviceDiscovered(const QBluetoothServiceInfo &info);
+ void serviceDiscovered(const QLowEnergyServiceInfo &info);
void finished();
void canceled();
void error(QBluetoothServiceDiscoveryAgent::Error error);
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index 0e782d5c..c7fc47fb 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -41,13 +41,17 @@
#include "qbluetoothservicediscoveryagent.h"
#include "qbluetoothservicediscoveryagent_p.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include "qlowenergyserviceinfo_p.h"
#include "bluez/manager_p.h"
#include "bluez/adapter_p.h"
#include "bluez/device_p.h"
+#include "bluez/characteristic_p.h"
#include <QtCore/QLoggingCategory>
#include <QtDBus/QDBusPendingCallWatcher>
+#include <QtCore/QUuid>
QT_BEGIN_NAMESPACE
@@ -96,6 +100,15 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
adapter = new OrgBluezAdapterInterface(QLatin1String("org.bluez"), reply.value().path(),
QDBusConnection::systemBus());
+ if (m_deviceAdapterAddress.isNull()) {
+ QDBusPendingReply<QVariantMap> reply = adapter->GetProperties();
+ reply.waitForFinished();
+ if (!reply.isError()) {
+ const QBluetoothAddress path_address(reply.value().value(QStringLiteral("Address")).toString());
+ m_deviceAdapterAddress = path_address;
+ }
+ }
+
QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter->CreateDevice(address.toString());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(deviceObjectPath, q);
@@ -173,17 +186,74 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
delete adapter;
adapter = 0;
- QString pattern;
- foreach (const QBluetoothUuid &uuid, uuidFilter)
- pattern += uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}')) + QLatin1Char(' ');
+ QVariantMap deviceProperties;
+ QString classType;
+ QDBusPendingReply<QVariantMap> deviceReply = device->GetProperties();
+ deviceReply.waitForFinished();
+ if (!deviceReply.isError()) {
+ deviceProperties = deviceReply.value();
+ classType = deviceProperties.value(QStringLiteral("Class")).toString();
+ }
- pattern = pattern.trimmed();
- qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Discover restrictions:" << pattern;
+ /*
+ * Low Energy services in bluez are represented as the list of the paths that can be
+ * accessed with org.bluez.Characteristic
+ */
+ //QDBusArgument services = v.value(QLatin1String("Services")).value<QDBusArgument>();
+
+
+ /*
+ * Bluez v4.1 does not have extra bit which gives information if device is Bluetooth
+ * Low Energy device and the way to discover it is with Class property of the Bluetooth device.
+ * Low Energy devices do not have property Class.
+ * In case we have LE device finish service discovery; otherwise search for regular services.
+ */
+ if (classType.isEmpty()) { //is BLE device or device properties above not retrievable
+ qCDebug(QT_BT_BLUEZ) << "Discovered BLE-only device. Normal service discovery skipped.";
+ delete device;
+ device = 0;
- QDBusPendingReply<ServiceMap> discoverReply = device->DiscoverServices(pattern);
- watcher = new QDBusPendingCallWatcher(discoverReply, q);
- QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
- q, SLOT(_q_discoveredServices(QDBusPendingCallWatcher*)));
+ const QStringList deviceUuids = deviceProperties.value(QStringLiteral("UUIDs")).toStringList();
+ for (int i = 0; i < deviceUuids.size(); i++) {
+ QString b = deviceUuids.at(i);
+ b = b.remove(QLatin1Char('{')).remove(QLatin1Char('}'));
+ const QBluetoothUuid uuid(b);
+
+ qCDebug(QT_BT_BLUEZ) << "Discovered BLE service" << uuid << uuidFilter.size();
+ QLowEnergyServiceInfo lowEnergyService(uuid);
+ lowEnergyService.d_ptr->adapterAddress = m_deviceAdapterAddress;
+ lowEnergyService.setDevice(discoveredDevices.at(0));
+ if (uuidFilter.isEmpty())
+ emit q->serviceDiscovered(lowEnergyService);
+ else {
+ for (int j = 0; j < uuidFilter.size(); j++) {
+ if (uuidFilter.at(j) == uuid)
+ emit q->serviceDiscovered(lowEnergyService);
+
+ }
+ }
+
+ }
+
+ if (singleDevice && deviceReply.isError()) {
+ error = QBluetoothServiceDiscoveryAgent::InputOutputError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Unable to access device");
+ emit q->error(error);
+ }
+ _q_serviceDiscoveryFinished();
+ } else {
+ QString pattern;
+ foreach (const QBluetoothUuid &uuid, uuidFilter)
+ pattern += uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}')) + QLatin1Char(' ');
+
+ pattern = pattern.trimmed();
+ qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Discover restrictions:" << pattern;
+
+ QDBusPendingReply<ServiceMap> discoverReply = device->DiscoverServices(pattern);
+ watcher = new QDBusPendingCallWatcher(discoverReply, q);
+ QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ q, SLOT(_q_discoveredServices(QDBusPendingCallWatcher*)));
+ }
}
void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingCallWatcher *watcher)
@@ -213,36 +283,50 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
qCDebug(QT_BT_BLUEZ) << "Parsing xml" << discoveredDevices.at(0).address().toString() << discoveredDevices.count() << map.count();
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
foreach (const QString &record, reply.value()) {
QXmlStreamReader xml(record);
QBluetoothServiceInfo serviceInfo;
- serviceInfo.setDevice(discoveredDevices.at(0));
+ bool btle = false; // Detecting potential BTLE services
while (!xml.atEnd()) {
xml.readNext();
- if (xml.tokenType() == QXmlStreamReader::StartElement &&
- xml.name() == QLatin1String("attribute")) {
- quint16 attributeId =
- xml.attributes().value(QLatin1String("id")).toString().toUShort(0, 0);
+ if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == QStringLiteral("attribute")) {
+ quint16 attributeId = xml.attributes().value(QStringLiteral("id")).toString().toUShort(0, 0);
if (xml.readNextStartElement()) {
QVariant value = readAttributeValue(xml);
-
+ if (attributeId == 1) {// Attribute with id 1 contains UUID of the service
+ const QBluetoothServiceInfo::Sequence seq = value.value<QBluetoothServiceInfo::Sequence>();
+ for (int i = 0; i < seq.count(); i++) {
+ const QBluetoothUuid uuid = seq.at(i).value<QBluetoothUuid>();
+ if ((uuid.data1 & 0x1800) == 0x1800) {// We are taking into consideration that LE services starts at 0x1800
+ QLowEnergyServiceInfo leService(uuid);
+ leService.setDevice(discoveredDevices.at(0));
+ btle = true;
+ emit q->serviceDiscovered(leService);
+ break;
+ }
+ }
+ }
serviceInfo.setAttribute(attributeId, value);
}
}
}
- if (!serviceInfo.isValid())
- continue;
+ if (!btle) {
+ serviceInfo.setDevice(discoveredDevices.at(0));
+ if (!serviceInfo.isValid())
+ continue;
- Q_Q(QBluetoothServiceDiscoveryAgent);
+ discoveredServices.append(serviceInfo);
+ qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString();
+ emit q->serviceDiscovered(serviceInfo);
+ }
- discoveredServices.append(serviceInfo);
- qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString();
- emit q->serviceDiscovered(serviceInfo);
// could stop discovery, check for state
if(discoveryState() == Inactive){
qCDebug(QT_BT_BLUEZ) << "Exit discovery after stop";
@@ -257,6 +341,130 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
_q_serviceDiscoveryFinished();
}
+/*
+ * Following three methods are implemented in this way to avoid blocking the main thread.
+ * We first go through list of services path and then through services characteristics paths.
+ *
+ * Bluez v4.x does not have support for LE devices through org.bluez interfaces. Because of that
+ * these functions will not be used now. I propose to leave them commented because in Bluez v5.x
+ * we have support for LE devices and we can use these functions.
+ */
+/*
+void QBluetoothServiceDiscoveryAgentPrivate::_g_discoveredGattService()
+{
+
+ if (!gattServices.empty()) {
+ qDebug() << gattServices.at(0) << gattServices.size();
+ gattService = QLowEnergyServiceInfo(gattServices.at(0));
+ gattService.getProperties();
+ QObject::connect(gattService.d_ptr.data(), SIGNAL(finished()), this, SLOT(_g_discoveredGattService()));
+ characteristic = new OrgBluezCharacteristicInterface(QLatin1String("org.bluez"), gattServices.at(0), QDBusConnection::systemBus());
+ QDBusPendingReply<QList<QDBusObjectPath> > characterictisReply = characteristic->DiscoverCharacteristics();
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(characterictisReply, this);
+ QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ this, SLOT(_q_discoverGattCharacteristics(QDBusPendingCallWatcher*)));
+
+ gattServices.removeFirst();
+ q_ptr->lowEnergyServiceDiscovered(gattService);
+ emit gattService.d_ptr->finished();
+ }
+ else
+ q_ptr->finished();
+
+}
+
+void QBluetoothServiceDiscoveryAgentPrivate::_q_discoverGattCharacteristics(QDBusPendingCallWatcher *watcher)
+{
+
+ QDBusPendingReply<QList<QDBusObjectPath> > characterictisReply = *watcher;
+ if (characterictisReply.isError()){
+ qDebug()<< "Discovering service characteristic error" << characterictisReply.error().message();
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+ error = QBluetoothServiceDiscoveryAgent::UnknownError;
+ errorString = characterictisReply.error().message();
+ emit q->error(error);
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
+ foreach (const QDBusObjectPath &characteristicPath, characterictisReply.value())
+ gattCharacteristics.append(characteristicPath.path());
+ characteristic = new OrgBluezCharacteristicInterface(QLatin1String("org.bluez"), gattCharacteristics.at(0), QDBusConnection::systemBus());
+ QDBusPendingReply<QVariantMap> characteristicProperty = characteristic->GetProperties();
+ watcher = new QDBusPendingCallWatcher(characteristicProperty, this);
+ _q_discoveredGattCharacteristic(watcher);
+
+}
+
+void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredGattCharacteristic(QDBusPendingCallWatcher *watcher)
+{
+
+ QDBusPendingReply<QVariantMap> characteristicProperty = *watcher;
+ //qDebug()<<characteristicProperty.value();
+ if (characteristicProperty.isError()){
+ qDebug() << "Characteristic properties error" << characteristicProperty.error().message();
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+ error = QBluetoothServiceDiscoveryAgent::UnknownError;
+ errorString = characteristicProperty.error().message();
+ emit q->error(error);
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+ QStringList serviceName;
+
+ if (characteristicProperty.isError())
+ qDebug()<<characteristicProperty.error().message();
+
+ QVariantMap properties = characteristicProperty.value();
+ QString name = properties.value(QLatin1String("Name")).toString();
+ QString description = properties.value(QLatin1String("Description")).toString();
+ serviceName = description.split(QStringLiteral(" "));
+ QString charUuid = properties.value(QLatin1String("UUID")).toString();
+ QBluetoothUuid characteristicUuid(charUuid);
+
+ QVariant value = properties.value(QLatin1String("Value"));
+ QByteArray byteValue = QByteArray();
+ if (value.type() == QVariant::ByteArray)
+ byteValue = value.toByteArray();
+
+ //qDebug() << name << description << characteristicUuid.toString()<< byteValue.size();
+ gattCharacteristic = QLowEnergyCharacteristicInfo(name, description, characteristicUuid, byteValue);
+ gattCharacteristic.setPath(gattCharacteristics.at(0));
+ qDebug() << gattCharacteristics.at(0);
+ gattService.addCharacteristic(gattCharacteristic);
+
+
+ //Testing part for setting the property
+ QString b = "f000aa02-0451-4000-b000-000000000000";
+ QBluetoothUuid u(b);
+ if (gattCharacteristic.uuid() == u){
+ for (int j = 0; j< byteValue.size(); j++){
+ qDebug() << (int) byteValue.at(j);
+ byteValue[j]=1;
+ qDebug() << (int) byteValue.at(j);
+ }
+ bool s = gattCharacteristic.setPropertyValue(QStringLiteral("Value"), byteValue);
+ qDebug() <<s;
+ }
+
+ QString serName = serviceName.at(0) + " Service";
+
+ gattCharacteristics.removeFirst();
+ if (gattCharacteristics.isEmpty()){
+ q_ptr->lowEnergyServiceDiscovered(gattService);
+ emit gattService.d_ptr->finished();
+ }
+ else{
+ OrgBluezCharacteristicInterface *characteristicProperties = new OrgBluezCharacteristicInterface(QLatin1String("org.bluez"), gattCharacteristics.at(0), QDBusConnection::systemBus());
+ QDBusPendingReply<QVariantMap> characteristicProperty = characteristicProperties->GetProperties();
+ watcher = new QDBusPendingCallWatcher(characteristicProperty, this);
+ QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ this, SLOT(_q_discoveredGattCharacteristic(QDBusPendingCallWatcher*)));
+ }
+
+}
+*/
+
QVariant QBluetoothServiceDiscoveryAgentPrivate::readAttributeValue(QXmlStreamReader &xml)
{
if (xml.name() == QLatin1String("boolean")) {
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_p.h b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
index bfd6d954..65082558 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
@@ -46,13 +46,16 @@
#include "qbluetoothdeviceinfo.h"
#include "qbluetoothserviceinfo.h"
#include "qbluetoothservicediscoveryagent.h"
+#include "qlowenergyserviceinfo.h"
#include <QStack>
+#include <QStringList>
#ifdef QT_BLUEZ_BLUETOOTH
class OrgBluezManagerInterface;
class OrgBluezAdapterInterface;
class OrgBluezDeviceInterface;
+class OrgBluezCharacteristicInterface;
QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher;
class QXmlStreamReader;
@@ -108,7 +111,6 @@ public:
void setDiscoveryMode(QBluetoothServiceDiscoveryAgent::DiscoveryMode m) { mode = m; }
QBluetoothServiceDiscoveryAgent::DiscoveryMode DiscoveryMode() { return mode; }
- // private slots
void _q_deviceDiscoveryFinished();
void _q_deviceDiscovered(const QBluetoothDeviceInfo &info);
void _q_serviceDiscoveryFinished();
@@ -116,6 +118,12 @@ public:
#ifdef QT_BLUEZ_BLUETOOTH
void _q_discoveredServices(QDBusPendingCallWatcher *watcher);
void _q_createdDevice(QDBusPendingCallWatcher *watcher);
+ //Slots below are used for discovering Bluetooth Low Energy devices. It will be used with Bluez 5.x version.
+ /*
+ void _g_discoveredGattService();
+ void _q_discoverGattCharacteristics(QDBusPendingCallWatcher *watcher);
+ void _q_discoveredGattCharacteristic(QDBusPendingCallWatcher *watcher);
+ */
#endif
#ifdef QT_ANDROID_BLUETOOTH
void _q_processFetchedUuids(const QBluetoothAddress &address, const QList<QBluetoothUuid> &uuids);
@@ -149,6 +157,7 @@ private:
QSocketNotifier *rdNotifier;
QTimer m_queryTimer;
bool m_btInitialized;
+ bool m_serviceScanDone;
#endif
public:
@@ -168,11 +177,15 @@ private:
QBluetoothServiceDiscoveryAgent::DiscoveryMode mode;
bool singleDevice;
-
#ifdef QT_BLUEZ_BLUETOOTH
OrgBluezManagerInterface *manager;
OrgBluezAdapterInterface *adapter;
OrgBluezDeviceInterface *device;
+ // variables below are used for discovering Bluetooth Low Energy devices
+ OrgBluezCharacteristicInterface *characteristic;
+ QStringList gattServices;
+ QStringList gattCharacteristics;
+ QLowEnergyCharacteristicInfo gattCharacteristic;
#endif
#ifdef QT_ANDROID_BLUETOOTH
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
index 59551451..37fabfab 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
@@ -45,16 +45,22 @@
#include "qbluetoothdeviceinfo.h"
#include "qbluetoothdevicediscoveryagent.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include "qlowenergyserviceinfo_p.h"
+
#include <QStringList>
#include "qbluetoothuuid.h"
-
+#include <stdio.h>
+#include <unistd.h>
#include <sys/pps.h>
#ifdef QT_QNX_BT_BLUETOOTH
#include <errno.h>
#include <QPointer>
#endif
-
#include <QFile>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <QtCore/private/qcore_unix_p.h>
@@ -196,33 +202,45 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
#else
qCDebug(QT_BT_QNX) << "Starting Service discovery for" << address.toString();
const QString filePath = QStringLiteral("/pps/services/bluetooth/remote_devices/").append(address.toString());
+ bool hasError = false;
if ((m_rdfd = qt_safe_open(filePath.toLocal8Bit().constData(), O_RDONLY)) == -1) {
if (QFile::exists(filePath + QLatin1String("-00")) ||
- QFile::exists(filePath + QLatin1String("-01"))) {
- qCDebug(QT_BT_QNX) << "LE device discovered...skipping";
+ QFile::exists(filePath + QLatin1String("-01")))
+ {
+ qCDebug(QT_BT_QNX) << "LE device discovered...";
+ QString lePath = filePath + QStringLiteral("-00");
+ if ((m_rdfd = qt_safe_open(lePath.toLocal8Bit().constData(), O_RDONLY)) == -1) {
+ lePath = filePath + QStringLiteral("-01");
+ if ((m_rdfd = qt_safe_open(lePath.toLocal8Bit().constData(), O_RDONLY)) == -1)
+ hasError = true;
+ }
} else {
- qCWarning(QT_BT_QNX) << "Failed to open " << filePath;
- error = QBluetoothServiceDiscoveryAgent::InputOutputError;
- errorString = QBluetoothServiceDiscoveryAgent::tr("Failed to open remote device file");
- q->error(error);
+ hasError = true;
}
+ }
+ if (hasError) {
+ qCWarning(QT_BT_QNX) << "Failed to open " << filePath;
+ error = QBluetoothServiceDiscoveryAgent::InputOutputError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Failed to open remote device file");
+ q->error(error);
_q_serviceDiscoveryFinished();
return;
+ }
+
+ if (rdNotifier)
+ delete rdNotifier;
+ rdNotifier = new QSocketNotifier(m_rdfd, QSocketNotifier::Read, this);
+ if (rdNotifier) {
+ connect(rdNotifier, SIGNAL(activated(int)), this, SLOT(remoteDevicesChanged(int)));
} else {
- if (rdNotifier)
- delete rdNotifier;
- rdNotifier = new QSocketNotifier(m_rdfd, QSocketNotifier::Read, this);
- if (rdNotifier) {
- connect(rdNotifier, SIGNAL(activated(int)), this, SLOT(remoteDevicesChanged(int)));
- } else {
- qCWarning(QT_BT_QNX) << "Service Discovery: Failed to connect to rdNotifier";
- error = QBluetoothServiceDiscoveryAgent::InputOutputError;
- errorString = QBluetoothServiceDiscoveryAgent::tr("Failed to connect to notifier");
- q->error(error);
- _q_serviceDiscoveryFinished();
- return;
- }
+ qWarning() << "Service Discovery: Failed to connect to rdNotifier";
+ error = QBluetoothServiceDiscoveryAgent::InputOutputError;
+ errorString = QStringLiteral("Failed to connect to rdNotifier");
+ q->error(error);
+ _q_serviceDiscoveryFinished();
+ return;
}
+
m_queryTimer.start(10000);
ppsSendControlMessage("service_query", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()), this);
#endif
@@ -258,14 +276,14 @@ void QBluetoothServiceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
pps_decoder_cleanup(&ppsDecoder);
return;
}
-
+ // Checking for standard Bluetooth services
pps_decoder_push(&ppsDecoder, "available_services");
-
+ bool standardService = false;
const char *next_service = 0;
for (int service_count=0; pps_decoder_get_string(&ppsDecoder, 0, &next_service ) == PPS_DECODER_OK; service_count++) {
if (next_service == 0)
break;
-
+ standardService = true;
qCDebug(QT_BT_QNX) << Q_FUNC_INFO << "Service" << next_service;
QBluetoothServiceInfo serviceInfo;
@@ -325,7 +343,38 @@ void QBluetoothServiceDiscoveryAgentPrivate::remoteDevicesChanged(int fd)
}
}
+ if (standardService) // we need to pop back for the LE service scan
+ pps_decoder_pop(&ppsDecoder);
+ //Checking for Bluetooth Low Energy services
+ pps_decoder_push(&ppsDecoder, "gatt_available_services");
+
+ for (int service_count=0; pps_decoder_get_string(&ppsDecoder, 0, &next_service ) == PPS_DECODER_OK; service_count++) {
+ if (next_service == 0)
+ break;
+
+ QString lowEnergyUuid(next_service);
+ qCDebug(QT_BT_QNX) << "LE Service: " << lowEnergyUuid << next_service;
+ QBluetoothUuid leUuid;
+
+ //In case of custom UUIDs (e.g. Texas Instruments SenstorTag LE Device)
+ if ( lowEnergyUuid.length() > 4 ) {
+ leUuid = QBluetoothUuid(lowEnergyUuid);
+ }
+ else {// Official UUIDs are presented in 4 characters (for instance 180A)
+ lowEnergyUuid = QStringLiteral("0x") + lowEnergyUuid;
+ leUuid = QBluetoothUuid(lowEnergyUuid.toUShort(0,0));
+ }
+
+ QLowEnergyServiceInfo lowEnergyService(leUuid);
+ lowEnergyService.setDevice(discoveredDevices.at(0));
+ qCDebug(QT_BT_QNX) << "Adding Low Energy service" << lowEnergyService.serviceUuid();
+ q_ptr->serviceDiscovered(lowEnergyService);
+ }
+
pps_decoder_cleanup(&ppsDecoder);
+ //Deleting notifier since services will not change.
+ delete rdNotifier;
+ rdNotifier = 0;
}
void QBluetoothServiceDiscoveryAgentPrivate::controlReply(ppsResult result)
@@ -338,6 +387,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::controlReply(ppsResult result)
if (!result.errorMsg.isEmpty()) {
qCWarning(QT_BT_QNX) << Q_FUNC_INFO << result.errorMsg;
errorString = result.errorMsg;
+ if (errorString == QObject::tr("Operation canceled"))
+ _q_serviceDiscoveryFinished();
error = QBluetoothServiceDiscoveryAgent::InputOutputError;
q->error(error);
} else {
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp
index 85d48d49..92b20f2a 100644
--- a/src/bluetooth/qbluetoothuuid.cpp
+++ b/src/bluetooth/qbluetoothuuid.cpp
@@ -107,73 +107,293 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
The list below explicitly states as what type each UUID shall be used.
- \value ServiceDiscoveryServer Service discovery server UUID (service)
- \value BrowseGroupDescriptor Browser group descriptor (service)
- \value PublicBrowseGroup Public browse group service class. Services which have the public
- browse group in their \l {QBluetoothServiceInfo::BrowseGroupList}{browse group list}
- are discoverable by the remote devices.
- \value SerialPort Serial Port Profile UUID (service & profile)
- \value LANAccessUsingPPP LAN Access Profile UUID (service & profile)
- \value DialupNetworking Dial-up Networking Profile UUID (service & profile)
- \value IrMCSync Synchronization Profile UUID (service & profile)
- \value ObexObjectPush OBEX object push service UUID (service & profile)
- \value OBEXFileTransfer File Transfer Profile (FTP) UUID (service & profile)
- \value IrMCSyncCommand Synchronization Profile UUID (profile)
- \value Headset Headset Profile (HSP) UUID (service & profile)
- \value AudioSource Advanced Audio Distribution Profile (A2DP) UUID (service)
- \value AudioSink Advanced Audio Distribution Profile (A2DP) UUID (service)
- \value AV_RemoteControlTarget Audio/Video Remote Control Profile (AVRCP) UUID (service)
- \value AdvancedAudioDistribution Advanced Audio Distribution Profile (A2DP) UUID (profile)
- \value AV_RemoteControl Audio/Video Remote Control Profile (AVRCP) UUID (service & profile)
+ \value ServiceDiscoveryServer Service discovery server UUID (service)
+ \value BrowseGroupDescriptor Browser group descriptor (service)
+ \value PublicBrowseGroup Public browse group service class. Services which have the public
+ browse group in their \l {QBluetoothServiceInfo::BrowseGroupList}{browse group list}
+ are discoverable by the remote devices.
+ \value SerialPort Serial Port Profile UUID (service & profile)
+ \value LANAccessUsingPPP LAN Access Profile UUID (service & profile)
+ \value DialupNetworking Dial-up Networking Profile UUID (service & profile)
+ \value IrMCSync Synchronization Profile UUID (service & profile)
+ \value ObexObjectPush OBEX object push service UUID (service & profile)
+ \value OBEXFileTransfer File Transfer Profile (FTP) UUID (service & profile)
+ \value IrMCSyncCommand Synchronization Profile UUID (profile)
+ \value Headset Headset Profile (HSP) UUID (service & profile)
+ \value AudioSource Advanced Audio Distribution Profile (A2DP) UUID (service)
+ \value AudioSink Advanced Audio Distribution Profile (A2DP) UUID (service)
+ \value AV_RemoteControlTarget Audio/Video Remote Control Profile (AVRCP) UUID (service)
+ \value AdvancedAudioDistribution Advanced Audio Distribution Profile (A2DP) UUID (profile)
+ \value AV_RemoteControl Audio/Video Remote Control Profile (AVRCP) UUID (service & profile)
\value AV_RemoteControlController Audio/Video Remote Control Profile UUID (service)
- \value HeadsetAG Headset Profile (HSP) UUID (service)
- \value PANU Personal Area Networking Profile (PAN) UUID (service & profile)
- \value NAP Personal Area Networking Profile (PAN) UUID (service & profile)
- \value GN Personal Area Networking Profile (PAN) UUID (service & profile)
- \value DirectPrinting Basic Printing Profile (BPP) UUID (service)
- \value ReferencePrinting Related to Basic Printing Profile (BPP) UUID (service)
- \value BasicImage Basic Imaging Profile (BIP) UUID (profile)
- \value ImagingResponder Basic Imaging Profile (BIP) UUID (service)
+ \value HeadsetAG Headset Profile (HSP) UUID (service)
+ \value PANU Personal Area Networking Profile (PAN) UUID (service & profile)
+ \value NAP Personal Area Networking Profile (PAN) UUID (service & profile)
+ \value GN Personal Area Networking Profile (PAN) UUID (service & profile)
+ \value DirectPrinting Basic Printing Profile (BPP) UUID (service)
+ \value ReferencePrinting Related to Basic Printing Profile (BPP) UUID (service)
+ \value BasicImage Basic Imaging Profile (BIP) UUID (profile)
+ \value ImagingResponder Basic Imaging Profile (BIP) UUID (service)
\value ImagingAutomaticArchive Basic Imaging Profile (BIP) UUID (service)
\value ImagingReferenceObjects Basic Imaging Profile (BIP) UUID (service)
- \value Handsfree Hands-Free Profile (HFP) UUID (service & profile)
- \value HandsfreeAudioGateway Hands-Free Audio Gateway (HFP) UUID (service)
+ \value Handsfree Hands-Free Profile (HFP) UUID (service & profile)
+ \value HandsfreeAudioGateway Hands-Free Audio Gateway (HFP) UUID (service)
\value DirectPrintingReferenceObjectsService Basic Printing Profile (BPP) UUID (service)
- \value ReflectedUI Basic Printing Profile (BPP) UUID (service)
- \value BasicPrinting Basic Printing Profile (BPP) UUID (profile)
- \value PrintingStatus Basic Printing Profile (BPP) UUID (service)
+ \value ReflectedUI Basic Printing Profile (BPP) UUID (service)
+ \value BasicPrinting Basic Printing Profile (BPP) UUID (profile)
+ \value PrintingStatus Basic Printing Profile (BPP) UUID (service)
\value HumanInterfaceDeviceService Human Interface Device (HID) UUID (service & profile)
\value HardcopyCableReplacement Hardcopy Cable Replacement Profile (HCRP) (profile)
- \value HCRPrint Hardcopy Cable Replacement Profile (HCRP) (service)
- \value HCRScan Hardcopy Cable Replacement Profile (HCRP) (service)
- \value SIMAccess SIM Access Profile (SAP) UUID (service and profile)
- \value PhonebookAccessPCE Phonebook Access Profile (PBAP) UUID (service)
- \value PhonebookAccessPSE Phonebook Access Profile (PBAP) UUID (service)
- \value PhonebookAccess Phonebook Access Profile (PBAP) (profile)
- \value HeadsetHS Headset Profile (HSP) UUID (service)
- \value MessageAccessServer Message Access Profile (MAP) UUID (service)
- \value MessageNotificationServer Message Access Profile (MAP) UUID (service)
- \value MessageAccessProfile Message Access Profile (MAP) UUID (profile)
- \value GNSS Global Navigation Satellite System UUID (profile)
- \value GNSSServer Global Navigation Satellite System Server (UUID) (service)
- \value Display3D 3D Synchronization Display UUID (service)
- \value Glasses3D 3D Synchronization Glasses UUID (service)
- \value Synchronization3D 3D Synchronization UUID (profile)
- \value MPSProfile Multi-Profile Specification UUID (profile)
- \value MPSService Multi-Profile Specification UUID (service)
- \value PnPInformation Device Identification (DID) UUID (service & profile)
- \value GenericNetworking Generic networking UUID (service)
- \value GenericFileTransfer Generic file transfer UUID (service)
- \value GenericAudio Generic audio UUID (service)
- \value GenericTelephony Generic telephone UUID (service)
- \value VideoSource Video Distribution Profile (VDP) UUID (service)
- \value VideoSink Video Distribution Profile (VDP) UUID (service)
- \value VideoDistribution Video Distribution Profile (VDP) UUID (profile)
- \value HDP Health Device Profile (HDP) UUID (profile)
- \value HDPSource Health Device Profile Source (HDP) UUID (service)
- \value HDPSink Health Device Profile Sink (HDP) UUID (service)
-
- \sa QBluetoothServiceInfo::ServiceClassIds
+ \value HCRPrint Hardcopy Cable Replacement Profile (HCRP) (service)
+ \value HCRScan Hardcopy Cable Replacement Profile (HCRP) (service)
+ \value SIMAccess SIM Access Profile (SAP) UUID (service and profile)
+ \value PhonebookAccessPCE Phonebook Access Profile (PBAP) UUID (service)
+ \value PhonebookAccessPSE Phonebook Access Profile (PBAP) UUID (service)
+ \value PhonebookAccess Phonebook Access Profile (PBAP) (profile)
+ \value HeadsetHS Headset Profile (HSP) UUID (service)
+ \value MessageAccessServer Message Access Profile (MAP) UUID (service)
+ \value MessageNotificationServer Message Access Profile (MAP) UUID (service)
+ \value MessageAccessProfile Message Access Profile (MAP) UUID (profile)
+ \value GNSS Global Navigation Satellite System UUID (profile)
+ \value GNSSServer Global Navigation Satellite System Server (UUID) (service)
+ \value Display3D 3D Synchronization Display UUID (service)
+ \value Glasses3D 3D Synchronization Glasses UUID (service)
+ \value Synchronization3D 3D Synchronization UUID (profile)
+ \value MPSProfile Multi-Profile Specification UUID (profile)
+ \value MPSService Multi-Profile Specification UUID (service)
+ \value PnPInformation Device Identification (DID) UUID (service & profile)
+ \value GenericNetworking Generic networking UUID (service)
+ \value GenericFileTransfer Generic file transfer UUID (service)
+ \value GenericAudio Generic audio UUID (service)
+ \value GenericTelephony Generic telephone UUID (service)
+ \value VideoSource Video Distribution Profile (VDP) UUID (service)
+ \value VideoSink Video Distribution Profile (VDP) UUID (service)
+ \value VideoDistribution Video Distribution Profile (VDP) UUID (profile)
+ \value HDP Health Device Profile (HDP) UUID (profile)
+ \value HDPSource Health Device Profile Source (HDP) UUID (service)
+ \value HDPSink Health Device Profile Sink (HDP) UUID (service)
+ \value GenericAccess Generic access service for Bluetooth Low Energy devices UUID (service).
+ It contains generic information about the device. All available Characteristics are readonly.
+ \value GenericAttribute
+ \value ImmediateAlert Immediate Alert UUID (service). The service exposes a control point to allow a peer
+ device to cause the device to immediately alert.
+ \value LinkLoss Link Loss UUID (service). The service defines behavior when a link is lost between two devices.
+ \value TxPower Transmission Power UUID (service). The service exposes a device’s current
+ transmit power level when in a connection.
+ \value CurrentTimeService Current Time UUID (service). The service defines how the current time can be exposed using
+ the Generic Attribute Profile (GATT).
+ \value ReferenceTimeUpdateService Reference Time update UUID (service). The service defines how a client can request
+ an update from a reference time source from a time server.
+ \value NextDSTChangeService Next DST change UUID (service). The service defines how the information about an
+ upcoming DST change can be exposed.
+ \value Glucose Glucose UUID (service). The service exposes glucose and other data from a glucose sensor
+ for use in consumer and professional healthcare applications.
+ \value HealthThermometer Health Thermometer UUID (service). The Health Thermometer service exposes temperature
+ and other data from a thermometer intended for healthcare and fitness applications.
+ \value DeviceInformation Device Information UUID (service). The Device Information Service exposes manufacturer
+ and/or vendor information about a device.
+ \value HeartRate Heart Rate UUID (service). The service exposes the heart rate and other data from a
+ Heart Rate Sensor intended for fitness applications.
+ \value PhoneAlertStatusService Phone Alert Status UUID (service). The service exposes the phone alert status when
+ in a connection.
+ \value BatteryService Battery UUID (service). The Battery Service exposes the state of a battery within a device.
+ \value BloodPressure Blood Pressure UUID (service). The service exposes blood pressure and other data from a blood pressure
+ monitor intended for healthcare applications.
+ \value AlertNotificationService Alert Notification UUID (service). The Alert Notification service exposes alert
+ information on a device.
+ \value HumanInterfaceDevice Human Interface UUID (service). The service exposes the HID reports and other HID data
+ intended for HID Hosts and HID Devices.
+ \value ScanParameters Scan Parameters UUID (service). The Scan Parameters Service enables a GATT Server device
+ to expose a characteristic for the GATT Client to write its scan interval and scan window
+ on the GATT Server device.
+ \value RunningSpeedAndCadence Runnung Speed and Cadence UUID (service). The service exposes speed, cadence and other
+ data from a Running Speed and Cadence Sensor intended for fitness applications.
+ \value CyclingSpeedAndCadence Cycling Speed and Cadence UUID (service). The service exposes speed-related and
+ cadence-related data from a Cycling Speed and Cadence sensor intended for fitness
+ applications.
+ \value CyclingPower Cycling Speed UUID (service). The service exposes power- and force-related data and
+ optionally speed- and cadence-related data from a Cycling Power
+ sensor intended for sports and fitness applications.
+ \value LocationAndNavigation Location Navigation UUID (service). The service exposes location and navigation-related
+ data from a Location and Navigation sensor intended for outdoor activity applications.
+*/
+
+/*!
+ \enum QBluetoothUuid::CharacteristicId
+
+ This enum is a convienience type for Bluetooth low energy service characteristics class UUIDs. Values of this type
+ will be implicitly converted into a QBluetoothUuid when necessary.
+
+ \value AlertCategoryID Categories of alerts/messages.
+ \value AlertCategoryIDBitMask Categories of alerts/messages.
+ \value AlertLevel The level of an alert a device is to sound.
+ If this level is changed while the alert is being sounded,
+ the new level should take effect.
+ \value AlertNotificationControlPoint Control point of the Alert Notification server.
+ Client can write the command here to request the several
+ functions toward the server.
+ \value AlertStatus The Alert Status characteristic defines the Status of alert.
+ \value Appearance The external appearance of this device. The values are composed
+ of a category (10-bits) and sub-categories (6-bits).
+ \value BatteryLevel The current charge level of a battery. 100% represents fully charged
+ while 0% represents fully discharged.
+ \value BloodPressureFeature The Blood Pressure Feature characteristic is used to describe the supported
+ features of the Blood Pressure Sensor.
+ \value BloodPressureMeasurement The Blood Pressure Measurement characteristic is a variable length structure
+ containing a Flags field, a Blood Pressure Measurement Compound Value field,
+ and contains additional fields such as Time Stamp, Pulse Rate and User ID
+ as determined by the contents of the Flags field.
+ \value BodySensorLocation
+ \value BootKeyboardInputReport The Boot Keyboard Input Report characteristic is used to transfer fixed format
+ and length Input Report data between a HID Host operating in Boot Protocol Mode
+ and a HID Service corresponding to a boot keyboard.
+ \value BootKeyboardOutputReport The Boot Keyboard Output Report characteristic is used to transfer fixed format
+ and length Output Report data between a HID Host operating in Boot Protocol Mode
+ and a HID Service corresponding to a boot keyboard.
+ \value BootMouseInputReport The Boot Mouse Input Report characteristic is used to transfer fixed format and
+ length Input Report data between a HID Host operating in Boot Protocol Mode and
+ a HID Service corresponding to a boot mouse.
+ \value CSCFeature The CSC (Cycling Speed and Cadence) Feature characteristic is used to describe
+ the supported features of the Server.
+ \value CSCMeasurement The CSC Measurement characteristic (CSC refers to Cycling Speed and Cadence)
+ is a variable length structure containing a Flags field and, based on the contents
+ of the Flags field, may contain one or more additional fields as shown in the tables
+ below.
+ \value CurrentTime
+ \value CyclingPowerControlPoint The Cycling Power Control Point characteristic is used to request a specific function
+ to be executed on the receiving device.
+ \value CyclingPowerFeature The CP Feature characteristic is used to report a list of features supported by
+ the device.
+ \value CyclingPowerMeasurement The Cycling Power Measurement characteristic is a variable length structure containing
+ a Flags field, an Instantaneous Power field and, based on the contents of the Flags
+ field, may contain one or more additional fields as shown in the table below.
+ \value CyclingPowerVector The Cycling Power Vector characteristic is a variable length structure containing
+ a Flags fieldand based on the contents of the Flags field, may contain one or more
+ additional fields as shown in the table below.
+ \value DateTime The Date Time characteristic is used to represent time.
+ \value DayDateTime
+ \value DayOfWeek
+ \value DeviceName
+ \value DSTOffset
+ \value ExactTime256
+ \value FirmwareRevisionString The value of this characteristic is a UTF-8 string representing the firmware revision
+ for the firmware within the device.
+ \value GlucoseFeature The Glucose Feature characteristic is used to describe the supported features
+ of the Server. When read, the Glucose Feature characteristic returns a value
+ that is used by a Client to determine the supported features of the Server.
+ \value GlucoseMeasurement The Glucose Measurement characteristic is a variable length structure containing
+ a Flags field, a Sequence Number field, a Base Time field and, based upon the contents
+ of the Flags field, may contain a Time Offset field, Glucose Concentration field,
+ Type-Sample Location field and a Sensor Status Annunciation field.
+ \value GlucoseMeasurementContext
+ \value HardwareRevisionString The value of this characteristic is a UTF-8 string representing the hardware revision
+ for the hardware within the device.
+ \value HeartRateControlPoint
+ \value HeartRateMeasurement
+ \value HIDControlPoint The HID Control Point characteristic is a control-point attribute that defines the
+ HID Commands when written.
+ \value HIDInformation The HID Information Characteristic returns the HID attributes when read.
+ \value IEEE1107320601RegulatoryCertificationDataList The value of the characteristic is an opaque structure listing
+ various regulatory and/or certification compliance items to which the device
+ claims adherence.
+ \value IntermediateCuffPressure This characteristic has the same format as the Blood Pressure Measurement
+ characteristic.
+ \value IntermediateTemperature The Intermediate Temperature characteristic has the same format as the
+ Temperature Measurement characteristic
+ \value LNControlPoint The LN Control Point characteristic is used to request a specific function
+ to be executed on the receiving device.
+ \value LNFeature The LN Feature characteristic is used to report a list of features supported
+ by the device.
+ \value LocalTimeInformation
+ \value LocationAndSpeed The Location and Speed characteristic is a variable length structure containing
+ a Flags field and, based on the contents of the Flags field, may contain a combination
+ of data fields.
+ \value ManufacturerNameString The value of this characteristic is a UTF-8 string representing the name of the
+ manufacturer of the device.
+ \value MeasurementInterval The Measurement Interval characteristic defines the time between measurements.
+ \value ModelNumberString The value of this characteristic is a UTF-8 string representing the model number
+ assigned by the device vendor.
+ \value Navigation The Navigation characteristic is a variable length structure containing a Flags field,
+ a Bearing field, a Heading field and, based on the contents of the Flags field.
+ \value NewAlert This characteristic defines the category of the alert and how many new alerts of
+ that category have occurred in the server device.
+ \value PeripheralPreferredConnectionParameters
+ \value PeripheralPrivacyFlag
+ \value PnPID The PnP_ID characteristic returns its value when read using the GATT Characteristic
+ Value Read procedure.
+ \value PositionQuality The Position Quality characteristic is a variable length structure containing a
+ Flags field and at least one of the optional data
+ \value ProtocolMode The Protocol Mode characteristic is used to expose the current protocol mode of
+ the HID Service with which it is associated, or to set the desired protocol
+ mode of the HID Service.
+ \value ReconnectionAddress The Information included in this page is informative. The normative descriptions
+ are contained in the applicable specification.
+ \value RecordAccessControlPoint This control point is used with a service to provide basic management functionality
+ for the Glucose Sensor patient record database.
+ \value ReferenceTimeInformation
+ \value Report The Report characteristic is used to exchange data between a HID Device and a HID Host.
+ \value ReportMap Only a single instance of this characteristic exists as part of a HID Service.
+ \value RingerControlPoint The Ringer Control Point characteristic defines the Control Point of Ringer.
+ \value RingerSetting The Ringer Setting characteristic defines the Setting of the Ringer.
+ \value RSCFeature The RSC (Running Speed and Cadence) Feature characteristic is used to describe the
+ supported features of the Server.
+ \value RSCMeasurement RSC refers to Running Speed and Cadence.
+ \value SCControlPoint The SC Control Point characteristic is used to request a specific function to be
+ executed on the receiving device.
+ \value ScanIntervalWindow The Scan Interval Window characteristic is used to store the scan parameters of
+ the GATT Client.
+ \value ScanRefresh The Scan Refresh characteristic is used to notify the Client that the Server
+ requires the Scan Interval Window characteristic to be written with the latest
+ values upon notification.
+ \value SensorLocation The Sensor Location characteristic is used to expose the location of the sensor.
+ \value SerialNumberString The value of this characteristic is a variable-length UTF-8 string representing
+ the serial number for a particular instance of the device.
+ \value ServiceChanged
+ \value SoftwareRevisionString The value of this characteristic is a UTF-8 string representing the software
+ revision for the software within the device.
+ \value SupportedNewAlertCategory Category that the server supports for new alert.
+ \value SupportedUnreadAlertCategory Category that the server supports for unread alert.
+ \value SystemID If the system ID is based of a Bluetooth Device Address with a Company Identifier
+ (OUI) is 0x123456 and the Company Assigned Identifier is 0x9ABCDE, then the System
+ Identifier is required to be 0x123456FFFE9ABCDE.
+ \value TemperatureMeasurement The Temperature Measurement characteristic is a variable length structure containing
+ a Flags field, a Temperature Measurement Value field and, based upon the contents of
+ the Flags field, optionally a Time Stamp field and/or a Temperature Type field.
+ \value TemperatureType The Temperature Type characteristic is an enumeration that indicates where the
+ temperature was measured.
+ \value TimeAccuracy
+ \value TimeSource
+ \value TimeUpdateControlPoint
+ \value TimeUpdateState
+ \value TimeWithDST
+ \value TimeZone
+ \value TxPowerLevel The value of the characteristic is a signed 8 bit integer that has a fixed point
+ exponent of 0.
+ \value UnreadAlertStatus This characteristic shows how many numbers of unread alerts exist in the specific
+ category in the device.
+*/
+
+/*!
+ \enum QBluetoothUuid::DescriptorID
+
+ This enum is a convienience type for Bluetooth low energy service descriptor class UUIDs. Values of this type
+ will be implicitly converted into a QBluetoothUuid when necessary.
+
+ \value CharacteristicExtendedProperties Descriptor defines additional Characteristic Properties.
+ \value CharacteristicUserDescription Descriptor provides a textual user description for a characteristic value.
+ \value ClientCharacteristicConfiguration Descriptor defines how the characteristic may be configured by a specific client.
+ \value ServerCharacteristicConfiguration Descriptor defines how the characteristic descriptor is associated with may be
+ configured for the server.
+ \value CharacteristicPresentationFormat Descriptor defines the format of the Characteristic Value.
+ \value CharacteristicAggregateFormat Descriptor defines the format of an aggregated Characteristic Value.
+ \value ValidRange descriptor is used for defining the range of a characteristics.
+ Two mandatory fields are contained (upper and lower bounds) which define the range.
+ \value ExternalReportReference Allows a HID Host to map information from the Report Map characteristic value for
+ Input Report, Output Report or Feature Report data to the Characteristic UUID of
+ external service characteristics used to transfer the associated data.
+ \value ReportReference Mapping information in the form of a Report ID and Report Type which maps the
+ current parent characteristic to the Report ID(s) and Report Type (s) defined
+ within the Report Map characteristic.
*/
/*!
@@ -205,6 +425,16 @@ QBluetoothUuid::QBluetoothUuid(ServiceClassUuid uuid)
}
/*!
+ Constructs a new Bluetooth UUID from the characteristic id \a uuid.
+*/
+QBluetoothUuid::QBluetoothUuid(CharacteristicId uuid)
+: QUuid(uuid, baseUuid()->data2, baseUuid()->data3, baseUuid()->data4[0], baseUuid()->data4[1],
+ baseUuid()->data4[2], baseUuid()->data4[3], baseUuid()->data4[4], baseUuid()->data4[5],
+ baseUuid()->data4[6], baseUuid()->data4[7])
+{
+}
+
+/*!
Constructs a new Bluetooth UUID from the 16 bit \a uuid.
*/
QBluetoothUuid::QBluetoothUuid(quint16 uuid)
diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h
index 014b975a..c67d2e31 100644
--- a/src/bluetooth/qbluetoothuuid.h
+++ b/src/bluetooth/qbluetoothuuid.h
@@ -151,12 +151,131 @@ public:
VideoDistribution = 0x1305,
HDP = 0x1400,
HDPSource = 0x1401,
- HDPSink = 0x1402
+ HDPSink = 0x1402,
+ GenericAccess = 0x1800,
+ GenericAttribute = 0x1801,
+ ImmediateAlert = 0x1802,
+ LinkLoss = 0x1803,
+ TxPower = 0x1804,
+ CurrentTimeService = 0x1805,
+ ReferenceTimeUpdateService = 0x1806,
+ NextDSTChangeService = 0x1807,
+ Glucose = 0x1808,
+ HealthThermometer = 0x1809,
+ DeviceInformation = 0x180a,
+ HeartRate = 0x180d,
+ PhoneAlertStatusService = 0x180e,
+ BatteryService = 0x180f,
+ BloodPressure = 0x1810,
+ AlertNotificationService = 0x1811,
+ HumanInterfaceDevice = 0x1812,
+ ScanParameters = 0x1813,
+ RunningSpeedAndCadence = 0x1814,
+ CyclingSpeedAndCadence = 0x1816,
+ CyclingPower = 0x1818,
+ LocationAndNavigation = 0x1819,
+ };
+
+ enum CharacteristicId {
+ AlertCategoryID = 0x2a43,
+ AlertCategoryIDBitMask = 0x2a42,
+ AlertLevel = 0x2a06,
+ AlertNotificationControlPoint = 0x2a44,
+ AlertStatus = 0x2a3f,
+ Appearance = 0x2a01,
+ BatteryLevel = 0x2a19,
+ BloodPressureFeature = 0x2a49,
+ BloodPressureMeasurement = 0x2a35,
+ BodySensorLocation = 0x2a38,
+ BootKeyboardInputReport = 0x2a22,
+ BootKeyboardOutputReport = 0x2a32,
+ BootMouseInputReport = 0x2a33,
+ CSCFeature = 0x2a5c,
+ CSCMeasurement = 0x2a5b,
+ CurrentTime = 0x2a2b,
+ CyclingPowerControlPoint = 0x2a66,
+ CyclingPowerFeature = 0x2a65,
+ CyclingPowerMeasurement = 0x2a63,
+ CyclingPowerVector = 0x2a64,
+ DateTime = 0x2a08,
+ DayDateTime = 0x2a0a,
+ DayOfWeek = 0x2a09,
+ DeviceName = 0x2a00,
+ DSTOffset = 0x2a0d,
+ ExactTime256 = 0x2a0c,
+ FirmwareRevisionString = 0x2a26,
+ GlucoseFeature = 0x2a51,
+ GlucoseMeasurement = 0x2a18,
+ GlucoseMeasurementContext = 0x2a34,
+ HardwareRevisionString = 0x2a27,
+ HeartRateControlPoint = 0x2a39,
+ HeartRateMeasurement = 0x2a37,
+ HIDControlPoint = 0x2a4c,
+ HIDInformation = 0x2a4a,
+ IEEE1107320601RegulatoryCertificationDataList = 0x2a2a,
+ IntermediateCuffPressure = 0x2a36,
+ IntermediateTemperature = 0x2a1e,
+ LNControlPoint = 0x2a6b,
+ LNFeature = 0x2a6a,
+ LocalTimeInformation = 0x2a0f,
+ LocationAndSpeed = 0x2a67,
+ ManufacturerNameString = 0x2a29,
+ MeasurementInterval = 0x2a21,
+ ModelNumberString = 0x2a24,
+ Navigation = 0x2a68,
+ NewAlert = 0x2a46,
+ PeripheralPreferredConnectionParameters = 0x2a04,
+ PeripheralPrivacyFlag = 0x2a02,
+ PnPID = 0x2a50,
+ PositionQuality = 0x2a69,
+ ProtocolMode = 0x2a4e,
+ ReconnectionAddress = 0x2a03,
+ RecordAccessControlPoint = 0x2a52,
+ ReferenceTimeInformation = 0x2a14,
+ Report = 0x2a4d,
+ ReportMap = 0x2a4b,
+ RingerControlPoint = 0x2a40,
+ RingerSetting = 0x2a41,
+ RSCFeature = 0x2a54,
+ RSCMeasurement = 0x2a53,
+ SCControlPoint = 0x2a55,
+ ScanIntervalWindow = 0x2a4f,
+ ScanRefresh = 0x2a31,
+ SensorLocation = 0x2a5d,
+ SerialNumberString = 0x2a25,
+ ServiceChanged = 0x2a05,
+ SoftwareRevisionString = 0x2a28,
+ SupportedNewAlertCategory = 0x2a47,
+ SupportedUnreadAlertCategory = 0x2a48,
+ SystemID = 0x2a23,
+ TemperatureMeasurement = 0x2a1c,
+ TemperatureType = 0x2a1d,
+ TimeAccuracy = 0x2a12,
+ TimeSource = 0x2a13,
+ TimeUpdateControlPoint = 0x2a16,
+ TimeUpdateState = 0x2a17,
+ TimeWithDST = 0x2a11,
+ TimeZone = 0x2a0e,
+ TxPowerLevel = 0x2a07,
+ UnreadAlertStatus = 0x2a45
+ };
+
+ enum DescriptorID {
+ CharacteristicExtendedProperties = 0x2900,
+ CharacteristicUserDescription = 0x2901,
+ ClientCharacteristicConfiguration = 0x2902,
+ ServerCharacteristicConfiguration = 0x2903,
+ CharacteristicPresentationFormat = 0x2904,
+ CharacteristicAggregateFormat = 0x2905,
+ ValidRange = 0x2906,
+ ExternalReportReference = 0x2907,
+ ReportReference = 0x2908
};
QBluetoothUuid();
QBluetoothUuid(ProtocolUuid uuid);
QBluetoothUuid(ServiceClassUuid uuid);
+ QBluetoothUuid(CharacteristicId uuid);
explicit QBluetoothUuid(quint16 uuid);
explicit QBluetoothUuid(quint32 uuid);
explicit QBluetoothUuid(quint128 uuid);
diff --git a/src/bluetooth/qlowenergycharacteristicinfo.cpp b/src/bluetooth/qlowenergycharacteristicinfo.cpp
new file mode 100644
index 00000000..66994131
--- /dev/null
+++ b/src/bluetooth/qlowenergycharacteristicinfo.cpp
@@ -0,0 +1,298 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycharacteristicinfo.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include <QHash>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QLowEnergyCharacteristicInfo
+ \inmodule QtBluetooth
+ \brief The QLowEnergyCharacteristicInfo class stores information about a Bluetooth
+ Low Energy service characteristic.
+
+ QLowEnergyCharacteristicInfo provides information about a Bluetooth Low Energy
+ service characteristic's name, UUID, value, permissions, handle and descriptors.
+ To get the full characteristic specification and information it is necessary to
+ connect to the service using QLowEnergyServiceInfo and QLowEnergyController classes.
+ Some characteristics can contain none, one or more descriptors.
+*/
+
+/*!
+ \enum QLowEnergyCharacteristicInfo::Property
+
+ This enum describes the properties of a characteristic.
+
+ \value Broadcasting Allow for the broadcasting of Generic Attributes (GATT) characteristic values.
+ \value Read Allow the characteristic values to be read.
+ \value WriteNoResponse Allow characteristic values without responses to be written.
+ \value Write Allow for characteristic values to be written.
+ \value Notify Permits notification of characteristic values.
+ \value Indicate Permits indications of characteristic values.
+ \value WriteSigned Permits signed writes of the GATT characteristic values.
+ \value ExtendedProperty Additional characteristic properties are defined in the characteristic
+ extended properties descriptor.
+*/
+
+/*!
+ Method for parsing the characteristic name with given \a uuid.
+ * \brief parseUuid
+ * \param uuid
+ * \return
+ */
+QString parseUuid(QBluetoothUuid uuid) {
+ static QHash<int, QString> uuidnames;
+ if ( uuidnames.isEmpty() ) {
+ uuidnames[0x2a43] = QStringLiteral("Alert Category ID");
+ uuidnames[0x2A42] = QStringLiteral("Alert Category ID Bit Mask");
+ uuidnames[0x2A06] = QStringLiteral("Alert Level");
+ uuidnames[0x2A44] = QStringLiteral("Alert Notification Control Point");
+ uuidnames[0x2A3F] = QStringLiteral("Alert Status");
+ uuidnames[0x2A01] = QStringLiteral("GAP Appearance");
+ uuidnames[0x2A19] = QStringLiteral("Battery Level");
+ uuidnames[0x2A49] = QStringLiteral("Blood Pressure Feature");
+ uuidnames[0x2A35] = QStringLiteral("Blood Pressure Measurement");
+ uuidnames[0x2A38] = QStringLiteral("Body Sensor Location");
+ uuidnames[0x2A22] = QStringLiteral("Boot Keyboard Input Report");
+ uuidnames[0x2A32] = QStringLiteral("Boot Keyboard Output Report");
+ uuidnames[0x2A33] = QStringLiteral("Boot Mouse Input Report");
+ uuidnames[0x2A2B] = QStringLiteral("Current Time");
+ uuidnames[0x2A08] = QStringLiteral("Date Time");
+ uuidnames[0x2A0A] = QStringLiteral("Day Date Time");
+ uuidnames[0x2A09] = QStringLiteral("Day of Week");
+ uuidnames[0x2A00] = QStringLiteral("GAP Device Name");
+ uuidnames[0x2A0D] = QStringLiteral("DST Offset");
+ uuidnames[0x2A0C] = QStringLiteral("Exact Time 256");
+ uuidnames[0x2A26] = QStringLiteral("Firmware Revision String");
+ uuidnames[0x2A51] = QStringLiteral("Glucose Feature");
+ uuidnames[0x2A18] = QStringLiteral("Glucose Measurement");
+ uuidnames[0x2A34] = QStringLiteral("Glucose Measurement Context");
+ uuidnames[0x2A27] = QStringLiteral("Hardware Revision String");
+ uuidnames[0x2A39] = QStringLiteral("Heart Rate Control Point");
+ uuidnames[0x2A37] = QStringLiteral("Heart Rate Measurement");
+ uuidnames[0x2A4C] = QStringLiteral("HID Control Point");
+ uuidnames[0x2A4A] = QStringLiteral("HID Information");
+ uuidnames[0x2A2A] = QStringLiteral("IEEE 11073 20601 Regulatory Certification Data List");
+ uuidnames[0x2A36] = QStringLiteral("Intermediate Blood Pressure");
+ uuidnames[0x2A1E] = QStringLiteral("Iintermediate Temperature");
+ uuidnames[0x2A0F] = QStringLiteral("Local Time Information");
+ uuidnames[0x2A29] = QStringLiteral("Manufacturer Name String");
+ uuidnames[0x2A21] = QStringLiteral("Measurement Interval");
+ uuidnames[0x2A24] = QStringLiteral("Model Number String");
+ uuidnames[0x2A46] = QStringLiteral("New Alert");
+ uuidnames[0x2A04] = QStringLiteral("GAP Peripheral Preferred Connection Parameters");
+ uuidnames[0x2A02] = QStringLiteral("GAP Peripheral Privacy Flag");
+ uuidnames[0x2A50] = QStringLiteral("PNP ID");
+ uuidnames[0x2A4E] = QStringLiteral("Protocol Mode");
+ uuidnames[0x2A03] = QStringLiteral("GAP Reconnection Address");
+ uuidnames[0x2A52] = QStringLiteral("Record Access Control Point");
+ uuidnames[0x2A14] = QStringLiteral("Reference Time Information");
+ uuidnames[0x2A4D] = QStringLiteral("Report");
+ uuidnames[0x2A4B] = QStringLiteral("Report Map");
+ uuidnames[0x2A40] = QStringLiteral("Ringer Control Point");
+ uuidnames[0x2A41] = QStringLiteral("Ringer Setting");
+ uuidnames[0x2A4F] = QStringLiteral("Scan Interval Window");
+ uuidnames[0x2A31] = QStringLiteral("Scan Refresh");
+ uuidnames[0x2A25] = QStringLiteral("Serial Number String");
+ uuidnames[0x2A05] = QStringLiteral("GATT Service Changed");
+ uuidnames[0x2A28] = QStringLiteral("Software Revision String");
+ uuidnames[0x2A47] = QStringLiteral("Supported New Alert Category");
+ uuidnames[0x2A48] = QStringLiteral("Supported Unread Alert Category");
+ uuidnames[0x2A23] = QStringLiteral("System ID");
+ uuidnames[0x2A1C] = QStringLiteral("Temperature Measurement");
+ uuidnames[0x2A1D] = QStringLiteral("Temperature Type");
+ uuidnames[0x2A12] = QStringLiteral("Time Accuracy");
+ uuidnames[0x2A13] = QStringLiteral("Time Source");
+ uuidnames[0x2A16] = QStringLiteral("Time Update Control Point");
+ uuidnames[0x2A17] = QStringLiteral("Time Update State");
+ uuidnames[0x2A11] = QStringLiteral("Time With DST");
+ uuidnames[0x2A0E] = QStringLiteral("Time Zone");
+ uuidnames[0x2A07] = QStringLiteral("TX Power");
+ uuidnames[0x2A45] = QStringLiteral("Unread Alert Status");
+ }
+ QString name = uuidnames.value(uuid.toUInt16(), QStringLiteral("Unknown Characteristic"));
+ return name;
+
+}
+
+/*!
+ Construct a new QLowEnergyCharacteristicInfo.
+*/
+QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo():
+ d_ptr(new QLowEnergyCharacteristicInfoPrivate)
+{
+
+}
+
+/*!
+ Construct a new QLowEnergyCharacteristicInfo with given \a uuid.
+*/
+QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo(const QBluetoothUuid &uuid):
+ d_ptr(new QLowEnergyCharacteristicInfoPrivate)
+{
+ d_ptr->uuid = uuid;
+}
+
+/*!
+ Construct a new QLowEnergyCharacteristicInfo that is a copy of \a other.
+
+ The two copies continue to share the same underlying data which does not detach
+ upon write.
+*/
+QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo(const QLowEnergyCharacteristicInfo &other):
+ d_ptr(other.d_ptr)
+{
+
+}
+
+/*!
+ Destroys the QLowEnergyCharacteristicInfo object.
+*/
+QLowEnergyCharacteristicInfo::~QLowEnergyCharacteristicInfo()
+{
+
+}
+
+/*!
+ Returns the name of the gatt characteristic.
+*/
+QString QLowEnergyCharacteristicInfo::name() const
+{
+ d_ptr->name = parseUuid(d_ptr->uuid);
+ return d_ptr->name;
+}
+
+/*!
+ Returns the UUID of the gatt characteristic.
+*/
+QBluetoothUuid QLowEnergyCharacteristicInfo::uuid() const
+{
+ return d_ptr->uuid;
+}
+
+/*!
+ Returns the properties value of the gatt characteristic.
+*/
+QVariantMap QLowEnergyCharacteristicInfo::properties() const
+{
+ return d_ptr->properties;
+}
+
+/*!
+ Returns permissions of the gatt characteristic.
+*/
+int QLowEnergyCharacteristicInfo::permissions() const
+{
+ return d_ptr->permission;
+}
+
+/*!
+ Returns value of the gatt characteristic.
+*/
+QByteArray QLowEnergyCharacteristicInfo::value() const
+{
+ return d_ptr->value;
+}
+
+/*!
+ Returns the handle of the gatt characteristic.
+*/
+QString QLowEnergyCharacteristicInfo::handle() const
+{
+ return d_ptr->handle;
+}
+
+/*!
+ Returns the true or false statement depending whether the characteristic is notification
+ (enables conctant updates when value is changed on LE device).
+*/
+bool QLowEnergyCharacteristicInfo::isNotificationCharacteristic() const
+{
+ return d_ptr->notification;
+}
+
+/*!
+ Sets the value \a value of the characteristic. This only caches the value. To write
+ a value directly to the device QLowEnergyController class must be used.
+
+ \sa QLowEnergyController::writeCharacteristic()
+*/
+void QLowEnergyCharacteristicInfo::setValue(const QByteArray &value)
+{
+ d_ptr->value = value;
+}
+
+/*!
+ Makes a copy of the \a other and assigns it to this QLowEnergyCharacteristicInfo object.
+ The two copies continue to share the same service and registration details.
+*/
+QLowEnergyCharacteristicInfo &QLowEnergyCharacteristicInfo::operator=(const QLowEnergyCharacteristicInfo &other)
+{
+ d_ptr = other.d_ptr;
+ return *this;
+}
+
+/*!
+ Returns true if the QLowEnergyCharacteristicInfo object is valid, otherwise returns false.
+ If it returns false, it means that service that this characteristic belongs was not connected.
+*/
+bool QLowEnergyCharacteristicInfo::isValid() const
+{
+ if (d_ptr->uuid == QBluetoothUuid())
+ return false;
+ if (d_ptr->handle.toUShort(0,0) == 0)
+ return false;
+ if (!d_ptr->valid())
+ return false;
+ return true;
+}
+
+/*!
+ Returns the list of characteristic descriptors.
+*/
+QList<QLowEnergyDescriptorInfo> QLowEnergyCharacteristicInfo::descriptors() const
+{
+ return d_ptr->descriptorsList;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycharacteristicinfo.h b/src/bluetooth/qlowenergycharacteristicinfo.h
new file mode 100644
index 00000000..ceaac46e
--- /dev/null
+++ b/src/bluetooth/qlowenergycharacteristicinfo.h
@@ -0,0 +1,105 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYCHARACTERISTICINFO_H
+#define QLOWENERGYCHARACTERISTICINFO_H
+#include <QtCore/QSharedPointer>
+#include <QtCore/QObject>
+#include <QtBluetooth/QBluetoothUuid>
+#include <QtBluetooth/QLowEnergyDescriptorInfo>
+
+QT_BEGIN_NAMESPACE
+
+class QBluetoothUuid;
+class QLowEnergyCharacteristicInfoPrivate;
+
+class Q_BLUETOOTH_EXPORT QLowEnergyCharacteristicInfo
+{
+ friend class QLowEnergyServiceInfo;
+ friend class QLowEnergyServiceInfoPrivate;
+ friend class QLowEnergyController;
+ friend class QLowEnergyControllerPrivate;
+ friend class QLowEnergyCharacteristicInfoPrivate;
+public:
+
+ enum Property {
+ Broadcasting = 0x01,
+ Read = 0x02,
+ WriteNoResponse = 0x04,
+ Write = 0x08,
+ Notify = 0x10,
+ Indicate = 0x20,
+ WriteSigned = 0x40,
+ ExtendedProperty = 0x80
+ };
+
+ QLowEnergyCharacteristicInfo();
+ QLowEnergyCharacteristicInfo(const QBluetoothUuid &uuid);
+ QLowEnergyCharacteristicInfo(const QLowEnergyCharacteristicInfo &other);
+ ~QLowEnergyCharacteristicInfo();
+
+ QLowEnergyCharacteristicInfo &operator=(const QLowEnergyCharacteristicInfo &other);
+
+ QString name() const;
+
+ QBluetoothUuid uuid() const;
+
+ void setValue(const QByteArray &value);
+ QByteArray value() const;
+
+ int permissions() const;
+ QVariantMap properties() const;
+ QString handle() const;
+
+ bool isNotificationCharacteristic() const;
+
+ QList<QLowEnergyDescriptorInfo> descriptors() const;
+
+ bool isValid() const;
+
+protected:
+ QSharedPointer<QLowEnergyCharacteristicInfoPrivate> d_ptr;
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYCHARACTERISTICINFO_H
diff --git a/src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp b/src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp
new file mode 100644
index 00000000..a6592186
--- /dev/null
+++ b/src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp
@@ -0,0 +1,101 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycharacteristicinfo.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include "bluez/characteristic_p.h"
+#include "qlowenergyprocess_p.h"
+
+#include <QtDBus/QDBusPendingCallWatcher>
+
+//#define QT_LOWENERGYCHARACTERISTIC_DEBUG
+
+#ifdef QT_LOWENERGYCHARACTERISTIC_DEBUG
+#include <QtCore/QDebug>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+QLowEnergyCharacteristicInfoPrivate::QLowEnergyCharacteristicInfoPrivate()
+ : permission(0), notification (false), handle(QStringLiteral("0x0000")),
+ properties(QVariantMap()), characteristic(0), m_signalConnected(false)
+{
+ process = process->instance();
+ t=0;
+}
+
+QLowEnergyCharacteristicInfoPrivate::~QLowEnergyCharacteristicInfoPrivate()
+{
+ delete characteristic;
+}
+
+void QLowEnergyCharacteristicInfoPrivate::setValue(const QByteArray &wantedValue)
+{
+ Q_UNUSED(wantedValue);
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::readDescriptors()
+{
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::readValue()
+{
+
+}
+
+bool QLowEnergyCharacteristicInfoPrivate::valid()
+{
+ return true;
+}
+
+bool QLowEnergyCharacteristicInfoPrivate::enableNotification()
+{
+ return false;
+}
+
+void QLowEnergyCharacteristicInfoPrivate::disableNotification()
+{
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycharacteristicinfo_p.cpp b/src/bluetooth/qlowenergycharacteristicinfo_p.cpp
new file mode 100644
index 00000000..092a2580
--- /dev/null
+++ b/src/bluetooth/qlowenergycharacteristicinfo_p.cpp
@@ -0,0 +1,85 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycharacteristicinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QLowEnergyCharacteristicInfoPrivate::QLowEnergyCharacteristicInfoPrivate()
+{
+
+}
+
+QLowEnergyCharacteristicInfoPrivate::~QLowEnergyCharacteristicInfoPrivate()
+{
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::setValue(const QByteArray &wantedValue)
+{
+ Q_UNUSED(wantedValue);
+}
+
+bool QLowEnergyCharacteristicInfoPrivate::enableNotification()
+{
+ return false;
+}
+
+void QLowEnergyCharacteristicInfoPrivate::disableNotification()
+{
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::readDescriptors()
+{
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::readValue()
+{
+
+}
+
+bool QLowEnergyCharacteristicInfoPrivate::valid()
+{
+ return false;
+}
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycharacteristicinfo_p.h b/src/bluetooth/qlowenergycharacteristicinfo_p.h
new file mode 100644
index 00000000..59353d5f
--- /dev/null
+++ b/src/bluetooth/qlowenergycharacteristicinfo_p.h
@@ -0,0 +1,117 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYCHARACTERISTICINFO_P_H
+#define QLOWENERGYCHARACTERISTICINFO_P_H
+#include "qbluetoothuuid.h"
+#include "qlowenergycharacteristicinfo.h"
+
+#ifdef QT_BLUEZ_BLUETOOTH
+#include <QtDBus/QtDBus>
+#include <QObject>
+#endif
+#ifdef QT_QNX_BLUETOOTH
+#include <btapi/btdevice.h>
+#include <btapi/btgatt.h>
+#include <btapi/btspp.h>
+#include <btapi/btle.h>
+#endif
+#ifdef QT_BLUEZ_BLUETOOTH
+class OrgBluezCharacteristicInterface;
+QT_FORWARD_DECLARE_CLASS(QLowEnergyProcess);
+#endif
+
+QT_BEGIN_NAMESPACE
+class QBluetoothUuid;
+class QLowEnergyCharacteristicInfo;
+
+class QLowEnergyCharacteristicInfoPrivate: public QObject
+{
+ Q_OBJECT
+public:
+ QLowEnergyCharacteristicInfoPrivate();
+ ~QLowEnergyCharacteristicInfoPrivate();
+
+ void setValue(const QByteArray &wantedValue);
+ void readValue();
+ bool valid();
+ void readDescriptors();
+ bool enableNotification();
+ void disableNotification();
+
+ QString name;
+ QBluetoothUuid uuid;
+ QByteArray value;
+ int permission;
+ bool notification;
+ QString handle;
+ QString notificationHandle;
+ int instance;
+ QVariantMap properties;
+ QString errorString;
+ QList<QLowEnergyDescriptorInfo> descriptorsList;
+#ifdef QT_QNX_BLUETOOTH
+ bt_gatt_characteristic_t characteristic;
+ int characteristicMtu;
+ bt_gatt_char_prop_mask characteristicProperties;
+ static void serviceNotification(int, short unsigned int, const unsigned char*, short unsigned int, void *);
+#endif
+#ifdef QT_BLUEZ_BLUETOOTH
+ QString path;
+ int t;
+ QString startingHandle;
+#endif
+
+Q_SIGNALS:
+ void notifyValue(const QBluetoothUuid &);
+ void error(const QBluetoothUuid &);
+
+private:
+#ifdef QT_BLUEZ_BLUETOOTH
+ OrgBluezCharacteristicInterface *characteristic;
+ QLowEnergyProcess *process;
+ bool m_signalConnected;
+#endif
+
+};
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYCHARACTERISTICINFO_P_H
diff --git a/src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp b/src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp
new file mode 100644
index 00000000..09db7e67
--- /dev/null
+++ b/src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp
@@ -0,0 +1,332 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QLoggingCategory>
+#include "qlowenergycharacteristicinfo_p.h"
+#include <btapi/btdevice.h>
+#include <btapi/btgatt.h>
+#include <btapi/btle.h>
+#include <errno.h>
+#include "qlowenergyserviceinfo.h"
+#include "qlowenergyserviceinfo_p.h"
+#include "qlowenergydescriptorinfo_p.h"
+#include "qnx/ppshelpers_p.h"
+
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_BT_QNX)
+
+int hexValue(QChar inChar)
+{
+ if (inChar.isDigit())
+ return (inChar.unicode() - '0');
+ else
+ return (inChar.toUpper().unicode() - 'A' + 10);
+ return -1;
+}
+
+int stringToBuffer(const QString &stringData, quint8 *buffer, int bufferLength)
+{
+ int consumed = 0;
+ for (int i = 0; i < bufferLength; i++) {
+ const int hex = hexValue(stringData.at(i).toLatin1());
+ if (hex >= 0) {
+ if ((consumed % 2) == 0) {
+ buffer[(consumed / 2)] = hex << 4;
+ } else {
+ buffer[(consumed / 2)] |= hex;
+ }
+
+ consumed++;
+ }
+ }
+
+ // Round up the number of bytes we consumed to a multiple of 2.
+ if ((consumed % 2) != 0)
+ ++consumed;
+
+ return consumed;
+}
+
+QLowEnergyCharacteristicInfoPrivate::QLowEnergyCharacteristicInfoPrivate():
+ permission(0), notification(false), handle(QStringLiteral("0x0000")), instance(-1)
+{
+
+}
+
+QLowEnergyCharacteristicInfoPrivate::~QLowEnergyCharacteristicInfoPrivate()
+{
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::serviceNotification(int instance, short unsigned int handle, const unsigned char*val, short unsigned int len, void *userData)
+{
+ if (val == 0)
+ return;
+ QPointer<QLowEnergyServiceInfoPrivate> *ClassPointer = static_cast<QPointer<QLowEnergyServiceInfoPrivate> *>(userData);
+ QLowEnergyServiceInfoPrivate *p = ClassPointer->data();
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------";
+ qCDebug(QT_BT_QNX) << "[Notification] received (service uuid, handle, value, instance):" << p->uuid << handle << val << instance;
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------";
+ //Check if the notification from wanted characteristic
+ bool current = false;
+ QLowEnergyCharacteristicInfo chars;
+ for (int i = 0; i < p->characteristicList.size(); i++) {
+ QString charHandle;
+ charHandle.setNum(handle);
+ charHandle = charHandle;
+ if (charHandle == ((QLowEnergyCharacteristicInfo)p->characteristicList.at(i)).handle() ) {
+ chars = QLowEnergyCharacteristicInfo((QLowEnergyCharacteristicInfo)p->characteristicList.at(i));
+ QByteArray receivedValue;
+
+ for (int j = 0; j < len; j++) {
+ QByteArray hexadecimal;
+ hexadecimal.append(val[j]);
+ receivedValue.append(hexadecimal.toHex());
+ }
+
+ p->characteristicList.at(i).d_ptr->notification = true;
+ p->characteristicList.at(i).d_ptr->setValue(receivedValue);
+ current = true;
+ }
+ }
+
+ if (!current)
+ qCDebug(QT_BT_QNX) << "Notificiation received and does not belong to this characteristic.";
+}
+
+bool QLowEnergyCharacteristicInfoPrivate::enableNotification()
+{
+ if (instance == -1) {
+ qCDebug(QT_BT_QNX) << " GATT service not connected ";
+ errorString = QStringLiteral("Service is not connected");
+ emit error(uuid);
+ return false;
+ }
+ if ( (permission & QLowEnergyCharacteristicInfo::Notify) == 0) {
+ qCDebug(QT_BT_QNX) << "Notification changes not allowed";
+ errorString = QStringLiteral("This characteristic does not support notifications.");
+ emit error(uuid);
+ return false;
+ }
+
+ int rc = bt_gatt_enable_notify(instance, &characteristic, 1);
+ if (rc != 0) {
+ qCDebug(QT_BT_QNX) << "bt_gatt_enable_notify errno=" << errno << strerror(errno);
+ errorString = QString::fromLatin1(strerror(errno));
+ emit error(uuid);
+ return false;
+ } else {
+ qCDebug(QT_BT_QNX) << "bt_gatt_enable_notify was presumably OK";
+ return true;
+ }
+}
+
+void QLowEnergyCharacteristicInfoPrivate::setValue(const QByteArray &wantedValue)
+{
+ if (permission & QLowEnergyCharacteristicInfo::Write) {
+ const int characteristicLen = wantedValue.size();
+ uint8_t *characteristicBuffer = (uint8_t *)alloca(characteristicLen / 2 + 1);
+ if (!characteristicBuffer) {
+ qCDebug(QT_BT_QNX) << "GATT characteristic: Not enough memory";
+ errorString = QStringLiteral("Not enough memory.");
+ emit error(uuid);
+ bt_gatt_disconnect_instance(instance);
+ return;
+ }
+
+ const int consumed = stringToBuffer(QString::fromLocal8Bit(wantedValue), characteristicBuffer, characteristicLen);
+
+ if (consumed > 0) {
+ int byteCount;
+ byteCount = bt_gatt_write_value(instance, handle.toUShort(), 0, characteristicBuffer, (consumed / 2));
+
+ if (byteCount < 0) {
+ qCDebug(QT_BT_QNX) << "Unable to write characteristic value: " << errno << strerror(errno);
+ errorString = QStringLiteral("Unable to write characteristic value: ") + QString::fromLatin1(strerror(errno));
+ emit error(uuid);
+ }
+ }
+ }
+ else if (!notification) {
+ errorString = QStringLiteral("Characteristic does not allow write operations. The wanted value was not written to the device.");
+ emit error(uuid);
+ }
+ value = wantedValue;
+ properties[QStringLiteral("value")] = value;
+ emit notifyValue(uuid);
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::disableNotification()
+{
+ int rc = bt_gatt_enable_notify(instance, &characteristic, 0);
+ if (rc != 0)
+ qCDebug(QT_BT_QNX) << "bt_gatt_enable_notify errno=" << errno << strerror(errno);
+ else
+ qCDebug(QT_BT_QNX) << "bt_gatt_enable_notify was presumably OK";
+
+}
+
+void QLowEnergyCharacteristicInfoPrivate::readDescriptors()
+{
+ descriptorsList.clear();
+ int count = bt_gatt_descriptors_count(instance, &characteristic);
+
+ if (count == -1) {
+ qWarning() << "GATT descriptors count failed:" << errno << "(" << strerror(errno) << ")";
+ bt_gatt_disconnect_instance(instance);
+ return;
+ }
+
+ bt_gatt_descriptor_t *descriptorList = 0;
+ if (count > 0) {
+ descriptorList = (bt_gatt_descriptor_t*)alloca(count * sizeof(bt_gatt_descriptor_t));
+ if (!descriptorList) {
+ qCDebug(QT_BT_QNX) <<"GATT descriptors: Not enough memory";
+ bt_gatt_disconnect_instance(instance);
+ return;
+ }
+
+ /* BEGIN WORKAROUND - Temporary fix to address race condition */
+ int number = 0;
+ do {
+ number = bt_gatt_descriptors(instance, &characteristic, descriptorList, count);
+ } while ((number == -1) && (errno == EBUSY));
+
+ count = number;
+ /* END WORKAROUND */
+ }
+
+ if (count == -1) {
+ qCDebug(QT_BT_QNX) << "GATT descriptors failed: %1 (%2)" << errno << strerror(errno);
+ bt_gatt_disconnect_instance(instance);
+ return;
+ }
+
+ characteristicMtu = bt_gatt_get_mtu(instance);
+
+ uint8_t *descriptorBuffer = (uint8_t *)alloca(characteristicMtu);
+ if (!descriptorBuffer) {
+ qCDebug(QT_BT_QNX) <<"GATT descriptors: Not enough memory";
+ bt_gatt_disconnect_instance(instance);
+ return;
+ }
+
+ for (int i = 0; i < count; i++) {
+ QVariantMap map;
+
+ map[QStringLiteral("uuid")] = QString::fromLatin1(descriptorList[i].uuid);
+
+ map[QStringLiteral("handle")] = descriptorList[i].handle;
+ QString descHanlde;
+ descHanlde.setNum(descriptorList[i].handle);
+ QString descriptorUuid(descriptorList[i].uuid);
+ QBluetoothUuid descUuid(descriptorUuid);
+ QLowEnergyDescriptorInfo descriptor(descUuid, descHanlde);
+
+ uint8_t more = 1;
+ int byteCount;
+ for (int offset = 0; more; offset += byteCount) {
+ byteCount = bt_gatt_read_value(instance, descriptorList[i].handle, offset, descriptorBuffer, characteristicMtu, &more);
+ if (byteCount < 0) {
+ qCDebug(QT_BT_QNX) << "Unable to read descriptor value:"<< errno<< strerror(errno);
+ break;
+ }
+ descriptor.d_ptr->m_value = QByteArray();
+ for (int j = 0; j < byteCount; j++) {
+ QString hexadecimal;
+ hexadecimal.setNum(descriptorBuffer[j], 16);
+ descriptor.d_ptr->m_value.append(hexadecimal.toLatin1());
+ }
+
+ }
+
+ map[QStringLiteral("value")] = descriptor.d_ptr->m_value;
+ descriptor.d_ptr->m_properties = map;
+ descriptorsList.append(descriptor);
+
+ }
+}
+
+void QLowEnergyCharacteristicInfoPrivate::readValue()
+{
+ if ((permission & QLowEnergyCharacteristicInfo::Read) == 0) {
+ qCDebug(QT_BT_QNX) << "GATT characteristic: Read not permitted";
+ return;
+ }
+
+ uint8_t *characteristicBuffer = (uint8_t *)alloca(characteristicMtu);
+ if (!characteristicBuffer) {
+ qCDebug(QT_BT_QNX) << "GATT characteristic: Not enough memory";
+ bt_gatt_disconnect_instance(instance);
+ return;
+ }
+
+ QString descriptorString;
+
+ int byteCount = 0;
+ uint8_t more = 1;
+ for (int offset = 0; more; offset += byteCount) {
+ byteCount = bt_gatt_read_value(instance, handle.toUShort(), offset, characteristicBuffer, characteristicMtu, &more);
+ if (byteCount < 0) {
+ qCDebug(QT_BT_QNX) << "Unable to read characteristic value: " << errno << strerror(errno);
+ break;
+ }
+ value = QByteArray();
+ for (int j = 0; j < byteCount; j++) {
+ QString hexadecimal;
+ hexadecimal.setNum(characteristicBuffer[j], 16);
+ value.append(hexadecimal.toLatin1());
+ }
+ properties["value"] = value;
+ }
+}
+
+bool QLowEnergyCharacteristicInfoPrivate::valid()
+{
+ if (instance == -1)
+ return false;
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
new file mode 100644
index 00000000..16571a18
--- /dev/null
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -0,0 +1,222 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycontroller.h"
+#include "qlowenergycontroller_p.h"
+#include "qlowenergyserviceinfo_p.h"
+#include "qlowenergycharacteristicinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+/*!
+ \class QLowEnergyController
+ \inmodule QtBluetooth
+ \brief The QLowEnergyController class is used for connecting and reading data from LE device
+ services.
+
+ To read data contained in LE service characteristics, the LE device must be paired and turned on.
+ First, connect necessary signals from the class and then connect to service by passing the wanted service
+ to \l connectoToService() function. \l connected() signal will be emitted on success or \l error()
+ signal in case of failure. It is possible to get error message by calling errorString function
+ in QLowEnergyServiceInfo class.
+
+ In case of disconnecting from service, pass the wanted service to \l disconnectFromService()
+ function and \l disconnected signal will be emitted.
+
+ It is enough to use one instance of this class to connect to more service on more devices,
+ but it is not possible to create more QLowEnergyController classes and connect to same
+ service on the same LE device.
+
+
+ \sa QLowEnergyServiceInfo, QLowEnergyCharacteristicInfo
+*/
+
+/*!
+ \fn void QLowEnergyController::connected(const QLowEnergyServiceInfo &)
+
+ This signal is emitted when a LE service is connected, passing connected QLowEnergyServiceInfo
+ instance.
+
+ \sa connectToService(const QLowEnergyServiceInfo &leService)
+*/
+
+/*!
+ \fn void QLowEnergyController::error(const QLowEnergyServiceInfo &)
+
+ This signal is emitted when the service error occurs.
+
+ \sa errorString()
+*/
+
+/*!
+ \fn void QLowEnergyController::error(const QLowEnergyCharacteristicInfo &)
+
+ This signal is emitted when the characteristic error occurs.
+
+ \sa errorString()
+*/
+
+/*!
+ \fn void QLowEnergyController::disconnected(const QLowEnergyServiceInfo &)
+
+ Emits disconnected signal with disconnected LE service.
+*/
+
+/*!
+ \fn QLowEnergyController::valueChanged(const QLowEnergyCharacteristicInfo &)
+
+ Emits a signal when the characteristic value is changed. This signal is emitted
+ after calling \l enableNotifications(const QLowEnergyCharacteristicInfo &characteristic)
+ function.
+
+ \sa enableNotifications(const QLowEnergyCharacteristicInfo &characteristic)
+*/
+
+
+/*!
+ Construct a new QLowEnergyInfo object with the \a parent.
+*/
+QLowEnergyController::QLowEnergyController(QObject *parent):
+ QObject(parent), d_ptr(new QLowEnergyControllerPrivate)
+{
+ d_ptr->q_ptr = this;
+}
+
+QLowEnergyController::~QLowEnergyController()
+{
+
+}
+
+/*!
+ Returns the list of all Bluetooth LE Services that were added.
+*/
+QList<QLowEnergyServiceInfo> QLowEnergyController::services() const
+{
+ return d_ptr->m_leServices;
+}
+
+/*!
+ Connects to the given \a leService. If the given service is not valid, or if
+ the given service is already connected, nothing will happen.
+
+*/
+void QLowEnergyController::connectToService(const QLowEnergyServiceInfo &leService)
+{
+ d_ptr->connectService(leService);
+}
+
+
+/*!
+ Disconnects the given \a leService. If the given service was not connected, nothing will be done.
+
+ If the \a leService is not passed or it is invalid, all connected services will be disconnected.
+
+*/
+void QLowEnergyController::disconnectFromService(const QLowEnergyServiceInfo &leService)
+{
+ d_ptr->disconnectService(leService);
+}
+
+
+/*!
+ Enables receiving notifications from the given \a characteristic. If the service characteristic
+ does not belong to one of the services or characteristic permissions do not allow notifications,
+ the function will return false.
+*/
+bool QLowEnergyController::enableNotifications(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ return d_ptr->enableNotification(characteristic);
+}
+
+/*!
+ Disables receiving notifications from the given \a characteristic. If the service characteristic
+ does not belong to one of the services, nothing wil lbe done.
+
+ \sa addLeService
+*/
+void QLowEnergyController::disableNotifications(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ d_ptr->disableNotification(characteristic);
+}
+
+/*!
+ Returns a human-readable description of the last error that occurred.
+
+ \sa error(const QLowEnergyServiceInfo &), error(const QLowEnergyCharacteristicInfo &)
+*/
+QString QLowEnergyController::errorString() const
+{
+ return d_ptr->errorString;
+}
+
+/*!
+ This method is called for the Linux platform if a device has a random device address that
+ is used for connecting.
+ */
+void QLowEnergyController::setRandomAddress()
+{
+ d_ptr->m_randomAddress = true;
+}
+
+/*!
+ This method writes the wanted \a characteristic taking its value. This value is written directly
+ to the Bluetooth Low Energy device. In case wanted characteristic is not connected or does not
+ have write permission, it will return false with the corresponding error string.
+
+ \sa QLowEnergyCharacteristicInfo::setValue(), errorString(), error()
+ */
+bool QLowEnergyController::writeCharacteristic(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ return d_ptr->write(characteristic);
+}
+
+/*!
+ This method writes the wanted \a descriptor taking its value. This value is written directly
+ to the Bluetooth Low Energy device. In case wanted descriptor is not connected it will return
+ false with the corresponding error string.
+
+ \sa QLowEnergyDescriptorInfo::setValue(), errorString(), error()
+ */
+bool QLowEnergyController::writeDescriptor(const QLowEnergyDescriptorInfo &descriptor)
+{
+ return d_ptr->write(descriptor);
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h
new file mode 100644
index 00000000..dcef728e
--- /dev/null
+++ b/src/bluetooth/qlowenergycontroller.h
@@ -0,0 +1,97 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYCONTROLLER_H
+#define QLOWENERGYCONTROLLER_H
+
+#include <QtCore/QObject>
+#include <QtBluetooth/qbluetoothglobal.h>
+#include <QtBluetooth/QBluetoothAddress>
+#include <QtBluetooth/QLowEnergyCharacteristicInfo>
+#include <QtBluetooth/QLowEnergyServiceInfo>
+#include <QtBluetooth/QLowEnergyDescriptorInfo>
+
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyControllerPrivate;
+
+class Q_BLUETOOTH_EXPORT QLowEnergyController: public QObject
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QLowEnergyController)
+public:
+ QLowEnergyController(QObject *parent = 0);
+ ~QLowEnergyController();
+ QList<QLowEnergyServiceInfo> services() const;
+ void connectToService(const QLowEnergyServiceInfo &leService);
+ void disconnectFromService(const QLowEnergyServiceInfo &leService = QLowEnergyServiceInfo());
+ bool enableNotifications(const QLowEnergyCharacteristicInfo &characteristic);
+ void disableNotifications(const QLowEnergyCharacteristicInfo &characteristic);
+ bool writeCharacteristic(const QLowEnergyCharacteristicInfo &characteristic);
+ bool writeDescriptor(const QLowEnergyDescriptorInfo &descriptor);
+ QString errorString() const;
+ void setRandomAddress();
+
+Q_SIGNALS:
+ void connected(const QLowEnergyServiceInfo &);
+ void error(const QLowEnergyServiceInfo &);
+ void error(const QLowEnergyCharacteristicInfo &);
+ void disconnected(const QLowEnergyServiceInfo &);
+ void valueChanged(const QLowEnergyCharacteristicInfo &);
+
+
+
+private:
+ QLowEnergyControllerPrivate *d_ptr;
+
+ Q_PRIVATE_SLOT(d_func(), void _q_serviceConnected(const QBluetoothUuid &uuid))
+ Q_PRIVATE_SLOT(d_func(), void _q_serviceError(const QBluetoothUuid &uuid))
+ Q_PRIVATE_SLOT(d_func(), void _q_characteristicError(const QBluetoothUuid &uuid))
+ Q_PRIVATE_SLOT(d_func(), void _q_valueReceived(const QBluetoothUuid &uuid))
+ Q_PRIVATE_SLOT(d_func(), void _q_serviceDisconnected(const QBluetoothUuid &uuid))
+#ifdef QT_BLUEZ_BLUETOOTH
+ Q_PRIVATE_SLOT(d_func(), void _q_replyReceived(const QString &reply))
+#endif
+};
+
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYCONTROLLER_H
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
new file mode 100644
index 00000000..042ef5f4
--- /dev/null
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -0,0 +1,518 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycontroller.h"
+#include "qlowenergycontroller_p.h"
+#include "qlowenergyserviceinfo_p.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include "qlowenergyprocess_p.h"
+#include "qlowenergydescriptorinfo.h"
+#include "qlowenergydescriptorinfo_p.h"
+#include "moc_qlowenergycontroller.cpp"
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
+
+QLowEnergyControllerPrivate::QLowEnergyControllerPrivate():
+ m_randomAddress(false), m_step(0), m_commandStarted(false)
+{
+
+}
+
+QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate()
+{
+
+}
+
+void QLowEnergyControllerPrivate::_q_serviceConnected(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid)
+ emit q_ptr->connected((QLowEnergyServiceInfo)m_leServices.at(i));
+
+ }
+}
+
+void QLowEnergyControllerPrivate::_q_serviceError(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) {
+ QLowEnergyServiceInfo service((QLowEnergyServiceInfo)m_leServices.at(i));
+ //errorString = service.d_ptr->errorString;
+ emit q_ptr->error(service);
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::_q_characteristicError(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ QList<QLowEnergyCharacteristicInfo> characteristics = m_leServices.at(i).characteristics();
+ for (int j = 0; j < characteristics.size(); j++) {
+ if (characteristics.at(j).uuid() == uuid) {
+ errorString = characteristics.at(j).d_ptr->errorString;
+ emit q_ptr->error(characteristics.at(j));
+ }
+ }
+ }
+}
+
+
+void QLowEnergyControllerPrivate::_q_valueReceived(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ QList<QLowEnergyCharacteristicInfo> characteristics = m_leServices.at(i).characteristics();
+ for (int j = 0; j < characteristics.size(); j++) {
+ if (characteristics.at(j).uuid() == uuid)
+ emit q_ptr->valueChanged(characteristics.at(j));
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::_q_serviceDisconnected(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) {
+ QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(connectedToService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceConnected(QBluetoothUuid)));
+ QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(error(QBluetoothUuid)), q_ptr, SLOT(_q_serviceError(QBluetoothUuid)));
+ QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(disconnectedFromService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceDisconnected(QBluetoothUuid)));
+ emit q_ptr->disconnected((QLowEnergyServiceInfo)m_leServices.at(i));
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::connectService(const QLowEnergyServiceInfo &service)
+{
+ errorString = QString();
+ service.d_ptr->characteristicList.clear();
+ bool add = true;
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).serviceUuid() == service.serviceUuid()) {
+ m_leServices.replace(i, service);
+ add = false;
+ break;
+ }
+ }
+ if (add)
+ m_leServices.append(service);
+ process = process->instance();
+ if (!process->isConnected()) {
+ if (m_commandStarted)
+ connectToTerminal();
+ else {
+ QObject::connect(process, SIGNAL(replySend(const QString &)), q_ptr, SLOT(_q_replyReceived(const QString &)));
+ QString command = QStringLiteral("gatttool -i ") + service.d_ptr->adapterAddress.toString() + QStringLiteral(" -b ") + service.d_ptr->deviceInfo.address().toString() + QStringLiteral(" -I");
+ if (m_randomAddress)
+ command += QStringLiteral(" -t random");
+ qCDebug(QT_BT_BLUEZ) << "[REGISTER] uuid inside: " << service.d_ptr->uuid << command;
+ process->startCommand(command);
+ m_commandStarted = true;
+ }
+ process->addConnection();
+ }
+ else
+ service.d_ptr->m_step = 1;
+}
+
+void QLowEnergyControllerPrivate::disconnectService(const QLowEnergyServiceInfo &service)
+{
+ if (service.isValid()) {
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).serviceUuid() == service.serviceUuid() && service.isConnected()) {
+ process = process->instance();
+ process->endProcess();
+ m_leServices.at(i).d_ptr->connected = false;
+ m_leServices.at(i).d_ptr->m_step = 0;
+ m_leServices.at(i).d_ptr->m_valueCounter = 0;
+ m_leServices.removeAt(i);
+ emit q_ptr->disconnected(service);
+ break;
+ }
+ }
+ }
+ else
+ disconnectAllServices();
+}
+
+void QLowEnergyControllerPrivate::_q_replyReceived(const QString &reply)
+{
+ qCDebug(QT_BT_BLUEZ) << "reply: " << reply;
+ // STEP 0
+ if (m_step == 0 && !m_leServices.isEmpty())
+ connectToTerminal();
+ if (reply.contains(QStringLiteral("Connection refused (111)"))) {
+ errorString = QStringLiteral("Connection refused (111)");
+ disconnectAllServices();
+ }
+ else if (reply.contains(QStringLiteral("Device busy"))) {
+ errorString = QStringLiteral("Connection refused (111)");
+ disconnectAllServices();
+ }
+ else if (reply.contains(QStringLiteral("disconnected"))) {
+ errorString = QStringLiteral("Trying to execute command on disconnected service");
+ disconnectAllServices();
+ }
+ else {
+ // STEP 1
+ if (reply.contains(QStringLiteral("[CON]"))) {
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).d_ptr->m_step == 1) {
+ setHandles();
+ m_leServices.at(i).d_ptr->m_step++;
+ }
+ }
+ }
+
+ // STEP 2
+ if (reply.contains(QStringLiteral("attr")) && reply.contains(QStringLiteral("uuid"))){
+ const QStringList handles = reply.split(QStringLiteral("\n"));
+ foreach (const QString &handle, handles) {
+ if (handle.contains(QStringLiteral("attr")) && handle.contains(QStringLiteral("uuid"))) {
+ const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("[\\s+|,]")),
+ QString::SkipEmptyParts);
+ Q_ASSERT(handleDetails.count() == 9);
+ const QBluetoothUuid foundUuid(handleDetails.at(8));
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (foundUuid == m_leServices.at(i).serviceUuid() && m_leServices.at(i).d_ptr->m_step == 2) {
+ m_leServices.at(i).d_ptr->startingHandle = handleDetails.at(2);
+ m_leServices.at(i).d_ptr->endingHandle = handleDetails.at(6);
+ setCharacteristics(i);
+ }
+ }
+ }
+ }
+ }
+
+ // STEP 3
+ if (reply.contains(QStringLiteral("char")) && reply.contains(QStringLiteral("uuid")) && reply.contains(QStringLiteral("properties"))) {
+ const QStringList handles = reply.split(QStringLiteral("\n"));
+ int stepSet = -1;
+ foreach (const QString& handle, handles) {
+ if (handle.contains(QStringLiteral("char")) && handle.contains(QStringLiteral("uuid"))) {
+ const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("[\\s+|,]")),
+ QString::SkipEmptyParts);
+ Q_ASSERT(handleDetails.count() == 11);
+ const QString charHandle = handleDetails.at(8);
+ ushort charHandleId = charHandle.toUShort(0, 0);
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if ( charHandleId >= m_leServices.at(i).d_ptr->startingHandle.toUShort(0,0) &&
+ charHandleId <= m_leServices.at(i).d_ptr->endingHandle.toUShort(0,0))
+ {
+ const QBluetoothUuid charUuid(handleDetails.at(10));
+ QVariantMap map;
+
+ QLowEnergyCharacteristicInfo charInfo(charUuid);
+ charInfo.d_ptr->handle = charHandle;
+ charInfo.d_ptr->startingHandle = handleDetails.at(1);
+ charInfo.d_ptr->permission = handleDetails.at(4).toUShort(0,0);
+ map[QStringLiteral("uuid")] = charUuid.toString();
+ map[QStringLiteral("handle")] = charHandle;
+ map[QStringLiteral("permission")] = charInfo.d_ptr->permission;
+ charInfo.d_ptr->properties = map;
+ if (!(charInfo.d_ptr->permission & QLowEnergyCharacteristicInfo::Read))
+ qCDebug(QT_BT_BLUEZ) << "GATT characteristic: Read not permitted: " << charInfo.d_ptr->uuid;
+ else
+ m_leServices.at(i).d_ptr->m_readCounter++;
+ m_leServices.at(i).d_ptr->characteristicList.append(charInfo);
+ stepSet = i;
+ break;
+ }
+ }
+ }
+ }
+ if ( stepSet != -1)
+ readCharacteristicValue(stepSet);
+ }
+
+ // STEP 4 and STEP 5
+ // This part is for reading characteristic values and setting the notifications
+ if (reply.contains(QStringLiteral("handle")) && reply.contains(QStringLiteral("value")) && !reply.contains(QStringLiteral("char"))) {
+ int index = -1; // setting characteristics values
+ int index1 = -1; // setting notifications and descriptors
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).d_ptr->m_step == 4)
+ index = i;
+ if (m_leServices.at(i).d_ptr->m_step == 5)
+ index1 = i;
+ }
+ const QStringList handles = reply.split(QStringLiteral("\n"));
+ bool lastStep = false;
+ foreach (const QString &handle, handles) {
+ if (handle.contains(QStringLiteral("handle")) &&
+ handle.contains(QStringLiteral("value")))
+ {
+ const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("\\W+")), QString::SkipEmptyParts);
+ if (index != -1) {
+ if (!m_leServices.at(index).d_ptr->characteristicList.isEmpty()) {
+ for (int j = 0; j < m_leServices.at(index).d_ptr->characteristicList.size(); j++) {
+ const QLowEnergyCharacteristicInfo chars = m_leServices.at(index).d_ptr->characteristicList.at(j);
+ const QString handleId = handleDetails.at(1);
+ qCDebug(QT_BT_BLUEZ) << handleId << handleId.toUShort(0,0) << chars.handle() << chars.handle().toUShort(0,0);
+ if (handleId.toUShort(0,0) == chars.handle().toUShort(0,0)) {
+ QString value;
+ for ( int k = 3; k < handleDetails.size(); k++)
+ value = value + handleDetails.at(k);
+ m_leServices.at(index).d_ptr->characteristicList[j].d_ptr->value = value.toUtf8();
+ qCDebug(QT_BT_BLUEZ) << "Characteristic value set." << m_leServices.at(index).d_ptr->characteristicList[j].uuid() << chars.d_ptr->handle << value;
+ m_leServices.at(index).d_ptr->m_valueCounter++;
+ }
+ }
+ }
+ if (m_leServices.at(index).d_ptr->m_valueCounter == m_leServices.at(index).d_ptr->m_readCounter) {
+ setNotifications();
+ m_leServices.at(index).d_ptr->m_step++;
+ }
+ }
+ if (index1 != -1) {
+ for (int j = 0; j < (m_leServices.at(index1).d_ptr->characteristicList.size()-1); j++) {
+ QLowEnergyCharacteristicInfo chars = m_leServices.at(index1).d_ptr->characteristicList.at(j);
+ QLowEnergyCharacteristicInfo charsNext = m_leServices.at(index1).d_ptr->characteristicList.at(j+1);
+ const QString handleId = handleDetails.at(1);
+ ushort h = handleId.toUShort(0, 0);
+ qCDebug(QT_BT_BLUEZ) << handleId << h << chars.handle() << chars.handle().toUShort(0,0);
+
+ if (h > chars.handle().toUShort(0,0) && h < charsNext.handle().toUShort(0,0)) {
+ chars.d_ptr->notificationHandle = handleId;
+ chars.d_ptr->notification = true;
+ QBluetoothUuid descUuid((ushort)0x2902);
+ QLowEnergyDescriptorInfo descriptor(descUuid, handleId);
+ QString val;
+ //TODO why do we start parsing value from k = 0? Shouldn't it be k = 2
+ for (int k = 3; k < handleDetails.size(); k++)
+ val = val + handleDetails.at(k);
+ descriptor.d_ptr->m_value = val.toUtf8();
+ QVariantMap map;
+ map[QStringLiteral("uuid")] = descUuid.toString();
+ map[QStringLiteral("handle")] = handleId;
+ map[QStringLiteral("value")] = val.toUtf8();
+ m_leServices.at(index1).d_ptr->characteristicList[j].d_ptr->descriptorsList.append(descriptor);
+ qCDebug(QT_BT_BLUEZ) << "Notification characteristic set." << chars.d_ptr->handle << chars.d_ptr->notificationHandle;
+ }
+ }
+ if (!lastStep) {
+ m_leServices.at(index1).d_ptr->m_step++;
+ m_leServices.at(index1).d_ptr->connected = true;
+ emit q_ptr->connected(m_leServices.at(index1));
+ }
+ lastStep = true;
+ }
+ }
+ }
+ }
+
+ // READING ADVERTISEMENT FROM THE BLE DEVICE
+ if (reply.contains(QStringLiteral("Notification handle"))) {
+ QStringList update, row;
+ update = reply.split(QStringLiteral("\n"));
+ for (int i = 0; i< update.size(); i ++) {
+ if (update.at(i).contains(QStringLiteral("Notification handle"))) {
+ row = update.at(i).split(QRegularExpression(QStringLiteral("\\W+")), QString::SkipEmptyParts);
+ for (int j = 0; j < m_leServices.size(); j++) {
+ for (int k = 0; k < m_leServices.at(j).characteristics().size(); k++) {
+ if (m_leServices.at(j).characteristics().at(k).handle() == row.at(2)) {
+
+ QString notificationValue = QStringLiteral("");
+ for (int s = 4 ; s< row.size(); s++)
+ notificationValue += row.at(s);
+ m_leServices.at(j).characteristics().at(k).d_ptr->value = notificationValue.toUtf8();
+ m_leServices.at(j).characteristics().at(k).d_ptr->properties[QStringLiteral("value")] = notificationValue.toUtf8();
+ emit q_ptr->valueChanged(m_leServices.at(j).characteristics().at(k));
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::disconnectAllServices()
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ process = process->instance();
+ process->endProcess();
+ m_leServices.at(i).d_ptr->m_step = 0;
+ m_leServices.at(i).d_ptr->m_valueCounter = 0;
+ if (m_leServices.at(i).isConnected()) {
+ m_leServices.at(i).d_ptr->connected = false;
+ emit q_ptr->disconnected(m_leServices.at(i));
+ }
+ if (errorString != QString())
+ emit q_ptr->error(m_leServices.at(i));
+ m_step = 0;
+ }
+ m_leServices.clear();
+}
+
+void QLowEnergyControllerPrivate::connectToTerminal()
+{
+ process->executeCommand(QStringLiteral("connect"));
+ process->executeCommand(QStringLiteral("\n"));
+ for (int i = 0; i < m_leServices.size(); i++)
+ m_leServices.at(i).d_ptr->m_step = 1;
+ m_step++;
+}
+
+void QLowEnergyControllerPrivate::setHandles()
+{
+ process->executeCommand(QStringLiteral("primary"));
+ process->executeCommand(QStringLiteral("\n"));
+ m_step++;
+}
+
+void QLowEnergyControllerPrivate::setCharacteristics(int a)
+{
+ const QString command = QStringLiteral("characteristics ") + m_leServices.at(a).d_ptr->startingHandle + QStringLiteral(" ") + m_leServices.at(a).d_ptr->endingHandle;
+ process->executeCommand(command);
+ process->executeCommand(QStringLiteral("\n"));
+ m_leServices.at(a).d_ptr->m_step++;
+}
+
+void QLowEnergyControllerPrivate::setNotifications()
+{
+ process->executeCommand(QStringLiteral("char-read-uuid 2902"));
+ process->executeCommand(QStringLiteral("\n"));
+}
+
+void QLowEnergyControllerPrivate::readCharacteristicValue(int index)
+{
+ for (int i = 0; i < m_leServices.at(index).d_ptr->characteristicList.size(); i++) {
+ if ((m_leServices.at(index).d_ptr->characteristicList.at(i).d_ptr->permission & QLowEnergyCharacteristicInfo::Read)) {
+ const QString uuidHandle = m_leServices.at(index).d_ptr->characteristicList.at(i).uuid().toString().remove(QLatin1Char('{')).remove(QLatin1Char('}'));
+ const QString command = QStringLiteral("char-read-uuid ") + uuidHandle;
+ process->executeCommand(command);
+ process->executeCommand(QStringLiteral("\n"));
+ }
+ }
+ m_leServices.at(index).d_ptr->m_step++;
+}
+
+void QLowEnergyControllerPrivate::writeValue(const QString &handle, const QByteArray &value)
+{
+ process = process->instance();
+ QString command = QStringLiteral("char-write-req ") + handle + QStringLiteral(" ") + QString::fromLocal8Bit(value.constData());
+ process->executeCommand(command);
+ process->executeCommand(QStringLiteral("\n"));
+
+}
+
+bool QLowEnergyControllerPrivate::enableNotification(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ bool foundCharacteristic = false;
+ bool foundDescriptor = false;
+ const QBluetoothUuid descUuid((ushort)0x2902);
+ for (int i = 0; i < m_leServices.size(); i++) {
+ for (int j = 0; j < m_leServices.at(i).characteristics().size(); j++) {
+ if (m_leServices.at(i).characteristics().at(j).uuid() == characteristic.uuid()) {
+ foundCharacteristic = true;
+ for (int k = 0; k < m_leServices.at(i).characteristics().at(j).descriptors().size(); k++) {
+ if (m_leServices.at(i).characteristics().at(j).descriptors().at(k).uuid() == descUuid){
+ foundDescriptor = true;
+ QByteArray val;
+ val.append(48);
+ val.append(49);
+ val.append(48);
+ val.append(48);
+ writeValue(m_leServices.at(i).characteristics().at(j).descriptors().at(k).handle(), val);
+ return true;
+ }
+ }
+ }
+ }
+ }
+ if (!foundDescriptor || !foundCharacteristic) {
+ errorString = QStringLiteral("Characteristic or notification descriptor not found.");
+ emit q_ptr->error(characteristic);
+ return false;
+ }
+
+}
+
+void QLowEnergyControllerPrivate::disableNotification(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ const QBluetoothUuid descUuid((ushort)0x2902);
+ for (int i = 0; i < m_leServices.size(); i++) {
+ for (int j = 0; j < m_leServices.at(i).characteristics().size(); j++) {
+ if (m_leServices.at(i).characteristics().at(j).uuid() == characteristic.uuid()) {
+ for (int k = 0; k < m_leServices.at(i).characteristics().at(j).descriptors().size(); k++) {
+ if (m_leServices.at(i).characteristics().at(j).descriptors().at(k).uuid() == descUuid){
+ QByteArray val;
+ val.append(48);
+ val.append(48);
+ val.append(48);
+ val.append(48);
+ writeValue(m_leServices.at(i).characteristics().at(j).descriptors().at(k).handle(), val);
+ }
+ }
+ }
+ }
+ }
+}
+
+bool QLowEnergyControllerPrivate::write(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ if (process->isConnected() && characteristic.isValid()) {
+ if (QLowEnergyCharacteristicInfo::Write & characteristic.permissions()) {
+ writeValue(characteristic.handle(), characteristic.value());
+ return true;
+ } else {
+ errorString = QStringLiteral("This characteristic does not support write operations.");
+ emit q_ptr->error(characteristic);
+ return false;
+ }
+ } else {
+ errorString = QStringLiteral("The device is not connected or characteristic is not valid");
+ emit q_ptr->error(characteristic);
+ return false;
+ }
+}
+
+bool QLowEnergyControllerPrivate::write(const QLowEnergyDescriptorInfo &descriptor)
+{
+ if (process->isConnected()) {
+ writeValue(descriptor.handle(), descriptor.value());
+ return true;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller_p.cpp b/src/bluetooth/qlowenergycontroller_p.cpp
new file mode 100644
index 00000000..66230585
--- /dev/null
+++ b/src/bluetooth/qlowenergycontroller_p.cpp
@@ -0,0 +1,120 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycontroller_p.h"
+#include "moc_qlowenergycontroller.cpp"
+
+QT_BEGIN_NAMESPACE
+
+QLowEnergyControllerPrivate::QLowEnergyControllerPrivate()
+{
+
+}
+
+QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate()
+{
+
+}
+
+void QLowEnergyControllerPrivate::connectService(const QLowEnergyServiceInfo &service)
+{
+ Q_UNUSED(service);
+}
+
+void QLowEnergyControllerPrivate::disconnectService(const QLowEnergyServiceInfo &leService)
+{
+ Q_UNUSED(leService);
+}
+
+void QLowEnergyControllerPrivate::disconnectAllServices()
+{
+
+}
+
+void QLowEnergyControllerPrivate::_q_characteristicError(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_serviceConnected(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_serviceDisconnected(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_serviceError(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_valueReceived(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+bool QLowEnergyControllerPrivate::enableNotification(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ Q_UNUSED(characteristic);
+ return false;
+}
+
+void QLowEnergyControllerPrivate::disableNotification(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ Q_UNUSED(characteristic);
+}
+
+bool QLowEnergyControllerPrivate::write(const QLowEnergyCharacteristicInfo &characteristic)
+{
+ Q_UNUSED(characteristic);
+ return false;
+}
+
+bool QLowEnergyControllerPrivate::write(const QLowEnergyDescriptorInfo &descriptor)
+{
+ Q_UNUSED(descriptor);
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
new file mode 100644
index 00000000..826f88c1
--- /dev/null
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -0,0 +1,94 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QLOWENERGYCONTROLLER_P_H
+#define QLOWENERGYCONTROLLER_P_H
+#include "qlowenergycontroller.h"
+
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyController;
+class QLowEnergyProcess;
+
+class QLowEnergyControllerPrivate
+{
+ Q_DECLARE_PUBLIC(QLowEnergyController)
+public:
+ QLowEnergyControllerPrivate();
+ ~QLowEnergyControllerPrivate();
+ void connectService(const QLowEnergyServiceInfo &service);
+ void disconnectService(const QLowEnergyServiceInfo &leService = QLowEnergyServiceInfo());
+ bool enableNotification(const QLowEnergyCharacteristicInfo &characteristic);
+ void disableNotification(const QLowEnergyCharacteristicInfo &characteristic);
+ bool write(const QLowEnergyCharacteristicInfo &characteristic);
+ bool write(const QLowEnergyDescriptorInfo &descriptor);
+
+ void _q_serviceConnected(const QBluetoothUuid &uuid);
+ void _q_serviceError(const QBluetoothUuid &uuid);
+ void _q_characteristicError(const QBluetoothUuid &uuid);
+ void _q_valueReceived(const QBluetoothUuid &uuid);
+ void _q_serviceDisconnected(const QBluetoothUuid &uuid);
+ void disconnectAllServices();
+
+ QList<QLowEnergyServiceInfo> m_leServices;
+ QString errorString;
+
+#ifdef QT_BLUEZ_BLUETOOTH
+ void connectToTerminal();
+ void setHandles();
+ void setCharacteristics(int);
+ void setNotifications();
+ void readCharacteristicValue(int);
+ void writeValue(const QString &, const QByteArray &);
+public slots:
+ void _q_replyReceived(const QString &reply);
+#endif
+private:
+ bool m_randomAddress;
+#ifdef QT_BLUEZ_BLUETOOTH
+ QLowEnergyProcess *process;
+ int m_step;
+ bool m_deviceConnected;
+ bool m_commandStarted;
+#endif
+ QLowEnergyController *q_ptr;
+};
+QT_END_NAMESPACE
+#endif // QLOWENERGYCONTROLLER_P_H
diff --git a/src/bluetooth/qlowenergydescriptorinfo.cpp b/src/bluetooth/qlowenergydescriptorinfo.cpp
new file mode 100644
index 00000000..f18276ba
--- /dev/null
+++ b/src/bluetooth/qlowenergydescriptorinfo.cpp
@@ -0,0 +1,175 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergydescriptorinfo.h"
+#include "qlowenergydescriptorinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QLowEnergyDescriptorInfo
+ \inmodule QtBluetooth
+ \brief The QLowEnergyDescriptorInfo class stores information about the Bluetooth
+ Low Energy descriptor.
+
+ QLowEnergyDescriptorInfo provides information about a Bluetooth Low Energy
+ descriptor's name, UUID, value and handle. Descriptors are contained in the
+ Bluetooth Low Energy characteristic and they provide additional information
+ about the characteristic (data format, notification activation, etc).
+*/
+
+QString parseDescriptorUuid(const QBluetoothUuid &uuid)
+{
+ static QHash<int, QString> uuidnames;
+ if ( uuidnames.isEmpty() ) {
+ uuidnames[0x2905] = QStringLiteral("Characteristic Aggregate Format");
+ uuidnames[0x2900] = QStringLiteral("Characteristic Extended Properties");
+ uuidnames[0x2904] = QStringLiteral("Characteristic Presentation Format");
+ uuidnames[0x2901] = QStringLiteral("Characteristic User Description");
+ uuidnames[0x2902] = QStringLiteral("Client Characteristic Configuration");
+ uuidnames[0x2907] = QStringLiteral("External Report Reference");
+ uuidnames[0x2908] = QStringLiteral("Report Reference");
+ uuidnames[0x2903] = QStringLiteral("Server Characteristic Configuration");
+ uuidnames[0x2906] = QStringLiteral("Valid Range");
+ }
+ QString name = uuidnames.value(uuid.toUInt16(), QStringLiteral("Unknow Descriptor"));
+ return name;
+}
+
+QLowEnergyDescriptorInfoPrivate::QLowEnergyDescriptorInfoPrivate(const QBluetoothUuid &uuid, const QString &handle):
+ m_value(QByteArray()), m_uuid(uuid), m_handle(handle), m_properties(QVariantMap()), m_name(QStringLiteral(""))
+{
+
+}
+
+QLowEnergyDescriptorInfoPrivate::~QLowEnergyDescriptorInfoPrivate()
+{
+
+}
+
+/*!
+ Construct a new QLowEnergyCharacteristicInfo with given \a uuid.
+*/
+QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid):
+ d_ptr(new QLowEnergyDescriptorInfoPrivate(uuid, QStringLiteral("0x0000")))
+{
+
+}
+
+/*!
+ Construct a new QLowEnergyDescriptorInfo with given \a uuid and the \a handle.
+*/
+QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, const QString &handle):
+ d_ptr(new QLowEnergyDescriptorInfoPrivate(uuid, handle))
+{
+ d_ptr->m_name = parseDescriptorUuid(uuid);
+}
+
+/*!
+ Destroys the QLowEnergyDescriptorInfo object.
+*/
+QLowEnergyDescriptorInfo::~QLowEnergyDescriptorInfo()
+{
+
+}
+
+/*!
+ Makes a copy of the \a other and assigns it to this QLowEnergyDescriptorInfo object.
+ The two copies continue to share the same service and registration details.
+*/
+QLowEnergyDescriptorInfo &QLowEnergyDescriptorInfo::operator=(const QLowEnergyDescriptorInfo &other)
+{
+ d_ptr = other.d_ptr;
+ return *this;
+}
+
+/*!
+ Returns the UUID of the descriptor.
+*/
+QBluetoothUuid QLowEnergyDescriptorInfo::uuid() const
+{
+ return d_ptr->m_uuid;
+}
+
+/*!
+ Returns the handle of the descriptor.
+*/
+QString QLowEnergyDescriptorInfo::handle() const
+{
+ return d_ptr->m_handle;
+}
+
+/*!
+ Returns the value of the descriptor.
+*/
+QByteArray QLowEnergyDescriptorInfo::value() const
+{
+ return d_ptr->m_value;
+}
+
+/*!
+ Returns the properties of the descriptor.
+*/
+QVariantMap QLowEnergyDescriptorInfo::properties() const
+{
+ return d_ptr->m_properties;
+}
+
+/*!
+ Returns the name of the descriptor.
+*/
+QString QLowEnergyDescriptorInfo::name() const
+{
+ return d_ptr->m_name;
+}
+
+/*!
+ Sets the value \a value of the descriptor. This only caches the value. To write
+ a value directly to the device QLowEnergyController class must be used.
+
+ \sa QLowEnergyController::writeDescriptor()
+*/
+void QLowEnergyDescriptorInfo::setValue(const QByteArray &value)
+{
+ d_ptr->m_value = value;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergydescriptorinfo.h b/src/bluetooth/qlowenergydescriptorinfo.h
new file mode 100644
index 00000000..925ea122
--- /dev/null
+++ b/src/bluetooth/qlowenergydescriptorinfo.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYDESCRIPTORINFO_H
+#define QLOWENERGYDESCRIPTORINFO_H
+
+#include <QtCore/QSharedPointer>
+#include <QtCore/QVariantMap>
+#include <QtBluetooth/QBluetoothUuid>
+
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyCharacteristicInfo;
+class QLowEnergyDescriptorInfoPrivate;
+
+class Q_BLUETOOTH_EXPORT QLowEnergyDescriptorInfo
+{
+ friend class QLowEnergyCharacteristicInfo;
+ friend class QLowEnergyCharacteristicInfoPrivate;
+ friend class QLowEnergyServiceInfoPrivate;
+ friend class QLowEnergyControllerPrivate;
+public:
+ explicit QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid);
+ ~QLowEnergyDescriptorInfo();
+
+ QLowEnergyDescriptorInfo &operator=(const QLowEnergyDescriptorInfo &other);
+ QByteArray value() const;
+ QBluetoothUuid uuid() const;
+ QString handle() const;
+ QVariantMap properties() const;
+ QString name() const;
+ void setValue(const QByteArray &value);
+
+private:
+ QSharedPointer<QLowEnergyDescriptorInfoPrivate> d_ptr;
+ QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, const QString &handle);
+};
+
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYDESCRIPTORINFO_H
diff --git a/src/bluetooth/qlowenergydescriptorinfo_p.h b/src/bluetooth/qlowenergydescriptorinfo_p.h
new file mode 100644
index 00000000..e167859f
--- /dev/null
+++ b/src/bluetooth/qlowenergydescriptorinfo_p.h
@@ -0,0 +1,59 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYDESCRIPTORINFO_P_H
+#define QLOWENERGYDESCRIPTORINFO_P_H
+
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyDescriptorInfoPrivate
+{
+public:
+ QLowEnergyDescriptorInfoPrivate(const QBluetoothUuid &uuid, const QString &handle);
+ ~QLowEnergyDescriptorInfoPrivate();
+ QByteArray m_value;
+ QBluetoothUuid m_uuid;
+ QString m_handle;
+ QVariantMap m_properties;
+ QString m_name;
+};
+QT_END_NAMESPACE
+#endif // QLOWENERGYDESCRIPTORINFO_P_H
diff --git a/src/bluetooth/qlowenergyprocess_bluez.cpp b/src/bluetooth/qlowenergyprocess_bluez.cpp
new file mode 100644
index 00000000..26013273
--- /dev/null
+++ b/src/bluetooth/qlowenergyprocess_bluez.cpp
@@ -0,0 +1,145 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyprocess_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QLowEnergyProcess, processInstance)
+
+/*!
+ * Private constructor. Constructs the new QLowEnergyProcess, sets variables and connects
+ * signal to a slot.
+ */
+QLowEnergyProcess::QLowEnergyProcess()
+{
+ m_process = new QProcess();
+ connected = false;
+ m_counter = 0;
+ connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(replyRead()));
+}
+
+/*!
+ Destroys the QLowEnergyProcess object.
+*/
+QLowEnergyProcess::~QLowEnergyProcess()
+{
+ m_process->kill();
+ delete m_process;
+}
+
+/*!
+ Returns the instance of this clas. This class is a singleton class.
+*/
+
+QLowEnergyProcess *QLowEnergyProcess::instance()
+{
+ return processInstance();
+}
+
+/*!
+ Returns the QProcess that this class is using.
+*/
+QProcess *QLowEnergyProcess::getProcess()
+{
+ return m_process;
+}
+
+/*!
+ Slot that emits a signal replySend. This slot is connected with QProcess signal
+ and it is called whenever something comes to output.
+*/
+void QLowEnergyProcess::replyRead()
+{
+ QByteArray result = m_process->readAll();
+ QString back = QString::fromLocal8Bit(result.data());
+ if (back.size() > 10)
+ emit replySend(back);
+}
+
+/*!
+ Starts the process with \a command. This method is used only when starting the
+ process.
+
+ \sa executeCommand()
+*/
+void QLowEnergyProcess::startCommand(const QString &command)
+{
+ m_process->start(command);
+ if (!m_process->waitForStarted())
+ qDebug() << "Could not start the process under the command: "<<command;
+}
+
+/*!
+ Executes the \a command. This method is called after process started.
+
+ \sa startCommand()
+*/
+void QLowEnergyProcess::executeCommand(const QString &command)
+{
+ m_process->write(command.toUtf8().constData());
+}
+
+/*!
+ Terminate running process.
+*/
+void QLowEnergyProcess::endProcess()
+{
+ m_counter--;
+ if (m_counter == 0) {
+ executeCommand(QStringLiteral("disconnect"));
+ executeCommand(QStringLiteral("\n"));
+ connected = false;
+ }
+}
+
+bool QLowEnergyProcess::isConnected() const
+{
+ return connected;
+}
+
+void QLowEnergyProcess::addConnection()
+{
+ m_counter++;
+ connected = true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergyprocess_p.cpp b/src/bluetooth/qlowenergyprocess_p.cpp
new file mode 100644
index 00000000..3303bef0
--- /dev/null
+++ b/src/bluetooth/qlowenergyprocess_p.cpp
@@ -0,0 +1,68 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyprocess_p.h"
+
+QLowEnergyProcess::QLowEnergyProcess()
+{
+
+}
+
+/*!
+ Destroys the QLowEnergyProcess object.
+*/
+QLowEnergyProcess::~QLowEnergyProcess()
+{
+
+}
+
+/*!
+ Returns the instance of this class. This class is a singleton class.
+*/
+QLowEnergyProcess *QLowEnergyProcess::instance()
+{
+ return 0;
+}
+
+bool QLowEnergyProcess::isConnected() const
+{
+ return false;
+}
diff --git a/src/bluetooth/qlowenergyprocess_p.h b/src/bluetooth/qlowenergyprocess_p.h
new file mode 100644
index 00000000..3f65b1e7
--- /dev/null
+++ b/src/bluetooth/qlowenergyprocess_p.h
@@ -0,0 +1,98 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYPROCESS_H
+#define QLOWENERGYPROCESS_H
+
+#include <QtCore>
+#include <QObject>
+#ifdef QT_QNX_BLUETOOTH
+#include <QList>
+#include <QPointer>
+#include "qlowenergyserviceinfo_p.h"
+#endif
+#ifdef QT_BLUEZ_BLUETOOTH
+#include <QProcess>
+#endif
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyProcess: public QObject
+{
+ Q_OBJECT
+ friend class QLowEnergyServiceInfoPrivate;
+public:
+ QLowEnergyProcess();
+ ~QLowEnergyProcess();
+
+ static QLowEnergyProcess *instance();
+ bool isConnected() const;
+#ifdef QT_QNX_BLUETOOTH
+ static void handleEvent(const int, const char *, const char *);
+ void addPointer(QLowEnergyServiceInfoPrivate* classPointer);
+#endif
+#ifdef QT_BLUEZ_BLUETOOTH
+ QProcess *getProcess();
+
+ void startCommand(const QString &command);
+ void executeCommand(const QString &command);
+ void endProcess();
+ void addConnection();
+
+Q_SIGNALS:
+ void replySend(const QString &reply);
+
+private slots:
+ void replyRead();
+#endif
+
+private:
+#ifdef QT_BLUEZ_BLUETOOTH
+ QProcess *m_process;
+ int m_counter;
+#endif
+#ifdef QT_QNX_BLUETOOTH
+ QList<QObject*> m_classPointers;
+#endif
+ bool connected;
+};
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYPROCESS_H
diff --git a/src/bluetooth/qlowenergyprocess_qnx.cpp b/src/bluetooth/qlowenergyprocess_qnx.cpp
new file mode 100644
index 00000000..1fa8cc48
--- /dev/null
+++ b/src/bluetooth/qlowenergyprocess_qnx.cpp
@@ -0,0 +1,96 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyprocess_p.h"
+#include <btapi/btdevice.h>
+#include <errno.h>
+#include "qlowenergyserviceinfo.h"
+#include "qlowenergyserviceinfo_p.h"
+#include <btapi/btgatt.h>
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QLowEnergyProcess, processInstance)
+
+void QLowEnergyProcess::handleEvent(const int event, const char *bt_address, const char *event_data)
+{
+ qDebug() << "[HANDLE Event] (event, address, event data): " << event << bt_address << event_data;
+}
+
+QLowEnergyProcess::QLowEnergyProcess()
+{
+ connected = false;
+ if (bt_device_init( &(this->handleEvent) ) < 0)
+ qDebug() << "[INIT] Init problem." << errno << strerror(errno);
+ else
+ connected = true;
+
+}
+
+/*!
+ Destroys the QLowEnergyProcess object.
+*/
+QLowEnergyProcess::~QLowEnergyProcess()
+{
+ bt_device_deinit();
+ bt_gatt_deinit();
+ qDeleteAll(m_classPointers);
+ m_classPointers.clear();
+}
+
+/*!
+ Returns the instance of this clas. This class is a singleton class.
+*/
+
+QLowEnergyProcess *QLowEnergyProcess::instance()
+{
+ return processInstance();
+}
+
+bool QLowEnergyProcess::isConnected() const
+{
+ return connected;
+}
+
+void QLowEnergyProcess::addPointer(QLowEnergyServiceInfoPrivate* classPointer)
+{
+ m_classPointers.append(classPointer);
+}
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergyserviceinfo.cpp b/src/bluetooth/qlowenergyserviceinfo.cpp
new file mode 100644
index 00000000..23ead34e
--- /dev/null
+++ b/src/bluetooth/qlowenergyserviceinfo.cpp
@@ -0,0 +1,242 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyserviceinfo.h"
+#include "qlowenergyserviceinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QLowEnergyServiceInfo
+ \inmodule QtBluetooth
+ \brief The QLowEnergyServiceInfo class stores information about the Bluetooth
+ Low Energy service.
+
+ QLowEnergyServiceInfo provides information about a Bluetooth Low Energy
+ service's name, device, UUID, connection status, service type, handle
+ and characteristics. A Bluetooth Low Energy device can have one or more
+ low energy services. Each low energy service contains one or more
+ characteristics. The class is used with the QLowEnergyController
+ class. It is necessary to connect to the service first in order
+ to get the all service information and characteristics.
+*/
+
+/*!
+ \enum QLowEnergyServiceInfo::ServiceType
+
+ This enum describes the type of the service. One LE device can have one or more primary services.
+
+ \value PrimaryService The primary service. The primary service can have one or
+ more included services.
+ \value IncludedService The included service by primary services.
+*/
+
+/*!
+ Method for parsing the service name with given \a uuid.
+ * \brief parseUuid
+ * \param uuid
+ * \return
+ */
+QString parseUuid(const QBluetoothUuid &uuid)
+{
+ static QHash<int, QString> uuidnames;
+ if ( uuidnames.isEmpty() ) {
+ uuidnames[0x1800] = QStringLiteral("Generic Access");
+ uuidnames[0x1801] = QStringLiteral("Generic Attribute");
+ uuidnames[0x1802] = QStringLiteral("ImmediateAlert");
+ uuidnames[0x1803] = QStringLiteral("Link Loss");
+ uuidnames[0x1804] = QStringLiteral("Tx Power");
+ uuidnames[0x1805] = QStringLiteral("Current Time Service");
+ uuidnames[0x1806] = QStringLiteral("Reference Time Update Service");
+ uuidnames[0x1807] = QStringLiteral("Next DST Change Service");
+ uuidnames[0x1808] = QStringLiteral("Glucose");
+ uuidnames[0x1809] = QStringLiteral("Health Thermometer");
+ uuidnames[0x180A] = QStringLiteral("Device Information");
+ uuidnames[0x180D] = QStringLiteral("Heart Rate");
+ uuidnames[0x180E] = QStringLiteral("Phone Alert Status Service");
+ uuidnames[0x180F] = QStringLiteral("Battery Service");
+ uuidnames[0x1810] = QStringLiteral("Blood Pressure");
+ uuidnames[0x1811] = QStringLiteral("Alert Notification Service");
+ uuidnames[0x1812] = QStringLiteral("Human Interface Device");
+ uuidnames[0x1813] = QStringLiteral("Scan Parameters");
+ uuidnames[0x1814] = QStringLiteral("Running Speed and Cadance");
+ uuidnames[0x1816] = QStringLiteral("Cycling Speed and Cadance");
+ uuidnames[0x1818] = QStringLiteral("Cycling Power");
+ uuidnames[0x1819] = QStringLiteral("Location and Navigation");
+ }
+ QString name = uuidnames.value(uuid.toUInt16(), QStringLiteral("Unknow Service"));
+ return name;
+}
+
+/*!
+ Construct a new QLowEnergyServiceInfo.
+*/
+QLowEnergyServiceInfo::QLowEnergyServiceInfo():
+ d_ptr(QSharedPointer<QLowEnergyServiceInfoPrivate>(new QLowEnergyServiceInfoPrivate))
+{
+
+}
+
+/*!
+ Construct a new QLowEnergyServiceInfo object with the given \a uuid.
+
+ Based on uuid, corresponsing service name is given.
+*/
+QLowEnergyServiceInfo::QLowEnergyServiceInfo(const QBluetoothUuid &uuid):
+ d_ptr(QSharedPointer<QLowEnergyServiceInfoPrivate>(new QLowEnergyServiceInfoPrivate))
+{
+ d_ptr->uuid = QBluetoothUuid(uuid);
+ d_ptr->serviceName = parseUuid(d_ptr->uuid);
+}
+
+/*!
+ Construct a new QLowEnergyServiceInfo that is a copy of \a other.
+
+ The two copies continue to share the same underlying data which does not detach
+ upon write.
+*/
+QLowEnergyServiceInfo::QLowEnergyServiceInfo(const QLowEnergyServiceInfo &other):
+ d_ptr(other.d_ptr)
+{
+
+}
+
+/*!
+ Destroys the QLowEnergyServiceInfo object.
+*/
+QLowEnergyServiceInfo::~QLowEnergyServiceInfo()
+{
+
+}
+
+/*!
+ Returns the gatt service uuid.
+*/
+QBluetoothUuid QLowEnergyServiceInfo::serviceUuid() const
+{
+ return d_ptr->uuid;
+}
+
+/*!
+ Returns the list of service characteristics. If service was not connected, an empty
+ list will be returned.
+*/
+QList<QLowEnergyCharacteristicInfo> QLowEnergyServiceInfo::characteristics() const
+{
+ return d_ptr->characteristicList;
+}
+
+/*!
+ Returns the service name.
+*/
+QString QLowEnergyServiceInfo::serviceName() const
+{
+ return d_ptr->serviceName;
+}
+
+/*!
+ Sets service type with \a type.
+*/
+void QLowEnergyServiceInfo::setServiceType(QLowEnergyServiceInfo::ServiceType type)
+{
+ d_ptr->serviceType = type;
+}
+
+/*!
+ Returns the service type. If setServiceType is not called default service type
+ (PrimaryService) is returned.
+*/
+QLowEnergyServiceInfo::ServiceType QLowEnergyServiceInfo::serviceType() const
+{
+ return d_ptr->serviceType;
+}
+
+/*!
+ Makes a copy of the \a other and assigns it to this QLowEnergyServiceInfo object.
+ The two copies continue to share the same service and registration details.
+*/
+QLowEnergyServiceInfo &QLowEnergyServiceInfo::operator=(const QLowEnergyServiceInfo &other)
+{
+ d_ptr = other.d_ptr;
+ return *this;
+}
+
+/*!
+ Checks whether service is connected.
+ */
+bool QLowEnergyServiceInfo::isConnected() const
+{
+ return d_ptr->connected;
+}
+
+/*!
+ Returns the address of the Bluetooth device that provides this service.
+*/
+QBluetoothDeviceInfo QLowEnergyServiceInfo::device() const
+{
+ return d_ptr->deviceInfo;
+}
+
+/*!
+ Sets the Bluetooth device that provides this service to \a device.
+*/
+void QLowEnergyServiceInfo::setDevice(const QBluetoothDeviceInfo &device)
+{
+ d_ptr->deviceInfo = device;
+}
+
+/*!
+ Returns true if the QLowEnergyServiceInfo object is valid, otherwise returns false.
+*/
+bool QLowEnergyServiceInfo::isValid() const
+{
+ if (d_ptr->uuid == QBluetoothUuid())
+ return false;
+ if (!d_ptr->deviceInfo.isValid())
+ return false;
+ if (!d_ptr->valid())
+ return false;
+ return true;
+}
+
+QT_END_NAMESPACE
+
+
diff --git a/src/bluetooth/qlowenergyserviceinfo.h b/src/bluetooth/qlowenergyserviceinfo.h
new file mode 100644
index 00000000..6fb2316a
--- /dev/null
+++ b/src/bluetooth/qlowenergyserviceinfo.h
@@ -0,0 +1,98 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYSERVICEINFO_H
+#define QLOWENERGYSERVICEINFO_H
+#include <QtCore/QSharedPointer>
+#include <QtBluetooth/QBluetoothAddress>
+#include <QtBluetooth/QBluetoothDeviceInfo>
+#include <QtBluetooth/QBluetoothUuid>
+#include <QtBluetooth/QLowEnergyCharacteristicInfo>
+
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyServiceInfoPrivate;
+class QBluetoothAddress;
+
+class Q_BLUETOOTH_EXPORT QLowEnergyServiceInfo
+{
+ friend class QBluetoothServiceDiscoveryAgent;
+ friend class QBluetoothServiceDiscoveryAgentPrivate;
+ friend class QLowEnergyController;
+ friend class QLowEnergyControllerPrivate;
+public:
+ enum ServiceType {
+ PrimaryService = 0x00000001,
+ IncludedService = 0x00000002
+ };
+
+ QLowEnergyServiceInfo();
+ QLowEnergyServiceInfo(const QBluetoothUuid &uuid);
+ QLowEnergyServiceInfo(const QLowEnergyServiceInfo &other);
+
+ ~QLowEnergyServiceInfo();
+
+ QLowEnergyServiceInfo &operator=(const QLowEnergyServiceInfo &other);
+
+ void setDevice(const QBluetoothDeviceInfo &info);
+ QBluetoothDeviceInfo device() const;
+
+ QBluetoothUuid serviceUuid() const;
+
+ QList<QLowEnergyCharacteristicInfo> characteristics() const;
+
+ QString serviceName() const;
+
+ void setServiceType(QLowEnergyServiceInfo::ServiceType type);
+ QLowEnergyServiceInfo::ServiceType serviceType() const;
+
+ bool isConnected() const;
+
+ bool isValid() const;
+
+protected:
+ QSharedPointer<QLowEnergyServiceInfoPrivate> d_ptr;
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYSERVICEINFO_H
diff --git a/src/bluetooth/qlowenergyserviceinfo_bluez.cpp b/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
new file mode 100644
index 00000000..9e34fee4
--- /dev/null
+++ b/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
@@ -0,0 +1,86 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyserviceinfo_p.h"
+#include "qlowenergyserviceinfo.h"
+#include "qlowenergycharacteristicinfo.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include "qlowenergyprocess_p.h"
+#include "qbluetoothlocaldevice.h"
+#include "bluez/characteristic_p.h"
+#include "qlowenergydescriptorinfo.h"
+#include "qlowenergydescriptorinfo_p.h"
+
+//#define QT_LOWENERGYSERVICE_DEBUG
+
+#ifdef QT_LOWENERGYSERVICE_DEBUG
+#include <QtCore/QDebug>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate():
+ serviceType(QLowEnergyServiceInfo::PrimaryService), connected(false), characteristic(0), m_valueCounter(0), m_readCounter(0)
+{
+ m_step = 0;
+ QBluetoothLocalDevice localDevice;
+ adapterAddress = localDevice.address();
+}
+
+QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate(const QString &servicePath):
+ serviceType(QLowEnergyServiceInfo::PrimaryService), connected(false), path(servicePath), characteristic(0)
+{
+ m_step = 0;
+}
+
+QLowEnergyServiceInfoPrivate::~QLowEnergyServiceInfoPrivate()
+{
+ delete characteristic;
+}
+
+bool QLowEnergyServiceInfoPrivate::valid()
+{
+ if (adapterAddress == QBluetoothAddress())
+ return false;
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergyserviceinfo_p.cpp b/src/bluetooth/qlowenergyserviceinfo_p.cpp
new file mode 100644
index 00000000..0679278b
--- /dev/null
+++ b/src/bluetooth/qlowenergyserviceinfo_p.cpp
@@ -0,0 +1,70 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyserviceinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate()
+{
+
+}
+
+QLowEnergyServiceInfoPrivate::~QLowEnergyServiceInfoPrivate()
+{
+
+}
+
+void QLowEnergyServiceInfoPrivate::registerServiceWatcher()
+{
+
+}
+
+void QLowEnergyServiceInfoPrivate::unregisterServiceWatcher()
+{
+
+}
+
+bool QLowEnergyServiceInfoPrivate::valid()
+{
+ return false;
+}
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergyserviceinfo_p.h b/src/bluetooth/qlowenergyserviceinfo_p.h
new file mode 100644
index 00000000..d033a613
--- /dev/null
+++ b/src/bluetooth/qlowenergyserviceinfo_p.h
@@ -0,0 +1,118 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOWENERGYSERVICEINFO_P_H
+#define QLOWENERGYSERVICEINFO_P_H
+#include "qbluetoothuuid.h"
+#include "qlowenergyserviceinfo.h"
+#include "qlowenergycharacteristicinfo.h"
+#include <QPointer>
+
+#ifdef QT_BLUEZ_BLUETOOTH
+class OrgBluezCharacteristicInterface;
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QBluetoothUuid;
+class QLowEnergyServiceInfo;
+class QLowEnergyCharacteristicInfo;
+class QLowEnergyProcess;
+
+class QLowEnergyServiceInfoPrivate: public QObject
+{
+ Q_OBJECT
+ friend class QLowEnergyControllerPrivate;
+
+public:
+ QLowEnergyServiceInfoPrivate();
+#ifdef QT_BLUEZ_BLUETOOTH
+ QLowEnergyServiceInfoPrivate(const QString &servicePath);
+#endif
+ ~QLowEnergyServiceInfoPrivate();
+
+ void registerServiceWatcher();
+ void unregisterServiceWatcher();
+ bool valid();
+
+ QString serviceName;
+
+ QBluetoothUuid uuid;
+
+ QList<QLowEnergyCharacteristicInfo> characteristicList;
+ QLowEnergyServiceInfo::ServiceType serviceType;
+ bool connected;
+ QBluetoothDeviceInfo deviceInfo;
+#ifdef QT_BLUEZ_BLUETOOTH
+ QString startingHandle;
+ QString endingHandle;
+ QString path;
+ QBluetoothAddress adapterAddress;
+#endif
+
+#ifdef QT_QNX_BLUETOOTH
+ static void serviceConnected(const char*, const char*, int, int, short unsigned int, short unsigned int, short unsigned int, void*);
+ static void serviceUpdate(const char *, int , short unsigned int, short unsigned int, short unsigned int, void *);
+ static void serviceDisconnected(const char *, const char *, int, int, void *);
+ static void serviceNotification(int, short unsigned int, const char unsigned *, short unsigned int, void *);
+ //static void handleEvent(const int, const char *, const char *);
+#endif
+
+Q_SIGNALS:
+ void finished();
+ void connectedToService(const QBluetoothUuid &);
+ void error(const QBluetoothUuid &);
+ void disconnectedFromService(const QBluetoothUuid &);
+
+private:
+ QLowEnergyProcess *process;
+#ifdef QT_BLUEZ_BLUETOOTH
+ OrgBluezCharacteristicInterface *characteristic;
+ int m_step;
+ int m_valueCounter;
+ int m_readCounter;
+#endif
+ int m_instance;
+};
+
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYSERVICEINFO_P_H
diff --git a/src/bluetooth/qlowenergyserviceinfo_qnx.cpp b/src/bluetooth/qlowenergyserviceinfo_qnx.cpp
new file mode 100644
index 00000000..5ab214de
--- /dev/null
+++ b/src/bluetooth/qlowenergyserviceinfo_qnx.cpp
@@ -0,0 +1,268 @@
+
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QLoggingCategory>
+#include "qlowenergyserviceinfo_p.h"
+#include "qlowenergycharacteristicinfo.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include "qlowenergyprocess_p.h"
+#include <btapi/btdevice.h>
+#include <btapi/btgatt.h>
+#include <btapi/btspp.h>
+#include <btapi/btle.h>
+#include <errno.h>
+#include <QPointer>
+#include "qnx/ppshelpers_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_BT_QNX)
+
+void QLowEnergyServiceInfoPrivate::serviceConnected(const char *bdaddr, const char *service, int instance, int err, short unsigned int connInt, short unsigned int latency, short unsigned int superTimeout, void *userData)
+{
+ Q_UNUSED(latency);
+ Q_UNUSED(connInt);
+ Q_UNUSED(superTimeout);
+ QPointer<QLowEnergyServiceInfoPrivate> *classPointer = static_cast<QPointer<QLowEnergyServiceInfoPrivate> *>(userData);
+ QLowEnergyServiceInfoPrivate *p = classPointer->data();
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------";
+ qCDebug(QT_BT_QNX) << "[SERVICE: Connected] (service uuid, instance):" << p->uuid << instance;
+ qCDebug(QT_BT_QNX) << "[SERVICE: Connected] Device address: " << bdaddr;
+ qCDebug(QT_BT_QNX) << "[SERVICE: Connected] Device service: " << service;
+ qCDebug(QT_BT_QNX) << "[SERVICE: Connected] Possible error: " << err;
+ if (err != 0) {
+ qCDebug(QT_BT_QNX) << "An error occurred in service connected callback: " << strerror(err);
+ p->errorString = QString::fromLatin1(strerror(err));
+ p->error(p->uuid);
+ }
+ p->characteristicList.clear();
+ bt_gatt_characteristic_t* data;
+ data = (bt_gatt_characteristic_t*) malloc(sizeof(bt_gatt_characteristic_t));
+ if (0 == data) {
+ qCDebug(QT_BT_QNX) << "[SERVICE: Connected] GATT characteristics: Not enough memory";
+ bt_gatt_disconnect_instance(instance);
+ p->errorString = QStringLiteral("GATT characteristics: Not enough memory");
+ p->error(p->uuid);
+ return;
+ }
+
+ int num_characteristics = bt_gatt_characteristics_count(instance);
+
+ if (num_characteristics > -1) {
+ qCDebug(QT_BT_QNX) << "Characteristics number: "<< num_characteristics;
+ bt_gatt_characteristic_t *allCharacteristicList;
+
+ allCharacteristicList = (bt_gatt_characteristic_t*) malloc(num_characteristics * sizeof(bt_gatt_characteristic_t));
+ if (0 == allCharacteristicList) {
+ qCDebug(QT_BT_QNX) <<" GATT characteristics: Not enough memory";
+ bt_gatt_disconnect_instance(instance);
+ p->errorString = QStringLiteral("GATT characteristics: Not enough memory");
+ p->error(p->uuid);
+ return;
+ }
+
+ /* BEGIN WORKAROUND - Temporary fix to address race condition */
+ int number = 0;
+ do {
+ number = bt_gatt_characteristics(instance, allCharacteristicList, num_characteristics);
+ } while ((number == -1) && (errno== EBUSY));
+ //Using sub to subscribe notification callback only once
+ bool sub = false;
+ int characteristicListSize = number;
+
+ for (int i = 0; i < characteristicListSize; i++) {
+ qCDebug(QT_BT_QNX) << "Characteristic: uuid,handle,value_handle, properties:" << allCharacteristicList[i].uuid << "," << allCharacteristicList[i].handle << "," << allCharacteristicList[i].value_handle << ", " << allCharacteristicList[i].properties;
+ QString charUuid = QString::fromLatin1(allCharacteristicList[i].uuid);
+ QString handleUuid;
+ handleUuid.setNum(allCharacteristicList[i].value_handle);
+ QBluetoothUuid characteristicUuid;
+ if (charUuid.toUShort(0,0) == 0) {
+ charUuid = charUuid.remove(0,2);
+ characteristicUuid = QBluetoothUuid(charUuid);
+ }
+ else
+ characteristicUuid = QBluetoothUuid(charUuid.toUShort(0,0));
+ QVariantMap map;
+ QLowEnergyCharacteristicInfo characteristicInfo(characteristicUuid);
+ characteristicInfo.d_ptr->handle = handleUuid;
+ characteristicInfo.d_ptr->instance = instance;
+ characteristicInfo.d_ptr->characteristic = allCharacteristicList[i];
+ characteristicInfo.d_ptr->permission = allCharacteristicList[i].properties;
+ map[QStringLiteral("uuid")] = characteristicUuid.toString();
+ map[QStringLiteral("handle")] = handleUuid;
+ map[QStringLiteral("permission")] = characteristicInfo.d_ptr->permission;
+ characteristicInfo.d_ptr->properties = map;
+ characteristicInfo.d_ptr->readDescriptors();
+
+ characteristicInfo.d_ptr->readValue();
+ //Subscribe only once since it is static function
+ if (sub == false) {
+ int rc = bt_gatt_reg_notifications(instance, &(characteristicInfo.d_ptr->serviceNotification));
+ if (rc != 0) {
+ qCDebug(QT_BT_QNX) << "[SERVICE: Connected] bt_gatt_reg_notifications failed." << errno << strerror(errno);
+ p->errorString = QString::fromLatin1(strerror(errno));
+ p->error(p->uuid);
+ }
+ else
+ qCDebug(QT_BT_QNX) << "[SERVICE: Connected] bt_gatt_reg_notifications was presumably OK";
+ sub = true;
+ }
+ p->characteristicList.append(characteristicInfo);
+
+ }
+
+ if (allCharacteristicList != NULL) {
+ free(allCharacteristicList);
+ allCharacteristicList = NULL;
+ }
+
+ /* END WORKAROUND */
+ }
+
+ p->connected = true;
+ qCDebug(QT_BT_QNX) << p;
+ emit p->connectedToService(p->uuid);
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------------------------------------";
+}
+
+void QLowEnergyServiceInfoPrivate::serviceUpdate(const char *bdaddr, int instance, short unsigned int connInt, short unsigned int latency, short unsigned int superTimeout, void *userData)
+{
+ Q_UNUSED(latency);
+ Q_UNUSED(connInt);
+ Q_UNUSED(superTimeout);
+ Q_UNUSED(userData);
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------";
+ qCDebug(QT_BT_QNX) << "[SERVICE: Update] (instance):" << instance;
+ qCDebug(QT_BT_QNX) << "[SERVICE: Update] Device address: " << bdaddr;
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------";
+}
+
+void QLowEnergyServiceInfoPrivate::serviceDisconnected(const char *bdaddr, const char *service, int instance, int reason, void *userData)
+{
+ QPointer<QLowEnergyServiceInfoPrivate> *classPointer = static_cast<QPointer<QLowEnergyServiceInfoPrivate> *>(userData);
+ QLowEnergyServiceInfoPrivate *p = classPointer->data();
+ emit p->disconnectedFromService(p->uuid);
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------";
+ qCDebug(QT_BT_QNX) << "[SERVICE: Disconnect] (service, instance, reason):" << service << instance << reason;
+ qCDebug(QT_BT_QNX) << "[SERVICE: Disconnect] Device address: " << bdaddr;
+ qCDebug(QT_BT_QNX) << "---------------------------------------------------";
+ delete p;
+ delete classPointer;
+}
+
+QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate():
+ errorString(QString()), m_instance(0)
+{
+ qRegisterMetaType<QBluetoothUuid>("QBluetoothUuid");
+}
+
+QLowEnergyServiceInfoPrivate::~QLowEnergyServiceInfoPrivate()
+{
+
+}
+
+void QLowEnergyServiceInfoPrivate::registerServiceWatcher()
+{
+ bt_gatt_callbacks_t gatt_callbacks = { &(this->serviceConnected), this->serviceDisconnected, this->serviceUpdate };
+ errno=0;
+ process = process->instance();
+ if (!process->isConnected()) {
+ qCDebug(QT_BT_QNX) << "[INIT] Init problem." << errno << strerror(errno);
+ errorString = QStringLiteral("Initialization of device falied. ") + QString::fromLatin1(strerror(errno));
+ emit error(uuid);
+ return;
+ }
+
+ errno=0;
+ if (bt_gatt_init(&gatt_callbacks) < 0) {
+ qCDebug(QT_BT_QNX) << "[INIT] GAT Init problem." << errno << strerror(errno);
+ errorString = QStringLiteral("Callbacks initialization failed. ") + QString::fromLatin1(strerror(errno));
+ emit error(uuid);
+ return;
+ }
+ if (bt_le_init(0) != EOK) {
+ qWarning() << "LE initialization failure " << errno;
+ }
+
+ QPointer<QLowEnergyServiceInfoPrivate> *classPointer = new QPointer<QLowEnergyServiceInfoPrivate>(this);
+ process->addPointer(classPointer->data());
+ QString serviceUuid = uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}'));
+ if (serviceUuid.contains(QStringLiteral("000000000000")))
+ serviceUuid = QStringLiteral("0x") + serviceUuid.toUpper();
+ else
+ serviceUuid = QStringLiteral("0x") + serviceUuid[4] + serviceUuid[5] + serviceUuid[6] + serviceUuid[7];
+ errno=0;
+ bt_gatt_conn_parm_t conParm;
+ conParm.minConn = 0x30;
+ conParm.maxConn = 0x50;
+ conParm.latency = 0;
+ conParm.superTimeout = 50;
+ if (bt_gatt_connect_service(deviceInfo.address().toString().toLocal8Bit().constData(), serviceUuid.toLocal8Bit().constData(), 0, &conParm, classPointer) < 0) {
+ qCDebug(QT_BT_QNX) << "[SERVICE] Connection to service failed." << errno << strerror(errno);
+ errorString = QStringLiteral("[SERVICE] Connection to service failed.") + QString::fromLatin1(strerror(errno));
+ emit error(uuid);
+ }
+ qCDebug(QT_BT_QNX) << "errno after connect: " << errno;
+}
+
+void QLowEnergyServiceInfoPrivate::unregisterServiceWatcher()
+{
+ QString serviceUuid = uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}'));
+ if (serviceUuid.contains(QStringLiteral("000000000000")))
+ serviceUuid = QStringLiteral("0x") + serviceUuid.toUpper();
+ else
+ serviceUuid = QStringLiteral("0x") + serviceUuid[4] + serviceUuid[5] + serviceUuid[6] + serviceUuid[7];
+ if (bt_gatt_disconnect_service(deviceInfo.address().toString().toLocal8Bit().constData(), serviceUuid.toLocal8Bit().constData()) < 0) {
+ qCDebug(QT_BT_QNX) << "[SERVICE] Disconnect service request failed. " << errno << strerror(errno);
+ emit error(uuid);
+ } else {
+ emit disconnectedFromService(uuid);
+ qCDebug(QT_BT_QNX) << "[SERVICE] Disconnected from service OK.";
+ }
+}
+
+bool QLowEnergyServiceInfoPrivate::valid()
+{
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qnx/qnxnfcmanager.cpp b/src/nfc/qnx/qnxnfcmanager.cpp
index d4736746..92152c26 100644
--- a/src/nfc/qnx/qnxnfcmanager.cpp
+++ b/src/nfc/qnx/qnxnfcmanager.cpp
@@ -44,6 +44,7 @@
#include <QMetaObject>
#include "../qllcpsocket_qnx_p.h"
#include <QCoreApplication>
+#include <QStringList>
QT_BEGIN_NAMESPACE