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 bt_status_t __bt_connect_le_device_internal(int client_if, const bt_bdaddr_t *bd_addr,
gboolean auto_connect);
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 */
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));
- if (gattc_app == NULL) {
- DBG("Failed to allocate memory");
- return NULL;
- }
-
- 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) {
/*send event */
client_app_info = g_malloc0(sizeof(hal_gatt_client_app));
- if (NULL == client_app_info) {
- ERR("Failed to allocate memory");
- return BT_STATUS_FAIL;
- }
-
client_app_info->client_if = gattc_app->client_if;
memcpy(&client_app_info->app_uuid, app_uuid, sizeof(bt_uuid_t));
g_idle_add(__bt_hal_register_client_cb, (gpointer)client_app_info);
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;
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;
}
gattc_data = g_malloc0(sizeof(hal_gattc_client_info_t));
- if (NULL == gattc_data) {
- ERR("Unable to allocate memory");
- ret = BT_STATUS_FAIL;
- goto fail;
- }
-
memcpy(gattc_data->bd_addr.address, bd_addr->address,
BT_HAL_ADDRESS_LENGTH_MAX);
gattc_data->client_if = client_if;
NULL,
(GAsyncReadyCallback)__le_disconnection_req_cb, gattc_data);
return ret;
-fail:
- if (device_proxy)
- g_object_unref(device_proxy);
-
- g_free(gattc_data);
-
- return ret;
}
/** Disconnect a remote device or cancel a pending connection */
{
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, 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));
_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));
}
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) {
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;
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);
}
}
}
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);
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)
{
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");
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);
}
}
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)) {
/* 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));
}
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 */
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)) {
/* 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));
}
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);
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);
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)
{
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) {
}
resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t));
- if (NULL == resp_data) {
- ERR("failed to get the memory");
- return BT_STATUS_FAIL;
- }
-
resp_data->conn_id = conn_id;
memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t));
memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_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,
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) {
- 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) {
}
resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t));
- if (NULL == resp_data) {
- ERR("failed to get the memory");
- return BT_STATUS_FAIL;
- }
-
resp_data->conn_id = conn_id;
memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t));
memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t));
{
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;
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,
{
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;
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;
}
{
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) {
- 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 */
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;
}
}
resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t));
- if (NULL == resp_data) {
- ERR("failed to get the memory");
- return BT_STATUS_FAIL;
- }
-
resp_data->conn_id = conn_id;
memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t));
memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t));
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));
}
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 */
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;
}
}
resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t));
- if (NULL == resp_data) {
- ERR("failed to get the memory");
- return BT_STATUS_FAIL;
- }
-
resp_data->conn_id = conn_id;
memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t));
memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t));
/* 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;
return BT_STATUS_FAIL;
}
- resp_data = malloc(sizeof(hal_gatt_resp_data_t));
- if (NULL == resp_data) {
- ERR("failed to get the memory");
- return BT_STATUS_FAIL;
- }
+ resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t));
+
+ INFO_C("### Request StartNotify : %s [%s]", gattc_char->chr_path + 15, char_uuid_str);
- DBG("#StartNotify");
g_dbus_connection_call_sync(g_conn,
BT_HAL_BLUEZ_NAME,
char_handle,
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"))
/* 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;
return BT_STATUS_FAIL;
}
- resp_data = malloc(sizeof(hal_gatt_resp_data_t));
- if (NULL == resp_data) {
- ERR("failed to get the memory");
- return BT_STATUS_FAIL;
- }
+ 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,
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;
}
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,
}
g_variant_unref(reply);
- INFO("LE Connection parameter Updated");
+ DBG("LE Connection parameter Updated");
return ret;
}
{
CHECK_BTGATT_INIT();
- DBG("+");
-
return __hal_update_conn_parameter(bd, min_int, max_int, latency, timeout);
}
return BT_STATUS_UNSUPPORTED;
}
-/** MTU Exchange request from client */
-bt_status_t configure_mtu(int conn_id, int mtu)
+static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
{
- CHECK_BTGATT_INIT();
- return BT_STATUS_UNSUPPORTED;
-}
+ 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;
-/** Setup scan filter params */
-bt_status_t scan_filter_param_setup(int client_if, int action, int filt_index, int feat_seln,
- int list_logic_type, int filt_logic_type, int rssi_high_thres,
- int rssi_low_thres, int dely_mode, int found_timeout,
- int lost_timeout, int found_timeout_cnt)
-{
- CHECK_BTGATT_INIT();
- return BT_STATUS_UNSUPPORTED;
+ 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);
}
-/** Configure a scan filter condition */
-bt_status_t scan_filter_add_remove(int client_if, int action, int filt_type,
- int filt_index, int company_id,
- int company_id_mask, const bt_uuid_t *p_uuid,
+
+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 */
+static bt_status_t configure_mtu(int conn_id, int mtu)
+{
+ CHECK_BTGATT_INIT();
+
+ return __hal_configure_mtu(conn_id, mtu);
+}
+
+/** Setup scan filter params */
+bt_status_t scan_filter_param_setup(int client_if, int action, int filt_index, int feat_seln,
+ int list_logic_type, int filt_logic_type, int rssi_high_thres,
+ int rssi_low_thres, int dely_mode, int found_timeout,
+ int lost_timeout, int found_timeout_cnt)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret, *param;
+ CHECK_BTGATT_INIT();
+
+ proxy = _bt_hal_get_adapter_proxy();
+
+ if (proxy == NULL)
+ return BT_STATUS_FAIL;
+
+ param = g_variant_new("(iiiiiiiiiiii)",
+ client_if,
+ action,
+ filt_index,
+ feat_seln,
+ list_logic_type,
+ filt_logic_type,
+ rssi_high_thres,
+ rssi_low_thres,
+ dely_mode,
+ found_timeout,
+ lost_timeout,
+ found_timeout_cnt);
+ ret = g_dbus_proxy_call_sync(proxy, "scan_filter_param_setup",
+ param, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_param_setup Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ return BT_STATUS_SUCCESS;
+}
+
+/** Configure a scan filter condition */
+bt_status_t scan_filter_add_remove(int client_if, int action, int filt_type,
+ int filt_index, int company_id,
+ int company_id_mask, const bt_uuid_t *p_uuid,
const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
char addr_type, int data_len, char* p_data, int mask_len,
char* p_mask)
{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret, *param;
+ GVariant *arr_uuid_param = NULL, *arr_uuid_mask_param = NULL;
+ GVariant *arr_data_param = NULL, *arr_data_mask_param = NULL;
+ GArray *arr_uuid = NULL;
+ GArray *arr_uuid_mask = NULL;
+ GArray *arr_data = NULL;
+ GArray *arr_data_mask = NULL;
CHECK_BTGATT_INIT();
+
+ proxy = _bt_hal_get_adapter_proxy();
+
+ if (proxy == NULL)
+ return BT_STATUS_FAIL;
+
+ if (filt_type == BT_SCAN_FILTER_FEATURE_DEVICE_ADDRESS) {
+
+ char address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+
+ _bt_hal_convert_addr_type_to_string(address, bd_addr->address);
+
+ INFO("BT_SCAN_FILTER_FEATURE_DEVICE_ADDRESS being added\nRemote Device Address is [%s]", address);
+
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+
+ param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
+ client_if, // client_if
+ action, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
+ BT_SCAN_FILTER_FEATURE_DEVICE_ADDRESS, // filter_type
+ filt_index, // filter_index
+ company_id, // company_id
+ company_id_mask, // company_id_mask
+ arr_uuid_param, // p_uuid
+ arr_uuid_mask_param, // p_uuid_mask
+ address, // string
+ addr_type, // address_type
+ arr_data_param, // p_data
+ arr_data_mask_param); // p_mask
+
+ ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
+ param, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_add_remove Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ if (filt_type == BT_SCAN_FILTER_FEATURE_DEVICE_NAME) {
+
+ INFO("BT_SCAN_FILTER_FEATURE_DEVICE_NAME being added\nRemote Device Name is %s", p_data);
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+
+ param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
+ client_if, // client_if
+ action, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
+ BT_SCAN_FILTER_FEATURE_DEVICE_NAME, // filter_type
+ filt_index, // filter_index
+ company_id, // company_id
+ company_id_mask, // company_id_mask
+ arr_uuid_param, // p_uuid
+ arr_uuid_mask_param, // p_uuid_mask
+ p_data, // string
+ addr_type, // address_type
+ arr_data_param, // p_data
+ arr_data_mask_param);
+
+ ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
+ param, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_add_remove Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ if (filt_type == BT_SCAN_FILTER_FEATURE_SERVICE_UUID) {
+
+ arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
+ g_array_append_vals(arr_uuid, p_uuid->uu, data_len * sizeof(guint8));
+ g_array_append_vals(arr_uuid_mask, p_uuid_mask->uu, mask_len * sizeof(guint8));
+
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+
+ param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
+ client_if, // client_if
+ action, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
+ BT_SCAN_FILTER_FEATURE_SERVICE_UUID, // filter_type
+ filt_index, // filter_index
+ company_id, // company_id
+ company_id_mask, // company_id_mask
+ arr_uuid_param, // p_uuid
+ arr_uuid_mask_param, // p_uuid_mask
+ "", // string
+ addr_type, // address_type
+ arr_data_param, // p_data
+ arr_data_mask_param);
+
+ ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
+ param, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_add_remove Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ g_array_free(arr_uuid, TRUE);
+ g_array_free(arr_uuid_mask, TRUE);
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ if (filt_type == BT_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID) {
+
+ arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
+ g_array_append_vals(arr_uuid, p_uuid->uu, data_len * sizeof(guint8));
+ g_array_append_vals(arr_uuid_mask, p_uuid_mask->uu, mask_len * sizeof(guint8));
+
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+
+ param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
+ client_if, // client_if
+ action, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
+ BT_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID, // filter_type
+ filt_index, // filter_index
+ company_id, // company_id
+ company_id_mask, // company_id_mask
+ arr_uuid_param, // p_uuid
+ arr_uuid_mask_param, // p_uuid_mask
+ "", // string
+ addr_type, // address_type
+ arr_data_param, // p_data
+ arr_data_mask_param);
+
+ ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_add_remove Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ g_array_free(arr_uuid, TRUE);
+ g_array_free(arr_uuid_mask, TRUE);
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ if (filt_type == BT_SCAN_FILTER_FEATURE_SERVICE_DATA) {
+
+ arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
+ g_array_append_vals(arr_data, p_data, data_len * sizeof(guint8));
+ g_array_append_vals(arr_data_mask, p_mask, mask_len * sizeof(guint8));
+
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_data->data, arr_data->len, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
+
+ param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
+ client_if, // client_if
+ action, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
+ BT_SCAN_FILTER_FEATURE_SERVICE_DATA, // filter_type
+ filt_index, // filter_index
+ company_id, // company_id
+ company_id_mask, // company_id_mask
+ arr_uuid_param, // p_uuid
+ arr_uuid_mask_param, // p_uuid_mask
+ "", // string
+ addr_type, // address_type
+ arr_data_param, // p_data
+ arr_data_mask_param);
+
+ ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_add_remove Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ g_array_free(arr_data, TRUE);
+ g_array_free(arr_data_mask, TRUE);
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ if (filt_type == BT_SCAN_FILTER_FEATURE_MANUFACTURER_DATA) {
+
+ arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
+ g_array_append_vals(arr_data, p_data, data_len * sizeof(guint8));
+ g_array_append_vals(arr_data_mask, p_mask, mask_len * sizeof(guint8));
+
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_data->data, arr_data->len, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
+
+ param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
+ client_if, // client_if
+ action, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
+ BT_SCAN_FILTER_FEATURE_MANUFACTURER_DATA, // filter_type
+ filt_index, // filter_index
+ company_id, // company_id
+ company_id_mask, // company_id_mask
+ arr_uuid_param, // p_uuid
+ arr_uuid_mask_param, // p_uuid_mask
+ "", // string
+ addr_type, // address_type
+ arr_data_param, // p_data
+ arr_data_mask_param);
+
+ ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_add_remove Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ g_array_free(arr_data, TRUE);
+ g_array_free(arr_data_mask, TRUE);
+
+ return BT_STATUS_SUCCESS;
+ }
+
return BT_STATUS_UNSUPPORTED;
}
/** Clear all scan filter conditions for specific filter index*/
bt_status_t scan_filter_clear(int client_if, int filt_index)
{
+ 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_clear",
+ g_variant_new("(ii)", client_if, filt_index),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error) {
+ ERR("scan_filter_clear Fail: %s", error->message);
+ g_clear_error(&error);
+ return BT_STATUS_FAIL;
+ }
+ if (ret)
+ g_variant_unref(ret);
+ return BT_STATUS_SUCCESS;
}
/** 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 */
.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;
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;
}
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;
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;
}
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;
}
}
}
gattc_data = g_malloc0(sizeof(hal_gattc_client_info_t));
- if (gattc_data == NULL) {
- ERR("Unable to allocate memory");
- ret = BT_STATUS_NOMEM;
- goto fail;
- }
memcpy(gattc_data->bd_addr.address, bd_addr->address,
BT_HAL_ADDRESS_LENGTH_MAX);
(GAsyncReadyCallback)__le_connection_req_cb, gattc_data);
return ret;
-
-fail:
- if (device_proxy)
- g_object_unref(device_proxy);
-
- g_free(gattc_data);
-
- return ret;
}
static bt_status_t _bt_hold_current_advertising()
if (is_advertising) {
DBG("+ Stop current advertising");
- ret = _bt_hal_enable_advertising(0, FALSE, FALSE);
+ ret = _bt_hal_enable_advertising(0, 0, FALSE, FALSE);
g_timeout_add(2000, __bt_hold_current_advertising_timeout_cb, NULL);
}
{
DBG("+ start current advertising");
- _bt_hal_enable_advertising(0, TRUE, FALSE);
+ _bt_hal_enable_advertising(0, 0, TRUE, FALSE);
return FALSE;
}
/*add gatt server connection info*/
gatt_conn_info = g_malloc0(sizeof(hal_gattc_server_info_t));
- if (gatt_conn_info == NULL) {
- ERR("Failed to allocate memory");
- goto fail;
- }
-
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);
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);
}
+gboolean _bt_hal_check_gattc_is_existing(const char *address)
+{
+ bt_bdaddr_t bd_addr;
+ _bt_hal_convert_addr_string_to_type(bd_addr.address, address);
+ if (__bt_find_gatt_client_info(&bd_addr) != NULL)
+ return TRUE;
+ else
+ return FALSE;
+}
+
void _bt_hal_handle_gattc_connected_event(char* address, gboolean gatt_connected)
{
int result = BT_STATUS_SUCCESS;
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;
}
}
}
+
+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));
+}