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 if (rem_info->manufacturer_data)
336 g_free(rem_info->manufacturer_data);
337 rem_info->manufacturer_data =
338 g_memdup2(oal_dev_props->adv_data,
339 oal_dev_props->adv_len);
340 BT_DBG("----Advertising Data Length: %d",
341 rem_info->manufacturer_data_len);
343 for (k = 0; k < rem_info->manufacturer_data_len; k++) {
344 BT_INFO("Check data[%d] = [[0x%x]",
345 k, oal_dev_props->adv_data[k]);
349 /* a. Check if bonding is on-going, if yes, we MUST update the bonding device properties */
350 if (trigger_bond_info && !strcmp(trigger_bond_info->addr, rem_info->address)) {
351 BT_DBG("Bonding is ongoing, try update properties");
352 if (!trigger_bond_info->dev_info ||
353 (!trigger_bond_info->dev_info->name &&
354 !trigger_bond_info->dev_info->alias) ||
355 !trigger_bond_info->dev_info->address ||
356 trigger_bond_info->dev_info->uuid_count == 0) {
357 BT_DBG("Complete data is not present, Assigning rem_info");
358 if (!trigger_bond_info->dev_info)
359 trigger_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
360 _bt_copy_remote_dev_info(trigger_bond_info->dev_info, rem_info);
363 BT_DBG("Bonding dev addr has matched with remote dev properties address [%s]", rem_info->address);
364 __bt_handle_ongoing_bond(trigger_bond_info->dev_info, FALSE);
365 } else if (incoming_bond_info && !g_strcmp0(incoming_bond_info->addr, rem_info->address)) {
366 BT_DBG("Incoming Bond is ongoing, try update properties");
367 if (!incoming_bond_info->dev_info ||
368 (!incoming_bond_info->dev_info->name &&
369 !incoming_bond_info->dev_info->alias) ||
370 !incoming_bond_info->dev_info->address ||
371 incoming_bond_info->dev_info->uuid_count == 0) {
372 BT_DBG("Complete data is not present, Assigning rem_info");
373 if (!incoming_bond_info->dev_info)
374 incoming_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
375 _bt_copy_remote_dev_info(incoming_bond_info->dev_info, rem_info);
378 BT_DBG("Incoming Bond addr matches with remote dev properties address [%s]", rem_info->address);
379 __bt_handle_ongoing_bond(incoming_bond_info->dev_info, TRUE);
382 /* Add device to bonded list */
383 _bt_service_add_device_to_bonded_list(rem_info);
385 /* Handle SDP Device properties update */
386 if (service_search_info && service_search_info->dev_info) {
387 if (!strcmp(service_search_info->addr, rem_info->address)) {
388 BT_DBG("Properties received and SDP request pending, fill device properties and send event");
389 service_search_info->dev_info->class = rem_info->class;
390 service_search_info->dev_info->paired = rem_info->paired;
391 service_search_info->dev_info->connected = rem_info->connected;
392 service_search_info->dev_info->rssi = rem_info->rssi;
393 service_search_info->dev_info->addr_type = rem_info->addr_type;
394 service_search_info->dev_info->trust = rem_info->trust;
397 service_search_info->dev_info->manufacturer_data = NULL;
398 service_search_info->dev_info->manufacturer_data_len = 0;
400 __bt_handle_ongoing_device_service_search(service_search_info->dev_info);
404 _bt_free_remote_dev(rem_info);
407 static int __get_oal_trusted_profile(bluetooth_trusted_profile_t profile)
410 case TRUSTED_PROFILE_PBAP:
411 return OAL_TRUSTED_PROFILE_PBAP;
412 case TRUSTED_PROFILE_MAP:
413 return OAL_TRUSTED_PROFILE_MAP;
414 case TRUSTED_PROFILE_SAP:
415 return OAL_TRUSTED_PROFILE_SAP;
416 case TRUSTED_PROFILE_HFP_HF:
417 return OAL_TRUSTED_PROFILE_HFP_HF;
418 case TRUSTED_PROFILE_A2DP:
419 return OAL_TRUSTED_PROFILE_A2DP;
420 case TRUSTED_PROFILE_ALL:
421 return OAL_TRUSTED_PROFILE_ALL;
427 int _bt_set_trust_profile(bluetooth_device_address_t *addr,
428 bluetooth_trusted_profile_t profile, gboolean trust)
431 bt_address_t bd_addr;
432 oal_trusted_profile_e oal_profile;
436 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
438 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
439 oal_profile = __get_oal_trusted_profile(profile);
440 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
442 result = device_set_trust_profile(&bd_addr, oal_profile, trust);
443 if (result != OAL_STATUS_SUCCESS) {
444 BT_ERR("device_set_trust_profile error: [%d]", result);
445 return _bt_convert_oal_status_to_bt_error(result);
449 return BLUETOOTH_ERROR_NONE;
452 int _bt_get_trust_profile(bluetooth_device_address_t *addr,
453 bluetooth_trusted_profile_t profile, guint *trust)
456 bt_address_t bd_addr;
457 oal_trusted_profile_e oal_profile;
461 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
463 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
464 oal_profile = __get_oal_trusted_profile(profile);
465 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
467 result = device_get_trust_profile(&bd_addr, oal_profile, trust);
468 if (result != OAL_STATUS_SUCCESS) {
469 BT_ERR("device_set_trust_profile error: [%d]", result);
470 return _bt_convert_oal_status_to_bt_error(result);
474 return BLUETOOTH_ERROR_NONE;
477 static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remote_dev_info)
479 GVariant *param = NULL;
480 GVariant *uuids = NULL;
481 GVariantBuilder *builder = NULL;
482 GVariant *manufacturer_data;
486 BT_INFO("Send Service Search request event");
488 if (remote_dev_info->alias)
489 name = remote_dev_info->alias;
491 name = remote_dev_info->name;
493 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
494 for (i = 0; i < remote_dev_info->uuid_count; i++) {
495 g_variant_builder_add(builder, "s",
496 remote_dev_info->uuids[i]);
498 uuids = g_variant_new("as", builder);
499 g_variant_builder_unref(builder);
500 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
501 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
504 param = g_variant_new("(isunsbub@asn@ay)",
505 BLUETOOTH_ERROR_NONE,
506 remote_dev_info->address,
507 remote_dev_info->class,
508 remote_dev_info->rssi,
510 remote_dev_info->paired,
511 remote_dev_info->connected,
512 remote_dev_info->trust,
514 remote_dev_info->manufacturer_data_len,
516 /* Send the event to application */
517 _bt_send_event(BT_ADAPTER_EVENT,
518 BLUETOOTH_EVENT_SERVICE_SEARCHED,
521 __bt_free_service_search_info(&service_search_info);
525 static void __bt_device_services_callback(event_dev_services_t* uuid_list)
527 bt_remote_dev_info_t *rem_info = NULL;
531 if (trigger_bond_info && _bt_compare_adddress(trigger_bond_info->dev_addr,
532 (bluetooth_device_address_t *)&uuid_list->address) == TRUE) {
533 bluetooth_device_address_t *dev_addr = trigger_bond_info->dev_addr;
535 BT_DBG("Bonding dev addr has matched");
536 /* Bonding ongoing, Query device properties again */
537 if (BLUETOOTH_ERROR_NONE ==
538 _bt_device_get_bonded_device_info(dev_addr))
539 BT_DBG("_bt_device_get_bonded_device_info success");
541 BT_ERR("_bt_device_get_bonded_device_info failed");
544 if (service_search_info == NULL) {
546 BT_DBG("searching_info == NULL");
550 if (_bt_compare_adddress(service_search_info->dev_addr,
551 (bluetooth_device_address_t *)&uuid_list->address) == FALSE) {
552 BT_DBG("This device is not queried");
556 rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
557 memset(rem_info, 0x00, sizeof(bt_remote_dev_info_t));
559 rem_info->address = g_new0(char, BT_ADDRESS_STRING_SIZE);
560 _bt_convert_addr_type_to_string(rem_info->address, uuid_list->address.addr);
562 rem_info->uuid_count = uuid_list->num;
564 BT_INFO("Address [%s]", rem_info->address);
565 BT_INFO("Number of UUID's [%d]", rem_info->uuid_count);
566 if (rem_info->uuid_count > 0)
567 rem_info->uuids = g_new0(char *, rem_info->uuid_count);
569 /* Fill Remote Device Service List list */
570 for (i = 0; i < rem_info->uuid_count; i++) {
571 rem_info->uuids[i] = g_malloc0(BLUETOOTH_UUID_STRING_MAX);
572 _bt_uuid_to_string((service_uuid_t *)&uuid_list->service_list[i].uuid, rem_info->uuids[i]);
573 BT_DBG("UUID value=%s", rem_info->uuids[i]);
576 /* Update local cache */
577 _bt_update_remote_dev_property(rem_info->address, DEV_PROP_SERVICES, (void *)rem_info);
579 BT_DBG("DBUS return");
580 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_SEARCH_SERVICE,
581 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
583 /* Save UUID List of remote devices */
584 if (service_search_info->dev_info)
585 _bt_free_remote_dev(service_search_info->dev_info);
586 service_search_info->dev_info = rem_info;
588 /* Query Other device properties */
589 if (_bt_device_get_bonded_device_info(service_search_info->dev_addr) == BLUETOOTH_ERROR_NONE) {
590 BT_DBG("Bonded device info query posted to stack successfully");
592 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
593 __bt_free_service_search_info(&service_search_info);
598 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event)
600 oal_service_t service_id = auth_event->service_id;
601 gchar address[BT_ADDRESS_STR_LEN];
604 _bt_convert_addr_type_to_string(address, auth_event->address.addr);
606 BT_DBG("service_d: %d", service_id);
608 switch (service_id) {
610 BT_DBG("Incoming HID Profile conn Req from device addr [%s]", address);
612 case A2DP_SERVICE_ID:
613 if (TIZEN_FEATURE_FHUB_REFERENCE)
614 BT_DBG("Incoming A2DP(Remote: Source) profile conn Req from device addr [%s]", address);
616 BT_DBG("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
617 _bt_a2dp_src_handle_incoming_authorization(address, service_id);
619 case A2DP_SRC_SERVICE_ID:
620 if (TIZEN_FEATURE_FHUB_REFERENCE)
621 BT_DBG("Incoming A2DP(Remote: Sink) profile conn Req from device addr [%s]", address);
623 BT_DBG("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
624 _bt_a2dp_sink_handle_incoming_authorization(address, service_id);
626 case AVRCP_SERVICE_ID:
627 if (TIZEN_FEATURE_FHUB_REFERENCE) {
628 BT_DBG("Incoming AVRCP (Remote: Target) Profile conn Req from device addr [%s]", address);
629 _bt_audio_handle_incoming_authorization(address, service_id);
632 BT_DBG("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
635 case AVRCP_CT_SERVICE_ID:
636 BT_DBG("Incoming AVRCP (Remote: Controller) Profile conn Req from device addr [%s]", address);
638 #ifdef TIZEN_FEATURE_BT_OBEX
639 case OPP_SERVICE_ID: {
640 GVariant *param = NULL;
643 if (_bt_obex_server_is_custom() == false) {
644 /* Allow the connection for native OPP server */
648 name = g_strdup(address);
650 BT_DBG("Incoming OPP conn Req from device addr [%s]", address);
651 _bt_obex_server_set_pending_conn_auth_device_addr(address);
652 param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, name);
653 _bt_send_event(BT_OPP_SERVER_EVENT,
654 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE, param);
661 BT_DBG("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
662 _bt_audio_handle_incoming_authorization(address, service_id);
665 BT_DBG("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
667 case HSP_HS_SERVICE_ID:
668 case HFP_HS_SERVICE_ID:
669 BT_DBG("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
670 _bt_audio_handle_incoming_authorization(address, service_id);
673 case IOTIVITY_SERVICE_ID:
674 BT_DBG("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
678 /* For now, reject authorization for any service apart from above switch cases */
679 BT_DBG("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_id, address);
680 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, FALSE, FALSE);
681 if (res != OAL_STATUS_SUCCESS)
682 BT_ERR("authorize_response: %d", res);
686 /* Auto accept authorization request for HID, A2DP and AVRCP profiles */
687 BT_INFO("Auto Accept authorization");
688 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, TRUE, FALSE);
689 if (res != OAL_STATUS_SUCCESS)
690 BT_ERR("authorize_response: %d", res);
693 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond)
695 GVariant *param = NULL;
697 if ((remote_dev_info->name || remote_dev_info->alias)
698 && remote_dev_info->address
699 && remote_dev_info->uuids) {
700 GVariant *uuids = NULL;
701 GVariantBuilder *builder = NULL;
702 GVariant *manufacturer_data;
706 if (remote_dev_info->alias)
707 name = remote_dev_info->alias;
709 name = remote_dev_info->name;
711 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
712 for (i = 0; i < remote_dev_info->uuid_count; i++) {
713 g_variant_builder_add(builder, "s",
714 remote_dev_info->uuids[i]);
716 uuids = g_variant_new("as", builder);
717 g_variant_builder_unref(builder);
718 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
719 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
722 param = g_variant_new("(isunsbub@asn@ay)",
723 BLUETOOTH_ERROR_NONE,
724 remote_dev_info->address,
725 remote_dev_info->class,
726 remote_dev_info->rssi,
728 remote_dev_info->paired,
729 remote_dev_info->connected,
730 remote_dev_info->trust,
732 remote_dev_info->manufacturer_data_len,
734 /* Send the event to application */
735 _bt_send_event(BT_ADAPTER_EVENT,
736 BLUETOOTH_EVENT_BONDING_FINISHED,
738 BT_PERMANENT_LOG("Paired %s", remote_dev_info->address + 12);
739 BT_INFO_C("### Paired %s", remote_dev_info->address + 12);
741 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
743 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
744 __bt_free_pairing_info(&trigger_pairing_info);
747 BT_INFO("Lets wait for more remote device properties");
751 static void __handle_incoming_bond_created_event(bt_address_t *bd_addr)
753 char address[BT_ADDRESS_STRING_SIZE];
754 bluetooth_device_address_t dev_addr;
757 * BlueZ sends paired signal for each paired device, during activation,
758 * We should ignore this, otherwise application thinks that a new device
761 if (_bt_adapter_get_status() != BT_ACTIVATED) {
762 BT_DBG("BT is not activated, so ignore this");
766 _bt_convert_addr_type_to_string(address, bd_addr->addr);
767 if (!incoming_bond_info) {
768 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
770 if (g_strcmp0(incoming_bond_info->addr, address)) {
771 BT_DBG("Previous Bond address: [%s] differs from new address: [%s]",
772 address, incoming_bond_info->addr);
773 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
774 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
778 BT_INFO("Incoming bond successfully completed");
779 g_strlcpy(incoming_bond_info->addr, address, BT_ADDRESS_STRING_SIZE);
780 incoming_bond_info->dev_info = NULL;
782 _bt_convert_addr_string_to_type(dev_addr.addr, incoming_bond_info->addr);
783 if (BLUETOOTH_ERROR_NONE == _bt_device_get_bonded_device_info(&dev_addr)) {
784 BT_DBG("Bonded device info query posted to stack successfully");
786 BT_ERR("Bonded device info query failed");
787 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
792 static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr)
794 gchar address[BT_ADDRESS_STR_LEN];
795 bluetooth_device_address_t dev_addr;
797 if (trigger_bond_info == NULL) {
799 BT_DBG("trigger_bond_info == NULL, Handle incomming bond event");
800 __handle_incoming_bond_created_event(bd_addr);
804 _bt_convert_addr_type_to_string(address, bd_addr->addr);
805 if (g_strcmp0(trigger_bond_info->addr, address)) {
806 BT_DBG("Bonding address= [%s] is different from requested address =[%s]",
807 address, trigger_bond_info->addr);
808 __handle_incoming_bond_created_event(bd_addr);
812 /* Bonding state will be cleaned up & BONDING FINISHED EVENT
813 will be sent only when Properties are fetched from stack
814 Till that time lets not free trigger_bond_info.
815 However it is possible that while fetching device properties, internal
816 stack error can occur which can lead to no valid properties or
817 no properties at all. So in such cases, we must not wait for properties,
818 otherwise, it can lead to infinite wait */
819 _bt_convert_addr_string_to_type(dev_addr.addr,
820 trigger_bond_info->addr);
822 if (_bt_device_get_bonded_device_info(&dev_addr) == BLUETOOTH_ERROR_NONE) {
823 BT_DBG("Bonded device info query posted to stack successfully");
824 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
825 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
827 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
828 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
829 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
830 /* Destroy if at all device got bonded at stack level */
831 device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
833 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
834 __bt_free_pairing_info(&trigger_pairing_info);
838 /**********************************************************************************************
839 * Bond removal event can be triggered for following reasons -
840 * a. If Bonding procedure if failed (for Auth failed, Page timeout, cancelled by user etc)
841 * b. If Application requests for explicitly removing the bond
842 * c. When application attempt to create bond,bond is removed first which triggers this event
843 * c. is in-line with Bluedroid bond create\emoval architecture
844 *********************************************************************************************/
845 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr)
847 char address[BT_ADDRESS_STRING_SIZE];
849 _bt_convert_addr_type_to_string(address, bd_addr->addr);
850 _bt_service_remove_device_from_bonded_list(address);
852 if (trigger_unbond_info) {
853 BT_DBG("Bond removal request successfully handled, return DBUS and send event");
854 GVariant *param = NULL;
855 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_UNBOND_DEVICE,
856 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
857 param = g_variant_new("(is)", BLUETOOTH_ERROR_NONE, trigger_unbond_info->addr);
858 _bt_send_event(BT_ADAPTER_EVENT,
859 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
861 BT_PERMANENT_LOG("Unpaired %s", trigger_unbond_info->addr + 12);
862 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
863 __bt_free_pairing_info(&trigger_pairing_info);
864 } else if (trigger_bond_info) {
865 BT_ERR("Bonding was removed");
866 __bt_device_handle_bond_state();
870 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event)
873 oal_status_t status = bond_fail_event->status;
874 BT_INFO("Bonding failed, reason: %d", status);
877 case OAL_STATUS_RMT_DEVICE_DOWN:
879 if (trigger_bond_info) {
880 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
881 BT_INFO("OAL_STATUS_RMT_DEVICE_DOWN:Lets retry bonding!! retry count [%d]",
883 int ret = OAL_STATUS_SUCCESS;
884 if (bond_retry_count < MAX_BOND_RETRY_COUNT) {
885 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
886 if (ret != OAL_STATUS_SUCCESS) {
887 BT_ERR("Create Bond procedure could not suceed");
888 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
889 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
890 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
891 __bt_free_pairing_info(&trigger_pairing_info);
892 bond_retry_count = 0;
897 BT_ERR("Create Bond failed MAX_BOND_RETRY_COUNT TIMES!!");
898 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
899 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
900 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
901 __bt_free_pairing_info(&trigger_pairing_info);
902 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
903 bond_retry_count = 0;
909 case OAL_STATUS_AUTH_FAILED:
911 /*TODO Auto pairing status set & ignore auto pairing logics can be done at this point.
912 To be considered later*/
913 int result = BLUETOOTH_ERROR_INTERNAL;
914 BT_INFO("BT_OPERATION_STATUS_AUTH_FAILED");
916 BT_INFO("add device in pairing black list");
917 _bt_set_autopair_status_in_bonding_info(FALSE);
919 if (trigger_bond_info) {
920 __bt_ignore_auto_pairing_request(trigger_bond_info->addr);
921 BT_ERR("Create Bond procedure could not suceed, check if cancelled by User");
922 if (trigger_bond_info->is_cancelled_by_user) {
923 BT_ERR("Bonding is cancelled by user");
924 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
926 __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
927 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
928 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
931 __bt_free_pairing_info(&trigger_pairing_info);
934 case OAL_STATUS_ALREADY_CONNECT:
936 int result = BLUETOOTH_ERROR_ALREADY_CONNECT;
937 BT_INFO("OAL_STATUS_ALREADY_CONNECT");
939 if (trigger_bond_info) {
940 __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
941 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
942 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
946 case OAL_STATUS_INTERNAL_ERROR:
948 BT_INFO("OAL_STATUS_INTERNAL_ERROR");
949 if (trigger_unbond_info) {
950 BT_INFO("Bond removal request failed, return DBUS and send event");
951 GVariant *param = NULL;
952 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_UNBOND_DEVICE,
953 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
954 param = g_variant_new("(is)", BLUETOOTH_ERROR_INTERNAL, trigger_unbond_info->addr);
955 _bt_send_event(BT_ADAPTER_EVENT,
956 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
958 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
959 } else if (trigger_bond_info) {
960 if (__bt_device_handle_bond_state() != BLUETOOTH_ERROR_NONE) {
961 if (trigger_bond_info) {
962 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
963 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
964 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
969 __bt_free_pairing_info(&trigger_pairing_info);
974 BT_ERR("Unknown status of Bond failed event status [%d]", status);
982 static gboolean __bt_device_init_dbfw_rssi_cb(gpointer user_data)
988 static void __bt_device_parse_dbfw_set_rssi(unsigned char *data, uint32_t length)
991 dbfw_rssi = 0xFFFFFF00 | data[4];
992 BT_INFO("dbfw_rssi = %d", dbfw_rssi);
993 g_timeout_add(1000, __bt_device_init_dbfw_rssi_cb, NULL);
996 static void __bt_device_dbfw_plus_info_callback(event_dev_dbfw_plus_info_t *dbfw_info)
999 char *data_str = NULL;
1002 data_str = g_malloc0(dbfw_info->length * 2 + 1);
1003 for (i = 0; i < dbfw_info->length; i++)
1004 snprintf(&data_str[i * 2], 3, "%02X", dbfw_info->data[i]);
1005 data_str[i * 2] = '\0';
1007 switch(dbfw_info->event_code) {
1008 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_INFO:
1009 BT_DBG("## Event Code: Linkloss Debug Info");
1010 snprintf(evt_str, 18, "[DBFW]Linkloss(D)");
1011 __bt_device_parse_dbfw_set_rssi(dbfw_info->data, dbfw_info->length);
1013 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_CLOCK_INFO:
1014 BT_DBG("## Event Code: Linkloss Clock Info");
1015 snprintf(evt_str, 18, "[DBFW]Linkloss(C)");
1017 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_PAGE_SLOTS:
1018 BT_DBG("## Event Code: Linkloss Page slots");
1019 snprintf(evt_str, 18, "[DBFW]Linkloss(P)");
1021 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_LMP_TRACE:
1022 BT_DBG("## Event Code: Linkloss LMP trace");
1023 snprintf(evt_str, 18, "[DBFW]Linkloss(L)");
1025 case BT_DBFW_PLUS_EVENT_CODE_A2DP_INFO:
1026 BT_DBG("## Event Code: A2DP Info");
1027 snprintf(evt_str, 18, "[DBFW]A2DP");
1029 case BT_DBFW_PLUS_EVENT_CODE_HFP_INFO:
1030 BT_DBG("## Event Code: HFP Info");
1031 snprintf(evt_str, 18, "[DBFW]HFP");
1033 case BT_DBFW_PLUS_EVENT_CODE_HFP_SCO_PACKET_TYPE_INFO:
1034 BT_DBG("## Event Code: HFP SCO Packet Type");
1035 snprintf(evt_str, 18, "[DBFW]SCO");
1038 BT_DBG("## Unknown event code (0x%02x)", dbfw_info->event_code);
1039 snprintf(evt_str, 18, "[DBFW]0x%02X", dbfw_info->event_code);
1043 BT_PERMANENT_LOG("%s 0x%s", evt_str, data_str);
1047 static void __bt_device_event_handler(int event_type, gpointer event_data)
1049 int eventcheck = OAL_EVENT_DEVICE_PROPERTIES;
1050 BT_DBG("event [%d] Event check = [%d]", event_type, eventcheck);
1052 switch (event_type) {
1053 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY: {
1054 BT_INFO("BREDR Device Found");
1055 __bt_device_remote_device_found_callback(event_data, FALSE);
1058 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE: {
1059 BT_INFO("Dual Device Found");
1060 __bt_device_remote_device_found_callback(event_data, FALSE);
1063 case OAL_EVENT_DEVICE_PROPERTIES: {
1064 BT_INFO("Remote Device properties Received");
1065 __bt_device_remote_properties_callback((event_dev_properties_t *)event_data);
1068 case OAL_EVENT_DEVICE_BONDING_SUCCESS: {
1069 BT_INFO("Bonding Success event Received");
1070 __bt_device_handle_bond_completion_event((bt_address_t *)event_data);
1073 case OAL_EVENT_DEVICE_BONDING_REMOVED: {
1074 BT_INFO("Bonding Removed event Received");
1075 __bt_device_handle_bond_removal_event((bt_address_t *)event_data);
1078 case OAL_EVENT_DEVICE_BONDING_FAILED: {
1079 BT_INFO("Bonding Failed event Received");
1080 __bt_device_handle_bond_failed_event((event_dev_bond_failed_t*) event_data);
1083 case OAL_EVENT_DEVICE_ACL_CONNECTED: {
1084 BT_DBG("ACL Connected event Received");
1085 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 0);
1088 case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
1089 BT_DBG("ACL Disconnected event Received");
1090 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 0);
1093 case OAL_EVENT_DEVICE_LE_CONNECTED: {
1094 BT_DBG("LE Connected event Received");
1095 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 1);
1098 case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
1099 BT_DBG("LE Disconnected event Received");
1100 __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 1);
1103 case OAL_EVENT_DEVICE_PIN_REQUEST: {
1104 BT_INFO("PIN Request Received");
1105 __bt_device_pin_request_callback((remote_device_t*)event_data);
1108 case OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST: {
1109 BT_INFO("Passkey Entry request Received");
1110 __bt_device_ssp_passkey_entry_callback((remote_device_t*)event_data);
1113 case OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST:{
1114 BT_INFO("Passkey Confirmation Request Received");
1115 __bt_device_ssp_passkey_confirmation_callback((event_dev_passkey_t *)event_data);
1118 case OAL_EVENT_DEVICE_PASSKEY_DISPLAY: {
1119 BT_INFO("Passkey Display Request Received");
1120 __bt_device_ssp_passkey_display_callback((event_dev_passkey_t *)event_data);
1123 case OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST: {
1124 BT_INFO("SSP Consent Request Received");
1125 __bt_device_ssp_consent_callback((remote_device_t*)event_data);
1128 case OAL_EVENT_DEVICE_SERVICES: {
1129 BT_INFO("Remote Device Services Received");
1130 __bt_device_services_callback((event_dev_services_t*)event_data);
1133 case OAL_EVENT_DEVICE_AUTHORIZE_REQUEST: {
1134 BT_INFO("Remote Device Authorization Request");
1135 __bt_device_authorization_request_callback((event_dev_authorize_req_t*)event_data);
1138 case OAL_EVENT_DEVICE_TRUSTED: {
1139 BT_INFO("Remote Device Trusted");
1140 __bt_device_trusted_callback(TRUE, (event_dev_trust_t*)event_data);
1143 case OAL_EVENT_DEVICE_UNTRUSTED: {
1144 BT_INFO("Remote Device UnTrusted");
1145 __bt_device_trusted_callback(FALSE, (event_dev_trust_t*)event_data);
1148 case OAL_EVENT_DEVICE_NAME: {
1149 remote_device_t *rem_dev = event_data;
1150 gchar address[BT_ADDRESS_STR_LEN];
1152 _bt_convert_addr_type_to_string(address, rem_dev->address.addr);
1153 BT_INFO("Remote Device name Received");
1154 BT_INFO("Name: %s, Address: %s", rem_dev->name, address);
1156 /* Update local cache */
1157 _bt_update_remote_dev_property(address, DEV_PROP_NAME, (void *)rem_dev->name);
1160 case OAL_EVENT_DEVICE_TRUSTED_PROFILES_CHANGED: {
1161 event_device_trusted_profiles_t *ev = event_data;
1162 char address[BT_ADDRESS_STRING_SIZE];
1166 _bt_convert_addr_type_to_string(address, ev->address.addr);
1167 _bt_send_event(BT_DEVICE_EVENT,
1168 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1169 g_variant_new("(isi)", BLUETOOTH_ERROR_NONE,
1170 address, ev->trust_val));
1173 case OAL_EVENT_RSSI_MONITORING_ENABLED: {
1174 event_dev_rssi_info_t *ev = event_data;
1175 char address[BT_ADDRESS_STRING_SIZE];
1180 _bt_convert_addr_type_to_string(address, ev->address.addr);
1181 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1182 address, ev->link_type, TRUE);
1183 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1186 case OAL_EVENT_RSSI_MONITORING_DISABLED: {
1187 event_dev_rssi_info_t *ev = event_data;
1188 char address[BT_ADDRESS_STRING_SIZE];
1193 _bt_convert_addr_type_to_string(address, ev->address.addr);
1194 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1195 address, ev->link_type, FALSE);
1196 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1199 case OAL_EVENT_RSSI_ALERT_RECEIVED: {
1200 event_dev_rssi_info_t *ev = event_data;
1201 char address[BT_ADDRESS_STRING_SIZE];
1206 _bt_convert_addr_type_to_string(address, ev->address.addr);
1207 param = g_variant_new("(isiii)", BLUETOOTH_ERROR_NONE,
1208 address, ev->link_type, ev->alert_type, ev->rssi);
1209 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ALERT, param);
1212 case OAL_EVENT_RAW_RSSI_RECEIVED: {
1213 event_dev_rssi_info_t *ev = event_data;
1214 char address[BT_ADDRESS_STRING_SIZE];
1219 _bt_convert_addr_type_to_string(address, ev->address.addr);
1220 param = g_variant_new("(isii)", BLUETOOTH_ERROR_NONE,
1221 address, ev->link_type, ev->rssi);
1222 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RAW_RSSI, param);
1225 case OAL_EVENT_DEVICE_DBFW_PLUS_INFO: {
1226 __bt_device_dbfw_plus_info_callback((event_dev_dbfw_plus_info_t*)event_data);
1230 BT_INFO("Unhandled event..");
1234 /* Legacy Pairing event handler */
1235 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
1238 char address[BT_ADDRESS_STRING_SIZE];
1239 char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
1240 bool incoming = false;
1243 _bt_convert_addr_type_to_string(address, pin_req_event->address.addr);
1245 BT_INFO("Address[%s]", address);
1246 BT_INFO("Name[%s]", pin_req_event->name);
1247 BT_INFO("COD[%d]", pin_req_event->cod);
1249 if (trigger_pairing_info) {
1250 /* BTAPI support only one pairing at a time */
1251 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1252 BT_ERR("New PIN request address [%s]", address);
1253 device_reject_pin_request(&pin_req_event->address);
1257 /* If user initiated bonding and auto response is possible, just reply with default 0000*/
1258 if (_bt_is_bonding_device_address(address) == TRUE &&
1259 _bt_agent_is_auto_response(pin_req_event->cod, address, pin_req_event->name)) {
1260 /* Note: Currently even if SYSPOPUP is supported, we use Fixed PIN "0000" for basic pairing
1261 as BT SYSPOPUP is currently not working for PIN KEY entry in Tizen platform. This needs
1262 to be checked and fixed apropriately */
1263 _bt_set_autopair_status_in_bonding_info(TRUE);
1264 device_accept_pin_request(&pin_req_event->address, "0000");
1265 } else if (_bt_agent_is_hid_keyboard(pin_req_event->cod)) {
1266 BT_DBG("Remote Device is HID keyboard Type..");
1267 char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
1269 if (_bt_agent_generate_passkey(str_passkey,
1270 BT_PASSKEY_MAX_LENGTH) != 0) {
1271 device_reject_pin_request(&pin_req_event->address);
1274 device_accept_pin_request(&pin_req_event->address, str_passkey);
1276 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1278 if(trigger_bond_info == NULL)
1281 param = g_variant_new("(bsss)", incoming, address, pin_req_event->name, str_passkey);
1282 _bt_send_event(BT_ADAPTER_EVENT,
1283 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1284 BT_DBG("Key board pairing in process");
1285 } else if (BLUETOOTH_ERROR_NONE == __bt_get_device_pin_code(address, pin_code)) {
1286 BT_DBG("Use stored PIN code [%s]", pin_code);
1287 device_accept_pin_request(&pin_req_event->address, pin_code);
1289 if (_bt_is_bonding_device_address(address) == TRUE) {
1290 BT_DBG("Show Pin entry");
1291 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1292 trigger_pairing_info->addr = g_strdup(address);
1293 trigger_pairing_info->is_ssp = FALSE;
1295 BT_DBG("Send BLUETOOTH_EVENT_PIN_REQUEST");
1297 if(trigger_bond_info == NULL)
1300 param = g_variant_new("(bss)", incoming, address, pin_req_event->name);
1301 _bt_send_event(BT_ADAPTER_EVENT,
1302 BLUETOOTH_EVENT_PIN_REQUEST, param);
1307 _bt_agent_release_memory();
1311 /* SSP Pairing event handler */
1312 static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info)
1315 gchar address[BT_ADDRESS_STR_LEN];
1318 bool incoming = false;
1322 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1324 name = dev_info->name;
1326 BT_INFO("Address[%s]", address);
1327 BT_INFO("Name[%s]", name);
1328 BT_INFO("COD[%d]", dev_info->cod);
1330 if (trigger_pairing_info) {
1331 /* BTAPI support only one pairing at a time */
1332 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1333 BT_ERR("New PIN request address [%s]", address);
1334 device_reject_pin_request(&dev_info->address);
1339 /* Set pairing data */
1340 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1341 trigger_pairing_info->addr = g_strdup(address);
1342 trigger_pairing_info->is_ssp = TRUE;
1344 if(trigger_bond_info == NULL)
1347 param = g_variant_new("(bss)", incoming, p_addr, name);
1348 _bt_send_event(BT_ADAPTER_EVENT,
1349 BLUETOOTH_EVENT_PASSKEY_REQUEST, param);
1353 static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *dev_info)
1356 gchar address[BT_ADDRESS_STR_LEN];
1359 char str_passkey[7];
1360 bool incoming = false; /*Stores if bonding request is incoming(true) or outgoing(false) */
1363 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1365 name = dev_info->device_info.name;
1367 BT_INFO("Address[%s]", address);
1368 BT_INFO("Name[%s]", name);
1369 BT_INFO("COD[%d]", dev_info->device_info.cod);
1371 if (trigger_pairing_info) {
1372 /* BTAPI support only one pairing at a time */
1373 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1374 BT_ERR("New PIN request address [%s]", address);
1375 device_reject_pin_request(&dev_info->device_info.address);
1380 /* Set pairing data */
1381 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1382 trigger_pairing_info->addr = g_strdup(address);
1383 trigger_pairing_info->is_ssp = TRUE;
1385 BT_DBG("Send BLUETOOTH_EVENT_PASSKEY_CONFIRMATION");
1386 snprintf(str_passkey, sizeof(str_passkey), "%.6d", dev_info->pass_key);
1388 /*Storing if bond is incoming or outgoing*/
1389 if(trigger_bond_info == NULL)
1392 param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
1393 _bt_send_event(BT_ADAPTER_EVENT,
1394 BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST, param);
1398 static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_info)
1401 gchar address[BT_ADDRESS_STR_LEN];
1404 char str_passkey[7];
1405 bool incoming = false;
1408 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1410 name = dev_info->device_info.name;
1412 BT_INFO("Address[%s]", address);
1413 BT_INFO("Name[%s]", name);
1414 BT_INFO("COD[%d]", dev_info->device_info.cod);
1416 if (trigger_pairing_info) {
1417 /* BTAPI support only one pairing at a time */
1418 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1419 BT_ERR("New PIN request address [%s]", address);
1420 device_reject_pin_request(&dev_info->device_info.address);
1425 /* Set pairing data */
1426 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1427 trigger_pairing_info->addr = g_strdup(address);
1428 trigger_pairing_info->is_ssp = TRUE;
1430 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1431 snprintf(str_passkey, sizeof(str_passkey), "%06d", dev_info->pass_key);
1433 if(trigger_bond_info == NULL)
1436 param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
1438 if (passkey_watcher) {
1439 BT_INFO("Send passkey to %s", passkey_watcher);
1440 _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
1441 BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, param);
1443 _bt_send_event(BT_ADAPTER_EVENT,
1444 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1449 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info)
1451 gchar address[BT_ADDRESS_STR_LEN];
1458 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1459 name = dev_info->name;
1460 cod = dev_info->cod;
1462 BT_INFO("Address[%s]", address);
1463 BT_INFO("Name[%s]", name);
1464 BT_INFO("COD[%d]", cod);
1466 if (trigger_pairing_info) {
1467 /* BTAPI support only one pairing at a time */
1468 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1469 BT_ERR("New PIN request address [%s]", address);
1470 device_reject_pin_request(&dev_info->address);
1475 /* Set pairing data */
1476 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1477 trigger_pairing_info->addr = g_strdup(address);
1478 trigger_pairing_info->is_ssp = TRUE;
1480 local_major = ((cod >> 8) & 0x001f);
1481 local_minor = (cod & 0x00fc);
1482 BT_DBG("SSP_CONSENT: Major type=[0x%x] and Minor type=[0x%x]", local_major, local_minor);
1484 /*TODO: BLUETOOTH_EVENT_SSP_CONSENT_REQUEST to be handled in Tizen */
1488 static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
1489 gboolean connected, unsigned char type)
1491 gchar address[BT_ADDRESS_STR_LEN];
1492 int disc_reason = 0;
1493 GVariant *param = NULL;
1494 bt_device_conn_info_t conn_info;
1496 _bt_convert_addr_type_to_string(address, acl_event->address.addr);
1498 _bt_logging_connection(connected, type);
1500 disc_reason = acl_event->status;
1503 BT_PERMANENT_LOG("Connected %s %s", !type ? "EDR" : "LE", address + 12);
1504 param = g_variant_new("(isy)", BLUETOOTH_ERROR_NONE, address, type);
1505 _bt_send_event(BT_DEVICE_EVENT,
1506 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1509 BT_PERMANENT_LOG("Disconnected %s(%d) %s", !type ? "EDR" : "LE", disc_reason, address + 12);
1510 param = g_variant_new("(isyi)", disc_reason, address, type, dbfw_rssi);
1511 _bt_send_event(BT_DEVICE_EVENT,
1512 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1516 conn_info.connected = connected;
1517 conn_info.type = type;
1518 /* Update local cache */
1519 _bt_update_remote_dev_property(address, DEV_PROP_CONNECTED, (void *)&conn_info);
1521 /*handle LE connected device info*/
1523 _bt_handle_le_connected_dev_info(address, connected);
1526 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble)
1528 bt_remote_dev_info_t *dev_info = NULL;
1529 int result = BLUETOOTH_ERROR_NONE;
1530 GVariant *param = NULL;
1531 GVariant *uuids = NULL;
1532 GVariant *manufacturer_data = NULL;
1533 GVariantBuilder *builder = NULL;
1536 ret_if(_bt_is_discovering() == FALSE);
1537 ret_if(event_data == NULL);
1539 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
1542 event_ble_dev_found_t * oal_ble_dev = event_data;
1543 BT_INFO("Device type [%d]", oal_ble_dev->device_info.type);
1545 _bt_copy_remote_dev(dev_info, &oal_ble_dev->device_info);
1547 dev_info->manufacturer_data_len = oal_ble_dev->adv_len;
1548 if (dev_info->manufacturer_data_len)
1549 dev_info->manufacturer_data = g_memdup2(oal_ble_dev->adv_data,
1550 dev_info->manufacturer_data_len);
1552 dev_info->manufacturer_data = NULL;
1553 BT_DBG("----Advertising Data Length: %d", dev_info->manufacturer_data_len);
1555 event_dev_found_t * oal_dev = event_data;
1556 _bt_copy_remote_dev(dev_info, &oal_dev->device_info);
1559 /* If Remote device name is NULL or still RNR is not done then display address as name. */
1560 if (dev_info->name == NULL)
1561 dev_info->name = g_strdup(dev_info->address);
1562 BT_DBG("Name %s", dev_info->name);
1564 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1565 for (i = 0; i < dev_info->uuid_count; i++)
1566 g_variant_builder_add(builder, "s", dev_info->uuids[i]);
1568 uuids = g_variant_new("as", builder);
1569 g_variant_builder_unref(builder);
1571 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1572 dev_info->manufacturer_data,
1573 dev_info->manufacturer_data_len,
1577 param = g_variant_new("(isunsbub@asn@ay)", result,
1583 dev_info->connected,
1586 dev_info->manufacturer_data_len,
1589 _bt_send_event(BT_ADAPTER_EVENT,
1590 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1593 _bt_free_remote_dev(dev_info);
1596 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info)
1598 gchar address[BT_ADDRESS_STR_LEN];
1599 int result = BLUETOOTH_ERROR_NONE;
1600 GVariant *param = NULL;
1603 _bt_convert_addr_type_to_string(address, info->address.addr);
1605 /* Update local cache */
1606 _bt_update_remote_dev_property(address, DEV_PROP_TRUST, (void *)&trusted);
1608 param = g_variant_new("(is)", result, address);
1609 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1610 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1611 /* Send event to application */
1612 _bt_send_event(BT_DEVICE_EVENT,
1618 static void __bt_free_pairing_info(bt_pairing_data_t **p_info)
1620 bt_pairing_data_t * info = *p_info;
1630 static void __bt_free_bond_info(uint8_t type)
1633 case BT_DEVICE_BOND_INFO:
1634 if (!trigger_bond_info)
1637 if (trigger_bond_info->addr)
1638 g_free(trigger_bond_info->addr);
1639 if (trigger_bond_info->dev_addr)
1640 g_free(trigger_bond_info->dev_addr);
1641 if (trigger_bond_info->dev_info)
1642 _bt_free_remote_dev(trigger_bond_info->dev_info);
1643 g_free(trigger_bond_info);
1644 trigger_bond_info = NULL;
1646 case BT_DEVICE_INCOMING_BOND_INFO:
1647 if (!incoming_bond_info)
1650 if (incoming_bond_info->dev_info)
1651 _bt_free_remote_dev(incoming_bond_info->dev_info);
1652 g_free(incoming_bond_info);
1653 incoming_bond_info = NULL;
1655 case BT_DEVICE_UNBOND_INFO:
1656 if (!trigger_unbond_info)
1659 if (trigger_unbond_info->addr)
1660 g_free(trigger_unbond_info->addr);
1661 if (trigger_unbond_info->dev_addr)
1662 g_free(trigger_unbond_info->dev_addr);
1663 if (trigger_unbond_info->dev_info)
1664 _bt_free_remote_dev(trigger_unbond_info->dev_info);
1665 g_free(trigger_unbond_info);
1666 trigger_unbond_info = NULL;
1671 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info)
1673 bt_service_search_info_data_t * info = *p_info;
1680 if (info->dev_addr) {
1681 g_free(info->dev_addr);
1682 info->dev_addr = NULL;
1685 if (info->dev_info) {
1686 _bt_free_remote_dev(info->dev_info);
1687 info->dev_info = NULL;
1695 static int __bt_device_handle_bond_state(void)
1697 BT_DBG("Current Bond state: %d", bt_device_bond_state);
1698 int ret = OAL_STATUS_INTERNAL_ERROR;
1700 switch (bt_device_bond_state) {
1701 case BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY:
1702 /*TODO:Bonding during discovery: Unhandled!!*/
1703 BT_INFO("Bonding during discovery: Unhandled!!");
1705 case BT_DEVICE_BOND_STATE_DISCOVERY_CANCELLED:
1706 /*TODO:Bonding during discovery: Unhandled!!*/
1707 BT_INFO("Bonding during discovery: Unhandled!!");
1709 case BT_DEVICE_BOND_STATE_REMOVE_BONDING:
1710 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING;
1711 ret = device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
1712 if (ret != OAL_STATUS_SUCCESS)
1713 ret = __bt_device_handle_bond_state();
1715 case BT_DEVICE_BOND_STATE_REMOVED_BONDING:
1716 bt_device_bond_state = BT_DEVICE_BOND_STATE_NONE;
1717 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
1718 /* Bonding procedure was started but unfortunately could not complete.
1719 Basically removed bonding was success, but create bond request could not proceed
1720 So lets cleanup the context */
1721 if (ret != OAL_STATUS_SUCCESS) {
1722 BT_ERR("Create Bond procedure could not suceed");
1723 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1724 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1725 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1726 __bt_free_pairing_info(&trigger_pairing_info);
1729 case BT_DEVICE_BOND_STATE_NONE:
1730 BT_INFO("Create Bond failed!!");
1731 if (trigger_bond_info) {
1732 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1733 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1734 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1735 __bt_free_pairing_info(&trigger_pairing_info);
1742 if (ret != OAL_STATUS_SUCCESS)
1743 return _bt_convert_oal_status_to_bt_error(ret);
1745 return BLUETOOTH_ERROR_NONE;
1748 int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr)
1751 bt_address_t bd_addr;
1753 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
1755 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
1756 result = device_query_attributes(&bd_addr);
1757 if (result != OAL_STATUS_SUCCESS) {
1758 BT_ERR("device_query_attributes error: [%d]", result);
1759 return _bt_convert_oal_status_to_bt_error(result);
1762 return BLUETOOTH_ERROR_NONE;
1765 int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias)
1768 char address[BT_ADDRESS_STRING_SIZE];
1770 BT_CHECK_PARAMETER(alias, return);
1772 ret = device_set_alias((bt_address_t *)device_address, (char *)alias);
1773 if (ret != OAL_STATUS_SUCCESS) {
1774 BT_ERR("device_set_alias: %d", ret);
1775 return _bt_convert_oal_status_to_bt_error(ret);
1778 /* Update local cache */
1779 _bt_convert_addr_type_to_string(address, device_address->addr);
1780 _bt_update_remote_dev_property(address, DEV_PROP_ALIAS, (void *)alias);
1782 return BLUETOOTH_ERROR_NONE;
1785 int _bt_bond_device(bluetooth_device_address_t *device_address,
1786 unsigned short conn_type, GArray **out_param1)
1788 int result = BLUETOOTH_ERROR_NONE;
1789 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1790 bluetooth_device_info_t dev_info;
1791 const char *stack_name = NULL;
1793 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1795 /* If bonding or discovery already going on */
1796 if (trigger_bond_info || _bt_is_discovering()) {
1797 BT_ERR("Device is buzy, bonding can not proceed now..");
1798 result = BLUETOOTH_ERROR_DEVICE_BUSY;
1802 /*TODO: If unbonding with same device going on */
1803 _bt_convert_addr_type_to_string(address, device_address->addr);
1805 trigger_bond_info = g_malloc0(sizeof(bt_bond_data_t));
1806 trigger_bond_info->addr = g_strdup(address);
1807 trigger_bond_info->conn_type = conn_type;
1808 trigger_bond_info->is_device_creating = TRUE;
1809 trigger_bond_info->dev_addr = g_memdup2(device_address, sizeof(bluetooth_device_address_t));
1810 trigger_bond_info->dev_info = NULL;
1812 /* Ready to initiate bonding */
1814 stack_name = oal_get_stack_name();
1815 if (stack_name && !g_strcmp0(stack_name, "bluez")) {
1816 BT_DBG("[bluez] Create bond by type %d", conn_type);
1817 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING;
1819 /* In Tizen, we will first remove bond and then attempt to create bond to keep
1820 consistency with bluedroid. Even if remove bond fails due to device not already
1821 bonded, then straight away create bond is triggered. This is because, remove bond
1822 is handled differently in bluedroid and bluez. In Bluez, if device is
1823 already removed, remove bond call fails.
1824 However in bluedroid, remove bond on already removed device returns success. So we will
1825 handle the cases transparently */
1826 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVE_BONDING;
1829 #if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
1830 bond_retry_count = 0;
1832 result = __bt_device_handle_bond_state();
1834 if (result != BLUETOOTH_ERROR_NONE)
1840 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1841 memcpy(dev_info.device_address.addr, device_address->addr,
1842 BLUETOOTH_ADDRESS_LENGTH);
1844 g_array_append_vals(*out_param1, &dev_info,
1845 sizeof(bluetooth_device_info_t));
1846 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1851 int _bt_unbond_device(bluetooth_device_address_t *device_address,
1852 GArray **out_param1)
1854 int result = OAL_STATUS_SUCCESS;
1855 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1856 bluetooth_device_info_t dev_info;
1858 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1860 _bt_convert_addr_type_to_string(address, device_address->addr);
1862 trigger_unbond_info = g_malloc0(sizeof(bt_bond_data_t));
1863 trigger_unbond_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1864 trigger_unbond_info->addr = g_strdup(address);
1865 trigger_unbond_info->dev_addr = g_memdup2(device_address, sizeof(bluetooth_device_address_t));
1867 /* Check if Bonding is already going on, we should not abruptly remove bonding*/
1868 if (trigger_bond_info && strncmp(trigger_bond_info->addr, trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE) == 0) {
1869 BT_ERR("Bonding with same device already ongoing");
1870 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
1874 _bt_stop_timer_for_connection();
1875 result = device_destroy_bond((bt_address_t *)device_address);
1876 if (result != OAL_STATUS_SUCCESS)
1879 return BLUETOOTH_ERROR_NONE;
1882 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1883 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1884 trigger_unbond_info->addr);
1886 g_array_append_vals(*out_param1, &dev_info,
1887 sizeof(bluetooth_device_info_t));
1888 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
1890 return _bt_convert_oal_status_to_bt_error(result);
1893 int _bt_cancel_bonding(void)
1895 int result = OAL_STATUS_SUCCESS;
1898 retv_if(trigger_bond_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
1900 result = device_stop_bond((bt_address_t *)trigger_bond_info->dev_addr);
1902 if (result == OAL_STATUS_SUCCESS)
1903 trigger_bond_info->is_cancelled_by_user = TRUE;
1908 int _bt_passkey_reply(const char *passkey, gboolean cnfm_reply)
1910 bluetooth_device_address_t device_address;
1911 int ret = OAL_STATUS_SUCCESS;
1912 BT_INFO("reply: %d", cnfm_reply);
1914 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1915 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1917 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1919 if (trigger_pairing_info->is_ssp) {
1921 ret = device_accept_passkey_entry((bt_address_t *)&device_address, atoi(passkey));
1923 ret = device_reject_passkey_entry((bt_address_t *)&device_address);
1924 trigger_pairing_info->is_ssp = FALSE;
1927 ret = device_accept_pin_request((bt_address_t *)&device_address, passkey);
1929 ret = device_reject_pin_request((bt_address_t *)&device_address);
1932 __bt_free_pairing_info(&trigger_pairing_info);
1934 if (ret != OAL_STATUS_SUCCESS) {
1935 BT_ERR("_bt_device_handle_passkey_reply: err [%d]", ret);
1936 return _bt_convert_oal_status_to_bt_error(ret);
1940 return BLUETOOTH_ERROR_NONE;
1943 int _bt_passkey_confirmation_reply(gboolean cnfm_reply)
1945 BT_INFO("BT_PASSKEY_CONFIRMATION_REPLY");
1946 bluetooth_device_address_t device_address;
1947 int ret = OAL_STATUS_SUCCESS;
1948 BT_INFO("reply: %d", cnfm_reply);
1950 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1951 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1953 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1955 ret = device_reply_passkey_confirmation((bt_address_t *)&device_address, cnfm_reply);
1957 __bt_free_pairing_info(&trigger_pairing_info);
1958 if (ret != OAL_STATUS_SUCCESS) {
1959 BT_ERR("_bt_device_handle_passkey_confirmation_reply: err [%d]", ret);
1960 return BLUETOOTH_ERROR_INTERNAL;
1964 return BLUETOOTH_ERROR_NONE;
1967 gboolean _bt_device_is_pairing(void)
1969 return (trigger_pairing_info) ? TRUE : FALSE;
1972 gboolean _bt_device_is_bonding(void)
1974 return (trigger_bond_info) ? TRUE : FALSE;
1977 gboolean _bt_is_bonding_device_address(const char *address)
1979 if (trigger_bond_info == NULL || trigger_bond_info->addr == NULL)
1982 if (g_strcmp0(trigger_bond_info->addr, address) == 0) {
1983 BT_DBG("[%s] is bonding device", address);
1987 BT_DBG("[%s] is NOT bonding device", address);
1991 void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
1993 ret_if(trigger_bond_info == NULL);
1994 trigger_bond_info->is_autopair = is_autopair;
1997 int _bt_search_device(bluetooth_device_address_t *device_address)
1999 int result = OAL_STATUS_SUCCESS;
2002 BT_CHECK_PARAMETER(device_address, return);
2004 if (trigger_bond_info) {
2005 BT_ERR("Bonding in progress");
2006 return BLUETOOTH_ERROR_DEVICE_BUSY;
2009 if (service_search_info) {
2010 BT_ERR("Service searching in progress");
2011 return BLUETOOTH_ERROR_DEVICE_BUSY;
2014 /* allocate user data so that it can be retrieved in callback */
2015 service_search_info = g_malloc0(sizeof(bt_service_search_info_data_t));
2016 service_search_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2017 service_search_info->dev_addr = g_memdup2(device_address, sizeof(bluetooth_device_address_t));
2019 _bt_convert_addr_type_to_string(service_search_info->addr,
2020 device_address->addr);
2022 result = device_query_services((bt_address_t *)device_address);
2024 if (result != OAL_STATUS_SUCCESS) {
2025 BT_ERR("Device Service Search Failed..: %d", result);
2026 __bt_free_service_search_info(&service_search_info);
2027 return _bt_convert_oal_status_to_bt_error(result);
2029 return BLUETOOTH_ERROR_NONE;
2032 int _bt_cancel_search_device(void)
2034 int ret = OAL_STATUS_SUCCESS;
2035 retv_if(service_search_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
2037 ret = device_stop_query_sevices((bt_address_t *)service_search_info->dev_addr);
2039 if (ret != OAL_STATUS_SUCCESS) {
2040 BT_ERR("SDP Cancel request failed [%d]", ret);
2041 return _bt_convert_oal_status_to_bt_error(ret);
2044 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_CANCEL_BY_USER, BT_SEARCH_SERVICE,
2045 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
2047 __bt_free_service_search_info(&service_search_info);
2049 return BLUETOOTH_ERROR_NONE;
2053 int _bt_set_authorization(bluetooth_device_address_t *device_address,
2056 int ret = OAL_STATUS_SUCCESS;
2059 BT_CHECK_PARAMETER(device_address, return);
2060 BT_INFO("Device to be Trusted? [%d]", authorize);
2062 ret = device_set_authorized((bt_address_t*)device_address, authorize);
2063 if (ret != OAL_STATUS_SUCCESS) {
2064 BT_ERR("device_set_authorized: %d", ret);
2065 return _bt_convert_oal_status_to_bt_error(ret);
2068 return BLUETOOTH_ERROR_NONE;
2071 gboolean _bt_is_device_connected(bluetooth_device_address_t *device_address, int svc_type)
2073 gboolean is_connected;
2074 oal_service_t svc_id;
2076 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
2079 * TODO: While adding support for new profiles, need to add more
2080 * <svc_type, svc_id> mapping here.
2083 case BT_PROFILE_CONN_HID:
2084 svc_id = HID_SERVICE_ID;
2086 case BT_PROFILE_CONN_A2DP:
2087 svc_id = A2DP_SERVICE_ID; /* Remote is A2DP Sink */
2089 case BT_PROFILE_CONN_A2DP_SINK:
2090 svc_id = A2DP_SRC_SERVICE_ID; /* Remote is A2DP Source*/
2092 case BT_PROFILE_CONN_HSP:
2093 svc_id = HFP_HS_SERVICE_ID; /* Remote is HFP HF Unit */
2095 case BT_PROFILE_CONN_HFG:
2096 svc_id = HFP_SERVICE_ID; /* Remote is HFP AG Unit */
2098 case BT_PROFILE_CONN_GATT:
2099 return _bt_is_remote_gatt_device_connected(device_address); /* Remote is GATT client or Server */
2101 BT_DBG("Unknown svc_type: %d", svc_type);
2105 is_connected = device_get_svc_conn_state((bt_address_t*)device_address, svc_id);
2107 BT_DBG("svc_type: %d, is_connected: %s",
2108 svc_type, is_connected ? "TRUE" : "FALSE");
2110 return is_connected;
2113 int _bt_socket_reply_conn_authorization(char *address, gboolean reply)
2115 bt_address_t bd_addr;
2120 retv_if(NULL == address, BLUETOOTH_ERROR_INVALID_PARAM);
2121 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2122 res = device_reply_auth_request(&bd_addr, 0, reply, FALSE);
2123 if (res != OAL_STATUS_SUCCESS) {
2124 BT_ERR("authorize_response: %d", res);
2125 return _bt_convert_oal_status_to_bt_error(res);
2129 return BLUETOOTH_ERROR_NONE;
2132 int _bt_enable_rssi(bluetooth_device_address_t *addr, int link_type,
2133 int low_threshold, int in_range_threshold, int high_threshold)
2136 bt_address_t bd_addr;
2140 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
2142 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
2143 result = device_enable_rssi_monitoring(&bd_addr, link_type,
2144 low_threshold, in_range_threshold, high_threshold);
2145 if (result != OAL_STATUS_SUCCESS) {
2146 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
2147 return _bt_convert_oal_status_to_bt_error(result);
2151 return BLUETOOTH_ERROR_NONE;
2154 int _bt_get_rssi_strength(bluetooth_device_address_t *addr, int link_type)
2157 bt_address_t bd_addr;
2161 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
2163 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
2164 result = device_get_connected_link_rssi_strength(&bd_addr, link_type);
2165 if (result != OAL_STATUS_SUCCESS) {
2166 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
2167 return _bt_convert_oal_status_to_bt_error(result);
2171 return BLUETOOTH_ERROR_NONE;
2174 int _bt_set_passkey_notification(const char *sender, gboolean enable)
2178 BT_INFO("Set passkey notification(sender:%s, %s)",
2179 sender, enable ? "Enable" : "Disable");
2181 result = device_enable_gap_auth_notifications(OAL_PASSKEY_DISPLAY, enable);
2182 if (OAL_STATUS_SUCCESS != result) {
2183 BT_ERR("device_enable_gap_auth_notifications error: [%d]", result);
2184 return _bt_convert_oal_status_to_bt_error(result);
2187 g_free(passkey_watcher);
2189 passkey_watcher = g_strdup(sender);
2191 passkey_watcher = NULL;
2193 return BLUETOOTH_ERROR_NONE;
2196 static int __bt_get_device_pin_code(const char *address, char *pin_code)
2200 BT_CHECK_PARAMETER(address, return);
2201 BT_CHECK_PARAMETER(pin_code, return);
2203 for (l = pin_info_list; l != NULL; l = l->next) {
2204 bt_pin_code_info_t *pin_info = l->data;
2206 if (!pin_info || !pin_info->address)
2209 if (g_strcmp0(pin_info->address, address) == 0) {
2210 g_strlcpy(pin_code, pin_info->pin_code,
2211 BLUETOOTH_PIN_CODE_MAX_LENGTH + 1);
2212 return BLUETOOTH_ERROR_NONE;
2216 return BLUETOOTH_ERROR_NOT_FOUND;
2219 int _bt_set_pin_code(bluetooth_device_address_t *device_address,
2220 bluetooth_device_pin_code_t *pin_code)
2222 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2223 bt_pin_code_info_t *pin_info = NULL;
2226 BT_CHECK_PARAMETER(device_address, return);
2227 BT_CHECK_PARAMETER(pin_code, return);
2228 retv_if(g_slist_length(pin_info_list) >= BT_DEVICE_PIN_CODE_SLOT_MAX,
2229 BLUETOOTH_ERROR_NO_RESOURCES);
2231 _bt_convert_addr_type_to_string(address, device_address->addr);
2233 for (l = pin_info_list; l != NULL; l = l->next) {
2236 if (!pin_info || !pin_info->address)
2239 if (g_strcmp0(pin_info->address, address) == 0) {
2240 g_free(pin_info->pin_code);
2241 pin_info->pin_code = g_strdup(pin_code->pin_code);
2242 return BLUETOOTH_ERROR_NONE;
2246 pin_info = g_malloc0(sizeof(bt_pin_code_info_t));
2247 pin_info->address = g_strdup(address);
2248 pin_info->pin_code = g_strdup(pin_code->pin_code);
2249 pin_info_list = g_slist_append(pin_info_list, pin_info);
2251 return BLUETOOTH_ERROR_NONE;
2254 int _bt_unset_pin_code(bluetooth_device_address_t *device_address)
2256 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2257 bt_pin_code_info_t *pin_info = NULL;
2262 BT_CHECK_PARAMETER(device_address, return);
2264 _bt_convert_addr_type_to_string(address, device_address->addr);
2266 for (l = pin_info_list; l != NULL; l = l->next) {
2269 if (!pin_info || !pin_info->address)
2272 if (g_strcmp0(pin_info->address, address) == 0) {
2273 pin_info_list = g_slist_remove(pin_info_list, pin_info);
2274 g_free(pin_info->address);
2275 g_free(pin_info->pin_code);
2282 return BLUETOOTH_ERROR_NONE;
2285 int _bt_device_get_ida(bluetooth_device_address_t *device_address, bluetooth_device_address_t *id_address)
2287 int result = BLUETOOTH_ERROR_NONE;
2288 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2290 _bt_convert_addr_type_to_string(address, device_address->addr);
2292 BT_DBG("getting IDA for remote device: [%s]", address);
2294 result = device_get_ida((bt_address_t*)device_address, (bt_address_t*)id_address);
2296 if (result != OAL_STATUS_SUCCESS) {
2297 BT_ERR("device_get_ida Failed %d", result);
2298 return _bt_convert_oal_status_to_bt_error(result);
2304 static bt_connected_le_dev_t *__bt_get_le_connected_dev_info(const char *address)
2307 bt_connected_le_dev_t *dev;
2312 for (l = le_connected_dev_list; l; l = g_slist_next(l)) {
2315 if (g_strcmp0(dev->address, address) == 0)
2321 static void __bt_le_conn_param_free(void *data)
2323 bt_le_conn_param_t *param = (bt_le_conn_param_t *)data;
2325 BT_DBG("%s", param->sender);
2326 g_free(param->sender);
2330 static void _bt_add_le_connected_dev_info(const char *address)
2332 bt_connected_le_dev_t *dev = NULL;
2337 dev = g_malloc0(sizeof(bt_connected_le_dev_t));
2338 dev->address = g_strdup(address);
2340 le_connected_dev_list = g_slist_append(le_connected_dev_list, dev);
2345 static void _bt_remove_le_connected_dev_info(const char *address)
2347 bt_connected_le_dev_t *dev = NULL;
2352 dev = __bt_get_le_connected_dev_info(address);
2356 g_slist_free_full(dev->senders, __bt_le_conn_param_free);
2357 le_connected_dev_list = g_slist_remove(le_connected_dev_list, dev);
2358 g_free(dev->address);
2364 static void _bt_handle_le_connected_dev_info(const char *address, gboolean connected)
2366 BT_DBG("update le_connected_dev_list");
2369 _bt_add_le_connected_dev_info(address);
2371 _bt_remove_le_connected_dev_info(address);
2374 static bt_le_conn_param_t *__bt_get_le_conn_param_info(bt_connected_le_dev_t *dev, const char *sender)
2377 bt_le_conn_param_t *param = NULL;
2379 if (!dev || !sender)
2382 for (l = dev->senders; l; l = g_slist_next(l)) {
2384 if (g_strcmp0(param->sender, sender) == 0)
2391 static gint __bt_compare_le_conn_param_key(gpointer *a, gpointer *b)
2393 bt_le_conn_param_t *parama = (bt_le_conn_param_t *)a;
2394 bt_le_conn_param_t *paramb = (bt_le_conn_param_t *)b;
2396 return parama->key > paramb->key;
2400 int _bt_add_le_conn_param_info(const char *address, const char *sender,
2401 float interval_min, float interval_max, guint16 latency, guint16 time_out)
2403 bt_connected_le_dev_t *dev = NULL;
2404 bt_le_conn_param_t *param = NULL;
2405 bt_le_conn_param_t *data = NULL;
2407 if (!address || !sender)
2408 return BLUETOOTH_ERROR_INVALID_PARAM;
2410 dev = __bt_get_le_connected_dev_info(address);
2412 return BLUETOOTH_ERROR_INTERNAL;
2414 param = __bt_get_le_conn_param_info(dev, sender);
2416 data = g_malloc0(sizeof(bt_le_conn_param_t));
2417 data->sender = g_strdup(sender);
2418 data->interval_min = interval_min;
2419 data->interval_max = interval_max;
2420 data->latency = latency;
2421 data->time_out = time_out;
2422 data->key = interval_min + (interval_max - interval_min)/2;
2424 if (param == NULL) {
2425 BT_DBG("Add param %s %s %f %f", address, sender, interval_min, interval_max);
2426 dev->senders = g_slist_append(dev->senders, data);
2428 BT_DBG("Update param %s %s %f %f", address, sender, interval_min, interval_max);
2429 dev->senders = g_slist_remove(dev->senders, param);
2430 g_free(param->sender);
2432 dev->senders = g_slist_append(dev->senders, data);
2435 /* Sorting. First element have the minimum interval */
2436 dev->senders = g_slist_sort(dev->senders,
2437 (GCompareFunc)__bt_compare_le_conn_param_key);
2439 return BLUETOOTH_ERROR_NONE;
2443 static int __bt_le_set_conn_parameter(const char *address,
2444 float interval_min, float interval_max,
2445 guint16 latency, guint16 time_out)
2447 bt_address_t dev_addr = { {0} };
2448 guint32 min, max, to;
2450 BT_INFO("Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
2451 interval_min, interval_max, latency, time_out);
2453 min = interval_min / BT_LE_CONN_INTERVAL_SPLIT;
2454 max = interval_max / BT_LE_CONN_INTERVAL_SPLIT;
2455 to = time_out / BT_LE_CONN_TO_SPLIT;
2457 BT_DBG("updating: Min interval: %d, Max interval: %d, Latency: %d, Supervision timeout: %d",
2458 min, max, latency, to);
2460 _bt_convert_addr_string_to_type(dev_addr.addr, address);
2462 return gattc_conn_param_update(&dev_addr, min, max, latency, to);
2465 int _bt_le_set_default_connection_param(const char *address,
2466 float interval_min, float interval_max,
2467 guint16 latency, guint16 time_out)
2469 return __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out);
2472 int _bt_remove_le_conn_param_info(const char *address, const char *sender)
2474 bt_connected_le_dev_t *dev = NULL;
2475 bt_le_conn_param_t *param = NULL;
2477 if (!address || !sender)
2478 return BLUETOOTH_ERROR_INVALID_PARAM;
2480 dev = __bt_get_le_connected_dev_info(address);
2482 return BLUETOOTH_ERROR_INTERNAL;
2484 param = __bt_get_le_conn_param_info(dev, sender);
2486 BT_DBG("Remove param %s %s ", address, sender);
2487 dev->senders = g_slist_remove(dev->senders, param);
2488 g_free(param->sender);
2492 return BLUETOOTH_ERROR_NONE;
2495 int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
2496 bluetooth_le_connection_param_t *param)
2499 return BLUETOOTH_ERROR_INVALID_PARAM;
2501 memset(param, 0x00, sizeof(bluetooth_le_connection_param_t));
2504 case BLUETOOTH_LE_CONNECTION_MODE_BALANCED:
2505 param->interval_min = BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL;
2506 param->interval_max = BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL;
2507 param->latency = BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY;
2508 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2511 case BLUETOOTH_LE_CONNECTION_MODE_LOW_LATENCY:
2512 param->interval_min = BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL;
2513 param->interval_max = BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL;
2514 param->latency = BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY;
2515 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2518 case BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER:
2519 param->interval_min = BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL;
2520 param->interval_max = BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL;
2521 param->latency = BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY;
2522 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2526 BT_ERR("Unhandled mode : %d", mode);
2530 return BLUETOOTH_ERROR_NONE;
2533 int _bt_le_connection_update(const char *sender,
2534 unsigned char *device_address,
2535 float interval_min, float interval_max,
2536 guint16 latency, guint16 time_out)
2538 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2539 guint32 min_supervision_to;
2540 bt_connected_le_dev_t *dev = NULL;
2541 bt_le_conn_param_t *param = NULL;
2542 int ret = BLUETOOTH_ERROR_NONE;
2544 BT_CHECK_PARAMETER(device_address, return);
2546 BT_DBG("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
2547 sender, interval_min, interval_max, latency, time_out);
2549 if (interval_min > interval_max ||
2550 interval_min < BT_LE_CONN_INTERVAL_MIN ||
2551 interval_max > BT_LE_CONN_INTERVAL_MAX) {
2552 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2556 if (time_out < BT_LE_CONN_SUPER_TO_MIN ||
2557 time_out > BT_LE_CONN_SUPER_TO_MAX) {
2558 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2562 if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) {
2563 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2568 * The Supervision_Timeout in milliseconds shall be larger than
2569 * (1 + Conn_Latency) * Conn_Interval_Max * 2,
2570 * where Conn_Interval_Max is given in milliseconds.
2573 min_supervision_to = (1 + latency) * interval_max * 2;
2574 if (time_out <= min_supervision_to) {
2575 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2579 _bt_convert_addr_type_to_string(address, device_address);
2580 BT_DBG("Remote device address: %s", address);
2582 _bt_add_le_conn_param_info(address, sender, interval_min, interval_max, 0, 2000);
2584 dev = __bt_get_le_connected_dev_info(address);
2586 BT_ERR("device not found in the list");
2587 ret = BLUETOOTH_ERROR_NOT_CONNECTED;
2591 if (g_slist_length(dev->senders) == 1)
2594 param = dev->senders->data;
2596 BT_DBG("dev %f, param %f, input %f", dev->interval_min, param->interval_min, interval_min);
2598 if (dev->interval_min == param->interval_min && dev->interval_max == param->interval_max) {
2599 BT_DBG("Skip due to same interval");
2603 interval_min = param->interval_min;
2604 interval_max = param->interval_max;
2608 ret = __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out);
2610 if (ret != OAL_STATUS_SUCCESS) {
2611 _bt_remove_le_conn_param_info(address, sender);
2612 BT_DBG("fail to update the LE connection parameter");
2613 ret = _bt_convert_oal_status_to_bt_error(ret);
2617 dev->interval_min = interval_min;
2618 dev->interval_max = interval_max;
2620 return BLUETOOTH_ERROR_NONE;
2625 int _bt_disconnect_device(bluetooth_device_address_t *device_address)
2627 int result = OAL_STATUS_SUCCESS;
2631 retv_if(!device_address, BLUETOOTH_ERROR_INVALID_PARAM);
2633 result = device_disconnect((bt_address_t *)device_address);
2634 if (result != OAL_STATUS_SUCCESS) {
2635 BT_DBG("Failed to disconnect device");
2636 return _bt_convert_oal_status_to_bt_error(result);
2640 return BLUETOOTH_ERROR_NONE;
2643 static gboolean __bt_ignore_auto_pairing_request(const char *address)
2648 char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
2656 if (address == NULL)
2659 /* Get the LAP(Lower Address part) */
2660 /* User BT_LOWER_ADDRESS_LENGTH+1 for lap_address to accomodate
2662 snprintf(lap_address, sizeof(lap_address), ",%s", address);
2664 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
2667 BT_ERR("fopen failed \n");
2671 fseek(fp, 0, SEEK_END);
2676 BT_ERR("Get file size failed \n");
2681 buffer = g_malloc0(sizeof(char) * size);
2682 result = fread((char *)buffer, 1, size, fp);
2684 if (result != size) {
2685 BT_ERR("Read Error\n");
2690 lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
2696 /* Write the data and insert new device data */
2697 for (i = 0; lines[i] != NULL; i++) {
2698 if (g_str_has_prefix(lines[i], "AddressBlacklist")) {
2699 temp_buffer = g_strconcat(lines[i], lap_address, NULL);
2701 lines[i] = temp_buffer;
2704 buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
2706 /* Fix : NULL_RETURNS */
2707 retv_if(buffer == NULL, FALSE);
2709 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "w");
2712 BT_ERR("fopen failed \n");
2717 BT_DBG("Buffer = %s\n", buffer);
2718 fwrite(buffer, 1, strlen(buffer), fp);