typedef struct {
bt_bdaddr_t bd_addr; /*remote server address*/
+ int conn_id;
int inst_id; /*server instance id*/
GSList *gatt_list_services;
} hal_gattc_server_info_t;
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)
struct hal_ev_gatt_client_registered ev;
hal_gatt_client_app *client_info = user_data;
- DBG("+");
/* Prepare to send AV connecting event */
memset(&ev, 0, sizeof(ev));
ev.status = BT_STATUS_SUCCESS;
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);
hal_gatt_client_app *gattc_app = NULL;
hal_gatt_client_app *client_app_info = NULL;
- DBG("+");
/* add gatt client in list */
gattc_app = __hal_gattc_add_client_app(app_uuid);
if (gattc_app == NULL) {
bt_status_t btif_gattc_register_client(bt_uuid_t *uuid)
{
CHECK_BTGATT_INIT();
- DBG("+");
return __hal_gattc_register_client_app(uuid);
}
client_info->conn_id = conn_id;
client_info->inst_id = server_inst_id;
hal_gattc_client_info_list = g_slist_append(hal_gattc_client_info_list, client_info);
+ DBG("Added client connection info in list");
/* Add server connection info in list */
- server_info = g_malloc0(sizeof(hal_gattc_server_info_t));
- memcpy(server_info->bd_addr.address, bd_addr->address, BT_HAL_ADDRESS_LENGTH_MAX);
- server_info->inst_id = server_inst_id;
- hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, server_info);
+ server_info = __bt_find_gatt_conn_info(bd_addr);
+ if (server_info == NULL) {
+ server_info = g_malloc0(sizeof(hal_gattc_server_info_t));
+ memcpy(server_info->bd_addr.address, bd_addr->address, BT_HAL_ADDRESS_LENGTH_MAX);
+ server_info->conn_id = conn_id;
+ server_info->inst_id = server_inst_id;
+ hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, server_info);
+ DBG("Added server connection info in list");
+ }
- DBG("Added client/server connection info in list");
return BT_STATUS_SUCCESS;
}
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_status_t btif_gattc_unregister_client(int client_if)
{
CHECK_BTGATT_INIT();
- DBG("+");
return __hal_gattc_unregister_client(client_if);
}
int ret = BT_STATUS_SUCCESS;
CHECK_BTGATT_INIT();
- DBG("+");
if (NULL == bd_addr)
return BT_STATUS_PARM_INVALID;
{
CHECK_BTGATT_INIT();
- DBG("+");
-
return _hal_gattc_disconnect(client_if, bd_addr, conn_id);
}
static hal_gattc_service_t* _gattc_find_service_from_uuid(hal_gattc_server_info_t *conn_info, bt_uuid_t *svc_uuid)
{
- DBG("+");
-
GSList *l;
hal_gattc_service_t *info = NULL;
if (info == NULL)
continue;
- if (!memcmp(&info->svc_uuid, svc_uuid, sizeof(bt_uuid_t))) {
- INFO("Found GATT service uuid");
+ if (!memcmp(&info->svc_uuid, svc_uuid, sizeof(bt_uuid_t)))
return info;
}
- }
+
return NULL;
}
static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_svc, bt_uuid_t *char_uuid,
bt_gatt_characteristic_property_t prop)
{
- DBG("+");
-
GSList *l;
hal_gattc_char_t *info = NULL;
if (!memcmp(&info->chr_uuid, char_uuid, sizeof(bt_uuid_t)) &&
(info->permission & prop)) {
- INFO("Found GATT char uuid");
return info;
}
}
static hal_gattc_char_t* _gattc_find_char_from_uuid_for_notify(hal_gattc_service_t *gattc_svc, bt_uuid_t *char_uuid)
{
- DBG("+");
-
GSList *l;
hal_gattc_char_t *info = NULL;
if (!memcmp(&info->chr_uuid, char_uuid, sizeof(bt_uuid_t)) &&
((info->permission & HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY) ||
(info->permission & HAL_GATT_CHARACTERISTIC_PROPERTY_INDICATE))) {
- INFO("Found GATT char uuid");
return info;
}
}
static hal_gattc_desc_t* _gattc_find_desc_from_uuid(hal_gattc_char_t *gattc_char, bt_uuid_t *desc_uuid)
{
- DBG("+");
-
GSList *l;
hal_gattc_desc_t *info = NULL;
if (info == NULL)
continue;
- if (!memcmp(&info->desc_uuid, desc_uuid, sizeof(bt_uuid_t))) {
- INFO("Found GATT descriptor uuid");
+ if (!memcmp(&info->desc_uuid, desc_uuid, sizeof(bt_uuid_t)))
return info;
}
- }
return NULL;
}
static hal_gattc_service_t* _hal_gatt_client_add_service(hal_gattc_server_info_t *conn_info,
const char *uuid_str, const char *object_path, int is_primary)
{
- DBG("+");
hal_gattc_service_t *gattc_service = NULL;
gattc_service = g_malloc0(sizeof(hal_gattc_service_t));
_bt_hal_convert_uuid_string_to_type(gattc_service->svc_uuid.uu, uuid_str);
gattc_service->is_primary = is_primary;
- DBG("service count[%d]", g_slist_length(conn_info->gatt_list_services));
+ 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);
- DBG("svc path [%s] svc uuid [%s]", object_path, uuid_str);
-
return gattc_service;
}
static void _hal_gattc_add_characteristic(hal_gattc_service_t *gatt_svc, char *char_handle)
{
- DBG("+");
hal_gattc_char_t *gattc_char = NULL;
gattc_char = g_malloc0(sizeof(hal_gattc_char_t));
int i;
gchar *gp_char_path = NULL;
- DBG("+");
-
/* add the service */
gatt_svc = _hal_gatt_client_add_service(conn_info, uuid_str, object_path, is_primary);
if (gatt_svc == NULL) {
gattc_desc->desc_path = g_strdup(desc_path);
gattc_char->gatt_list_descs = g_slist_append(gattc_char->gatt_list_descs, gattc_desc);
-
- DBG("char path: [%s]", gattc_char->chr_path);
- DBG("desc path: [%s]", gattc_desc->desc_path);
}
static void _hal_gattc_update_char_property(hal_gattc_char_t *gattc_char, const char* char_uuid_str,
gchar *gp_desc_path = NULL;
int i;
- DBG("+");
-
if (char_uuid_str == NULL) {
DBG("char_uuid_str is NULL");
return;
}
//update the char uuid
- DBG("char UUID: [%s] ", char_uuid_str);
- DBG("char path: [%s]", gattc_char->chr_path);
-
_bt_hal_convert_uuid_string_to_type(gattc_char->chr_uuid.uu, char_uuid_str);
//update char permission
static void _hal_gattc_update_desc_property(hal_gattc_desc_t *gattc_desc, const char* desc_uuid_str)
{
- DBG("+");
-
if (desc_uuid_str == NULL) {
DBG("char_uuid_str is NULL");
return;
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (conn_info == NULL) {
- ERR("conn_info is NULL");
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return;
}
- DBG("service count[%d]", g_slist_length(conn_info->gatt_list_services));
-
for (l = conn_info->gatt_list_services; l != NULL; l = g_slist_next(l)) {
svc_info = (hal_gattc_service_t*)l->data;
if (svc_info == NULL)
continue;
- DBG("[%s]", svc_info->svc_path);
-
/* find characteristic object path */
for (k = svc_info->gatt_list_chars; k != NULL; k = g_slist_next(k)) {
char_info = (hal_gattc_char_t *)k->data;
if (char_info == NULL)
continue;
- DBG("[%s]", char_info->chr_path);
-
/* descriptor */
for (m = char_info->gatt_list_descs; m != NULL; m = g_slist_next(m)) {
desc_info = (hal_gattc_desc_t *)m->data;
if (desc_info == NULL)
continue;
-
- DBG("[%s]", desc_info->desc_path);
}
}
}
GVariantIter *char_iter = NULL;
GPtrArray *gp_char_array = NULL;
- DBG("+");
-
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info");
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
+#if 0
+ // TODO: This logic is not able to handle in case service-added event is coming unexpectedly.
+ /* Check the service info is stored */
+ if (g_slist_length(conn_info->gatt_list_services) > 0) {
+ GSList *l = NULL;
+ hal_gattc_service_t *svc_info = NULL;
+ char svc_uuid_str[BT_HAL_UUID_STRING_LEN] = {0, };
+ DBG("Send event from service info list");
+ for (l = conn_info->gatt_list_services; l != NULL; l = g_slist_next(l)) {
+ svc_info = l->data;
+ if (svc_info == NULL)
+ continue;
+ _bt_hal_convert_uuid_type_to_string(svc_uuid_str, svc_info->svc_uuid.uu);
+ _bt_hal_send_search_service_result_event(conn_id,
+ svc_info->is_primary, svc_uuid_str, conn_info->inst_id);
+ }
+ _bt_hal_send_search_service_complete_event(conn_id, BT_STATUS_SUCCESS);
+ return BT_STATUS_SUCCESS;
+ } else {
+ DBG("No stored service, request to bluez");
+ }
+#endif
+
_bt_hal_convert_addr_type_to_string(device_address,
(unsigned char *)conn_info->bd_addr.address);
while (g_variant_iter_loop(svc_iter, "{sv}", &key, &value)) {
if (g_strcmp0(key, "Primary") == 0) {
is_primary = g_variant_get_boolean(value);
- DBG("primary");
if (is_primary) {
g_ptr_array_add(gp_array, (gpointer)object_path);
svc_count++;
}
} else if (g_strcmp0(key, "UUID") == 0) {
uuid_str = g_variant_get_string(value, &len);
- DBG(" UUID: [%s]", uuid_str);
} else if (g_strcmp0(key, "Characteristics") == 0) {
g_variant_get(value, "ao", &char_iter);
if (char_iter != NULL) {
while (g_variant_iter_loop(char_iter, "&o", &char_handle)) {
- DBG("char handle : %s", char_handle);
g_ptr_array_add(gp_char_array, (gpointer)char_handle);
}
}
}
if (uuid_str) {
- DBG("send search service result event");
_bt_hal_send_search_service_result_event(conn_id, is_primary,
uuid_str, conn_info->inst_id);
return;
}
- DBG("sending gatt client search char result event conn_id[%d] status[%d]", conn_id, status);
-
memset(&ev, 0, sizeof(ev));
ev.conn_id = conn_id;
ev.inst_id = svc_id->id.inst_id;
memcpy(ev.svc_uuid, svc_id->id.uuid.uu, sizeof(ev.svc_uuid));
if (status == BT_STATUS_SUCCESS) {
- DBG("building char uuid");
+ /* building char uuid */
memcpy(ev.char_uuid, char_uuid->uu, sizeof(ev.char_uuid));
ev.char_prop = char_prop;
}
- DBG("sending the char search event");
-
+ DBG("sending the char search event. conn_id[%d] status[%d]", conn_id, status);
event_cb(HAL_EV_GATT_CLIENT_CHARAC_SEARCH_RESULT, (void *)&ev, sizeof(ev));
}
return ret;
}
+static void __hal_convert_permission_flag_to_str(unsigned int permission)
+{
+ char perm[200] = { 0, };
+
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_BROADCAST)
+ g_strlcat(perm, "broadcast ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_READ)
+ g_strlcat(perm, "read ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE_NO_RESPONSE)
+ g_strlcat(perm, "write-without-response ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE)
+ g_strlcat(perm, "write ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY)
+ g_strlcat(perm, "notify ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_INDICATE)
+ g_strlcat(perm, "indicate ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_SIGNED_WRITE)
+ g_strlcat(perm, "authenticated-signed-writes ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_RELIABLE_WRITE)
+ g_strlcat(perm, "reliable-write ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_WRITABLE_AUXILIARIES)
+ g_strlcat(perm, "writable-auxiliaries ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_READ)
+ g_strlcat(perm, "encrypt-read ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_WRITE)
+ g_strlcat(perm, "encrypt-write ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_READ)
+ g_strlcat(perm, "encrypt-authenticated-read ", sizeof(perm));
+ if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_WRITE)
+ g_strlcat(perm, "encrypt-authenticated-write ", sizeof(perm));
+
+ DBG("permission [0x%04x] : %s\n", permission, perm);
+ return;
+}
static bt_status_t _hal_gattc_get_characteristic_info(hal_gattc_char_t *gattc_char)
{
}
char_handle = gattc_char->chr_path;
- DBG("char path:[%s]", gattc_char->chr_path);
-
g_conn = _bt_hal_get_system_gconn();
if (NULL == g_conn) {
ERR("_bt_gdbus_get_system_gconn returned NULL");
while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
if (!g_strcmp0(key, "UUID")) {
char_uuid_str = g_variant_dup_string(value, &len);
- DBG("char UUID [%s]", char_uuid_str);
+ INFO("%s [%s]", char_handle + 37, char_uuid_str);
} else if (!g_strcmp0(key, "Flags")) {
g_variant_get(value, "as", &char_perm_iter);
char_permission = 0x00;
while (g_variant_iter_loop(char_perm_iter, "s", &permission)) {
- DBG("char permission: [%s]", permission);
char_permission |= _hal_get_permission_flag(permission);
}
+ __hal_convert_permission_flag_to_str(char_permission);
} 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)) {
- DBG("char descriptor : %s", char_desc_handle);
-
g_ptr_array_add(gp_desc_array, (gpointer)char_desc_handle);
}
}
char svc_uuid_str[BT_HAL_UUID_STRING_LEN];
int status = BT_STATUS_FAIL;
- DBG("conn_id[%d]", conn_id);
-
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
/* send event */
if (BT_STATUS_SUCCESS == status) {
- DBG("Sending the success charateristics event");
_bt_hal_send_client_char_search_result_event(conn_id, status, srvc_id,
&gattc_char->chr_uuid, gattc_char->permission);
}
}
- DBG("sending final event");
-
status = BT_STATUS_FAIL;
_bt_hal_send_client_char_search_result_event(conn_id, status, srvc_id, NULL, 0);
bt_status_t btif_gattc_get_characteristic(int conn_id,
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id)
{
- DBG("+");
CHECK_BTGATT_INIT();
if (start_char_id == NULL) {
char* desc_handle = NULL;
const gchar *desc_uuid_str = NULL;
- DBG("+");
-
if (gattc_desc->desc_path == NULL) {
DBG("desc path is NULL");
return BT_STATUS_FAIL;
}
desc_handle = gattc_desc->desc_path;
- DBG("desc path:[%s]", gattc_desc->desc_path);
-
g_conn = _bt_hal_get_system_gconn();
if (NULL == g_conn) {
ERR("_bt_gdbus_get_system_gconn returned NULL");
while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
if (!g_strcmp0(key, "UUID")) {
desc_uuid_str = g_variant_get_string(value, &len);
- DBG("desc UUID [%s]", desc_uuid_str);
_hal_gattc_update_desc_property(gattc_desc, desc_uuid_str);
break;
}
return;
}
- DBG("sending gatt client search desc result event conn_id[%d] status[%d]", conn_id, status);
-
memset(&ev, 0, sizeof(ev));
ev.conn_id = conn_id;
ev.inst_id = svc_id->id.inst_id;
memcpy(ev.char_uuid, char_id->uuid.uu, sizeof(ev.char_uuid));
if (status == BT_STATUS_SUCCESS) {
- DBG("building desc uuid");
+ /* building desc uuid */
memcpy(ev.desc_uuid, desc_uuid->uu, sizeof(ev.desc_uuid));
}
- DBG("sending the desc search event");
+ DBG("sending the desc search event. conn_id[%d] status[%d]", conn_id, status);
event_cb(HAL_EV_GATT_CLIENT_DESC_SEARCH_RESULT, (void *)&ev, sizeof(ev));
}
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
/* send event */
if (BT_STATUS_SUCCESS == status) {
- DBG("Sending the success descriptor event");
_bt_hal_send_client_desc_search_result_event(conn_id, status, srvc_id,
char_id, &gattc_desc->desc_uuid);
}
}
}
- DBG("sending final event");
-
status = BT_STATUS_FAIL;
_bt_hal_send_client_desc_search_result_event(conn_id, status, srvc_id, char_id, NULL);
btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
btgatt_gatt_id_t *start_descr_id)
{
- DBG("+");
CHECK_BTGATT_INIT();
if (start_descr_id == NULL) {
- DBG("Get all the descriptors");
return _hal_gattc_get_all_descriptor(conn_id, srvc_id, char_id);
} else {
DBG("TBD Get specific descriptor");
return;
}
- DBG("sending gatt client charac read conn_id[%d] status[%d]", resp_data->conn_id, result);
-
memset(&ev, 0, sizeof(ev));
ev.conn_id = resp_data->conn_id;
ev.inst_id = resp_data->srvc_id.id.inst_id;
ev.len = len;
if (len > 0) {
- DBG("building the char read value [%d]", len);
+ /* building the char read value */
memcpy(ev.value, value, len);
}
- DBG("sending the gatt client read charac event");
+ DBG("sending gatt client charac read event. conn_id[%d] status[%d]", resp_data->conn_id, result);
event_cb(HAL_EV_GATT_CLIENT_READ_CHARAC, (void *)&ev, sizeof(ev));
}
hal_gatt_resp_data_t *resp_data = user_data;
int result = BT_STATUS_SUCCESS;
- DBG("+");
-
system_gconn = _bt_hal_get_system_gconn();
value = g_dbus_connection_call_finish(system_gconn, res, &error);
while (g_variant_iter_loop(iter, "y", &g_byte))
g_byte_array_append(gp_byte_array, &g_byte, 1);
-/*
- DBG("value is");
- for (i = 0; i < gp_byte_array->len; i++)
- DBG("%02x", gp_byte_array->data[i]);
-*/
//send value event
__hal_send_char_read_event(resp_data, result, gp_byte_array->data, gp_byte_array->len);
g_variant_iter_free(iter);
g_variant_unref(value);
- DBG("-");
}
-
static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t *srvc_id,
btgatt_gatt_id_t *char_id, int auth_req)
{
/* get the connection info */
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
}
_bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu);
- DBG("%s %s", gattc_service->svc_path + 37, svc_uuid_str);
/* find characteristic */
gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid,
char_handle = gattc_char->chr_path;
- DBG("calling char read value");
-
g_dbus_connection_call(g_conn, BT_HAL_BLUEZ_NAME, char_handle, BT_HAL_GATT_CHAR_INTERFACE,
"ReadValue", g_variant_new("(a{sv})", builder),
G_VARIANT_TYPE("(ay)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL,
int auth_req)
{
CHECK_BTGATT_INIT();
- DBG("+");
return _hal_read_characteristic_value(conn_id, srvc_id, char_id, auth_req);
}
return;
}
- DBG("sending gatt client charac write conn_id[%d] status[%d]", resp_data->conn_id, result);
-
memset(&ev, 0, sizeof(ev));
ev.conn_id = resp_data->conn_id;
ev.inst_id = resp_data->srvc_id.id.inst_id;
memcpy(ev.svc_uuid, resp_data->srvc_id.id.uuid.uu, sizeof(ev.svc_uuid));
memcpy(ev.char_uuid, resp_data->char_id.uuid.uu, sizeof(ev.char_uuid));
- DBG("sending the gatt client write charac event");
+ DBG("sending gatt client charac write event. conn_id[%d] status[%d]", resp_data->conn_id, result);
event_cb(HAL_EV_GATT_CLIENT_WRITE_CHARAC, (void *)&ev, sizeof(ev));
}
g_variant_get(value, "(hq)", &idx, &att_mtu);
*fd = g_unix_fd_list_get(fd_list, idx, NULL);
- INFO("FD is %d index is %d mtu is %d", *fd, idx, att_mtu);
+ INFO("Acquired Write fd %d, index %d, mtu %d", *fd, idx, att_mtu);
*mtu = att_mtu;
g_object_unref(fd_list);
notify_fd = g_unix_fd_list_get(fd_list, idx, NULL);
*mtu = att_mtu;
- INFO("Acquired characteristic Notify fd %d, mtu %d", notify_fd, *mtu);
+ INFO("Acquired Notify fd %d, mtu %d", notify_fd, *mtu);
*fd = notify_fd;
bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE;
int ret = BT_STATUS_SUCCESS;
- DBG("+");
-
ret = __hal_get_write_prop(write_type, &write_prop);
if (BT_STATUS_FAIL == ret) {
DBG("received invalid write type:[%d] ", write_type);
/* get the connection info */
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE_NO_RESPONSE;
int ret = BT_STATUS_SUCCESS;
- DBG("+");
DBG("svc isntance id:[%d]", srvc_id->id.inst_id);
/* get the connection info */
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
if (ret != BT_STATUS_SUCCESS)
return ret;
- INFO("Characterstics FD erite characterstics fd is %d", *fd);
return ret;
}
bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY;
int ret = BT_STATUS_SUCCESS;
- DBG("+");
- DBG("svc isntance id:[%d]", srvc_id->id.inst_id);
+ DBG("svc isntance id [%d]", srvc_id->id.inst_id);
/* get the connection info */
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
if (ret != BT_STATUS_SUCCESS)
return ret;
- INFO("Characterstics FD write characterstics fd is %d", *fd);
-
return ret;
}
{
CHECK_BTGATT_INIT();
- DBG("+");
-
DBG("svc isntance id:[%d]", srvc_id->id.inst_id);
return _hal_write_characteristic_value(conn_id, srvc_id, char_id, write_type,
len, auth_req, p_value);
return;
}
- DBG("sending gatt client desc read conn_id[%d] status[%d]", resp_data->conn_id, result);
-
memset(&ev, 0, sizeof(ev));
ev.conn_id = resp_data->conn_id;
ev.inst_id = resp_data->srvc_id.id.inst_id;
ev.len = len;
if (len > 0) {
- DBG("building the desc read value [%d]", len);
+ /* building the desc read value */
memcpy(ev.value, value, len);
}
- DBG("sending the gatt client read descriptor event");
+ DBG("sending gatt client desc read conn_id[%d] status[%d]", resp_data->conn_id, result);
event_cb(HAL_EV_GATT_CLIENT_READ_DESC, (void *)&ev, sizeof(ev));
}
hal_gattc_desc_t *gattc_desc = NULL;
- DBG("+");
-
/* get the connection info */
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
return;
}
- DBG("sending gatt client charac write conn_id[%d] status[%d]", resp_data->conn_id, result);
-
memset(&ev, 0, sizeof(ev));
ev.conn_id = resp_data->conn_id;
ev.inst_id = resp_data->srvc_id.id.inst_id;
memcpy(ev.char_uuid, resp_data->char_id.uuid.uu, sizeof(ev.char_uuid));
memcpy(ev.desc_uuid, resp_data->desc_id.uuid.uu, sizeof(ev.desc_uuid));
- DBG("sending the gatt client write charac event");
+ DBG("sending gatt client charac write event. conn_id[%d] status[%d]", resp_data->conn_id, result);
event_cb(HAL_EV_GATT_CLIENT_WRITE_DESC, (void *)&ev, sizeof(ev));
}
/* get the connection info */
conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
if (NULL == conn_info) {
- ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+ ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
return BT_STATUS_FAIL;
}
{
CHECK_BTGATT_INIT();
- DBG("+");
-
return __hal_update_conn_parameter(bd, min_int, max_int, latency, timeout);
}
struct hal_ev_gatt_client_mtu_exchange_completed ev;
struct conn_mtu_s *conn_mtu = (struct conn_mtu_s *)user_data;
- DBG("+");
-
reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
g_object_unref(proxy);
if (reply == NULL) {
.batchscan_enb_batch_scan = batchscan_enb_batch_scan,
.batchscan_dis_batch_scan = batchscan_dis_batch_scan,
.batchscan_read_reports = batchscan_read_reports,
- .add_connection_info = btif_gattc_add_connection_info
+ .add_connection_info = btif_gattc_add_connection_info,
};
static hal_gattc_server_info_t *__bt_find_gatt_conn_info(const bt_bdaddr_t *serv_addr)
{
- DBG("+");
-
GSList *l;
hal_gattc_server_info_t *info = NULL;
if (info == NULL)
continue;
- if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t))) {
- INFO("GATT connection found addr");
+ if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t)))
return info;
}
- }
+
return NULL;
}
static hal_gattc_client_info_t *__bt_find_gatt_client_info(bt_bdaddr_t *serv_addr)
{
- DBG("+");
-
GSList *l;
hal_gattc_client_info_t *info = NULL;
if (info == NULL)
continue;
- if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t))) {
- INFO("GATT client info found addr");
+ if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t)))
return info;
}
- }
+
return NULL;
}
if (info == NULL)
continue;
- if (info->conn_id == conn_id) {
- INFO("GATT client info found for conn_id [%d]", conn_id);
+ if (info->conn_id == conn_id)
return info;
}
- }
+
return NULL;
}
if ((info->inst_id == gattc_client->inst_id) &&
!memcmp(&info->bd_addr, &gattc_client->bd_addr, sizeof(bt_bdaddr_t))) {
- INFO("GATT connection found for conn_id [%d]", conn_id);
return info;
}
}
/*add gatt server connection info*/
gatt_conn_info = g_malloc0(sizeof(hal_gattc_server_info_t));
memcpy(gatt_conn_info->bd_addr.address, gattc_data->bd_addr.address, BT_HAL_ADDRESS_LENGTH_MAX);
+ gatt_conn_info->conn_id = gattc_data->conn_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);
return;
}
- DBG("sending gatt client search service result event conn_id[%d]", conn_id);
+ DBG("Send service searching result. [%s] conn_id[%d]", uuid_str, conn_id);
memset(&ev, 0, sizeof(ev));
ev.conn_id = conn_id;
}
}
+ if (uuid_str == NULL || gp_char_array == NULL) {
+ ERR("uuid_str and gp_char_array should be set");
+ goto done;
+ }
+
/* Create new service */
_gattc_create_new_service(server_info, is_primary, uuid_str, service_path, gp_char_array);
+done:
g_variant_iter_free(property_iter);
g_variant_unref(result);
g_object_unref(properties_proxy);
_bt_hal_convert_device_path_to_address(path, address);
_bt_hal_convert_addr_string_to_type(ev.bdaddr, address);
- ev.change_type = is_added;
server_info = __bt_find_gatt_conn_info((bt_bdaddr_t *)ev.bdaddr);
if (server_info == NULL) {
ERR("service_info is NULL");
}
if (is_added) {
+ /* Get service UUID from path */
__bt_hal_gattc_get_uuid_from_path(path, &uuid_str);
- DBG("GATT Service(%s) Added", uuid_str);
- /* Set UUID by using path */
- _bt_hal_convert_uuid_string_to_type(ev.uuid, uuid_str);
- g_free(uuid_str);
+ if (uuid_str) {
+ DBG("conn_id(%d) GATT Service(%s) Added", server_info->conn_id, uuid_str);
+ _bt_hal_convert_uuid_string_to_type(ev.uuid, uuid_str);
+ g_free(uuid_str);
+ } else {
+ ERR("uuid_str is NULL");
+ return;
+ }
/* Create new service and append into the list */
__hal_gattc_get_service_info(server_info, path);
if (g_strcmp0(service->svc_path, path) == 0) {
memcpy(ev.uuid, service->svc_uuid.uu, sizeof(bt_uuid_t));
uuid_str = g_malloc0(BT_HAL_UUID_STRING_LEN);
- /* Set UUID from stored service info */
_bt_hal_convert_uuid_type_to_string(uuid_str, ev.uuid);
- DBG("GATT Service(%s) Removed", uuid_str);
- g_free(uuid_str);
+ DBG("conn_id(%d) GATT Service(%s) Removed", server_info->conn_id, uuid_str);
/* Remove service info in list */
server_info->gatt_list_services = g_slist_remove(server_info->gatt_list_services, service);
break;
}
}
+
+ if (uuid_str) {
+ g_free(uuid_str);
+ } else {
+ ERR("uuid_str is NULL");
+ return;
+ }
}
/* Send GATT Client service changed event */
+ ev.change_type = is_added;
+ ev.conn_id = server_info->conn_id;
+ ev.inst_id = server_info->inst_id;
event_cb(HAL_EV_GATT_CLIENT_SERVICE_CHANGED, (void *)&ev, sizeof(ev));
}
-