Change 'enable' method to async operation
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_service.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Contact: Suresh Kumar N (suresh.n@samsung.com)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include "zigbee_service_interface_common.h"
20
21 #include <zblib_driver_service.h>
22
23 static void *_service_interface_ref_zigbee_service(ZigBeeServiceInterface *service_interface)
24 {
25         ZigbeeObjectSkeleton *zigbee_object = NULL;
26         ZigbeeCustomData_t *custom_data = NULL;
27         ZigbeeService *service = NULL;
28
29         custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
30         if (NULL == custom_data) {
31                 Z_LOGE("D-BUS service interface custom_data is NULL!");
32                 return NULL;
33         }
34
35         /* Get zigbee object */
36         zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
37         if (NULL == zigbee_object) {
38                 Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
39                 return NULL;
40         }
41
42         service = zigbee_object_get_service(ZIGBEE_OBJECT(zigbee_object));
43         return service;
44 }
45
46 static void on_service_zb_hw_reset_resp(ZigBeeServiceInterface *service_interface,
47         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
48 {
49         ZigbeeServiceInterfaceRespCbData_t *cb_data =
50                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
51
52         ZigbeeService *service_object;
53         GDBusMethodInvocation *invocation;
54         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
55
56         NOT_USED(service_interface);
57         NOT_USED(request_id);
58
59         if (NULL == resp_data || 0 == resp_data_len) {
60                 Z_LOGE("resp_data is null");
61                 g_free(cb_data);
62                 return;
63         }
64
65         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
66         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
67
68         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
69         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
70
71         zigbee_service_complete_zb_hw_reset(service_object, invocation, payload->result);
72
73         g_free(cb_data);
74 }
75
76 static gboolean on_service_zb_hw_reset(ZigbeeService *service_object,
77         GDBusMethodInvocation *invocation,
78         gpointer user_data)
79 {
80         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
81         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
82
83         gboolean ret;
84
85         /* Allocate response callback data */
86         resp_cb_data =
87                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
88                         invocation, NULL, 0);
89         if (NULL == resp_cb_data) {
90                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
91
92                 /* Send failure response */
93                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
94
95                 return TRUE;
96         }
97
98         /* Dispatch request */
99         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
100                 ZBLIB_DRIVER_TYPE_SERVICE,
101                 ZBLIB_SERVICE_OPS_ZB_HW_RESET,
102                 NULL, 0,
103                 on_service_zb_hw_reset_resp, resp_cb_data);
104         if (FALSE == ret) {
105                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
106
107                 /* Free response callback data */
108                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
109
110                 /* Send failure response */
111                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
112
113                 return TRUE;
114         }
115
116         return TRUE;
117 }
118
119 static void on_service_form_network_resp(ZigBeeServiceInterface *service_interface,
120         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
121 {
122         ZigbeeServiceInterfaceRespCbData_t *cb_data =
123                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
124
125         ZigbeeService *service_object;
126         GDBusMethodInvocation *invocation;
127         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
128
129         NOT_USED(service_interface);
130         NOT_USED(request_id);
131
132         if (NULL == resp_data || 0 == resp_data_len) {
133                 Z_LOGE("resp_data is null");
134                 g_free(cb_data);
135                 return;
136         }
137
138         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
139         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
140
141         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
142         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
143
144         zigbee_service_complete_form_network(service_object, invocation, payload->result);
145
146         g_free(cb_data);
147 }
148
149 static gboolean on_service_form_network(ZigbeeService *service_object,
150         GDBusMethodInvocation *invocation,
151         gpointer user_data)
152 {
153         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
154         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
155
156         gboolean ret;
157
158         /* Allocate response callback data */
159         resp_cb_data =
160                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
161                         invocation, NULL, 0);
162         if (NULL == resp_cb_data) {
163                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
164
165                 /* Send failure response */
166                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
167
168                 return TRUE;
169         }
170
171         /* Dispatch request */
172         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
173                 ZBLIB_DRIVER_TYPE_SERVICE,
174                 ZBLIB_SERVICE_OPS_FORM_NETWORK,
175                 NULL, 0,
176                 on_service_form_network_resp, resp_cb_data);
177         if (FALSE == ret) {
178                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
179
180                 /* Free response callback data */
181                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
182
183                 /* Send failure response */
184                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
185
186                 return TRUE;
187         }
188
189         return TRUE;
190 }
191
192 static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface,
193         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
194 {
195         ZigbeeServiceInterfaceRespCbData_t *cb_data =
196                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
197
198         ZigbeeService *service_object;
199         GDBusMethodInvocation *invocation;
200         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
201
202         NOT_USED(service_interface);
203         NOT_USED(request_id);
204
205         if (NULL == resp_data || 0 == resp_data_len) {
206                 Z_LOGE("resp_data is null");
207                 g_free(cb_data);
208                 return;
209         }
210
211         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
212         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
213
214         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
215         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
216
217         zigbee_service_complete_coex_start(service_object, invocation, payload->result);
218
219         g_free(cb_data);
220 }
221
222 static gboolean on_service_coex_start(ZigbeeService *service_object,
223         GDBusMethodInvocation *invocation,
224         gchar channel,
225         gpointer user_data)
226 {
227         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
228         ZigbeeServiceCoexStart_t req;
229         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
230
231         gboolean ret;
232
233         memset(&req, 0x0, sizeof(ZigbeeServiceCoexStart_t));
234
235         /* Update request structure */
236         req.channel = channel;
237
238         /* Allocate response callback data */
239         resp_cb_data =
240                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
241                         invocation, NULL, 0);
242         if (NULL == resp_cb_data) {
243                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
244
245                 /* Send failure response */
246                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
247
248                 return TRUE;
249         }
250
251         /* Dispatch request */
252         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
253                 ZBLIB_DRIVER_TYPE_SERVICE,
254                 ZBLIB_SERVICE_OPS_COEX_START,
255                 &req, sizeof(req),
256                 on_service_coex_start_resp, resp_cb_data);
257         if (FALSE == ret) {
258                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
259
260                 /* Free response callback data */
261                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
262
263                 /* Send failure response */
264                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
265
266                 return TRUE;
267         }
268
269         return TRUE;
270 }
271
272 static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface,
273         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
274 {
275         ZigbeeServiceInterfaceRespCbData_t *cb_data =
276                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
277
278         ZigbeeService *service_object;
279         GDBusMethodInvocation *invocation;
280         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
281
282         NOT_USED(service_interface);
283         NOT_USED(request_id);
284
285         if (NULL == resp_data || 0 == resp_data_len) {
286                 Z_LOGE("resp_data is null");
287                 g_free(cb_data);
288                 return;
289         }
290
291         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
292         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
293
294         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
295         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
296
297         zigbee_service_complete_coex_stop(service_object, invocation, payload->result);
298
299         g_free(cb_data);
300 }
301
302 static gboolean on_service_coex_stop(ZigbeeService *service_object,
303         GDBusMethodInvocation *invocation,
304         gpointer user_data)
305 {
306         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
307         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
308
309         gboolean ret;
310
311         /* Allocate response callback data */
312         resp_cb_data =
313                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
314                         invocation, NULL, 0);
315         if (NULL == resp_cb_data) {
316                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
317
318                 /* Send failure response */
319                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
320
321                 return TRUE;
322         }
323
324         /* Dispatch request */
325         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
326                 ZBLIB_DRIVER_TYPE_SERVICE,
327                 ZBLIB_SERVICE_OPS_COEX_STOP,
328                 NULL, 0,
329                 on_service_coex_stop_resp, resp_cb_data);
330         if (FALSE == ret) {
331                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
332
333                 /* Free response callback data */
334                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
335
336                 /* Send failure response */
337                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
338
339                 return TRUE;
340         }
341
342         return TRUE;
343 }
344
345 static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interface,
346         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
347 {
348         ZigbeeServiceInterfaceRespCbData_t *cb_data =
349                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
350
351         ZigbeeService *service_object;
352         GDBusMethodInvocation *invocation;
353         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
354
355         NOT_USED(service_interface);
356         NOT_USED(request_id);
357
358         if (NULL == resp_data || 0 == resp_data_len) {
359                 Z_LOGE("resp_data is null");
360                 g_free(cb_data);
361                 return;
362         }
363
364         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
365         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
366
367         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
368         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
369
370         zigbee_service_complete_leave_network(service_object, invocation, payload->result);
371
372         g_free(cb_data);
373 }
374
375 static gboolean on_service_leave_network(ZigbeeService *service_object,
376         GDBusMethodInvocation *invocation,
377         gpointer user_data)
378 {
379         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
380         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
381
382         gboolean ret;
383
384         /* Allocate response callback data */
385         resp_cb_data =
386                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
387                         invocation, NULL, 0);
388         if (NULL == resp_cb_data) {
389                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
390
391                 /* Send failure response */
392                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
393
394                 return TRUE;
395         }
396
397         /* Dispatch request */
398         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
399                 ZBLIB_DRIVER_TYPE_SERVICE,
400                 ZBLIB_SERVICE_OPS_LEAVE_NETWORK,
401                 NULL, 0,
402                 on_service_leave_network_resp, resp_cb_data);
403         if (FALSE == ret) {
404                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
405
406                 /* Free response callback data */
407                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
408
409                 /* Send failure response */
410                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
411
412                 return TRUE;
413         }
414
415         return TRUE;
416 }
417
418 static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_interface,
419         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
420 {
421         ZigbeeServiceInterfaceRespCbData_t *cb_data =
422                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
423
424         ZigbeeService *service_object;
425         GDBusMethodInvocation *invocation;
426
427         ZigbeeServiceGetNetworkInfoResp_t *payload =
428                 (ZigbeeServiceGetNetworkInfoResp_t*)resp_data;
429
430         GVariant *v_eui64 = NULL;
431
432         NOT_USED(service_interface);
433         NOT_USED(request_id);
434
435         if (NULL == resp_data || 0 == resp_data_len) {
436                 Z_LOGE("resp_data is null");
437                 g_free(cb_data);
438                 return;
439         }
440
441         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
442         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
443
444         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
445         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
446
447         v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
448                 payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
449
450         zigbee_service_complete_get_network_info(service_object, invocation,
451                 payload->result, v_eui64, payload->node_id,
452                 payload->pan_id, payload->channel, payload->radio_tx_power);
453
454         g_free(cb_data);
455 }
456
457 static gboolean on_service_get_network_info(ZigbeeService *service_object,
458         GDBusMethodInvocation *invocation,
459         gpointer user_data)
460 {
461         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
462         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
463
464         gboolean ret;
465
466         /* Allocate response callback data */
467         resp_cb_data =
468                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
469                         invocation, NULL, 0);
470         if (NULL == resp_cb_data) {
471                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
472
473                 /* Send failure response */
474                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
475
476                 return TRUE;
477         }
478
479         /* Dispatch request */
480         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
481                 ZBLIB_DRIVER_TYPE_SERVICE,
482                 ZBLIB_SERVICE_OPS_GET_NETWORK_INFO,
483                 NULL, 0,
484                 on_service_get_network_info_resp, resp_cb_data);
485         if (FALSE == ret) {
486                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
487
488                 /* Free response callback data */
489                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
490
491                 /* Send failure response */
492                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
493
494                 return TRUE;
495         }
496
497         return TRUE;
498 }
499
500 static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interface,
501         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
502 {
503         ZigbeeServiceInterfaceRespCbData_t *cb_data =
504                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
505
506         ZigbeeService *service_object;
507         GDBusMethodInvocation *invocation;
508         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
509
510         NOT_USED(service_interface);
511         NOT_USED(request_id);
512
513         if (NULL == resp_data || 0 == resp_data_len) {
514                 Z_LOGE("resp_data is null");
515                 g_free(cb_data);
516                 return;
517         }
518
519         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
520         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
521
522         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
523         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
524
525         zigbee_service_complete_permit_join(service_object, invocation, payload->result);
526
527         g_free(cb_data);
528 }
529
530 static gboolean on_service_permit_join(ZigbeeService *service_object,
531         GDBusMethodInvocation *invocation,
532         gint duration,
533         gboolean permit_join,
534         gpointer user_data)
535 {
536         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
537         ZigbeeServicePermitJoin_t req;
538         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
539
540         gboolean ret;
541
542         memset(&req, 0x0, sizeof(ZigbeeServicePermitJoin_t));
543
544         /* Update request structure */
545         req.duration = duration;
546         req.permit_join = permit_join;
547
548         /* Allocate response callback data */
549         resp_cb_data =
550                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
551                         invocation, NULL, 0);
552         if (NULL == resp_cb_data) {
553                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
554
555                 /* Send failure response */
556                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
557
558                 return TRUE;
559         }
560
561         /* Dispatch request */
562         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
563                 ZBLIB_DRIVER_TYPE_SERVICE,
564                 ZBLIB_SERVICE_OPS_PERMIT_JOIN,
565                 &req, sizeof(req),
566                 on_service_permit_join_resp, resp_cb_data);
567         if (FALSE == ret) {
568                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
569
570                 /* Free response callback data */
571                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
572
573                 /* Send failure response */
574                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
575
576                 return TRUE;
577         }
578
579         return TRUE;
580 }
581
582 static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interface,
583         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
584 {
585         ZigbeeServiceInterfaceRespCbData_t *cb_data =
586                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
587
588         ZigbeeService *service_object;
589         GDBusMethodInvocation *invocation;
590         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
591
592         NOT_USED(service_interface);
593         NOT_USED(request_id);
594
595         if (NULL == resp_data || 0 == resp_data_len) {
596                 Z_LOGE("resp_data is null");
597                 g_free(cb_data);
598                 return;
599         }
600
601         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
602         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
603
604         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
605         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
606
607         zigbee_service_complete_leave_request(service_object, invocation, payload->result);
608
609         g_free(cb_data);
610 }
611
612 static gboolean on_service_leave_request(ZigbeeService *service_object,
613         GDBusMethodInvocation *invocation,
614         GVariant *eui64,
615         gchar remove_child,
616         gchar rejoin,
617         gpointer user_data)
618 {
619         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
620         ZigbeeServiceLeaveRequest_t req;
621         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
622
623         GVariantIter *iter = NULL;
624         guint i = 0;
625
626         gboolean ret;
627
628         memset(&req, 0x0, sizeof(ZigbeeServiceLeaveRequest_t));
629
630         /* Update request structure */
631         g_variant_get(eui64, "a(y)", &iter);
632         while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
633                 i++;
634                 if (i >= ZIGBEE_EUI64_SIZE)
635                         break;
636         }
637         req.remove_child = remove_child;
638         req.rejoin = rejoin;
639
640         Z_LOGD("IEEE Address = %X:%X:%X:%X:%X:%X:%X:%X",
641                 req.eui64[0], req.eui64[1], req.eui64[2], req.eui64[3],
642                 req.eui64[4], req.eui64[5], req.eui64[6], req.eui64[7]);
643         Z_LOGD("remove_child [%d]", remove_child);
644         Z_LOGD("rejoin [%d]", rejoin);
645
646         /* Allocate response callback data */
647         resp_cb_data =
648                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
649                         invocation, NULL, 0);
650         if (NULL == resp_cb_data) {
651                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
652
653                 /* Send failure response */
654                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
655
656                 return TRUE;
657         }
658
659         /* Dispatch request */
660         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
661                 ZBLIB_DRIVER_TYPE_SERVICE,
662                 ZBLIB_SERVICE_OPS_LEAVE_REQUEST,
663                 &req, sizeof(req),
664                 on_service_leave_request_resp, resp_cb_data);
665         if (FALSE == ret) {
666                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
667
668                 /* Free response callback data */
669                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
670
671                 /* Send failure response */
672                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
673
674                 return TRUE;
675         }
676
677         return TRUE;
678 }
679
680 static void on_service_get_device_list_resp(ZigBeeServiceInterface *service_interface,
681         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
682 {
683         ZigbeeServiceInterfaceRespCbData_t *cb_data =
684                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
685
686         ZigbeeService *service_object;
687         GDBusMethodInvocation *invocation;
688
689         NOT_USED(service_interface);
690         NOT_USED(request_id);
691
692         if (NULL == resp_data || 0 == resp_data_len) {
693                 Z_LOGE("resp_data is null");
694                 g_free(cb_data);
695                 return;
696         }
697
698         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
699         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
700
701         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
702         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
703
704         /* To-To : zigbee_service_complete_get_device_list */
705         //zigbee_service_complete_get_device_list(service_object, invocation,   resp_data);
706
707         g_free(cb_data);
708 }
709
710 static gboolean on_service_get_device_list(ZigbeeService *service_object,
711         GDBusMethodInvocation *invocation,
712         gpointer user_data)
713 {
714         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
715         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
716
717         gboolean ret;
718
719         /* Allocate response callback data */
720         resp_cb_data =
721                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
722                         invocation, NULL, 0);
723         if (NULL == resp_cb_data) {
724                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
725
726                 /* Send failure response */
727                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
728
729                 return TRUE;
730         }
731
732         /* Dispatch request */
733         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
734                 ZBLIB_DRIVER_TYPE_SERVICE,
735                 ZBLIB_SERVICE_OPS_GET_DEVICE_LIST,
736                 NULL, 0,
737                 on_service_get_device_list_resp, resp_cb_data);
738         if (FALSE == ret) {
739                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
740
741                 /* Free response callback data */
742                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
743
744                 /* Send failure response */
745                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
746
747                 return TRUE;
748         }
749
750         return TRUE;
751 }
752
753 static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface,
754         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
755 {
756         ZigbeeServiceInterfaceRespCbData_t *cb_data =
757                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
758
759         ZigbeeService *service_object;
760         GDBusMethodInvocation *invocation;
761         ZigbeeServiceGetMacResp_t *payload =
762                 (ZigbeeServiceGetMacResp_t*)resp_data;
763
764         GVariant *v_eui64 = NULL;
765
766         NOT_USED(service_interface);
767         NOT_USED(request_id);
768
769         if (NULL == resp_data || 0 == resp_data_len) {
770                 Z_LOGE("resp_data is null");
771                 g_free(cb_data);
772                 return;
773         }
774
775         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
776         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
777
778         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
779         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
780
781         v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
782                 payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
783
784         zigbee_service_complete_get_mac(service_object, invocation, payload->result,
785                 v_eui64);
786
787         g_free(cb_data);
788 }
789
790 static gboolean on_service_get_mac(ZigbeeService *service_object,
791         GDBusMethodInvocation *invocation,
792         gpointer user_data)
793 {
794         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
795         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
796
797         gboolean ret;
798
799         /* Allocate response callback data */
800         resp_cb_data =
801                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
802                         invocation, NULL, 0);
803         if (NULL == resp_cb_data) {
804                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
805
806                 /* Send failure response */
807                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
808
809                 return TRUE;
810         }
811
812         /* Dispatch request */
813         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
814                 ZBLIB_DRIVER_TYPE_SERVICE,
815                 ZBLIB_SERVICE_OPS_GET_MAC,
816                 NULL, 0,
817                 on_service_get_mac_resp, resp_cb_data);
818         if (FALSE == ret) {
819                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
820
821                 /* Free response callback data */
822                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
823
824                 /* Send failure response */
825                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
826
827                 return TRUE;
828         }
829
830         return TRUE;
831 }
832
833 static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_interface,
834         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
835 {
836         ZigbeeServiceInterfaceRespCbData_t *cb_data =
837                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
838
839         ZigbeeService *service_object;
840         GDBusMethodInvocation *invocation;
841         ZigbeeServiceGetDeviceInfoResp_t *payload =
842                 (ZigbeeServiceGetDeviceInfoResp_t*)resp_data;
843
844         GVariant *variant = NULL;
845         GVariantBuilder* builder = NULL;
846         int i = 0;
847         int index = 0;
848
849         NOT_USED(service_interface);
850         NOT_USED(request_id);
851
852         if (NULL == resp_data || 0 == resp_data_len) {
853                 Z_LOGE("resp_data is null");
854                 g_free(cb_data);
855                 return;
856         }
857
858         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
859         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
860
861         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
862         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
863
864         builder = g_variant_builder_new(G_VARIANT_TYPE ("a(qyayyay)"));
865         for (index = 0; index < payload->count; index++) {
866                 ZigbeeServiceGetDeviceInfoDetailResp_t *device = &(payload->list[index]);
867                 GVariantBuilder* mac_builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
868                 GVariantBuilder* endpoint_builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
869
870                 for (i = 0; i < ZIGBEE_EUI64_SIZE; i++) {
871                         g_variant_builder_add (mac_builder, "y", device->eui64[i]);
872                 }
873                 for (i = 0; i < device->endpoint_count; i++) {
874                         g_variant_builder_add (endpoint_builder, "y", device->endpoints[i]);
875                 }
876
877                 g_variant_builder_add (builder, "(qyayyay)",
878                         device->node_id, device->node_type,
879                         mac_builder, device->endpoint_count, endpoint_builder);
880
881                 g_variant_builder_unref (mac_builder);
882                 g_variant_builder_unref (endpoint_builder);
883         }
884
885         variant = g_variant_builder_end(builder);
886         zigbee_service_complete_get_device_info(service_object, invocation,
887                 payload->result, variant);
888
889         g_free(cb_data);
890 }
891
892 static gboolean on_service_get_device_info(ZigbeeService *service_object,
893         GDBusMethodInvocation *invocation,
894         gpointer user_data)
895 {
896         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
897         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
898
899         gboolean ret;
900
901         /* Allocate response callback data */
902         resp_cb_data =
903                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
904                         invocation, NULL, 0);
905         if (NULL == resp_cb_data) {
906                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
907
908                 /* Send failure response */
909                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
910
911                 return TRUE;
912         }
913
914         /* Dispatch request */
915         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
916                 ZBLIB_DRIVER_TYPE_SERVICE,
917                 ZBLIB_SERVICE_OPS_GET_DEVICE_INFO,
918                 NULL, 0,
919                 on_service_get_device_info_resp, resp_cb_data);
920         if (FALSE == ret) {
921                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
922
923                 /* Free response callback data */
924                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
925
926                 /* Send failure response */
927                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
928
929                 return TRUE;
930         }
931
932         return TRUE;
933 }
934
935 static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_interface,
936         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
937 {
938         ZigbeeServiceInterfaceRespCbData_t *cb_data =
939                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
940
941         ZigbeeService *service_object;
942         GDBusMethodInvocation *invocation;
943         ZigbeeServiceGetEndpointListResp_t *payload =
944                 (ZigbeeServiceGetEndpointListResp_t*)resp_data;
945         GVariant *v_endpoints = NULL;
946
947         NOT_USED(service_interface);
948         NOT_USED(request_id);
949
950         if (NULL == resp_data || 0 == resp_data_len) {
951                 Z_LOGE("resp_data is null");
952                 g_free(cb_data);
953                 return;
954         }
955
956         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
957         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
958
959         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
960         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
961
962         v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
963                 payload->endpoints, payload->endpoint_count, TRUE, NULL, NULL);
964
965         zigbee_service_complete_get_endpoint_list(service_object, invocation,
966                 payload->result, v_endpoints);
967
968         g_free(cb_data);
969 }
970
971 static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
972         GDBusMethodInvocation *invocation,
973         GVariant *eui64,
974         gpointer user_data)
975 {
976         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
977         ZigbeeServiceGetEndpointList_t req;
978         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
979
980         GVariantIter *iter = NULL;
981         guint i = 0;
982
983         gboolean ret;
984
985         memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
986
987         /* Update request structure */
988         g_variant_get(eui64, "a(y)", &iter);
989         while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
990                 i++;
991                 if (i >= ZIGBEE_EUI64_SIZE)
992                         break;
993         }
994
995         /* Allocate response callback data */
996         resp_cb_data =
997                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
998                         invocation, NULL, 0);
999         if (NULL == resp_cb_data) {
1000                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1001
1002                 /* Send failure response */
1003                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1004
1005                 return TRUE;
1006         }
1007
1008         /* Dispatch request */
1009         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1010                 ZBLIB_DRIVER_TYPE_SERVICE,
1011                 ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST,
1012                 &req, sizeof(req),
1013                 on_service_get_endpoint_list_resp, resp_cb_data);
1014         if (FALSE == ret) {
1015                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1016
1017                 /* Free response callback data */
1018                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1019
1020                 /* Send failure response */
1021                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1022
1023                 return TRUE;
1024         }
1025
1026         return TRUE;
1027 }
1028
1029 static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_interface,
1030         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1031 {
1032         ZigbeeServiceInterfaceRespCbData_t *cb_data =
1033                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1034
1035         ZigbeeService *service_object;
1036         GDBusMethodInvocation *invocation;
1037         ZigbeeServiceGetClusterListResp_t *payload =
1038                 (ZigbeeServiceGetClusterListResp_t*)resp_data;
1039         GVariant *v_in_clusters = NULL;
1040         GVariant *v_out_clusters = NULL;
1041
1042         NOT_USED(service_interface);
1043         NOT_USED(request_id);
1044
1045         if (NULL == resp_data || 0 == resp_data_len) {
1046                 Z_LOGE("resp_data is null");
1047                 g_free(cb_data);
1048                 return;
1049         }
1050
1051         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1052         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
1053
1054         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1055         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1056
1057         v_in_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1058                 payload->in_clusters, (payload->in_cluster_count * sizeof(unsigned short)),
1059                 TRUE, NULL, NULL);
1060         v_out_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1061                 payload->out_clusters, (payload->out_cluster_count * sizeof(unsigned short)),
1062                 TRUE, NULL, NULL);
1063
1064         zigbee_service_complete_get_cluster_list(service_object, invocation,
1065                 payload->result, v_in_clusters, v_out_clusters);
1066
1067         g_free(cb_data);
1068 }
1069
1070 static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
1071         GDBusMethodInvocation *invocation,
1072         GVariant *eui64,
1073         gchar endpoint,
1074         gpointer user_data)
1075 {
1076         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1077         ZigbeeServiceGetClusterList_t req;
1078         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1079
1080         GVariantIter *iter = NULL;
1081         guint i = 0;
1082
1083         gboolean ret;
1084
1085         memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
1086
1087         /* Update request structure */
1088         g_variant_get(eui64, "a(y)", &iter);
1089         while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
1090                 i++;
1091                 if (i >= ZIGBEE_EUI64_SIZE)
1092                         break;
1093         }
1094         req.endpoint = endpoint;
1095
1096         /* Allocate response callback data */
1097         resp_cb_data =
1098                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1099                         invocation, NULL, 0);
1100         if (NULL == resp_cb_data) {
1101                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1102
1103                 /* Send failure response */
1104                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1105
1106                 return TRUE;
1107         }
1108
1109         /* Dispatch request */
1110         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1111                 ZBLIB_DRIVER_TYPE_SERVICE,
1112                 ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST,
1113                 &req, sizeof(req),
1114                 on_service_get_cluster_list_resp, resp_cb_data);
1115         if (FALSE == ret) {
1116                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1117
1118                 /* Free response callback data */
1119                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1120
1121                 /* Send failure response */
1122                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1123
1124                 return TRUE;
1125         }
1126
1127         return TRUE;
1128 }
1129
1130 static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interface,
1131         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1132 {
1133         ZigbeeServiceInterfaceRespCbData_t *cb_data =
1134                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1135
1136         ZigbeeService *service_object;
1137         GDBusMethodInvocation *invocation;
1138         ZigbeeServiceServiceNodeTypeResp_t *payload =
1139                 (ZigbeeServiceServiceNodeTypeResp_t *)resp_data;
1140
1141         NOT_USED(service_interface);
1142         NOT_USED(request_id);
1143
1144         if (NULL == resp_data || 0 == resp_data_len) {
1145                 Z_LOGE("resp_data is null");
1146                 g_free(cb_data);
1147                 return;
1148         }
1149
1150         service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1151         zblib_check_null_free_and_ret("service_object", service_object, cb_data);
1152
1153         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1154         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1155
1156         zigbee_service_complete_get_node_type(service_object, invocation,
1157                 payload->result, payload->node_type);
1158
1159         g_free(cb_data);
1160 }
1161
1162 static gboolean on_service_get_node_type(ZigbeeService *service_object,
1163         GDBusMethodInvocation *invocation,
1164         GVariant *eui64,
1165         gpointer user_data)
1166 {
1167         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1168         ZigbeeServiceGetNodeType_t req;
1169         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1170
1171         GVariantIter *iter = NULL;
1172         guint i = 0;
1173
1174         gboolean ret;
1175
1176         memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
1177
1178         /* Update request structure */
1179         g_variant_get(eui64, "a(y)", &iter);
1180         while (g_variant_iter_loop(iter, "(y)", req.eui64[i])) {
1181                 i++;
1182                 if (i >= ZIGBEE_EUI64_SIZE)
1183                         break;
1184         }
1185
1186         /* Allocate response callback data */
1187         resp_cb_data =
1188                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1189                         invocation, NULL, 0);
1190         if (NULL == resp_cb_data) {
1191                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1192
1193                 /* Send failure response */
1194                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1195
1196                 return TRUE;
1197         }
1198
1199         /* Dispatch request */
1200         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1201                 ZBLIB_DRIVER_TYPE_SERVICE,
1202                 ZBLIB_SERVICE_OPS_GET_NODE_TYPE,
1203                 &req, sizeof(req),
1204                 on_service_get_node_type_resp, resp_cb_data);
1205         if (FALSE == ret) {
1206                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1207
1208                 /* Free response callback data */
1209                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1210
1211                 /* Send failure response */
1212                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1213
1214                 return TRUE;
1215         }
1216
1217         return TRUE;
1218 }
1219
1220 void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface *service_interface,
1221         guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1222 {
1223         ZigbeeService *service_object;
1224
1225         zblib_check_null_ret("service_interface", service_interface);
1226
1227         if (NULL == noti_data || 0 == noti_data_len) {
1228                 Z_LOGE("noti_data is NULL");
1229                 return;
1230         }
1231
1232         service_object = _service_interface_ref_zigbee_service(service_interface);
1233         zblib_check_null_ret("service_object", service_object);
1234
1235         NOT_USED(noti_cb_data);
1236
1237         switch(noti_id) {
1238         case ZBLIB_SERVICE_NOTI_FORM_NETWORK_DONE: {
1239                 ZigbeeServiceServiceFormNetworkDone_t *panid_t =
1240                         (ZigbeeServiceServiceFormNetworkDone_t*)noti_data;
1241
1242                 Z_LOGD("form_network_done : [0x%X]", panid_t->pan_id);
1243
1244                 zigbee_service_emit_form_network_done(service_object, panid_t->pan_id);
1245         }
1246         break;
1247         case ZBLIB_SERVICE_NOTI_CHILD_JOINED: {
1248                 ZigbeeServiceServiceChildJoined_t *child_t =
1249                         (ZigbeeServiceServiceChildJoined_t*)noti_data;
1250
1251                 GVariant *v_eui64 = NULL;
1252                 GVariant *v_endpoints = NULL;
1253
1254                 v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1255                         child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1256                 v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1257                         child_t->endpoints, child_t->endpoint_count, TRUE, NULL, NULL);
1258                 if (NULL == v_eui64 || NULL == v_endpoints) {
1259                         Z_LOGE("Failed to create variant!");
1260                         if (v_eui64)
1261                                 g_object_unref(v_eui64);
1262                         if (v_endpoints)
1263                                 g_object_unref(v_endpoints);
1264                 } else {
1265                         zigbee_service_emit_child_joined(service_object,
1266                                 v_eui64, child_t->endpoint_count, v_endpoints, child_t->node_id);
1267                 }
1268         }
1269         break;
1270         case ZBLIB_SERVICE_NOTI_CHILD_REJOINED: {
1271                 ZigbeeServiceServiceChildRejoined_t *child_t =
1272                         (ZigbeeServiceServiceChildRejoined_t*)noti_data;
1273
1274                 GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1275                         child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1276                 if (NULL == v_eui64) {
1277                         Z_LOGE("Failed to create variant!");
1278                 } else {
1279                         zigbee_service_emit_child_rejoined(service_object, v_eui64);
1280                 }
1281         }
1282         break;
1283         case ZBLIB_SERVICE_NOTI_CHILD_LEFT: {
1284                 ZigbeeServiceServiceChildLeft_t *child_left_t =
1285                         (ZigbeeServiceServiceChildLeft_t*)noti_data;
1286
1287                 GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1288                         child_left_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1289                 if (NULL == v_eui64) {
1290                         Z_LOGE("Failed to create variant!");
1291                 } else {
1292                         zigbee_service_emit_child_left(service_object,
1293                                 v_eui64, child_left_t->status);
1294                 }
1295         }
1296         break;
1297         case ZBLIB_SERVICE_NOTI_LEAVE_NETWORK_DONE: {
1298                 ZigbeeServiceServiceLeaveNetworkDone_t leave_net_t;
1299                 memcpy(&leave_net_t, noti_data, noti_data_len);
1300                 zigbee_service_emit_leave_network_done(service_object, leave_net_t.pan_id);
1301         }
1302         break;
1303         default:
1304                 Z_LOGE("Unexpected notification [%x]", noti_id);
1305         break;
1306         }
1307
1308         /* ZigbeeService should be dereferenced */
1309         g_object_unref(service_object);
1310 }
1311
1312 gboolean zigbee_service_dbus_interface_service_init(ZigBeeServiceInterface *service_interface,
1313         ZigbeeObjectSkeleton *zigbee_object)
1314 {
1315         ZigbeeService *service_object;
1316
1317         if (NULL == service_interface) {
1318                 Z_LOGE("service_interface is NULL");
1319                 return FALSE;
1320         }
1321
1322         service_object = zigbee_service_skeleton_new();
1323         zigbee_object_skeleton_set_service(zigbee_object, service_object);
1324         g_object_unref(service_object);
1325
1326         Z_LOGI("service_object: [%p]", service_object);
1327
1328         /*
1329          * Register signal handlers for 'service' interface
1330          */
1331         g_signal_connect(service_object,
1332                 "handle-zb-hw-reset",
1333                 G_CALLBACK(on_service_zb_hw_reset), service_interface);
1334
1335         g_signal_connect(service_object,
1336                 "handle-form-network",
1337                 G_CALLBACK(on_service_form_network), service_interface);
1338
1339         g_signal_connect(service_object,
1340                 "handle-coex-start",
1341                 G_CALLBACK(on_service_coex_start), service_interface);
1342
1343         g_signal_connect(service_object,
1344                 "handle-coex-stop",
1345                 G_CALLBACK(on_service_coex_stop), service_interface);
1346
1347         g_signal_connect(service_object,
1348                 "handle-leave-network",
1349                 G_CALLBACK(on_service_leave_network), service_interface);
1350
1351         g_signal_connect(service_object,
1352                 "handle-get-network-info",
1353                 G_CALLBACK(on_service_get_network_info), service_interface);
1354
1355         g_signal_connect(service_object,
1356                 "handle-permit-join",
1357                 G_CALLBACK(on_service_permit_join), service_interface);
1358
1359         g_signal_connect(service_object,
1360                 "handle-leave-request",
1361                 G_CALLBACK(on_service_leave_request), service_interface);
1362
1363         g_signal_connect(service_object,
1364                 "handle-get-device-list",
1365                 G_CALLBACK(on_service_get_device_list), service_interface);
1366
1367         g_signal_connect(service_object,
1368                 "handle-get-mac",
1369                 G_CALLBACK(on_service_get_mac), service_interface);
1370
1371         g_signal_connect(service_object,
1372                 "handle-get-device-info",
1373                 G_CALLBACK(on_service_get_device_info), service_interface);
1374
1375         g_signal_connect(service_object,
1376                 "handle-get-endpoint-list",
1377                 G_CALLBACK(on_service_get_endpoint_list), service_interface);
1378
1379         g_signal_connect(service_object,
1380                 "handle-get-cluster-list",
1381                 G_CALLBACK(on_service_get_cluster_list), service_interface);
1382
1383         g_signal_connect(service_object,
1384                 "handle-get-node-type",
1385                 G_CALLBACK(on_service_get_node_type), service_interface);
1386
1387         return TRUE;
1388 }