Skip to content

Commit 82f2f0d

Browse files
ArekBalysNordicrlubos
authored andcommitted
samples: matter: Introduce Timed Schedule Access in Lock
- Regenerated Matter Lock Zap to include Timed Schedule Access feature - Added Schedules for WeekDay, YearDay and Holiday to the credentials manager according to Matter Specification. - Implemented callbacks for the schedule feature required by door-lock-server. - Moved credentials manager users, schedules and credentials implementations to separate files due to a high number of lines in the credentials_manager.cpp file. - Added a guide to Matter Lock sample on how to use this feature. - Added guide how to enable the timed-access schedule feature - Updated release notes. - Changed names from credentials to access Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
1 parent 83acef8 commit 82f2f0d

19 files changed

+2205
-772
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,9 @@ Matter samples that used :ref:`zephyr:nrf-ieee802154-rpmsg-sample` or :ref:`mult
602602
* :ref:`matter_lock_sample` sample:
603603

604604
* Added support for emulation of the nRF7001 Wi-Fi companion IC on the nRF7002 DK.
605-
* Added a door lock credentials manager module.
605+
* Added a door lock access manager module.
606606
The module is used to implement support for refined handling and persistent storage of PIN codes.
607+
* Added the ::ref::`matter_lock_scheduled_timed_access` feature.
607608

608609
Multicore samples
609610
-----------------

samples/matter/lock/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,23 @@ target_include_directories(app PRIVATE
2828
src
2929
)
3030

31-
FILE(GLOB cred_srcs src/credentials/*.cpp)
31+
SET(access_srcs src/access/access_data_types.cpp
32+
src/access/access_manager_credentials.cpp
33+
src/access/access_manager_users.cpp
34+
src/access/access_manager.cpp
35+
src/access/access_storage.cpp
36+
)
37+
38+
if(CONFIG_LOCK_SCHEDULES)
39+
LIST(APPEND access_srcs src/access/access_manager_schedules.cpp)
40+
endif()
3241

3342
target_sources(app PRIVATE
3443
src/app_task.cpp
3544
src/bolt_lock_manager.cpp
3645
src/main.cpp
3746
src/zcl_callbacks.cpp
38-
${cred_srcs}
47+
${access_srcs}
3948
)
4049

4150
if(CONFIG_THREAD_WIFI_SWITCHING)

samples/matter/lock/Kconfig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ config LOCK_MAX_CREDENTIAL_LENGTH
2222
int "Maximum length of the single credential supported by the lock"
2323
default 10
2424

25+
config LOCK_SCHEDULES
26+
bool "Support for WeekDay, YearDay and Holiday schedules in lock"
27+
help
28+
This option adds support for an optional Timed Schedule Access Lock feature.
29+
You can use Week Day, Year Day and Holiday schedules to restrict access for a
30+
specific user for a defined time window. For example, use it to
31+
give the user access only for three days in week.
32+
33+
if LOCK_SCHEDULES
34+
35+
config LOCK_MAX_WEEKDAY_SCHEDULES_PER_USER
36+
int "Maximum number of WeekDay schedules per one user supported by the lock"
37+
default 5
38+
39+
config LOCK_MAX_YEARDAY_SCHEDULES_PER_USER
40+
int "Maximum number of YearDay schedules per one user supported by the lock"
41+
default 5
42+
43+
config LOCK_MAX_HOLIDAY_SCHEDULES
44+
int "Maximum number of Holiday schedules supported by the lock"
45+
default 5
46+
47+
endif
48+
2549
config LOCK_ENABLE_DEBUG
2650
bool "Enable debug features to print users and credentials"
2751
depends on SHELL
@@ -32,6 +56,15 @@ config LOCK_ENABLE_DEBUG
3256

3357
if LOCK_ENABLE_DEBUG
3458

59+
config LOCK_PRINT_STORAGE_STATUS
60+
bool "Print storage status after each store call"
61+
help
62+
Debug feature to print the debug-level log that contains information of the entry being stored
63+
to persistent storage and how many bytes are left to store the new entry. It can be used to verify
64+
whether credential, schedule or user entries are written properly to persistent storage.
65+
This option should be disabled in production firmware
66+
version.
67+
3568
# This should be deterined based on the maximum possible command length that depends on the LOCK_MAX_CREDENTIAL_LENGTH
3669
config SHELL_CMD_BUFF_SIZE
3770
default 300

samples/matter/lock/README.rst

Lines changed: 223 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ For details, see the `Commissioning the device`_ section.
7676
Door lock credentials
7777
=====================
7878

79-
By default, the application supports only PIN code credentials, but it is possible to implement support for other door lock credential types by using the ``CredentialsManager`` module.
79+
By default, the application supports only PIN code credentials, but it is possible to implement support for other door lock credential types by using the ``AccessManager`` module.
8080
The credentials can be used to control remote access to the bolt lock.
8181
The PIN code assigned by the Matter controller is stored persistently, which means that it can survive a device reboot.
8282
Depending on the IPv6 network technology in use, the following storage backends are supported by default to store the PIN code credential:
@@ -481,6 +481,115 @@ Upgrading the device firmware
481481

482482
To upgrade the device firmware, complete the steps listed for the selected method in the :doc:`matter:nrfconnect_examples_software_update` tutorial of the Matter documentation.
483483

484+
.. _matter_lock_scheduled_timed_access:
485+
486+
Scheduled timed access
487+
======================
488+
489+
The scheduled timed access feature is an optional Matter lock feature that can be applicable to all available lock users.
490+
You can use the scheduled timed access feature to allow guest users of the home to access the lock at the specific scheduled times.
491+
To use this feature, you need to create at least one user on the lock device, and assign credentials.
492+
For more information about setting user credentials, see the Saving users and credentials on door lock devices section of the :doc:`matter:chip_tool_guide` page in the :doc:`Matter documentation set <matter:index>`, and the :ref:`matter_lock_sample_remote_access_with_pin` section of this sample.
493+
494+
You can schedule the following types of timed access:
495+
496+
- ``Week-day`` - Restricts access to a specified time window on certain days of the week for a specific user.
497+
This schedule grants repeated access each week.
498+
When the schedule is cleared, the user is granted unrestricted access.
499+
500+
- ``Year-day`` - Restricts access to a specified time window on a specific date window.
501+
This schedule grants access only once, and does not repeat.
502+
When the schedule is cleared, the user is granted unrestricted access.
503+
504+
- ``Holiday`` - Sets up a holiday operating mode in the lock device.
505+
You can choose one of the following operating modes:
506+
507+
- ``Normal`` - The lock operates normally.
508+
- ``Vacation`` - Only remote operations are enabled.
509+
- ``Privacy`` - All external interactions with the lock are disabled.
510+
Can only be used if the lock is in the locked state.
511+
Manually unlocking the lock changes the mode to ``Normal``.
512+
- ``NoRemoteLockUnlock`` - All remote operations with the lock are disabled.
513+
- ``Passage`` - The lock can be operated without providing a PIN.
514+
This option can be used, for example, for employees during working hours.
515+
516+
To enable the scheduled timed access feature, complete the following steps:
517+
518+
1. Enable all needed scheduled timed access types in the ZAP file:
519+
520+
a. Open the :file:`lock.zap` file using the following west command:
521+
522+
.. code-block:: console
523+
524+
west zap-gui
525+
526+
#. Select the endpoint that contains the Matter Door Lock cluster.
527+
By default, this is `Endpoint-1`.
528+
529+
#. Click the :guilabel:`Configure` symbol for the ``Door Lock`` cluster entry.
530+
#. In the **Door Lock** context window, go to the **Attributes** tab and enable all required attributes:
531+
532+
* ``NumberOfWeekDaySchedulesSupportedPerUser`` for the ``Week-day`` schedule support.
533+
* ``NumberOfYearDaySchedulesSupportedPerUser`` for the ``Year-day`` schedule support.
534+
* ``NumberOfHolidaySchedulesSupported`` for the ``Holiday`` schedule support.
535+
536+
#. In the **Door Lock** context window, go to the **Attribute Reporting** page and enable all required attribute reporting entries:
537+
538+
* ``NumberOfWeekDaySchedulesSupportedPerUser`` for the ``Week-day`` schedule support.
539+
* ``NumberOfYearDaySchedulesSupportedPerUser`` for the ``Year-day`` schedule support.
540+
* ``NumberOfHolidaySchedulesSupported`` for the ``Holiday`` schedule support.
541+
542+
#. In the **Door Lock** context window, go to the **Commands** page and enable all required command entries:
543+
544+
* For the ``Week-day`` schedule support:
545+
546+
* ``SetWeekDaySchedule``
547+
* ``GetWeekDaySchedule``
548+
* ``GetWeekDayScheduleResponse``
549+
* ``ClearWeekDaySchedule``
550+
551+
* For the ``Year-day`` schedule support:
552+
553+
* ``SetYearDaySchedule``
554+
* ``GetYearDaySchedule``
555+
* ``GetYearDayScheduleResponse``
556+
* ``ClearYearDaySchedule``
557+
558+
* For the ``Holiday`` schedule support:
559+
560+
* ``SetHolidaySchedule``
561+
* ``GetHolidaySchedule``
562+
* ``GetHolidayScheduleResponse``
563+
* ``ClearHolidaySchedule``
564+
565+
#. In the **Door Lock** context window, go to the **Attributes** tab and set the proper bits for the ``FeatureMap`` attribute:
566+
567+
* For the ``Week-day`` schedule support set the ``5th`` bit of the feature map bit map.
568+
* For the ``Year-day`` schedule support set the ``11th`` bit of the feature map bit map.
569+
* For the ``Holiday`` schedule support set the ``12th`` bit of the feature map bit map.
570+
571+
#. Save the :file:`lock.zap` file, and close ZAP-tool.
572+
#. Generate new ZAP files with the changes in the Door Lock cluster using the following west command:
573+
574+
.. code-block:: console
575+
576+
west zap-generate
577+
578+
#. Enable the feature in the |NCS| Matter Lock sample by setting the :kconfig:option:`CONFIG_LOCK_SCHEDULES` Kconfig option to ``y``.
579+
#. Use the following Kconfig options to modify the maximum number of specific schedule types:
580+
581+
- :kconfig:option:`CONFIG_LOCK_MAX_WEEKDAY_SCHEDULES_PER_USER` to define the maximum number of ``Week-day`` schedules for one user.
582+
- :kconfig:option:`CONFIG_LOCK_MAX_YEARDAY_SCHEDULES_PER_USER` to define the maximum number of ``Year-day`` schedules for one user.
583+
- :kconfig:option:`CONFIG_LOCK_MAX_HOLIDAY_SCHEDULES` to define the maximum number of ``Holiday`` schedules.
584+
585+
To learn more about configuring the Door Lock cluster, see the :ref:`ug_matter_creating_accessory` user guide.
586+
587+
All scheduled timed access entries are saved to non-volatile memory and loaded automatically after device reboot.
588+
To disable the feature, you need to revert all changes in the :file:`lock.zap` file, re-generate the ZAP files and set the :kconfig:option:`CONFIG_LOCK_SCHEDULES` Kconfig option to ``n``.
589+
590+
.. note::
591+
Adding a single schedule for a user contributes to the settings partition memory occupancy increase.
592+
484593
.. _matter_lock_sample_remote_access_with_pin:
485594

486595
Testing remote access with PIN code credential
@@ -536,6 +645,119 @@ After building the sample and programming it to your development kit, complete t
536645
.. note::
537646
Accessing the door lock remotely without a valid PIN code credential will fail.
538647

648+
.. _matter_lock_sample_schedule_testing:
649+
650+
Testing scheduled timed access
651+
==============================
652+
653+
.. note::
654+
You can test :ref:`matter_lock_scheduled_timed_access` using any Matter compatible controller.
655+
The following steps use the CHIP Tool controller as an example.
656+
657+
After building the sample with the feature enabled and programming it to your development kit, complete the following steps to test scheduled timed access:
658+
659+
1. |connect_kit|
660+
#. |connect_terminal_ANSI|
661+
#. Wait until the device boots.
662+
#. Commission an accessory with node ID equal to 10 to the Matter network by following the steps described in the `Commissioning the device`_ section.
663+
#. Add the example ``Home`` door lock user:
664+
665+
.. code-block:: console
666+
667+
./chip-tool doorlock set-user 0 2 Home 123 1 0 0 10 1 --timedInteractionTimeoutMs 5000
668+
669+
This command creates a ``Home`` user with a unique ID of ``123`` and an index of ``2``.
670+
The new user's status is set to ``1``, and both its type and credential rule to ``0``.
671+
The user is assigned to the door lock cluster residing on endpoint ``1`` of the node with ID ``10``.
672+
673+
#. Set the example ``Week-day`` schedule using the following command:
674+
675+
.. parsed-literal::
676+
:class: highlight
677+
678+
./chip-tool doorlock set-week-day-schedule *weekday-index* *user-index* *days-mask* *start-hour* *start-minute* *end-hour* *end-minute* *destination-id* *endpoint-id*
679+
680+
* *weekday-index* is the index of the new schedule, starting from ``1``.
681+
The maximum value is defined by the :kconfig:option:`CONFIG_LOCK_MAX_WEEKDAY_SCHEDULES_PER_USER` Kconfig option.
682+
* *user-index* is the user index defined for the user created in the previous step.
683+
* *days-mask* is a bitmap of numbers of the week days starting from ``0`` as a Sunday and finishing at ``6`` as a Saturday.
684+
For example, to assign this schedule to Tuesday, Thursday and Saturday you need to provide ``84`` because it is equivalent to the ``01010100`` bitmap.
685+
* *start-hour* is the starting hour for the week day schedule.
686+
* *start-minute* is the starting minute for the week day schedule.
687+
* *end-hour* is the ending hour for the week day schedule.
688+
* *end-minute* is the ending hour for the week day schedule.
689+
* *destination-id* is the device node ID.
690+
* *endpoint-id* is the Matter door lock endpoint, in this sample assigned to ``1``.
691+
692+
For example, use the following command to set a ``Week-day`` schedule with index ``1`` for Tuesday, Thursday and Saturday to start at 7:30 AM and finish at 10:30 AM, dedicated for user with ID ``2``:
693+
694+
.. code-block:: console
695+
696+
./chip-tool doorlock set-week-day-schedule 1 2 84 7 30 10 30 1 1
697+
698+
699+
#. Set the example ``Year-day`` schedule using the following command:
700+
701+
.. parsed-literal::
702+
:class: highlight
703+
704+
./chip-tool doorlock set-year-day-schedule *yearday-index* *user-index* *localtime-start* *localtime-end* *destination-id* *endpoint-id*
705+
706+
707+
* *yearday-index* is the index of the new schedule, starting from ``1``.
708+
The maximum value is defined by the :kconfig:option:`CONFIG_LOCK_MAX_YEARDAY_SCHEDULES_PER_USER` kconfig option.
709+
* *user-index* is the user index defined for the user created in the previous step.
710+
* *localtime-start* is the starting time in Epoch Time.
711+
* *localtime-end* is the ending time in Epoch Time.
712+
* *destination-id* is the device node ID.
713+
* *endpoint-id* is the Matter door lock endpoint, in this sample assigned to ``1``.
714+
715+
Both ``localtime-start`` and ``localtime-end`` are in seconds with the local time offset based on the local timezone and DST offset on the day represented by the value.
716+
717+
For example, use the following command to set a ``Year-day`` schedule with index ``1`` to start on Monday, May 27, 2024, at 7:00:00 AM GMT+02:00 DST and finish on Thursday, May 30, 2024, at 7:00:00 AM GMT+02:00 DST dedicated for user with ID ``2``::
718+
719+
.. code-block:: console
720+
721+
./chip-tool doorlock set-year-day-schedule 1 2 1716786000 1717045200 1 1
722+
723+
#. Set the example ``Holiday`` schedule using the following command:
724+
725+
.. parsed-literal::
726+
:class: highlight
727+
728+
./chip-tool doorlock set-holiday-schedule *holiday-index* *localtime-start* *localtime-end* *operating-mode* *destination-id* *endpoint-id*
729+
730+
* *holiday-index* is the index of the new schedule, starting from ``1``.
731+
* *localtime-start* is the starting time in Epoch Time.
732+
* *localtime-end* is the ending time in Epoch Time.
733+
* *operating-mode* is the operating mode described in the :ref:`matter_lock_scheduled_timed_access` section of this guide.
734+
* *destination-id* is the device node ID.
735+
* *endpoint-id* is the Matter door lock endpoint, in this sample assigned to ``1``.
736+
737+
For example, use the following command to setup a ``Holiday`` schedule with the operating mode ``Vacation`` to start on Monday, May 27, 2024, at 7:00:00 AM GMT+02:00 DST and finish on Thursday, May 30, 2024, at 7:00:00 AM GMT+02:00 DST:
738+
739+
.. parsed-literal::
740+
:class: highlight
741+
742+
./chip-tool doorlock set-holiday-schedule 1 1716786000 1717045200 1 1 1
743+
744+
#. Read saved schedules using the following commands and providing the same arguments you used in the earlier steps:
745+
746+
.. parsed-literal::
747+
:class: highlight
748+
749+
./chip-tool doorlock get-week-day-schedule *weekday-index* *user-index* *destination-id* *endpoint-id*
750+
751+
.. parsed-literal::
752+
:class: highlight
753+
754+
./chip-tool doorlock get-year-day-schedule *yearday-index* *user-index* *destination-id* *endpoint-id*
755+
756+
.. parsed-literal::
757+
:class: highlight
758+
759+
./chip-tool doorlock get-holiday-schedule *holiday-index* *destination-id* *endpoint-id*
760+
539761
.. _matter_lock_sample_switching_thread_wifi:
540762

541763
Testing switching between Thread and Wi-Fi

0 commit comments

Comments
 (0)