+bt_status_t btif_gatt_get_data_batching_available_packets(unsigned int *available_packets)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+ guint32 available_pkts;
+
+ CHECK_BTGATT_INIT();
+
+ if (available_packets == NULL) {
+ ERR("available_packets is NULL");
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ proxy = _bt_hal_get_adapter_proxy();
+ if (proxy == NULL) {
+ ERR("proxy is NULL");
+ return BT_STATUS_FAIL;
+ }
+
+ ret = g_dbus_proxy_call_sync(proxy, "GetLeBatchingAvailablePkts",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (error) {
+ int result = BT_STATUS_FAIL;
+
+ ERR("SetLeBatchingParam Fail: %s", error->message);
+ if (g_strrstr(error->message, "Operation is not supported"))
+ result = BT_STATUS_UNSUPPORTED;
+
+ g_clear_error(&error);
+ return result;
+ }
+ g_variant_get(ret, "(u)", &available_pkts);
+ g_variant_unref(ret);
+
+ INFO("GATT Batching available packets: %u", available_pkts);
+ *available_packets = available_pkts;
+ return BT_STATUS_SUCCESS;
+}
+
+bt_status_t btif_gatt_enable_data_batching(const bt_bdaddr_t *bd_addr, int packet_threshold, int timeout)
+{
+ char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+ CHECK_BTGATT_INIT();
+
+ if (bd_addr == NULL) {
+ ERR("bd_addr is NULL");
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ proxy = _bt_hal_get_adapter_proxy();
+ if (proxy == NULL) {
+ ERR("proxy is NULL");
+ return BT_STATUS_FAIL;
+ }
+
+ _bt_hal_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->address);
+ ret = g_dbus_proxy_call_sync(proxy, "EnableLeBatching",
+ g_variant_new("(sii)", device_address, packet_threshold, timeout),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (error) {
+ int result = BT_STATUS_FAIL;
+
+ ERR("SetLeBatchingParam Fail: %s", error->message);
+ if (g_strrstr(error->message, "Operation is not supported"))
+ result = BT_STATUS_UNSUPPORTED;
+ else if (g_strrstr(error->message, "Invalid arguments"))
+ result = BT_STATUS_PARM_INVALID;
+
+ g_clear_error(&error);
+ return result;
+ }
+ g_variant_unref(ret);
+
+ INFO("GATT Batching is enabled");
+ return BT_STATUS_SUCCESS;
+}
+
+bt_status_t btif_gatt_disable_data_batching(const bt_bdaddr_t *bd_addr)
+{
+ char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+ CHECK_BTGATT_INIT();
+
+ if (bd_addr == NULL) {
+ ERR("bd_addr is NULL");
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ proxy = _bt_hal_get_adapter_proxy();
+ if (proxy == NULL) {
+ ERR("proxy is NULL");
+ return BT_STATUS_FAIL;
+ }
+
+ _bt_hal_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->address);
+ ret = g_dbus_proxy_call_sync(proxy, "DisableLeBatching",
+ g_variant_new("(s)", device_address),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (error) {
+ int result = BT_STATUS_FAIL;
+
+ ERR("SetLeBatching Fail: %s", error->message);
+ if (g_strrstr(error->message, "Operation is not supported"))
+ result = BT_STATUS_UNSUPPORTED;
+
+ g_clear_error(&error);
+ return result;
+ }
+ g_variant_unref(ret);
+
+ INFO("GATT Batching is disabled");
+ return BT_STATUS_SUCCESS;
+}
+