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