7 #include <zcl/zb-zcl-type.h>
8 #include <zcl/zb-zcl-attribute-type.h>
12 #include "zb-common.h"
13 #include "zcl/zb-zcl-type.h"
15 API const char* zb_get_cluster_name(int id)
17 const char* clust_name = NULL;
20 case ZB_ZCL_BASIC_CLUSTER_ID:
21 clust_name = "ZB_ZCL_BASIC_CLUSTER_ID : 0x0000";
23 case ZB_ZCL_POWER_CONFIG_CLUSTER_ID:
24 clust_name = "ZB_ZCL_POWER_CONFIG_CLUSTER_ID : 0x0001";
26 case ZB_ZCL_DEVICE_TEMP_CLUSTER_ID:
27 clust_name = "ZB_ZCL_DEVICE_TEMP_CLUSTER_ID : 0x0002";
29 case ZB_ZCL_IDENTIFY_CLUSTER_ID:
30 clust_name = "ZB_ZCL_IDENTIFY_CLUSTER_ID : 0x0003";
32 case ZB_ZCL_GROUPS_CLUSTER_ID:
33 clust_name = "ZB_ZCL_GROUPS_CLUSTER_ID : 0x0004";
35 case ZB_ZCL_SCENES_CLUSTER_ID:
36 clust_name = "ZB_ZCL_SCENES_CLUSTER_ID : 0x0005";
38 case ZB_ZCL_ON_OFF_CLUSTER_ID:
39 clust_name = "ZB_ZCL_ON_OFF_CLUSTER_ID : 0x0006";
41 case ZB_ZCL_ON_OFF_SWITCH_CONFIG_CLUSTER_ID:
42 clust_name = "ZB_ZCL_ON_OFF_SWITCH_CONFIG_CLUSTER_ID : 0x0007";
44 case ZB_ZCL_LEVEL_CONTROL_CLUSTER_ID:
45 clust_name = "ZB_ZCL_LEVEL_CONTROL_CLUSTER_ID : 0x0008";
47 case ZB_ZCL_ALARM_CLUSTER_ID:
48 clust_name = "ZB_ZCL_ALARM_CLUSTER_ID : 0x0009";
50 case ZB_ZCL_TIME_CLUSTER_ID:
51 clust_name = "ZB_ZCL_TIME_CLUSTER_ID : 0x000A";
53 case ZB_ZCL_RSSI_LOCATION_CLUSTER_ID:
54 clust_name = "ZB_ZCL_RSSI_LOCATION_CLUSTER_ID : 0x000B";
56 case ZB_ZCL_BINARY_INPUT_BASIC_CLUSTER_ID:
57 clust_name = "ZB_ZCL_BINARY_INPUT_BASIC_CLUSTER_ID : 0x000F";
59 case ZB_ZCL_COMMISSIONING_CLUSTER_ID:
60 clust_name = "ZB_ZCL_COMMISSIONING_CLUSTER_ID : 0x0015";
62 case ZB_ZCL_PARTITION_CLUSTER_ID:
63 clust_name = "ZB_ZCL_PARTITION_CLUSTER_ID : 0x0016";
65 case ZB_ZCL_OTA_BOOTLOAD_CLUSTER_ID:
66 clust_name = "ZB_ZCL_OTA_BOOTLOAD_CLUSTER_ID : 0x0019";
68 case ZB_ZCL_POWER_PROFILE_CLUSTER_ID:
69 clust_name = "ZB_ZCL_POWER_PROFILE_CLUSTER_ID : 0x001A";
71 case ZB_ZCL_APPLIANCE_CONTROL_CLUSTER_ID:
72 clust_name = "ZB_ZCL_APPLIANCE_CONTROL_CLUSTER_ID : 0x001B";
74 case ZB_ZCL_POLL_CONTROL_CLUSTER_ID:
75 clust_name = "ZB_ZCL_POLL_CONTROL_CLUSTER_ID : 0x0020";
77 case ZB_ZCL_SHADE_CONFIG_CLUSTER_ID:
78 clust_name = "ZB_ZCL_SHADE_CONFIG_CLUSTER_ID : 0x0100";
80 case ZB_ZCL_DOOR_LOCK_CLUSTER_ID:
81 clust_name = "ZB_ZCL_DOOR_LOCK_CLUSTER_ID : 0x0101";
83 case ZB_ZCL_WINDOW_COVERING_CLUSTER_ID:
84 clust_name = "ZB_ZCL_WINDOW_COVERING_CLUSTER_ID : 0x0102";
86 case ZB_ZCL_PUMP_CONFIG_CONTROL_CLUSTER_ID:
87 clust_name = "ZB_ZCL_PUMP_CONFIG_CONTROL_CLUSTER_ID : 0x0200";
89 case ZB_ZCL_THERMOSTAT_CLUSTER_ID:
90 clust_name = "ZB_ZCL_THERMOSTAT_CLUSTER_ID : 0x0201";
92 case ZB_ZCL_FAN_CONTROL_CLUSTER_ID:
93 clust_name = "ZB_ZCL_FAN_CONTROL_CLUSTER_ID : 0x0202";
95 case ZB_ZCL_DEHUMID_CONTROL_CLUSTER_ID:
96 clust_name = "ZB_ZCL_DEHUMID_CONTROL_CLUSTER_ID : 0x0203";
98 case ZB_ZCL_THERMOSTAT_UI_CONFIG_CLUSTER_ID:
99 clust_name = "ZB_ZCL_THERMOSTAT_UI_CONFIG_CLUSTER_ID : 0x0204";
101 case ZB_ZCL_COLOR_CONTROL_CLUSTER_ID:
102 clust_name = "ZB_ZCL_COLOR_CONTROL_CLUSTER_ID : 0x0300";
104 case ZB_ZCL_BALLAST_CONFIGURATION_CLUSTER_ID:
105 clust_name = "ZB_ZCL_BALLAST_CONFIGURATION_CLUSTER_ID : 0x0301";
107 case ZB_ZCL_ILLUM_MEASUREMENT_CLUSTER_ID:
108 clust_name = "ZB_ZCL_ILLUM_MEASUREMENT_CLUSTER_ID : 0x0400";
110 case ZB_ZCL_ILLUM_LEVEL_SENSING_CLUSTER_ID:
111 clust_name = "ZB_ZCL_ILLUM_LEVEL_SENSING_CLUSTER_ID : 0x0401";
113 case ZB_ZCL_TEMP_MEASUREMENT_CLUSTER_ID:
114 clust_name = "ZB_ZCL_TEMP_MEASUREMENT_CLUSTER_ID : 0x0402";
116 case ZB_ZCL_PRESSURE_MEASUREMENT_CLUSTER_ID:
117 clust_name = "ZB_ZCL_PRESSURE_MEASUREMENT_CLUSTER_ID : 0x0403";
119 case ZB_ZCL_FLOW_MEASUREMENT_CLUSTER_ID:
120 clust_name = "ZB_ZCL_FLOW_MEASUREMENT_CLUSTER_ID : 0x0404";
122 case ZB_ZCL_RELATIVE_HUMIDITY_MEASUREMENT_CLUSTER_ID:
123 clust_name = "ZB_ZCL_RELATIVE_HUMIDITY_MEASUREMENT_CLUSTER_ID : 0x0405";
125 case ZB_ZCL_OCCUPANCY_SENSING_CLUSTER_ID:
126 clust_name = "ZB_ZCL_OCCUPANCY_SENSING_CLUSTER_ID : 0x0406";
128 case ZB_ZCL_IAS_ZONE_CLUSTER_ID:
129 clust_name = "ZB_ZCL_IAS_ZONE_CLUSTER_ID : 0x0500";
131 case ZB_ZCL_IAS_ACE_CLUSTER_ID:
132 clust_name = "ZB_ZCL_IAS_ACE_CLUSTER_ID : 0x0501";
134 case ZB_ZCL_IAS_WD_CLUSTER_ID:
135 clust_name = "ZB_ZCL_IAS_WD_CLUSTER_ID : 0x0502";
137 case ZB_ZCL_GENERIC_TUNNEL_CLUSTER_ID:
138 clust_name = "ZB_ZCL_GENERIC_TUNNEL_CLUSTER_ID : 0x0600";
140 case ZB_ZCL_BACNET_PROTOCOL_TUNNEL_CLUSTER_ID:
141 clust_name = "ZB_ZCL_BACNET_PROTOCOL_TUNNEL_CLUSTER_ID : 0x0601";
143 case ZB_ZCL_11073_PROTOCOL_TUNNEL_CLUSTER_ID:
144 clust_name = "ZB_ZCL_11073_PROTOCOL_TUNNEL_CLUSTER_ID : 0x0614";
146 case ZB_ZCL_ISO7816_PROTOCOL_TUNNEL_CLUSTER_ID:
147 clust_name = "ZB_ZCL_ISO7816_PROTOCOL_TUNNEL_CLUSTER_ID : 0x0615";
149 case ZB_ZCL_PRICE_CLUSTER_ID:
150 clust_name = "ZB_ZCL_PRICE_CLUSTER_ID : 0x0700";
152 case ZB_ZCL_DEMAND_RESPONSE_LOAD_CONTROL_CLUSTER_ID:
153 clust_name = "ZB_ZCL_DEMAND_RESPONSE_LOAD_CONTROL_CLUSTER_ID : 0x0701";
155 case ZB_ZCL_SIMPLE_METERING_CLUSTER_ID:
156 clust_name = "ZB_ZCL_SIMPLE_METERING_CLUSTER_ID : 0x0702";
158 case ZB_ZCL_MESSAGING_CLUSTER_ID:
159 clust_name = "ZB_ZCL_MESSAGING_CLUSTER_ID : 0x0703";
161 case ZB_ZCL_TUNNELING_CLUSTER_ID:
162 clust_name = "ZB_ZCL_TUNNELING_CLUSTER_ID : 0x0704";
164 case ZB_ZCL_PREPAYMENT_CLUSTER_ID:
165 clust_name = "ZB_ZCL_PREPAYMENT_CLUSTER_ID : 0x0705";
167 case ZB_ZCL_ENERGY_MANAGEMENT_CLUSTER_ID:
168 clust_name = "ZB_ZCL_ENERGY_MANAGEMENT_CLUSTER_ID : 0x0706";
170 case ZB_ZCL_TOU_CALENDAR_CLUSTER_ID:
171 clust_name = "ZB_ZCL_TOU_CALENDAR_CLUSTER_ID : 0x0707";
173 case ZB_ZCL_DEVICE_MANAGEMENT_CLUSTER_ID:
174 clust_name = "ZB_ZCL_DEVICE_MANAGEMENT_CLUSTER_ID : 0x0708";
176 case ZB_ZCL_EVENTS_CLUSTER_ID:
177 clust_name = "ZB_ZCL_EVENTS_CLUSTER_ID : 0x0709";
179 case ZB_ZCL_MDU_PAIRING_CLUSTER_ID:
180 clust_name = "ZB_ZCL_MDU_PAIRING_CLUSTER_ID : 0x070A";
182 case ZB_ZCL_KEY_ESTABLISHMENT_CLUSTER_ID:
183 clust_name = "ZB_ZCL_KEY_ESTABLISHMENT_CLUSTER_ID : 0x0800";
185 case ZB_ZCL_INFORMATION_CLUSTER_ID:
186 clust_name = "ZB_ZCL_INFORMATION_CLUSTER_ID : 0x0900";
188 case ZB_ZCL_DATA_SHARING_CLUSTER_ID:
189 clust_name = "ZB_ZCL_DATA_SHARING_CLUSTER_ID : 0x0901";
191 case ZB_ZCL_GAMING_CLUSTER_ID:
192 clust_name = "ZB_ZCL_GAMING_CLUSTER_ID : 0x0902";
194 case ZB_ZCL_DATA_RATE_CONTROL_CLUSTER_ID:
195 clust_name = "ZB_ZCL_DATA_RATE_CONTROL_CLUSTER_ID : 0x0903";
197 case ZB_ZCL_VOICE_OVER_ZIGBEE_CLUSTER_ID:
198 clust_name = "ZB_ZCL_VOICE_OVER_ZIGBEE_CLUSTER_ID : 0x0904";
200 case ZB_ZCL_CHATTING_CLUSTER_ID:
201 clust_name = "ZB_ZCL_CHATTING_CLUSTER_ID : 0x0905";
203 case ZB_ZCL_PAYMENT_CLUSTER_ID:
204 clust_name = "ZB_ZCL_PAYMENT_CLUSTER_ID : 0x0A01";
206 case ZB_ZCL_BILLING_CLUSTER_ID:
207 clust_name = "ZB_ZCL_BILLING_CLUSTER_ID : 0x0A02";
209 case ZB_ZCL_APPLIANCE_IDENTIFICATION_CLUSTER_ID:
210 clust_name = "ZB_ZCL_APPLIANCE_IDENTIFICATION_CLUSTER_ID : 0x0B00";
212 case ZB_ZCL_METER_IDENTIFICATION_CLUSTER_ID:
213 clust_name = "ZB_ZCL_DATA_RATE_CONTROL_CLUSTER_ID : 0x0B01";
215 case ZB_ZCL_APPLIANCE_EVENTS_AND_ALERT_CLUSTER_ID:
216 clust_name = "ZB_ZCL_APPLIANCE_EVENTS_AND_ALERT_CLUSTER_ID : 0x0B02";
218 case ZB_ZCL_APPLIANCE_STATISTICS_CLUSTER_ID:
219 clust_name = "ZB_ZCL_APPLIANCE_STATISTICS_CLUSTER_ID : 0x0905";
221 case ZB_ZCL_ELECTRICAL_MEASUREMENT_CLUSTER_ID:
222 clust_name = "ZB_ZCL_ELECTRICAL_MEASUREMENT_CLUSTER_ID : 0x0B04";
224 case ZB_ZCL_DIAGNOSTICS_CLUSTER_ID:
225 clust_name = "ZB_ZCL_DIAGNOSTICS_CLUSTER_ID : 0x0B05";
227 case ZB_ZCL_ZLL_COMMISSIONING_CLUSTER_ID:
228 clust_name = "ZB_ZCL_ZLL_COMMISSIONING_CLUSTER_ID : 0x1000";
231 clust_name = "UNDEFINED_CLUSTER";
238 typedef struct _attr_type_size {
243 static AttrTypeSize attribute_sizes[] = {
244 {ZB_ZCL_NO_DATA_ATTRIBUTE_TYPE, 0},
245 {ZB_ZCL_8_BIT_DATA, 1},
246 {ZB_ZCL_16_BIT_DATA, 2},
247 {ZB_ZCL_24_BIT_DATA, 3},
248 {ZB_ZCL_32_BIT_DATA, 4},
249 {ZB_ZCL_40_BIT_DATA, 5},
250 {ZB_ZCL_48_BIT_DATA, 6},
251 {ZB_ZCL_56_BIT_DATA, 7},
252 {ZB_ZCL_64_BIT_DATA, 8},
254 {ZB_ZCL_8_BIT_BITMAP, 1},
255 {ZB_ZCL_16_BIT_BITMAP, 2},
256 {ZB_ZCL_24_BIT_BITMAP, 3},
257 {ZB_ZCL_32_BIT_BITMAP, 4},
258 {ZB_ZCL_40_BIT_BITMAP, 5},
259 {ZB_ZCL_48_BIT_BITMAP, 6},
260 {ZB_ZCL_56_BIT_BITMAP, 7},
261 {ZB_ZCL_64_BIT_BITMAP, 8},
262 {ZB_ZCL_UNSIGNED_8_BIT_INTEGER, 1},
263 {ZB_ZCL_UNSIGNED_16_BIT_INTEGER, 2},
264 {ZB_ZCL_UNSIGNED_24_BIT_INTEGER, 3},
265 {ZB_ZCL_UNSIGNED_32_BIT_INTEGER, 4},
266 {ZB_ZCL_UNSIGNED_40_BIT_INTEGER, 5},
267 {ZB_ZCL_UNSIGNED_48_BIT_INTEGER, 6},
268 {ZB_ZCL_UNSIGNED_56_BIT_INTEGER, 7},
269 {ZB_ZCL_UNSIGNED_64_BIT_INTEGER, 8},
270 {ZB_ZCL_SIGNED_8_BIT_INTEGER, 1},
271 {ZB_ZCL_SIGNED_16_BIT_INTEGER, 2},
272 {ZB_ZCL_SIGNED_24_BIT_INTEGER, 3},
273 {ZB_ZCL_SIGNED_32_BIT_INTEGER, 4},
274 {ZB_ZCL_SIGNED_40_BIT_INTEGER, 5},
275 {ZB_ZCL_SIGNED_48_BIT_INTEGER, 6},
276 {ZB_ZCL_SIGNED_56_BIT_INTEGER, 7},
277 {ZB_ZCL_SIGNED_64_BIT_INTEGER, 8},
278 {ZB_ZCL_8_BIT_ENUMERATION, 1},
279 {ZB_ZCL_16_BIT_ENUMERATION, 2},
280 {ZB_ZCL_SEMI_PRECISION, 2},
281 {ZB_ZCL_SINGLE_PRECISION, 4},
282 {ZB_ZCL_DOUBLE_PRECISION, 8},
283 {ZB_ZCL_TIME_OF_DAY, 4},
285 {ZB_ZCL_UTC_TIME, 4},
286 {ZB_ZCL_CLUSTER_ID, 2},
287 {ZB_ZCL_ATTRIBUTE_ID, 2},
288 {ZB_ZCL_BACNET_OID, 4},
289 {ZB_ZCL_IEEE_ADDRESS, 8},
290 {ZB_ZCL_128_BIT_SECURITY_KEY, 16},
293 static unsigned char analog_discrete_thresholds[] = {
294 0x07, DATA_TYPE_NONE,
295 0x1F, DATA_TYPE_DISCRETE,
296 0x2F, DATA_TYPE_ANALOG,
297 0x37, DATA_TYPE_DISCRETE,
298 0x3F, DATA_TYPE_ANALOG,
299 0x57, DATA_TYPE_DISCRETE,
300 0xDF, DATA_TYPE_NONE,
301 0xE7, DATA_TYPE_ANALOG,
305 API int zb_get_analog_or_discret(unsigned char type)
309 while (analog_discrete_thresholds[index] < type)
312 return analog_discrete_thresholds[index+1];
315 API int zb_get_data_size(unsigned char type)
318 int count = (int)(sizeof(attribute_sizes) / 2);
319 for (i = 0; i < count; i++) {
320 if (attribute_sizes[i].type == type)
321 return attribute_sizes[i].size;
326 API int zb_create_read_attr_status_record(read_attr_status_record_h *handle)
328 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
329 read_attr_status_record_h simple = calloc(1, sizeof(struct read_attribute_status_record_s));
330 RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
332 return ZIGBEE_ERROR_NONE;
335 API void zb_destroy_read_attr_status_record(read_attr_status_record_h handle)
337 RET_IF(NULL == handle);
343 API int zb_get_id_from_read_attr_status_record(read_attr_status_record_h handle,
346 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
347 RETV_IF(NULL == id, ZIGBEE_ERROR_INVALID_PARAMETER);
349 return ZIGBEE_ERROR_NONE;
352 API int zb_set_id_to_read_attr_status_record(read_attr_status_record_h handle,
355 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
357 return ZIGBEE_ERROR_NONE;
360 API int zb_get_status_from_read_attr_status_record(read_attr_status_record_h handle,
361 unsigned char* status)
363 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
364 RETV_IF(NULL == status, ZIGBEE_ERROR_INVALID_PARAMETER);
365 *status = handle->status;
366 return ZIGBEE_ERROR_NONE;
369 API int zb_set_status_to_read_attr_status_record(read_attr_status_record_h handle,
370 unsigned char status)
372 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
373 handle->status = status;
374 return ZIGBEE_ERROR_NONE;
377 API int zb_get_type_from_read_attr_status_record(read_attr_status_record_h handle,
380 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
381 RETV_IF(NULL == type, ZIGBEE_ERROR_INVALID_PARAMETER);
382 *type = handle->type;
383 return ZIGBEE_ERROR_NONE;
386 API int zb_set_type_to_read_attr_status_record(read_attr_status_record_h handle,
389 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
391 return ZIGBEE_ERROR_NONE;
394 API int zb_get_value_from_read_attr_status_record(read_attr_status_record_h handle,
395 unsigned char type, zb_value_h value)
399 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
400 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
401 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_NO_DATA);
403 len = zb_get_data_size(type);
405 memcpy(value->val, handle->value, len);
408 } else if (ZB_ZCL_OCTAT_STRING == type || ZB_ZCL_CHRACTER_STRING == type) {
414 value->str = calloc(1, sizeof(struct attribute_str_s));
415 RETV_IF(NULL == value->str, ZIGBEE_ERROR_OUT_OF_MEMORY);
416 value->str->n = *handle->value;
417 /* The first 1 byte indicate invalid or length of string */
418 if (0xff == value->str->n) {
420 return ZIGBEE_ERROR_NO_DATA;
422 value->str->v = calloc(value->str->n+1, 1);
423 if (NULL == value->str->v) {
425 return ZIGBEE_ERROR_OUT_OF_MEMORY;
427 memcpy(value->str->v, handle->value+sizeof(value->str->n), value->str->n);
430 value->size = value->str->n;
431 } else if (ZB_ZCL_LONG_OCTAT_STRING == type || ZB_ZCL_LONG_CHRACTER_STRING == type) {
434 free(value->wstr->v);
437 value->wstr = calloc(1, sizeof(struct attribute_wstr_s));
438 RETV_IF(NULL == value->wstr, ZIGBEE_ERROR_OUT_OF_MEMORY);
439 value->wstr->n = *(handle->value+1) << 8 | *handle->value;
440 /* The first 2 byte indicate invalid or length of string */
441 if (0xffff == value->wstr->n) {
443 return ZIGBEE_ERROR_NO_DATA;
445 value->wstr->v = calloc(value->wstr->n+1, 1);
446 if (NULL == value->wstr->v) {
448 return ZIGBEE_ERROR_OUT_OF_MEMORY;
450 memcpy(value->wstr->v, handle->value+sizeof(value->wstr->n), value->wstr->n);
453 value->size = value->wstr->n;
455 return ZIGBEE_ERROR_NOT_SUPPORTED;
457 return ZIGBEE_ERROR_NONE;
460 API int zb_set_value_to_read_attr_status_record(read_attr_status_record_h handle,
461 unsigned char type, zb_value_h value)
465 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
466 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
471 len = zb_get_data_size(type);
473 handle->value = calloc(len, sizeof(char));
474 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
475 memcpy(handle->value, value->val, len);
476 } else if (ZB_ZCL_OCTAT_STRING == type || ZB_ZCL_CHRACTER_STRING == type) {
477 RETV_IF(NULL == value->str, ZIGBEE_ERROR_NO_DATA);
478 handle->value = calloc(value->str->n + sizeof(value->str->n), sizeof(char));
479 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
480 handle->value[0] = value->str->n;
481 memcpy(handle->value + sizeof(value->str->n),
482 value->str->v+sizeof(value->str->n), value->str->n);
483 } else if (ZB_ZCL_LONG_OCTAT_STRING == type || ZB_ZCL_LONG_CHRACTER_STRING == type) {
484 RETV_IF(NULL == value->wstr, ZIGBEE_ERROR_NO_DATA);
485 handle->value = calloc(value->wstr->n + sizeof(value->wstr->n), sizeof(char));
486 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
487 handle->value[0] = value->wstr->n & 0xff;
488 handle->value[1] = (value->wstr->n >> 8) & 0xff ;
489 memcpy(handle->value + sizeof(value->wstr->n),
490 value->wstr->v+sizeof(value->wstr->n), value->wstr->n);
492 return ZIGBEE_ERROR_NOT_SUPPORTED;
494 return ZIGBEE_ERROR_NONE;
497 API int zb_create_value(zb_value_h *handle)
499 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
500 zb_value_h simple = calloc(1, sizeof(struct zb_value_s));
501 RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
503 return ZIGBEE_ERROR_NONE;
506 API void zb_destroy_value(zb_value_h handle)
508 RET_IF(NULL == handle);
511 free(handle->str->v);
516 free(handle->wstr->v);
522 API int zb_set_value(zb_value_h handle, unsigned char type, unsigned char *value,
527 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
528 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
530 len = zb_get_data_size(type);
532 memcpy(handle->val, value, len);
535 } else if (ZB_ZCL_OCTAT_STRING == type || ZB_ZCL_CHRACTER_STRING == type) {
538 free(handle->str->v);
541 /* string size exception case */
542 RETV_IF(0xff - 1 < handle->str->n, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
543 handle->str = malloc(sizeof(struct attribute_str_s));
544 RETV_IF(NULL == handle->str, ZIGBEE_ERROR_OUT_OF_MEMORY);
545 handle->str->n = count;
546 /* The first 1 byte indicate invalid or length of string */
547 handle->str->v = calloc(sizeof(unsigned char), handle->str->n + sizeof(handle->str->n));
548 RETV_IF(NULL == handle->str->v, ZIGBEE_ERROR_OUT_OF_MEMORY);
549 memcpy(handle->str->v, value+sizeof(handle->str->n), handle->str->n);
552 handle->size = count;
553 } else if (ZB_ZCL_LONG_OCTAT_STRING == type || ZB_ZCL_LONG_CHRACTER_STRING == type) {
556 free(handle->wstr->v);
559 /* 2 byte string size exception case */
560 RETV_IF(0xffff - 1 < handle->wstr->n, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
561 handle->wstr = malloc(sizeof(struct attribute_wstr_s));
562 RETV_IF(NULL == handle->wstr, ZIGBEE_ERROR_OUT_OF_MEMORY);
563 handle->wstr->n = count;
564 /* The first 2 byte indicate invalid or length of string */
565 handle->wstr->v = calloc(sizeof(unsigned char), handle->wstr->n + sizeof(handle->wstr->n));
566 RETV_IF(NULL == handle->wstr->v, ZIGBEE_ERROR_OUT_OF_MEMORY);
567 memcpy(handle->wstr->v, value+sizeof(handle->wstr->n), handle->wstr->n);
570 handle->size = count;
572 return ZIGBEE_ERROR_NOT_SUPPORTED;
574 return ZIGBEE_ERROR_NONE;
577 API int zb_get_value(zb_value_h handle, unsigned char *type, unsigned char **value,
581 unsigned char *s = NULL;
583 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
584 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
586 len = zb_get_data_size(handle->type);
588 s = calloc(handle->size + 1 , sizeof(char));
589 memcpy(s, handle->val, len);
591 } else if (ZB_ZCL_OCTAT_STRING == handle->type || ZB_ZCL_CHRACTER_STRING == handle->type) {
592 RETV_IF(NULL == handle->str, ZIGBEE_ERROR_NO_DATA);
593 s = calloc(sizeof(unsigned char), handle->str->n);
594 RETV_IF(NULL == s, ZIGBEE_ERROR_OUT_OF_MEMORY);
595 memcpy(s, handle->str->v+sizeof(handle->str->n), handle->str->n);
596 *count = handle->str->n;
597 } else if (ZB_ZCL_OCTAT_STRING == handle->type || ZB_ZCL_CHRACTER_STRING == handle->type) {
598 RETV_IF(NULL == handle->wstr, ZIGBEE_ERROR_NO_DATA);
599 s = calloc(sizeof(unsigned char), handle->wstr->n);
600 RETV_IF(NULL == s, ZIGBEE_ERROR_OUT_OF_MEMORY);
601 memcpy(s, handle->wstr->v+sizeof(handle->wstr->n), handle->wstr->n);
602 *count = handle->wstr->n;
604 return ZIGBEE_ERROR_NOT_SUPPORTED;
606 *type = handle->type;
609 return ZIGBEE_ERROR_NONE;
612 API int zb_create_discover_attr_info(discover_attr_info_record_h *handle)
614 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
615 discover_attr_info_record_h simple = calloc(1,
616 sizeof(struct discover_attribute_info_record_s));
617 RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
619 return ZIGBEE_ERROR_NONE;
622 API void zb_destroy_discover_attr_info(discover_attr_info_record_h handle)
627 API int zb_get_id_from_discover_attr_info(
628 discover_attr_info_record_h handle,
631 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
632 RETV_IF(NULL == id, ZIGBEE_ERROR_INVALID_PARAMETER);
634 return ZIGBEE_ERROR_NONE;
637 API int zb_set_id_to_discover_attr_info(
638 discover_attr_info_record_h handle,
641 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
643 return ZIGBEE_ERROR_NONE;
646 API int zb_get_type_from_discover_attr_info(
647 discover_attr_info_record_h handle,
650 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
651 RETV_IF(NULL == type, ZIGBEE_ERROR_INVALID_PARAMETER);
652 *type = handle->type;
653 return ZIGBEE_ERROR_NONE;
656 API int zb_set_type_to_discover_attr_info(
657 discover_attr_info_record_h handle,
660 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
662 return ZIGBEE_ERROR_NONE;
665 API int zb_create_write_attr_record(
666 write_attr_record_h *handle)
668 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
669 write_attr_record_h t = calloc(1, sizeof(struct write_attribute_record_s));
670 RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
672 return ZIGBEE_ERROR_NONE;
675 API void zb_destroy_write_attr_record(write_attr_record_h handle)
677 RET_IF(NULL == handle);
683 API int zb_set_id_to_write_attr_record(write_attr_record_h handle,
686 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
688 return ZIGBEE_ERROR_NONE;
691 API int zb_set_type_to_write_attr_record(write_attr_record_h handle,
694 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
696 return ZIGBEE_ERROR_NONE;
699 API int zb_set_buf_to_write_attr_record(write_attr_record_h handle,
700 unsigned char type, unsigned char *value, int count)
703 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
708 len = zb_get_data_size(type);
710 handle->value = calloc(count + 1 , sizeof(char));
711 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
712 memcpy(handle->value, value, count);
713 } else if (ZB_ZCL_OCTAT_STRING == type || ZB_ZCL_CHRACTER_STRING == type) {
714 handle->value = calloc(count + sizeof(unsigned char) + 1, sizeof(char));
715 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
716 /* The first 1 byte indicate invalid or length of string */
717 handle->value[0] = count & 0xff;
718 memcpy(handle->value + sizeof(unsigned char), value + sizeof(unsigned char), count);
719 } else if (ZB_ZCL_LONG_OCTAT_STRING == handle->type || ZB_ZCL_LONG_CHRACTER_STRING == handle->type) {
720 handle->value = calloc(count + sizeof(unsigned short) + 1, sizeof(char));
721 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
722 /* The first 2 byte indicate invalid or length of string */
723 handle->value[0] = count & 0xff;
724 handle->value[1] = (count >> 8) & 0xff ;
725 memcpy(handle->value + sizeof(unsigned short), value + sizeof(unsigned short), count);
727 return ZIGBEE_ERROR_NOT_SUPPORTED;
729 return ZIGBEE_ERROR_NONE;
732 API int zb_set_value_to_write_attr_record(write_attr_record_h handle, zb_value_h value)
736 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
737 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
742 len = zb_get_data_size(value->type);
744 handle->value = calloc(value->size + 1 , sizeof(char));
745 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
746 memcpy(handle->value, value->val, value->size);
747 handle->type = value->type;
748 } else if (ZB_ZCL_OCTAT_STRING == handle->type || ZB_ZCL_CHRACTER_STRING == handle->type) {
749 RETV_IF(NULL == value->str, ZIGBEE_ERROR_NO_DATA);
750 /* 1 byte string size exception case */
751 RETV_IF(0xff - 1 < value->str->n, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
752 handle->value = calloc(value->str->n + sizeof(value->str->n), sizeof(char));
753 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
754 /* The first 1 byte indicate invalid or length of string */
755 handle->value[0] = value->str->n & 0xff;
756 memcpy(handle->value + sizeof(value->str->n),
757 value->str->v + sizeof(value->str->n), value->str->n);
758 } else if (ZB_ZCL_LONG_OCTAT_STRING == handle->type || ZB_ZCL_LONG_CHRACTER_STRING == handle->type) {
759 RETV_IF(NULL == value->wstr, ZIGBEE_ERROR_NO_DATA);
760 /* 2 byte string size exception case */
761 RETV_IF(0xffff - 1 < value->wstr->n, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
762 handle->value = calloc(value->wstr->n + sizeof(value->wstr->n), sizeof(char));
763 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
764 /* The first 2 byte indicate invalid or length of string */
765 handle->value[0] = value->wstr->n & 0xff;
766 handle->value[1] = (value->wstr->n >> 8) & 0xff ;
767 memcpy(handle->value + sizeof(value->wstr->n),
768 value->wstr->v + sizeof(value->wstr->n), value->wstr->n);
770 return ZIGBEE_ERROR_NOT_SUPPORTED;
772 return ZIGBEE_ERROR_NONE;
775 API int zb_create_write_attr_status(write_attr_status_record_h *handle)
777 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
778 write_attr_status_record_h simple = calloc(1,
779 sizeof(struct write_attribute_status_record_s));
780 RETVM_IF(NULL == simple, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
782 return ZIGBEE_ERROR_NONE;
785 API void zb_destroy_write_attr_status(write_attr_status_record_h handle)
790 API int zb_get_status_from_write_attr_status(write_attr_status_record_h handle,
791 unsigned char *status)
793 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
794 RETV_IF(NULL == status, ZIGBEE_ERROR_INVALID_PARAMETER);
795 *status = handle->status;
796 return ZIGBEE_ERROR_NONE;
799 API int zb_set_status_to_write_attr_status(write_attr_status_record_h handle,
800 unsigned char status)
802 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
803 handle->status = status;
804 return ZIGBEE_ERROR_NONE;
807 API int zb_get_id_from_write_attr_status(write_attr_status_record_h handle,
810 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
811 RETV_IF(NULL == id, ZIGBEE_ERROR_INVALID_PARAMETER);
813 return ZIGBEE_ERROR_NONE;
816 API int zb_set_id_to_write_attr_status(write_attr_status_record_h handle,
819 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
821 return ZIGBEE_ERROR_NONE;
824 API int zb_create_report_config_record(report_config_record_h *handle)
826 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
827 report_config_record_h t;
828 t = calloc(1, sizeof(struct reporting_configuration_record_s));
829 RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
831 return ZIGBEE_ERROR_NONE;
834 API void zb_destroy_report_config_record(report_config_record_h handle)
836 RET_IF(NULL == handle);
838 free(handle->change);
842 API int zb_get_dir_from_report_config_record(report_config_record_h handle,
845 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
846 RETV_IF(NULL == dir, ZIGBEE_ERROR_INVALID_PARAMETER);
848 return ZIGBEE_ERROR_NONE;
851 API int zb_set_dir_to_report_config_record(report_config_record_h handle,
854 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
855 if (dir == ZB_ZCL_CLIENT_TO_SERVER)
859 return ZIGBEE_ERROR_NONE;
862 API int zb_get_id_from_report_config_record(report_config_record_h handle,
865 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
866 RETV_IF(NULL == id, ZIGBEE_ERROR_INVALID_PARAMETER);
868 return ZIGBEE_ERROR_NONE;
871 API int zb_set_id_to_report_config_record(report_config_record_h handle,
874 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
876 return ZIGBEE_ERROR_NONE;
880 API int zb_get_type_from_report_config_record(report_config_record_h handle,
883 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
884 RETV_IF(NULL == type, ZIGBEE_ERROR_INVALID_PARAMETER);
885 *type = handle->type;
886 return ZIGBEE_ERROR_NONE;
889 API int zb_set_type_to_report_config_record(report_config_record_h handle,
892 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
894 return ZIGBEE_ERROR_NONE;
898 API int zb_get_min_i_from_report_config_record(report_config_record_h handle,
899 unsigned short *min_i)
901 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
902 RETV_IF(NULL == min_i, ZIGBEE_ERROR_INVALID_PARAMETER);
903 *min_i = handle->min_i;
904 return ZIGBEE_ERROR_NONE;
907 API int zb_set_min_i_to_report_config_record(report_config_record_h handle,
908 unsigned short min_i)
910 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
911 handle->min_i = min_i;
912 return ZIGBEE_ERROR_NONE;
915 API int zb_get_max_i_from_report_config_record(report_config_record_h handle,
916 unsigned short *max_i)
918 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
919 RETV_IF(NULL == max_i, ZIGBEE_ERROR_INVALID_PARAMETER);
920 *max_i = handle->max_i;
921 return ZIGBEE_ERROR_NONE;
924 API int zb_set_max_i_to_report_config_record(report_config_record_h handle,
925 unsigned short max_i)
927 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
928 handle->max_i = max_i;
929 return ZIGBEE_ERROR_NONE;
932 API int zb_get_timeout_from_report_config_record(report_config_record_h handle,
935 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
936 RETV_IF(NULL == to, ZIGBEE_ERROR_INVALID_PARAMETER);
938 return ZIGBEE_ERROR_NONE;
941 API int zb_set_timeout_to_report_config_record(report_config_record_h handle,
944 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
946 return ZIGBEE_ERROR_NONE;
949 API int zb_get_change_from_report_config_record1(report_config_record_h handle,
953 int data_type = DATA_TYPE_NONE;
957 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
958 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
959 RETV_IF(NULL == handle->change, ZIGBEE_ERROR_NO_DATA);
961 len = zb_get_data_size(handle->type);
962 data_type = zb_get_analog_or_discret(handle->type);
963 if (0 < len /* && DATA_TYPE_ANALOG == data_type */) {
964 memcpy(value->val, handle->change, len);
965 value->type = handle->type;
968 return ZIGBEE_ERROR_NOT_SUPPORTED;
970 return ZIGBEE_ERROR_NONE;
973 API int zb_set_change_to_report_config_record1(report_config_record_h handle,
977 int data_type = DATA_TYPE_NONE;
981 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
982 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
985 free(handle->change);
987 len = zb_get_data_size(value->type);
988 data_type = zb_get_analog_or_discret(value->type);
989 if (0 < len /* && DATA_TYPE_ANALOG == data_type */) {
990 handle->change = calloc(len + 1, sizeof(char));
991 RETVM_IF(NULL == handle->change, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
992 memcpy(handle->change, value->val, len);
993 handle->type = value->type;
995 return ZIGBEE_ERROR_NOT_SUPPORTED;
997 return ZIGBEE_ERROR_NONE;
1000 API int zb_get_change_from_report_config_record2(report_config_record_h handle,
1001 unsigned char *type, unsigned char **value, int *size)
1004 int data_type = DATA_TYPE_NONE;
1005 unsigned char *t = NULL;
1007 NOT_USED(data_type);
1009 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1010 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
1011 RETV_IF(NULL == handle->change, ZIGBEE_ERROR_NO_DATA);
1013 len = zb_get_data_size(handle->type);
1014 data_type = zb_get_analog_or_discret(handle->type);
1015 if (0 < len /* && DATA_TYPE_ANALOG == data_type */) {
1016 t = calloc(len + 1, sizeof(char));
1017 RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
1018 memcpy(t, handle->change, len);
1020 *type = handle->type;
1023 return ZIGBEE_ERROR_NOT_SUPPORTED;
1025 return ZIGBEE_ERROR_NONE;
1027 API int zb_set_change_to_report_config_record2(
1028 report_config_record_h handle, unsigned char type, unsigned char *value)
1031 int data_type = DATA_TYPE_NONE;
1033 NOT_USED(data_type);
1035 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1037 free(handle->change);
1039 len = zb_get_data_size(type);
1040 data_type = zb_get_analog_or_discret(type);
1042 if (0 < len /* && DATA_TYPE_ANALOG == data_type */) {
1043 handle->change = calloc(len + 1, sizeof(unsigned char));
1044 RETVM_IF(NULL == handle->change, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
1045 memcpy(handle->change, value, len);
1046 handle->type = type;
1048 return ZIGBEE_ERROR_NOT_SUPPORTED;
1050 return ZIGBEE_ERROR_NONE;
1053 API int zb_get_change_from_report_config_record3(report_config_record_h handle,
1054 unsigned char *type, unsigned char *value, int *size)
1057 int data_type = DATA_TYPE_NONE;
1059 NOT_USED(data_type);
1061 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1062 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
1063 RETV_IF(NULL == handle->change, ZIGBEE_ERROR_NO_DATA);
1065 len = zb_get_data_size(handle->type);
1066 data_type = zb_get_analog_or_discret(handle->type);
1067 if (0 < len /* && DATA_TYPE_ANALOG == data_type */) {
1068 memcpy(value, handle->change, len);
1069 *type = handle->type;
1072 return ZIGBEE_ERROR_NOT_SUPPORTED;
1074 return ZIGBEE_ERROR_NONE;
1077 API int zb_create_read_report_config_record(read_report_config_record_h *handle)
1079 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1080 read_report_config_record_h t =
1081 calloc(1, sizeof(struct read_reporting_configuration_record_s));
1082 RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
1084 return ZIGBEE_ERROR_NONE;
1087 API void zb_destroy_read_report_config_record(read_report_config_record_h handle)
1092 API int zb_set_dir_to_read_report_config_record(read_report_config_record_h handle,
1095 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1096 if (dir == ZB_ZCL_CLIENT_TO_SERVER)
1100 return ZIGBEE_ERROR_NONE;
1103 API int zb_get_dir_from_read_report_config_record(read_report_config_record_h handle,
1106 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1108 return ZIGBEE_ERROR_NONE;
1111 API int zb_set_id_to_read_report_config_record(read_report_config_record_h handle,
1114 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1116 return ZIGBEE_ERROR_NONE;
1119 API int zb_get_id_from_read_report_config_record(read_report_config_record_h handle,
1122 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1124 return ZIGBEE_ERROR_NONE;
1127 API int zb_create_report_config_response_record(
1128 report_config_response_record_h *handle)
1130 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1131 report_config_response_record_h t =
1132 calloc(1, sizeof(struct reporting_configuration_response_record_s));
1133 RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
1135 return ZIGBEE_ERROR_NONE;
1138 API void zb_destroy_report_config_response_record(
1139 report_config_response_record_h handle)
1144 API int zb_get_status_from_report_config_response_record(
1145 report_config_response_record_h handle, unsigned char *status)
1147 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1148 RETV_IF(NULL == status, ZIGBEE_ERROR_INVALID_PARAMETER);
1149 *status = handle->status;
1150 return ZIGBEE_ERROR_NONE;
1153 API int zb_set_status_to_report_config_response_record(
1154 report_config_response_record_h handle, unsigned char status)
1156 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1157 handle->status = status;
1158 return ZIGBEE_ERROR_NONE;
1161 API int zb_get_dir_from_report_config_response_record(
1162 report_config_response_record_h handle, unsigned char *dir)
1164 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1165 RETV_IF(NULL == dir, ZIGBEE_ERROR_INVALID_PARAMETER);
1167 return ZIGBEE_ERROR_NONE;
1170 API int zb_set_dir_to_report_config_response_record(
1171 report_config_response_record_h handle, unsigned char dir)
1173 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1174 handle->dir = handle->dir;
1175 return ZIGBEE_ERROR_NONE;
1178 API int zb_get_id_from_report_config_response_record(
1179 report_config_response_record_h handle, unsigned short *id)
1181 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1182 RETV_IF(NULL == id, ZIGBEE_ERROR_INVALID_PARAMETER);
1184 return ZIGBEE_ERROR_NONE;
1187 API int zb_set_id_to_report_config_response_record(
1188 report_config_response_record_h handle, unsigned short id)
1190 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1192 return ZIGBEE_ERROR_NONE;
1195 API int zb_create_attr_report(attr_report_h *handle)
1197 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1198 attr_report_h t = calloc(1, sizeof(struct attribute_report_s));
1199 RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
1201 return ZIGBEE_ERROR_NONE;
1204 API void zb_destroy_attr_report(attr_report_h handle)
1208 free(handle->value);
1213 API int zb_get_id_from_attr_report(attr_report_h handle, unsigned short *id)
1215 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1216 RETV_IF(NULL == id, ZIGBEE_ERROR_INVALID_PARAMETER);
1218 return ZIGBEE_ERROR_NONE;
1221 API int zb_set_id_to_attr_report(attr_report_h handle, unsigned short id)
1223 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1225 return ZIGBEE_ERROR_NONE;
1228 API int zb_get_type_from_attr_report(attr_report_h handle, unsigned char *type)
1230 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1231 RETV_IF(NULL == type, ZIGBEE_ERROR_INVALID_PARAMETER);
1232 *type = handle->type;
1233 return ZIGBEE_ERROR_NONE;
1236 API int zb_set_type_to_attr_report(attr_report_h handle, unsigned char type)
1238 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1239 handle->type = type;
1240 return ZIGBEE_ERROR_NONE;
1243 API int zb_get_value_from_attr_report(attr_report_h handle, zb_value_h value)
1247 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1248 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
1249 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_NO_DATA);
1251 len = zb_get_data_size(handle->type);
1253 memcpy(value->val, handle->value, len);
1255 value->type = handle->type;
1256 } else if (ZB_ZCL_OCTAT_STRING == handle->type || ZB_ZCL_CHRACTER_STRING == handle->type) {
1259 free(value->str->v);
1262 value->str = calloc(1, sizeof(struct attribute_str_s));
1263 RETV_IF(NULL == value->str, ZIGBEE_ERROR_OUT_OF_MEMORY);
1264 value->str->n = *handle->value;
1265 /* The first 1 byte indicate invalid or length of string */
1266 if (0xff == value->str->n) {
1268 return ZIGBEE_ERROR_NO_DATA;
1270 value->str->v = calloc(value->str->n+1, 1);
1271 if (NULL == value->str->v) {
1273 return ZIGBEE_ERROR_OUT_OF_MEMORY;
1275 memcpy(value->str->v, handle->value+sizeof(value->str->n), value->str->n);
1277 value->type = handle->type;
1278 value->size = value->str->n;
1279 } else if (ZB_ZCL_LONG_OCTAT_STRING == handle->type || ZB_ZCL_LONG_CHRACTER_STRING == handle->type) {
1282 free(value->wstr->v);
1285 value->wstr = calloc(1, sizeof(struct attribute_wstr_s));
1286 RETV_IF(NULL == value->wstr, ZIGBEE_ERROR_OUT_OF_MEMORY);
1287 value->wstr->n = *(handle->value+1) << 8 | *handle->value;
1288 /* The first 2 byte indicate invalid or length of string */
1289 if (0xffff == value->wstr->n) {
1291 return ZIGBEE_ERROR_NO_DATA;
1293 value->wstr->v = calloc(value->wstr->n+1, 1);
1294 if (NULL == value->wstr->v) {
1296 return ZIGBEE_ERROR_OUT_OF_MEMORY;
1298 memcpy(value->wstr->v, handle->value+sizeof(value->wstr->n), value->wstr->n);
1300 value->type = handle->type;
1301 value->size = value->wstr->n;
1303 return ZIGBEE_ERROR_NOT_SUPPORTED;
1305 return ZIGBEE_ERROR_NONE;
1308 API int zb_set_value_to_attr_report(attr_report_h handle, zb_value_h value)
1312 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1313 RETV_IF(NULL == value, ZIGBEE_ERROR_INVALID_PARAMETER);
1316 free(handle->value);
1318 len = zb_get_data_size(value->type);
1320 handle->value = calloc(value->size + 1 , sizeof(char));
1321 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
1322 memcpy(handle->value, value->val, value->size);
1323 handle->type = value->type;
1324 } else if (ZB_ZCL_OCTAT_STRING == handle->type || ZB_ZCL_CHRACTER_STRING == handle->type) {
1325 RETV_IF(NULL == value->str, ZIGBEE_ERROR_NO_DATA);
1326 handle->value = calloc(value->str->n + sizeof(value->str->n), sizeof(char));
1327 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
1328 /* The first 1 byte indicate invalid or length of string */
1329 handle->value[0] = value->str->n & 0xff;
1330 memcpy(handle->value + sizeof(value->str->n),
1331 value->str->v + sizeof(value->str->n), value->str->n);
1332 } else if (ZB_ZCL_LONG_OCTAT_STRING == handle->type || ZB_ZCL_LONG_CHRACTER_STRING == handle->type) {
1333 RETV_IF(NULL == value->wstr, ZIGBEE_ERROR_NO_DATA);
1334 handle->value = calloc(value->wstr->n + sizeof(value->wstr->n), sizeof(char));
1335 RETV_IF(NULL == handle->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
1336 /* The first 2 byte indicate invalid or length of string */
1337 handle->value[0] = value->wstr->n & 0xff;
1338 handle->value[1] = (value->wstr->n >> 8) & 0xff ;
1339 memcpy(handle->value + sizeof(value->wstr->n),
1340 value->wstr->v + sizeof(value->wstr->n), value->wstr->n);
1342 return ZIGBEE_ERROR_NOT_SUPPORTED;
1344 return ZIGBEE_ERROR_NONE;
1349 * @brief Figure 2.33 Format of the Selector Field
1354 unsigned char indicator; /**< number of index */
1355 unsigned short *index; /**< index list */
1359 * @brief stcuture for reading attribute
1363 struct read_structured_attribute_record_s {
1364 unsigned short id; /**< attribute identifier */
1365 struct selector_s *selector; /**< selector format */
1369 * @brief Figure 2.11 Format of the Write Attribute Record Field
1373 struct write_attribute_structured_status_record_s {
1374 unsigned char status; /**< status */
1375 unsigned short id; /**< identifier */
1376 struct selector_s selector; /**< selector */
1380 * @brief Figure 2.32 Format of the Write Attribute Record Field
1384 struct write_attribute_structured_record_s {
1385 unsigned short id; /**< attribute identifier */
1386 struct selector_s selector;
1387 unsigned char type; /**< attribute data type */
1388 unsigned char *value; /**< data value */; /**< attribute value */
1391 API int zb_create_extended_attr_info(extended_attr_info_h *handle)
1393 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1394 extended_attr_info_h t = calloc(1, sizeof(struct extended_attribute_infomation_s));
1395 RETVM_IF(NULL == t, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
1397 return ZIGBEE_ERROR_NONE;
1400 API void zb_destroy_extended_attr_info(extended_attr_info_h handle)
1405 API int zb_get_id_from_extended_attr_info(extended_attr_info_h handle,
1408 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1409 RETV_IF(NULL == id, ZIGBEE_ERROR_INVALID_PARAMETER);
1411 return ZIGBEE_ERROR_NONE;
1414 API int zb_set_id_to_extended_attr_info(extended_attr_info_h handle,
1417 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1419 return ZIGBEE_ERROR_NONE;
1422 API int zb_get_type_from_extended_attr_info(extended_attr_info_h handle,
1423 unsigned char *type)
1425 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1426 RETV_IF(NULL == type, ZIGBEE_ERROR_INVALID_PARAMETER);
1427 *type = handle->type;
1428 return ZIGBEE_ERROR_NONE;
1431 API int zb_set_type_to_extended_attr_info(extended_attr_info_h handle,
1434 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1435 handle->type = type;
1436 return ZIGBEE_ERROR_NONE;
1439 API int zb_get_acl_from_extended_attr_info(extended_attr_info_h handle,
1442 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1443 RETV_IF(NULL == acl, ZIGBEE_ERROR_INVALID_PARAMETER);
1445 return ZIGBEE_ERROR_NONE;
1448 API int zb_set_acl_to_extended_attr_info(extended_attr_info_h handle,
1451 RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
1453 return ZIGBEE_ERROR_NONE;