[Adapt] Refactor Bonding failed event handling codes 59/86059/1
authorAnupam Roy <anupam.r@samsung.com>
Mon, 1 Aug 2016 14:43:28 +0000 (20:13 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Mon, 1 Aug 2016 14:43:28 +0000 (20:13 +0530)
Change-Id: I23cb9e280a9e1f9bbc285381a09658f6de149bb7
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-service-adaptation/services/device/bt-service-core-device.c

index 1158985..25f1574 100644 (file)
@@ -622,12 +622,17 @@ static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_f
                        int ret = OAL_STATUS_SUCCESS;
                        if (bond_retry_count < MAX_BOND_RETRY_COUNT) {
                                ret = device_create_bond((bt_address_t *)trigger_bond_info->dev_addr, BLUETOOTH_DEV_CONN_DEFAULT);
-                               bond_retry_count++;
+                               if (ret != OAL_STATUS_SUCCESS) {
+                                       BT_ERR("Create Bond procedure could not suceed");
+                                       __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);
+                                       bond_retry_count = 0;
+                               } else
+                                       bond_retry_count++;
                        } else {
                                BT_ERR("Create Bond failed MAX_BOND_RETRY_COUNT TIMES!!");
-                       }
-                       if (ret != OAL_STATUS_SUCCESS || bond_retry_count >= MAX_BOND_RETRY_COUNT) {
-                               BT_ERR("Create Bond procedure could not suceed");
                                __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);
@@ -672,10 +677,12 @@ static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_f
                        __bt_free_pairing_info(&trigger_pairing_info);
                } else if (trigger_bond_info) {
                        if (__bt_device_handle_bond_state()!= BLUETOOTH_ERROR_NONE) {
-                               __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);
+                               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;
@@ -1130,6 +1137,7 @@ static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* in
 
 static void __bt_free_pairing_info(bt_pairing_data_t **p_info)
 {
+       BT_DBG("+");
        bt_pairing_data_t * info = *p_info;
        if (info) {
                if(info->addr) {
@@ -1139,6 +1147,7 @@ static void __bt_free_pairing_info(bt_pairing_data_t **p_info)
                g_free(info);
        }
        *p_info = NULL;
+       BT_DBG("-");
 }
 
 static void __bt_free_bond_info(uint8_t type)
@@ -1181,6 +1190,7 @@ static void __bt_free_bond_info(uint8_t type)
                        trigger_unbond_info = NULL;
                }
        }
+       BT_INFO("-");
 }
 
 static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info)