Adapt device disconnect to BT HAL framework
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / device / bt-service-core-device.c
index abd1bb8..dc7337d 100644 (file)
@@ -207,8 +207,9 @@ void __bt_device_handle_pending_requests(int result, int service_function,
        BT_DBG("+");
 
        /* Get method invocation context */
-       for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+       for (l = _bt_get_invocation_list(); l != NULL; ) {
                req_info = l->data;
+               l = g_slist_next(l);
                if (req_info == NULL || req_info->service_function != service_function)
                        continue;
 
@@ -1123,6 +1124,7 @@ static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
        GVariant *param;
        char address[BT_ADDRESS_STRING_SIZE];
        char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
+       bool incoming = false;
        BT_DBG("+");
 
        _bt_convert_addr_type_to_string(address, pin_req_event->address.addr);
@@ -1159,7 +1161,11 @@ static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
                device_accept_pin_request(&pin_req_event->address, str_passkey);
 
                BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
-               param = g_variant_new("(isss)", BLUETOOTH_ERROR_NONE, address, pin_req_event->name, str_passkey);
+
+               if(trigger_bond_info == NULL)
+                       incoming = true;
+
+               param = g_variant_new("(bsss)", incoming, address, pin_req_event->name, str_passkey);
                _bt_send_event(BT_ADAPTER_EVENT,
                                BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
                BT_DBG("Key board pairing in process");
@@ -1174,7 +1180,11 @@ static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
                        trigger_pairing_info->is_ssp = FALSE;
 
                        BT_DBG("Send BLUETOOTH_EVENT_PIN_REQUEST");
-                       param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, pin_req_event->name);
+
+                       if(trigger_bond_info == NULL)
+                               incoming = true;
+
+                       param = g_variant_new("(bss)", incoming, address, pin_req_event->name);
                        _bt_send_event(BT_ADAPTER_EVENT,
                                        BLUETOOTH_EVENT_PIN_REQUEST, param);
                }
@@ -1192,7 +1202,8 @@ static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info)
        gchar address[BT_ADDRESS_STR_LEN];
        char *p_addr;
        gchar *name;
-       int result = BLUETOOTH_ERROR_NONE;
+       bool incoming = false;
+
        BT_DBG("+");
 
        _bt_convert_addr_type_to_string(address, dev_info->address.addr);
@@ -1217,7 +1228,10 @@ static void __bt_device_ssp_passkey_entry_callback(remote_device_t* dev_info)
        trigger_pairing_info->addr = g_strdup(address);
        trigger_pairing_info->is_ssp = TRUE;
 
-       param = g_variant_new("(iss)", result, p_addr, name);
+       if(trigger_bond_info == NULL)
+               incoming = true;
+
+       param = g_variant_new("(bss)", incoming, p_addr, name);
        _bt_send_event(BT_ADAPTER_EVENT,
                        BLUETOOTH_EVENT_PASSKEY_REQUEST, param);
        BT_DBG("-");
@@ -1230,7 +1244,7 @@ static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *d
        char *p_addr;
        gchar *name;
        char str_passkey[7];
-       int result = BLUETOOTH_ERROR_NONE;
+       bool incoming = false; /*Stores if bonding request is incoming(true) or outgoing(false) */
        BT_DBG("+");
 
        _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
@@ -1258,7 +1272,11 @@ static void __bt_device_ssp_passkey_confirmation_callback(event_dev_passkey_t *d
        BT_DBG("Send BLUETOOTH_EVENT_PASSKEY_CONFIRMATION");
        snprintf(str_passkey, sizeof(str_passkey), "%.6d", dev_info->pass_key);
 
-       param = g_variant_new("(isss)", result, p_addr, name, str_passkey);
+       /*Storing if bond is incoming or outgoing*/
+       if(trigger_bond_info == NULL)
+               incoming = true;
+
+       param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
        _bt_send_event(BT_ADAPTER_EVENT,
                        BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST, param);
        BT_DBG("-");
@@ -1271,7 +1289,7 @@ static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_in
        char *p_addr;
        gchar *name;
        char str_passkey[7];
-       int result = BLUETOOTH_ERROR_NONE;
+       bool incoming = false;
        BT_DBG("+");
 
        _bt_convert_addr_type_to_string(address, dev_info->device_info.address.addr);
@@ -1299,7 +1317,11 @@ static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_in
        BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
        snprintf(str_passkey, sizeof(str_passkey), "%06d", dev_info->pass_key);
 
-       param = g_variant_new("(isss)", result, p_addr, name, str_passkey);
+       if(trigger_bond_info == NULL)
+               incoming = true;
+
+        param = g_variant_new("(bsss)", incoming, p_addr, name, str_passkey);
+
        if (passkey_watcher) {
                BT_INFO("Send passkey to %s", passkey_watcher);
                _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
@@ -2472,4 +2494,22 @@ fail:
        return ret;
 }
 
+int _bt_disconnect_device(bluetooth_device_address_t *device_address)
+{
+       int result = OAL_STATUS_SUCCESS;
+
+       BT_DBG("+");
+
+       retv_if(!device_address, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       result = device_disconnect((bt_address_t *)device_address);
+       if (result != OAL_STATUS_SUCCESS) {
+               BT_DBG("Failed to disconnect device");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
+
 #endif