QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus( const QBluetoothAddress &address) const { if (!isValid()) return Unpaired; bool paired = false; bool btle = false; // Bluetooth Low Energy devices QByteArray qnxPath("/pps/services/bluetooth/remote_devices/"); qnxPath.append(address.toString().toUtf8()); int m_rdfd; if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) { btle = true; qnxPath.append("-00"); if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) { qnxPath.replace((qnxPath.length()-3), 3, "-01"); if ((m_rdfd = qt_safe_open(qnxPath.constData(), O_RDONLY)) == -1) return Unpaired; } } pps_decoder_t ppsDecoder; pps_decoder_initialize(&ppsDecoder, NULL); QBluetoothAddress deviceAddr; QString deviceName; if (!ppsReadRemoteDevice(m_rdfd, &ppsDecoder, &deviceAddr, &deviceName)) return Unpaired; bool known = false; // Paired BTLE devices have only known field set to true. if (btle) pps_decoder_get_bool(&ppsDecoder, "known", &known); pps_decoder_get_bool(&ppsDecoder, "paired", &paired); pps_decoder_cleanup(&ppsDecoder); if (paired) return Paired; else if (btle && known) return Paired; else return Unpaired; }
QVariant ppsReadSetting(const char *property) { int settingsFD; char buf[ppsBufferSize]; if ((settingsFD = qt_safe_open(btSettingsFDPath, O_RDONLY)) == -1) { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to open "<< btSettingsFDPath; return QVariant(); } QVariant result; qt_safe_read( settingsFD, &buf, sizeof(buf)); pps_decoder_t decoder; pps_decoder_initialize(&decoder, 0); if (pps_decoder_parse_pps_str(&decoder, buf) == PPS_DECODER_OK) { pps_decoder_push(&decoder, 0); pps_node_type_t nodeType = pps_decoder_type(&decoder, property); if (nodeType == PPS_TYPE_STRING) { const char *dat; if (pps_decoder_get_string(&decoder, property, &dat) == PPS_DECODER_OK) { result = QString::fromUtf8(dat); qCDebug(QT_BT_QNX) << "Read setting" << result; } else { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property; return QVariant(); } } else if (nodeType == PPS_TYPE_BOOL) { bool dat; if (pps_decoder_get_bool(&decoder, property, &dat) == PPS_DECODER_OK) { result = dat; qCDebug(QT_BT_QNX) << "Read setting" << result; } else { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property; return QVariant(); } } else if (nodeType == PPS_TYPE_NUMBER) { int dat; if (pps_decoder_get_int(&decoder, property, &dat) == PPS_DECODER_OK) { result = dat; qCDebug(QT_BT_QNX) << "Read setting" << result; } else { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property; return QVariant(); } } else { qCDebug(QT_BT_QNX) << Q_FUNC_INFO << "unrecognized entry for settings"; } } pps_decoder_cleanup(&decoder); qt_safe_close(settingsFD); return result; }
QPpsAttribute QPpsObjectPrivate::decodeBool(pps_decoder_t *decoder) { bool value; pps_decoder_error_t error = pps_decoder_get_bool(decoder, 0, &value); if (error != PPS_DECODER_OK) { qWarning() << "QPpsObjectPrivate::decodeBool: pps_decoder_get_bool failed"; return QPpsAttribute(); } QPpsAttribute::Flags flags = readFlags(decoder); return QPpsAttributePrivate::createPpsAttribute(value, flags); }
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++) { qCDebug(QT_BT_QNX) << 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) { qCWarning(QT_BT_QNX) << "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) { qCDebug(QT_BT_QNX) << "Type missmatch"; } else { qCDebug(QT_BT_QNX) << "An unknown error occurred while checking connected status."; } pps_decoder_cleanup(&ppsDecoder); } } return devices; }
QVariant ppsRemoteDeviceStatus(const QByteArray &address, const char *property) { int rmFD; char buf[ppsBufferSize]; QByteArray filename = btRemoteDevFDPath; filename.append(address); if ((rmFD = qt_safe_open(filename.constData(), O_RDONLY)) < 0) { qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to open "<< btRemoteDevFDPath << address; return false; } QVariant res; qt_safe_read(rmFD, &buf, sizeof(buf)); pps_decoder_t ppsDecoder; pps_decoder_initialize(&ppsDecoder, 0); if (pps_decoder_parse_pps_str(&ppsDecoder, buf) == PPS_DECODER_OK) { pps_decoder_push(&ppsDecoder, 0); //Find out about the node type pps_node_type_t nodeType = pps_decoder_type(&ppsDecoder, property); if (nodeType == PPS_TYPE_STRING) { const char *dat; pps_decoder_get_string(&ppsDecoder,property,&dat); res = QString::fromUtf8(dat); } else if (nodeType == PPS_TYPE_BOOL) { bool dat; pps_decoder_get_bool(&ppsDecoder,property,&dat); res = QVariant(dat); } else { qCDebug(QT_BT_QNX) << "RDStatus: No node type" << property; } } pps_decoder_cleanup(&ppsDecoder); qt_safe_close(rmFD); return res; }