Implement get_att_mtu logic in hal gatt client 92/235592/1
authorWootak Jung <wootak.jung@samsung.com>
Mon, 8 Jun 2020 02:44:32 +0000 (11:44 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Mon, 8 Jun 2020 02:44:32 +0000 (11:44 +0900)
Change-Id: I8013154244497fe471fc6ce6ba63b2495c7b16d4
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-oal/bluez_hal/src/bt-hal-gatt-client.c
bt-oal/hardware/bt_gatt_client.h
bt-oal/include/oal-gatt.h
bt-oal/oal-gatt.c
bt-service-adaptation/services/gatt/bt-service-gatt.c

index 6c7835f..823812e 100644 (file)
@@ -2771,6 +2771,92 @@ static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
        g_free(conn_mtu);
 }
 
+static bt_status_t get_att_mtu(int conn_id, int *mtu_size)
+{
+       CHECK_BTGATT_INIT();
+       GDBusProxy *device_proxy;
+       gchar *device_path = NULL;
+       GError *error = NULL;
+       GVariant *value;
+       GVariant *tmp_value;
+       GDBusConnection *conn;
+       GVariant *result = NULL;
+       int ret = BT_STATUS_SUCCESS;
+       char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+       hal_gattc_client_info_t *gattc_client = NULL;
+       unsigned int mtu;
+
+       if (mtu_size == NULL)
+               return BT_STATUS_PARM_INVALID;
+
+       conn = _bt_hal_get_system_gconn();
+       if (conn == NULL) {
+               ERR("conn NULL");
+               return BT_STATUS_FAIL;
+       }
+
+       gattc_client = __bt_find_gatt_client_info_from_conn_id(conn_id);
+       if (gattc_client == NULL) {
+               INFO("GATT client conn info not found");
+               return BT_STATUS_FAIL;
+       }
+
+       _bt_hal_convert_addr_type_to_string(device_address,
+                               (unsigned char *)gattc_client->bd_addr.address);
+
+       device_path = _bt_hal_get_device_object_path(device_address);
+       if (device_path == NULL) {
+               ERR("device_path NULL : [%s]", device_address);
+               return BT_STATUS_FAIL;
+       }
+
+       device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_HAL_BLUEZ_NAME,
+                       device_path, BT_HAL_PROPERTIES_INTERFACE,  NULL, NULL);
+
+       g_free(device_path);
+       if (NULL == device_proxy) {
+               ERR("device_proxy returned NULL");
+               return BT_STATUS_FAIL;
+       }
+
+       result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
+                       g_variant_new("(s)", BT_HAL_DEVICE_INTERFACE),
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       &error);
+       if (result == NULL) {
+               if (error != NULL) {
+                       ERR("Error occured in Proxy call [%s]\n", error->message);
+                       g_error_free(error);
+               }
+               g_object_unref(device_proxy);
+               return BT_STATUS_FAIL;
+       }
+
+       g_variant_get(result , "(@a{sv})", &value);
+       g_variant_unref(result);
+
+       tmp_value = g_variant_lookup_value(value, "AttMtu", G_VARIANT_TYPE_UINT16);
+       if (tmp_value == NULL) {
+               g_object_unref(device_proxy);
+               g_variant_unref(value);
+               return BT_STATUS_FAIL;
+       }
+
+       mtu = g_variant_get_uint16(tmp_value);
+
+       DBG("ATT MTU : [%d]", mtu);
+
+       g_variant_unref(tmp_value);
+       g_variant_unref(value);
+       g_object_unref(device_proxy);
+
+       *mtu_size = (int) mtu;
+
+       return ret;
+}
 
 static bt_status_t __hal_configure_mtu(int conn_id, int mtu)
 {
@@ -3455,6 +3541,7 @@ const btgatt_client_interface_t btgatt_client_interface = {
        .get_device_type = get_device_type,
        .conn_parameter_update = btif_gattc_conn_parameter_update,
        .test_command = test_command,
+       .get_att_mtu = get_att_mtu,
        .configure_mtu = configure_mtu,
        .scan_filter_param_setup = scan_filter_param_setup,
        .scan_filter_add_remove = scan_filter_add_remove,
index e9f2983..e1ba5b9 100644 (file)
@@ -340,6 +340,9 @@ typedef struct {
        /** Test mode interface */
        bt_status_t (*test_command)(int command, btgatt_test_params_t* params);
 
+       /* Get current att mtu size of active connection */
+       bt_status_t (*get_att_mtu)(int conn_id, int *mtu_size);
+
        /** MTU Exchange request from client */
        bt_status_t (*configure_mtu)(int conn_id, int mtu);
 
index ebdf246..4d06060 100644 (file)
@@ -523,6 +523,8 @@ oal_status_t gattc_deregister_for_notification(int conn_id, bt_address_t * addre
 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
                int status, int fd, int mtu, void *);
 
+oal_status_t gattc_get_att_mtu(int conn_id, int *mtu);
+
 oal_status_t gattc_configure_mtu(int conn_id, int mtu);
 
 oal_status_t gatt_get_data_batching_available_packets(
index e3a6547..4fd1513 100644 (file)
@@ -2429,6 +2429,30 @@ oal_status_t gattc_register_scan_filter(oal_ble_scan_filter_t* filter_data)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t gattc_get_att_mtu(int conn_id, int *mtu)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       API_TRACE("Get ATT MTU, conn_id: %d", conn_id);
+       CHECK_OAL_GATT_ENABLED();
+       CHECK_CLIENT_CONNECTION(conn_id);
+       OAL_CHECK_PARAMETER(mtu, return);
+
+       /* To prevent crash in case other libraries not support this api */
+       if (gatt_api->client->get_att_mtu == NULL) {
+               BT_WARN("get_att_mtu is NULL");
+               return OAL_STATUS_NOT_SUPPORT;
+       }
+
+       ret = gatt_api->client->get_att_mtu(conn_id, mtu);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("GATT MTU Size failed, status: %s", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       BT_INFO("Current ATT MTU Size: %d", *mtu);
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t gattc_configure_mtu(int conn_id, int mtu)
 {
        int ret;
index a3a0d78..06df298 100644 (file)
@@ -2607,10 +2607,18 @@ int _bt_get_att_mtu(bluetooth_device_address_t *address,
                return BLUETOOTH_ERROR_NOT_CONNECTED;
        }
 
-       ret = gatts_get_att_mtu(conn_info->connection_id, &stack_mtu);
-       if (ret != OAL_STATUS_SUCCESS) {
-               BT_ERR("ret: %d", ret);
-               return _bt_convert_oal_status_to_bt_error(ret);
+       if (conn_info->instance_id == -1) {
+               ret = gattc_get_att_mtu(conn_info->connection_id, &stack_mtu);
+               if (ret != OAL_STATUS_SUCCESS) {
+                       BT_ERR("ret: %d", ret);
+                       return _bt_convert_oal_status_to_bt_error(ret);
+               }
+       } else {
+               ret = gatts_get_att_mtu(conn_info->connection_id, &stack_mtu);
+               if (ret != OAL_STATUS_SUCCESS) {
+                       BT_ERR("ret: %d", ret);
+                       return _bt_convert_oal_status_to_bt_error(ret);
+               }
        }
 
        BT_INFO("ATT MTU received from OAL [%d]", stack_mtu);