4 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Anupam Roy <anupam.r@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-hf-dbus-handler.h"
34 #include "bt-hal-event-receiver.h"
36 static const bthf_callbacks_t *bt_hal_hf_cbacks;
38 static bool interface_ready(void)
40 return bt_hal_hf_cbacks != NULL;
43 static bt_status_t hf_connect(bt_bdaddr_t *bd_addr)
46 return _bt_hal_dbus_handler_hf_connect(bd_addr);
49 static bt_status_t hf_disconnect(bt_bdaddr_t *bd_addr)
52 return _bt_hal_dbus_handler_hf_disconnect(bd_addr);
55 static bt_status_t hf_connect_audio(bt_bdaddr_t *bd_addr)
58 return BT_STATUS_UNSUPPORTED;
61 static bt_status_t hf_disconnect_audio(bt_bdaddr_t *bd_addr)
64 return BT_STATUS_UNSUPPORTED;
67 static bt_status_t hf_start_voice_recognition(bt_bdaddr_t *bd_addr)
70 return BT_STATUS_UNSUPPORTED;
73 static bt_status_t hf_stop_voice_recognition(bt_bdaddr_t *bd_addr)
76 return BT_STATUS_UNSUPPORTED;
79 static bt_status_t hf_voume_control(bthf_volume_type_t type, int volume,
83 return BT_STATUS_UNSUPPORTED;
86 static bt_status_t hf_device_status_notification(bthf_network_state_t ntk_state,
87 bthf_service_type_t svc_type, int signal, int batt_chg)
90 return BT_STATUS_UNSUPPORTED;
93 static bt_status_t hf_cops_response(const char *cops, bt_bdaddr_t *bd_addr)
96 return BT_STATUS_UNSUPPORTED;
99 static bt_status_t hf_cind_response(int svc, int num_active, int num_held,
100 bthf_call_state_t call_setup_state,
101 int signal, int roam, int batt_chg,
102 bt_bdaddr_t *bd_addr)
105 return BT_STATUS_UNSUPPORTED;
108 static bt_status_t hf_formatted_at_response(const char *rsp, bt_bdaddr_t *bd_addr)
111 return BT_STATUS_UNSUPPORTED;
114 static bt_status_t hf_at_response(bthf_at_response_t response_code,
115 int error_code, bt_bdaddr_t *bd_addr)
118 return BT_STATUS_UNSUPPORTED;
121 static bt_status_t hf_clcc_response(int index, bthf_call_direction_t dir,
122 bthf_call_state_t state, bthf_call_mode_t mode,
123 bthf_call_mpty_type_t mpty, const char *number,
124 bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr)
127 return BT_STATUS_UNSUPPORTED;
130 static bt_status_t hf_phone_state_change(int num_active, int num_held, bthf_call_state_t call_setup_state,
131 const char *number, bthf_call_addrtype_t type)
134 return BT_STATUS_UNSUPPORTED;
137 static void __bt_hal_handle_hf_conn_state(void *buf, uint16_t len)
139 struct hal_ev_handsfree_conn_state *ev = buf;
141 if (bt_hal_hf_cbacks->connection_state_cb)
142 bt_hal_hf_cbacks->connection_state_cb(ev->state, (bt_bdaddr_t *) ev->bdaddr);
145 static void __bt_hal_handle_hf_audio_conn_state(void *buf, uint16_t len)
147 struct hal_ev_handsfree_audio_state *ev = buf;
149 if (bt_hal_hf_cbacks->audio_state_cb)
150 bt_hal_hf_cbacks->audio_state_cb(ev->state, (bt_bdaddr_t *) ev->bdaddr);
153 static void __bt_hal_handle_hf_events(int message, void *buf, uint16_t len)
156 if (!interface_ready())
159 case HAL_EV_HANDSFREE_CONN_STATE:
160 DBG("Event: HAL_EV_HANDSFREE_CONN_STATE");
161 __bt_hal_handle_hf_conn_state(buf, len);
163 case HAL_EV_HANDSFREE_AUDIO_STATE:
164 DBG("Event: HAL_EV_HANDSFREE_AUDIO_STATE");
165 __bt_hal_handle_hf_audio_conn_state(buf, len);
168 DBG("Event Currently not handled!!");
174 static bt_status_t init(bthf_callbacks_t* callbacks, int max_hf_clients)
178 if (interface_ready())
179 return BT_STATUS_DONE;
181 if (max_hf_clients > 1)
182 return BT_STATUS_UNSUPPORTED;
183 bt_hal_hf_cbacks = callbacks;
184 DBG("Register HF AG Role callback function");
185 _bt_hal_register_hf_dbus_handler_cb(__bt_hal_handle_hf_events);
186 _bt_hal_register_event_handler_cb(HAL_HF_AG, __bt_hal_handle_hf_events);
187 return BT_STATUS_SUCCESS;
190 static void cleanup(void)
194 if (!interface_ready())
197 _bt_hal_unregister_event_handler_cb(HAL_HF_AG);
198 bt_hal_hf_cbacks = NULL;
201 static bthf_interface_t bthf_if = {
202 .size = sizeof(bthf_if),
204 .connect = hf_connect,
205 .disconnect = hf_disconnect,
206 .connect_audio = hf_connect_audio,
207 .disconnect_audio = hf_disconnect_audio,
208 .start_voice_recognition = hf_start_voice_recognition,
209 .stop_voice_recognition = hf_stop_voice_recognition,
210 .volume_control = hf_voume_control,
211 .device_status_notification = hf_device_status_notification,
212 .cops_response = hf_cops_response,
213 .cind_response = hf_cind_response,
214 .formatted_at_response = hf_formatted_at_response,
215 .at_response = hf_at_response,
216 .clcc_response = hf_clcc_response,
217 .phone_state_change = hf_phone_state_change,
221 /*******************************************************************************
223 ** Function bt_get_hf_interface
225 ** Description Get the hf callback interface
227 ** Returns bthf_interface_t
229 *******************************************************************************/
230 const bthf_interface_t *bt_get_hf_interface()