2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
31 extern struct menu_data menu_zdo_binding[];
32 extern struct menu_data menu_zdo_device[];
33 extern struct menu_data menu_zdo_network[];
35 extern struct menu_data menu_zcl_global[];
36 extern struct menu_data menu_zcl_cluster[];
37 extern struct menu_data menu_custom[];
39 static char data_remove_children[MENU_DATA_SIZE + 1] = "1";
40 static char data_endpoint[MENU_DATA_SIZE + 1] = "1";
41 static char data_rejoin[MENU_DATA_SIZE + 1] = "0";
42 static char data_pj_timeout[MENU_DATA_SIZE + 1] = "90";
43 static char data_choose_target[MENU_DATA_SIZE + 1] = "0";
44 static char data_dest_addr16[MENU_DATA_SIZE + 1] = "";
46 zb_nwk_addr panid = 0x615F;
47 zb_ieee_addr co_addr64 = { 0xD0, 0x52, 0xA8, 0xA9, 0x8F, 0xB7, 0x00, 0x01 };
49 zb_nwk_addr st_addr16 = 0x708B;
50 zb_ieee_addr st_addr64 = { 0x00, 0x0D, 0x6F, 0x00, 0x04, 0x2B, 0xBE, 0x14 };
52 zb_nwk_addr sj_addr16 = 0x4756;
53 zb_ieee_addr sj_addr64 = { 0x24, 0xFD, 0x5B, 0x00, 0x01, 0x01, 0x86, 0xB6 };
55 zb_nwk_addr dest_addr16 = 0x1D1A;
56 zb_ieee_addr dest_addr64 = { 0x00, 0x12, 0x4B, 0x00, 0x02, 0xF2, 0x58, 0x5B };
58 simple_desc_s st_ep1, st_ep2, st_ep3, st_ep4, sj_ep1;
59 simple_desc_s dimmer_ep1, s_thermostat_ep1, huebulb_ep1;
61 zb_end_dev_info_h *target_list = NULL;
62 int target_list_count;
64 static const char* zb_event_str[] = {
66 "ZB_ZDP_ENABLE_EVENT",
67 "ZB_ZDP_FORM_NETWORK_DONE",
69 "ZB_ZDP_REJOIN_EVENT",
71 "ZB_ZDP_LEAVE_DONE_EVENT",
72 "ZB_ZDP_UPDATED_NETWORK_NOTIFICATION_EVENT",
73 "ZB_ZDP_BIND_RSP_EVENT",
74 "ZB_ZDP_UNBIND_RSP_EVENT",
75 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
78 "ZB_ZCL_GLOBAL_DEFAULT_RSP_EVENT",
79 "ZB_ZCL_GLOBAL_ATTRIBUTE_REPORT_EVENT",
80 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
81 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
85 "ZB_ZCL_IAS_ZONE_ENROLL_REQUEST_EVENT",
86 "ZB_ZCL_IAS_ZONE_STATUS_CHANGE_NOTIFICATION_EVENT",
87 "ZB_ZCL_IAS_ZONE_STATUS_CHANGE_EXTENDED_NOTIFICATION_EVENT",
88 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
89 NULL, NULL, NULL, NULL, NULL,
92 "ZB_ZCL_LEVEL_CONTROL_CURRENT_LEVEL_ATTRIBUTE_REPORT_EVENT",
93 "ZB_ZCL_COLOR_CONTROL_CURRENT_X_ATTRIBUTE_REPORT_EVENT",
94 "ZB_ZCL_COLOR_CONTROL_CURRENT_Y_ATTRIBUTE_REPORT_EVENT",
95 "ZB_ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_REPORT_EVENT",
96 "ZB_ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_REPORT_EVENT",
97 "ZB_ZCL_COLOR_CONTROL_CURRENT_TEMPERATURE_ATTRIBUTE_REPORT_EVENT",
98 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
102 "ZB_ZCL_DOOR_LOCK_OPERATIONAL_NOTIFICATION_EVENT",
103 "ZB_ZCL_DOOR_LOCK_PROGRAMING_NOTIFICATION_EVENT",
104 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
105 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
108 "ZB_ZCL_SIMPLE_METERING_REMOVE_MIRROR_EVENT",
109 "ZB_ZCL_SIMPLE_METERING_REQUEST_MIRROR_EVENT",
110 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
111 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
117 const char* zigbee_error_to_string(zb_error_e err)
120 /* CHECK: List all enum values here */
121 CASE_TO_STR(ZIGBEE_ERROR_NONE)
122 CASE_TO_STR(ZIGBEE_ERROR_INVALID_PARAMETER)
123 CASE_TO_STR(ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE)
124 CASE_TO_STR(ZIGBEE_ERROR_OUT_OF_MEMORY)
125 CASE_TO_STR(ZIGBEE_ERROR_IO_ERROR)
126 CASE_TO_STR(ZIGBEE_ERROR_NO_DATA)
127 CASE_TO_STR(ZIGBEE_ERROR_NOT_SUPPORTED)
128 CASE_TO_STR(ZIGBEE_ERROR_PERMISSION_DENIED)
129 CASE_TO_STR(ZIGBEE_ERROR_INVALID_ENDPOINT)
130 CASE_TO_STR(ZIGBEE_ERROR_INVALID_ADDRESS)
131 CASE_TO_STR(ZIGBEE_ERROR_OPERATION_FAILED)
133 return "ZIGBEE_ERROR_UNKNOWN";
137 static void _init_endpoints()
139 /* Samjin power outlet EP1 */
141 sj_ep1.profileid = 0x0104;
142 sj_ep1.deviceid = 0x0002;
143 sj_ep1.num_of_in_clusters = 7;
144 sj_ep1.num_of_out_clusters = 1;
145 /* In clusters : 0000 0003 0004 0005 0006 0009 0B04 0B05 */
146 sj_ep1.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
147 sj_ep1.in_clusters[1] = ZB_ZCL_CLUSTER_IDENTIFY;
148 sj_ep1.in_clusters[2] = ZB_ZCL_CLUSTER_GROUPS;
149 sj_ep1.in_clusters[3] = ZB_ZCL_CLUSTER_SCENES;
150 sj_ep1.in_clusters[4] = ZB_ZCL_CLUSTER_ON_OFF;
151 sj_ep1.in_clusters[5] = ZB_ZCL_CLUSTER_ALARM;
152 sj_ep1.in_clusters[6] = ZB_ZCL_CLUSTER_DIAGNOSTICS;
153 /* Out clusters : 0019 */
154 /*unsigned short sj_out_clusters[] = { ZB_ZCL_CLUSTER_ID_OTA_BOOTLOAD };*/
156 /* SmartThings open/close sensor EP1 */
158 st_ep1.profileid = 0x0104;
159 st_ep1.deviceid = 0x0402;
160 st_ep1.num_of_in_clusters = 7;
161 st_ep1.num_of_out_clusters = 1;
162 st_ep1.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
163 st_ep1.in_clusters[1] = ZB_ZCL_CLUSTER_POWER_CONFIG;
164 st_ep1.in_clusters[2] = ZB_ZCL_CLUSTER_IDENTIFY;
165 st_ep1.in_clusters[3] = ZB_ZCL_CLUSTER_TEMP_MEASUREMENT;
166 st_ep1.in_clusters[4] = ZB_ZCL_CLUSTER_IAS_ZONE;
167 st_ep1.in_clusters[5] = ZB_ZCL_CLUSTER_POLL_CONTROL;
168 st_ep1.in_clusters[6] = ZB_ZCL_CLUSTER_DIAGNOSTICS;
169 st_ep1.out_clusters[0] = ZB_ZCL_CLUSTER_OTA_BOOTLOAD;
171 /* SmartThings open/close sensor EP2 */
173 st_ep2.profileid = 0xC2DF;
174 st_ep2.deviceid = 0x000C;
175 st_ep2.num_of_in_clusters = 4;
176 st_ep2.num_of_out_clusters = 1;
177 st_ep2.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
178 st_ep2.in_clusters[1] = ZB_ZCL_CLUSTER_IDENTIFY;
179 st_ep2.in_clusters[2] = ZB_ZCL_CLUSTER_SCENES;
180 st_ep2.in_clusters[3] = 0xFC0F;
181 st_ep2.out_clusters[0] = ZB_ZCL_CLUSTER_IDENTIFY;
183 /* SmartThings Motion Sensor EP1 */
185 st_ep3.profileid = 0x0104;
186 st_ep3.deviceid = 0x0402;
187 st_ep3.num_of_in_clusters = 7;
188 st_ep3.num_of_out_clusters = 1;
189 st_ep3.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
190 st_ep3.in_clusters[1] = ZB_ZCL_CLUSTER_POWER_CONFIG;
191 st_ep3.in_clusters[2] = ZB_ZCL_CLUSTER_IDENTIFY;
192 st_ep3.in_clusters[3] = ZB_ZCL_CLUSTER_POLL_CONTROL;
193 st_ep3.in_clusters[4] = ZB_ZCL_CLUSTER_TEMP_MEASUREMENT;
194 st_ep3.in_clusters[5] = ZB_ZCL_CLUSTER_IAS_ZONE;
195 st_ep3.in_clusters[6] = ZB_ZCL_CLUSTER_DIAGNOSTICS;
196 st_ep3.out_clusters[0] = ZB_ZCL_CLUSTER_OTA_BOOTLOAD;
198 /* SmartThings Motion Sensor EP2 */
200 st_ep4.profileid = 0xC2DF;
201 st_ep4.deviceid = 0x0107;
202 st_ep4.num_of_in_clusters = 5;
203 st_ep4.num_of_out_clusters = 1;
204 st_ep4.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
205 st_ep4.in_clusters[1] = ZB_ZCL_CLUSTER_POWER_CONFIG;
206 st_ep4.in_clusters[2] = ZB_ZCL_CLUSTER_IDENTIFY;
207 st_ep4.in_clusters[3] = ZB_ZCL_CLUSTER_DIAGNOSTICS;
208 st_ep4.in_clusters[4] = 0xFC46;
209 st_ep4.out_clusters[0] = ZB_ZCL_CLUSTER_OTA_BOOTLOAD;
211 /* Things Simulator - GE_ZigBeeDimmer */
213 dimmer_ep1.profileid = 0x0104;
214 dimmer_ep1.deviceid = 0xffff;
215 dimmer_ep1.num_of_in_clusters = 7;
216 dimmer_ep1.num_of_out_clusters = 1;
217 dimmer_ep1.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
218 dimmer_ep1.in_clusters[1] = ZB_ZCL_CLUSTER_IDENTIFY;
219 dimmer_ep1.in_clusters[2] = ZB_ZCL_CLUSTER_GROUPS;
220 dimmer_ep1.in_clusters[3] = ZB_ZCL_CLUSTER_SCENES;
221 dimmer_ep1.in_clusters[4] = ZB_ZCL_CLUSTER_ON_OFF;
222 dimmer_ep1.in_clusters[5] = ZB_ZCL_CLUSTER_LEVEL_CONTROL;
223 dimmer_ep1.in_clusters[6] = ZB_ZCL_CLUSTER_DIAGNOSTICS;
224 /*dimmer_ep1.in_clusters[7] = ZB_ZCL_CLUSTER_ID_SIMPLE_METERING;*/
225 dimmer_ep1.out_clusters[0] = ZB_ZCL_CLUSTER_TIME;
226 /*dimmer_ep1.out_clusters[1] = ZB_ZCL_CLUSTER_ID_OTA_BOOTLOAD;*/
228 /* Things Simulator - CentraLite_Thermostat */
229 s_thermostat_ep1.ep = 1;
230 s_thermostat_ep1.profileid = 0x0104;
231 s_thermostat_ep1.deviceid = 0xffff;
232 s_thermostat_ep1.num_of_in_clusters = 8;
233 s_thermostat_ep1.num_of_out_clusters = 2;
234 s_thermostat_ep1.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
235 s_thermostat_ep1.in_clusters[1] = ZB_ZCL_CLUSTER_POWER_CONFIG;
236 s_thermostat_ep1.in_clusters[2] = ZB_ZCL_CLUSTER_IDENTIFY;
237 s_thermostat_ep1.in_clusters[3] = ZB_ZCL_CLUSTER_POLL_CONTROL;
238 s_thermostat_ep1.in_clusters[4] = ZB_ZCL_CLUSTER_THERMOSTAT;
239 s_thermostat_ep1.in_clusters[5] = ZB_ZCL_CLUSTER_FAN_CONTROL;
240 s_thermostat_ep1.in_clusters[6] = ZB_ZCL_CLUSTER_THERMOSTAT_UI_CONFIG;
241 s_thermostat_ep1.in_clusters[7] = ZB_ZCL_CLUSTER_DIAGNOSTICS;
242 s_thermostat_ep1.out_clusters[0] = ZB_ZCL_CLUSTER_TIME;
243 s_thermostat_ep1.out_clusters[1] = ZB_ZCL_CLUSTER_OTA_BOOTLOAD;
245 /* Things Simulator - Zigbee_HueBulb */
247 huebulb_ep1.profileid = 0x0104;
248 huebulb_ep1.deviceid = 0xffff;
249 huebulb_ep1.num_of_in_clusters = 8;
250 huebulb_ep1.num_of_out_clusters = 1;
251 huebulb_ep1.in_clusters[0] = ZB_ZCL_CLUSTER_BASIC;
252 huebulb_ep1.in_clusters[1] = ZB_ZCL_CLUSTER_IDENTIFY;
253 huebulb_ep1.in_clusters[2] = ZB_ZCL_CLUSTER_GROUPS;
254 huebulb_ep1.in_clusters[3] = ZB_ZCL_CLUSTER_SCENES;
255 huebulb_ep1.in_clusters[4] = ZB_ZCL_CLUSTER_ON_OFF;
256 huebulb_ep1.in_clusters[5] = ZB_ZCL_CLUSTER_LEVEL_CONTROL;
257 huebulb_ep1.in_clusters[6] = ZB_ZCL_CLUSTER_COLOR_CONTROL;
258 huebulb_ep1.in_clusters[7] = ZB_ZCL_CLUSTER_ZLL_COMMISSIONING;
259 huebulb_ep1.out_clusters[0] = ZB_ZCL_CLUSTER_OTA_BOOTLOAD;
262 static void _zb_form_network_done_cb(zb_nwk_addr panid, void *user_data)
264 msgp("\nform_network_done received PANID = 0x%04X\n", panid);
267 static void _zb_disable_network_done_cb(unsigned char ret, void *user_data)
269 msgp("\ndisable_network result received = 0x%02X\n", ret);
272 static void _zb_event_cb(zb_nwk_addr addr16, zb_ieee_addr addr64, zb_event_e e,
273 zb_event_data_h ev, void* user_data)
280 zb_cluster_id clusterid;
281 zb_command_id commandid;
285 msgp("Event received = %s [0x%02X]", zb_event_str[e], e);
287 switch (event_type) {
288 case ZB_ZDP_ENABLE_EVENT:
290 zb_ev_get_enable_status(
294 msg(" zigbee state = %d [%s]", status, (status ? "Enabled" : "Disabled"));
297 case ZB_ZDP_FORM_NETWORK_DONE:
299 zb_nwk_addr pan_id = 0;
300 zb_ev_get_form_network_panid(ev, &pan_id);
301 msg("0x%d form network done", pan_id);
304 case ZB_ZDP_JOIN_EVENT:
306 zb_end_point *ep = NULL;
307 zb_ev_get_join_count(
316 msg(" %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X joined",
317 addr64[0], addr64[1], addr64[2], addr64[3],
318 addr64[4], addr64[5], addr64[6], addr64[7]);
319 msg("end-point count = %d", count);
320 for (int i = 0; i < count; i++)
330 case ZB_ZDP_REJOIN_EVENT:
332 msg(" %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X rejoined",
333 addr64[0], addr64[1], addr64[2], addr64[3],
334 addr64[4], addr64[5], addr64[6], addr64[7]);
337 case ZB_ZDP_CHILD_LEFT: {
338 zb_error_e status = 0;
339 zb_ev_get_child_left_status(ev, &status);
340 msg(" %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X left Status Code = 0x%02X",
341 addr64[0], addr64[1], addr64[2], addr64[3],
342 addr64[4], addr64[5], addr64[6], addr64[7], status);
345 case ZB_ZDP_LEAVE_DONE_EVENT: {
346 msg(" 0x%04X leave done\n", addr16);
349 case ZB_ZDP_UPDATED_NETWORK_NOTIFICATION_EVENT: {
350 msg(" Update network notification received\n");
353 case ZB_ZDP_BIND_RSP_EVENT:
355 /* zb_parse_bind_cb(ev, &status); */
356 /* msg("binding %04X, result=%0X\n", addr16, status); */
357 msg(" Not implemented");
360 case ZB_ZDP_UNBIND_RSP_EVENT:
362 /* zb_parse_unbind_cb(ev, &status); */
363 /* msg("unbinding %04X, result=%0X\n", addr16, status); */
364 msg(" Not implemented");
367 case ZB_ZCL_GLOBAL_DEFAULT_RSP_EVENT:
369 zb_zcl_status_e zcl_status;
370 zb_ev_get_global_default_rsp_ep(
374 zb_ev_get_global_default_rsp_cluster_id(
378 zb_ev_get_global_default_rsp_command_id(
382 zb_ev_get_global_default_rsp_status(
387 msg(" addr16 = 0x%04X", addr16);
388 msg(" endpoint = 0x%02X", ep);
389 msg(" cluster_id = 0x%04X (%s)", clusterid, zb_zcl_get_cluster_id_str(clusterid));
390 msg(" commandid = 0x%02X", commandid);
391 msg(" status = 0x%02X (%s)",
392 zcl_status, zb_zcl_get_status_str(zcl_status));
395 case ZB_ZCL_GLOBAL_ATTRIBUTE_REPORT_EVENT:
400 zb_zcl_data_type_e type;
401 unsigned char rec_len = 0;
402 unsigned char *buf = NULL;
404 zb_zcl_attr_report_h *records = NULL;
406 ret = zb_ev_get_global_attr_report_records(
411 if (ZIGBEE_ERROR_NONE != ret) {
412 msg("zb_ev_get_global_attr_report_records(0x%X) - FAILED!!! [%s]",
413 ret, zigbee_error_to_string(ret));
416 if (NULL == records) {
417 msg("records is NULL");
421 msg("Global Attribute Report Event Received from = 0x%04X record_len=%d",
423 for (j = 0; j < rec_len; j++) {
424 zb_attr_report_get_id(
428 msg(" id = [0x%04X]", id);
429 zb_attr_report_get_type(
433 msg(" type = [0x%02X][%s]", type, zb_zcl_get_data_type_str(type));
434 zb_attr_report_get_value(
440 if (ZIGBEE_ERROR_NONE == ret) {
441 for (i = 0; i < count; i++)
442 msg(" 0x%02X ", buf[i]);
452 case ZB_ZCL_ALARM_EVENT:
454 unsigned short count = 0;
455 zb_ev_get_alarm_count(ev, &count);
456 msg("Alarm Event Received = %d\n", count);
459 case ZB_ZCL_IAS_ZONE_ENROLL_REQUEST_EVENT:
461 /*zb_nwk_addr addr16;*/
462 zb_zcl_ias_zone_type_e zone_type;
463 unsigned char ep, mfg_code;
464 msg("IAS Zone Request Received\n");
466 zb_ev_get_enroll_request_src_ep(
470 zb_ev_get_enroll_request_zone_type(
474 zb_ev_get_enroll_request_mfg_code(
479 /*msg("Network Address from 0x%04X\n", addr16);*/
480 msg(" End-Point from 0x%02X", ep);
481 msg(" Zone Type = 0x%04X", zone_type);
482 msg(" Manufacturer Code = 0x%02X", mfg_code);
483 zb_zcl_zone_enroll_response(
487 ZB_ZCL_IAS_ZONE_ENROLL_SUCCESS,
492 case ZB_ZCL_IAS_ZONE_STATUS_CHANGE_NOTIFICATION_EVENT:
494 unsigned short zone_status;
496 zb_ev_get_ias_noti_src_ep(
500 zb_ev_get_ias_noti_zone_status(
505 msg(" addr16 = 0x%04X", addr16);
506 msg(" endpoint = 0x%02X", ep);
507 msg(" zone_status = 0x%04X", zone_status);
511 case ZB_ZCL_IAS_ZONE_STATUS_CHANGE_EXTENDED_NOTIFICATION_EVENT:
513 unsigned char status, zone_id;
514 unsigned short zone_status, delay;
516 zb_ev_get_ias_ext_noti_src_ep(
520 zb_ev_get_ias_ext_noti_status(
524 zb_ev_get_ias_ext_noti_zone_status(
528 zb_ev_get_ias_ext_noti_zone_id(
532 zb_ev_get_ias_ext_noti_delay(
537 msg(" addr16 = 0x%04X", addr16);
538 msg(" endpoint = 0x%02X", ep);
539 msg(" status = 0x%02X", status);
540 msg(" zone_status = 0x%04X", zone_status);
541 msg(" zone_id = 0x%04X", zone_id);
542 msg(" delay = 0x%04X", delay);
544 /* Closed or not alarmed */
545 if (0x01 == (zone_status & 0x01))
546 zb_zcl_on_off_control(
552 /* Opened or alarmed */
553 else if (0x00 == (zone_status & 0x01))
554 zb_zcl_on_off_control(
562 case ZB_ZCL_LEVEL_CONTROL_CURRENT_LEVEL_ATTRIBUTE_REPORT_EVENT:
564 case ZB_ZCL_COLOR_CONTROL_CURRENT_X_ATTRIBUTE_REPORT_EVENT:
566 case ZB_ZCL_COLOR_CONTROL_CURRENT_Y_ATTRIBUTE_REPORT_EVENT:
568 case ZB_ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_REPORT_EVENT:
570 case ZB_ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_REPORT_EVENT:
572 case ZB_ZCL_COLOR_CONTROL_CURRENT_TEMPERATURE_ATTRIBUTE_REPORT_EVENT:
574 case ZB_ZCL_DOOR_LOCK_OPERATIONAL_NOTIFICATION_EVENT:
576 case ZB_ZCL_DOOR_LOCK_PROGRAMING_NOTIFICATION_EVENT:
578 case ZB_ZCL_SIMPLE_METERING_REMOVE_MIRROR_EVENT:
580 case ZB_ZCL_SIMPLE_METERING_REQUEST_MIRROR_EVENT:
583 msgp("Unhandled Event received = [0x%02X]", e);
589 static int run_create(MManager *mm, struct menu_data *menu)
591 int ret = ZIGBEE_ERROR_NONE;
593 msg("Already handle exist.");
600 if (ZIGBEE_ERROR_NONE != ret) {
601 msg("zb_create(0x%X) - FAILED!!! [%s]",
602 ret, zigbee_error_to_string(ret));
609 static int run_destroy(MManager *mm, struct menu_data *menu)
611 if (NULL == handle) {
612 msg("Already destroyed or not created.");
624 static int run_enable(MManager *mm, struct menu_data *menu)
626 int ret = ZIGBEE_ERROR_NONE;
628 /* Set event callback */
629 ret = zb_set_event_cb(
633 if (ZIGBEE_ERROR_NONE != ret) {
634 msg("zb_set_event_cb(0x%X) - FAILED!!! [%s]",
635 ret, zigbee_error_to_string(ret));
639 msg(" - zb_set_event_cb() ret: [0x%X] [%s]",
640 ret, zigbee_error_to_string(ret));
646 if (ZIGBEE_ERROR_NONE != ret) {
647 msg("zb_enable(0x%X) - FAILED!!! [%s]",
648 ret, zigbee_error_to_string(ret));
652 msg(" - zb_enable() ret: [0x%X] [%s]",
653 ret, zigbee_error_to_string(ret));
658 static int run_disable(MManager *mm, struct menu_data *menu)
660 /* De-register event callback */
661 int ret = ZIGBEE_ERROR_NONE;
666 if (ZIGBEE_ERROR_NONE != ret) {
667 msg("zb_disable(0x%X) - FAILED!!! [%s]",
668 ret, zigbee_error_to_string(ret));
672 msg(" - zb_disable() ret: [0x%X] [%s]",
673 ret, zigbee_error_to_string(ret));
678 static int run_hw_reset(MManager *mm, struct menu_data *menu)
680 int ret = ZIGBEE_ERROR_NONE;
685 if (ZIGBEE_ERROR_NONE != ret) {
686 msg("zb_hw_reset(0x%X) - FAILED!!! [%s]",
687 ret, zigbee_error_to_string(ret));
691 msg(" - zb_hw_reset() ret: [0x%X] [%s]",
692 ret, zigbee_error_to_string(ret));
697 static int run_coex_start(MManager *mm, struct menu_data *menu)
699 int ret = ZIGBEE_ERROR_NONE;
700 unsigned char channel = 11;
706 if (ZIGBEE_ERROR_NONE != ret) {
707 msg("zb_coex_start(0x%X) - FAILED!!! [%s]",
708 ret, zigbee_error_to_string(ret));
712 msg(" - zb_coex_start() ret: [0x%X] [%s]",
713 ret, zigbee_error_to_string(ret));
718 static int run_coex_stop(MManager *mm, struct menu_data *menu)
720 int ret = ZIGBEE_ERROR_NONE;
725 if (ZIGBEE_ERROR_NONE != ret) {
726 msg("zb_coex_stop(0x%X) - FAILED!!! [%s]",
727 ret, zigbee_error_to_string(ret));
731 msg(" - zb_coex_stop() ret: [0x%X] [%s]",
732 ret, zigbee_error_to_string(ret));
737 static int run_get_network_info(MManager *mm, struct menu_data *menu)
739 int ret = ZIGBEE_ERROR_NONE;
742 unsigned char channel;
743 unsigned char tx_power;
745 ret = zb_get_network_info(
753 if (ZIGBEE_ERROR_NONE != ret) {
754 msg("zb_get_network_info(0x%X) - FAILED!!! [%s]",
755 ret, zigbee_error_to_string(ret));
759 msg(" - zb_get_network_info() ret: [0x%X] [%s]",
760 ret, zigbee_error_to_string(ret));
761 msg(" IEEE ADDR : %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
762 co_addr64[0], co_addr64[1], co_addr64[2],
763 co_addr64[3], co_addr64[4], co_addr64[5],
764 co_addr64[6], co_addr64[7]);
765 msg(" nodeID [0x%02X]", nodeid);
766 msg(" PanID [0x%02X]", panid);
767 msg(" Channel [%d] Tx Power [%d]", channel, tx_power);
772 static int run_get_controller_mac_address(MManager *mm, struct menu_data *menu)
774 int ret = ZIGBEE_ERROR_NONE;
776 ret = zb_get_controller_mac_address(handle, co_addr64);
777 if (ZIGBEE_ERROR_NONE != ret) {
778 msg("zb_get_controller_mac_address(%d) - FAILED!!! [%s]",
779 ret, zigbee_error_to_string(ret));
783 msg(" - zb_get_controller_mac_address() ret: [0x%X] [%s]",
784 ret, zigbee_error_to_string(ret));
785 msg(" IEEE ADDR : %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
786 co_addr64[0], co_addr64[1], co_addr64[2], co_addr64[3],
787 co_addr64[4], co_addr64[5], co_addr64[6], co_addr64[7]);
792 static int run_get_end_dev_info_list(MManager *mm, struct menu_data *menu)
794 int ret = ZIGBEE_ERROR_NONE;
799 unsigned char num_of_ep;
800 unsigned char *ep_list = NULL;
801 zb_end_dev_info_h *list = NULL;
804 ret = zb_end_dev_info_get_list(
809 for (i = 0; i < count && list; i++) {
810 zb_end_dev_info_get_network_address(
814 zb_end_dev_info_get_ieee_address(
819 msgb("[# %02d]", (i+1));
820 if (!strncmp((char *)sj_addr64, (char *)addr64, sizeof(addr64))) {
822 msgb(" Found [Samjin Power Outlet] !!");
824 if (!strncmp((char *)st_addr64, (char *)addr64, sizeof(addr64))) {
826 msgb(" Found [ST Open/Close Sensor] !!");
828 msg(" network address = 0x%02X", addr16);
829 msg(" IEEE address = %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
830 addr64[0], addr64[1], addr64[2], addr64[3],
831 addr64[4], addr64[5], addr64[6], addr64[7]);
833 zb_end_dev_info_get_num_of_ep(
837 msg(" number of end-points = 0x%04X", num_of_ep);
839 zb_end_dev_info_get_ep_list(
848 for (j = 0; j < num_of_ep; j++)
849 msgn("%04x ", ep_list[j]);
854 zb_end_dev_info_list_free(
858 msg(" - zb_end_dev_info_get_list() ret: [0x%X] [%s]",
859 ret, zigbee_error_to_string(ret));
864 static int run_get_endpoint_list(MManager *mm, struct menu_data *menu)
866 int ret = ZIGBEE_ERROR_NONE;
868 unsigned char count = 0;
869 zb_end_point *ep_list = NULL;
871 ret = zb_end_dev_get_endpoint_list(
876 if (ZIGBEE_ERROR_NONE != ret) {
877 msg("zb_end_dev_get_endpoint_list(%d) - FAILED!!! [%s]",
878 ret, zigbee_error_to_string(ret));
882 msg(" - zb_end_dev_get_endpoint_list() ret: [0x%X] [%s]",
883 ret, zigbee_error_to_string(ret));
884 msgb("Endpoints count [%d] : ", count);
885 for (i = 0; i < count; i++)
886 msgn(" %04d", ep_list[i]);
897 static int run_get_cluster_list(MManager *mm, struct menu_data *menu)
899 int ret = ZIGBEE_ERROR_NONE;
901 unsigned char ep = 1;
902 unsigned char in_count = 0;
903 unsigned char out_count = 0;
904 zb_cluster_id *in_cluster_list = NULL;
905 zb_cluster_id *out_cluster_list = NULL;
907 if (strlen(data_endpoint) > 0)
908 ep = (unsigned char)strtol(data_endpoint, NULL, 10);
910 ret = zb_end_dev_info_get_cluster_list(
918 if (ZIGBEE_ERROR_NONE != ret) {
919 msg("zb_end_dev_info_get_cluster_list (%d) - FAILED!!! [%s]",
920 ret, zigbee_error_to_string(ret));
924 msg(" - zb_end_dev_info_get_cluster_list() ret: [0x%X] [%s]",
925 ret, zigbee_error_to_string(ret));
926 msgb("In Clusters count [%d] : ", in_count);
927 for (i = 0; i < in_count; i++)
928 msgn(" %04X (%s)\n", in_cluster_list[i], zb_zcl_get_cluster_id_str(in_cluster_list[i]));
931 if (in_cluster_list) {
932 free(in_cluster_list);
933 in_cluster_list = NULL;
936 msgb("Out Clusters count [%d] : ", out_count);
937 for (i = 0; i < out_count; i++)
939 out_cluster_list[i], zb_zcl_get_cluster_id_str(out_cluster_list[i]));
942 if (out_cluster_list) {
943 free(out_cluster_list);
944 out_cluster_list = NULL;
950 static int run_choose_end_device_list(MManager *mm, struct menu_data *menu)
952 int ret = ZIGBEE_ERROR_NONE;
956 unsigned char num_of_ep;
957 zb_end_point *ep_list = NULL;
959 if (NULL != target_list)
960 zb_end_dev_info_list_free(target_list);
962 ret = zb_end_dev_info_get_list(
968 msg(" - zb_end_dev_info_get_list() ret: [0x%X] [%s]",
969 ret, zigbee_error_to_string(ret));
972 for (i = 0; i < target_list_count && target_list; i++) {
973 zb_end_dev_info_get_network_address(
977 zb_end_dev_info_get_ieee_address(
982 msgb("[# %02d] End device", (i+1));
983 if (!strncmp((char *)sj_addr64, (char *)addr64, sizeof(addr64))) {
985 msgb(" Found [Samjin Power Outlet] !!");
987 if (!strncmp((char *)st_addr64, (char *)addr64, sizeof(addr64))) {
989 msgb(" Found [ST Open/Close Sensor] !!");
991 msg(" network address = 0x%02X", addr16);
992 msg(" IEEE address = %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
993 addr64[0], addr64[1], addr64[2], addr64[3],
994 addr64[4], addr64[5], addr64[6], addr64[7]);
996 zb_end_dev_info_get_num_of_ep(
1000 msg(" number of end-points = 0x%04X", num_of_ep);
1002 zb_end_dev_info_get_ep_list(
1008 if (NULL == ep_list)
1011 for (j = 0; j < num_of_ep; j++)
1012 msgn("%04x ", ep_list[j]);
1021 static int run_select_device(MManager *mm, struct menu_data *menu)
1024 int selected = (int)strtol(data_choose_target, NULL, 10);
1027 /* Apply manual address first */
1028 if (strlen(data_dest_addr16) > 0) {
1029 dest_addr16 = (unsigned short)strtol(data_dest_addr16, NULL, 16);
1030 msg(" network addr [0x%04X] selected.", dest_addr16);
1031 memset(data_dest_addr16, '\0', MENU_DATA_SIZE + 1);
1035 if (NULL == target_list) {
1036 msg("Please select device list first !");
1040 if (selected <= 0) {
1041 msg("Please input valid device index !");
1045 for (i = 0; i < target_list_count && target_list; i++) {
1046 if (selected == (i+1)) {
1047 zb_end_dev_info_get_network_address(
1051 zb_end_dev_info_get_ieee_address(
1055 dest_addr16 = addr16;
1056 msg(" network addr [0x%04X] selected.", dest_addr16);
1057 msg(" ieee address = %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
1058 dest_addr64[0], dest_addr64[1], dest_addr64[2], dest_addr64[3],
1059 dest_addr64[4], dest_addr64[5], dest_addr64[6], dest_addr64[7]);
1064 msg(" Index [%d] was not found from end device list", selected);
1069 static int run_form_network(MManager *mm, struct menu_data *menu)
1071 int ret = ZIGBEE_ERROR_NONE;
1073 ret = zb_form_network(
1075 _zb_form_network_done_cb,
1078 if (ZIGBEE_ERROR_NONE != ret) {
1079 msg("zb_form_network(0x%X) - FAILED!!! [%s]",
1080 ret, zigbee_error_to_string(ret));
1084 msg(" - zb_form_network() ret: [0x%X] [%s]",
1085 ret, zigbee_error_to_string(ret));
1090 static int run_disable_network(MManager *mm, struct menu_data *menu)
1092 int ret = ZIGBEE_ERROR_NONE;
1094 ret = zb_disable_network(
1096 _zb_disable_network_done_cb,
1099 if (ZIGBEE_ERROR_NONE != ret) {
1100 msg("zb_disable_network(0x%X) - FAILED!!! [%s]",
1101 ret, zigbee_error_to_string(ret));
1105 msg(" - zb_disable_network() ret: [0x%X] [%s]",
1106 ret, zigbee_error_to_string(ret));
1111 static int run_leave_device(MManager *mm, struct menu_data *menu)
1113 int ret = ZIGBEE_ERROR_NONE;
1114 bool remove_children = true;
1115 bool rejoin = false;
1116 unsigned char var = 0;
1118 if (strlen(data_remove_children)) {
1119 var = (unsigned char)strtol(data_remove_children, NULL, 10);
1120 remove_children = (var == 0) ? false : true;
1122 if (strlen(data_rejoin)) {
1123 var = (unsigned char)strtol(data_rejoin, NULL, 10);
1124 rejoin = (var == 0) ? false : true;
1127 ret = zb_leave_device(
1133 if (ret != ZIGBEE_ERROR_NONE) {
1134 msg("zb_leave_device(0x%X) - FAILED!!! [%s]",
1135 ret, zigbee_error_to_string(ret));
1139 msg(" - zb_leave_device() ret: [0x%X] [%s]",
1140 ret, zigbee_error_to_string(ret));
1145 static int run_permit_join(MManager *mm, struct menu_data *menu)
1147 int ret = ZIGBEE_ERROR_NONE;
1148 unsigned char timeout = 90;
1150 if (strlen(data_pj_timeout))
1151 timeout = (unsigned char)strtol(data_pj_timeout, NULL, 10);
1153 ret = zb_permit_join(
1157 if (ZIGBEE_ERROR_NONE != ret) {
1158 msg("zb_permit_join(0x%X) - FAILED!!! [%s]",
1159 ret, zigbee_error_to_string(ret));
1163 msg(" - zb_permit_join() ret: [0x%X] [%s]",
1164 ret, zigbee_error_to_string(ret));
1169 struct menu_data menu_sel_device[] = {
1170 { "1", "Device list", NULL, run_choose_end_device_list, data_choose_target },
1171 { "2", "Input network addr manually (hex)", NULL, NULL, data_dest_addr16 },
1172 { "3", "Apply", NULL, run_select_device, NULL },
1176 static struct menu_data _menu_get_cluster_list[] = {
1177 { "1", "Endpoint", NULL, NULL, data_endpoint },
1178 { "2", "Run", NULL, run_get_cluster_list, NULL },
1182 static struct menu_data menu_device[] = {
1183 { "1", "zb_create", NULL, run_create, NULL },
1184 { "2", "zb_destroy", NULL, run_destroy, NULL },
1185 { "3", "zb_enable", NULL, run_enable, NULL },
1186 { "4", "zb_disable", NULL, run_disable, NULL },
1187 { "5", "zb_hw_reset", NULL, run_hw_reset, NULL },
1188 { "6", "zb_coex_start", NULL, run_coex_start, NULL },
1189 { "7", "zb_coex_stop", NULL, run_coex_stop, NULL },
1190 { "8", "zb_end_dev_info_get_list", NULL, run_get_end_dev_info_list, NULL },
1191 { "9", "zb_get_endpoint_list", NULL, run_get_endpoint_list, NULL },
1192 { "10", "zb_end_dev_info_get_cluster_list ", _menu_get_cluster_list, NULL, NULL },
1196 static struct menu_data _menu_leave_device[] = {
1197 { "1", "Remove children", NULL, NULL, data_remove_children },
1198 { "2", "Rejoin", NULL, NULL, data_rejoin },
1199 { "3", "Run", NULL, run_leave_device, NULL },
1203 static struct menu_data _menu_permit_join[] = {
1204 { "1", "Timeout", NULL, NULL, data_pj_timeout },
1205 { "2", "Run", NULL, run_permit_join, NULL },
1209 static struct menu_data menu_network[] = {
1210 { "1", "zb_get_network_info", NULL, run_get_network_info, NULL },
1211 { "2", "zb_get_controller_mac_address", NULL, run_get_controller_mac_address, NULL },
1212 { "3", "zb_form_network", NULL, run_form_network, NULL },
1213 { "4", "zb_disable_network", NULL, run_disable_network, NULL },
1214 { "5", "zb_leave_device", _menu_leave_device, NULL, NULL },
1215 { "6", "zb_permit_join", _menu_permit_join, NULL, NULL },
1219 static struct menu_data menu_zcl[] = {
1220 { "1", "Global Commands", menu_zcl_global, NULL, NULL },
1221 { "2", "Cluster Commands", menu_zcl_cluster, NULL, NULL },
1225 static struct menu_data menu_zdo[] = {
1226 { "1", "Binding Manager", menu_zdo_binding, NULL, NULL },
1227 { "2", "Device Discovery", menu_zdo_device, NULL, NULL },
1228 { "3", "Network Manager", menu_zdo_network, NULL, NULL },
1232 static struct menu_data menu_main[] = {
1233 { "1", "Device", menu_device, NULL, NULL },
1234 { "2", "Network", menu_network, NULL, NULL },
1235 { "3", "Cluster Library", menu_zcl, NULL, NULL },
1236 { "4", "Device Object", menu_zdo, NULL, NULL },
1237 { "5", "Custom", menu_custom, NULL, NULL },
1241 static int __select_handle_register_event(MManager *mm, struct menu_data *menu)
1245 if (NULL != handle) {
1257 if (ZIGBEE_ERROR_NONE != ret) {
1258 msg("zb_create(0x%X) - FAILED!!! [%s]",
1259 ret, zigbee_error_to_string(ret));
1262 msg("zb_create(0x%X) - SUCCESS!!!. handle [%p]", ret, handle);
1265 /* Set event callback */
1266 ret = zb_set_event_cb(
1270 if (ZIGBEE_ERROR_NONE != ret) {
1271 msg("zb_set_event_cb(0x%X) - FAILED!!!", ret);
1275 msg(" - zb_set_event_cb() ret: [0x%X] [%s]",
1276 ret, zigbee_error_to_string(ret));
1282 if (ZIGBEE_ERROR_PERMISSION_DENIED == ret) {
1283 /* Admin permission is not set, but we can do normal operations */
1284 msg("zb_enable(0x%X) - FAILED!!!", ret);
1285 } else if (ZIGBEE_ERROR_NONE != ret) {
1286 msg("zb_enable(0x%X) - FAILED!!! [%s]",
1287 ret, zigbee_error_to_string(ret));
1291 msg(" - zb_enable() ret: [0x%X] [%s]",
1292 ret, zigbee_error_to_string(ret));
1294 /* Set coordinator address */
1295 ret = zb_get_controller_mac_address(
1299 if (ZIGBEE_ERROR_NONE != ret)
1300 msg("zb_get_controller_mac_address(%d) - FAILED!!! [%s]",
1301 ret, zigbee_error_to_string(ret));
1303 msg(" Coordinator Address:");
1304 msg(" %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
1305 co_addr64[0], co_addr64[1], co_addr64[2], co_addr64[3],
1306 co_addr64[4], co_addr64[5], co_addr64[6], co_addr64[7]);
1308 menu_manager_set_user_data(mm, handle);
1313 static gboolean __create_init_menu(struct menu_data init_menu[1])
1315 init_menu[0].key = "1";
1316 init_menu[0].title = "Init";
1317 init_menu[0].sub_menu = menu_main;
1318 init_menu[0].callback = __select_handle_register_event;
1319 init_menu[0].data = NULL;
1324 int main(int arg, char **argv)
1326 GMainLoop *mainloop = NULL;
1327 GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
1329 struct menu_data init_menu[1+1] = { {NULL, NULL, } };
1331 #if !GLIB_CHECK_VERSION(2, 35, 0)
1334 #if !GLIB_CHECK_VERSION(2, 31, 0)
1335 g_thread_init(NULL);
1337 mainloop = g_main_loop_new(NULL, FALSE);
1340 msg("* ZigBee Test application ");
1341 msg("* Build On: %s %s", __DATE__, __TIME__);
1343 if (__create_init_menu(init_menu) == FALSE)
1346 manager = menu_manager_new(init_menu, mainloop);
1350 menu_manager_run(manager);
1352 g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
1353 on_menu_manager_keyboard, manager);
1354 g_main_loop_run(mainloop);
1357 if (NULL != target_list)
1358 zb_end_dev_info_list_free(
1367 g_main_loop_unref(mainloop);
1368 msg("******* Bye bye *******");