# Copyright (c) 2023 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.

name:
    4.4.20. [TC-CNET-4.22] [Thread] Verification for ScanNetworks command
    [DUT-Server]

PICS:
    - CNET.S.F01

config:
    nodeId: 0x12344321
    cluster: "Network Commissioning"
    #PIXIT.CNET.ENDPOINT_THREAD
    endpoint: 0
    PIXIT.CNET.THREAD_1ST_OPERATIONALDATASET:
        type: octet_string
        defaultValue: "hex:1111111122222222"

tests:
    - label:
          "Step 1: TH sends ScanNetworks command to the DUT with the SSID field
          omitted and the Breadcrumb field set to 1"
      PICS: CNET.S.C00.Rsp && CNET.S.C01.Tx
      command: "ScanNetworks"
      arguments:
          values:
              - name: "SSID"
                value: ""
              - name: "Breadcrumb"
                value: 1
      response:
          values:
              - name: "NetworkingStatus"
                constraints:
                    anyOf: [0, 1, 5, 6, 12]
              - name: "DebugText"
                constraints:
                    maxLength: 512
              - name: "ThreadScanResults"
                constraints:
                    type: list

    - label:
          "Step 1: Verify each element in the ThreadScanResults list will have
          the following fields:"
      verification: |
          ./chip-tool networkcommissioning scan-networks 54 0 --Breadcrumb 1

          Via the TH (chip-tool), verify:
          -the NetworkingStatus value as 0 that mentions success.
          -the PanId value is in the range of 0 to 65534.
          -the ExtendedPanId value is type of uint64.
          -the NetworkName value is type of string with a size of 1 to 16 bytes.
          -the Channel is type of uint16 with range 0 to 65535.
          -the version value is type of uint8(0 to 255).
          -the ExtendedAddress is a hwaddr with a size of 8 bytes
          -the RSSI is of type int8 with a range of -120 to 0.
          -the LQI is type of uint8(0 to 255).

          [1658297246.000815][7679:7684] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0031 Command=0x0000_0001
          [1658297246.001029][7679:7684] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Command 0x0000_0001
          [1658297246.001190][7679:7684] CHIP:TOO:   ScanNetworksResponse: {
          [1658297246.001270][7679:7684] CHIP:TOO:     networkingStatus: 0
          [1658297246.001357][7679:7684] CHIP:TOO:     threadScanResults: 1 entries
          [1658297246.001485][7679:7684] CHIP:TOO:       [1]: {
          [1658297246.001548][7679:7684] CHIP:TOO:         PanId: 64206
          [1658297246.001607][7679:7684] CHIP:TOO:         ExtendedPanId: 3861484836749312
          [1658297246.001665][7679:7684] CHIP:TOO:         NetworkName: GRL
          [1658297246.001721][7679:7684] CHIP:TOO:         Channel: 11
          [1658297246.001777][7679:7684] CHIP:TOO:         Version: 4
          [1658297246.001841][7679:7684] CHIP:TOO:         ExtendedAddress: 166E0A0000000001
          [1658297246.001900][7679:7684] CHIP:TOO:         Rssi: -81
          [1658297246.001955][7679:7684] CHIP:TOO:         Lqi: 48
          [1658297246.002010][7679:7684] CHIP:TOO:        }
          [1658297246.002070][7679:7684] CHIP:TOO:    }
          [1658297246.002181][7679:7684] CHIP:DMG: ICR moving to [AwaitingDe]
          [1658297246.002298][7679:7684] CHIP:EM: Sending Standalone Ack for MessageCounter:124278362 on exchange 24525i
      cluster: "LogCommands"
      command: "UserPrompt"
      PICS: PICS_USER_PROMPT && CNET.S.C00.Rsp && CNET.S.C01.Tx
      arguments:
          values:
              - name: "message"
                value: "Please enter 'y' for success"
              - name: "expectedValue"
                value: "y"

    - label:
          "Step 2: TH reads Breadcrumb attribute from the General Commissioning
          Cluster"
      cluster: "General Commissioning"
      command: "readAttribute"
      attribute: "Breadcrumb"
      response:
          value: 1
          constraints:
              type: int64u

    - label:
          "Step 3: TH sends ScanNetworks command to the DUT with the SSID field
          set to null and the Breadcrumb field set to 2"
      PICS: CNET.S.C00.Rsp && CNET.S.C01.Tx
      command: "ScanNetworks"
      arguments:
          values:
              - name: "SSID"
                value: null
              - name: "Breadcrumb"
                value: 2
      response:
          values:
              - name: "NetworkingStatus"
                constraints:
                    anyOf: [0, 1, 5, 6, 12]
              - name: "DebugText"
                constraints:
                    maxLength: 512
              - name: "ThreadScanResults"
                constraints:
                    type: list

    - label:
          "Step 3: Verify each element in the ThreadScanResults list will have
          the following fields:"
      verification: |
          ./chip-tool networkcommissioning scan-networks 54 0 --Breadcrumb 2

          Via the TH (chip-tool), verify:
          -the NetworkingStatus value as 0 that mentions success.
          -the PanId value is in the range of 0 to 65534.
          -the ExtendedPanId value is type of uint64.
          -the NetworkName value is type of string with a size of 1 to 16 bytes.
          -the Channel is type of uint16 with range 0 to 65535.
          -the version value is type of uint8(0 to 255).
          -the ExtendedAddress is a hwaddr with a size of 8 bytes
          -the RSSI is of type int8 with a range of -120 to 0.
          -the LQI is type of uint8(0 to 255).

          [1658297283.141075][7695:7700] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0031 Command=0x0000_0001
          [1658297283.141183][7695:7700] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Command 0x0000_0001
          [1658297283.141356][7695:7700] CHIP:TOO:   ScanNetworksResponse: {
          [1658297283.141438][7695:7700] CHIP:TOO:     networkingStatus: 0
          [1658297283.141534][7695:7700] CHIP:TOO:     threadScanResults: 2 entries
          [1658297283.141663][7695:7700] CHIP:TOO:       [1]: {
          [1658297283.141729][7695:7700] CHIP:TOO:         PanId: 64206
          [1658297283.141788][7695:7700] CHIP:TOO:         ExtendedPanId: 3861484836749312
          [1658297283.141847][7695:7700] CHIP:TOO:         NetworkName: GRL
          [1658297283.141904][7695:7700] CHIP:TOO:         Channel: 11
          [1658297283.141961][7695:7700] CHIP:TOO:         Version: 4
          [1658297283.142023][7695:7700] CHIP:TOO:         ExtendedAddress: 166E0A0000000001
          [1658297283.142079][7695:7700] CHIP:TOO:         Rssi: -80
          [1658297283.142134][7695:7700] CHIP:TOO:         Lqi: 52
          [1658297283.142188][7695:7700] CHIP:TOO:        }
          [1658297283.142271][7695:7700] CHIP:TOO:       [2]: {
          [1658297283.142331][7695:7700] CHIP:TOO:         PanId: 64206
          [1658297283.142386][7695:7700] CHIP:TOO:         ExtendedPanId: 3861484836749312
          [1658297283.142443][7695:7700] CHIP:TOO:         NetworkName: GRL
          [1658297283.142500][7695:7700] CHIP:TOO:         Channel: 11
          [1658297283.142551][7695:7700] CHIP:TOO:         Version: 4
          [1658297283.142609][7695:7700] CHIP:TOO:         ExtendedAddress: 166E0A0000000001
          [1658297283.142665][7695:7700] CHIP:TOO:         Rssi: -83
          [1658297283.142718][7695:7700] CHIP:TOO:         Lqi: 44
          [1658297283.142771][7695:7700] CHIP:TOO:        }
          [1658297283.142828][7695:7700] CHIP:TOO:    }
          [1658297283.142958][7695:7700] CHIP:DMG: ICR moving to [AwaitingDe]
          [1658297283.143074][7695:7700] CHIP:EM: Sending Standalone Ack for MessageCounter:115607423 on exchange 55136i
      cluster: "LogCommands"
      command: "UserPrompt"
      PICS: PICS_USER_PROMPT && CNET.S.C00.Rsp && CNET.S.C01.Tx
      arguments:
          values:
              - name: "message"
                value: "Please enter 'y' for success"
              - name: "expectedValue"
                value: "y"

    - label:
          "Step 4: TH reads Breadcrumb attribute from the General Commissioning
          Cluster"
      cluster: "General Commissioning"
      command: "readAttribute"
      attribute: "Breadcrumb"
      response:
          value: 2
          constraints:
              type: int64u
    - label:
          "Step 5: TH sends ScanNetworks command to the DUT with the SSID field
          set to a random string of ASCII characters with a size of between 1
          and 31 characters and the Breadcrumb field set to 3"
      PICS: CNET.S.C00.Rsp && CNET.S.C01.Tx
      command: "ScanNetworks"
      arguments:
          values:
              - name: "SSID"
                value: "hex:1111111522222222"
              - name: "Breadcrumb"
                value: 3
      response:
          values:
              - name: "NetworkingStatus"
                constraints:
                    anyOf: [0, 1, 5, 6, 12]
              - name: "DebugText"
                constraints:
                    maxLength: 512
              - name: "ThreadScanResults"
                constraints:
                    type: list

    - label:
          "Step 5: Verify each element in the ThreadScanResults list will have
          the following fields:"
      verification: |
          ./chip-tool networkcommissioning scan-networks 54 0 --Breadcrumb 3

          Via the TH (chip-tool), verify:
          -the NetworkingStatus value should be as 0 that mentions success.
          -the PanId value should be with in the range of 0 to 65534.
          -the ExtendedPanId value is type of uint64.
          -the NetworkName value is type of string with a size of 1 to 16 bytes.
          -the Channel is type of uint16 with range 0 to 65535.
          -the version value is type of uint8(0 to 255).
          -the ExtendedAddress is a hwaddr with a size of 8 bytes
          -the RSSI is of type int8 with a range of -120 to 0.
          -the LQI is type of uint8(0 to 255).

          [1658297312.201709][7708:7713] CHIP:DMG: },
          [1658297312.201898][7708:7713] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0031 Command=0x0000_0001
          [1658297312.202021][7708:7713] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Command 0x0000_0001
          [1658297312.202196][7708:7713] CHIP:TOO:   ScanNetworksResponse: {
          [1658297312.202276][7708:7713] CHIP:TOO:     networkingStatus: 0
          [1658297312.202359][7708:7713] CHIP:TOO:     threadScanResults: 1 entries
          [1658297312.202481][7708:7713] CHIP:TOO:       [1]: {
          [1658297312.202544][7708:7713] CHIP:TOO:         PanId: 64206
          [1658297312.202604][7708:7713] CHIP:TOO:         ExtendedPanId: 3861484836749312
          [1658297312.202663][7708:7713] CHIP:TOO:         NetworkName: GRL
          [1658297312.202718][7708:7713] CHIP:TOO:         Channel: 11
          [1658297312.202775][7708:7713] CHIP:TOO:         Version: 4
          [1658297312.202838][7708:7713] CHIP:TOO:         ExtendedAddress: 166E0A0000000001
          [1658297312.202897][7708:7713] CHIP:TOO:         Rssi: -78
          [1658297312.202952][7708:7713] CHIP:TOO:         Lqi: 60
          [1658297312.203007][7708:7713] CHIP:TOO:        }
          [1658297312.203066][7708:7713] CHIP:TOO:    }
          [1658297312.203176][7708:7713] CHIP:DMG: ICR moving to [AwaitingDe]
          [1658297312.203284][7708:7713] CHIP:EM: Sending Standalone Ack for MessageCounter:217378941 on exchange 37389i
      cluster: "LogCommands"
      command: "UserPrompt"
      PICS: PICS_USER_PROMPT && CNET.S.C00.Rsp && CNET.S.C01.Tx
      arguments:
          values:
              - name: "message"
                value: "Please enter 'y' for success"
              - name: "expectedValue"
                value: "y"

    - label:
          "Step 6: TH reads Breadcrumb attribute from the General Commissioning
          Cluster"
      cluster: "General Commissioning"
      command: "readAttribute"
      attribute: "Breadcrumb"
      response:
          value: 3
          constraints:
              type: int64u
