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)
{
.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,
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;
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);