# 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:
    4.1.7. [TC-CADMIN-1.7] Commissioning window handling timeout and revocation
    using ECM [DUT - Commissioner]

PICS:
    - CADMIN.C
    - CADMIN.C.C00.Tx

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

tests:
    - label: "Note"
      verification: |
          For DUT as comissioner  test cases, Chip-tool command used below are an example to verify the functionality. For certification test, we expect DUT should have a capability or way to run the equivalent command.
      disabled: true

    - label: "Precondition"
      verification: |
          Reset Devices to factory defaults
      disabled: true

    - label: "Step 1: DUT_CR1 starts a commissioning process with TH_CE"
      PICS: CADMIN.C
      verification: |
          "1. Provision the TH_CE (all-cluster-app) device using DUT_CR1 (chip-tool ) on the raspi" "
      disabled: true

    - label:
          "Step 2: DUT_CR1 sends command to TH_CE to open a commissioning window
          with a commissioning timeout of PIXIT.CADMIN.CwDuration seconds using
          ECM"
      PICS: CADMIN.C.C00.Tx
      verification: |
          On DUT_CR1 send the below command

           Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command with their all-cluster-app and for the second and third commissioners.


          ./chip-tool pairing open-commissioning-window 1 1 300 1000 3840

          Verify the Open commisioning window on the TH_CE(all-cluster-app) Log:

          [1660901022.112296][3045:3045] CHIP:DIS: mDNS service published: _matterc._udp
          [1660901022.112389][3045:3045] CHIP:ZCL: Commissioning window is now open
          [1660901022.112474][3045:3045] CHIP:DMG: Command handler moving to [ Preparing]
      disabled: true

    - label:
          "Step 3a: A User Consent screen pops up asking for Users permission to
          allow second commissioner to control TH_CE"
      PICS: CADMIN.M.UserInterfaceDisplay
      verification: |
          Verify the User Consent pop up screen. Verify that the pop up closes after user gives permission
      disabled: true

    - label:
          "Step 3.b: 11 digit Manual Code is displayed on the screen in textual
          format for User to see"
      PICS: CADMIN.M.UserInterfaceDisplay
      verification: |
          Verify that the displayed Manual Code is 11 digits long and doesn’t contain Vendor_ID or Product_ID.
      disabled: true

    - label:
          "Step 3.c: A voice prompt of the Manual Code format should be heard"
      PICS: CADMIN.M.AudioInterface
      verification: |
          Verify voice prompt saying the manual code. Verify the voice prompt repeats if user asks.
      disabled: true

    - label:
          "Step 4: TH_CR2 starts a commissioning process with TH_CE after
          PIXIT.CADMIN.CwDuration (that was given in step 2) + 10 seconds"
      PICS: CADMIN.C
      verification: |
          On TH_CR2 send the below command

          Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers

           (considering 36366524220 as the manual code generated by DUT controller)
          ./chip-tool pairing code 2 36366524220 --commissioner-name beta

          Verify the below message in the TH_CR2(chip-tool) Log:

          [1663841939.843550][13897:13897] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0)
          [1663841939.843617][13897:13897] CHIP:DL: Inet Layer shutdown
          [1663841939.843673][13897:13897] CHIP:DL: BLE Layer shutdown
          [1663841939.843727][13897:13897] CHIP:DL: System Layer shutdown
          [1663841939.844009][13897:13897] CHIP:TOO: Run command failure: ../../examples/chip-tool/commands/pairing/PairingCommand.cpp:151: CHIP Error 0x00000003: Incorrect state
      disabled: true

    - label:
          "Step 5: DUT_CR1 sends command to TH_CE to open a new commissioning
          window with a commissioning timeout of PIXIT.CADMIN.CwDuration seconds
          using ECM"
      PICS: CADMIN.C.C00.Tx
      verification: |
          On DUT_CR1 send the below command

          Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers

          ./chip-tool pairing open-commissioning-window 1 1 300 1000 3840

          Verify the Open commisioning window on the TH_CE(all-cluster-app) Log:

          [1660901022.112296][3045:3045] CHIP:DIS: mDNS service published: _matterc._udp
          [1660901022.112389][3045:3045] CHIP:ZCL: Commissioning window is now open
          [1660901022.112474][3045:3045] CHIP:DMG: Command handler moving to [ Preparing]
      disabled: true

    - label:
          "Step 6: DUT_CR1 sends command to TH_CE to revoke the commissioning
          window"
      PICS: CADMIN.C.C02.Tx
      verification: |
          On DUT_CR1 send the below command

            Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers

          ./chip-tool administratorcommissioning revoke-commissioning 1 0 --timedInteractionTimeoutMs 1000


          Verify the Commissioning window is closed in TH_CE(all-clusters-app) Log
          [1661485834.635244][6993:6993] CHIP:DIS: mDNS service published: _matter._tcp
          [1661485834.635293][6993:6993] CHIP:ZCL: Commissioning window is now closed
          [1661485834.635328][6993:6993] CHIP:DMG: Command handler moving to [ Preparing]
      disabled: true

    - label: "Step 7: TH_CR2 starts a commissioning process with TH_CE"
      PICS: CADMIN.C
      verification: |
          On TH_CR2 send the below command

            Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers

           (considering 34921141778 as the manual code generated by DUT controller)
          ./chip-tool pairing code 2 34921141778 --commissioner-name beta

          [1665481996.784125][4913:4913] CHIP:TS: Pending Last Known Good Time: 2022-10-10T05:00:30
          [1665481996.784447][4913:4913] CHIP:TS: Previous Last Known Good Time: 2022-10-10T05:00:30
          [1665481996.784506][4913:4913] CHIP:TS: Reverted Last Known Good Time to previous value
          [1665481996.785092][4913:4913] CHIP:DL: writing settings to file (/tmp/chip_counters.ini-9I5bK9)
          [1665481996.786704][4913:4913] CHIP:DL: renamed tmp file to file (/tmp/chip_counters.ini)
          [1665481996.786930][4913:4913] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0)
          [1665481996.786999][4913:4913] CHIP:DL: Inet Layer shutdown
          [1665481996.787065][4913:4913] CHIP:DL: BLE Layer shutdown
          [1665481996.787123][4913:4913] CHIP:DL: System Layer shutdown
          [1665481996.787363][4913:4913] CHIP:TOO: Run command failure: ../../commands/pairing/PairingCommand.cpp:164: CHIP Error 0x00000003: Incorrect state
      disabled: true

    - label:
          "Step 8: DUT_CR1 sends command to TH_CE to revoke the commissioning
          window"
      PICS: CADMIN.C.C02.Tx
      verification: |
          On DUT_CR1 send the below command

            Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers

          ./chip-tool administratorcommissioning revoke-commissioning 1 0 --timedInteractionTimeoutMs 1000


          Verify the Commissioning window is closed in TH_CE(all-clusters-app) Log

          [1661485921.687243][6993:6993] CHIP:ZCL: Received command to close commissioning window
          [1661485921.687265][6993:6993] CHIP:ZCL: Commissioning window is currently not open
          [1661485921.687298][6993:6993] CHIP:DMG: Command handler moving to [ Preparing]
      disabled: true

    - label:
          "Step 9: DUT_CR1 sends commands to TH_CE to write and read the Basic
          Information Clusters NodeLabel mandatory attribute"
      PICS: BINFO.C.A0005
      verification: |
          On DUT_CR1 send the below command

            Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers
          ./chip-tool  basicinformation write node-label te5new 1 0

          Verify Write request on TH_CE(all-clusters-app) Log

          [1660894021.901330][2871:2871] CHIP:EM: Handling via exchange: 9616r, Delegate: 0xaaaada21ffc0
          [1660894021.901426][2871:2871] CHIP:IM: Received Write request
          [1660894021.901484][2871:2871] CHIP:DMG: IM WH moving to [Initialized]
          [1660894021.901613][2871:2871] CHIP:DMG: WriteRequestMessage =
          [1660894021.901676][2871:2871] CHIP:DMG: {
          [1660894021.901735][2871:2871] CHIP:DMG:         suppressResponse = false,
          [1660894021.901802][2871:2871] CHIP:DMG:         timedRequest = false,
          [1660894021.901864][2871:2871] CHIP:DMG:         AttributeDataIBs =
          [1660894021.901940][2871:2871] CHIP:DMG:         [
          [1660894021.902001][2871:2871] CHIP:DMG:                 AttributeDataIB =
          [1660894021.902071][2871:2871] CHIP:DMG:                 {
          [1660894021.902136][2871:2871] CHIP:DMG:                         AttributePathIB =
          [1660894021.902219][2871:2871] CHIP:DMG:                         {
          [1660894021.902302][2871:2871] CHIP:DMG:                                 Endpoint = 0x0,
          [1660894021.902394][2871:2871] CHIP:DMG:                                 Cluster = 0x28,
          [1660894021.902488][2871:2871] CHIP:DMG:                                 Attribute = 0x0000_0005,
          [1660894021.902574][2871:2871] CHIP:DMG:                         }
          [1660894021.902827][2871:2871] CHIP:DMG:
          [1660894021.902912][2871:2871] CHIP:DMG:                         Data = "te5new" (6 chars),
          [1660894021.902985][2871:2871] CHIP:DMG:                 },

          ./chip-tool  basicinformation read node-label 1 0
          Verify read request on TH_CE(all-clusters-app) Log


          [1660894142.828718][2871:2871] CHIP:EM: Handling via exchange: 62454r, Delegate: 0xaaaada21ffc0
          [1660894142.828834][2871:2871] CHIP:IM: Received Read request
          [1660894142.829023][2871:2871] CHIP:DMG: ReadRequestMessage =
          [1660894142.829097][2871:2871] CHIP:DMG: {
          [1660894142.829153][2871:2871] CHIP:DMG:         AttributePathIBs =
          [1660894142.829235][2871:2871] CHIP:DMG:         [
          [1660894142.829306][2871:2871] CHIP:DMG:                 AttributePathIB =
          [1660894142.829376][2871:2871] CHIP:DMG:                 {
          [1660894142.829449][2871:2871] CHIP:DMG:                         Endpoint = 0x0,
          [1660894142.829532][2871:2871] CHIP:DMG:                         Cluster = 0x28,
          [1660894142.829627][2871:2871] CHIP:DMG:                         Attribute = 0x0000_0005,
          [1660894142.829703][2871:2871] CHIP:DMG:                 }
          [1660894142.829777][2871:2871] CHIP:DMG:
      disabled: true

    - label:
          "Step 10: DUT_CR1 sends command to TH_CE to open a commissioning
          window with a commissioning timeout of PIXIT.CADMIN.CwDuration seconds
          using ECM"
      PICS: CADMIN.C.C00.Tx
      verification: |
          On DUT_CR1 send the below command

            Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers

          ./chip-tool pairing open-commissioning-window 1 1 300 1000 3840

          Verify the Commissioning window is opened in TH_CE(all-clusters-app) Log

          [1660901022.112296][3045:3045] CHIP:DIS: mDNS service published: _matterc._udp
          [1660901022.112389][3045:3045] CHIP:ZCL: Commissioning window is now open
          [1660901022.112474][3045:3045] CHIP:DMG: Command handler moving to [ Preparing]
      disabled: true

    - label: "Step 11: TH_CR2 starts a commissioning process with TH_CE"
      PICS: CADMIN.C
      verification: |
          On TH_CR2 send the below command

            Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command in their DUT or use multiple commissioners/controllers

           (considering 35256543344 as the manual code generated by DUT controller)
          ./chip-tool pairing code 2 35256543344 --commissioner-name beta

           Verify whether you got below message in the log of TH_CR2(CHIP-TOOL)
          Device commissioning completed with success
      disabled: true

    - label: "Step 12: TH_CR3 starts a commissioning process with TH_CE"
      PICS: CADMIN.C
      verification: |
          On TH_CR3 send the below command

           Below are the example command for using single RPI as multiple controller. Vendor should have the provision to use the equivalent command with their all-cluster-app and for the second and third commissioners.

            (considering 35256543344 as the manual code generated by DUT controller)
          ./chip-tool pairing code 3 35256543344 --commissioner-name gamma

          verify you got the following message in the TH_CR3(chip-tool) log

          [1678796869.645576][648903:648903] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0)
          [1678796869.645584][648903:648903] CHIP:DL: Inet Layer shutdown
          [1678796869.645589][648903:648903] CHIP:DL: BLE Layer shutdown
          [1678796869.645596][648903:648903] CHIP:DL: System Layer shutdown
          [1678796869.645693][648903:648903] CHIP:TOO: Run command failure: ../../commands/pairing/PairingCommand.cpp:215: CHIP Error 0x00000003: Incorrect state
      disabled: true
