Skip to content

Commit

Permalink
Add some better logging around PASE session setup in Matter.framework. (
Browse files Browse the repository at this point in the history
#33231)

Log the device ID being used.
  • Loading branch information
bzbarsky-apple authored Apr 30, 2024
1 parent 3062e91 commit 335ae19
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ - (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
newNodeID:(NSNumber *)newNodeID
error:(NSError * __autoreleasing *)error
{
MTR_LOG_DEFAULT("Setting up commissioning session for device ID 0x%016llX with setup payload %@", newNodeID.unsignedLongLongValue, payload);

[[MTRMetricsCollector sharedInstance] resetMetrics];

// Track overall commissioning
Expand Down Expand Up @@ -663,6 +665,8 @@ - (BOOL)setupCommissioningSessionWithDiscoveredDevice:(MTRCommissionableBrowserR
newNodeID:(NSNumber *)newNodeID
error:(NSError * __autoreleasing *)error
{
MTR_LOG_DEFAULT("Setting up commissioning session for already-discovered device %@ and device ID 0x%016llX with setup payload %@", discoveredDevice, newNodeID.unsignedLongLongValue, payload);

[[MTRMetricsCollector sharedInstance] resetMetrics];

// Track overall commissioning
Expand Down Expand Up @@ -912,7 +916,10 @@ - (MTRBaseDevice *)deviceBeingCommissionedWithNodeID:(NSNumber *)nodeID error:(N
return [[MTRBaseDevice alloc] initWithPASEDevice:deviceProxy controller:self];
};

return [self syncRunOnWorkQueueWithReturnValue:block error:error];
MTRBaseDevice * device = [self syncRunOnWorkQueueWithReturnValue:block error:error];
MTR_LOG_DEFAULT("Getting device being commissioned with node ID 0x%016llX: %@ (error: %@)",
nodeID.unsignedLongLongValue, device, (error ? *error : nil));
return device;
}

- (MTRBaseDevice *)baseDeviceForNodeID:(NSNumber *)nodeID
Expand Down
2 changes: 2 additions & 0 deletions src/darwin/Framework/CHIP/MTRSetupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ typedef NS_OPTIONS(NSUInteger, MTRDiscoveryCapabilities) {
MTRDiscoveryCapabilitiesBLE = 1 << 1, // Device supports BLE
MTRDiscoveryCapabilitiesOnNetwork = 1 << 2, // Device supports On Network setup

// If new values are added here, update the "description" method to include them.

MTRDiscoveryCapabilitiesAllMask
= MTRDiscoveryCapabilitiesSoftAP | MTRDiscoveryCapabilitiesBLE | MTRDiscoveryCapabilitiesOnNetwork,
};
Expand Down
20 changes: 20 additions & 0 deletions src/darwin/Framework/CHIP/MTRSetupPayload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ + (MTRSetupPayload * _Nullable)setupPayloadWithOnboardingPayload:(NSString *)onb
return payload;
}

- (NSString *)description
{
NSMutableArray<NSString *> * capabilities = [NSMutableArray array];
if (self.discoveryCapabilities & MTRDiscoveryCapabilitiesSoftAP) {
[capabilities addObject:@"SoftAP"];
}
if (self.discoveryCapabilities & MTRDiscoveryCapabilitiesBLE) {
[capabilities addObject:@"BLE"];
}
if (self.discoveryCapabilities & MTRDiscoveryCapabilitiesOnNetwork) {
[capabilities addObject:@"OnNetwork"];
}
if (capabilities.count == 0) {
[capabilities addObject:@"Unknown"];
}

return [NSString stringWithFormat:@"<MTRSetupPayload: discriminator=0x%x hasShortDiscriminator=%@ discoveryCapabilities=%@>",
self.discriminator.unsignedIntValue, self.hasShortDiscriminator ? @"YES" : @"NO", [capabilities componentsJoinedByString:@"|"]];
}

#pragma mark - NSSecureCoding

static NSString * const MTRSetupPayloadCodingKeyVersion = @"MTRSP.ck.version";
Expand Down
10 changes: 10 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ - (void)controller:(MTRDeviceController *)controller commissioningSessionEstabli
{
XCTAssertEqual(error.code, 0);

NSError * getDeviceError = nil;
__auto_type * device = [controller deviceBeingCommissionedWithNodeID:@(kDeviceId) error:&getDeviceError];
XCTAssertNil(getDeviceError);
XCTAssertNotNil(device);

// Now check that getting with some other random id fails.
device = [controller deviceBeingCommissionedWithNodeID:@(kDeviceId + 1) error:&getDeviceError];
XCTAssertNil(device);
XCTAssertNotNil(getDeviceError);

__auto_type * params = [[MTRCommissioningParameters alloc] init];
params.countryCode = @("au");

Expand Down

0 comments on commit 335ae19

Please sign in to comment.