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