# 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.1.9. [TC-DD-1.9] Manual Pairing Code Payload Verification [DUT -
    Commissioner]

PICS:
    - MCORE.ROLE.COMMISSIONER
    - MCORE.DD.MANUAL_PC_COMMISSIONING

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: |
          Manual Pairing Code is printed on the Commissionee device or in additional provided materials (ex: manual, companion app, web service).
      disabled: true

    - label:
          "Step 1: Provide the 11-digit/21-digit Manual Pairing Code from the TH
          Device in text, speech or any format supported by DUT"
      verification: |
          1. Launch all-clusters-app on the raspi , get the Manual Pairing code from the log

          ./chip-all-clusters-app --wifi

          [13293:13293] CHIP:DL: Device Configuration:
          [1653306603.740569][13293:13293] CHIP:DL:   Serial Number: TEST_SN
          [1653306603.740607][13293:13293] CHIP:DL:   Vendor Id: 65521 (0xFFF1)
          [1653306603.740644][13293:13293] CHIP:DL:   Product Id: 32769 (0x8001)
          [1653306603.740676][13293:13293] CHIP:DL:   Hardware Version: 0
          [1653306603.740700][13293:13293] CHIP:DL:   Setup Pin Code (0 for UNKNOWN/ERROR): 20202021
          [1653306603.740722][13293:13293] CHIP:DL:   Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3840 (0xF00)
          [1653306603.740752][13293:13293] CHIP:DL:   Manufacturing Date: (not set)
          [1653306603.740777][13293:13293] CHIP:DL:   Device Type: 65535 (0xFFFF)
          [1653306603.740798][13293:13293] CHIP:-: ==== Onboarding payload for Standard Commissioning Flow ====
          [1653306603.740846][13293:13293] CHIP:SVR: SetupQRCode: [MT:-24J042C00KA0648G00]
          [1653306603.740877][13293:13293] CHIP:SVR: Copy/paste the below URL in a browser to see the QR Code:
          [1653306603.740898][13293:13293] CHIP:SVR: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J042C00KA0648G00
          [1653306603.740929][13293:13293] CHIP:SVR: Manual pairing code: [34970112332]
          [1653306603.740951][13293:13293] CHIP:-: ==== Onboarding payload for Custom Commissioning Flows ====
          [1653306603.741000][13293:13293] CHIP:SVR: SetupQRCode: [MT:-24J0YXE00KA0648G00]
          [1653306603.741028][13293:13293] CHIP:SVR: Copy/paste the below URL in a browser to see the QR Code:
          [1653306603.741049][13293:13293] CHIP:SVR: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J0YXE00KA0648G00
          [1653306603.741081][13293:13293] CHIP:SVR: Manual pairing code: [749701123365521327694]


          2. Parse 11-digit Manual Pairing code
           ./chip-tool payload parse-setup-payload 34970112332

          Verify in DUT(CHIP-TOOL)
          [1667811737.160767][10335:10335] CHIP:SPL: Parsing decimalRepresentation: 34970112332
          [1667811737.161131][10335:10335] CHIP:SPL: Version:             0
          [1667811737.161191][10335:10335] CHIP:SPL: VendorID:            0
          [1667811737.161234][10335:10335] CHIP:SPL: ProductID:           0
          [1667811737.161286][10335:10335] CHIP:SPL: Custom flow:         0    (STANDARD)
          [1667811737.161338][10335:10335] CHIP:SPL: Discovery Bitmask:   UNKNOWN
          [1667811737.161389][10335:10335] CHIP:SPL: Short discriminator: 15   (0xf)
          [1667811737.161440][10335:10335] CHIP:SPL: Passcode:            20202021


          3. Parse 21-digit Manual Pairing code
           ./chip-tool payload parse-setup-payload 749701123365521327694

          Verify in DUT as commissoiner side:
          CHIP:SPL: Parsing decimalRepresentation: 749701123365521327694
          CHIP:SPL: CommissioningFlow: 2
          CHIP:SPL: VendorID: 65521
          CHIP:SPL: Version: 0
          CHIP:SPL: ProductID: 32769
          CHIP:SPL: Discriminator: 3840
          CHIP:SPL: SetUpPINCode: 20202021
          CHIP:SPL: RendezvousInformation: 0

          4. Parse payload by commissioning the TH
          ./chip-tool pairing code 1 34970112332

          Verify in DUT(CHIP-TOOL)
          [1653556303.582797][4071:4076] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0030 Command=0x0000_0005
          [1653556303.582850][4071:4076] CHIP:CTL: Received CommissioningComplete response, errorCode=0
          [1653556303.582891][4071:4076] CHIP:CTL: Successfully finished commissioning step 'SendComplete'
          [1653556303.582927][4071:4076] CHIP:CTL: Commissioning stage next step: 'SendComplete' -> 'Cleanup'
          [1653556303.582964][4071:4076] CHIP:CTL: Performing next commissioning step 'Cleanup'
          [1653556303.583040][4071:4076] CHIP:CTL: Successfully finished commissioning step 'Cleanup'
          [1653556303.583110][4071:4076] CHIP:TOO: Device commissioning completed with success
          [1653556303.583209][4071:4076] CHIP:DMG: ICR moving to [AwaitingDe]
          [1653556303.583255][4071:4076] CHIP:EM: Sending Standalone Ack for MessageCounter:9735725 on exchange 24476i
      disabled: true
