Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed May 7, 2024
1 parent ec853df commit c0abb3f
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ - (uint16_t)vendorId
return _cppCastingPlayer->GetVendorId();
}

- (uint64_t)nodeId
{
return _cppCastingPlayer->GetNodeId();
}

- (uint8_t)fabricIndex
{
return _cppCastingPlayer->GetFabricIndex();
}

- (uint32_t)deviceType
{
return _cppCastingPlayer->GetDeviceType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@

@interface MCCastingPlayer ()

+ (MCCastingPlayer * _Nullable)getTargetCastingPlayer;

- (instancetype _Nonnull)initWithCppCastingPlayer:(matter::casting::memory::Strong<matter::casting::core::CastingPlayer>)cppCastingPlayer;

+ (MCCastingPlayer * _Nullable)getTargetCastingPlayer;
//- (uint64_t)nodeId;
//- (uint8_t)fabricIndex;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ - (instancetype _Nonnull)initWithCppEndpoint:(matter::casting::memory::Strong<ma
return self;
}

- (NSMutableArray *)getServerList
{
NSMutableArray * serverList = [NSMutableArray new];
if (_cppEndpoint != nil) {
std::vector<chip::ClusterId> cppServerList = _cppEndpoint->GetServerList();
for (chip::ClusterId clusterId : cppServerList) {
[serverList addObject:@(clusterId)];
}
}
return serverList;
}

