# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default

name:
    3.3.19. [TC-DD-3.19] Commissioning Flow - Commission, Unpair and
    Re-commission Device [DUT - Commissionee]

PICS:
    - MCORE.ROLE.COMMISSIONEE
    - MCORE.DD.QR

config:
    nodeId: 0x12344321
    cluster: "Basic Information"
    endpoint: 0

tests:
    - label: "Preconditions"
      verification: |
          1 - Commissioner is on an operational network and has accurate date, time, timezone, regulatory, and fabric information available.
          2 - 5.1.3 - QR code is printed on the Commissionee device or in additional provided materials (ex: manual).

          To put the DUT into commissionable state and verify commissionable state.
          This step is same in couple of other cases (like DD) so use the same verification method here too i.e. if your DUT is discoverable over mDNS then use 'chiptool discover commissionables'  to discover mDNS adv and provision the device using 'chip-tool pairing code node-id payload'.
          otherwise if your DUT is advertising over BLE , pls use the '/chip-tool pairing ble-wifi 1 zigbeehome matter123 20202021 3841 --trace_decode 1' command to discover and provision the device (BTW the SSID , passwd, descriminator ..etc are configurable parameters for your DUT)
      disabled: true

    - label:
          "Step 1: Place DUT into commissioning mode using the DUTs
          manufacturers means to be discovered by the TH Commissioner"
      verification: |
          Verify on DUT (All-cluster-app):
          ./chip-all-clusters-app --discriminator 3841

          [1651111142.369356][32024:32024] CHIP:DL: Device Configuration:
          [1651111142.369395][32024:32024] CHIP:DL:   Serial Number: TEST_SN
          [1651111142.369438][32024:32024] CHIP:DL:   Vendor Id: 65521 (0xFFF1)
          [1651111142.369470][32024:32024] CHIP:DL:   Product Id: 32769 (0x8001)
          [1651111142.369496][32024:32024] CHIP:DL:   Hardware Version: 0
          [1651111142.369514][32024:32024] CHIP:DL:   Setup Pin Code (0 for UNKNOWN/ERROR): 20202021
          [1651111142.369531][32024:32024] CHIP:DL:   Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3841 (0xF01)
          [1651111142.369555][32024:32024] CHIP:DL:   Manufacturing Date: (not set)
          [1651111142.369573][32024:32024] CHIP:DL:   Device Type: 65535 (0xFFFF)
          [1651111142.370760][32024:32024] CHIP:SVR: SetupQRCode: [MT:-24J0ALY01KA0648G00]

          Verify on TH (Chip-tool):
          For devices already on the network:
           ./chip-tool discover commissionables

          [1651111150395] [95835:65674062] CHIP: [DL] Mdns: OnNewAddress interface: 7 ip:192.168.1.2
          [1651111150395] [95835:65674062] CHIP: [DIS]         Vendor ID: 65521
          [1651111150395] [95835:65674062] CHIP: [DIS]         Product ID: 32769
          [1651111150395] [95835:65674062] CHIP: [DIS]         Long Discriminator: 3841
          [1651111150395] [95835:65674062] CHIP: [DIS]         Pairing Hint: 33
          [1651111150395] [95835:65674062] CHIP: [DIS]         Hostname: DCA6328D2B9F0000
          [1651111150395] [95835:65674062] CHIP: [DIS]         Instance Name: B4B6B83476500D4A
          [1651111150395] [95835:65674062] CHIP: [DIS]         IP Address #1: fe80::dea6:32ff:fe8d:2b9f
          [1651111150395] [95835:65674062] CHIP: [DIS]         IP Address #2: fe80::dea6:32ff:fe8d:2ba0
          [1651111150395] [95835:65674062] CHIP: [DIS]         IP Address #3: 192.168.1.2
          [1651111150395] [95835:65674062] CHIP: [DIS]         Port: 5540
          [1651111150395] [95835:65674062] CHIP: [DIS]         Commissioning Mode: 1
          [1651111150395] [95835:65674062] CHIP: [DIS]         Mrp Interval idle: 5000 ms
          [1651111150395] [95835:65674062] CHIP: [DIS]         Mrp Interval active: 300 ms


          For devices not on the network (i.e. BLE discovery):
          1. Discover commissionables over BLE using a BLE discovery tool of choice.
          Try NRF Connect app (https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-desktop)
          OR
          HCIDump (https://ubuntu.com/core/docs/bluez/reference/commands)
          Observe the DUT advertising in a commissionable state
      disabled: true

    - label:
          "Step 2: Scan DUTs QR code using the TH Commissioner. Follow any steps
          needed for the Commissioner/Commissionee to complete the commissioning
          process over the DUT Commissionees method of device discovery"
      verification: |
          Verify on DUT (All-cluster-app):
          [1651111335.475159][32130:32130] CHIP:SVR: Commissioning completed successfully
          [1651111335.475204][32130:32130] CHIP:DIS: Updating services using commissioning mode 0

          Verify on TH (Chip-tool):
           ./chip-tool pairing code 1 MT:-24J0ALY01KA0648G00

          [1651111335378] [95843:65675989] CHIP: [CTL] Received CommissioningComplete response
          [1651111335378] [95843:65675989] CHIP: [CTL] Successfully finished commissioning step 'SendComplete'
          [1651111335378] [95843:65675989] CHIP: [CTL] Commissioning stage next step: 'SendComplete' -> 'Cleanup'
          [1651111335378] [95843:65675989] CHIP: [CTL] Performing next commissioning step 'Cleanup'
          [1651111335378] [95843:65675989] CHIP: [CTL] Successfully finished commissioning step 'Cleanup'
          [1651111335378] [95843:65675989] CHIP: [TOO] Device commissioning completed with success
      disabled: true

    - label:
          "Step 3: Using TH Commissioner, unpair the DUT Commissionee from the
          Matter network."
      verification: |
          Verify on TH (Chip-tool):
          ./chip-tool operationalcredentials remove-fabric 1 1 0

          CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0008
          CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Command 0x0000_0008
          CHIP:TOO:   NOCResponse: {
          CHIP:TOO:     statusCode: 0
          CHIP:TOO:     fabricIndex: 1
          CHIP:TOO:    }
          CHIP:DMG: ICR moving to [AwaitingDe]
      disabled: true

    - label:
          "Step 4: Place DUT Commissionee back into commissioning mode using the
          DUT manufacturers means to be discovered by the TH Commissioner"
      verification: |
          1. On RasPi DUT  rm -rf /tmp/chip*
          2. On RasPi DUT ./chip-all-clusters-app --discriminator 3841

          Verify on TH (Chip-tool):
          For devices already on the network:
           ./chip-tool discover commissionables
          [1651111576350] [95850:65678872] CHIP: [DL] Mdns: OnNewAddress interface: 7 ip:192.168.1.2
          [1651111576350] [95850:65678872] CHIP: [DIS]         Vendor ID: 65521
          [1651111576350] [95850:65678872] CHIP: [DIS]         Product ID: 32769
          [1651111576350] [95850:65678872] CHIP: [DIS]         Long Discriminator: 3841
          [1651111576350] [95850:65678872] CHIP: [DIS]         Pairing Hint: 33
          [1651111576350] [95850:65678872] CHIP: [DIS]         Hostname: DCA6328D2B9F0000
          [1651111576350] [95850:65678872] CHIP: [DIS]         Instance Name: F17CF4C2DECCDA4B
          [1651111576350] [95850:65678872] CHIP: [DIS]         IP Address #1: fe80::dea6:32ff:fe8d:2ba0
          [1651111576350] [95850:65678872] CHIP: [DIS]         IP Address #2: fe80::dea6:32ff:fe8d:2b9f
          [1651111576350] [95850:65678872] CHIP: [DIS]         IP Address #3: 192.168.1.2
          [1651111576350] [95850:65678872] CHIP: [DIS]         Port: 5540
          [1651111576350] [95850:65678872] CHIP: [DIS]         Commissioning Mode: 1
          [1651111576350] [95850:65678872] CHIP: [DIS]         Mrp Interval idle: 5000 ms
          [1651111576350] [95850:65678872] CHIP: [DIS]         Mrp Interval active: 300 ms


          For devices not on the network (i.e. BLE discovery):
          1. Discover commissionables over BLE using a BLE discovery tool of choice.
          Try NRF Connect app (https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-desktop)
          OR
          HCIDump (https://ubuntu.com/core/docs/bluez/reference/commands)
          Observe the DUT advertising in a commissionable state
      disabled: true

    - label:
          "Step 5: Scan DUTs QR code using the TH Commissioner. Follow any steps
          needed for the Commissioner/Commissionee to complete the commissioning
          process over the DUT Commissionees method of device discovery"
      verification: |
          Verify on DUT (All-cluster-app):
          [1651111614.006849][32259:32259] CHIP:SVR: Commissioning completed successfully
          [1651111614.006893][32259:32259] CHIP:DIS: Updating services using commissioning mode 0

          Verify on TH (Chip-tool):
           ./chip-tool pairing code 1 MT:-24J0ALY01KA0648G00

          [1651111613912] [95856:65679504] CHIP: [CTL] Received CommissioningComplete response
          [1651111613912] [95856:65679504] CHIP: [CTL] Successfully finished commissioning step 'SendComplete'
          [1651111613912] [95856:65679504] CHIP: [CTL] Commissioning stage next step: 'SendComplete' -> 'Cleanup'
          [1651111613912] [95856:65679504] CHIP: [CTL] Performing next commissioning step 'Cleanup'
          [1651111613912] [95856:65679504] CHIP: [CTL] Successfully finished commissioning step 'Cleanup'
          [1651111613912] [95856:65679504] CHIP: [TOO] Device commissioning completed with success
      disabled: true
