# 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.5.2. [TC-IDM-5.2] Status Response from DUT in response to a Timed Request
    Action from TH.

PICS:
    - MCORE.IDM.S

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

tests:
    - label:
          "Step 1: TH sends a Timed Request Message with the timeout value set.
          (Example - 200 milliseconds). +"
      verification: |
          ./chip-tool onoff on 1 1 --timedInteractionTimeoutMs 200

          Verify on TH(chip-tool) receives the StatusResponseMessage for the data sent in the above command

          [1655798564.112839][7055:7060] CHIP:DMG: StatusResponseMessage =
          [1655798564.112870][7055:7060] CHIP:DMG: {
          [1655798564.112898][7055:7060] CHIP:DMG:         Status = 0x00 (SUCCESS),
          [1655798564.112927][7055:7060] CHIP:DMG:         InteractionModelRevision = 1
          [1655798564.112954][7055:7060] CHIP:DMG: }
          [1655798564.112983][7055:7060] CHIP:IM: Received status response, status is 0x00 (SUCCESS)
      disabled: true

    - label:
          "Step 2: TH sends a Timed Request Message(Timed Write Transaction)
          with the timeout value set. (Example - 200 milliseconds). Wait for the
          status response message to be received. Send the Write Request Message
          to the DUT."
      verification: |
          ./chip-tool levelcontrol write on-level 1 1 1 --timedInteractionTimeoutMs 500

          Verify on TH(chip-tool) receives the WriteResponseMessage for the data sent in the above command

          [1655798786.131890][7065:7070] CHIP:DMG: WriteResponseMessage =
          [1655798786.131932][7065:7070] CHIP:DMG: {
          [1655798786.131984][7065:7070] CHIP:DMG:         AttributeStatusIBs =
          [1655798786.132035][7065:7070] CHIP:DMG:         [
          [1655798786.132089][7065:7070] CHIP:DMG:                 AttributeStatusIB =
          [1655798786.132142][7065:7070] CHIP:DMG:                 {
          [1655798786.132246][7065:7070] CHIP:DMG:                         AttributePathIB =
          [1655798786.132311][7065:7070] CHIP:DMG:                         {
          [1655798786.132377][7065:7070] CHIP:DMG:                                 Endpoint = 0x1,
          [1655798786.132439][7065:7070] CHIP:DMG:                                 Cluster = 0x8,
          [1655798786.132512][7065:7070] CHIP:DMG:                                 Attribute = 0x0000_0011,
          [1655798786.132578][7065:7070] CHIP:DMG:                         }
          [1655798786.132635][7065:7070] CHIP:DMG:
          [1655798786.132704][7065:7070] CHIP:DMG:                         StatusIB =
          [1655798786.132770][7065:7070] CHIP:DMG:                         {
          [1655798786.132822][7065:7070] CHIP:DMG:                                 status = 0x00 (SUCCESS),
          [1655798786.132892][7065:7070] CHIP:DMG:                         },
          [1655798786.132960][7065:7070] CHIP:DMG:
          [1655798786.133006][7065:7070] CHIP:DMG:                 },
          [1655798786.133070][7065:7070] CHIP:DMG:
          [1655798786.133109][7065:7070] CHIP:DMG:         ],
          [1655798786.133173][7065:7070] CHIP:DMG:
          [1655798786.133213][7065:7070] CHIP:DMG:         InteractionModelRevision = 1
          [1655798786.133269][7065:7070] CHIP:DMG: }
          [1655798786.133385][7065:7070] CHIP:DMG: WriteClient moving to [AwaitingDe]


           By sending a ReadRequest that the Write action was performed correctly.

          ./chip-tool levelcontrol read on-level 1 1

          [1655799013.466144][7075:7080] CHIP:TOO: Endpoint: 1 Cluster: 0x0000_0008 Attribute 0x0000_0011 DataVersion: 737039642
          [1655799013.466237][7075:7080] CHIP:TOO:   on level: 1
          [1655799013.466336][7075:7080] CHIP:EM: Sending Standalone Ack for MessageCounter:202402347 on exchange 58038i
      disabled: true

    - label:
          "Step 3: TH sends a Timed Request Message(Timed Invoke Transaction)
          with the timeout value set. (Example - 200 milliseconds). Wait for the
          status response message to be received. Wait for 5 seconds(Timer has
          expired) and then send the Invoke Request Message to the DUT."
      verification: |
          On TH(chip-tool), Verify the DUT's response based on Matter release versions:

          For Matter release 1.4 or later, verify that the DUT responds with a status of TIMEOUT (0x94).
          For Matter release 1.3 or earlier, verify that the DUT sends back a Status response with either TIMEOUT (0x94) or UNSUPPORTED_ACCESS (0x7e).

           ./chip-tool onoff on 1 1 --repeat-delay-ms 1000  --timedInteractionTimeoutMs 500

          [1720440076.857] [11806:11808] [EM] Found matching exchange: 17395i, Delegate: 0xffff7c008198
          [1720440076.857] [11806:11808] [EM] CHIP MessageCounter:107413542 not in RetransTable on exchange 17395i
          [1720440076.858] [11806:11808] [EM] >>> [E:17395i S:706 M:204574784 (Ack:107413543)] (S) Msg RX from 1:0000000000000001 [67EF] --- Type 0001:01 (IM:StatusResponse)
          [1720440076.858] [11806:11808] [EM] Found matching exchange: 17395i, Delegate: 0xffff7c008198
          [1720440076.858] [11806:11808] [EM] Rxd Ack; Removing MessageCounter:107413543 from Retrans Table on exchange 17395i
          [1720440076.858] [11806:11808] [DMG] ICR moving to [ResponseRe]
          [1720440076.858] [11806:11808] [DMG] StatusResponseMessage =
          [1720440076.858] [11806:11808] [DMG] {
          [1720440076.858] [11806:11808] [DMG]         Status = 0x94 (TIMEOUT),
          [1720440076.858] [11806:11808] [DMG]         InteractionModelRevision = 11
          [1720440076.858] [11806:11808] [DMG] }
          [1720440076.858] [11806:11808] [IM] Received status response, status is 0x94 (TIMEOUT)
          [1720440076.858] [11806:11808] [TOO] Error: IM Error 0x00000594: General error: 0x94 (TIMEOUT)
          [1720440076.858] [11806:11808] [EM] <<< [E:17395i S:706 M:107413546 (Ack:204574784)] (S) Msg TX to 1:0000000000000001 [67EF] [UDP:[fe80::e65f:1ff:fe49:ae1a%eth0]:5540] --- Type 0001:01 (IM:StatusResponse)
      disabled: true

    - label:
          "Step 4: TH sends a Timed Request Message(Timed Write Transaction)
          with the timeout value set. (Example - 200 milliseconds). Wait for the
          status response message to be received. Wait for 5 seconds(Timer has
          expired) and then send the Write Request Message to the DUT."
      verification: |
          On TH(chip-tool), Verify the DUT's response based on Matter release versions:

          For Matter release 1.4 or later, verify that the DUT responds with a status of TIMEOUT (0x94).
          For Matter release 1.3 or earlier, verify that the DUT sends back a Status response with either TIMEOUT (0x94) or UNSUPPORTED_ACCESS (0x7e).

          ./chip-tool modeselect write on-mode 0 1 1 --repeat-delay-ms 1000 --timedInteractionTimeoutMs 500

          On TH(chip-tool), Verify we are getting status response and UNSUPPORTED_ACCESS  from DUT to TH for above command


          [1720440084.666] [11810:11812] [EM] Found matching exchange: 22607i, Delegate: 0xffff9000a040
          [1720440084.666] [11810:11812] [EM] Rxd Ack; Removing MessageCounter:200551619 from Retrans Table on exchange 22607i
          [1720440084.667] [11810:11812] [DMG] WriteClient moving to [ResponseRe]
          [1720440084.667] [11810:11812] [DMG] StatusResponseMessage =
          [1720440084.667] [11810:11812] [DMG] {
          [1720440084.667] [11810:11812] [DMG]         Status = 0x94 (TIMEOUT),
          [1720440084.667] [11810:11812] [DMG]         InteractionModelRevision = 11
          [1720440084.667] [11810:11812] [DMG] }
          [1720440084.667] [11810:11812] [IM] Received status response, status is 0x94 (TIMEOUT)
          [1720440084.667] [11810:11812] [TOO] Error: IM Error 0x00000594: General error: 0x94 (TIMEOUT)
          [1720440084.667] [11810:11812] [EM] <<< [E:22607i S:23365 M:200551622 (Ack:3244934)] (S) Msg TX to 1:0000000000000001 [67EF] [UDP:[fe80::e65f:1ff:fe49:ae1a%eth0]:5540] --- Type 0001:01 (IM:StatusResponse)
          [1720440084.668] [11810:11812] [DMG] WriteClient moving to [AwaitingDe]
      disabled: true
