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 #ifdef TIZEN_GATT_CLIENT
45 #include "bt-service-gatt.h"
47 #include "bt-service-headset-connection.h"
48 #include "bt-service-main.h"
49 #ifdef TIZEN_MDM_ENABLE
50 #include "bt-service-mdm.h"
52 #ifdef TIZEN_FEATURE_BT_OBEX
53 #include "bt-service-obex-server.h"
55 #include "bt-service-util.h"
58 #include <oal-event.h>
59 #include <oal-manager.h>
60 #include <oal-adapter-mgr.h>
61 #include <oal-device-mgr.h>
63 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
64 #define MAX_BOND_RETRY_COUNT 3
66 #define BT_PASSKEY_MAX_LENGTH 4
68 #define BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT 6000 /* msec */
70 #define BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL 30 /* msec */
71 #define BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL 50 /* msec */
72 #define BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY 0 /* event */
74 #define BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL 10 /* msec */
75 #define BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL 30 /* msec */
76 #define BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY 0 /* event */
78 #define BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL 80 /* msec */
79 #define BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL 100 /* msec */
80 #define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY 2 /* event */
82 /* Bonding Info structure */
87 unsigned short conn_type;
88 gboolean is_cancelled_by_user;
89 gboolean is_device_creating;
90 bluetooth_device_address_t *dev_addr;
91 bt_remote_dev_info_t *dev_info;
94 /* Searching Info structure */
98 gboolean is_cancelled_by_user;
99 bluetooth_device_address_t *dev_addr;
100 bt_remote_dev_info_t *dev_info;
101 } bt_service_search_info_data_t;
103 /* Pairing Info structure */
106 gboolean is_autopair;
111 char addr[BT_ADDRESS_STRING_SIZE];
112 bt_remote_dev_info_t *dev_info;
113 } bt_incoming_bond_data_t;
115 /* Bonding and Pairing Informations */
116 bt_bond_data_t *trigger_bond_info;
117 bt_bond_data_t *trigger_unbond_info;
118 bt_pairing_data_t *trigger_pairing_info;
119 bt_service_search_info_data_t *service_search_info;
121 bt_incoming_bond_data_t *incoming_bond_info;
124 BT_DEVICE_BOND_STATE_NONE,
125 BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY,
126 BT_DEVICE_BOND_STATE_DISCOVERY_CANCELLED,
127 BT_DEVICE_BOND_STATE_REMOVE_BONDING,
128 BT_DEVICE_BOND_STATE_REMOVED_BONDING,
129 BT_DEVICE_BOND_STATE_STARTED,
130 BT_DEVICE_BOND_STATE_WAIT_PROP,
131 BT_DEVICE_BOND_STATE_WAIT_DID
136 BT_DEVICE_INCOMING_BOND_INFO,
137 BT_DEVICE_UNBOND_INFO
140 /* BT device bond state variable */
141 static bt_bond_state_e bt_device_bond_state;
142 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
143 static int bond_retry_count;
146 static char *passkey_watcher;
147 static GSList *pin_info_list = NULL;
149 /** DBFW+ Event Code */
151 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_INFO = 0x10,
152 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_CLOCK_INFO = 0x11,
153 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_PAGE_SLOTS = 0x12,
154 BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_LMP_TRACE = 0x13,
155 BT_DBFW_PLUS_EVENT_CODE_A2DP_INFO = 0x20,
156 BT_DBFW_PLUS_EVENT_CODE_HFP_INFO = 0x31,
157 BT_DBFW_PLUS_EVENT_CODE_HFP_SCO_PACKET_TYPE_INFO = 0x32,
158 } bt_dbfw_plus_event_code_t;
160 static int dbfw_rssi;
162 #ifdef TIZEN_GATT_CLIENT
168 } bt_connected_le_dev_t;
177 } bt_le_conn_param_t;
179 static GSList *le_connected_dev_list = NULL;
181 #define BT_LE_CONN_INTERVAL_MIN 7.5 /* msec */
182 #define BT_LE_CONN_INTERVAL_MAX 4000 /* msec */
183 #define BT_LE_CONN_SUPER_TO_MIN 100 /* msec */
184 #define BT_LE_CONN_SUPER_TO_MAX 32000 /* msec */
185 #define BT_LE_CONN_SLAVE_LATENCY_MAX 499
186 #define BT_LE_CONN_TO_SPLIT 10 /* msec */
187 #define BT_LE_CONN_INTERVAL_SPLIT 1.25 /* msec */
189 static void _bt_handle_le_connected_dev_info(const char *address, gboolean connected);
192 /* Forward declaration */
193 static void __bt_device_event_handler(int event_type, gpointer event_data);
194 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble);
197 static int __bt_device_handle_bond_state(void);
198 static void __bt_free_bond_info(uint8_t type);
199 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info);
200 static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr);
201 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr);
202 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event);
203 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond);
204 static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
205 gboolean connected, unsigned char type);
206 static void __bt_free_pairing_info(bt_pairing_data_t **p_info);
208 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info);
209 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event);
210 static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_info);
211 static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *dev_info);
212 static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info);
213 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event);
215 static void __bt_device_services_callback(event_dev_services_t* uuid_list);
216 static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remote_dev_info);
218 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info);
220 static int __bt_get_device_pin_code(const char *address, char *pin_code);
221 static gboolean __bt_ignore_auto_pairing_request(const char *address);
223 gboolean _bt_is_device_creating(void)
225 if (!trigger_bond_info)
227 return trigger_bond_info->is_device_creating;
230 void _bt_device_state_handle_callback_set_request(void)
232 _bt_service_register_event_handler_callback(
233 BT_DEVICE_MODULE, __bt_device_event_handler);
236 void __bt_device_handle_pending_requests(int result, int service_function,
237 void *user_data, unsigned int size)
241 invocation_info_t *req_info = NULL;
245 /* Get method invocation context */
246 for (l = _bt_get_invocation_list(); l != NULL; ) {
249 if (req_info == NULL || req_info->service_function != service_function)
252 switch (service_function) {
253 case BT_SEARCH_SERVICE: {
254 char *address = (char *)user_data;
255 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
256 BT_ERR("Unexpected: Info request pending for a different address!!");
259 BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
260 bt_sdp_info_t sdp_info;
262 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
263 _bt_convert_addr_string_to_type(sdp_info.device_addr.addr, address);
265 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
266 g_array_append_vals(out_param, &sdp_info, sizeof(bt_sdp_info_t));
267 _bt_service_method_return(req_info->context, out_param, result);
269 _bt_free_info_from_invocation_list(req_info);
270 g_array_free(out_param, TRUE);
274 case BT_BOND_DEVICE: {
275 char *address = (char *)user_data;
276 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
277 BT_ERR("Unexpected: Info request pending for a different address!!");
280 BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
281 bluetooth_device_info_t dev_info;
282 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
283 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
285 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
286 g_array_append_vals(out_param, &dev_info,
287 sizeof(bluetooth_device_info_t));
288 _bt_service_method_return(req_info->context, out_param, result);
290 _bt_free_info_from_invocation_list(req_info);
291 g_array_free(out_param, TRUE);
295 case BT_UNBOND_DEVICE: {
296 char *address = (char *)user_data;
297 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
298 BT_ERR("Unexpected: Info request pending for a different address!!");
301 BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
302 bluetooth_device_address_t dev_addr;
303 _bt_convert_addr_string_to_type(dev_addr.addr, address);
304 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
305 g_array_append_vals(out_param, &dev_addr,
306 sizeof(bluetooth_device_address_t));
307 _bt_service_method_return(req_info->context, out_param, result);
309 _bt_free_info_from_invocation_list(req_info);
310 g_array_free(out_param, TRUE);
315 BT_ERR("Unhandled case");
323 * Remote device properties are received on all following conditions
324 * a. When Bonding in on-going
325 * b. When device properties are updated\changed for a connected device
326 * (due to SDP or any other reason)
328 static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_dev_props)
330 bt_remote_dev_info_t *rem_info = NULL;
332 rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
333 _bt_copy_remote_dev(rem_info, &(oal_dev_props->device_info));
335 if (oal_dev_props->adv_len > 0) {
338 rem_info->manufacturer_data_len = oal_dev_props->adv_len;
339 rem_info->manufacturer_data =
340 g_memdup(oal_dev_props->adv_data,
341 oal_dev_props->adv_len);
342 BT_DBG("----Advertising Data Length: %d",
343 rem_info->manufacturer_data_len);
345 for (k = 0; k < rem_info->manufacturer_data_len; k++) {
346 BT_INFO("Check data[%d] = [[0x%x]",
347 k, oal_dev_props->adv_data[k]);
350 rem_info->manufacturer_data = NULL;
351 rem_info->manufacturer_data_len = 0;
354 /* a. Check if bonding is on-going, if yes, we MUST update the bonding device properties */
355 if (trigger_bond_info && !strcmp(trigger_bond_info->addr, rem_info->address)) {
356 BT_DBG("Bonding is ongoing, try update properties");
357 if (!trigger_bond_info->dev_info ||
358 (!trigger_bond_info->dev_info->name &&
359 !trigger_bond_info->dev_info->alias) ||
360 !trigger_bond_info->dev_info->address ||
361 trigger_bond_info->dev_info->uuid_count == 0) {
362 BT_DBG("Complete data is not present, Assigning rem_info");
363 if (!trigger_bond_info->dev_info)
364 trigger_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
365 _bt_copy_remote_dev_info(trigger_bond_info->dev_info, rem_info);
368 BT_DBG("Bonding dev addr has matched with remote dev properties address [%s]", rem_info->address);
369 __bt_handle_ongoing_bond(trigger_bond_info->dev_info, FALSE);
370 } else if (incoming_bond_info && !g_strcmp0(incoming_bond_info->addr, rem_info->address)) {
371 BT_DBG("Incoming Bond is ongoing, try update properties");
372 if (!incoming_bond_info->dev_info ||
373 (!incoming_bond_info->dev_info->name &&
374 !incoming_bond_info->dev_info->alias) ||
375 !incoming_bond_info->dev_info->address ||
376 incoming_bond_info->dev_info->uuid_count == 0) {
377 BT_DBG("Complete data is not present, Assigning rem_info");
378 if (!incoming_bond_info->dev_info)
379 incoming_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
380 _bt_copy_remote_dev_info(incoming_bond_info->dev_info, rem_info);
383 BT_DBG("Incoming Bond addr matches with remote dev properties address [%s]", rem_info->address);
384 __bt_handle_ongoing_bond(incoming_bond_info->dev_info, TRUE);
387 /* Add device to bonded list */
388 _bt_service_add_device_to_bonded_list(rem_info);
390 /* Handle SDP Device properties update */
391 if (service_search_info && service_search_info->dev_info) {
392 if (!strcmp(service_search_info->addr, rem_info->address)) {
393 BT_DBG("Properties received and SDP request pending, fill device properties and send event");
394 service_search_info->dev_info->class = rem_info->class;
395 service_search_info->dev_info->paired = rem_info->paired;
396 service_search_info->dev_info->connected = rem_info->connected;
397 service_search_info->dev_info->rssi = rem_info->rssi;
398 service_search_info->dev_info->addr_type = rem_info->addr_type;
399 service_search_info->dev_info->trust = rem_info->trust;
402 service_search_info->dev_info->manufacturer_data = NULL;
403 service_search_info->dev_info->manufacturer_data_len = 0;
405 __bt_handle_ongoing_device_service_search(service_search_info->dev_info);
409 _bt_free_remote_dev(rem_info);
412 static int __get_oal_trusted_profile(bluetooth_trusted_profile_t profile)
415 case TRUSTED_PROFILE_PBAP:
416 return OAL_TRUSTED_PROFILE_PBAP;
417 case TRUSTED_PROFILE_MAP:
418 return OAL_TRUSTED_PROFILE_MAP;
419 case TRUSTED_PROFILE_SAP:
420 return OAL_TRUSTED_PROFILE_SAP;
421 case TRUSTED_PROFILE_HFP_HF:
422 return OAL_TRUSTED_PROFILE_HFP_HF;
423 case TRUSTED_PROFILE_A2DP:
424 return OAL_TRUSTED_PROFILE_A2DP;
425 case TRUSTED_PROFILE_ALL:
426 return OAL_TRUSTED_PROFILE_ALL;
432 int _bt_set_trust_profile(bluetooth_device_address_t *addr,
433 bluetooth_trusted_profile_t profile, gboolean trust)
436 bt_address_t bd_addr;
437 oal_trusted_profile_e oal_profile;
441 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
443 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
444 oal_profile = __get_oal_trusted_profile(profile);
445 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
447 result = device_set_trust_profile(&bd_addr, oal_profile, trust);
448 if (result != OAL_STATUS_SUCCESS) {
449 BT_ERR("device_set_trust_profile error: [%d]", result);
450 return _bt_convert_oal_status_to_bt_error(result);
454 return BLUETOOTH_ERROR_NONE;
457 int _bt_get_trust_profile(bluetooth_device_address_t *addr,
458 bluetooth_trusted_profile_t profile, guint *trust)
461 bt_address_t bd_addr;
462 oal_trusted_profile_e oal_profile;
466 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
468 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
469 oal_profile = __get_oal_trusted_profile(profile);
470 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
472 result = device_get_trust_profile(&bd_addr, oal_profile, trust);
473 if (result != OAL_STATUS_SUCCESS) {
474 BT_ERR("device_set_trust_profile error: [%d]", result);
475 return _bt_convert_oal_status_to_bt_error(result);
479 return BLUETOOTH_ERROR_NONE;
482 static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remote_dev_info)
484 GVariant *param = NULL;
485 GVariant *uuids = NULL;
486 GVariantBuilder *builder = NULL;
487 GVariant *manufacturer_data;
491 BT_INFO("Send Service Search request event");
493 if (remote_dev_info->alias)
494 name = remote_dev_info->alias;
496 name = remote_dev_info->name;
498 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
499 for (i = 0; i < remote_dev_info->uuid_count; i++) {
500 g_variant_builder_add(builder, "s",
501 remote_dev_info->uuids[i]);
503 uuids = g_variant_new("as", builder);
504 g_variant_builder_unref(builder);
505 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
506 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
509 param = g_variant_new("(isunsbub@asn@ay)",
510 BLUETOOTH_ERROR_NONE,
511 remote_dev_info->address,
512 remote_dev_info->class,
513 remote_dev_info->rssi,
515 remote_dev_info->paired,
516 remote_dev_info->connected,
517 remote_dev_info->trust,
519 remote_dev_info->manufacturer_data_len,
521 /* Send the event to application */
522 _bt_send_event(BT_ADAPTER_EVENT,
523 BLUETOOTH_EVENT_SERVICE_SEARCHED,
526 __bt_free_service_search_info(&service_search_info);
530 static void __bt_device_services_callback(event_dev_services_t* uuid_list)
532 bt_remote_dev_info_t *rem_info = NULL;
536 if (trigger_bond_info && _bt_compare_adddress(trigger_bond_info->dev_addr,
537 (bluetooth_device_address_t *)&uuid_list->address) == TRUE) {
538 bluetooth_device_address_t *dev_addr = trigger_bond_info->dev_addr;
540 BT_DBG("Bonding dev addr has matched");
541 /* Bonding ongoing, Query device properties again */
542 if (BLUETOOTH_ERROR_NONE ==
543 _bt_device_get_bonded_device_info(dev_addr))
544 BT_DBG("_bt_device_get_bonded_device_info success");
546 BT_ERR("_bt_device_get_bonded_device_info failed");
549 if (service_search_info == NULL) {
551 BT_DBG("searching_info == NULL");
555 if (_bt_compare_adddress(service_search_info->dev_addr,
556 (bluetooth_device_address_t *)&uuid_list->address) == FALSE) {
557 BT_DBG("This device is not queried");
561 rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
562 memset(rem_info, 0x00, sizeof(bt_remote_dev_info_t));
564 rem_info->address = g_new0(char, BT_ADDRESS_STRING_SIZE);
565 _bt_convert_addr_type_to_string(rem_info->address, uuid_list->address.addr);
567 rem_info->uuid_count = uuid_list->num;
569 BT_INFO("Address [%s]", rem_info->address);
570 BT_INFO("Number of UUID's [%d]", rem_info->uuid_count);
571 if (rem_info->uuid_count > 0)
572 rem_info->uuids = g_new0(char *, rem_info->uuid_count);
574 /* Fill Remote Device Service List list */
575 for (i = 0; i < rem_info->uuid_count; i++) {
576 rem_info->uuids[i] = g_malloc0(BLUETOOTH_UUID_STRING_MAX);
577 _bt_uuid_to_string((service_uuid_t *)&uuid_list->service_list[i].uuid, rem_info->uuids[i]);
578 BT_DBG("UUID value=%s", rem_info->uuids[i]);
581 /* Update local cache */
582 _bt_update_remote_dev_property(rem_info->address, DEV_PROP_SERVICES, (void *)rem_info);
584 BT_DBG("DBUS return");
585 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_SEARCH_SERVICE,
586 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
588 /* Save UUID List of remote devices */
589 if (service_search_info->dev_info)
590 _bt_free_remote_dev(service_search_info->dev_info);
591 service_search_info->dev_info = rem_info;
593 /* Query Other device properties */
594 if (_bt_device_get_bonded_device_info(service_search_info->dev_addr) == BLUETOOTH_ERROR_NONE) {
595 BT_DBG("Bonded device info query posted to stack successfully");
597 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
598 __bt_free_service_search_info(&service_search_info);
603 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event)
605 oal_service_t service_id = auth_event->service_id;
606 gchar address[BT_ADDRESS_STR_LEN];
609 _bt_convert_addr_type_to_string(address, auth_event->address.addr);
611 BT_DBG("service_d: %d", service_id);
613 switch (service_id) {
615 BT_DBG("Incoming HID Profile conn Req from device addr [%s]", address);
617 case A2DP_SERVICE_ID:
618 BT_DBG("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
619 _bt_a2dp_src_handle_incoming_authorization(address, service_id);
621 case A2DP_SRC_SERVICE_ID:
622 BT_DBG("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
623 _bt_a2dp_sink_handle_incoming_authorization(address, service_id);
625 case AVRCP_SERVICE_ID:
626 BT_DBG("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
628 case AVRCP_CT_SERVICE_ID:
629 BT_DBG("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
631 #ifdef TIZEN_FEATURE_BT_OBEX
632 case OPP_SERVICE_ID: {
633 GVariant *param = NULL;
636 if (_bt_obex_server_is_custom() == false) {
637 /* Allow the connection for native OPP server */
641 name = g_strdup(address);
643 BT_DBG("Incoming OPP conn Req from device addr [%s]", address);
644 _bt_obex_server_set_pending_conn_auth_device_addr(address);
645 param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, name);
646 _bt_send_event(BT_OPP_SERVER_EVENT,
647 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE, param);
654 BT_DBG("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
655 _bt_audio_handle_incoming_authorization(address, service_id);
658 BT_DBG("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
660 case HSP_HS_SERVICE_ID:
661 case HFP_HS_SERVICE_ID:
662 BT_DBG("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
663 _bt_audio_handle_incoming_authorization(address, service_id);
666 case IOTIVITY_SERVICE_ID:
667 BT_DBG("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
671 /* For now, reject authorization for any service apart from above switch cases */
672 BT_DBG("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_id, address);
673 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, FALSE, FALSE);
674 if (res != OAL_STATUS_SUCCESS)
675 BT_ERR("authorize_response: %d", res);
679 /* Auto accept authorization request for HID, A2DP and AVRCP profiles */
680 BT_INFO("Auto Accept authorization");
681 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, TRUE, FALSE);
682 if (res != OAL_STATUS_SUCCESS)
683 BT_ERR("authorize_response: %d", res);
686 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond)
688 GVariant *param = NULL;
690 if ((remote_dev_info->name || remote_dev_info->alias)
691 && remote_dev_info->address
692 && remote_dev_info->uuids) {
693 GVariant *uuids = NULL;
694 GVariantBuilder *builder = NULL;
695 GVariant *manufacturer_data;
699 if (remote_dev_info->alias)
700 name = remote_dev_info->alias;
702 name = remote_dev_info->name;
704 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
705 for (i = 0; i < remote_dev_info->uuid_count; i++) {
706 g_variant_builder_add(builder, "s",
707 remote_dev_info->uuids[i]);
709 uuids = g_variant_new("as", builder);
710 g_variant_builder_unref(builder);
711 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
712 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
715 param = g_variant_new("(isunsbub@asn@ay)",
716 BLUETOOTH_ERROR_NONE,
717 remote_dev_info->address,
718 remote_dev_info->class,
719 remote_dev_info->rssi,
721 remote_dev_info->paired,
722 remote_dev_info->connected,
723 remote_dev_info->trust,
725 remote_dev_info->manufacturer_data_len,
727 /* Send the event to application */
728 _bt_send_event(BT_ADAPTER_EVENT,
729 BLUETOOTH_EVENT_BONDING_FINISHED,
731 BT_PERMANENT_LOG("Paired %s", remote_dev_info->address + 12);
732 BT_INFO_C("### Paired %s", remote_dev_info->address + 12);
734 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
736 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
737 __bt_free_pairing_info(&trigger_pairing_info);
740 BT_INFO("Lets wait for more remote device properties");
744 static void __handle_incoming_bond_created_event(bt_address_t *bd_addr)
746 char address[BT_ADDRESS_STRING_SIZE];
747 bluetooth_device_address_t dev_addr;
750 * BlueZ sends paired signal for each paired device, during activation,
751 * We should ignore this, otherwise application thinks that a new device
754 if (_bt_adapter_get_status() != BT_ACTIVATED) {
755 BT_DBG("BT is not activated, so ignore this");
759 _bt_convert_addr_type_to_string(address, bd_addr->addr);
760 if (!incoming_bond_info) {
761 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
763 if (g_strcmp0(incoming_bond_info->addr, address)) {
764 BT_DBG("Previous Bond address: [%s] differs from new address: [%s]",
765 address, incoming_bond_info->addr);
766 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
767 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
771 BT_INFO("Incoming bond successfully completed");
772 g_strlcpy(incoming_bond_info->addr, address, BT_ADDRESS_STRING_SIZE);
773 incoming_bond_info->dev_info = NULL;
775 _bt_convert_addr_string_to_type(dev_addr.addr, incoming_bond_info->addr);
776 if (BLUETOOTH_ERROR_NONE == _bt_device_get_bonded_device_info(&dev_addr)) {
777 BT_DBG("Bonded device info query posted to stack successfully");
779 BT_ERR("Bonded device info query failed");
780 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
785 static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr)
787 gchar address[BT_ADDRESS_STR_LEN];
788 bluetooth_device_address_t dev_addr;
790 if (trigger_bond_info == NULL) {
792 BT_DBG("trigger_bond_info == NULL, Handle incomming bond event");
793 __handle_incoming_bond_created_event(bd_addr);
797 _bt_convert_addr_type_to_string(address, bd_addr->addr);
798 if (g_strcmp0(trigger_bond_info->addr, address)) {
799 BT_DBG("Bonding address= [%s] is different from requested address =[%s]",
800 address, trigger_bond_info->addr);
801 __handle_incoming_bond_created_event(bd_addr);
805 /* Bonding state will be cleaned up & BONDING FINISHED EVENT
806 will be sent only when Properties are fetched from stack
807 Till that time lets not free trigger_bond_info.
808 However it is possible that while fetching device properties, internal
809 stack error can occur which can lead to no valid properties or
810 no properties at all. So in such cases, we must not wait for properties,
811 otherwise, it can lead to infinite wait */
812 _bt_convert_addr_string_to_type(dev_addr.addr,
813 trigger_bond_info->addr);
815 if (_bt_device_get_bonded_device_info(&dev_addr) == BLUETOOTH_ERROR_NONE) {
816 BT_DBG("Bonded device info query posted to stack successfully");
817 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
818 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
820 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
821 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
822 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
823 /* Destroy if at all device got bonded at stack level */
824 device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
826 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
827 __bt_free_pairing_info(&trigger_pairing_info);
831 /**********************************************************************************************
832 * Bond removal event can be triggered for following reasons -
833 * a. If Bonding procedure if failed (for Auth failed, Page timeout, cancelled by user etc)
834 * b. If Application requests for explicitly removing the bond
835 * c. When application attempt to create bond,bond is removed first which triggers this event
836 * c. is in-line with Bluedroid bond create\emoval architecture
837 *********************************************************************************************/
838 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr)
840 char address[BT_ADDRESS_STRING_SIZE];
842 _bt_convert_addr_type_to_string(address, bd_addr->addr);
843 _bt_service_remove_device_from_bonded_list(address);
845 if (trigger_unbond_info) {
846 BT_DBG("Bond removal request successfully handled, return DBUS and send event");
847 GVariant *param = NULL;
848 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_UNBOND_DEVICE,
849 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
850 param = g_variant_new("(is)", BLUETOOTH_ERROR_NONE, trigger_unbond_info->addr);
851 _bt_send_event(BT_ADAPTER_EVENT,
852 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
854 BT_PERMANENT_LOG("Unpaired %s", trigger_unbond_info->addr + 12);
855 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
856 __bt_free_pairing_info(&trigger_pairing_info);
857 } else if (trigger_bond_info) {
858 BT_ERR("Bonding was removed");
859 __bt_device_handle_bond_state();
863 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event)
866 oal_status_t status = bond_fail_event->status;
867 BT_INFO("Bonding failed, reason: %d", status);
870 case OAL_STATUS_RMT_DEVICE_DOWN:
872 if (trigger_bond_info) {
873 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
874 BT_INFO("OAL_STATUS_RMT_DEVICE_DOWN:Lets retry bonding!! retry count [%d]",
876 int ret = OAL_STATUS_SUCCESS;
877 if (bond_retry_count < MAX_BOND_RETRY_COUNT) {
878 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
879 if (ret != OAL_STATUS_SUCCESS) {
880 BT_ERR("Create Bond procedure could not suceed");
881 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
882 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
883 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
884 __bt_free_pairing_info(&trigger_pairing_info);
885 bond_retry_count = 0;
890 BT_ERR("Create Bond failed MAX_BOND_RETRY_COUNT TIMES!!");
891 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
892 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
893 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
894 __bt_free_pairing_info(&trigger_pairing_info);
895 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
896 bond_retry_count = 0;
902 case OAL_STATUS_AUTH_FAILED:
904 /*TODO Auto pairing status set & ignore auto pairing logics can be done at this point.
905 To be considered later*/
906 int result = BLUETOOTH_ERROR_INTERNAL;
907 BT_INFO("BT_OPERATION_STATUS_AUTH_FAILED");
909 BT_INFO("add device in pairing black list");
910 _bt_set_autopair_status_in_bonding_info(FALSE);
912 if (trigger_bond_info) {
913 __bt_ignore_auto_pairing_request(trigger_bond_info->addr);
914 BT_ERR("Create Bond procedure could not suceed, check if cancelled by User");
915 if (trigger_bond_info->is_cancelled_by_user) {
916 BT_ERR("Bonding is cancelled by user");
917 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
919 __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
920 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
921 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
924 __bt_free_pairing_info(&trigger_pairing_info);
927 case OAL_STATUS_ALREADY_CONNECT:
929 int result = BLUETOOTH_ERROR_ALREADY_CONNECT;
930 BT_INFO("OAL_STATUS_ALREADY_CONNECT");
932 if (trigger_bond_info) {
933 __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
934 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
935 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
939 case OAL_STATUS_INTERNAL_ERROR:
941 BT_INFO("OAL_STATUS_INTERNAL_ERROR");
942 if (trigger_unbond_info) {
943 BT_INFO("Bond removal request failed, return DBUS and send event");
944 GVariant *param = NULL;
945 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_UNBOND_DEVICE,
946 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
947 param = g_variant_new("(is)", BLUETOOTH_ERROR_INTERNAL, trigger_unbond_info->addr);
948 _bt_send_event(BT_ADAPTER_EVENT,
949 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
951 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
952 } else if (trigger_bond_info) {
953 if (__bt_device_handle_bond_state() != BLUETOOTH_ERROR_NONE) {
954 if (trigger_bond_info) {
955 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
956 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
957 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
962 __bt_free_pairing_info(&trigger_pairing_info);
967 BT_ERR("Unknown status of Bond failed event status [%d]", status);
975 static gboolean __bt_device_init_dbfw_rssi_cb(gpointer user_data)
981 static void __bt_device_parse_dbfw_set_rssi(unsigned char *data, uint32_t length)
984 dbfw_rssi = 0xFFFFFF00 | data[4];
985 BT_INFO("dbfw_rssi = %d", dbfw_rssi);
986 g_timeout_add(1000, __bt_device_init_dbfw_rssi_cb, NULL);
989 static void __bt_device_dbfw_plus_info_callback(event_dev_dbfw_plus_info_t *dbfw_info)
992 char *data_str = NULL;
995 data_str = g_malloc0(dbfw_info->length * 2 + 1);
996 for (i = 0; i < dbfw_info->length; i++)
997 snprintf(&data_str[i * 2], 3, "%02X", dbfw_info->data[i]);
998 data_str[i * 2] = '\0';
1000 switch(dbfw_info->event_code) {
1001 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_INFO:
1002 BT_DBG("## Event Code: Linkloss Debug Info");
1003 snprintf(evt_str, 18, "[DBFW]Linkloss(D)");
1004 __bt_device_parse_dbfw_set_rssi(dbfw_info->data, dbfw_info->length);
1006 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_CLOCK_INFO:
1007 BT_DBG("## Event Code: Linkloss Clock Info");
1008 snprintf(evt_str, 18, "[DBFW]Linkloss(C)");
1010 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_PAGE_SLOTS:
1011 BT_DBG("## Event Code: Linkloss Page slots");
1012 snprintf(evt_str, 18, "[DBFW]Linkloss(P)");
1014 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_LMP_TRACE:
1015 BT_DBG("## Event Code: Linkloss LMP trace");
1016 snprintf(evt_str, 18, "[DBFW]Linkloss(L)");
1018 case BT_DBFW_PLUS_EVENT_CODE_A2DP_INFO:
1019 BT_DBG("## Event Code: A2DP Info");
1020 snprintf(evt_str, 18, "[DBFW]A2DP");
1022 case BT_DBFW_PLUS_EVENT_CODE_HFP_INFO:
1023 BT_DBG("## Event Code: HFP Info");
1024 snprintf(evt_str, 18, "[DBFW]HFP");
1026 case BT_DBFW_PLUS_EVENT_CODE_HFP_SCO_PACKET_TYPE_INFO:
1027 BT_DBG("## Event Code: HFP SCO Packet Type");
1028 snprintf(evt_str, 18, "[DBFW]SCO");
1031 BT_DBG("## Unknown event code (0x%02x)", dbfw_info->event_code);
1032 snprintf(evt_str, 18, "[DBFW]0x%02X", dbfw_info->event_code);
1036 BT_PERMANENT_LOG("%s 0x%s", evt_str, data_str);
1040 static void __bt_device_event_handler(int event_type, gpointer event_data)
1042 int eventcheck = OAL_EVENT_DEVICE_PROPERTIES;
1043 BT_DBG("event [%d] Event check = [%d]", event_type, eventcheck);
1045 switch (event_type) {
1046 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY: {
1047 BT_INFO("BREDR Device Found");
1048 __bt_device_remote_device_found_callback(event_data, FALSE);
1051 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE: {
1052 BT_INFO("Dual Device Found");
1053 __bt_device_remote_device_found_callback(event_data, FALSE);
1056 case OAL_EVENT_DEVICE_PROPERTIES: {
1057 BT_INFO("Remote Device properties Received");
1058 __bt_device_remote_properties_callback((event_dev_properties_t *)event_data);
1061 case OAL_EVENT_DEVICE_BONDING_SUCCESS: {
1062 BT_INFO("Bonding Success event Received");
1063 __bt_device_handle_bond_completion_event((bt_address_t *)event_data);
1066 case OAL_EVENT_DEVICE_BONDING_REMOVED: {
1067 BT_INFO("Bonding Removed event Received");
1068 __bt_device_handle_bond_removal_event((bt_address_t *)event_data);
1071 case OAL_EVENT_DEVICE_BONDING_FAILED: {
1072 BT_INFO("Bonding Failed event Received");
1073 __bt_device_handle_bond_failed_event((event_dev_bond_failed_t*) event_data);
1076 case OAL_EVENT_DEVICE_ACL_CONNECTED: {
1077 BT_DBG("ACL Connected event Received");
1078 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 0);
1081 case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
1082 BT_DBG("ACL Disconnected event Received");
1083 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 0);
1086 case OAL_EVENT_DEVICE_LE_CONNECTED: {
1087 BT_DBG("LE Connected event Received");
1088 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 1);
1091 case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
1092 BT_DBG("LE Disconnected event Received");
1093 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 1);
1096 case OAL_EVENT_DEVICE_PIN_REQUEST: {
1097 BT_INFO("PIN Request Received");
1098 __bt_device_pin_request_callback((remote_device_t*)event_data);
1101 case OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST: {
1102 BT_INFO("Passkey Entry request Received");
1103 __bt_device_ssp_passkey_entry_callback((remote_device_t*)event_data);
1106 case OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST:{
1107 BT_INFO("Passkey Confirmation Request Received");
1108 __bt_device_ssp_passkey_confirmation_callback((event_dev_passkey_t *)event_data);
1111 case OAL_EVENT_DEVICE_PASSKEY_DISPLAY: {
1112 BT_INFO("Passkey Display Request Received");
1113 __bt_device_ssp_passkey_display_callback((event_dev_passkey_t *)event_data);
1116 case OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST: {
1117 BT_INFO("SSP Consent Request Received");
1118 __bt_device_ssp_consent_callback((remote_device_t*)event_data);
1121 case OAL_EVENT_DEVICE_SERVICES: {
1122 BT_INFO("Remote Device Services Received");
1123 __bt_device_services_callback((event_dev_services_t*)event_data);
1126 case OAL_EVENT_DEVICE_AUTHORIZE_REQUEST: {
1127 BT_INFO("Remote Device Authorization Request");
1128 __bt_device_authorization_request_callback((event_dev_authorize_req_t*)event_data);
1131 case OAL_EVENT_DEVICE_TRUSTED: {
1132 BT_INFO("Remote Device Trusted");
1133 __bt_device_trusted_callback(TRUE, (event_dev_trust_t*)event_data);
1136 case OAL_EVENT_DEVICE_UNTRUSTED: {
1137 BT_INFO("Remote Device UnTrusted");
1138 __bt_device_trusted_callback(FALSE, (event_dev_trust_t*)event_data);
1141 case OAL_EVENT_DEVICE_NAME: {
1142 remote_device_t *rem_dev = event_data;
1143 gchar address[BT_ADDRESS_STR_LEN];
1145 _bt_convert_addr_type_to_string(address, rem_dev->address.addr);
1146 BT_INFO("Remote Device name Received");
1147 BT_INFO("Name: %s, Address: %s", rem_dev->name, address);
1149 /* Update local cache */
1150 _bt_update_remote_dev_property(address, DEV_PROP_NAME, (void *)rem_dev->name);
1153 case OAL_EVENT_DEVICE_TRUSTED_PROFILES_CHANGED: {
1154 event_device_trusted_profiles_t *ev = event_data;
1155 char address[BT_ADDRESS_STRING_SIZE];
1159 _bt_convert_addr_type_to_string(address, ev->address.addr);
1160 _bt_send_event(BT_DEVICE_EVENT,
1161 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1162 g_variant_new("(isi)", BLUETOOTH_ERROR_NONE,
1163 address, ev->trust_val));
1166 case OAL_EVENT_RSSI_MONITORING_ENABLED: {
1167 event_dev_rssi_info_t *ev = event_data;
1168 char address[BT_ADDRESS_STRING_SIZE];
1173 _bt_convert_addr_type_to_string(address, ev->address.addr);
1174 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1175 address, ev->link_type, TRUE);
1176 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1179 case OAL_EVENT_RSSI_MONITORING_DISABLED: {
1180 event_dev_rssi_info_t *ev = event_data;
1181 char address[BT_ADDRESS_STRING_SIZE];
1186 _bt_convert_addr_type_to_string(address, ev->address.addr);
1187 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1188 address, ev->link_type, FALSE);
1189 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1192 case OAL_EVENT_RSSI_ALERT_RECEIVED: {
1193 event_dev_rssi_info_t *ev = event_data;
1194 char address[BT_ADDRESS_STRING_SIZE];
1199 _bt_convert_addr_type_to_string(address, ev->address.addr);
1200 param = g_variant_new("(isiii)", BLUETOOTH_ERROR_NONE,
1201 address, ev->link_type, ev->alert_type, ev->rssi);
1202 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ALERT, param);
1205 case OAL_EVENT_RAW_RSSI_RECEIVED: {
1206 event_dev_rssi_info_t *ev = event_data;
1207 char address[BT_ADDRESS_STRING_SIZE];
1212 _bt_convert_addr_type_to_string(address, ev->address.addr);
1213 param = g_variant_new("(isii)", BLUETOOTH_ERROR_NONE,
1214 address, ev->link_type, ev->rssi);
1215 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RAW_RSSI, param);
1218 case OAL_EVENT_DEVICE_DBFW_PLUS_INFO: {
1219 __bt_device_dbfw_plus_info_callback((event_dev_dbfw_plus_info_t*)event_data);
1223 BT_INFO("Unhandled event..");
1227 /* Legacy Pairing event handler */
1228 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
1231 char address[BT_ADDRESS_STRING_SIZE];
1232 char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
1233 bool incoming = false;
1236 _bt_convert_addr_type_to_string(address, pin_req_event->address.addr);
1238 BT_INFO("Address[%s]", address);
1239 BT_INFO("Name[%s]", pin_req_event->name);
1240 BT_INFO("COD[%d]", pin_req_event->cod);
1242 if (trigger_pairing_info) {
1243 /* BTAPI support only one pairing at a time */
1244 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1245 BT_ERR("New PIN request address [%s]", address);
1246 device_reject_pin_request(&pin_req_event->address);
1250 /* If user initiated bonding and auto response is possible, just reply with default 0000*/
1251 if (_bt_is_bonding_device_address(address) == TRUE &&
1252 _bt_agent_is_auto_response(pin_req_event->cod, address, pin_req_event->name)) {
1253 /* Note: Currently even if SYSPOPUP is supported, we use Fixed PIN "0000" for basic pairing
1254 as BT SYSPOPUP is currently not working for PIN KEY entry in Tizen platform. This needs
1255 to be checked and fixed apropriately */
1256 _bt_set_autopair_status_in_bonding_info(TRUE);
1257 device_accept_pin_request(&pin_req_event->address, "0000");
1258 } else if (_bt_agent_is_hid_keyboard(pin_req_event->cod)) {
1259 BT_DBG("Remote Device is HID keyboard Type..");
1260 char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
1262 if (_bt_agent_generate_passkey(str_passkey,
1263 BT_PASSKEY_MAX_LENGTH) != 0) {
1264 device_reject_pin_request(&pin_req_event->address);
1267 device_accept_pin_request(&pin_req_event->address, str_passkey);
1269 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1271 if(trigger_bond_info == NULL)
1274 param = g_variant_new("(bsss)", incoming, address, pin_req_event->name, str_passkey);
1275 _bt_send_event(BT_ADAPTER_EVENT,
1276 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1277 BT_DBG("Key board pairing in process");
1278 } else if (BLUETOOTH_ERROR_NONE == __bt_get_device_pin_code(address, pin_code)) {
1279 BT_DBG("Use stored PIN code [%s]", pin_code);
1280 device_accept_pin_request(&pin_req_event->address, pin_code);
1282 if (_bt_is_bonding_device_address(address) == TRUE) {
1283 BT_DBG("Show Pin entry");
1284 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1285 trigger_pairing_info->addr = g_strdup(address);
1286 trigger_pairing_info->is_ssp = FALSE;
1288 BT_DBG("Send BLUETOOTH_EVENT_PIN_REQUEST");
1290 if(trigger_bond_info == NULL)
1293 param = g_variant_new("(bss)", incoming, address, pin_req_event->name);
1294 _bt_send_event(BT_ADAPTER_EVENT,
1295 BLUETOOTH_EVENT_PIN_REQUEST, param);
1300 _bt_agent_release_memory();
1304 /* SSP Pairing event handler */
1305 static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info)
1308 gchar address[BT_ADDRESS_STR_LEN];
1311 bool incoming = false;
1315 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1317 name = dev_info->name;
1319 BT_INFO("Address[%s]", address);
1320 BT_INFO("Name[%s]", name);
1321 BT_INFO("COD[%d]", dev_info->cod);
1323 if (trigger_pairing_info) {
1324 /* BTAPI support only one pairing at a time */
1325 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1326 BT_ERR("New PIN request address [%s]", address);
1327 device_reject_pin_request(&dev_info->address);
1332 /* Set pairing data */
1333 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1334 trigger_pairing_info->addr = g_strdup(address);
1335 trigger_pairing_info->is_ssp = TRUE;
1337 if(trigger_bond_info == NULL)
1340 param = g_variant_new("(bss)", incoming, p_addr, name);
1341 _bt_send_event(BT_ADAPTER_EVENT,
1342 BLUETOOTH_EVENT_PASSKEY_REQUEST, param);
1346 static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *dev_info)
1349 gchar address[BT_ADDRESS_STR_LEN];
1352 char str_passkey[7];
1353 bool incoming = false; /*Stores if bonding request is incoming(true) or outgoing(false) */
1356 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1358 name = dev_info->device_info.name;
1360 BT_INFO("Address[%s]", address);
1361 BT_INFO("Name[%s]", name);
1362 BT_INFO("COD[%d]", dev_info->device_info.cod);
1364 if (trigger_pairing_info) {
1365 /* BTAPI support only one pairing at a time */
1366 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1367 BT_ERR("New PIN request address [%s]", address);
1368 device_reject_pin_request(&dev_info->device_info.address);
1373 /* Set pairing data */
1374 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1375 trigger_pairing_info->addr = g_strdup(address);
1376 trigger_pairing_info->is_ssp = TRUE;
1378 BT_DBG("Send BLUETOOTH_EVENT_PASSKEY_CONFIRMATION");
1379 snprintf(str_passkey, sizeof(str_passkey), "%.6d", dev_info->pass_key);
1381 /*Storing if bond is incoming or outgoing*/
1382 if(trigger_bond_info == NULL)
1385 param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
1386 _bt_send_event(BT_ADAPTER_EVENT,
1387 BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST, param);
1391 static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_info)
1394 gchar address[BT_ADDRESS_STR_LEN];
1397 char str_passkey[7];
1398 bool incoming = false;
1401 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1403 name = dev_info->device_info.name;
1405 BT_INFO("Address[%s]", address);
1406 BT_INFO("Name[%s]", name);
1407 BT_INFO("COD[%d]", dev_info->device_info.cod);
1409 if (trigger_pairing_info) {
1410 /* BTAPI support only one pairing at a time */
1411 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1412 BT_ERR("New PIN request address [%s]", address);
1413 device_reject_pin_request(&dev_info->device_info.address);
1418 /* Set pairing data */
1419 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1420 trigger_pairing_info->addr = g_strdup(address);
1421 trigger_pairing_info->is_ssp = TRUE;
1423 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1424 snprintf(str_passkey, sizeof(str_passkey), "%06d", dev_info->pass_key);
1426 if(trigger_bond_info == NULL)
1429 param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
1431 if (passkey_watcher) {
1432 BT_INFO("Send passkey to %s", passkey_watcher);
1433 _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
1434 BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, param);
1436 _bt_send_event(BT_ADAPTER_EVENT,
1437 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1442 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info)
1444 gchar address[BT_ADDRESS_STR_LEN];
1451 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1452 name = dev_info->name;
1453 cod = dev_info->cod;
1455 BT_INFO("Address[%s]", address);
1456 BT_INFO("Name[%s]", name);
1457 BT_INFO("COD[%d]", cod);
1459 if (trigger_pairing_info) {
1460 /* BTAPI support only one pairing at a time */
1461 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1462 BT_ERR("New PIN request address [%s]", address);
1463 device_reject_pin_request(&dev_info->address);
1468 /* Set pairing data */
1469 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1470 trigger_pairing_info->addr = g_strdup(address);
1471 trigger_pairing_info->is_ssp = TRUE;
1473 local_major = ((cod >> 8) & 0x001f);
1474 local_minor = (cod & 0x00fc);
1475 BT_DBG("SSP_CONSENT: Major type=[0x%x] and Minor type=[0x%x]", local_major, local_minor);
1477 /*TODO: BLUETOOTH_EVENT_SSP_CONSENT_REQUEST to be handled in Tizen */
1481 static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
1482 gboolean connected, unsigned char type)
1484 gchar address[BT_ADDRESS_STR_LEN];
1485 int disc_reason = 0;
1486 GVariant *param = NULL;
1487 bt_device_conn_info_t conn_info;
1489 _bt_convert_addr_type_to_string(address, acl_event->address.addr);
1491 _bt_logging_connection(connected, type);
1493 disc_reason = acl_event->status;
1496 BT_PERMANENT_LOG("Connected %s %s", !type ? "EDR" : "LE", address + 12);
1497 param = g_variant_new("(isy)", BLUETOOTH_ERROR_NONE, address, type);
1498 _bt_send_event(BT_DEVICE_EVENT,
1499 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1502 BT_PERMANENT_LOG("Disconnected %s(%d) %s", !type ? "EDR" : "LE", disc_reason, address + 12);
1503 param = g_variant_new("(isyi)", disc_reason, address, type, dbfw_rssi);
1504 _bt_send_event(BT_DEVICE_EVENT,
1505 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1509 conn_info.connected = connected;
1510 conn_info.type = type;
1511 /* Update local cache */
1512 _bt_update_remote_dev_property(address, DEV_PROP_CONNECTED, (void *)&conn_info);
1514 #ifdef TIZEN_GATT_CLIENT
1515 /*handle LE connected device info*/
1517 _bt_handle_le_connected_dev_info(address, connected);
1522 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble)
1524 bt_remote_dev_info_t *dev_info = NULL;
1525 int result = BLUETOOTH_ERROR_NONE;
1526 GVariant *param = NULL;
1527 GVariant *uuids = NULL;
1528 GVariant *manufacturer_data = NULL;
1529 GVariantBuilder *builder = NULL;
1532 ret_if(_bt_is_discovering() == FALSE);
1533 ret_if(event_data == NULL);
1535 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
1538 event_ble_dev_found_t * oal_ble_dev = event_data;
1539 BT_INFO("Device type [%d]", oal_ble_dev->device_info.type);
1541 _bt_copy_remote_dev(dev_info, &oal_ble_dev->device_info);
1543 dev_info->manufacturer_data_len = oal_ble_dev->adv_len;
1544 if (dev_info->manufacturer_data_len)
1545 dev_info->manufacturer_data = g_memdup(oal_ble_dev->adv_data,
1546 dev_info->manufacturer_data_len);
1548 dev_info->manufacturer_data = NULL;
1549 BT_DBG("----Advertising Data Length: %d", dev_info->manufacturer_data_len);
1551 event_dev_found_t * oal_dev = event_data;
1552 _bt_copy_remote_dev(dev_info, &oal_dev->device_info);
1555 /* If Remote device name is NULL or still RNR is not done then display address as name. */
1556 if (dev_info->name == NULL)
1557 dev_info->name = g_strdup(dev_info->address);
1558 BT_DBG("Name %s", dev_info->name);
1560 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1561 for (i = 0; i < dev_info->uuid_count; i++)
1562 g_variant_builder_add(builder, "s", dev_info->uuids[i]);
1564 uuids = g_variant_new("as", builder);
1565 g_variant_builder_unref(builder);
1567 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1568 dev_info->manufacturer_data,
1569 dev_info->manufacturer_data_len,
1573 param = g_variant_new("(isunsbub@asn@ay)", result,
1579 dev_info->connected,
1582 dev_info->manufacturer_data_len,
1585 _bt_send_event(BT_ADAPTER_EVENT,
1586 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1589 _bt_free_remote_dev(dev_info);
1592 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info)
1594 gchar address[BT_ADDRESS_STR_LEN];
1595 int result = BLUETOOTH_ERROR_NONE;
1596 GVariant *param = NULL;
1599 _bt_convert_addr_type_to_string(address, info->address.addr);
1601 /* Update local cache */
1602 _bt_update_remote_dev_property(address, DEV_PROP_TRUST, (void *)&trusted);
1604 param = g_variant_new("(is)", result, address);
1605 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1606 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1607 /* Send event to application */
1608 _bt_send_event(BT_DEVICE_EVENT,
1614 static void __bt_free_pairing_info(bt_pairing_data_t **p_info)
1616 bt_pairing_data_t * info = *p_info;
1626 static void __bt_free_bond_info(uint8_t type)
1629 case BT_DEVICE_BOND_INFO:
1630 if (!trigger_bond_info)
1633 if (trigger_bond_info->addr)
1634 g_free(trigger_bond_info->addr);
1635 if (trigger_bond_info->dev_addr)
1636 g_free(trigger_bond_info->dev_addr);
1637 if (trigger_bond_info->dev_info)
1638 _bt_free_remote_dev(trigger_bond_info->dev_info);
1639 g_free(trigger_bond_info);
1640 trigger_bond_info = NULL;
1642 case BT_DEVICE_INCOMING_BOND_INFO:
1643 if (!incoming_bond_info)
1646 if (incoming_bond_info->dev_info)
1647 _bt_free_remote_dev(incoming_bond_info->dev_info);
1648 g_free(incoming_bond_info);
1649 incoming_bond_info = NULL;
1651 case BT_DEVICE_UNBOND_INFO:
1652 if (!trigger_unbond_info)
1655 if (trigger_unbond_info->addr)
1656 g_free(trigger_unbond_info->addr);
1657 if (trigger_unbond_info->dev_addr)
1658 g_free(trigger_unbond_info->dev_addr);
1659 if (trigger_unbond_info->dev_info)
1660 _bt_free_remote_dev(trigger_unbond_info->dev_info);
1661 g_free(trigger_unbond_info);
1662 trigger_unbond_info = NULL;
1667 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info)
1669 bt_service_search_info_data_t * info = *p_info;
1676 if (info->dev_addr) {
1677 g_free(info->dev_addr);
1678 info->dev_addr = NULL;
1681 if (info->dev_info) {
1682 _bt_free_remote_dev(info->dev_info);
1683 info->dev_info = NULL;
1691 static int __bt_device_handle_bond_state(void)
1693 BT_DBG("Current Bond state: %d", bt_device_bond_state);
1694 int ret = OAL_STATUS_INTERNAL_ERROR;
1696 switch (bt_device_bond_state) {
1697 case BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY:
1698 /*TODO:Bonding during discovery: Unhandled!!*/
1699 BT_INFO("Bonding during discovery: Unhandled!!");
1701 case BT_DEVICE_BOND_STATE_DISCOVERY_CANCELLED:
1702 /*TODO:Bonding during discovery: Unhandled!!*/
1703 BT_INFO("Bonding during discovery: Unhandled!!");
1705 case BT_DEVICE_BOND_STATE_REMOVE_BONDING:
1706 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING;
1707 ret = device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
1708 if (ret != OAL_STATUS_SUCCESS)
1709 ret = __bt_device_handle_bond_state();
1711 case BT_DEVICE_BOND_STATE_REMOVED_BONDING:
1712 bt_device_bond_state = BT_DEVICE_BOND_STATE_NONE;
1713 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
1714 /* Bonding procedure was started but unfortunately could not complete.
1715 Basically removed bonding was success, but create bond request could not proceed
1716 So lets cleanup the context */
1717 if (ret != OAL_STATUS_SUCCESS) {
1718 BT_ERR("Create Bond procedure could not suceed");
1719 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1720 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1721 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1722 __bt_free_pairing_info(&trigger_pairing_info);
1725 case BT_DEVICE_BOND_STATE_NONE:
1726 BT_INFO("Create Bond failed!!");
1727 if (trigger_bond_info) {
1728 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1729 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1730 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1731 __bt_free_pairing_info(&trigger_pairing_info);
1738 if (ret != OAL_STATUS_SUCCESS)
1739 return _bt_convert_oal_status_to_bt_error(ret);
1741 return BLUETOOTH_ERROR_NONE;
1744 int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr)
1747 bt_address_t bd_addr;
1749 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
1751 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
1752 result = device_query_attributes(&bd_addr);
1753 if (result != OAL_STATUS_SUCCESS) {
1754 BT_ERR("device_query_attributes error: [%d]", result);
1755 return _bt_convert_oal_status_to_bt_error(result);
1758 return BLUETOOTH_ERROR_NONE;
1761 int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias)
1764 char address[BT_ADDRESS_STRING_SIZE];
1766 BT_CHECK_PARAMETER(alias, return);
1768 ret = device_set_alias((bt_address_t *)device_address, (char *)alias);
1769 if (ret != OAL_STATUS_SUCCESS) {
1770 BT_ERR("device_set_alias: %d", ret);
1771 return _bt_convert_oal_status_to_bt_error(ret);
1774 /* Update local cache */
1775 _bt_convert_addr_type_to_string(address, device_address->addr);
1776 _bt_update_remote_dev_property(address, DEV_PROP_ALIAS, (void *)alias);
1778 return BLUETOOTH_ERROR_NONE;
1781 int _bt_bond_device(bluetooth_device_address_t *device_address,
1782 unsigned short conn_type, GArray **out_param1)
1784 int result = BLUETOOTH_ERROR_NONE;
1785 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1786 bluetooth_device_info_t dev_info;
1787 const char *stack_name = NULL;
1789 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1791 /* If bonding or discovery already going on */
1792 if (trigger_bond_info || _bt_is_discovering()) {
1793 BT_ERR("Device is buzy, bonding can not proceed now..");
1794 result = BLUETOOTH_ERROR_DEVICE_BUSY;
1798 /*TODO: If unbonding with same device going on */
1799 _bt_convert_addr_type_to_string(address, device_address->addr);
1801 trigger_bond_info = g_malloc0(sizeof(bt_bond_data_t));
1802 trigger_bond_info->addr = g_strdup(address);
1803 trigger_bond_info->conn_type = conn_type;
1804 trigger_bond_info->is_device_creating = TRUE;
1805 trigger_bond_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
1806 trigger_bond_info->dev_info = NULL;
1808 /* Ready to initiate bonding */
1810 stack_name = oal_get_stack_name();
1811 if (stack_name && !g_strcmp0(stack_name, "bluez")) {
1812 BT_DBG("[bluez] Create bond by type %d", conn_type);
1813 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING;
1815 /* In Tizen, we will first remove bond and then attempt to create bond to keep
1816 consistency with bluedroid. Even if remove bond fails due to device not already
1817 bonded, then straight away create bond is triggered. This is because, remove bond
1818 is handled differently in bluedroid and bluez. In Bluez, if device is
1819 already removed, remove bond call fails.
1820 However in bluedroid, remove bond on already removed device returns success. So we will
1821 handle the cases transparently */
1822 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVE_BONDING;
1825 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
1826 bond_retry_count = 0;
1828 result = __bt_device_handle_bond_state();
1830 if (result != BLUETOOTH_ERROR_NONE)
1836 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1837 memcpy(dev_info.device_address.addr, device_address->addr,
1838 BLUETOOTH_ADDRESS_LENGTH);
1840 g_array_append_vals(*out_param1, &dev_info,
1841 sizeof(bluetooth_device_info_t));
1842 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1847 int _bt_unbond_device(bluetooth_device_address_t *device_address,
1848 GArray **out_param1)
1850 int result = OAL_STATUS_SUCCESS;
1851 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1852 bluetooth_device_info_t dev_info;
1854 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1856 _bt_convert_addr_type_to_string(address, device_address->addr);
1858 trigger_unbond_info = g_malloc0(sizeof(bt_bond_data_t));
1859 trigger_unbond_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1860 trigger_unbond_info->addr = g_strdup(address);
1861 trigger_unbond_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
1863 /* Check if Bonding is already going on, we should not abruptly remove bonding*/
1864 if (trigger_bond_info && strncmp(trigger_bond_info->addr, trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE) == 0) {
1865 BT_ERR("Bonding with same device already ongoing");
1866 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
1870 _bt_stop_timer_for_connection();
1871 result = device_destroy_bond((bt_address_t *)device_address);
1872 if (result != OAL_STATUS_SUCCESS)
1875 return BLUETOOTH_ERROR_NONE;
1878 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1879 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1880 trigger_unbond_info->addr);
1882 g_array_append_vals(*out_param1, &dev_info,
1883 sizeof(bluetooth_device_info_t));
1884 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
1886 return _bt_convert_oal_status_to_bt_error(result);
1889 int _bt_cancel_bonding(void)
1891 int result = OAL_STATUS_SUCCESS;
1894 retv_if(trigger_bond_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
1896 result = device_stop_bond((bt_address_t *)trigger_bond_info->dev_addr);
1898 if (result == OAL_STATUS_SUCCESS)
1899 trigger_bond_info->is_cancelled_by_user = TRUE;
1904 int _bt_passkey_reply(const char *passkey, gboolean cnfm_reply)
1906 bluetooth_device_address_t device_address;
1907 int ret = OAL_STATUS_SUCCESS;
1908 BT_INFO("reply: %d", cnfm_reply);
1910 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1911 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1913 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1915 if (trigger_pairing_info->is_ssp) {
1917 ret = device_accept_passkey_entry((bt_address_t *)&device_address, atoi(passkey));
1919 ret = device_reject_passkey_entry((bt_address_t *)&device_address);
1920 trigger_pairing_info->is_ssp = FALSE;
1923 ret = device_accept_pin_request((bt_address_t *)&device_address, passkey);
1925 ret = device_reject_pin_request((bt_address_t *)&device_address);
1928 __bt_free_pairing_info(&trigger_pairing_info);
1930 if (ret != OAL_STATUS_SUCCESS) {
1931 BT_ERR("_bt_device_handle_passkey_reply: err [%d]", ret);
1932 return _bt_convert_oal_status_to_bt_error(ret);
1936 return BLUETOOTH_ERROR_NONE;
1939 int _bt_passkey_confirmation_reply(gboolean cnfm_reply)
1941 BT_INFO("BT_PASSKEY_CONFIRMATION_REPLY");
1942 bluetooth_device_address_t device_address;
1943 int ret = OAL_STATUS_SUCCESS;
1944 BT_INFO("reply: %d", cnfm_reply);
1946 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1947 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1949 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1951 ret = device_reply_passkey_confirmation((bt_address_t *)&device_address, cnfm_reply);
1953 __bt_free_pairing_info(&trigger_pairing_info);
1954 if (ret != OAL_STATUS_SUCCESS) {
1955 BT_ERR("_bt_device_handle_passkey_confirmation_reply: err [%d]", ret);
1956 return BLUETOOTH_ERROR_INTERNAL;
1960 return BLUETOOTH_ERROR_NONE;
1963 gboolean _bt_device_is_pairing(void)
1965 return (trigger_pairing_info) ? TRUE : FALSE;
1968 gboolean _bt_device_is_bonding(void)
1970 return (trigger_bond_info) ? TRUE : FALSE;
1973 gboolean _bt_is_bonding_device_address(const char *address)
1975 if (trigger_bond_info == NULL || trigger_bond_info->addr == NULL)
1978 if (g_strcmp0(trigger_bond_info->addr, address) == 0) {
1979 BT_DBG("[%s] is bonding device", address);
1983 BT_DBG("[%s] is NOT bonding device", address);
1987 void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
1989 ret_if(trigger_bond_info == NULL);
1990 trigger_bond_info->is_autopair = is_autopair;
1993 int _bt_search_device(bluetooth_device_address_t *device_address)
1995 int result = OAL_STATUS_SUCCESS;
1998 BT_CHECK_PARAMETER(device_address, return);
2000 if (trigger_bond_info) {
2001 BT_ERR("Bonding in progress");
2002 return BLUETOOTH_ERROR_DEVICE_BUSY;
2005 if (service_search_info) {
2006 BT_ERR("Service searching in progress");
2007 return BLUETOOTH_ERROR_DEVICE_BUSY;
2010 /* allocate user data so that it can be retrieved in callback */
2011 service_search_info = g_malloc0(sizeof(bt_service_search_info_data_t));
2012 service_search_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2013 service_search_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
2015 _bt_convert_addr_type_to_string(service_search_info->addr,
2016 device_address->addr);
2018 result = device_query_services((bt_address_t *)device_address);
2020 if (result != OAL_STATUS_SUCCESS) {
2021 BT_ERR("Device Service Search Failed..: %d", result);
2022 __bt_free_service_search_info(&service_search_info);
2023 return _bt_convert_oal_status_to_bt_error(result);
2025 return BLUETOOTH_ERROR_NONE;
2028 int _bt_cancel_search_device(void)
2030 int ret = OAL_STATUS_SUCCESS;
2031 retv_if(service_search_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
2033 ret = device_stop_query_sevices((bt_address_t *)service_search_info->dev_addr);
2035 if (ret != OAL_STATUS_SUCCESS) {
2036 BT_ERR("SDP Cancel request failed [%d]", ret);
2037 return _bt_convert_oal_status_to_bt_error(ret);
2040 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_CANCEL_BY_USER, BT_SEARCH_SERVICE,
2041 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
2043 __bt_free_service_search_info(&service_search_info);
2045 return BLUETOOTH_ERROR_NONE;
2049 int _bt_set_authorization(bluetooth_device_address_t *device_address,
2052 int ret = OAL_STATUS_SUCCESS;
2055 BT_CHECK_PARAMETER(device_address, return);
2056 BT_INFO("Device to be Trusted? [%d]", authorize);
2058 ret = device_set_authorized((bt_address_t*)device_address, authorize);
2059 if (ret != OAL_STATUS_SUCCESS) {
2060 BT_ERR("device_set_authorized: %d", ret);
2061 return _bt_convert_oal_status_to_bt_error(ret);
2064 return BLUETOOTH_ERROR_NONE;
2067 gboolean _bt_is_device_connected(bluetooth_device_address_t *device_address, int svc_type)
2069 gboolean is_connected;
2070 oal_service_t svc_id;
2072 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
2075 * TODO: While adding support for new profiles, need to add more
2076 * <svc_type, svc_id> mapping here.
2079 case BT_PROFILE_CONN_HID:
2080 svc_id = HID_SERVICE_ID;
2082 case BT_PROFILE_CONN_A2DP:
2083 svc_id = A2DP_SERVICE_ID; /* Remote is A2DP Sink */
2085 case BT_PROFILE_CONN_A2DP_SINK:
2086 svc_id = A2DP_SRC_SERVICE_ID; /* Remote is A2DP Source*/
2088 case BT_PROFILE_CONN_HSP:
2089 svc_id = HFP_HS_SERVICE_ID; /* Remote is HFP HF Unit */
2091 case BT_PROFILE_CONN_HFG:
2092 svc_id = HFP_SERVICE_ID; /* Remote is HFP AG Unit */
2094 #ifdef TIZEN_GATT_CLIENT
2095 case BT_PROFILE_CONN_GATT:
2096 return _bt_is_remote_gatt_device_connected(device_address); /* Remote is GATT client or Server */
2099 BT_DBG("Unknown svc_type: %d", svc_type);
2103 is_connected = device_get_svc_conn_state((bt_address_t*)device_address, svc_id);
2105 BT_DBG("svc_type: %d, is_connected: %s",
2106 svc_type, is_connected ? "TRUE" : "FALSE");
2108 return is_connected;
2111 int _bt_rfcomm_reply_conn_authorization(char *address, gboolean reply)
2113 bt_address_t bd_addr;
2118 retv_if(NULL == address, BLUETOOTH_ERROR_INVALID_PARAM);
2119 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2120 res = device_reply_auth_request(&bd_addr, 0, reply, FALSE);
2121 if (res != OAL_STATUS_SUCCESS) {
2122 BT_ERR("authorize_response: %d", res);
2123 return _bt_convert_oal_status_to_bt_error(res);
2127 return BLUETOOTH_ERROR_NONE;
2130 int _bt_enable_rssi(bluetooth_device_address_t *addr, int link_type,
2131 int low_threshold, int in_range_threshold, int high_threshold)
2134 bt_address_t bd_addr;
2138 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
2140 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
2141 result = device_enable_rssi_monitoring(&bd_addr, link_type,
2142 low_threshold, in_range_threshold, high_threshold);
2143 if (result != OAL_STATUS_SUCCESS) {
2144 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
2145 return _bt_convert_oal_status_to_bt_error(result);
2149 return BLUETOOTH_ERROR_NONE;
2152 int _bt_get_rssi_strength(bluetooth_device_address_t *addr, int link_type)
2155 bt_address_t bd_addr;
2159 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
2161 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
2162 result = device_get_connected_link_rssi_strength(&bd_addr, link_type);
2163 if (result != OAL_STATUS_SUCCESS) {
2164 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
2165 return _bt_convert_oal_status_to_bt_error(result);
2169 return BLUETOOTH_ERROR_NONE;
2172 int _bt_set_passkey_notification(const char *sender, gboolean enable)
2176 BT_INFO("Set passkey notification(sender:%s, %s)",
2177 sender, enable ? "Enable" : "Disable");
2179 result = device_enable_gap_auth_notifications(OAL_PASSKEY_DISPLAY, enable);
2180 if (OAL_STATUS_SUCCESS != result) {
2181 BT_ERR("device_enable_gap_auth_notifications error: [%d]", result);
2182 return _bt_convert_oal_status_to_bt_error(result);
2185 g_free(passkey_watcher);
2187 passkey_watcher = g_strdup(sender);
2189 passkey_watcher = NULL;
2191 return BLUETOOTH_ERROR_NONE;
2194 static int __bt_get_device_pin_code(const char *address, char *pin_code)
2198 BT_CHECK_PARAMETER(address, return);
2199 BT_CHECK_PARAMETER(pin_code, return);
2201 for (l = pin_info_list; l != NULL; l = l->next) {
2202 bt_pin_code_info_t *pin_info = l->data;
2204 if (!pin_info || !pin_info->address)
2207 if (g_strcmp0(pin_info->address, address) == 0) {
2208 g_strlcpy(pin_code, pin_info->pin_code,
2209 BLUETOOTH_PIN_CODE_MAX_LENGTH + 1);
2210 return BLUETOOTH_ERROR_NONE;
2214 return BLUETOOTH_ERROR_NOT_FOUND;
2217 int _bt_set_pin_code(bluetooth_device_address_t *device_address,
2218 bluetooth_device_pin_code_t *pin_code)
2220 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2221 bt_pin_code_info_t *pin_info = NULL;
2224 BT_CHECK_PARAMETER(device_address, return);
2225 BT_CHECK_PARAMETER(pin_code, return);
2226 retv_if(g_slist_length(pin_info_list) >= BT_DEVICE_PIN_CODE_SLOT_MAX,
2227 BLUETOOTH_ERROR_NO_RESOURCES);
2229 _bt_convert_addr_type_to_string(address, device_address->addr);
2231 for (l = pin_info_list; l != NULL; l = l->next) {
2234 if (!pin_info || !pin_info->address)
2237 if (g_strcmp0(pin_info->address, address) == 0) {
2238 g_free(pin_info->pin_code);
2239 pin_info->pin_code = g_strdup(pin_code->pin_code);
2240 return BLUETOOTH_ERROR_NONE;
2244 pin_info = g_malloc0(sizeof(bt_pin_code_info_t));
2245 pin_info->address = g_strdup(address);
2246 pin_info->pin_code = g_strdup(pin_code->pin_code);
2247 pin_info_list = g_slist_append(pin_info_list, pin_info);
2249 return BLUETOOTH_ERROR_NONE;
2252 int _bt_unset_pin_code(bluetooth_device_address_t *device_address)
2254 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2255 bt_pin_code_info_t *pin_info = NULL;
2260 BT_CHECK_PARAMETER(device_address, return);
2262 _bt_convert_addr_type_to_string(address, device_address->addr);
2264 for (l = pin_info_list; l != NULL; l = l->next) {
2267 if (!pin_info || !pin_info->address)
2270 if (g_strcmp0(pin_info->address, address) == 0) {
2271 pin_info_list = g_slist_remove(pin_info_list, pin_info);
2272 g_free(pin_info->address);
2273 g_free(pin_info->pin_code);
2280 return BLUETOOTH_ERROR_NONE;
2283 int _bt_device_get_ida(bluetooth_device_address_t *device_address, bluetooth_device_address_t *id_address)
2285 int result = BLUETOOTH_ERROR_NONE;
2286 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2288 _bt_convert_addr_type_to_string(address, device_address->addr);
2290 BT_DBG("getting IDA for remote device: [%s]", address);
2292 result = device_get_ida((bt_address_t*)device_address, (bt_address_t*)id_address);
2294 if (result != OAL_STATUS_SUCCESS) {
2295 BT_ERR("device_get_ida Failed %d", result);
2296 return _bt_convert_oal_status_to_bt_error(result);
2302 #ifdef TIZEN_GATT_CLIENT
2303 static bt_connected_le_dev_t *__bt_get_le_connected_dev_info(const char *address)
2306 bt_connected_le_dev_t *dev;
2311 for (l = le_connected_dev_list; l; l = g_slist_next(l)) {
2314 if (g_strcmp0(dev->address, address) == 0)
2320 static void __bt_le_conn_param_free(void *data)
2322 bt_le_conn_param_t *param = (bt_le_conn_param_t *)data;
2324 BT_DBG("%s", param->sender);
2325 g_free(param->sender);
2329 static void _bt_add_le_connected_dev_info(const char *address)
2331 bt_connected_le_dev_t *dev = NULL;
2336 dev = g_malloc0(sizeof(bt_connected_le_dev_t));
2337 dev->address = g_strdup(address);
2339 le_connected_dev_list = g_slist_append(le_connected_dev_list, dev);
2344 static void _bt_remove_le_connected_dev_info(const char *address)
2346 bt_connected_le_dev_t *dev = NULL;
2351 dev = __bt_get_le_connected_dev_info(address);
2355 g_slist_free_full(dev->senders, __bt_le_conn_param_free);
2356 le_connected_dev_list = g_slist_remove(le_connected_dev_list, dev);
2357 g_free(dev->address);
2363 static void _bt_handle_le_connected_dev_info(const char *address, gboolean connected)
2365 BT_DBG("update le_connected_dev_list");
2368 _bt_add_le_connected_dev_info(address);
2370 _bt_remove_le_connected_dev_info(address);
2373 static bt_le_conn_param_t *__bt_get_le_conn_param_info(bt_connected_le_dev_t *dev, const char *sender)
2376 bt_le_conn_param_t *param = NULL;
2378 if (!dev || !sender)
2381 for (l = dev->senders; l; l = g_slist_next(l)) {
2383 if (g_strcmp0(param->sender, sender) == 0)
2390 static gint __bt_compare_le_conn_param_key(gpointer *a, gpointer *b)
2392 bt_le_conn_param_t *parama = (bt_le_conn_param_t *)a;
2393 bt_le_conn_param_t *paramb = (bt_le_conn_param_t *)b;
2395 return parama->key > paramb->key;
2399 int _bt_add_le_conn_param_info(const char *address, const char *sender,
2400 float interval_min, float interval_max, guint16 latency, guint16 time_out)
2402 bt_connected_le_dev_t *dev = NULL;
2403 bt_le_conn_param_t *param = NULL;
2404 bt_le_conn_param_t *data = NULL;
2406 if (!address || !sender)
2407 return BLUETOOTH_ERROR_INVALID_PARAM;
2409 dev = __bt_get_le_connected_dev_info(address);
2411 return BLUETOOTH_ERROR_INTERNAL;
2413 param = __bt_get_le_conn_param_info(dev, sender);
2415 data = g_malloc0(sizeof(bt_le_conn_param_t));
2416 data->sender = g_strdup(sender);
2417 data->interval_min = interval_min;
2418 data->interval_max = interval_max;
2419 data->latency = latency;
2420 data->time_out = time_out;
2421 data->key = interval_min + (interval_max - interval_min)/2;
2423 if (param == NULL) {
2424 BT_DBG("Add param %s %s %f %f", address, sender, interval_min, interval_max);
2425 dev->senders = g_slist_append(dev->senders, data);
2427 BT_DBG("Update param %s %s %f %f", address, sender, interval_min, interval_max);
2428 dev->senders = g_slist_remove(dev->senders, param);
2429 g_free(param->sender);
2431 dev->senders = g_slist_append(dev->senders, data);
2434 /* Sorting. First element have the minimum interval */
2435 dev->senders = g_slist_sort(dev->senders,
2436 (GCompareFunc)__bt_compare_le_conn_param_key);
2438 return BLUETOOTH_ERROR_NONE;
2442 static int __bt_le_set_conn_parameter(const char *address,
2443 float interval_min, float interval_max,
2444 guint16 latency, guint16 time_out)
2446 bt_address_t dev_addr = { {0} };
2447 guint32 min, max, to;
2449 BT_INFO("Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
2450 interval_min, interval_max, latency, time_out);
2452 min = interval_min / BT_LE_CONN_INTERVAL_SPLIT;
2453 max = interval_max / BT_LE_CONN_INTERVAL_SPLIT;
2454 to = time_out / BT_LE_CONN_TO_SPLIT;
2456 BT_DBG("updating: Min interval: %d, Max interval: %d, Latency: %d, Supervision timeout: %d",
2457 min, max, latency, to);
2459 _bt_convert_addr_string_to_type(dev_addr.addr, address);
2461 return gattc_conn_param_update(&dev_addr, min, max, latency, to);
2464 int _bt_remove_le_conn_param_info(const char *address, const char *sender)
2466 bt_connected_le_dev_t *dev = NULL;
2467 bt_le_conn_param_t *param = NULL;
2469 if (!address || !sender)
2470 return BLUETOOTH_ERROR_INVALID_PARAM;
2472 dev = __bt_get_le_connected_dev_info(address);
2474 return BLUETOOTH_ERROR_INTERNAL;
2476 param = __bt_get_le_conn_param_info(dev, sender);
2478 BT_DBG("Remove param %s %s ", address, sender);
2479 dev->senders = g_slist_remove(dev->senders, param);
2480 g_free(param->sender);
2484 return BLUETOOTH_ERROR_NONE;
2487 int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
2488 bluetooth_le_connection_param_t *param)
2491 return BLUETOOTH_ERROR_INVALID_PARAM;
2493 memset(param, 0x00, sizeof(bluetooth_le_connection_param_t));
2496 case BLUETOOTH_LE_CONNECTION_MODE_BALANCED:
2497 param->interval_min = BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL;
2498 param->interval_max = BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL;
2499 param->latency = BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY;
2500 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2503 case BLUETOOTH_LE_CONNECTION_MODE_LOW_LATENCY:
2504 param->interval_min = BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL;
2505 param->interval_max = BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL;
2506 param->latency = BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY;
2507 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2510 case BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER:
2511 param->interval_min = BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL;
2512 param->interval_max = BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL;
2513 param->latency = BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY;
2514 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2518 BT_ERR("Unhandled mode : %d", mode);
2522 return BLUETOOTH_ERROR_NONE;
2525 int _bt_le_connection_update(const char *sender,
2526 unsigned char *device_address,
2527 float interval_min, float interval_max,
2528 guint16 latency, guint16 time_out)
2530 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2531 guint32 min_supervision_to;
2532 bt_connected_le_dev_t *dev = NULL;
2533 bt_le_conn_param_t *param = NULL;
2534 int ret = BLUETOOTH_ERROR_NONE;
2536 BT_CHECK_PARAMETER(device_address, return);
2538 BT_DBG("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
2539 sender, interval_min, interval_max, latency, time_out);
2541 if (interval_min > interval_max ||
2542 interval_min < BT_LE_CONN_INTERVAL_MIN ||
2543 interval_max > BT_LE_CONN_INTERVAL_MAX) {
2544 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2548 if (time_out < BT_LE_CONN_SUPER_TO_MIN ||
2549 time_out > BT_LE_CONN_SUPER_TO_MAX) {
2550 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2554 if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) {
2555 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2560 * The Supervision_Timeout in milliseconds shall be larger than
2561 * (1 + Conn_Latency) * Conn_Interval_Max * 2,
2562 * where Conn_Interval_Max is given in milliseconds.
2565 min_supervision_to = (1 + latency) * interval_max * 2;
2566 if (time_out <= min_supervision_to) {
2567 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2571 _bt_convert_addr_type_to_string(address, device_address);
2572 BT_DBG("Remote device address: %s", address);
2574 _bt_add_le_conn_param_info(address, sender, interval_min, interval_max, 0, 2000);
2576 dev = __bt_get_le_connected_dev_info(address);
2578 BT_ERR("device not found in the list");
2579 ret = BLUETOOTH_ERROR_NOT_CONNECTED;
2583 if (g_slist_length(dev->senders) == 1)
2586 param = dev->senders->data;
2588 BT_DBG("dev %f, param %f, input %f", dev->interval_min, param->interval_min, interval_min);
2590 if (dev->interval_min == param->interval_min && dev->interval_max == param->interval_max) {
2591 BT_DBG("Skip due to same interval");
2595 interval_min = param->interval_min;
2596 interval_max = param->interval_max;
2600 ret = __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out);
2602 if (ret != OAL_STATUS_SUCCESS) {
2603 _bt_remove_le_conn_param_info(address, sender);
2604 BT_DBG("fail to update the LE connection parameter");
2605 ret = _bt_convert_oal_status_to_bt_error(ret);
2609 dev->interval_min = interval_min;
2610 dev->interval_max = interval_max;
2612 return BLUETOOTH_ERROR_NONE;
2617 int _bt_disconnect_device(bluetooth_device_address_t *device_address)
2619 int result = OAL_STATUS_SUCCESS;
2623 retv_if(!device_address, BLUETOOTH_ERROR_INVALID_PARAM);
2625 result = device_disconnect((bt_address_t *)device_address);
2626 if (result != OAL_STATUS_SUCCESS) {
2627 BT_DBG("Failed to disconnect device");
2628 return _bt_convert_oal_status_to_bt_error(result);
2632 return BLUETOOTH_ERROR_NONE;
2635 static gboolean __bt_ignore_auto_pairing_request(const char *address)
2640 char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
2648 if (address == NULL)
2651 /* Get the LAP(Lower Address part) */
2652 /* User BT_LOWER_ADDRESS_LENGTH+1 for lap_address to accomodate
2654 snprintf(lap_address, sizeof(lap_address), ",%s", address);
2656 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
2659 BT_ERR("fopen failed \n");
2663 fseek(fp, 0, SEEK_END);
2668 BT_ERR("Get file size failed \n");
2673 buffer = g_malloc0(sizeof(char) * size);
2674 result = fread((char *)buffer, 1, size, fp);
2676 if (result != size) {
2677 BT_ERR("Read Error\n");
2682 lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
2688 /* Write the data and insert new device data */
2689 for (i = 0; lines[i] != NULL; i++) {
2690 if (g_str_has_prefix(lines[i], "AddressBlacklist")) {
2691 temp_buffer = g_strconcat(lines[i], lap_address, NULL);
2693 lines[i] = temp_buffer;
2696 buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
2698 /* Fix : NULL_RETURNS */
2699 retv_if(buffer == NULL, FALSE);
2701 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "w");
2704 BT_ERR("fopen failed \n");
2709 BT_DBG("Buffer = %s\n", buffer);
2710 fwrite(buffer, 1, strlen(buffer), fp);