diff --git a/examples/darwin-framework-tool/commands/payload/SetupPayloadParseCommand.mm b/examples/darwin-framework-tool/commands/payload/SetupPayloadParseCommand.mm index 97241da2efcb84..15be061b9308db 100644 --- a/examples/darwin-framework-tool/commands/payload/SetupPayloadParseCommand.mm +++ b/examples/darwin-framework-tool/commands/payload/SetupPayloadParseCommand.mm @@ -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; @@ -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); @@ -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) { diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.m index d20b623edd9c1e..a5227a673797b5 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Enumeration/EnumerateViewController.m @@ -133,7 +133,7 @@ - (void)enumerate for (NSNumber * endpoint in endpointsInUse) { MTRBaseClusterDescriptor * descriptorCluster = [[MTRBaseClusterDescriptor alloc] initWithDevice:device endpoint:endpoint queue:dispatch_get_main_queue()]; - [descriptorCluster readAttributeDeviceListWithCompletionHandler:^( + [descriptorCluster readAttributeDeviceTypeListWithCompletionHandler:^( NSArray * _Nullable value, NSError * _Nullable error) { if (error) { NSString * resultLog = [[NSString alloc] diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m index e31e52b6bff618..ec4ce5d69052ca 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m @@ -706,10 +706,10 @@ - (void)updateUIFields:(MTRSetupPayload *)payload rawPayload:(nullable NSString } else { _manualCodeLabel.hidden = YES; _versionLabel.text = [NSString stringWithFormat:@"%@", payload.version]; - if (payload.rendezvousInformation == nil) { + if (payload.discoveryCapabilities == MTRDiscoveryCapabilitiesUnknown) { _rendezVousInformation.text = NOT_APPLICABLE_STRING; } else { - _rendezVousInformation.text = [NSString stringWithFormat:@"%lu", [payload.rendezvousInformation unsignedLongValue]]; + _rendezVousInformation.text = [NSString stringWithFormat:@"%lu", payload.discoveryCapabilities]; } if ([payload.serialNumber length] > 0) { self->_serialNumber.text = payload.serialNumber; @@ -719,7 +719,7 @@ - (void)updateUIFields:(MTRSetupPayload *)payload rawPayload:(nullable NSString } _discriminatorLabel.text = [NSString stringWithFormat:@"%@", payload.discriminator]; - _setupPinCodeLabel.text = [NSString stringWithFormat:@"%@", payload.setUpPINCode]; + _setupPinCodeLabel.text = [NSString stringWithFormat:@"%@", payload.setupPasscode]; // TODO: Only display vid and pid if present _vendorID.text = [NSString stringWithFormat:@"%@", payload.vendorID]; _productID.text = [NSString stringWithFormat:@"%@", payload.productID]; @@ -747,7 +747,7 @@ - (void)parseOptionalData:(MTRSetupPayload *)payload continue; } - BOOL isTypeString = [info.infoType isEqualToNumber:[NSNumber numberWithInt:MTROptionalQRCodeInfoTypeString]]; + BOOL isTypeString = (info.infoType == MTROptionalQRCodeInfoTypeString); if (!isTypeString) { return; } @@ -767,26 +767,29 @@ - (void)parseOptionalData:(MTRSetupPayload *)payload - (void)handleRendezVous:(MTRSetupPayload *)payload rawPayload:(NSString *)rawPayload { - if (payload.rendezvousInformation == nil) { + if (payload.discoveryCapabilities == MTRDiscoveryCapabilitiesUnknown) { NSLog(@"Rendezvous Default"); [self handleRendezVousDefault:rawPayload]; return; } - // TODO: This is a pretty broken way to handle a bitmask. - switch ([payload.rendezvousInformation unsignedLongValue]) { - case MTRDiscoveryCapabilitiesNone: - case MTRDiscoveryCapabilitiesOnNetwork: - case MTRDiscoveryCapabilitiesBLE: - case MTRDiscoveryCapabilitiesAllMask: + // Avoid SoftAP if we have other options. + if ((payload.discoveryCapabilities & MTRDiscoveryCapabilitiesOnNetwork) + || (payload.discoveryCapabilities & MTRDiscoveryCapabilitiesBLE)) { NSLog(@"Rendezvous Default"); [self handleRendezVousDefault:rawPayload]; - break; - case MTRDiscoveryCapabilitiesSoftAP: + return; + } + + if (payload.discoveryCapabilities & MTRDiscoveryCapabilitiesSoftAP) { NSLog(@"Rendezvous Wi-Fi"); [self handleRendezVousWiFi:[self getNetworkName:payload.discriminator]]; - break; + return; } + + // Just fall back on the default. + NSLog(@"Rendezvous Default"); + [self handleRendezVousDefault:rawPayload]; } - (NSString *)getNetworkName:(NSNumber *)discriminator @@ -879,9 +882,8 @@ - (void)scannedQRCode:(NSString *)qrCode [self->_captureSession stopRunning]; [self->_session invalidateSession]; }); - MTRQRCodeSetupPayloadParser * parser = [[MTRQRCodeSetupPayloadParser alloc] initWithBase38Representation:qrCode]; NSError * error; - _setupPayload = [parser populatePayload:&error]; + _setupPayload = [MTRSetupPayload setupPayloadWithOnboardingPayload:qrCode error:&error]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self postScanningQRCodeState]; @@ -952,9 +954,8 @@ - (IBAction)enteredManualCode:(id)sender NSString * decimalString = _manualCodeTextField.text; [self manualCodeEnteredStartState]; - MTRManualSetupPayloadParser * parser = [[MTRManualSetupPayloadParser alloc] initWithDecimalStringRepresentation:decimalString]; NSError * error; - _setupPayload = [parser populatePayload:&error]; + _setupPayload = [MTRSetupPayload setupPayloadWithOnboardingPayload:decimalString error:&error]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, INDICATOR_DELAY), dispatch_get_main_queue(), ^{ [self displayManualCodeInSetupPayloadView:self->_setupPayload decimalString:decimalString withError:error]; }); diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.h b/src/darwin/Framework/CHIP/MTRDeviceController.h index 31f55b3ad6c449..071b9d892e1212 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController.h @@ -18,7 +18,6 @@ #import #import -#import @class MTRBaseDevice; diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload.h b/src/darwin/Framework/CHIP/MTRSetupPayload.h index 4d6587ac6d7b88..4b9c3298352e06 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload.h +++ b/src/darwin/Framework/CHIP/MTRSetupPayload.h @@ -19,8 +19,8 @@ NS_ASSUME_NONNULL_BEGIN -typedef NS_ENUM(NSUInteger, MTRDiscoveryCapabilities) { - MTRDiscoveryCapabilitiesNone = 0, // Device does not support any method for rendezvous +typedef NS_OPTIONS(NSUInteger, MTRDiscoveryCapabilities) { + MTRDiscoveryCapabilitiesUnknown = 0, // Device capabilties are not known (e.g. all we have is a manual pairing code). MTRDiscoveryCapabilitiesSoftAP = 1 << 0, // Device supports WiFi softAP MTRDiscoveryCapabilitiesBLE = 1 << 1, // Device supports BLE MTRDiscoveryCapabilitiesOnNetwork = 1 << 2, // Device supports On Network setup @@ -36,19 +36,26 @@ typedef NS_ENUM(NSUInteger, MTRCommissioningFlow) { MTRCommissioningFlowInvalid = 3, }; -typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) { - MTROptionalQRCodeInfoTypeUnknown, - MTROptionalQRCodeInfoTypeString, - MTROptionalQRCodeInfoTypeInt32 -}; +typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) { MTROptionalQRCodeInfoTypeString, MTROptionalQRCodeInfoTypeInt32 }; +/** + * An optional information item present in the QR code the setup payload was + * initialized from. + */ @interface MTROptionalQRCodeInfo : NSObject -@property (nonatomic, copy) NSNumber * infoType; +@property (nonatomic, assign) MTROptionalQRCodeInfoType infoType; +// The numeric value of the TLV tag for this information item. @property (nonatomic, copy) NSNumber * tag; -@property (nonatomic, copy) NSNumber * integerValue; -@property (nonatomic, copy) NSString * stringValue; +// Exactly one of integerValue and stringValue will be non-nil, depending on the +// the value of "infoType". +@property (nonatomic, copy, nullable) NSNumber * integerValue; +@property (nonatomic, copy, nullable) NSString * stringValue; @end +/** + * A setup payload that can be created from a pairing code and serialized to a + * pairing code. + */ @interface MTRSetupPayload : NSObject @property (nonatomic, copy) NSNumber * version; @@ -56,17 +63,20 @@ typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) { @property (nonatomic, copy) NSNumber * productID; @property (nonatomic, assign) MTRCommissioningFlow commissioningFlow; /** - * rendezvousInformation is nil when the discovery capabilities bitmask is - * unknown. - * - * Otherwise its value is made up of the MTRDiscoveryCapabilities flags. + * The value of discoveryCapabilities is made up of the various MTRDiscoveryCapabilities flags. */ -@property (nonatomic, copy, nullable) NSNumber * rendezvousInformation; +@property (nonatomic, assign) MTRDiscoveryCapabilities discoveryCapabilities; @property (nonatomic, copy) NSNumber * discriminator; +/** + * If hasShortDiscriminator is true, the discriminator value contains just the + * high 4 bits of the full discriminator. For example, if + * hasShortDiscriminator is true and discriminator is 0xA, then the full + * discriminator can be anything in the range 0xA00 t0 0xAFF. + */ @property (nonatomic, assign) BOOL hasShortDiscriminator; -@property (nonatomic, copy) NSNumber * setUpPINCode; +@property (nonatomic, copy) NSNumber * setupPasscode; -@property (nonatomic, copy) NSString * serialNumber; +@property (nonatomic, copy, nullable) NSString * serialNumber; - (nullable NSArray *)getAllOptionalVendorData:(NSError * __autoreleasing *)error; /** @@ -74,6 +84,14 @@ typedef NS_ENUM(NSUInteger, MTROptionalQRCodeInfoType) { */ + (NSNumber *)generateRandomSetupPasscode; +/** + * Create an MTRSetupPayload with the given onboarding payload. + * + * Will return nil on errors (e.g. if the onboarding payload cannot be parsed). + */ ++ (MTRSetupPayload * _Nullable)setupPayloadWithOnboardingPayload:(NSString *)onboardingPayload + error:(NSError * __autoreleasing *)error; + /** Get 11 digit manual entry code from the setup payload. */ - (nullable NSString *)manualEntryCode; diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload.mm b/src/darwin/Framework/CHIP/MTRSetupPayload.mm index 2dbcd1e3cfede5..7c2df4dbbdd178 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload.mm +++ b/src/darwin/Framework/CHIP/MTRSetupPayload.mm @@ -17,6 +17,7 @@ #import "MTRError.h" #import "MTRError_Internal.h" +#import "MTROnboardingPayloadParser.h" #import "MTRSetupPayload_Internal.h" #import "setup_payload/ManualSetupPayloadGenerator.h" #import @@ -28,13 +29,13 @@ @implementation MTRSetupPayload { chip::SetupPayload _chipSetupPayload; } -- (NSNumber *)convertRendezvousFlags:(const chip::Optional &)value +- (MTRDiscoveryCapabilities)convertRendezvousFlags:(const chip::Optional &)value { if (!value.HasValue()) { - return nil; + return MTRDiscoveryCapabilitiesUnknown; } - NSUInteger flags = MTRDiscoveryCapabilitiesNone; + NSUInteger flags = 0; if (value.Value().Has(chip::RendezvousInformationFlag::kBLE)) { flags |= MTRDiscoveryCapabilitiesBLE; } @@ -44,7 +45,11 @@ - (NSNumber *)convertRendezvousFlags:(const chip::Optional(self.commissioningFlow) forKey:MTRSetupPayloadCodingKeyCommissioningFlow]; - [coder encodeObject:self.rendezvousInformation forKey:MTRSetupPayloadCodingKeyRendezvousFlags]; + [coder encodeInteger:static_cast(self.discoveryCapabilities) forKey:MTRSetupPayloadCodingKeyDiscoveryCapabilities]; [coder encodeInteger:static_cast(self.hasShortDiscriminator) forKey:MTRSetupPayloadCodingKeyHasShortDiscriminator]; [coder encodeObject:self.discriminator forKey:MTRSetupPayloadCodingKeyDiscriminator]; - [coder encodeObject:self.setUpPINCode forKey:MTRSetupPayloadCodingKeySetupPINCode]; + [coder encodeObject:self.setupPasscode forKey:MTRSetupPayloadCodingKeySetupPasscode]; [coder encodeObject:self.serialNumber forKey:MTRSetupPayloadCodingKeySerialNumber]; } @@ -176,11 +188,10 @@ - (nullable instancetype)initWithCoder:(NSCoder *)decoder NSNumber * vendorID = [decoder decodeObjectOfClass:[NSNumber class] forKey:MTRSetupPayloadCodingKeyVendorID]; NSNumber * productID = [decoder decodeObjectOfClass:[NSNumber class] forKey:MTRSetupPayloadCodingKeyProductID]; NSInteger commissioningFlow = [decoder decodeIntegerForKey:MTRSetupPayloadCodingKeyCommissioningFlow]; - NSNumber * rendezvousInformation = [decoder decodeObjectOfClass:[NSNumber class] - forKey:MTRSetupPayloadCodingKeyRendezvousFlags]; + NSInteger discoveryCapabilities = [decoder decodeIntegerForKey:MTRSetupPayloadCodingKeyDiscoveryCapabilities]; NSInteger hasShortDiscriminator = [decoder decodeIntegerForKey:MTRSetupPayloadCodingKeyHasShortDiscriminator]; NSNumber * discriminator = [decoder decodeObjectOfClass:[NSNumber class] forKey:MTRSetupPayloadCodingKeyDiscriminator]; - NSNumber * setUpPINCode = [decoder decodeObjectOfClass:[NSNumber class] forKey:MTRSetupPayloadCodingKeySetupPINCode]; + NSNumber * setupPasscode = [decoder decodeObjectOfClass:[NSNumber class] forKey:MTRSetupPayloadCodingKeySetupPasscode]; NSString * serialNumber = [decoder decodeObjectOfClass:[NSString class] forKey:MTRSetupPayloadCodingKeySerialNumber]; MTRSetupPayload * payload = [[MTRSetupPayload alloc] init]; @@ -188,10 +199,10 @@ - (nullable instancetype)initWithCoder:(NSCoder *)decoder payload.vendorID = vendorID; payload.productID = productID; payload.commissioningFlow = static_cast(commissioningFlow); - payload.rendezvousInformation = rendezvousInformation; + payload.discoveryCapabilities = static_cast(discoveryCapabilities); payload.hasShortDiscriminator = static_cast(hasShortDiscriminator); payload.discriminator = discriminator; - payload.setUpPINCode = setUpPINCode; + payload.setupPasscode = setupPasscode; payload.serialNumber = serialNumber; return payload; @@ -211,7 +222,7 @@ - (nullable NSString *)manualEntryCode } else { payload.discriminator.SetLongValue([self.discriminator unsignedShortValue]); } - payload.setUpPINCode = [self.setUpPINCode unsignedIntValue]; + payload.setUpPINCode = [self.setupPasscode unsignedIntValue]; err = chip::ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(outDecimalString); diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload_Internal.h b/src/darwin/Framework/CHIP/MTRSetupPayload_Internal.h index 4abd9d9e8a5b05..7950d029c84790 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload_Internal.h +++ b/src/darwin/Framework/CHIP/MTRSetupPayload_Internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus - (id)initWithSetupPayload:(chip::SetupPayload)setupPayload; -- (NSNumber *)convertRendezvousFlags:(const chip::Optional &)value; +- (MTRDiscoveryCapabilities)convertRendezvousFlags:(const chip::Optional &)value; - (MTRCommissioningFlow)convertCommissioningFlow:(chip::CommissioningFlow)value; #endif diff --git a/src/darwin/Framework/CHIP/Matter.h b/src/darwin/Framework/CHIP/Matter.h index d702cb7c4f21fc..c2040c08a882c4 100644 --- a/src/darwin/Framework/CHIP/Matter.h +++ b/src/darwin/Framework/CHIP/Matter.h @@ -38,12 +38,10 @@ #import #import #import -#import #import #import #import #import -#import #import #import #import diff --git a/src/darwin/Framework/CHIPTests/MTRSetupPayloadParserTests.m b/src/darwin/Framework/CHIPTests/MTRSetupPayloadParserTests.m index 67b6a9caad9c6a..feadedac8d091d 100644 --- a/src/darwin/Framework/CHIPTests/MTRSetupPayloadParserTests.m +++ b/src/darwin/Framework/CHIPTests/MTRSetupPayloadParserTests.m @@ -18,9 +18,6 @@ * limitations under the License. */ // module headers -#import "MTRManualSetupPayloadParser.h" -#import "MTROnboardingPayloadParser.h" -#import "MTRQRCodeSetupPayloadParser.h" #import "MTRSetupPayload.h" // additional includes @@ -38,87 +35,81 @@ @implementation MTRSetupPayloadParserTests - (void)testOnboardingPayloadParser_Manual_NoError { NSError * error; - MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"636108753500001000015" error:&error]; + MTRSetupPayload * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:@"636108753500001000015" error:&error]; XCTAssertNotNil(payload); XCTAssertNil(error); XCTAssertTrue(payload.hasShortDiscriminator); XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 10); - XCTAssertEqual(payload.setUpPINCode.unsignedIntegerValue, 123456780); + XCTAssertEqual(payload.setupPasscode.unsignedIntegerValue, 123456780); XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 1); XCTAssertEqual(payload.productID.unsignedIntegerValue, 1); XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowCustom); XCTAssertEqual(payload.version.unsignedIntegerValue, 0); - XCTAssertNil(payload.rendezvousInformation); + XCTAssertEqual(payload.discoveryCapabilities, MTRDiscoveryCapabilitiesUnknown); } - (void)testOnboardingPayloadParser_QRCode_NoError { NSError * error; - MTRSetupPayload * payload = [MTROnboardingPayloadParser setupPayloadForOnboardingPayload:@"MT:R5L90MP500K64J00000" - error:&error]; + MTRSetupPayload * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:@"MT:R5L90MP500K64J00000" error:&error]; XCTAssertNotNil(payload); XCTAssertNil(error); XCTAssertFalse(payload.hasShortDiscriminator); XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 128); - XCTAssertEqual(payload.setUpPINCode.unsignedIntegerValue, 2048); + XCTAssertEqual(payload.setupPasscode.unsignedIntegerValue, 2048); XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 12); XCTAssertEqual(payload.productID.unsignedIntegerValue, 1); XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowStandard); XCTAssertEqual(payload.version.unsignedIntegerValue, 5); - XCTAssertNotNil(payload.rendezvousInformation); - XCTAssertEqual([payload.rendezvousInformation unsignedLongValue], MTRDiscoveryCapabilitiesSoftAP); + XCTAssertEqual(payload.discoveryCapabilities, MTRDiscoveryCapabilitiesSoftAP); } - (void)testOnboardingPayloadParser_NFC_NoError { NSError * error; - MTRSetupPayload * payload = [MTROnboardingPayloadParser - setupPayloadForOnboardingPayload:@"MT:R5L90MP500K64J0A33P0SET70.QT52B.E23-WZE0WISA0DK5N1K8SQ1RYCU1O0" - error:&error]; + MTRSetupPayload * payload = + [MTRSetupPayload setupPayloadWithOnboardingPayload:@"MT:R5L90MP500K64J0A33P0SET70.QT52B.E23-WZE0WISA0DK5N1K8SQ1RYCU1O0" + error:&error]; XCTAssertNotNil(payload); XCTAssertNil(error); XCTAssertFalse(payload.hasShortDiscriminator); XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 128); - XCTAssertEqual(payload.setUpPINCode.unsignedIntegerValue, 2048); + XCTAssertEqual(payload.setupPasscode.unsignedIntegerValue, 2048); XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 12); XCTAssertEqual(payload.productID.unsignedIntegerValue, 1); XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowStandard); XCTAssertEqual(payload.version.unsignedIntegerValue, 5); - XCTAssertNotNil(payload.rendezvousInformation); - XCTAssertEqual([payload.rendezvousInformation unsignedLongValue], MTRDiscoveryCapabilitiesSoftAP); + XCTAssertEqual(payload.discoveryCapabilities, MTRDiscoveryCapabilitiesSoftAP); } - (void)testManualParser { NSError * error; - MTRManualSetupPayloadParser * parser = - [[MTRManualSetupPayloadParser alloc] initWithDecimalStringRepresentation:@"636108753500001000015"]; - MTRSetupPayload * payload = [parser populatePayload:&error]; + MTRSetupPayload * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:@"636108753500001000015" error:&error]; XCTAssertNotNil(payload); XCTAssertNil(error); XCTAssertTrue(payload.hasShortDiscriminator); XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 10); - XCTAssertEqual(payload.setUpPINCode.unsignedIntegerValue, 123456780); + XCTAssertEqual(payload.setupPasscode.unsignedIntegerValue, 123456780); XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 1); XCTAssertEqual(payload.productID.unsignedIntegerValue, 1); XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowCustom); XCTAssertEqual(payload.version.unsignedIntegerValue, 0); - XCTAssertNil(payload.rendezvousInformation); + XCTAssertEqual(payload.discoveryCapabilities, MTRDiscoveryCapabilitiesUnknown); } - (void)testManualParser_Error { NSError * error; - MTRManualSetupPayloadParser * parser = [[MTRManualSetupPayloadParser alloc] initWithDecimalStringRepresentation:@""]; - MTRSetupPayload * payload = [parser populatePayload:&error]; + MTRSetupPayload * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:@"" error:&error]; XCTAssertNil(payload); XCTAssertEqual(error.code, MTRErrorCodeInvalidStringLength); @@ -127,9 +118,7 @@ - (void)testManualParser_Error - (void)testQRCodeParser_Error { NSError * error; - MTRQRCodeSetupPayloadParser * parser = - [[MTRQRCodeSetupPayloadParser alloc] initWithBase38Representation:@"MT:R5L90MP500K64J0000."]; - MTRSetupPayload * payload = [parser populatePayload:&error]; + MTRSetupPayload * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:@"MT:R5L90MP500K64J0000." error:&error]; XCTAssertNil(payload); XCTAssertEqual(error.code, MTRErrorCodeInvalidArgument); @@ -138,30 +127,27 @@ - (void)testQRCodeParser_Error - (void)testQRCodeParser { NSError * error; - MTRQRCodeSetupPayloadParser * parser = - [[MTRQRCodeSetupPayloadParser alloc] initWithBase38Representation:@"MT:R5L90MP500K64J00000"]; - MTRSetupPayload * payload = [parser populatePayload:&error]; + MTRSetupPayload * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:@"MT:R5L90MP500K64J00000" error:&error]; XCTAssertNotNil(payload); XCTAssertNil(error); XCTAssertFalse(payload.hasShortDiscriminator); XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 128); - XCTAssertEqual(payload.setUpPINCode.unsignedIntegerValue, 2048); + XCTAssertEqual(payload.setupPasscode.unsignedIntegerValue, 2048); XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 12); XCTAssertEqual(payload.productID.unsignedIntegerValue, 1); XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowStandard); XCTAssertEqual(payload.version.unsignedIntegerValue, 5); - XCTAssertNotNil(payload.rendezvousInformation); - XCTAssertEqual([payload.rendezvousInformation unsignedLongValue], MTRDiscoveryCapabilitiesSoftAP); + XCTAssertEqual(payload.discoveryCapabilities, MTRDiscoveryCapabilitiesSoftAP); } - (void)testQRCodeParserWithOptionalData { NSError * error; - MTRQRCodeSetupPayloadParser * parser = [[MTRQRCodeSetupPayloadParser alloc] - initWithBase38Representation:@"MT:R5L90MP500K64J0A33P0SET70.QT52B.E23-WZE0WISA0DK5N1K8SQ1RYCU1O0"]; - MTRSetupPayload * payload = [parser populatePayload:&error]; + MTRSetupPayload * payload = + [MTRSetupPayload setupPayloadWithOnboardingPayload:@"MT:R5L90MP500K64J0A33P0SET70.QT52B.E23-WZE0WISA0DK5N1K8SQ1RYCU1O0" + error:&error]; XCTAssertNotNil(payload); XCTAssertNil(error); @@ -169,12 +155,11 @@ - (void)testQRCodeParserWithOptionalData XCTAssertEqual(payload.version.unsignedIntegerValue, 5); XCTAssertFalse(payload.hasShortDiscriminator); XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 128); - XCTAssertEqual(payload.setUpPINCode.unsignedIntegerValue, 2048); + XCTAssertEqual(payload.setupPasscode.unsignedIntegerValue, 2048); XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 12); XCTAssertEqual(payload.productID.unsignedIntegerValue, 1); XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowStandard); - XCTAssertNotNil(payload.rendezvousInformation); - XCTAssertEqual([payload.rendezvousInformation unsignedLongValue], MTRDiscoveryCapabilitiesSoftAP); + XCTAssertEqual(payload.discoveryCapabilities, MTRDiscoveryCapabilitiesSoftAP); XCTAssertTrue([payload.serialNumber isEqualToString:@"123456789"]); NSArray * vendorOptionalInfo = [payload getAllOptionalVendorData:&error]; @@ -182,13 +167,31 @@ - (void)testQRCodeParserWithOptionalData XCTAssertEqual([vendorOptionalInfo count], 2); for (MTROptionalQRCodeInfo * info in vendorOptionalInfo) { if (info.tag.intValue == 130) { - XCTAssertEqual(info.infoType.intValue, MTROptionalQRCodeInfoTypeString); + XCTAssertEqual(info.infoType, MTROptionalQRCodeInfoTypeString); XCTAssertTrue([info.stringValue isEqualToString:@"myData"]); } else if (info.tag.intValue == 131) { - XCTAssertEqual(info.infoType.intValue, MTROptionalQRCodeInfoTypeInt32); + XCTAssertEqual(info.infoType, MTROptionalQRCodeInfoTypeInt32); XCTAssertEqual(info.integerValue.intValue, 12); } } } +- (void)testQRCodeWithNoCapabilities +{ + NSError * error; + MTRSetupPayload * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:@"MT:M5L9000000K64J00000" error:&error]; + + XCTAssertNotNil(payload); + XCTAssertNil(error); + + XCTAssertFalse(payload.hasShortDiscriminator); + XCTAssertEqual(payload.discriminator.unsignedIntegerValue, 128); + XCTAssertEqual(payload.setupPasscode.unsignedIntegerValue, 2048); + XCTAssertEqual(payload.vendorID.unsignedIntegerValue, 12); + XCTAssertEqual(payload.productID.unsignedIntegerValue, 1); + XCTAssertEqual(payload.commissioningFlow, MTRCommissioningFlowStandard); + XCTAssertEqual(payload.version.unsignedIntegerValue, 0); + XCTAssertEqual(payload.discoveryCapabilities, MTRDiscoveryCapabilitiesOnNetwork); +} + @end diff --git a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj index c9d9940d9c6611..d643e28707c3f0 100644 --- a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj +++ b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj @@ -118,13 +118,13 @@ AF1CB8702874B04C00865A96 /* MTROTAProviderDelegateBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1CB86F2874B04C00865A96 /* MTROTAProviderDelegateBridge.h */; }; AF5F90FF2878D351005503FA /* MTROTAProviderDelegateBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = AF5F90FE2878D351005503FA /* MTROTAProviderDelegateBridge.mm */; }; B20252972459E34F00F97062 /* Matter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B202528D2459E34F00F97062 /* Matter.framework */; }; - B289D4212639C0D300D4E314 /* MTROnboardingPayloadParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B289D41F2639C0D300D4E314 /* MTROnboardingPayloadParser.h */; settings = {ATTRIBUTES = (Public, ); }; }; + B289D4212639C0D300D4E314 /* MTROnboardingPayloadParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B289D41F2639C0D300D4E314 /* MTROnboardingPayloadParser.h */; }; B289D4222639C0D300D4E314 /* MTROnboardingPayloadParser.m in Sources */ = {isa = PBXBuildFile; fileRef = B289D4202639C0D300D4E314 /* MTROnboardingPayloadParser.m */; }; B2E0D7B1245B0B5C003C5B48 /* Matter.h in Headers */ = {isa = PBXBuildFile; fileRef = B2E0D7A8245B0B5C003C5B48 /* Matter.h */; settings = {ATTRIBUTES = (Public, ); }; }; - B2E0D7B2245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B2E0D7A9245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h */; settings = {ATTRIBUTES = (Public, ); }; }; + B2E0D7B2245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B2E0D7A9245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h */; }; B2E0D7B3245B0B5C003C5B48 /* MTRError.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2E0D7AA245B0B5C003C5B48 /* MTRError.mm */; }; B2E0D7B4245B0B5C003C5B48 /* MTRError_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = B2E0D7AB245B0B5C003C5B48 /* MTRError_Internal.h */; }; - B2E0D7B5245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B2E0D7AC245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.h */; settings = {ATTRIBUTES = (Public, ); }; }; + B2E0D7B5245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B2E0D7AC245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.h */; }; B2E0D7B6245B0B5C003C5B48 /* MTRManualSetupPayloadParser.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2E0D7AD245B0B5C003C5B48 /* MTRManualSetupPayloadParser.mm */; }; B2E0D7B7245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2E0D7AE245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.mm */; }; B2E0D7B8245B0B5C003C5B48 /* MTRSetupPayload.h in Headers */ = {isa = PBXBuildFile; fileRef = B2E0D7AF245B0B5C003C5B48 /* MTRSetupPayload.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -511,7 +511,6 @@ 515C1C70284F9FFB00A48F0C /* MTRMemory.h in Headers */, 7534F12928BFF20300390851 /* MTRDeviceAttestationDelegate_Internal.h in Headers */, D4772A46285AE98400383630 /* MTRClusterConstants.h in Headers */, - B289D4212639C0D300D4E314 /* MTROnboardingPayloadParser.h in Headers */, 513DDB862761F69300DAA01A /* MTRAttributeTLVValueDecoder_Internal.h in Headers */, 2CB7163F252F731E0026E2BB /* MTRDevicePairingDelegate.h in Headers */, 88EBF8CE27FABDD500686BC1 /* MTRDeviceAttestationDelegate.h in Headers */, @@ -522,10 +521,12 @@ 754F3DF427FBB94B00E60580 /* MTREventTLVValueDecoder_Internal.h in Headers */, 3CF134AF289D90FF0017A19E /* MTRNOCChainIssuer.h in Headers */, 3CF134AB289D8DF70017A19E /* MTRAttestationInfo.h in Headers */, - B2E0D7B2245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h in Headers */, 3CF134A7289D8ADA0017A19E /* MTRCSRInfo.h in Headers */, B2E0D7B1245B0B5C003C5B48 /* Matter.h in Headers */, 7596A84428762729004DAE0E /* MTRDevice.h in Headers */, + B2E0D7B5245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.h in Headers */, + B2E0D7B2245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h in Headers */, + B289D4212639C0D300D4E314 /* MTROnboardingPayloadParser.h in Headers */, B2E0D7B8245B0B5C003C5B48 /* MTRSetupPayload.h in Headers */, 7596A84D287782EF004DAE0E /* MTRAsyncCallbackWorkQueue_Internal.h in Headers */, 7596A83E28751220004DAE0E /* MTRBaseClusters_internal.h in Headers */, @@ -543,7 +544,6 @@ 5129BCFD26A9EE3300122DDF /* MTRError.h in Headers */, 2C8C8FC1253E0C2100797F05 /* MTRPersistentStorageDelegate.h in Headers */, AF1CB8702874B04C00865A96 /* MTROTAProviderDelegateBridge.h in Headers */, - B2E0D7B5245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.h in Headers */, 1EC4CE6425CC276600D7304F /* MTRBaseClusters.h in Headers */, 2C5EEEF6268A85C400CAE3D3 /* MTRDeviceConnectionBridge.h in Headers */, 2C8C8FC0253E0C2100797F05 /* MTRPersistentStorageDelegateBridge.h in Headers */,