X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-oal%2Fbluez_hal%2Fsrc%2Fbt-hal-gatt-client.c;h=17ccddb0fd7a8618bfae8fcf62935f496f7de140;hb=9ab3a27b600cf4d760e7a510b16f1a662caa3fce;hp=544e4c8d48ab8a9d7e7d5774847a7ddf76bced16;hpb=6d2d19a0849d91417d12151ffa584158d5641608;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-client.c b/bt-oal/bluez_hal/src/bt-hal-gatt-client.c index 544e4c8..17ccddb 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-client.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-client.c @@ -123,6 +123,7 @@ typedef struct { 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; @@ -145,7 +146,12 @@ static guint pending_le_conn_timer_id = 0; 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; @@ -162,8 +168,10 @@ typedef struct { static GSList * hal_gattc_client_app_list = NULL; -static int bt_client_if = 0; - +struct conn_mtu_s { + int conn_id; + int mtu; +}; static bt_status_t __bt_connect_le_device_internal(int client_if, const bt_bdaddr_t *bd_addr, gboolean auto_connect); @@ -176,8 +184,51 @@ static hal_gattc_server_info_t *__bt_find_gatt_conn_info_from_conn_id(int conn_ static void _bt_hal_send_search_service_result_event(int conn_id, int is_primary, const char* uuid_str, int inst_id); static void _bt_hal_send_search_service_complete_event(int conn_id, int status); -static hal_gattc_server_info_t *__bt_find_gatt_conn_info(bt_bdaddr_t *serv_addr); +static hal_gattc_server_info_t *__bt_find_gatt_conn_info(const bt_bdaddr_t *serv_addr); 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 */ @@ -203,7 +254,6 @@ static gboolean __bt_hal_register_client_cb(gpointer user_data) 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; @@ -221,14 +271,10 @@ static gboolean __bt_hal_register_client_cb(gpointer user_data) 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; @@ -244,11 +290,17 @@ static hal_gatt_client_app *__hal_gattc_add_client_app(bt_uuid_t *app_uuid) } } + 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); @@ -261,7 +313,6 @@ static bt_status_t __hal_gattc_register_client_app(bt_uuid_t *app_uuid) 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) { @@ -284,11 +335,38 @@ static bt_status_t __hal_gattc_register_client_app(bt_uuid_t *app_uuid) bt_status_t btif_gattc_register_client(bt_uuid_t *uuid) { CHECK_BTGATT_INIT(); - DBG("+"); return __hal_gattc_register_client_app(uuid); } +bt_status_t btif_gattc_add_connection_info(const bt_bdaddr_t *bd_addr, int conn_id, int server_inst_id) +{ + hal_gattc_client_info_t *client_info = NULL; + hal_gattc_server_info_t *server_info = NULL; + + /* Add client connection info in list */ + client_info = g_malloc0(sizeof(hal_gattc_client_info_t)); + client_info->client_if = -1; + memcpy(client_info->bd_addr.address, bd_addr->address, BT_HAL_ADDRESS_LENGTH_MAX); + 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 = __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"); + } + + return BT_STATUS_SUCCESS; +} + bt_status_t __hal_gattc_unregister_client(int client_if) { GSList *l; @@ -306,6 +384,9 @@ bt_status_t __hal_gattc_unregister_client(int client_if) 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); } @@ -319,7 +400,6 @@ bt_status_t __hal_gattc_unregister_client(int client_if) bt_status_t btif_gattc_unregister_client(int client_if) { CHECK_BTGATT_INIT(); - DBG("+"); return __hal_gattc_unregister_client(client_if); } @@ -346,7 +426,6 @@ bt_status_t btif_gattc_client_connect(int client_if, const bt_bdaddr_t *bd_addr, int ret = BT_STATUS_SUCCESS; CHECK_BTGATT_INIT(); - DBG("+"); if (NULL == bd_addr) return BT_STATUS_PARM_INVALID; @@ -488,8 +567,6 @@ bt_status_t btif_gattc_client_disconnect(int client_if, const bt_bdaddr_t *bd_ad { CHECK_BTGATT_INIT(); - DBG("+"); - return _hal_gattc_disconnect(client_if, bd_addr, conn_id); } @@ -502,8 +579,6 @@ bt_status_t refresh(int client_if, const bt_bdaddr_t *bd_addr) 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; @@ -512,11 +587,10 @@ static hal_gattc_service_t* _gattc_find_service_from_uuid(hal_gattc_server_info_ 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; } @@ -524,8 +598,6 @@ static hal_gattc_service_t* _gattc_find_service_from_uuid(hal_gattc_server_info_ 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; @@ -536,7 +608,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_s if (!memcmp(&info->chr_uuid, char_uuid, sizeof(bt_uuid_t)) && (info->permission & prop)) { - INFO("Found GATT char uuid"); return info; } } @@ -545,8 +616,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_s 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; @@ -558,7 +627,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid_for_notify(hal_gattc_service 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; } } @@ -567,8 +635,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid_for_notify(hal_gattc_service 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; @@ -577,19 +643,16 @@ static hal_gattc_desc_t* _gattc_find_desc_from_uuid(hal_gattc_char_t *gattc_char 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, char *object_path, int is_primary) + 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)); @@ -597,18 +660,15 @@ static hal_gattc_service_t* _hal_gatt_client_add_service(hal_gattc_server_info_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)); @@ -621,14 +681,12 @@ static void _hal_gattc_add_characteristic(hal_gattc_service_t *gatt_svc, char *c } static void _gattc_create_new_service(hal_gattc_server_info_t *conn_info, gboolean is_primary, - const char* uuid_str, char *object_path, GPtrArray *gp_char_array) + const char* uuid_str, const char *object_path, GPtrArray *gp_char_array) { hal_gattc_service_t* gatt_svc = NULL; 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) { @@ -653,9 +711,6 @@ static void _hal_gattc_add_descriptor(hal_gattc_char_t *gattc_char, char *desc_p 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, @@ -664,17 +719,12 @@ static void _hal_gattc_update_char_property(hal_gattc_char_t *gattc_char, const 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 @@ -689,8 +739,6 @@ static void _hal_gattc_update_char_property(hal_gattc_char_t *gattc_char, const 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; @@ -713,38 +761,28 @@ static void browse_service_char(int conn_id) hal_gattc_char_t *char_info = NULL; hal_gattc_desc_t *desc_info = NULL; - DBG("+"); - conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); if (conn_info == NULL) { - DBG("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("svc path [%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("char path[%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("desc path[%s]", desc_info->desc_path); } } } @@ -783,14 +821,35 @@ static bt_status_t _gattc_client_search_service(int conn_id) 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) { - DBG("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); @@ -822,19 +881,16 @@ static bt_status_t _gattc_client_search_service(int conn_id) 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); } } @@ -842,7 +898,6 @@ static bt_status_t _gattc_client_search_service(int conn_id) } 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); @@ -900,8 +955,6 @@ static void _bt_hal_send_client_char_search_result_event(int conn_id, int status 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; @@ -910,13 +963,12 @@ static void _bt_hal_send_client_char_search_result_event(int conn_id, int status 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)); } @@ -959,6 +1011,40 @@ static int _hal_get_permission_flag(char *permission) 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) { @@ -979,16 +1065,12 @@ static bt_status_t _hal_gattc_get_characteristic_info(hal_gattc_char_t *gattc_ch gchar* permission; unsigned int char_permission = 0 ; - DBG("+"); - if (gattc_char->chr_path == NULL) { DBG("char path is NULL"); return BT_STATUS_FAIL; } 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"); @@ -1031,20 +1113,18 @@ static bt_status_t _hal_gattc_get_characteristic_info(hal_gattc_char_t *gattc_ch 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 handle : %s", char_desc_handle); - g_ptr_array_add(gp_desc_array, (gpointer)char_desc_handle); } } @@ -1071,26 +1151,21 @@ static bt_status_t _gattc_get_all_characteristic(int conn_id, char svc_uuid_str[BT_HAL_UUID_STRING_LEN]; int status = BT_STATUS_FAIL; - DBG("+"); - DBG("conn_id[%d]", conn_id); - conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); if (NULL == conn_info) { - DBG("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; } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); - _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); + INFO("%s %s", gattc_service->svc_path + 37, svc_uuid_str); /* find characteristic object path */ for (l = gattc_service->gatt_list_chars; l != NULL; l = g_slist_next(l)) { @@ -1099,14 +1174,11 @@ static bt_status_t _gattc_get_all_characteristic(int conn_id, /* 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); @@ -1123,7 +1195,6 @@ static bt_status_t _gattc_get_all_characteristic(int conn_id, 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) { @@ -1149,16 +1220,12 @@ static bt_status_t _hal_gattc_get_descriptor_info(hal_gattc_desc_t *gattc_desc) 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"); @@ -1199,7 +1266,6 @@ static bt_status_t _hal_gattc_get_descriptor_info(hal_gattc_desc_t *gattc_desc) 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; } @@ -1222,8 +1288,6 @@ static void _bt_hal_send_client_desc_search_result_event(int conn_id, int status 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; @@ -1234,11 +1298,11 @@ static void _bt_hal_send_client_desc_search_result_event(int conn_id, int status 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)); } @@ -1256,24 +1320,21 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id, char char_uuid_str[BT_HAL_UUID_STRING_LEN]; int status = BT_STATUS_FAIL; - DBG("+"); - conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); if (NULL == conn_info) { - DBG("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; } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); + INFO("%s %s", gattc_service->svc_path + 37, svc_uuid_str); /* find characteristics */ /* a service can have two char with same uuid */ @@ -1283,10 +1344,8 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id, continue; if (!memcmp(&gattc_char->chr_uuid, &char_id->uuid, sizeof(bt_uuid_t))) { - INFO("Found GATT char uuid"); - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + INFO("%s %s", gattc_char->chr_path + 37, char_uuid_str); /* get descriptor uuid */ for (m = gattc_char->gatt_list_descs; m != NULL; m = g_slist_next(m)) { @@ -1298,7 +1357,6 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id, /* 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); } @@ -1306,8 +1364,6 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id, } } - DBG("sending final event"); - status = BT_STATUS_FAIL; _bt_hal_send_client_desc_search_result_event(conn_id, status, srvc_id, char_id, NULL); @@ -1325,11 +1381,9 @@ bt_status_t btif_gattc_get_descriptor(int conn_id, 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"); @@ -1346,8 +1400,6 @@ static void __hal_send_char_read_event(hal_gatt_resp_data_t *resp_data, int resu 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; @@ -1359,11 +1411,11 @@ static void __hal_send_char_read_event(hal_gatt_resp_data_t *resp_data, int resu 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)); } @@ -1379,9 +1431,6 @@ static void __hal_internal_read_char_cb(GObject *source_object, guint8 g_byte; hal_gatt_resp_data_t *resp_data = user_data; int result = BT_STATUS_SUCCESS; - int i; - - DBG("+"); system_gconn = _bt_hal_get_system_gconn(); value = g_dbus_connection_call_finish(system_gconn, res, &error); @@ -1403,10 +1452,6 @@ static void __hal_internal_read_char_cb(GObject *source_object, while (g_variant_iter_loop(iter, "y", &g_byte)) g_byte_array_append(gp_byte_array, &g_byte, 1); - //print the value - 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); @@ -1417,10 +1462,8 @@ static void __hal_internal_read_char_cb(GObject *source_object, 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) { @@ -1435,38 +1478,32 @@ static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t char char_uuid_str[BT_HAL_UUID_STRING_LEN]; char* char_handle = NULL; - DBG("+"); - /* get the connection info */ conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); if (NULL == conn_info) { - DBG("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; } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); - /* find characteristic */ gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid, HAL_GATT_CHARACTERISTIC_PROPERTY_READ); if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); + ERR("Failed to get the gatt char"); return BT_STATUS_FAIL; } - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + INFO("%s %s", gattc_char->chr_path + 37, char_uuid_str); g_conn = _bt_hal_get_system_gconn(); if (NULL == g_conn) { @@ -1487,8 +1524,6 @@ static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t 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, @@ -1505,7 +1540,6 @@ bt_status_t btif_read_characteristic(int conn_id, int auth_req) { CHECK_BTGATT_INIT(); - DBG("+"); return _hal_read_characteristic_value(conn_id, srvc_id, char_id, auth_req); } @@ -1519,8 +1553,6 @@ static void __hal_send_char_write_event(hal_gatt_resp_data_t *resp_data, int res 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; @@ -1530,7 +1562,7 @@ static void __hal_send_char_write_event(hal_gatt_resp_data_t *resp_data, int res 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)); } @@ -1625,7 +1657,7 @@ static int __bluetooth_gatt_acquire_write_fd(const char *chr, int *fd, int *mtu) 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); @@ -1676,7 +1708,7 @@ static int __bluetooth_gatt_acquire_notify_fd(const char *chr, int *fd, int *mtu 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; @@ -1707,8 +1739,6 @@ static bt_status_t _hal_write_characteristic_value(int conn_id, btgatt_srvc_id_t 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); @@ -1718,31 +1748,29 @@ static bt_status_t _hal_write_characteristic_value(int conn_id, btgatt_srvc_id_t /* get the connection info */ conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); if (NULL == conn_info) { - DBG("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; } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); + 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, write_prop); if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); + ERR("Failed to get the gatt char"); return BT_STATUS_FAIL; } - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + DBG("%s %s", gattc_char->chr_path + 37, char_uuid_str); g_conn = _bt_hal_get_system_gconn(); if (NULL == g_conn) { @@ -1791,11 +1819,6 @@ bt_status_t btif_get_acquire_write_fd(int conn_id, { CHECK_BTGATT_INIT(); - DBG("+"); - - DBG("svc isntance id:[%d]", srvc_id->id.inst_id); - - hal_gattc_service_t *gattc_service = NULL; hal_gattc_server_info_t * conn_info = NULL; hal_gattc_char_t *gattc_char = NULL; @@ -1804,41 +1827,36 @@ bt_status_t btif_get_acquire_write_fd(int conn_id, 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 */ + /* get the connection info */ conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); if (NULL == conn_info) { - DBG("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; } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid, write_prop); - if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); - return BT_STATUS_FAIL; - } + if (NULL == gattc_char) { + ERR("Failed to get the gatt char"); + return BT_STATUS_FAIL; + } - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); - + INFO("%s %s", gattc_char->chr_path + 37, char_uuid_str); ret = __bluetooth_gatt_acquire_write_fd(gattc_char->chr_path, fd, mtu); if (ret != BT_STATUS_SUCCESS) return ret; - - ERR("Characterstics FD erite characterstics fd is %d", *fd); - - return ret; + return ret; } bt_status_t btif_get_acquire_notify_fd(int conn_id, @@ -1846,11 +1864,6 @@ bt_status_t btif_get_acquire_notify_fd(int conn_id, { CHECK_BTGATT_INIT(); - DBG("+"); - - DBG("svc isntance id:[%d]", srvc_id->id.inst_id); - - hal_gattc_service_t *gattc_service = NULL; hal_gattc_server_info_t * conn_info = NULL; hal_gattc_char_t *gattc_char = NULL; @@ -1859,42 +1872,36 @@ bt_status_t btif_get_acquire_notify_fd(int conn_id, 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); - /* get the connection info */ - conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); - if (NULL == conn_info) { - DBG("Failed to get the conn_info for conn_id[%d]", conn_id); - return BT_STATUS_FAIL; - } + /* 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); + return BT_STATUS_FAIL; + } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid, write_prop); - if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); - return BT_STATUS_FAIL; - } + if (NULL == gattc_char) { + ERR("Failed to get the gatt char"); + return BT_STATUS_FAIL; + } - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); - + INFO("%s %s", gattc_char->chr_path + 37, char_uuid_str); ret = __bluetooth_gatt_acquire_notify_fd(gattc_char->chr_path, fd, mtu); if (ret != BT_STATUS_SUCCESS) return ret; - - ERR("Characterstics FD write characterstics fd is %d", *fd); - - return ret; - + return ret; } @@ -1906,8 +1913,6 @@ bt_status_t btif_write_characteristic(int conn_id, { 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); @@ -1922,8 +1927,6 @@ static void __hal_send_desc_read_event(hal_gatt_resp_data_t *resp_data, int resu 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; @@ -1936,11 +1939,11 @@ static void __hal_send_desc_read_event(hal_gatt_resp_data_t *resp_data, int resu 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)); } @@ -2015,25 +2018,22 @@ static bt_status_t _hal_read_descriptor_value(int conn_id, btgatt_srvc_id_t *srv 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) { - DBG("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; } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); + DBG("%s %s", gattc_service->svc_path + 37, svc_uuid_str); /* find characteristic */ /* service can have two char with same uuid */ @@ -2043,24 +2043,21 @@ static bt_status_t _hal_read_descriptor_value(int conn_id, btgatt_srvc_id_t *srv continue; if (!memcmp(&gattc_char->chr_uuid, &char_id->uuid, sizeof(bt_uuid_t))) { - INFO("Found GATT char uuid"); - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + DBG("%s %s", gattc_char->chr_path + 37, char_uuid_str); /* find descriptor */ gattc_desc = _gattc_find_desc_from_uuid(gattc_char, &desc_id->uuid); if (gattc_desc) { - DBG("desc path [%s]", gattc_desc->desc_path); _bt_hal_convert_uuid_type_to_string(desc_uuid_str, gattc_desc->desc_uuid.uu); - DBG("desc uuid [%s]", desc_uuid_str); + DBG("%s %s", gattc_desc->desc_path + 37, desc_uuid_str); break; } } } if (NULL == gattc_desc) { - DBG("Failed to get the gatt desc"); + ERR("Failed to get the gatt desc"); return BT_STATUS_FAIL; } @@ -2115,8 +2112,6 @@ static void __hal_send_desc_write_event(hal_gatt_resp_data_t *resp_data, int res 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; @@ -2127,7 +2122,7 @@ static void __hal_send_desc_write_event(hal_gatt_resp_data_t *resp_data, int res 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)); } @@ -2193,27 +2188,26 @@ static bt_status_t _hal_write_descriptor_value(int conn_id, btgatt_srvc_id_t *sr ret = __hal_get_write_prop(write_type, &write_prop); if (BT_STATUS_FAIL == ret) { - DBG("received invalid write type:[%d] ", write_type); + ERR("received invalid write type:[%d] ", write_type); return BT_STATUS_FAIL; } /* get the connection info */ conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id); if (NULL == conn_info) { - DBG("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; } /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); + DBG("%s %s", gattc_service->svc_path + 37, svc_uuid_str); /* find characteristic */ /* service can have two char with same uuid */ @@ -2223,24 +2217,21 @@ static bt_status_t _hal_write_descriptor_value(int conn_id, btgatt_srvc_id_t *sr continue; if (!memcmp(&gattc_char->chr_uuid, &char_id->uuid, sizeof(bt_uuid_t))) { - INFO("Found GATT char uuid"); - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + DBG("%s %s", gattc_char->chr_path + 37, char_uuid_str); /* find descriptor */ gattc_desc = _gattc_find_desc_from_uuid(gattc_char, &descr_id->uuid); if (gattc_desc) { - DBG("desc path [%s]", gattc_desc->desc_path); _bt_hal_convert_uuid_type_to_string(desc_uuid_str, gattc_desc->desc_uuid.uu); - DBG("desc uuid [%s]", desc_uuid_str); + DBG("%s %s", gattc_desc->desc_path + 37, desc_uuid_str); break; } } } if (NULL == gattc_desc) { - DBG("Failed to get the gatt desc"); + ERR("Failed to get the gatt desc"); return BT_STATUS_FAIL; } @@ -2377,25 +2368,23 @@ static bt_status_t _hal_register_for_notification(int client_if, /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); + DBG("%s %s", gattc_service->svc_path + 15, svc_uuid_str); /* find characteristic */ gattc_char = _gattc_find_char_from_uuid_for_notify(gattc_service, &char_id->uuid); if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); + ERR("Failed to get the gatt char"); return BT_STATUS_FAIL; } - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + DBG("%s %s", gattc_char->chr_path + 15, char_uuid_str); char_handle = gattc_char->chr_path; @@ -2407,7 +2396,8 @@ static bt_status_t _hal_register_for_notification(int client_if, resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); - DBG("#StartNotify"); + INFO_C("### Request StartNotify : %s [%s]", gattc_char->chr_path + 15, char_uuid_str); + g_dbus_connection_call_sync(g_conn, BT_HAL_BLUEZ_NAME, char_handle, @@ -2420,7 +2410,7 @@ static bt_status_t _hal_register_for_notification(int client_if, if (error) { g_dbus_error_strip_remote_error(error); - ERR("### Watch Failed: %s", error->message); + ERR("### StartNotify Failed: %s", error->message); if (g_strrstr(error->message, "Already notifying")) result = BT_STATUS_SUCCESS; else if (g_strrstr(error->message, "In Progress")) @@ -2538,25 +2528,23 @@ static bt_status_t _hal_deregister_for_notification(int client_if, /* find service */ gattc_service = _gattc_find_service_from_uuid(conn_info, &srvc_id->id.uuid); if (NULL == gattc_service) { - DBG("Failed to get the gatt service"); + ERR("Failed to get the gatt service"); return BT_STATUS_FAIL; } - DBG("service path [%s]", gattc_service->svc_path); _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu); - DBG("service uuid [%s]", svc_uuid_str); + DBG("%s %s", gattc_service->svc_path + 15, svc_uuid_str); /* find characteristic */ gattc_char = _gattc_find_char_from_uuid_for_notify(gattc_service, &char_id->uuid); if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); + ERR("Failed to get the gatt char"); return BT_STATUS_FAIL; } - DBG("char path [%s]", gattc_char->chr_path); _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + DBG("%s %s", gattc_char->chr_path + 15, char_uuid_str); char_handle = gattc_char->chr_path; @@ -2568,7 +2556,7 @@ static bt_status_t _hal_deregister_for_notification(int client_if, resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); - DBG("#StartNotify"); + INFO("### Request StopNotify : %s [%s]", gattc_char->chr_path + 15, char_uuid_str); g_dbus_connection_call_sync(g_conn, BT_HAL_BLUEZ_NAME, char_handle, @@ -2580,7 +2568,7 @@ static bt_status_t _hal_deregister_for_notification(int client_if, BT_HAL_MAX_DBUS_TIMEOUT, NULL, &error); if (error) { - ERR("### Watch Failed: %s", error->message); + ERR("### StopNotify Failed: %s", error->message); g_clear_error(&error); result = BT_STATUS_FAIL; } @@ -2665,7 +2653,7 @@ static bt_status_t __hal_update_conn_parameter(bt_bdaddr_t *bd_addr, return BT_STATUS_FAIL; } - INFO("### LeConnUpdate"); + INFO("Request LeConnUpdate"); reply = g_dbus_proxy_call_sync(device_proxy, "LeConnUpdate", g_variant_new("(uuuu)", min_int, max_int, latency, timeout), G_DBUS_CALL_FLAGS_NONE, @@ -2687,7 +2675,7 @@ static bt_status_t __hal_update_conn_parameter(bt_bdaddr_t *bd_addr, } g_variant_unref(reply); - INFO("LE Connection parameter Updated"); + DBG("LE Connection parameter Updated"); return ret; } @@ -2696,8 +2684,6 @@ bt_status_t btif_gattc_conn_parameter_update(bt_bdaddr_t *bd, int min_int, int m { CHECK_BTGATT_INIT(); - DBG("+"); - return __hal_update_conn_parameter(bd, min_int, max_int, latency, timeout); } @@ -2708,11 +2694,103 @@ bt_status_t test_command(int command, btgatt_test_params_t* params) return BT_STATUS_UNSUPPORTED; } +static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res, + gpointer user_data) +{ + GError *g_error = NULL; + GVariant *reply = NULL; + int result = BT_STATUS_SUCCESS; + struct hal_ev_gatt_client_mtu_exchange_completed ev; + struct conn_mtu_s *conn_mtu = (struct conn_mtu_s *)user_data; + + reply = g_dbus_proxy_call_finish(proxy, res, &g_error); + g_object_unref(proxy); + if (reply == NULL) { + ERR("Connect LE Dbus Call Error"); + if (g_error) { + ERR("Error occured in RequestAttMtu [%s]", g_error->message); + g_clear_error(&g_error); + } + result = BT_STATUS_FAIL; + } + g_variant_unref(reply); + + memset(&ev, 0, sizeof(ev)); + ev.status = result; + ev.mtu = conn_mtu->mtu; + ev.conn_id = conn_mtu->conn_id; + + if (!event_cb) { + ERR("gatt client callback not registered"); + } else { + DBG("sending gatt client MTU exchange completed event"); + event_cb(HAL_EV_GATT_CLIENT_MTU_EXCHANGE_COMPLETED , (void *)&ev, sizeof(ev)); + } + + g_free(conn_mtu); +} + + +static bt_status_t __hal_configure_mtu(int conn_id, int mtu) +{ + gchar *device_path = NULL; + GDBusProxy *device_proxy = NULL; + GDBusConnection *conn; + hal_gattc_client_info_t *gattc_client = NULL; + char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 }; + struct conn_mtu_s *conn_mtu = g_malloc0(sizeof(struct conn_mtu_s)); + + 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_DEVICE_INTERFACE, NULL, NULL); + + g_free(device_path); + if (NULL == device_proxy) { + ERR("device_proxy returned NULL"); + return BT_STATUS_FAIL; + } + + conn_mtu->conn_id = conn_id; + conn_mtu->mtu = mtu; + + g_dbus_proxy_call(device_proxy, "RequestAttMtu", + g_variant_new("(q)", mtu), + G_DBUS_CALL_FLAGS_NONE, + BT_HAL_MAX_DBUS_TIMEOUT, + NULL, + (GAsyncReadyCallback)__bt_request_att_mtu_device_cb, + conn_mtu); + + return BT_STATUS_SUCCESS; +} + /** MTU Exchange request from client */ -bt_status_t configure_mtu(int conn_id, int mtu) +static bt_status_t configure_mtu(int conn_id, int mtu) { CHECK_BTGATT_INIT(); - return BT_STATUS_UNSUPPORTED; + + return __hal_configure_mtu(conn_id, mtu); } /** Setup scan filter params */ @@ -3106,8 +3184,28 @@ bt_status_t scan_filter_clear(int client_if, int filt_index) /** Enable / disable scan filter feature*/ bt_status_t scan_filter_enable(int client_if, bool enable) { + GDBusProxy *proxy; + GError *error = NULL; + GVariant *ret; CHECK_BTGATT_INIT(); - return BT_STATUS_UNSUPPORTED; + + proxy = _bt_hal_get_adapter_proxy(); + if (proxy == NULL) + return BT_STATUS_FAIL; + + ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable", + g_variant_new("(ib)", client_if, enable), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + + if (error) { + ERR("scan_filter_enable Fail: %s", error->message); + g_clear_error(&error); + return BT_STATUS_FAIL; + } + g_variant_unref(ret); + + return BT_STATUS_SUCCESS; } /** Sets the LE scan interval and window in units of N*0.625 msec */ @@ -3195,13 +3293,12 @@ const btgatt_client_interface_t btgatt_client_interface = { .batchscan_cfg_storage = batchscan_cfg_storage, .batchscan_enb_batch_scan = batchscan_enb_batch_scan, .batchscan_dis_batch_scan = batchscan_dis_batch_scan, - .batchscan_read_reports = batchscan_read_reports + .batchscan_read_reports = batchscan_read_reports, + .add_connection_info = btif_gattc_add_connection_info, }; -static hal_gattc_server_info_t *__bt_find_gatt_conn_info(bt_bdaddr_t *serv_addr) +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; @@ -3210,18 +3307,15 @@ static hal_gattc_server_info_t *__bt_find_gatt_conn_info(bt_bdaddr_t *serv_addr) 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; @@ -3230,18 +3324,15 @@ static hal_gattc_client_info_t *__bt_find_gatt_client_info(bt_bdaddr_t *serv_add 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; } static hal_gattc_client_info_t *__bt_find_gatt_client_info_from_conn_id(int conn_id) { - DBG("+"); - GSList *l; hal_gattc_client_info_t *info = NULL; @@ -3250,25 +3341,22 @@ static hal_gattc_client_info_t *__bt_find_gatt_client_info_from_conn_id(int conn 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; } static hal_gattc_server_info_t *__bt_find_gatt_conn_info_from_conn_id(int conn_id) { - DBG("+"); - GSList *l; hal_gattc_server_info_t *info = NULL; hal_gattc_client_info_t *gattc_client = NULL; gattc_client = __bt_find_gatt_client_info_from_conn_id(conn_id); if (gattc_client == NULL) { - INFO("GATT client conn info not found"); + ERR("GATT client conn info not found"); return NULL; } @@ -3279,7 +3367,6 @@ static hal_gattc_server_info_t *__bt_find_gatt_conn_info_from_conn_id(int conn_ 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; } } @@ -3455,6 +3542,7 @@ static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res, /*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); @@ -3467,81 +3555,65 @@ fail: g_free(gattc_data); } -void __hal_gattc_free_svc_info(hal_gattc_service_t *svc_info) +static void __hal_gattc_free_desc_info(hal_gattc_desc_t *desc_info) { - g_free(svc_info->svc_path); - g_free(svc_info); + g_free(desc_info->desc_path); + g_free(desc_info); } -void __hal_gattc_free_char_info(hal_gattc_char_t *char_info) +static void __hal_gattc_free_char_info(hal_gattc_char_t *char_info) { + GSList *l = NULL; + hal_gattc_desc_t *desc_info = NULL; + for (l = char_info->gatt_list_descs; l != NULL; ) { + desc_info = l->data; + l = g_slist_next(l); + if (desc_info == NULL) + continue; + /* Remove descriptor element */ + char_info->gatt_list_descs = g_slist_remove(char_info->gatt_list_descs, desc_info); + __hal_gattc_free_desc_info(desc_info); + } + g_slist_free(char_info->gatt_list_descs); g_free(char_info->chr_path); g_free(char_info); } -void __hal_gattc_free_desc_info(hal_gattc_desc_t *desc_info) +static void __hal_gattc_free_svc_info(hal_gattc_service_t *svc_info) { - g_free(desc_info->desc_path); - g_free(desc_info); + GSList *l = NULL; + hal_gattc_char_t *char_info = NULL; + for (l = svc_info->gatt_list_chars; l != NULL; ) { + char_info = l->data; + l = g_slist_next(l); + if (char_info == NULL) + continue; + /* Remove characteristic element */ + svc_info->gatt_list_chars = g_slist_remove(svc_info->gatt_list_chars, char_info); + __hal_gattc_free_char_info(char_info); + } + g_slist_free(svc_info->gatt_list_chars); + g_free(svc_info->svc_path); + g_free(svc_info); } -void __hal_clean_gattc_server_info(hal_gattc_server_info_t *conn_info) +static void __hal_clean_gattc_server_info(hal_gattc_server_info_t *conn_info) { - GSList *l; - GSList *m; - GSList *k; + GSList *l = NULL; hal_gattc_service_t *svc_info = NULL; - hal_gattc_char_t *char_info = NULL; - hal_gattc_desc_t *desc_info = NULL; DBG("+"); - for (l = conn_info->gatt_list_services; l != NULL;) { - svc_info = (hal_gattc_service_t*)l->data; + for (l = conn_info->gatt_list_services; l != NULL; ) { + svc_info = (hal_gattc_service_t *)l->data; + l = g_slist_next(l); if (svc_info == NULL) continue; - l = g_slist_next(l); - - for (m = svc_info->gatt_list_chars; m != NULL; ) { - char_info = (hal_gattc_char_t*)m->data; - if (char_info == NULL) - continue; - m = g_slist_next(m); - - for (k = char_info->gatt_list_descs; k != NULL; ) { - desc_info = (hal_gattc_desc_t*)k->data; - if (desc_info == NULL) - continue; - k = g_slist_next(k); - - /*remove desc element*/ - char_info->gatt_list_descs = g_slist_remove(char_info->gatt_list_descs, desc_info); - __hal_gattc_free_desc_info(desc_info); - } - - /*remove desc list*/ - g_slist_free(char_info->gatt_list_descs); - char_info->gatt_list_descs = NULL; - - /*remove char element*/ - svc_info->gatt_list_chars = g_slist_remove(svc_info->gatt_list_chars, char_info); - __hal_gattc_free_char_info(char_info); - } - - /*remove char list*/ - g_slist_free(svc_info->gatt_list_chars); - svc_info->gatt_list_chars = NULL; - - /*remove svc element*/ + /* Remove service element */ conn_info->gatt_list_services = g_slist_remove(conn_info->gatt_list_services, svc_info); __hal_gattc_free_svc_info(svc_info); } - - /*remove svc list */ g_slist_free(conn_info->gatt_list_services); - conn_info->gatt_list_services = NULL; - - /*remove conn info*/ g_free(conn_info); } @@ -3632,7 +3704,7 @@ static void _bt_hal_send_search_service_result_event(int conn_id, int is_primary 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; @@ -3746,3 +3818,203 @@ void _bt_hal_handle_gattc_value_changed_event(int result, const char *char_handl } } } + +static bt_status_t __hal_gattc_get_service_info(hal_gattc_server_info_t *server_info, const char *service_path) +{ + GDBusConnection *g_conn = NULL; + GDBusProxy *properties_proxy = NULL; + GVariant *result = NULL; + GError *error = NULL; + GVariantIter *property_iter = NULL; + const gchar *key = NULL; + GVariant *value = NULL; + const char *uuid_str = NULL; + gsize len = 0; + gboolean is_primary = FALSE; + GVariantIter *char_iter = NULL; + const char *char_handle = NULL; + GPtrArray *gp_char_array = NULL; + + if (service_path == NULL) { + ERR("service_path is NULL"); + return BT_STATUS_FAIL; + } + + DBG("service_path: %s", service_path); + + g_conn = _bt_hal_get_system_gconn(); + if (g_conn == NULL) { + ERR("g_conn is NULL"); + return BT_STATUS_FAIL; + } + + properties_proxy = g_dbus_proxy_new_sync(g_conn, + G_DBUS_PROXY_FLAGS_NONE, NULL, + BT_HAL_BLUEZ_NAME, + service_path, + BT_HAL_PROPERTIES_INTERFACE, + NULL, &error); + if (properties_proxy == NULL) { + ERR("properties_proxy is NULL"); + return BT_STATUS_FAIL; + } + + result = g_dbus_proxy_call_sync(properties_proxy, + "GetAll", + g_variant_new("(s)", BT_HAL_GATT_SERVICE_INTERFACE), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (result == NULL) { + if (error != NULL) { + ERR("Fail to get properties (Error: %s)", error->message); + g_clear_error(&error); + } else { + ERR("Fail to get properties"); + } + g_object_unref(properties_proxy); + return BT_STATUS_FAIL; + } + + g_variant_get(result, "(a{sv})", &property_iter); + + 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) { + gp_char_array = g_ptr_array_new(); + 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 == 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); + DBG("-"); + return BT_STATUS_SUCCESS; +} + +static void __bt_hal_gattc_get_uuid_from_path(const char *path, char **service_uuid) +{ + GDBusConnection *conn = NULL; + GDBusProxy *proxy = NULL; + GError *err = NULL; + GVariant *ret = NULL; + GVariant *value = NULL; + + conn = _bt_hal_get_system_gconn(); + if (conn == NULL) { + ERR("_bt_gdbus_get_system_gconn returned NULL"); + return; + } + + proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, + BT_HAL_BLUEZ_NAME, path, BT_HAL_PROPERTIES_INTERFACE, NULL, &err); + if (proxy == NULL) { + ERR("device_proxy returned NULL"); + return; + } + + ret = g_dbus_proxy_call_sync(proxy, "Get", + g_variant_new("(ss)", BT_HAL_GATT_SERVICE_INTERFACE, "UUID"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); + if (err) { + ERR("DBus Error : %s", err->message); + g_clear_error(&err); + } else { + g_variant_get(ret, "(v)", &value); + *service_uuid = g_variant_dup_string(value, NULL); + g_variant_unref(value); + g_variant_unref(ret); + } + + if (proxy) + g_object_unref(proxy); + + return; +} + +void _bt_hal_handle_gattc_service_changed_event(gboolean is_added, const char *path) +{ + struct hal_ev_gatt_client_service_changed ev = {0, }; + char address[BT_HAL_ADDRESS_STRING_SIZE]; + hal_gattc_server_info_t *server_info = NULL; + hal_gattc_service_t *service = NULL; + GSList *list = NULL; + char *uuid_str = NULL; + + _bt_hal_convert_device_path_to_address(path, address); + _bt_hal_convert_addr_string_to_type(ev.bdaddr, address); + server_info = __bt_find_gatt_conn_info((bt_bdaddr_t *)ev.bdaddr); + if (server_info == NULL) { + ERR("service_info is NULL"); + return; + } + + if (is_added) { + /* Get service UUID from path */ + __bt_hal_gattc_get_uuid_from_path(path, &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); + } else { + /* Find service UUID from path */ + for (list = server_info->gatt_list_services; list; list = g_slist_next(list)) { + service = (hal_gattc_service_t *)list->data; + if (service == NULL) + continue; + + 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); + _bt_hal_convert_uuid_type_to_string(uuid_str, ev.uuid); + 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); + __hal_gattc_free_svc_info(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)); +}