# 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.19. [TC-CADMIN-1.19] max number of Commissioned Fabrics and
    SupportedFabrics rollover using ECM [DUT - Commissionee]
PICS:
    - CADMIN.S

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

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

    - label: "Step 1: TH_CR1 starts a commissioning process with DUT_CE"
      PICS: CADMIN.S
      verification: |
          "1. Provision the device using TH_CR1 -chip tool(use above instructions) ,
          "
      disabled: true

    - label:
          "Step 2: TH_CR1 opens a commissioning window on DUT_CE using a
          commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM"
      PICS: CADMIN.S.C00.Rsp
      verification: |
          On TH_CR1 (chip tool), open commissioning window using ECM

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

          Verify Manual pairing code on TH_CR1 (chip-tool) Log

          [1635925713.966786][9695:9700] CHIP:SC: Success status report received. Session was established
          [1635925713.966839][9695:9700] CHIP:IN: New secure session created for device 0x0000000000000001, key 33!!
          [1635925713.966938][9695:9700] CHIP:CTL: OpenCommissioningWindow for device ID 1
          [1635925713.972601][9695:9700] CHIP:DMG: ICR moving to [AddingComm]
          [1635925713.972705][9695:9700] CHIP:DMG: ICR moving to [AddedComma]
          [1635925713.972815][9695:9700] CHIP:IN: Prepared encrypted message 0xaaaad9b57d10 to 0x0000000000000001 of type 0x8 and protocolId (0, 1) on exchange 31056i with MessageCounter:0.
          [1635925713.972876][9695:9700] CHIP:IN: Sending encrypted msg 0xaaaad9b57d10 with MessageCounter:0 to 0x0000000000000001 at monotonic time: 13449459 msec
          [1635925713.973006][9695:9700] CHIP:DMG: ICR moving to [CommandSen]
          [1635925713.973061][9695:9700] CHIP:CTL: Manual pairing code: [36217551633]
          [1635925713.973120][9695:9700] CHIP:CTL: SetupQRCode: [MT:00000CQM00A7F87ZT10]
          [1635925713.973178][9695:9700] CHIP:EM: Sending Standalone Ack for MessageCounter:1964916542 on exchange 31055i
      disabled: true

    - label: "Step 3: THn starts a commissioning process with DUT_CE"
      PICS: CADMIN.S
      verification: |
          On TH_CR1+1 controller using chip tool connect to the accessory


          ./chip-tool pairing code 2 36217551633  --commissioner-name beta

          Verify you got below message on TH_CR1+1(chip-tool) log
          Device commissioning completed with success
      disabled: true

    - label:
          "Step 4: Repeat Step 3 and Step 4 an additional (SupportedFabrics - 2)
          times to reach an index value of SupportedFabrics on DUT_CE"
      PICS: CADMIN.S.C00.Rsp
      verification: |
          Repeat step 3 until  CommissionedFabrics=SupportedFabrics  (Supported fabrics value obtained in the precondition)

          Use the following command to verify the currentcommissioned fabric (Output number may vary depends on the number successful commissioning )

          ./chip-tool operationalcredentials read commissioned-fabrics 1 0

          [1660907933.677983][33780:33785] CHIP:TOO:   CommissionedFabrics: 16
      disabled: true

    - label:
          "Step 5: THn_1 starts a commissioning process and opens a
          commissioning window with DUT_CE"
      PICS: CADMIN.S
      verification: |
          On THnth controller using chip tool connect to the accessory

          ./chip-tool pairing code 6 36217551633 --commissioner-name 4

          Verify DUT_CE responds with NOCResponse with a StatusCode of 0x05 on THn (chip-tool) log

          CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0008
          [1649756670.402192][10794:10799] CHIP:CTL: Device returned status 5 on receiving the NOC
          [1649756670.402221][10794:10799] CHIP:CTL: Add NOC failed with error ../../third_party/connectedhomeip/src/controller/CHIPDeviceController.cpp:1110: CHIP Error 0x0000000B: No memory
          [1649756670.402241][10794:10799] CHIP:CTL: Failed to perform commissioning step 13
      disabled: true

    - label: "Step 6: TH_CR1 removes FabricIndex1"
      PICS: OPCREDS.S.C0a.Rsp
      verification: |
          on TH_CR1 using chip tool, remove fabric with FabricIndex=1

          ./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]

          Verify CommissionedFabrics=SupportedFabrics-1 on  TH_CR1(chip-tool) log

          ./chip-tool operationalcredentials read commissioned-fabrics 2 0 --commissioner-name beta

          [1660907933.677983][33780:33785] CHIP:TOO:   CommissionedFabrics: 15
      disabled: true
