Adapt HF Profile Connect & Disconnect to BT HAL framework
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-hf-client.c
1 /*
2  * BLUETOOTH HAL
3  *
4  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  *              http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <dlog.h>
25
26 #include "bt-hal.h"
27 #include "bt-hal-log.h"
28 #include "bt-hal-msg.h"
29 #include "bt-hal-utils.h"
30
31 #include "bt-hal-hf-client-dbus-handler.h"
32 #include "bt-hal-event-receiver.h"
33 #include "bt-hal-hf-client.h"
34
35 static bthf_client_callbacks_t *bt_hal_hf_client_cbacks;
36
37 static bool interface_ready(void)
38 {
39         return bt_hal_hf_client_cbacks != NULL;
40 }
41
42 static bt_status_t bt_hal_hf_client_connect(bt_bdaddr_t *bd_addr)
43 {
44         DBG("");
45         return _bt_hal_dbus_handler_hf_client_connect(bd_addr);
46 }
47
48 static bt_status_t bt_hal_hf_client_disconnect(bt_bdaddr_t *bd_addr)
49 {
50         DBG("");
51         return _bt_hal_dbus_handler_hf_client_disconnect(bd_addr);
52 }
53
54 static bt_status_t bt_hal_hf_client_connect_audio(bt_bdaddr_t *bd_addr)
55 {
56         DBG("");
57         return BT_STATUS_UNSUPPORTED;
58 }
59
60 static bt_status_t bt_hal_hf_client_disconnect_audio(bt_bdaddr_t *bd_addr)
61 {
62         DBG("");
63         return BT_STATUS_UNSUPPORTED;
64 }
65
66 static bt_status_t bt_hal_hf_client_start_voice_recognition(void)
67 {
68         DBG("");
69         return BT_STATUS_UNSUPPORTED;
70 }
71
72 static bt_status_t bt_hal_hf_client_stop_voice_recognition(void)
73 {
74         DBG("");
75         return BT_STATUS_UNSUPPORTED;
76 }
77
78 static bt_status_t bt_hal_hf_client_volume_control(bthf_client_volume_type_t type, int volume)
79 {
80         DBG("");
81         return BT_STATUS_UNSUPPORTED;
82 }
83
84 static bt_status_t bt_hal_hf_client_dial(const char *number)
85 {
86         DBG("");
87         return BT_STATUS_UNSUPPORTED;
88 }
89
90 static bt_status_t bt_hal_hf_client_dial_memory(int location)
91 {
92         DBG("");
93         return BT_STATUS_UNSUPPORTED;
94 }
95
96 static bt_status_t bt_hal_hf_client_handle_call_action(bthf_client_call_action_t action, int idx)
97 {
98         DBG("");
99         return BT_STATUS_UNSUPPORTED;
100 }
101
102 static bt_status_t bt_hal_hf_client_query_current_calls(void)
103 {
104         DBG("");
105         return BT_STATUS_UNSUPPORTED;
106 }
107
108 static bt_status_t bt_hal_hf_client_query_current_operator_name(void)
109 {
110         DBG("");
111         return BT_STATUS_UNSUPPORTED;
112 }
113
114 static bt_status_t bt_hal_hf_client_retrieve_subscriber_info(void)
115 {
116         DBG("");
117         return BT_STATUS_UNSUPPORTED;
118 }
119
120 static bt_status_t bt_hal_hf_client_send_dtmf(char code)
121 {
122         DBG("");
123         return BT_STATUS_UNSUPPORTED;
124 }
125
126 static bt_status_t bt_hal_hf_client_request_last_voice_tag_number(void)
127 {
128         DBG("");
129         return BT_STATUS_UNSUPPORTED;
130 }
131
132 static bt_status_t bt_hal_hf_client_send_at_cmd(int cmd, int val1, int val2, const char *arg)
133 {
134         DBG("");
135         return BT_STATUS_UNSUPPORTED;
136 }
137
138 static bt_status_t bt_hal_hf_client_send_voice_data(unsigned char *p_buf, unsigned char len)
139 {
140         DBG("");
141         return BT_STATUS_UNSUPPORTED;
142 }
143
144 static void __bt_hal_handle_hf_client_conn_state(void *buf, uint16_t len)
145 {
146         struct hal_ev_hf_client_conn_state *ev = buf;
147         unsigned int peer_feat = 0;
148         unsigned int chld_feat = 0;
149
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);
153 }
154
155 static void __bt_hal_handle_hf_client_events(int message, void *buf, uint16_t len)
156 {
157         DBG("+");
158         if (!interface_ready())
159                 return;
160         switch (message) {
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);
164                 break;
165         default:
166                 DBG("Event Currently not handled!!");
167                 break;
168         }
169         DBG("-");
170 }
171
172 static bt_status_t bt_hal_hf_init(bthf_client_callbacks_t* callbacks)
173 {
174         DBG("");
175
176         if (interface_ready())
177                 return BT_STATUS_DONE;
178
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;
184 }
185
186 static void bt_hal_hf_cleanup(void)
187 {
188         if (!interface_ready())
189                 return;
190
191         _bt_hal_unregister_event_handler_cb(HAL_HF_AG);
192         bt_hal_hf_client_cbacks = NULL;
193 }
194
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,
216 };
217
218 /*******************************************************************************
219 **
220 ** Function         bt_get_hf_client_interface
221 **
222 ** Description      Get the hf client callback interface
223 **
224 ** Returns          bthf_client_interface_t
225 **
226 *******************************************************************************/
227 bthf_client_interface_t *bt_get_hf_client_interface()
228 {
229         return &bthf_client_if;
230 }