BT_HAL_GATT_REQUEST_TYPE_READ = 0x00, /* Read Requested */
BT_HAL_GATT_REQUEST_TYPE_WRITE = 0x01, /* Write Requested */
BT_HAL_GATT_REQUEST_TYPE_EXEC_WRITE = 0x02, /* Exec Write Requested */
+ BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_WRITE = 0x03, /* Exec Write Requested */
+ BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY = 0x04, /* Exec Write Requested */
} bt_gatt_request_type_e;
struct gatt_req_info {
" <interface name='org.bluez.GattCharacteristic1'>"
" <method name='ReadValue'>"
" <arg type='s' name='address' direction='in'/>"
-" <arg type='y' name='id' direction='in'/>"
+" <arg type='u' name='id' direction='in'/>"
" <arg type='q' name='offset' direction='in'/>"
" <arg type='ay' name='Value' direction='out'/>"
" </method>"
" <method name='WriteValue'>"
" <arg type='s' name='address' direction='in'/>"
-" <arg type='y' name='id' direction='in'/>"
+" <arg type='u' name='id' direction='in'/>"
" <arg type='q' name='offset' direction='in'/>"
+" <arg type='b' name='response_needed' direction='in'/>"
" <arg type='ay' name='value' direction='in'/>"
" </method>"
+" <method name ='AcquireWrite'>"
+" <arg type='a{sv}' name='properties' direction='in'/>"
+" <arg type='h' name='fd' direction='out'/>"
+" <arg type='q' name='mtu' direction='out'/>"
+" </method>"
+" <method name = 'AcquireNotify'>"
+" <arg type='a{sv}' name='properties' direction='in'/>"
+" <arg type='h' name='fd' direction='out'/>"
+" <arg type='q' name='mtu' direction='out'/>"
+" </method>"
" <method name='StartNotify'>"
" </method>"
" <method name='StopNotify'>"
" </property>"
" <property type='ao' name='Descriptors' access='read'>"
" </property>"
+" <property type='b' name='WriteAcquired' access='read'>"
+" </property>"
+" <property type='b' name='NotifyAcquired' access='read'>"
+" </property>"
" </interface>"
"</node>";
" </interface>"
"</node>";
-GSList *_bt_get_service_list_from_server(int instance)
+static GSList *_bt_get_service_list_from_server(int instance)
{
GSList *l;
INFO("Number of GATT Server apps [%d]", g_slist_length(gatt_server_apps));
return NULL;
}
-void _bt_remote_service_from_gatt_server(int instance, int service_handle)
+static void _bt_remote_service_from_gatt_server(int instance, int service_handle)
{
GSList *l;
GSList *l1;
}
}
-void _bt_hal_update_gatt_service_in_gatt_server(int slot, struct gatt_service_info *serv_info)
+static void _bt_hal_update_gatt_service_in_gatt_server(int slot, struct gatt_service_info *serv_info)
{
GSList *l;
for (l = gatt_server_apps; l; l = g_slist_next(l)) {
return NULL;
}
-char *__bt_gatt_find_char_path_from_handle(int char_hdl)
+static char *__bt_gatt_find_char_path_from_handle(int char_hdl)
{
GSList *l1, *l2;
return NULL;
}
-struct gatt_char_info *__bt_gatt_find_char_info_from_handle(int char_hdl)
+static struct gatt_char_info *__bt_gatt_find_char_info_from_handle(int char_hdl)
{
GSList *l1, *l2;
GSList *gatt_services = NULL;
int *instance;
instance = (int*)user_data;
+ gboolean writeAcquired = FALSE;
+ gboolean notifyAcquired = FALSE;
DBG("Getting values for service, chars and descriptors");
DBG("GATT Server App for which services are requested [%d]", *instance);
if (g_slist_length(gatt_services) == 0) {
ERR("No registered GATT services!!!!");
g_dbus_method_invocation_return_value(invocation, NULL);
+ g_variant_builder_unref(builder);
return;
}
for (i = 0; i < char_info->flags_length; i++) {
g_variant_builder_add(builder2, "s",
char_info->char_flags[i]);
+ if (strncmp(char_info->char_flags[i], "write-without-response", 16) == 0)
+ writeAcquired = TRUE;
+
+ if (strncmp(char_info->char_flags[i], "notify", 4) == 0)
+ notifyAcquired = TRUE;
}
flags_val = g_variant_new("as", builder2);
g_variant_new("b", notify));
/* Unicast */
+ g_variant_builder_add(inner_builder, "{sv}", "WriteAcquired",
+ g_variant_new("b", writeAcquired));
+
+ /* NotifyAcquired */
+ g_variant_builder_add(inner_builder, "{sv}", "NotifyAcquired",
+ g_variant_new("b", notifyAcquired));
+
+ /* Unicast */
unicast = g_strdup("00:00:00:00:00:00");
g_variant_builder_add(inner_builder, "{sv}", "Unicast",
g_variant_new("s", unicast));
struct gatt_client_info_t *conn_info = NULL;
struct gatt_req_info *req_info = NULL;
+ memset(&ev, 0, sizeof(ev));
+
DBG("WriteValue");
DBG("Application path = %s", object_path);
DBG("Sender = %s", sender);
}
len = g_variant_get_size(var);
- if (len > 0) {
+ if (len > 0 && len < 600) {
char *data;
data = (char *)g_variant_get_data(var);
memcpy(ev.value, data, len);
}
/* Send HAL event */
- memset(&ev, 0, sizeof(ev));
ev.conn_id = conn_info->connection_id;
ev.trans_id = req_id;
ev.att_handle = desc_hdl;
struct gatt_client_info_t *conn_info = NULL;
struct gatt_service_info *svc_info = NULL;
+ g_variant_get(parameters, "(&suq)",
+ &addr, &req_id, &offset);
+
+ DBG("Request id = %u, Offset = %u", req_id, offset);
DBG("Application path = %s", object_path);
DBG("Sender = %s", sender);
+ DBG("Address = %s", addr);
/* Check if device is already in connected list */
conn_info = __bt_find_remote_gatt_client_info(addr);
return;
}
- g_variant_get(parameters, "(&suq)", &addr, &req_id, &offset);
- DBG("Request id = %u, Offset = %u", req_id, offset);
-
/* Store requets information */
req_info = g_new0(struct gatt_req_info, 1);
req_info->attr_path = g_strdup(object_path);
req_info->svc_path = g_strdup(svc_info->serv_path);
req_info->request_id = req_id;
+ req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_READ;
req_info->offset = offset;
req_info->context = invocation;
/* Convert address to hex */
_bt_hal_convert_addr_string_to_type(ev.bdaddr, addr);
-
event_cb(HAL_EV_GATT_READ_REQUESTED, (void *)&ev, sizeof(ev));
return;
} else if (g_strcmp0(method_name, "WriteValue") == 0) {
gboolean response_needed = FALSE;
struct hal_ev_gatt_server_write_req ev;
int char_hdl = -1;
+ int len;
struct gatt_service_info *svc_info = NULL;
struct gatt_req_info *req_info = NULL;
struct gatt_client_info_t *conn_info = NULL;
+ memset(&ev, 0, sizeof(ev));
+
DBG("WriteValue");
DBG("Application path = %s", object_path);
DBG("Sender = %s", sender);
return;
}
+ len = g_variant_get_size(var);
+ if (len > 0 && len < 600) {
+ char *data;
+ data = (char *)g_variant_get_data(var);
+ memcpy(ev.value, data, len);
+ ev.length = len;
+ }
+
if (response_needed) {
/* Store requets information */
req_info = g_new0(struct gatt_req_info, 1);
req_info->attr_path = g_strdup(object_path);
req_info->svc_path = g_strdup(svc_info->serv_path);
req_info->request_id = req_id;
+ req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_WRITE;
req_info->offset = offset;
req_info->context = invocation;
}
/* Send HAL event */
- memset(&ev, 0, sizeof(ev));
ev.conn_id = conn_info->connection_id;
ev.trans_id = req_id;
ev.att_handle = char_hdl;
_bt_hal_convert_addr_string_to_type(ev.bdaddr, addr);
event_cb(HAL_EV_GATT_INDICATE_CFM, (void *)&ev, sizeof(ev));
+ } else if (g_strcmp0(method_name, "AcquireWrite") == 0) {
+
+ uint16_t mtu = 512;
+ int char_hdl = -1;
+ struct hal_ev_gatt_server_acquire_write_res ev;
+ struct gatt_service_info *svc_info = NULL;
+ struct gatt_req_info *req_info = NULL;
+ struct gatt_client_info_t *conn_info = NULL;
+ char * dev_path = NULL;
+ char * link = 0;
+ char addr[BT_HAL_ADDRESS_STRING_SIZE];
+
+ DBG("AcquireWrite");
+ DBG("Application path = %s", object_path);
+ DBG("Sender = %s", sender);
+
+ GVariantIter* iter;
+ g_variant_get(parameters, "(a{sv})", &iter);
+ char* key = NULL;
+ GVariant* value = NULL;
+ while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+ if (g_strcmp0(key, "MTU") == 0)
+ g_variant_get(value, "i", &mtu);
+ else if (g_strcmp0(key, "link") == 0)
+ g_variant_get(value, "s", &link);
+ else if (g_strcmp0(key, "device") == 0)
+ g_variant_get(value, "o", &dev_path);
+ }
+
+ DBG("AcquireWrite values retived");
+ DBG(" path %s LINK = %s, MTU = %u", addr, link, mtu);
+
+ svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
+
+ _bt_hal_convert_device_path_to_address(dev_path, addr);
+
+ DBG("remote address %s", addr);
+
+ /* Check if device is already in connected list */
+ conn_info = __bt_find_remote_gatt_client_info(addr);
+
+ if (conn_info == NULL) {
+ ERR("Cleint info not found\n");
+ goto done;
+ }
+
+ if (svc_info == NULL) {
+ ERR("svc_info info not found\n");
+ goto done;
+ }
+
+ /* Store requets information */
+ req_info = g_new0(struct gatt_req_info, 1);
+ req_info->attr_path = g_strdup(object_path);
+ req_info->svc_path = g_strdup(svc_info->serv_path);
+ req_info->request_id = conn_info->connection_id;
+ req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
+ req_info->offset = mtu;
+ req_info->context = invocation;
+
+ /* Append request info in list of requests for the particular connection */
+ conn_info->gatt_req_info_list = g_slist_append(conn_info->gatt_req_info_list, req_info);
+
+ /* Send HAL event */
+ memset(&ev, 0, sizeof(ev));
+ ev.conn_id = conn_info->connection_id;
+ ev.char_handl = char_hdl;
+ ev.mtu = mtu;
+ ev.trans_id = conn_info->connection_id;
+ _bt_hal_convert_addr_string_to_type(ev.bdaddr, addr);
+ event_cb(HAL_EV_GATT_SERVER_ACQUIRE_WRITE_RES, (void *)&ev, sizeof(ev));
+
+ DBG("HAL_EV_GATT_ACQUIRE_WRITE_RES called");
+
+
+ return;
+ } else if (g_strcmp0(method_name, "AcquireNotify") == 0) {
+
+ uint16_t mtu = 512;
+ int char_hdl = -1;
+ struct hal_ev_gatt_server_acquire_notify ev;
+ struct gatt_service_info *svc_info = NULL;
+ struct gatt_client_info_t *conn_info = NULL;
+ struct gatt_req_info *req_info = NULL;
+
+ DBG("AcquireNotify");
+ DBG("Application path = %s", object_path);
+ DBG("Sender = %s", sender);
+
+ GVariantIter* iter;
+ g_variant_get(parameters, "(a{sv})", &iter);
+ char* key = NULL;
+ GVariant* value = NULL;
+ while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+ if (g_strcmp0(key, "MTU") == 0)
+ g_variant_get(value, "q", &mtu);
+ }
+
+ DBG("AcquireNotify values retived");
+ DBG(" MTU = %u", mtu);
+
+ svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
+
+ if (svc_info == NULL) {
+ ERR("svc_info info not found\n");
+ goto done;
+ }
+
+ /* Store requets information */
+ req_info = g_new0(struct gatt_req_info, 1);
+ req_info->attr_path = g_strdup(object_path);
+ req_info->svc_path = g_strdup(svc_info->serv_path);
+ req_info->request_id = 33;
+ req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY;
+ req_info->offset = mtu;
+ req_info->context = invocation;
+
+ conn_info = g_new0(struct gatt_client_info_t, 1);
+ conn_info->addr = g_strdup(object_path);
+ INFO("Added GATT client path[%s]", conn_info->addr);
+ conn_info->connection_id = 33;
+ conn_info->instance_id = 33;
+ /* Append request info in list of requests for the particular connection */
+ conn_info->gatt_req_info_list = g_slist_append(conn_info->gatt_req_info_list, req_info);
+ gatt_client_info_list = g_slist_append(gatt_client_info_list, conn_info);
+
+ /* Send HAL event */
+ memset(&ev, 0, sizeof(ev));
+ ev.conn_id = 33;
+ ev.char_handl = char_hdl;
+ ev.mtu = mtu;
+ ev.trans_id = 33;
+
+ event_cb(HAL_EV_GATT_SERVER_ACQUIRE_NOTIFY_RES, (void *)&ev, sizeof(ev));
+
+ DBG("HAL_EV_GATT_ACQUIRE_NOTIFY_RES called");
+
+ return;
}
+done:
g_dbus_method_invocation_return_value(invocation, NULL);
}
-gboolean __bt_hal_gatt_emit_interface_removed(gchar *object_path, gchar *interface)
+static gboolean __bt_hal_gatt_emit_interface_removed(gchar *object_path, gchar *interface)
{
gboolean ret;
GError *error = NULL;
return BT_STATUS_SUCCESS;
}
-void _bt_hal_remove_gatt_server_from_list(int server_if)
+static void _bt_hal_remove_gatt_server_from_list(int server_if)
{
GSList *l;
struct gatt_server_app *info = NULL;
return BT_STATUS_SUCCESS;
}
-static bt_status_t gatt_server_close(int server_if, const bt_bdaddr_t *bd_addr, int conn_id)
+static void __le_disconnection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
{
- CHECK_BTGATT_INIT();
- return BT_STATUS_SUCCESS;
-}
+ GError *g_error = NULL;
+ GVariant *reply = NULL;
-static void __bt_gatt_close_gdbus_connection(void)
-{
- GError *err = NULL;
DBG("+");
- if (g_conn == NULL)
- return;
-
- if (!g_dbus_connection_flush_sync(g_conn, NULL, &err)) {
- ERR("Fail to flush the connection: %s", err->message);
- g_error_free(err);
- err = NULL;
- }
-
- if (!g_dbus_connection_close_sync(g_conn, NULL, &err)) {
- if (err) {
- ERR("Fail to close the dbus connection: %s", err->message);
- g_error_free(err);
+ reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
+ g_object_unref(proxy);
+ if (reply == NULL) {
+ ERR("Disconnect LE Dbus Call Error");
+ if (g_error) {
+ ERR("Error: %s\n", g_error->message);
+ g_clear_error(&g_error);
}
}
-
- g_object_unref(g_conn);
- g_conn = NULL;
- DBG("-");
+ g_variant_unref(reply);
}
-static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
+
+static bt_status_t gatt_server_close(int server_if, const bt_bdaddr_t *bd_addr, int conn_id)
{
- GDBusConnection *local_system_gconn = NULL;
- char *address;
- GError *err = NULL;
+ CHECK_BTGATT_INIT();
+
+ char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path;
+ GDBusProxy *device_proxy;
+ GDBusConnection *g_conn;
+ struct gatt_client_info_t *conn_info = NULL;
+
+ INFO("+");
+ if (NULL == bd_addr) {
+ ERR("bd_addr is NULL");
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ /* GDBUS Connection Info validate */
+ g_conn = _bt_hal_get_system_gconn();
if (g_conn == NULL) {
- address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (address == NULL) {
- if (err) {
- ERR("Failed to get bus address: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
+ ERR("Could not get System DBUS Connection");
+ return BT_STATUS_FAIL;
+ }
- g_conn = g_dbus_connection_new_for_address_sync(address,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- NULL, /* GDBusAuthObserver */
- NULL,
- &err);
- if (!g_conn) {
- if (err) {
- ERR("Unable to connect to dbus: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
- } else if (g_dbus_connection_is_closed(g_conn)) {
- address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (address == NULL) {
- if (err) {
- ERR("Failed to get bus address: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
+ /* Connection Info validate */
+ conn_info = __bt_find_remote_gatt_client_info_from_conn(conn_id);
+ if (conn_info == NULL) {
+ ERR("No Connection Inforamtion!!!");
+ return BT_STATUS_FAIL;
+ }
- local_system_gconn = g_dbus_connection_new_for_address_sync(address,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- NULL, /* GDBusAuthObserver */
- NULL,
- &err);
+ _bt_hal_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->address);
- if (!local_system_gconn) {
- ERR("Unable to connect to dbus: %s", err->message);
- g_clear_error(&err);
- }
+ //check if connection has the same device address
+ if (g_strcmp0(conn_info->addr, device_address) != 0) {
+ ERR("device address [%s] does not match", device_address);
+ return BT_STATUS_FAIL;
+ }
- g_conn = local_system_gconn;
+ device_path = _bt_hal_get_device_object_path(conn_info->addr);
+ if (device_path == NULL) {
+ ERR("device_path is NULL");
+ return BT_STATUS_PARM_INVALID;
}
- return g_conn;
+ device_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_HAL_BLUEZ_NAME,
+ device_path, BT_HAL_DEVICE_INTERFACE, NULL, NULL);
+
+
+ g_free(device_path);
+ if (device_proxy == NULL)
+ return BT_STATUS_FAIL;
+
+ INFO("Disconnect LE [%s]", device_address);
+
+ g_dbus_proxy_call(device_proxy, "DisconnectLE",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_HAL_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__le_disconnection_req_cb, conn_info);
+
+ INFO("-");
+ return BT_STATUS_SUCCESS;
}
static char* __bt_hal_convert_uuid_to_string(bt_uuid_t *srvc_id)
return strdup(uuid);
}
-int __bt_hal_add_service_to_dbus(char *app_path, int slot, btgatt_srvc_id_t *srvc_id)
+static int __bt_hal_add_service_to_dbus(char *app_path, int slot, btgatt_srvc_id_t *srvc_id)
{
+ gboolean ret;
/* For GATT service specific */
GDBusNodeInfo *node_info;
guint object_id;
g_variant_builder_add(builder, "{sa{sv}}",
GATT_SERV_INTERFACE, inner_builder);
- g_dbus_connection_emit_signal(g_conn, NULL, "/",
+ ret = g_dbus_connection_emit_signal(g_conn, NULL, "/",
"org.freedesktop.Dbus.ObjectManager",
"InterfacesAdded",
g_variant_new("(oa{sa{sv}})",
path, builder),
&error);
+ if (!ret) {
+ if (error) {
+ /* dbus gives error cause */
+ ERR("d-bus api failure: errcode[%x], message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
+ }
/* Send Service handle to application */
user_data = g_malloc0(sizeof(hal_gatt_service_added));
char *app_path = (char*)user_data;
INFO("UnregisterApplication is completed app [%s]", app_path);
GError *error = NULL;
- GVariant *result;
+ GVariant *result = NULL;
+ if (manager_gproxy)
result = g_dbus_proxy_call_finish(manager_gproxy, res, &error);
if (result == NULL) {
if (gatt_server_apps == NULL) {
INFO("All GATT servers are removed, clean all DBUS resources");
if (owner_id) {
- /* unregister the exported interface for object manager
- g_conn and manager_id are common for all GATT servers */
- g_dbus_connection_unregister_object(g_conn,
- manager_id);
+ /* unregister the exported interface for object manager */
+ g_dbus_connection_unregister_object(g_conn, manager_id);
manager_id = 0;
g_bus_unown_name(owner_id);
owner_id = 0;
g_object_unref(manager_gproxy);
manager_gproxy = NULL;
-
- /* Close the GDBUS connection */
- __bt_gatt_close_gdbus_connection();
}
}
INFO("-");
}
-int __bt_hal_gatt_init(void)
+static int __bt_hal_gatt_init(void)
{
- GDBusConnection *conn = NULL;
DBG("+");
+
/* Only once for ALL GATT Servers */
if (owner_id == 0) {
- owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- BT_GATT_SERVICE_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL, NULL);
- }
- INFO("Owner ID [%d]", owner_id);
+ GError *err = NULL;
+ gchar *name = NULL;
- /* Only once for ALL GATT Servers conn = g_conn(global)*/
- conn = __bt_gatt_get_gdbus_connection();
- if (!conn) {
- ERR("Unable to get connection");
- return BT_STATUS_FAIL;
+ g_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (!g_conn) {
+ if (err) {
+ ERR("Unable to connect to gdbus: %s", err->message);
+ g_clear_error(&err);
+ }
+ return BT_STATUS_FAIL;
+ }
+
+ name = g_strdup_printf("%s.p%d", BT_GATT_SERVICE_NAME, getpid());
+ INFO("well-known name: %s", name);
+
+ owner_id = g_bus_own_name_on_connection(g_conn, name,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL, NULL);
}
+ INFO("Owner ID [%d]", owner_id);
/* Only once for ALL GATT Servers */
if (manager_node_info == NULL) {
return BT_STATUS_SUCCESS;
}
-void _bt_hal_is_gatt_server_initialzed(int slot, char **app_path)
+static void _bt_hal_is_gatt_server_initialzed(int slot, char **app_path)
{
GSList *l;
*app_path = NULL;
}
-void _bt_hal_update_gatt_server_path(int slot, char *app_path)
+static void _bt_hal_update_gatt_server_path(int slot, char *app_path)
{
if (app_path == NULL)
return;
char *app_path = NULL;
GError *error = NULL;
int *app_id = NULL;
- guint manager_id;
int result = BT_STATUS_SUCCESS;
g_error_free(error);
goto failed;
}
+ INFO("manager_id [%d]", manager_id);
/* For current GATT Server, app_path is created, save it in Table */
_bt_hal_update_gatt_server_path(server_if, app_path);
len = g_slist_length(gatt_services);
l = g_slist_nth(gatt_services, len -1);
+ if (NULL == l)
+ return FALSE;
info = l->data;
bt_uuid_t *uuid, int properties,
int permissions)
{
+ gboolean ret;
GError *error = NULL;
guint object_id;
GDBusNodeInfo *node_info;
GATT_CHAR_INTERFACE,
inner_builder);
- g_dbus_connection_emit_signal(g_conn, NULL, "/",
+ ret = g_dbus_connection_emit_signal(g_conn, NULL, "/",
"org.freedesktop.Dbus.ObjectManager",
"InterfacesAdded",
g_variant_new("(oa{sa{sv}})",
path, builder),
&error);
+ if (!ret) {
+ if (error) {
+ /* dbus gives error cause */
+ ERR("d-bus api failure: errcode[%x], message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
+ }
//*char_path = g_strdup(path);
g_variant_new("(oa{sa{sv}})",
path, builder),
&error);
+ if (error != NULL) {
+ ERR("g_dbus_connection_emit_signal failed: errCode[%x], message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
//*desc_path = g_strdup(path);
{
struct gatt_service_info *svc_info = NULL;
GSList *l = NULL;
-
for (l = gatt_services; l; l = g_slist_next(l)) {
svc_info = (struct gatt_service_info *)l->data;
- if (svc_info->serv_path == service_path) {
+
+
+ if (!g_strcmp0(svc_info->serv_path, service_path)) {
DBG("Return the state of the gatt service %d",
svc_info->is_svc_registered);
return svc_info->is_svc_registered;
g_variant_builder_add(outer_builder, "{sv}", "Notifying",
g_variant_new("b", notify));
- _bt_hal_convert_addr_type_to_string(addr, (unsigned char *)conn_info->addr);
+ memcpy(addr, conn_info->addr, BT_HAL_ADDRESS_STRING_SIZE);
+ DBG("Send Indication to Unicast addr [%s]", addr);
g_variant_builder_add(outer_builder, "{sv}", "Unicast",
g_variant_new("s", addr));
}
DBG("Reponse Value length [%d]", response->attr_value.len);
+ DBG("Request type: [%d]", req_info->request_type);
+
/* DEBUG */
for (i = 0; i < response->attr_value.len; i++)
- DBG("Resonse [%d] = [0x%x]", response->attr_value.value[i]);
-
+ DBG("Resonse [%d] = [0x%x]", i, response->attr_value.value[i]);
if (req_info->request_type == BT_HAL_GATT_REQUEST_TYPE_READ) {
GVariantBuilder *inner_builder = NULL;
return BT_STATUS_SUCCESS;
}
+
+static bt_status_t gatt_server_send_acquire_response(int conn_id, int trans_id,
+ int status, int fd, int mtu, void *fdlist)
+{
+ CHECK_BTGATT_INIT();
+
+ struct gatt_req_info *req_info = NULL;
+ struct gatt_client_info_t *conn_info = NULL;
+
+ DBG("GATT Server Send Response Conn ID [%d]", conn_id);
+
+ conn_info = __bt_find_remote_gatt_client_info_from_conn(conn_id);
+ if (conn_info == NULL) {
+ ERR("No Connection Inforamtion!!!");
+ return BT_STATUS_FAIL;
+ }
+
+ req_info = __bt_find_remote_gatt_client_request_info(conn_id, trans_id);
+ if (req_info == NULL) {
+ ERR("No Request Inforamtion!!!");
+ return BT_STATUS_FAIL;
+ }
+
+ if (status != BT_STATUS_SUCCESS) {
+ ERR("resp_state is 0x%X", status);
+
+ g_dbus_method_invocation_return_dbus_error(req_info->context,
+ "org.bluez.Error.Failed", "Application Error");
+
+ conn_info->gatt_req_info_list = g_slist_remove(conn_info->gatt_req_info_list, req_info);
+
+ req_info->context = NULL;
+ if (req_info->attr_path)
+ g_free(req_info->attr_path);
+ if (req_info->svc_path)
+ g_free(req_info->svc_path);
+ g_free(req_info);
+
+ return BT_STATUS_SUCCESS;
+ }
+
+
+ if (req_info->request_type == BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_WRITE) {
+
+ INFO("GATT Server Send Response BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_WRITE to bluez %d\n", fd);
+ g_dbus_method_invocation_return_value_with_unix_fd_list(
+ req_info->context, g_variant_new("(hq)", 0, mtu), (GUnixFDList*)fdlist);
+
+ } else if (req_info->request_type == BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY) {
+
+ INFO("GATT Server Send Response BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY to bluez %d\n", fd);
+ g_dbus_method_invocation_return_value_with_unix_fd_list(
+ req_info->context, g_variant_new("(hq)", 0, mtu), (GUnixFDList*)fdlist);
+
+ } else {
+ g_dbus_method_invocation_return_value(req_info->context, NULL);
+ }
+ conn_info->gatt_req_info_list = g_slist_remove(conn_info->gatt_req_info_list, req_info);
+
+ req_info->context = NULL;
+ if (req_info->attr_path)
+ g_free(req_info->attr_path);
+ if (req_info->svc_path)
+ g_free(req_info->svc_path);
+ g_free(req_info);
+
+ return BT_STATUS_SUCCESS;
+}
+
+
static bt_status_t gatt_server_update_att_value(int server_if, int attribute_handle,
int value_length, char* att_value)
{
update_value = g_variant_new("ay", inner_builder);
- outer_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
g_variant_builder_add(outer_builder, "{sv}", "Value",
update_value);
}
const btgatt_server_interface_t btgatt_server_interface = {
- gatt_server_register_app,
- gatt_server_unregister_app,
- gatt_server_open,
- gatt_server_close,
- gatt_server_add_service,
- gatt_server_add_included_service,
- gatt_server_add_characteristic,
- gatt_server_add_descriptor,
- gatt_server_start_service,
- gatt_server_stop_service,
- gatt_server_delete_service,
- gatt_server_send_indication,
- gatt_server_send_response,
- gatt_server_update_att_value,
- gatt_server_listen,
- gatt_server_set_adv_data,
- gatt_server_multi_adv_enable,
- gatt_server_multi_adv_update,
- gatt_server_multi_adv_set_inst_data,
- gatt_server_multi_adv_disable,
- gatt_server_get_mtu_size
+ .register_server = gatt_server_register_app,
+ .unregister_server = gatt_server_unregister_app,
+ .connect = gatt_server_open,
+ .disconnect = gatt_server_close,
+ .add_service = gatt_server_add_service,
+ .add_included_service = gatt_server_add_included_service,
+ .add_characteristic = gatt_server_add_characteristic,
+ .add_descriptor = gatt_server_add_descriptor,
+ .start_service = gatt_server_start_service,
+ .stop_service = gatt_server_stop_service,
+ .delete_service = gatt_server_delete_service,
+ .send_indication = gatt_server_send_indication,
+ .send_response = gatt_server_send_response,
+ .update_att_value = gatt_server_update_att_value,
+ .listen = gatt_server_listen,
+ .set_adv_data = gatt_server_set_adv_data,
+ .multi_adv_enable = gatt_server_multi_adv_enable,
+ .multi_adv_update = gatt_server_multi_adv_update,
+ .multi_adv_set_inst_data = gatt_server_multi_adv_set_inst_data,
+ .multi_adv_disable = gatt_server_multi_adv_disable,
+ .get_att_mtu = gatt_server_get_mtu_size,
+ .send_response_acquire = gatt_server_send_acquire_response
};