2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Suresh Kumar N (suresh.n@samsung.com)
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "zigbee_service_interface_common.h"
21 #include <zblib_driver_zcl_group.h>
23 static void on_zcl_group_add_group_resp(ZigBeeServiceInterface *service_interface,
24 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
26 ZigbeeServiceInterfaceRespCbData_t *cb_data =
27 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
30 NOT_USED(service_interface);
33 NOT_USED(resp_data_len);
36 static gboolean on_zcl_group_add_group(ZigbeeZcl_group *zcl_group_object,
37 GDBusMethodInvocation *invocation,
44 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
45 ZigbeeZclGroupAddGroup_t req;
46 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
48 GVariantIter *iter = NULL;
53 memset(&req, 0x0, sizeof(ZigbeeZclGroupAddGroup_t));
55 /* Update request structure */
56 req.node_id = node_id;
57 req.dest_ep = dest_ep;
58 req.group_id = group_id;
59 g_variant_get(group_name, "ay", &iter);
60 while (g_variant_iter_loop(iter, "y", req.group_name[i])) {
62 if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
66 /* Allocate response callback data */
68 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
70 if (NULL == resp_cb_data) {
71 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
73 /* Send failure response */
74 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
79 /* Dispatch request */
80 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
81 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
82 ZBLIB_ZCL_GROUP_OPS_ADD_GROUP,
84 on_zcl_group_add_group_resp, resp_cb_data);
86 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
88 /* Free response callback data */
89 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
91 /* Send failure response */
92 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
100 static void on_zcl_group_view_group_resp(ZigBeeServiceInterface *service_interface,
101 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
103 ZigbeeServiceInterfaceRespCbData_t *cb_data =
104 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
107 NOT_USED(service_interface);
108 NOT_USED(request_id);
110 NOT_USED(resp_data_len);
113 static gboolean on_zcl_group_view_group(ZigbeeZcl_group *zcl_group_object,
114 GDBusMethodInvocation *invocation,
120 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
121 ZigbeeZclGroupViewGroup_t req;
122 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
126 memset(&req, 0x0, sizeof(ZigbeeZclGroupViewGroup_t));
128 /* Update request structure */
129 req.node_id = node_id;
130 req.dest_ep = dest_ep;
131 req.group_id = group_id;
133 /* Allocate response callback data */
135 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
136 invocation, NULL, 0);
137 if (NULL == resp_cb_data) {
138 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
140 /* Send failure response */
141 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
146 /* Dispatch request */
147 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
148 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
149 ZBLIB_ZCL_GROUP_OPS_VIEW_GROUP,
151 on_zcl_group_view_group_resp, resp_cb_data);
153 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
155 /* Free response callback data */
156 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
158 /* Send failure response */
159 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
167 static void on_zcl_group_get_group_membership_resp(ZigBeeServiceInterface *service_interface,
168 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
170 ZigbeeServiceInterfaceRespCbData_t *cb_data =
171 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
174 NOT_USED(service_interface);
175 NOT_USED(request_id);
177 NOT_USED(resp_data_len);
180 static gboolean on_zcl_group_get_group_membership(ZigbeeZcl_group *zcl_group_object,
181 GDBusMethodInvocation *invocation,
185 GVariant *group_list,
188 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
189 ZigbeeZclGroupGetGroupMembership_t req;
190 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
192 GVariantIter *iter = NULL;
197 memset(&req, 0x0, sizeof(ZigbeeZclGroupGetGroupMembership_t));
199 /* Update request structure */
200 req.node_id = node_id;
201 req.dest_ep = dest_ep;
202 req.group_count = group_count;
203 req.group_list = g_malloc0(sizeof(gshort) * group_count);
204 g_variant_get(group_list, "aq", &iter);
205 while (g_variant_iter_loop(iter, "q", req.group_list[i])) {
207 if (i >= group_count)
211 /* Allocate response callback data */
213 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
214 invocation, NULL, 0);
215 if (NULL == resp_cb_data) {
216 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
218 /* Send failure response */
219 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
224 /* Dispatch request */
225 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
226 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
227 ZBLIB_ZCL_GROUP_OPS_GET_GROUP_MEMBERSHIP,
229 on_zcl_group_get_group_membership_resp, resp_cb_data);
232 g_free(req.group_list);
235 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
237 /* Free response callback data */
238 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
240 /* Send failure response */
241 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
249 static void on_zcl_group_remove_group_resp(ZigBeeServiceInterface *service_interface,
250 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
252 ZigbeeServiceInterfaceRespCbData_t *cb_data =
253 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
256 NOT_USED(service_interface);
257 NOT_USED(request_id);
259 NOT_USED(resp_data_len);
262 static gboolean on_zcl_group_remove_group(ZigbeeZcl_group *zcl_group_object,
263 GDBusMethodInvocation *invocation,
269 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
270 ZigbeeZclGroupRemoveGroup_t req;
271 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
275 memset(&req, 0x0, sizeof(ZigbeeZclGroupRemoveGroup_t));
277 /* Update request structure */
278 req.node_id = node_id;
279 req.dest_ep = dest_ep;
280 req.group_id = group_id;
282 /* Allocate response callback data */
284 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
285 invocation, NULL, 0);
286 if (NULL == resp_cb_data) {
287 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
289 /* Send failure response */
290 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
295 /* Dispatch request */
296 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
297 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
298 ZBLIB_ZCL_GROUP_OPS_REMOVE_GROUP,
300 on_zcl_group_remove_group_resp, resp_cb_data);
302 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
304 /* Free response callback data */
305 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
307 /* Send failure response */
308 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
316 static void on_zcl_group_remove_all_group_resp(ZigBeeServiceInterface *service_interface,
317 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
319 ZigbeeServiceInterfaceRespCbData_t *cb_data =
320 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
323 NOT_USED(service_interface);
324 NOT_USED(request_id);
326 NOT_USED(resp_data_len);
329 static gboolean on_zcl_group_remove_all_group(ZigbeeZcl_group *zcl_group_object,
330 GDBusMethodInvocation *invocation,
335 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
336 ZigbeeZclGroupRemoveAllGroup_t req;
337 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
341 memset(&req, 0x0, sizeof(ZigbeeZclGroupRemoveAllGroup_t));
343 /* Update request structure */
344 req.node_id = node_id;
345 req.dest_ep = dest_ep;
347 /* Allocate response callback data */
349 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
350 invocation, NULL, 0);
351 if (NULL == resp_cb_data) {
352 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
354 /* Send failure response */
355 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
360 /* Dispatch request */
361 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
362 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
363 ZBLIB_ZCL_GROUP_OPS_REMOVE_ALL_GROUP,
365 on_zcl_group_remove_all_group_resp, resp_cb_data);
367 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
369 /* Free response callback data */
370 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
372 /* Send failure response */
373 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
381 static void on_zcl_group_add_group_if_identifying_resp(ZigBeeServiceInterface *service_interface,
382 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
384 ZigbeeServiceInterfaceRespCbData_t *cb_data =
385 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
388 NOT_USED(service_interface);
389 NOT_USED(request_id);
391 NOT_USED(resp_data_len);
394 static gboolean on_zcl_group_add_group_if_identifying(ZigbeeZcl_group *zcl_group_object,
395 GDBusMethodInvocation *invocation,
399 GVariant *group_name,
402 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
403 ZigbeeZclGroupAddGroupIfIdentifying_t req;
404 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
406 GVariantIter *iter = NULL;
411 memset(&req, 0x0, sizeof(ZigbeeZclGroupAddGroupIfIdentifying_t));
413 /* Update request structure */
414 req.node_id = node_id;
415 req.dest_ep = dest_ep;
416 req.group_id = group_id;
417 g_variant_get(group_name, "ay", &iter);
418 while (g_variant_iter_loop(iter, "y", req.group_name[i])) {
420 if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
424 /* Allocate response callback data */
426 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
427 invocation, NULL, 0);
428 if (NULL == resp_cb_data) {
429 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
431 /* Send failure response */
432 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
437 /* Dispatch request */
438 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
439 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
440 ZBLIB_ZCL_GROUP_OPS_ADD_GROUP_IF_IDENTIFYING,
442 on_zcl_group_add_group_if_identifying_resp, resp_cb_data);
444 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
446 /* Free response callback data */
447 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
449 /* Send failure response */
450 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
458 void zigbee_service_dbus_interface_zcl_group_notification(ZigBeeServiceInterface *service_interface,
459 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
461 if (NULL == service_interface) {
462 Z_LOGE("service_interface is NULL");
468 NOT_USED(noti_data_len);
469 NOT_USED(noti_cb_data);
472 gboolean zigbee_service_dbus_interface_zcl_group_init(ZigBeeServiceInterface *service_interface,
473 ZigbeeObjectSkeleton *zigbee_object)
475 ZigbeeZcl_group *zcl_group_object;
477 if (NULL == service_interface) {
478 Z_LOGE("service_interface is NULL");
482 zcl_group_object = zigbee_zcl_group_skeleton_new();
483 zigbee_object_skeleton_set_zcl_group(zigbee_object, zcl_group_object);
484 g_object_unref(zcl_group_object);
486 Z_LOGI("zcl_group_object: [%p]", zcl_group_object);
489 * Register signal handlers for 'zcl_group' interface
491 g_signal_connect(zcl_group_object,
493 G_CALLBACK(on_zcl_group_add_group), service_interface);
495 g_signal_connect(zcl_group_object,
497 G_CALLBACK(on_zcl_group_view_group), service_interface);
499 g_signal_connect(zcl_group_object,
500 "handle-get-group-membership",
501 G_CALLBACK(on_zcl_group_get_group_membership), service_interface);
503 g_signal_connect(zcl_group_object,
504 "handle-remove-group",
505 G_CALLBACK(on_zcl_group_remove_group), service_interface);
507 g_signal_connect(zcl_group_object,
508 "handle-remove-all-group",
509 G_CALLBACK(on_zcl_group_remove_all_group), service_interface);
511 g_signal_connect(zcl_group_object,
512 "handle-add-group-if-identifying",
513 G_CALLBACK(on_zcl_group_add_group_if_identifying), service_interface);