Server with characterstics property 'write-without-response' will receive the data
on socket file descriptor.AcquireWrite method handler is implemented in OAL
Change-Id: I4b8134b8eda87f775ebf72b5e98ce6753e6a9b84
Signed-off-by: Avichal Agarwal <avichal.a@samsung.com>
#include "bt-event-handler.h"
#include "bt-gatt-client.h"
#include "bt-request-sender.h"
+#include "bt-gatt-server.h"
#define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
#define BT_RELIABLE_DISABLE_TIME 300 /* 300 ms */
_bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
result, &read_info,
event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_GATT_SERVER_ACQUIRE_WRITE) == 0) {
+
+ bluetooth_gatt_server_send_acquire_response(parameters);
+
} else if (strcasecmp(signal_name, BT_GATT_SERVER_NOTIFICATION_COMPLETED) == 0) {
const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
#include<unistd.h>
#include<stdint.h>
#include<stdbool.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <gio/gunixfdlist.h>
#include "bt-common.h"
/* TODO_40 : 4.0 merge - Need to check why includes bt-event-handler.h */
return result;
}
+
+static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
+ GIOCondition cond, gpointer data)
+{
+
+ bluetooth_gatt_server_acquire_write_info_t *write_data = (bluetooth_gatt_server_acquire_write_info_t*)data;
+
+ BT_INFO("FD io write data received remote adress [%s]\n", write_data->adress);
+
+ if (cond & G_IO_IN) {
+ GIOStatus status = G_IO_STATUS_NORMAL;
+ GError *err = NULL;
+ char *buffer = NULL;
+ gsize len = 0;
+ int BUF = BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX;
+
+ buffer = g_malloc0(BUF);
+
+ status = g_io_channel_read_chars(gio, buffer,
+ BUF, &len, &err);
+
+ if (status != G_IO_STATUS_NORMAL) {
+ BT_ERR("IO Channel read is failed with %d", status);
+ g_free(buffer);
+ if (err) {
+ BT_ERR("IO Channel read error [%s]", err->message);
+ if (status == G_IO_STATUS_ERROR) {
+ BT_ERR("cond : %d", cond);
+ g_error_free(err);
+ g_io_channel_shutdown(gio, TRUE, NULL);
+ g_io_channel_unref(gio);
+
+ return FALSE;
+ }
+ g_error_free(err);
+ }
+ return FALSE;
+ }
+
+ if (len > 0) {
+
+ BT_INFO(" FD io sending value changed %s %d \n", buffer, len);
+
+
+ bluetooth_gatt_server_write_requested_info_t write_info;
+ if (len < BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX)
+ memcpy(write_info.data.data, buffer, len);
+
+ write_info.length = len;
+ write_info.need_resp = false;
+ write_info.attribute_handle = write_data->attribute_handle;
+ //memcpy()
+ _bt_convert_addr_string_to_type(write_info.device_address.addr, write_data->adress);
+ write_info.connection_id = write_data->connection_id;
+ write_info.offset = write_data->offset;
+ write_info.request_id = -2;
+
+ BT_INFO("ACQUIRING EVENT \n");
+
+ bt_event_info_t *event_info;
+ event_info = _bt_event_get_cb_data(BT_GATT_SERVER_EVENT);
+
+ if (event_info) {
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
+ BLUETOOTH_ERROR_NONE, &write_info,
+ event_info->cb, event_info->user_data);
+ } else {
+ BT_ERR("eventinfo failed");
+ }
+
+
+ }
+ g_free(buffer);
+
+ return TRUE;
+ }
+
+ if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
+ BT_ERR("Error : GIOCondition %d, ]", cond);
+ g_io_channel_shutdown(gio, TRUE, NULL);
+ g_io_channel_unref(gio);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void bluetooth_gatt_server_send_acquire_response(GVariant * parameters)
+{
+ int con_id = -1;
+ int tran_id = -1;
+ int att_han = -1;
+ int pipefd[2] = {-1,};
+ int mtu = -1;
+ int offset = -1;
+ char err_msg[512] = {'\0'};
+ GIOChannel *channel = NULL;
+ char *addr = NULL;
+ int result = -1;
+
+ g_variant_get(parameters, "(iiiiii&s)",
+ &result,
+ &con_id,
+ &tran_id,
+ &att_han,
+ &mtu,
+ &offset,
+ &addr);
+
+ BT_DBG("GATT Server Acquire Write From Remote Client [%s]", addr);
+ BT_DBG("GATT ServerAcquire Conn ID: [%d]", con_id);
+ BT_DBG("GATT Server Acquire write att handle:[%d]", att_han);
+ BT_DBG("GATT Server Acquire Write Offset: [%d]", offset);
+
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipefd) < 0) {
+ strerror_r(errno, err_msg, sizeof(err_msg));
+ BT_ERR("socketpair(): %s", err_msg);
+ return ;
+ }
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ //param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+ bluetooth_gatt_server_acquire_response_params_t data;
+ data.req_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
+ data.fd = pipefd[1];
+ data.mtu = mtu;
+ data.request_id = tran_id;
+
+ bluetooth_gatt_server_acquire_write_info_t *write_info = g_malloc0(sizeof(bluetooth_gatt_server_acquire_write_info_t)) ;
+
+ write_info->attribute_handle = att_han;
+ write_info->connection_id = tran_id;
+ write_info->offset = offset;
+
+ memcpy(write_info->adress, addr , BLUETOOTH_ADDRESS_STRING_LENGTH);
+
+ BT_INFO("FD read %d remote adress [%s ] \n", pipefd[0], addr);
+
+
+ channel = g_io_channel_unix_new(pipefd[0]);
+ g_io_channel_set_encoding(channel, NULL, NULL);
+ g_io_channel_set_buffered(channel, FALSE);
+ g_io_channel_set_close_on_unref(channel, TRUE);
+ g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP),
+ bluetooth_gatt_server_acquire_channel_write_cb, write_info);
+
+
+ GUnixFDList *fd_list = g_unix_fd_list_new();
+ GError *error = NULL;
+
+ g_unix_fd_list_append(fd_list, pipefd[1], &error);
+ g_assert_no_error(error);
+ close(pipefd[1]);
+
+ g_array_append_vals(in_param1, &data, sizeof(bluetooth_gatt_server_acquire_response_params_t));
+
+ BT_INFO("Sending event BT_GATT_SERVER_ACQURE_WRITE_RESPONSE file descriptor value [%d] [ %s],", data.fd, addr);
+
+ result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_GATT_SERVER_ACQURE_WRITE_RESPONSE,
+ in_param1, in_param2, in_param3, in_param4, fd_list, &out_param, NULL);
+
+ BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+}
+
--- /dev/null
+#ifndef _BT_GATT_SERVER_H_
+#define _BT_GATT_SERVER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+void bluetooth_gatt_server_send_acquire_response(GVariant * parameter);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_BT_GATT_SERVER_H_*/
<policy user="root">
<!-- service name(org.bt.frwk.p<pid>) is changeable by pid -->
<allow own_prefix="org.bt.frwk"/>
+ <allow send_interface="org.bluez.GattCharacteristic1"/>
+ <allow send_destination="org.bluez"/>
+ <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
<allow send_interface="org.bluez.Profile1" send_member="NewConnection"/>
<allow send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
</policy>
<policy group="network_fw">
<!-- service name(org.bt.frwk.p<pid>) is changeable by pid -->
<allow own_prefix="org.bt.frwk"/>
+ <allow send_interface="org.bluez.GattCharacteristic1"/>
+ <allow send_destination="org.bluez"/>
+ <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
<allow send_interface="org.bluez.Profile1" send_member="NewConnection"/>
<allow send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
</policy>
<policy context="default">
<deny own_prefix="org.bt.frwk"/>
+ <deny send_interface="org.bluez.GattCharacteristic1"/>
+ <deny send_destination="org.bluez"/>
+ <deny send_interface="org.freedesktop.DBus.ObjectManager"/>
<deny send_interface="org.bluez.Profile1" send_member="NewConnection"/>
<deny send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
</policy>
</busconfig>
+
uint8_t svc_uuid[16];
uint8_t char_uuid[16];
} __attribute__((packed));
+
+#define HAL_EV_GATT_SERVER_ACQUIRE_WRITE_RES 0XC9
+struct hal_ev_gatt_server_acquire_write_res {
+ int32_t mtu;
+ int32_t trans_id;
+ int32_t conn_id;
+ int32_t char_handl;
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+
+
#endif //_BT_HAL_MSG_H_
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 {
" <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>";
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);
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));
_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 adress %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) {
+
+
+ }
+done:
g_dbus_method_invocation_return_value(invocation, 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;
+ int i;
+
+ 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) {
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("(hq)", fd, mtu));
+ } 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)
{
gatt_server_multi_adv_update,
gatt_server_multi_adv_set_inst_data,
gatt_server_multi_adv_disable,
- gatt_server_get_mtu_size
+ gatt_server_get_mtu_size,
+ gatt_server_send_acquire_response
};
ev->is_prep, ev->value);
}
+static void __bt_hal_handle_gatt_server_acquire_write_requested(void *buf, uint16_t len)
+{
+ struct hal_ev_gatt_server_acquire_write_res *ev = buf;
+
+ DBG("acquire write requested event recived");
+
+ if (bt_gatt_callbacks->server->request_acquire_write_cb)
+ bt_gatt_callbacks->server->request_acquire_write_cb(ev->mtu, ev->conn_id, ev->trans_id, ev->char_handl, (bt_bdaddr_t *)ev->bdaddr);
+}
+
static void __bt_hal_handle_gatt_server_indicate_confirmed(void *buf, uint16_t len)
{
struct hal_ev_gatt_server_indicate_cfm *ev = buf;
-
if (bt_gatt_callbacks->server->indication_confirmation_cb)
bt_gatt_callbacks->server->indication_confirmation_cb(ev->conn_id, ev->trans_id,
ev->att_handle, (bt_bdaddr_t *) ev->bdaddr);
__bt_handle_gatt_client_watch_notification(buf, len);
break;
}
+ case HAL_EV_GATT_SERVER_ACQUIRE_WRITE_RES:{
+ __bt_hal_handle_gatt_server_acquire_write_requested(buf, len);
+ break;
+ }
+
default:
DBG("Event Currently not handled!!");
break;
int attr_handle, int offset, int length,
bool need_rsp, bool is_prep, uint8_t* value);
+/**
+ * Callback invoked when a remote device has requested to acqiore write to a
+ * characteristic .
+ */
+typedef void (*request_acquire_write_callback)(int mtu, int conn_id, int trans_id,
+ int attr_handle, bt_bdaddr_t *bda);
+
/** Callback invoked when a previously prepared write is to be executed */
typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
bt_bdaddr_t *bda, int exec_write);
+
+
/**
* Callback triggered in response to send_response if the remote device
* sends a confirmation.
#ifdef TIZEN_BT_HAL
notification_enabled_callback notif_enabled_cb;
#endif
+ request_acquire_write_callback request_acquire_write_cb;
} btgatt_server_callbacks_t;
/** Represents the standard BT-GATT server interface. */
/* Get current att mtu size of active connection */
bt_status_t (*get_att_mtu)(int conn_id, int *mtu_size);
+
+ /** Send a response to a acquire write/notify operation */
+ bt_status_t (*send_response_acquire)(int conn_id, int trans_id,
+ int status, int fd, int mtu, void *);
} btgatt_server_interface_t;
__END_DECLS
EVENT(OAL_EVENT_GATTC_SERVICE_CHANGED_IND) /* gattc service changed indication */\
EVENT(OAL_EVENT_GATTC_PREPARE_WRITE) /* gattc prepare write */\
EVENT(OAL_EVENT_GATTC_EXECUTE_WRITE) /* gattc execute write */\
+ EVENT(OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE) /* gattc acquire write */\
+ EVENT(OAL_EVENT_GATTS_REQUEST_ACQUIRE_NOTIFY) /* gattc acquire notify */\
EVENT(OAL_EVENT_END) /* End of event*/\
typedef struct {
gatts_trans_attr_t attr_trans;
+ int mtu;
+ bt_address_t address;
+} event_gatts_srvc_acquire_attr_t ;
+
+typedef struct {
+ gatts_trans_attr_t attr_trans;
int length;
bt_address_t address;
uint8_t value[OAL_GATT_MAX_ATTR_LEN];
oal_status_t gattc_write_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id, oal_gatt_write_type_t write_type,
int len, oal_gatt_auth_req_t auth_req, char* data);
+oal_status_t gattc_acquire_notify(int conn_id, oal_gatt_srvc_id_t *srvc_id,
+ oal_gatt_id_t *char_id, int *fd , char *path);
+
+oal_status_t gattc_acquire_write(int conn_id, oal_gatt_srvc_id_t *srvc_id,
+ oal_gatt_id_t *char_id, oal_gatt_auth_req_t auth_req , int *fd , char *path);
+
oal_status_t gattc_write_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id, oal_gatt_id_t *desc_id,
oal_gatt_write_type_t write_type, int len, oal_gatt_auth_req_t auth_req, char* data);
oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
+
+oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
+ int status, int fd, int mtu, void *);
+
#endif /* OAL_GATT_H_ */
bool need_rsp, bool is_prep, uint8_t* value);
static void cb_gatts_response_confirmation(int status, int handle);
+static void cb_gatts_acquire_write(int fd, int conn_id, int trans_id, int attr_handle, bt_bdaddr_t*);
+
static void cb_indication_confirmation(int conn_id, int trans_id, int attr_handle, bt_bdaddr_t *bda);
static void cb_gatts_connection(int conn_id, int server_if, int connected, bt_bdaddr_t *bda);
#ifdef TIZEN_BT_HAL
cb_notifcation_changed,
#endif
+ cb_gatts_acquire_write
};
/* Forward declaration for GATT client callbacks */
BT_INFO("Current ATT MTU Size: %d", *mtu);
return OAL_STATUS_SUCCESS;
}
+oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
+ int status, int fd, int mtu , void * fdlist)
+{
+ int ret = OAL_STATUS_SUCCESS;
+
+ API_TRACE("Server Send Response : ConnId = %d, TransId = %d, %d", conn_id, trans_id, fd);
+ CHECK_OAL_GATT_ENABLED();
+
+ ret = gatt_api->server->send_response_acquire(conn_id, trans_id, status, fd, mtu, fdlist);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT Server Send Response failed: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+ return OAL_STATUS_SUCCESS;
+}
oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id,
int num_handles)
{
send_event(OAL_EVENT_GATTS_REQUEST_WRITE, event, sizeof(event_gatts_srvc_write_attr_t));
}
+static void cb_gatts_acquire_write(int mtu, int conn_id, int trans_id, int attr_handle , bt_bdaddr_t *bda)
+
+{
+ BT_INFO("BTGATT SERVER REQUEST ACQUIRE WRITE conn_id:%d", conn_id);
+
+ event_gatts_srvc_acquire_attr_t* event = g_new0(event_gatts_srvc_acquire_attr_t, 1);
+
+ event->attr_trans.attr_handle = attr_handle;
+ event->attr_trans.conn_id = conn_id;
+ event->attr_trans.trans_id = trans_id;
+ event->mtu = mtu;
+ memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
+
+ send_event(OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE, event, sizeof(event_gatts_srvc_acquire_attr_t));
+}
+
static void cb_gatts_response_confirmation(int status, int handle)
{
BT_INFO("BTGATT SERVER RESPONSE CONFIRMATION CB, status:%d, handle:%d", status, handle);
break;
}
+ case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
+
+ bluetooth_gatt_server_acquire_response_params_t param;
+ char *app;
+ GDBusMessage *msg;
+ msg = g_dbus_method_invocation_get_message(context);
+ GUnixFDList *fd_list;
+ int fd = -1;;
+ int *fd_list_array;
+ int len;
+
+ BT_ERR("sending acquire write respose \n");
+
+ fd_list = g_dbus_message_get_unix_fd_list(msg);
+
+ memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
+
+ app = (char*)g_dbus_method_invocation_get_sender(context);
+
+ __bt_service_get_parameters(in_param1, ¶m,
+ sizeof(bluetooth_gatt_server_acquire_response_params_t));
+
+ BT_ERR("sending acquire write respose sent \n ");
+
+ fd_list_array = g_unix_fd_list_peek_fds(fd_list, &len);
+ BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
+ fd = fd_list_array[0];
+
+ param.fd = fd;
+ result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
+
+ break;
+ }
case BT_GATT_SERVER_SEND_INDICATION: {
bluetooth_gatt_server_indication_params_t param;
bluetooth_gatt_att_data_t data;
case BT_GATT_SERVER_STOP_SERVICE:
case BT_GATT_SERVER_DELETE_SERVICE:
case BT_GATT_SERVER_SEND_RESPONSE:
+ case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
case BT_GATT_SERVER_SEND_INDICATION:
case BT_GATT_SERVER_UPDATE_VALUE:
case BT_GATT_SERVER_DEREGISTER:
case OAL_EVENT_GATTS_REQUEST_READ: /* gatts Request Read from client */\
case OAL_EVENT_GATTS_REQUEST_WRITE: /* gatts Request Write from client */\
case OAL_EVENT_GATTS_IND_CONFIRM: /* gatts Indicate confirmation from remote client */\
+ case OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE:
+ case OAL_EVENT_GATTS_REQUEST_ACQUIRE_NOTIFY:
/* Tizen Platform Specific */
case OAL_EVENT_GATTS_NOTIFICATION: /* gatts Notification changed event */\
case OAL_EVENT_GATTS_MTU_CHANGED: /* gatts MTU changed event */\
case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED:
signal = BT_GATT_SERVER_NOTIFICATION_CHANGED;
break;
+ case BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE:
+ signal = BT_GATT_SERVER_ACQUIRE_WRITE;
+ break;
#endif
#ifdef TIZEN_GATT_CLIENT
case BLUETOOTH_EVENT_GATT_READ_CHAR: /* GATT Client */
}
#endif
+
+static void __bt_handle_gatt_server_acquire_write_requested(event_gatts_srvc_acquire_attr_t *event)
+{
+ GVariant *param = NULL;
+ int result = BLUETOOTH_ERROR_NONE;
+ struct gatt_server_req_info *req_info = NULL;
+ bluetooth_device_address_t dev_addr;
+ char adress[BT_ADDRESS_STRING_SIZE] = {'/0',};
+ ;
+ BT_INFO("GATT Server ACQUIRE Write Req Connection ID: [%d]", event->attr_trans.conn_id);
+ BT_INFO("GATT Server ACQUIRE Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
+ BT_INFO("GATT Server ACQUIRE Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
+
+ //adress = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ memcpy(dev_addr.addr, event->address.addr, 6);
+
+ req_info = g_new0(struct gatt_server_req_info, 1);
+ req_info->request_id = event->attr_trans.trans_id;
+ req_info->attribute_handle = event->attr_trans.attr_handle;
+ req_info->connection_id = event->attr_trans.conn_id;
+ req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
+ gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
+
+ _bt_convert_addr_type_to_string(adress,
+ (unsigned char *)dev_addr.addr);
+
+ param = g_variant_new("(iiiiiis)", result,
+ event->attr_trans.conn_id,
+ event->attr_trans.trans_id,
+ event->attr_trans.attr_handle,
+ event->mtu, event->attr_trans.offset, adress);
+ BT_INFO("GATT Server ACQUIRE Write Req Attribute remote adress : [%s]", adress);
+
+
+ _bt_send_event(BT_GATT_SERVER_EVENT,
+ BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE,
+ param);
+}
+
static void __bt_handle_gatt_server_write_requested(event_gatts_srvc_write_attr_t *event)
{
char *address;
__bt_handle_gatt_server_write_requested((event_gatts_srvc_write_attr_t *)event_data);
break;
}
+ case OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE: {
+ BT_INFO("OAL Event: GATT Server Acquire Write Request");
+ __bt_handle_gatt_server_acquire_write_requested((event_gatts_srvc_acquire_attr_t*)event_data);
+ break;
+ }
case OAL_EVENT_GATTS_IND_CONFIRM: {
BT_INFO("OAL Event: GATT Server Indication confirmed");
__bt_handle_gatt_server_indicate_confirmed((event_gatts_ind_cnfrm_t *)event_data);
return BLUETOOTH_ERROR_NONE;
}
+int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param , void *fd_list)
+{
+ BT_CHECK_PARAMETER(sender, return);
+ BT_CHECK_PARAMETER(param, return);
+ struct gatt_server_req_info *req_info = NULL;
+ int ret = OAL_STATUS_SUCCESS;
+
+
+ BT_INFO("GATT acquire Server Response: Req Type [%d] req_id [%d] fd [%d] mtu[%d]",
+ param->req_type, param->request_id,
+ param->fd,
+ param->mtu);
+
+ /* Search for matching Request in List */
+ req_info = __bt_gatt_server_find_request_info(param->request_id, param->req_type);
+ if (!req_info) {
+ BT_ERR("GATT acquire Server Req Info not found for current response..return Error");
+ return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+ }
+
+ ret = gatt_send_response_acquire(req_info->connection_id, param->request_id, 0, param->fd, param->mtu, fd_list);
+
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("ret: %d", ret);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ BT_INFO("GATT acquire Server Response successfully sent");
+ /* Remove GATT server request from list */
+ gatt_server_requests = g_slist_remove(gatt_server_requests, req_info);
+ g_free(req_info->addr);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+
+
int _bt_gatt_server_send_indication(char *sender, bluetooth_device_address_t *dev_addr,
bluetooth_gatt_att_data_t *data,
bluetooth_gatt_server_indication_params_t *param)
int _bt_get_att_mtu(bluetooth_device_address_t *address,
unsigned int *mtu);
+int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param, void *);
+
#ifdef TIZEN_GATT_CLIENT
char * _bt_gatt_get_default_gatt_client_uuid(void);
BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, /** <GATT Characteristic Notification change event */
BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED, /** <GATT Characteristic Notification or Indication completed event */
BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED, /** <GATT Client service change event */
-
+ BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE, /** <GATT Characteristic/Descriptor Value change event */
+ BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_NOTIFY,
BLUETOOTH_EVENT_AG_CONNECTED = BLUETOOTH_EVENT_AUDIO_BASE, /**<AG service connected event*/
BLUETOOTH_EVENT_AG_DISCONNECTED, /**<AG service disconnected event*/
BLUETOOTH_EVENT_AG_SPEAKER_GAIN, /**<Speaker gain request event*/
BLUETOOTH_GATT_REQUEST_TYPE_READ = 0x00, /* Read Requested */
BLUETOOTH_GATT_REQUEST_TYPE_WRITE = 0x01, /* Write Requested */
BLUETOOTH_GATT_REQUEST_TYPE_EXEC_WRITE = 0x02, /* Exec Write Requested */
+ BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE = 0x03,
+ BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY = 0x04
} bluetooth_gatt_att_request_type_e;
/**
} bluetooth_gatt_server_write_requested_info_t;
/**
+* GATT Server Write Requested Info
+*/
+typedef struct {
+ int connection_id; /** < GATT Server Connection ID */
+ int request_id; /** < GATT Server Write Request ID */
+ int attribute_handle; /** < GATT Server Write att handle */
+ int offset; /** < GATT Server attribute offset */
+ char adress[BLUETOOTH_ADDRESS_STRING_LENGTH];
+} bluetooth_gatt_server_acquire_write_info_t;;
+
+
+/**
* GATT Server Update Characteristic Value
*/
typedef struct {
} bluetooth_gatt_server_response_params_t;
/**
+ * GATT Server acquire response data
+ */
+typedef struct {
+ bluetooth_gatt_att_request_type_e req_type;
+ int request_id;
+ int fd;
+ int mtu;
+} bluetooth_gatt_server_acquire_response_params_t;
+
+/**
* GATT Server Bluedroid Specific Permission Mask
*/
typedef enum {
#define BT_FUNC_PBAP_BASE ((int)(BT_FUNC_RFCOMM_BASE + 0x0020))
#define BT_FUNC_HDP_BASE ((int)(BT_FUNC_PBAP_BASE + 0x0020))
#define BT_FUNC_GATT_BASE ((int)(BT_FUNC_HDP_BASE + 0x0020))
-#define BT_FUNC_IPSP_BASE ((int)(BT_FUNC_GATT_BASE + 0x0020))
+#define BT_FUNC_IPSP_BASE ((int)(BT_FUNC_GATT_BASE + 0x0040))
#define BT_FUNC_DPM_BASE ((int)(BT_FUNC_IPSP_BASE + 0x0020))
#define BT_FUNC_PXP_BASE ((int)(BT_FUNC_DPM_BASE + 0x0030)) /* Adding 0x0030 to base, as DPM has more use case */
#define BT_FUNC_MAP_BASE ((int)(BT_FUNC_PXP_BASE + 0x0020))
BT_GATT_SERVER_STOP_SERVICE,
BT_GATT_SERVER_DELETE_SERVICE,
BT_GATT_SERVER_SEND_RESPONSE,
+ BT_GATT_SERVER_ACQURE_WRITE_RESPONSE,
BT_GATT_SERVER_SEND_INDICATION,
BT_GATT_SERVER_UPDATE_VALUE,
BT_GATT_SERVER_DEREGISTER,
BT_OTP_ENABLE_NOTIFICATION,
BT_OTP_WRITE_VALUE,
BT_LE_OTC_CONNECT,
- BT_LE_OTC_DISCONNECT,
+ BT_LE_OTC_DISCONNECT
} bt_function_t;
typedef struct {
#define BT_GATT_SERVER_READ_REQ "GattServerReadReq"
#define BT_GATT_SERVER_NOTIFICATION_COMPLETED "GattServerNotification"
#define BT_GATT_SERVER_NOTIFICATION_CHANGED "GattServerNotifChanged"
+#define BT_GATT_SERVER_ACQUIRE_WRITE "GattServerACquireWrite"
+#define BT_GATT_SERVER_ACQUIRE_NOTIFICATION "GattServerAcquireNotify"
#endif
#ifdef TIZEN_GATT_CLIENT