# 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:
    120.2.2. [TC-BIND-2.2] Binding Cluster Attributes-DUT handles its Groups
    settings [DUT-Controller]

PICS:
    - BIND.C
    - GRPKEY.C

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 controller test cases. For certification test, we expect DUT should have a capability or way to run the equivalent command.

          Take 2 raspi, 1 as Lighting app and another one as chip-tool. and use [ nRF52840-DK ]Thread device as  light-switch-app.
      disabled: true

    - label: "Pre-Conditions"
      verification: |
          TH2 supports On/Off server on Endpoint 1.
          TH2 supports Groups server on Endpoint 1.
          DUT behaves as Group Admin
          TH2 should have an ACL entry with the AuthMode as Group by DUT
          DUT supports On/Off client
      disabled: true

    - label: "Step 1: Factory Reset DUT"
      verification: |
          Vendor specific action, for chip-tool run
          rm -rf /tmp/chip*
      disabled: true

    - label: "Step 2: Commission DUT to TH1s fabric"
      verification: |
          Advertise the [ light-switch-app ] on [ nRF52840-DK ]Thread device  and  pair the TH using below cmmd.

          ./chip-tool pairing ble-thread 74 hex:0e080000000000010000000300000f35060004001fffe0020810101191022022920708fd6587bfe9821353051000112237945966880899aabbccddeeff030f7070656e5468726561644465696f6c010212340410f23d85dd55d9748cc6a1fd5fccbb1da20c0402a0fff8 20202021 3840
      disabled: true

    - label: "Step 3: TH1 enables DUT as Controller"
      verification: |

      disabled: true

    - label: "Step 4: Commission TH2 to TH1s fabric (Node ID = 2)"
      verification: |
          Advertise the [Lighting-app] on Raspi and  pair the TH using below cmmd.

          ./chip-tool pairing onnetwork 2 20202021

          On TH1(Chip-tool), Verify the success response

          [1659104612.592373][62366:62371] CHIP:DMG:         SuppressResponse = true,
          [1659104612.592399][62366:62371] CHIP:DMG:         InteractionModelRevision = 1
          [1659104612.592432][62366:62371] CHIP:DMG: }
          [1659104612.593187][62366:62371] CHIP:CTL: Successfully finished commissioning step 'ReadCommissioningInfo'
      disabled: true

    - label:
          "Step 5: DUT generates fabric-unique GroupID, GroupName, random key,
          EpochKey0 and GroupKeySetID."
      verification: |
          As Admin generates it is not necessary to verify
      disabled: true

    - label:
          "Step 6: DUT sends KeySetWrite command to GroupKeyManagement cluster
          to TH2 on Endpoint 0."
      PICS: GRPKEY.C.C00.Tx
      verification: |
          Run this command for [ nRF52840-DK ]Thread device in chip-tool:

          ./chip-tool groupkeymanagement key-set-write '{"groupKeySetID": 42,
          "groupKeySecurityPolicy": 0, "epochKey0":
          "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime0": 2220000,"epochKey1":
          "d1d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime1": 2220001,"epochKey2":
          "d2d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime2": 2220002 }' 74 0

          On TH1(Chip-tool), Verify the success response for KeySetWrite

          [1657719041.075123][4541:4546] CHIP:DMG: ICR moving to [ResponseRe]
          [1657719041.075174][4541:4546] CHIP:DMG: InvokeResponseMessage =
          [1657719041.075200][4541:4546] CHIP:DMG: {
          [1657719041.075224][4541:4546] CHIP:DMG:         suppressResponse = false,
          [1657719041.075255][4541:4546] CHIP:DMG:         InvokeResponseIBs =
          [1657719041.075287][4541:4546] CHIP:DMG:         [
          [1657719041.075311][4541:4546] CHIP:DMG:                 InvokeResponseIB =
          [1657719041.075347][4541:4546] CHIP:DMG:                 {
          [1657719041.075376][4541:4546] CHIP:DMG:                         CommandStatusIB =
          [1657719041.075408][4541:4546] CHIP:DMG:                         {
          [1657719041.075439][4541:4546] CHIP:DMG:                                 CommandPathIB =
          [1657719041.075473][4541:4546] CHIP:DMG:                                 {
          [1657719041.075507][4541:4546] CHIP:DMG:                                         EndpointId = 0x0,
          [1657719041.075542][4541:4546] CHIP:DMG:                                         ClusterId = 0x3f,
          [1657719041.075577][4541:4546] CHIP:DMG:                                         CommandId = 0x0,
          [1657719041.075609][4541:4546] CHIP:DMG:                                 },
          [1657719041.075646][4541:4546] CHIP:DMG:
          [1657719041.075676][4541:4546] CHIP:DMG:                                 StatusIB =
          [1657719041.075709][4541:4546] CHIP:DMG:                                 {
          [1657719041.075743][4541:4546] CHIP:DMG:                                         status = 0x00 (SUCCESS),
          [1657719041.075775][4541:4546] CHIP:DMG:                                 },
          [1657719041.075809][4541:4546] CHIP:DMG:
          [1657719041.075840][4541:4546] CHIP:DMG:                         },
          [1657719041.075874][4541:4546] CHIP:DMG:
          [1657719041.075902][4541:4546] CHIP:DMG:                 },
          [1657719041.075935][4541:4546] CHIP:DMG:
          [1657719041.075959][4541:4546] CHIP:DMG:         ],
          [1657719041.075988][4541:4546] CHIP:DMG:
          [1657719041.076012][4541:4546] CHIP:DMG:         InteractionModelRevision = 1


          Run this command for lighting app in chip-tool:

          ./chip-tool groupkeymanagement key-set-write '{"groupKeySetID": 42,
          "groupKeySecurityPolicy": 0, "epochKey0":
          "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime0": 2220000,"epochKey1":
          "d1d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime1": 2220001,"epochKey2":
          "d2d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime2": 2220002 }' 2 0

          On TH1(Chip-tool), Verify the success response for KeySetWrite

          [1657717291.809861][3361:3366] CHIP:DMG: ICR moving to [ResponseRe]
          [1657717291.809913][3361:3366] CHIP:DMG: InvokeResponseMessage =
          [1657717291.809939][3361:3366] CHIP:DMG: {
          [1657717291.809965][3361:3366] CHIP:DMG:         suppressResponse = false,
          [1657717291.809992][3361:3366] CHIP:DMG:         InvokeResponseIBs =
          [1657717291.810025][3361:3366] CHIP:DMG:         [
          [1657717291.810051][3361:3366] CHIP:DMG:                 InvokeResponseIB =
          [1657717291.810088][3361:3366] CHIP:DMG:                 {
          [1657717291.810115][3361:3366] CHIP:DMG:                         CommandStatusIB =
          [1657717291.810149][3361:3366] CHIP:DMG:                         {
          [1657717291.810179][3361:3366] CHIP:DMG:                                 CommandPathIB =
          [1657717291.810215][3361:3366] CHIP:DMG:                                 {
          [1657717291.810252][3361:3366] CHIP:DMG:                                         EndpointId = 0x0,
          [1657717291.810290][3361:3366] CHIP:DMG:                                         ClusterId = 0x3f,
          [1657717291.810326][3361:3366] CHIP:DMG:                                         CommandId = 0x0,
          [1657717291.810364][3361:3366] CHIP:DMG:                                 },
          [1657717291.810403][3361:3366] CHIP:DMG:
          [1657717291.810435][3361:3366] CHIP:DMG:                                 StatusIB =
          [1657717291.810470][3361:3366] CHIP:DMG:                                 {
          [1657717291.810507][3361:3366] CHIP:DMG:                                         status = 0x00 (SUCCESS),
          [1657717291.810540][3361:3366] CHIP:DMG:                                 },
          [1657717291.810575][3361:3366] CHIP:DMG:
          [1657717291.810606][3361:3366] CHIP:DMG:                         },
          [1657717291.810641][3361:3366] CHIP:DMG:
          [1657717291.810668][3361:3366] CHIP:DMG:                 },
          [1657717291.810700][3361:3366] CHIP:DMG:
          [1657717291.810725][3361:3366] CHIP:DMG:         ],
          [1657717291.810757][3361:3366] CHIP:DMG:
          [1657717291.810782][3361:3366] CHIP:DMG:         InteractionModelRevision = 1
          [1657717291.810807][3361:3366] CHIP:DMG: },
          [1657717291.810869][3361:3366] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_003F Command=0x0000_0000 Status=0x0
      disabled: true

    - label:
          "Step 7: DUT binds GroupId with GroupKeySetID in the GroupKeyMap
          attribute list on GroupKeyManagement cluster to TH2 on Endpoint 0"
      PICS: GRPKEY.C.A0000
      verification: |
          Run this cmmd for [ nRF52840-DK ]Thread device in chip-tool:

          ./chip-tool groupkeymanagement write group-key-map '[{"groupId": 1, "groupKeySetID": 42, "fabricIndex": 1}]' 74 0

          On TH1(Chip-tool), Verify the success response for GroupKeySetID

          [1657719130.464175][4557:4562] CHIP:DMG:                         StatusIB =
          [1657719130.464214][4557:4562] CHIP:DMG:                         {
          [1657719130.464256][4557:4562] CHIP:DMG:                                 status = 0x00 (SUCCESS),
          [1657719130.464298][4557:4562] CHIP:DMG:                         },
          [1657719130.464342][4557:4562] CHIP:DMG:


          Run this cmmd for lighting app in chip-tool:

          ./chip-tool groupkeymanagement write group-key-map '[{"groupId": 1, "groupKeySetID": 42, "fabricIndex": 1}]' 2 0

          On TH1(Chip-tool), Verify the success response for GroupKeySetID

          StatusIB =
                          {
                                  status = 0x00 (SUCCESS),
                  }
      disabled: true

    - label:
          "Step 8: DUT sends AddGroup( Group Name and Group-ID) Command to TH2
          on Endpoint 1."
      PICS: G.C.C00.Tx
      verification: |
          Run this command for [ nRF52840-DK ]Thread device in chip-tool:

          ./chip-tool groups add-group 0x0001 grp1 74 1

          Verify the SUCCESS status response On TH1(Chip-tool) log and below is the sample log provided for the raspi platform

          [1657719097.788236][4548:4554] CHIP:TOO: Endpoint: 1 Cluster: 0x0000_0004 Command 0x0000_0000
          [1657719097.788325][4548:4554] CHIP:TOO:   AddGroupResponse: {
          [1657719097.788366][4548:4554] CHIP:TOO:     status: 0
          [1657719097.788393][4548:4554] CHIP:TOO:     groupId: 1
          [1657719097.788418][4548:4554] CHIP:TOO:    }

          Run this command for lighting app in chip-tool:

          ./chip-tool groups add-group 0x0001 grp1 2 1

          On TH1(chip-tool), Verify the success response for AddGroup

          [1657717342.599740][3368:3373] CHIP:TOO: Endpoint: 1 Cluster: 0x0000_0004 Command 0x0000_0000
          [1657717342.599891][3368:3373] CHIP:TOO:   AddGroupResponse: {
          [1657717342.599959][3368:3373] CHIP:TOO:     status: 0
          [1657717342.600007][3368:3373] CHIP:TOO:     groupId: 1
          [1657717342.600054][3368:3373] CHIP:TOO:    }
          [1657717342.600130][3368:3373] CHIP:DMG: ICR moving

          Run this commands for both Ligh-switch-app and Lighting-app:

          ./chip-tool groupsettings add-group grp1 0x0001

          ./chip-tool groupsettings add-keysets 0x0042 0 0x000000000021dfe0 hex:d0d1d2d3d4d5d6d7d8d9dadbdcdddedf

          ./chip-tool groupsettings bind-keyset 0x0001 0x0042

          ./chip-tool groupsettings show-groups

            +-------------------------------------------------------------------------------------+
            | Available Groups :                                                                  |
            +-------------------------------------------------------------------------------------+
            | Group Id   |  KeySet Id     |   Group Name                                          |
            | 0x101           0x1a1            Group #1                                           |
            | 0x102           0x1a2            Group #2                                           |
            | 0x1               0x42              grp1                                                   |
            +-------------------------------------------------------------------------------------+"
      disabled: true

    - label:
          "Step 9: TH1 writes Binding entry into DUT with Entry 1: Group = The
          Group ID in the AddGroup command sent from DUT to TH2"
      verification: |
          Before write the binding entries run the ACL Commands:

          Run this commandd for [ nRF52840-DK ]Thread device in chip-tool:

          ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null },{"fabricIndex": 1, "privilege": 4, "authMode": 3, "subjects": [1], "targets": null }]' 74 0

          Verify the SUCCESS status response On TH1(Chip-tool) log and below is the sample log provided for the raspi platform

          [1659075680.943991][2687:2692] CHIP:DMG:                         StatusIB =
          [1659075680.944052][2687:2692] CHIP:DMG:                         {
          [1659075680.944116][2687:2692] CHIP:DMG:                                 status = 0x00 (SUCCESS),

          Run this commandd for lighting app in chip-tool:

          ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null },{"fabricIndex": 1, "privilege": 4, "authMode": 3, "subjects": [1], "targets": null }]' 2 0

          Verify the SUCCESS status response On TH1(Chip-tool) log and below is the sample log provided for the raspi platform

          [1659075680.943991][2687:2692] CHIP:DMG:                         StatusIB =
          [1659075680.944052][2687:2692] CHIP:DMG:                         {
          [1659075680.944116][2687:2692] CHIP:DMG:                                 status = 0x00 (SUCCESS),

          Run this command for [ nRF52840-DK ]Thread device in chip-tool:

          ./chip-tool binding write binding '[{"group" : "0x0001"}]' 74 1

          Verify the SUCCESS status response On TH1(Chip-tool) log and below is the sample log provided for the raspi platform

          [1657717436.184899][4353:4358] CHIP:DMG:                         StatusIB =
          [1657717436.184940][4353:4358] CHIP:DMG:                         {
          [1657717436.184981][4353:4358] CHIP:DMG:                                 status = 0x00 (SUCCESS),
          [1657717436.185022][4353:4358] CHIP:DMG:                         },
          [1657717436.185062][4353:4358] CHIP:DMG:
      disabled: true

    - label:
          "Step 10a: DUT is triggered to send Multicast message On command to
          its binding entries"
      PICS: OO.C.C01.Tx
      verification: |
          Press button no.2 on [ nRF52840-DK ]thread board
      disabled: true

    - label: "Step 10b: TH1 reads OnOff attribute from TH2 (Endpoint 1)"
      PICS: OO.C.C01.Tx
      verification: |
          Run this cmmd for lighting app in chip-tool:

          ./chip-tool onoff read on-off 2 1

          On TH1 (Chip-tool) log, Verify that OnOff value is set to ON(TRUE) and below is the sample log provided for the raspi platform

          [1657717900.832851][4381:4386] CHIP:TOO: Endpoint: 1 Cluster: 0x0000_0006 Attribute 0x0000_0000 DataVersion: 1558029216
          [1657717900.832890][4381:4386] CHIP:TOO:   OnOff: TRUE
      disabled: true

    - label: "Step 11: TH1 removes all the binding entries from DUT"
      verification: |
          Run this command for [ nRF52840-DK ]Thread device in chip-tool:

          ./chip-tool binding write binding '[]' 74 1

          Verify the SUCCESS status response On TH1(Chip-tool) log and below is the sample log provided for the raspi platform

          [1659362827.431927][2469:2475] CHIP:DMG:                         StatusIB =
          [1659362827.431996][2469:2475] CHIP:DMG:                         {
          [1659362827.432070][2469:2475] CHIP:DMG:                                 status = 0x00 (SUCCESS),
          [1659362827.432154][2469:2475] CHIP:DMG:                         },
      disabled: true

    - label:
          "Step 12a: DUT is triggered to send Multicast message off command to
          its binding entries"
      PICS: OO.C.C00.Tx
      verification: |
          Press button no.2 on [ nRF52840-DK ] thread board
      disabled: true

    - label: "Step 12b: TH1 reads OnOff attribute from TH2 (Endpoint 1)"
      PICS: OO.C.C01.Tx
      verification: |
          Run this command for lighting app in chip-tool:

          ./chip-tool onoff read on-off 2 1

          On TH1 (Chip-tool) log, Verify that OnOff value is set to ON(TRUE) and below is the sample log provided for the raspi platform

          [1657718251.169765][4425:4431] CHIP:TOO: Endpoint: 1 Cluster: 0x0000_0006 Attribute 0x0000_0000 DataVersion: 1558029223
          [1657718251.169817][4425:4431] CHIP:TOO:   OnOff: TRUE
      disabled: true
