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_zdo_bind.h>
23 static void on_zdo_bind_bind_req_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_zdo_bind_bind_req(ZigbeeZdo_bind *zdo_bind_object,
37 GDBusMethodInvocation *invocation,
48 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
49 ZigbeeZdoBindBindReq_t req;
50 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
52 GVariantIter *iter = NULL;
57 memset(&req, 0x0, sizeof(ZigbeeZdoBindBindReq_t));
59 /* Update request structure */
60 req.node_id = node_id;
61 g_variant_get(src_addr, "ay", &iter);
62 while (g_variant_iter_loop(iter, "y", req.src_addr[i])) {
64 if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
68 req.cluster_id = cluster_id;
69 g_variant_get(dst_addr, "ay", &iter);
70 while (g_variant_iter_loop(iter, "y", req.dst_addr[i])) {
72 if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
75 req.bind_type = bind_type;
76 req.group_addr = group_addr;
79 /* Allocate response callback data */
81 zigbee_service_dbus_interface_create_resp_cb_data(zdo_bind_object,
83 if (NULL == resp_cb_data) {
84 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
86 /* Send failure response */
87 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
92 /* Dispatch request */
93 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
94 ZBLIB_DRIVER_TYPE_ZDO_BIND,
95 ZBLIB_ZDO_BIND_OPS_BIND_REQ,
97 on_zdo_bind_bind_req_resp, resp_cb_data);
99 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
101 /* Free response callback data */
102 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
104 /* Send failure response */
105 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
113 static void on_zdo_bind_unbind_req_resp(ZigBeeServiceInterface *service_interface,
114 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
116 ZigbeeServiceInterfaceRespCbData_t *cb_data =
117 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
120 NOT_USED(service_interface);
121 NOT_USED(request_id);
123 NOT_USED(resp_data_len);
126 static gboolean on_zdo_bind_unbind_req(ZigbeeZdo_bind *zdo_bind_object,
127 GDBusMethodInvocation *invocation,
138 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
139 ZigbeeZdoBindUnbindReq_t req;
140 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
142 GVariantIter *iter = NULL;
147 memset(&req, 0x0, sizeof(ZigbeeZdoBindUnbindReq_t));
149 /* Update request structure */
150 req.node_id = node_id;
151 g_variant_get(src_addr, "ay", &iter);
152 while (g_variant_iter_loop(iter, "y", req.src_addr[i])) {
154 if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
158 req.cluster_id = cluster_id;
159 g_variant_get(dst_addr, "ay", &iter);
160 while (g_variant_iter_loop(iter, "y", req.dst_addr[i])) {
162 if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
165 req.bind_type = bind_type;
166 req.group_addr = group_addr;
169 /* Allocate response callback data */
171 zigbee_service_dbus_interface_create_resp_cb_data(zdo_bind_object,
172 invocation, NULL, 0);
173 if (NULL == resp_cb_data) {
174 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
176 /* Send failure response */
177 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
182 /* Dispatch request */
183 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
184 ZBLIB_DRIVER_TYPE_ZDO_BIND,
185 ZBLIB_ZDO_BIND_OPS_UNBIND_REQ,
187 on_zdo_bind_unbind_req_resp, resp_cb_data);
189 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
191 /* Free response callback data */
192 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
194 /* Send failure response */
195 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
203 void zigbee_service_dbus_interface_zdo_bind_notification(ZigBeeServiceInterface *service_interface,
204 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
206 if (NULL == service_interface) {
207 Z_LOGE("service_interface is NULL");
213 NOT_USED(noti_data_len);
214 NOT_USED(noti_cb_data);
217 gboolean zigbee_service_dbus_interface_zdo_bind_init(ZigBeeServiceInterface *service_interface,
218 ZigbeeObjectSkeleton *zigbee_object)
220 ZigbeeZdo_bind *zdo_bind_object;
222 if (NULL == service_interface) {
223 Z_LOGE("service_interface is NULL");
227 zdo_bind_object = zigbee_zdo_bind_skeleton_new();
228 zigbee_object_skeleton_set_zdo_bind(zigbee_object, zdo_bind_object);
229 g_object_unref(zdo_bind_object);
231 Z_LOGI("zdo_bind_object: [%p]", zdo_bind_object);
234 * Register signal handlers for 'zdo_bind' interface
236 g_signal_connect(zdo_bind_object,
238 G_CALLBACK(on_zdo_bind_bind_req), service_interface);
240 g_signal_connect(zdo_bind_object,
242 G_CALLBACK(on_zdo_bind_unbind_req), service_interface);