Fix the coverity issues
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_zcl_group.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_zcl_group.h>
22
23 /* LCOV_EXCL_START */
24 static void *_service_interface_ref_zigbee_zcl_group(ZigBeeServiceInterface *service_interface)
25 {
26         ZigbeeObjectSkeleton *zigbee_object = NULL;
27         ZigbeeCustomData_t *custom_data = NULL;
28         ZigbeeZcl_group *group_object = NULL;
29
30         custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
31         if (NULL == custom_data) {
32                 Z_LOGE("D-BUS service interface custom_data is NULL!");
33                 return NULL;
34         }
35
36         /* Get zigbee object */
37         zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
38         if (NULL == zigbee_object) {
39                 Z_LOGW("Cannot find ZigBee D-BUS interface object!");
40                 return NULL;
41         }
42
43         group_object = zigbee_object_get_zcl_group(ZIGBEE_OBJECT(zigbee_object));
44         return group_object;
45 }
46
47 static void on_zcl_group_add_group_resp(ZigBeeServiceInterface *service_interface,
48         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
49 {
50         ZigbeeServiceInterfaceRespCbData_t *cb_data =
51                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
52
53         ZigbeeZcl_group *group_object = NULL;
54         GDBusMethodInvocation *invocation = NULL;
55
56         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
57
58         NOT_USED(service_interface);
59         NOT_USED(request_id);
60
61         if (NULL == resp_data || 0 == resp_data_len) {
62                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
63                 g_free(cb_data);
64                 return;
65         }
66
67         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
68         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
69
70         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
71         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
72
73         zigbee_zcl_group_complete_add_group(group_object, invocation, payload->result);
74
75         g_free(cb_data);
76 }
77
78 static gboolean on_zcl_group_add_group(ZigbeeZcl_group *zcl_group_object,
79         GDBusMethodInvocation *invocation,
80         gshort node_id,
81         gchar dest_ep,
82         gshort group_id,
83         GVariant *group_name,
84         gpointer user_data)
85 {
86         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
87         ZigbeeZclGroupAddGroup_t req;
88         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
89
90         GVariantIter *iter = NULL;
91         gint i = 0;
92
93         gboolean ret;
94
95         memset(&req, 0x0, sizeof(ZigbeeZclGroupAddGroup_t));
96
97         /* Update request structure */
98         req.node_id = node_id;
99         req.dest_ep = dest_ep;
100         req.group_id = group_id;
101
102
103         g_variant_get(group_name, "a(y)", &iter);
104         while (g_variant_iter_loop(iter, "(y)", &req.group_name[i])) {
105                 i++;
106                 if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
107                         break;
108         }
109
110         /* Allocate response callback data */
111         resp_cb_data =
112                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
113                         invocation, NULL, 0);
114         if (NULL == resp_cb_data) {
115                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
116
117                 /* Send failure response */
118                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
119
120                 return TRUE;
121         }
122
123         /* Dispatch request */
124         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
125                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
126                 ZBLIB_ZCL_GROUP_OPS_ADD_GROUP,
127                 &req, sizeof(req),
128                 on_zcl_group_add_group_resp, resp_cb_data);
129         if (FALSE == ret) {
130                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
131
132                 /* Free response callback data */
133                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
134
135                 /* Send failure response */
136                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
137
138                 return TRUE;
139         }
140
141         return TRUE;
142 }
143
144 static void on_zcl_group_view_group_resp(ZigBeeServiceInterface *service_interface,
145         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
146 {
147         ZigbeeServiceInterfaceRespCbData_t *cb_data =
148                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
149
150         ZigbeeZcl_group *group_object = NULL;
151         GDBusMethodInvocation *invocation = NULL;
152
153         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
154
155         NOT_USED(service_interface);
156         NOT_USED(request_id);
157
158         if (NULL == resp_data || 0 == resp_data_len) {
159                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
160                 g_free(cb_data);
161                 return;
162         }
163
164         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
165         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
166
167         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
168         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
169
170         zigbee_zcl_group_complete_view_group(group_object, invocation, payload->result);
171
172         g_free(cb_data);
173 }
174
175 static gboolean on_zcl_group_view_group(ZigbeeZcl_group *zcl_group_object,
176         GDBusMethodInvocation *invocation,
177         gushort node_id,
178         guchar dest_ep,
179         gushort group_id,
180         gpointer user_data)
181 {
182         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
183         ZigbeeZclGroupViewGroup_t req;
184         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
185
186         gboolean ret;
187
188         memset(&req, 0x0, sizeof(ZigbeeZclGroupViewGroup_t));
189
190         /* Update request structure */
191         req.node_id = node_id;
192         req.dest_ep = dest_ep;
193         req.group_id = group_id;
194
195         /* Allocate response callback data */
196         resp_cb_data =
197                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
198                         invocation, NULL, 0);
199         if (NULL == resp_cb_data) {
200                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
201
202                 /* Send failure response */
203                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
204
205                 return TRUE;
206         }
207
208         /* Dispatch request */
209         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
210                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
211                 ZBLIB_ZCL_GROUP_OPS_VIEW_GROUP,
212                 &req, sizeof(req),
213                 on_zcl_group_view_group_resp, resp_cb_data);
214         if (FALSE == ret) {
215                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
216
217                 /* Free response callback data */
218                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
219
220                 /* Send failure response */
221                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
222
223                 return TRUE;
224         }
225
226         return TRUE;
227 }
228
229 static void on_zcl_group_get_group_membership_resp(ZigBeeServiceInterface *service_interface,
230         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
231 {
232         ZigbeeServiceInterfaceRespCbData_t *cb_data =
233                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
234
235         ZigbeeZcl_group *group_object = NULL;
236         GDBusMethodInvocation *invocation = NULL;
237
238         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
239
240         NOT_USED(service_interface);
241         NOT_USED(request_id);
242
243         if (NULL == resp_data || 0 == resp_data_len) {
244                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
245                 g_free(cb_data);
246                 return;
247         }
248
249         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
250         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
251
252         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
253         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
254
255         zigbee_zcl_group_complete_get_group_membership(group_object, invocation, payload->result);
256
257         g_free(cb_data);
258 }
259
260 static gboolean on_zcl_group_get_group_membership(ZigbeeZcl_group *zcl_group_object,
261         GDBusMethodInvocation *invocation,
262         gshort node_id,
263         gchar dest_ep,
264         gchar group_count,
265         GVariant *group_list,
266         gpointer user_data)
267 {
268         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
269         ZigbeeZclGroupGetGroupMembership_t req;
270         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
271
272         GVariantIter *iter = NULL;
273         gint i = 0;
274         gushort value = 0;
275
276         gboolean ret;
277
278         memset(&req, 0x0, sizeof(ZigbeeZclGroupGetGroupMembership_t));
279
280         /* Update request structure */
281         req.node_id = node_id;
282         req.dest_ep = dest_ep;
283         req.group_count = group_count;
284         req.group_list = g_malloc0(sizeof(gushort) * group_count);
285         g_variant_get(group_list, "aq", &iter);
286         while (i < group_count && g_variant_iter_loop(iter, "q", &value)) {
287                 Z_LOGD("  cluster: [%d]", value);
288                 req.group_list[i] = value;
289                 i++;
290         }
291
292         /* Allocate response callback data */
293         resp_cb_data =
294                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
295                         invocation, NULL, 0);
296         if (NULL == resp_cb_data) {
297                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
298
299                 g_free(req.group_list);
300
301                 /* Send failure response */
302                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
303
304                 return TRUE;
305         }
306
307         /* Dispatch request */
308         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
309                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
310                 ZBLIB_ZCL_GROUP_OPS_GET_GROUP_MEMBERSHIP,
311                 &req, sizeof(req),
312                 on_zcl_group_get_group_membership_resp, resp_cb_data);
313
314         /* Free resource */
315         g_free(req.group_list);
316
317         if (FALSE == ret) {
318                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
319
320                 /* Free response callback data */
321                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
322
323                 /* Send failure response */
324                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
325
326                 return TRUE;
327         }
328
329         return TRUE;
330 }
331
332 static void on_zcl_group_remove_group_resp(ZigBeeServiceInterface *service_interface,
333         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
334 {
335         ZigbeeServiceInterfaceRespCbData_t *cb_data =
336                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
337
338         ZigbeeZcl_group *group_object = NULL;
339         GDBusMethodInvocation *invocation = NULL;
340
341         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
342
343         NOT_USED(service_interface);
344         NOT_USED(request_id);
345
346         if (NULL == resp_data || 0 == resp_data_len) {
347                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
348                 g_free(cb_data);
349                 return;
350         }
351
352         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
353         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
354
355         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
356         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
357
358         zigbee_zcl_group_complete_remove_group(group_object, invocation, payload->result);
359
360         g_free(cb_data);
361 }
362
363 static gboolean on_zcl_group_remove_group(ZigbeeZcl_group *zcl_group_object,
364         GDBusMethodInvocation *invocation,
365         gshort node_id,
366         gchar dest_ep,
367         gshort group_id,
368         gpointer user_data)
369 {
370         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
371         ZigbeeZclGroupRemoveGroup_t req;
372         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
373
374         gboolean ret;
375
376         memset(&req, 0x0, sizeof(ZigbeeZclGroupRemoveGroup_t));
377
378         /* Update request structure */
379         req.node_id = node_id;
380         req.dest_ep = dest_ep;
381         req.group_id = group_id;
382
383         /* Allocate response callback data */
384         resp_cb_data =
385                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
386                         invocation, NULL, 0);
387         if (NULL == resp_cb_data) {
388                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
389
390                 /* Send failure response */
391                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
392
393                 return TRUE;
394         }
395
396         /* Dispatch request */
397         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
398                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
399                 ZBLIB_ZCL_GROUP_OPS_REMOVE_GROUP,
400                 &req, sizeof(req),
401                 on_zcl_group_remove_group_resp, resp_cb_data);
402         if (FALSE == ret) {
403                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
404
405                 /* Free response callback data */
406                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
407
408                 /* Send failure response */
409                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
410
411                 return TRUE;
412         }
413
414         return TRUE;
415 }
416
417 static void on_zcl_group_remove_all_group_resp(ZigBeeServiceInterface *service_interface,
418         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
419 {
420         ZigbeeServiceInterfaceRespCbData_t *cb_data =
421                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
422
423         ZigbeeZcl_group *group_object = NULL;
424         GDBusMethodInvocation *invocation = NULL;
425
426         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
427
428         NOT_USED(service_interface);
429         NOT_USED(request_id);
430
431         if (NULL == resp_data || 0 == resp_data_len) {
432                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
433                 g_free(cb_data);
434                 return;
435         }
436
437         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
438         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
439
440         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
441         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
442
443         zigbee_zcl_group_complete_remove_all_group(group_object, invocation, payload->result);
444
445         g_free(cb_data);
446 }
447
448 static gboolean on_zcl_group_remove_all_group(ZigbeeZcl_group *zcl_group_object,
449         GDBusMethodInvocation *invocation,
450         gshort node_id,
451         gchar dest_ep,
452         gpointer user_data)
453 {
454         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
455         ZigbeeZclGroupRemoveAllGroup_t req;
456         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
457
458         gboolean ret;
459
460         memset(&req, 0x0, sizeof(ZigbeeZclGroupRemoveAllGroup_t));
461
462         /* Update request structure */
463         req.node_id = node_id;
464         req.dest_ep = dest_ep;
465
466         /* Allocate response callback data */
467         resp_cb_data =
468                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
469                         invocation, NULL, 0);
470         if (NULL == resp_cb_data) {
471                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
472
473                 /* Send failure response */
474                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
475
476                 return TRUE;
477         }
478
479         /* Dispatch request */
480         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
481                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
482                 ZBLIB_ZCL_GROUP_OPS_REMOVE_ALL_GROUP,
483                 &req, sizeof(req),
484                 on_zcl_group_remove_all_group_resp, resp_cb_data);
485         if (FALSE == ret) {
486                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
487
488                 /* Free response callback data */
489                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
490
491                 /* Send failure response */
492                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
493
494                 return TRUE;
495         }
496
497         return TRUE;
498 }
499
500 static void on_zcl_group_add_group_if_identifying_resp(ZigBeeServiceInterface *service_interface,
501         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
502 {
503         ZigbeeServiceInterfaceRespCbData_t *cb_data =
504                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
505
506         ZigbeeZcl_group *group_object = NULL;
507         GDBusMethodInvocation *invocation = NULL;
508
509         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
510
511         NOT_USED(service_interface);
512         NOT_USED(request_id);
513
514         if (NULL == resp_data || 0 == resp_data_len) {
515                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
516                 g_free(cb_data);
517                 return;
518         }
519
520         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
521         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
522
523         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
524         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
525
526         zigbee_zcl_group_complete_add_group_if_identifying(group_object, invocation, payload->result);
527
528         g_free(cb_data);
529 }
530
531 static gboolean on_zcl_group_add_group_if_identifying(ZigbeeZcl_group *zcl_group_object,
532         GDBusMethodInvocation *invocation,
533         gshort node_id,
534         gchar dest_ep,
535         gshort group_id,
536         GVariant *group_name,
537         gpointer user_data)
538 {
539         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
540         ZigbeeZclGroupAddGroupIfIdentifying_t req;
541         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
542
543         GVariantIter *iter = NULL;
544         gint i = 0;
545
546         gboolean ret;
547
548         memset(&req, 0x0, sizeof(ZigbeeZclGroupAddGroupIfIdentifying_t));
549
550         /* Update request structure */
551         req.node_id = node_id;
552         req.dest_ep = dest_ep;
553         req.group_id = group_id;
554         g_variant_get(group_name, "a(y)", &iter);
555         while (g_variant_iter_loop(iter, "(y)", &req.group_name[i])) {
556                 i++;
557                 if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
558                         break;
559         }
560
561         /* Allocate response callback data */
562         resp_cb_data =
563                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
564                         invocation, NULL, 0);
565         if (NULL == resp_cb_data) {
566                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
567
568                 /* Send failure response */
569                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
570
571                 return TRUE;
572         }
573
574         /* Dispatch request */
575         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
576                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
577                 ZBLIB_ZCL_GROUP_OPS_ADD_GROUP_IF_IDENTIFYING,
578                 &req, sizeof(req),
579                 on_zcl_group_add_group_if_identifying_resp, resp_cb_data);
580         if (FALSE == ret) {
581                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
582
583                 /* Free response callback data */
584                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
585
586                 /* Send failure response */
587                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
588
589                 return TRUE;
590         }
591
592         return TRUE;
593 }
594
595 void zigbee_service_dbus_interface_zcl_group_notification(ZigBeeServiceInterface *service_interface,
596         guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
597 {
598         ZigbeeZcl_group *group_object;
599
600         zblib_check_null_ret("service_interface", service_interface);
601
602         if (NULL == noti_data || 0 == noti_data_len) {
603                 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
604                 return;
605         }
606
607         group_object = _service_interface_ref_zigbee_zcl_group(service_interface);
608         zblib_check_null_ret("group_object", group_object);
609
610         NOT_USED(noti_cb_data);
611
612         switch (noti_id) {
613         case ZBLIB_SERVICE_NOTI_ADD_GROUP_RSP: {
614                 ZigbeeZclGroupAddGroupNoti_t *rsp =
615                         (ZigbeeZclGroupAddGroupNoti_t*)noti_data;
616
617                 Z_LOGD("add_group_rsp from : [0x%X]", rsp->node_id);
618
619                 zigbee_zcl_group_emit_add_group_rsp(group_object, rsp->node_id, rsp->src_ep,
620                         rsp->status, rsp->group_id);
621         }
622         break;
623         case ZBLIB_SERVICE_NOTI_VIEW_GROUP_RSP: {
624                 ZigbeeZclGroupViewGroupNoti_t *rsp =
625                         (ZigbeeZclGroupViewGroupNoti_t*)noti_data;
626
627                 Z_LOGD("view_group_rsp from : [0x%X]", rsp->node_id);
628
629                 zigbee_zcl_group_emit_view_group_rsp(group_object, rsp->node_id, rsp->src_ep,
630                         rsp->status, rsp->group_id, rsp->group_name);
631         }
632         break;
633         case ZBLIB_SERVICE_NOTI_GET_GROUP_MEMBERSHIP_RSP: {
634                 int i;
635                 GVariant* group_list = NULL;
636                 GVariantBuilder *attr_builder = NULL;
637
638                 ZigbeeZclGroupGetGroupMembershipNoti_t *rsp =
639                         (ZigbeeZclGroupGetGroupMembershipNoti_t*)noti_data;
640
641                 Z_LOGD("get_group_membership_rsp from : [0x%X]", rsp->node_id);
642
643                 attr_builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
644
645                 for (i = 0; i < rsp->group_count; i++)
646                         g_variant_builder_add(attr_builder, "q", rsp->group_list[i]);
647                 group_list = g_variant_builder_end(attr_builder);
648                 g_variant_builder_unref(attr_builder);
649
650                 zigbee_zcl_group_emit_get_group_membership_rsp(group_object, rsp->node_id,
651                         rsp->src_ep, rsp->capacity, rsp->group_count, group_list);
652         }
653         break;
654         case ZBLIB_SERVICE_NOTI_REMOVE_GROUP_RSP: {
655                 ZigbeeZclGroupRemoveGroupNoti_t *rsp =
656                         (ZigbeeZclGroupRemoveGroupNoti_t*)noti_data;
657
658                 Z_LOGD("remove_group_rsp from : [0x%X]", rsp->node_id);
659
660                 zigbee_zcl_group_emit_remove_group_rsp(group_object, rsp->node_id, rsp->src_ep,
661                         rsp->status, rsp->group_id);
662         }
663         break;
664         default:
665                 Z_LOGE("Unexpected notification [%x]", noti_id);
666         break;
667         }
668
669         /* ZigbeeZcl_group should be dereferenced */
670         g_object_unref(group_object);
671 }
672 /* LCOV_EXCL_STOP */
673
674 gboolean zigbee_service_dbus_interface_zcl_group_init(ZigBeeServiceInterface *service_interface,
675         ZigbeeObjectSkeleton *zigbee_object)
676 {
677         ZigbeeZcl_group *zcl_group_object;
678
679         if (NULL == service_interface) {
680                 /* LCOV_EXCL_START */
681                 Z_LOGE("service_interface is NULL");
682                 return FALSE;
683                 /* LCOV_EXCL_STOP */
684         }
685
686         zcl_group_object = zigbee_zcl_group_skeleton_new();
687         zigbee_object_skeleton_set_zcl_group(zigbee_object, zcl_group_object);
688         g_object_unref(zcl_group_object);
689
690         Z_LOGI("zcl_group_object: [%p]", zcl_group_object);
691
692         /*
693          * Register signal handlers for 'zcl_group' interface
694          */
695         g_signal_connect(zcl_group_object,
696                 "handle-add-group",
697                 G_CALLBACK(on_zcl_group_add_group), service_interface);
698
699         g_signal_connect(zcl_group_object,
700                 "handle-view-group",
701                 G_CALLBACK(on_zcl_group_view_group), service_interface);
702
703         g_signal_connect(zcl_group_object,
704                 "handle-get-group-membership",
705                 G_CALLBACK(on_zcl_group_get_group_membership), service_interface);
706
707         g_signal_connect(zcl_group_object,
708                 "handle-remove-group",
709                 G_CALLBACK(on_zcl_group_remove_group), service_interface);
710
711         g_signal_connect(zcl_group_object,
712                 "handle-remove-all-group",
713                 G_CALLBACK(on_zcl_group_remove_all_group), service_interface);
714
715         g_signal_connect(zcl_group_object,
716                 "handle-add-group-if-identifying",
717                 G_CALLBACK(on_zcl_group_add_group_if_identifying), service_interface);
718
719         return TRUE;
720 }