Modify the log level
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / bt-request-handler.c
index ef37f72..5a2f90a 100644 (file)
@@ -251,7 +251,8 @@ static gboolean __bt_is_sync_function(int service_function)
                        || service_function == BT_MESH_NETWORK_DELETE_APPKEY
                        || service_function == BT_MESH_NETWORK_UPDATE_APPKEY
                        || service_function == BT_L2CAP_LE_LISTEN_AND_ACCEPT
-                       || service_function == BT_L2CAP_LE_LISTEN)
+                       || service_function == BT_L2CAP_LE_LISTEN
+                       || service_function == BT_REQ_ATT_MTU)
                return TRUE;
        else
                return FALSE;
@@ -957,7 +958,7 @@ int __bt_bluez_request(int function_name,
               result = _bt_set_le_privacy(set_privacy);
               break;
        }
-       case BT_ADD_WHITE_LIST: {
+       case BT_ADD_ALLOW_LIST: {
                bluetooth_device_address_t address = { {0} };
                int address_type = 0;
                bool is_add = true;
@@ -965,10 +966,10 @@ int __bt_bluez_request(int function_name,
                                &address, sizeof(bluetooth_device_address_t));
                __bt_service_get_parameters(in_param2,
                                &address_type, sizeof(int));
-               result = _bt_set_white_list(&address, address_type, is_add);
+               result = _bt_set_allow_list(&address, address_type, is_add);
                break;
        }
-       case BT_REMOVE_WHITE_LIST: {
+       case BT_REMOVE_ALLOW_LIST: {
                bluetooth_device_address_t address = { {0} };
                int address_type = 0;
                bool is_add = false;
@@ -976,7 +977,7 @@ int __bt_bluez_request(int function_name,
                                &address, sizeof(bluetooth_device_address_t));
                __bt_service_get_parameters(in_param2,
                                &address_type, sizeof(int));
-               result = _bt_set_white_list(&address, address_type, is_add);
+               result = _bt_set_allow_list(&address, address_type, is_add);
                break;
         }
        case BT_UPDATE_LE_CONNECTION_MODE: {
@@ -1222,105 +1223,106 @@ int __bt_bluez_request(int function_name,
                g_array_append_vals(*out_param1, &value, sizeof(int));
                break;
        }
-       case BT_DPM_ADD_DEVICES_BLACKLIST: {
+       case BT_DPM_ADD_DEVICES_BLOCKLIST: {
                bluetooth_device_address_t address = { {0} };
 
                __bt_service_get_parameters(in_param1, &address,
                        sizeof(bluetooth_device_address_t));
 
-               result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address);
+               result = _bt_dpm_add_bluetooth_devices_to_blocklist(&address);
                break;
        }
-       case BT_DPM_ADD_DEVICES_WHITELIST: {
+       case BT_DPM_ADD_DEVICES_ALLOWLIST: {
                bluetooth_device_address_t address = { {0} };
 
                __bt_service_get_parameters(in_param1, &address,
                        sizeof(bluetooth_device_address_t));
 
-               result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address);
+               result = _bt_dpm_add_bluetooth_devices_to_allowlist(&address);
                break;
        }
-       case BT_DPM_ADD_UUIDS_BLACKLIST: {
+       case BT_DPM_ADD_UUIDS_BLOCKLIST: {
                const char *uuid = NULL;
 
                uuid = g_variant_get_data(in_param1);
 
-               result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid);
+               result = _bt_dpm_add_bluetooth_uuids_to_blocklist(uuid);
                break;
        }
-       case BT_DPM_ADD_UUIDS_WHITELIST: {
+       case BT_DPM_ADD_UUIDS_ALLOWLIST: {
                const char *uuid = NULL;
 
                uuid = g_variant_get_data(in_param1);
 
-               result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid);
+               result = _bt_dpm_add_bluetooth_uuids_to_allowlist(uuid);
                break;
        }
-       case BT_DPM_CLEAR_DEVICES_BLACKLIST: {
-               result = _bt_dpm_clear_bluetooth_devices_from_blacklist();
+       case BT_DPM_CLEAR_DEVICES_BLOCKLIST: {
+               result = _bt_dpm_clear_bluetooth_devices_from_blocklist();
                break;
        }
-       case BT_DPM_CLEAR_DEVICES_WHITELIST: {
-               result = _bt_dpm_clear_bluetooth_devices_from_whitelist();
+       case BT_DPM_CLEAR_DEVICES_ALLOWLIST: {
+               result = _bt_dpm_clear_bluetooth_devices_from_allowlist();
                break;
        }
-       case BT_DPM_CLEAR_UUIDS_BLACKLIST: {
-               result = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
+       case BT_DPM_CLEAR_UUIDS_BLOCKLIST: {
+               result = _bt_dpm_clear_bluetooth_uuids_from_blocklist();
                break;
        }
-       case BT_DPM_CLEAR_UUIDS_WHITELIST: {
-               result = _bt_dpm_clear_bluetooth_uuids_from_whitelist();
+       case BT_DPM_CLEAR_UUIDS_ALLOWLIST: {
+               result = _bt_dpm_clear_bluetooth_uuids_from_allowlist();
                break;
        }
-       case BT_DPM_REMOVE_DEVICE_BLACKLIST: {
+       case BT_DPM_REMOVE_DEVICE_BLOCKLIST: {
                bluetooth_device_address_t address = { {0} };
 
                __bt_service_get_parameters(in_param1, &address,
                        sizeof(bluetooth_device_address_t));
 
-               result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address);
+               result = _bt_dpm_remove_bluetooth_devices_from_blocklist(&address);
                break;
        }
-       case BT_DPM_REMOVE_DEVICE_WHITELIST: {
+       case BT_DPM_REMOVE_DEVICE_ALLOWLIST: {
                bluetooth_device_address_t address = { {0} };
 
                __bt_service_get_parameters(in_param1, &address,
                        sizeof(bluetooth_device_address_t));
 
-               result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address);
+               result = _bt_dpm_remove_bluetooth_devices_from_allowlist(&address);
                break;
        }
-       case BT_DPM_REMOVE_UUID_BLACKLIST: {
+       case BT_DPM_REMOVE_UUID_BLOCKLIST: {
                const char *uuid = NULL;
 
                uuid = g_variant_get_data(in_param1);
 
-               result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid);
+               result = _bt_dpm_remove_bluetooth_uuids_from_blocklist(uuid);
                break;
        }
-       case BT_DPM_REMOVE_UUID_WHITELIST: {
+       case BT_DPM_REMOVE_UUID_ALLOWLIST: {
                const char *uuid = NULL;
 
                uuid = g_variant_get_data(in_param1);
 
-               result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid);
+               result = _bt_dpm_remove_bluetooth_uuids_from_allowlist(uuid);
 
                break;
        }
-       case BT_DPM_GET_DEVICES_BLACKLIST: {
-               result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1);
+       case BT_DPM_GET_DEVICES_BLOCKLIST: {
+               result = _bt_dpm_get_bluetooth_devices_from_blocklist(out_param1);
                break;
        }
-       case BT_DPM_GET_DEVICES_WHITELIST: {
-               result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1);
+       case BT_DPM_GET_DEVICES_ALLOWLIST: {
+               result = _bt_dpm_get_bluetooth_devices_from_allowlist(out_param1);
+
                break;
        }
-       case BT_DPM_GET_UUIDS_BLACKLIST: {
-               result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1);
+       case BT_DPM_GET_UUIDS_BLOCKLIST: {
+               result = _bt_dpm_get_bluetooth_uuids_from_blocklist(out_param1);
                break;
        }
-       case BT_DPM_GET_UUIDS_WHITELIST: {
-               result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1);
+       case BT_DPM_GET_UUIDS_ALLOWLIST: {
+               result = _bt_dpm_get_bluetooth_uuids_from_allowlist(out_param1);
                break;
        }
        case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
@@ -1476,6 +1478,7 @@ int __bt_bluez_request(int function_name,
 
                        conn_info.device_role = RFCOMM_ROLE_CLIENT;
                        conn_info.socket_fd = -1;
+                       memcpy(&conn_info.device_addr, &address, sizeof(bluetooth_device_address_t));
                        g_array_append_vals(*out_param1, &conn_info,
                                        sizeof(bluetooth_rfcomm_connection_t));
                } else {
@@ -2292,7 +2295,9 @@ int __bt_bluez_request(int function_name,
                int *adv_handle;
                bluetooth_advertising_data_t adv = { {0} };
                int length;
-               gboolean use_reserved_slot = FALSE;
+               bluetooth_le_slot_and_adv_type_t rs_at;
+               rs_at.is_legacy = TRUE;
+               rs_at.use_reserved_slot = FALSE;
 
                app = (char *)g_dbus_method_invocation_get_sender(context);
                adv_handle = g_malloc0(sizeof(int));
@@ -2304,9 +2309,9 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param2,
                                &adv, length);
                __bt_service_get_parameters(in_param4,
-                               &use_reserved_slot, sizeof(gboolean));
+                               &rs_at, sizeof(bluetooth_le_slot_and_adv_type_t));
                result = _bt_set_advertising_data(app, *adv_handle,
-                               &adv, length, use_reserved_slot);
+                               &adv, length, &rs_at);
                if (result != BLUETOOTH_ERROR_NONE) {
                        BT_ERR("Set Advertising data failed!!");
                        g_free(adv_handle);
@@ -2622,6 +2627,18 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+       case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE: {
+               char *uuid;
+               uuid = (char *)g_variant_get_data(in_param1);
+               result = _bt_gatt_server_set_service_persistence(uuid);
+               break;
+       }
+       case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE: {
+               char *uuid;
+               uuid = (char *)g_variant_get_data(in_param1);
+               result = _bt_gatt_server_unset_service_persistence(uuid);
+               break;
+       }
        case BT_GATT_SERVER_SEND_RESPONSE: {
                bluetooth_gatt_server_response_params_t param;
                bluetooth_gatt_att_data_t data;
@@ -2739,6 +2756,68 @@ int __bt_bluez_request(int function_name,
                result = _bt_gatt_server_update_attribute_value(app, instance_id, &param);
                break;
        }
+       case BT_GATT_SERVER_READ_PHY: {
+               bluetooth_device_address_t address = { {0} };
+
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_gatt_server_read_phy(&address);
+               break;
+       }
+       case BT_GATT_SERVER_SET_PHY: {
+               bluetooth_device_address_t address = { {0} };
+               int tx_phy;
+               int rx_phy;
+               int phy_options;
+
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2,
+                               &tx_phy, sizeof(int));
+               __bt_service_get_parameters(in_param3,
+                               &rx_phy, sizeof(int));
+               __bt_service_get_parameters(in_param4,
+                               &phy_options, sizeof(int));
+
+               result = _bt_gatt_server_set_phy(&address, tx_phy, rx_phy, phy_options);
+               break;
+       }
+       case BT_GATT_CLIENT_READ_PHY: {
+               bluetooth_device_address_t address = { {0} };
+
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_gatt_client_read_phy(&address);
+               break;
+       }
+       case BT_GATT_CLIENT_SET_PHY: {
+               bluetooth_device_address_t address = { {0} };
+               int tx_phy;
+               int rx_phy;
+               int phy_options;
+
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2,
+                               &tx_phy, sizeof(int));
+               __bt_service_get_parameters(in_param3,
+                               &rx_phy, sizeof(int));
+               __bt_service_get_parameters(in_param4,
+                               &phy_options, sizeof(int));
+
+               result = _bt_gatt_client_set_phy(&address, tx_phy, rx_phy, phy_options);
+               break;
+       }
        case BT_GET_ATT_MTU: {
                bluetooth_device_address_t address = { {0} };
                unsigned int mtu = 0;
@@ -3393,6 +3472,28 @@ normal:
                g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
                break;
        }
+       case BT_IS_LE_EXTENDED_ADVERTISING_SUPPORTED: {
+               gboolean is_extended_advertising_supported = FALSE;
+
+               is_extended_advertising_supported = _bt_is_le_extended_advertising_supported();
+               g_array_append_vals(*out_param1, &is_extended_advertising_supported,
+                       sizeof(gboolean));
+               break;
+       }
+       case BT_IS_LE_EXTENDED_SCAN_SUPPORTED: {
+               gboolean is_extended_scan_supported = FALSE;
+
+               is_extended_scan_supported = _bt_is_le_extended_scan_supported();
+               g_array_append_vals(*out_param1, &is_extended_scan_supported, sizeof(gboolean));
+               break;
+       }
+       case BT_LE_MAX_ADVERTISING_DATA_LEN: {
+               gint max_advertising_len = 0;
+
+               max_advertising_len = _bt_le_get_maximum_advertising_len();
+               g_array_append_vals(*out_param1, &max_advertising_len, sizeof(gint));
+               break;
+       }
        case BT_DISCONNECT_DEVICE: {
                bluetooth_device_address_t address = { {0} };
 
@@ -3402,6 +3503,24 @@ normal:
                result = _bt_disconnect_device(&address);
                break;
        }
+       case BT_SET_SCANNING_PHY: {
+               int phy = 0;
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+               __bt_service_get_parameters(in_param1, &phy, sizeof(int));
+
+               result = _bt_set_scan_phy(sender, phy);
+
+               break;
+       }
+       case BT_SET_SCANNING_ROLE: {
+               int role = 0;
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+               __bt_service_get_parameters(in_param1, &role, sizeof(int));
+
+               result = _bt_set_scan_role(sender, role);
+
+               break;
+       }
        case BT_REGISTER_SCAN_FILTER: {
                bluetooth_le_scan_filter_t scan_filter;
 
@@ -4447,6 +4566,7 @@ normal:
                        conn_info.device_role = L2CAP_LE_ROLE_CLIENT;
                        conn_info.socket_fd = -1;
                        conn_info.psm = psm;
+                       memcpy(&conn_info.device_addr, &address, sizeof(bluetooth_device_address_t));
                        g_array_append_vals(*out_param1, &conn_info,
                                        sizeof(bluetooth_l2cap_le_connection_t));
                } else {
@@ -4498,6 +4618,7 @@ normal:
                socket_fd = _bt_l2cap_le_socket_listen(psm, true);
                if (socket_fd > 0) {
                        result = BLUETOOTH_ERROR_NONE;
+                       sender = (char *)g_dbus_method_invocation_get_sender(context);
                        _bt_save_invocation_context(context,
                                        result, sender, function_name, NULL);
                } else {
@@ -4514,6 +4635,7 @@ normal:
                socket_fd = _bt_l2cap_le_socket_listen(psm, false);
                if (socket_fd > 0) {
                        result = BLUETOOTH_ERROR_NONE;
+                       sender = (char *)g_dbus_method_invocation_get_sender(context);
                        _bt_save_invocation_context(context, result,
                                        sender, function_name, NULL);
                } else {
@@ -5157,6 +5279,8 @@ static void __bt_service_cleanup_nspid_list(const char *unique_name)
        GSList *l;
        struct nspid_t *nspid;
 
+       ret_if(unique_name == NULL);
+
        for (l = nspid_list; l; l = g_slist_next(l)) {
                nspid = l->data;
                if (!nspid)
@@ -5345,7 +5469,7 @@ gboolean __bt_service_check_privilege(int function_name,
                return FALSE;
        }
 
-       BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
+       BT_INFO("%s, %s, %s", unique_name, client_creds, user_creds);
 
        switch (function_name) {
        case BT_SET_LOCAL_NAME:
@@ -5456,22 +5580,22 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_DPM_GET_DEVICE_RESTRITION:
        case BT_DPM_SET_UUID_RESTRITION:
        case BT_DPM_GET_UUID_RESTRITION:
-       case BT_DPM_ADD_DEVICES_BLACKLIST:
-       case BT_DPM_ADD_DEVICES_WHITELIST:
-       case BT_DPM_ADD_UUIDS_BLACKLIST:
-       case BT_DPM_ADD_UUIDS_WHITELIST:
-       case BT_DPM_CLEAR_DEVICES_BLACKLIST:
-       case BT_DPM_CLEAR_DEVICES_WHITELIST:
-       case BT_DPM_CLEAR_UUIDS_BLACKLIST:
-       case BT_DPM_CLEAR_UUIDS_WHITELIST:
-       case BT_DPM_REMOVE_DEVICE_BLACKLIST:
-       case BT_DPM_REMOVE_DEVICE_WHITELIST:
-       case BT_DPM_REMOVE_UUID_BLACKLIST:
-       case BT_DPM_REMOVE_UUID_WHITELIST:
-       case BT_DPM_GET_DEVICES_BLACKLIST:
-       case BT_DPM_GET_DEVICES_WHITELIST:
-       case BT_DPM_GET_UUIDS_BLACKLIST:
-       case BT_DPM_GET_UUIDS_WHITELIST:
+       case BT_DPM_ADD_DEVICES_BLOCKLIST:
+       case BT_DPM_ADD_DEVICES_ALLOWLIST:
+       case BT_DPM_ADD_UUIDS_BLOCKLIST:
+       case BT_DPM_ADD_UUIDS_ALLOWLIST:
+       case BT_DPM_CLEAR_DEVICES_BLOCKLIST:
+       case BT_DPM_CLEAR_DEVICES_ALLOWLIST:
+       case BT_DPM_CLEAR_UUIDS_BLOCKLIST:
+       case BT_DPM_CLEAR_UUIDS_ALLOWLIST:
+       case BT_DPM_REMOVE_DEVICE_BLOCKLIST:
+       case BT_DPM_REMOVE_DEVICE_ALLOWLIST:
+       case BT_DPM_REMOVE_UUID_BLOCKLIST:
+       case BT_DPM_REMOVE_UUID_ALLOWLIST:
+       case BT_DPM_GET_DEVICES_BLOCKLIST:
+       case BT_DPM_GET_DEVICES_ALLOWLIST:
+       case BT_DPM_GET_UUIDS_BLOCKLIST:
+       case BT_DPM_GET_UUIDS_ALLOWLIST:
        case BT_DPM_SET_ALLOW_OUTGOING_CALL:
        case BT_DPM_GET_ALLOW_OUTGOING_CALL:
        case BT_DPM_SET_PAIRING_STATE:
@@ -5519,6 +5643,8 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_GATT_SERVER_START_SERVICE:
        case BT_GATT_SERVER_STOP_SERVICE:
        case BT_GATT_SERVER_DELETE_SERVICE:
+       case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE:
+       case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE:
        case BT_GATT_SERVER_SEND_RESPONSE:
        case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
        case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
@@ -5526,6 +5652,10 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_GATT_SERVER_UPDATE_VALUE:
        case BT_GATT_SERVER_DEREGISTER:
 #endif
+       case BT_GATT_SERVER_READ_PHY:
+       case BT_GATT_SERVER_SET_PHY:
+       case BT_GATT_CLIENT_READ_PHY:
+       case BT_GATT_CLIENT_SET_PHY:
        case BT_REQ_ATT_MTU:
        case BT_PBAP_CONNECT:
        case BT_PBAP_DISCONNECT:
@@ -5579,9 +5709,9 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_DISABLE_ADAPTER_LE:
        case BT_SET_CONNECTABLE:
        case BT_SET_DISCOVERABLE_MODE:
-       case BT_ADD_WHITE_LIST:
-       case BT_REMOVE_WHITE_LIST:
-       case BT_CLEAR_WHITE_LIST:
+       case BT_ADD_ALLOW_LIST:
+       case BT_REMOVE_ALLOW_LIST:
+       case BT_CLEAR_ALLOW_LIST:
        case BT_SET_MANUFACTURER_DATA:
 
        case BT_CANCEL_SEARCH_SERVICE:
@@ -5741,6 +5871,11 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_IS_ADVERTISING:
        case BT_IS_LE_2M_PHY_SUPPORTED:
        case BT_IS_LE_CODED_PHY_SUPPORTED:
+       case BT_SET_SCANNING_ROLE:
+       case BT_SET_SCANNING_PHY:
+       case BT_IS_LE_EXTENDED_ADVERTISING_SUPPORTED:
+       case BT_IS_LE_EXTENDED_SCAN_SUPPORTED:
+       case BT_LE_MAX_ADVERTISING_DATA_LEN:
        case BT_REGISTER_SCAN_FILTER:
        case BT_IS_SCAN_FILTER_SUPPORTED:
        case BT_GET_ATT_MTU:
@@ -5847,7 +5982,7 @@ static void __name_owner_changed(GDBusConnection *connection,
        const char *new_owner = NULL;
 
        g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
-       if (*new_owner != '\0')
+       if (new_owner && *new_owner != '\0')
                return;
 
        _bt_check_hdp_app_termination(name);