diff --git a/examples/generic_switch/README.md b/examples/generic_switch/README.md index 251ef0696..27aa9d6aa 100644 --- a/examples/generic_switch/README.md +++ b/examples/generic_switch/README.md @@ -2,12 +2,33 @@ This example creates a Generic Switch device using the ESP Matter data model. +This example aims to demonstrate the use of Fixed Label Cluster which provides a feature for the device to tag an endpoint with zero or more read-only labels using nvs api. + +Note: + In order to retrieve the label-list from the fixed-label cluster the two options: + ``CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER`` and ``CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER`` have been set through sdkcofig.defaults. See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about building and flashing the firmware. ## 1. Additional Environment Setup -No additional setup is required. +The steps below should be followed in order to access the fixed-labels. +- If monitoring the device using ``idf.py monitor``,press `` Ctrl + ]`` to stop the process. +- The following command must be executed to flash the mfg partition: +``` +esptool.py -p [port-name] write_flash 0x10000 mfg_binaries/20202020_3841.bin +``` +- Execute the command ``idf.py monitor`` +- Commission the device with ``discriminator: 20202020``and `` passcode: 3841`` +- Command: +``` +chip-tool pairing ble-wifi 0x7283 [ssid] [password] 20202020 3841 +``` +- To read the fixed-labels, use chip-tool. +- Command : +``` +chip-tool fixedlabels read label-list 0x7283 1 +``` ## 2. Post Commissioning Setup diff --git a/examples/generic_switch/main/app_main.cpp b/examples/generic_switch/main/app_main.cpp index 9d74e3716..ce6398a92 100644 --- a/examples/generic_switch/main/app_main.cpp +++ b/examples/generic_switch/main/app_main.cpp @@ -107,6 +107,9 @@ extern "C" void app_main() switch_endpoint_id = endpoint::get_id(endpoint); ESP_LOGI(TAG, "Generic Switch created with endpoint_id %d", switch_endpoint_id); + cluster::fixed_label::config_t fl_config; + cluster_t *fl_cluster = cluster::fixed_label::create(endpoint, &fl_config, CLUSTER_FLAG_SERVER); + /* Add additional features to the node */ cluster_t *cluster = cluster::get(endpoint, Switch::Id); #if CONFIG_GENERIC_SWITCH_TYPE_LATCHING @@ -122,6 +125,22 @@ extern "C" void app_main() ESP_LOGE(TAG, "Matter start failed: %d", err); } + nvs_handle_t handle; + nvs_open_from_partition(CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION_LABEL, "chip-factory", NVS_READWRITE, &handle); + + int32_t out_value = 0; + if (nvs_get_i32(handle, "fl-sz/1", &out_value) == ESP_ERR_NVS_NOT_FOUND) + { + nvs_set_i32(handle, "fl-sz/1", 2); + nvs_set_str(handle, "fl-k/1/0", "myEP1LBL1"); + nvs_set_str(handle, "fl-v/1/0", "valEP1LBL1"); + nvs_set_str(handle, "fl-k/1/1", "myEP1LBL2"); + nvs_set_str(handle, "fl-v/1/1", "valEP1LBL2"); + } + + nvs_commit(handle); + nvs_close(handle); + #if CONFIG_ENABLE_CHIP_SHELL esp_matter::console::diagnostics_register_commands(); esp_matter::console::wifi_register_commands(); diff --git a/examples/generic_switch/mfg_binaries/20202020_3841.bin b/examples/generic_switch/mfg_binaries/20202020_3841.bin new file mode 100644 index 000000000..692529fa4 Binary files /dev/null and b/examples/generic_switch/mfg_binaries/20202020_3841.bin differ diff --git a/examples/generic_switch/sdkconfig.defaults b/examples/generic_switch/sdkconfig.defaults index b9730e305..a759ded2d 100644 --- a/examples/generic_switch/sdkconfig.defaults +++ b/examples/generic_switch/sdkconfig.defaults @@ -36,3 +36,7 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n # Disable DS Peripheral CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +# Enable for fixed-label +CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER=y +CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER=y diff --git a/tools/mfg_tool/chip_nvs.py b/tools/mfg_tool/chip_nvs.py index d3597e17f..ffec2c389 100644 --- a/tools/mfg_tool/chip_nvs.py +++ b/tools/mfg_tool/chip_nvs.py @@ -46,13 +46,6 @@ CHIP_NVS_MAP = { 'encoding': 'string', 'value': None, }, - - # Device Attestation Credentials - 'cert-dclrn': { - 'type': 'file', - 'encoding': 'binary', - 'value': None, - }, } } diff --git a/tools/mfg_tool/mfg_tool.py b/tools/mfg_tool/mfg_tool.py index 08c2c3141..c05585a97 100755 --- a/tools/mfg_tool/mfg_tool.py +++ b/tools/mfg_tool/mfg_tool.py @@ -343,8 +343,6 @@ def write_per_device_unique_data(args): chip_factory_update('dac-pub-key', os.path.abspath(dacs[2])) chip_factory_update('pai-cert', os.path.abspath(PAI['cert_der'])) - chip_factory_update('cert-dclrn', os.path.relpath(args.cert_dclrn)) - # If serial number is not passed, then generate one if (args.serial_num is None): chip_factory_update('serial-num', binascii.b2a_hex(os.urandom(SERIAL_NUMBER_LEN)).decode('utf-8')) @@ -478,55 +476,55 @@ def get_args(): 0:WiFi-SoftAP, 1:BLE, 2:On-network. Default is BLE.', choices=[0, 1, 2]) g_dac = parser.add_argument_group('Device attestation credential options') - g_dac.add_argument('-cn', '--cn-prefix', type=str, default='ESP32', + g_dac.add_argument('-cn', '--cn-prefix', default='ESP32', help='The common name prefix of the subject of the generated certificate.') g_dac.add_argument('-lt', '--lifetime', default=4294967295, type=any_base_int, help='Lifetime of the generated certificate. Default is 4294967295 if not specified, \ this indicate that certificate does not have well defined expiration date.') - g_dac.add_argument('-vf', '--valid-from', type=str, + g_dac.add_argument('-vf', '--valid-from', help='The start date for the certificate validity period in format --
[ :: ]. \ Default is current date.') # If DAC is present then PAI key is not required, so it is marked as not required here # but, if DAC is not present then PAI key is required and that case is validated in validate_args() - g_dac.add_argument('-c', '--cert', type=str, required=False, help='The input certificate file in PEM format.') - g_dac.add_argument('-k', '--key', type=str, required=False, help='The input key file in PEM format.') - g_dac.add_argument('-cd', '--cert-dclrn', type=str, required=True, help='The certificate declaration file in DER format.') - g_dac.add_argument('--dac-cert', type=str, help='The input DAC certificate file in PEM format.') - g_dac.add_argument('--dac-key', type=str, help='The input DAC private key file in PEM format.') + g_dac.add_argument('-c', '--cert', help='The input certificate file in PEM format.') + g_dac.add_argument('-k', '--key', help='The input key file in PEM format.') + g_dac.add_argument('-cd', '--cert-dclrn', help='The certificate declaration file in DER format.') + g_dac.add_argument('--dac-cert', help='The input DAC certificate file in PEM format.') + g_dac.add_argument('--dac-key', help='The input DAC private key file in PEM format.') input_cert_group = g_dac.add_mutually_exclusive_group(required=False) input_cert_group.add_argument('--paa', action='store_true', help='Use input certificate as PAA certificate.') input_cert_group.add_argument('--pai', action='store_true', help='Use input certificate as PAI certificate.') g_dev_inst_info = parser.add_argument_group('Device instance information options') - g_dev_inst_info.add_argument('-v', '--vendor-id', type=any_base_int, required=False, help='Vendor id') - g_dev_inst_info.add_argument('--vendor-name', type=str, required=False, help='Vendor name') - g_dev_inst_info.add_argument('-p', '--product-id', type=any_base_int, required=False, help='Product id') - g_dev_inst_info.add_argument('--product-name', type=str, required=False, help='Product name') - g_dev_inst_info.add_argument('--hw-ver', type=any_base_int, required=False, help='Hardware version') - g_dev_inst_info.add_argument('--hw-ver-str', type=str, required=False, help='Hardware version string') - g_dev_inst_info.add_argument('--mfg-date', type=str, required=False, help='Manufacturing date in format YYYY-MM-DD') - g_dev_inst_info.add_argument('--serial-num', type=str, required=False, help='Serial number') + g_dev_inst_info.add_argument('-v', '--vendor-id', type=any_base_int, help='Vendor id') + g_dev_inst_info.add_argument('--vendor-name', help='Vendor name') + g_dev_inst_info.add_argument('-p', '--product-id', type=any_base_int, help='Product id') + g_dev_inst_info.add_argument('--product-name', help='Product name') + g_dev_inst_info.add_argument('--hw-ver', type=any_base_int, help='Hardware version') + g_dev_inst_info.add_argument('--hw-ver-str', help='Hardware version string') + g_dev_inst_info.add_argument('--mfg-date', help='Manufacturing date in format YYYY-MM-DD') + g_dev_inst_info.add_argument('--serial-num', help='Serial number') g_dev_inst_info.add_argument('--enable-rotating-device-id', action='store_true', help='Enable Rotating device id in the generated binaries') - g_dev_inst_info.add_argument('--rd-id-uid', type=str, required=False, + g_dev_inst_info.add_argument('--rd-id-uid', help='128-bit unique identifier for generating rotating device identifier, provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"') g_dev_inst = parser.add_argument_group('Device instance options') - g_dev_inst.add_argument('--calendar-types', type=str, nargs='+', required=False, + g_dev_inst.add_argument('--calendar-types', nargs='+', help='List of supported calendar types. Supported Calendar Types: Buddhist, Chinese, Coptic, \ Ethiopian, Gregorian, Hebrew, Indian, Islamic, Japanese, Korean, Persian, Taiwanese') - g_dev_inst.add_argument('--locales', type=str, nargs='+', required=False, + g_dev_inst.add_argument('--locales', nargs='+', help='List of supported locales, Language Tag as defined by BCP47, eg. en-US en-GB') - g_dev_inst.add_argument('--fixed-labels', type=str, nargs='+', required=False, + g_dev_inst.add_argument('--fixed-labels', nargs='+', help='List of fixed labels, eg: "0/orientation/up" "1/orientation/down" "2/orientation/down"') g_basic = parser.add_argument_group('Few more Basic clusters options') - g_basic.add_argument('--product-label', type=str, required=False, help='Product label') - g_basic.add_argument('--product-url', type=str, required=False, help='Product URL') + g_basic.add_argument('--product-label', help='Product label') + g_basic.add_argument('--product-url', help='Product URL') g_extra_info = parser.add_argument_group('Extra information options using csv files') - g_extra_info.add_argument('--csv', type=str, help='CSV file containing the partition schema for extra options. \ + g_extra_info.add_argument('--csv', help='CSV file containing the partition schema for extra options. \ [REF: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/mass_mfg.html#csv-configuration-file]') - g_extra_info.add_argument('--mcsv', type=str, help='Master CSV file containig optional/extra values specified by the user. \ + g_extra_info.add_argument('--mcsv', help='Master CSV file containig optional/extra values specified by the user. \ [REF: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/mass_mfg.html#master-value-csv-file]') return parser.parse_args() @@ -561,6 +559,10 @@ def add_optional_KVs(args): chip_factory_append('dac-pub-key', 'file', 'binary', None) chip_factory_append('pai-cert', 'file', 'binary', None) + # Add certificate declaration + if args.cert_dclrn: + chip_factory_append('cert-dclrn','file','binary', os.path.relpath(args.cert_dclrn)) + # Add the Keys in csv files if args.csv is not None: chip_nvs_map_append_config_csv(args.csv)