af23c3f450fff7834e96c9c43981f5311afea93b
[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 on_service_enable_resp(ZigBeeServiceInterface *service_interface,
24         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
25 {
26         ZigbeeServiceInterfaceRespCbData_t *cb_data =
27                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
28
29         NOT_USED(cb_data);
30         NOT_USED(service_interface);
31         NOT_USED(request_id);
32         NOT_USED(resp_data);
33         NOT_USED(resp_data_len);
34 }
35
36 static gboolean on_service_enable(ZigbeeService *service_object,
37         GDBusMethodInvocation *invocation,
38         gpointer user_data)
39 {
40         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
41         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
42
43         gboolean ret;
44
45         Z_LOGE("KSR");
46
47         /* Allocate response callback data */
48         resp_cb_data =
49                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
50                         invocation, NULL, 0);
51         if (NULL == resp_cb_data) {
52                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
53
54                 /* Send failure response */
55                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
56
57                 return TRUE;
58         }
59
60         /* Dispatch request */
61         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
62                 ZBLIB_DRIVER_TYPE_SERVICE,
63                 ZBLIB_SERVICE_OPS_ENABLE,
64                 NULL, 0,
65                 on_service_enable_resp, resp_cb_data);
66         if (FALSE == ret) {
67                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
68
69                 /* Free response callback data */
70                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
71
72                 /* Send failure response */
73                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
74
75                 return TRUE;
76         }
77
78         return TRUE;
79 }
80
81 static void on_service_disable_resp(ZigBeeServiceInterface *service_interface,
82         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
83 {
84         ZigbeeServiceInterfaceRespCbData_t *cb_data =
85                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
86
87         NOT_USED(cb_data);
88         NOT_USED(service_interface);
89         NOT_USED(request_id);
90         NOT_USED(resp_data);
91         NOT_USED(resp_data_len);
92 }
93
94 static gboolean on_service_disable(ZigbeeService *service_object,
95         GDBusMethodInvocation *invocation,
96         gpointer user_data)
97 {
98         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
99         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
100
101         gboolean ret;
102
103         /* Allocate response callback data */
104         resp_cb_data =
105                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
106                         invocation, NULL, 0);
107         if (NULL == resp_cb_data) {
108                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
109
110                 /* Send failure response */
111                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
112
113                 return TRUE;
114         }
115
116         /* Dispatch request */
117         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
118                 ZBLIB_DRIVER_TYPE_SERVICE,
119                 ZBLIB_SERVICE_OPS_DISABLE,
120                 NULL, 0,
121                 on_service_disable_resp, resp_cb_data);
122         if (FALSE == ret) {
123                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
124
125                 /* Free response callback data */
126                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
127
128                 /* Send failure response */
129                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
130
131                 return TRUE;
132         }
133
134         return TRUE;
135 }
136
137 static void on_service_zb_hw_reset_resp(ZigBeeServiceInterface *service_interface,
138         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
139 {
140         ZigbeeServiceInterfaceRespCbData_t *cb_data =
141                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
142
143         NOT_USED(cb_data);
144         NOT_USED(service_interface);
145         NOT_USED(request_id);
146         NOT_USED(resp_data);
147         NOT_USED(resp_data_len);
148 }
149
150 static gboolean on_service_zb_hw_reset(ZigbeeService *service_object,
151         GDBusMethodInvocation *invocation,
152         gpointer user_data)
153 {
154         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
155         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
156
157         gboolean ret;
158
159         /* Allocate response callback data */
160         resp_cb_data =
161                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
162                         invocation, NULL, 0);
163         if (NULL == resp_cb_data) {
164                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
165
166                 /* Send failure response */
167                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
168
169                 return TRUE;
170         }
171
172         /* Dispatch request */
173         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
174                 ZBLIB_DRIVER_TYPE_SERVICE,
175                 ZBLIB_SERVICE_OPS_ZB_HW_RESET,
176                 NULL, 0,
177                 on_service_zb_hw_reset_resp, resp_cb_data);
178         if (FALSE == ret) {
179                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
180
181                 /* Free response callback data */
182                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
183
184                 /* Send failure response */
185                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
186
187                 return TRUE;
188         }
189
190         return TRUE;
191 }
192
193 static void on_service_form_network_resp(ZigBeeServiceInterface *service_interface,
194         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
195 {
196         ZigbeeServiceInterfaceRespCbData_t *cb_data =
197                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
198
199         NOT_USED(cb_data);
200         NOT_USED(service_interface);
201         NOT_USED(request_id);
202         NOT_USED(resp_data);
203         NOT_USED(resp_data_len);
204 }
205
206 static gboolean on_service_form_network(ZigbeeService *service_object,
207         GDBusMethodInvocation *invocation,
208         gpointer user_data)
209 {
210         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
211         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
212
213         gboolean ret;
214
215         /* Allocate response callback data */
216         resp_cb_data =
217                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
218                         invocation, NULL, 0);
219         if (NULL == resp_cb_data) {
220                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
221
222                 /* Send failure response */
223                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
224
225                 return TRUE;
226         }
227
228         /* Dispatch request */
229         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
230                 ZBLIB_DRIVER_TYPE_SERVICE,
231                 ZBLIB_SERVICE_OPS_FORM_NETWORK,
232                 NULL, 0,
233                 on_service_form_network_resp, resp_cb_data);
234         if (FALSE == ret) {
235                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
236
237                 /* Free response callback data */
238                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
239
240                 /* Send failure response */
241                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
242
243                 return TRUE;
244         }
245
246         return TRUE;
247 }
248
249 static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface,
250         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
251 {
252         ZigbeeServiceInterfaceRespCbData_t *cb_data =
253                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
254
255         NOT_USED(cb_data);
256         NOT_USED(service_interface);
257         NOT_USED(request_id);
258         NOT_USED(resp_data);
259         NOT_USED(resp_data_len);
260 }
261
262 static gboolean on_service_coex_start(ZigbeeService *service_object,
263         GDBusMethodInvocation *invocation,
264         gchar channel,
265         gpointer user_data)
266 {
267         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
268         ZigbeeServiceCoexStart_t req;
269         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
270
271         gboolean ret;
272
273         memset(&req, 0x0, sizeof(ZigbeeServiceCoexStart_t));
274
275         /* Update request structure */
276         req.channel = channel;
277
278         /* Allocate response callback data */
279         resp_cb_data =
280                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
281                         invocation, NULL, 0);
282         if (NULL == resp_cb_data) {
283                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
284
285                 /* Send failure response */
286                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
287
288                 return TRUE;
289         }
290
291         /* Dispatch request */
292         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
293                 ZBLIB_DRIVER_TYPE_SERVICE,
294                 ZBLIB_SERVICE_OPS_COEX_START,
295                 &req, sizeof(req),
296                 on_service_coex_start_resp, resp_cb_data);
297         if (FALSE == ret) {
298                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
299
300                 /* Free response callback data */
301                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
302
303                 /* Send failure response */
304                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
305
306                 return TRUE;
307         }
308
309         return TRUE;
310 }
311
312 static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface,
313         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
314 {
315         ZigbeeServiceInterfaceRespCbData_t *cb_data =
316                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
317
318         NOT_USED(cb_data);
319         NOT_USED(service_interface);
320         NOT_USED(request_id);
321         NOT_USED(resp_data);
322         NOT_USED(resp_data_len);
323 }
324
325 static gboolean on_service_coex_stop(ZigbeeService *service_object,
326         GDBusMethodInvocation *invocation,
327         gpointer user_data)
328 {
329         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
330         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
331
332         gboolean ret;
333
334         /* Allocate response callback data */
335         resp_cb_data =
336                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
337                         invocation, NULL, 0);
338         if (NULL == resp_cb_data) {
339                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
340
341                 /* Send failure response */
342                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
343
344                 return TRUE;
345         }
346
347         /* Dispatch request */
348         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
349                 ZBLIB_DRIVER_TYPE_SERVICE,
350                 ZBLIB_SERVICE_OPS_COEX_STOP,
351                 NULL, 0,
352                 on_service_coex_stop_resp, resp_cb_data);
353         if (FALSE == ret) {
354                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
355
356                 /* Free response callback data */
357                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
358
359                 /* Send failure response */
360                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
361
362                 return TRUE;
363         }
364
365         return TRUE;
366 }
367
368 static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interface,
369         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
370 {
371         ZigbeeServiceInterfaceRespCbData_t *cb_data =
372                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
373
374         NOT_USED(cb_data);
375         NOT_USED(service_interface);
376         NOT_USED(request_id);
377         NOT_USED(resp_data);
378         NOT_USED(resp_data_len);
379 }
380
381 static gboolean on_service_leave_network(ZigbeeService *service_object,
382         GDBusMethodInvocation *invocation,
383         gpointer user_data)
384 {
385         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
386         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
387
388         gboolean ret;
389
390         /* Allocate response callback data */
391         resp_cb_data =
392                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
393                         invocation, NULL, 0);
394         if (NULL == resp_cb_data) {
395                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
396
397                 /* Send failure response */
398                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
399
400                 return TRUE;
401         }
402
403         /* Dispatch request */
404         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
405                 ZBLIB_DRIVER_TYPE_SERVICE,
406                 ZBLIB_SERVICE_OPS_LEAVE_NETWORK,
407                 NULL, 0,
408                 on_service_leave_network_resp, resp_cb_data);
409         if (FALSE == ret) {
410                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
411
412                 /* Free response callback data */
413                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
414
415                 /* Send failure response */
416                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
417
418                 return TRUE;
419         }
420
421         return TRUE;
422 }
423
424 static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_interface,
425         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
426 {
427         ZigbeeServiceInterfaceRespCbData_t *cb_data =
428                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
429
430         NOT_USED(cb_data);
431         NOT_USED(service_interface);
432         NOT_USED(request_id);
433         NOT_USED(resp_data);
434         NOT_USED(resp_data_len);
435 }
436
437 static gboolean on_service_get_network_info(ZigbeeService *service_object,
438         GDBusMethodInvocation *invocation,
439         gpointer user_data)
440 {
441         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
442         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
443
444         gboolean ret;
445
446         /* Allocate response callback data */
447         resp_cb_data =
448                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
449                         invocation, NULL, 0);
450         if (NULL == resp_cb_data) {
451                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
452
453                 /* Send failure response */
454                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
455
456                 return TRUE;
457         }
458
459         /* Dispatch request */
460         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
461                 ZBLIB_DRIVER_TYPE_SERVICE,
462                 ZBLIB_SERVICE_OPS_GET_NETWORK_INFO,
463                 NULL, 0,
464                 on_service_get_network_info_resp, resp_cb_data);
465         if (FALSE == ret) {
466                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
467
468                 /* Free response callback data */
469                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
470
471                 /* Send failure response */
472                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
473
474                 return TRUE;
475         }
476
477         return TRUE;
478 }
479
480 static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interface,
481         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
482 {
483         ZigbeeServiceInterfaceRespCbData_t *cb_data =
484                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
485
486         NOT_USED(cb_data);
487         NOT_USED(service_interface);
488         NOT_USED(request_id);
489         NOT_USED(resp_data);
490         NOT_USED(resp_data_len);
491 }
492
493 static gboolean on_service_permit_join(ZigbeeService *service_object,
494         GDBusMethodInvocation *invocation,
495         gint duration,
496         gboolean permit_join,
497         gpointer user_data)
498 {
499         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
500         ZigbeeServicePermitJoin_t req;
501         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
502
503         gboolean ret;
504
505         memset(&req, 0x0, sizeof(ZigbeeServicePermitJoin_t));
506
507         /* Update request structure */
508         req.duration = duration;
509         req.permit_join = permit_join;
510
511         /* Allocate response callback data */
512         resp_cb_data =
513                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
514                         invocation, NULL, 0);
515         if (NULL == resp_cb_data) {
516                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
517
518                 /* Send failure response */
519                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
520
521                 return TRUE;
522         }
523
524         /* Dispatch request */
525         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
526                 ZBLIB_DRIVER_TYPE_SERVICE,
527                 ZBLIB_SERVICE_OPS_PERMIT_JOIN,
528                 &req, sizeof(req),
529                 on_service_permit_join_resp, resp_cb_data);
530         if (FALSE == ret) {
531                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
532
533                 /* Free response callback data */
534                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
535
536                 /* Send failure response */
537                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
538
539                 return TRUE;
540         }
541
542         return TRUE;
543 }
544
545 static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interface,
546         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
547 {
548         ZigbeeServiceInterfaceRespCbData_t *cb_data =
549                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
550
551         NOT_USED(cb_data);
552         NOT_USED(service_interface);
553         NOT_USED(request_id);
554         NOT_USED(resp_data);
555         NOT_USED(resp_data_len);
556 }
557
558 static gboolean on_service_leave_request(ZigbeeService *service_object,
559         GDBusMethodInvocation *invocation,
560         GVariant *eui64,
561         gchar remove_child,
562         gchar rejoin,
563         gpointer user_data)
564 {
565         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
566         ZigbeeServiceLeaveRequest_t req;
567         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
568
569         GVariantIter *iter = NULL;
570         guint i = 0;
571
572         gboolean ret;
573
574         memset(&req, 0x0, sizeof(ZigbeeServiceLeaveRequest_t));
575
576         /* Update request structure */
577         g_variant_get(eui64, "ay", &iter);
578         while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
579                 i++;
580                 if (i >= ZIGBEE_EUI64_SIZE)
581                         break;
582         }
583         req.remove_child = remove_child;
584         req.rejoin = rejoin;
585
586         /* Allocate response callback data */
587         resp_cb_data =
588                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
589                         invocation, NULL, 0);
590         if (NULL == resp_cb_data) {
591                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
592
593                 /* Send failure response */
594                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
595
596                 return TRUE;
597         }
598
599         /* Dispatch request */
600         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
601                 ZBLIB_DRIVER_TYPE_SERVICE,
602                 ZBLIB_SERVICE_OPS_LEAVE_REQUEST,
603                 &req, sizeof(req),
604                 on_service_leave_request_resp, resp_cb_data);
605         if (FALSE == ret) {
606                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
607
608                 /* Free response callback data */
609                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
610
611                 /* Send failure response */
612                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
613
614                 return TRUE;
615         }
616
617         return TRUE;
618 }
619
620 static void on_service_get_device_list_resp(ZigBeeServiceInterface *service_interface,
621         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
622 {
623         ZigbeeServiceInterfaceRespCbData_t *cb_data =
624                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
625
626         NOT_USED(cb_data);
627         NOT_USED(service_interface);
628         NOT_USED(request_id);
629         NOT_USED(resp_data);
630         NOT_USED(resp_data_len);
631 }
632
633 static gboolean on_service_get_device_list(ZigbeeService *service_object,
634         GDBusMethodInvocation *invocation,
635         gpointer user_data)
636 {
637         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
638         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
639
640         gboolean ret;
641
642         /* Allocate response callback data */
643         resp_cb_data =
644                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
645                         invocation, NULL, 0);
646         if (NULL == resp_cb_data) {
647                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
648
649                 /* Send failure response */
650                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
651
652                 return TRUE;
653         }
654
655         /* Dispatch request */
656         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
657                 ZBLIB_DRIVER_TYPE_SERVICE,
658                 ZBLIB_SERVICE_OPS_GET_DEVICE_LIST,
659                 NULL, 0,
660                 on_service_get_device_list_resp, resp_cb_data);
661         if (FALSE == ret) {
662                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
663
664                 /* Free response callback data */
665                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
666
667                 /* Send failure response */
668                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
669
670                 return TRUE;
671         }
672
673         return TRUE;
674 }
675
676 static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface,
677         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
678 {
679         ZigbeeServiceInterfaceRespCbData_t *cb_data =
680                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
681
682         NOT_USED(cb_data);
683         NOT_USED(service_interface);
684         NOT_USED(request_id);
685         NOT_USED(resp_data);
686         NOT_USED(resp_data_len);
687 }
688
689 static gboolean on_service_get_mac(ZigbeeService *service_object,
690         GDBusMethodInvocation *invocation,
691         gpointer user_data)
692 {
693         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
694         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
695
696         gboolean ret;
697
698         /* Allocate response callback data */
699         resp_cb_data =
700                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
701                         invocation, NULL, 0);
702         if (NULL == resp_cb_data) {
703                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
704
705                 /* Send failure response */
706                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
707
708                 return TRUE;
709         }
710
711         /* Dispatch request */
712         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
713                 ZBLIB_DRIVER_TYPE_SERVICE,
714                 ZBLIB_SERVICE_OPS_GET_MAC,
715                 NULL, 0,
716                 on_service_get_mac_resp, resp_cb_data);
717         if (FALSE == ret) {
718                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
719
720                 /* Free response callback data */
721                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
722
723                 /* Send failure response */
724                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
725
726                 return TRUE;
727         }
728
729         return TRUE;
730 }
731
732 static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_interface,
733         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
734 {
735         ZigbeeServiceInterfaceRespCbData_t *cb_data =
736                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
737
738         NOT_USED(cb_data);
739         NOT_USED(service_interface);
740         NOT_USED(request_id);
741         NOT_USED(resp_data);
742         NOT_USED(resp_data_len);
743 }
744
745 static gboolean on_service_get_device_info(ZigbeeService *service_object,
746         GDBusMethodInvocation *invocation,
747         gpointer user_data)
748 {
749         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
750         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
751
752         gboolean ret;
753
754         /* Allocate response callback data */
755         resp_cb_data =
756                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
757                         invocation, NULL, 0);
758         if (NULL == resp_cb_data) {
759                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
760
761                 /* Send failure response */
762                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
763
764                 return TRUE;
765         }
766
767         /* Dispatch request */
768         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
769                 ZBLIB_DRIVER_TYPE_SERVICE,
770                 ZBLIB_SERVICE_OPS_GET_DEVICE_INFO,
771                 NULL, 0,
772                 on_service_get_device_info_resp, resp_cb_data);
773         if (FALSE == ret) {
774                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
775
776                 /* Free response callback data */
777                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
778
779                 /* Send failure response */
780                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
781
782                 return TRUE;
783         }
784
785         return TRUE;
786 }
787
788 static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_interface,
789         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
790 {
791         ZigbeeServiceInterfaceRespCbData_t *cb_data =
792                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
793
794         NOT_USED(cb_data);
795         NOT_USED(service_interface);
796         NOT_USED(request_id);
797         NOT_USED(resp_data);
798         NOT_USED(resp_data_len);
799 }
800
801 static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
802         GDBusMethodInvocation *invocation,
803         GVariant *eui64,
804         gpointer user_data)
805 {
806         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
807         ZigbeeServiceGetEndpointList_t req;
808         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
809
810         GVariantIter *iter = NULL;
811         guint i = 0;
812
813         gboolean ret;
814
815         memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
816
817         /* Update request structure */
818         g_variant_get(eui64, "ay", &iter);
819         while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
820                 i++;
821                 if (i >= ZIGBEE_EUI64_SIZE)
822                         break;
823         }
824
825         /* Allocate response callback data */
826         resp_cb_data =
827                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
828                         invocation, NULL, 0);
829         if (NULL == resp_cb_data) {
830                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
831
832                 /* Send failure response */
833                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
834
835                 return TRUE;
836         }
837
838         /* Dispatch request */
839         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
840                 ZBLIB_DRIVER_TYPE_SERVICE,
841                 ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST,
842                 &req, sizeof(req),
843                 on_service_get_endpoint_list_resp, resp_cb_data);
844         if (FALSE == ret) {
845                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
846
847                 /* Free response callback data */
848                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
849
850                 /* Send failure response */
851                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
852
853                 return TRUE;
854         }
855
856         return TRUE;
857 }
858
859 static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_interface,
860         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
861 {
862         ZigbeeServiceInterfaceRespCbData_t *cb_data =
863                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
864
865         NOT_USED(cb_data);
866         NOT_USED(service_interface);
867         NOT_USED(request_id);
868         NOT_USED(resp_data);
869         NOT_USED(resp_data_len);
870 }
871
872 static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
873         GDBusMethodInvocation *invocation,
874         GVariant *eui64,
875         gchar endpoint,
876         gpointer user_data)
877 {
878         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
879         ZigbeeServiceGetClusterList_t req;
880         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
881
882         GVariantIter *iter = NULL;
883         guint i = 0;
884
885         gboolean ret;
886
887         memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
888
889         /* Update request structure */
890         g_variant_get(eui64, "ay", &iter);
891         while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
892                 i++;
893                 if (i >= ZIGBEE_EUI64_SIZE)
894                         break;
895         }
896         req.endpoint = endpoint;
897
898         /* Allocate response callback data */
899         resp_cb_data =
900                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
901                         invocation, NULL, 0);
902         if (NULL == resp_cb_data) {
903                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
904
905                 /* Send failure response */
906                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
907
908                 return TRUE;
909         }
910
911         /* Dispatch request */
912         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
913                 ZBLIB_DRIVER_TYPE_SERVICE,
914                 ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST,
915                 &req, sizeof(req),
916                 on_service_get_cluster_list_resp, resp_cb_data);
917         if (FALSE == ret) {
918                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
919
920                 /* Free response callback data */
921                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
922
923                 /* Send failure response */
924                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
925
926                 return TRUE;
927         }
928
929         return TRUE;
930 }
931
932 static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interface,
933         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
934 {
935         ZigbeeServiceInterfaceRespCbData_t *cb_data =
936                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
937
938         NOT_USED(cb_data);
939         NOT_USED(service_interface);
940         NOT_USED(request_id);
941         NOT_USED(resp_data);
942         NOT_USED(resp_data_len);
943 }
944
945 static gboolean on_service_get_node_type(ZigbeeService *service_object,
946         GDBusMethodInvocation *invocation,
947         GVariant *eui64,
948         gpointer user_data)
949 {
950         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
951         ZigbeeServiceGetNodeType_t req;
952         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
953
954         GVariantIter *iter = NULL;
955         guint i = 0;
956
957         gboolean ret;
958
959         memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
960
961         /* Update request structure */
962         g_variant_get(eui64, "ay", &iter);
963         while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
964                 i++;
965                 if (i >= ZIGBEE_EUI64_SIZE)
966                         break;
967         }
968
969         /* Allocate response callback data */
970         resp_cb_data =
971                 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
972                         invocation, NULL, 0);
973         if (NULL == resp_cb_data) {
974                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
975
976                 /* Send failure response */
977                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
978
979                 return TRUE;
980         }
981
982         /* Dispatch request */
983         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
984                 ZBLIB_DRIVER_TYPE_SERVICE,
985                 ZBLIB_SERVICE_OPS_GET_NODE_TYPE,
986                 &req, sizeof(req),
987                 on_service_get_node_type_resp, resp_cb_data);
988         if (FALSE == ret) {
989                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
990
991                 /* Free response callback data */
992                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
993
994                 /* Send failure response */
995                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
996
997                 return TRUE;
998         }
999
1000         return TRUE;
1001 }
1002
1003 gboolean zigbee_service_dbus_interface_service_init(ZigBeeServiceInterface *service_interface,
1004         ZigbeeObjectSkeleton *zigbee_object)
1005 {
1006         ZigbeeService *service_object;
1007
1008         if (NULL == service_interface) {
1009                 Z_LOGE("service_interface is NULL");
1010                 return FALSE;
1011         }
1012
1013         service_object = zigbee_service_skeleton_new();
1014         zigbee_object_skeleton_set_service(zigbee_object, service_object);
1015         g_object_unref(service_object);
1016
1017         Z_LOGI("service_object: [%p]", service_object);
1018
1019         /*
1020          * Register signal handlers for 'service' interface
1021          */
1022         g_signal_connect(service_object,
1023                 "handle-enable",
1024                 G_CALLBACK(on_service_enable), service_interface);
1025
1026         g_signal_connect(service_object,
1027                 "handle-disable",
1028                 G_CALLBACK(on_service_disable), service_interface);
1029
1030         g_signal_connect(service_object,
1031                 "handle-zb-hw-reset",
1032                 G_CALLBACK(on_service_zb_hw_reset), service_interface);
1033
1034         g_signal_connect(service_object,
1035                 "handle-form-network",
1036                 G_CALLBACK(on_service_form_network), service_interface);
1037
1038         g_signal_connect(service_object,
1039                 "handle-coex-start",
1040                 G_CALLBACK(on_service_coex_start), service_interface);
1041
1042         g_signal_connect(service_object,
1043                 "handle-coex-stop",
1044                 G_CALLBACK(on_service_coex_stop), service_interface);
1045
1046         g_signal_connect(service_object,
1047                 "handle-leave-network",
1048                 G_CALLBACK(on_service_leave_network), service_interface);
1049
1050         g_signal_connect(service_object,
1051                 "handle-get-network-info",
1052                 G_CALLBACK(on_service_get_network_info), service_interface);
1053
1054         g_signal_connect(service_object,
1055                 "handle-permit-join",
1056                 G_CALLBACK(on_service_permit_join), service_interface);
1057
1058         g_signal_connect(service_object,
1059                 "handle-leave-request",
1060                 G_CALLBACK(on_service_leave_request), service_interface);
1061
1062         g_signal_connect(service_object,
1063                 "handle-get-device-list",
1064                 G_CALLBACK(on_service_get_device_list), service_interface);
1065
1066         g_signal_connect(service_object,
1067                 "handle-get-mac",
1068                 G_CALLBACK(on_service_get_mac), service_interface);
1069
1070         g_signal_connect(service_object,
1071                 "handle-get-device-info",
1072                 G_CALLBACK(on_service_get_device_info), service_interface);
1073
1074         g_signal_connect(service_object,
1075                 "handle-get-endpoint-list",
1076                 G_CALLBACK(on_service_get_endpoint_list), service_interface);
1077
1078         g_signal_connect(service_object,
1079                 "handle-get-cluster-list",
1080                 G_CALLBACK(on_service_get_cluster_list), service_interface);
1081
1082         g_signal_connect(service_object,
1083                 "handle-get-node-type",
1084                 G_CALLBACK(on_service_get_node_type), service_interface);
1085
1086         return TRUE;
1087 }