static int bt_conn_id = 0;
static int bt_inst_id = 0;
-#define BT_GATTC_CL_MAX 32
+/* Should match the range with bt-service-gatt.c's MAX_APPS_SUPPORTED */
+/* TODO: Adjust MAX Client after modifying MAX app handle logic */
+#define BT_GATTC_CL_MAX 11
+
+static int assigned_if = 0;
+static gboolean client_if_used[BT_GATTC_CL_MAX];
typedef struct {
int conn_id;
static GSList * hal_gattc_client_app_list = NULL;
-static int bt_client_if = 0;
-
struct conn_mtu_s {
int conn_id;
int mtu;
static hal_gattc_client_info_t *__bt_find_gatt_client_info(bt_bdaddr_t *serv_addr);
static hal_gattc_client_info_t *__bt_find_gatt_client_info_from_conn_id(int conn_id);
+void _bt_hal_gatt_client_init(void)
+{
+ assigned_if = 0;
+ memset(client_if_used, 0x00, sizeof(client_if_used));
+}
+
+static int __bt_hal_gatt_assign_if(void)
+{
+ int index;
+
+ index = assigned_if + 1;
+
+ if (index >= BT_GATTC_CL_MAX)
+ index = 1;
+
+ while (client_if_used[index] == TRUE) {
+ if (index == assigned_if) {
+ /* No available ID */
+ ERR("All interface ID is used");
+ return -1;
+ }
+
+ index++;
+
+ if (index >= BT_GATTC_CL_MAX)
+ index = 1;
+ }
+
+ assigned_if = index;
+ client_if_used[index] = TRUE;
+
+ return assigned_if;
+}
+
+static void __bt_hal_gatt_delete_if(int client_if)
+{
+ if (client_if >= BT_GATTC_CL_MAX || client_if < 0)
+ return;
+
+ client_if_used[client_if] = FALSE;
+}
+
/* To send stack event to hal-av handler */
void _bt_hal_register_gatt_client_handler_cb(handle_stack_msg cb)
return FALSE;
}
-static int __hal_generate_client_id()
-{
- return ++bt_client_if;
-}
-
static hal_gatt_client_app *__hal_gattc_add_client_app(bt_uuid_t *app_uuid)
{
GSList *l;
+ int client_if = 0;
hal_gatt_client_app *info = NULL;
hal_gatt_client_app *gattc_app = NULL;
}
}
+ client_if = __bt_hal_gatt_assign_if();
+ if (client_if == -1) {
+ ERR("Fail to allocate the client if");
+ return NULL;
+ }
+
DBG("adding the gatt client app");
//add client app
gattc_app = g_malloc0(sizeof(hal_gatt_client_app));
- gattc_app->client_if = __hal_generate_client_id();
+ gattc_app->client_if = client_if;
memcpy(&gattc_app->app_uuid, app_uuid, sizeof(bt_uuid_t));
hal_gattc_client_app_list = g_slist_append(hal_gattc_client_app_list, gattc_app);
if (info->client_if == client_if) {
DBG("gatt client app found");
+
+ __bt_hal_gatt_delete_if(client_if);
+
hal_gattc_client_app_list = g_slist_remove(hal_gattc_client_app_list, info);
g_free(info);
}
_bt_hal_convert_uuid_string_to_type(gattc_service->svc_uuid.uu, uuid_str);
gattc_service->is_primary = is_primary;
- INFO("[%d] [%s] [%s]", g_slist_length(conn_info->gatt_list_services), object_path + 15, uuid_str);
-
conn_info->gatt_list_services = g_slist_append(conn_info->gatt_list_services, gattc_service);
+ INFO("Toatal svc [%d] Added [%s] [%s]", g_slist_length(conn_info->gatt_list_services), object_path + 15, uuid_str);
return gattc_service;
}
char_permission |= _hal_get_permission_flag(permission);
}
__hal_convert_permission_flag_to_str(char_permission);
+ g_variant_iter_free(char_perm_iter);
} else if (!g_strcmp0(key, "Descriptors")) {
g_variant_get(value, "ao", &char_desc_iter);
while (g_variant_iter_loop(char_desc_iter, "&o", &char_desc_handle)) {
g_ptr_array_add(gp_desc_array, (gpointer)char_desc_handle);
}
+ g_variant_iter_free(char_desc_iter);
}
}
if (!g_strcmp0(key, "UUID")) {
desc_uuid_str = g_variant_get_string(value, &len);
_hal_gattc_update_desc_property(gattc_desc, desc_uuid_str);
+
+ g_free((gchar *)key);
+ g_variant_unref(value);
break;
}
}
conn = _bt_hal_get_system_gconn();
if (conn == NULL) {
ERR("conn NULL");
+ g_free(conn_mtu);
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");
+ g_free(conn_mtu);
return BT_STATUS_FAIL;
}
device_path = _bt_hal_get_device_object_path(device_address);
if (device_path == NULL) {
ERR("device_path NULL : [%s]", device_address);
+ g_free(conn_mtu);
return BT_STATUS_FAIL;
}
g_free(device_path);
if (NULL == device_proxy) {
ERR("device_proxy returned NULL");
+ g_free(conn_mtu);
return BT_STATUS_FAIL;
}
int ret = BT_STATUS_SUCCESS;
hal_gattc_client_info_t *gattc_data;
- DBG("+");
-
if (NULL == bd_addr) {
ERR("bd_addr is NULL");
return BT_STATUS_PARM_INVALID;
ret = BT_STATUS_FAIL;
return ret;
}
- ERR("device_path:%s", device_path);
device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_HAL_BLUEZ_NAME,
memcpy(gattc_data->bd_addr.address, bd_addr->address,
BT_HAL_ADDRESS_LENGTH_MAX);
- DBG("Connect LE [%s]", device_address);
+ DBG("ConnectLE [%s]", device_address);
gattc_data->client_if = client_if;
struct hal_ev_gatt_client_connected ev;
hal_gattc_server_info_t *gatt_conn_info = NULL;
- DBG("+");
-
reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
g_object_unref(proxy);
if (reply == NULL) {
g_variant_unref(reply);
if (NULL == gattc_data) {
- ERR("server_data is NULL");
+ ERR("gattc_data is NULL");
return;
}
goto fail;
}
- DBG("adding the server conn info in list");
+ DBG("LE connected. Adding the gattc server/client conn info in list");
gattc_data->conn_id = __hal_generate_conn_id() ;
gattc_data->inst_id = __hal_generate_server_instance_id();
gatt_conn_info->inst_id = gattc_data->inst_id;
hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, gatt_conn_info);
- DBG("-");
return;
fail:
if (!event_cb) {
ERR("gatt client callback not registered");
} else {
- DBG("sending gatt client connected status event");
event_cb(event, (void *)&ev, sizeof(ev));
}
while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
if (g_strcmp0(key, "UUID") == 0) {
uuid_str = g_variant_get_string(value, &len);
- DBG("UUID: %s", uuid_str);
} else if (g_strcmp0(key, "Primary") == 0) {
is_primary = g_variant_get_boolean(value);
- DBG("is_primary: %s", is_primary ? "TRUE" : "FALSE");
} else if (g_strcmp0(key, "Characteristics") == 0) {
g_variant_get(value, "ao", &char_iter);
if (char_iter != NULL) {
DBG("char_handle: %s", char_handle);
g_ptr_array_add(gp_char_array, (gpointer)char_handle);
}
+ g_variant_iter_free(char_iter);
}
}
}
g_variant_iter_free(property_iter);
g_variant_unref(result);
g_object_unref(properties_proxy);
- DBG("-");
+
return BT_STATUS_SUCCESS;
}