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