Skip to content

Commit

Permalink
Darwin API review fixes for MTRSetupPayload and MTROptionalQRCodeInfo (
Browse files Browse the repository at this point in the history
…project-chip#22566)

* Rename MTRDiscoveryCapabilitiesNone to MTRDiscoveryCapabilitiesUnknown to
  indicate capabilities unknown (e.g. manual setup code).
* In MTROptionalQRCodeInfo mark integerValue and stringValue as nullable and
  document they are mutually exclusive.
* In MTROptionalQRCodeInfo switch infoType to MTROptionalQRCodeInfoType, not
  NSNumber.
* Change rendezvousInformation to just be a MTRDiscoveryCapabilities value, not
  nullable NSNumber, with MTRDiscoveryCapabilitiesNone meaning unknown. When
  parsing QR code, if the value ends up as 0, reset it to
  MTRDiscoveryCapabilitiesOnNetwork.
* Rename setUpPINCode to setupPasscode.
* Mark serialNumber as nullable.
* Add setupPayloadWithOnboardingPayload class method on MTRSetupPayload.
* Stop exposing the various payload parser APIs from the framework;
  consumers should use setupPayloadWithOnboardingPayload.

Fixes project-chip#22543

Fixes project-chip#22539

Addresses part of project-chip#22420
  • Loading branch information
bzbarsky-apple committed Sep 12, 2022
1 parent 4b38a4a commit 756bd36
Show file tree
Hide file tree
Showing 61 changed files with 39,912 additions and 43,444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ClusterCommand : public ModelCommand {
timedInvokeTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
clientQueue:callbackQueue
queue:callbackQueue
completion:^(
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
responsesNeeded--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@
ChipLogProgress(chipTool, "Sending command to node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
[commissioner getBaseDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
if (error != nil) {
SetCommandExitStatus(error, "Error getting connected device");
return;
}

CHIP_ERROR err;
if (device == nil) {
err = CHIP_ERROR_INTERNAL;
} else {
err = SendCommand(device, mEndPointId);
}

if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
return;
}
}];
completion:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
if (error != nil) {
SetCommandExitStatus(error, "Error getting connected device");
return;
}

CHIP_ERROR err;
if (device == nil) {
err = CHIP_ERROR_INTERNAL;
} else {
err = SendCommand(device, mEndPointId);
}

if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
return;
}
}];
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ReadAttribute : public ModelCommand {
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
params:params
clientQueue:callbackQueue
queue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading attribute", error);
Expand Down Expand Up @@ -135,7 +135,7 @@ class SubscribeAttribute : public ModelCommand {
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]
maxInterval:[NSNumber numberWithUnsignedInteger:mMaxInterval]
params:params
clientQueue:callbackQueue
queue:callbackQueue
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (values) {
for (id item in values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class WriteAttribute : public ModelCommand {
timedWriteTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
clientQueue:callbackQueue
queue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error writing attribute", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@
params.commissioningTimeout = @(mCommissioningWindowTimeoutMs);
params.timedInvokeTimeoutMs = @(10000);
[cluster openBasicCommissioningWindowWithParams:params
completionHandler:^(NSError * _Nullable error) {
if (error == nil) {
self->SetCommandExitStatus(CHIP_NO_ERROR);
} else {
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
}
}];
completion:^(NSError * _Nullable error) {
if (error == nil) {
self->SetCommandExitStatus(CHIP_NO_ERROR);
} else {
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
}
}];
} else {
[device
openCommissioningWindowWithSetupPasscode:[MTRSetupPayload generateRandomSetupPasscode]
discriminator:@(mDiscriminator)
duration:@(mCommissioningWindowTimeoutMs)
clientQueue:mWorkQueue
queue:mWorkQueue
completion:^(MTRSetupPayload * _Nullable payload, NSError * error) {
if (error != nil) {
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,46 +111,47 @@
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);
MTRDeviceController * commissioner = CurrentCommissioner();
[commissioner getBaseDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
CHIP_ERROR err = CHIP_NO_ERROR;
if (error) {
err = MTRErrorToCHIPErrorCode(error);
LogNSError("Error: ", error);
SetCommandExitStatus(err);
} else if (device == nil) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL));
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
} else {
ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId);
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue];
[opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^(
NSNumber * _Nullable value, NSError * _Nullable readError) {
if (readError) {
CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError);
LogNSError("Failed to get current fabric: ", readError);
SetCommandExitStatus(readErr);
return;
}
MTROperationalCredentialsClusterRemoveFabricParams * params =
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
params.fabricIndex = value;
[opCredsCluster
removeFabricWithParams:params
completionHandler:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable removeError) {
CHIP_ERROR removeErr = CHIP_NO_ERROR;
if (removeError) {
removeErr = MTRErrorToCHIPErrorCode(removeError);
LogNSError("Failed to remove current fabric: ", removeError);
} else {
ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId);
}
SetCommandExitStatus(removeErr);
}];
}];
}
}];
[commissioner
getBaseDevice:mNodeId
queue:callbackQueue
completion:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
CHIP_ERROR err = CHIP_NO_ERROR;
if (error) {
err = MTRErrorToCHIPErrorCode(error);
LogNSError("Error: ", error);
SetCommandExitStatus(err);
} else if (device == nil) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL));
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
} else {
ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId);
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue];
[opCredsCluster
readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) {
if (readError) {
CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError);
LogNSError("Failed to get current fabric: ", readError);
SetCommandExitStatus(readErr);
return;
}
MTROperationalCredentialsClusterRemoveFabricParams * params =
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
params.fabricIndex = value;
[opCredsCluster
removeFabricWithParams:params
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable removeError) {
CHIP_ERROR removeErr = CHIP_NO_ERROR;
if (removeError) {
removeErr = MTRErrorToCHIPErrorCode(removeError);
LogNSError("Failed to remove current fabric: ", removeError);
} else {
ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId);
}
SetCommandExitStatus(removeErr);
}];
}];
}
}];
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
NSString * codeString = [NSString stringWithCString:mCode encoding:NSASCIIStringEncoding];
NSError * error;
MTRSetupPayload * payload;
payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:codeString error:&error];
payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:codeString error:&error];
if (error) {
LogNSError("Error: ", error);
return CHIP_ERROR_INTERNAL;
Expand All @@ -78,37 +78,33 @@
NSLog(@"ProductID: %@", payload.productID);
NSLog(@"Custom flow: %lu (%@)", payload.commissioningFlow, CustomFlowString(payload.commissioningFlow));
{
if (payload.rendezvousInformation == nil) {
if (payload.discoveryCapabilities == MTRDiscoveryCapabilitiesUnknown) {
NSLog(@"Capabilities: UNKNOWN");
} else {
NSMutableString * humanFlags = [[NSMutableString alloc] init];

auto value = [payload.rendezvousInformation unsignedLongValue];
if (value == MTRDiscoveryCapabilitiesNone) {
[humanFlags appendString:@"NONE"];
} else {
if (value & MTRDiscoveryCapabilitiesSoftAP) {
[humanFlags appendString:@"SoftAP"];
}
if (value & MTRDiscoveryCapabilitiesBLE) {
if (!humanFlags) {
[humanFlags appendString:@", "];
}
[humanFlags appendString:@"BLE"];
auto value = payload.discoveryCapabilities;
if (value & MTRDiscoveryCapabilitiesSoftAP) {
[humanFlags appendString:@"SoftAP"];
}
if (value & MTRDiscoveryCapabilitiesBLE) {
if (!humanFlags) {
[humanFlags appendString:@", "];
}
if (value & MTRDiscoveryCapabilitiesOnNetwork) {
if (!humanFlags) {
[humanFlags appendString:@", "];
}
[humanFlags appendString:@"ON NETWORK"];
[humanFlags appendString:@"BLE"];
}
if (value & MTRDiscoveryCapabilitiesOnNetwork) {
if (!humanFlags) {
[humanFlags appendString:@", "];
}
[humanFlags appendString:@"ON NETWORK"];
}

NSLog(@"Capabilities: 0x%02lX (%@)", value, humanFlags);
}
}
NSLog(@"Discriminator: %@", payload.discriminator);
NSLog(@"Passcode: %@", payload.setUpPINCode);
NSLog(@"Passcode: %@", payload.setupPasscode);

if (payload.serialNumber) {
NSLog(@"SerialNumber: %@", payload.serialNumber);
Expand All @@ -120,8 +116,8 @@
return CHIP_ERROR_INTERNAL;
}
for (const MTROptionalQRCodeInfo * info : optionalVendorData) {
bool isTypeString = [info.infoType isEqual:@(MTROptionalQRCodeInfoTypeString)];
bool isTypeInt32 = [info.infoType isEqual:@(MTROptionalQRCodeInfoTypeInt32)];
bool isTypeString = (info.infoType == MTROptionalQRCodeInfoTypeString);
bool isTypeInt32 = (info.infoType == MTROptionalQRCodeInfoTypeInt32);
VerifyOrReturnError(isTypeString || isTypeInt32, CHIP_ERROR_INVALID_ARGUMENT);

if (isTypeString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ typedef NS_ENUM(uint8_t, UserConsentState) {
- (void)handleQueryImageForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
completion:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completion;

- (void)handleApplyUpdateRequestForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
completion:
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completion;

- (void)handleNotifyUpdateAppliedForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler;
completion:(MTRStatusCompletion _Nonnull)completion;

@property (strong, nonatomic, nullable) NSArray<DeviceSoftwareVersionModel *> * candidates;
@property (strong, nonatomic, nullable) DeviceSoftwareVersionModel * selectedCandidate;
Expand Down
Loading

0 comments on commit 756bd36

Please sign in to comment.