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_custom.h>
23 static void on_custom_aps_send_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_custom_aps_send(ZigbeeCustom *custom_object,
37 GDBusMethodInvocation *invocation,
49 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
50 ZigbeeCustomApsSend_t req;
51 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
53 GVariantIter *iter = NULL;
58 memset(&req, 0x0, sizeof(ZigbeeCustomApsSend_t));
60 /* Update request structure */
61 req.node_id = node_id;
62 req.aps_frame_ctrl = aps_frame_ctrl;
64 req.dest_ep = dest_ep;
65 req.cluster_id = cluster_id;
66 req.profile_id = profile_id;
67 req.zcl_frame_ctrl = zcl_frame_ctrl;
68 req.mfg_code = mfg_code;
69 g_variant_get(payload, "ay", &iter);
70 while (g_variant_iter_loop(iter, "y", req.payload[i])) {
72 if (i >= ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN)
76 /* Allocate response callback data */
78 zigbee_service_dbus_interface_create_resp_cb_data(custom_object,
80 if (NULL == resp_cb_data) {
81 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
83 /* Send failure response */
84 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
89 /* Dispatch request */
90 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
91 ZBLIB_DRIVER_TYPE_CUSTOM,
92 ZBLIB_CUSTOM_OPS_APS_SEND,
94 on_custom_aps_send_resp, resp_cb_data);
96 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
98 /* Free response callback data */
99 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
101 /* Send failure response */
102 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
110 static void on_custom_zcl_send_resp(ZigBeeServiceInterface *service_interface,
111 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
113 ZigbeeServiceInterfaceRespCbData_t *cb_data =
114 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
117 NOT_USED(service_interface);
118 NOT_USED(request_id);
120 NOT_USED(resp_data_len);
123 static gboolean on_custom_zcl_send(ZigbeeCustom *custom_object,
124 GDBusMethodInvocation *invocation,
129 gchar zcl_frame_ctrl,
134 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
135 ZigbeeCustomZclSend_t req;
136 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
138 GVariantIter *iter = NULL;
143 memset(&req, 0x0, sizeof(ZigbeeCustomZclSend_t));
145 /* Update request structure */
146 req.node_id = node_id;
148 req.dest_ep = dest_ep;
149 req.cluster_id = cluster_id;
150 req.zcl_frame_ctrl = zcl_frame_ctrl;
152 g_variant_get(payload, "ay", &iter);
153 while (g_variant_iter_loop(iter, "y", req.payload[i])) {
155 if (i >= ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN)
159 /* Allocate response callback data */
161 zigbee_service_dbus_interface_create_resp_cb_data(custom_object,
162 invocation, NULL, 0);
163 if (NULL == resp_cb_data) {
164 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
166 /* Send failure response */
167 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
172 /* Dispatch request */
173 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
174 ZBLIB_DRIVER_TYPE_CUSTOM,
175 ZBLIB_CUSTOM_OPS_ZCL_SEND,
177 on_custom_zcl_send_resp, resp_cb_data);
179 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
181 /* Free response callback data */
182 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
184 /* Send failure response */
185 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
193 static void on_custom_send_to_local_resp(ZigBeeServiceInterface *service_interface,
194 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
196 ZigbeeServiceInterfaceRespCbData_t *cb_data =
197 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
200 NOT_USED(service_interface);
201 NOT_USED(request_id);
203 NOT_USED(resp_data_len);
206 static gboolean on_custom_send_to_local(ZigbeeCustom *custom_object,
207 GDBusMethodInvocation *invocation,
211 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
212 ZigbeeCustomSendToLocal_t req;
213 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
215 GVariantIter *iter = NULL;
220 memset(&req, 0x0, sizeof(ZigbeeCustomSendToLocal_t));
222 /* Update request structure */
223 g_variant_get(data, "ay", &iter);
224 while (g_variant_iter_loop(iter, "y", req.data[i])) {
226 if (i >= ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN)
230 /* Allocate response callback data */
232 zigbee_service_dbus_interface_create_resp_cb_data(custom_object,
233 invocation, NULL, 0);
234 if (NULL == resp_cb_data) {
235 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
237 /* Send failure response */
238 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
243 /* Dispatch request */
244 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
245 ZBLIB_DRIVER_TYPE_CUSTOM,
246 ZBLIB_CUSTOM_OPS_SEND_TO_LOCAL,
248 on_custom_send_to_local_resp, resp_cb_data);
250 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
252 /* Free response callback data */
253 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
255 /* Send failure response */
256 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
264 void zigbee_service_dbus_interface_custom_notification(ZigBeeServiceInterface *service_interface,
265 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
267 if (NULL == service_interface) {
268 Z_LOGE("service_interface is NULL");
274 NOT_USED(noti_data_len);
275 NOT_USED(noti_cb_data);
278 gboolean zigbee_service_dbus_interface_custom_init(ZigBeeServiceInterface *service_interface,
279 ZigbeeObjectSkeleton *zigbee_object)
281 ZigbeeCustom *custom_object;
283 if (NULL == service_interface) {
284 Z_LOGE("service_interface is NULL");
288 custom_object = zigbee_custom_skeleton_new();
289 zigbee_object_skeleton_set_custom(zigbee_object, custom_object);
290 g_object_unref(custom_object);
292 Z_LOGI("custom_object: [%p]", custom_object);
295 * Register signal handlers for 'custom' interface
297 g_signal_connect(custom_object,
299 G_CALLBACK(on_custom_aps_send), service_interface);
301 g_signal_connect(custom_object,
303 G_CALLBACK(on_custom_zcl_send), service_interface);
305 g_signal_connect(custom_object,
306 "handle-send-to-local",
307 G_CALLBACK(on_custom_send_to_local), service_interface);