forked from u236/homed-service-zigbee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ezsp.h
367 lines (312 loc) · 11.4 KB
/
ezsp.h
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
#ifndef EZSP_H
#define EZSP_H
#define ASH_REQUEST_TIMEOUT 2000
#define ASH_REQUEST_RETRIES 3
#define ASH_MIN_LENGTH 4
#define ASH_FLAG_BYTE 0x7E
#define ASH_CONTROL_ACK 0x80
#define ASH_CONTROL_NAK 0xA0
#define ASH_CONTROL_RST 0xC0
#define ASH_CONTROL_RSTACK 0xC1
#define ASH_CONTROL_ERROR 0xC2
#define FRAME_VERSION 0x0000
#define FRAME_REGISTER_ENDPOINT 0x0002
#define FRAME_SET_CONCENTRATOR 0x0010
#define FRAME_SET_MANUFACTURER_CODE 0x0015
#define FRAME_NETWORK_INIT 0x0017
#define FRAME_NETWORK_STATUS 0x0018
#define FRAME_STACK_STATUS_HANDLER 0x0019
#define FRAME_FORM_NERWORK 0x001E
#define FRAME_LEAVE_NETWORK 0x0020
#define FRAME_PERMIT_JOINING 0x0022
#define FRAME_TRUST_CENTER_JOIN_HANDLER 0x0024
#define FRAME_GET_IEEE_ADDRESS 0x0026
#define FRAME_GET_NETWORK_PARAMETERS 0x0028
#define FRAME_SEND_UNICAST 0x0034
#define FRAME_SEND_MULTICAST 0x0038
#define FRAME_MESSAGE_SENT_HANDLER 0x003F
#define FRAME_INCOMING_MESSAGE_HANDLER 0x0045
#define FRAME_MAC_FILTER_MATCH_MESSAGE_HANDLER 0x0046
#define FRAME_SET_CONFIG 0x0053
#define FRAME_SET_POLICY 0x0055
#define FRAME_SET_SOURCE_ROUTE_DISCOVERY_MODE 0x005A
#define FRAME_SET_MULTICAST_TABLE_ENTRY 0x0064
#define FRAME_SET_INITIAL_SECURITY_STATE 0x0068
#define FRAME_GET_KEY 0x006A
#define FRAME_CLEAR_TRANSIENT_LINK_KEYS 0x006B
#define FRAME_FIND_KEY_TABLE_ENTRY 0x0075
#define FRAME_ERASE_KEY_TABLE_ENTRY 0x0076
#define FRAME_SET_EXTENDED_TIMEOUT 0x007E
#define FRAME_SEND_RAW 0x0096
#define FRAME_GET_VALUE 0x00AA
#define FRAME_SET_VALUE 0x00AB
#define FRAME_ADD_TRANSIENT_LINK_KEY 0x00AF
#define FRAME_CLEAR_KEY_TABLE 0x00B1
#define FRAME_SET_CHANNEL 0x00B9
#define CONFIG_NEIGHBOR_TABLE_SIZE 0x02
#define CONFIG_APS_UNICAST_MESSAGE_COUNT 0x03
#define CONFIG_BINDING_TABLE_SIZE 0x04
#define CONFIG_STACK_PROFILE 0x0C
#define CONFIG_SECURITY_LEVEL 0x0D
#define CONFIG_MAX_HOPS 0x10
#define CONFIG_MAX_END_DEVICE_CHILDREN 0x11
#define CONFIG_INDIRECT_TRANSMISSION_TIMEOUT 0x12
#define CONFIG_END_DEVICE_POLL_TIMEOUT 0x13
#define CONFIG_TX_POWER_MODE 0x17
#define CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE 0x19
#define CONFIG_KEY_TABLE_SIZE 0x1E
#define CONFIG_BROADCAST_TABLE_SIZE 0x2B
#define CONFIG_RETRY_QUEUE_SIZE 0x34
#define CONFIG_TRANSIENT_KEY_TIMEOUT_S 0x36
#define POLICY_TRUST_CENTER 0x00
#define POLICY_BINDING_MODIFICATION_POLICY 0x01
#define POLICY_TC_KEY_REQUEST 0x05
#define POLICY_APP_KEY_REQUEST 0x06
#define SECURITY_TRUST_CENTER_USES_HASHED_LINK_KEY 0x0084
#define SECURITY_HAVE_PRECONFIGURED_KEY 0x0100
#define SECURITY_HAVE_NETWORK_KEY 0x0200
#define SECURITY_REQUIRE_ENCRYPTED_KEY 0x0800
#define VALUE_MAXIMUM_INCOMING_TRANSFER_SIZE 0x05
#define VALUE_MAXIMUM_OUTGOING_TRANSFER_SIZE 0x06
#define VALUE_STACK_TOKEN_WRITING 0x07
#define VALUE_VERSION_INFO 0x11
#define VALUE_END_DEVICE_KEEP_ALIVE_SUPPORT_MODE 0x3F
#define VALUE_TRANSIENT_DEVICE_TIMEOUT 0x43
#define CONCENTRATOR_HIGH_RAM 0xFFF9
#define CONCENTRATOR_MIN_TIME 5
#define CONCENTRATOR_MAX_TIME 60
#define CONCENTRATOR_ROUTE_ERROR_THRESHOLD 3
#define CONCENTRATOR_DELIVERY_FAILURE_THRESHOLD 1
#define STACK_STATUS_NETWORK_UP 0x90
#define STACK_STATUS_NETWORK_DOWN 0x91
#define TRUST_CENTER_UNSECURED_JOIN 0x01
#define TRUST_CENTER_DEVICE_LEFT 0x02
#define MESSAGE_TYPE_DIRECT 0x00
#define APS_OPTION_RETRY 0x0040
#define APS_OPTION_ENABLE_ROUTE_DISCOVERY 0x0100
#define APS_OPTION_ENABLE_ADDRESS_DISCOVERY 0x1000
#define NETWORK_STATUS_JOINED 0x02
#define CURRENT_NETWORK_KEY 0x03
#include "adapter.h"
#pragma pack(push, 1)
struct ezspHeaderStruct
{
quint8 sequence;
quint8 frameControlLow;
quint8 frameControlHigh;
quint16 frameId;
};
struct registerEndpointStruct
{
quint8 endpointId;
quint16 profileId;
quint16 deviceId;
quint8 appFlags;
quint8 inClustersCount;
quint8 outClustersCount;
};
struct setConcentratorStruct
{
quint8 enabled;
quint16 type;
quint16 minTime;
quint16 maxTime;
quint8 routeErrorThreshold;
quint8 deliveryFailureThreshold;
quint8 maxHops;
};
struct trustCenterJoinHandlerStruct
{
quint16 networkAddress;
quint64 ieeeAddress;
quint8 status;
quint8 decision;
quint16 parentAddress;
};
struct networkParametersStruct
{
quint64 extendedPanId;
quint16 panId;
quint8 txPower;
quint8 channel;
quint8 joinMethod;
quint16 networkManagerId;
quint8 networkUpdateId;
quint32 channelList;
};
struct sendUnicastStruct
{
quint8 type;
quint16 networkAddress;
quint16 profileId;
quint16 clusterId;
quint8 srcEndpointId;
quint8 dstEndpointId;
quint16 options;
quint16 groupId;
quint8 sequence;
quint8 tag;
quint8 length;
};
struct sendMulticastStruct
{
quint16 profileId;
quint16 clusterId;
quint8 srcEndpointId;
quint8 dstEndpointId;
quint16 options;
quint16 groupId;
quint8 sequence;
quint8 hops;
quint8 radius;
quint8 tag;
quint8 length;
};
struct sendIeeeRawStruct
{
quint16 ieeeFrameControl;
quint8 sequence;
quint16 dstPanId;
quint64 dstAddress;
quint16 srcPanId;
quint64 srcAddress;
quint16 networkFrameControl;
quint8 appFrameControl;
quint16 clusterId;
quint16 profileId;
};
struct sendRawStruct
{
quint16 ieeeFrameControl;
quint8 sequence;
quint16 dstPanId;
quint16 dstAddress;
quint16 srcPanId;
quint64 srcAddress;
quint16 networkFrameControl;
quint8 appFrameControl;
quint16 clusterId;
quint16 profileId;
};
struct messageSentHandlerStruct
{
quint8 type;
quint16 networkAddress;
quint16 profileId;
quint16 clusterId;
quint8 srcEndpointId;
quint8 dstEndpointId;
quint16 options;
quint16 groupId;
quint8 sequence;
quint8 tag;
quint8 status;
quint8 length;
};
struct incomingMessageHandlerStruct
{
quint8 type;
quint16 profileId;
quint16 clusterId;
quint8 srcEndpointId;
quint8 dstEndpointId;
quint16 options;
quint16 groupId;
quint8 sequence;
quint8 linkQuality;
quint8 rssi;
quint16 networkAddress;
quint8 bindingIndex;
quint8 addressIndex;
quint8 length;
};
struct macFilterMatchMessageHandlerStruct
{
quint8 index;
quint8 type;
quint8 linkQuality;
quint8 rssi;
quint8 length;
quint16 ieeeFrameControl;
quint8 sequence;
quint16 dstPanId;
quint64 dstAddress;
quint16 srcPanId;
quint64 srcAddress;
quint16 networkFrameControl;
quint8 appFrameControl;
quint16 clusterId;
quint16 profileId;
};
struct setConfigStruct
{
quint8 id;
quint16 value;
};
struct setValueStruct
{
quint8 id;
quint8 length;
quint16 value;
};
struct setMulticastStruct
{
quint16 groupId;
quint8 endpointId;
quint8 index;
};
struct setInitialSecurityStateStruct
{
quint16 bitmask;
quint8 preconfiguredKey[16];
quint8 networkKey[16];
quint8 networkKeySequenceNumber;
quint64 preconfiguredTrustCenter;
};
struct versionInfoStruct
{
quint16 build;
quint8 major;
quint8 minor;
quint8 patch;
};
#pragma pack(pop)
class EZSP : public Adapter
{
Q_OBJECT
public:
EZSP(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;
private:
QTimer *m_timer;
QByteArray m_networkKey;
quint8 m_version, m_stackStatus, m_sequenceId, m_acknowledgeId;
QByteArray m_replyData;
bool m_replyReceived, m_errorReceived;
QList <setConfigStruct> m_config, m_policy;
QList <setValueStruct> m_values;
quint16 getCRC(quint8 *data, quint32 length);
void randomize(QByteArray &data);
bool sendFrame(quint16 frameId, const QByteArray &data = QByteArray(), bool version = false);
void sendRequest(quint8 control, const QByteArray &payload = QByteArray());
void parsePacket(const QByteArray &payload);
bool startNetwork(quint64 extendedPanId);
bool startCoordinator(void);
void setManufacturerCode(quint16 value);
void handleError(const QString &reason);
void softReset(void) override;
void parseData(QByteArray &buffer) override;
bool permitJoin(bool enabled) override;
private slots:
void resetManufacturerCode(void);
void handleQueue(void) override;
signals:
void dataReceived(void);
void stackStatusReceived(void);
};
#endif