Skip to content

Commit

Permalink
Chagned Thread-enabled check to use NetworkCommissioning feature map,…
Browse files Browse the repository at this point in the history
… and fix affected unit test
  • Loading branch information
jtung-apple committed May 16, 2024
1 parent 13a16c0 commit e4668ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -967,18 +967,20 @@ - (BOOL)_deviceUsesThread
}
#endif

// Device is thread-enabled if there is a Thread Network Diagnostics cluster on endpoint 0
for (MTRClusterPath * path in [self _knownClusters]) {
if (path.endpoint.unsignedShortValue != kRootEndpointId) {
continue;
}

if (path.cluster.unsignedLongValue == MTRClusterIDTypeThreadNetworkDiagnosticsID) {
return YES;
}
MTRClusterPath * networkCommissioningClusterPath = [MTRClusterPath clusterPathWithEndpointID:@(0) clusterID:@(MTRClusterIDTypeNetworkCommissioningID)];
MTRDeviceClusterData * networkCommissioningClusterData = [self _clusterDataForPath:networkCommissioningClusterPath];
NSNumber * networkCommissioningClusterFeatureMapValueNumber = networkCommissioningClusterData.attributes[@(MTRClusterGlobalAttributeFeatureMapID)][MTRValueKey];
if (![networkCommissioningClusterFeatureMapValueNumber isKindOfClass:[NSNumber class]]) {
MTR_LOG_ERROR("%@ Unexpected NetworkCommissioning FeatureMap value %@", self, networkCommissioningClusterFeatureMapValueNumber);
return NO;
}

return NO;
// Bit 0 WiFi
// Bit 1 Thread
// Bit 2 Ethernet
uint32_t networkCommissioningClusterFeatureMapValue = static_cast<uint32_t>(networkCommissioningClusterFeatureMapValueNumber.unsignedLongValue);

return (networkCommissioningClusterFeatureMapValue & (1 << 1));
}

- (void)_clearSubscriptionPoolWork
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
static const uint16_t kTestProductId2 = 0x8001u;
static const uint16_t kTestDiscriminator1 = 3840u;
static const uint16_t kTestDiscriminator2 = 3839u;
static const uint16_t kTestDiscriminator3 = 101u;
static const uint16_t kTestDiscriminator4 = 102u;
static const uint16_t kTestDiscriminator5 = 103u;
static const uint16_t kTestDiscriminator6 = 104u;
static const uint16_t kTestDiscriminator7 = 105u;
static const uint16_t kDiscoverDeviceTimeoutInSeconds = 10;
static const uint16_t kExpectedDiscoveredDevicesCount = 2;

Expand Down Expand Up @@ -97,7 +102,7 @@ - (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice
XCTAssertEqual(instanceName.length, 16); // The instance name is random, so just ensure the len is right.
XCTAssertEqualObjects(vendorId, @(kTestVendorId));
XCTAssertTrue([productId isEqual:@(kTestProductId1)] || [productId isEqual:@(kTestProductId2)]);
XCTAssertTrue([discriminator isEqual:@(kTestDiscriminator1)] || [discriminator isEqual:@(kTestDiscriminator2)]);
XCTAssertTrue([discriminator isEqual:@(kTestDiscriminator1)] || [discriminator isEqual:@(kTestDiscriminator2)] || [discriminator isEqual:@(kTestDiscriminator3)] || [discriminator isEqual:@(kTestDiscriminator4)] || [discriminator isEqual:@(kTestDiscriminator5)] || [discriminator isEqual:@(kTestDiscriminator6)] || [discriminator isEqual:@(kTestDiscriminator7)]);
XCTAssertEqual(commissioningMode, YES);

NSLog(@"Found Device (%@) with discriminator: %@ (vendor: %@, product: %@)", instanceName, discriminator, vendorId, productId);
Expand Down

0 comments on commit e4668ca

Please sign in to comment.