diff options
Diffstat (limited to 'src/bluetooth')
-rw-r--r-- | src/bluetooth/bluetooth.pro | 5 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice.cpp | 21 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice.h | 3 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_bluez.cpp | 118 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_p.cpp | 5 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_p.h | 18 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_qnx.cpp | 63 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothservicediscoveryagent_p.h | 5 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp | 123 |
9 files changed, 359 insertions, 2 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 993f3646..ef53520c 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -77,6 +77,11 @@ config_bluez:qtHaveModule(dbus) { include(qnx/qnx.pri) + config_btapi10_2_1 { + DEFINES += QT_QNX_BT_BLUETOOTH + LIBS += -lbtapi + } + PRIVATE_HEADERS += \ qbluetoothtransferreply_qnx_p.h diff --git a/src/bluetooth/qbluetoothlocaldevice.cpp b/src/bluetooth/qbluetoothlocaldevice.cpp index 9661adcb..fa9057a1 100644 --- a/src/bluetooth/qbluetoothlocaldevice.cpp +++ b/src/bluetooth/qbluetoothlocaldevice.cpp @@ -188,6 +188,27 @@ bool QBluetoothLocalDevice::isValid() const */ /*! + \fn void QBluetoothLocalDevice::deviceConnected(const QBluetoothAddress &address) + \since 5.3 + + A device with \a address is connected with this device. +*/ + +/*! + \fn void QBluetoothLocalDevice::deviceDisconnected(const QBluetoothAddress &address) + \since 5.3 + + A device with \a address is disconnected from this device. +*/ + +/*! + \fn QList<QBluetoothAddress> connectedDevices() const + \since 5.3 + + Returns the list of connected devices. +*/ + +/*! \fn QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const Returns the current bluetooth pairing status of \a address, if it's unpaired, paired, or paired and authorized. diff --git a/src/bluetooth/qbluetoothlocaldevice.h b/src/bluetooth/qbluetoothlocaldevice.h index 713b5037..33010e9c 100644 --- a/src/bluetooth/qbluetoothlocaldevice.h +++ b/src/bluetooth/qbluetoothlocaldevice.h @@ -91,6 +91,7 @@ public: void setHostMode(QBluetoothLocalDevice::HostMode mode); HostMode hostMode() const; + QList<QBluetoothAddress> connectedDevices() const; void powerOn(); @@ -104,6 +105,8 @@ public Q_SLOTS: Q_SIGNALS: void hostModeStateChanged(QBluetoothLocalDevice::HostMode state); + void deviceConnected(const QBluetoothAddress &address) const; + void deviceDisconnected(const QBluetoothAddress &address) const; void pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing); void pairingDisplayPinCode(const QBluetoothAddress &address, QString pin); diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index 62df930a..846639fc 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -55,6 +55,11 @@ QT_BEGIN_NAMESPACE static const QLatin1String agentPath("/qt/agent"); +inline uint qHash(const QBluetoothAddress &address) +{ + return ::qHash(address.toUInt64()); +} + QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) : QObject(parent), d_ptr(new QBluetoothLocalDevicePrivate(this)) { @@ -155,6 +160,11 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const return HostPoweredOff; } +QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const +{ + return d_ptr->connectedDevices(); +} + QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() { QList<QBluetoothHostInfo> localDevices; @@ -335,9 +345,17 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet } QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress address) - : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q) + : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q), connectedCached(false) { initializeAdapter(); + connectDeviceChanges(); +} + +void QBluetoothLocalDevicePrivate::connectDeviceChanges() +{ + connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(PropertyChanged(QString,QDBusVariant))); + connect(adapter, SIGNAL(DeviceCreated(QDBusObjectPath)), SLOT(_q_deviceCreated(QDBusObjectPath))); + connect(adapter, SIGNAL(DeviceRemoved(QDBusObjectPath)), SLOT(_q_deviceRemoved(QDBusObjectPath))); } QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate() @@ -345,6 +363,7 @@ QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate() delete msgConnection; delete adapter; delete agent; + qDeleteAll(devices); } void QBluetoothLocalDevicePrivate::initializeAdapter() @@ -412,6 +431,103 @@ void QBluetoothLocalDevicePrivate::RequestConfirmation(const QDBusObjectPath &in return; } +void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &device) +{ + OrgBluezDeviceInterface *deviceInterface = + new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus()); + connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(_q_devicePropertyChanged(QString,QDBusVariant))); + devices << deviceInterface; + QDBusPendingReply<QVariantMap> properties = deviceInterface->asyncCall(QLatin1String("GetProperties")); + + properties.waitForFinished(); + if (!properties.isValid()) { + qCritical() << "Unable to get device properties from: " << device.path(); + return; + } + const QBluetoothAddress address = QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString()); + const bool connected = properties.value().value(QLatin1String("Connected")).toBool(); + + if (connectedCached) { + if (connected) + connectedDevicesSet.insert(address); + else + connectedDevicesSet.remove(address); + } + if (connected) + emit q_ptr->deviceConnected(address); + else + emit q_ptr->deviceDisconnected(address); +} + +void QBluetoothLocalDevicePrivate::_q_deviceRemoved(const QDBusObjectPath &device) +{ + foreach (OrgBluezDeviceInterface *deviceInterface, devices) { + if (deviceInterface->path() == device.path()) { + devices.remove(deviceInterface); + delete deviceInterface; //deviceDisconnected is already emitted by _q_devicePropertyChanged + break; + } + } +} + +void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &property, const QDBusVariant &value) +{ + OrgBluezDeviceInterface *deviceInterface = qobject_cast<OrgBluezDeviceInterface*>(sender()); + if (deviceInterface && property == QLatin1String("Connected")) { + QDBusPendingReply<QVariantMap> propertiesReply = deviceInterface->GetProperties(); + propertiesReply.waitForFinished(); + if (propertiesReply.isError()) { + qWarning() << propertiesReply.error().message(); + return; + } + const QVariantMap properties = propertiesReply.value(); + const QBluetoothAddress address = QBluetoothAddress(properties.value(QLatin1String("Address")).toString()); + const bool connected = value.variant().toBool(); + + if (connectedCached) { + if (connected) + connectedDevicesSet.insert(address); + else + connectedDevicesSet.remove(address); + } + if (connected) + emit q_ptr->deviceConnected(address); + else + emit q_ptr->deviceDisconnected(address); + } +} + +void QBluetoothLocalDevicePrivate::createCache() +{ + QDBusPendingReply<QList<QDBusObjectPath> > reply = adapter->ListDevices(); + reply.waitForFinished(); + if (reply.isError()) { + qWarning() << reply.error().message(); + return; + } + foreach (const QDBusObjectPath &device, reply.value()) { + OrgBluezDeviceInterface deviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus()); + + QDBusPendingReply<QVariantMap> properties = deviceInterface.asyncCall(QLatin1String("GetProperties")); + properties.waitForFinished(); + if (!properties.isValid()) { + qWarning() << "Unable to get properties for device " << device.path(); + return; + } + + if (properties.value().value(QLatin1String("Connected")).toBool()) + connectedDevicesSet.insert(QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString())); + } + connectedCached = true; +} + +QList<QBluetoothAddress> QBluetoothLocalDevicePrivate::connectedDevices() const +{ + if (!connectedCached) + const_cast<QBluetoothLocalDevicePrivate *>(this)->createCache(); + return connectedDevicesSet.toList(); +} + void QBluetoothLocalDevice::pairingConfirmation(bool confirmation) { if(!d_ptr || diff --git a/src/bluetooth/qbluetoothlocaldevice_p.cpp b/src/bluetooth/qbluetoothlocaldevice_p.cpp index 411863cb..d40e6473 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_p.cpp @@ -79,6 +79,11 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const return HostPoweredOff; } +QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const +{ + return QList<QBluetoothAddress>(); +} + QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() { QList<QBluetoothHostInfo> localDevices; diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h index 0f2aaca8..76a7e460 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.h +++ b/src/bluetooth/qbluetoothlocaldevice_p.h @@ -51,9 +51,11 @@ #include <QDBusContext> #include <QDBusObjectPath> #include <QDBusMessage> +#include <QSet> class OrgBluezAdapterInterface; class OrgBluezAgentAdaptor; +class OrgBluezDeviceInterface; QT_BEGIN_NAMESPACE class QDBusPendingCallWatcher; @@ -78,8 +80,13 @@ public: QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress localAddress = QBluetoothAddress()); ~QBluetoothLocalDevicePrivate(); + QSet<OrgBluezDeviceInterface *> devices; + QSet<QBluetoothAddress> connectedDevicesSet; OrgBluezAdapterInterface *adapter; OrgBluezAgentAdaptor *agent; + + QList<QBluetoothAddress> connectedDevices() const; + QString agent_path; QBluetoothAddress localAddress; QBluetoothAddress address; @@ -101,14 +108,22 @@ public Q_SLOTS: // METHODS void pairingCompleted(QDBusPendingCallWatcher*); void PropertyChanged(QString,QDBusVariant); + void _q_deviceCreated(const QDBusObjectPath &device); + void _q_deviceRemoved(const QDBusObjectPath &device); + void _q_devicePropertyChanged(const QString &property, const QDBusVariant &value); bool isValid() const; private: + void createCache(); + void connectDeviceChanges(); + QDBusMessage msgConfirmation; QDBusConnection *msgConnection; QBluetoothLocalDevice *q_ptr; + bool connectedCached; + void initializeAdapter(); }; @@ -134,6 +149,8 @@ public: void requestPairing(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing); void setAccess(int); + // This method will be used for emitting signals. + void connectedDevices(); Q_INVOKABLE void controlReply(ppsResult res); Q_INVOKABLE void controlEvent(ppsResult res); @@ -143,6 +160,7 @@ public: private: QBluetoothLocalDevice *q_ptr; bool isValidDevice; + QList<QBluetoothAddress> connectedDevicesSet; }; #else class QBluetoothLocalDevicePrivate : public QObject diff --git a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp index 780639f6..860df8c3 100644 --- a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp @@ -42,7 +42,10 @@ #include "qbluetoothlocaldevice.h" #include "qbluetoothaddress.h" #include "qbluetoothlocaldevice_p.h" +#include <sys/pps.h> #include "qnx/ppshelpers_p.h" +#include <QDir> +#include <QtCore/private/qcore_unix_p.h> QT_BEGIN_NAMESPACE @@ -93,6 +96,46 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const return this->d_ptr->hostMode(); } +QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const +{ + QList<QBluetoothAddress> devices; + QDir bluetoothDevices(QStringLiteral("/pps/services/bluetooth/remote_devices/")); + QStringList allFiles = bluetoothDevices.entryList(QDir::NoDotAndDotDot| QDir::Files); + for (int i = 0; i < allFiles.size(); i++) { + qBBBluetoothDebug() << allFiles.at(i); + int fileId; + const char *filePath = QByteArray("/pps/services/bluetooth/remote_devices/").append(allFiles.at(i).toUtf8().constData()).constData(); + if ((fileId = qt_safe_open(filePath, O_RDONLY)) == -1) + qWarning() << "Failed to open remote device file"; + else { + pps_decoder_t ppsDecoder; + pps_decoder_initialize(&ppsDecoder, 0); + + QBluetoothAddress deviceAddr; + QString deviceName; + + if (!ppsReadRemoteDevice(fileId, &ppsDecoder, &deviceAddr, &deviceName)) { + pps_decoder_cleanup(&ppsDecoder); + qDebug() << "Failed to open remote device file"; + } + + bool connectedDevice = false; + int a = pps_decoder_get_bool(&ppsDecoder, "acl_connected", &connectedDevice); + if (a == PPS_DECODER_OK) { + if (connectedDevice) + devices.append(deviceAddr); + } + else if ( a == PPS_DECODER_BAD_TYPE) + qBBBluetoothDebug() << "Type missmatch"; + else + qBBBluetoothDebug() << "An unknown error occurred while checking connected status."; + pps_decoder_cleanup(&ppsDecoder); + } + } + + return devices; +} + QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() { //We only have one device @@ -256,6 +299,25 @@ void QBluetoothLocalDevicePrivate::setAccess(int access) } } +void QBluetoothLocalDevicePrivate::connectedDevices() +{ + QList<QBluetoothAddress> devices = q_ptr->connectedDevices(); + for (int i = 0; i < devices.size(); i ++) { + if (!connectedDevicesSet.contains(devices.at(i))) { + QBluetoothAddress addr = devices.at(i); + connectedDevicesSet.append(addr); + emit q_ptr->deviceConnected(devices.at(i)); + } + } + for (int i = 0; i < connectedDevicesSet.size(); i ++) { + if (!devices.contains(connectedDevicesSet.at(i))) { + QBluetoothAddress addr = connectedDevicesSet.at(i); + emit q_ptr->deviceDisconnected(addr); + connectedDevicesSet.removeOne(addr); + } + } +} + void QBluetoothLocalDevicePrivate::controlReply(ppsResult result) { qBBBluetoothDebug() << Q_FUNC_INFO << result.msg << result.dat; @@ -276,6 +338,7 @@ void QBluetoothLocalDevicePrivate::controlEvent(ppsResult result) result.dat.first() == QStringLiteral("level")) { QBluetoothLocalDevice::HostMode newHostMode = hostMode(); qBBBluetoothDebug() << "New Host mode" << newHostMode; + connectedDevices(); Q_EMIT q_ptr->hostModeStateChanged(newHostMode); } } else if (result.msg == QStringLiteral("pairing_complete")) { diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_p.h b/src/bluetooth/qbluetoothservicediscoveryagent_p.h index 517f6a98..0691b490 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothservicediscoveryagent_p.h @@ -64,6 +64,7 @@ QT_END_NAMESPACE #include <fcntl.h> #include <unistd.h> #include <QTimer> +#include <btapi/btdevice.h> #endif QT_BEGIN_NAMESPACE @@ -125,11 +126,15 @@ private Q_SLOTS: void controlReply(ppsResult result); void controlEvent(ppsResult result); void queryTimeout(); +#ifdef QT_QNX_BT_BLUETOOTH + static void deviceServicesDiscoveryCallback(bt_sdp_list_t *, void *, uint8_t); +#endif private: int m_rdfd; QSocketNotifier *rdNotifier; QTimer m_queryTimer; + bool m_btInitialized; #endif public: diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp index 4c18f0e0..1f11174f 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp @@ -49,6 +49,10 @@ #include "qbluetoothuuid.h" #include <sys/pps.h> +#ifdef QT_QNX_BT_BLUETOOTH +#include <errno.h> +#include <QPointer> +#endif #include <QFile> @@ -56,13 +60,85 @@ QT_BEGIN_NAMESPACE +#ifdef QT_QNX_BT_BLUETOOTH +void QBluetoothServiceDiscoveryAgentPrivate::deviceServicesDiscoveryCallback(bt_sdp_list_t *result, void *user_data, uint8_t error) +{ + if (error != 0) + qWarning() << "Error received in callback: " << errno << strerror(errno); + QPointer<QBluetoothServiceDiscoveryAgentPrivate> *classPointer = static_cast<QPointer<QBluetoothServiceDiscoveryAgentPrivate> *>(user_data); + if (classPointer->isNull()) { + qBBBluetoothDebug() << "Pointer received in callback is null"; + return; + } + QBluetoothServiceDiscoveryAgentPrivate *p = classPointer->data(); + if ( result == 0) { + qBBBluetoothDebug() << "Result received in callback is null."; + p->errorString = QBluetoothServiceDiscoveryAgent::tr("Result received in callback is null."); + p->error = QBluetoothServiceDiscoveryAgent::InputOutputError; + p->q_ptr->error(p->error); + p->_q_serviceDiscoveryFinished(); + return; + } + + for (int i = 0; i < result->num_records; i++) { + bt_sdp_record_t rec = result->record[i]; + QBluetoothServiceInfo serviceInfo; + serviceInfo.setDevice(p->discoveredDevices.at(0)); + serviceInfo.setServiceName(rec.name); + serviceInfo.setServiceDescription(rec.description); + //serviceInfo.setServiceAvailability(rec.availability); + serviceInfo.setServiceProvider(QString(rec.provider)); + QBluetoothServiceInfo::Sequence protocolDescriptorList; + for ( int j = 0; j < rec.num_protocol; j++) { + bt_sdp_prot_t protoc = rec.protocol[j]; + QString protocolUuid(protoc.uuid); + protocolUuid = QStringLiteral("0x") + protocolUuid; + QBluetoothUuid pUuid(protocolUuid.toUShort(0,0)); + protocolDescriptorList << QVariant::fromValue(pUuid); + for ( int k = 0; k < 2; k++) + protocolDescriptorList << QVariant::fromValue(QString::fromLatin1(protoc.parm[k])); + } + serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); + qBBBluetoothDebug() << "Service name " << rec.name << " Description: " << rec.description << "uuid " << rec.serviceId << "provider: " << rec.provider; + qBBBluetoothDebug() << "num protocol " << rec.num_protocol << "record handle " << rec.record_handle << "class id" << rec.num_classId << "availability " << rec.availability << rec.num_language; + + QList<QBluetoothUuid> serviceClassId; + + for (int j = 0; j < rec.num_classId; j++) { + bt_sdp_class_t uuid = rec.classId[j]; + qBBBluetoothDebug() << "uuid: " << uuid.uuid; + QString protocolUuid(uuid.uuid); + protocolUuid = QStringLiteral("0x") + protocolUuid; + QBluetoothUuid Uuid(protocolUuid.toUShort(0,0)); + if (j == 0) { + serviceInfo.setServiceUuid(Uuid); + //Check if the UUID is in the uuidFilter + if (!p->uuidFilter.isEmpty() && !p->uuidFilter.contains(Uuid)) + continue; + } + serviceClassId << Uuid; + } + serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, QVariant::fromValue(serviceClassId)); + serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, + QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); + p->q_ptr->serviceDiscovered(serviceInfo); + } + p->_q_serviceDiscoveryFinished(); + //delete p; + //delete classPointer; +} +#endif + QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter) - : m_rdfd(-1), rdNotifier(0), error(QBluetoothServiceDiscoveryAgent::NoError), deviceAddress(deviceAdapter), state(Inactive), + : m_rdfd(-1), rdNotifier(0), m_btInitialized(false), error(QBluetoothServiceDiscoveryAgent::NoError), deviceAddress(deviceAdapter), state(Inactive), deviceDiscoveryAgent(0), mode(QBluetoothServiceDiscoveryAgent::MinimalDiscovery) { ppsRegisterControl(); connect(&m_queryTimer, SIGNAL(timeout()), this, SLOT(queryTimeout())); ppsRegisterForEvent(QStringLiteral("service_updated"), this); + //Needed for connecting signals and slots from static function + qRegisterMetaType<QBluetoothServiceInfo>("QBluetoothServiceInfo"); + qRegisterMetaType<QBluetoothServiceDiscoveryAgent::Error>("QBluetoothServiceDiscoveryAgent::Error"); } QBluetoothServiceDiscoveryAgentPrivate::~QBluetoothServiceDiscoveryAgentPrivate() @@ -74,6 +150,50 @@ QBluetoothServiceDiscoveryAgentPrivate::~QBluetoothServiceDiscoveryAgentPrivate( void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &address) { Q_Q(QBluetoothServiceDiscoveryAgent); +#ifdef QT_QNX_BT_BLUETOOTH + errno = 0; + if (!m_btInitialized) { + if (bt_device_init( 0 ) < 0) { + qWarning() << "Failed to initialize bluetooth stack."; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; + errorString = QBluetoothServiceDiscoveryAgent::tr("Failed to open to initialize bluetooth stack"); + q->error(error); + _q_serviceDiscoveryFinished(); + return; + } + } + m_btInitialized = true; + errno = 0; + bt_remote_device_t *remoteDevice = bt_rdev_get_device(address.toString().toLocal8Bit().constData()); + int deviceType = bt_rdev_get_type(remoteDevice); + if (deviceType == -1) { + qWarning() << "Could not retrieve remote device (address is 00:00:00:00:00:00)."; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; + errorString = QBluetoothServiceDiscoveryAgent::tr("Could not retrieve remote device (address is 00:00:00:00:00:00)."); + q->error(error); + _q_serviceDiscoveryFinished(); + return; + } + /* + * In case remote device is LE device, calling bt_rdev_sdp_search_async will cause memory fault. + */ + + if ( deviceType >1) { + errno = 0; + QPointer<QBluetoothServiceDiscoveryAgentPrivate> *classPointer = new QPointer<QBluetoothServiceDiscoveryAgentPrivate>(this); + int b = bt_rdev_sdp_search_async(remoteDevice, 0, &(this->deviceServicesDiscoveryCallback), classPointer); + if ( b != 0 ) { + qWarning() << "Failed to run search on device: " << address.toString(); + error = QBluetoothServiceDiscoveryAgent::InputOutputError; + errorString = QBluetoothServiceDiscoveryAgent::tr(strerror(errno)); + q->error(error); + _q_serviceDiscoveryFinished(); + return; + } + } + else + _q_serviceDiscoveryFinished(); +#else qBBBluetoothDebug() << "Starting Service discovery for" << address.toString(); QByteArray filePath = QByteArray("/pps/services/bluetooth/remote_devices/").append(address.toString().toUtf8().constData()); if ((m_rdfd = qt_safe_open(filePath.constData(), O_RDONLY)) == -1) { @@ -105,6 +225,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr } m_queryTimer.start(10000); ppsSendControlMessage("service_query", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()), this); +#endif } void QBluetoothServiceDiscoveryAgentPrivate::stop() |