- (NSNumber * _Nonnull)identifier
{
return [NSNumber numberWithUnsignedShort:_cppEndpoint->GetId()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

- (instancetype _Nonnull)initWithCppEndpoint:(matter::casting::memory::Strong<matter::casting::core::Endpoint>)cppEndpoint;

- (NSMutableArray *)getServerList;

@end

#endif /* MCEndpoint_Internal_h */
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#ifndef CastingServerBridge_h
#define CastingServerBridge_h

__attribute__((deprecated("This class is deprecated. Use ../../../../APIs.md instead.")))
__attribute__((deprecated("This class is deprecated. Use the APIs described in /examples/tv-casting-app/APIs.md instead.")))
@interface CastingServerBridge : NSObject

+ (CastingServerBridge * _Nullable)getSharedInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ - (void)openBasicCommissioningWindow:(dispatch_queue_t _Nonnull)clientQueue
_onConnectionFailureCallback = onConnectionFailureCallback;
_onNewOrUpdatedEndpointCallback = onNewOrUpdatedEndpointCallback;

// short-circuit commissioningWindow callbacks with MATTER_NO_ERROR
// no-op: short-circuit commissioningWindow callbacks with MATTER_NO_ERROR
dispatch_async(clientQueue, ^{
if (commissioningCallbackHandlers != nil) {
if (commissioningCallbackHandlers.commissioningWindowRequestedHandler != nil) {
Expand All @@ -222,9 +222,27 @@ - (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)comm
MCEndpointFilter * filter = [MCEndpointFilter new];
filter.vendorId = kAmazonAppVendorId;

[commissioner.getCastingPlayer verifyOrEstablishConnectionWithCompletionBlock:^(NSError * _Nullable) {
// TODO: callback on _onConnectionSuccessCallback, _onConnectionFailureCallback, _onNewOrUpdatedEndpointCallback
[commissioner.getCastingPlayer verifyOrEstablishConnectionWithCompletionBlock:^(NSError * _Nullable err) {
dispatch_async(clientQueue, ^{
if (err == nil) {
MCCastingPlayer * castingPlayer = [MCCastingPlayer getTargetCastingPlayer];
if (self->_onConnectionSuccessCallback != nil) {
self->_onConnectionSuccessCallback([[VideoPlayer alloc] initWithCastingPlayer:castingPlayer]);
}

if (self->_onNewOrUpdatedEndpointCallback != nil && castingPlayer != nil) {
NSArray<MCEndpoint *> * endpoints = castingPlayer.endpoints;
for (MCEndpoint * endpoint in endpoints) {
self->_onNewOrUpdatedEndpointCallback([[ContentApp alloc] initWithEndpoint:endpoint]);
}
}
}
});
} desiredEndpointFilter:filter];

dispatch_async(clientQueue, ^{
udcRequestSentHandler(MATTER_NO_ERROR);
});
}

- (void)getActiveTargetVideoPlayers:(dispatch_queue_t _Nonnull)clientQueue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#import <Foundation/Foundation.h>

#import "../MCEndpoint.h"

#ifndef ContentApp_h
#define ContentApp_h

Expand All @@ -33,6 +35,8 @@

- (instancetype)initWithEndpointId:(uint16_t)endpointId clusterIds:(NSMutableArray *)clusterIds;

- (instancetype)initWithEndpoint:(MCEndpoint *)endpoint;

- (BOOL)supportsClusterWithId:(uint32_t)clusterId;

- (BOOL)supportsApplicationLauncher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#import <Foundation/Foundation.h>

#import "../MCEndpoint_Internal.h"
#import "ContentApp.h"

#include <app-common/zap-generated/ids/Clusters.h>
Expand All @@ -41,6 +42,16 @@ - (instancetype)initWithEndpointId:(uint16_t)endpointId clusterIds:(NSMutableArr
return self;
}

- (instancetype)initWithEndpoint:(MCEndpoint *)endpoint
{
if (self = [super init]) {
_endpointId = [endpoint.identifier unsignedShortValue];
_clusterIds = [endpoint getServerList];
_isInitialized = true;
}
return self;
}

- (BOOL)supportsClusterWithId:(uint32_t)clusterId
{
if (_clusterIds != nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,38 +93,30 @@ - (MCDeviceAttestationCredentials *)castingAppDidReceiveRequestForDeviceAttestat

- (MatterError *)castingApp:(id)sender didReceiveRequestToSignCertificateRequest:(NSData *)csrData outRawSignature:(NSData * _Nonnull * _Nonnull)outRawSignature
{
NSLog(@"castingApp didReceiveRequestToSignCertificateRequest");

ChipLogProgress(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest called");
if (self.dacHolder != nil) {
CHIP_ERROR result = CHIP_NO_ERROR;

// Get the private SecKey from dacHolder
SecKeyRef privateSecKey = [self.dacHolder getDeviceAttestationCertPrivateKeyRef];

if (privateSecKey == nil) {
NSLog(@"Failed to retrieve private key from dacHolder.");
ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest No privateSecKey found");
return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT];
}

// Sign csrData to get asn1SignatureData
CFErrorRef error = nil;
CFDataRef asn1SignatureData = SecKeyCreateSignature(privateSecKey, kSecKeyAlgorithmECDSASignatureMessageX962SHA256, (__bridge CFDataRef) csrData, &error);
if (error != nil || asn1SignatureData == nil) {
NSLog(@"Failed to sign message. Error: %@", error);
if (error != nil) {
ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest failed to sign message, err: %@", error);
return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT];
}

// Convert ASN.1 DER signature to SEC1 raw format
MatterError * conversionError = [MCCryptoUtils ecdsaAsn1SignatureToRawWithFeLengthBytes:32
asn1Signature:asn1SignatureData
outRawSignature:outRawSignature];

if (conversionError != MATTER_NO_ERROR) {
NSLog(@"Failed to convert to raw signature.");
return conversionError;
if (asn1SignatureData == nil) {
ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest failed to sign message, asn1SignatureData is nil");
return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT];
}

return [MCErrorUtils MatterErrorFromChipError:result];
// Convert ASN.1 DER signature to SEC1 raw format
return [MCCryptoUtils ecdsaAsn1SignatureToRawWithFeLengthBytes:32 asn1Signature:asn1SignatureData
outRawSignature:outRawSignature];
}

return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

#import <Foundation/Foundation.h>

#import "ContentApp.h"
#import "VideoPlayer.h"
// #import "../MCCastingPlayer_Internal.h"

@interface VideoPlayer ()

Expand Down Expand Up @@ -73,17 +75,21 @@ - (instancetype)initWithCastingPlayer:(MCCastingPlayer *)castingPlayer
{
if (self = [super init]) {
_castingPlayer = castingPlayer;
//_nodeId = castingPlayer.nodeId;
//_fabricIndex = castingPlayer.fabricIndex;
_deviceName = castingPlayer.deviceName;
_vendorId = castingPlayer.vendorId;
_productId = castingPlayer.productId;
_deviceType = castingPlayer.deviceType;
_hostName = castingPlayer.hostName;
_instanceName = castingPlayer.instanceName;
_contentApps = [NSMutableArray new];
NSArray<MCEndpoint *> * endpoints = castingPlayer.endpoints;
for (MCEndpoint * endpoint in endpoints) {
[_contentApps addObject:[[ContentApp alloc] initWithEndpoint:endpoint]];
}
_isConnected = false; // this will make the compat shim call the openBasicCommissioningWindow API
_isInitialized = true;

//_contentApps = contentApps; TODO
//_MACAddress = MACAddress;
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
3C621CB32B6078B7005CDBA3 /* MCApplicationBasicReadVendorIDExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C621CB22B6078B7005CDBA3 /* MCApplicationBasicReadVendorIDExampleViewModel.swift */; };
3C621CB52B607FFD005CDBA3 /* MCActionSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C621CB42B607FFD005CDBA3 /* MCActionSelectorView.swift */; };
3C69204A2AA1368F00D0F613 /* MCInitializationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6920492AA1368F00D0F613 /* MCInitializationExample.swift */; };
3C81C75728F8E418001CB9D1 /* ConnectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C75628F8E418001CB9D1 /* ConnectionView.swift */; };
3C81C75928F8E42D001CB9D1 /* ConnectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C75828F8E42D001CB9D1 /* ConnectionViewModel.swift */; };
3C94377D2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C94377C2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift */; };
3C94377F2B364D510096E5F4 /* MCConnectionExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C94377E2B364D510096E5F4 /* MCConnectionExampleViewModel.swift */; };
3C94378E2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C94378D2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift */; };
Expand Down Expand Up @@ -69,8 +67,6 @@
3C7507AE28529A5F00D7DB3A /* CommissioningView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommissioningView.swift; sourceTree = "<group>"; };
3C7507B62853A3AD00D7DB3A /* CommissionerDiscoveryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommissionerDiscoveryViewModel.swift; sourceTree = "<group>"; };
3C7507B82853EFF000D7DB3A /* CommissioningViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommissioningViewModel.swift; sourceTree = "<group>"; };
3C81C75628F8E418001CB9D1 /* ConnectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionView.swift; sourceTree = "<group>"; };
3C81C75828F8E42D001CB9D1 /* ConnectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionViewModel.swift; sourceTree = "<group>"; };
3C94377C2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCDiscoveryExampleViewModel.swift; sourceTree = "<group>"; };
3C94377E2B364D510096E5F4 /* MCConnectionExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCConnectionExampleViewModel.swift; sourceTree = "<group>"; };
3C94378D2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCDiscoveryExampleView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -111,8 +107,6 @@
3C7507B62853A3AD00D7DB3A /* CommissionerDiscoveryViewModel.swift */,
3C7507AE28529A5F00D7DB3A /* CommissioningView.swift */,
3C7507B82853EFF000D7DB3A /* CommissioningViewModel.swift */,
3C81C75628F8E418001CB9D1 /* ConnectionView.swift */,
3C81C75828F8E42D001CB9D1 /* ConnectionViewModel.swift */,
3CA1CA7928E281080023ED44 /* ClusterSelectorView.swift */,
3CA19434285BA780004768D5 /* ContentLauncherView.swift */,
3CA19436285BA877004768D5 /* ContentLauncherViewModel.swift */,
Expand Down Expand Up @@ -277,7 +271,6 @@
3C4F52302B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift in Sources */,
3C621CB32B6078B7005CDBA3 /* MCApplicationBasicReadVendorIDExampleViewModel.swift in Sources */,
3C621CB52B607FFD005CDBA3 /* MCActionSelectorView.swift in Sources */,
3C81C75928F8E42D001CB9D1 /* ConnectionViewModel.swift in Sources */,
3CA1CA7A28E281080023ED44 /* ClusterSelectorView.swift in Sources */,
3C94378E2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift in Sources */,
EAF14299296D561900E17793 /* CertTestView.swift in Sources */,
Expand All @@ -291,7 +284,6 @@
3CCB8749286A5D0F00771BAD /* ContentLauncherView.swift in Sources */,
3CCB874A286A5D0F00771BAD /* ContentLauncherViewModel.swift in Sources */,
EAF1429B296D57DF00E17793 /* CertTestViewModel.swift in Sources */,
3C81C75728F8E418001CB9D1 /* ConnectionView.swift in Sources */,
3CC0E8FC2841DD3400EC6A18 /* ContentView.swift in Sources */,
3CA1CA7C28E282150023ED44 /* MediaPlaybackView.swift in Sources */,
3CC0E8FA2841DD3400EC6A18 /* TvCastingApp.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct CommissionerDiscoveryView: View {
destination: {
if(commissioner.isPreCommissioned())
{
ConnectionView(_selectedVideoPlayer: commissioner.getConnectableVideoPlayer())
Text("Error: unexpected value for commissioner.isPreCommissioned: true")
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,15 @@ struct CommissioningView: View {
.border(Color.blue, width: 1)
.padding()

if(self.selectedCommissioner != nil)
if(viewModel.udcRequestSent == true)
{
if(viewModel.udcRequestSent == true)
{
Text("Complete commissioning on " + (selectedCommissioner?.deviceName)!)
.padding()
}
else if(viewModel.udcRequestSent == false) {
Text("Could not send user directed commissioning request to " + (selectedCommissioner?.deviceName)! + "! Complete commissioning manually!")
.foregroundColor(Color.red)
.padding()
}
Text("Complete commissioning on " + (selectedCommissioner?.deviceName)!)
.padding()
}
else{
Text("Complete commissioning with a commissioner manually!").padding()
else if(viewModel.udcRequestSent == false) {
Text("Could not send user directed commissioning request to " + (selectedCommissioner?.deviceName)!)
.foregroundColor(Color.red)
.padding()
}
}
else if(viewModel.commisisoningWindowOpened == false) {
Expand Down

This file was deleted.

Loading

0 comments on commit c0abb3f

Please sign in to comment.