2 * Copyright (c) 2015 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Anupam Roy <anupam.r@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include <vconf-internal-keys.h>
28 #include <bundle_internal.h>
29 #include <eventsystem.h>
31 /*bt-service headers */
32 #include "bt-internal-types.h"
33 #include "bt-request-handler.h"
34 #include "bt-service-a2dp-src.h"
35 #include "bt-service-a2dp-sink.h"
36 #include "bt-service-agent-util.h"
37 #include "bt-service-core-adapter.h"
38 #include "bt-service-core-adapter-le.h"
39 #include "bt-service-core-device.h"
40 #include "bt-service-common.h"
41 #include "bt-service-device-internal.h"
42 #include "bt-service-event.h"
43 #include "bt-service-event-receiver.h"
44 #include "bt-service-gatt.h"
45 #include "bt-service-headset-connection.h"
46 #include "bt-service-main.h"
47 #ifdef TIZEN_MDM_ENABLE
48 #include "bt-service-mdm.h"
50 #ifdef TIZEN_FEATURE_BT_OBEX
51 #include "bt-service-obex-server.h"
53 #include "bt-service-util.h"
56 #include <oal-event.h>
57 #include <oal-manager.h>
58 #include <oal-adapter-mgr.h>
59 #include <oal-device-mgr.h>
61 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
62 #define MAX_BOND_RETRY_COUNT 3
64 #define BT_PASSKEY_MAX_LENGTH 4
66 #define BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT 6000 /* msec */
68 #define BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL 30 /* msec */
69 #define BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL 50 /* msec */
70 #define BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY 0 /* event */
72 #define BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL 10 /* msec */
73 #define BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL 30 /* msec */
74 #define BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY 0 /* event */
76 #define BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL 80 /* msec */
77 #define BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL 100 /* msec */
78 #define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY 2 /* event */
80 /* Bonding Info structure */
85 unsigned short conn_type;
86 gboolean is_cancelled_by_user;
87 gboolean is_device_creating;
88 bluetooth_device_address_t *dev_addr;
89 bt_remote_dev_info_t *dev_info;
92 /* Searching Info structure */
96 gboolean is_cancelled_by_user;
97 bluetooth_device_address_t *dev_addr;
98 bt_remote_dev_info_t *dev_info;
99 } bt_service_search_info_data_t;
101 /* Pairing Info structure */
104 gboolean is_autopair;
109 char addr[BT_ADDRESS_STRING_SIZE];
110 bt_remote_dev_info_t *dev_info;
111 } bt_incoming_bond_data_t;
113 /* Bonding and Pairing Informations */
114 static bt_bond_data_t *trigger_bond_info;
115 static bt_bond_data_t *trigger_unbond_info;
116 static bt_pairing_data_t *trigger_pairing_info;
117 static bt_service_search_info_data_t *service_search_info;
119 static bt_incoming_bond_data_t *incoming_bond_info;
122 BT_DEVICE_BOND_STATE_NONE,
123 BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY,
124 BT_DEVICE_BOND_STATE_DISCOVERY_CANCELLED,
125 BT_DEVICE_BOND_STATE_REMOVE_BONDING,
126 BT_DEVICE_BOND_STATE_REMOVED_BONDING,
127 BT_DEVICE_BOND_STATE_STARTED,
128 BT_DEVICE_BOND_STATE_WAIT_PROP,
129 BT_DEVICE_BOND_STATE_WAIT_DID
134 BT_DEVICE_INCOMING_BOND_INFO,
135 BT_DEVICE_UNBOND_INFO
138 /* BT device bond state variable */
139 static bt_bond_state_e bt_device_bond_state;
140 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
141 static int bond_retry_count;
144 static char *passkey_watcher;
145 static GSList *pin_info_list = NULL;
147 /** DBFW+ Event Code */
149 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_INFO = 0x10,
150 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_CLOCK_INFO = 0x11,
151 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_PAGE_SLOTS = 0x12,
152 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_LMP_TRACE = 0x13,
153 BT_DBFW_PLUS_EVENT_CODE_A2DP_INFO = 0x20,
154 BT_DBFW_PLUS_EVENT_CODE_HFP_INFO = 0x31,
155 BT_DBFW_PLUS_EVENT_CODE_HFP_SCO_PACKET_TYPE_INFO = 0x32,
156 } bt_dbfw_plus_event_code_t;
158 static int dbfw_rssi;
165 } bt_connected_le_dev_t;
174 } bt_le_conn_param_t;
176 static GSList *le_connected_dev_list = NULL;
178 #define BT_LE_CONN_INTERVAL_MIN 7.5 /* msec */
179 #define BT_LE_CONN_INTERVAL_MAX 4000 /* msec */
180 #define BT_LE_CONN_SUPER_TO_MIN 100 /* msec */
181 #define BT_LE_CONN_SUPER_TO_MAX 32000 /* msec */
182 #define BT_LE_CONN_SLAVE_LATENCY_MAX 499
183 #define BT_LE_CONN_TO_SPLIT 10 /* msec */
184 #define BT_LE_CONN_INTERVAL_SPLIT 1.25 /* msec */
186 static void _bt_handle_le_connected_dev_info(const char *address, gboolean connected);
188 /* Forward declaration */
189 static void __bt_device_event_handler(int event_type, gpointer event_data);
190 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble);
193 static int __bt_device_handle_bond_state(void);
194 static void __bt_free_bond_info(uint8_t type);
195 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info);
196 static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr);
197 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr);
198 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event);
199 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond);
200 static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
201 gboolean connected, unsigned char type);
202 static void __bt_free_pairing_info(bt_pairing_data_t **p_info);
204 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info);
205 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event);
206 static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_info);
207 static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *dev_info);
208 static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info);
209 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event);
211 static void __bt_device_services_callback(event_dev_services_t* uuid_list);
212 static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remote_dev_info);
214 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info);
216 static int __bt_get_device_pin_code(const char *address, char *pin_code);
217 static gboolean __bt_ignore_auto_pairing_request(const char *address);
219 gboolean _bt_is_device_creating(void)
221 if (!trigger_bond_info)
223 return trigger_bond_info->is_device_creating;
226 void _bt_device_state_handle_callback_set_request(void)
228 _bt_service_register_event_handler_callback(
229 BT_DEVICE_MODULE, __bt_device_event_handler);
232 void __bt_device_handle_pending_requests(int result, int service_function,
233 void *user_data, unsigned int size)
237 invocation_info_t *req_info = NULL;
241 /* Get method invocation context */
242 for (l = _bt_get_invocation_list(); l != NULL; ) {
245 if (req_info == NULL || req_info->service_function != service_function)
248 switch (service_function) {
249 case BT_SEARCH_SERVICE: {
250 char *address = (char *)user_data;
251 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
252 BT_ERR("Unexpected: Info request pending for a different address!!");
255 BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
256 bt_sdp_info_t sdp_info;
258 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
259 _bt_convert_addr_string_to_type(sdp_info.device_addr.addr, address);
261 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
262 g_array_append_vals(out_param, &sdp_info, sizeof(bt_sdp_info_t));
263 _bt_service_method_return(req_info->context, out_param, result);
265 _bt_free_info_from_invocation_list(req_info);
266 g_array_free(out_param, TRUE);
270 case BT_BOND_DEVICE: {
271 char *address = (char *)user_data;
272 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
273 BT_ERR("Unexpected: Info request pending for a different address!!");
276 BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
277 bluetooth_device_info_t dev_info;
278 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
279 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
281 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
282 g_array_append_vals(out_param, &dev_info,
283 sizeof(bluetooth_device_info_t));
284 _bt_service_method_return(req_info->context, out_param, result);
286 _bt_free_info_from_invocation_list(req_info);
287 g_array_free(out_param, TRUE);
291 case BT_UNBOND_DEVICE: {
292 char *address = (char *)user_data;
293 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
294 BT_ERR("Unexpected: Info request pending for a different address!!");
297 BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
298 bluetooth_device_address_t dev_addr;
299 _bt_convert_addr_string_to_type(dev_addr.addr, address);
300 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
301 g_array_append_vals(out_param, &dev_addr,
302 sizeof(bluetooth_device_address_t));
303 _bt_service_method_return(req_info->context, out_param, result);
305 _bt_free_info_from_invocation_list(req_info);
306 g_array_free(out_param, TRUE);
311 BT_ERR("Unhandled case");
319 * Remote device properties are received on all following conditions
320 * a. When Bonding in on-going
321 * b. When device properties are updated\changed for a connected device
322 * (due to SDP or any other reason)
324 static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_dev_props)
326 bt_remote_dev_info_t *rem_info = NULL;
328 rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
329 _bt_copy_remote_dev(rem_info, &(oal_dev_props->device_info));
331 if (oal_dev_props->adv_len > 0) {
334 rem_info->manufacturer_data_len = oal_dev_props->adv_len;
335 rem_info->manufacturer_data =
336 g_memdup(oal_dev_props->adv_data,
337 oal_dev_props->adv_len);
338 BT_DBG("----Advertising Data Length: %d",
339 rem_info->manufacturer_data_len);
341 for (k = 0; k < rem_info->manufacturer_data_len; k++) {
342 BT_INFO("Check data[%d] = [[0x%x]",
343 k, oal_dev_props->adv_data[k]);
346 rem_info->manufacturer_data = NULL;
347 rem_info->manufacturer_data_len = 0;
350 /* a. Check if bonding is on-going, if yes, we MUST update the bonding device properties */
351 if (trigger_bond_info && !strcmp(trigger_bond_info->addr, rem_info->address)) {
352 BT_DBG("Bonding is ongoing, try update properties");
353 if (!trigger_bond_info->dev_info ||
354 (!trigger_bond_info->dev_info->name &&
355 !trigger_bond_info->dev_info->alias) ||
356 !trigger_bond_info->dev_info->address ||
357 trigger_bond_info->dev_info->uuid_count == 0) {
358 BT_DBG("Complete data is not present, Assigning rem_info");
359 if (!trigger_bond_info->dev_info)
360 trigger_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
361 _bt_copy_remote_dev_info(trigger_bond_info->dev_info, rem_info);
364 BT_DBG("Bonding dev addr has matched with remote dev properties address [%s]", rem_info->address);
365 __bt_handle_ongoing_bond(trigger_bond_info->dev_info, FALSE);
366 } else if (incoming_bond_info && !g_strcmp0(incoming_bond_info->addr, rem_info->address)) {
367 BT_DBG("Incoming Bond is ongoing, try update properties");
368 if (!incoming_bond_info->dev_info ||
369 (!incoming_bond_info->dev_info->name &&
370 !incoming_bond_info->dev_info->alias) ||
371 !incoming_bond_info->dev_info->address ||
372 incoming_bond_info->dev_info->uuid_count == 0) {
373 BT_DBG("Complete data is not present, Assigning rem_info");
374 if (!incoming_bond_info->dev_info)
375 incoming_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
376 _bt_copy_remote_dev_info(incoming_bond_info->dev_info, rem_info);
379 BT_DBG("Incoming Bond addr matches with remote dev properties address [%s]", rem_info->address);
380 __bt_handle_ongoing_bond(incoming_bond_info->dev_info, TRUE);
383 /* Add device to bonded list */
384 _bt_service_add_device_to_bonded_list(rem_info);
386 /* Handle SDP Device properties update */
387 if (service_search_info && service_search_info->dev_info) {
388 if (!strcmp(service_search_info->addr, rem_info->address)) {
389 BT_DBG("Properties received and SDP request pending, fill device properties and send event");
390 service_search_info->dev_info->class = rem_info->class;
391 service_search_info->dev_info->paired = rem_info->paired;
392 service_search_info->dev_info->connected = rem_info->connected;
393 service_search_info->dev_info->rssi = rem_info->rssi;
394 service_search_info->dev_info->addr_type = rem_info->addr_type;
395 service_search_info->dev_info->trust = rem_info->trust;
398 service_search_info->dev_info->manufacturer_data = NULL;
399 service_search_info->dev_info->manufacturer_data_len = 0;
401 __bt_handle_ongoing_device_service_search(service_search_info->dev_info);
405 _bt_free_remote_dev(rem_info);
408 static int __get_oal_trusted_profile(bluetooth_trusted_profile_t profile)
411 case TRUSTED_PROFILE_PBAP:
412 return OAL_TRUSTED_PROFILE_PBAP;
413 case TRUSTED_PROFILE_MAP:
414 return OAL_TRUSTED_PROFILE_MAP;
415 case TRUSTED_PROFILE_SAP:
416 return OAL_TRUSTED_PROFILE_SAP;
417 case TRUSTED_PROFILE_HFP_HF:
418 return OAL_TRUSTED_PROFILE_HFP_HF;
419 case TRUSTED_PROFILE_A2DP:
420 return OAL_TRUSTED_PROFILE_A2DP;
421 case TRUSTED_PROFILE_ALL:
422 return OAL_TRUSTED_PROFILE_ALL;
428 int _bt_set_trust_profile(bluetooth_device_address_t *addr,
429 bluetooth_trusted_profile_t profile, gboolean trust)
432 bt_address_t bd_addr;
433 oal_trusted_profile_e oal_profile;
437 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
439 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
440 oal_profile = __get_oal_trusted_profile(profile);
441 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
443 result = device_set_trust_profile(&bd_addr, oal_profile, trust);
444 if (result != OAL_STATUS_SUCCESS) {
445 BT_ERR("device_set_trust_profile error: [%d]", result);
446 return _bt_convert_oal_status_to_bt_error(result);
450 return BLUETOOTH_ERROR_NONE;
453 int _bt_get_trust_profile(bluetooth_device_address_t *addr,
454 bluetooth_trusted_profile_t profile, guint *trust)
457 bt_address_t bd_addr;
458 oal_trusted_profile_e oal_profile;
462 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
464 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
465 oal_profile = __get_oal_trusted_profile(profile);
466 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
468 result = device_get_trust_profile(&bd_addr, oal_profile, trust);
469 if (result != OAL_STATUS_SUCCESS) {
470 BT_ERR("device_set_trust_profile error: [%d]", result);
471 return _bt_convert_oal_status_to_bt_error(result);
475 return BLUETOOTH_ERROR_NONE;
478 static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remote_dev_info)
480 GVariant *param = NULL;
481 GVariant *uuids = NULL;
482 GVariantBuilder *builder = NULL;
483 GVariant *manufacturer_data;
487 BT_INFO("Send Service Search request event");
489 if (remote_dev_info->alias)
490 name = remote_dev_info->alias;
492 name = remote_dev_info->name;
494 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
495 for (i = 0; i < remote_dev_info->uuid_count; i++) {
496 g_variant_builder_add(builder, "s",
497 remote_dev_info->uuids[i]);
499 uuids = g_variant_new("as", builder);
500 g_variant_builder_unref(builder);
501 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
502 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
505 param = g_variant_new("(isunsbub@asn@ay)",
506 BLUETOOTH_ERROR_NONE,
507 remote_dev_info->address,
508 remote_dev_info->class,
509 remote_dev_info->rssi,
511 remote_dev_info->paired,
512 remote_dev_info->connected,
513 remote_dev_info->trust,
515 remote_dev_info->manufacturer_data_len,
517 /* Send the event to application */
518 _bt_send_event(BT_ADAPTER_EVENT,
519 BLUETOOTH_EVENT_SERVICE_SEARCHED,
522 __bt_free_service_search_info(&service_search_info);
526 static void __bt_device_services_callback(event_dev_services_t* uuid_list)
528 bt_remote_dev_info_t *rem_info = NULL;
532 if (trigger_bond_info && _bt_compare_adddress(trigger_bond_info->dev_addr,
533 (bluetooth_device_address_t *)&uuid_list->address) == TRUE) {
534 bluetooth_device_address_t *dev_addr = trigger_bond_info->dev_addr;
536 BT_DBG("Bonding dev addr has matched");
537 /* Bonding ongoing, Query device properties again */
538 if (BLUETOOTH_ERROR_NONE ==
539 _bt_device_get_bonded_device_info(dev_addr))
540 BT_DBG("_bt_device_get_bonded_device_info success");
542 BT_ERR("_bt_device_get_bonded_device_info failed");
545 if (service_search_info == NULL) {
547 BT_DBG("searching_info == NULL");
551 if (_bt_compare_adddress(service_search_info->dev_addr,
552 (bluetooth_device_address_t *)&uuid_list->address) == FALSE) {
553 BT_DBG("This device is not queried");
557 rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
558 memset(rem_info, 0x00, sizeof(bt_remote_dev_info_t));
560 rem_info->address = g_new0(char, BT_ADDRESS_STRING_SIZE);
561 _bt_convert_addr_type_to_string(rem_info->address, uuid_list->address.addr);
563 rem_info->uuid_count = uuid_list->num;
565 BT_INFO("Address [%s]", rem_info->address);
566 BT_INFO("Number of UUID's [%d]", rem_info->uuid_count);
567 if (rem_info->uuid_count > 0)
568 rem_info->uuids = g_new0(char *, rem_info->uuid_count);
570 /* Fill Remote Device Service List list */
571 for (i = 0; i < rem_info->uuid_count; i++) {
572 rem_info->uuids[i] = g_malloc0(BLUETOOTH_UUID_STRING_MAX);
573 _bt_uuid_to_string((service_uuid_t *)&uuid_list->service_list[i].uuid, rem_info->uuids[i]);
574 BT_DBG("UUID value=%s", rem_info->uuids[i]);
577 /* Update local cache */
578 _bt_update_remote_dev_property(rem_info->address, DEV_PROP_SERVICES, (void *)rem_info);
580 BT_DBG("DBUS return");
581 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_SEARCH_SERVICE,
582 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
584 /* Save UUID List of remote devices */
585 if (service_search_info->dev_info)
586 _bt_free_remote_dev(service_search_info->dev_info);
587 service_search_info->dev_info = rem_info;
589 /* Query Other device properties */
590 if (_bt_device_get_bonded_device_info(service_search_info->dev_addr) == BLUETOOTH_ERROR_NONE) {
591 BT_DBG("Bonded device info query posted to stack successfully");
593 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
594 __bt_free_service_search_info(&service_search_info);
599 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event)
601 oal_service_t service_id = auth_event->service_id;
602 gchar address[BT_ADDRESS_STR_LEN];
605 _bt_convert_addr_type_to_string(address, auth_event->address.addr);
607 BT_DBG("service_d: %d", service_id);
609 switch (service_id) {
611 BT_DBG("Incoming HID Profile conn Req from device addr [%s]", address);
613 case A2DP_SERVICE_ID:
614 BT_DBG("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
615 _bt_a2dp_src_handle_incoming_authorization(address, service_id);
617 case A2DP_SRC_SERVICE_ID:
618 BT_DBG("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
619 _bt_a2dp_sink_handle_incoming_authorization(address, service_id);
621 case AVRCP_SERVICE_ID:
622 BT_DBG("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
624 case AVRCP_CT_SERVICE_ID:
625 BT_DBG("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
627 #ifdef TIZEN_FEATURE_BT_OBEX
628 case OPP_SERVICE_ID: {
629 GVariant *param = NULL;
632 if (_bt_obex_server_is_custom() == false) {
633 /* Allow the connection for native OPP server */
637 name = g_strdup(address);
639 BT_DBG("Incoming OPP conn Req from device addr [%s]", address);
640 _bt_obex_server_set_pending_conn_auth_device_addr(address);
641 param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, name);
642 _bt_send_event(BT_OPP_SERVER_EVENT,
643 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE, param);
650 BT_DBG("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
651 _bt_audio_handle_incoming_authorization(address, service_id);
654 BT_DBG("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
656 case HSP_HS_SERVICE_ID:
657 case HFP_HS_SERVICE_ID:
658 BT_DBG("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
659 _bt_audio_handle_incoming_authorization(address, service_id);
662 case IOTIVITY_SERVICE_ID:
663 BT_DBG("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
667 /* For now, reject authorization for any service apart from above switch cases */
668 BT_DBG("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_id, address);
669 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, FALSE, FALSE);
670 if (res != OAL_STATUS_SUCCESS)
671 BT_ERR("authorize_response: %d", res);
675 /* Auto accept authorization request for HID, A2DP and AVRCP profiles */
676 BT_INFO("Auto Accept authorization");
677 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, TRUE, FALSE);
678 if (res != OAL_STATUS_SUCCESS)
679 BT_ERR("authorize_response: %d", res);
682 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond)
684 GVariant *param = NULL;
686 if ((remote_dev_info->name || remote_dev_info->alias)
687 && remote_dev_info->address
688 && remote_dev_info->uuids) {
689 GVariant *uuids = NULL;
690 GVariantBuilder *builder = NULL;
691 GVariant *manufacturer_data;
695 if (remote_dev_info->alias)
696 name = remote_dev_info->alias;
698 name = remote_dev_info->name;
700 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
701 for (i = 0; i < remote_dev_info->uuid_count; i++) {
702 g_variant_builder_add(builder, "s",
703 remote_dev_info->uuids[i]);
705 uuids = g_variant_new("as", builder);
706 g_variant_builder_unref(builder);
707 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
708 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
711 param = g_variant_new("(isunsbub@asn@ay)",
712 BLUETOOTH_ERROR_NONE,
713 remote_dev_info->address,
714 remote_dev_info->class,
715 remote_dev_info->rssi,
717 remote_dev_info->paired,
718 remote_dev_info->connected,
719 remote_dev_info->trust,
721 remote_dev_info->manufacturer_data_len,
723 /* Send the event to application */
724 _bt_send_event(BT_ADAPTER_EVENT,
725 BLUETOOTH_EVENT_BONDING_FINISHED,
727 BT_PERMANENT_LOG("Paired %s", remote_dev_info->address + 12);
728 BT_INFO_C("### Paired %s", remote_dev_info->address + 12);
730 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
732 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
733 __bt_free_pairing_info(&trigger_pairing_info);
736 BT_INFO("Lets wait for more remote device properties");
740 static void __handle_incoming_bond_created_event(bt_address_t *bd_addr)
742 char address[BT_ADDRESS_STRING_SIZE];
743 bluetooth_device_address_t dev_addr;
746 * BlueZ sends paired signal for each paired device, during activation,
747 * We should ignore this, otherwise application thinks that a new device
750 if (_bt_adapter_get_status() != BT_ACTIVATED) {
751 BT_DBG("BT is not activated, so ignore this");
755 _bt_convert_addr_type_to_string(address, bd_addr->addr);
756 if (!incoming_bond_info) {
757 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
759 if (g_strcmp0(incoming_bond_info->addr, address)) {
760 BT_DBG("Previous Bond address: [%s] differs from new address: [%s]",
761 address, incoming_bond_info->addr);
762 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
763 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
767 BT_INFO("Incoming bond successfully completed");
768 g_strlcpy(incoming_bond_info->addr, address, BT_ADDRESS_STRING_SIZE);
769 incoming_bond_info->dev_info = NULL;
771 _bt_convert_addr_string_to_type(dev_addr.addr, incoming_bond_info->addr);
772 if (BLUETOOTH_ERROR_NONE == _bt_device_get_bonded_device_info(&dev_addr)) {
773 BT_DBG("Bonded device info query posted to stack successfully");
775 BT_ERR("Bonded device info query failed");
776 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
781 static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr)
783 gchar address[BT_ADDRESS_STR_LEN];
784 bluetooth_device_address_t dev_addr;
786 if (trigger_bond_info == NULL) {
788 BT_DBG("trigger_bond_info == NULL, Handle incomming bond event");
789 __handle_incoming_bond_created_event(bd_addr);
793 _bt_convert_addr_type_to_string(address, bd_addr->addr);
794 if (g_strcmp0(trigger_bond_info->addr, address)) {
795 BT_DBG("Bonding address= [%s] is different from requested address =[%s]",
796 address, trigger_bond_info->addr);
797 __handle_incoming_bond_created_event(bd_addr);
801 /* Bonding state will be cleaned up & BONDING FINISHED EVENT
802 will be sent only when Properties are fetched from stack
803 Till that time lets not free trigger_bond_info.
804 However it is possible that while fetching device properties, internal
805 stack error can occur which can lead to no valid properties or
806 no properties at all. So in such cases, we must not wait for properties,
807 otherwise, it can lead to infinite wait */
808 _bt_convert_addr_string_to_type(dev_addr.addr,
809 trigger_bond_info->addr);
811 if (_bt_device_get_bonded_device_info(&dev_addr) == BLUETOOTH_ERROR_NONE) {
812 BT_DBG("Bonded device info query posted to stack successfully");
813 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
814 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
816 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
817 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
818 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
819 /* Destroy if at all device got bonded at stack level */
820 device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
822 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
823 __bt_free_pairing_info(&trigger_pairing_info);
827 /**********************************************************************************************
828 * Bond removal event can be triggered for following reasons -
829 * a. If Bonding procedure if failed (for Auth failed, Page timeout, cancelled by user etc)
830 * b. If Application requests for explicitly removing the bond
831 * c. When application attempt to create bond,bond is removed first which triggers this event
832 * c. is in-line with Bluedroid bond create\emoval architecture
833 *********************************************************************************************/
834 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr)
836 char address[BT_ADDRESS_STRING_SIZE];
838 _bt_convert_addr_type_to_string(address, bd_addr->addr);
839 _bt_service_remove_device_from_bonded_list(address);
841 if (trigger_unbond_info) {
842 BT_DBG("Bond removal request successfully handled, return DBUS and send event");
843 GVariant *param = NULL;
844 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_UNBOND_DEVICE,
845 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
846 param = g_variant_new("(is)", BLUETOOTH_ERROR_NONE, trigger_unbond_info->addr);
847 _bt_send_event(BT_ADAPTER_EVENT,
848 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
850 BT_PERMANENT_LOG("Unpaired %s", trigger_unbond_info->addr + 12);
851 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
852 __bt_free_pairing_info(&trigger_pairing_info);
853 } else if (trigger_bond_info) {
854 BT_ERR("Bonding was removed");
855 __bt_device_handle_bond_state();
859 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event)
862 oal_status_t status = bond_fail_event->status;
863 BT_INFO("Bonding failed, reason: %d", status);
866 case OAL_STATUS_RMT_DEVICE_DOWN:
868 if (trigger_bond_info) {
869 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
870 BT_INFO("OAL_STATUS_RMT_DEVICE_DOWN:Lets retry bonding!! retry count [%d]",
872 int ret = OAL_STATUS_SUCCESS;
873 if (bond_retry_count < MAX_BOND_RETRY_COUNT) {
874 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
875 if (ret != OAL_STATUS_SUCCESS) {
876 BT_ERR("Create Bond procedure could not suceed");
877 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
878 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
879 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
880 __bt_free_pairing_info(&trigger_pairing_info);
881 bond_retry_count = 0;
886 BT_ERR("Create Bond failed MAX_BOND_RETRY_COUNT TIMES!!");
887 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
888 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
889 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
890 __bt_free_pairing_info(&trigger_pairing_info);
891 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
892 bond_retry_count = 0;
898 case OAL_STATUS_AUTH_FAILED:
900 /*TODO Auto pairing status set & ignore auto pairing logics can be done at this point.
901 To be considered later*/
902 int result = BLUETOOTH_ERROR_INTERNAL;
903 BT_INFO("BT_OPERATION_STATUS_AUTH_FAILED");
905 BT_INFO("add device in pairing black list");
906 _bt_set_autopair_status_in_bonding_info(FALSE);
908 if (trigger_bond_info) {
909 __bt_ignore_auto_pairing_request(trigger_bond_info->addr);
910 BT_ERR("Create Bond procedure could not suceed, check if cancelled by User");
911 if (trigger_bond_info->is_cancelled_by_user) {
912 BT_ERR("Bonding is cancelled by user");
913 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
915 __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
916 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
917 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
920 __bt_free_pairing_info(&trigger_pairing_info);
923 case OAL_STATUS_ALREADY_CONNECT:
925 int result = BLUETOOTH_ERROR_ALREADY_CONNECT;
926 BT_INFO("OAL_STATUS_ALREADY_CONNECT");
928 if (trigger_bond_info) {
929 __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
930 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
931 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
935 case OAL_STATUS_INTERNAL_ERROR:
937 BT_INFO("OAL_STATUS_INTERNAL_ERROR");
938 if (trigger_unbond_info) {
939 BT_INFO("Bond removal request failed, return DBUS and send event");
940 GVariant *param = NULL;
941 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_UNBOND_DEVICE,
942 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
943 param = g_variant_new("(is)", BLUETOOTH_ERROR_INTERNAL, trigger_unbond_info->addr);
944 _bt_send_event(BT_ADAPTER_EVENT,
945 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
947 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
948 } else if (trigger_bond_info) {
949 if (__bt_device_handle_bond_state() != BLUETOOTH_ERROR_NONE) {
950 if (trigger_bond_info) {
951 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
952 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
953 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
958 __bt_free_pairing_info(&trigger_pairing_info);
963 BT_ERR("Unknown status of Bond failed event status [%d]", status);
971 static gboolean __bt_device_init_dbfw_rssi_cb(gpointer user_data)
977 static void __bt_device_parse_dbfw_set_rssi(unsigned char *data, uint32_t length)
980 dbfw_rssi = 0xFFFFFF00 | data[4];
981 BT_INFO("dbfw_rssi = %d", dbfw_rssi);
982 g_timeout_add(1000, __bt_device_init_dbfw_rssi_cb, NULL);
985 static void __bt_device_dbfw_plus_info_callback(event_dev_dbfw_plus_info_t *dbfw_info)
988 char *data_str = NULL;
991 data_str = g_malloc0(dbfw_info->length * 2 + 1);
992 for (i = 0; i < dbfw_info->length; i++)
993 snprintf(&data_str[i * 2], 3, "%02X", dbfw_info->data[i]);
994 data_str[i * 2] = '\0';
996 switch(dbfw_info->event_code) {
997 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_INFO:
998 BT_DBG("## Event Code: Linkloss Debug Info");
999 snprintf(evt_str, 18, "[DBFW]Linkloss(D)");
1000 __bt_device_parse_dbfw_set_rssi(dbfw_info->data, dbfw_info->length);
1002 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_CLOCK_INFO:
1003 BT_DBG("## Event Code: Linkloss Clock Info");
1004 snprintf(evt_str, 18, "[DBFW]Linkloss(C)");
1006 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_PAGE_SLOTS:
1007 BT_DBG("## Event Code: Linkloss Page slots");
1008 snprintf(evt_str, 18, "[DBFW]Linkloss(P)");
1010 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_LMP_TRACE:
1011 BT_DBG("## Event Code: Linkloss LMP trace");
1012 snprintf(evt_str, 18, "[DBFW]Linkloss(L)");
1014 case BT_DBFW_PLUS_EVENT_CODE_A2DP_INFO:
1015 BT_DBG("## Event Code: A2DP Info");
1016 snprintf(evt_str, 18, "[DBFW]A2DP");
1018 case BT_DBFW_PLUS_EVENT_CODE_HFP_INFO:
1019 BT_DBG("## Event Code: HFP Info");
1020 snprintf(evt_str, 18, "[DBFW]HFP");
1022 case BT_DBFW_PLUS_EVENT_CODE_HFP_SCO_PACKET_TYPE_INFO:
1023 BT_DBG("## Event Code: HFP SCO Packet Type");
1024 snprintf(evt_str, 18, "[DBFW]SCO");
1027 BT_DBG("## Unknown event code (0x%02x)", dbfw_info->event_code);
1028 snprintf(evt_str, 18, "[DBFW]0x%02X", dbfw_info->event_code);
1032 BT_PERMANENT_LOG("%s 0x%s", evt_str, data_str);
1036 static void __bt_device_event_handler(int event_type, gpointer event_data)
1038 int eventcheck = OAL_EVENT_DEVICE_PROPERTIES;
1039 BT_DBG("event [%d] Event check = [%d]", event_type, eventcheck);
1041 switch (event_type) {
1042 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY: {
1043 BT_INFO("BREDR Device Found");
1044 __bt_device_remote_device_found_callback(event_data, FALSE);
1047 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE: {
1048 BT_INFO("Dual Device Found");
1049 __bt_device_remote_device_found_callback(event_data, FALSE);
1052 case OAL_EVENT_DEVICE_PROPERTIES: {
1053 BT_INFO("Remote Device properties Received");
1054 __bt_device_remote_properties_callback((event_dev_properties_t *)event_data);
1057 case OAL_EVENT_DEVICE_BONDING_SUCCESS: {
1058 BT_INFO("Bonding Success event Received");
1059 __bt_device_handle_bond_completion_event((bt_address_t *)event_data);
1062 case OAL_EVENT_DEVICE_BONDING_REMOVED: {
1063 BT_INFO("Bonding Removed event Received");
1064 __bt_device_handle_bond_removal_event((bt_address_t *)event_data);
1067 case OAL_EVENT_DEVICE_BONDING_FAILED: {
1068 BT_INFO("Bonding Failed event Received");
1069 __bt_device_handle_bond_failed_event((event_dev_bond_failed_t*) event_data);
1072 case OAL_EVENT_DEVICE_ACL_CONNECTED: {
1073 BT_DBG("ACL Connected event Received");
1074 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 0);
1077 case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
1078 BT_DBG("ACL Disconnected event Received");
1079 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 0);
1082 case OAL_EVENT_DEVICE_LE_CONNECTED: {
1083 BT_DBG("LE Connected event Received");
1084 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 1);
1087 case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
1088 BT_DBG("LE Disconnected event Received");
1089 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 1);
1092 case OAL_EVENT_DEVICE_PIN_REQUEST: {
1093 BT_INFO("PIN Request Received");
1094 __bt_device_pin_request_callback((remote_device_t*)event_data);
1097 case OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST: {
1098 BT_INFO("Passkey Entry request Received");
1099 __bt_device_ssp_passkey_entry_callback((remote_device_t*)event_data);
1102 case OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST:{
1103 BT_INFO("Passkey Confirmation Request Received");
1104 __bt_device_ssp_passkey_confirmation_callback((event_dev_passkey_t *)event_data);
1107 case OAL_EVENT_DEVICE_PASSKEY_DISPLAY: {
1108 BT_INFO("Passkey Display Request Received");
1109 __bt_device_ssp_passkey_display_callback((event_dev_passkey_t *)event_data);
1112 case OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST: {
1113 BT_INFO("SSP Consent Request Received");
1114 __bt_device_ssp_consent_callback((remote_device_t*)event_data);
1117 case OAL_EVENT_DEVICE_SERVICES: {
1118 BT_INFO("Remote Device Services Received");
1119 __bt_device_services_callback((event_dev_services_t*)event_data);
1122 case OAL_EVENT_DEVICE_AUTHORIZE_REQUEST: {
1123 BT_INFO("Remote Device Authorization Request");
1124 __bt_device_authorization_request_callback((event_dev_authorize_req_t*)event_data);
1127 case OAL_EVENT_DEVICE_TRUSTED: {
1128 BT_INFO("Remote Device Trusted");
1129 __bt_device_trusted_callback(TRUE, (event_dev_trust_t*)event_data);
1132 case OAL_EVENT_DEVICE_UNTRUSTED: {
1133 BT_INFO("Remote Device UnTrusted");
1134 __bt_device_trusted_callback(FALSE, (event_dev_trust_t*)event_data);
1137 case OAL_EVENT_DEVICE_NAME: {
1138 remote_device_t *rem_dev = event_data;
1139 gchar address[BT_ADDRESS_STR_LEN];
1141 _bt_convert_addr_type_to_string(address, rem_dev->address.addr);
1142 BT_INFO("Remote Device name Received");
1143 BT_INFO("Name: %s, Address: %s", rem_dev->name, address);
1145 /* Update local cache */
1146 _bt_update_remote_dev_property(address, DEV_PROP_NAME, (void *)rem_dev->name);
1149 case OAL_EVENT_DEVICE_TRUSTED_PROFILES_CHANGED: {
1150 event_device_trusted_profiles_t *ev = event_data;
1151 char address[BT_ADDRESS_STRING_SIZE];
1155 _bt_convert_addr_type_to_string(address, ev->address.addr);
1156 _bt_send_event(BT_DEVICE_EVENT,
1157 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1158 g_variant_new("(isi)", BLUETOOTH_ERROR_NONE,
1159 address, ev->trust_val));
1162 case OAL_EVENT_RSSI_MONITORING_ENABLED: {
1163 event_dev_rssi_info_t *ev = event_data;
1164 char address[BT_ADDRESS_STRING_SIZE];
1169 _bt_convert_addr_type_to_string(address, ev->address.addr);
1170 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1171 address, ev->link_type, TRUE);
1172 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1175 case OAL_EVENT_RSSI_MONITORING_DISABLED: {
1176 event_dev_rssi_info_t *ev = event_data;
1177 char address[BT_ADDRESS_STRING_SIZE];
1182 _bt_convert_addr_type_to_string(address, ev->address.addr);
1183 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1184 address, ev->link_type, FALSE);
1185 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1188 case OAL_EVENT_RSSI_ALERT_RECEIVED: {
1189 event_dev_rssi_info_t *ev = event_data;
1190 char address[BT_ADDRESS_STRING_SIZE];
1195 _bt_convert_addr_type_to_string(address, ev->address.addr);
1196 param = g_variant_new("(isiii)", BLUETOOTH_ERROR_NONE,
1197 address, ev->link_type, ev->alert_type, ev->rssi);
1198 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ALERT, param);
1201 case OAL_EVENT_RAW_RSSI_RECEIVED: {
1202 event_dev_rssi_info_t *ev = event_data;
1203 char address[BT_ADDRESS_STRING_SIZE];
1208 _bt_convert_addr_type_to_string(address, ev->address.addr);
1209 param = g_variant_new("(isii)", BLUETOOTH_ERROR_NONE,
1210 address, ev->link_type, ev->rssi);
1211 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RAW_RSSI, param);
1214 case OAL_EVENT_DEVICE_DBFW_PLUS_INFO: {
1215 __bt_device_dbfw_plus_info_callback((event_dev_dbfw_plus_info_t*)event_data);
1219 BT_INFO("Unhandled event..");
1223 /* Legacy Pairing event handler */
1224 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
1227 char address[BT_ADDRESS_STRING_SIZE];
1228 char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
1229 bool incoming = false;
1232 _bt_convert_addr_type_to_string(address, pin_req_event->address.addr);
1234 BT_INFO("Address[%s]", address);
1235 BT_INFO("Name[%s]", pin_req_event->name);
1236 BT_INFO("COD[%d]", pin_req_event->cod);
1238 if (trigger_pairing_info) {
1239 /* BTAPI support only one pairing at a time */
1240 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1241 BT_ERR("New PIN request address [%s]", address);
1242 device_reject_pin_request(&pin_req_event->address);
1246 /* If user initiated bonding and auto response is possible, just reply with default 0000*/
1247 if (_bt_is_bonding_device_address(address) == TRUE &&
1248 _bt_agent_is_auto_response(pin_req_event->cod, address, pin_req_event->name)) {
1249 /* Note: Currently even if SYSPOPUP is supported, we use Fixed PIN "0000" for basic pairing
1250 as BT SYSPOPUP is currently not working for PIN KEY entry in Tizen platform. This needs
1251 to be checked and fixed apropriately */
1252 _bt_set_autopair_status_in_bonding_info(TRUE);
1253 device_accept_pin_request(&pin_req_event->address, "0000");
1254 } else if (_bt_agent_is_hid_keyboard(pin_req_event->cod)) {
1255 BT_DBG("Remote Device is HID keyboard Type..");
1256 char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
1258 if (_bt_agent_generate_passkey(str_passkey,
1259 BT_PASSKEY_MAX_LENGTH) != 0) {
1260 device_reject_pin_request(&pin_req_event->address);
1263 device_accept_pin_request(&pin_req_event->address, str_passkey);
1265 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1267 if(trigger_bond_info == NULL)
1270 param = g_variant_new("(bsss)", incoming, address, pin_req_event->name, str_passkey);
1271 _bt_send_event(BT_ADAPTER_EVENT,
1272 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1273 BT_DBG("Key board pairing in process");
1274 } else if (BLUETOOTH_ERROR_NONE == __bt_get_device_pin_code(address, pin_code)) {
1275 BT_DBG("Use stored PIN code [%s]", pin_code);
1276 device_accept_pin_request(&pin_req_event->address, pin_code);
1278 if (_bt_is_bonding_device_address(address) == TRUE) {
1279 BT_DBG("Show Pin entry");
1280 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1281 trigger_pairing_info->addr = g_strdup(address);
1282 trigger_pairing_info->is_ssp = FALSE;
1284 BT_DBG("Send BLUETOOTH_EVENT_PIN_REQUEST");
1286 if(trigger_bond_info == NULL)
1289 param = g_variant_new("(bss)", incoming, address, pin_req_event->name);
1290 _bt_send_event(BT_ADAPTER_EVENT,
1291 BLUETOOTH_EVENT_PIN_REQUEST, param);
1296 _bt_agent_release_memory();
1300 /* SSP Pairing event handler */
1301 static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info)
1304 gchar address[BT_ADDRESS_STR_LEN];
1307 bool incoming = false;
1311 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1313 name = dev_info->name;
1315 BT_INFO("Address[%s]", address);
1316 BT_INFO("Name[%s]", name);
1317 BT_INFO("COD[%d]", dev_info->cod);
1319 if (trigger_pairing_info) {
1320 /* BTAPI support only one pairing at a time */
1321 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1322 BT_ERR("New PIN request address [%s]", address);
1323 device_reject_pin_request(&dev_info->address);
1328 /* Set pairing data */
1329 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1330 trigger_pairing_info->addr = g_strdup(address);
1331 trigger_pairing_info->is_ssp = TRUE;
1333 if(trigger_bond_info == NULL)
1336 param = g_variant_new("(bss)", incoming, p_addr, name);
1337 _bt_send_event(BT_ADAPTER_EVENT,
1338 BLUETOOTH_EVENT_PASSKEY_REQUEST, param);
1342 static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *dev_info)
1345 gchar address[BT_ADDRESS_STR_LEN];
1348 char str_passkey[7];
1349 bool incoming = false; /*Stores if bonding request is incoming(true) or outgoing(false) */
1352 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1354 name = dev_info->device_info.name;
1356 BT_INFO("Address[%s]", address);
1357 BT_INFO("Name[%s]", name);
1358 BT_INFO("COD[%d]", dev_info->device_info.cod);
1360 if (trigger_pairing_info) {
1361 /* BTAPI support only one pairing at a time */
1362 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1363 BT_ERR("New PIN request address [%s]", address);
1364 device_reject_pin_request(&dev_info->device_info.address);
1369 /* Set pairing data */
1370 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1371 trigger_pairing_info->addr = g_strdup(address);
1372 trigger_pairing_info->is_ssp = TRUE;
1374 BT_DBG("Send BLUETOOTH_EVENT_PASSKEY_CONFIRMATION");
1375 snprintf(str_passkey, sizeof(str_passkey), "%.6d", dev_info->pass_key);
1377 /*Storing if bond is incoming or outgoing*/
1378 if(trigger_bond_info == NULL)
1381 param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
1382 _bt_send_event(BT_ADAPTER_EVENT,
1383 BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST, param);
1387 static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_info)
1390 gchar address[BT_ADDRESS_STR_LEN];
1393 char str_passkey[7];
1394 bool incoming = false;
1397 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1399 name = dev_info->device_info.name;
1401 BT_INFO("Address[%s]", address);
1402 BT_INFO("Name[%s]", name);
1403 BT_INFO("COD[%d]", dev_info->device_info.cod);
1405 if (trigger_pairing_info) {
1406 /* BTAPI support only one pairing at a time */
1407 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1408 BT_ERR("New PIN request address [%s]", address);
1409 device_reject_pin_request(&dev_info->device_info.address);
1414 /* Set pairing data */
1415 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1416 trigger_pairing_info->addr = g_strdup(address);
1417 trigger_pairing_info->is_ssp = TRUE;
1419 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1420 snprintf(str_passkey, sizeof(str_passkey), "%06d", dev_info->pass_key);
1422 if(trigger_bond_info == NULL)
1425 param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
1427 if (passkey_watcher) {
1428 BT_INFO("Send passkey to %s", passkey_watcher);
1429 _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
1430 BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, param);
1432 _bt_send_event(BT_ADAPTER_EVENT,
1433 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1438 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info)
1440 gchar address[BT_ADDRESS_STR_LEN];
1447 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1448 name = dev_info->name;
1449 cod = dev_info->cod;
1451 BT_INFO("Address[%s]", address);
1452 BT_INFO("Name[%s]", name);
1453 BT_INFO("COD[%d]", cod);
1455 if (trigger_pairing_info) {
1456 /* BTAPI support only one pairing at a time */
1457 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1458 BT_ERR("New PIN request address [%s]", address);
1459 device_reject_pin_request(&dev_info->address);
1464 /* Set pairing data */
1465 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1466 trigger_pairing_info->addr = g_strdup(address);
1467 trigger_pairing_info->is_ssp = TRUE;
1469 local_major = ((cod >> 8) & 0x001f);
1470 local_minor = (cod & 0x00fc);
1471 BT_DBG("SSP_CONSENT: Major type=[0x%x] and Minor type=[0x%x]", local_major, local_minor);
1473 /*TODO: BLUETOOTH_EVENT_SSP_CONSENT_REQUEST to be handled in Tizen */
1477 static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
1478 gboolean connected, unsigned char type)
1480 gchar address[BT_ADDRESS_STR_LEN];
1481 int disc_reason = 0;
1482 GVariant *param = NULL;
1483 bt_device_conn_info_t conn_info;
1485 _bt_convert_addr_type_to_string(address, acl_event->address.addr);
1487 _bt_logging_connection(connected, type);
1489 disc_reason = acl_event->status;
1492 BT_PERMANENT_LOG("Connected %s %s", !type ? "EDR" : "LE", address + 12);
1493 param = g_variant_new("(isy)", BLUETOOTH_ERROR_NONE, address, type);
1494 _bt_send_event(BT_DEVICE_EVENT,
1495 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1498 BT_PERMANENT_LOG("Disconnected %s(%d) %s", !type ? "EDR" : "LE", disc_reason, address + 12);
1499 param = g_variant_new("(isyi)", disc_reason, address, type, dbfw_rssi);
1500 _bt_send_event(BT_DEVICE_EVENT,
1501 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1505 conn_info.connected = connected;
1506 conn_info.type = type;
1507 /* Update local cache */
1508 _bt_update_remote_dev_property(address, DEV_PROP_CONNECTED, (void *)&conn_info);
1510 /*handle LE connected device info*/
1512 _bt_handle_le_connected_dev_info(address, connected);
1515 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble)
1517 bt_remote_dev_info_t *dev_info = NULL;
1518 int result = BLUETOOTH_ERROR_NONE;
1519 GVariant *param = NULL;
1520 GVariant *uuids = NULL;
1521 GVariant *manufacturer_data = NULL;
1522 GVariantBuilder *builder = NULL;
1525 ret_if(_bt_is_discovering() == FALSE);
1526 ret_if(event_data == NULL);
1528 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
1531 event_ble_dev_found_t * oal_ble_dev = event_data;
1532 BT_INFO("Device type [%d]", oal_ble_dev->device_info.type);
1534 _bt_copy_remote_dev(dev_info, &oal_ble_dev->device_info);
1536 dev_info->manufacturer_data_len = oal_ble_dev->adv_len;
1537 if (dev_info->manufacturer_data_len)
1538 dev_info->manufacturer_data = g_memdup(oal_ble_dev->adv_data,
1539 dev_info->manufacturer_data_len);
1541 dev_info->manufacturer_data = NULL;
1542 BT_DBG("----Advertising Data Length: %d", dev_info->manufacturer_data_len);
1544 event_dev_found_t * oal_dev = event_data;
1545 _bt_copy_remote_dev(dev_info, &oal_dev->device_info);
1548 /* If Remote device name is NULL or still RNR is not done then display address as name. */
1549 if (dev_info->name == NULL)
1550 dev_info->name = g_strdup(dev_info->address);
1551 BT_DBG("Name %s", dev_info->name);
1553 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1554 for (i = 0; i < dev_info->uuid_count; i++)
1555 g_variant_builder_add(builder, "s", dev_info->uuids[i]);
1557 uuids = g_variant_new("as", builder);
1558 g_variant_builder_unref(builder);
1560 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1561 dev_info->manufacturer_data,
1562 dev_info->manufacturer_data_len,
1566 param = g_variant_new("(isunsbub@asn@ay)", result,
1572 dev_info->connected,
1575 dev_info->manufacturer_data_len,
1578 _bt_send_event(BT_ADAPTER_EVENT,
1579 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1582 _bt_free_remote_dev(dev_info);
1585 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info)
1587 gchar address[BT_ADDRESS_STR_LEN];
1588 int result = BLUETOOTH_ERROR_NONE;
1589 GVariant *param = NULL;
1592 _bt_convert_addr_type_to_string(address, info->address.addr);
1594 /* Update local cache */
1595 _bt_update_remote_dev_property(address, DEV_PROP_TRUST, (void *)&trusted);
1597 param = g_variant_new("(is)", result, address);
1598 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1599 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1600 /* Send event to application */
1601 _bt_send_event(BT_DEVICE_EVENT,
1607 static void __bt_free_pairing_info(bt_pairing_data_t **p_info)
1609 bt_pairing_data_t * info = *p_info;
1619 static void __bt_free_bond_info(uint8_t type)
1622 case BT_DEVICE_BOND_INFO:
1623 if (!trigger_bond_info)
1626 if (trigger_bond_info->addr)
1627 g_free(trigger_bond_info->addr);
1628 if (trigger_bond_info->dev_addr)
1629 g_free(trigger_bond_info->dev_addr);
1630 if (trigger_bond_info->dev_info)
1631 _bt_free_remote_dev(trigger_bond_info->dev_info);
1632 g_free(trigger_bond_info);
1633 trigger_bond_info = NULL;
1635 case BT_DEVICE_INCOMING_BOND_INFO:
1636 if (!incoming_bond_info)
1639 if (incoming_bond_info->dev_info)
1640 _bt_free_remote_dev(incoming_bond_info->dev_info);
1641 g_free(incoming_bond_info);
1642 incoming_bond_info = NULL;
1644 case BT_DEVICE_UNBOND_INFO:
1645 if (!trigger_unbond_info)
1648 if (trigger_unbond_info->addr)
1649 g_free(trigger_unbond_info->addr);
1650 if (trigger_unbond_info->dev_addr)
1651 g_free(trigger_unbond_info->dev_addr);
1652 if (trigger_unbond_info->dev_info)
1653 _bt_free_remote_dev(trigger_unbond_info->dev_info);
1654 g_free(trigger_unbond_info);
1655 trigger_unbond_info = NULL;
1660 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info)
1662 bt_service_search_info_data_t * info = *p_info;
1669 if (info->dev_addr) {
1670 g_free(info->dev_addr);
1671 info->dev_addr = NULL;
1674 if (info->dev_info) {
1675 _bt_free_remote_dev(info->dev_info);
1676 info->dev_info = NULL;
1684 static int __bt_device_handle_bond_state(void)
1686 BT_DBG("Current Bond state: %d", bt_device_bond_state);
1687 int ret = OAL_STATUS_INTERNAL_ERROR;
1689 switch (bt_device_bond_state) {
1690 case BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY:
1691 /*TODO:Bonding during discovery: Unhandled!!*/
1692 BT_INFO("Bonding during discovery: Unhandled!!");
1694 case BT_DEVICE_BOND_STATE_DISCOVERY_CANCELLED:
1695 /*TODO:Bonding during discovery: Unhandled!!*/
1696 BT_INFO("Bonding during discovery: Unhandled!!");
1698 case BT_DEVICE_BOND_STATE_REMOVE_BONDING:
1699 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING;
1700 ret = device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
1701 if (ret != OAL_STATUS_SUCCESS)
1702 ret = __bt_device_handle_bond_state();
1704 case BT_DEVICE_BOND_STATE_REMOVED_BONDING:
1705 bt_device_bond_state = BT_DEVICE_BOND_STATE_NONE;
1706 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
1707 /* Bonding procedure was started but unfortunately could not complete.
1708 Basically removed bonding was success, but create bond request could not proceed
1709 So lets cleanup the context */
1710 if (ret != OAL_STATUS_SUCCESS) {
1711 BT_ERR("Create Bond procedure could not suceed");
1712 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1713 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1714 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1715 __bt_free_pairing_info(&trigger_pairing_info);
1718 case BT_DEVICE_BOND_STATE_NONE:
1719 BT_INFO("Create Bond failed!!");
1720 if (trigger_bond_info) {
1721 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1722 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1723 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1724 __bt_free_pairing_info(&trigger_pairing_info);
1731 if (ret != OAL_STATUS_SUCCESS)
1732 return _bt_convert_oal_status_to_bt_error(ret);
1734 return BLUETOOTH_ERROR_NONE;
1737 int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr)
1740 bt_address_t bd_addr;
1742 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
1744 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
1745 result = device_query_attributes(&bd_addr);
1746 if (result != OAL_STATUS_SUCCESS) {
1747 BT_ERR("device_query_attributes error: [%d]", result);
1748 return _bt_convert_oal_status_to_bt_error(result);
1751 return BLUETOOTH_ERROR_NONE;
1754 int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias)
1757 char address[BT_ADDRESS_STRING_SIZE];
1759 BT_CHECK_PARAMETER(alias, return);
1761 ret = device_set_alias((bt_address_t *)device_address, (char *)alias);
1762 if (ret != OAL_STATUS_SUCCESS) {
1763 BT_ERR("device_set_alias: %d", ret);
1764 return _bt_convert_oal_status_to_bt_error(ret);
1767 /* Update local cache */
1768 _bt_convert_addr_type_to_string(address, device_address->addr);
1769 _bt_update_remote_dev_property(address, DEV_PROP_ALIAS, (void *)alias);
1771 return BLUETOOTH_ERROR_NONE;
1774 int _bt_bond_device(bluetooth_device_address_t *device_address,
1775 unsigned short conn_type, GArray **out_param1)
1777 int result = BLUETOOTH_ERROR_NONE;
1778 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1779 bluetooth_device_info_t dev_info;
1780 const char *stack_name = NULL;
1782 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1784 /* If bonding or discovery already going on */
1785 if (trigger_bond_info || _bt_is_discovering()) {
1786 BT_ERR("Device is buzy, bonding can not proceed now..");
1787 result = BLUETOOTH_ERROR_DEVICE_BUSY;
1791 /*TODO: If unbonding with same device going on */
1792 _bt_convert_addr_type_to_string(address, device_address->addr);
1794 trigger_bond_info = g_malloc0(sizeof(bt_bond_data_t));
1795 trigger_bond_info->addr = g_strdup(address);
1796 trigger_bond_info->conn_type = conn_type;
1797 trigger_bond_info->is_device_creating = TRUE;
1798 trigger_bond_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
1799 trigger_bond_info->dev_info = NULL;
1801 /* Ready to initiate bonding */
1803 stack_name = oal_get_stack_name();
1804 if (stack_name && !g_strcmp0(stack_name, "bluez")) {
1805 BT_DBG("[bluez] Create bond by type %d", conn_type);
1806 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING;
1808 /* In Tizen, we will first remove bond and then attempt to create bond to keep
1809 consistency with bluedroid. Even if remove bond fails due to device not already
1810 bonded, then straight away create bond is triggered. This is because, remove bond
1811 is handled differently in bluedroid and bluez. In Bluez, if device is
1812 already removed, remove bond call fails.
1813 However in bluedroid, remove bond on already removed device returns success. So we will
1814 handle the cases transparently */
1815 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVE_BONDING;
1818 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
1819 bond_retry_count = 0;
1821 result = __bt_device_handle_bond_state();
1823 if (result != BLUETOOTH_ERROR_NONE)
1829 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1830 memcpy(dev_info.device_address.addr, device_address->addr,
1831 BLUETOOTH_ADDRESS_LENGTH);
1833 g_array_append_vals(*out_param1, &dev_info,
1834 sizeof(bluetooth_device_info_t));
1835 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1840 int _bt_unbond_device(bluetooth_device_address_t *device_address,
1841 GArray **out_param1)
1843 int result = OAL_STATUS_SUCCESS;
1844 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1845 bluetooth_device_info_t dev_info;
1847 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1849 _bt_convert_addr_type_to_string(address, device_address->addr);
1851 trigger_unbond_info = g_malloc0(sizeof(bt_bond_data_t));
1852 trigger_unbond_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1853 trigger_unbond_info->addr = g_strdup(address);
1854 trigger_unbond_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
1856 /* Check if Bonding is already going on, we should not abruptly remove bonding*/
1857 if (trigger_bond_info && strncmp(trigger_bond_info->addr, trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE) == 0) {
1858 BT_ERR("Bonding with same device already ongoing");
1859 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
1863 _bt_stop_timer_for_connection();
1864 result = device_destroy_bond((bt_address_t *)device_address);
1865 if (result != OAL_STATUS_SUCCESS)
1868 return BLUETOOTH_ERROR_NONE;
1871 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1872 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1873 trigger_unbond_info->addr);
1875 g_array_append_vals(*out_param1, &dev_info,
1876 sizeof(bluetooth_device_info_t));
1877 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
1879 return _bt_convert_oal_status_to_bt_error(result);
1882 int _bt_cancel_bonding(void)
1884 int result = OAL_STATUS_SUCCESS;
1887 retv_if(trigger_bond_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
1889 result = device_stop_bond((bt_address_t *)trigger_bond_info->dev_addr);
1891 if (result == OAL_STATUS_SUCCESS)
1892 trigger_bond_info->is_cancelled_by_user = TRUE;
1897 int _bt_passkey_reply(const char *passkey, gboolean cnfm_reply)
1899 bluetooth_device_address_t device_address;
1900 int ret = OAL_STATUS_SUCCESS;
1901 BT_INFO("reply: %d", cnfm_reply);
1903 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1904 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1906 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1908 if (trigger_pairing_info->is_ssp) {
1910 ret = device_accept_passkey_entry((bt_address_t *)&device_address, atoi(passkey));
1912 ret = device_reject_passkey_entry((bt_address_t *)&device_address);
1913 trigger_pairing_info->is_ssp = FALSE;
1916 ret = device_accept_pin_request((bt_address_t *)&device_address, passkey);
1918 ret = device_reject_pin_request((bt_address_t *)&device_address);
1921 __bt_free_pairing_info(&trigger_pairing_info);
1923 if (ret != OAL_STATUS_SUCCESS) {
1924 BT_ERR("_bt_device_handle_passkey_reply: err [%d]", ret);
1925 return _bt_convert_oal_status_to_bt_error(ret);
1929 return BLUETOOTH_ERROR_NONE;
1932 int _bt_passkey_confirmation_reply(gboolean cnfm_reply)
1934 BT_INFO("BT_PASSKEY_CONFIRMATION_REPLY");
1935 bluetooth_device_address_t device_address;
1936 int ret = OAL_STATUS_SUCCESS;
1937 BT_INFO("reply: %d", cnfm_reply);
1939 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1940 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1942 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1944 ret = device_reply_passkey_confirmation((bt_address_t *)&device_address, cnfm_reply);
1946 __bt_free_pairing_info(&trigger_pairing_info);
1947 if (ret != OAL_STATUS_SUCCESS) {
1948 BT_ERR("_bt_device_handle_passkey_confirmation_reply: err [%d]", ret);
1949 return BLUETOOTH_ERROR_INTERNAL;
1953 return BLUETOOTH_ERROR_NONE;
1956 gboolean _bt_device_is_pairing(void)
1958 return (trigger_pairing_info) ? TRUE : FALSE;
1961 gboolean _bt_device_is_bonding(void)
1963 return (trigger_bond_info) ? TRUE : FALSE;
1966 gboolean _bt_is_bonding_device_address(const char *address)
1968 if (trigger_bond_info == NULL || trigger_bond_info->addr == NULL)
1971 if (g_strcmp0(trigger_bond_info->addr, address) == 0) {
1972 BT_DBG("[%s] is bonding device", address);
1976 BT_DBG("[%s] is NOT bonding device", address);
1980 void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
1982 ret_if(trigger_bond_info == NULL);
1983 trigger_bond_info->is_autopair = is_autopair;
1986 int _bt_search_device(bluetooth_device_address_t *device_address)
1988 int result = OAL_STATUS_SUCCESS;
1991 BT_CHECK_PARAMETER(device_address, return);
1993 if (trigger_bond_info) {
1994 BT_ERR("Bonding in progress");
1995 return BLUETOOTH_ERROR_DEVICE_BUSY;
1998 if (service_search_info) {
1999 BT_ERR("Service searching in progress");
2000 return BLUETOOTH_ERROR_DEVICE_BUSY;
2003 /* allocate user data so that it can be retrieved in callback */
2004 service_search_info = g_malloc0(sizeof(bt_service_search_info_data_t));
2005 service_search_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2006 service_search_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
2008 _bt_convert_addr_type_to_string(service_search_info->addr,
2009 device_address->addr);
2011 result = device_query_services((bt_address_t *)device_address);
2013 if (result != OAL_STATUS_SUCCESS) {
2014 BT_ERR("Device Service Search Failed..: %d", result);
2015 __bt_free_service_search_info(&service_search_info);
2016 return _bt_convert_oal_status_to_bt_error(result);
2018 return BLUETOOTH_ERROR_NONE;
2021 int _bt_cancel_search_device(void)
2023 int ret = OAL_STATUS_SUCCESS;
2024 retv_if(service_search_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
2026 ret = device_stop_query_sevices((bt_address_t *)service_search_info->dev_addr);
2028 if (ret != OAL_STATUS_SUCCESS) {
2029 BT_ERR("SDP Cancel request failed [%d]", ret);
2030 return _bt_convert_oal_status_to_bt_error(ret);
2033 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_CANCEL_BY_USER, BT_SEARCH_SERVICE,
2034 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
2036 __bt_free_service_search_info(&service_search_info);
2038 return BLUETOOTH_ERROR_NONE;
2042 int _bt_set_authorization(bluetooth_device_address_t *device_address,
2045 int ret = OAL_STATUS_SUCCESS;
2048 BT_CHECK_PARAMETER(device_address, return);
2049 BT_INFO("Device to be Trusted? [%d]", authorize);
2051 ret = device_set_authorized((bt_address_t*)device_address, authorize);
2052 if (ret != OAL_STATUS_SUCCESS) {
2053 BT_ERR("device_set_authorized: %d", ret);
2054 return _bt_convert_oal_status_to_bt_error(ret);
2057 return BLUETOOTH_ERROR_NONE;
2060 gboolean _bt_is_device_connected(bluetooth_device_address_t *device_address, int svc_type)
2062 gboolean is_connected;
2063 oal_service_t svc_id;
2065 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
2068 * TODO: While adding support for new profiles, need to add more
2069 * <svc_type, svc_id> mapping here.
2072 case BT_PROFILE_CONN_HID:
2073 svc_id = HID_SERVICE_ID;
2075 case BT_PROFILE_CONN_A2DP:
2076 svc_id = A2DP_SERVICE_ID; /* Remote is A2DP Sink */
2078 case BT_PROFILE_CONN_A2DP_SINK:
2079 svc_id = A2DP_SRC_SERVICE_ID; /* Remote is A2DP Source*/
2081 case BT_PROFILE_CONN_HSP:
2082 svc_id = HFP_HS_SERVICE_ID; /* Remote is HFP HF Unit */
2084 case BT_PROFILE_CONN_HFG:
2085 svc_id = HFP_SERVICE_ID; /* Remote is HFP AG Unit */
2087 case BT_PROFILE_CONN_GATT:
2088 return _bt_is_remote_gatt_device_connected(device_address); /* Remote is GATT client or Server */
2090 BT_DBG("Unknown svc_type: %d", svc_type);
2094 is_connected = device_get_svc_conn_state((bt_address_t*)device_address, svc_id);
2096 BT_DBG("svc_type: %d, is_connected: %s",
2097 svc_type, is_connected ? "TRUE" : "FALSE");
2099 return is_connected;
2102 int _bt_rfcomm_reply_conn_authorization(char *address, gboolean reply)
2104 bt_address_t bd_addr;
2109 retv_if(NULL == address, BLUETOOTH_ERROR_INVALID_PARAM);
2110 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2111 res = device_reply_auth_request(&bd_addr, 0, reply, FALSE);
2112 if (res != OAL_STATUS_SUCCESS) {
2113 BT_ERR("authorize_response: %d", res);
2114 return _bt_convert_oal_status_to_bt_error(res);
2118 return BLUETOOTH_ERROR_NONE;
2121 int _bt_enable_rssi(bluetooth_device_address_t *addr, int link_type,
2122 int low_threshold, int in_range_threshold, int high_threshold)
2125 bt_address_t bd_addr;
2129 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
2131 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
2132 result = device_enable_rssi_monitoring(&bd_addr, link_type,
2133 low_threshold, in_range_threshold, high_threshold);
2134 if (result != OAL_STATUS_SUCCESS) {
2135 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
2136 return _bt_convert_oal_status_to_bt_error(result);
2140 return BLUETOOTH_ERROR_NONE;
2143 int _bt_get_rssi_strength(bluetooth_device_address_t *addr, int link_type)
2146 bt_address_t bd_addr;
2150 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
2152 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
2153 result = device_get_connected_link_rssi_strength(&bd_addr, link_type);
2154 if (result != OAL_STATUS_SUCCESS) {
2155 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
2156 return _bt_convert_oal_status_to_bt_error(result);
2160 return BLUETOOTH_ERROR_NONE;
2163 int _bt_set_passkey_notification(const char *sender, gboolean enable)
2167 BT_INFO("Set passkey notification(sender:%s, %s)",
2168 sender, enable ? "Enable" : "Disable");
2170 result = device_enable_gap_auth_notifications(OAL_PASSKEY_DISPLAY, enable);
2171 if (OAL_STATUS_SUCCESS != result) {
2172 BT_ERR("device_enable_gap_auth_notifications error: [%d]", result);
2173 return _bt_convert_oal_status_to_bt_error(result);
2176 g_free(passkey_watcher);
2178 passkey_watcher = g_strdup(sender);
2180 passkey_watcher = NULL;
2182 return BLUETOOTH_ERROR_NONE;
2185 static int __bt_get_device_pin_code(const char *address, char *pin_code)
2189 BT_CHECK_PARAMETER(address, return);
2190 BT_CHECK_PARAMETER(pin_code, return);
2192 for (l = pin_info_list; l != NULL; l = l->next) {
2193 bt_pin_code_info_t *pin_info = l->data;
2195 if (!pin_info || !pin_info->address)
2198 if (g_strcmp0(pin_info->address, address) == 0) {
2199 g_strlcpy(pin_code, pin_info->pin_code,
2200 BLUETOOTH_PIN_CODE_MAX_LENGTH + 1);
2201 return BLUETOOTH_ERROR_NONE;
2205 return BLUETOOTH_ERROR_NOT_FOUND;
2208 int _bt_set_pin_code(bluetooth_device_address_t *device_address,
2209 bluetooth_device_pin_code_t *pin_code)
2211 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2212 bt_pin_code_info_t *pin_info = NULL;
2215 BT_CHECK_PARAMETER(device_address, return);
2216 BT_CHECK_PARAMETER(pin_code, return);
2217 retv_if(g_slist_length(pin_info_list) >= BT_DEVICE_PIN_CODE_SLOT_MAX,
2218 BLUETOOTH_ERROR_NO_RESOURCES);
2220 _bt_convert_addr_type_to_string(address, device_address->addr);
2222 for (l = pin_info_list; l != NULL; l = l->next) {
2225 if (!pin_info || !pin_info->address)
2228 if (g_strcmp0(pin_info->address, address) == 0) {
2229 g_free(pin_info->pin_code);
2230 pin_info->pin_code = g_strdup(pin_code->pin_code);
2231 return BLUETOOTH_ERROR_NONE;
2235 pin_info = g_malloc0(sizeof(bt_pin_code_info_t));
2236 pin_info->address = g_strdup(address);
2237 pin_info->pin_code = g_strdup(pin_code->pin_code);
2238 pin_info_list = g_slist_append(pin_info_list, pin_info);
2240 return BLUETOOTH_ERROR_NONE;
2243 int _bt_unset_pin_code(bluetooth_device_address_t *device_address)
2245 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2246 bt_pin_code_info_t *pin_info = NULL;
2251 BT_CHECK_PARAMETER(device_address, return);
2253 _bt_convert_addr_type_to_string(address, device_address->addr);
2255 for (l = pin_info_list; l != NULL; l = l->next) {
2258 if (!pin_info || !pin_info->address)
2261 if (g_strcmp0(pin_info->address, address) == 0) {
2262 pin_info_list = g_slist_remove(pin_info_list, pin_info);
2263 g_free(pin_info->address);
2264 g_free(pin_info->pin_code);
2271 return BLUETOOTH_ERROR_NONE;
2274 int _bt_device_get_ida(bluetooth_device_address_t *device_address, bluetooth_device_address_t *id_address)
2276 int result = BLUETOOTH_ERROR_NONE;
2277 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2279 _bt_convert_addr_type_to_string(address, device_address->addr);
2281 BT_DBG("getting IDA for remote device: [%s]", address);
2283 result = device_get_ida((bt_address_t*)device_address, (bt_address_t*)id_address);
2285 if (result != OAL_STATUS_SUCCESS) {
2286 BT_ERR("device_get_ida Failed %d", result);
2287 return _bt_convert_oal_status_to_bt_error(result);
2293 static bt_connected_le_dev_t *__bt_get_le_connected_dev_info(const char *address)
2296 bt_connected_le_dev_t *dev;
2301 for (l = le_connected_dev_list; l; l = g_slist_next(l)) {
2304 if (g_strcmp0(dev->address, address) == 0)
2310 static void __bt_le_conn_param_free(void *data)
2312 bt_le_conn_param_t *param = (bt_le_conn_param_t *)data;
2314 BT_DBG("%s", param->sender);
2315 g_free(param->sender);
2319 static void _bt_add_le_connected_dev_info(const char *address)
2321 bt_connected_le_dev_t *dev = NULL;
2326 dev = g_malloc0(sizeof(bt_connected_le_dev_t));
2327 dev->address = g_strdup(address);
2329 le_connected_dev_list = g_slist_append(le_connected_dev_list, dev);
2334 static void _bt_remove_le_connected_dev_info(const char *address)
2336 bt_connected_le_dev_t *dev = NULL;
2341 dev = __bt_get_le_connected_dev_info(address);
2345 g_slist_free_full(dev->senders, __bt_le_conn_param_free);
2346 le_connected_dev_list = g_slist_remove(le_connected_dev_list, dev);
2347 g_free(dev->address);
2353 static void _bt_handle_le_connected_dev_info(const char *address, gboolean connected)
2355 BT_DBG("update le_connected_dev_list");
2358 _bt_add_le_connected_dev_info(address);
2360 _bt_remove_le_connected_dev_info(address);
2363 static bt_le_conn_param_t *__bt_get_le_conn_param_info(bt_connected_le_dev_t *dev, const char *sender)
2366 bt_le_conn_param_t *param = NULL;
2368 if (!dev || !sender)
2371 for (l = dev->senders; l; l = g_slist_next(l)) {
2373 if (g_strcmp0(param->sender, sender) == 0)
2380 static gint __bt_compare_le_conn_param_key(gpointer *a, gpointer *b)
2382 bt_le_conn_param_t *parama = (bt_le_conn_param_t *)a;
2383 bt_le_conn_param_t *paramb = (bt_le_conn_param_t *)b;
2385 return parama->key > paramb->key;
2389 int _bt_add_le_conn_param_info(const char *address, const char *sender,
2390 float interval_min, float interval_max, guint16 latency, guint16 time_out)
2392 bt_connected_le_dev_t *dev = NULL;
2393 bt_le_conn_param_t *param = NULL;
2394 bt_le_conn_param_t *data = NULL;
2396 if (!address || !sender)
2397 return BLUETOOTH_ERROR_INVALID_PARAM;
2399 dev = __bt_get_le_connected_dev_info(address);
2401 return BLUETOOTH_ERROR_INTERNAL;
2403 param = __bt_get_le_conn_param_info(dev, sender);
2405 data = g_malloc0(sizeof(bt_le_conn_param_t));
2406 data->sender = g_strdup(sender);
2407 data->interval_min = interval_min;
2408 data->interval_max = interval_max;
2409 data->latency = latency;
2410 data->time_out = time_out;
2411 data->key = interval_min + (interval_max - interval_min)/2;
2413 if (param == NULL) {
2414 BT_DBG("Add param %s %s %f %f", address, sender, interval_min, interval_max);
2415 dev->senders = g_slist_append(dev->senders, data);
2417 BT_DBG("Update param %s %s %f %f", address, sender, interval_min, interval_max);
2418 dev->senders = g_slist_remove(dev->senders, param);
2419 g_free(param->sender);
2421 dev->senders = g_slist_append(dev->senders, data);
2424 /* Sorting. First element have the minimum interval */
2425 dev->senders = g_slist_sort(dev->senders,
2426 (GCompareFunc)__bt_compare_le_conn_param_key);
2428 return BLUETOOTH_ERROR_NONE;
2432 static int __bt_le_set_conn_parameter(const char *address,
2433 float interval_min, float interval_max,
2434 guint16 latency, guint16 time_out)
2436 bt_address_t dev_addr = { {0} };
2437 guint32 min, max, to;
2439 BT_INFO("Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
2440 interval_min, interval_max, latency, time_out);
2442 min = interval_min / BT_LE_CONN_INTERVAL_SPLIT;
2443 max = interval_max / BT_LE_CONN_INTERVAL_SPLIT;
2444 to = time_out / BT_LE_CONN_TO_SPLIT;
2446 BT_DBG("updating: Min interval: %d, Max interval: %d, Latency: %d, Supervision timeout: %d",
2447 min, max, latency, to);
2449 _bt_convert_addr_string_to_type(dev_addr.addr, address);
2451 return gattc_conn_param_update(&dev_addr, min, max, latency, to);
2454 int _bt_le_set_default_connection_param(const char *address,
2455 float interval_min, float interval_max,
2456 guint16 latency, guint16 time_out)
2458 return __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out);
2461 int _bt_remove_le_conn_param_info(const char *address, const char *sender)
2463 bt_connected_le_dev_t *dev = NULL;
2464 bt_le_conn_param_t *param = NULL;
2466 if (!address || !sender)
2467 return BLUETOOTH_ERROR_INVALID_PARAM;
2469 dev = __bt_get_le_connected_dev_info(address);
2471 return BLUETOOTH_ERROR_INTERNAL;
2473 param = __bt_get_le_conn_param_info(dev, sender);
2475 BT_DBG("Remove param %s %s ", address, sender);
2476 dev->senders = g_slist_remove(dev->senders, param);
2477 g_free(param->sender);
2481 return BLUETOOTH_ERROR_NONE;
2484 int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
2485 bluetooth_le_connection_param_t *param)
2488 return BLUETOOTH_ERROR_INVALID_PARAM;
2490 memset(param, 0x00, sizeof(bluetooth_le_connection_param_t));
2493 case BLUETOOTH_LE_CONNECTION_MODE_BALANCED:
2494 param->interval_min = BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL;
2495 param->interval_max = BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL;
2496 param->latency = BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY;
2497 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2500 case BLUETOOTH_LE_CONNECTION_MODE_LOW_LATENCY:
2501 param->interval_min = BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL;
2502 param->interval_max = BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL;
2503 param->latency = BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY;
2504 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2507 case BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER:
2508 param->interval_min = BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL;
2509 param->interval_max = BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL;
2510 param->latency = BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY;
2511 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2515 BT_ERR("Unhandled mode : %d", mode);
2519 return BLUETOOTH_ERROR_NONE;
2522 int _bt_le_connection_update(const char *sender,
2523 unsigned char *device_address,
2524 float interval_min, float interval_max,
2525 guint16 latency, guint16 time_out)
2527 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2528 guint32 min_supervision_to;
2529 bt_connected_le_dev_t *dev = NULL;
2530 bt_le_conn_param_t *param = NULL;
2531 int ret = BLUETOOTH_ERROR_NONE;
2533 BT_CHECK_PARAMETER(device_address, return);
2535 BT_DBG("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
2536 sender, interval_min, interval_max, latency, time_out);
2538 if (interval_min > interval_max ||
2539 interval_min < BT_LE_CONN_INTERVAL_MIN ||
2540 interval_max > BT_LE_CONN_INTERVAL_MAX) {
2541 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2545 if (time_out < BT_LE_CONN_SUPER_TO_MIN ||
2546 time_out > BT_LE_CONN_SUPER_TO_MAX) {
2547 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2551 if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) {
2552 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2557 * The Supervision_Timeout in milliseconds shall be larger than
2558 * (1 + Conn_Latency) * Conn_Interval_Max * 2,
2559 * where Conn_Interval_Max is given in milliseconds.
2562 min_supervision_to = (1 + latency) * interval_max * 2;
2563 if (time_out <= min_supervision_to) {
2564 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2568 _bt_convert_addr_type_to_string(address, device_address);
2569 BT_DBG("Remote device address: %s", address);
2571 _bt_add_le_conn_param_info(address, sender, interval_min, interval_max, 0, 2000);
2573 dev = __bt_get_le_connected_dev_info(address);
2575 BT_ERR("device not found in the list");
2576 ret = BLUETOOTH_ERROR_NOT_CONNECTED;
2580 if (g_slist_length(dev->senders) == 1)
2583 param = dev->senders->data;
2585 BT_DBG("dev %f, param %f, input %f", dev->interval_min, param->interval_min, interval_min);
2587 if (dev->interval_min == param->interval_min && dev->interval_max == param->interval_max) {
2588 BT_DBG("Skip due to same interval");
2592 interval_min = param->interval_min;
2593 interval_max = param->interval_max;
2597 ret = __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out);
2599 if (ret != OAL_STATUS_SUCCESS) {
2600 _bt_remove_le_conn_param_info(address, sender);
2601 BT_DBG("fail to update the LE connection parameter");
2602 ret = _bt_convert_oal_status_to_bt_error(ret);
2606 dev->interval_min = interval_min;
2607 dev->interval_max = interval_max;
2609 return BLUETOOTH_ERROR_NONE;
2614 int _bt_disconnect_device(bluetooth_device_address_t *device_address)
2616 int result = OAL_STATUS_SUCCESS;
2620 retv_if(!device_address, BLUETOOTH_ERROR_INVALID_PARAM);
2622 result = device_disconnect((bt_address_t *)device_address);
2623 if (result != OAL_STATUS_SUCCESS) {
2624 BT_DBG("Failed to disconnect device");
2625 return _bt_convert_oal_status_to_bt_error(result);
2629 return BLUETOOTH_ERROR_NONE;
2632 static gboolean __bt_ignore_auto_pairing_request(const char *address)
2637 char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
2645 if (address == NULL)
2648 /* Get the LAP(Lower Address part) */
2649 /* User BT_LOWER_ADDRESS_LENGTH+1 for lap_address to accomodate
2651 snprintf(lap_address, sizeof(lap_address), ",%s", address);
2653 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
2656 BT_ERR("fopen failed \n");
2660 fseek(fp, 0, SEEK_END);
2665 BT_ERR("Get file size failed \n");
2670 buffer = g_malloc0(sizeof(char) * size);
2671 result = fread((char *)buffer, 1, size, fp);
2673 if (result != size) {
2674 BT_ERR("Read Error\n");
2679 lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
2685 /* Write the data and insert new device data */
2686 for (i = 0; lines[i] != NULL; i++) {
2687 if (g_str_has_prefix(lines[i], "AddressBlacklist")) {
2688 temp_buffer = g_strconcat(lines[i], lap_address, NULL);
2690 lines[i] = temp_buffer;
2693 buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
2695 /* Fix : NULL_RETURNS */
2696 retv_if(buffer == NULL, FALSE);
2698 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "w");
2701 BT_ERR("fopen failed \n");
2706 BT_DBG("Buffer = %s\n", buffer);
2707 fwrite(buffer, 1, strlen(buffer), fp);