Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/feature/add-lwip-ip…
Browse files Browse the repository at this point in the history
…v4-toggle-support-new' into feature/add-lwip-ipv4-toggle-support-new
  • Loading branch information
rosahay-silabs committed Oct 13, 2022
2 parents 600bad0 + 8749d70 commit 65386f5
Show file tree
Hide file tree
Showing 195 changed files with 102,934 additions and 95,026 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WildcardFragment : Fragment() {
private lateinit var addressUpdateFragment: AddressUpdateFragment

private val reportCallback = object : ReportCallback {
override fun onError(attributePath: ChipAttributePath, eventPath: ChipEventPath, ex: Exception) {
override fun onError(attributePath: ChipAttributePath?, eventPath: ChipEventPath?, ex: Exception) {
if (attributePath != null)
{
Log.e(TAG, "Report error for $attributePath: $ex")
Expand Down
2 changes: 1 addition & 1 deletion examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ executable("darwin-framework-tool") {
"commands/common/MTRError_Utils.h",
"commands/common/MTRLogging.h",
"commands/pairing/Commands.h",
"commands/pairing/DeviceControllerDelegateBridge.mm",
"commands/pairing/OpenCommissioningWindowCommand.h",
"commands/pairing/OpenCommissioningWindowCommand.mm",
"commands/pairing/PairingCommandBridge.mm",
"commands/pairing/PairingDelegateBridge.mm",
"commands/payload/SetupPayloadParseCommand.mm",
"commands/provider/Commands.h",
"commands/provider/OTAProviderDelegate.mm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class ClusterCommand : public ModelCommand {
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

while (repeatCount--) {
[device invokeCommandWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:clusterId]
commandID:[NSNumber numberWithUnsignedInteger:commandId]
[device invokeCommandWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:clusterId]
commandId:[NSNumber numberWithUnsignedInteger:commandId]
commandFields:commandFields
timedInvokeTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
queue:callbackQueue
clientQueue: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 @@ -25,15 +25,31 @@

CHIP_ERROR ModelCommand::RunCommand()
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);

MTRDeviceController * commissioner = CurrentCommissioner();
ChipLogProgress(chipTool, "Sending command to node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
auto * device = [MTRBaseDevice deviceWithNodeID:@(mNodeId) controller:commissioner];
CHIP_ERROR err = SendCommand(device, mEndPointId);
[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));
return err;
}
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 @@ -54,26 +54,24 @@ class ReadAttribute : public ModelCommand {
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
MTRReadParams * params = [[MTRReadParams alloc] init];
if (mFabricFiltered.HasValue()) {
params.fabricFiltered = mFabricFiltered.Value();
}
[device readAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
params:params
queue:callbackQueue
completion:^(
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading attribute", error);
}
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
}
SetCommandExitStatus(error);
}];
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
[device
readAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
params:params
clientQueue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading attribute", error);
}
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
}
SetCommandExitStatus(error);
}];
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -126,22 +124,18 @@ class SubscribeAttribute : public ModelCommand {
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
if (mFabricFiltered.HasValue()) {
params.fabricFiltered = mFabricFiltered.Value();
}
if (mKeepSubscriptions.HasValue()) {
params.keepPreviousSubscriptions = mKeepSubscriptions.Value();
}
if (mAutoResubscribe.HasValue()) {
params.autoResubscribe = mAutoResubscribe.Value();
}

[device subscribeAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;

[device subscribeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]
maxInterval:[NSNumber numberWithUnsignedInteger:mMaxInterval]
params:params
queue:callbackQueue
clientQueue:callbackQueue
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (values) {
for (id item in values) {
Expand Down Expand Up @@ -198,17 +192,16 @@ class SubscribeEvent : public ModelCommand {
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
if (mKeepSubscriptions.HasValue()) {
params.keepPreviousSubscriptions = mKeepSubscriptions.Value();
}
if (mAutoResubscribe.HasValue()) {
params.autoResubscribe = mAutoResubscribe.Value();
}
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;

[device subscribeWithQueue:callbackQueue
minInterval:mMinInterval
maxInterval:mMaxInterval
params:params
clusterStateCacheContainer:nil
cacheContainer:nil
attributeReportHandler:^(NSArray * value) {
SetCommandExitStatus(CHIP_NO_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class WriteAttribute : public ModelCommand {
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
[device
writeAttributeWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:clusterId]
attributeID:[NSNumber numberWithUnsignedInteger:attributeId]
writeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:clusterId]
attributeId:[NSNumber numberWithUnsignedInteger:attributeId]
value:value
timedWriteTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
queue:callbackQueue
clientQueue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error writing attribute", error);
Expand Down
33 changes: 18 additions & 15 deletions examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,25 @@

mOTADelegate = [[OTAProviderDelegate alloc] init];

auto factory = [MTRDeviceControllerFactory sharedInstance];
auto factory = [MTRControllerFactory sharedInstance];
if (factory == nil) {
ChipLogError(chipTool, "Controller factory is nil");
return CHIP_ERROR_INTERNAL;
}

auto params = [[MTRDeviceControllerFactoryParams alloc] initWithStorage:storage];
auto params = [[MTRControllerFactoryParams alloc] initWithStorage:storage];
params.port = @(kListenPort);
params.shouldStartServer = YES;
params.startServer = YES;
params.otaProviderDelegate = mOTADelegate;
NSArray<NSData *> * paaCertResults;
ReturnLogErrorOnFailure(GetPAACertsFromFolder(&paaCertResults));
if ([paaCertResults count] > 0) {
params.paaCerts = paaCertResults;
}

NSError * error;
if ([factory startControllerFactory:params error:&error] == NO) {
if ([factory startup:params] == NO) {
ChipLogError(chipTool, "Controller factory startup failed");
return MTRErrorToCHIPErrorCode(error);
return CHIP_ERROR_INTERNAL;
}

ReturnLogErrorOnFailure([gNocSigner createOrLoadKeys:storage]);
Expand All @@ -139,19 +138,21 @@

constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
for (size_t i = 0; i < ArraySize(identities); ++i) {
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithIPK:ipk fabricID:@(i + 1) nocSigner:gNocSigner];
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:gNocSigner
fabricId:(i + 1)
ipk:ipk];

// We're not sure whether we're creating a new fabric or using an
// existing one, so just try both.
auto controller = [factory createControllerOnExistingFabric:controllerParams error:&error];
auto controller = [factory startControllerOnExistingFabric:controllerParams];
if (controller == nil) {
// Maybe we didn't have this fabric yet.
controllerParams.vendorID = @(chip::VendorId::TestVendor1);
controller = [factory createControllerOnNewFabric:controllerParams error:&error];
controllerParams.vendorId = @(chip::VendorId::TestVendor1);
controller = [factory startControllerOnNewFabric:controllerParams];
}
if (controller == nil) {
ChipLogError(chipTool, "Controller startup failure.");
return MTRErrorToCHIPErrorCode(error);
return CHIP_ERROR_INTERNAL;
}

mControllers[identities[i]] = controller;
Expand Down Expand Up @@ -194,14 +195,16 @@
{
StopCommissioners();

auto factory = [MTRDeviceControllerFactory sharedInstance];
auto factory = [MTRControllerFactory sharedInstance];
NSData * ipk = [gNocSigner getIPK];

constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
for (size_t i = 0; i < ArraySize(identities); ++i) {
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithIPK:ipk fabricID:@(i + 1) nocSigner:gNocSigner];
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:gNocSigner
fabricId:(i + 1)
ipk:ipk];

auto controller = [factory createControllerOnExistingFabric:controllerParams error:nil];
auto controller = [factory startControllerOnExistingFabric:controllerParams];
mControllers[identities[i]] = controller;
}
}
Expand All @@ -213,7 +216,7 @@
mControllers.clear();
mCurrentController = nil;

[[MTRDeviceControllerFactory sharedInstance] stopControllerFactory];
[[MTRControllerFactory sharedInstance] shutdown];
}

CHIP_ERROR CHIPCommandBridge::StartWaiting(chip::System::Clock::Timeout duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface CHIPToolPersistentStorageDelegate : NSObject <MTRStorage>
@interface CHIPToolPersistentStorageDelegate : NSObject <MTRPersistentStorageDelegate>
- (nullable NSData *)storageDataForKey:(NSString *)key;
- (BOOL)setStorageData:(NSData *)value forKey:(NSString *)key;
- (BOOL)removeStorageDataForKey:(NSString *)key;
Expand Down
17 changes: 10 additions & 7 deletions examples/darwin-framework-tool/commands/pairing/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class PairCodeThread : public PairingCommandBridge
PairCodeThread() : PairingCommandBridge("code-thread", PairingMode::Code, PairingNetworkType::Thread) {}
};

class PairWithIPAddress : public PairingCommandBridge
{
public:
PairWithIPAddress() : PairingCommandBridge("ethernet", PairingMode::Ethernet, PairingNetworkType::Ethernet) {}
};

class PairBleWiFi : public PairingCommandBridge
{
public:
Expand All @@ -64,13 +70,10 @@ void registerCommandsPairing(Commands & commands)
const char * clusterName = "Pairing";

commands_list clusterCommands = {
make_unique<PairCode>(),
make_unique<PairCodeWifi>(),
make_unique<PairCodeThread>(),
make_unique<PairBleWiFi>(),
make_unique<PairBleThread>(),
make_unique<Unpair>(),
make_unique<OpenCommissioningWindowCommand>(),
make_unique<PairCode>(), make_unique<PairWithIPAddress>(),
make_unique<PairCodeWifi>(), make_unique<PairCodeThread>(),
make_unique<PairBleWiFi>(), make_unique<PairBleThread>(),
make_unique<Unpair>(), make_unique<OpenCommissioningWindowCommand>(),
};

commands.Register(clusterName, clusterCommands);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@
{
mWorkQueue = dispatch_queue_create("com.chip.open_commissioning_window", DISPATCH_QUEUE_SERIAL);
auto * controller = CurrentCommissioner();
auto * device = [MTRBaseDevice deviceWithNodeID:@(mNodeId) controller:controller];
auto * device = [MTRDevice deviceWithNodeID:mNodeId deviceController:controller];

auto * self = this;
if (mCommissioningWindowOption == 0) {
auto * cluster = [[MTRBaseClusterAdministratorCommissioning alloc] initWithDevice:device endpoint:@(0) queue:mWorkQueue];
auto * cluster = [[MTRClusterAdministratorCommissioning alloc] initWithDevice:device endpoint:0 queue:mWorkQueue];
auto * params = [[MTRAdministratorCommissioningClusterOpenBasicCommissioningWindowParams alloc] init];
params.commissioningTimeout = @(mCommissioningWindowTimeoutMs);
params.timedInvokeTimeoutMs = @(10000);
[cluster openBasicCommissioningWindowWithParams:params
completion:^(NSError * _Nullable error) {
if (error == nil) {
self->SetCommandExitStatus(CHIP_NO_ERROR);
} else {
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
}
}];
expectedValues:nil
expectedValueInterval:nil
completionHandler:^(NSError * _Nullable error) {
if (error == nil) {
self->SetCommandExitStatus(CHIP_NO_ERROR);
} else {
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
}
}];
} else {
[device
openCommissioningWindowWithSetupPasscode:[MTRSetupPayload generateRandomSetupPasscode]
Expand Down
Loading

0 comments on commit 65386f5

Please sign in to comment.