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-service-common.h"
34 #include "bt-service-util.h"
35 #include "bt-service-main.h"
36 #include "bt-service-core-device.h"
37 #include "bt-service-core-adapter.h"
38 #include "bt-service-event-receiver.h"
39 #include "bt-request-handler.h"
40 #include "bt-service-event.h"
41 #include "bt-service-agent-util.h"
42 #include "bt-service-a2dp-src.h"
43 #include "bt-service-a2dp-sink.h"
44 #ifdef TIZEN_FEATURE_BT_OBEX
45 #include "bt-service-obex-server.h"
47 #include "bt-service-device-internal.h"
50 #include <oal-event.h>
51 #include <oal-manager.h>
52 #include <oal-adapter-mgr.h>
53 #include <oal-device-mgr.h>
55 #define MAX_BOND_RETRY_COUNT 3
56 #define BT_PASSKEY_MAX_LENGTH 4
58 /* Bonding Info structure */
63 unsigned short conn_type;
64 gboolean is_cancelled_by_user;
65 gboolean is_device_creating;
66 bluetooth_device_address_t *dev_addr;
67 bt_remote_dev_info_t *dev_info;
70 /* Searching Info structure */
74 gboolean is_cancelled_by_user;
75 bluetooth_device_address_t *dev_addr;
76 bt_remote_dev_info_t *dev_info;
77 } bt_service_search_info_data_t;
79 /* Pairing Info structure */
87 char addr[BT_ADDRESS_STRING_SIZE];
88 bt_remote_dev_info_t *dev_info;
89 } bt_incoming_bond_data_t;
91 /* Bonding and Pairing Informations */
92 bt_bond_data_t *trigger_bond_info;
93 bt_bond_data_t *trigger_unbond_info;
94 bt_pairing_data_t *trigger_pairing_info;
95 bt_service_search_info_data_t *service_search_info;
96 #ifdef TIZEN_FEATURE_BT_OBEX
97 gboolean is_device_creating;
100 bt_incoming_bond_data_t *incoming_bond_info;
103 BT_DEVICE_BOND_STATE_NONE,
104 BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY,
105 BT_DEVICE_BOND_STATE_DISCOVERY_CANCELLED,
106 BT_DEVICE_BOND_STATE_REMOVE_BONDING,
107 BT_DEVICE_BOND_STATE_REMOVED_BONDING,
108 BT_DEVICE_BOND_STATE_STARTED,
109 BT_DEVICE_BOND_STATE_WAIT_PROP,
110 BT_DEVICE_BOND_STATE_WAIT_DID
115 BT_DEVICE_INCOMING_BOND_INFO,
116 BT_DEVICE_UNBOND_INFO
119 /* BT device bond state variable */
120 static bt_bond_state_e bt_device_bond_state;
121 static int bond_retry_count;
123 /* Forward declaration */
124 static void __bt_device_event_handler(int event_type, gpointer event_data);
125 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble);
128 static int __bt_device_handle_bond_state(void);
129 static void __bt_free_bond_info(uint8_t type);
130 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info);
131 static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr);
132 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr);
133 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event);
134 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond);
135 static void __bt_device_conn_state_changed_callback(event_dev_conn_status_t *acl_event,
136 gboolean connected, unsigned char type);
137 static void __bt_free_pairing_info(bt_pairing_data_t **p_info);
139 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info);
140 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event);
141 static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_info);
142 static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *dev_info);
143 static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info);
144 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event);
146 static void __bt_device_services_callback(event_dev_services_t* uuid_list);
147 static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remote_dev_info);
149 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info);
151 #ifdef TIZEN_FEATURE_BT_OBEX
152 gboolean _bt_is_device_creating(void)
154 return is_device_creating;
158 void _bt_device_state_handle_callback_set_request(void)
160 _bt_service_register_event_handler_callback(
161 BT_DEVICE_MODULE, __bt_device_event_handler);
164 void __bt_device_handle_pending_requests(int result, int service_function,
165 void *user_data, unsigned int size)
169 invocation_info_t *req_info = NULL;
173 /* Get method invocation context */
174 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
176 if (req_info == NULL || req_info->service_function != service_function)
179 switch (service_function) {
180 case BT_SEARCH_SERVICE: {
181 char *address = (char *)user_data;
182 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
183 BT_ERR("Unexpected: Info request pending for a different address!!");
186 BT_INFO("Found info request addr [%s]", (char*)req_info->user_data);
187 bt_sdp_info_t sdp_info;
189 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
190 _bt_convert_addr_string_to_type(sdp_info.device_addr.addr, address);
192 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
193 g_array_append_vals(out_param, &sdp_info, sizeof(bt_sdp_info_t));
194 _bt_service_method_return(req_info->context, out_param, result);
196 g_free(req_info->user_data);
197 _bt_free_info_from_invocation_list(req_info);
198 g_array_free(out_param, TRUE);
202 case BT_BOND_DEVICE: {
203 char *address = (char *)user_data;
204 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
205 BT_ERR("Unexpected: Info request pending for a different address!!");
208 BT_INFO("Found info request addr [%s]", (char*)req_info->user_data);
209 bluetooth_device_info_t dev_info;
210 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
211 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
213 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
214 g_array_append_vals(out_param, &dev_info,
215 sizeof(bluetooth_device_info_t));
216 _bt_service_method_return(req_info->context, out_param, result);
218 g_free(req_info->user_data);
219 _bt_free_info_from_invocation_list(req_info);
220 g_array_free(out_param, TRUE);
224 case BT_UNBOND_DEVICE: {
225 char *address = (char *)user_data;
226 if (strncmp((char*)req_info->user_data, address, BT_ADDRESS_STRING_SIZE)) {
227 BT_ERR("Unexpected: Info request pending for a different address!!");
230 BT_INFO("Found info request addr [%s]", (char*)req_info->user_data);
231 bluetooth_device_address_t dev_addr;
232 _bt_convert_addr_string_to_type(dev_addr.addr, address);
233 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
234 g_array_append_vals(out_param, &dev_addr,
235 sizeof(bluetooth_device_address_t));
236 _bt_service_method_return(req_info->context, out_param, result);
238 g_free(req_info->user_data);
239 _bt_free_info_from_invocation_list(req_info);
240 g_array_free(out_param, TRUE);
245 BT_ERR("Unhandled case");
253 * Remote device properties are received on all following conditions
254 * a. When Bonding in on-going
255 * b. When device properties are updated\changed for a connected device
256 * (due to SDP or any other reason)
258 static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_dev_props)
260 bt_remote_dev_info_t *rem_info = NULL;
263 rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
264 _bt_copy_remote_dev(rem_info, &(oal_dev_props->device_info));
266 if (oal_dev_props->adv_len > 0) {
269 rem_info->manufacturer_data_len = oal_dev_props->adv_len;
270 rem_info->manufacturer_data =
271 g_memdup(oal_dev_props->adv_data,
272 oal_dev_props->adv_len);
273 BT_DBG("----Advertising Data Length: %d",
274 rem_info->manufacturer_data_len);
276 for (k = 0; k < rem_info->manufacturer_data_len; k++) {
277 BT_INFO("Check data[%d] = [[0x%x]",
278 k, oal_dev_props->adv_data[k]);
281 rem_info->manufacturer_data = NULL;
282 rem_info->manufacturer_data_len = 0;
285 /* a. Check if bonding is on-going, if yes, we MUST update the bonding device properties */
286 if (trigger_bond_info && !strcmp(trigger_bond_info->addr, rem_info->address)) {
287 BT_INFO("Bonding is ongoing, try update properties");
288 if (!trigger_bond_info->dev_info ||
289 (!trigger_bond_info->dev_info->name &&
290 !incoming_bond_info->dev_info->alias) ||
291 !trigger_bond_info->dev_info->address ||
292 trigger_bond_info->dev_info->uuid_count == 0) {
293 BT_INFO("Complete data is not present, Assigning rem_info");
294 if (!trigger_bond_info->dev_info)
295 trigger_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
296 _bt_copy_remote_dev_info(trigger_bond_info->dev_info, rem_info);
299 BT_DBG("Bonding dev addr has matched with remote dev properties address [%s]", rem_info->address);
300 __bt_handle_ongoing_bond(trigger_bond_info->dev_info, FALSE);
301 } else if (incoming_bond_info && !g_strcmp0(incoming_bond_info->addr, rem_info->address)) {
302 BT_INFO("Incoming Bond is ongoing, try update properties");
303 if (!incoming_bond_info->dev_info ||
304 (!incoming_bond_info->dev_info->name &&
305 !incoming_bond_info->dev_info->alias) ||
306 !incoming_bond_info->dev_info->address ||
307 incoming_bond_info->dev_info->uuid_count == 0) {
308 BT_INFO("Complete data is not present, Assigning rem_info");
309 if (!incoming_bond_info->dev_info)
310 incoming_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
311 _bt_copy_remote_dev_info(incoming_bond_info->dev_info, rem_info);
314 BT_DBG("Incoming Bond addr matches with remote dev properties address [%s]", rem_info->address);
315 __bt_handle_ongoing_bond(incoming_bond_info->dev_info, TRUE);
318 /* Add device to bonded list */
319 _bt_service_add_device_to_bonded_list(rem_info);
321 /* Handle SDP Device properties update */
322 if (service_search_info && service_search_info->dev_info) {
323 if (!strcmp(service_search_info->addr, rem_info->address)) {
324 BT_DBG("Properties received and SDP request pending, fill device properties and send event");
325 service_search_info->dev_info->class = rem_info->class;
326 service_search_info->dev_info->paired = rem_info->paired;
327 service_search_info->dev_info->connected = rem_info->connected;
328 service_search_info->dev_info->rssi = rem_info->rssi;
329 service_search_info->dev_info->addr_type = rem_info->addr_type;
330 service_search_info->dev_info->trust = rem_info->trust;
333 service_search_info->dev_info->manufacturer_data = NULL;
334 service_search_info->dev_info->manufacturer_data_len = 0;
336 __bt_handle_ongoing_device_service_search(service_search_info->dev_info);
340 _bt_free_remote_dev(rem_info);
344 static int __get_oal_trusted_profile(bluetooth_trusted_profile_t profile)
347 case TRUSTED_PROFILE_PBAP:
348 return OAL_TRUSTED_PROFILE_PBAP;
349 case TRUSTED_PROFILE_MAP:
350 return OAL_TRUSTED_PROFILE_MAP;
351 case TRUSTED_PROFILE_SAP:
352 return OAL_TRUSTED_PROFILE_SAP;
353 case TRUSTED_PROFILE_HFP_HF:
354 return OAL_TRUSTED_PROFILE_HFP_HF;
355 case TRUSTED_PROFILE_A2DP:
356 return OAL_TRUSTED_PROFILE_A2DP;
357 case TRUSTED_PROFILE_ALL:
358 return OAL_TRUSTED_PROFILE_ALL;
364 int _bt_set_trust_profile(bluetooth_device_address_t *addr,
365 bluetooth_trusted_profile_t profile, gboolean trust)
368 bt_address_t bd_addr;
369 oal_trusted_profile_e oal_profile;
373 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
375 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
376 oal_profile = __get_oal_trusted_profile(profile);
377 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
379 result = device_set_trust_profile(&bd_addr, oal_profile, trust);
380 if (result != OAL_STATUS_SUCCESS) {
381 BT_ERR("device_set_trust_profile error: [%d]", result);
382 return BLUETOOTH_ERROR_INTERNAL;
386 return BLUETOOTH_ERROR_NONE;
389 int _bt_get_trust_profile(bluetooth_device_address_t *addr,
390 bluetooth_trusted_profile_t profile, guint *trust)
393 bt_address_t bd_addr;
394 oal_trusted_profile_e oal_profile;
398 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
400 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
401 oal_profile = __get_oal_trusted_profile(profile);
402 retv_if(0 == oal_profile, BLUETOOTH_ERROR_NOT_SUPPORT);
404 result = device_get_trust_profile(&bd_addr, oal_profile, trust);
405 if (result != OAL_STATUS_SUCCESS) {
406 BT_ERR("device_set_trust_profile error: [%d]", result);
407 return BLUETOOTH_ERROR_INTERNAL;
411 return BLUETOOTH_ERROR_NONE;
414 static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remote_dev_info)
416 GVariant *param = NULL;
417 GVariant *uuids = NULL;
418 GVariantBuilder *builder = NULL;
419 GVariant *manufacturer_data;
423 BT_INFO("Send Service Search request event");
425 if (remote_dev_info->alias)
426 name = remote_dev_info->alias;
428 name = remote_dev_info->name;
430 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
431 for (i = 0; i < remote_dev_info->uuid_count; i++) {
432 g_variant_builder_add(builder, "s",
433 remote_dev_info->uuids[i]);
435 uuids = g_variant_new("as", builder);
436 g_variant_builder_unref(builder);
437 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
438 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
441 param = g_variant_new("(isunsbub@asn@ay)",
442 BLUETOOTH_ERROR_NONE,
443 remote_dev_info->address,
444 remote_dev_info->class,
445 remote_dev_info->rssi,
447 remote_dev_info->paired,
448 remote_dev_info->connected,
449 remote_dev_info->trust,
451 remote_dev_info->manufacturer_data_len,
453 /* Send the event to application */
454 _bt_send_event(BT_ADAPTER_EVENT,
455 BLUETOOTH_EVENT_SERVICE_SEARCHED,
458 __bt_free_service_search_info(&service_search_info);
462 static void __bt_device_services_callback(event_dev_services_t* uuid_list)
464 bt_remote_dev_info_t *rem_info = NULL;
468 if (trigger_bond_info && _bt_compare_adddress(trigger_bond_info->dev_addr,
469 (bluetooth_device_address_t *)&uuid_list->address) == TRUE) {
470 bluetooth_device_address_t *dev_addr = trigger_bond_info->dev_addr;
472 BT_DBG("Bonding dev addr has matched");
473 /* Bonding ongoing, Query device properties again */
474 if (BLUETOOTH_ERROR_NONE ==
475 _bt_device_get_bonded_device_info(dev_addr))
476 BT_DBG("_bt_device_get_bonded_device_info success");
478 BT_ERR("_bt_device_get_bonded_device_info failed");
481 if (service_search_info == NULL) {
483 BT_DBG("searching_info == NULL");
487 if (_bt_compare_adddress(service_search_info->dev_addr,
488 (bluetooth_device_address_t *)&uuid_list->address) == FALSE) {
489 BT_DBG("This device is not queried");
493 rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
494 memset(rem_info, 0x00, sizeof(bt_remote_dev_info_t));
496 rem_info->address = g_new0(char, BT_ADDRESS_STRING_SIZE);
497 _bt_convert_addr_type_to_string(rem_info->address, uuid_list->address.addr);
499 rem_info->uuid_count = uuid_list->num;
501 BT_INFO("Address [%s]", rem_info->address);
502 BT_INFO("Number of UUID's [%d]", rem_info->uuid_count);
503 if (rem_info->uuid_count > 0)
504 rem_info->uuids = g_new0(char *, rem_info->uuid_count);
506 /* Fill Remote Device Service List list */
507 for (i = 0; i < rem_info->uuid_count; i++) {
508 rem_info->uuids[i] = g_malloc0(BLUETOOTH_UUID_STRING_MAX);
509 _bt_uuid_to_string((service_uuid_t *)&uuid_list->service_list[i].uuid, rem_info->uuids[i]);
510 BT_DBG("UUID value=%s", rem_info->uuids[i]);
513 /* Update local cache */
514 _bt_update_remote_dev_property(rem_info->address, DEV_PROP_SERVICES, (void *)rem_info);
516 BT_DBG("DBUS return");
517 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_SEARCH_SERVICE,
518 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
520 /* Save UUID List of remote devices */
521 if (service_search_info->dev_info)
522 _bt_free_remote_dev(service_search_info->dev_info);
523 service_search_info->dev_info = rem_info;
525 /* Query Other device properties */
526 if (_bt_device_get_bonded_device_info(service_search_info->dev_addr) == BLUETOOTH_ERROR_NONE) {
527 BT_DBG("Bonded device info query posted to stack successfully");
529 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
530 __bt_free_service_search_info(&service_search_info);
535 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event)
537 oal_service_t service_d = auth_event->service_id;
538 gchar address[BT_ADDRESS_STR_LEN];
541 _bt_convert_addr_type_to_string(address, auth_event->address.addr);
543 BT_INFO("service_d: %d", service_d);
547 BT_INFO("Incoming HID Profile conn Req from device addr [%s]", address);
549 case A2DP_SERVICE_ID:
550 BT_INFO("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
551 _bt_a2dp_src_handle_incoming_authorization(address, service_d);
553 case A2DP_SRC_SERVICE_ID:
554 BT_INFO("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
555 _bt_a2dp_sink_handle_incoming_authorization(address, service_d);
557 case AVRCP_SERVICE_ID:
558 BT_INFO("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
560 case AVRCP_CT_SERVICE_ID:
561 BT_INFO("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
563 #ifdef TIZEN_FEATURE_BT_OBEX
564 case OPP_SERVICE_ID: {
565 GVariant *param = NULL;
566 char *name = g_strdup(address); /* TODO: Retrieve and send correct name in OBEX conn auth req event */
568 BT_INFO("Incoming OPP conn Req from device addr [%s]", address);
569 _bt_obex_server_set_pending_conn_auth_device_addr(address);
570 param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, name);
571 _bt_send_event(BT_OPP_SERVER_EVENT,
572 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE, param);
578 BT_INFO("Incoming HSP_SERVICE_ID conn Req from device addr [%s]", address);
581 BT_INFO("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
584 BT_INFO("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
586 case HSP_HS_SERVICE_ID:
587 BT_INFO("Incoming HSP_HS_SERVICE_ID conn Req from device addr [%s]", address);
589 case HFP_HS_SERVICE_ID:
590 BT_INFO("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
593 case IOTIVITY_SERVICE_ID:
594 BT_INFO("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
598 /* For now, reject authorization for any service apart from above switch cases */
599 BT_INFO("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_d, address);
600 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, FALSE, FALSE);
601 if (res != OAL_STATUS_SUCCESS)
602 BT_ERR("authorize_response: %d", res);
606 /* Auto accept authorization request for HID, A2DP and AVRCP profiles */
607 BT_INFO("Auto Accept authorization");
608 res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, TRUE, FALSE);
609 if (res != OAL_STATUS_SUCCESS)
610 BT_ERR("authorize_response: %d", res);
614 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond)
616 GVariant *param = NULL;
619 if ((remote_dev_info->name || remote_dev_info->alias)
620 && remote_dev_info->address
621 && remote_dev_info->uuids) {
622 BT_INFO("All properties updated, time to send bonding finished event");
623 GVariant *uuids = NULL;
624 GVariantBuilder *builder = NULL;
625 GVariant *manufacturer_data;
629 if (remote_dev_info->alias)
630 name = remote_dev_info->alias;
632 name = remote_dev_info->name;
634 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
635 for (i = 0; i < remote_dev_info->uuid_count; i++) {
636 g_variant_builder_add(builder, "s",
637 remote_dev_info->uuids[i]);
639 uuids = g_variant_new("as", builder);
640 g_variant_builder_unref(builder);
641 manufacturer_data = g_variant_new_from_data((const GVariantType *)"ay",
642 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
645 param = g_variant_new("(isunsbub@asn@ay)",
646 BLUETOOTH_ERROR_NONE,
647 remote_dev_info->address,
648 remote_dev_info->class,
649 remote_dev_info->rssi,
651 remote_dev_info->paired,
652 remote_dev_info->connected,
653 remote_dev_info->trust,
655 remote_dev_info->manufacturer_data_len,
657 /* Send the event to application */
658 _bt_send_event(BT_ADAPTER_EVENT,
659 BLUETOOTH_EVENT_BONDING_FINISHED,
662 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
664 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
665 __bt_free_pairing_info(&trigger_pairing_info);
668 BT_INFO("Lets wait for more remote device properties");
672 static void __handle_incoming_bond_created_event(bt_address_t *bd_addr)
674 char address[BT_ADDRESS_STRING_SIZE];
675 bluetooth_device_address_t dev_addr;
680 * BlueZ sends paired signal for each paired device, during activation,
681 * We should ignore this, otherwise application thinks that a new device
684 if (_bt_adapter_get_status() != BT_ACTIVATED) {
685 BT_DBG("BT is not activated, so ignore this");
689 _bt_convert_addr_type_to_string(address, bd_addr->addr);
690 if (!incoming_bond_info) {
691 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
693 if (g_strcmp0(incoming_bond_info->addr, address)) {
694 BT_DBG("Previous Bond address: [%s] differs from new address: [%s]",
695 address, incoming_bond_info->addr);
696 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
697 incoming_bond_info = g_malloc0(sizeof(bt_incoming_bond_data_t));
701 BT_INFO("Incoming bond successfully completed");
702 g_strlcpy(incoming_bond_info->addr, address, BT_ADDRESS_STRING_SIZE);
703 incoming_bond_info->dev_info = NULL;
705 _bt_convert_addr_string_to_type(dev_addr.addr, incoming_bond_info->addr);
706 if (BLUETOOTH_ERROR_NONE == _bt_device_get_bonded_device_info(&dev_addr)) {
707 BT_DBG("Bonded device info query posted to stack successfully");
709 BT_ERR("Bonded device info query failed");
710 __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
716 static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr)
718 gchar address[BT_ADDRESS_STR_LEN];
719 bluetooth_device_address_t dev_addr;
723 if (trigger_bond_info == NULL) {
725 BT_DBG("trigger_bond_info == NULL, Handle incomming bond event");
726 __handle_incoming_bond_created_event(bd_addr);
730 _bt_convert_addr_type_to_string(address, bd_addr->addr);
731 if (g_strcmp0(trigger_bond_info->addr, address)) {
732 BT_DBG("Bonding address= [%s] is different from requested address =[%s]",
733 address, trigger_bond_info->addr);
734 __handle_incoming_bond_created_event(bd_addr);
738 BT_INFO("Bonding successfully completed");
739 /* Bonding state will be cleaned up & BONDING FINISHED EVENT
740 will be sent only when Properties are fetched from stack
741 Till that time lets not free trigger_bond_info.
742 However it is possible that while fetching device properties, internal
743 stack error can occur which can lead to no valid properties or
744 no properties at all. So in such cases, we must not wait for properties,
745 otherwise, it can lead to infinite wait */
746 _bt_convert_addr_string_to_type(dev_addr.addr,
747 trigger_bond_info->addr);
749 if (_bt_device_get_bonded_device_info(&dev_addr) == BLUETOOTH_ERROR_NONE) {
750 BT_DBG("BOnded device info query posted to stack successfully");
751 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
752 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
754 BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
755 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
756 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
757 /* Destroy if at all device got bonded at stack level */
758 device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
760 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
761 __bt_free_pairing_info(&trigger_pairing_info);
767 /**********************************************************************************************
768 * Bond removal event can be triggered for following reasons -
769 * a. If Bonding procedure if failed (for Auth failed, Page timeout, cancelled by user etc)
770 * b. If Application requests for explicitly removing the bond
771 * c. When application attempt to create bond,bond is removed first which triggers this event
772 * c. is in-line with Bluedroid bond create\emoval architecture
773 *********************************************************************************************/
774 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr)
776 char address[BT_ADDRESS_STRING_SIZE];
780 _bt_convert_addr_type_to_string(address, bd_addr->addr);
781 _bt_service_remove_device_from_bonded_list(address);
783 if (trigger_unbond_info) {
784 BT_INFO("Bond removal request successfully handled, return DBUS and send event");
785 GVariant *param = NULL;
786 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_UNBOND_DEVICE,
787 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
788 param = g_variant_new("(is)", BLUETOOTH_ERROR_NONE, trigger_unbond_info->addr);
789 _bt_send_event(BT_ADAPTER_EVENT,
790 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
792 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
793 __bt_free_pairing_info(&trigger_pairing_info);
794 } else if (trigger_bond_info) {
795 BT_ERR("Bonding was removed");
796 __bt_device_handle_bond_state();
801 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event)
804 oal_status_t status = bond_fail_event->status;
805 BT_INFO("Bonding failed, reason: %d", status);
808 case OAL_STATUS_RMT_DEVICE_DOWN:
810 if (trigger_bond_info) {
811 BT_INFO("OAL_STATUS_RMT_DEVICE_DOWN:Lets retry bonding!! retry count [%d]",
813 int ret = OAL_STATUS_SUCCESS;
814 if (bond_retry_count < MAX_BOND_RETRY_COUNT) {
815 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
816 if (ret != OAL_STATUS_SUCCESS) {
817 BT_ERR("Create Bond procedure could not suceed");
818 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
819 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
820 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
821 __bt_free_pairing_info(&trigger_pairing_info);
822 bond_retry_count = 0;
826 BT_ERR("Create Bond failed MAX_BOND_RETRY_COUNT TIMES!!");
827 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
828 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
829 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
830 __bt_free_pairing_info(&trigger_pairing_info);
831 bond_retry_count = 0;
836 case OAL_STATUS_AUTH_FAILED:
838 /*TODO Auto pairing status set & ignore auto pairing logics can be done at this point.
839 To be considered later*/
840 int result = BLUETOOTH_ERROR_INTERNAL;
841 BT_INFO("BT_OPERATION_STATUS_AUTH_FAILED");
842 if (trigger_bond_info) {
843 BT_ERR("Create Bond procedure could not suceed, check if cancelled by User");
844 if (trigger_bond_info->is_cancelled_by_user) {
845 BT_ERR("Bonding is cancelled by user");
846 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
848 __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
849 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
850 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
853 __bt_free_pairing_info(&trigger_pairing_info);
856 case OAL_STATUS_INTERNAL_ERROR:
858 BT_INFO("OAL_STATUS_INTERNAL_ERROR");
859 if (trigger_unbond_info) {
860 BT_INFO("Bond removal request failed, return DBUS and send event");
861 GVariant *param = NULL;
862 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_UNBOND_DEVICE,
863 trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
864 param = g_variant_new("(is)", BLUETOOTH_ERROR_INTERNAL, trigger_unbond_info->addr);
865 _bt_send_event(BT_ADAPTER_EVENT,
866 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
868 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
869 } else if (trigger_bond_info) {
870 if (__bt_device_handle_bond_state() != BLUETOOTH_ERROR_NONE) {
871 if (trigger_bond_info) {
872 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
873 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
874 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
879 __bt_free_pairing_info(&trigger_pairing_info);
884 BT_ERR("Unknown status of Bond failed event status [%d]", status);
892 static void __bt_device_event_handler(int event_type, gpointer event_data)
894 int eventcheck = OAL_EVENT_DEVICE_PROPERTIES;
895 BT_INFO("event [%d] Event check = [%d]", event_type, eventcheck);
897 switch (event_type) {
898 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY: {
899 BT_INFO("BREDR Device Found");
900 __bt_device_remote_device_found_callback(event_data, FALSE);
903 case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE: {
904 BT_INFO("Dual Device Found");
905 __bt_device_remote_device_found_callback(event_data, FALSE);
908 case OAL_EVENT_DEVICE_PROPERTIES: {
909 BT_INFO("Remote Device properties Received");
910 __bt_device_remote_properties_callback((event_dev_properties_t *)event_data);
913 case OAL_EVENT_DEVICE_BONDING_SUCCESS: {
914 BT_INFO("Bonding Success event Received");
915 __bt_device_handle_bond_completion_event((bt_address_t *)event_data);
918 case OAL_EVENT_DEVICE_BONDING_REMOVED: {
919 BT_INFO("Bonding Removed event Received");
920 __bt_device_handle_bond_removal_event((bt_address_t *)event_data);
923 case OAL_EVENT_DEVICE_BONDING_FAILED: {
924 BT_INFO("Bonding Failed event Received");
925 __bt_device_handle_bond_failed_event((event_dev_bond_failed_t*) event_data);
928 case OAL_EVENT_DEVICE_ACL_CONNECTED: {
929 BT_INFO("ACL Connected event Received");
930 event_dev_conn_status_t* param = event_data;
931 __bt_device_conn_state_changed_callback(param, TRUE, 0);
934 case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
935 BT_INFO("ACL Disconnected event Received");
936 __bt_device_conn_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 0);
939 case OAL_EVENT_DEVICE_LE_CONNECTED: {
940 BT_INFO("LE Connected event Received");
941 event_dev_conn_status_t* param = event_data;
942 __bt_device_conn_state_changed_callback(param, TRUE, 1);
945 case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
946 BT_INFO("LE Disconnected event Received");
947 __bt_device_conn_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 1);
950 case OAL_EVENT_DEVICE_PIN_REQUEST: {
951 BT_INFO("PIN Request Received");
952 __bt_device_pin_request_callback((remote_device_t*)event_data);
955 case OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST: {
956 BT_INFO("Passkey Entry request Received");
957 __bt_device_ssp_passkey_entry_callback((remote_device_t*)event_data);
960 case OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST:{
961 BT_INFO("Passkey Confirmation Request Received");
962 __bt_device_ssp_passkey_confirmation_callback((event_dev_passkey_t *)event_data);
965 case OAL_EVENT_DEVICE_PASSKEY_DISPLAY: {
966 BT_INFO("Passkey Display Request Received");
967 __bt_device_ssp_passkey_display_callback((event_dev_passkey_t *)event_data);
970 case OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST: {
971 BT_INFO("SSP Consent Request Received");
972 __bt_device_ssp_consent_callback((remote_device_t*)event_data);
975 case OAL_EVENT_DEVICE_SERVICES: {
976 BT_INFO("Remote Device Services Received");
977 __bt_device_services_callback((event_dev_services_t*)event_data);
980 case OAL_EVENT_DEVICE_AUTHORIZE_REQUEST: {
981 BT_INFO("Remote Device Authorization Request");
982 __bt_device_authorization_request_callback((event_dev_authorize_req_t*)event_data);
985 case OAL_EVENT_DEVICE_TRUSTED: {
986 BT_INFO("Remote Device Trusted");
987 __bt_device_trusted_callback(TRUE, (event_dev_trust_t*)event_data);
990 case OAL_EVENT_DEVICE_UNTRUSTED: {
991 BT_INFO("Remote Device UnTrusted");
992 __bt_device_trusted_callback(FALSE, (event_dev_trust_t*)event_data);
995 case OAL_EVENT_DEVICE_NAME: {
996 remote_device_t *rem_dev = event_data;
997 gchar address[BT_ADDRESS_STR_LEN];
999 _bt_convert_addr_type_to_string(address, rem_dev->address.addr);
1000 BT_INFO("Remote Device name Received");
1001 BT_INFO("Name: %s, Address: %s", rem_dev->name, address);
1003 /* Update local cache */
1004 _bt_update_remote_dev_property(address, DEV_PROP_NAME, (void *)rem_dev->name);
1007 case OAL_EVENT_DEVICE_TRUSTED_PROFILES_CHANGED: {
1008 event_device_trusted_profiles_t *ev = event_data;
1009 char address[BT_ADDRESS_STRING_SIZE];
1013 _bt_convert_addr_type_to_string(address, ev->address.addr);
1014 _bt_send_event(BT_DEVICE_EVENT,
1015 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1016 g_variant_new("(isi)", BLUETOOTH_ERROR_NONE,
1017 address, ev->trust_val));
1019 case OAL_EVENT_RSSI_MONITORING_ENABLED: {
1020 event_dev_rssi_info_t *ev = event_data;
1021 char address[BT_ADDRESS_STRING_SIZE];
1026 _bt_convert_addr_type_to_string(address, ev->address.addr);
1027 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1028 address, ev->link_type, TRUE);
1029 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1032 case OAL_EVENT_RSSI_MONITORING_DISABLED: {
1033 event_dev_rssi_info_t *ev = event_data;
1034 char address[BT_ADDRESS_STRING_SIZE];
1039 _bt_convert_addr_type_to_string(address, ev->address.addr);
1040 param = g_variant_new("(isib)", BLUETOOTH_ERROR_NONE,
1041 address, ev->link_type, FALSE);
1042 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ENABLED, param);
1045 case OAL_EVENT_RSSI_ALERT_RECEIVED: {
1046 event_dev_rssi_info_t *ev = event_data;
1047 char address[BT_ADDRESS_STRING_SIZE];
1052 _bt_convert_addr_type_to_string(address, ev->address.addr);
1053 param = g_variant_new("(isiii)", BLUETOOTH_ERROR_NONE,
1054 address, ev->link_type, ev->alert_type, ev->rssi);
1055 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RSSI_ALERT, param);
1058 case OAL_EVENT_RAW_RSSI_RECEIVED: {
1059 event_dev_rssi_info_t *ev = event_data;
1060 char address[BT_ADDRESS_STRING_SIZE];
1065 _bt_convert_addr_type_to_string(address, ev->address.addr);
1066 param = g_variant_new("(isii)", BLUETOOTH_ERROR_NONE,
1067 address, ev->link_type, ev->rssi);
1068 _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_RAW_RSSI, param);
1072 BT_INFO("Unhandled event..");
1076 /* Legacy Pairing event handler */
1077 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
1080 gchar address[BT_ADDRESS_STR_LEN];
1083 _bt_convert_addr_type_to_string(address, pin_req_event->address.addr);
1085 BT_INFO("Address[%s]", address);
1086 BT_INFO("Name[%s]", pin_req_event->name);
1087 BT_INFO("COD[%d]", pin_req_event->cod);
1089 if (trigger_pairing_info) {
1090 /* BTAPI support only one pairing at a time */
1091 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1092 BT_ERR("New PIN request address [%s]", address);
1093 device_reject_pin_request(&pin_req_event->address);
1097 /* If user initiated bonding and auto response is possible, just reply with default 0000*/
1098 if (_bt_is_bonding_device_address(address) == TRUE &&
1099 _bt_agent_is_auto_response(pin_req_event->cod, address, pin_req_event->name)) {
1100 /* Note: Currently even if SYSPOPUP is supported, we use Fixed PIN "0000" for basic pairing
1101 as BT SYSPOPUP is currently not working for PIN KEY entry in Tizen platform. This needs
1102 to be checked and fixed apropriately */
1103 _bt_set_autopair_status_in_bonding_info(TRUE);
1104 device_accept_pin_request(&pin_req_event->address, "0000");
1105 } else if (_bt_agent_is_hid_keyboard(pin_req_event->cod)) {
1106 BT_DBG("Remote Device is HID keyboard Type..");
1107 char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
1109 if (_bt_agent_generate_passkey(str_passkey,
1110 BT_PASSKEY_MAX_LENGTH) != 0) {
1111 device_reject_pin_request(&pin_req_event->address);
1114 device_accept_pin_request(&pin_req_event->address, str_passkey);
1116 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1117 param = g_variant_new("(isss)", BLUETOOTH_ERROR_NONE, address, pin_req_event->name, str_passkey);
1118 _bt_send_event(BT_ADAPTER_EVENT,
1119 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1120 BT_DBG("Key board pairing in process");
1122 if (_bt_is_bonding_device_address(address) == TRUE) {
1123 BT_DBG("Show Pin entry");
1124 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1125 trigger_pairing_info->addr = g_strdup(address);
1126 trigger_pairing_info->is_ssp = FALSE;
1128 BT_DBG("Send BLUETOOTH_EVENT_PIN_REQUEST");
1129 param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, pin_req_event->name);
1130 _bt_send_event(BT_ADAPTER_EVENT,
1131 BLUETOOTH_EVENT_PIN_REQUEST, param);
1136 _bt_agent_release_memory();
1140 /* SSP Pairing event handler */
1141 static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info)
1144 gchar address[BT_ADDRESS_STR_LEN];
1147 int result = BLUETOOTH_ERROR_NONE;
1150 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1152 name = dev_info->name;
1154 BT_INFO("Address[%s]", address);
1155 BT_INFO("Name[%s]", name);
1156 BT_INFO("COD[%d]", dev_info->cod);
1158 if (trigger_pairing_info) {
1159 /* BTAPI support only one pairing at a time */
1160 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1161 BT_ERR("New PIN request address [%s]", address);
1162 device_reject_pin_request(&dev_info->address);
1167 /* Set pairing data */
1168 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1169 trigger_pairing_info->addr = g_strdup(address);
1170 trigger_pairing_info->is_ssp = TRUE;
1172 param = g_variant_new("(iss)", result, p_addr, name);
1173 _bt_send_event(BT_ADAPTER_EVENT,
1174 BLUETOOTH_EVENT_PASSKEY_REQUEST, param);
1178 static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *dev_info)
1181 gchar address[BT_ADDRESS_STR_LEN];
1184 char str_passkey[7];
1185 int result = BLUETOOTH_ERROR_NONE;
1188 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1190 name = dev_info->device_info.name;
1192 BT_INFO("Address[%s]", address);
1193 BT_INFO("Name[%s]", name);
1194 BT_INFO("COD[%d]", dev_info->device_info.cod);
1196 if (trigger_pairing_info) {
1197 /* BTAPI support only one pairing at a time */
1198 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1199 BT_ERR("New PIN request address [%s]", address);
1200 device_reject_pin_request(&dev_info->device_info.address);
1205 /* Set pairing data */
1206 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1207 trigger_pairing_info->addr = g_strdup(address);
1208 trigger_pairing_info->is_ssp = TRUE;
1210 BT_DBG("Send BLUETOOTH_EVENT_PASSKEY_CONFIRMATION");
1211 snprintf(str_passkey, sizeof(str_passkey), "%.6d", dev_info->pass_key);
1213 param = g_variant_new("(isss)", result, p_addr, name, str_passkey);
1214 _bt_send_event(BT_ADAPTER_EVENT,
1215 BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST, param);
1219 static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_info)
1222 gchar address[BT_ADDRESS_STR_LEN];
1225 char str_passkey[7];
1226 int result = BLUETOOTH_ERROR_NONE;
1229 _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
1231 name = dev_info->device_info.name;
1233 BT_INFO("Address[%s]", address);
1234 BT_INFO("Name[%s]", name);
1235 BT_INFO("COD[%d]", dev_info->device_info.cod);
1237 if (trigger_pairing_info) {
1238 /* BTAPI support only one pairing at a time */
1239 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1240 BT_ERR("New PIN request address [%s]", address);
1241 device_reject_pin_request(&dev_info->device_info.address);
1246 /* Set pairing data */
1247 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1248 trigger_pairing_info->addr = g_strdup(address);
1249 trigger_pairing_info->is_ssp = TRUE;
1251 BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1252 snprintf(str_passkey, sizeof(str_passkey), "%.6d", dev_info->pass_key);
1254 param = g_variant_new("(isss)", result, p_addr, name, str_passkey);
1255 _bt_send_event(BT_ADAPTER_EVENT,
1256 BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
1261 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info)
1263 gchar address[BT_ADDRESS_STR_LEN];
1270 _bt_convert_addr_type_to_string(address, dev_info->address.addr);
1271 name = dev_info->name;
1272 cod = dev_info->cod;
1274 BT_INFO("Address[%s]", address);
1275 BT_INFO("Name[%s]", name);
1276 BT_INFO("COD[%d]", cod);
1278 if (trigger_pairing_info) {
1279 /* BTAPI support only one pairing at a time */
1280 BT_ERR("Already Pairing address [%s]", trigger_pairing_info->addr);
1281 BT_ERR("New PIN request address [%s]", address);
1282 device_reject_pin_request(&dev_info->address);
1287 /* Set pairing data */
1288 trigger_pairing_info = g_malloc0(sizeof(bt_pairing_data_t));
1289 trigger_pairing_info->addr = g_strdup(address);
1290 trigger_pairing_info->is_ssp = TRUE;
1292 local_major = ((cod >> 8) & 0x001f);
1293 local_minor = (cod & 0x00fc);
1294 BT_DBG("SSP_CONSENT: Major type=[0x%x] and Minor type=[0x%x]", local_major, local_minor);
1296 /*TODO: BLUETOOTH_EVENT_SSP_CONSENT_REQUEST to be handled in Tizen */
1300 static void __bt_device_conn_state_changed_callback(event_dev_conn_status_t *acl_event,
1301 gboolean connected, unsigned char type)
1303 gchar address[BT_ADDRESS_STR_LEN];
1304 int result = BLUETOOTH_ERROR_NONE;
1305 GVariant *param = NULL;
1306 bt_device_conn_info_t conn_info;
1309 _bt_convert_addr_type_to_string(address, acl_event->address.addr);
1312 param = g_variant_new("(isy)", result, address, type);
1313 _bt_send_event(BT_DEVICE_EVENT,
1314 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1317 param = g_variant_new("(isy)", result, address, type);
1318 _bt_send_event(BT_DEVICE_EVENT,
1319 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1323 conn_info.connected = connected;
1324 conn_info.type = type;
1325 /* Update local cache */
1326 _bt_update_remote_dev_property(address, DEV_PROP_CONNECTED, (void *)&conn_info);
1331 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble)
1333 bt_remote_dev_info_t *dev_info = NULL;
1334 int result = BLUETOOTH_ERROR_NONE;
1335 GVariant *param = NULL;
1336 GVariant *uuids = NULL;
1337 GVariant *manufacturer_data = NULL;
1338 GVariantBuilder *builder = NULL;
1342 ret_if(_bt_is_discovering() == FALSE);
1343 ret_if(event_data == NULL);
1345 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
1348 event_ble_dev_found_t * oal_ble_dev = event_data;
1349 BT_INFO("Device type [%d]", oal_ble_dev->device_info.type);
1351 _bt_copy_remote_dev(dev_info, &oal_ble_dev->device_info);
1353 dev_info->manufacturer_data_len = oal_ble_dev->adv_len;
1354 if (dev_info->manufacturer_data_len)
1355 dev_info->manufacturer_data = g_memdup(oal_ble_dev->adv_data,
1356 dev_info->manufacturer_data_len);
1358 dev_info->manufacturer_data = NULL;
1359 BT_DBG("----Advertising Data Length: %d", dev_info->manufacturer_data_len);
1361 event_dev_found_t * oal_dev = event_data;
1362 _bt_copy_remote_dev(dev_info, &oal_dev->device_info);
1365 /* If Remote device name is NULL or still RNR is not done then display address as name. */
1366 if (dev_info->name == NULL)
1367 dev_info->name = g_strdup(dev_info->address);
1368 BT_DBG("Name %s", dev_info->name);
1370 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1371 for (i = 0; i < dev_info->uuid_count; i++)
1372 g_variant_builder_add(builder, "s", dev_info->uuids[i]);
1374 uuids = g_variant_new("as", builder);
1375 g_variant_builder_unref(builder);
1377 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1378 dev_info->manufacturer_data,
1379 dev_info->manufacturer_data_len,
1383 param = g_variant_new("(isunsbub@asn@ay)", result,
1389 dev_info->connected,
1392 dev_info->manufacturer_data_len,
1395 _bt_send_event(BT_ADAPTER_EVENT,
1396 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1399 _bt_free_remote_dev(dev_info);
1403 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info)
1405 gchar address[BT_ADDRESS_STR_LEN];
1406 int result = BLUETOOTH_ERROR_NONE;
1407 GVariant *param = NULL;
1411 _bt_convert_addr_type_to_string(address, info->address.addr);
1413 /* Update local cache */
1414 _bt_update_remote_dev_property(address, DEV_PROP_TRUST, (void *)&trusted);
1416 param = g_variant_new("(is)", result, address);
1417 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1418 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1419 /* Send event to application */
1420 _bt_send_event(BT_DEVICE_EVENT,
1427 static void __bt_free_pairing_info(bt_pairing_data_t **p_info)
1430 bt_pairing_data_t * info = *p_info;
1441 static void __bt_free_bond_info(uint8_t type)
1446 case BT_DEVICE_BOND_INFO:
1447 if (!trigger_bond_info)
1450 if (trigger_bond_info->addr)
1451 g_free(trigger_bond_info->addr);
1452 if (trigger_bond_info->dev_addr)
1453 g_free(trigger_bond_info->dev_addr);
1454 if (trigger_bond_info->dev_info)
1455 _bt_free_remote_dev(trigger_bond_info->dev_info);
1456 g_free(trigger_bond_info);
1457 trigger_bond_info = NULL;
1459 case BT_DEVICE_INCOMING_BOND_INFO:
1460 if (!incoming_bond_info)
1463 if (incoming_bond_info->dev_info)
1464 _bt_free_remote_dev(incoming_bond_info->dev_info);
1465 g_free(incoming_bond_info);
1466 incoming_bond_info = NULL;
1468 case BT_DEVICE_UNBOND_INFO:
1469 if (!trigger_unbond_info)
1472 if (trigger_unbond_info->addr)
1473 g_free(trigger_unbond_info->addr);
1474 if (trigger_unbond_info->dev_addr)
1475 g_free(trigger_unbond_info->dev_addr);
1476 if (trigger_unbond_info->dev_info)
1477 _bt_free_remote_dev(trigger_unbond_info->dev_info);
1478 g_free(trigger_unbond_info);
1479 trigger_unbond_info = NULL;
1485 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info)
1487 bt_service_search_info_data_t * info = *p_info;
1494 if (info->dev_addr) {
1495 g_free(info->dev_addr);
1496 info->dev_addr = NULL;
1499 if (info->dev_info) {
1500 _bt_free_remote_dev(info->dev_info);
1501 info->dev_info = NULL;
1509 static int __bt_device_handle_bond_state(void)
1511 BT_INFO("Current Bond state: %d", bt_device_bond_state);
1512 int ret = OAL_STATUS_INTERNAL_ERROR;
1514 switch (bt_device_bond_state) {
1515 case BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY:
1516 /*TODO:Bonding during discovery: Unhandled!!*/
1517 BT_INFO("Bonding during discovery: Unhandled!!");
1519 case BT_DEVICE_BOND_STATE_DISCOVERY_CANCELLED:
1520 /*TODO:Bonding during discovery: Unhandled!!*/
1521 BT_INFO("Bonding during discovery: Unhandled!!");
1523 case BT_DEVICE_BOND_STATE_REMOVE_BONDING:
1524 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING;
1525 ret = device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
1526 if (ret != OAL_STATUS_SUCCESS)
1527 ret = __bt_device_handle_bond_state();
1529 case BT_DEVICE_BOND_STATE_REMOVED_BONDING:
1530 bt_device_bond_state = BT_DEVICE_BOND_STATE_NONE;
1531 ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, trigger_bond_info->conn_type);
1532 /* Bonding procedure was started but unfortunately could not complete.
1533 Basically removed bonding was success, but create bond request could not proceed
1534 So lets cleanup the context */
1535 if (ret != OAL_STATUS_SUCCESS) {
1536 BT_ERR("Create Bond procedure could not suceed");
1537 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1538 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1539 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1540 __bt_free_pairing_info(&trigger_pairing_info);
1543 case BT_DEVICE_BOND_STATE_NONE:
1544 BT_INFO("Create Bond failed!!");
1545 if (trigger_bond_info) {
1546 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
1547 trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
1548 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1549 __bt_free_pairing_info(&trigger_pairing_info);
1556 if (ret != OAL_STATUS_SUCCESS)
1557 return BLUETOOTH_ERROR_INTERNAL;
1559 return BLUETOOTH_ERROR_NONE;
1562 int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr)
1565 bt_address_t bd_addr;
1569 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
1571 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
1572 result = device_query_attributes(&bd_addr);
1573 if (result != OAL_STATUS_SUCCESS) {
1574 BT_ERR("device_query_attributes error: [%d]", result);
1575 return BLUETOOTH_ERROR_INTERNAL;
1579 return BLUETOOTH_ERROR_NONE;
1582 int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias)
1585 char address[BT_ADDRESS_STRING_SIZE];
1588 BT_CHECK_PARAMETER(alias, return);
1590 ret = device_set_alias((bt_address_t *)device_address, (char *)alias);
1591 if (ret != OAL_STATUS_SUCCESS) {
1592 BT_ERR("device_set_alias: %d", ret);
1593 return BLUETOOTH_ERROR_INTERNAL;
1596 /* Update local cache */
1597 _bt_convert_addr_type_to_string(address, device_address->addr);
1598 _bt_update_remote_dev_property(address, DEV_PROP_ALIAS, (void *)alias);
1601 return BLUETOOTH_ERROR_NONE;
1604 int _bt_bond_device(bluetooth_device_address_t *device_address,
1605 unsigned short conn_type, GArray **out_param1)
1607 int result = BLUETOOTH_ERROR_NONE;
1608 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1609 bluetooth_device_info_t dev_info;
1612 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1614 /* If bonding or discovery already going on */
1615 if (trigger_bond_info || _bt_is_discovering()) {
1616 BT_ERR("Device is buzy, bonding can not proceed now..");
1617 result = BLUETOOTH_ERROR_DEVICE_BUSY;
1621 /*TODO: If unbonding with same device going on */
1622 _bt_convert_addr_type_to_string(address, device_address->addr);
1624 trigger_bond_info = g_malloc0(sizeof(bt_bond_data_t));
1625 trigger_bond_info->addr = g_strdup(address);
1626 trigger_bond_info->conn_type = conn_type;
1627 trigger_bond_info->is_device_creating = TRUE;
1628 trigger_bond_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
1629 trigger_bond_info->dev_info = NULL;
1631 /* Ready to initiate bonding */
1633 /* In Tizen, we will first remove bond and then attempt to create bond to keep
1634 consistency with bluedroid. Even if remove bond fails due to device not already
1635 bonded, then straight away create bond is triggered. This is because, remove bond
1636 is handled differently in bluedroid and bluez. In Bluez, if device is
1637 already removed, remove bond call fails.
1638 However in bluedroid, remove bond on already removed device returns success. So we will
1639 handle the cases transparently*/
1640 bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVE_BONDING;
1641 bond_retry_count = 0;
1642 result = __bt_device_handle_bond_state();
1644 if (result != BLUETOOTH_ERROR_NONE)
1651 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1652 memcpy(dev_info.device_address.addr, device_address->addr,
1653 BLUETOOTH_ADDRESS_LENGTH);
1655 g_array_append_vals(*out_param1, &dev_info,
1656 sizeof(bluetooth_device_info_t));
1657 __bt_free_bond_info(BT_DEVICE_BOND_INFO);
1663 int _bt_unbond_device(bluetooth_device_address_t *device_address,
1664 GArray **out_param1)
1666 int result = OAL_STATUS_SUCCESS;
1667 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1668 bluetooth_device_info_t dev_info;
1671 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1673 _bt_convert_addr_type_to_string(address, device_address->addr);
1675 trigger_unbond_info = g_malloc0(sizeof(bt_bond_data_t));
1676 trigger_unbond_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1677 trigger_unbond_info->addr = g_strdup(address);
1678 trigger_unbond_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
1680 /* Check if Bonding is already going on, we should not abruptly remove bonding*/
1681 if (trigger_bond_info && strncmp(trigger_bond_info->addr, trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE) == 0) {
1682 BT_ERR("Bonding with same device already ongoing");
1683 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
1687 result = device_destroy_bond((bt_address_t *)device_address);
1688 if (result != OAL_STATUS_SUCCESS)
1694 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1695 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1696 trigger_unbond_info->addr);
1698 g_array_append_vals(*out_param1, &dev_info,
1699 sizeof(bluetooth_device_info_t));
1700 __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
1705 int _bt_cancel_bonding(void)
1707 int result = OAL_STATUS_SUCCESS;
1710 retv_if(trigger_bond_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
1712 result = device_stop_bond((bt_address_t *)trigger_bond_info->dev_addr);
1714 if (result == OAL_STATUS_SUCCESS)
1715 trigger_bond_info->is_cancelled_by_user = TRUE;
1720 int _bt_passkey_reply(const char *passkey, gboolean cnfm_reply)
1722 bluetooth_device_address_t device_address;
1723 int ret = OAL_STATUS_SUCCESS;
1724 BT_INFO("reply: %d", cnfm_reply);
1726 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1727 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1729 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1731 if (trigger_pairing_info->is_ssp) {
1733 ret = device_accept_passkey_entry((bt_address_t *)&device_address, atoi(passkey));
1735 ret = device_reject_passkey_entry((bt_address_t *)&device_address);
1736 trigger_pairing_info->is_ssp = FALSE;
1739 ret = device_accept_pin_request((bt_address_t *)&device_address, passkey);
1741 ret = device_reject_pin_request((bt_address_t *)&device_address);
1744 __bt_free_pairing_info(&trigger_pairing_info);
1746 if (ret != OAL_STATUS_SUCCESS) {
1747 BT_ERR("_bt_device_handle_passkey_reply: err [%d]", ret);
1748 return BLUETOOTH_ERROR_INTERNAL;
1752 return BLUETOOTH_ERROR_NONE;
1755 int _bt_passkey_confirmation_reply(gboolean cnfm_reply)
1757 BT_INFO("BT_PASSKEY_CONFIRMATION_REPLY");
1758 bluetooth_device_address_t device_address;
1759 int ret = OAL_STATUS_SUCCESS;
1760 BT_INFO("reply: %d", cnfm_reply);
1762 retv_if(trigger_pairing_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1763 retv_if(trigger_pairing_info->addr == NULL, BLUETOOTH_ERROR_INTERNAL);
1765 _bt_convert_addr_string_to_type(device_address.addr, trigger_pairing_info->addr);
1767 ret = device_reply_passkey_confirmation((bt_address_t *)&device_address, cnfm_reply);
1769 __bt_free_pairing_info(&trigger_pairing_info);
1770 if (ret != OAL_STATUS_SUCCESS) {
1771 BT_ERR("_bt_device_handle_passkey_confirmation_reply: err [%d]", ret);
1772 return BLUETOOTH_ERROR_INTERNAL;
1776 return BLUETOOTH_ERROR_NONE;
1779 gboolean _bt_device_is_pairing(void)
1781 return (trigger_pairing_info) ? TRUE : FALSE;
1784 gboolean _bt_device_is_bonding(void)
1786 return (trigger_bond_info) ? TRUE : FALSE;
1789 gboolean _bt_is_bonding_device_address(const char *address)
1791 if (trigger_bond_info == NULL || trigger_bond_info->addr == NULL)
1794 if (g_strcmp0(trigger_bond_info->addr, address) == 0) {
1795 BT_DBG("[%s] is bonding device", address);
1799 BT_DBG("[%s] is NOT bonding device", address);
1803 void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
1805 ret_if(trigger_bond_info == NULL);
1806 trigger_bond_info->is_autopair = is_autopair;
1809 int _bt_search_device(bluetooth_device_address_t *device_address)
1811 int result = OAL_STATUS_SUCCESS;
1814 BT_CHECK_PARAMETER(device_address, return);
1816 if (trigger_bond_info) {
1817 BT_ERR("Bonding in progress");
1818 return BLUETOOTH_ERROR_DEVICE_BUSY;
1821 if (service_search_info) {
1822 BT_ERR("Service searching in progress");
1823 return BLUETOOTH_ERROR_DEVICE_BUSY;
1826 /* allocate user data so that it can be retrieved in callback */
1827 service_search_info = g_malloc0(sizeof(bt_service_search_info_data_t));
1828 service_search_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1829 service_search_info->dev_addr = g_memdup(device_address, sizeof(bluetooth_device_address_t));
1831 _bt_convert_addr_type_to_string(service_search_info->addr,
1832 device_address->addr);
1834 result = device_query_services((bt_address_t *)device_address);
1836 if (result != OAL_STATUS_SUCCESS) {
1837 BT_ERR("Device Service Search Failed..: %d", result);
1838 __bt_free_service_search_info(&service_search_info);
1839 return BLUETOOTH_ERROR_INTERNAL;
1841 return BLUETOOTH_ERROR_NONE;
1844 int _bt_cancel_search_device(void)
1846 int ret = OAL_STATUS_SUCCESS;
1847 retv_if(service_search_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
1849 ret = device_stop_query_sevices((bt_address_t *)service_search_info->dev_addr);
1851 if (ret != OAL_STATUS_SUCCESS) {
1852 BT_ERR("SDP Cancel request failed [%d]", ret);
1853 return BLUETOOTH_ERROR_INTERNAL;
1856 __bt_device_handle_pending_requests(BLUETOOTH_ERROR_CANCEL_BY_USER, BT_SEARCH_SERVICE,
1857 service_search_info->addr, BT_ADDRESS_STRING_SIZE);
1859 __bt_free_service_search_info(&service_search_info);
1861 return BLUETOOTH_ERROR_NONE;
1865 int _bt_set_authorization(bluetooth_device_address_t *device_address,
1868 int ret = OAL_STATUS_SUCCESS;
1871 BT_CHECK_PARAMETER(device_address, return);
1872 BT_INFO("Device to be Trusted? [%d]", authorize);
1874 ret = device_set_authorized((bt_address_t*)device_address, authorize);
1875 if (ret != OAL_STATUS_SUCCESS) {
1876 BT_ERR("device_set_authorized: %d", ret);
1877 return BLUETOOTH_ERROR_INTERNAL;
1880 return BLUETOOTH_ERROR_NONE;
1883 gboolean _bt_is_device_connected(bluetooth_device_address_t *device_address, int svc_type)
1885 gboolean is_connected;
1886 oal_service_t svc_id;
1888 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1891 * TODO: While adding support for new profiles, need to add more
1892 * <svc_type, svc_id> mapping here.
1895 case BT_PROFILE_CONN_HID:
1896 svc_id = HID_SERVICE_ID;
1898 case BT_PROFILE_CONN_A2DP:
1899 svc_id = A2DP_SERVICE_ID; /* Remote is A2DP Sink */
1901 case BT_PROFILE_CONN_A2DP_SINK:
1902 svc_id = A2DP_SRC_SERVICE_ID; /* Remote is A2DP Source*/
1904 case BT_PROFILE_CONN_HSP:
1905 svc_id = HFP_HS_SERVICE_ID; /* Remote is HFP HF Unit */
1908 BT_DBG("Unknown svc_type: %d", svc_type);
1912 is_connected = device_get_svc_conn_state((bt_address_t*)device_address, svc_id);
1914 BT_DBG("svc_type: %d, is_connected: %s",
1915 svc_type, is_connected ? "TRUE" : "FALSE");
1917 return is_connected;
1920 int _bt_rfcomm_reply_conn_authorization(char *address, gboolean reply)
1922 bt_address_t bd_addr;
1927 retv_if(NULL == address, BLUETOOTH_ERROR_INVALID_PARAM);
1928 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1929 res = device_reply_auth_request(&bd_addr, 0, reply, FALSE);
1930 if (res != OAL_STATUS_SUCCESS) {
1931 BT_ERR("authorize_response: %d", res);
1932 return BLUETOOTH_ERROR_INTERNAL;
1936 return BLUETOOTH_ERROR_NONE;
1939 int _bt_enable_rssi(bluetooth_device_address_t *addr, int link_type,
1940 int low_threshold, int in_range_threshold, int high_threshold)
1943 bt_address_t bd_addr;
1947 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
1949 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
1950 result = device_enable_rssi_monitoring(&bd_addr, link_type,
1951 low_threshold, in_range_threshold, high_threshold);
1952 if (result != OAL_STATUS_SUCCESS) {
1953 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
1954 return BLUETOOTH_ERROR_INTERNAL;
1958 return BLUETOOTH_ERROR_NONE;
1961 int _bt_get_rssi_strength(bluetooth_device_address_t *addr, int link_type)
1964 bt_address_t bd_addr;
1968 retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
1970 memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
1971 result = device_get_connected_link_rssi_strength(&bd_addr, link_type);
1972 if (result != OAL_STATUS_SUCCESS) {
1973 BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
1974 return BLUETOOTH_ERROR_INTERNAL;
1978 return BLUETOOTH_ERROR_NONE;