Skip to content

Commit

Permalink
Bugfix: Dont read non-existing attributes for lock/unlock commands (p…
Browse files Browse the repository at this point in the history
…roject-chip#19373)

* [project-chip#19316] Don't require PIN for locking/unlocking the door when not required

* Update auto-generated files
  • Loading branch information
Morozov-5F authored Jun 9, 2022
1 parent 195181b commit 0adc4f3
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 65 deletions.
18 changes: 12 additions & 6 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3143,13 +3143,19 @@ bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * comma
}
else
{
// appclusters.pdf 5.3.4.1:
// If the RequirePINforRemoteOperation attribute is True then PINCode field SHALL be provided and the door lock SHALL NOT
// grant access if it is not provided.
bool requirePin = false;
VerifyOrExit(GetAttribute(endpoint, Attributes::RequirePINforRemoteOperation::Id,
Attributes::RequirePINforRemoteOperation::Get, requirePin),
/* credentialsOk is false here */);

// appclusters.pdf 5.3.4.1:
// If the RequirePINForRemoteOperation attribute is True then PINCode field SHALL be provided and the door lock SHALL NOT
// grant access if it is not provided. This attribute exists when COTA and PIN features are both enabled. Otherwise we
// assume PIN to be OK.
if (SupportsCredentialsOTA(endpoint) && SupportsPIN(endpoint))
{
auto status = Attributes::RequirePINforRemoteOperation::Get(endpoint, &requirePin);
VerifyOrExit(
EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE == status || EMBER_ZCL_STATUS_SUCCESS == status,
ChipLogError(Zcl, "Failed to read Require PIN For Remote Operation attribute, status=0x%x", to_underlying(status)));
}
credentialsOk = !requirePin;
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class DoorLockServer

inline bool SupportsSchedules(chip::EndpointId endpointId) { return HasFeature(endpointId, DoorLockFeature::kAccessSchedules); }

inline bool SupportsCredentialsOTA(chip::EndpointId endpointId)
{
return HasFeature(endpointId, DoorLockFeature::kCredentialsOTA);
}

inline bool SupportsUSR(chip::EndpointId endpointId)
{
// appclusters, 5.2.2: USR feature has conformance [PIN | RID | FGP | FACE]
Expand Down
20 changes: 20 additions & 0 deletions src/app/tests/suites/DL_LockUnlock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ tests:
- name: "nodeId"
value: nodeId

- label: "Try to unlock the door without PIN"
command: "UnlockDoor"
timedInteractionTimeoutMs: 10000

- label: "Verify that lock state attribute value is set to Unlocked"
command: "readAttribute"
attribute: "LockState"
response:
value: 2

- label: "Try to unlock the door without a PIN"
command: "LockDoor"
timedInteractionTimeoutMs: 10000

- label: "Verify that lock state attribute value is set to Locked"
command: "readAttribute"
attribute: "LockState"
response:
value: 1

- label: "Create new PIN credential and lock/unlock user"
command: "SetCredential"
timedInteractionTimeoutMs: 10000
Expand Down
110 changes: 81 additions & 29 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

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

Loading

0 comments on commit 0adc4f3

Please sign in to comment.