# 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.5. [TC-DD-3.5] Commissioning Flow - Concurrent [DUT - Commissioner]

PICS:
    - MCORE.ROLE.COMMISSIONER

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

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

    - label: "Preconditions"
      verification: |
          1 - 5.5 - Commissioner is on a network. - The network can either be WiFi or Thread.

          2 - 5.5 - Commissionee can either be a Matter device which is already on a network or the test harness connected to the network.
      disabled: true

    - label:
          "Step 1: Commissioner has regulatory and fabric information available
          and has accurate date, time and timezone"
      verification: |
          ./chip-all-clusters-app --wifi --discriminator 3841

          Verify in TH (ALL-CLUSTER-APP)

          [1653471956.966855][10713:10713] CHIP:SPT: PASE PBKDF iterations set to 1000
          [1653471956.966887][10713:10713] CHIP:SPT: LinuxCommissionableDataProvider didn't get a PASE salt, generating one.
          [1653471956.972152][10713:10713] CHIP:DL: Device Configuration:
          [1653471956.972270][10713:10713] CHIP:DL:   Serial Number: TEST_SN
          [1653471956.972315][10713:10713] CHIP:DL:   Vendor Id: 65521 (0xFFF1)
          [1653471956.972354][10713:10713] CHIP:DL:   Product Id: 32769 (0x8001)
          [1653471956.972388][10713:10713] CHIP:DL:   Hardware Version: 0
          [1653471956.972413][10713:10713] CHIP:DL:   Setup Pin Code (0 for UNKNOWN/ERROR): 20202021
          [1653471956.972435][10713:10713] CHIP:DL:   Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3841 (0xF01)
          [1653471956.972464][10713:10713] CHIP:DL:   Manufacturing Date: (not set)
          [1653471956.972488][10713:10713] CHIP:DL:   Device Type: 65535 (0xFFFF)
          [1653471956.972509][10713:10713] CHIP:-: ==== Onboarding payload for Standard Commissioning Flow ====
          [1653471956.972546][10713:10713] CHIP:SVR: SetupQRCode: [MT:-24J0CEK01KA0648G00]
          [1653471956.972579][10713:10713] CHIP:SVR: Copy/paste the below URL in a browser to see the QR Code:
          [1653471956.972600][10713:10713] CHIP:SVR: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J0CEK01KA0648G00
          [1653471956.972632][10713:10713] CHIP:SVR: Manual pairing code: [34970112332]
          [1653471956.972654][10713:10713] CHIP:-: ==== Onboarding payload for Custom Commissioning Flows ====
          [1653471956.972715][10713:10713] CHIP:SVR: SetupQRCode: [MT:-24J048N01KA0648G00]
          [1653471956.972748][10713:10713] CHIP:SVR: Copy/paste the below URL in a browser to see the QR Code:
          [1653471956.972769][10713:10713] CHIP:SVR: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J048N01KA0648G00
          [1653471956.972803][10713:10713] CHIP:SVR: Manual pairing code: [749701123365521327694]


          ./chip-tool pairing code 1 MT:-24J0CEK01KA0648G00
          Verify in DUT(CHIP-TOOL)

          [1657226543861] [30621:16744161] CHIP: [IN] SecureSession[0x6000007cc000]: Activated - Type:1 LSID:47293
          [1657226543861] [30621:16744161] CHIP: [IN] New secure session activated for device <FFFFFFFB00000000, 0>, LSID:47293 PSID:201!
          [1657226543861] [30621:16744161] CHIP: [CTL] Remote device completed SPAKE2+ handshake
          [1657226543861] [30621:16744161] CHIP: [CTL] Stopping commissioning discovery over DNS-SD
          [1657226543861] [30621:16744161] CHIP: [TOO] Pairing Success
          [1657226543861] [30621:16744161] CHIP: [TOO] PASE establishment successful
          [1657226543861] [30621:16744161] CHIP: [CTL] Commissioning stage next step: 'SecurePairing' -> 'ReadCommissioningInfo'
      disabled: true

    - label:
          "Step 2: Commissioner and Commissionee discover each other and connect
          via the discovery mode applicable for the DUT. If (MCORE.DD.DT_IP), TH
          device is advertising over IP Network using DNS-based Service
          Discovery (DNS-SD)"
      PICS: MCORE.DD.DISCOVERY_IP
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
          ./chip-all-clusters-app
          ...
          [1657226543.948995][369114:369114] CHIP:IN: SecureSession[0xaaaab60788e0]: Activated - Type:1 LSID:201
          [1657226543.949023][369114:369114] CHIP:IN: New secure session created for device <FFFFFFFB00000000, 0>, LSID:201 PSID:47293!
          [1657226543.949048][369114:369114] CHIP:SVR: Commissioning completed session establishment step

          Verify in DUT(CHIP-TOOL)
          ./chip-tool pairing code 1 MT:-24J0AFN00KA0648G00
          ...
          [1657226543861] [30621:16744161] CHIP: [IN] SecureSession[0x6000007cc000]: Activated - Type:1 LSID:47293
          [1657226543861] [30621:16744161] CHIP: [IN] New secure session activated for device <FFFFFFFB00000000, 0>, LSID:47293 PSID:201!
          [1657226543861] [30621:16744161] CHIP: [CTL] Remote device completed SPAKE2+ handshake
          [1657226543861] [30621:16744161] CHIP: [CTL] Stopping commissioning discovery over DNS-SD
          [1657226543861] [30621:16744161] CHIP: [TOO] Pairing Success
          [1657226543861] [30621:16744161] CHIP: [TOO] PASE establishment successful
          [1657226543861] [30621:16744161] CHIP: [CTL] Commissioning stage next step: 'SecurePairing' -> 'ReadCommissioningInfo'
      disabled: true

    - label:
          "Step 3: Establish encryption keys with Password Authenticated Session
          Establishment on the commissioning channel"
      verification: |
          Verify that the responder receives the PBKDFParamRequest message

          Verify in TH (ALL-CLUSTER-APP)
          CHIP:SC: Received PBKDF param request
          CHIP:SC: Peer assigned session ID 18450
          CHIP:SC: Found MRP parameters in the message
          CHIP:SC: Including MRP parameters in PBKDF param response
          CHIP:EM: Piggybacking Ack for MessageCounter:850320430 on exchange: 63762r
          CHIP:IN: Prepared unauthenticated message 0xaaaaad340560 to 0x0000000000000000 (0)  of type 0x21 and protocolId (0, 0) on exchange 63762r with MessageCounter:1341084110.
          CHIP:IN: Sending unauthenticated msg 0xaaaaad340560 with MessageCounter:1341084110 to 0x0000000000000000 at monotonic time: 0000000000FBA380 msec
          CHIP:SC: Sent PBKDF param response
      disabled: true

    - label:
          "Step 4: Commissioner SHALL re-arm Fail-safe timer on Commissionee
          within 60s (the autonomously Fail-safe timer length set by
          Commissionee)"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
          [1661796620.258906][17861:17861] CHIP:FS: GeneralCommissioning: Received ArmFailSafe (60s)
      disabled: true

    - label:
          "Step 5: Commissioner SHALL configure regulatory information in the
          Commissionee."
      PICS: MCORE.COM.WIRELESS
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
           NVS set: chip-config/regulatory-location = 0 (0x0)
      disabled: true

    - label:
          "Step 6: Commissioner requests operational CSR from Commissionee with
          OperationalCSRRequest command"
      verification: |
          1. Verify the following on DUT after commissioning

          Verify in TH (ALL-CLUSTER-APP)
          [1661746360.259922][132620:132620] CHIP:ZCL: OpCreds: Received a CSRRequest command
          [1661746360.259946][132620:132620] CHIP:ZCL: OpCreds: Finding fabric with fabricIndex 0x0
          [1661746360.259971][132620:132620] CHIP:EM: Sending Standalone Ack for MessageCounter:123253174 on exchange 23504r
          [1661746360.260030][132620:132620] CHIP:IN: Prepared secure message 0xffffe25a60c8 to 0xFFFFFFFB00000000 (0)  of type 0x10 and protocolId (0, 0) on exchange 23504r with MessageCounter:155549628.
          [1661746360.260066][132620:132620] CHIP:IN: Sending encrypted msg 0xffffe25a60c8 with MessageCounter:155549628 to 0xFFFFFFFB00000000 (0) at monotonic time: 000000000F107443 msec
          [1661746360.260187][132620:132620] CHIP:EM: Flushed pending ack for MessageCounter:123253174 on exchange 23504r
          [1661746360.261186][132620:132620] CHIP:ZCL: OpCreds: AllocatePendingOperationalKey succeeded
          [1661746360.261515][132620:132620] CHIP:ZCL: OpCreds: CSRRequest successful.
      disabled: true

    - label:
          "Step 7: Commissioner configures operational credentials on DUT if not
          previously installed"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)

          OpCreds: Received an AddTrustedRootCertificate command
      disabled: true

    - label:
          "Step 8: Commissioner configures itself as administrator in ACL on TH
          if needed"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)

          [1661746360.321195][132620:132620] CHIP:ZCL: OpCreds: Received an AddNOC command
          [1661746360.321224][132620:132620] CHIP:EM: Sending Standalone Ack for MessageCounter:123253178 on exchange 23506r
          [1661746360.321300][132620:132620] CHIP:IN: Prepared secure message 0xffffe25a60d8 to 0xFFFFFFFB00000000 (0)  of type 0x10 and protocolId (0, 0) on exchange 23506r with MessageCounter:155549632.
          [1661746360.321343][132620:132620] CHIP:IN: Sending encrypted msg 0xffffe25a60d8 with MessageCounter:155549632 to 0xFFFFFFFB00000000 (0) at monotonic time: 000000000F107480 msec
          [1661746360.321478][132620:132620] CHIP:EM: Flushed pending ack for MessageCounter:123253178 on exchange 23506r
          [1661746360.321713][132620:132620] CHIP:FP: Validating NOC chain
          [1661746360.322745][132620:132620] CHIP:FP: NOC chain validation successful
      disabled: true

    - label:
          "Step 9: Commissioner configures operational network on TH if TH both
          supports and requires"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
          [1660151567834] [99153:10411339] CHIP: [CTL] Received certificate signing request from the device
          [1660151567834] [99153:10411339] CHIP: [CTL] Successfully finished commissioning step 'SendOpCertSigningRequest'
      disabled: true

    - label:
          "Step 10: Commissioner instructs Commissionee to connect to
          operational network if not already connected"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
          [1660152735.835717][648909:648909] CHIP:ZCL: OpCreds: successfully created fabric index 0x1 via AddNOC
      disabled: true

    - label:
          "Step 11: Commissioner starts discovery of TH using Operational
          Discovery"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
          [1660152735.835315][648909:648909] CHIP:DIS: Broadcasting mDns reply for query from fe80::808c:7ff:fefd:3b1
          [1660152735.835522][648909:648909] CHIP:DIS: mDNS service published: _matter._tcp
          [1660152735.835565][648909:648909] CHIP:DMG: Endpoint 0, Cluster 0x0000_003E update version to 553aae1
          [1660152735.835594][648909:648909] CHIP:DMG: Endpoint 0, Cluster 0x0000_003E update version to 553aae2
      disabled: true

    - label:
          "Step 12: Commissioner opens a CASE session with TH over operational
          network"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)

           CASE Server enabling CASE session setups
          [1653471957.713139][10713:10713] CHIP:SVR: Joining Multicast groups
          [1653471957.713654][10713:10713] CHIP:ZCL: Emitting StartUp event
          [1653471957.714762][10713:10713] CHIP:EVL: LogEvent event number: 0x0000000000000000 priority: 2, endpoint id:  0x0 cluster id: 0x0000_0028 event id: 0x0 Sys timestamp: 0x000000000059AC88
          [1653471957.715456][10713:10713] CHIP:ZCL: GeneralDiagnosticsDelegate: OnDeviceRebooted
      disabled: true

    - label: "Step 13: Commissioner sends CommissioningComplete command"
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
          [1660154248.898113][7143:7143] CHIP:SVR: Commissioning completed successfully
      disabled: true

    - label:
          "Step 14: Commissioning channel between the Commissioner and
          Commissionee is terminated."
      verification: |
          Verify in TH (ALL-CLUSTER-APP)
          [1660154249.008047][7143:7143] CHIP:IN: Expiring all PASE sessions
          [1660154249.008069][7143:7143] CHIP:IN: SecureSession[0xaaab09155000]: MarkForEviction Type:1 LSID:5786
          [1660154249.008090][7143:7143] CHIP:SC: SecureSession[0xaaab09155000]: Moving from state 'kActive' --> 'kPendingEviction'
      disabled: true
