/
zb_zcl_common.h
2481 lines (2139 loc) · 114 KB
/
zb_zcl_common.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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ZBOSS Zigbee 3.0
*
* Copyright (c) 2012-2024 DSR Corporation, Denver CO, USA.
* www.dsr-zboss.com
* www.dsr-corporation.com
* All rights reserved.
*
*
* Use in source and binary forms, redistribution in binary form only, with
* or without modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 2. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 3. This software, with or without modification, must only be used with a Nordic
* Semiconductor ASA integrated circuit.
*
* 4. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* PURPOSE: Zigbee cluster library types and macros common for all clusters
*/
#ifndef ZB_ZCL_COMMON_H
#define ZB_ZCL_COMMON_H 1
#include <zboss_api_core.h> /* int types, zb_bufid_t */
/** @cond DOXYGEN_ZCL_SECTION */
#ifdef DEBUG
/* If defined, samples included to zcl source files will be compiled - need for development only */
#define ZB_COMPILE_ZCL_SAMPLE
#endif
/** @addtogroup ZB_ZCL_COMMON
* @{
*/
/**
* @defgroup zb_zcl_common_types ZCL common types
* @{
* @details
* The section contains enumerations defining cluster identifiers and inter-device operation
* statuses, and a callback type used to notify application on attribute value change (see @ref
* write_attr_cmd "Write attributes" command description).
*/
/*************************** ZCL cluster definitions ***********************************/
/*! ZCL payload maximum size; is used to calculate number of
* available bytes in variable-size commands */
/* TODO: current max size is defined for the worst case (nwk security
* enabled, long address is specified). Possibly - recalculate this
* max size in run-time taking into account current parameters */
/* TODO: check this value - calculate it correctly!!! */
/*
Let's count:
- max PHY payload - 127 bytes
- MAC hdr (w/o Pan ID completion, short src/dest) - (FC 2, Seq 1, Pan ID 2, DST addr 2, SRC addr
2, FCS 2) = 11b MAC
- NWK HDR 8 + 8*2 (addresses). Note: not use source routing, else have more fields.
- NWK security 18b
- APS HDR (without security) 8b
Total 61 (45 without ieee addresses).
So, rest is 127-61 = 66b
So, rest is 127-45 = 82b
*/
/* #define ZB_ZCL_MAX_PAYLOAD_SIZE 55 */
/*! Maximal payload size */
#define ZB_ZCL_HI_MAX_PAYLOAD_SIZE 66U
/*! Maximal payload size without long address sending */
#define ZB_ZCL_HI_WO_IEEE_MAX_PAYLOAD_SIZE 82U
struct zb_zcl_attr_s; /* Forward declaration */
/** @brief ZCL Cluster Init Handler. This handler is called on registering device context (@ref
ZB_AF_REGISTER_DEVICE_CTX). Initialization of the cluster should include @ref
zb_zcl_add_cluster_handlers call, if any of the cluster handlers are implemented.
Cluster Init handler is bound to the cluster declaration via ZB_ZCL_CLUSTER_DESC macro. Every
cluster should implement "<cluster_id>_<cluster_role>_INIT" macro, for example:
@code
#define ZB_ZCL_CLUSTER_ID_ON_OFF_SERVER_ROLE_INIT zb_zcl_on_off_init_server
#define ZB_ZCL_CLUSTER_ID_ON_OFF_CLIENT_ROLE_INIT zb_zcl_on_off_init_client
@endcode
If cluster does not have any initialization steps and does not need any cluster handlers,
Cluster Init handler may be NULL, for example:
@code
#define ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING_SERVER_ROLE_INIT (zb_zcl_cluster_init_t)NULL
#define ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING_CLIENT_ROLE_INIT (zb_zcl_cluster_init_t)NULL
@endcode
*/
typedef void (*zb_zcl_cluster_init_t)(void);
/** @brief ZCL Cluster Command Handler. This handler is called on incoming ZCL command for
corresponding cluster.
@param param - pointer to buffer with ZCL command
@return ZB_TRUE if command was handled (no additional actions are needed),
ZB_FALSE otherwise
*/
typedef zb_bool_t (*zb_zcl_cluster_handler_t)(zb_uint8_t param);
/** @brief ZCL Cluster Check Value Handler. This handler is called before attribute change (for
corresponding cluster) and checks if new value is in correct range and can be applied.
@param attr_id - ZCL Attribute ID
@param endpoint - Device Endpoint
@param value - pointer to the new Attribute Value
@return RET_OK if check is passed successfully (attribute can be changed),
RET_OUT_OF_RANGE if the value is out of range (TODO: describe),
RET_ERROR otherwise
*/
typedef zb_ret_t (*zb_zcl_cluster_check_value_t)(zb_uint16_t attr_id, zb_uint8_t endpoint, zb_uint8_t *value);
/** @brief ZCL Cluster Write Attribute Hook Handler. This handler is called before attribute change
(if any cluster-specific action needs to be bound to attribute change, it can be placed in this
handler).
@param endpoint - Device Endpoint
@param attr_id - ZCL Attribute ID
@param new_value - pointer to the new Attribute Value
@param manuf_code - manufacturer specific code
*/
typedef void (*zb_zcl_cluster_write_attr_hook_t)(zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *new_value, zb_uint16_t manuf_code);
/** @brief ZCL cluster description. */
typedef ZB_PACKED_PRE struct zb_zcl_cluster_desc_s
{
zb_uint16_t cluster_id; /**< ZCL 16-bit cluster id. @see zcl_cluster_id */
zb_uint16_t attr_count; /**< Attributes number supported by the cluster */
struct zb_zcl_attr_s *attr_desc_list; /**< List of cluster attributes,
declared using ZB_ZCL_DECLARE_<CLUSTER_NAME>_ATTRIB_LIST() macro */
zb_uint8_t role_mask; /**< Cluster role, refer to zcl_cluster_role */
zb_uint16_t manuf_code; /**< Manufacturer code for cluster and its attributes */
zb_zcl_cluster_init_t cluster_init;
} ZB_PACKED_STRUCT
zb_zcl_cluster_desc_t;
/**
* @brief Add ZCL cluster handlers for Cluster ID and Cluster Role.
*
* @param cluster_id - ZCL Cluster ID
* @param cluster_role - ZCL Cluster Role, see @ref zcl_cluster_role
* @param cluster_check_value - "Check Value" handler, see @ref zb_zcl_cluster_check_value_t; may
* be NULL if this handler is not needed
* @param cluster_write_attr_hook - "Write Attr Hook" handler, see @ref
* zb_zcl_cluster_write_attr_hook_t; may be NULL if this handler is not needed
* @param cluster_handler - "Cluster Commands" handler, see @ref zb_zcl_cluster_handler_t; may
* be NULL if this handler is not needed
*
* @return RET_OK if ZCL handlers were installed
* @return RET_ALREADY_EXISTS if ZCL handlers are already installed (for given Cluster ID and Role),
* new handlers will not be installed in that case
* @return RET_EMPTY if ZCL handlers were not installed
*/
zb_ret_t zb_zcl_add_cluster_handlers(zb_uint16_t cluster_id, zb_uint8_t cluster_role,
zb_zcl_cluster_check_value_t cluster_check_value,
zb_zcl_cluster_write_attr_hook_t cluster_write_attr_hook,
zb_zcl_cluster_handler_t cluster_handler);
/** @cond internals_doc */
zb_zcl_cluster_handler_t zb_zcl_get_cluster_handler(zb_uint16_t cluster_id, zb_uint8_t cluster_role);
zb_zcl_cluster_check_value_t zb_zcl_get_cluster_check_value(zb_uint16_t cluster_id, zb_uint8_t cluster_role);
zb_zcl_cluster_write_attr_hook_t zb_zcl_get_cluster_write_attr_hook(zb_uint16_t cluster_id, zb_uint8_t cluster_role);
#ifdef ZB_CONTROL4_NETWORK_SUPPORT
/** Functions for adding and getting Control4 Network cluster specific handlers */
zb_ret_t zb_zcl_add_control4_cluster_handlers(zb_uint16_t cluster_id, zb_uint8_t cluster_role,
zb_zcl_cluster_check_value_t cluster_check_value,
zb_zcl_cluster_write_attr_hook_t cluster_write_attr_hook,
zb_zcl_cluster_handler_t cluster_handler);
zb_zcl_cluster_handler_t zb_zcl_get_control4_cluster_handler(zb_uint16_t cluster_id, zb_uint8_t cluster_role);
zb_zcl_cluster_check_value_t zb_zcl_get_control4_cluster_check_value(zb_uint16_t cluster_id, zb_uint8_t cluster_role);
zb_zcl_cluster_write_attr_hook_t zb_zcl_get_control4_cluster_write_attr_hook(zb_uint16_t cluster_id, zb_uint8_t cluster_role);
#endif /* ZB_CONTROL4_NETWORK_SUPPORT */
/** @endcond */ /* internals_doc */
/**
* @name Cluster roles in message exchange
* @anchor zcl_cluster_role
*
* Note: These values were members of `enum zb_zcl_cluster_role_e` type but were converted to a
* set of macros due to MISRA violations.
*/
/** @{ */
/** Server cluster role */
#define ZB_ZCL_CLUSTER_SERVER_ROLE 0x01U
/** Client cluster role */
#define ZB_ZCL_CLUSTER_CLIENT_ROLE 0x02U
/** Internal value - used for searching any role (on the moment when cluster role is not known yet). */
#define ZB_ZCL_CLUSTER_ANY_ROLE 0x03U
/** Reverts cluster role */
#define ZB_ZCL_REVERT_CLUSTER_ROLE(_d) \
(((_d) != ZB_ZCL_CLUSTER_ANY_ROLE) ? (((_d) == ZB_ZCL_CLUSTER_SERVER_ROLE) ? ZB_ZCL_CLUSTER_CLIENT_ROLE : ZB_ZCL_CLUSTER_SERVER_ROLE) : \
ZB_ZCL_CLUSTER_ANY_ROLE)
/** @} */
/**
* @name ZCL cluster identifiers
* @anchor zcl_cluster_id
* @see ZCL spec, subclause 2.2.2
*/
/** @{ */
#define ZB_ZCL_CLUSTER_ID_BASIC 0x0000U /*!< Basic cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_POWER_CONFIG 0x0001U /*!< Power configuration cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_DEVICE_TEMP_CONFIG 0x0002U /*!< Device temperature configuration cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_IDENTIFY 0x0003U /*!< Identify cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_GROUPS 0x0004U /*!< Groups cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_SCENES 0x0005U /*!< Scenes cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_ON_OFF 0x0006U /*!< On/Off cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG 0x0007U /*!< On/Off switch configuration cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL 0x0008U /*!< Level control cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_ALARMS 0x0009U /*!< Alarms cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_TIME 0x000aU /*!< Time cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_RSSI_LOCATION 0x000bU /*!< RSSI location cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_ANALOG_INPUT 0x000cU /*!< Analog input (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT 0x000dU /*!< Analog output (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_ANALOG_VALUE 0x000eU /*!< Analog value (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_BINARY_INPUT 0x000fU /*!< Binary input (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_BINARY_OUTPUT 0x0010U /*!< Binary output (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_BINARY_VALUE 0x0011U /*!< Binary value (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_MULTI_INPUT 0x0012U /*!< Multistate input (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT 0x0013U /*!< Multistate output (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_MULTI_VALUE 0x0014U /*!< Multistate value (basic) cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_COMMISSIONING 0x0015U /*!< Commissioning cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_OTA_UPGRADE 0x0019U /*!< Over The Air cluster identifier. */
/* General clusters */
#define ZB_ZCL_CLUSTER_ID_POLL_CONTROL 0x0020U /*!< Poll control cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_GREEN_POWER 0x0021U /*!< Green Power cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_KEEP_ALIVE 0x0025U /*!< Keep Alive cluster identifier. */
/* Closures clusters */
#define ZB_ZCL_CLUSTER_ID_SHADE_CONFIG 0x0100U /*!< Shade configuration cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_DOOR_LOCK 0x0101U /*!< Door lock cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_WINDOW_COVERING 0x0102U /*!< Window covering cluster identifier. */
/* HVAC clusters */
#define ZB_ZCL_CLUSTER_ID_PUMP_CONFIG_CONTROL 0x200U /*!< Pump configuration and control cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_THERMOSTAT 0x201U /*!< Thermostat cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_FAN_CONTROL 0x202U /*!< Fan control cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_DEHUMID_CONTROL 0x203U /*!< Dehumidification control cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG 0x204U /*!< Thermostat user interface configuration cluster identifier. */
/* Lighting clusters */
#define ZB_ZCL_CLUSTER_ID_COLOR_CONTROL 0x0300U /*!< Color control cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_BALLAST_CONFIG 0x0301U /*!< Ballast configuration cluster identifier. */
/* Measurement and Sensing */
#define ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT 0x0400U /*!< Illuminance measurement */
#define ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT 0x0402U /*!< Temperature measurement */
#define ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT 0x0403U /*!< Pressure measurement */
#define ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT 0x0405U /*!< Relative humidity measurement */
#define ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING 0x0406U /*!< Occupancy sensing */
/* IAS clusters */
#define ZB_ZCL_CLUSTER_ID_IAS_ZONE 0x0500U /*!< IAS Zone cluster identifier */
#define ZB_ZCL_CLUSTER_ID_IAS_ACE 0x0501U /*!< IAS ACE cluster identifier */
#define ZB_ZCL_CLUSTER_ID_IAS_WD 0x0502U /*!< IAS WD cluster identifier */
/* Smart Energy */
#define ZB_ZCL_CLUSTER_ID_PRICE 0x0700U /*!< Price cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_DRLC 0x0701U /*!< Demand-Response cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_METERING 0x0702U /*!< Metering cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_MESSAGING 0x0703U /*!< Messaging cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_TUNNELING 0x0704U /*!< Tunneling cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_PREPAYMENT 0x0705U /*!< Prepayment cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_ENERGY_MANAGEMENT 0x0706U /*!< Energy Management cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_CALENDAR 0x0707U /*!< Calendar cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_DEVICE_MANAGEMENT 0x0708U /*!< Device Management cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_EVENTS 0x0709U /*!< Events cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_MDU_PAIRING 0x070AU /*!< MDU Pairing cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_SUB_GHZ 0x070BU /*!< Sub-GHz cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_DAILY_SCHEDULE 0x070DU /*!< Daily Schedule cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_KEY_ESTABLISHMENT 0x0800U /*!< Key Establishment cluster identifier. */
/* Home Automation */
#define ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS 0x0b02U /*!< Appliance events and alerts cluster identifier */
/* HA specU rev. 29U ver. 1.2 - Electricity MeasurementU not sure that its Electrical Measurement */
#define ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT 0x0b04U /*!< Electrical Measurement cluster identifier. */
#define ZB_ZCL_CLUSTER_ID_DIAGNOSTICS 0x0b05U /*!< Home Automation Diagnostics */
#define ZB_ZCL_CLUSTER_ID_WWAH 0xFC57U /*!< Works with All Hubs cluster identifier */
/** @cond touchlink */
#define ZB_ZCL_CLUSTER_ID_TOUCHLINK_COMMISSIONING 0x1000U /*!< Touchlink Commissioning cluster identifier */
/** @endcond */ /* touchlink */
/************** Manufacturer specific clusters ****************/
#define ZB_ZCL_CLUSTER_ID_TUNNEL 0xfc00U /*!< Manufacturer specific Tunnel cluster */
#define ZB_ZCL_CLUSTER_ID_IR_BLASTER 0xfc01U /*!< Manufacturer specific IR Blaster cluster */
#define ZB_ZCL_CLUSTER_ID_CUSTOM_ATTR 0xffeeU /*!< Custom Attributes */
#define ZB_ZCL_CLUSTER_ID_METER_IDENTIFICATION 0x0B01U /*!< Meter Identification cluster identifier */
/* TODO: define other clusters IDs */
/* Measurements and sensing clusters */
/* Security and safety clusters */
/** @} */
/**
* @brief Type for cluster roles in message exchange.
*
* Holds one of @ref zcl_cluster_id. Kept for backward compatibility as
* @ref zcl_cluster_id were declared previously as enum.
*/
typedef zb_uint16_t zb_zcl_cluster_id_t;
#ifdef ZB_CONTROL4_NETWORK_SUPPORT
#define ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING ((zb_uint16_t)0x0001)
#endif
/** @brief Check whether cluster is manufacturer specific. */
#define ZB_ZCL_IS_CLUSTER_MANUF_SPEC(_cluster_id) ((_cluster_id) > 0xfbff)
/** @brief Internal invalid manufacturer code value. */
#define ZB_ZCL_MANUF_CODE_INVALID 0x0000
/** @brief Parse frame operation status. */
typedef enum zb_zcl_parse_status_e
{
ZB_ZCL_PARSE_STATUS_SUCCESS, /**< Frame parsed successfully. */
ZB_ZCL_PARSE_STATUS_FAILURE /**< Frame parse operation failed. */
} zb_zcl_parse_status_t;
/** @brief Attribute Reporting Status. */
typedef enum zb_zcl_attribute_reporting_status_e
{
ZB_ZCL_AR_STATUS_PENDING = 0x00, /**< Pending. */
ZB_ZCL_AR_STATUS_COMPLETE = 0x01 /**< Attribute Reporting Complete. */
} zb_zcl_attribute_reporting_status_t;
/**
* @name ZCL status values
* @anchor zcl_status
* @see ZCL8 spec, subclause 2.6.3, Table 2-12
* @note The enumeration does not contain statuses not used in ZB HA profile
*/
/** @{ */
#define ZB_ZCL_STATUS_SUCCESS 0x00U /*!< ZCL Success */
#define ZB_ZCL_STATUS_FAIL 0x01U /*!< ZCL Fail */
#define ZB_ZCL_STATUS_NOT_AUTHORIZED 0x7EU /*!< The sender of the command does not have authorization to carry out this command. */
#define ZB_ZCL_STATUS_RESERVED 0x7FU /*!< CCB 2318 a reserved field may be used in the future and then be non-zero. */
#define ZB_ZCL_STATUS_MALFORMED_CMD 0x80U /*!< Malformed command */
#define ZB_ZCL_STATUS_UNSUP_CMD 0x81U /*!< ZCL8: Unsupported command */
#define ZB_ZCL_STATUS_UNSUP_CLUST_CMD 0x81U /*!< ZCL7: Unsupported cluster command, ZCL8: use UNSUP_COMMAND*/
#define ZB_ZCL_STATUS_UNSUP_GEN_CMD 0x82U /*!< ZCL7: Unsupported general command, ZCL8: use UNSUP_COMMAND*/
#define ZB_ZCL_STATUS_UNSUP_MANUF_CLUST_CMD 0x83U /*!< ZCL7: Unsupported manuf-specific clust command, ZCL8: use UNSUP_COMMAND*/
#define ZB_ZCL_STATUS_UNSUP_MANUF_GEN_CMD 0x84U /*!< ZCL7: Unsupported manuf-specific general command, ZCL8: use UNSUP_COMMAND*/
#define ZB_ZCL_STATUS_INVALID_FIELD 0x85U /*!< Invalid field */
#define ZB_ZCL_STATUS_UNSUP_ATTRIB 0x86U /*!< Unsupported attribute */
#define ZB_ZCL_STATUS_INVALID_VALUE 0x87U /*!< Invalid value */
#define ZB_ZCL_STATUS_READ_ONLY 0x88U /*!< Read only */
#define ZB_ZCL_STATUS_INSUFF_SPACE 0x89U /*!< Insufficient space */
#define ZB_ZCL_STATUS_DUPE_EXISTS 0x8aU /*!< ZCL7: Duplicate exists, ZCL8: use SUCCESS*/
#define ZB_ZCL_STATUS_NOT_FOUND 0x8bU /*!< Not found */
#define ZB_ZCL_STATUS_UNREPORTABLE_ATTRIB 0x8cU /*!< Unreportable attribute */
#define ZB_ZCL_STATUS_INVALID_TYPE 0x8dU /*!< Invalid type */
#define ZB_ZCL_STATUS_WRITE_ONLY 0x8fU /*!< ZCL7: Write only, ZCL8: use NOT_AUTHORIZED*/
#define ZB_ZCL_STATUS_INCONSISTENT_STARTUP_STATE 0x90U /*!< ZCL7: The value can put the device in an inconsistent state on startup, ZCL8: FAILURE, CCB 2477 Status Code Cleanup: never used */
#define ZB_ZCL_STATUS_DEFINED_OUT_OF_BAND 0x91U /*!< ZCL7: Out-of-band method to write an attribute, ZCL8: FAILURE, CCB 2477 Status Code Cleanup: never used */
#define ZB_ZCL_STATUS_INCONSISTENT 0x92U /*!< ZCL7: Supplied values are inconsistent, ZCL8: reserved, CCB 2477 Status Code Cleanup: never used */
/** ZCL7: The credentials presented by the device sending the command are not sufficient to perform this
* action.
* ZCL8: use FAILURE*/
#define ZB_ZCL_STATUS_ACTION_DENIED 0x93U
#define ZB_ZCL_STATUS_TIMEOUT 0x94U /*!< Timeout */
#define ZB_ZCL_STATUS_ABORT 0x95U /*!< Abort */
#define ZB_ZCL_STATUS_INVALID_IMAGE 0x96U /*!< Invalid OTA upgrade image */
#define ZB_ZCL_STATUS_WAIT_FOR_DATA 0x97U /*!< Server does not have data block available yet */
/**< No OTA upgrade image available for a particular client. */
#define ZB_ZCL_STATUS_NO_IMAGE_AVAILABLE 0x98U
/** The client still requires more OTA upgrade image files in order to successfully upgrade. */
#define ZB_ZCL_STATUS_REQUIRE_MORE_IMAGE 0x99U
/** The command has been received and is being processed.*/
#define ZB_ZCL_STATUS_NOTIFICATION_PENDING 0x9AU
#define ZB_ZCL_STATUS_HW_FAIL 0xc0U /*!< ZCL7: Hardware failure, ZCL8: use FAILURE */
#define ZB_ZCL_STATUS_SW_FAIL 0xc1U /*!< ZCL7: Software failure, ZCL8: use FAILURE */
#define ZB_ZCL_STATUS_CALIB_ERR 0xc2U /*!< ZCL7: Calibration error, ZCL8: reserved, CCB 2477 Status Code Cleanup: never used */
#define ZB_ZCL_STATUS_UNSUP_CLUST 0xc3U /*!< Cluster is not found on the target endpoint */
#define ZB_ZCL_STATUS_LIMIT_REACHED 0xc4U /*!< ZCL7: Cluster is not found on the target endpoint, ZCL8: use SUCCESS */
/** @} */
/**
* @brief Type for ZCL status values.
*
* Holds one of @ref zcl_status. Kept only for backward compatibility as
* @ref zcl_status were declared previously as enum.
*/
typedef zb_uint8_t zb_zcl_status_t;
/** @brief ZCL global attribute: cluster revision returned by default.
Used if the GLOBAL_CLUSTER_REVISION attribute is undefined for the cluster/role.
*/
#define ZB_ZCL_GLOBAL_CLUSTER_REVISION_DEFAULT 1
/** @brief ZCL pre-ZCL8 API default cluster revision (minimal Cluster revision)
*/
#define ZB_ZCL_CLUSTER_REV_MIN ZB_ZCL_GLOBAL_CLUSTER_REVISION_DEFAULT
/** @brief ZCL unknown peer Cluster revision value
*/
#define ZB_ZCL_PEER_CLUSTER_REV_UNKNOWN 0xFFFFu
/**
* @name ZCL backward compatibility modes
* @anchor zcl_backward_compatibility_modes
* @brief ZCL backward compatibility modes, introduced for ZCL8:
* ZB_ZCL_LEGACY_MODE (default mode) - pre-ZCL8 API sends packets in pre-ZCL8 format as is, no conversion applied
* ZCL8 API transforms packets into format according to the revision set in Cluster revision attribute value
* ZB_ZCL_AUTO_MODE - both pre-ZCL8 API and ZCL8 API transforms packets into format according to revision set in Cluster revision attribute value
* ZB_ZCL_COMPATIBILITY_MODE - both pre-ZCL8 API and ZCL8 API transforms packets into format according to peer Cluster revision provided by the application
* if the peer Cluster revision is greater than Cluster revision attribute value, then the Cluster revision will be used
* if there is no peer Cluster revision, the packet format is converted to the lowest possible Cluster revision
*/
/** @{ */
#define ZB_ZCL_LEGACY_MODE 0x00U /*!< ZBOSS ZCL legacy mode */
#define ZB_ZCL_AUTO_MODE 0x01U /*!< ZBOSS ZCL auto mode */
#define ZB_ZCL_COMPATIBILITY_MODE 0x02U /*!< ZBOSS ZCL compatibility mode */
/** @} */
/**
* @name ZCL backward compatibility status modes
* @anchor zcl_backward_compatibility_status_modes
* @brief ZCL backward compatibility status modes, introduced for ZCL8:
* ZCL8 spec merges some statuses defined in previous ZCL specs into one
* LIMIT_REACHED, DUPLICATE_EXISTS, SUCCESS ==> SUCCESS
* INCONSISTENT_STARTUP_STATE, DEFINED_OUT_OF_BAND, ACTION_DENIED, HARDWARE_FAILURE, SOFTWARE_FAILURE ==> FAILURE
* WRITE_ONLY, NOT_AUTHORIZED ==> NOT_AUTHORIZED
* MALFORMED_COMMAND, INVALID_FIELD ==> INVALID_FIELD
* UNSUP_CLUSTER_COMMAND, UNSUP_GENERAL_COMMAND, UNSUP_MANUF_CLUSTER_COMMAND, UNSUP_MANUF_GENERAL_COMMAND ==> UNSUP_COMMAND
* INCONSISTENT, CALIBRATION_ERROR, RESERVED ==> RESERVED
* There is no well-defined mechanism how to define which version of ZCL is used by the peer. It looks like the optimal solution is to
* send statuses according to ZCL6 and ZCL7 specifications. In that case there will be no miscommunication with legacy devices.
* Other ZCL8 devices should process obsolete statuses correctly because of backward compatibility required by ZCL8 spec.
* If application requires send statuses defined strictly according to ZCL8 spec, the device can be switch to this mode (and vice versa)
* in runtime to ZCL8 statuses mode via zb_zcl_set_backward_compatible_statuses_mode API function
* ZB_ZCL_STATUSES_PRE_ZCL8_MODE (default mode) - statuses will be send according to pre ZCL8 specifications
* ZB_ZCL_STATUSES_ZCL8_MODE - statuses will be send according to ZCL8 specification
*/
/** @{ */
#define ZB_ZCL_STATUSES_PRE_ZCL8_MODE 0x00U /*!< ZBOSS ZCL statuses Pre ZCL8 mode */
#define ZB_ZCL_STATUSES_ZCL8_MODE 0x01U /*!< ZBOSS ZCL statuses ZCL8 mode */
/** @} */
#if defined ZB_ENABLE_HA
/** @brief Discovery manufacture specific command
@param direction - direction 0 (client to server) or 1 (server to client)
@param ep - endpoint number
@param cluster_id - cluster ID
@param manuf_id - manufacture ID
@param recv_cmd_type - need list of received (ZB_TRUE) or generated (ZB_FALSE) command
@param value - (out) pointer to list command ID
@return number of value elements
*/
typedef zb_uint8_t (*zb_zcl_disc_manuf_cmd_cb_t)(
zb_uint8_t direction, zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint16_t manuf_id, zb_bool_t recv_cmd_type, zb_uint8_t **value);
#endif /* ZB_ENABLE_HA */
/********************************** ZCL attributes definitions ************************************/
/** @brief Informs application that some attribute value is being updated by Write attribute command
@param ep - endpoint number
@param cluster_id - cluster ID
@param attr_id - attribute ID of the attribute being updated
@param value - pointer to new data
*/
typedef void (*zb_zcl_modify_attr_value_cb_t)(
zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint16_t attr_id, zb_uint8_t *value);
/*! @defgroup zb_zcl_common_attrs General attributes' description
Types and macros shared among all attributes' definitions.
@{
Use @ref ZB_ZCL_SET_ATTRIBUTE
@par
*/
/** @brief Sets correctly ZCL char string value */
#define ZB_ZCL_SET_STRING_VAL(str, val, len) \
(ZB_MEMCPY((zb_uint8_t*)(str) + 1, (val), (len)), *(zb_uint8_t*)(str) = (len))
/** @brief Get ZCL string length */
#define ZB_ZCL_GET_STRING_LENGTH(str) ((str)[0])
#define ZB_ZCL_SET_STRING_LENGTH(str, _newlen) (((str))[0] = (_newlen))
/** @brief Returns size of a string constant */
#define ZB_ZCL_STRING_CONST_SIZE(str) (zb_uint8_t)(sizeof(str) - 1)
/** Get pointer to first char in the string. */
#define ZB_ZCL_GET_STRING_BEGIN(_str) (&((_str)[1]))
/** Get pointer to (begin + length) char in the string. */
#define ZB_ZCL_GET_STRING_END(_str) (ZB_ZCL_GET_STRING_BEGIN(_str) + ZB_ZCL_GET_STRING_LENGTH(_str))
/** Get pointer to char in string at specified pos. */
#define ZB_ZCL_GET_STRING_REF_AT(_str, _pos) (ZB_ZCL_GET_STRING_BEGIN(_str) + _pos)
/** Get char by specified pos. */
#define ZB_ZCL_GET_STRING_CHAR_AT(_str, _pos) *ZB_ZCL_GET_STRING_REF_AT(_str, _pos)
/** Turn ZCL Octet string into string with null-term. */
#define ZB_ZCL_STRING_TO_C_STRING(_str) \
{ \
zb_uint8_t _len = _str[0]; \
ZB_MEMMOVE(_str, _str + 1, _len); \
_str[_len] = 0; \
}
/** Set size of ZCL Octet String into 0 .*/
#define ZB_ZCL_STRING_CLEAR(_str) (_str[0] = 0)
/** Add some data to ZCL Octet String. */
static ZB_INLINE zb_uint16_t zb_zcl_string_append_data(zb_uint8_t *zcl_str,
zb_uint8_t zcl_str_max_size,
const zb_uint8_t *c_str,
zb_uint8_t c_str_len)
{
zb_uint16_t newlen = ZB_ZCL_GET_STRING_LENGTH(zcl_str) + (zb_uint16_t)c_str_len;
if (newlen < (zb_uint16_t) zcl_str_max_size)
{
ZB_MEMCPY(ZB_ZCL_GET_STRING_END(zcl_str), c_str, c_str_len);
ZB_ZCL_SET_STRING_LENGTH(zcl_str, (zb_uint8_t)newlen);
}
else
{
newlen = 0;
}
return newlen;
}
/** Add single byte to ZCL Octet String. */
static ZB_INLINE zb_uint16_t zb_zcl_string_append_byte(zb_uint8_t *zcl_str,
zb_uint8_t zcl_str_max_size,
zb_uint8_t value)
{
zb_uint16_t newlen = (zb_uint16_t)ZB_ZCL_GET_STRING_LENGTH(zcl_str) + 1U;
if (newlen < (zb_uint16_t) zcl_str_max_size)
{
*ZB_ZCL_GET_STRING_END(zcl_str) = value;
ZB_ASSERT(newlen <= ZB_UINT8_MAX);
ZB_ZCL_SET_STRING_LENGTH(zcl_str, (zb_uint8_t)newlen);
}
else
{
newlen = 0;
}
return newlen;
}
/** Append C-string to ZCL string. */
#define ZB_ZCL_STRING_APPEND_C_STR(_zcl_str, _zcl_str_max_size, _c_str) \
zb_zcl_string_append_data(_zcl_str, _zcl_str_max_size, (const zb_uint8_t *) _c_str, strlen(_c_str))
/** Append C-string to ZCL static string. */
#define ZB_ZCL_STATIC_STRING_APPEND_C_STR(_zcl_s_str, _c_str) \
ZB_ZCL_STRING_APPEND_C_STR((zb_uint8_t *) _zcl_s_str, sizeof(_zcl_s_str), _c_str)
/** Append char to ZCL static string. */
#define ZB_ZCL_STATIC_STRING_APPEND_CHAR(_zcl_s_str, _char) \
zb_zcl_string_append_byte(_zcl_s_str, sizeof(_zcl_s_str), (zb_uint8_t) _char)
/**
* @name ZCL attribute data type values
* @anchor zcl_attr_type
* @note The enumeration is not full, and does not contain ZCL types not used in HA profile.
* @see ZCL spec., subclause 2.5.2, Table 2-10. Data Types
*/
/** @{ */
#define ZB_ZCL_ATTR_TYPE_NULL 0x00U /*!< Null data type */
#define ZB_ZCL_ATTR_TYPE_8BIT 0x08U /*!< 8-bit value data type */
#define ZB_ZCL_ATTR_TYPE_16BIT 0x09U /*!< 16-bit value data type */
#define ZB_ZCL_ATTR_TYPE_24BIT 0x0aU /*!< 24-bit value data type */
#define ZB_ZCL_ATTR_TYPE_32BIT 0x0bU /*!< 32-bit value data type */
#define ZB_ZCL_ATTR_TYPE_40BIT 0x0cU /*!< 40-bit value data type */
#define ZB_ZCL_ATTR_TYPE_48BIT 0x0dU /*!< 48-bit value data type */
#define ZB_ZCL_ATTR_TYPE_56BIT 0x0eU /*!< 56-bit value data type */
#define ZB_ZCL_ATTR_TYPE_64BIT 0x0fU /*!< 64-bit value data type */
#define ZB_ZCL_ATTR_TYPE_BOOL 0x10U /*!< Boolean data type */
#define ZB_ZCL_ATTR_TYPE_8BITMAP 0x18U /*!< 8-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_16BITMAP 0x19U /*!< 16-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_24BITMAP 0x1aU /*!< 24-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_32BITMAP 0x1bU /*!< 32-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_40BITMAP 0x1cU /*!< 40-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_48BITMAP 0x1dU /*!< 48-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_56BITMAP 0x1eU /*!< 56-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_64BITMAP 0x1fU /*!< 64-bit bitmap data type */
#define ZB_ZCL_ATTR_TYPE_U8 0x20U /*!< Unsigned 8-bit value data type */
#define ZB_ZCL_ATTR_TYPE_U16 0x21U /*!< Unsigned 16-bit value data type */
#define ZB_ZCL_ATTR_TYPE_U24 0x22U /*!< Unsigned 24-bit value data type */
#define ZB_ZCL_ATTR_TYPE_U32 0x23U /*!< Unsigned 32-bit value data type */
#define ZB_ZCL_ATTR_TYPE_U40 0x24U /*!< Unsigned 40-bit value data type */
#define ZB_ZCL_ATTR_TYPE_U48 0x25U /*!< Unsigned 48-bit value data type */
#define ZB_ZCL_ATTR_TYPE_U56 0x26U /*!< Unsigned 56-bit value data type */
#define ZB_ZCL_ATTR_TYPE_U64 0x27U /*!< Unsigned 64-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S8 0x28U /*!< Signed 8-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S16 0x29U /*!< Signed 16-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S24 0x2aU /*!< Signed 24-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S32 0x2bU /*!< Signed 32-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S40 0x2cU /*!< Signed 40-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S48 0x2dU /*!< Signed 48-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S56 0x2eU /*!< Signed 56-bit value data type */
#define ZB_ZCL_ATTR_TYPE_S64 0x2fU /*!< Signed 64-bit value data type */
#define ZB_ZCL_ATTR_TYPE_8BIT_ENUM 0x30U /*!< 8-bit enumeration (U8 discrete) data type */
#define ZB_ZCL_ATTR_TYPE_16BIT_ENUM 0x31U /*!< 16-bit enumeration (U16 discrete) data type */
#define ZB_ZCL_ATTR_TYPE_SEMI 0x38U /*!< 2 byte floating point */
#define ZB_ZCL_ATTR_TYPE_SINGLE 0x39U /*!< 4 byte floating point */
#define ZB_ZCL_ATTR_TYPE_DOUBLE 0x3aU /*!< 8 byte floating point */
#define ZB_ZCL_ATTR_TYPE_OCTET_STRING 0x41U /*!< Octet string data type */
#define ZB_ZCL_ATTR_TYPE_CHAR_STRING 0x42U /*!< Character string (array) data type */
#define ZB_ZCL_ATTR_TYPE_LONG_OCTET_STRING 0x43U /*!< Long octet string */
#define ZB_ZCL_ATTR_TYPE_LONG_CHAR_STRING 0x44U /*!< Long character string */
#define ZB_ZCL_ATTR_TYPE_ARRAY 0x48U /*!< Array data type 2 + sum of content len */
#define ZB_ZCL_ATTR_TYPE_STRUCTURE 0x4cU /*!< Structure data type 2 + sum of content len */
#define ZB_ZCL_ATTR_TYPE_SET 0x50U /*!< Collection:set, size = sum of len of content */
#define ZB_ZCL_ATTR_TYPE_BAG 0x51U /*!< Collection:bag, size = sum of len of content */
#define ZB_ZCL_ATTR_TYPE_TIME_OF_DAY 0xe0U /*!< Time of day, 4 bytes */
#define ZB_ZCL_ATTR_TYPE_DATE 0xe1U /*!< Date, 4 bytes */
#define ZB_ZCL_ATTR_TYPE_UTC_TIME 0xe2U /*!< UTC Time, 4 bytes */
#define ZB_ZCL_ATTR_TYPE_CLUSTER_ID 0xe8U /*!< Cluster ID, 2 bytes */
#define ZB_ZCL_ATTR_TYPE_ATTRIBUTE_ID 0xe9U /*!< Attribute ID, 2 bytes */
#define ZB_ZCL_ATTR_TYPE_BACNET_OID 0xeaU /*!< BACnet OID, 4 bytes */
#define ZB_ZCL_ATTR_TYPE_IEEE_ADDR 0xf0U /*!< IEEE address (U64) type */
#define ZB_ZCL_ATTR_TYPE_128_BIT_KEY 0xf1U /*!< 128-bit security key */
/** Custom array of 32 elems data type (now is equal to ZB_ZCL_ATTR_TYPE_ARRAY) */
#define ZB_ZCL_ATTR_TYPE_CUSTOM_32ARRAY 0x4aU
#define ZB_ZCL_ATTR_TYPE_INVALID 0xffU /*!< Invalid data type */
/** @} */
/**
* @brief Type for ZCL attribute data type values.
*
* @deprecated holds one of @ref zcl_attr_type. Kept only for backward compatibility as
* @ref zcl_attr_type were declared previously as enum. Can be removed in future releases.
*/
typedef zb_uint8_t zb_zcl_attr_type_t;
/**
* @name ZCL attribute access values
* @anchor zcl_attr_access
*/
/** @{ */
#define ZB_ZCL_ATTR_ACCESS_READ_ONLY 0x01U
#define ZB_ZCL_ATTR_ACCESS_WRITE_ONLY 0x02U /*!< Attribute is write only */
/** Attribute is read/write */
#define ZB_ZCL_ATTR_ACCESS_READ_WRITE (ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_WRITE_ONLY)
#define ZB_ZCL_ATTR_ACCESS_REPORTING 0x04U /*!< Attribute is allowed for reporting */
/** @cond internals_doc */
/** Attribute is read only, but may be marked as writable due to ZCL specification (using
* ZB_ZCL_SET_ATTR_WRITABLE) */
#define ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL (ZB_ZCL_ATTR_ACCESS_READ_ONLY)
/** @endcond */ /* internals_doc */
#define ZB_ZCL_ATTR_ACCESS_SINGLETON 0x08U /*!< Attribute is singleton */
#define ZB_ZCL_ATTR_ACCESS_SCENE 0x10U /*!< Attribute is accessed through scene */
/* Use free bit in access attribute field to save RAM */
#define ZB_ZCL_ATTR_MANUF_SPEC 0x20U /*!< Attribute is manufacturer specific */
#define ZB_ZCL_ATTR_ACCESS_INTERNAL 0x40U /*!< ZBOSS Internal access only Attribute */
/** @} */
/**
* @brief Type for possible values of ZCL attribute access values.
*
* Holds one of @ref zcl_attr_access. Kept for backward compatibility as
* @ref zcl_attr_access were declared previously as enum.
*/
typedef zb_uint8_t zb_zcl_attr_access_t;
#define ZB_ZCL_ATTR_SET_WITH_ATTR_ID(_set, _id) ((_set << 8) | (_id & 0xFF))
/** @cond internals_doc */
/**
* @brief Sets attribute access type to WRITABLE, if it is optionally permitted.
* @param attr_desc - pointer to attribute descriptor
* @hideinitializer
*/
#define ZB_ZCL_SET_ATTR_WRITABLE(attr_desc) \
{ \
if (attr_desc->access & ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL) \
{ \
attr_desc->access |= ZB_ZCL_ATTR_ACCESS_WRITE_ONLY; \
} \
}
/** @endcond */ /* internals_doc */
/*! @brief ZCL attribute definition structure */
typedef ZB_PACKED_PRE struct zb_zcl_attr_s
{
zb_uint16_t id; /*!< Attribute id */
zb_uint8_t type; /*!< Attribute type see @ref zcl_attr_type */
zb_uint8_t access; /*!< Attribute access options according to @ref zcl_attr_access */
zb_uint16_t manuf_code; /*!< Manufactirer specific ID */
void* data_p; /*!< Pointer to data */
} ZB_PACKED_STRUCT
zb_zcl_attr_t;
/**
* @name Global attributes that are included to each cluster
* @anchor zcl_attr_global
* @see ZCL spec - 6.0
*/
/** @{ */
#define ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID 0xfffdU /*!< Cluster revision */
#define ZB_ZCL_ATTR_GLOBAL_ATTRIBUTE_REPORTING_STATUS_ID 0xfffeU /*!< Attribute reporting status */
/** @} */
/** @brief ZCL 6.0: Default value for cluster revision global attribute,
* see @ref zcl_attr_global
*/
#define ZB_ZCL_CLUSTER_REVISION_DEFAULT 1
/** @cond internals_doc */
/*! @internal @brief Set attribute description.
@param attr_id - attribute identifier (defined individually for any particular cluster).
@param data_ptr - pointer to attribute's value storage.
Creates attribute description value (@ref zb_zcl_attr_s) initialized with provided pointer to
attribute's data.
*/
#define ZB_ZCL_SET_ATTR_DESC(attr_id, data_ptr) ZB_SET_ATTR_DESCR_WITH_##attr_id(data_ptr),
/*! @internal @brief Set manufacturer specific attribute description.
@param attr_id - attribute identifier (defined individually for any particular cluster).
@param attr_type - attribute data type @see @ref zcl_attr_type
@param attr_access - attribute access bitmask @see @ref zcl_attr_access
@param manuf_code - attribute manufacturer specific ID
@param data_ptr - pointer to attribute's value storage.
Creates attribute description value (@ref zb_zcl_attr_s) initialized with provided pointer to
attribute's data.
*/
#define ZB_ZCL_SET_MANUF_SPEC_ATTR_DESC(attr_id, attr_type, attr_access, manuf_code, data_ptr) \
{ \
attr_id, \
attr_type, \
attr_access | ZB_ZCL_ATTR_MANUF_SPEC, \
(manuf_code), \
(void*) data_ptr \
},
/*! @internal @brief Start declaration of attributes list */
#define ZB_ZCL_START_DECLARE_ATTRIB_LIST(attrs_desc_name) \
zb_uint16_t cluster_revision_##attrs_desc_name = ZB_ZCL_CLUSTER_REVISION_DEFAULT; \
zb_zcl_attr_t attrs_desc_name [] = { \
{ \
ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID, \
ZB_ZCL_ATTR_TYPE_U16, \
ZB_ZCL_ATTR_ACCESS_READ_ONLY, \
ZB_ZCL_NON_MANUFACTURER_SPECIFIC, \
(void*) &(cluster_revision_##attrs_desc_name) \
},
/*! @internal @brief Start declaration of static attributes list */
#define ZB_ZCL_START_DECLARE_ATTRIB_LIST_STATIC(attrs_desc_name) \
static zb_uint16_t cluster_revision_##attrs_desc_name = ZB_ZCL_CLUSTER_REVISION_DEFAULT; \
static zb_zcl_attr_t attrs_desc_name [] = { \
{ \
ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID, \
ZB_ZCL_ATTR_TYPE_U16, \
ZB_ZCL_ATTR_ACCESS_READ_ONLY, \
ZB_ZCL_NON_MANUFACTURER_SPECIFIC, \
(void*) &(cluster_revision_##attrs_desc_name) \
},
/** @endcond */ /* internals_doc */
/*! @brief Start declaration of attributes list with cluster revision */
#define ZB_ZCL_START_DECLARE_ATTRIB_LIST_CLUSTER_REVISION(attrs_desc_name, cluster_name) \
zb_uint16_t cluster_revision_##attrs_desc_name = cluster_name##_CLUSTER_REVISION_DEFAULT; \
zb_zcl_attr_t attrs_desc_name [] = { \
{ \
ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID, \
ZB_ZCL_ATTR_TYPE_U16, \
ZB_ZCL_ATTR_ACCESS_READ_ONLY, \
ZB_ZCL_NON_MANUFACTURER_SPECIFIC, \
(void*) &(cluster_revision_##attrs_desc_name) \
},
/** @cond internals_doc */
/*! @internal @brief Start declaration of static attributes list with cluster revision */
#define ZB_ZCL_START_DECLARE_ATTRIB_LIST_CLUSTER_REVISION_STATIC(attrs_desc_name, cluster_name) \
static zb_uint16_t cluster_revision_##attrs_desc_name = cluster_name##_CLUSTER_REVISION_DEFAULT; \
static zb_zcl_attr_t attrs_desc_name [] = { \
{ \
ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID, \
ZB_ZCL_ATTR_TYPE_U16, \
ZB_ZCL_ATTR_ACCESS_READ_ONLY, \
ZB_ZCL_NON_MANUFACTURER_SPECIFIC, \
(void*) &(cluster_revision_##attrs_desc_name) \
},
/*! @internal @brief End declaration of attributes list */
#define ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST \
{ \
ZB_ZCL_NULL_ID, \
0, \
0, \
ZB_ZCL_NON_MANUFACTURER_SPECIFIC, \
NULL \
} \
}
#define ZB_ZCL_SET_ATTR_DESC_M(id, data_ptr, type, attr) \
{ \
(id), (type), (attr), ZB_ZCL_NON_MANUFACTURER_SPECIFIC, (data_ptr) \
},
#if !(defined ZB_ZCL_DISABLE_REPORTING) || defined(DOXYGEN)
/*! @internal @brief Check, if attribute is reportable */
#define ZB_ZCL_IS_ATTR_REPORTABLE(attr_desc) ((attr_desc)->access & ZB_ZCL_ATTR_ACCESS_REPORTING)
#endif
/*! @internal @brief Check, if attribute is singleton */
#define ZB_ZCL_IS_ATTR_SINGLETON(attr_desc) ZB_BIT_IS_SET((attr_desc)->access, ZB_ZCL_ATTR_ACCESS_SINGLETON)
/*! @internal @brief Check, if attribute is accessed through scene */
#define ZB_ZCL_IS_ATTR_SCENE_ACCESSED(attr_desc) ZB_BIT_IS_SET((attr_desc)->access, ZB_ZCL_ATTR_ACCESS_SCENE)
/*! @internal @brief Check, if attribute is manufacturer specific */
#define ZB_ZCL_IS_ATTR_MANUF_SPEC(attr_desc) ZB_BIT_IS_SET((attr_desc)->access, ZB_ZCL_ATTR_MANUF_SPEC)
/*! Mark attribute ID to distinguish if it is common/manufacturer
specific/internal attribute:
- set bit 15 (the highest) for internal attributes
- set bit 14 for manufacturer specific attributes
*/
/*! @internal @brief Mark attribute Id as custom/manufacture specific attribute */
#define ZB_ZCL_ATTR_INTERNAL_ID(_attr_id) ((_attr_id) | (1U << 15))
/*! @internal @brief Check if attribute Id is custom/manufacture specific */
#define ZB_ZCL_ATTR_CHECK_INTERNAL_ID(_attr_id) ((_attr_id) & (1U << 15))
/*! @internal @brief Mark attribute Id as custom/manufacture specific attribute */
#define ZB_ZCL_ATTR_CUSTOM_ID(_attr_id) ((_attr_id) | (1U << 14))
/*! @internal @brief Check if attribute Id is custom/manufacture specific */
#define ZB_ZCL_ATTR_CHECK_CUSTOM_ID(_attr_id) ((_attr_id) & (1U << 14))
/*! @internal @brief Start number for custom attributes */
#define ZB_ZCL_ATTR_CUSTOM_START_NUMBER 0xfff0
/*! @internal @brief Check boolean type attribute value */
#define ZB_ZCL_CHECK_BOOL_VALUE(x) ((x) == ZB_FALSE || (x) == ZB_TRUE)
/** @endcond */ /* internals_doc */
/**
* @brief Sets attribute value, perform all needed checks before and after setting new value,
* including read-only check and marking for reporting.
* @param ep - end point number.
* @param cluster_id - cluster identifier.
* @param cluster_role - role (see @ref zcl_cluster_role)
* @param attr_id - attribute identifier.
* @param value_ptr - pointer to new attribute value.
* @param check_access - boolean flag to specify if to perform access check or not.
* @hideinitializer
*/
#define ZB_ZCL_SET_ATTRIBUTE(ep, cluster_id, cluster_role, attr_id, value_ptr, check_access) \
ZVUNUSED(zb_zcl_set_attr_val(ep, cluster_id, cluster_role, attr_id, value_ptr, check_access))
/**
* @brief Set attribute 8-bit value without any check. Use this macro
* on your own risk, if and only if you are absolutely sure that no check for Access
* rights, Reporting and attribute type is needed.
* @param attr_desc - pointer to an attribute description structure @ref zb_zcl_attr_s.
* @param value - 8-bit value to be set.
* @hideinitializer
*/
#define ZB_ZCL_SET_DIRECTLY_ATTR_VAL8(attr_desc, value) \
(*(zb_uint8_t*)attr_desc->data_p = (zb_uint8_t)(value))
/**
* @brief Set attribute 16-bit value without any check. Use this macro
* on your own risk, if and only if you are absolutely sure that no check for Access
* rights, Reporting and attribute type is needed.
* @param attr_desc - pointer to an attribute description structure @ref zb_zcl_attr_s.
* @param value - 16-bit value to be set.
* @hideinitializer
*/
#define ZB_ZCL_SET_DIRECTLY_ATTR_VAL16(attr_desc, value) \
(*(zb_uint16_t*)attr_desc->data_p = (zb_uint16_t)(value))
/**
* @brief Set attribute 32-bit value without any check. Use this macro
* on your own risk, if and only if you are absolutely sure that no check for Access
* rights, Reporting and attribute type is needed.
* @param attr_desc - pointer to an attribute description structure @ref zb_zcl_attr_s.
* @param value - 32-bit value to be set.
* @hideinitializer
*/
#define ZB_ZCL_SET_DIRECTLY_ATTR_VAL32(attr_desc, value) \
(*(zb_uint32_t*)attr_desc->data_p = (zb_uint32_t)(value))
/*! Get 8-bit unsigned attribute value (without any check) */
#define ZB_ZCL_GET_ATTRIBUTE_VAL_8(attr_desc) \
(*(zb_uint8_t*)attr_desc->data_p)
/*! Get 8-bit signed attribute value (without any check) */
#define ZB_ZCL_GET_ATTRIBUTE_VAL_S8(attr_desc) \
(*(zb_int8_t*)attr_desc->data_p)
/*! Get 16-bit unsigned attribute value (without any check) */
#define ZB_ZCL_GET_ATTRIBUTE_VAL_16(attr_desc) \
(*(zb_uint16_t*)attr_desc->data_p)
/*! Get 16-bit signed attribute value (without any check) */
#define ZB_ZCL_GET_ATTRIBUTE_VAL_S16(attr_desc) \
(*(zb_int16_t*)attr_desc->data_p)
/*! Get 32-bit unsigned attribute value (without any check) */
#define ZB_ZCL_GET_ATTRIBUTE_VAL_32(attr_desc) \
(*(zb_uint32_t*)attr_desc->data_p)
/*! Get 32-bit unsigned attribute value (without any check) */
#define ZB_ZCL_GET_ATTRIBUTE_VAL_S32(attr_desc) \
(*(zb_int32_t*)attr_desc->data_p)
/*! @} */ /* General attributes' description */
/************************************** ZCL frame definitions ************************************/
/*! @defgroup zb_zcl_common_frame General frame description
Types and macros required for ZCL frame manipulations
@{
*/
/** @cond internals_doc */
/*! @brief ZCL header size */
#define ZB_ZCL_GET_HEADER_SIZE(frm_ctl) \
( (ZB_ZCL_IS_MANUF_SPECIFIC(frm_ctl)) \
? sizeof(zb_zcl_frame_hdr_full_t) \
: sizeof(zb_zcl_frame_hdr_short_t))
/** @internal @brief Cuts ZCL header form a buffer. */
#define ZB_ZCL_CUT_HEADER(buf) \
(void)zb_buf_cut_left(buf, ZB_ZCL_GET_HEADER_SIZE(*(zb_uint8_t*)zb_buf_begin(buf)))
/** @endcond */ /* internals_doc */
/** @name ZCL frame type
* @brief Defines Permitted values for Frame Type subfield of Frame Control field in ZCL frame.
* @anchor zcl_frame_type
*/
/** @{ */
#define ZB_ZCL_FRAME_TYPE_COMMON 0x00U /*!< Command acts across the entire profile */
#define ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC 0x01U /*!< Command is specific to a cluster */