4 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
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.
27 #include "bt-hal-log.h"
28 #include "bt-hal-msg.h"
29 #include "bt-hal-utils.h"
31 #include "bt-hal-hf-client-dbus-handler.h"
32 #include "bt-hal-event-receiver.h"
33 #include "bt-hal-hf-client.h"
35 static bthf_client_callbacks_t *bt_hal_hf_client_cbacks;
37 static bool interface_ready(void)
39 return bt_hal_hf_client_cbacks != NULL;
42 static bt_status_t bt_hal_hf_client_connect(bt_bdaddr_t *bd_addr)
45 return _bt_hal_dbus_handler_hf_client_connect(bd_addr);
48 static bt_status_t bt_hal_hf_client_disconnect(bt_bdaddr_t *bd_addr)
51 return _bt_hal_dbus_handler_hf_client_disconnect(bd_addr);
54 static bt_status_t bt_hal_hf_client_connect_audio(bt_bdaddr_t *bd_addr)
57 return BT_STATUS_UNSUPPORTED;
60 static bt_status_t bt_hal_hf_client_disconnect_audio(bt_bdaddr_t *bd_addr)
63 return BT_STATUS_UNSUPPORTED;
66 static bt_status_t bt_hal_hf_client_start_voice_recognition(void)
69 return BT_STATUS_UNSUPPORTED;
72 static bt_status_t bt_hal_hf_client_stop_voice_recognition(void)
75 return BT_STATUS_UNSUPPORTED;
78 static bt_status_t bt_hal_hf_client_volume_control(bthf_client_volume_type_t type, int volume)
81 return BT_STATUS_UNSUPPORTED;
84 static bt_status_t bt_hal_hf_client_dial(const char *number)
87 return BT_STATUS_UNSUPPORTED;
90 static bt_status_t bt_hal_hf_client_dial_memory(int location)
93 return BT_STATUS_UNSUPPORTED;
96 static bt_status_t bt_hal_hf_client_handle_call_action(bthf_client_call_action_t action, int idx)
99 return BT_STATUS_UNSUPPORTED;
102 static bt_status_t bt_hal_hf_client_query_current_calls(void)
105 return BT_STATUS_UNSUPPORTED;
108 static bt_status_t bt_hal_hf_client_query_current_operator_name(void)
111 return BT_STATUS_UNSUPPORTED;
114 static bt_status_t bt_hal_hf_client_retrieve_subscriber_info(void)
117 return BT_STATUS_UNSUPPORTED;
120 static bt_status_t bt_hal_hf_client_send_dtmf(char code)
123 return BT_STATUS_UNSUPPORTED;
126 static bt_status_t bt_hal_hf_client_request_last_voice_tag_number(void)
129 return BT_STATUS_UNSUPPORTED;
132 static bt_status_t bt_hal_hf_client_send_at_cmd(int cmd, int val1, int val2, const char *arg)
135 return BT_STATUS_UNSUPPORTED;
138 static bt_status_t bt_hal_hf_client_send_voice_data(unsigned char *p_buf, unsigned char len)
141 return BT_STATUS_UNSUPPORTED;
144 static void __bt_hal_handle_hf_client_conn_state(void *buf, uint16_t len)
146 struct hal_ev_hf_client_conn_state *ev = buf;
147 unsigned int peer_feat = 0;
148 unsigned int chld_feat = 0;
150 if (bt_hal_hf_client_cbacks->connection_state_cb)
151 bt_hal_hf_client_cbacks->connection_state_cb(ev->state,
152 peer_feat, chld_feat, (bt_bdaddr_t *) ev->bdaddr);
155 static void __bt_hal_handle_hf_client_events(int message, void *buf, uint16_t len)
158 if (!interface_ready())
161 case HAL_EV_HF_CLIENT_CONN_STATE:
162 DBG("Event: HAL_EV_HF_CLIENT_CONN_STATE");
163 __bt_hal_handle_hf_client_conn_state(buf, len);
166 DBG("Event Currently not handled!!");
172 static bt_status_t bt_hal_hf_init(bthf_client_callbacks_t* callbacks)
176 if (interface_ready())
177 return BT_STATUS_DONE;
179 bt_hal_hf_client_cbacks = callbacks;
180 DBG("Register HF Client Role callback function");
181 _bt_hal_register_hf_client_dbus_handler_cb(__bt_hal_handle_hf_client_events);
182 _bt_hal_register_event_handler_cb(HAL_HF_CLIENT, __bt_hal_handle_hf_client_events);
183 return BT_STATUS_SUCCESS;
186 static void bt_hal_hf_cleanup(void)
188 if (!interface_ready())
191 _bt_hal_unregister_event_handler_cb(HAL_HF_AG);
192 bt_hal_hf_client_cbacks = NULL;
195 static bthf_client_interface_t bthf_client_if = {
196 .size = sizeof(bthf_client_if),
197 .init = bt_hal_hf_init,
198 .connect = bt_hal_hf_client_connect,
199 .disconnect = bt_hal_hf_client_disconnect,
200 .connect_audio = bt_hal_hf_client_connect_audio,
201 .disconnect_audio = bt_hal_hf_client_disconnect_audio,
202 .start_voice_recognition = bt_hal_hf_client_start_voice_recognition,
203 .stop_voice_recognition = bt_hal_hf_client_stop_voice_recognition,
204 .volume_control = bt_hal_hf_client_volume_control,
205 .dial = bt_hal_hf_client_dial,
206 .dial_memory = bt_hal_hf_client_dial_memory,
207 .handle_call_action = bt_hal_hf_client_handle_call_action,
208 .query_current_calls = bt_hal_hf_client_query_current_calls,
209 .query_current_operator_name = bt_hal_hf_client_query_current_operator_name,
210 .retrieve_subscriber_info = bt_hal_hf_client_retrieve_subscriber_info,
211 .send_dtmf = bt_hal_hf_client_send_dtmf,
212 .request_last_voice_tag_number = bt_hal_hf_client_request_last_voice_tag_number,
213 .cleanup = bt_hal_hf_cleanup,
214 .send_at_cmd = bt_hal_hf_client_send_at_cmd,
215 .send_voice_data = bt_hal_hf_client_send_voice_data,
218 /*******************************************************************************
220 ** Function bt_get_hf_client_interface
222 ** Description Get the hf client callback interface
224 ** Returns bthf_client_interface_t
226 *******************************************************************************/
227 bthf_client_interface_t *bt_get_hf_client_interface()
229 return &bthf_client_if;