Skip to content

Commit

Permalink
Get peer's node ID from session instead of packet header for response…
Browse files Browse the repository at this point in the history
… handling (#9287)

* Get peer's node ID from session instead of packet header for response handling

* Fix typo
  • Loading branch information
pan-apple authored and pull[bot] committed Sep 1, 2021
1 parent 6757b99 commit 4603997
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,9 @@ CHIP_ERROR DeviceController::OnMessageReceived(Messaging::ExchangeContext * ec,
uint16_t index;

VerifyOrExit(mState == State::Initialized, ChipLogError(Controller, "OnMessageReceived was called in incorrect state"));
VerifyOrExit(ec != nullptr, ChipLogError(Controller, "OnMessageReceived was called with null exchange"));

VerifyOrExit(packetHeader.GetSourceNodeId().HasValue(),
ChipLogError(Controller, "OnMessageReceived was called for unknown source node"));

index = FindDeviceIndex(packetHeader.GetSourceNodeId().Value());
index = FindDeviceIndex(ec->GetSecureSession().GetPeerNodeId());
VerifyOrExit(index < kNumMaxActiveDevices, ChipLogError(Controller, "OnMessageReceived was called for unknown device object"));

mActiveDevices[index].OnMessageReceived(ec, packetHeader, payloadHeader, std::move(msgBuf));
Expand Down
73 changes: 73 additions & 0 deletions src/darwin/Framework/CHIP/templates/clusters-tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,79 @@ CHIPDevice * GetPairedDevice(uint64_t deviceId)
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0000_BindOnOff_Test
{
XCTestExpectation * expectation = [self expectationWithDescription:@"Binding to OnOff Cluster complete"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPBinding * bindingCluster = [[CHIPBinding alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(bindingCluster);
[bindingCluster bind:kDeviceId groupId:0
endpointId:1
clusterId:6
responseHandler:^(NSError * err, NSDictionary * values) {
NSLog(@"Reporting Test Binding status : %@", err);
XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0001_ConfigureOnOff_Test
{
XCTestExpectation * expectation = [self expectationWithDescription:@"Reporting OnOff configured"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPOnOff * onOffCluster = [[CHIPOnOff alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(onOffCluster);
[onOffCluster configureAttributeOnOffWithMinInterval:0
maxInterval:1
responseHandler:^(NSError * err, NSDictionary * values) {
NSLog(@"Reporting Test Configure status: %@", err);

XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0002_ReportOnOff_Test
{
XCTestExpectation * expectation = [self expectationWithDescription:@"First report received"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPOnOff * onOffCluster = [[CHIPOnOff alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(onOffCluster);
[onOffCluster reportAttributeOnOffWithResponseHandler:^(NSError * err, NSDictionary * values)
{
NSLog(@"Reporting Test Report first report: %@", err);
[expectation fulfill];
XCTAssertEqual(err.code, 0);
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0003_StopReportOnOff_Test
{
XCTestExpectation * expectation = [self expectationWithDescription:@"Reporting OnOff cancelled"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPOnOff * onOffCluster = [[CHIPOnOff alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(onOffCluster);
[onOffCluster configureAttributeOnOffWithMinInterval:0
maxInterval:0xffff
responseHandler:^(NSError * err, NSDictionary * values) {
NSLog(@"Reporting Test Cancel Reports status: %@", err);

XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

{{>test_cluster tests="TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1"}}

{{#chip_client_clusters}}
Expand Down
73 changes: 73 additions & 0 deletions src/darwin/Framework/CHIPTests/CHIPClustersTests.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4603997

Please sign in to comment.