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.
20 #include <zblib_driver.h>
21 #include <zblib_request.h>
23 #include "zblib_driver_zdodev_control.h"
27 ZblibDriverZdodevControlOps_t *ops; /**< Operations */
28 } ZblibDriverZdodevControlPrivData_t;
30 static gboolean __zblib_driver_zdodev_control_dispatcher(ZigBeeDriver *driver, guint request_id)
32 ZigBeeService *service = NULL;
37 Z_LOGE("driver is NULL");
41 service = zblib_driver_ref_service(driver);
42 if (NULL == service) {
43 Z_LOGE("service is NULL");
47 /* Fetch request_type using request_id */
48 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
51 ops_id = zblib_request_get_ops_id(request_type);
53 case ZBLIB_ZDODEV_CONTROL_OPS_NWK_ADDR_REQ: {
57 case ZBLIB_ZDODEV_CONTROL_OPS_MATCHED_DESCRIPTOR_REQ: {
61 case ZBLIB_ZDODEV_CONTROL_OPS_IEEE_ADDR_REQ: {
65 case ZBLIB_ZDODEV_CONTROL_OPS_ACTIVE_EP_REQ: {
69 case ZBLIB_ZDODEV_CONTROL_OPS_NODE_DESC_REQ: {
73 case ZBLIB_ZDODEV_CONTROL_OPS_POWER_DESC_REQ: {
77 case ZBLIB_ZDODEV_CONTROL_OPS_COMPLEX_DESC_REQ: {
81 case ZBLIB_ZDODEV_CONTROL_OPS_USER_DESC_REQ: {
85 case ZBLIB_ZDODEV_CONTROL_OPS_USER_DESC_SET_REQ: {
89 case ZBLIB_ZDODEV_CONTROL_OPS_DEVICE_ANNOUNCE: {
93 case ZBLIB_ZDODEV_CONTROL_OPS_SIMPLE_DESC_REQ: {
97 case ZBLIB_ZDODEV_CONTROL_OPS_MGMT_LQI_REQ: {
101 case ZBLIB_ZDODEV_CONTROL_OPS_MGMT_RTG_REQ: {
105 case ZBLIB_ZDODEV_CONTROL_OPS_MGMT_BIND_REQ: {
109 case ZBLIB_ZDODEV_CONTROL_OPS_MGMT_PERMIT_JOIN_REQ: {
113 case ZBLIB_ZDODEV_CONTROL_OPS_NWK_UPDATE_REQ: {
117 case ZBLIB_ZDODEV_CONTROL_OPS_NWK_DISC_REQ: {
128 static void __zblib_driver_zdodev_control_free_hook(ZigBeeDriver *driver)
130 ZblibDriverZdodevControlPrivData_t *priv_data = NULL;
132 if (NULL == driver) {
133 Z_LOGE("driver is NULL");
137 /* Fetch private data */
138 priv_data = zblib_driver_ref_object(driver);
139 if (NULL == priv_data) {
140 Z_LOGE("priv_data is NULL");
148 ZigBeeDriver *zblib_driver_zdodev_control_new(ZigBeePlugin *plugin,
149 const gchar *driver_name,
150 ZblibDriverZdodevControlOps_t *ops)
152 ZigBeeDriver *driver = NULL;
153 ZblibDriverZdodevControlPrivData_t *priv_data = NULL;
156 if (NULL == plugin) {
157 Z_LOGE("plugin is NULL");
161 /* Create new driver */
162 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZDODEV_CONTROL);
163 if (NULL == driver) {
164 Z_LOGE("driver is NULL");
168 /* Allocate memory for private data */
169 priv_data = g_malloc0(sizeof(ZblibDriverZdodevControlPrivData_t));
171 /* Update private data */
172 priv_data->ops = ops;
174 /* Link private data to driver */
175 ret = zblib_driver_link_object(driver, priv_data);
177 Z_LOGE("zblib_driver_link_object failed!");
179 /* Free allocated resources */
186 /* Set operations dispatcher function */
187 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zdodev_control_dispatcher);
189 Z_LOGE("zblib_driver_set_dispatcher failed!");
191 /* Free allocated resources */
198 /* Set free hook function */
199 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zdodev_control_free_hook);
201 Z_LOGE("zblib_driver_set_free_hook failed!");
203 /* Free allocated resources */
213 void zblib_driver_zdodev_control_free(ZigBeeDriver *driver)
215 if (NULL == driver) {
216 Z_LOGE("driver is NULL");
221 zblib_driver_free(driver);