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_ias_zone.h>
24 static void *_service_interface_ref_zigbee_zcl_ias_zone(ZigBeeServiceInterface *service_interface)
26 ZigbeeObjectSkeleton *zigbee_object = NULL;
27 ZigbeeCustomData_t *custom_data = NULL;
28 ZigbeeZcl_ias_zone *ias_object = NULL;
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!");
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!", zigbee_object);
43 ias_object = zigbee_object_get_zcl_ias_zone(ZIGBEE_OBJECT(zigbee_object));
47 static void on_zclias_control_enroll_response_resp(ZigBeeServiceInterface *service_interface,
48 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
50 ZigbeeServiceInterfaceRespCbData_t *cb_data =
51 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
53 ZigbeeZcl_ias_zone *ias_object = NULL;
54 GDBusMethodInvocation *invocation = NULL;
56 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
58 NOT_USED(service_interface);
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);
67 ias_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
68 zblib_check_null_free_and_ret("ias_object", ias_object, cb_data);
70 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
71 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
73 zigbee_zcl_ias_zone_complete_enroll_response(ias_object, invocation, payload->result);
78 static gboolean on_zclias_control_enroll_response(ZigbeeZcl_ias_zone *zclias_control_object,
79 GDBusMethodInvocation *invocation,
86 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
87 ZigbeeZclIasZoneEnrollResponse_t req;
88 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
92 memset(&req, 0x0, sizeof(ZigbeeZclIasZoneEnrollResponse_t));
94 /* Update request structure */
95 req.node_id = node_id;
96 req.dest_ep = dest_ep;
97 req.enroll_code = enroll_code;
98 req.zone_id = zone_id;
100 /* Allocate response callback data */
102 zigbee_service_dbus_interface_create_resp_cb_data(zclias_control_object,
103 invocation, NULL, 0);
104 if (NULL == resp_cb_data) {
105 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
107 /* Send failure response */
108 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
113 /* Dispatch request */
114 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
115 ZBLIB_DRIVER_TYPE_ZCL_IAS_ZONE,
116 ZBLIB_ZCL_IAS_ZONE_OPS_ENROLL_RESPONSE,
118 on_zclias_control_enroll_response_resp, resp_cb_data);
120 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
122 /* Free response callback data */
123 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
125 /* Send failure response */
126 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
134 void zigbee_service_dbus_interface_zcl_ias_zone_notification(ZigBeeServiceInterface *service_interface,
135 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
137 ZigbeeZcl_ias_zone *ias_object;
139 zblib_check_null_ret("service_interface", service_interface);
141 if (NULL == noti_data || 0 == noti_data_len) {
142 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
146 ias_object = _service_interface_ref_zigbee_zcl_ias_zone(service_interface);
147 zblib_check_null_ret("ias_object", ias_object);
149 NOT_USED(noti_cb_data);
152 case ZBLIB_ZCL_IAS_ZONE_NOTI_ZONE_STATUS_CHANGE: {
153 ZigbeeZclIasZoneStatusChangeNoti_t *rsp =
154 (ZigbeeZclIasZoneStatusChangeNoti_t*)noti_data;
156 Z_LOGD("status_change_rpt from : [0x%X]", rsp->node_id);
158 zigbee_zcl_ias_zone_emit_status_change_rpt(ias_object, rsp->node_id, rsp->src_ep,
159 rsp->zone_status, rsp->extended_status, rsp->zone_id, rsp->delay);
162 case ZBLIB_ZCL_IAS_ZONE_NOTI_ENROLL_REQUEST: {
163 ZigbeeZclIasEnrollRequestNoti_t *rsp =
164 (ZigbeeZclIasEnrollRequestNoti_t*)noti_data;
166 Z_LOGD("enroll_request from : [0x%X]", rsp->node_id);
168 zigbee_zcl_ias_zone_emit_enroll_request(ias_object, rsp->node_id, rsp->src_ep,
169 rsp->zone_type, rsp->mfg_code);
173 Z_LOGE("Unexpected notification [%x]", noti_id);
177 /* ZigbeeZcl_ias_zone should be dereferenced */
178 g_object_unref(ias_object);
182 gboolean zigbee_service_dbus_interface_zcl_ias_zone_init(ZigBeeServiceInterface *service_interface,
183 ZigbeeObjectSkeleton *zigbee_object)
185 ZigbeeZcl_ias_zone *zclias_control_object;
187 if (NULL == service_interface) {
188 /* LCOV_EXCL_START */
189 Z_LOGE("service_interface is NULL");
194 zclias_control_object = zigbee_zcl_ias_zone_skeleton_new();
195 zigbee_object_skeleton_set_zcl_ias_zone(zigbee_object, zclias_control_object);
196 g_object_unref(zclias_control_object);
198 Z_LOGI("zclias_control_object: [%p]", zclias_control_object);
201 * Register signal handlers for 'zclias_control' interface
203 g_signal_connect(zclias_control_object,
204 "handle-enroll-response",
205 G_CALLBACK(on_zclias_control_enroll_response), service_interface);