# 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.11. [TC-DD-3.11] Commissioning Flow = 0 (Standard Flow) - QR Code [DUT -
    Commissioner]

PICS:
    - MCORE.ROLE.COMMISSIONER
    - MCORE.DD.QR_COMMISSIONING
    - MCORE.DD.STANDARD_COMM_FLOW

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 - DUT is on an operational network and has accurate date, time, timezone, regulatory, and fabric information available.

          2 - QR Code is printed on the Commissionee device or in additional provided materials (ex: manual, companion app, web service).

          An example onboarding QR code could be "MT:-24J029Q00KA0648G00" (following 5.1.3 "QR Code", Table 34 "Packed Binary Data Structure for Onboarding Payload") which includes:

          - 3-bit Version String=000

          - 16-bit Vendor ID=0xFFF1 (as defined in section 2.5.2. "Vendor Identifier")

          - 16-bit Product ID=0x8001 (as defined in section 2.5.3. "Product Identifier")

          - 2-bit Custom Flow=10 (Custom Commissioning Flow = 2)

          - 8-bit Discovery Capabilities Bitmask=00000100 (OnNetwork)

          - 12-bit Discriminator=0xF00

          - 27-bit Passcode=20202021

          - 4-bit Padding=0000

          - no variable-length TLV Data included (as defined in section 5.1.3.1. "Payload", subsection "TLV Data")
      disabled: true

    - label:
          "Step 1a: Standard Commissioning Flow: Use a Commissionee with a QR
          code that has the Custom Flow field set to 0 and supports BLE for its
          Discovery Capability. Ensure the Version bit string follows the
          current Matter spec. documentation."
      PICS: MCORE.DD.DISCOVERY_BLE
      verification: |
          Verifiy on TH(ALL-CLUSTER-APP):

           ./chip-all-clusters-app --capabilities 2 --ble-device 1
          ...
          [1667888323.966941][3151:3151] CHIP:DL: Device Configuration:
          [1667888323.967057][3151:3151] CHIP:DL:   Serial Number: TEST_SN
          [1667888323.967179][3151:3151] CHIP:DL:   Vendor Id: 65521 (0xFFF1)
          [1667888323.967270][3151:3151] CHIP:DL:   Product Id: 32769 (0x8001)
          [1667888323.967351][3151:3151] CHIP:DL:   Hardware Version: 0
          [1667888323.967409][3151:3151] CHIP:DL:   Setup Pin Code (0 for UNKNOWN/ERROR): 20202021
          [1667888323.967489][3151:3151] CHIP:DL:   Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3840 (0xF00)
          [1667888323.967566][3151:3151] CHIP:DL:   Manufacturing Date: (not set)
          [1667888323.967616][3151:3151] CHIP:DL:   Device Type: 65535 (0xFFFF)
          [1667888323.967720][3151:3151] CHIP:SVR: SetupQRCode: [MT:-24J042C00KA0648G00]
          [1667888323.967788][3151:3151] CHIP:SVR: Copy/paste the below URL in a browser to see the QR Code:
          [1667888323.967841][3151:3151] CHIP:SVR: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J042C00KA0648G00
          [1667888323.967940][3151:3151] CHIP:SVR: Manual pairing code: [34970112332]
          [1667888323.968031][3151:3151] CHIP:DMG: Endpoint 0, Cluster 0x0000_001D update version to ea7ea7b8
      disabled: true

    - label: "Step 1b: Scan the QR code from the previous step using the DUT."
      PICS: MCORE.DD.SCAN_QR_CODE
      verification: |
          1. Verify the QR code is scanned by DUT.
          Note: chip-tool does not support physically scanning QR codes
      disabled: true

    - label:
          "Step 1c: Using the DUT, parse the THs QR code and follow any steps
          needed for the Commissioner/Commissionee to complete the commissioning
          process using BLE"
      PICS: MCORE.DD.DISCOVERY_BLE
      verification: |
          Verify on the DUT (CHIP-TOOL):
           ./chip-tool pairing code 1  MT:-24J0YXE00KA0648G00

          [1657232374820] [31379:16804218] CHIP: [CTL] Received CommissioningComplete response, errorCode=0
          [1657232374820] [31379:16804218] CHIP: [CTL] Successfully finished commissioning step 'SendComplete'
          [1657232374820] [31379:16804218] CHIP: [CTL] Commissioning stage next step: 'SendComplete' -> 'Cleanup'
          [1657232374820] [31379:16804218] CHIP: [CTL] Performing next commissioning step 'Cleanup'
          [1657232374820] [31379:16804218] CHIP: [CTL] Successfully finished commissioning step 'Cleanup'
          [1657232374820] [31379:16804218] CHIP: [TOO] Device commissioning completed with success

          Verifiy on TH(ALL-CLUSTER-APP):

          [1657232374.956508][370357:370357] CHIP:DL: HandlePlatformSpecificBLEEvent 32784
          [1657232374.956534][370357:370357] CHIP:SVR: Commissioning completed successfully
          [1657232374.956577][370357:370357] CHIP:DIS: Updating services using commissioning mode 0
      disabled: true

    - label:
          "Step 2a: Standard Commissioning Flow: Use a Commissionee with a QR
          code that has the Custom Flow field set to 0, supports IP Network for
          its Discovery Capability and is already on the same IP network as the
          DUT commissioner. Ensure the Version bit string follows the current
          Matter spec. documentation."
      PICS: MCORE.DD.DISCOVERY_IP
      verification: |
          ./chip-all-clusters-app --custom-flow 0 --capabilities 4

          Verifiy on TH(ALL-CLUSTER-APP):
          [1651105420.610637][27312:27312] CHIP:DL: Device Configuration:
          [1651105420.610695][27312:27312] CHIP:DL:   Serial Number: TEST_SN
          [1651105420.610727][27312:27312] CHIP:DL:   Vendor Id: 65521 (0xFFF1)
          [1651105420.610761][27312:27312] CHIP:DL:   Product Id: 32769 (0x8001)
          [1651105420.610792][27312:27312] CHIP:DL:   Hardware Version: 0
          [1651105420.610815][27312:27312] CHIP:DL:   Setup Pin Code (0 for UNKNOWN/ERROR): 20202021
          [1651105420.610836][27312:27312] CHIP:DL:   Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3840 (0xF00)
          [1651105420.610864][27312:27312] CHIP:DL:   Manufacturing Date: (not set)
          [1651105420.610886][27312:27312] CHIP:DL:   Device Type: 65535 (0xFFFF)
          [1651105420.610907][27312:27312] CHIP:-: ==== Onboarding payload for Standard Commissioning Flow ====
          [1651105420.610962][27312:27312] CHIP:SVR: SetupQRCode: [MT:-24J0AFN00KA0648G00]
      disabled: true

    - label: "Step 2b: Scan the QR code from the previous step using the DUT."
      PICS: MCORE.DD.SCAN_QR_CODE
      verification: |
          1. Verify the QR code is scanned by DUT

           Note: chip-tool does not support physically scanning QR codes
      disabled: true

    - label:
          "Step 2c: Using the DUT, parse the THs QR code and follow any steps
          needed for the Commissioner/Commissionee to complete the commissioning
          process using IP Network"
      PICS: MCORE.DD.DISCOVERY_IP
      verification: |
          Verify on the DUT (CHIP-TOOL):
           ./chip-tool pairing code 1 MT:-24J0AFN00KA0648G00

          [1651105530854] [95067:65607294] CHIP: [CTL] Received CommissioningComplete response
          [1651105530854] [95067:65607294] CHIP: [CTL] Successfully finished commissioning step 'SendComplete'
          [1651105530854] [95067:65607294] CHIP: [CTL] Commissioning stage next step: 'SendComplete' -> 'Cleanup'
          [1651105530854] [95067:65607294] CHIP: [CTL] Performing next commissioning step 'Cleanup'
          [1651105530854] [95067:65607294] CHIP: [CTL] Successfully finished commissioning step 'Cleanup'
          [1651105530854] [95067:65607294] CHIP: [TOO] Device commissioning completed with success

          Verifiy on TH(ALL-CLUSTER-APP):

          [1651105530.973166][27371:27371] CHIP:SVR: Commissioning completed successfully
          [1651105530.973215][27371:27371] CHIP:DIS: Updating services using commissioning mode 0
      disabled: true

    - label: "Step 2d: Scan the QR code from the previous step using the DUT."
      PICS: MCORE.DD.DISCOVERY_PAF
      verification: |
          1. User has a QR code to pass into DUT

          # ./chip-all-clusters-app --wifi --wifipaf --custom-flow 0 --capabilities 8
          [1719392550.248867][1563:1563] CHIP:SVR: SetupQRCode: [MT:-24J0M3810KA0648G00]
          [1719392550.248883][1563:1563] CHIP:SVR: Copy/paste the below URL in a browser to see the QR Code:
          [1719392550.248892][1563:1563] CHIP:SVR: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J0M3810KA0648G00
          [1719392550.248911][1563:1563] CHIP:SVR: Manual pairing code: [34970112332]
      disabled: true

    - label: "Step 2e: Verify the QR code has been scanned successfully."
      PICS: MCORE.DD.SCAN_QR_CODE
      verification: |
          1. Verify the QR code has been scanned successfully.

          $ sudo ./chip-tool payload parse-setup-payload MT:-24J0M3810KA0648G00
          [1719392883.120482][28468:28468] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_tool_kvs
          [1719392883.120687][28468:28468] CHIP:SPL: Parsing base38Representation: MT:-24J0M3810KA0648G00
          [1719392883.120839][28468:28468] CHIP:SPL: Version: 0
          [1719392883.120859][28468:28468] CHIP:SPL: VendorID: 65521
          [1719392883.120874][28468:28468] CHIP:SPL: ProductID: 32769
          [1719392883.120890][28468:28468] CHIP:SPL: Custom flow: 0 (STANDARD)
          [1719392883.120910][28468:28468] CHIP:SPL: Discovery Bitmask: 0x08 (Wi-Fi PAF)
          [1719392883.120928][28468:28468] CHIP:SPL: Long discriminator: 3840 (0xf00)
          [1719392883.120944][28468:28468] CHIP:SPL: Passcode: 20202021
      disabled: true

    - label:
          "Step 2f: Using the DUT, parse the TH’s QR code and follow any steps
          needed for the Commissioner/Commissionee to complete the commissioning
          process using Wi-Fi PAF"
      PICS: MCORE.DD.DISCOVERY_PAF
      verification: |
          1. DUT parses QR code and DUT commissions TH to the Matter network

          $ sudo ./chip-tool pairing code-wifi 1 n_m_2g nxp12345 MT:-24J0M3810KA0648G00
      disabled: true

    - label:
          "Step 3a: Standard Commissioning Flow: Use a Commissionee with a QR
          code that has the Custom Flow field set to 0 and supports SoftAP for
          its Discovery Capability. Ensure the Version bit string follows the
          current Matter spec. documentation."
      PICS: MCORE.DD.DISCOVERY_SOFTAP
      verification: |
          Out of Scope
          SoftAP commissioning not currently supported
      disabled: true

    - label: "Step 3b: Scan the QR code from the previous step using the DUT."
      PICS: MCORE.DD.SCAN_QR_CODE
      verification: |
          Out of Scope
          SoftAP commissioning not currently supported
          1. Verify the QR code is scanned by DUT, chip-tool does not support physically scanning QR codes
      disabled: true

    - label:
          "Step 3c: Using the DUT, parse the THs QR code and follow any steps
          needed for the Commissioner/Commissionee to complete the commissioning
          process using SoftAP"
      PICS: MCORE.DD.DISCOVERY_SOFTAP
      verification: |
          Out of Scope
          SoftAP commissioning not currently supported
      disabled: true
