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