gsize size = 0;
bdstr_t bdstr;
- /*Below code is commented out for handling Get Bonded devices for BLuez case.
- GetALl properties on a particular device interface can reyurn properties of
- an unpaired or untrusted device. If We block the below event, Application
- request (BT_GET_BONDED_DEVICES) will timeout on DBUS */
-#if 0
- if(BT_STATUS_SUCCESS != status) {
- BT_ERR("[%s]status: %d", bdt_bd2str((bt_address_t*)bd_addr, &bdstr), status);
- return;
- }
-#endif
- BT_DBG("[%s]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
+ BT_DBG("[%s]status: [%d] num properties [%d]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr),
+ status, num_properties);
+
dev_info = g_new0(remote_device_t, 1);
memcpy(dev_info->address.addr, bd_addr->address, 6);
parse_device_properties(num_properties, properties, dev_info, &adv_info);
- if(num_properties == 1) {
+ if (num_properties == 0) {
+ BT_ERR("!!Unexpected!! num properties is 0 status [%d]", status);
+ /* It is possible that app called get bonded device info for a device
+ which is not yet bonded or udner bonding, in such case, stack will return no properties.
+ It is also possible that after bonding is done, BT MW attempted to fetch
+ bonded device info, but due to internal stack error, 0 properties with status FAIL
+ are received from stack. In such cases, simply send the event to BT MW
+ and let it handle this event */
+ event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
+ memcpy(&dev_props_event->device_info,
+ dev_info, sizeof(remote_device_t));
+ event_data = dev_props_event;
+ event = OAL_EVENT_DEVICE_PROPERTIES;
+ size = sizeof(event_dev_properties_t);
+ } else if (num_properties == 1) {
/* For one particular property a dedicated event to be sent */
switch(properties[0].type) {
case BT_PROPERTY_BDNAME:
bt_bond_data_t *trigger_unbond_info;
bt_pairing_data_t *trigger_pairing_info;
+
typedef enum {
BT_DEVICE_BOND_STATE_NONE,
BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY,
}
BT_INFO("Bonding successfully completed");
- /* TODO: Bonding state will be cleaned up & BONDING FINISHED EVENT
+ /* Bonding state will be cleaned up & BONDING FINISHED EVENT
will be sent only when Properties are fetched from stack
- Till that time lets not free trigger_bond_info */
- __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
- trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
-
+ Till that time lets not free trigger_bond_info.
+ However it is possible that while fetching device properties, internal
+ stack error can occur which can lead to no valid properties or
+ no properties at all. So in such cases, we must not wait for properties,
+ otherwise, it can lead to infinite wait */
_bt_convert_addr_string_to_type(dev_addr.addr,
- trigger_bond_info->addr);
- _bt_device_get_bonded_device_info(&dev_addr);
+ trigger_bond_info->addr);
+
+ if (_bt_device_get_bonded_device_info(&dev_addr) == BLUETOOTH_ERROR_NONE) {
+ BT_DBG("BOnded device info query posted to stack successfully");
+ __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
+ trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
+ } else {
+ BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
+ __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
+ trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
+ /* Destroy if at all device got bonded at stack level */
+ device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
+
+ __bt_free_bond_info(BT_DEVICE_BOND_INFO);
+ __bt_free_pairing_info(&trigger_pairing_info);
+ }
+
BT_INFO("-");
}
__bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
__bt_free_pairing_info(&trigger_pairing_info);
} else if (trigger_bond_info) {
+ BT_ERR("Bonding was removed");
__bt_device_handle_bond_state();
}
BT_INFO("-");
BT_INFO("ACL Connected event Received");
event_dev_conn_status_t* param = event_data;
__bt_device_acl_state_changed_callback(param, TRUE);
- __bt_device_handle_bond_removal_event(&(param->address));
break;
}
case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
break;
case BT_DEVICE_BOND_STATE_NONE:
BT_INFO("Create Bond failed!!");
+ if (trigger_bond_info) {
+ __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
+ trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
+ __bt_free_bond_info(BT_DEVICE_BOND_INFO);
+ __bt_free_pairing_info(&trigger_pairing_info);
+ }
break;
default:
break;