-
Notifications
You must be signed in to change notification settings - Fork 0
/
z3.h
523 lines (468 loc) · 13.1 KB
/
z3.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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
#ifndef __Z3_H_
#define __Z3_H_
#ifdef __cplusplus
extern "C" {
#endif
/*=============
*Struct Define
*===========================================================================================*/
typedef struct stAttr {
short attrid;
unsigned char type;
int len;
char *data;
long last; /* last update time (ms)*/
} stAttr_t;
typedef struct stCluster {
short clsid;
int attrcnt;
stAttr_t *attrs;
}stCluster_t;
typedef struct stNodeDesc {
unsigned char nodetype;
unsigned char complex_desc_available;
unsigned char user_desc_available;
unsigned char reserved;
unsigned char apsflag;
unsigned char freqband;
unsigned char mac_cap;
short manufacturer_code;
unsigned char max_buffer_size;
short min_incomming_transfer_size;
short server_mask_capabilities;
unsigned char max_outgoing_transfer_size;
unsigned char desc_capability;
}stNodeDesc_t;
typedef struct stSimplerDesc {
unsigned char ep;
short appproid;
short appdevid;
unsigned char appdevver;
char reserved;
int incnt;
stCluster_t *incls;
int outcnt;
stCluster_t *outcls;
}stSimplerDesc_t;
typedef struct stZ3Device {
unsigned char extaddr[8];
short nwkaddr;
int epcnt;
stSimplerDesc_t *epdescs;
stNodeDesc_t nodedesc;
} stZ3Device_t;
typedef struct stZclAttr {
short aid;
const char *name;
char type;
int min;
int max;
char *rw;
int len;
const char *def;
char mad;
char cr; /* config report */
short minrptdlt;
short maxrptdlt;
int changerpt;
}stZclAttr_t;
typedef struct stZclRcmd {
char cmd;
const char *name;
char mad;
}stZclRcmd_t;
typedef struct stZclGcmd {
char cmd;
const char *name;
char mad;
}stZclGcmd_t;
typedef struct stZclServer {
int support;
int acnt;
stZclAttr_t attrs[30];
int rcnt;
stZclRcmd_t rcmds[30];
int gcmt;
stZclGcmd_t gcmds[30];
}stZclServer_t;
typedef struct stZclServer stZclClient_t;
typedef struct stZclCluster {
short cid;
char *name;
stZclServer_t server;
stZclClient_t client;
}stZclCluster_t;
enum {
t_NODATA = 0x00,
t_DATA8 = 0x08,
t_DATA16 = 0x09,
t_DATA24 = 0x0a,
t_DATA32 = 0x0b,
t_DATA40 = 0x0c,
t_DATA48 = 0x0d,
t_DATA56 = 0x0e,
t_DATA64 = 0x0f,
t_BOOL = 0x10,
t_MAP8 = 0X18,
t_MAP16 = 0x19,
t_MAP24 = 0x1a,
t_MAP32 = 0x1b,
t_MAP40 = 0x1c,
t_MAP48 = 0x1d,
t_MAP56 = 0x1e,
t_MAP64 = 0x1f,
t_UINT8 = 0x20,
t_UINT16 = 0x21,
t_UINT24 = 0x22,
t_UINT32 = 0x23,
t_UINT40 = 0x24,
t_UINT48 = 0x25,
t_UINT56 = 0x26,
t_UINT64 = 0x27,
t_INT8 = 0x28,
t_INT16 = 0x29,
t_INT24 = 0x2a,
t_INT32 = 0x2b,
t_INT40 = 0x2c,
t_INT48 = 0x2d,
t_INT56 = 0x2e,
t_INT64 = 0x2f,
t_ENUM8 = 0x30,
t_ENUM16 = 0X31,
t_SEMI = 0x38,
t_SINGLE = 0x39,
t_DOUBLE = 0x3a,
t_OCTSTR = 0x41,
t_STRING = 0x42,
t_OCTSTR16 = 0x43,
t_STRING16 = 0x44,
t_ARRAY = 0x48,
t_STRUCT = 0x4c,
t_SET = 0x50,
t_BAG = 0x51,
t_TOD = 0xe0,
t_DATE = 0xe1,
t_UTC = 0xe2,
t_CLUSTERID = 0xe8,
t_ATTRIBID = 0xe9,
t_BACOID = 0xea,
t_EUI64 = 0xf0,
t_KEY128 = 0xf1,
/*t_OPAUE = 0x, */
t_UNK = 0xff,
/*
t_UINT8 = 0x00,
t_MAP32 = 0x01,
t_UINT16 = 0x02,
t_MAP8 = 0x03,
t_BOOL = 0x04,
t_ENUM8 = 0x05,
t_UTC = 0x06,
t_DATA8 = 0x07,
t_INT16 = 0x08,
t_INT8 = 0x09,
t_ENUM16 = 0x0a,
t_MAP16 = 0x0b,
t_EUI64 = 0x0c,
t_STRING = 0x0d,
t_INT24 = 0x0e,
*/
};
typedef stZ3Device_t stZigbeeDevice_t;
typedef stSimplerDesc_t stZigbeeSimplerDesc_t;
typedef stCluster_t stZigbeeCluster_t;
typedef stAttr_t stZigbeeAttr_t;
/*=============
* To Implement
*===========================================================================================*/
stZclCluster_t *z3_get_clusters();
int z3_get_clusters_cnt();
/*=============
* Callback Api
*===========================================================================================*/
/*
* @param[in] addr - 8bytes device's mac
* */
int z3_register(char *addr, int *epList, int epListLen, char *ModelStr, char *model, int type, int battery);
int z3_unregister(char *addr);
int z3_online(char *addr, long last, int online);
int z3_attr(char *addr, unsigned char ep, unsigned short clsid, const char *buf, int len, int linkQuality);
int z3_cmd(char *addr, unsigned char ep, unsigned short clsid, const char *buf, int len, int linkQuality);
int z3_simple_desc(char *addr, unsigned char ep, char *buf, int len);
/**
* -1 any faile
* 1 rbsdk_add_dev or assoc ok
* 2 match desc req ok
* 3 active_endpiont_req ok
* 4 simple ok
* 5 read report ok
* 6 config report ok
* 7 bind req ok
* 8 zone_enroolment ok
* ---------------------------------
* -1 rbsdk_add_dev failed or timeou
* -2 match desc req failed or timeout
* -3 active_endpiont_req failed or timeout
* -4 simple failed or timeout
* -5 read report failed or timeout
* -6 config report failed or timeout
* -7 bind req faile or timeout
* -8 zone_enroolment failed or timeout
**/
int z3_exploration(char *addr, int status, int cluster);
int z3_zcl_cmd_ret(char *addr, unsigned char ep, unsigned short clsid, char cmdid, int status, int linkQuality, void *context, unsigned char seq);
int z3_set_att_ret(char *addr, unsigned char ep, unsigned short clsid, unsigned short attr, int status, int linkQuality, void *context);
int z3_get_att_ret(char *addr, unsigned char ep, unsigned short clsid, unsigned short attr, int status, int linkQuality, void *context);
int z3_zcl_cmd_res(char *addr, unsigned char ep, unsigned short clusterid, unsigned char cmd, unsigned char seq, char *buf, int len);
/*=============
* Call Api Sync & Async
* Sync Api only can be called in the same thread with sdk
* Async can be called in multi threads
*===========================================================================================*/
/** z3_get_device(char *addr);
*
* get local device
*
* @param[in] addr subdevice addr to send to
*
* @return local device pointer or NULL.
*
* @warning none
*
* @note none
*
* @see none
*/
stZ3Device_t *z3_get_device(char *addr);
/** z3_list_device(void (*cb)(char *addr, int *epList, int epListLen, char *ModelStr, char *model, int type, int battery));
*
* list local device
*
* @param[in] cb callback function to each device
*
* @return
*
* @warning none
*
* @note none
*
* @see none
*/
void z3_list_device(void (*cb)(char *addr, int *epList, int epListLen, char *ModelStr, char *model, int type, int battery));
void z3_list_device_a(void (*cb)(char *addr, int *epList, int epListLen, char *ModelStr, char *model, int type, int battery));
/** z3_run
*
* start zigbee 3 stack, it will not return
*
* @param[in] argc arguments count
* @param[in] argv arguments
*
* @return 0->ok, else failed.
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_run(int argc, char *argv[]);
/** z3_versoin
*
* get sdk version
*
* @param[in] none
*
* @return version
*
* @warning none
*
* @note none
*
* @see none
*/
char *z3_version();
/** z3_fd_reg(int fd, void (*func)(int fd))
*
* register a fd to sdk io loop
*
* @param[in] fd , fd to register
*
* @return 0 -> ok, -1 error
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_fd_reg(int fd, void (*func)(int fd));
/** z3_fd_unreg(int fd, void (*func)(int fd))
*
* unregister a fd from sdk io loop
*
* @param[in] fd , fd to unregister, will match fd and func
*
* @return 0 -> ok, -1 error
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_fd_unreg(int fd, void (*func)(int fd));
/** z3_permit
*
* open zigbee network, permit subdevice to join.
*
* @param[in] addr subdevice addr, "ffffffffffffffff" will allow all device to join, othewise it only allow the addr-device to join.
* @param[in] duration time of open the network, must in 0 ~ 120
*
* @return 0->ok, else failed.
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_permit(char *addr, int duration);
int z3_permit_a(char *addr, int duration);
/** z3_remove
*
* remove subdevice form local list with force or not.
*
* @param[in] addr subdevice addr to remove
* @param[in] force 0->send a leave message to the device and wait response, remove this when receive this response
* 1->flag the deivce to leaved status, and send leave message when receive any message from this device and then remove it
* 2->direct remove this device from local
*
* @return 0->ok, else failed.
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_remove(char *addr, int force);
int z3_remove_a(char *addr, int force);
/** z3_get_attr
*
* send a read attribute message to device
*
* @param[in] addr subdevice addr to send to
* @param[in] ep subdevice endpoint to send to
* @param[in] cluster subdevice cluster to send to
* @param[in] attrid subdevice attribute id to send to
*
* @return 0->ok, else failed.
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_get_att(char *addr, char ep, short cluster, short attrid);
int z3_get_att_a(char *addr, char ep, short cluster, short attrid);
/** z3_set_attr
*
* send a write attribute message to device
*
* @param[in] addr subdevice addr to send to
* @param[in] ep subdevice endpoint to send to
* @param[in] cluster subdevice cluster to send to
* @param[in] attrid subdevice attribute id to send to
* @param[in] attrtype subdevice attribute type
* @param[in] data data to write to attribute
* @param[in] len data len
*
* @return 0->ok, else failed.
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_set_att(char *addr, char ep, short cluster, short attrid, int attrtype, char *data, int len);
int z3_set_att_a(char *addr, char ep, short cluster, short attrid, int attrtype, char *data, int len);
/** z3_zcl_cmd
*
* send a zcl command message to device
*
* @param[in] addr subdevice addr to send to
* @param[in] manufacturer manufacturer if this cluster is manufacturer cluster, else set to zero
* @param[in] ep subdevice endpoint to send to
* @param[in] cluster subdevice cluster to send to
* @param[in] cmdid subdevice command id to send to
* @param[in] data data to send
* @param[in] len data len
*
* @return 0->ok, else failed.
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_zcl_cmd(char *addr, short manufacturer, char ep, short cluster, char cmdid, char *data, int len, void *context);
int z3_zcl_cmd_a(char *addr, short manufacturer, char ep, short cluster, char cmdid, char *data, int len, void *context);
/** z3_grp_cmd
*
* send a zcl command message to device
*
* @param[in] grpid group id to send
* @param[in] manufacturer manufacturer if this cluster is manufacturer cluster, else set to zero
* @param[in] ep subdevice endpoint to send to
* @param[in] cluster subdevice cluster to send to
* @param[in] cmdid subdevice command id to send to
* @param[in] data data to send
* @param[in] len data len
*
* @return 0->ok, else failed.
*
* @warning none
*
* @note none
*
* @see none
*/
int z3_grp_cmd(short grpid, short manufacturer, char ep, short cluster, char cmdid, char *data, int len, void *context);
int z3_grp_cmd_a(short grpid, short manufacturer, char ep, short cluster, char cmdid, char *data, int len, void *context);
stZigbeeDevice_t *zigbee_search_by_extaddr_ext(char extaddr[8]);
unsigned char zigbee_get_ep_value(stZigbeeDevice_t *zd, unsigned char ep);
stZigbeeSimplerDesc_t *zigbee_simplerdesc_get(stZigbeeDevice_t *dev, unsigned char ep);
stZigbeeCluster_t *zigbee_cluster_get(stZigbeeSimplerDesc_t *simdesc, char inOrout, short cluster);
stZigbeeAttr_t *zigbee_attr_get(stZigbeeCluster_t *cluster, short attrid);
/**
* Problem :
*
* 1. Provide End Point List Array in dev_added callback: int (*rpt_dev_added)(char *mac, char *ModelStr, int *epList, int epListLen, char *model, int type, int battery);
* ok you can get this inormation from z3_get_device
*
* 2. Provide linkQuality parameter in ZCL data: int (*rpt_cmd)(char *mac, int ep, int cluster, int cmd, char *buf, int len, int linkQuality);
* ok
*
* 3. Provide linkQuality parameter in ZCL attribute data: int (*rpt_cmd)(char *mac, int ep, int cluster, int cmd, char *buf, int len, int linkQuality);
* ok
*
* 4. Provide Simple Descriptor Response callback: int (*rpt_simple_desc_rsp)(char *mac, int ep, char *buf, int len);
*
* 5. Support manufacturer specific frame control and application context parameter:
* int rbsdk_zcl_cmd(char *mac, int ep, int cluster, int manufacturerSpecific, int cmdid, char *data, int len, void *context);
*
* 6. Provide ZCL Command status callback with application context parameter returned:
* int (*rpt_zcl_cmd_status)(char *mac, int ep, int cluster, int cmdid, int status, int linkQuality, void *context);
*
* 7. Add Bind request: Endpoint binding should be done for *all* the clusters specifically IAS_ZONE and IAS_ACE clusters
* – we currently see that these clusters are not sent the command. We have devices that don’t report unless you explicitly bind.
*
* 8. Configure Reporting for battery operated devices: This should have minimum reporting interval as 900 sec to reduce battery impact. Currently it is 60 sec. It should remain 60 seconds for mains powered devices.
* */
#ifdef __cplusplus
}
#endif
#endif