summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bluetooth/osx/osxbtsdpinquiry.mm79
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_osx.mm15
2 files changed, 88 insertions, 6 deletions
diff --git a/src/bluetooth/osx/osxbtsdpinquiry.mm b/src/bluetooth/osx/osxbtsdpinquiry.mm
index 6df2d16e..23d1bd84 100644
--- a/src/bluetooth/osx/osxbtsdpinquiry.mm
+++ b/src/bluetooth/osx/osxbtsdpinquiry.mm
@@ -53,6 +53,64 @@ SDPInquiryDelegate::~SDPInquiryDelegate()
{
}
+namespace {
+
+QBluetoothUuid sdp_element_to_uuid(IOBluetoothSDPDataElement *element)
+{
+ QT_BT_MAC_AUTORELEASEPOOL;
+
+ if (!element || [element getTypeDescriptor] != kBluetoothSDPDataElementTypeUUID)
+ return {};
+
+ return qt_uuid([[element getUUIDValue] getUUIDWithLength:16]);
+}
+
+QBluetoothUuid extract_service_ID(IOBluetoothSDPServiceRecord *record)
+{
+ Q_ASSERT(record);
+
+ QT_BT_MAC_AUTORELEASEPOOL;
+
+ return sdp_element_to_uuid([record getAttributeDataElement:kBluetoothSDPAttributeIdentifierServiceID]);
+}
+
+QVector<QBluetoothUuid> extract_service_class_ID_list(IOBluetoothSDPServiceRecord *record)
+{
+ Q_ASSERT(record);
+
+ QT_BT_MAC_AUTORELEASEPOOL;
+
+ IOBluetoothSDPDataElement *const idList = [record getAttributeDataElement:kBluetoothSDPAttributeIdentifierServiceClassIDList];
+ if (!idList || [idList getTypeDescriptor] != kBluetoothSDPDataElementTypeDataElementSequence)
+ return {};
+
+ QVector<QBluetoothUuid> uuids;
+ NSArray *const arr = [idList getArrayValue];
+ for (IOBluetoothSDPDataElement *dataElement in arr) {
+ const auto qtUuid = sdp_element_to_uuid(dataElement);
+ if (!qtUuid.isNull())
+ uuids.push_back(qtUuid);
+ }
+
+ return uuids;
+}
+
+QBluetoothServiceInfo::Sequence service_class_ID_list_to_sequence(const QVector<QBluetoothUuid> &uuids)
+{
+ if (uuids.isEmpty())
+ return {};
+
+ QBluetoothServiceInfo::Sequence sequence;
+ for (const auto &uuid : uuids) {
+ Q_ASSERT(!uuid.isNull());
+ sequence.append(QVariant::fromValue(uuid));
+ }
+
+ return sequence;
+}
+
+} // unnamed namespace
+
QVariant extract_attribute_value(IOBluetoothSDPDataElement *dataElement)
{
Q_ASSERT_X(dataElement, Q_FUNC_INFO, "invalid data element (nil)");
@@ -72,7 +130,7 @@ QVariant extract_attribute_value(IOBluetoothSDPDataElement *dataElement)
case kBluetoothSDPDataElementTypeSignedInt:
return [[dataElement getNumberValue] intValue];
case kBluetoothSDPDataElementTypeUUID:
- return QVariant::fromValue(qt_uuid([[dataElement getUUIDValue] getUUIDWithLength:16]));
+ return QVariant::fromValue(sdp_element_to_uuid(dataElement));
case kBluetoothSDPDataElementTypeString:
case kBluetoothSDPDataElementTypeURL:
return QString::fromNSString([dataElement getStringValue]);
@@ -110,6 +168,15 @@ void extract_service_record(IOBluetoothSDPServiceRecord *record, QBluetoothServi
const QVariant attributeValue = OSXBluetooth::extract_attribute_value(element);
serviceInfo.setAttribute(attributeID, attributeValue);
}
+
+ const QBluetoothUuid serviceUuid = extract_service_ID(record);
+ if (!serviceUuid.isNull())
+ serviceInfo.setServiceUuid(serviceUuid);
+
+ const QVector<QBluetoothUuid> uuids(extract_service_class_ID_list(record));
+ const auto sequence = service_class_ID_list_to_sequence(uuids);
+ if (!sequence.isEmpty())
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, sequence);
}
QList<QBluetoothUuid> extract_services_uuids(IOBluetoothDevice *device)
@@ -124,11 +191,13 @@ QList<QBluetoothUuid> extract_services_uuids(IOBluetoothDevice *device)
NSArray * const records = device.services;
for (IOBluetoothSDPServiceRecord *record in records) {
- IOBluetoothSDPDataElement *const element =
- [record getAttributeDataElement:kBluetoothSDPAttributeIdentifierServiceClassIDList];
+ const QBluetoothUuid serviceID = extract_service_ID(record);
+ if (!serviceID.isNull())
+ uuids.push_back(serviceID);
- if (element && [element getTypeDescriptor] == kBluetoothSDPDataElementTypeUUID)
- uuids.append(qt_uuid([[element getUUIDValue] getUUIDWithLength:16]));
+ const QVector<QBluetoothUuid> idList(extract_service_class_ID_list(record));
+ if (idList.size())
+ uuids.append(idList.toList());
}
return uuids;
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm
index 6a0247a6..bd9cc7f3 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm
@@ -94,6 +94,8 @@ private:
bool isDuplicatedService(const QBluetoothServiceInfo &serviceInfo) const;
void serviceDiscoveryFinished();
+ bool serviceHasMathingUuid(const QBluetoothServiceInfo &serviceInfo) const;
+
QBluetoothServiceDiscoveryAgent *q_ptr;
QBluetoothServiceDiscoveryAgent::Error error;
@@ -369,7 +371,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(cons
if (!serviceInfo.isValid())
continue;
- if (!uuidFilter.isEmpty() && !uuidFilter.contains(serviceInfo.serviceUuid()))
+ if (!uuidFilter.isEmpty() && !serviceHasMathingUuid(serviceInfo))
continue;
if (!isDuplicatedService(serviceInfo)) {
@@ -424,6 +426,17 @@ void QBluetoothServiceDiscoveryAgentPrivate::serviceDiscoveryFinished()
startServiceDiscovery();
}
+bool QBluetoothServiceDiscoveryAgentPrivate::serviceHasMathingUuid(const QBluetoothServiceInfo &serviceInfo) const
+{
+ for (const auto &requestedUuid : uuidFilter) {
+ if (serviceInfo.serviceUuid() == requestedUuid)
+ return true;
+ if (serviceInfo.serviceClassUuids().contains(requestedUuid))
+ return true;
+ }
+ return false;
+}
+
QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(QObject *parent)
: QObject(parent),
d_ptr(new QBluetoothServiceDiscoveryAgentPrivate(this, QBluetoothAddress()))