File: app_config.py

package info (click to toggle)
zigpy-znp 0.13.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,120 kB
  • sloc: python: 14,459; makefile: 6
file content (218 lines) | stat: -rw-r--r-- 6,609 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
"""commands to configure parameters of the device, trust center and BDB subsystem."""

import zigpy_znp.types as t


class TimeoutIndex(t.enum8):
    Seconds_10 = 0x00

    Minutes_2 = 0x01
    Minutes_4 = 0x02
    Minutes_8 = 0x03
    Minutes_16 = 0x04
    Minutes_32 = 0x05
    Minutes_64 = 0x06
    Minutes_128 = 0x07
    Minutes_256 = 0x08
    Minutes_512 = 0x09
    Minutes_1024 = 0x0A
    Minutes_2048 = 0x0B
    Minutes_4096 = 0x0C
    Minutes_8192 = 0x0D
    Minutes_16384 = 0x0E


class CentralizedLinkKeyMode(t.enum8):
    UseDefault = 0x00
    UseProvidedInstallCode = 0x01
    UseProvidedInstallCodeAndFallbackToDefault = 0x02
    UseProvidedAPSLinkKey = 0x03
    UseProvidedAPSLinkKeyAndFallbackToDefault = 0x04


class BDBCommissioningStatus(t.enum8):
    Success = 0x00
    InProgress = 0x01
    NoNetwork = 0x02
    TLTargetFailure = 0x03
    TLNotAaCapable = 0x04
    TLNoScanResponse = 0x05
    TLNotPermitted = 0x06
    TCLKExFailure = 0x07
    FormationFailure = 0x08
    FBTargetInProgress = 0x09
    FBInitiatorInProgress = 0x0A
    FBNoIdentifyQueryResponse = 0x0B
    FBBindingTableFull = 0x0C
    NetworkRestored = 0x0D
    Failure = 0x0E


class BDBCommissioningMode(t.bitmap8):
    NONE = 0

    InitiatorTouchLink = 1 << 0
    NwkSteering = 1 << 1
    NwkFormation = 1 << 2
    FindingBinding = 1 << 3
    Touchlink = 1 << 4
    ParentLost = 1 << 5


class InstallCodeFormat(t.enum8):
    InstallCodeAndCRC = 0x01
    KeyDerivedFromInstallCode = 0x02


class AppConfig(t.CommandsBase, subsystem=t.Subsystem.APPConfig):
    # sets the network frame counter to the value specified in the Frame Counter Value.
    # For projects with multiple instances of frame counter, the message sets the
    # frame counter of the current network
    SetNwkFrameCounter = t.CommandDef(
        t.CommandType.SREQ,
        0xFF,
        req_schema=(t.Param("FrameCounterValue", t.uint32_t, "network frame counter"),),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Set the default value used by parent device to expire legacy child devices
    SetDefaultRemoteEndDeviceTimeout = t.CommandDef(
        t.CommandType.SREQ,
        0x01,
        req_schema=(
            t.Param("TimeoutIndex", TimeoutIndex, "0x00 -- 10s otherwise 2^N minutes"),
        ),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Sets in ZED the timeout value to be send to parent device for child expiring
    SetEndDeviceTimeout = t.CommandDef(
        t.CommandType.SREQ,
        0x02,
        req_schema=(
            t.Param("TimeoutIndex", TimeoutIndex, "0x00 -- 10s otherwise 2^N minutes"),
        ),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Set the AllowRejoin TC policy
    SetAllowRejoinTCPolicy = t.CommandDef(
        t.CommandType.SREQ,
        0x03,
        req_schema=(
            t.Param(
                "AllowRejoin",
                t.Bool,
                "whether or not the Trust center allows rejoins with well-known key",
            ),
        ),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Set the commissioning methods to be executed. Initialization of BDB is executed
    # with this call, regardless of its parameters
    BDBStartCommissioning = t.CommandDef(
        t.CommandType.SREQ,
        0x05,
        req_schema=(t.Param("Mode", BDBCommissioningMode, "Commissioning mode"),),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Set BDB primary or secondary channel masks
    BDBSetChannel = t.CommandDef(
        t.CommandType.SREQ,
        0x08,
        req_schema=(
            t.Param("IsPrimary", t.Bool, "True -- is primary channel"),
            t.Param("Channel", t.Channels, "Channel set mask"),
        ),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Add a preconfigured key (plain key or IC) to Trust Center device
    BDBAddInstallCode = t.CommandDef(
        t.CommandType.SREQ,
        0x04,
        req_schema=(
            t.Param(
                "InstallCodeFormat",
                InstallCodeFormat,
                ("0x01 -- Install code + CRC  0x02 -- Key derived from install code"),
            ),
            t.Param("IEEE", t.EUI64, "IEEE address of the joining device"),
            t.Param(
                "InstallCode", t.Bytes, "16 bytes for derived key, 18 for IC + CRC"
            ),
        ),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Set the policy flag on Trust Center device to mandate or not the TCLK
    # exchange procedure
    BDBSetTcRequireKeyExchange = t.CommandDef(
        t.CommandType.SREQ,
        0x09,
        req_schema=(
            t.Param("BdbTrustCenterRequireKeyExchange", t.Bool, "Require key exchange"),
        ),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Sets the policy to mandate or not the usage of an Install Code upon joining
    BDBSetJoinUsesInstallCodeKey = t.CommandDef(
        t.CommandType.SREQ,
        0x06,
        req_schema=(t.Param("BdbJoinUsesInstallCodeKey", t.Bool, "Use install code"),),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # On joining devices, set the default key or an install code to attempt
    # to join the network
    BDBSetActiveDefaultCentralizedKey = t.CommandDef(
        t.CommandType.SREQ,
        0x07,
        req_schema=(
            t.Param(
                "CentralizedLinkKeyModes",
                CentralizedLinkKeyMode,
                (
                    "which key will be used when performing association "
                    "to a centralized network"
                ),
            ),
            t.Param("InstallCode", t.Bytes, "key in any of its formats"),
        ),
        rsp_schema=t.STATUS_SCHEMA,
    )

    # Instruct the ZED to try to rejoin its previews network. Use only in ZED devices
    BDBZedAttemptRecoverNWK = t.CommandDef(
        t.CommandType.SREQ, 0x0A, req_schema=(), rsp_schema=t.STATUS_SCHEMA
    )

    # MT_APP_CONFIG Callbacks
    # Callback to receive notifications from BDB process
    BDBCommissioningNotification = t.CommandDef(
        t.CommandType.AREQ,
        0x80,
        rsp_schema=(
            t.Param(
                "Status",
                BDBCommissioningStatus,
                "Status of the commissioning mode notified",
            ),
            t.Param(
                "Mode",
                BDBCommissioningMode,
                "Commissioning mode to which status is related",
            ),
            t.Param(
                "RemainingModes",
                BDBCommissioningMode,
                (
                    "Bitmask of the remaining commissioning modes after "
                    "this notification"
                ),
            ),
        ),
    )