4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Atul Kumar Rai <a.rai@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "bt-hal-log.h"
30 #include "bt-hal-msg.h"
31 #include "bt-hal-utils.h"
33 #include "bt-hal-event-receiver.h"
34 #include "bt-hal-hdp-dbus-handler.h"
36 static const bthl_callbacks_t *bt_hal_hdp_cbacks;
38 static bool interface_ready(void)
40 return bt_hal_hdp_cbacks != NULL;
43 static void __bt_hal_handle_app_reg_state(void *buf, uint16_t len)
45 struct hal_ev_hdp_app_reg_state *ev = buf;
50 ERR("Event data is NULL, return");
54 if (bt_hal_hdp_cbacks->app_reg_state_cb)
55 bt_hal_hdp_cbacks->app_reg_state_cb(ev->app_id, ev->state);
60 static void __bt_hal_handle_hdp_conn_state(void *buf, uint16_t len)
62 struct hal_ev_hdp_conn_state *ev = buf;
67 ERR("Event data is NULL, return");
71 if (bt_hal_hdp_cbacks->channel_state_cb)
72 bt_hal_hdp_cbacks->channel_state_cb(ev->app_id, (bt_bdaddr_t *)(ev->bdaddr),
73 ev->mdep_index, ev->channel_id, ev->channel_state, ev->data_fd);
78 static void __bt_hal_handle_hdp_events(int message, void *buf, uint16_t len)
82 if (!interface_ready())
86 case HAL_EV_HDP_APP_REG_STATE:
87 DBG("Event: HAL_EV_HDP_APP_REG_STATE");
88 __bt_hal_handle_app_reg_state(buf, len);
90 case HAL_EV_HDP_CONN_STATE:
91 DBG("Event: HAL_EV_HDP_CONN_STATE");
92 __bt_hal_handle_hdp_conn_state(buf, len);
95 DBG("Event Currently not handled!!");
102 /** Register HL application */
103 static bt_status_t hdp_register_application(bthl_reg_param_t *p_reg_param, int *app_id)
105 int ret = BT_STATUS_SUCCESS;
112 return BT_STATUS_PARM_INVALID;
114 if (!p_reg_param->application_name)
115 return BT_STATUS_PARM_INVALID;
118 return BT_STATUS_PARM_INVALID;
120 /* Currently only 1 dep config is supported per app id */
121 if (0 > p_reg_param->number_of_mdeps || 1 < p_reg_param->number_of_mdeps) {
122 ERR("Currently only 1 dep config is supported per app");
123 return BT_STATUS_PARM_INVALID;
126 role = p_reg_param->mdep_cfg[0].mdep_role;
127 data_type = p_reg_param->mdep_cfg[0].data_type;
128 channel_type = p_reg_param->mdep_cfg[0].channel_type;
129 desc = p_reg_param->mdep_cfg[0].mdep_description;
131 ret = _bt_hal_dbus_handler_hdp_register_application(
132 role, data_type, channel_type, desc, app_id);
133 if (BT_STATUS_SUCCESS != ret) {
134 ERR("_bt_hal_dbus_handler_hdp_register_application failed");
137 DBG("app_id: %d", *app_id);
143 /** Unregister HL application */
144 static bt_status_t hdp_unregister_application(int app_id)
150 ret = _bt_hal_dbus_handler_hdp_unregister_application(app_id);
151 if (BT_STATUS_SUCCESS != ret)
152 ERR("_bt_hal_dbus_handler_hdp_unregister_application failed");
158 /** connect channel */
159 static bt_status_t hdp_connect_channel(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int *channel_id)
166 ret = _bt_hal_dbus_handler_hdp_connect_channel(app_id, bd_addr, channel_id);
167 if (BT_STATUS_SUCCESS != ret)
168 ERR("_bt_hal_dbus_handler_hdp_unregister_application failed");
174 /** destroy channel */
175 static bt_status_t hdp_destroy_channel(int channel_id)
181 ret = _bt_hal_dbus_handler_hdp_destroy_channel(channel_id);
182 if (BT_STATUS_SUCCESS != ret)
183 ERR("_bt_hal_dbus_handler_hdp_unregister_application failed");
189 static bt_status_t init(bthl_callbacks_t *callbacks)
193 if (interface_ready())
194 return BT_STATUS_DONE;
196 bt_hal_hdp_cbacks = callbacks;
197 DBG("Register HDP events callback function");
198 _bt_hal_register_hdp_dbus_handler_cb(__bt_hal_handle_hdp_events);
200 return BT_STATUS_SUCCESS;
203 static void cleanup(void)
207 if (!interface_ready())
210 DBG("Un-register HDP events callback function");
211 _bt_hal_unregister_hdp_dbus_handler_cb();
213 bt_hal_hdp_cbacks = NULL;
216 static bthl_interface_t hl_if = {
217 .size = sizeof(hl_if),
219 .register_application = hdp_register_application,
220 .unregister_application = hdp_unregister_application,
221 .connect_channel = hdp_connect_channel,
222 .destroy_channel = hdp_destroy_channel,
226 bthl_interface_t *bt_get_hl_interface(void)