2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include <bluetooth-api.h>
27 #include <system_info.h>
29 #include "bluetooth.h"
30 #include "bluetooth_internal.h"
31 #include "bluetooth_extension.h"
32 #include "bluetooth_private.h"
33 #include "bluetooth-media-control.h"
34 #include "bluetooth-telephony-api.h"
36 static bool is_initialized = false;
37 static bool is_le_initialized = false;
40 static bt_event_sig_event_slot_s bt_event_slot_container[BT_EVENT_MAX] = { {NULL, NULL}, };
47 static bt_err2str_table_t err2str[] = {
48 { BT_ERROR_CANCELLED, "CANCELLED" },
49 { BT_ERROR_INVALID_PARAMETER, "INVALID_PARAMETER" },
50 { BT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY" },
51 { BT_ERROR_RESOURCE_BUSY, "RESOURCE_BUSY" },
52 { BT_ERROR_TIMED_OUT, "TIMED_OUT" },
53 { BT_ERROR_NOW_IN_PROGRESS, "NOW_IN_PROGRESS" },
54 { BT_ERROR_NOT_INITIALIZED, "NOT_INITIALIZED" },
55 { BT_ERROR_NOT_ENABLED, "DEVICE_NOT_ENABLED" },
56 { BT_ERROR_ALREADY_DONE, "ALREADY_DONE" },
57 { BT_ERROR_OPERATION_FAILED, "OPERATION_FAILED" },
58 { BT_ERROR_NOT_IN_PROGRESS, "NOT_IN_PROGRESS" },
59 { BT_ERROR_REMOTE_DEVICE_NOT_BONDED, "REMOTE_DEVICE_NOT_BONDED" },
60 { BT_ERROR_AUTH_REJECTED, "AUTH_REJECTED" },
61 { BT_ERROR_AUTH_FAILED, "AUTH_FAILED" },
62 { BT_ERROR_REMOTE_DEVICE_NOT_FOUND, "REMOTE_DEVICE_NOT_FOUND" },
63 { BT_ERROR_SERVICE_SEARCH_FAILED, "SERVICE_SEARCH_FAILED" },
64 { BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED, "REMOTE_DEVICE_NOT_CONNECTED" },
65 { BT_ERROR_PERMISSION_DENIED, "PERMISSION_DENIED" },
66 { BT_ERROR_SERVICE_NOT_FOUND, "SERVICE_NOT_FOUND" },
67 { BT_ERROR_NOT_SUPPORTED, "NOT_SUPPORTD" },
68 { BT_ERROR_NO_DATA, "NO_DATA" },
69 { BT_ERROR_QUOTA_EXCEEDED, "QUOTA EXCEEDED" },
70 { BT_ERROR_AGAIN, "AGAIN" },
71 { BT_ERROR_DEVICE_POLICY_RESTRICTION, "DEVICE_POLICY_RESTRICTION" },
80 static bt_err2pub_table_t err2pub[] = {
81 { BLUETOOTH_ERROR_NONE, BT_ERROR_NONE },
82 { BLUETOOTH_ERROR_INVALID_DATA, BT_ERROR_INVALID_PARAMETER },
83 { BLUETOOTH_ERROR_INVALID_PARAM, BT_ERROR_INVALID_PARAMETER },
84 { BLUETOOTH_ERROR_NOT_CONNECTED, BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED },
85 { BLUETOOTH_ERROR_NOT_SUPPORT, BT_ERROR_NOT_SUPPORTED },
86 { BLUETOOTH_ERROR_MEMORY_ALLOCATION, BT_ERROR_OUT_OF_MEMORY },
87 { BLUETOOTH_ERROR_OUT_OF_MEMORY, BT_ERROR_OUT_OF_MEMORY },
88 { BLUETOOTH_ERROR_TIMEOUT, BT_ERROR_TIMED_OUT },
89 { BLUETOOTH_ERROR_DEVICE_NOT_ENABLED, BT_ERROR_NOT_ENABLED },
90 { BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED, BT_ERROR_ALREADY_DONE },
91 { BLUETOOTH_ERROR_ALREADY_INITIALIZED, BT_ERROR_ALREADY_DONE },
92 { BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST, BT_ERROR_ALREADY_DONE },
93 { BLUETOOTH_ERROR_ALREADY_DEACTIVATED, BT_ERROR_ALREADY_DONE },
94 { BLUETOOTH_ERROR_ALREADY_CONNECT, BT_ERROR_ALREADY_DONE },
95 { BLUETOOTH_ERROR_NOT_PAIRED, BT_ERROR_REMOTE_DEVICE_NOT_BONDED },
96 { BLUETOOTH_ERROR_NOT_IN_OPERATION, BT_ERROR_NOT_IN_PROGRESS },
97 { BLUETOOTH_ERROR_IN_PROGRESS, BT_ERROR_NOW_IN_PROGRESS },
98 { BLUETOOTH_ERROR_DEVICE_BUSY, BT_ERROR_RESOURCE_BUSY },
99 { BLUETOOTH_ERROR_CANCEL, BT_ERROR_CANCELLED },
100 { BLUETOOTH_ERROR_CANCEL_BY_USER, BT_ERROR_CANCELLED },
101 { BLUETOOTH_ERROR_AUTHENTICATION_FAILED, BT_ERROR_AUTH_FAILED },
102 { BLUETOOTH_ERROR_HOST_DOWN, BT_ERROR_REMOTE_DEVICE_NOT_FOUND },
103 { BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR, BT_ERROR_SERVICE_SEARCH_FAILED },
104 { BLUETOOTH_ERROR_PERMISSION_DEINED, BT_ERROR_PERMISSION_DENIED },
105 { BLUETOOTH_ERROR_SERVICE_NOT_FOUND, BT_ERROR_SERVICE_NOT_FOUND },
106 { BLUETOOTH_ERROR_NOT_INITIALIZED, BT_ERROR_NOT_INITIALIZED },
107 { BLUETOOTH_ERROR_NO_RESOURCES, BT_ERROR_QUOTA_EXCEEDED },
108 { BLUETOOTH_ERROR_AUTHENTICATION_REJECTED, BT_ERROR_AUTH_REJECTED },
109 { BLUETOOTH_ERROR_AUTHORIZATION_REJECTED, BT_ERROR_AUTHORIZATION_REJECTED },
110 { BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION, BT_ERROR_DEVICE_POLICY_RESTRICTION },
111 { BLUETOOTH_ERROR_NO_DATA, BT_ERROR_NO_DATA },
112 { BLUETOOTH_ERROR_PARING_FAILED, BT_ERROR_OPERATION_FAILED },
113 { BLUETOOTH_ERROR_MAX_CONNECTION, BT_ERROR_OPERATION_FAILED },
114 { BLUETOOTH_ERROR_REGISTRATION_FAILED, BT_ERROR_OPERATION_FAILED },
115 { BLUETOOTH_ERROR_CONNECTION_BUSY, BT_ERROR_OPERATION_FAILED },
116 { BLUETOOTH_ERROR_MAX_CLIENT, BT_ERROR_OPERATION_FAILED },
117 { BLUETOOTH_ERROR_INVALID_CALLBACK, BT_ERROR_OPERATION_FAILED },
118 { BLUETOOTH_ERROR_NOT_FOUND, BT_ERROR_OPERATION_FAILED },
119 { BLUETOOTH_ERROR_INTERNAL, BT_ERROR_OPERATION_FAILED },
120 { BLUETOOTH_ERROR_CONNECTION_ERROR, BT_ERROR_OPERATION_FAILED },
121 { BLUETOOTH_ERROR_ACCESS_DENIED, BT_ERROR_OPERATION_FAILED },
122 { 0xFF, BT_ERROR_OPERATION_FAILED }
128 } bt_event2index_table_t;
130 static bt_event2index_table_t event2index[] = {
131 { BLUETOOTH_EVENT_ENABLED, BT_EVENT_STATE_CHANGED },
132 { BLUETOOTH_EVENT_DISABLED, BT_EVENT_STATE_CHANGED },
133 { BLUETOOTH_EVENT_DISABLED_BATTERY_DATA, BT_EVENT_ADAPTER_DISABLED_BATTERY_DATA},
134 { BLUETOOTH_EVENT_LE_ENABLED, BT_EVENT_LE_STATE_CHANGED },
135 { BLUETOOTH_EVENT_LE_DISABLED, BT_EVENT_LE_STATE_CHANGED },
136 { BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, BT_EVENT_NAME_CHANGED },
137 { BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED, BT_EVENT_VISIBILITY_MODE_CHANGED },
138 { BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, BT_EVENT_VISIBILITY_DURATION_CHANGED },
139 { BLUETOOTH_EVENT_DISCOVERY_STARTED, BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED },
140 { BLUETOOTH_EVENT_DISCOVERY_FINISHED, BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED },
141 { BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED, BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED },
142 { BLUETOOTH_EVENT_BONDING_FINISHED, BT_EVENT_BOND_CREATED },
143 { BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED, BT_EVENT_BOND_DESTROYED },
144 { BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, BT_EVENT_AUTHENTICATION_REQUEST },
145 { BLUETOOTH_EVENT_PASSKEY_REQUEST, BT_EVENT_AUTHENTICATION_REQUEST},
146 { BLUETOOTH_EVENT_PIN_REQUEST, BT_EVENT_AUTHENTICATION_REQUEST },
147 { BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST, BT_EVENT_AUTHENTICATION_REQUEST },
148 { BLUETOOTH_EVENT_DEVICE_AUTHORIZED, BT_EVENT_AUTHORIZATION_CHANGED },
149 { BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED, BT_EVENT_AUTHORIZATION_CHANGED },
150 { BLUETOOTH_EVENT_DEVICE_CONNECTED, BT_EVENT_DEVICE_CONNECTION_STATUS },
151 { BLUETOOTH_EVENT_DEVICE_DISCONNECTED, BT_EVENT_DEVICE_CONNECTION_STATUS },
152 #ifdef TIZEN_GATT_CLIENT
153 { BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED, BT_EVENT_GATT_CONNECTION_STATUS },
154 { BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED, BT_EVENT_GATT_CONNECTION_STATUS },
155 { BLUETOOTH_EVENT_GATT_SERVER_CONNECTED, BT_EVENT_GATT_CONNECTION_STATUS },
156 { BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED, BT_EVENT_GATT_CONNECTION_STATUS },
158 { BLUETOOTH_EVENT_GATT_CONNECTED, BT_EVENT_GATT_CONNECTION_STATUS; },
159 { BLUETOOTH_EVENT_GATT_DISCONNECTED, BT_EVENT_GATT_CONNECTION_STATUS; },
161 { BLUETOOTH_EVENT_SERVICE_SEARCHED, BT_EVENT_SERVICE_SEARCHED },
162 { BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED, BT_EVENT_DATA_RECEIVED },
163 { BLUETOOTH_EVENT_RFCOMM_CONNECTED, BT_EVENT_CONNECTION_STATE_CHANGED },
164 { BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, BT_EVENT_CONNECTION_STATE_CHANGED },
165 { BLUETOOTH_EVENT_RFCOMM_AUTHORIZE, BT_EVENT_RFCOMM_CONNECTION_REQUESTED },
166 { BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE, BT_EVENT_OPP_CONNECTION_REQUESTED },
167 { BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, BT_EVENT_OPP_PUSH_REQUESTED },
168 { BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED, BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS },
169 { BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS, BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS },
170 { BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED, BT_EVENT_OPP_SERVER_TRANSFER_FINISHED },
171 { BLUETOOTH_EVENT_OPC_CONNECTED, BT_EVENT_OPP_CLIENT_PUSH_RESPONSED },
172 { BLUETOOTH_EVENT_OPC_TRANSFER_STARTED, BT_EVENT_OPP_CLIENT_PUSH_PROGRESS },
173 { BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS, BT_EVENT_OPP_CLIENT_PUSH_PROGRESS },
174 { BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE, BT_EVENT_OPP_CLIENT_PUSH_PROGRESS },
175 { BLUETOOTH_EVENT_OPC_DISCONNECTED, BT_EVENT_OPP_CLIENT_PUSH_FINISHED },
176 { BLUETOOTH_EVENT_MAP_LIST_FOLDERS_COMPLETE, BT_EVENT_MAP_CLIENT_LIST_FOLDERS },
177 { BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE, BT_EVENT_MAP_CLIENT_LIST_FILTER_FIELDS },
178 { BLUETOOTH_EVENT_MAP_LIST_MESSAGES_COMPLETE, BT_EVENT_MAP_CLIENT_LIST_MESSAGES },
179 { BLUETOOTH_EVENT_MAP_GET_MESSAGE_COMPLETE, BT_EVENT_MAP_CLIENT_GET_MESSAGE },
180 { BLUETOOTH_EVENT_MAP_PUSH_MESSAGE_COMPLETE, BT_EVENT_MAP_CLIENT_PUSH_MESSAGE },
181 { BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED, BT_EVENT_NAP_CONNECTION_STATE_CHANGED },
182 { BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED, BT_EVENT_NAP_CONNECTION_STATE_CHANGED },
183 { BLUETOOTH_EVENT_NETWORK_CONNECTED, BT_EVENT_PAN_CONNECTION_STATE_CHANGED },
184 { BLUETOOTH_EVENT_NETWORK_DISCONNECTED, BT_EVENT_PAN_CONNECTION_STATE_CHANGED },
185 { BLUETOOTH_EVENT_HDP_DATA_RECEIVED, BT_EVENT_HDP_DATA_RECEIVED },
186 { BLUETOOTH_EVENT_HDP_CONNECTED, BT_EVENT_HDP_CONNECTED },
187 { BLUETOOTH_EVENT_HDP_DISCONNECTED, BT_EVENT_HDP_DISCONNECTED },
188 { BLUETOOTH_EVENT_AG_CONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
189 { BLUETOOTH_EVENT_AG_DISCONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
190 { BLUETOOTH_EVENT_AG_SPEAKER_GAIN, BT_EVENT_AG_SPEAKER_GAIN_CHANGE },
191 { BLUETOOTH_EVENT_AG_MIC_GAIN, BT_EVENT_AG_MICROPHONE_GAIN_CHANGE },
192 { BLUETOOTH_EVENT_AG_AUDIO_CONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
193 { BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
194 { BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED, BT_EVENT_AG_SCO_CONNECTION_STATUS },
195 { BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED, BT_EVENT_AG_SCO_CONNECTION_STATUS },
196 { BLUETOOTH_EVENT_TELEPHONY_SET_SPEAKER_GAIN, BT_EVENT_AG_SPEAKER_GAIN_CHANGE },
197 { BLUETOOTH_EVENT_TELEPHONY_SET_MIC_GAIN, BT_EVENT_AG_MICROPHONE_GAIN_CHANGE },
198 { BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL, BT_EVENT_AG_CALL_HANDLING_EVENT },
199 { BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL, BT_EVENT_AG_CALL_HANDLING_EVENT },
200 { BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL, BT_EVENT_AG_CALL_HANDLING_EVENT },
201 { BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL, BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT },
202 { BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL, BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT },
203 { BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL, BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT },
204 { BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL, BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT },
205 { BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER, BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT },
206 { BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF, BT_EVENT_AG_DTMF_TRANSMITTED },
207 { BLUETOOTH_EVENT_AV_CONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
208 { BLUETOOTH_EVENT_AV_DISCONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
209 { BLUETOOTH_EVENT_AV_SOURCE_CONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
210 { BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
211 { BLUETOOTH_EVENT_AVRCP_CONNECTED, BT_EVENT_AVRCP_CONNECTION_STATUS },
212 { BLUETOOTH_EVENT_AVRCP_DISCONNECTED, BT_EVENT_AVRCP_CONNECTION_STATUS },
213 { BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED, BT_EVENT_AVRCP_CONTROL_CONNECTION_STATUS },
214 { BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED, BT_EVENT_AVRCP_CONTROL_CONNECTION_STATUS },
215 { BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS, BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED },
216 { BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS, BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED },
217 { BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS, BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED },
218 { BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS, BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED },
219 { BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS, BT_EVENT_AVRCP_REPEAT_MODE_CHANGED },
220 { BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS, BT_EVENT_AVRCP_REPEAT_MODE_CHANGED },
221 { BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS, BT_EVENT_AVRCP_SCAN_MODE_CHANGED },
222 { BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS, BT_EVENT_AVRCP_SCAN_MODE_CHANGED },
223 { BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS, BT_EVENT_AVRCP_SONG_POSITION_CHANGED },
224 { BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED, BT_EVENT_AVRCP_PLAY_STATUS_CHANGED },
225 { BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED, BT_EVENT_AVRCP_TRACK_INFO_CHANGED },
226 { BLUETOOTH_EVENT_AVRCP_DELAY_CHANGED, BT_EVENT_AVRCP_DELAY_CHANGED },
227 { BLUETOOTH_EVENT_AVRCP_VOLUME_CHANGED, BT_EVENT_AUDIO_ABSOLUTE_VOLUME_CHANGED },
228 { BLUETOOTH_EVENT_AUDIO_AVC_STATUS, BT_EVENT_AUDIO_AVC_STATUS_CHANGED},
229 { BLUETOOTH_HID_CONNECTED, BT_EVENT_HID_CONNECTION_STATUS },
230 { BLUETOOTH_HID_DISCONNECTED, BT_EVENT_HID_CONNECTION_STATUS },
231 { BLUETOOTH_HID_DEVICE_CONNECTED, BT_EVENT_HID_DEVICE_CONNECTION_STATUS },
232 { BLUETOOTH_HID_DEVICE_DISCONNECTED, BT_EVENT_HID_DEVICE_CONNECTION_STATUS },
233 { BLUETOOTH_HID_DEVICE_DATA_RECEIVED, BT_EVENT_HID_DEVICE_DATA_RECEIVED },
234 { BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED, BT_EVENT_GATT_CLIENT_VALUE_CHANGED },
235 { BLUETOOTH_EVENT_GATT_READ_CHAR, BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC },
236 { BLUETOOTH_EVENT_GATT_WRITE_CHAR, BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC },
237 { BLUETOOTH_EVENT_GATT_READ_DESC, BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR },
238 { BLUETOOTH_EVENT_GATT_WRITE_DESC, BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR },
239 { BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED, BT_EVENT_GATT_ATT_MTU_CHANGE_STATUS },
240 { BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED, BT_EVENT_MANUFACTURER_DATA_CHANGED },
241 { BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, BT_EVENT_PASSKEY_NOTIFICATION_EVENT },
242 { BLUETOOTH_EVENT_CONNECTABLE_CHANGED, BT_EVENT_CONNECTABLE_CHANGED_EVENT },
243 { BLUETOOTH_EVENT_TELEPHONY_VENDOR_AT_CMD, BT_EVENT_AG_VENDOR_CMD },
244 { BLUETOOTH_EVENT_TELEPHONY_HF_BATTERY_LEVEL_CHANGED, BT_EVENT_AG_BATTERY_LEVEL_CHANGE },
245 { BLUETOOTH_EVENT_RSSI_ENABLED, BT_EVENT_RSSI_ENABLED_EVENT },
246 { BLUETOOTH_EVENT_RSSI_ALERT, BT_EVENT_RSSI_ALERT_EVENT },
247 { BLUETOOTH_EVENT_RAW_RSSI, BT_EVENT_GET_RSSI_EVENT },
248 { BLUETOOTH_EVENT_IPSP_CONNECTED, BT_EVENT_IPSP_CONNECTION_STATUS },
249 { BLUETOOTH_EVENT_IPSP_DISCONNECTED, BT_EVENT_IPSP_CONNECTION_STATUS },
250 { BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED, BT_EVENT_SUPPORTED_TRUSTED_PROFILE_EVENT },
251 { BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, BT_EVENT_LE_DATA_LENGTH_CHANGED },
252 { BLUETOOTH_PBAP_CONNECTED, BT_EVENT_PBAP_CONNECTION_STATUS },
253 { BLUETOOTH_PBAP_DISCONNECTED, BT_EVENT_PBAP_CONNECTION_STATUS },
254 { BLUETOOTH_PBAP_PHONEBOOK_SIZE, BT_EVENT_PBAP_PHONEBOOK_SIZE },
255 { BLUETOOTH_PBAP_PHONEBOOK_PULL, BT_EVENT_PBAP_PHONEBOOK_PULL },
256 { BLUETOOTH_PBAP_VCARD_LIST, BT_EVENT_PBAP_VCARD_LIST },
257 { BLUETOOTH_PBAP_VCARD_PULL, BT_EVENT_PBAP_VCARD_PULL },
258 { BLUETOOTH_PBAP_PHONEBOOK_SEARCH, BT_EVENT_PBAP_PHONEBOOK_SEARCH },
259 { BLUETOOTH_EVENT_HF_CONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
260 { BLUETOOTH_EVENT_HF_DISCONNECTED, BT_EVENT_AUDIO_CONNECTION_STATUS },
261 { BLUETOOTH_EVENT_HF_AUDIO_CONNECTED, BT_EVENT_HF_SCO_CONNECTION_STATUS },
262 { BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED, BT_EVENT_HF_SCO_CONNECTION_STATUS },
263 { BLUETOOTH_EVENT_HF_RING_INDICATOR, BT_EVENT_HF_REMOTE_CALL_EVENT },
264 { BLUETOOTH_EVENT_HF_CALL_TERMINATED, BT_EVENT_HF_REMOTE_CALL_EVENT },
265 { BLUETOOTH_EVENT_HF_CALL_STARTED, BT_EVENT_HF_REMOTE_CALL_EVENT },
266 { BLUETOOTH_EVENT_HF_CALL_ENDED, BT_EVENT_HF_REMOTE_CALL_EVENT },
267 { BLUETOOTH_EVENT_HF_CALL_WAITING, BT_EVENT_HF_REMOTE_CALL_EVENT },
268 { BLUETOOTH_EVENT_HF_CALL_ON_HOLD, BT_EVENT_HF_REMOTE_CALL_EVENT },
269 { BLUETOOTH_EVENT_HF_CALL_UNHOLD, BT_EVENT_HF_REMOTE_CALL_EVENT },
270 { BLUETOOTH_EVENT_HF_CALL_SWAPPED, BT_EVENT_HF_REMOTE_CALL_EVENT },
271 { BLUETOOTH_EVENT_HF_CALL_FAILED_TO_DIAL, BT_EVENT_HF_REMOTE_CALL_EVENT },
272 { BLUETOOTH_EVENT_HF_CALL_IDLE, BT_EVENT_HF_REMOTE_CALL_EVENT },
273 { BLUETOOTH_EVENT_HF_CALLSETUP_INCOMING, BT_EVENT_HF_REMOTE_CALL_EVENT },
274 { BLUETOOTH_EVENT_HF_CALLSETUP_DIALING, BT_EVENT_HF_REMOTE_CALL_EVENT },
275 { BLUETOOTH_EVENT_HF_CALLSETUP_ALERTING, BT_EVENT_HF_REMOTE_CALL_EVENT },
276 { BLUETOOTH_EVENT_HF_VENDOR_DEP_CMD, BT_EVENT_HF_VENDOR_DEP_CMD_EVENT },
277 { BLUETOOTH_EVENT_HF_VOLUME_SPEAKER, BT_EVENT_HF_SPEAKER_GAIN_CHANGE },
278 { BLUETOOTH_EVENT_HF_CALL_STATUS, BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT },
279 { BLUETOOTH_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED, BT_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED },
280 { BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED, BT_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED },
281 { BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED, BT_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED },
282 { BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED, BT_EVENT_IPSP_INIT_STATE_CHANGED },
283 { BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED, BT_EVENT_PROXIMITY_REPORTER_PROPERTY_CHANGED },
284 { BLUETOOTH_EVENT_TDS_ACTIVATION_REQUESTED, BT_EVENT_TDS_ACTIVATION_REQUESTED },
285 { BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED, BT_EVENT_OTP_SERVER_STATE_CHANGED },
286 { BLUETOOTH_EVENT_MESH_SCAN_STARTED, BT_EVENT_MESH_NETWORK_SCAN_STATE_CHANGED },
287 { BLUETOOTH_EVENT_MESH_SCAN_FINISHED, BT_EVENT_MESH_NETWORK_SCAN_STATE_CHANGED },
288 { BLUETOOTH_EVENT_MESH_SCAN_RESULT, BT_EVENT_MESH_NETWORK_SCAN_STATE_CHANGED },
289 { BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST, BT_EVENT_MESH_AUTHENTICATION_REQUEST },
290 { BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED, BT_EVENT_MESH_NETWORK_PROVISIONING_RESULT },
291 { BLUETOOTH_EVENT_MESH_NODE_BROWSED, BT_EVENT_MESH_NODE_BROWSING_COMPLETED },
292 { BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES, BT_EVENT_MESH_NODE_VENDOR_FEATURES },
293 { BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED, BT_EVENT_MESH_NODE_KEY_CONFIGURATION_COMPLETED },
294 { BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED, BT_EVENT_MESH_NODE_TTL_EXECUTE_COMPLETED },
295 { BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND, BT_EVENT_MESH_NODE_MODEL_BIND_APPKEY_COMPLETED },
296 { BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST, BT_EVENT_MESH_NODE_MODEL_APPKEY_LIST },
297 { BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED, BT_EVENT_MESH_NODE_MODEL_EXECUTE_MSG_COMPLETED },
298 { BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST, BT_EVENT_MESH_NODE_MODEL_SUB_LIST },
299 { BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED, BT_EVENT_MESH_NODE_MODEL_GROUP_SUB },
300 { BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED, BT_EVENT_MESH_NODE_MODEL_GROUP_VIR_SUB },
301 { BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS, BT_EVENT_MESH_NODE_MODEL_PUBLICATION },
305 static bt_feature_table_t feature_table[] = {
306 {"tizen.org/feature/network.bluetooth", FALSE, FALSE}, /* BT_FEATURE_COMMON */
307 {"tizen.org/feature/network.bluetooth.le", FALSE, FALSE}, /* BT_FEATURE_LE */
308 {"tizen.org/feature/network.bluetooth.le.5_0", FALSE, FALSE}, /* BT_FEATURE_LE_5_0 */
309 {"tizen.org/feature/network.bluetooth.le.ipsp", FALSE, FALSE}, /* BT_FEATURE_IPSP */
310 {"tizen.org/feature/network.bluetooth.le.mesh", TRUE, TRUE}, /* BT_FEATURE_MESH */
311 {"tizen.org/feature/network.bluetooth.audio.call", FALSE, FALSE}, /* BT_FEATURE_AUDIO_CALL */
312 {"tizen.org/feature/network.bluetooth.audio.media", FALSE, FALSE}, /* BT_FEATURE_AUDIO_MEDIA */
313 {"tizen.org/feature/network.bluetooth.audio.controller", FALSE, FALSE}, /* BT_FEATURE_AUDIO_CONTROLLER */
314 {"tizen.org/feature/network.bluetooth.health", FALSE, FALSE}, /* BT_FEATURE_HEALTH */
315 {"tizen.org/feature/network.bluetooth.hid", FALSE, FALSE}, /* BT_FEATURE_HID_HOST */
316 {"tizen.org/feature/network.bluetooth.hid_device", FALSE, FALSE}, /* BT_FEATURE_HID_DEVICE */
317 {"tizen.org/feature/network.bluetooth.opp", FALSE, FALSE}, /* BT_FEATURE_OPP */
318 {"tizen.org/feature/network.bluetooth.map", FALSE, FALSE}, /* BT_FEATURE_MAP */
319 {"tizen.org/feature/network.tethering.bluetooth", FALSE, FALSE}, /* BT_FEATURE_TETHERING */
320 {"tizen.org/feature/network.bluetooth.phonebook.client", FALSE, FALSE}, /* BT_FEATURE_PBAP_CLIENT */
321 {"tizen.org/feature/network.bluetooth.oob", FALSE, FALSE}, /* BT_FEATURE_OOB */
322 {"tizen.org/feature/network.bluetooth.le.gatt.server", FALSE, FALSE}, /* BT_FEATURE_GATT_SERVER */
323 {"tizen.org/feature/network.bluetooth.le.gatt.client", FALSE, FALSE} /* BT_FEATURE_GATT_CLIENT */
329 static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *user_data);
330 static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void *user_data);
331 static int __bt_get_cb_index(int event);
332 static void __bt_convert_lower_to_upper(char *origin);
333 static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_info_t *source, int error);
334 static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info);
335 static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **dest, bt_connection_info_t *source);
336 static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info);
337 static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info);
338 static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info);
339 static int __bt_get_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s **scan_info, bluetooth_le_device_info_t *source_info);
340 static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s *scan_info);
342 /* TDS Forward declarations */
343 static void __bt_free_tds_scan_result_info_s(bt_tds_transport_block_list_s *discovery_info);
349 int bt_initialize(void)
353 BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
354 if (is_initialized != true) {
355 ret = bluetooth_register_callback(&__bt_event_proxy, NULL);
356 if (ret != BLUETOOTH_ERROR_NONE && ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
357 BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); /* LCOV_EXCL_LINE */
358 #ifdef TIZEN_FEATURE_TCT_TMP_SUPPORT
359 return BT_ERROR_NONE; /* LCOV_EXCL_LINE */
361 return BT_ERROR_OPERATION_FAILED; /* LCOV_EXCL_LINE */
364 is_initialized = true;
366 return BT_ERROR_NONE;
369 int bt_deinitialize(void)
371 BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
372 BT_CHECK_INIT_STATUS();
373 if (bluetooth_unregister_callback() != BLUETOOTH_ERROR_NONE) {
374 BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); /* LCOV_EXCL_LINE */
375 #ifdef TIZEN_FEATURE_TCT_TMP_SUPPORT
376 return BT_ERROR_NONE; /* LCOV_EXCL_LINE */
378 return BT_ERROR_OPERATION_FAILED; /* LCOV_EXCL_LINE */
381 is_initialized = false;
383 return BT_ERROR_NONE;
386 int bt_get_uuid_name(const char *uuid, char **name)
388 BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
389 BT_CHECK_INPUT_PARAMETER(uuid);
390 BT_CHECK_INPUT_PARAMETER(name);
392 return _bt_get_error_code(bluetooth_get_uuid_name(uuid, name));
398 int _bt_check_supported_feature(bt_feature_t feature, bool *supported)
402 if (feature < BT_FEATURE_BASE || feature >= BT_FEATURE_MAX) {
403 BT_ERR("Invalid parameter. feature [%d]", feature);
404 return BT_ERROR_INVALID_PARAMETER;
407 if (TRUE == feature_table[feature].is_check) {
408 *supported = feature_table[feature].value;
409 return BT_ERROR_NONE;
412 ret = system_info_get_platform_bool(feature_table[feature].name, supported);
413 if (SYSTEM_INFO_ERROR_NONE != ret) {
414 BT_ERR("fail to get %s", feature_table[feature].name);
415 return BT_ERROR_OPERATION_FAILED;
418 feature_table[feature].is_check = TRUE;
419 feature_table[feature].value = *supported;
421 return BT_ERROR_NONE;
424 int _bt_check_init_status(void)
426 if (is_initialized != true) {
427 BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED);
428 return BT_ERROR_NOT_INITIALIZED;
431 return BT_ERROR_NONE;
434 void _bt_set_cb(int events, void *callback, void *user_data)
436 bt_event_slot_container[events].callback = callback;
437 bt_event_slot_container[events].user_data = user_data;
440 void _bt_unset_cb(int events)
442 if (bt_event_slot_container[events].callback != NULL) {
443 bt_event_slot_container[events].callback = NULL;
444 bt_event_slot_container[events].user_data = NULL;
448 bool _bt_check_cb(int events)
450 return (bt_event_slot_container[events].callback != NULL) ? true : false;
453 int _bt_le_adapter_init(void)
455 if (is_le_initialized)
456 return BT_ERROR_NONE;
458 if (bluetooth_le_register_callback(&__bt_le_event_proxy, NULL) != BLUETOOTH_ERROR_NONE) {
459 BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); /* LCOV_EXCL_LINE */
460 return BT_ERROR_OPERATION_FAILED; /* LCOV_EXCL_LINE */
462 is_le_initialized = true;
464 return BT_ERROR_NONE;
467 /* LCOV_EXCL_START */
468 int _bt_le_adapter_deinit(void)
470 if (!is_le_initialized) {
471 BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED);
472 return BT_ERROR_NOT_INITIALIZED;
475 if (!_bt_check_cb(BT_EVENT_LE_STATE_CHANGED)) {
476 if (bluetooth_le_unregister_callback() != BLUETOOTH_ERROR_NONE) {
477 BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED);
478 return BT_ERROR_OPERATION_FAILED;
480 is_le_initialized = false;
483 return BT_ERROR_NONE;
487 int _bt_get_error_code(int origin_error)
491 for (i = 0; err2pub[i].origin_err != 0xFF; i++) {
492 if (err2pub[i].origin_err == origin_error)
493 return err2pub[i].public_err;
496 return BT_ERROR_OPERATION_FAILED; /* LCOV_EXCL_LINE */
499 int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_t *source_dev)
503 BT_CHECK_INPUT_PARAMETER(source_dev);
505 *dest_dev = (bt_device_info_s *)malloc(sizeof(bt_device_info_s));
506 if (*dest_dev == NULL)
507 return BT_ERROR_OUT_OF_MEMORY;
509 if (strlen(source_dev->device_name.name) > 0)
510 (*dest_dev)->remote_name = strdup(source_dev->device_name.name);
512 (*dest_dev)->remote_name = NULL;
514 _bt_convert_address_to_string(&((*dest_dev)->remote_address), &(source_dev->device_address));
516 (*dest_dev)->bt_class.major_device_class = source_dev->device_class.major_class;
517 (*dest_dev)->bt_class.minor_device_class = source_dev->device_class.minor_class;
518 (*dest_dev)->bt_class.major_service_class_mask = source_dev->device_class.service_class;
519 if (source_dev->service_index > 0) {
520 (*dest_dev)->service_uuid = (char **)malloc(sizeof(char *) *source_dev->service_index);
521 if ((*dest_dev)->service_uuid != NULL) {
522 for (i = 0; i < source_dev->service_index; i++) {
523 (*dest_dev)->service_uuid[i] =
524 g_strndup(source_dev->uuids[i],
525 BLUETOOTH_UUID_STRING_MAX - 1);
526 if ((*dest_dev)->service_uuid[i] != NULL)
527 __bt_convert_lower_to_upper((*dest_dev)->service_uuid[i]);
531 (*dest_dev)->service_uuid = NULL;
533 (*dest_dev)->service_count = source_dev->service_index;
534 (*dest_dev)->is_bonded = (bool)source_dev->paired;
535 (*dest_dev)->is_connected = source_dev->connected != BLUETOOTH_CONNECTED_LINK_NONE ? TRUE : FALSE;
536 (*dest_dev)->is_authorized = (bool)source_dev->trust;
538 (*dest_dev)->manufacturer_data_len = source_dev->manufacturer_data.data_len;
539 if (source_dev->manufacturer_data.data_len > 0) {
540 (*dest_dev)->manufacturer_data = (char *)malloc(source_dev->manufacturer_data.data_len);
541 if ((*dest_dev)->manufacturer_data)
542 memcpy((*dest_dev)->manufacturer_data, source_dev->manufacturer_data.data,
543 source_dev->manufacturer_data.data_len);
545 return BT_ERROR_OUT_OF_MEMORY;
547 (*dest_dev)->manufacturer_data = (char *)malloc(1);
548 if ((*dest_dev)->manufacturer_data)
549 (*dest_dev)->manufacturer_data[0] = 0;
551 return BT_ERROR_OUT_OF_MEMORY;
554 return BT_ERROR_NONE;
557 void _bt_free_bt_device_info_s(bt_device_info_s *device_info)
561 if (device_info == NULL)
564 if (device_info->remote_name != NULL)
565 free(device_info->remote_name);
567 if (device_info->remote_address != NULL)
568 free(device_info->remote_address);
570 if (device_info->service_uuid != NULL) {
571 for (i = 0; i < device_info->service_count; i++) {
572 if (device_info->service_uuid[i] != NULL)
573 g_free(device_info->service_uuid[i]);
575 free(device_info->service_uuid);
578 if (device_info->manufacturer_data != NULL)
579 free(device_info->manufacturer_data);
585 /* LCOV_EXCL_START */
586 int _bt_get_ad_data_by_type(char *in_data, int in_len,
587 char in_type, char **data, int *data_len)
589 if (in_data == NULL || data == NULL || data_len == NULL)
590 return BLUETOOTH_ERROR_INTERNAL;
593 return BLUETOOTH_ERROR_INTERNAL;
599 for (i = 0; i < in_len; i++) {
601 if (len <= 0 || i + 1 >= in_len) {
602 BT_ERR("Invalid advertising data");
603 return BLUETOOTH_ERROR_INTERNAL;
606 type = in_data[i + 1];
607 if (type == in_type) {
617 if (i + len > in_len) {
618 BT_ERR("Invalid advertising data");
619 return BLUETOOTH_ERROR_INTERNAL;
620 } else if (len == 0) {
621 BT_DBG("AD Type 0x%02x data is not set", in_type);
624 return BLUETOOTH_ERROR_NONE;
627 *data = g_memdup(&in_data[i], len);
629 return BLUETOOTH_ERROR_OUT_OF_MEMORY;
632 return BLUETOOTH_ERROR_NONE;
635 int _bt_get_link_loss_rssi(void)
641 int _bt_convert_address_to_string(char **addr_str, bluetooth_device_address_t *addr_hex)
643 char address[18] = { 0, };
645 BT_CHECK_INPUT_PARAMETER(addr_hex);
647 snprintf(address, 18, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", addr_hex->addr[0], addr_hex->addr[1], addr_hex->addr[2], addr_hex->addr[3], addr_hex->addr[4], addr_hex->addr[5]);
648 *addr_str = strdup(address);
650 if (*addr_str != NULL)
651 return BT_ERROR_NONE;
653 return BT_ERROR_OUT_OF_MEMORY; /* LCOV_EXCL_LINE */
656 void _bt_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char *addr_str)
658 char *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
660 if (addr_str == NULL || strlen(addr_str) != 17) {
661 BT_ERR("Invalid address string: %s", addr_str);
665 if (addr_str[2] != ':' || addr_str[5] != ':' ||
666 addr_str[8] != ':' || addr_str[11] != ':' ||
667 addr_str[14] != ':' || addr_str[17] != '\0') {
668 BT_ERR("Invalid MAC format");
672 addr_hex->addr[0] = strtol(addr_str, &ptr5, 16);
673 addr_hex->addr[1] = strtol(ptr5 + 1, &ptr4, 16);
674 addr_hex->addr[2] = strtol(ptr4 + 1, &ptr3, 16);
675 addr_hex->addr[3] = strtol(ptr3 + 1, &ptr2, 16);
676 addr_hex->addr[4] = strtol(ptr2 + 1, &ptr1, 16);
677 addr_hex->addr[5] = strtol(ptr1 + 1, NULL, 16);
680 char *_bt_convert_error_to_string(int error)
684 for (i = 0; err2str[i].err != 0; i++) {
685 if (err2str[i].err == error)
686 return err2str[i].str;
689 return "UNKNOWN"; /* LCOV_EXCL_LINE */
692 /* LCOV_EXCL_START */
693 bool _bt_get_random_bytes(void *buf, size_t num_bytes)
698 fd = open("/dev/urandom", O_RDONLY);
702 len = read(fd, buf, num_bytes);
713 /* LCOV_EXCL_START */
714 char *_bt_convert_uuid_to_uuid128(const char *uuid)
722 case 4: /* UUID 16bits */
723 uuid128 = g_strdup_printf("0000%s-0000-1000-8000-00805f9b34fb", uuid);
726 case 8: /* UUID 32bits */
727 uuid128 = g_strdup_printf("%s-0000-1000-8000-00805f9b34fb", uuid); /* LCOV_EXCL_LINE */
728 break; /* LCOV_EXCL_LINE */
730 case 36: /* UUID 128bits */
731 uuid128 = strdup(uuid); /* LCOV_EXCL_LINE */
732 break; /* LCOV_EXCL_LINE */
742 bt_adapter_visibility_mode_e _bt_get_bt_visibility_mode_e(bluetooth_discoverable_mode_t mode)
745 case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE:
746 return BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE;
747 case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE:
748 return BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE; /* LCOV_EXCL_LINE */
750 return BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
758 /* LCOV_EXCL_START */
759 static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_info_t *source, int error)
763 *dest = (bt_device_sdp_info_s *)g_malloc0(sizeof(bt_device_sdp_info_s));
765 if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) {
766 __bt_free_bt_device_sdp_info_s(*dest);
767 return BT_ERROR_OUT_OF_MEMORY;
769 if (error != BT_ERROR_NONE) {
770 BT_DBG("In error case, ignore other fields of service search");
771 return BT_ERROR_NONE;
774 if (source->service_index > 0) {
775 (*dest)->service_uuid = (char **)malloc(sizeof(char *) *source->service_index);
776 if ((*dest)->service_uuid == NULL) {
777 __bt_free_bt_device_sdp_info_s(*dest);
778 return BT_ERROR_OUT_OF_MEMORY;
781 for (i = 0; i < source->service_index; i++) {
782 (*dest)->service_uuid[i] = strdup(source->uuids[i]);
783 if ((*dest)->service_uuid[i] == NULL) {
784 __bt_free_bt_device_sdp_info_s(*dest);
785 return BT_ERROR_OUT_OF_MEMORY;
787 __bt_convert_lower_to_upper((*dest)->service_uuid[i]);
790 (*dest)->service_uuid = NULL;
792 (*dest)->service_count = source->service_index;
794 return BT_ERROR_NONE;
797 static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info)
801 if (sdp_info == NULL)
804 if (sdp_info->remote_address != NULL)
805 free(sdp_info->remote_address);
807 if (sdp_info->service_uuid != NULL) {
808 for (i = 0; i < sdp_info->service_count; i++) {
809 if (sdp_info->service_uuid[i] != NULL)
810 free(sdp_info->service_uuid[i]);
812 free(sdp_info->service_uuid);
819 static int __bt_get_bt_gatt_client_att_mtu_info_s(bt_gatt_client_att_mtu_info_s **dest, bluetooth_le_att_mtu_info_t *source)
821 BT_CHECK_INPUT_PARAMETER(source);
823 *dest = (bt_gatt_client_att_mtu_info_s *)g_malloc0(sizeof(bt_gatt_client_att_mtu_info_s));
825 if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_address)) != BT_ERROR_NONE) {
829 return BT_ERROR_OUT_OF_MEMORY;
832 (*dest)->mtu = source->mtu;
833 (*dest)->status = source->status;
835 return BT_ERROR_NONE;
838 static int __bt_get_bt_gatt_server_att_mtu_info_s(bt_gatt_server_att_mtu_info_s **dest, bluetooth_le_att_mtu_info_t *source)
840 BT_CHECK_INPUT_PARAMETER(source);
842 *dest = (bt_gatt_server_att_mtu_info_s *)g_malloc0(sizeof(bt_gatt_server_att_mtu_info_s));
844 if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_address)) != BT_ERROR_NONE) {
848 return BT_ERROR_OUT_OF_MEMORY;
851 (*dest)->mtu = source->mtu;
852 (*dest)->status = source->status;
854 return BT_ERROR_NONE;
857 static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **dest, bt_connection_info_t *source)
859 *dest = (bt_device_connection_info_s *)g_malloc0(sizeof(bt_device_connection_info_s));
861 if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) {
862 __bt_free_bt_device_connection_info_s(*dest);
863 return BT_ERROR_OUT_OF_MEMORY;
866 switch (source->addr_type) {
868 (*dest)->link = BT_DEVICE_CONNECTION_LINK_BREDR;
872 (*dest)->link = BT_DEVICE_CONNECTION_LINK_LE;
875 (*dest)->link = BT_DEVICE_CONNECTION_LINK_BREDR;
879 BT_INFO("Disconnect reason from FRWK[0x%x]", source->disc_reason);
881 switch (source->disc_reason) {
882 /* After ACR for BT_DEVICE_DISCONNECT_REASON_AUTH_FAILED, will enable this code */
884 case (int)BLUETOOTH_ERROR_AUTH_FAILURE:
885 (*dest)->disconn_reason = BT_DEVICE_DISCONNECT_REASON_AUTH_FAILED;
888 case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
889 BT_INFO("Disconnected due to Timeout");
890 (*dest)->disconn_reason = BT_DEVICE_DISCONNECT_REASON_TIMEOUT;
892 case (int)BLUETOOTH_ERROR_REMOTE_USER_TERM:
893 case (int)BLUETOOTH_ERROR_REMOTE_LOW_RESOURCES:
894 case (int)BLUETOOTH_ERROR_REMOTE_POWER_OFF:
895 (*dest)->disconn_reason = BT_DEVICE_DISCONNECT_REASON_REMOTE;
897 case (int)BLUETOOTH_ERROR_LOCAL_HOST_TERM:
898 (*dest)->disconn_reason = BT_DEVICE_DISCONNECT_REASON_LOCAL_HOST;
901 (*dest)->disconn_reason = BT_DEVICE_DISCONNECT_REASON_UNKNOWN;
904 BT_INFO("Disconnected reason to app [0x%x]", (*dest)->disconn_reason);
906 dbfw_rssi = source->rssi;
908 return BT_ERROR_NONE;
911 #ifdef TIZEN_FEATURE_GATT_RELAY
912 /* Search for handle */
913 static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(int att_handle, bt_gatt_server_h *server,
914 bt_gatt_h *gatt_handle, bool *is_own_handle, void **user_data)
916 const GSList *gatt_server_list = NULL;
917 const GSList *l1, *l2, *l3, *l4;
919 gatt_server_list = _bt_gatt_get_server_list();
921 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
922 bt_gatt_server_s *serv = l1->data;
927 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
928 bt_gatt_service_s *svc = l2->data;
930 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
931 bt_gatt_characteristic_s *chr = l3->data;
934 if (chr->handle == att_handle) {
935 if (chr->read_requested_cb) {
936 BT_DBG("GATT Server: char handle found [%s]", chr->uuid);
937 *user_data = chr->read_requested_user_data;
940 *is_own_handle = true;
941 return chr->read_requested_cb;
945 for (l4 = chr->descriptors; l4 != NULL; l4 = l4->next) {
946 bt_gatt_descriptor_s *desc = l4->data;
948 if (desc && desc->handle == att_handle) {
949 if (desc->read_requested_cb) {
950 *user_data = desc->read_requested_user_data;
953 *is_own_handle = true;
954 BT_DBG("GATT Server: desc handle found [%s]", desc->uuid);
955 return desc->read_requested_cb;
968 static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_change_cb(int att_handle, bt_gatt_h *server,
969 bt_gatt_h *gatt_handle, bool *is_own_handle, void **user_data)
971 const GSList *gatt_server_list = NULL;
972 const GSList *l1, *l2, *l3, *l4;
974 gatt_server_list = _bt_gatt_get_server_list();
976 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
977 bt_gatt_server_s *serv = l1->data;
982 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
983 bt_gatt_service_s *svc = l2->data;
985 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
986 bt_gatt_characteristic_s *chr = l3->data;
989 if (chr->handle == att_handle) {
990 if (chr->write_value_requested_cb) {
991 BT_DBG("GATT Server: char handle found [%s]", chr->uuid);
992 *user_data = chr->write_value_requested_user_data;
995 *is_own_handle = true;
996 return chr->write_value_requested_cb;
1000 for (l4 = chr->descriptors; l4 != NULL; l4 = l4->next) {
1001 bt_gatt_descriptor_s *desc = l4->data;
1003 if (desc && desc->handle == att_handle) {
1004 if (desc->write_value_requested_cb) {
1005 *user_data = desc->write_value_requested_user_data;
1006 *gatt_handle = desc;
1008 *is_own_handle = true;
1009 BT_DBG("GATT Server: desc handle found [%s]", desc->uuid);
1010 return desc->write_value_requested_cb;
1023 static bt_gatt_server_characteristic_notification_state_changed_cb
1024 __bt_gatt_attribute_get_notification_change_cb(
1025 bt_gatt_server_h *server, int handle, bt_gatt_h *char_handle, void **user_data)
1027 const GSList *gatt_server_list = NULL;
1028 const GSList *l1, *l2, *l3;
1030 gatt_server_list = _bt_gatt_get_server_list();
1032 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
1033 bt_gatt_server_s *serv = l1->data;
1038 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
1039 bt_gatt_service_s *svc = l2->data;
1041 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
1042 bt_gatt_characteristic_s *chr = l3->data;
1044 if (chr && chr->handle == handle) {
1045 if (chr->notification_changed_cb) {
1046 *user_data = chr->notification_changed_user_data;
1047 *char_handle = (bt_gatt_h*) chr;
1049 return chr->notification_changed_cb;
1059 static bt_gatt_server_notification_sent_cb __bt_gatt_attribute_get_notification_completed_cb(
1060 bt_gatt_server_h *server, int handle, bt_gatt_h *char_handle, void **user_data)
1062 const GSList *gatt_server_list = NULL;
1063 const GSList *l1, *l2, *l3;
1065 gatt_server_list = _bt_gatt_get_server_list();
1067 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
1068 bt_gatt_server_s *serv = l1->data;
1073 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
1074 bt_gatt_service_s *svc = l2->data;
1076 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
1077 bt_gatt_characteristic_s *chr = l3->data;
1079 if (chr && chr->handle == handle) {
1080 if (chr->notified_cb) {
1081 *user_data = chr->notified_user_data;
1082 *char_handle = (bt_gatt_h*) chr;
1084 return chr->notified_cb;
1094 void _bt_gatt_server_event_proxy(int event, gatt_server_event_param_t *param, void *user_data)
1096 bluetooth_event_param_t new_param;
1097 new_param.event = param->event;
1098 new_param.param_data = param->param_data;
1099 new_param.result = param->result;
1100 new_param.user_data = NULL;
1101 __bt_event_proxy(event, &new_param, user_data);
1104 static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(
1105 bt_gatt_h service, bt_gatt_h attribute, bt_gatt_h *gatt_handle, void **user_data)
1107 gchar *svc_path = (gchar *)service;
1108 gchar *att_path = (gchar *)attribute;
1109 const GSList *gatt_server_list = NULL;
1110 const GSList *l1, *l2, *l3, *l4;
1112 gatt_server_list = _bt_gatt_get_server_list();
1114 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
1115 bt_gatt_server_s *serv = l1->data;
1120 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
1121 bt_gatt_service_s *svc = l2->data;
1126 if (g_strcmp0(svc->path, svc_path) == 0) {
1127 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
1128 bt_gatt_characteristic_s *chr = l3->data;
1131 if (g_strcmp0(chr->path, att_path) == 0) {
1132 if (chr->read_requested_cb) {
1133 *user_data = chr->read_requested_user_data;
1135 return chr->read_requested_cb;
1139 for (l4 = chr->descriptors; l4 != NULL; l4 = l4->next) {
1140 bt_gatt_descriptor_s *desc = l4->data;
1142 if (desc && g_strcmp0(desc->path, att_path) == 0) {
1143 if (desc->read_requested_cb) {
1144 *user_data = desc->read_requested_user_data;
1145 *gatt_handle = desc;
1146 return desc->read_requested_cb;
1161 static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_change_cb(
1162 bt_gatt_h service, bt_gatt_h attribute, bt_gatt_h *gatt_handle, void **user_data)
1164 gchar *svc_path = (gchar *)service;
1165 gchar *att_path = (gchar *)attribute;
1166 const GSList *gatt_server_list = NULL;
1167 const GSList *l1, *l2, *l3, *l4;
1169 gatt_server_list = _bt_gatt_get_server_list();
1171 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
1172 bt_gatt_server_s *serv = l1->data;
1177 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
1178 bt_gatt_service_s *svc = l2->data;
1183 if (g_strcmp0(svc->path, svc_path) == 0) {
1184 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
1185 bt_gatt_characteristic_s *chr = l3->data;
1188 if (g_strcmp0(chr->path, att_path) == 0) {
1189 if (chr->write_value_requested_cb) {
1190 *user_data = chr->write_value_requested_user_data;
1192 return chr->write_value_requested_cb;
1196 for (l4 = chr->descriptors; l4 != NULL; l4 = l4->next) {
1197 bt_gatt_descriptor_s *desc = l4->data;
1199 if (desc && g_strcmp0(desc->path, att_path) == 0) {
1200 if (desc->write_value_requested_cb) {
1201 *user_data = desc->write_value_requested_user_data;
1202 *gatt_handle = desc;
1203 return desc->write_value_requested_cb;
1217 static bt_gatt_server_characteristic_notification_state_changed_cb
1218 __bt_gatt_attribute_get_notification_change_cb(
1219 bt_gatt_h service, bt_gatt_h attribute, bt_gatt_h *gatt_handle, void **user_data)
1221 gchar *svc_path = (gchar *)service;
1222 gchar *att_path = (gchar *)attribute;
1223 const GSList *gatt_server_list = NULL;
1224 const GSList *l1, *l2, *l3;
1226 gatt_server_list = _bt_gatt_get_server_list();
1228 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
1229 bt_gatt_server_s *serv = l1->data;
1234 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
1235 bt_gatt_service_s *svc = l2->data;
1237 if (g_strcmp0(svc->path, svc_path) == 0) {
1238 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
1239 bt_gatt_characteristic_s *chr = l3->data;
1241 if (chr && g_strcmp0(chr->path, att_path) == 0) {
1242 if (chr->notification_changed_cb) {
1243 *user_data = chr->notification_changed_user_data;
1245 return chr->notification_changed_cb;
1256 static bt_gatt_server_notification_sent_cb __bt_gatt_attribute_get_notification_completed_cb(
1257 bt_gatt_h service, bt_gatt_h attribute, void **user_data)
1259 gchar *svc_path = (gchar *)service;
1260 gchar *att_path = (gchar *)attribute;
1261 const GSList *gatt_server_list = NULL;
1262 const GSList *l1, *l2, *l3;
1264 gatt_server_list = _bt_gatt_get_server_list();
1266 for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
1267 bt_gatt_server_s *serv = l1->data;
1272 for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
1273 bt_gatt_service_s *svc = l2->data;
1275 if (g_strcmp0(svc->path, svc_path) == 0) {
1276 for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
1277 bt_gatt_characteristic_s *chr = l3->data;
1279 if (chr && g_strcmp0(chr->path, att_path) == 0) {
1280 if (chr->notified_cb) {
1281 *user_data = chr->notified_user_data;
1282 return chr->notified_cb;
1294 void _bt_mesh_event_proxy(int event, mesh_event_param_t *param, void *user_data)
1298 bluetooth_event_param_t new_param;
1299 new_param.event = param->event;
1300 new_param.param_data = param->param_data;
1301 new_param.result = param->result;
1302 new_param.user_data = NULL;
1303 __bt_event_proxy(event, &new_param, user_data);
1306 static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info)
1308 if (conn_info == NULL)
1311 if (conn_info->remote_address != NULL)
1312 free(conn_info->remote_address);
1318 void _bt_audio_event_proxy(int event, bt_audio_event_param_t *param, void *user_data)
1320 bluetooth_event_param_t new_param;
1321 new_param.event = param->event;
1322 new_param.param_data = param->param_data;
1323 new_param.result = param->result;
1324 new_param.user_data = NULL;
1325 __bt_event_proxy(event, &new_param, user_data);
1328 void _bt_hf_event_proxy(int event, bt_hf_event_param_t *param, void *user_data)
1330 bluetooth_event_param_t new_param;
1331 new_param.event = param->event;
1332 new_param.param_data = param->param_data;
1333 new_param.result = param->result;
1334 new_param.user_data = NULL;
1335 __bt_event_proxy(event, &new_param, user_data);
1338 void _bt_telephony_event_proxy(int event, telephony_event_param_t *param, void *user_data)
1340 bluetooth_event_param_t new_param;
1341 new_param.event = param->event;
1342 new_param.param_data = param->param_data;
1343 new_param.result = param->result;
1344 new_param.user_data = NULL;
1345 __bt_event_proxy(event, &new_param, user_data);
1348 void _bt_avrcp_event_proxy(int event, media_event_param_t *param, void *user_data)
1350 bluetooth_event_param_t new_param;
1351 new_param.event = param->event;
1352 new_param.param_data = param->param_data;
1353 new_param.result = param->result;
1354 new_param.user_data = param->user_data;
1355 __bt_event_proxy(event, &new_param, user_data);
1358 void _bt_hid_event_proxy(int event, hid_event_param_t *param, void *user_data)
1360 bluetooth_event_param_t new_param;
1361 new_param.event = param->event;
1362 new_param.param_data = param->param_data;
1363 new_param.result = param->result;
1364 new_param.user_data = param->user_data;
1365 __bt_event_proxy(event, &new_param, user_data);
1368 #ifdef TIZEN_GATT_CLIENT
1369 void _bt_gatt_client_event_proxy(int event,
1370 gatt_client_event_param_t *param, void *user_data)
1372 bluetooth_event_param_t new_param;
1373 new_param.event = param->event;
1374 new_param.param_data = param->param_data;
1375 new_param.result = param->result;
1376 new_param.user_data = NULL;
1377 __bt_event_proxy(event, &new_param, user_data);
1381 /* LCOV_EXCL_STOP */
1383 static bool __bt_need_to_handle(int event)
1385 int event_index = -1;
1388 case BLUETOOTH_EVENT_ADVERTISING_STARTED:
1389 case BLUETOOTH_EVENT_ADVERTISING_STOPPED:
1390 #ifdef TIZEN_GATT_CLIENT
1391 case BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED:
1392 case BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED:
1393 case BLUETOOTH_EVENT_GATT_SERVER_CONNECTED:
1394 case BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED:
1396 case BLUETOOTH_EVENT_GATT_CONNECTED:
1397 case BLUETOOTH_EVENT_GATT_DISCONNECTED:
1399 case BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED:
1400 case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED:
1401 case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED:
1402 case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED:
1403 case BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED:
1404 case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED:
1405 case BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED:
1406 case BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT:
1407 case BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED:
1408 case BLUETOOTH_EVENT_TDS_ACTIVATION_INDICATION:
1409 case BLUETOOTH_EVENT_OTP_READ_CHAR_VAL:
1410 case BLUETOOTH_EVENT_OTP_NOTIFICATION_ENABLED:
1411 case BLUETOOTH_EVENT_OTP_WRITE_CHAR_VAL:
1412 case BLUETOOTH_EVENT_OTP_INDICATION:
1413 case BLUETOOTH_EVENT_OTC_STATE_CHANGED:
1414 case BLUETOOTH_EVENT_GATT_READ_CHAR:
1415 case BLUETOOTH_EVENT_GATT_WRITE_CHAR:
1416 case BLUETOOTH_EVENT_GATT_READ_DESC:
1417 case BLUETOOTH_EVENT_GATT_WRITE_DESC:
1419 case BLUETOOTH_EVENT_MESH_SCAN_STARTED:
1420 case BLUETOOTH_EVENT_MESH_SCAN_FINISHED:
1421 case BLUETOOTH_EVENT_MESH_SCAN_RESULT:
1422 case BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST:
1423 case BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED:
1424 case BLUETOOTH_EVENT_MESH_NODE_BROWSED:
1425 case BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES:
1426 case BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED:
1427 case BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED:
1428 case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST:
1429 case BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST:
1430 case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND:
1431 case BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED:
1432 case BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED:
1433 case BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS:
1434 case BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED:
1440 event_index = __bt_get_cb_index(event);
1441 if (event_index != -1 && bt_event_slot_container[event_index].callback)
1447 static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *user_data)
1451 int *discoverable_timeout;
1454 bluetooth_rfcomm_connection_t *connection_ind = NULL;
1455 bluetooth_rfcomm_disconnection_t *disconnection_ind = NULL;
1456 bt_socket_connection_s rfcomm_connection;
1457 bt_device_sdp_info_s *sdp_info = NULL;
1458 bt_device_connection_info_s *conn_info = NULL;
1459 bt_adapter_device_discovery_info_s *discovery_info = NULL;
1460 bt_device_info_s *bonded_device = NULL;
1461 bluetooth_rfcomm_connection_request_t *reqeust_ind = NULL;
1462 bt_obex_server_authorize_into_t *auth_info = NULL;
1463 bt_obex_server_transfer_info_t *transfer_info = NULL;
1464 bt_opc_transfer_info_t *client_info = NULL;
1465 bluetooth_device_address_t *bd_addr = NULL;
1466 telephony_event_callid_t *call_data = NULL;
1467 char *device_addr = NULL;
1468 char *phone_number = NULL;
1469 int error_code = BT_ERROR_NONE;
1470 int event_index = -1;
1471 bluetooth_network_device_info_t *dev_info = NULL;
1472 bt_hdp_connected_t *hdp_conn_info = NULL;
1473 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
1474 bt_hdp_data_ind_t *hdp_data_ind = NULL;
1475 bt_gatt_char_value_t *char_val = NULL;
1476 media_metadata_attributes_t *metadata = NULL;
1477 bluetooth_authentication_request_info_t *auth_information = NULL;
1478 bt_le_data_length_params_t *data_length_info = NULL;
1479 bt_ipsp_connection_info_t *bt_ipsp_iface_info = NULL;
1480 bt_pxp_property_changed_params_t *bt_pxp_property_info = NULL;
1481 bluetooth_tds_activation_req_t *tds_act_req_info = NULL;
1483 #ifdef TIZEN_GATT_CLIENT
1484 bt_gatt_char_property_t *char_prop = NULL;
1486 if (!__bt_need_to_handle(event))
1489 event_index = __bt_get_cb_index(event);
1492 case BLUETOOTH_EVENT_ENABLED:
1493 BT_INFO("bt_adapter_state_changed_cb() will be called with BT_ADAPTER_ENABLED"); /* LCOV_EXCL_LINE */
1494 ((bt_adapter_state_changed_cb) bt_event_slot_container[event_index].callback)
1495 (_bt_get_error_code(param->result), BT_ADAPTER_ENABLED, bt_event_slot_container[event_index].user_data);
1497 case BLUETOOTH_EVENT_DISABLED:
1498 BT_INFO("bt_adapter_state_changed_cb() will be called with BT_ADAPTER_DISABLED");
1499 ((bt_adapter_state_changed_cb) bt_event_slot_container[event_index].callback)
1500 (_bt_get_error_code(param->result), BT_ADAPTER_DISABLED, bt_event_slot_container[event_index].user_data);
1502 case BLUETOOTH_EVENT_DISABLED_BATTERY_DATA:
1503 BT_INFO("bt_adapter_disable_battery_cb() will be called");
1504 ((bt_adapter_disable_battery_cb)bt_event_slot_container[event_index].callback)((bt_battery_info_s *)(param->param_data));
1506 case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
1507 BT_INFO("bt_adapter_name_changed_cb() will be called");
1508 ((bt_adapter_name_changed_cb)bt_event_slot_container[event_index].callback)
1509 ((char *)(param->param_data), bt_event_slot_container[event_index].user_data);
1511 /* LCOV_EXCL_START */
1512 case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
1513 BT_INFO("bt_adapter_visibility_mode_changed_cb() will be called");
1514 ((bt_adapter_visibility_mode_changed_cb)bt_event_slot_container[event_index].callback)
1515 (_bt_get_error_code(param->result), _bt_get_bt_visibility_mode_e(*(bt_adapter_visibility_mode_e *)(param->param_data)), bt_event_slot_container[event_index].user_data);
1517 case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
1518 BT_INFO("bt_adapter_visibility_duration_changed_cb() will be called");
1519 discoverable_timeout = (int *)(param->param_data);
1520 ((bt_adapter_visibility_duration_changed_cb)bt_event_slot_container[event_index].callback)
1521 (*discoverable_timeout, bt_event_slot_container[event_index].user_data);
1523 case BLUETOOTH_EVENT_CONNECTABLE_CHANGED:
1524 BT_INFO("bt_adapter_connectable_changed_cb() will be called");
1525 ((bt_adapter_connectable_changed_cb)bt_event_slot_container[event_index].callback)
1526 (_bt_get_error_code(param->result), *(bool *)(param->param_data), bt_event_slot_container[event_index].user_data);
1528 case BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED: {
1529 BT_INFO("bt_device_trusted_profile_cb() will be called");
1530 bt_supported_profile_trusted_t *parameter = param->param_data;
1531 ((bt_device_trusted_profiles_cb)bt_event_slot_container[event_index].callback)
1532 (_bt_get_error_code(param->result), parameter->address, parameter->profile, parameter->supported, parameter->trusted, bt_event_slot_container[event_index].user_data);
1535 case BLUETOOTH_EVENT_DISCOVERY_STARTED:
1536 BT_INFO("bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_STARTED");
1537 ((bt_adapter_device_discovery_state_changed_cb) bt_event_slot_container[event_index].callback)
1538 (_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_STARTED, NULL, bt_event_slot_container[event_index].user_data);
1540 case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
1541 BT_INFO("bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FINISHED");
1542 ((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback)
1543 (_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, NULL, bt_event_slot_container[event_index].user_data);
1545 case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
1546 BT_INFO("bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FOUND");
1547 if (__bt_get_bt_adapter_device_discovery_info_s(&discovery_info, (bluetooth_device_info_t *)(param->param_data)) == BT_ERROR_NONE) {
1548 ((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback)
1549 (_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FOUND, discovery_info, bt_event_slot_container[event_index].user_data);
1550 __bt_free_bt_adapter_device_discovery_info_s(discovery_info);
1552 ((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback)
1553 (_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FOUND, NULL, bt_event_slot_container[event_index].user_data);
1556 case BLUETOOTH_EVENT_BONDING_FINISHED:
1557 BT_INFO("bt_device_bond_created_cb() will be called");
1558 _bt_get_bt_device_info_s(&bonded_device, (bluetooth_device_info_t *)(param->param_data));
1560 ((bt_device_bond_created_cb)bt_event_slot_container[event_index].callback)
1561 (_bt_get_error_code(param->result), bonded_device, bt_event_slot_container[event_index].user_data);
1562 _bt_free_bt_device_info_s(bonded_device);
1563 bonded_device = NULL;
1565 case BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED:
1566 BT_INFO("bt_device_bond_destroyed_cb() will be called");
1567 _bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data));
1568 ((bt_device_bond_destroyed_cb)bt_event_slot_container[event_index].callback)
1569 (_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data);
1570 if (device_addr != NULL)
1574 case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
1575 BT_INFO("Callbacks will be called for \
1576 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1577 auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
1578 _bt_convert_address_to_string(&device_addr, &auth_information->device_address);
1579 BT_DBG("BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY: name = %s address = %s passkey = %s incoming = %d", auth_information->device_name.name,
1580 device_addr, auth_information->str_passkey, auth_information->incoming);
1582 if (bt_event_slot_container[event_index].callback != NULL)
1584 ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
1585 (_bt_get_error_code(param->result), BT_AUTH_KEYBOARD_PASSKEY_DISPLAY, auth_information->device_name.name,
1586 device_addr, auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
1589 if (bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
1591 ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
1592 (auth_information->incoming, BT_AUTH_KEYBOARD_PASSKEY_DISPLAY, auth_information->device_name.name,
1593 device_addr, auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
1596 if (device_addr != NULL)
1599 case BLUETOOTH_EVENT_PIN_REQUEST:
1600 BT_INFO("Callbacks will be called for \
1601 BLUETOOTH_EVENT_PIN_REQUEST");
1602 auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
1603 _bt_convert_address_to_string(&device_addr, &auth_information->device_address);
1605 BT_DBG("BUETOOTH_EVENT_PIN_REQUEST: name = %s address = %s incoming = %d", auth_information->device_name.name,
1606 device_addr, auth_information->incoming);
1608 if(bt_event_slot_container[event_index].callback != NULL)
1610 ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
1611 (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
1612 auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
1615 if(bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
1617 ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
1618 (auth_information->incoming, BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
1619 auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
1622 if (device_addr != NULL)
1625 case BLUETOOTH_EVENT_PASSKEY_REQUEST:
1626 BT_INFO("Callbacks will be called for \
1627 BLUETOOTH_EVENT_PASSKEY_REQUEST");
1629 auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
1630 _bt_convert_address_to_string(&device_addr, &auth_information->device_address);
1632 BT_DBG("BLUETOOTH_EVENT_PASSKEY_REQUEST: name = %s address = %s", auth_information->device_name.name,
1634 if(bt_event_slot_container[event_index].callback != NULL)
1636 ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
1637 (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
1638 auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
1641 if(bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
1643 ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
1644 (auth_information->incoming, BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
1645 auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
1648 if (device_addr != NULL)
1651 case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
1652 BT_INFO("Callbacks will be called for \
1653 BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST");
1655 auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
1656 _bt_convert_address_to_string(&device_addr, &auth_information->device_address);
1658 BT_DBG("BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST: name = %s address = %s passkey = %s incoming = %d",
1659 auth_information->device_name.name, device_addr, auth_information->str_passkey, auth_information->incoming);
1660 if (bt_event_slot_container[event_index].callback != NULL)
1662 ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
1663 (_bt_get_error_code(param->result), BT_AUTH_PASSKEY_CONFIRM_REQUEST, auth_information->device_name.name, device_addr,
1664 auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
1667 if (bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
1669 ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
1670 (auth_information->incoming, BT_AUTH_PASSKEY_CONFIRM_REQUEST, auth_information->device_name.name, device_addr,
1671 auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
1674 if (device_addr != NULL)
1677 case BLUETOOTH_EVENT_DEVICE_AUTHORIZED:
1678 BT_INFO("bt_device_authorization_changed_cb() will be called with BT_DEVICE_AUTHORIZED");
1679 _bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data));
1680 ((bt_device_authorization_changed_cb)bt_event_slot_container[event_index].callback)
1681 (BT_DEVICE_AUTHORIZED, device_addr, bt_event_slot_container[event_index].user_data);
1682 if (device_addr != NULL)
1685 case BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED:
1686 BT_INFO("bt_device_authorization_changed_cb() will be called with BT_DEVICE_UNAUTHORIZED");
1687 _bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data));
1688 ((bt_device_authorization_changed_cb)bt_event_slot_container[event_index].callback)
1689 (BT_DEVICE_UNAUTHORIZED, device_addr, bt_event_slot_container[event_index].user_data);
1690 if (device_addr != NULL)
1693 case BLUETOOTH_EVENT_DEVICE_CONNECTED:
1694 BT_INFO("bt_device_connection_state_changed_cb() will be called");
1695 if (__bt_get_bt_device_connection_info_s(&conn_info, (bt_connection_info_t *)(param->param_data))
1697 ((bt_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
1698 (true, conn_info, bt_event_slot_container[event_index].user_data);
1699 __bt_free_bt_device_connection_info_s(conn_info);
1702 case BLUETOOTH_EVENT_DEVICE_DISCONNECTED:
1703 BT_INFO("bt_device_connection_state_changed_cb() will be called");
1704 if (__bt_get_bt_device_connection_info_s(&conn_info, (bt_connection_info_t *)(param->param_data))
1706 ((bt_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
1707 (false, conn_info, bt_event_slot_container[event_index].user_data);
1708 __bt_free_bt_device_connection_info_s(conn_info);
1712 case BLUETOOTH_EVENT_RSSI_ENABLED:
1713 BT_INFO("bt_rssi_monitor_enabled_cb() will be called");
1714 bt_rssi_enabled_t *enabled = (bt_rssi_enabled_t *)(param->param_data);
1716 if (_bt_check_cb(event_index)) {
1717 ((bt_rssi_monitor_enabled_cb)bt_event_slot_container[event_index].callback)
1718 (enabled->address, enabled->link_type, enabled->rssi_enabled,
1719 bt_event_slot_container[event_index].user_data);
1720 _bt_unset_cb(BT_EVENT_RSSI_ENABLED_EVENT);
1723 case BLUETOOTH_EVENT_RSSI_ALERT: {
1724 BT_INFO("bt_rssi_alert_cb() will be called");
1729 bt_rssi_alert_t *rssi_alert = (bt_rssi_alert_t *)(param->param_data);;
1731 alert_type = rssi_alert->alert_type;
1732 rssi_dbm = rssi_alert->rssi_dbm;
1733 address = rssi_alert->address;
1734 link_type = rssi_alert->link_type;
1735 if (_bt_check_cb(event_index)) {
1736 ((bt_rssi_alert_cb)bt_event_slot_container[event_index].callback)
1737 (address, link_type, alert_type, rssi_dbm,
1738 bt_event_slot_container[event_index].user_data);
1742 case BLUETOOTH_EVENT_RAW_RSSI: {
1743 BT_INFO("bt_rssi_strength_cb() will be called");
1747 bt_raw_rssi_t *raw_rssi = (bt_raw_rssi_t *)(param->param_data);;
1749 rssi_dbm = raw_rssi->rssi_dbm;
1750 address = raw_rssi->address;
1751 link_type = raw_rssi->link_type;
1753 if (_bt_check_cb(event_index)) {
1754 BT_INFO("BT Address [%s] Link Type[%d] RSSI dBm[%d]",
1755 address, link_type, rssi_dbm);
1756 ((bt_rssi_strength_cb)bt_event_slot_container[event_index].callback)
1757 (address, link_type, rssi_dbm, bt_event_slot_container[event_index].user_data);
1758 _bt_unset_cb(BT_EVENT_GET_RSSI_EVENT);
1762 case BLUETOOTH_EVENT_SERVICE_SEARCHED:
1763 BT_INFO("bt_device_service_searched_cb() will be called");
1764 error_code = _bt_get_error_code(param->result);
1765 /* In service search, BT_ERROR_SERVICE_SEARCH_FAILED is returned instead of BT_ERROR_OPERATION_FAILED. */
1766 if (error_code == BT_ERROR_OPERATION_FAILED)
1767 error_code = BT_ERROR_SERVICE_SEARCH_FAILED;
1769 if (__bt_get_bt_device_sdp_info_s(&sdp_info, (bt_sdp_info_t *)(param->param_data), error_code)
1771 ((bt_device_service_searched_cb)bt_event_slot_container[event_index].callback)
1772 (error_code, sdp_info, bt_event_slot_container[event_index].user_data);
1773 __bt_free_bt_device_sdp_info_s(sdp_info);
1776 case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
1777 /* BT_INFO("bt_socket_data_received_cb() will be * called"); */
1778 ((bt_socket_data_received_cb)bt_event_slot_container[event_index].callback)
1779 ((bt_socket_received_data_s *)(param->param_data), bt_event_slot_container[event_index].user_data);
1781 case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
1782 BT_INFO("bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_CONNECTED");
1783 if (param->result == BLUETOOTH_ERROR_INVALID_PARAM)
1784 error_code = BT_ERROR_OPERATION_FAILED;
1786 error_code = _bt_get_error_code(param->result);
1788 memset(&rfcomm_connection, 0x00, sizeof(bt_socket_connection_s));
1789 connection_ind = (bluetooth_rfcomm_connection_t *)(param->param_data);
1791 if (connection_ind) {
1792 rfcomm_connection.socket_fd = connection_ind->socket_fd;
1793 rfcomm_connection.local_role = connection_ind->device_role;
1794 rfcomm_connection.server_fd = connection_ind->server_id;
1796 if (strlen(connection_ind->uuid) > 0) {
1797 rfcomm_connection.service_uuid = strdup(connection_ind->uuid);
1798 BT_INFO("uuid: [%s]", rfcomm_connection.service_uuid);
1801 _bt_convert_address_to_string(&(rfcomm_connection.remote_address),
1802 &(connection_ind->device_addr));
1805 ((bt_socket_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
1806 (error_code, BT_SOCKET_CONNECTED, &rfcomm_connection, bt_event_slot_container[event_index].user_data);
1808 if (rfcomm_connection.remote_address != NULL) {
1809 free(rfcomm_connection.remote_address);
1810 rfcomm_connection.remote_address = NULL;
1813 if (rfcomm_connection.service_uuid != NULL) {
1814 free(rfcomm_connection.service_uuid);
1815 rfcomm_connection.service_uuid = NULL;
1819 case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
1820 BT_INFO("bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_DISCONNECTED");
1822 memset(&rfcomm_connection, 0x00, sizeof(bt_socket_connection_s));
1823 disconnection_ind = (bluetooth_rfcomm_disconnection_t *)(param->param_data);
1825 if (disconnection_ind) {
1826 rfcomm_connection.socket_fd = disconnection_ind->socket_fd;
1827 rfcomm_connection.local_role = disconnection_ind->device_role;
1829 if (strlen(disconnection_ind->uuid) > 0) {
1830 rfcomm_connection.service_uuid = strdup(disconnection_ind->uuid);
1831 BT_INFO("uuid: [%s]", rfcomm_connection.service_uuid);
1834 _bt_convert_address_to_string(&(rfcomm_connection.remote_address),
1835 &(disconnection_ind->device_addr));
1838 ((bt_socket_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
1839 (_bt_get_error_code(param->result), BT_SOCKET_DISCONNECTED, &rfcomm_connection, bt_event_slot_container[event_index].user_data);
1841 if (rfcomm_connection.remote_address != NULL) {
1842 free(rfcomm_connection.remote_address);
1843 rfcomm_connection.remote_address = NULL;
1846 if (rfcomm_connection.service_uuid != NULL) {
1847 free(rfcomm_connection.service_uuid);
1848 rfcomm_connection.service_uuid = NULL;
1852 case BLUETOOTH_EVENT_RFCOMM_AUTHORIZE:
1853 BT_INFO("bt_socket_connection_requested_cb() will be called");
1854 reqeust_ind = (bluetooth_rfcomm_connection_request_t *)(param->param_data);
1855 _bt_convert_address_to_string(&device_addr, &(reqeust_ind->device_addr));
1856 ((bt_socket_connection_requested_cb)bt_event_slot_container[event_index].callback)
1857 (reqeust_ind->socket_fd, device_addr, bt_event_slot_container[event_index].user_data);
1859 if (device_addr != NULL)
1862 case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
1863 BT_INFO("bt_opp_server_connection_requested_cb() will be called");
1864 bd_addr = (bluetooth_device_address_t *)(param->param_data);
1865 _bt_convert_address_to_string(&device_addr, bd_addr);
1866 ((bt_opp_server_connection_requested_cb)bt_event_slot_container[event_index].callback)
1867 (device_addr, bt_event_slot_container[event_index].user_data);
1869 if (device_addr != NULL)
1872 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
1873 BT_INFO("bt_opp_server_push_requested_cb() will be called");
1874 auth_info = (bt_obex_server_authorize_into_t *)(param->param_data);
1875 ((bt_opp_server_push_requested_cb)bt_event_slot_container[event_index].callback)
1876 (auth_info->filename, auth_info->length, bt_event_slot_container[event_index].user_data);
1879 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
1880 BT_INFO("bt_opp_server_transfer_started_cb() will be called");
1881 transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data);
1882 ((bt_opp_server_transfer_progress_cb)bt_event_slot_container[event_index].callback)
1883 (transfer_info->filename, transfer_info->file_size, 0, bt_event_slot_container[event_index].user_data);
1886 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
1887 BT_INFO("bt_opp_server_transfer_in_progress_cb() will be called");
1888 transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data);
1889 ((bt_opp_server_transfer_progress_cb)bt_event_slot_container[event_index].callback)
1890 (transfer_info->filename, transfer_info->file_size, transfer_info->percentage, bt_event_slot_container[event_index].user_data);
1893 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
1894 BT_INFO("bt_opp_server_transfer_completed_cb() will be called");
1895 transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data);
1897 ((bt_opp_server_transfer_finished_cb)bt_event_slot_container[event_index].callback)
1898 (_bt_get_error_code(param->result), transfer_info->filename, transfer_info->file_size, bt_event_slot_container[event_index].user_data);
1902 case BLUETOOTH_EVENT_OPC_CONNECTED:
1903 BT_INFO("bt_opp_client_push_responded_cb() will be called");
1904 bd_addr = (bluetooth_device_address_t *)(param->param_data);
1905 _bt_convert_address_to_string(&device_addr, bd_addr);
1907 ((bt_opp_client_push_responded_cb)bt_event_slot_container[event_index].callback)
1908 (_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data);
1910 if (device_addr != NULL)
1914 case BLUETOOTH_EVENT_OPC_DISCONNECTED:
1915 BT_INFO("bt_opp_client_push_finished_cb() will be called");
1916 bd_addr = (bluetooth_device_address_t *)(param->param_data);
1917 _bt_convert_address_to_string(&device_addr, bd_addr);
1919 ((bt_opp_client_push_finished_cb)bt_event_slot_container[event_index].callback)
1920 (_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data);
1922 if (device_addr != NULL)
1926 case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
1927 BT_INFO("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
1928 /* This event don't be used in CAPI */
1931 case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
1932 BT_INFO("bt_opp_client_transfer_in_progress_cb() will be called");
1933 client_info = (bt_opc_transfer_info_t *)(param->param_data);
1935 /* Progress 100% event will be invoked by BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE*/
1936 if (client_info->percentage != 100)
1937 ((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback)
1938 (client_info->filename, client_info->size, client_info->percentage, bt_event_slot_container[event_index].user_data);
1941 case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
1942 BT_INFO("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
1943 client_info = (bt_opc_transfer_info_t *)(param->param_data);
1945 if (param->result == BLUETOOTH_ERROR_NONE)
1946 ((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback)
1947 (client_info->filename, client_info->size, 100, bt_event_slot_container[event_index].user_data);
1950 case BLUETOOTH_EVENT_MAP_CONNECTED:
1951 BT_INFO("bt_map_client_??????????_cb() will be called");
1952 bd_addr = (bluetooth_device_address_t *)(param->param_data);
1953 _bt_convert_address_to_string(&device_addr, bd_addr);
1955 /* TODO: MAP, see above */
1957 if (device_addr != NULL)
1961 case BLUETOOTH_EVENT_MAP_DISCONNECTED:
1962 BT_INFO("bt_map_client_??????????_cb() will be called");
1963 bd_addr = (bluetooth_device_address_t *)(param->param_data);
1964 _bt_convert_address_to_string(&device_addr, bd_addr);
1966 /* TODO: MAP, see above */
1968 if (device_addr != NULL)
1971 case BLUETOOTH_EVENT_MAP_LIST_FOLDERS_COMPLETE:
1972 BT_INFO("BLUETOOTH_EVENT_MAP_LIST_FOLDERS_COMPLETE event");
1973 //do not need to release memory, it is managed by bluetooth-frwk
1974 bt_map_client_folders_s* folders_struct = (bt_map_client_folders_s*) param->param_data;
1975 ((bt_map_client_list_folders_cb)bt_event_slot_container[event_index].callback)
1976 (param->result, folders_struct->names, folders_struct->size,
1977 bt_event_slot_container[event_index].user_data);
1980 case BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE:
1982 BT_INFO(" BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE event");
1983 bt_map_list_filter_fields_info_t* fields_info = (bt_map_list_filter_fields_info_t*)(param->param_data);
1985 ((bt_map_client_list_filter_fields_cb)bt_event_slot_container[event_index].callback)
1986 (param->result, fields_info->fields, fields_info->size,
1987 bt_event_slot_container[event_index].user_data);
1991 case BLUETOOTH_EVENT_MAP_LIST_MESSAGES_COMPLETE:
1992 BT_INFO("BLUETOOTH_EVENT_MAP_LIST_MESSAGES_COMPLETE event");
1993 bt_map_client_message_items_s* messages_struct = (bt_map_client_message_items_s*) param->param_data;
1994 ((bt_map_client_list_messages_cb)bt_event_slot_container[event_index].callback)(
1996 (bt_map_client_message_item_s*)(messages_struct->message_items),
1997 messages_struct->size,
1998 bt_event_slot_container[event_index].user_data);
2001 case BLUETOOTH_EVENT_MAP_GET_MESSAGE_COMPLETE:
2002 BT_INFO("BLUETOOTH_EVENT_MAP_GET_MESSAGE_COMPLETE event");
2004 bt_get_message_callback_data *data = bt_event_slot_container[event_index].user_data;
2005 char *target_file = (char*) data->target_file;
2006 void *map_user_data = data->user_data;
2008 bt_map_client_message_s *res = g_malloc0(sizeof(bt_map_client_message_s));
2009 res->file_path = target_file;
2011 ((bt_map_client_get_message_cb)bt_event_slot_container[event_index].callback)(
2012 param->result, res, map_user_data);
2018 case BLUETOOTH_EVENT_MAP_PUSH_MESSAGE_COMPLETE:
2019 BT_INFO("BLUETOOTH_EVENT_MAP_PUSH_MESSAGE_COMPLETE event");
2021 ((bt_map_client_push_message_cb)bt_event_slot_container[event_index].callback)(
2023 bt_event_slot_container[event_index].user_data);
2026 case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
2027 BT_INFO("BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED");
2028 dev_info = (bluetooth_network_device_info_t *)(param->param_data);
2030 if (param->result != BLUETOOTH_ERROR_NONE)
2031 BT_ERR("Fail to connect the network server");
2033 _bt_convert_address_to_string(&device_addr, &dev_info->device_address);
2034 ((bt_nap_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2035 (TRUE, device_addr, dev_info->interface_name, bt_event_slot_container[event_index].user_data);
2037 if (device_addr != NULL)
2041 case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
2042 BT_INFO("BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED");
2043 dev_info = (bluetooth_network_device_info_t *)(param->param_data);
2045 if (param->result != BLUETOOTH_ERROR_NONE)
2046 BT_ERR("Fail to disconnect the network server");
2048 _bt_convert_address_to_string(&device_addr, &dev_info->device_address);
2049 ((bt_nap_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2050 (FALSE, device_addr, dev_info->interface_name, bt_event_slot_container[event_index].user_data);
2052 if (device_addr != NULL)
2055 case BLUETOOTH_EVENT_NETWORK_DISCONNECTED:
2056 BT_INFO("BLUETOOTH_EVENT_NETWORK_DISCONNECTED");
2057 bd_addr = (bluetooth_device_address_t *)(param->param_data);
2058 _bt_convert_address_to_string(&device_addr, bd_addr);
2060 ((bt_panu_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2061 (_bt_get_error_code(param->result), FALSE, device_addr, BLUETOOTH_NETWORK_NAP_ROLE,
2062 bt_event_slot_container[event_index].user_data);
2063 if (device_addr != NULL)
2067 case BLUETOOTH_EVENT_NETWORK_CONNECTED:
2068 BT_INFO("BLUETOOTH_EVENT_NETWORK_CONNECTED");
2069 bd_addr = (bluetooth_device_address_t *)(param->param_data);
2070 _bt_convert_address_to_string(&device_addr, bd_addr);
2072 ((bt_panu_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2073 (_bt_get_error_code(param->result), TRUE, device_addr, BLUETOOTH_NETWORK_NAP_ROLE,
2074 bt_event_slot_container[event_index].user_data);
2075 if (device_addr != NULL)
2079 case BLUETOOTH_EVENT_HDP_CONNECTED:
2080 BT_INFO("HDP Connected ");
2081 hdp_conn_info = (bt_hdp_connected_t *)(param->param_data);
2082 _bt_convert_address_to_string(&device_addr, &hdp_conn_info->device_address);
2083 ((bt_hdp_connected_cb)bt_event_slot_container[event_index].callback)
2084 (_bt_get_error_code(param->result), device_addr, hdp_conn_info->app_handle,
2085 hdp_conn_info->type, hdp_conn_info->channel_id,
2086 bt_event_slot_container[event_index].user_data);
2088 if (device_addr != NULL)
2092 case BLUETOOTH_EVENT_HDP_DISCONNECTED:
2093 BT_INFO("HDP disconnected callback will be ");
2094 hdp_disconn_info = (bt_hdp_disconnected_t *)(param->param_data);
2096 _bt_convert_address_to_string(&device_addr, &hdp_disconn_info->device_address);
2097 ((bt_hdp_disconnected_cb)bt_event_slot_container[event_index].callback)
2098 (_bt_get_error_code(param->result), device_addr,
2099 hdp_disconn_info->channel_id, bt_event_slot_container[event_index].user_data);
2101 if (device_addr != NULL)
2104 case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
2105 BT_INFO("HDP data received callback will be ");
2106 hdp_data_ind = (bt_hdp_data_ind_t *)(param->param_data);
2107 if (param->result != BLUETOOTH_ERROR_NONE)
2108 BT_ERR("Fail to receive HDP data");
2110 ((bt_hdp_data_received_cb)bt_event_slot_container[event_index].callback)
2111 (hdp_data_ind->channel_id, hdp_data_ind->buffer, hdp_data_ind->size,
2112 bt_event_slot_container[event_index].user_data);
2114 case BLUETOOTH_EVENT_AG_CONNECTED:
2115 BT_INFO("BLUETOOTH_EVENT_AG_CONNECTED ");
2116 device_addr = (char *)(param->param_data);
2117 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2118 (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
2119 bt_event_slot_container[event_index].user_data);
2121 case BLUETOOTH_EVENT_AG_DISCONNECTED:
2122 BT_INFO("BLUETOOTH_EVENT_AG_DISCONNECTED ");
2123 device_addr = (char *)(param->param_data);
2124 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2125 (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
2126 bt_event_slot_container[event_index].user_data);
2128 case BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED:
2129 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED ");
2130 ((bt_ag_sco_state_changed_cb)bt_event_slot_container[event_index].callback)
2131 (_bt_get_error_code(param->result), TRUE,
2132 bt_event_slot_container[event_index].user_data);
2134 case BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED:
2135 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED ");
2136 ((bt_ag_sco_state_changed_cb)bt_event_slot_container[event_index].callback)
2137 (_bt_get_error_code(param->result), FALSE,
2138 bt_event_slot_container[event_index].user_data);
2140 case BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL:
2141 call_data = (telephony_event_callid_t *)param->param_data;
2142 call_id = call_data->callid;
2143 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL ");
2144 ((bt_ag_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2145 (BT_AG_CALL_HANDLING_EVENT_ANSWER, call_id,
2146 bt_event_slot_container[event_index].user_data);
2148 case BLUETOOTH_EVENT_TELEPHONY_SET_MIC_GAIN:
2149 gain = (int *)(param->param_data);
2150 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_SET_MIC_GAIN ");
2151 ((bt_ag_microphone_gain_changed_cb)bt_event_slot_container[event_index].callback)
2152 (*gain, bt_event_slot_container[event_index].user_data);
2154 case BLUETOOTH_EVENT_TELEPHONY_SET_SPEAKER_GAIN:
2155 gain = (int *)(param->param_data);
2156 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_SET_SPEAKER_GAIN ");
2157 ((bt_ag_speaker_gain_changed_cb)bt_event_slot_container[event_index].callback)
2158 (*gain, bt_event_slot_container[event_index].user_data);
2160 case BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL:
2161 call_data = (telephony_event_callid_t *)param->param_data;
2162 call_id = call_data->callid;
2163 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL ");
2164 ((bt_ag_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2165 (BT_AG_CALL_HANDLING_EVENT_RELEASE, call_id,
2166 bt_event_slot_container[event_index].user_data);
2168 case BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL:
2169 call_data = (telephony_event_callid_t *)param->param_data;
2170 call_id = call_data->callid;
2171 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL ");
2172 ((bt_ag_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2173 (BT_AG_CALL_HANDLING_EVENT_REJECT, call_id,
2174 bt_event_slot_container[event_index].user_data);
2176 case BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL:
2177 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL ");
2178 ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2179 (BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_HELD_CALLS,
2180 bt_event_slot_container[event_index].user_data);
2182 case BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL:
2183 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL ");
2184 ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2185 (BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_ACTIVE_CALLS,
2186 bt_event_slot_container[event_index].user_data);
2188 case BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL:
2189 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL ");
2190 ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2191 (BT_AG_MULTI_CALL_HANDLING_EVENT_ACTIVATE_HELD_CALL,
2192 bt_event_slot_container[event_index].user_data);
2194 case BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL:
2195 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL ");
2196 ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2197 (BT_AG_MULTI_CALL_HANDLING_EVENT_MERGE_CALLS,
2198 bt_event_slot_container[event_index].user_data);
2200 case BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER:
2201 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER ");
2202 ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback)
2203 (BT_AG_MULTI_CALL_HANDLING_EVENT_EXPLICIT_CALL_TRANSFER,
2204 bt_event_slot_container[event_index].user_data);
2206 case BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF: {
2207 telephony_event_dtmf_t *call_data = param->param_data;
2209 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF ");
2210 ((bt_ag_dtmf_transmitted_cb)bt_event_slot_container[event_index].callback)
2211 (call_data->dtmf, bt_event_slot_container[event_index].user_data);
2214 case BLUETOOTH_EVENT_TELEPHONY_VENDOR_AT_CMD: {
2215 char *vendor_cmd = param->param_data;
2217 BT_INFO("BLUETOOTH_EVENT_TELEPHONY_VENDOR_AT_CMD");
2218 ((bt_ag_vendor_cmd_cb)bt_event_slot_container[event_index].callback)
2219 (vendor_cmd, bt_event_slot_container[event_index].user_data);
2222 case BLUETOOTH_EVENT_AG_SPEAKER_GAIN:
2223 BT_INFO("BLUETOOTH_EVENT_AG_SPEAKER_GAIN");
2224 int *spk_gain = (int *)(param->param_data);
2225 ((bt_ag_speaker_gain_changed_cb)bt_event_slot_container[event_index].callback)
2226 (*spk_gain, bt_event_slot_container[event_index].user_data);
2228 case BLUETOOTH_EVENT_AG_MIC_GAIN:
2229 BT_INFO("BLUETOOTH_EVENT_AG_MIC_GAIN");
2230 int *mik_gain = (int *)(param->param_data);
2231 ((bt_ag_microphone_gain_changed_cb)bt_event_slot_container[event_index].callback)
2232 (*mik_gain, bt_event_slot_container[event_index].user_data);
2234 case BLUETOOTH_EVENT_AG_AUDIO_CONNECTED:
2235 BT_INFO("BLUETOOTH_EVENT_AG_AUDIO_CONNECTED");
2236 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2237 (_bt_get_error_code(param->result), TRUE, NULL, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
2238 bt_event_slot_container[event_index].user_data);
2240 case BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED:
2241 BT_INFO("BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED");
2242 device_addr = (char *)(param->param_data);
2244 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2245 (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
2246 bt_event_slot_container[event_index].user_data);
2248 case BLUETOOTH_EVENT_AV_CONNECTED:
2249 BT_INFO("BLUETOOTH_EVENT_AV_CONNECTED ");
2250 device_addr = (char *)(param->param_data);
2251 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2252 (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP,
2253 bt_event_slot_container[event_index].user_data);
2255 case BLUETOOTH_EVENT_AV_DISCONNECTED:
2256 BT_INFO("BLUETOOTH_EVENT_AV_DISCONNECTED ");
2257 device_addr = (char *)(param->param_data);
2258 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2259 (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP,
2260 bt_event_slot_container[event_index].user_data);
2262 case BLUETOOTH_EVENT_AV_SOURCE_CONNECTED:
2263 BT_INFO("BLUETOOTH_EVENT_AV_SOURCE_CONNECTED");
2264 device_addr = (char *)(param->param_data);
2265 ((bt_audio_connection_state_changed_cb) bt_event_slot_container[event_index].callback)
2266 (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP_SINK,
2267 bt_event_slot_container[event_index].user_data);
2269 case BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED:
2270 BT_INFO("BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED");
2271 device_addr = (char *)(param->param_data);
2272 ((bt_audio_connection_state_changed_cb) bt_event_slot_container[event_index].callback)
2273 (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP_SINK,
2274 bt_event_slot_container[event_index].user_data);
2276 case BLUETOOTH_EVENT_AUDIO_AVC_STATUS:
2277 BT_INFO("BLUETOOTH_EVENT_AUDIO_AVC_STATUS ");
2278 bool *avc_activated = (bool *)(param->param_data);
2279 ((bt_audio_avc_status_changed_cb)bt_event_slot_container[event_index].callback)
2280 (*avc_activated, bt_event_slot_container[event_index].user_data);
2282 case BLUETOOTH_EVENT_AVRCP_CONNECTED:
2283 BT_INFO("BLUETOOTH_EVENT_AVRCP_CONNECTED ");
2284 device_addr = (char *)(param->param_data);
2285 ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2286 (TRUE, device_addr, bt_event_slot_container[event_index].user_data);
2288 case BLUETOOTH_EVENT_AVRCP_DISCONNECTED:
2289 BT_INFO("BLUETOOTH_EVENT_AVRCP_DISCONNECTED ");
2290 device_addr = (char *)(param->param_data);
2291 ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2292 (FALSE, device_addr, bt_event_slot_container[event_index].user_data);
2294 case BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS:
2295 BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS ");
2296 avrcp_mode = (int *)(param->param_data);
2297 ((bt_avrcp_shuffle_mode_changed_cb)bt_event_slot_container[event_index].callback)
2298 ((bt_avrcp_shuffle_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2300 case BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS:
2301 BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS ");
2302 avrcp_mode = (int *)(param->param_data);
2303 ((bt_avrcp_equalizer_state_changed_cb)bt_event_slot_container[event_index].callback)
2304 ((bt_avrcp_equalizer_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2306 case BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS:
2307 BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS ");
2308 avrcp_mode = (int *)(param->param_data);
2309 ((bt_avrcp_repeat_mode_changed_cb)bt_event_slot_container[event_index].callback)
2310 ((bt_avrcp_repeat_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2312 case BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS:
2313 BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS ");
2314 avrcp_mode = (int *)(param->param_data);
2315 ((bt_avrcp_scan_mode_changed_cb)bt_event_slot_container[event_index].callback)
2316 ((bt_avrcp_scan_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2318 case BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED:
2319 BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED ");
2320 device_addr = (char *)(param->param_data);
2321 ((bt_avrcp_control_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2322 (TRUE, device_addr, bt_event_slot_container[event_index].user_data);
2324 case BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED:
2325 BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED ");
2326 device_addr = (char *)(param->param_data);
2327 ((bt_avrcp_control_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2328 (FALSE, device_addr, bt_event_slot_container[event_index].user_data);
2330 case BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS:
2331 BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS ");
2332 avrcp_mode = (int *)(param->param_data);
2333 ((bt_avrcp_shuffle_mode_changed_cb)bt_event_slot_container[event_index].callback)
2334 ((bt_avrcp_shuffle_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2336 case BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS:
2337 BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS ");
2338 avrcp_mode = (int *)(param->param_data);
2339 ((bt_avrcp_equalizer_state_changed_cb)bt_event_slot_container[event_index].callback)
2340 ((bt_avrcp_equalizer_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2342 case BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS:
2343 BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS ");
2344 avrcp_mode = (int *)(param->param_data);
2345 ((bt_avrcp_repeat_mode_changed_cb)bt_event_slot_container[event_index].callback)
2346 ((bt_avrcp_repeat_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2348 case BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS:
2349 BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS ");
2350 avrcp_mode = (int *)(param->param_data);
2351 ((bt_avrcp_scan_mode_changed_cb)bt_event_slot_container[event_index].callback)
2352 ((bt_avrcp_scan_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2354 case BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED:
2355 BT_INFO("BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED ");
2356 avrcp_mode = (int *)(param->param_data);
2357 ((bt_avrcp_play_status_changed_cb)bt_event_slot_container[event_index].callback)
2358 ((bt_avrcp_player_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data);
2360 case BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS:
2361 BT_INFO("BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS ");
2362 unsigned int *postion = (unsigned int *)(param->param_data);
2363 ((bt_avrcp_position_changed_cb)bt_event_slot_container[event_index].callback)
2364 (*postion, bt_event_slot_container[event_index].user_data);
2366 case BLUETOOTH_EVENT_AVRCP_DELAY_CHANGED:
2367 BT_INFO("BLUETOOTH_EVENT_AVRCP_DELAY_CHANGED ");
2368 unsigned int *delay = (unsigned int *)(param->param_data);
2369 ((bt_avrcp_delay_changed_cb)bt_event_slot_container[event_index].callback)
2370 (*delay, bt_event_slot_container[event_index].user_data);
2372 case BLUETOOTH_EVENT_AVRCP_VOLUME_CHANGED:
2373 BT_INFO("BLUETOOTH_EVENT_AVRCP_VOLUME_CHANGED ");
2374 unsigned int *volume = (unsigned int *)(param->param_data);
2375 ((bt_audio_absolute_volume_changed_cb)bt_event_slot_container[event_index].callback)
2376 (*volume, bt_event_slot_container[event_index].user_data);
2378 /* We should handle for avrcp control role in later */
2380 case BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED:
2381 BT_INFO("BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED ");
2382 bt_avrcp_metadata_attributes_info_s meta_info = {0, };
2383 metadata = (media_metadata_attributes_t *)(param->param_data);
2384 meta_info.title = metadata->title; /* No need to allocate memory*/
2385 meta_info.artist = metadata->artist; /* No need to allocate memory*/
2386 meta_info.album = metadata->album; /* No need to allocate memory*/
2387 meta_info.genre = metadata->genre; /* No need to allocate memory*/
2388 meta_info.total_tracks = metadata->total_tracks;
2389 meta_info.number = metadata->number;
2390 meta_info.duration = metadata->duration;
2391 ((bt_avrcp_track_info_changed_cb)bt_event_slot_container[event_index].callback)
2392 (&meta_info, bt_event_slot_container[event_index].user_data);
2394 case BLUETOOTH_HID_CONNECTED:
2395 BT_INFO("BLUETOOTH_HID_CONNECTED");
2396 bd_addr = (bluetooth_device_address_t *)(param->param_data);
2397 _bt_convert_address_to_string(&device_addr, bd_addr);
2398 ((bt_hid_host_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2399 (_bt_get_error_code(param->result), TRUE, device_addr, bt_event_slot_container[event_index].user_data);
2401 if (device_addr != NULL)
2404 case BLUETOOTH_HID_DISCONNECTED:
2405 BT_INFO("BLUETOOTH_HID_DISCONNECTED");
2406 bd_addr = (bluetooth_device_address_t *)(param->param_data);
2407 _bt_convert_address_to_string(&device_addr, bd_addr);
2408 ((bt_hid_host_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2409 (_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data);
2411 if (device_addr != NULL)
2414 case BLUETOOTH_HID_DEVICE_CONNECTED:
2415 BT_INFO("BLUETOOTH_HID_DEVICE_CONNECTED");
2416 bd_addr = (bluetooth_device_address_t *)(param->param_data);
2417 _bt_convert_address_to_string(&device_addr, bd_addr);
2418 ((bt_hid_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2419 (_bt_get_error_code(param->result), TRUE, device_addr, bt_event_slot_container[event_index].user_data);
2421 if (device_addr != NULL)
2424 case BLUETOOTH_HID_DEVICE_DISCONNECTED:
2425 BT_INFO("BLUETOOTH_HID_DEVICE_DISCONNECTED");
2426 bd_addr = (bluetooth_device_address_t *)(param->param_data);
2427 _bt_convert_address_to_string(&device_addr, bd_addr);
2428 ((bt_hid_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
2429 (_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data);
2431 if (device_addr != NULL)
2434 case BLUETOOTH_HID_DEVICE_DATA_RECEIVED:
2435 BT_INFO("HID Device Data");
2436 ((bt_hid_device_data_received_cb)bt_event_slot_container[event_index].callback)
2437 ((bt_hid_device_received_data_s *)(param->param_data), bt_event_slot_container[event_index].user_data);
2439 #ifdef TIZEN_GATT_CLIENT
2440 /* Local is GATT server */
2441 case BLUETOOTH_EVENT_GATT_SERVER_CONNECTED: {
2442 bt_gatt_connection_state_changed_cb cb = NULL;
2443 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_CONNECTED");
2444 _bt_convert_address_to_string(&device_addr,
2445 (bluetooth_device_address_t *)(param->param_data));
2447 if (event_index >= 0)
2448 cb = bt_event_slot_container[event_index].callback;
2450 cb(_bt_get_error_code(param->result), TRUE, device_addr,
2451 bt_event_slot_container[event_index].user_data);
2453 g_free(device_addr);
2457 case BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED: {
2458 bt_gatt_connection_state_changed_cb cb = NULL;
2459 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED");
2460 _bt_convert_address_to_string(&device_addr,
2461 (bluetooth_device_address_t *)(param->param_data));
2462 if (event_index >= 0)
2463 cb = bt_event_slot_container[event_index].callback;
2465 cb(_bt_get_error_code(param->result), FALSE, device_addr,
2466 bt_event_slot_container[event_index].user_data);
2468 g_free(device_addr);
2472 /* Local is GATT client */
2473 case BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED: {
2474 bt_gatt_client_s *client_s;
2475 bt_gatt_connection_state_changed_cb cb = NULL;
2476 BT_INFO("BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED");
2477 _bt_convert_address_to_string(&device_addr,
2478 (bluetooth_device_address_t *)(param->param_data));
2480 client_s = (bt_gatt_client_s *)_bt_gatt_get_client(device_addr);
2482 if (BT_ERROR_NONE == _bt_get_error_code(param->result)) {
2483 if (client_s && !client_s->services_discovered) {
2484 BT_INFO("GATT Connected but services are not discovered yet, start browse client id [%d]",
2485 client_s->client_id);
2486 BT_INFO("GATT Client Connected address[%s]", device_addr);
2488 client_s->connected = true;
2489 _bt_gatt_client_update_services(client_s);
2494 __bt_hrp_le_connection_state_changed_cb(param->result, device_addr, TRUE);
2496 if (event_index >= 0)
2497 cb = bt_event_slot_container[event_index].callback;
2499 cb(_bt_get_error_code(param->result), TRUE, device_addr,
2500 bt_event_slot_container[event_index].user_data);
2501 g_free(device_addr);
2505 case BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED: {
2506 bt_gatt_client_s *client_s;
2507 bt_gatt_connection_state_changed_cb cb = NULL;
2508 BT_INFO("BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED");
2509 _bt_convert_address_to_string(&device_addr,
2510 (bluetooth_device_address_t *)(param->param_data));
2511 client_s = (bt_gatt_client_s *)_bt_gatt_get_client(device_addr);
2512 BT_INFO("GATT DisConnected address[%s] result [%d]", device_addr,
2513 _bt_get_error_code(param->result));
2515 BT_INFO("GATT CLient instance present for addr [%s] client ID [%d]",
2516 client_s->remote_address, client_s->client_id);
2517 client_s->connected = false;
2518 /* Mark services not discovered */
2519 client_s->services_discovered = false;
2524 __bt_hrp_le_connection_state_changed_cb(param->result, device_addr, FALSE);
2526 if (event_index >= 0)
2527 cb = bt_event_slot_container[event_index].callback;
2529 cb(_bt_get_error_code(param->result), FALSE, device_addr,
2530 bt_event_slot_container[event_index].user_data);
2531 g_free(device_addr);
2536 case BLUETOOTH_EVENT_GATT_CONNECTED: {
2537 bt_gatt_client_s *client_s;
2538 bt_gatt_connection_state_changed_cb cb = NULL;
2539 bool is_pxp_initialized = FALSE;
2540 BT_INFO("BLUETOOTH_EVENT_GATT_CONNECTED");
2541 _bt_convert_address_to_string(&device_addr,
2542 (bluetooth_device_address_t *)(param->param_data));
2543 client_s = (bt_gatt_client_s *)_bt_gatt_get_client(device_addr);
2545 client_s->connected = true;
2546 _bt_gatt_client_update_services(client_s);
2548 if (event_index >= 0)
2549 cb = bt_event_slot_container[event_index].callback;
2551 cb(_bt_get_error_code(param->result), TRUE, device_addr,
2552 bt_event_slot_container[event_index].user_data);
2554 /* The below check is for calling the callback for proximity profile reporter/Monitor role */
2555 _bt_check_proximity_is_initialized(&is_pxp_initialized);
2556 if (is_pxp_initialized)
2557 _bt_proximity_connection_set_state_changed(param->result, device_addr, TRUE);
2560 _bt_tds_update_seeker_connection_state_changed(param->result, device_addr, TRUE);
2563 _bt_otp_client_connection_state_changed(param->result, device_addr, TRUE);
2566 __bt_hrp_le_connection_state_changed_cb(param->result, device_addr, TRUE);
2568 if (device_addr != NULL)
2573 case BLUETOOTH_EVENT_GATT_DISCONNECTED: {
2574 bt_gatt_client_s *client_s;
2575 bt_gatt_connection_state_changed_cb cb = NULL;
2576 bool is_pxp_initialized = FALSE;
2577 BT_INFO("BLUETOOTH_EVENT_GATT_DISCONNECTED");
2578 _bt_convert_address_to_string(&device_addr,
2579 (bluetooth_device_address_t *)(param->param_data));
2580 client_s = (bt_gatt_client_s *)_bt_gatt_get_client(device_addr);
2582 client_s->connected = false;
2583 if (event_index >= 0)
2584 cb = bt_event_slot_container[event_index].callback;
2586 cb(_bt_get_error_code(param->result), FALSE, device_addr,
2587 bt_event_slot_container[event_index].user_data);
2588 /* The below check is for calling the callback for proximity profile reporter/Monitor role */
2589 _bt_check_proximity_is_initialized(&is_pxp_initialized);
2590 if (is_pxp_initialized)
2591 _bt_proximity_connection_set_state_changed(param->result, device_addr, FALSE);
2594 _bt_tds_update_seeker_connection_state_changed(param->result, device_addr, FALSE);
2597 _bt_otp_client_connection_state_changed(param->result, device_addr, FALSE);
2600 __bt_hrp_le_connection_state_changed_cb(param->result, device_addr, FALSE);
2602 if (device_addr != NULL)
2608 case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED:
2609 #ifdef TIZEN_GATT_CLIENT
2610 char_prop = (bt_gatt_char_property_t*)(param->param_data);
2611 if (char_prop == NULL)
2614 ((_bt_gatt_client_val_changed_cb)bt_event_slot_container[event_index].callback)
2615 (char_prop->prop.uuid, char_prop->address, char_prop->value, char_prop->val_len,
2616 bt_event_slot_container[event_index].user_data);
2618 char_val = (bt_gatt_char_value_t *)(param->param_data);
2620 if (char_val == NULL)
2623 ((_bt_gatt_client_value_changed_cb)bt_event_slot_container[event_index].callback)
2624 (char_val->char_handle, char_val->char_value, char_val->val_len,
2625 bt_event_slot_container[event_index].user_data);
2628 #ifdef TIZEN_GATT_CLIENT
2629 case BLUETOOTH_EVENT_GATT_READ_CHAR:
2630 BT_INFO("BLUETOOTH_EVENT_GATT_READ_CHAR");
2631 _bt_handle_gatt_client_char_read_completed_event(param->result, param->param_data);
2633 case BLUETOOTH_EVENT_GATT_WRITE_CHAR:
2634 BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_CHAR");
2635 _bt_handle_gatt_client_char_write_completed_event(param->result, param->param_data);
2637 case BLUETOOTH_EVENT_GATT_READ_DESC:
2638 BT_INFO("BLUETOOTH_EVENT_GATT_READ_DESC");
2639 _bt_handle_gatt_client_desc_read_completed_event(param->result, param->param_data);
2641 case BLUETOOTH_EVENT_GATT_WRITE_DESC:
2642 BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_DESC");
2643 _bt_handle_gatt_client_desc_write_completed_event(param->result, param->param_data);
2646 case BLUETOOTH_EVENT_GATT_READ_CHAR:
2647 BT_INFO("BLUETOOTH_EVENT_GATT_READ_CHAR");
2648 _handle_gatt_client_read_completed_event(param->result,
2651 case BLUETOOTH_EVENT_GATT_WRITE_CHAR:
2652 BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_CHAR");
2653 _handle_gatt_client_write_completed_event(param->result,
2656 case BLUETOOTH_EVENT_GATT_READ_DESC:
2657 BT_INFO("BLUETOOTH_EVENT_GATT_READ_DESC");
2658 _handle_gatt_client_read_completed_event(param->result,
2661 case BLUETOOTH_EVENT_GATT_WRITE_DESC:
2662 BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_DESC");
2663 _handle_gatt_client_write_completed_event(param->result,
2667 case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED: {
2668 #ifdef TIZEN_FEATURE_GATT_RELAY
2669 bluetooth_gatt_server_read_requested_info_t *read_req =
2670 (bluetooth_gatt_server_read_requested_info_t *)(param->param_data);
2671 bt_gatt_server_read_value_requested_cb cb_read;
2672 void *user_data_read = NULL;
2673 bt_gatt_h gatt_handle = NULL;
2674 bt_gatt_server_h serv = NULL;
2675 bool is_own_handle = false;
2677 cb_read = __bt_gatt_attribute_get_read_cb(read_req->attribute_handle,
2678 &serv, &gatt_handle, &is_own_handle, &user_data_read);
2681 _bt_convert_address_to_string(&device_addr, &read_req->device_address);
2683 BT_DBG("conn_id %d, trans id %d, attr handle %d, offset %d, is_long %d, addr %s",
2684 read_req->connection_id, read_req->request_id,
2685 read_req->attribute_handle, read_req->offset,
2686 read_req->is_long, device_addr);
2688 if (cb_read == NULL) {
2689 BT_DBG("GATT Server: App has not set the Read requested callback..for the current handle");
2690 if (is_own_handle) {
2691 BT_DBG("GATT Server: Internal response sent for Read Request");
2692 bt_gatt_server_send_response(read_req->request_id,
2693 BT_GATT_REQUEST_TYPE_READ, 0,
2694 BLUETOOTH_ERROR_INTERNAL, NULL, 0);
2697 if (device_addr != NULL)
2702 cb_read(device_addr, read_req->request_id, serv, gatt_handle, read_req->offset, user_data_read);
2704 if (device_addr != NULL)
2707 bt_gatt_read_req_t *read_req = param->param_data;
2708 bt_gatt_server_read_value_requested_cb cb;
2709 void *user_data_read = NULL;
2710 bt_gatt_h gatt_handle = NULL;
2712 cb = __bt_gatt_attribute_get_read_cb(read_req->service_handle,
2713 read_req->att_handle, &gatt_handle, &user_data_read);
2715 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED");
2717 bluetooth_gatt_send_response(read_req->req_id,
2718 BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ,
2719 BLUETOOTH_ATT_ERROR_INTERNAL, 0, NULL, 0);
2723 cb(read_req->address, read_req->req_id, read_req->service_handle,
2724 gatt_handle, read_req->offset,
2729 case BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED: {
2730 #ifdef TIZEN_FEATURE_GATT_RELAY
2731 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_WRITE_REQUESTED");
2732 bt_gatt_server_write_value_requested_cb cb_wr;
2733 void *user_data_write = NULL;
2734 bt_gatt_h gatt_handle = NULL;
2735 bt_gatt_h server = NULL;
2736 bool is_own_handle = false;
2737 bluetooth_gatt_server_write_requested_info_t *write_req =
2738 (bluetooth_gatt_server_write_requested_info_t *)(param->param_data);
2740 char *val = g_malloc0(write_req->length);
2742 BT_ERR("failed to allocate val");
2746 memcpy(val, write_req->data.data, write_req->length);
2747 cb_wr = __bt_gatt_attribute_get_value_change_cb(write_req->attribute_handle,
2748 &server, &gatt_handle, &is_own_handle, &user_data_write);
2751 _bt_convert_address_to_string(&device_addr, &write_req->device_address);
2753 BT_DBG("GATT Server Write Requested [%s] att handle %d, conn id %d, trans id %d, offset %d, length %d, need resp %d",
2754 device_addr, write_req->attribute_handle, write_req->connection_id, write_req->request_id,
2755 write_req->offset, write_req->length, write_req->need_resp);
2758 if (cb_wr == NULL) {
2759 BT_DBG("GATT Server: App has not set the Write requested callback..for the current handle");
2761 if (write_req->need_resp && is_own_handle) {
2762 BT_DBG("GATT Server: Internal response sent for Write Request");
2764 bt_gatt_server_send_response(write_req->request_id,
2765 BT_GATT_REQUEST_TYPE_WRITE, 0,
2766 BLUETOOTH_ERROR_INTERNAL, NULL, 0);
2772 if (device_addr != NULL)
2777 cb_wr(device_addr, write_req->request_id, server, gatt_handle,
2778 write_req->need_resp, write_req->offset,
2779 val, write_req->length, user_data_write);
2785 if (device_addr != NULL)
2788 bt_gatt_value_change_t *value_change = param->param_data;
2789 bt_gatt_server_write_value_requested_cb cb;
2790 void *user_data_write = NULL;
2791 bt_gatt_h gatt_handle = NULL;
2792 cb = __bt_gatt_attribute_get_value_change_cb(value_change->service_handle,
2793 value_change->att_handle, &gatt_handle, &user_data_write);
2795 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGE");
2797 if (value_change->response_needed == FALSE)
2800 bluetooth_gatt_send_response(value_change->req_id,
2801 BLUETOOTH_GATT_ATT_REQUEST_TYPE_WRITE,
2802 BLUETOOTH_ATT_ERROR_INTERNAL, 0, NULL, 0);
2806 cb(value_change->address, value_change->req_id, value_change->service_handle,
2807 gatt_handle, (bool)value_change->response_needed, value_change->offset,
2808 (char *)value_change->att_value, value_change->val_len, user_data_write);
2812 case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED: {
2813 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED");
2814 #ifdef TIZEN_FEATURE_GATT_RELAY
2815 bluetooth_gatt_server_notification_changed_t *notif_info =
2816 (bluetooth_gatt_server_notification_changed_t*)(param->param_data);
2818 bt_gatt_server_characteristic_notification_state_changed_cb cb;
2819 bt_gatt_server_h server_handle = NULL;
2820 bt_gatt_h char_handle = NULL;
2821 void *user_data_cfm = NULL;
2823 cb = __bt_gatt_attribute_get_notification_change_cb(&server_handle,
2824 notif_info->handle, &char_handle, &user_data_cfm);
2827 BT_INFO("cb is NULL");
2831 cb(notif_info->notification, server_handle, char_handle, user_data_cfm);
2833 bt_gatt_char_notify_change_t *value_change = param->param_data;
2834 bt_gatt_server_characteristic_notification_state_changed_cb cb;
2835 void *user_data_cfm = NULL;
2836 bt_gatt_h gatt_handle = NULL;
2837 cb = __bt_gatt_attribute_get_notification_change_cb(value_change->service_handle,
2838 value_change->att_handle, &gatt_handle, &user_data_cfm);
2840 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED");
2844 cb(value_change->att_notify, value_change->service_handle,
2845 gatt_handle, user_data_cfm);
2849 case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED: {
2850 #ifdef TIZEN_FEATURE_GATT_RELAY
2851 bluetooth_gatt_server_indicate_confirmed_info_t *cfm_info =
2852 (bluetooth_gatt_server_indicate_confirmed_info_t*)(param->param_data);
2853 bt_gatt_server_notification_sent_cb cb;
2854 bt_gatt_server_h server_handle = NULL;
2855 bt_gatt_h char_handle = NULL;
2857 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED");
2859 void *user_data_cfm = NULL;
2861 cb = __bt_gatt_attribute_get_notification_completed_cb(&server_handle,
2862 cfm_info->handle, &char_handle, &user_data_cfm);
2868 _bt_convert_address_to_string(&device_addr, &cfm_info->device_address);
2870 cb(_bt_get_error_code(param->result), device_addr,
2871 server_handle, char_handle,
2872 cfm_info->completed, user_data_cfm);
2875 if (device_addr != NULL)
2878 bt_gatt_indicate_confirm_t *confrim_status = param->param_data;
2879 bt_gatt_server_notification_sent_cb cb;
2880 void *local_user_data = NULL;
2881 cb = __bt_gatt_attribute_get_notification_completed_cb(confrim_status->service_handle,
2882 confrim_status->att_handle, &local_user_data);
2884 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED");
2888 cb(_bt_get_error_code(param->result), confrim_status->address,
2889 confrim_status->service_handle,
2890 confrim_status->att_handle, confrim_status->complete, local_user_data);
2894 case BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED: {
2895 const GSList *server_list = NULL;
2896 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED");
2898 char_val = (bt_gatt_char_value_t *)(param->param_data);
2900 if (char_val == NULL)
2903 for (server_list = _bt_gatt_get_server_list() ; server_list; server_list = g_slist_next(server_list)) {
2904 bt_gatt_server_s *serv = (bt_gatt_server_s *)server_list->data;
2905 GSList *service_list = NULL;
2907 for (service_list = serv->services; service_list; service_list = g_slist_next(service_list)) {
2908 bt_gatt_service_s *svc = (bt_gatt_service_s *)service_list->data;
2909 GSList *char_list = NULL;
2911 for (char_list = svc->characteristics; char_list; char_list = g_slist_next(char_list)) {
2912 bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)char_list->data;
2914 if (chr && g_strcmp0(char_val->char_handle, chr->path) == 0) {
2917 if (char_val->val_len > 0)
2918 chr->value = g_memdup(char_val->char_value, char_val->val_len);
2919 chr->value_length = char_val->val_len;
2920 /* TODO : Fix build error temporary */
2921 if (chr->write_value_requested_cb)
2922 chr->write_value_requested_cb(NULL, 0, (bt_gatt_server_h)serv, (bt_gatt_h)chr,
2923 TRUE, 0, (char *)char_val->char_value, char_val->val_len,
2924 chr->write_value_requested_user_data);
2931 case BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED: {
2932 bt_gatt_service_change_t *service_change =
2933 (bt_gatt_service_change_t *)(param->param_data);
2934 const GSList *l = NULL;
2935 bt_gatt_client_s *client = NULL;
2936 bt_gatt_service_s *svc = NULL;
2939 BT_INFO("BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED");
2941 if (service_change == NULL) {
2942 BT_ERR("service_change is NULL");
2946 _bt_convert_address_to_string(&device_addr,
2947 &service_change->device_addr);
2949 /* Check if TDS Service removed */
2950 _bt_tds_check_service_changed(device_addr, service_change);
2952 /* Check if OTS Service removed */
2953 _bt_otp_check_service_changed(device_addr, service_change);
2955 client = _bt_gatt_get_client(device_addr);
2956 if (device_addr != NULL)
2960 if (client == NULL) {
2961 BT_ERR("There is NO matched client");
2965 if (service_change->change_type == BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_ADD) {
2966 for (l = client->services; l; l = g_slist_next(l)) {
2968 #ifdef TIZEN_GATT_CLIENT
2969 if (!g_strcmp0(svc->uuid, service_change->uuid))
2972 if (!g_strcmp0(svc->path, service_change->svc_path))
2977 BT_INFO("already added service");
2980 #ifdef TIZEN_GATT_CLIENT
2981 BT_INFO("Service(%s) is added", service_change->uuid);
2982 client->services_discovered = false;
2983 svc = _bt_gatt_client_add_service(client, service_change->uuid, service_change->inst_id);
2985 BT_ERR("_bt_gatt_client_add_service is failed");
2989 svc = _bt_gatt_client_add_service(client, service_change->svc_path);
2991 BT_ERR("_bt_gatt_client_add_service is failed");
2996 if (client->connected && client->service_changed_cb)
2997 client->service_changed_cb(client,
2998 BT_GATT_CLIENT_SERVICE_ADDED,
2999 service_change->uuid,
3000 client->service_changed_user_data);
3001 } else { /* BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_REMOVE */
3002 for (l = client->services; l; l = g_slist_next(l)) {
3004 #ifdef TIZEN_GATT_CLIENT
3005 if (!g_strcmp0(svc->uuid, service_change->uuid))
3008 if (!g_strcmp0(svc->path, service_change->svc_path))
3013 BT_ERR("There is NO matched service");
3017 #ifdef TIZEN_GATT_CLIENT
3018 BT_INFO("Service(%s) is removed", svc->uuid);
3019 client->services_discovered = false;
3020 ret = _bt_gatt_client_remove_service(client, svc->uuid);
3021 if (ret != BT_ERROR_NONE) {
3022 BT_ERR("_bt_gatt_client_remove_service is failed");
3026 bt_gatt_service_destroy((bt_gatt_h)svc);
3029 if (client->connected && client->service_changed_cb)
3030 client->service_changed_cb(client,
3031 BT_GATT_CLIENT_SERVICE_REMOVED,
3032 service_change->uuid,
3033 client->service_changed_user_data);
3037 /* LCOV_EXCL_STOP */
3038 case BLUETOOTH_EVENT_ADVERTISING_STARTED:
3039 BT_INFO("BLUETOOTH_EVENT_ADVERTISING_STARTED");
3040 adv_handle = (int *)(param->param_data);
3042 _bt_adapter_le_invoke_advertising_state_cb(*adv_handle,
3043 _bt_get_error_code(param->result), BT_ADAPTER_LE_ADVERTISING_STARTED);
3046 case BLUETOOTH_EVENT_ADVERTISING_STOPPED:
3047 BT_INFO("BLUETOOTH_EVENT_ADVERTISING_STOPPED"); /* LCOV_EXCL_START */
3048 adv_handle = (int *)(param->param_data);
3050 _bt_adapter_le_invoke_advertising_state_cb(*adv_handle,
3051 _bt_get_error_code(param->result), BT_ADAPTER_LE_ADVERTISING_STOPPED); /* LCOV_EXCL_STOP */
3054 case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: /* LCOV_EXCL_START */
3055 BT_INFO("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED");
3057 ((bt_adapter_manufacturer_data_changed_cb)bt_event_slot_container[event_index].callback)
3058 (param->param_data, param->result,
3059 bt_event_slot_container[event_index].user_data);
3063 case BLUETOOTH_EVENT_PASSKEY_NOTIFICATION: {
3064 const char *address = NULL;
3065 const char *passkey = NULL;
3066 const char **passkey_info = param->param_data;
3067 BT_INFO("BLUETOOTH_EVENT_PASSKEY_NOTIFICATION");
3069 address = passkey_info[0];
3070 passkey = passkey_info[1];
3072 ((bt_adapter_passkey_notification_cb)bt_event_slot_container[event_index].callback)
3073 (address, passkey, bt_event_slot_container[event_index].user_data);
3077 case BLUETOOTH_EVENT_IPSP_CONNECTED:
3078 BT_INFO("BLUETOOTH_EVENT_IPSP_CONNECTED");
3079 bt_ipsp_iface_info = (bt_ipsp_connection_info_t *)(param->param_data);
3080 _bt_convert_address_to_string(&device_addr, &bt_ipsp_iface_info->btaddr);
3082 ((bt_ipsp_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
3083 (_bt_get_error_code(param->result), TRUE, device_addr, bt_ipsp_iface_info->if_name,
3084 bt_event_slot_container[event_index].user_data);
3086 if (device_addr != NULL)
3089 case BLUETOOTH_EVENT_IPSP_DISCONNECTED:
3090 BT_INFO("BLUETOOTH_EVENT_IPSP_DISCONNECTED");
3091 bt_ipsp_iface_info = (bt_ipsp_connection_info_t *)(param->param_data);
3092 _bt_convert_address_to_string(&device_addr, &bt_ipsp_iface_info->btaddr);
3094 ((bt_ipsp_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
3095 (_bt_get_error_code(param->result), FALSE, device_addr, bt_ipsp_iface_info->if_name,
3096 bt_event_slot_container[event_index].user_data);
3098 if (device_addr != NULL)
3101 case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED: {
3102 bt_gatt_client_att_mtu_info_s *mtu_info = NULL;
3103 bt_gatt_client_s *client = NULL;
3105 BT_INFO("BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED");
3107 if (__bt_get_bt_gatt_client_att_mtu_info_s(&mtu_info,
3108 (bluetooth_le_att_mtu_info_t *)(param->param_data)) != BT_ERROR_NONE) {
3109 BT_ERR("Fail to get MTU info");
3113 if (mtu_info == NULL)
3116 client = _bt_gatt_get_client(mtu_info->remote_address);
3118 if (client && client->connected && client->att_mtu_changed_cb)
3119 client->att_mtu_changed_cb(client,
3120 (const bt_gatt_client_att_mtu_info_s *)mtu_info,
3121 client->att_mtu_changed_user_data);
3123 if (bt_event_slot_container[event_index].callback)
3124 ((bt_device_att_mtu_changed_cb)bt_event_slot_container[event_index].callback)
3125 (_bt_get_error_code(param->result), (bt_device_att_mtu_info_s *)mtu_info,
3126 bt_event_slot_container[event_index].user_data);
3132 case BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED: {
3133 bt_gatt_server_att_mtu_info_s *mtu_info = NULL;
3134 const GSList *server_list = NULL;
3135 bt_gatt_server_s *server = NULL;
3137 BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED");
3139 server_list = _bt_gatt_get_server_list();
3143 server = (bt_gatt_server_s *)server_list->data;
3145 if (__bt_get_bt_gatt_server_att_mtu_info_s(&mtu_info,
3146 (bluetooth_le_att_mtu_info_t *)(param->param_data)) != BT_ERROR_NONE) {
3147 BT_ERR("Fail to get MTU info");
3151 if (mtu_info == NULL)
3154 if (server && server->att_mtu_changed_cb)
3155 server->att_mtu_changed_cb(server,
3156 (const bt_gatt_server_att_mtu_info_s *)mtu_info,
3157 server->att_mtu_changed_user_data);
3162 case BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED:
3163 BT_INFO("__bt_le_set_data_length_changed_cb() will be called");
3164 data_length_info = (bt_le_data_length_params_t *)(param->param_data);
3165 _bt_convert_address_to_string(&device_addr, &data_length_info->device_address);
3167 ((_bt_le_set_data_length_changed_cb)bt_event_slot_container[event_index].callback)
3168 (_bt_get_error_code(param->result), device_addr, data_length_info->max_tx_octets,
3169 data_length_info->max_tx_time, data_length_info->max_rx_octets, data_length_info->max_rx_time,
3170 bt_event_slot_container[event_index].user_data);
3172 if (device_addr != NULL)
3175 case BLUETOOTH_PBAP_CONNECTED: {
3176 bt_pbap_connection_state_changed_cb cb = bt_event_slot_container[event_index].callback;
3177 void *user_data_pbap = bt_event_slot_container[event_index].user_data;
3178 bt_pbap_connected_t *connected = (bt_pbap_connected_t *)param->param_data;
3180 BT_INFO("BLUETOOTH_PBAP_CONNECTED");
3182 _bt_convert_address_to_string(&device_addr, &connected->btaddr);
3183 cb(_bt_get_error_code(param->result), true, device_addr, user_data_pbap);
3185 if (device_addr != NULL)
3190 case BLUETOOTH_PBAP_DISCONNECTED: {
3191 bt_pbap_connection_state_changed_cb cb = bt_event_slot_container[event_index].callback;
3192 void *user_data_pbap = bt_event_slot_container[event_index].user_data;
3193 bt_pbap_connected_t *connected = (bt_pbap_connected_t *)param->param_data;
3195 BT_INFO("BLUETOOTH_PBAP_DISCONNECTED");
3197 _bt_convert_address_to_string(&device_addr, &connected->btaddr);
3198 cb(_bt_get_error_code(param->result), false, device_addr, user_data_pbap);
3200 if (device_addr != NULL)
3205 case BLUETOOTH_PBAP_PHONEBOOK_SIZE: {
3206 bt_pbap_phone_book_size_cb cb = bt_event_slot_container[event_index].callback;
3207 void *user_data_pbap = bt_event_slot_container[event_index].user_data;
3208 bt_pbap_phonebook_size_t *pb_size = (bt_pbap_phonebook_size_t *)param->param_data;
3210 BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_SIZE");
3212 _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SIZE);
3213 _bt_convert_address_to_string(&device_addr, &pb_size->btaddr);
3214 cb(_bt_get_error_code(param->result), device_addr, pb_size->size, user_data_pbap);
3216 if (device_addr != NULL)
3221 case BLUETOOTH_PBAP_PHONEBOOK_PULL: {
3222 bt_pbap_phone_book_received_cb cb = bt_event_slot_container[event_index].callback;
3223 void *user_data_pbap = bt_event_slot_container[event_index].user_data;
3224 bt_pbap_phonebook_pull_t *pb_pull = (bt_pbap_phonebook_pull_t *)(param->param_data);
3226 BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_PULL");
3228 _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_PULL);
3229 _bt_convert_address_to_string(&device_addr, &pb_pull->btaddr);
3230 cb(_bt_get_error_code(param->result), device_addr,
3231 (const char *)pb_pull->vcf_file, user_data_pbap);
3233 if (device_addr != NULL)
3238 case BLUETOOTH_PBAP_VCARD_LIST: {
3240 bt_pbap_list_vcards_cb cb = bt_event_slot_container[event_index].callback;
3241 void *user_data_pbap = bt_event_slot_container[event_index].user_data;
3242 bt_pbap_vcard_list_t *vc_list = (bt_pbap_vcard_list_t *)(param->param_data);
3243 bt_pbap_vcard_info_s *vcard_info = NULL;
3245 BT_INFO("BLUETOOTH_PBAP_VCARD_LIST");
3247 if (vc_list->length > 0) {
3248 vcard_info = g_malloc0(vc_list->length * sizeof(bt_pbap_vcard_info_s));
3250 for (i = 0; i < vc_list->length; i++)
3251 vcard_info[i].contact_name = g_strdup(vc_list->vcards[i]);
3254 _bt_unset_cb(BT_EVENT_PBAP_VCARD_LIST);
3255 _bt_convert_address_to_string(&device_addr, &vc_list->btaddr);
3256 cb(_bt_get_error_code(param->result), device_addr,
3257 (const bt_pbap_vcard_info_s *)vcard_info, vc_list->length,
3260 if (device_addr != NULL)
3263 if (vcard_info != NULL) {
3264 for (i = 0; i < vc_list->length; i++)
3265 g_free((char *)vcard_info[i].contact_name);
3270 case BLUETOOTH_PBAP_VCARD_PULL: {
3271 bt_pbap_phone_book_received_cb cb = bt_event_slot_container[event_index].callback;
3272 void *user_data_pbap = bt_event_slot_container[event_index].user_data;
3273 bt_pbap_vcard_pull_t *vc_pull = (bt_pbap_vcard_pull_t *)(param->param_data);
3275 BT_INFO("BLUETOOTH_PBAP_VCARD_PULL");
3277 _bt_unset_cb(BT_EVENT_PBAP_VCARD_PULL);
3278 _bt_convert_address_to_string(&device_addr, &vc_pull->btaddr);
3279 cb(_bt_get_error_code(param->result), device_addr,
3280 (const char *)vc_pull->vcf_file, user_data_pbap);
3282 if (device_addr != NULL)
3287 case BLUETOOTH_PBAP_PHONEBOOK_SEARCH: {
3289 bt_pbap_list_vcards_cb cb = bt_event_slot_container[event_index].callback;
3290 void *local_user_data = bt_event_slot_container[event_index].user_data;
3291 bt_pbap_phonebook_search_list_t *vc_list = (bt_pbap_phonebook_search_list_t *)(param->param_data);
3292 bt_pbap_vcard_info_s *vcard_info = NULL;
3294 if (vc_list->length > 0) {
3295 vcard_info = g_malloc0(vc_list->length * sizeof(bt_pbap_vcard_info_s));
3297 for (i = 0; i < vc_list->length; i++)
3298 vcard_info[i].contact_name = g_strdup(vc_list->vcards[i]);
3301 BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_SEARCH");
3303 _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SEARCH);
3304 _bt_convert_address_to_string(&device_addr, &vc_list->btaddr);
3305 cb(_bt_get_error_code(param->result), device_addr,
3306 (const bt_pbap_vcard_info_s *)vcard_info, vc_list->length,
3309 if (device_addr != NULL)
3312 if (vcard_info != NULL) {
3313 for (i = 0; i < vc_list->length; i++)
3314 g_free((char *)vcard_info[i].contact_name);
3319 case BLUETOOTH_EVENT_HF_CONNECTED:
3320 BT_INFO("BLUETOOTH_EVENT_HF_CONNECTED");
3321 device_addr = (char *)(param->param_data);
3322 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
3323 (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_AG,
3324 bt_event_slot_container[event_index].user_data);
3326 case BLUETOOTH_EVENT_HF_DISCONNECTED:
3327 BT_INFO("BLUETOOTH_EVENT_HF_DISCONNECTED");
3328 device_addr = (char *)(param->param_data);
3329 ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
3330 (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_AG,
3331 bt_event_slot_container[event_index].user_data);
3333 case BLUETOOTH_EVENT_HF_AUDIO_CONNECTED:
3334 BT_INFO("BLUETOOTH_EVENT_HF_AUDIO_CONNECTED");
3335 device_addr = (char *)(param->param_data);
3336 ((bt_hf_sco_state_changed_cb)bt_event_slot_container[event_index].callback)
3337 (_bt_get_error_code(param->result), TRUE,
3338 bt_event_slot_container[event_index].user_data);
3340 case BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED:
3341 BT_INFO("BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED");
3342 device_addr = (char *)(param->param_data);
3343 ((bt_hf_sco_state_changed_cb)bt_event_slot_container[event_index].callback)
3344 (_bt_get_error_code(param->result), FALSE,
3345 bt_event_slot_container[event_index].user_data);
3347 case BLUETOOTH_EVENT_HF_RING_INDICATOR:
3348 BT_INFO("BLUETOOTH_EVENT_HF_RING_INDICATOR");
3349 phone_number = (char *)(param->param_data);
3350 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3351 (BT_HF_REMOTE_CALL_EVENT_RINGING, phone_number,
3352 bt_event_slot_container[event_index].user_data);
3354 case BLUETOOTH_EVENT_HF_CALL_TERMINATED:
3355 BT_INFO("BLUETOOTH_EVENT_HF_CALL_TERMINATED");
3356 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3357 (BT_HF_REMOTE_CALL_EVENT_CALL_TERMINATED, NULL,
3358 bt_event_slot_container[event_index].user_data);
3360 case BLUETOOTH_EVENT_HF_CALL_FAILED_TO_DIAL:
3361 BT_INFO("BLUETOOTH_EVENT_HF_CALL_FAILED_TO_DIAL");
3362 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3363 (BT_HF_REMOTE_CALL_EVENT_FAILED_TO_DIALING, NULL,
3364 bt_event_slot_container[event_index].user_data);
3366 case BLUETOOTH_EVENT_HF_CALL_IDLE:
3367 BT_INFO("BLUETOOTH_EVENT_HF_CALL_IDLE");
3368 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3369 (BT_HF_REMOTE_CALL_EVENT_IDLE, NULL,
3370 bt_event_slot_container[event_index].user_data);
3372 case BLUETOOTH_EVENT_HF_CALLSETUP_INCOMING:
3373 BT_INFO("BLUETOOTH_EVENT_HF_CALLSETUP_INCOMING");
3374 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3375 (BT_HF_REMOTE_CALL_EVENT_INCOMING, NULL,
3376 bt_event_slot_container[event_index].user_data);
3378 case BLUETOOTH_EVENT_HF_CALLSETUP_DIALING:
3379 BT_INFO("BLUETOOTH_EVENT_HF_CALLSETUP_DIALING");
3380 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3381 (BT_HF_REMOTE_CALL_EVENT_DIALING, NULL,
3382 bt_event_slot_container[event_index].user_data);
3384 case BLUETOOTH_EVENT_HF_CALLSETUP_ALERTING:
3385 BT_INFO("BLUETOOTH_EVENT_HF_CALLSETUP_ALERTING");
3386 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3387 (BT_HF_REMOTE_CALL_EVENT_ALERTING, NULL,
3388 bt_event_slot_container[event_index].user_data);
3390 case BLUETOOTH_EVENT_HF_CALL_STARTED:
3391 BT_INFO("BLUETOOTH_EVENT_HF_CALL_STARTED");
3392 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3393 (BT_HF_REMOTE_CALL_EVENT_CALL_STARTED, NULL,
3394 bt_event_slot_container[event_index].user_data);
3396 case BLUETOOTH_EVENT_HF_CALL_ENDED:
3397 BT_INFO("BLUETOOTH_EVENT_HF_CALL_ENDED");
3398 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3399 (BT_HF_REMOTE_CALL_EVENT_CALL_ENDED, NULL,
3400 bt_event_slot_container[event_index].user_data);
3402 case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED:
3403 BT_INFO("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED");
3404 ((bt_hf_remote_device_state_changed_cb)bt_event_slot_container[event_index].callback)
3405 (BT_HF_REMOTE_DEVICE_STATE_VOICE_RECOGNITON, TRUE,
3406 bt_event_slot_container[event_index].user_data);
3408 case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED:
3409 BT_INFO("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED");
3410 ((bt_hf_remote_device_state_changed_cb)bt_event_slot_container[event_index].callback)
3411 (BT_HF_REMOTE_DEVICE_STATE_VOICE_RECOGNITON, FALSE,
3412 bt_event_slot_container[event_index].user_data);
3414 case BLUETOOTH_EVENT_HF_CALL_WAITING:
3415 BT_INFO("BLUETOOTH_EVENT_HF_CALL_WAITING");
3416 phone_number = (char *)(param->param_data);
3417 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3418 (BT_HF_REMOTE_CALL_EVENT_WAITING, phone_number,
3419 bt_event_slot_container[event_index].user_data);
3421 case BLUETOOTH_EVENT_HF_CALL_ON_HOLD:
3422 BT_INFO("BLUETOOTH_EVENT_HF_CALL_ON_HOLD");
3423 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3424 (BT_HF_REMOTE_CALL_EVENT_HELD, NULL,
3425 bt_event_slot_container[event_index].user_data);
3427 case BLUETOOTH_EVENT_HF_CALL_UNHOLD:
3428 BT_INFO("BLUETOOTH_EVENT_HF_CALL_UNHOLD");
3429 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3430 (BT_HF_REMOTE_CALL_EVENT_UNHELD, NULL,
3431 bt_event_slot_container[event_index].user_data);
3433 case BLUETOOTH_EVENT_HF_CALL_SWAPPED:
3434 BT_INFO("BLUETOOTH_EVENT_HF_CALL_SWAPPED");
3435 ((bt_hf_remote_call_event_cb)bt_event_slot_container[event_index].callback)
3436 (BT_HF_REMOTE_CALL_EVENT_SWAPPED, NULL,
3437 bt_event_slot_container[event_index].user_data);
3439 case BLUETOOTH_EVENT_HF_VENDOR_DEP_CMD: {
3440 BT_INFO("BLUETOOTH_EVENT_HF_VENDOR_DEP_CMD");
3441 bluetooth_vendor_dep_at_cmd_t *cmd = (bluetooth_vendor_dep_at_cmd_t *)(param->param_data);
3442 bt_hf_vendor_dep_at_cmd_s command = {0, };
3443 command.app_id = cmd->app_id;
3444 command.message = strdup(cmd->message);
3445 ((bt_hf_vendor_dep_cmd_event_cb)bt_event_slot_container[event_index].callback)
3446 (command, bt_event_slot_container[event_index].user_data);
3449 case BLUETOOTH_EVENT_HF_VOLUME_SPEAKER: {
3450 BT_INFO("BLUETOOTH_EVENT_HF_VOLUME_SPEAKER");
3451 int *spk_gain = (int *)(param->param_data);
3452 ((bt_hf_speaker_gain_changed_cb)bt_event_slot_container[event_index].callback)
3453 (*spk_gain, bt_event_slot_container[event_index].user_data);
3456 case BLUETOOTH_EVENT_HF_CALL_STATUS: {
3457 BT_INFO("BLUETOOTH_EVENT_HF_CALL_STATUS");
3458 bt_hf_call_list_s *handle = (bt_hf_call_list_s *)(param->param_data);
3460 GSList *call_list = NULL;
3462 for (l = g_list_first(handle->list); l; l = g_list_next(l)) {
3463 bt_hf_call_status_info_t *hf_call_info = l->data;
3464 bt_hf_call_status_info_s *call_info = NULL;
3466 call_info = g_malloc0(sizeof(bt_hf_call_status_info_s));
3467 call_info->number = strdup(hf_call_info->number);
3468 call_info->direction = hf_call_info->direction;
3469 call_info->status = hf_call_info->status;
3470 call_info->multi_party = hf_call_info->mpart;
3471 call_info->index = hf_call_info->idx;
3472 call_list = g_slist_append(call_list, call_info);
3475 ((bt_hf_call_status_updated_event_cb)bt_event_slot_container[event_index].callback)
3476 (call_list, bt_event_slot_container[event_index].user_data);
3479 case BLUETOOTH_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED: {
3480 bluetooth_hf_ciev_device_event_t *device_event = (bluetooth_hf_ciev_device_event_t *)(param->param_data);
3482 BT_INFO("BLUETOOTH_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED (status %d)(value %d)",
3483 device_event->event, device_event->value);
3485 ((bt_hf_remote_device_state_changed_cb)bt_event_slot_container[event_index].callback)
3486 ((bt_hf_remote_device_state_e) device_event->event, device_event->value,
3487 bt_event_slot_container[event_index].user_data);
3490 case BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED: {
3491 BT_DBG("BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED"); /* LCOV_EXCL_LINE */
3492 ((bt_ipsp_init_state_changed_cb)bt_event_slot_container[event_index].callback) /* LCOV_EXCL_LINE */
3493 (_bt_get_error_code(param->result), *(bool *)(param->param_data), /* LCOV_EXCL_LINE */
3494 bt_event_slot_container[event_index].user_data);
3497 case BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED: {
3498 BT_DBG("BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED"); /* LCOV_EXCL_LINE */
3499 bt_pxp_property_info = (bt_pxp_property_changed_params_t *)(param->param_data);
3500 _bt_convert_address_to_string(&device_addr, &bt_pxp_property_info->device_address);
3502 ((bt_proximity_reporter_property_changed_cb)bt_event_slot_container[event_index].callback) /* LCOV_EXCL_LINE */
3503 (_bt_get_error_code(param->result), device_addr,
3504 bt_pxp_property_info->service_type,
3505 bt_pxp_property_info->alert_lvl, bt_event_slot_container[event_index].user_data);
3507 if (device_addr != NULL)
3511 case BLUETOOTH_EVENT_TDS_ACTIVATION_REQUESTED: {
3512 BT_DBG("BLUETOOTH_EVENT_TDS_ACTIVATION_REQUESTED"); /* LCOV_EXCL_LINE */
3513 tds_act_req_info = (bluetooth_tds_activation_req_t *)(param->param_data);
3514 _bt_convert_address_to_string(&device_addr, &tds_act_req_info->rem_addr);
3516 ((bt_tds_activation_requested_cb)bt_event_slot_container[event_index].callback) /* LCOV_EXCL_LINE */
3517 (device_addr, tds_act_req_info->transport, tds_act_req_info->tds_data.data,
3518 tds_act_req_info->tds_data.length, bt_event_slot_container[event_index].user_data);
3520 if (device_addr != NULL)
3524 case BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED: {
3525 BT_DBG("BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED"); /* LCOV_EXCL_LINE */
3526 bluetooth_tds_transport_data_info_t *info = NULL;
3527 bluetooth_device_address_t *addr = NULL;
3529 if (_bt_get_error_code(param->result) == BT_ERROR_NONE) {
3530 info = (bluetooth_tds_transport_data_info_t *)(param->param_data);
3531 _bt_convert_address_to_string(&device_addr, &info->device_address);
3532 _bt_tds_send_complete_transport_data(_bt_get_error_code(param->result), device_addr,
3533 info->data, info->data_length);
3535 BT_ERR("TDS Complete data Read request failed!!!");
3536 addr = (bluetooth_device_address_t *)(param->param_data);
3537 _bt_convert_address_to_string(&device_addr, addr);
3538 _bt_tds_send_complete_transport_data(_bt_get_error_code(param->result), device_addr,
3541 BT_DBG("TDS Complete data blocks received: Remote provider address [%s]", device_addr);
3542 if (device_addr != NULL)
3546 case BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT: {
3547 BT_DBG("BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT"); /* LCOV_EXCL_LINE */
3548 _bt_convert_address_to_string(&device_addr,
3549 (bluetooth_device_address_t *)(param->param_data));
3551 _bt_tds_control_point_activation_result_update(_bt_get_error_code(param->result), device_addr);
3553 if (device_addr != NULL)
3557 case BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED: {
3558 BT_DBG("BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED"); /* LCOV_EXCL_LINE */
3559 _bt_convert_address_to_string(&device_addr,
3560 (bluetooth_device_address_t *)(param->param_data));
3562 _bt_tds_control_point_enabled_update(_bt_get_error_code(param->result), device_addr);
3564 if (device_addr != NULL)
3567 } case BLUETOOTH_EVENT_TDS_ACTIVATION_INDICATION: {
3568 BT_DBG("BLUETOOTH_EVENT_TDS_ACTIVATION_INDICATION"); /* LCOV_EXCL_LINE */
3569 bluetooth_tds_indication_res_t *tds_act_ind_res = NULL;
3570 tds_act_ind_res = (bluetooth_tds_indication_res_t *)(param->param_data);
3572 _bt_convert_address_to_string(&device_addr, &tds_act_ind_res->rem_addr);
3574 BT_ERR("Address [%s]", device_addr);
3575 _bt_tds_control_point_indication_response_update(device_addr, tds_act_ind_res);
3577 if (device_addr != NULL)
3581 case BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED: {
3582 bt_otp_server_state_changed_cb cb = bt_event_slot_container[event_index].callback;
3583 bool *status = (bool *)(param->param_data);
3585 BT_INFO("BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED [%s]", *status ? "enabled" : "disabled");
3587 cb(_bt_get_error_code(param->result), *status ? true : false);
3590 case BLUETOOTH_EVENT_OTP_READ_CHAR_VAL: {
3591 BT_DBG("BLUETOOTH_EVENT_OTP_READ_CHAR_VAL"); /* LCOV_EXCL_LINE */
3592 bluetooth_otp_resp_info_t *info = NULL;
3593 char *handle = NULL;
3595 if (param->result == BT_ATT_ERROR_NONE) {
3596 info = (bluetooth_otp_resp_info_t *)(param->param_data);
3597 BT_ERR("Read Success Handle [%s]", info->handle);
3598 _bt_otp_client_read_value_response(param->result,
3599 info->handle, info->data, info->data_length);
3601 handle = (char *)(param->param_data);
3602 BT_ERR("Read Fail Handle [%s]", handle);
3603 _bt_otp_client_read_value_response(param->result,
3608 case BLUETOOTH_EVENT_OTP_WRITE_CHAR_VAL: {
3609 BT_DBG("BLUETOOTH_EVENT_OTP_WRITE_CHAR_VAL"); /* LCOV_EXCL_LINE */
3610 char *handle = (char *)(param->param_data);
3611 BT_ERR("Handle [%s]", handle);
3612 _bt_otp_client_write_value_response(param->result, handle);
3615 case BLUETOOTH_EVENT_OTP_NOTIFICATION_ENABLED: {
3616 BT_DBG("BLUETOOTH_EVENT_OTP_NOTIFICATION_ENABLED"); /* LCOV_EXCL_LINE */
3617 char *handle = (char *)(param->param_data);
3618 BT_DBG("Handle [%s]", handle);
3619 _bt_otp_client_notification_enabled(_bt_get_error_code(param->result), handle);
3621 } case BLUETOOTH_EVENT_OTP_INDICATION: {
3622 BT_DBG("BLUETOOTH_EVENT_OTP_INDICATION"); /* LCOV_EXCL_LINE */
3623 bluetooth_otp_resp_info_t *otp_ind_info = NULL;
3624 otp_ind_info = (bluetooth_otp_resp_info_t *)(param->param_data);
3625 BT_DBG("Handle [%s]", otp_ind_info->handle);
3626 _bt_otp_client_indication(_bt_get_error_code(param->result), otp_ind_info);
3628 } case BLUETOOTH_EVENT_OTC_STATE_CHANGED: {
3629 BT_DBG("BLUETOOTH_EVENT_OTC_STATE_CHANGED"); /* LCOV_EXCL_LINE */
3630 bluetooth_otc_info_t *otc_info = NULL;
3631 otc_info = (bluetooth_otc_info_t *)(param->param_data);
3633 BT_ERR("Address [%s]", otc_info->address);
3634 _bt_otc_connection_state_changed(_bt_get_error_code(param->result), otc_info);
3636 } case BLUETOOTH_EVENT_MESH_SCAN_STARTED: {
3637 BT_INFO("BLUETOOTH_EVENT_MESH_SCAN_STARTED");
3638 bluetooth_mesh_network_t *network = NULL;
3639 bt_mesh_network_s *info = NULL;
3640 network = (bluetooth_mesh_network_t *)(param->param_data);
3642 info = _bt_mesh_get_network_handle_info(network->uuid);
3645 BT_INFO("Mesh: Scan status for Network UUID[%s] Name [%s]",
3646 info->uuid, info->name);
3647 ((bt_mesh_network_scan_unprovisioned_device_result_cb)
3648 bt_event_slot_container[event_index].callback)
3649 (_bt_get_error_code(param->result), (bt_mesh_network_h) info,
3650 BT_MESH_SCANNING_STARTED, NULL,
3651 bt_event_slot_container[event_index].user_data);
3653 } case BLUETOOTH_EVENT_MESH_SCAN_FINISHED: {
3654 BT_INFO("BLUETOOTH_EVENT_MESH_SCAN_FINISHED");
3655 bluetooth_mesh_network_t *network = NULL;
3656 bt_mesh_network_s *info = NULL;
3657 network = (bluetooth_mesh_network_t *)(param->param_data);
3659 info = _bt_mesh_get_network_handle_info(network->uuid);
3662 BT_INFO("Mesh: Scan status for Network UUID[%s] Name [%s]",
3663 info->uuid, info->name);
3664 ((bt_mesh_network_scan_unprovisioned_device_result_cb)
3665 bt_event_slot_container[event_index].callback)
3666 (_bt_get_error_code(param->result), (bt_mesh_network_h) info,
3667 BT_MESH_SCANNING_FINISHED, NULL,
3668 bt_event_slot_container[event_index].user_data);
3670 } case BLUETOOTH_EVENT_MESH_SCAN_RESULT: {
3671 BT_INFO("BLUETOOTH_EVENT_MESH_SCAN_RESULT");
3672 bluetooth_mesh_scan_result_t *scan_result = NULL;
3673 bt_mesh_network_s *info = NULL;
3674 bt_mesh_scan_result_s *scan_res;
3675 scan_result = (bluetooth_mesh_scan_result_t *)(param->param_data);
3677 info = _bt_mesh_get_network_handle_info(scan_result->net_uuid);
3681 BT_INFO("Mesh: Scan Result: Dev UUID[%s]", scan_result->dev_uuid);
3683 scan_res = g_malloc0(sizeof(bt_mesh_scan_result_s));
3684 scan_res->uuid = g_strdup(scan_result->dev_uuid);
3685 scan_res->rssi = scan_result->rssi;
3686 /* TODO Fill OOB Info and URI hash data during testing */
3688 ((bt_mesh_network_scan_unprovisioned_device_result_cb)
3689 bt_event_slot_container[event_index].callback)
3690 (_bt_get_error_code(param->result), (bt_mesh_network_h) info,
3691 BT_MESH_SCAN_DEVICE_FOUND, scan_res,
3692 bt_event_slot_container[event_index].user_data);
3694 g_free(scan_res->uuid);
3697 } case BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST: {
3698 BT_INFO("BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST");
3699 bluetooth_mesh_authentication_request_t *auth_req = NULL;
3700 bt_mesh_network_s *info = NULL;
3701 auth_req = (bluetooth_mesh_authentication_request_t *)(param->param_data);
3703 info = _bt_mesh_get_network_handle_info(auth_req->net_uuid);
3707 BT_INFO("Mesh: Authentication request: Type [%d]", auth_req->auth_type);
3708 _bt_mesh_get_auth_string_from_value(auth_req->auth_type);
3709 ((bt_mesh_authentication_request_cb)
3710 bt_event_slot_container[event_index].callback)
3711 (_bt_get_error_code(param->result),
3712 (bt_mesh_authentication_type_e) auth_req->auth_type,
3713 auth_req->auth_value,
3714 bt_event_slot_container[event_index].user_data);
3716 } case BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED: {
3717 BT_INFO("BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED");
3718 bluetooth_mesh_provisioning_result_t *prov_res = NULL;
3719 bt_mesh_network_s *info = NULL;
3720 prov_res = (bluetooth_mesh_provisioning_result_t *)(param->param_data);
3722 info = _bt_mesh_get_network_handle_info(prov_res->net_uuid);
3726 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
3727 BT_INFO("Mesh: Provisioning Result: SUCCESS");
3729 BT_INFO("Mesh: Provisioning Result: FAILED: Reason [%d]",
3732 ((bt_mesh_network_device_provision_cb)
3733 bt_event_slot_container[event_index].callback)
3734 (_bt_get_error_code(param->result),
3735 (bt_mesh_network_h) info, prov_res->dev_uuid,
3736 bt_event_slot_container[event_index].user_data);
3738 } case BLUETOOTH_EVENT_MESH_NODE_BROWSED: {
3739 BT_INFO("BLUETOOTH_EVENT_MESH_NODE_BROWSED");
3740 bluetooth_mesh_node_discover_t *res = NULL;
3741 bt_mesh_network_s *info = NULL;
3742 bt_mesh_node_s *node_s = NULL;
3743 res = (bluetooth_mesh_node_discover_t *)(param->param_data);
3744 BT_INFO("Mesh: Network UUID [%s]", res->net_uuid);
3746 info = _bt_mesh_get_network_handle_info(res->net_uuid);
3750 if (_bt_get_error_code(param->result) == BT_ERROR_NONE) {
3751 BT_INFO("Mesh: Remote Node Browsing: SUCCESS");
3752 node_s = _bt_mesh_remote_node_browsed(res->net_uuid, res->dev_uuid,
3753 res->unicast, res->count);
3754 ((bt_mesh_node_discover_status_cb)
3755 bt_event_slot_container[event_index].callback)
3756 (_bt_get_error_code(param->result), (bt_mesh_network_h) info,
3757 (bt_mesh_node_h) node_s,
3758 bt_event_slot_container[event_index].user_data);
3760 BT_INFO("Mesh: Remote Node Browsing: FAILED");
3761 ((bt_mesh_node_discover_status_cb)
3762 bt_event_slot_container[event_index].callback)
3763 (_bt_get_error_code(param->result), (bt_mesh_network_h) info,
3764 NULL, bt_event_slot_container[event_index].user_data);
3767 } case BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES: {
3768 BT_INFO("BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES");
3769 bluetooth_mesh_node_features_t *res = NULL;
3770 bt_mesh_network_s *network_s = NULL;
3771 bt_mesh_node_s *node_s = NULL;
3772 res = (bluetooth_mesh_node_features_t *)(param->param_data);
3774 network_s = _bt_mesh_get_network_handle_info(res->net_uuid);
3778 node_s = _bt_mesh_remote_node_browsed(res->net_uuid, res->dev_uuid,
3779 res->unicast, res->elem_count);
3783 if (_bt_get_error_code(param->result) == BT_ERROR_NONE) {
3784 BT_INFO("Mesh: Node Vendor Features: SUCCESS");
3785 node_s->features.cid = res->vendor_info.companyid;
3786 node_s->features.pid = res->vendor_info.versionid;
3787 node_s->features.vid = res->vendor_info.vendorid;
3788 node_s->features.crpl = res->vendor_info.crpl;
3790 if (res->features.relay)
3791 node_s->features.features = BT_MESH_FEATURE_RELAY;
3792 if (res->features.proxy)
3793 node_s->features.features |= BT_MESH_FEATURE_PROXY;
3794 if (res->features.frnd)
3795 node_s->features.features |= BT_MESH_FEATURE_FRIEND;
3796 if (res->features.lpn)
3797 node_s->features.features |= BT_MESH_FEATURE_LOWPOWER;
3799 ((bt_mesh_node_features_cb)
3800 bt_event_slot_container[event_index].callback)
3801 (_bt_get_error_code(param->result), (bt_mesh_node_h) node_s,
3802 (bt_mesh_node_features_s*)&node_s->features,
3803 bt_event_slot_container[event_index].user_data);
3805 BT_INFO("Mesh: Node Vendor Features: FAILED");
3806 ((bt_mesh_node_features_cb)
3807 bt_event_slot_container[event_index].callback)
3808 (_bt_get_error_code(param->result), (bt_mesh_node_h) node_s,
3809 NULL, bt_event_slot_container[event_index].user_data);
3812 } case BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED: {
3813 BT_INFO("BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED");
3814 bluetooth_mesh_key_configure_t *res = NULL;
3815 bt_mesh_network_s *info = NULL;
3816 bt_mesh_node_s *node_s = NULL;
3817 bt_mesh_netkey_s *netkey_s = NULL;
3818 bt_mesh_appkey_s *appkey_s = NULL;
3819 res = (bluetooth_mesh_key_configure_t *)(param->param_data);
3821 info = _bt_mesh_get_network_handle_info(res->net_uuid);
3825 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
3826 BT_INFO("Mesh: Node Key Cofiguration: SUCCESS");
3828 BT_INFO("Mesh: Node Key Cofiguration: FAILED");
3829 node_s = _bt_mesh_get_node_from_unicast(res->net_uuid,
3830 res->primary_unicast);
3832 BT_ERR("Mesh: Node not found in Network!! Unexpected!!");
3835 /* Handle NetKey configuration events */
3836 if (res->is_netkey == true) {
3837 netkey_s = _bt_mesh_handle_node_netkey_configure(info, node_s,
3839 (bt_mesh_node_key_configuration_e)res->op);
3841 ((bt_mesh_netkey_status_cb)bt_event_slot_container[event_index].callback)
3842 (_bt_get_error_code(param->result), (bt_mesh_node_key_configuration_e)res->op,
3843 (bt_mesh_node_h) node_s, (bt_mesh_netkey_h) netkey_s,
3844 bt_event_slot_container[event_index].user_data);
3845 /* Handle AppKey configuration events */
3847 appkey_s = _bt_mesh_handle_node_appkey_configure(info, node_s, res->netkey_idx,
3848 res->appkey_idx, (bt_mesh_node_key_configuration_e)res->op);
3850 ((bt_mesh_appkey_status_cb)
3851 bt_event_slot_container[event_index].callback)
3852 (_bt_get_error_code(param->result),
3853 (bt_mesh_node_key_configuration_e)res->op,
3854 (bt_mesh_node_h) node_s, (bt_mesh_netkey_h) netkey_s,
3855 (bt_mesh_appkey_h) appkey_s,
3856 bt_event_slot_container[event_index].user_data);
3859 } case BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED: {
3860 BT_INFO("BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED");
3861 bluetooth_mesh_node_ttl_info_t *res = NULL;
3862 bt_mesh_network_s *info = NULL;
3863 bt_mesh_node_s *node_s = NULL;
3864 bt_mesh_node_ttl_operation_e ttl_op;
3865 res = (bluetooth_mesh_node_ttl_info_t *)(param->param_data);
3866 BT_INFO("Mesh: Network UUID [%s]", res->net_uuid);
3868 info = _bt_mesh_get_network_handle_info(res->net_uuid);
3871 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
3872 BT_INFO("Mesh: Node TTL configure [%s]: SUCCESS",
3873 res->is_set ? "Set" : "Get");
3875 BT_INFO("Mesh: Node TTL configure [%s]: FAILED",
3876 res->is_set ? "Set" : "Get");
3878 node_s = _bt_mesh_get_node_from_unicast(res->net_uuid, res->unicast);
3881 ttl_op = res->is_set ? BT_MESH_TTL_SET : BT_MESH_TTL_GET;
3882 ((bt_mesh_node_ttl_cb)
3883 bt_event_slot_container[event_index].callback)
3884 (_bt_get_error_code(param->result), (bt_mesh_node_h) node_s,
3886 bt_event_slot_container[event_index].user_data);
3889 case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND: {
3890 BT_INFO("BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND");
3891 bluetooth_mesh_model_configure_t *res = NULL;
3892 bt_mesh_model_s *model_s = NULL;
3893 bt_mesh_appkey_s *appkey_s = NULL;
3894 bt_mesh_network_s *network_s = NULL;
3895 res = (bluetooth_mesh_model_configure_t *)(param->param_data);
3897 network_s = _bt_mesh_get_network_handle_info(res->net_uuid);
3901 BT_INFO("Mesh: Model AppKey %s Result", res->is_bind ? "Bind" : "UnBind");
3902 model_s = _bt_mesh_get_node_get_model_from_element(res->net_uuid,
3903 res->primary_unicast, res->elem_index, res->model);
3907 appkey_s = _bt_mesh_network_get_appkey_from_index(network_s, res->appkey_idx);
3911 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
3912 BT_INFO("Mesh: Model AppKey Configuration: SUCCESS");
3914 BT_INFO("Mesh: Model AppKey Configuration: FAILED");
3917 ((bt_mesh_model_bind_cb)
3918 bt_event_slot_container[event_index].callback)
3919 (_bt_get_error_code(param->result),
3920 (bt_mesh_model_h) model_s,
3921 (bt_mesh_appkey_h) appkey_s,
3922 bt_event_slot_container[event_index].user_data);
3924 ((bt_mesh_model_unbind_cb)
3925 bt_event_slot_container[event_index].callback)
3926 (_bt_get_error_code(param->result),
3927 (bt_mesh_model_h) model_s,
3928 (bt_mesh_appkey_h)appkey_s,
3929 bt_event_slot_container[event_index].user_data);
3933 case BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED:
3934 case BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED: {
3935 BT_INFO("BLUETOOTH_EVENT_MESH_SUBSCRIPTION_CONFIGURED");
3936 bluetooth_mesh_model_configure_t *res = NULL;
3937 bt_mesh_network_s *network_s = NULL;
3938 bt_mesh_node_s *node_s = NULL;
3939 bt_mesh_element_s *element_s = NULL;
3940 bt_mesh_group_s *group_s = NULL;
3941 bt_mesh_model_s *model_s = NULL;
3942 bt_mesh_model_subscription_op_e sub_op;
3943 res = (bluetooth_mesh_model_configure_t *)(param->param_data);
3945 network_s = _bt_mesh_get_network_handle_info(res->net_uuid);
3949 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
3950 BT_INFO("Mesh: Model Subscription Configuration: SUCCESS");
3952 BT_INFO("Mesh: Model Subscription Configuration: FAILED");
3954 node_s = _bt_mesh_get_node_from_unicast(res->net_uuid,
3955 res->primary_unicast);
3959 element_s = _bt_mesh_get_node_get_element_from_index(res->net_uuid,
3960 res->primary_unicast, res->elem_index);
3963 model_s = _bt_mesh_get_node_get_model_from_element(res->net_uuid,
3964 res->primary_unicast, res->elem_index, res->model);
3967 group_s = _bt_mesh_get_group_from_sub(network_s,
3968 model_s, res->op, res->sub_addr);
3971 if (sub_op == BT_MESH_MODEL_SUBSCRIPTION_DELETE_ALL)
3972 ((bt_mesh_model_subscription_op_cb)
3973 bt_event_slot_container[event_index].callback)
3974 (_bt_get_error_code(param->result), sub_op,
3975 (bt_mesh_model_h) model_s, NULL,
3976 bt_event_slot_container[event_index].user_data);
3978 ((bt_mesh_model_subscription_op_cb)
3979 bt_event_slot_container[event_index].callback)
3980 (_bt_get_error_code(param->result), sub_op,
3981 (bt_mesh_model_h) model_s, (bt_mesh_group_h) group_s,
3982 bt_event_slot_container[event_index].user_data);
3985 case BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS: {
3986 BT_INFO("BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS");
3987 bluetooth_mesh_model_configure_t *res = NULL;
3988 bt_mesh_network_s *network_s = NULL;
3989 bt_mesh_group_s *group_s = NULL;
3990 bt_mesh_appkey_s *appkey_s = NULL;
3991 bt_mesh_model_s *model_s = NULL;
3992 res = (bluetooth_mesh_model_configure_t *)(param->param_data);
3994 network_s = _bt_mesh_get_network_handle_info(res->net_uuid);
3998 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
3999 BT_INFO("Mesh: Model Publication Status: SUCCESS");
4001 BT_INFO("Mesh: Model Publication Status: FAILED");
4003 BT_INFO("Mesh: AppKey Index [0x%2.2x]", res->appkey_idx);
4004 BT_INFO("Mesh: Model ID[0x%4.4x]", res->model);
4006 appkey_s = _bt_mesh_network_get_appkey_from_index(network_s, res->appkey_idx);
4010 model_s = _bt_mesh_get_node_get_model_from_element(res->net_uuid,
4011 res->primary_unicast, res->elem_index, res->model);
4014 model_s->pub_addr = res->pub_addr;
4015 BT_INFO("Mesh: Model Publication address [0x%2.2x]", model_s->pub_addr);
4016 group_s = _bt_mesh_network_get_group(network_s, res->pub_addr);
4018 /* Exception is Unassigned address */
4019 if (!group_s && res->pub_addr == 0x0000) {
4020 BT_INFO("Mesh: Model Publication Group is set to Unassigned");
4021 ((bt_mesh_model_publication_status_cb)
4022 bt_event_slot_container[event_index].callback)
4023 (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
4024 NULL, (bt_mesh_appkey_h) appkey_s,
4025 bt_event_slot_container[event_index].user_data);
4027 BT_INFO("Mesh: Send Model Publication Status event");
4028 ((bt_mesh_model_publication_status_cb)
4029 bt_event_slot_container[event_index].callback)
4030 (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
4031 (bt_mesh_group_h) group_s, (bt_mesh_appkey_h) appkey_s,
4032 bt_event_slot_container[event_index].user_data);
4036 case BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST: {
4037 BT_INFO("BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST");
4038 bluetooth_mesh_model_configure_t *res = NULL;
4039 bt_mesh_network_s *info = NULL;
4040 bt_mesh_node_s *node_s = NULL;
4041 bt_mesh_model_s *model_s;
4042 bt_mesh_element_s *element_s;
4043 GSList *appkeylist = NULL;
4045 res = (bluetooth_mesh_model_configure_t *)(param->param_data);
4046 BT_INFO("Mesh: Model AppKey List result for Network [%s]",
4049 info = _bt_mesh_get_network_handle_info(res->net_uuid);
4052 model_s = _bt_mesh_get_node_get_model_from_element(res->net_uuid,
4053 res->primary_unicast, res->elem_index, res->model);
4057 element_s = model_s->parent;
4058 node_s = element_s->parent;
4060 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
4061 BT_INFO("Mesh: Node Model AppKeyList: SUCCESS");
4063 BT_INFO("Mesh: Node Model AppKeyList : FAILED");
4065 total = res->appkeylist_count;
4066 BT_INFO("Mesh: Total Appkeys Bound to Model [%d]", total);
4068 for (int i = 0; i < total; i++) {
4069 bt_mesh_appkey_s *appkey;
4070 appkey = _bt_mesh_node_get_appkey(node_s, *res->appkey_list[i]);
4072 BT_INFO("Mesh: AppKey found for Index [%d]", *res->appkey_list[i]);
4073 appkeylist = g_slist_append(appkeylist, appkey);
4077 ((bt_mesh_model_appkey_list_cb)
4078 bt_event_slot_container[event_index].callback)
4079 (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
4081 bt_event_slot_container[event_index].user_data);
4084 case BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST: {
4085 BT_INFO("BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST");
4086 bluetooth_mesh_model_configure_t *res = NULL;
4087 bt_mesh_network_s *network_s = NULL;
4088 bt_mesh_node_s *node_s = NULL;
4089 bt_mesh_model_s *model_s;
4090 bt_mesh_element_s *element_s;
4091 GSList *sublist = NULL;
4093 res = (bluetooth_mesh_model_configure_t *)(param->param_data);
4095 network_s = _bt_mesh_get_network_handle_info(res->net_uuid);
4099 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
4100 BT_INFO("Mesh: Node Model Subscription List: SUCCESS");
4102 BT_INFO("Mesh: Node Model Subscription List: FAILED");
4104 node_s = _bt_mesh_get_node_from_unicast(res->net_uuid,
4105 res->primary_unicast);
4109 element_s = _bt_mesh_get_element_from_index(node_s, res->elem_index);
4112 model_s = _bt_mesh_get_model_from_modelid(element_s, res->model);
4115 total = res->sublist_count;
4116 BT_INFO("Total Subscription in the model [%d]", total);
4118 for (int i = 0; i < total; i++) {
4119 bt_mesh_group_s *group_s;
4120 group_s = _bt_mesh_network_get_group(network_s, *res->sub_list[i]);
4122 BT_INFO("Mesh: Subscription address [0x%2.2x]", *res->sub_list[i]);
4125 sublist = g_slist_append(sublist, group_s);
4127 ((bt_mesh_model_subscription_list_cb)
4128 bt_event_slot_container[event_index].callback)
4129 (_bt_get_error_code(param->result), (bt_mesh_model_h) model_s,
4131 bt_event_slot_container[event_index].user_data);
4133 } case BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED: {
4134 BT_INFO("BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED");
4135 bluetooth_mesh_model_msg_t *res = NULL;
4136 bt_mesh_network_s *info = NULL;
4137 bt_mesh_element_s *element_s = NULL;
4138 bt_mesh_appkey_s *appkey_s = NULL;
4139 bt_mesh_model_msg_params_s *msg = NULL;
4140 res = (bluetooth_mesh_model_msg_t *)(param->param_data);
4142 info = _bt_mesh_get_network_handle_info(res->net_uuid);
4146 if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
4147 BT_INFO("Mesh: Node Model Message execution: SUCCESS");
4149 BT_INFO("Mesh: Node Model Message execution: Failed");
4151 /* Get Element info */
4152 element_s = _bt_mesh_get_node_get_element_from_index(res->net_uuid,
4153 res->primary_unicast, res->elem_index);
4155 /* In case of group message, element may not be found */
4156 BT_INFO("Mesh: Element not found in Network!!");
4159 /* Get appkey info */
4160 appkey_s = _bt_mesh_network_get_appkey_from_index(info, res->appkey_idx);
4162 msg = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
4163 BT_DBG("Mesh: Msg opcode: 0x%4.4X", res->opcode);
4164 msg->opcode = res->opcode;
4165 if (res->msg_len > 0) {
4166 msg->data = g_memdup(res->msg, res->msg_len + 1);
4167 BT_DBG("Mesh: msg %s", msg->data);
4170 ((bt_mesh_model_msg_cb)bt_event_slot_container[event_index].callback)
4171 (_bt_get_error_code(param->result), (bt_mesh_element_h) element_s,
4172 (bt_mesh_appkey_h) appkey_s, msg,
4173 bt_event_slot_container[event_index].user_data);
4177 BT_INFO("Unknown function");
4181 /* LCOV_EXCL_STOP */
4183 static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void *user_data)
4185 bt_adapter_le_device_scan_result_info_s *scan_info = NULL;
4186 int event_index = -1;
4188 event_index = __bt_get_cb_index(event);
4189 if (event == BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND)
4190 BT_DBG("Need to check 2 slots in the case");
4191 else if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL)
4195 case BLUETOOTH_EVENT_LE_ENABLED:
4196 BT_INFO("BLUETOOTH_EVENT_LE_ENABLED"); /* LCOV_EXCL_LINE */
4197 ((bt_adapter_le_state_changed_cb) bt_event_slot_container[event_index].callback) /* LCOV_EXCL_LINE */
4198 (_bt_get_error_code(param->result), BT_ADAPTER_LE_ENABLED, bt_event_slot_container[event_index].user_data);
4200 case BLUETOOTH_EVENT_LE_DISABLED:
4201 BT_INFO("BLUETOOTH_EVENT_LE_DISABLED"); /* LCOV_EXCL_LINE */
4202 ((bt_adapter_le_state_changed_cb) bt_event_slot_container[event_index].callback) /* LCOV_EXCL_LINE */
4203 (_bt_get_error_code(param->result), BT_ADAPTER_LE_DISABLED, bt_event_slot_container[event_index].user_data);
4205 case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
4206 event_index = BT_EVENT_LE_SCAN_RESULT_UPDATED;
4207 if (bt_event_slot_container[event_index].callback != NULL) {
4208 if (__bt_get_bt_adapter_le_device_scan_info_s(&scan_info, (bluetooth_le_device_info_t *)(param->param_data)) == BT_ERROR_NONE) {
4209 ((bt_adapter_le_scan_result_cb)bt_event_slot_container[event_index].callback)
4210 (_bt_get_error_code(param->result), scan_info, bt_event_slot_container[event_index].user_data);
4212 ((bt_adapter_le_scan_result_cb)bt_event_slot_container[event_index].callback)
4213 (_bt_get_error_code(param->result), NULL, bt_event_slot_container[event_index].user_data);
4216 /* TDS Provider Search: Uses Scan Info */
4217 if (bt_event_slot_container[BT_EVENT_TDS_PROVIDER_FOUND_RESULT].callback != NULL) {
4222 if (__bt_get_bt_adapter_le_device_scan_info_s(&scan_info,
4223 (bluetooth_le_device_info_t *)(param->param_data)) != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
4227 _bt_get_ad_data_by_type((char*)scan_info->adv_data, scan_info->adv_data_len,
4228 BT_ADAPTER_LE_ADVERTISING_DATA_TRANSPORT_DISCOVERY,
4231 BT_DBG("TDS Service available Data length[%d]", data_len);
4232 bt_tds_transport_block_list_s *info = g_malloc0(sizeof(bt_tds_transport_block_list_s));
4234 if (_bt_tds_parse_transport_blocks(&info, data, data_len) == BT_ERROR_NONE) {
4235 ((bt_tds_provider_scan_result_cb)bt_event_slot_container[BT_EVENT_TDS_PROVIDER_FOUND_RESULT].callback) /* LCOV_EXCL_LINE */
4236 (_bt_get_error_code(param->result),
4237 scan_info->remote_address, info,
4239 bt_event_slot_container[BT_EVENT_TDS_PROVIDER_FOUND_RESULT].user_data);
4241 __bt_free_tds_scan_result_info_s(info);
4248 __bt_free_bt_adapter_le_device_scan_info_s(scan_info);
4255 /* LCOV_EXCL_START */
4256 static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info)
4260 BT_CHECK_INPUT_PARAMETER(source_info);
4262 *discovery_info = (bt_adapter_device_discovery_info_s *)malloc(sizeof(bt_adapter_device_discovery_info_s));
4263 if (*discovery_info == NULL)
4264 return BT_ERROR_OUT_OF_MEMORY;
4266 if (strlen(source_info->device_name.name) > 0)
4267 (*discovery_info)->remote_name = strdup(source_info->device_name.name);
4269 (*discovery_info)->remote_name = NULL;
4271 _bt_convert_address_to_string(&((*discovery_info)->remote_address), &(source_info->device_address));
4273 (*discovery_info)->bt_class.major_device_class = source_info->device_class.major_class;
4274 (*discovery_info)->bt_class.minor_device_class = source_info->device_class.minor_class;
4275 (*discovery_info)->bt_class.major_service_class_mask = source_info->device_class.service_class;
4277 if (source_info->service_index > 0) {
4278 (*discovery_info)->service_uuid = (char **)malloc(sizeof(char *) *source_info->service_index);
4279 if ((*discovery_info)->service_uuid != NULL) {
4280 for (i = 0; i < source_info->service_index; i++) {
4281 (*discovery_info)->service_uuid[i] = strdup(source_info->uuids[i]);
4282 if ((*discovery_info)->service_uuid[i] != NULL)
4283 __bt_convert_lower_to_upper((*discovery_info)->service_uuid[i]);
4288 (*discovery_info)->service_uuid = NULL;
4290 (*discovery_info)->service_count = source_info->service_index;
4292 (*discovery_info)->rssi = (int)source_info->rssi;
4293 (*discovery_info)->is_bonded = (bool)source_info->paired;
4295 (*discovery_info)->appearance = 0;
4297 (*discovery_info)->manufacturer_data_len = source_info->manufacturer_data.data_len;
4298 if ((*discovery_info)->manufacturer_data_len > 0) {
4299 (*discovery_info)->manufacturer_data = malloc(source_info->manufacturer_data.data_len);
4300 memcpy((*discovery_info)->manufacturer_data, source_info->manufacturer_data.data, source_info->manufacturer_data.data_len);
4302 (*discovery_info)->manufacturer_data = NULL;
4305 return BT_ERROR_NONE;
4308 static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info)
4312 if (discovery_info == NULL)
4315 if (discovery_info->remote_name != NULL)
4316 free(discovery_info->remote_name);
4318 if (discovery_info->remote_address != NULL)
4319 free(discovery_info->remote_address);
4321 if (discovery_info->service_uuid != NULL) {
4322 for (i = 0; i < discovery_info->service_count; i++) {
4323 if (discovery_info->service_uuid[i] != NULL)
4324 free(discovery_info->service_uuid[i]);
4326 free(discovery_info->service_uuid);
4328 if (discovery_info->manufacturer_data != NULL)
4329 free(discovery_info->manufacturer_data);
4331 free(discovery_info);
4332 discovery_info = NULL;
4335 static int __bt_get_bt_adapter_le_device_scan_info_s(
4336 bt_adapter_le_device_scan_result_info_s **scan_info,
4337 bluetooth_le_device_info_t *source_info)
4340 BT_CHECK_INPUT_PARAMETER(source_info);
4342 *scan_info = (bt_adapter_le_device_scan_result_info_s *)malloc(sizeof(bt_adapter_le_device_scan_result_info_s));
4343 if (*scan_info == NULL)
4344 return BT_ERROR_OUT_OF_MEMORY;
4346 _bt_convert_address_to_string(&((*scan_info)->remote_address), &(source_info->device_address));
4348 if (source_info->addr_type == 0x02)
4349 (*scan_info)->address_type = BT_DEVICE_RANDOM_ADDRESS;
4351 (*scan_info)->address_type = BT_DEVICE_PUBLIC_ADDRESS; /* LCOV_EXCL_LINE */
4352 (*scan_info)->rssi = (int)source_info->rssi;
4353 (*scan_info)->adv_data_len = source_info->adv_ind_data.data_len;
4354 if ((*scan_info)->adv_data_len > 0) {
4355 (*scan_info)->adv_data = malloc(source_info->adv_ind_data.data_len);
4356 memcpy((*scan_info)->adv_data, source_info->adv_ind_data.data.data, source_info->adv_ind_data.data_len);
4358 (*scan_info)->adv_data = NULL; /* LCOV_EXCL_LINE */
4361 (*scan_info)->scan_data_len = source_info->scan_resp_data.data_len;
4362 if ((*scan_info)->scan_data_len > 0) {
4363 (*scan_info)->scan_data = malloc(source_info->scan_resp_data.data_len); /* LCOV_EXCL_LINE */
4364 memcpy((*scan_info)->scan_data, source_info->scan_resp_data.data.data, source_info->scan_resp_data.data_len); /* LCOV_EXCL_LINE */
4366 (*scan_info)->scan_data = NULL;
4369 return BT_ERROR_NONE;
4373 static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s *scan_info)
4375 if (scan_info == NULL)
4378 if (scan_info->remote_address != NULL)
4379 free(scan_info->remote_address);
4381 if (scan_info->adv_data != NULL)
4382 free(scan_info->adv_data);
4383 if (scan_info->scan_data != NULL)
4384 free(scan_info->scan_data);
4390 static void __bt_free_tds_scan_result_info_s(bt_tds_transport_block_list_s *discovery_info)
4394 if (discovery_info == NULL)
4397 for (k = 0; k < discovery_info->num_transport_block; k++) {
4398 g_free(discovery_info->data[k]->data);
4399 g_free(discovery_info->data[k]);
4402 g_free(discovery_info);
4403 discovery_info = NULL;
4407 /* LCOV_EXCL_STOP */
4408 static int __bt_get_cb_index(int event)
4412 for (i = 0; event2index[i].event != 0; i++) {
4413 if (event2index[i].event == event)
4414 return event2index[i].index;
4417 return -1; /* LCOV_EXCL_LINE */
4420 /* LCOV_EXCL_START */
4421 static void __bt_convert_lower_to_upper(char *origin)
4423 int length = strlen(origin);
4426 for (i = 0; i < length; i++) {
4427 if (islower(origin[i]))
4428 origin[i] = toupper(origin[i]);
4431 /* LCOV_EXCL_STOP */
4433 tizen_profile_t profile = _PROFILE_UNKNOWN;
4434 tizen_profile_t _get_tizen_profile()
4436 char *profileName = NULL;
4438 if (__builtin_expect(profile != _PROFILE_UNKNOWN, 1))
4441 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
4443 return _PROFILE_UNKNOWN;
4445 switch (*profileName) {
4448 profile = _PROFILE_MOBILE;
4452 profile = _PROFILE_WEARABLE;
4456 profile = _PROFILE_TV;
4460 if (!strncasecmp(profileName, "ivi", 3))
4461 profile = _PROFILE_IVI;
4462 else if (!strncasecmp(profileName, "iot", 3))
4463 profile = _PROFILE_IOT;
4465 profile = _PROFILE_COMMON;
4467 default: // common or unknown ==> ALL ARE COMMON.
4468 profile = _PROFILE_COMMON;