-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathzstack.h
More file actions
392 lines (326 loc) · 9.87 KB
/
Copy pathzstack.h
File metadata and controls
392 lines (326 loc) · 9.87 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#ifndef ZSTACK_H
#define ZSTACK_H
#define ZSTACK_SKIP_BOOTLOADER 0xEF
#define ZSTACK_PACKET_FLAG 0xFE
#define ZSTACK_NVSYS_ZSTACK 0x01
#define ZSTACK_REQUEST_TIMEOUT 10000
#define ZSTACK_READ_NIB_RETRY_INTERVAL 3000
#define ZSTACK_READ_NIB_RETRIES 10
#define ZSTACK_NWKKEY_UNALIGNED_LENGTH 21
#define ZSTACK_NIB_LENGTH 116
#define ZSTACK_NOT_STARTED_AUTOMATICALLY 0x00
#define ZSTACK_COORDINATOR_STARTED 0x09
#define ZSTACK_AF_ACK_REQUEST 0x10
#define ZSTACK_AF_DISCV_ROUTE 0x20
#define ZSTACK_AF_DEFAULT_RADIUS 0x0F
#define ZSTACK_SYS_VERSION 0x2102
#define ZSTACK_SYS_OSAL_NV_ITEM_INIT 0x2107
#define ZSTACK_SYS_OSAL_NV_READ 0x2108
#define ZSTACK_SYS_OSAL_NV_WRITE 0x2109
#define ZSTACK_SYS_OSAL_NV_LENGTH 0x2113
#define ZSTACK_SYS_SET_TX_POWER 0x2114
#define ZSTACK_SYS_OSAL_NV_READ_EXT 0x211C
#define ZSTACK_SYS_NV_LENGTH 0x2132
#define ZSTACK_SYS_NV_READ 0x2133
#define ZSTACK_SYS_NV_WRITE 0x2134
#define ZSTACK_AF_REGISTER 0x2400
#define ZSTACK_AF_DATA_REQUEST 0x2401
#define ZSTACK_AF_DATA_REQUEST_EXT 0x2402
#define ZSTACK_AF_INTER_PAN_CTL 0x2410
#define ZSTACK_ZDO_MGMT_PERMIT_JOIN_REQ 0x2536
#define ZSTACK_ZDO_MSG_CB_REGISTER 0x253E
#define ZSTACK_ZDO_STARTUP_FROM_APP 0x2540
#define ZSTACK_ZB_READ_CONFIGURATION 0x2604
#define ZSTACK_ZB_WRITE_CONFIGURATION 0x2605
#define ZSTACK_UTIL_GET_DEVICE_INFO 0x2700
#define ZSTACK_APP_CNF_BDB_SET_CHANNEL 0x2F08
#define ZSTACK_SYS_RESET_REQ 0x4100
#define ZSTACK_SYS_RESET_IND 0x4180
#define ZSTACK_AF_DATA_CONFIRM 0x4480
#define ZSTACK_AF_INCOMING_MSG 0x4481
#define ZSTACK_AF_INCOMING_MSG_EXT 0x4482
#define ZSTACK_ZDO_MGMT_PERMIT_JOIN_RSP 0x45B6
#define ZSTACK_ZDO_MGMT_NWK_UPDATE_RSP 0x45B8
#define ZSTACK_ZDO_STATE_CHANGE_IND 0x45C0
#define ZSTACK_ZDO_END_DEVICE_ANNCE_IND 0x45C1
#define ZSTACK_ZDO_SRC_RTG_IND 0x45C4
#define ZSTACK_ZDO_CONCENTRATOR_IND 0x45C8
#define ZSTACK_ZDO_LEAVE_IND 0x45C9
#define ZSTACK_ZDO_TC_DEV_IND 0x45CA
#define ZSTACK_ZDO_PERMIT_JOIN_IND 0x45CB
#define ZSTACK_ZDO_MSG_CB_INCOMING 0x45FF
#define ZSTACK_APP_CNF_BDB_COMMISSIONING 0x4F80
#define ZCD_NV_EXTADDR 0x0001
#define ZCD_NV_STARTUP_OPTION 0x0003
#define ZCD_NV_NIB 0x0021
#define ZCD_NV_EXTENDED_PAN_ID 0x002D
#define ZCD_NV_NWK_ACTIVE_KEY_INFO 0x003A
#define ZCD_NV_NWK_ALTERN_KEY_INFO 0x003B
#define ZCD_NV_APS_USE_EXT_PANID 0x0047
#define ZCD_NV_PRECFGKEY 0x0062
#define ZCD_NV_PRECFGKEYS_ENABLE 0x0063
#define ZCD_NV_NWKKEY 0x0082
#define ZCD_NV_PANID 0x0083
#define ZCD_NV_CHANLIST 0x0084
#define ZCD_NV_LOGICAL_TYPE 0x0087
#define ZCD_NV_ZDO_DIRECT_CB 0x008F
#define ZCD_NV_LEGACY_TCLK_TABLE_START 0x0101
#define ZCD_NV_EX_ADDRMGR 0x0001
#define ZCD_NV_EX_TCLK_TABLE 0x0004
#define ZCD_NV_EX_NWK_SEC_MATERIAL_TABLE 0x0007
#include "adapter.h"
#pragma pack(push, 1)
struct zstackVersionStruct
{
quint8 transport;
quint8 product;
quint8 major;
quint8 minor;
quint8 patch;
quint32 build;
};
struct zstackAddGroupStruct
{
quint8 endpointId;
quint16 groupId;
quint8 nameLength;
};
struct zstackRegisterEndpointStruct
{
quint8 endpointId;
quint16 profileId;
quint16 deviceId;
quint8 version;
quint8 latency;
};
struct zstackPermitJoinStruct
{
quint8 mode;
quint16 dstAddress;
quint8 duration;
quint8 significance;
};
struct zstackDataRequestStruct
{
quint16 networkAddress;
quint8 dstEndpointId;
quint8 srcEndpointId;
quint16 clusterId;
quint8 transactionId;
quint8 options;
quint8 radius;
quint8 length;
};
struct zstackExtendedRequestStruct
{
quint8 dstAddressMode;
quint64 dstAddress;
quint8 dstEndpointId;
quint16 dstPanId;
quint8 srcEndpointId;
quint16 clusterId;
quint8 transactionId;
quint8 options;
quint8 radius;
quint16 length;
};
struct zstackSetChannelStruct
{
quint8 isPrimary;
quint32 channel;
};
struct zstackNvLengthStruct
{
quint8 system;
quint16 id;
quint16 subId;
};
struct zstackNvInitStruct
{
quint16 id;
quint16 length;
quint8 count;
};
struct zstackNvReadStruct
{
quint16 id;
quint8 offset;
};
struct zstackNvReadExtendedStruct
{
quint16 id;
quint16 offset;
};
struct zstackNvReplyStruct
{
quint8 status;
quint8 length;
};
struct zstackNvWriteStruct
{
quint16 id;
quint8 offset;
quint8 length;
};
struct zstackNvItemStruct
{
quint8 system;
quint16 id;
quint16 subId;
quint16 offset;
quint8 length;
};
struct zstackReadConfigurationStruct
{
quint8 status;
quint8 id;
quint8 length;
};
struct zstackWriteConfigurationStruct
{
quint8 id;
quint8 length;
};
struct zstackNetworkInfoStruct
{
quint64 extendedPanId;
quint16 panId;
quint8 channel;
};
struct zstackAddressManagerStruct
{
quint8 user;
quint8 padding;
quint16 networkAddress;
quint64 ieeeAddress;
};
struct zstackTcLinkKeyStruct
{
quint32 txCounter;
quint32 rxCounter;
quint64 ieeeAddress;
quint8 keyAttributes;
quint8 keyType;
quint8 seedShift;
quint8 padding;
};
struct zstackSecurityMaterialStruct
{
quint32 frameCounter;
quint64 extendedPanId;
};
struct zstackDataConfirmStruct
{
quint8 status;
quint8 endpointId;
quint8 transactionId;
};
struct zstackIncomingMessageStruct
{
quint16 groupId;
quint16 clusterId;
quint16 srcAddress;
quint8 srcEndpointId;
quint8 dstEndpointId;
quint8 broadcast;
quint8 linkQuality;
quint8 security;
quint32 timestamp;
quint8 transactionId;
quint8 length;
};
struct zstackExtendedMessageStruct
{
quint16 groupId;
quint16 clusterId;
quint8 srcAddressMode;
quint64 srcAddress;
quint8 srcEndpointId;
quint16 srcPanId;
quint8 dstEndpointId;
quint8 broadcast;
quint8 linkQuality;
quint8 security;
quint32 timestamp;
quint8 transactionId;
quint16 length;
};
struct zstackZdoMessageStruct
{
quint16 srcAddress;
quint8 broadcast;
quint16 clusterId;
quint8 security;
quint8 transactionId;
quint16 dstAddress;
};
struct zstackDeviceLeaveStruct
{
quint16 networkAddress;
quint64 ieeeAddress;
quint8 request;
quint8 remove;
quint8 rejoin;
};
#pragma pack(pop)
enum class ZStackVersion
{
ZStack3x0,
ZStack30x,
ZStack12x
};
enum class RestoreStatus
{
Unknown,
Pending,
Running
};
class ZStack : public Adapter
{
Q_OBJECT
public:
ZStack(QSettings *config, QObject *parent);
bool unicastRequest(quint8 id, quint16 networkAddress, quint8 srcEndPointId, quint8 dstEndPointId, quint16 clusterId, const QByteArray &payload) override;
bool multicastRequest(quint8 id, quint16 groupId, quint8 srcEndPointId, quint8 dstEndPointId, quint16 clusterId, const QByteArray &payload) override;
bool unicastInterPanRequest(quint8 id, const QByteArray &ieeeAddress, quint16 clusterId, const QByteArray &payload) override;
bool broadcastInterPanRequest(quint8 id, quint16 clusterId, const QByteArray &payload) override;
bool setInterPanChannel(quint8 channel) override;
void resetInterPanChannel(void) override;
bool backupSupported(void) override { return m_version == ZStackVersion::ZStack3x0; }
bool createBackup(QJsonObject &backup) override;
private:
ZStackVersion m_version;
RestoreStatus m_restore;
quint8 m_status;
bool m_clear;
quint16 m_command;
QByteArray m_replyData, m_nibData;
QMap <quint16, QByteArray> m_nvItems;
QMap <quint16, quint8> m_nvItemSize;
QList <quint16> m_zdoClusters;
bool restoreBackup(const QJsonObject &backup);
bool extendedRequest(quint8 id, const QByteArray &address, quint8 dstEndpointId, quint16 dstPanId, quint8 srcEndpointId, quint16 clusterId, const QByteArray &payload, bool group = false);
bool extendedRequest(quint8 id, quint16 address, quint8 dstEndpointId, quint16 dstPanId, quint8 srcEndpointId, quint16 clusterId, const QByteArray &payload, bool group = false);
bool sendRequest(quint16 command, const QByteArray &data = QByteArray());
void parsePacket(quint16 command, const QByteArray &data);
int nvItemLength(quint16 id);
int nvItemLength(quint16 id, quint16 subId);
int nvItemSize(quint16 id);
bool readNvItem(quint16 id, QByteArray &data);
bool readNvItem(quint16 id, quint16 subId, QByteArray &data, int length = 0);
bool writeNvItem(quint16 id, const QByteArray &data);
bool writeNvItem(quint16 id, quint16 subId, const QByteArray &data);
bool writeConfig(quint16 id, const QByteArray &data);
bool readNetworkInfo(zstackNetworkInfoStruct &info);
bool writeNetworkInfo(const zstackNetworkInfoStruct &info);
bool startCommissioning(void);
bool startCoordinator(void);
void softReset(void) override;
void parseData(void) override;
bool permitJoin(bool enabled) override;
private slots:
void handleQueue(void) override;
signals:
void dataReceived(void);
};
#endif