#define BT_UUID_STRING_MAX 64
#define BT_SENDER_MAX_LENGTH 50
#define MAX_APPS_SUPPORTED 11 /* Slot 0 is not used */
+#define BT_DEFAULT_ATT_MTU 23
#ifdef TIZEN_GATT_CLIENT
#define NUM_UUID 20
char *addr; /* Remote GATT Server address */
};
+struct gatt_client_info_t {
+ int connection_id; /* This value will uniquely identify a GATT client-server connection */
+ int instance_id; /* This value unique identifies a GATT server instance */
+ char *addr; /* Remote GATT client address */
+};
+
+/* TODO:
+ * Remove this feature if code is verified
+ * Remove gatt_client/server_info_t and use gatt_conn_info_t
+ * Remove gatt_client/server_info_list and use gatt_conn_info_list
+ */
+#define __INTEGRATE_GATT_INFO__
+#ifndef __INTEGRATE_GATT_INFO__
/* Linked List of connected Remote GATT Servers */
static GSList *gatt_server_info_list = NULL;
+/* Linked List of connected Remote GATT clients */
+static GSList *gatt_client_info_list = NULL;
+#else
+/* GATT Connection Info List Structure */
+struct gatt_conn_info_t {
+ char *addr; /* Remote GATT address */
+ int connection_id; /* This value will uniquely identify a GATT client-server connection */
+ int client_id; /* This value unique identifies a GATT Client instance */
+ int instance_id; /* This value unique identifies a GATT Server instance */
+};
+
+/* Linked List of connected Remote GATT info */
+static GSList *gatt_conn_info_list = NULL;
+#define gatt_server_info_t gatt_conn_info_t
+#define gatt_client_info_t gatt_conn_info_t
+#define gatt_server_info_list gatt_conn_info_list
+#define gatt_client_info_list gatt_conn_info_list
+#endif
typedef struct {
gboolean is_changed;
int inst_id;
} bt_gatt_included_service_info_t;
-GSList *list_gatt_info;
-
+static GSList *list_gatt_info = NULL;
#endif
char *addr; /* Remote GATT client address */
};
-/* GATT Client Info List Structure */
-struct gatt_client_info_t {
- int connection_id; /* This value will uniquely identify a GATT client-server connection */
- int instance_id; /* This value unique identifies a GATT server instance */
- char *addr; /* Remote GATT client address */
-};
-
/* GATT Indicate confirm result */
struct gatt_indicate_cfm_result_info_t {
int result; /* Result of event */
static int __bt_gatt_send_indication_to_all_connected_clients(bluetooth_gatt_att_data_t *data,
bluetooth_gatt_server_indication_params_t *param);
-static void __bt_remove_all_service_handles(int instance_id);
+static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info);
+
+static void __bt_free_service_info(bt_gatt_service_info_t *service_info);
+
+static int __bt_unregister_gatt_client_instance(int client_if);
+
+static void __bt_service_reset_gatt_data(void);
#ifdef TIZEN_GATT_CLIENT
static void __bt_handle_client_instance_registered(event_gattc_register_t *data);
static void __bt_handle_client_descriptor_read_data(event_gattc_read_data *event_data);
static void __bt_handle_client_characteristic_write_data(event_gattc_write_data *event_data);
static void __bt_handle_client_descriptor_write_data(event_gattc_write_data *event_data);
-static int __bt_do_unregister_gatt_instance(int instance_id);
static void __bt_hanlde_le_device_disconnection(event_dev_conn_status_t *event_data);
static void __bt_handle_client_notification_registered(event_gattc_regdereg_notify_t *event_data,
gboolean is_registered);
-
+static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data);
+static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data);
+static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data);
#endif
-static int __bt_do_unregister_server_instance(int server_instance);
+static int __bt_unregister_gatt_server_instance(int server_instance);
+static void __bt_cleanup_remote_services(struct gatt_server_info_t *conn_info);
+
+/*mtu device list*/
+struct gatt_mtu_info_t {
+ char *addr; /* Remote GATT Server address */
+ int att_mtu;
+};
+
+static GSList *gatt_mtu_info_list = NULL;
+
+static struct gatt_mtu_info_t *__bt_find_mtu_gatt_device(char *address);
+static void __bt_remove_mtu_gatt_device(char *address);
+static void __bt_add_mtu_gatt_device(char *address);
+static void __bt_update_mtu_gatt_device(char *address, int mtu);
/* Linked List of GATT requests from Remote GATT Clients */
static GSList *gatt_server_requests = NULL;
-/* Linked List of connected Remote GATT clients */
-static GSList *gatt_client_info_list = NULL;
-
/* Number of clients to be notified to */
static int num_indicate_clients;
static void __bt_gatt_event_handler(int event_type, gpointer event_data);
+typedef enum {
+ BT_GATT_SERVER = 1,
+ BT_GATT_CLIENT,
+} bt_gatt_type_e;
+
void _bt_check_adv_app_termination(const char *name)
{
bt_service_app_info_t *app = NULL;
int k;
- int apps[MAX_APPS_SUPPORTED];
+ int apps[MAX_APPS_SUPPORTED] = { 0, };
ret_if(NULL == name);
app = &numapps[k];
/* Search for a app which has same sender and stop adv is running */
- if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) {
- BT_DBG("Match found, name: %s", name);
-
- /* Unregister all service handles with stack */
- __bt_remove_all_service_handles(app->instance_id);
+ if (strcasecmp(app->sender, name) == 0 && app->is_initialized == TRUE) {
+ BT_DBG("numapps[%d] Match found, name: %s", k, name);
- /* If Advertising is enabled, stop it */
- if (app->adv_handle > 0) {
- BT_INFO("Stop advertising on instance ID [%d]", app->instance_id);
- /* Disable adv if running */
- BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
- app->adv_handle, name);
- _bt_set_advertising(app->sender, app->adv_handle, FALSE, FALSE);
- }
+ /* TODO 2: Need to manage app info as list, not array.
+ This loop always run for MAX count if any apps are terminated.
+ */
/* Save instances of all apps that need to be unregistered */
- apps[app->instance_id] = 1;
+ if (app->instance_id != -1) {
+ /* GATT server */
+ /* Unregister all service handles with stack */
+ __bt_remove_all_service_handles(app);
+
+ /* If Advertising is enabled, stop it */
+ if (app->adv_handle != 0) {
+ BT_INFO("Stop advertising on instance ID [%d]", app->instance_id);
+ /* Disable adv if running */
+ BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
+ app->adv_handle, name);
+ _bt_set_advertising(app->sender, app->adv_handle, FALSE, FALSE);
+ }
+
+ apps[app->instance_id] = BT_GATT_SERVER; /* App holds a GATT server Instance */
+ } else if (app->client_id != -1) {
+ /* GATT client */
+ apps[app->client_id] = BT_GATT_CLIENT; /* App holds a GATT client Instance */
+ }
}
}
/* Unregister all apps one by one */
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
- if (apps[k] == 1) {
- BT_INFO("Unregister app[%d]", k);
+ if (apps[k] == BT_GATT_SERVER) {
+ BT_INFO("Unregister server app[%d]", k);
/* Unregister server instance */
- __bt_do_unregister_server_instance(k);
+ __bt_unregister_gatt_server_instance(k);
+ } else if (apps[k] == BT_GATT_CLIENT) {
+ BT_INFO("Unregister client app[%d]", k);
+ /* Unregister client instance */
+ __bt_unregister_gatt_client_instance(k);
}
}
}
int _bt_gatt_init(void)
{
+ const char *stack_name = NULL;
+
BT_DBG("+");
if (OAL_STATUS_SUCCESS != gatt_enable()) {
/* Register gatt event handler */
_bt_service_register_event_handler_callback(BT_GATT_MODULE, __bt_gatt_event_handler);
-#ifdef TIZEN_GATT_CLIENT
- /*In bluedroid product, defacult gatt client is handled differently*/
- __bt_register_default_gatt_client();
-#endif
+
+ __bt_service_reset_gatt_data();
+
+ stack_name = oal_get_stack_name();
+
+ if (stack_name && g_strcmp0(stack_name, "bluez") == 0) {
+ /*In the platform, defacult gatt client should be registered */
+ __bt_register_default_gatt_client();
+ }
+
BT_DBG("-");
return BLUETOOTH_ERROR_NONE;
}
-static void __bt_service_reset_gatt_data()
+static void __bt_service_reset_gatt_data(void)
{
int k;
memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
numapps[k].adv_data_len = 0;
numapps[k].scan_rsp_len = 0;
+
+ /* GATT client */
+ numapps[k].client_id = -1;
+ memset(numapps[k].address.addr, 0x00, BLUETOOTH_ADDRESS_LENGTH);
+ numapps[k].is_watcher_enabled = FALSE;
}
}
{
BT_INFO("GATT deinit");
+ /* Un-register the default gatt client before */
+ __bt_unregister_gatt_client_instance(gatt_default_client);
+
if (OAL_STATUS_SUCCESS != gatt_disable())
BT_ERR("gatt deinit failed");
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
info = &numapps[k];
+ /* Do not update client instance */
+ if (info->instance_id == -1)
+ continue;
/* Search for a app which has same sender and adv handle as 0 */
if (!g_strcmp0(info->sender, sender) && info->adv_handle == 0)
info->adv_handle = adv_handle;
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
info = &numapps[k];
- if (info->instance_id == server_instance && info->adv_handle != -1) {
+ if (info->instance_id == server_instance && info->adv_handle != 0) {
*adv_handle = info->adv_handle;
BT_DBG("Server instance [%d] Adv handle [%d] Sender [%s]", server_instance, *adv_handle, info->sender);
return g_strdup(info->sender);
void _bt_set_new_adv_data(bluetooth_advertising_data_t *adv, int len, int instance)
{
int k;
- BT_DBG("+");
+ BT_DBG("");
bt_service_app_info_t *info = NULL;
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
info = &numapps[k];
break;
}
}
- BT_DBG("-");
}
void _bt_set_new_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int len, int instance)
{
int k;
- BT_DBG("+");
+ BT_DBG("");
bt_service_app_info_t *info = NULL;
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
info = &numapps[k];
break;
}
}
- BT_DBG("-");
}
void _bt_get_previous_adv_data(bluetooth_advertising_data_t *adv, int *len, int instance)
{
int k;
- BT_DBG("+");
bt_service_app_info_t *info = NULL;
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
void _bt_get_previous_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int *len, int instance)
{
int k;
- BT_DBG("+");
+ BT_DBG("");
bt_service_app_info_t *info = NULL;
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
}
}
-#ifdef TIZEN_GATT_CLIENT
-static int __bt_do_unregister_gatt_instance(int instance_id)
+static int __bt_unregister_gatt_client_instance(int client_if)
{
int ret = OAL_STATUS_SUCCESS;
int k;
- BT_INFO("DeAllocate server or client instance ID [%d]", instance_id);
+ BT_INFO("DeAllocate client instance ID [%d]", client_if);
/* Reset data: instance_id parameter could be either for GATT Server or for GATT client */
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
- if (numapps[k].instance_id == instance_id) {
- BT_INFO("This is a GATT server app, unregister: Slot [%d] vacant", k);
- numapps[k].is_initialized = FALSE;
- numapps[k].instance_id = -1;
- numapps[k].adv_handle = 0;
- numapps[k].adv_instance = -1;
- memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
- memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
- memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
- memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
- numapps[k].adv_data_len = 0;
- numapps[k].scan_rsp_len = 0;
-
- /* Its a GATT Server Instance */
- ret = gatts_unregister(instance_id);
- if (ret != OAL_STATUS_SUCCESS) {
- BT_ERR("DeAllocate server instance with stack Fail ret: %d", ret);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- break;
- } else if (numapps[k].client_id == instance_id) {
+ if (numapps[k].client_id == client_if) {
BT_INFO("This is a GATT client app, unregister: Slot [%d] vacant", k);
numapps[k].client_id = -1;
numapps[k].is_initialized = FALSE;
memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
/* Its a GATT Client Instance */
- ret = gattc_deregister(instance_id);
+ ret = gattc_deregister(client_if);
if (ret != OAL_STATUS_SUCCESS) {
BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
return BLUETOOTH_ERROR_INTERNAL;
}
return BLUETOOTH_ERROR_NONE;
}
-#endif
-static int __bt_do_unregister_server_instance(int server_instance)
+static int __bt_unregister_gatt_server_instance(int server_instance)
{
int ret = OAL_STATUS_SUCCESS;
int k;
return BLUETOOTH_ERROR_NONE;
}
-static void __bt_remove_all_service_handles(int instance_id)
+static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
{
GSList *l;
int *handle = NULL;
int ret = OAL_STATUS_SUCCESS;
int count;
- count = g_slist_length(numapps[instance_id].service_handles);
+ if (app_info == NULL)
+ return;
+
+ count = g_slist_length(app_info->service_handles);
BT_INFO("Before handle removal: current count [%d]", count);
- for (l = numapps[instance_id].service_handles; l != NULL;) {
+ for (l = app_info->service_handles; l != NULL;) {
handle = l->data;
l = g_slist_next(l);
if (handle) {
- BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, instance_id);
- if (_bt_gatt_server_stop_service(numapps[instance_id].sender, *handle, instance_id) != BLUETOOTH_ERROR_NONE)
+ BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, app_info->instance_id);
+ if (_bt_gatt_server_stop_service(app_info->sender, *handle, app_info->instance_id) != BLUETOOTH_ERROR_NONE)
continue;
- ret = gatts_delete_service(instance_id, *handle);
+ ret = gatts_delete_service(app_info->instance_id, *handle);
if (ret != OAL_STATUS_SUCCESS) {
BT_ERR("ret: %d", ret);
continue;
} else {
- numapps[instance_id].service_handles = g_slist_remove(numapps[instance_id].service_handles, handle);
+ app_info->service_handles = g_slist_remove(app_info->service_handles, handle);
g_free(handle);
handle = NULL;
- count = g_slist_length(numapps[instance_id].service_handles);
+ count = g_slist_length(app_info->service_handles);
BT_INFO("After deleting current count [%d]", count);
}
}
if (!g_strcmp0(info->sender, sender)) {
BT_INFO("Unregister GATT server instance [%d]", info->instance_id);
/* Unregister all service handles with stack */
- __bt_remove_all_service_handles(info->instance_id);
+ __bt_remove_all_service_handles(info);
/* Disable adv if running */
BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
if (!numapps[server_instance].service_handles) {
BT_INFO("There are no Service handles with this app, safe to unregister");
/* Unregister server instance only if this sender does not have any gatt services in it */
- result = __bt_do_unregister_server_instance(server_instance);
+ result = __bt_unregister_gatt_server_instance(server_instance);
} else {
numapps[server_instance].adv_handle = 0;
memset(numapps[server_instance].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
if (apps[k] == 1) {
BT_INFO("Unregister app[%d]", k);
/* Unregister server instance */
- __bt_do_unregister_server_instance(k);
+ __bt_unregister_gatt_server_instance(k);
}
}
int k;
oal_uuid_t uuid;
- BT_INFO("###Check on which instance Server instance can be initialized....");
+ BT_INFO("Check on which instance Server instance can be initialized....");
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
if (numapps[k].is_initialized == 1) {
- BT_INFO("Instance ID [%d] is already in use..Check next slot", numapps[k].instance_id);
+ BT_DBG("Instance ID [%d] is already in use..Check next slot", numapps[k].instance_id);
} else {
slot = k;
- BT_INFO("Time to register GATT Server..UUID to be used is [%s] slot [%d]", uuid_list[slot-1], slot);
+ BT_DBG("Time to register GATT Server..UUID to be used is [%s] slot [%d]", uuid_list[slot-1], slot);
break;
}
}
g_free(uuid_string);
return BLUETOOTH_ERROR_INTERNAL;
}
- BT_INFO("GATT Server registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
+ BT_DBG("GATT Server registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
/* Return & wait for GATT Server Instance Initialization event */
memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
GArray *out_param;
invocation_info_t *req_info = NULL;
ret_if(data == NULL);
- BT_DBG("+");
- for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+ for (l = _bt_get_invocation_list(); l != NULL; ) {
req_info = l->data;
+ l = g_slist_next(l);
if (req_info == NULL || req_info->service_function != service_function)
continue;
#ifndef GATT_DIRECT
case BT_GATT_SERVER_REGISTER: {
bt_service_app_info_t *param = (bt_service_app_info_t*)data;
- BT_INFO("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
+
if (!g_strcmp0(req_info->sender, param->sender)) {
BT_DBG("GATT Server app found [%s]", req_info->sender);
case BT_GATT_SERVER_START_SERVICE:
case BT_GATT_SERVER_DELETE_SERVICE: {
bt_service_app_info_t *param = (bt_service_app_info_t*)data;
- BT_INFO("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
int *saved_instance_id = (int*)req_info->user_data;
if (!g_strcmp0(req_info->sender, param->sender) && param->instance_id == *saved_instance_id) {
case BT_GATT_SERVER_ADD_DESCRIPTOR:
case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
int *handle = (int*)data;
- BT_INFO("Characteristic added: Handle [%d]", *handle);
+ BT_DBG("Characteristic added: Handle [%d]", *handle);
out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
g_array_append_vals(out_param, handle, sizeof(int));
#ifdef TIZEN_GATT_CLIENT
case BT_GATT_CLIENT_REGISTER: {
bt_service_app_info_t *param = (bt_service_app_info_t*)data;
- BT_INFO("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
+
if (!g_strcmp0(req_info->sender, param->sender)) {
BT_DBG("GATT Client app found [%s] created client ID [%d]",
req_info->sender, param->client_id);
_bt_convert_addr_type_to_string(address,
(unsigned char *)(¶m->device_addr.addr));
- BT_INFO("Request Sender [%s] address [%s]", req_info->sender, address);
-
/* Match address to determine same request */
if (!g_strcmp0((char*)req_info->user_data, address)) {
BT_DBG("GATT Client app found [%s] Remote address [%s]",
bt_char_browse_info_t param;
memcpy((void*)¶m, data, sizeof(bt_char_browse_info_t));
//bt_char_browse_info_t *param = (bt_char_browse_info_t*)data;
- BT_INFO("Request Sender [%s]", req_info->sender);
+
bluetooth_gatt_client_svc_prop_info_t *prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
/* Match both address and service properties to determine same request */
sizeof(bluetooth_device_address_t)) &&
!memcmp(param.svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
param.svc_inst_id == prop->svc.instance_id) {
- BT_INFO("Returning Service properties");
+ BT_DBG("Returning Service properties");
out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
g_array_append_vals(out_param, ¶m, sizeof(bt_char_browse_info_t));
case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
bt_descriptor_browse_info_t *param = (bt_descriptor_browse_info_t*)data;
- BT_INFO("Request Sender [%s]", req_info->sender);
bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
/* Match both address, service properties &char properties to determine same request */
param->svc_inst_id == prop->svc.instance_id &&
!memcmp(param->char_uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
param->char_inst_id == prop->characteristic.instance_id) {
- BT_INFO("Returning Characteristic properties");
+ BT_DBG("Returning Characteristic properties");
out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
g_array_append_vals(out_param, param, sizeof(bt_descriptor_browse_info_t));
_bt_service_method_return(req_info->context, out_param, result);
case BT_GATT_WATCH_CHARACTERISTIC: {
bt_gatt_notif_reg_info_t *param = (bt_gatt_notif_reg_info_t*)data;
bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
- BT_INFO("Request Sender [%s]", req_info->sender);
+
/* Match both address, service properties &char properties to determine same request */
if (!memcmp(param->addr.addr,
prop->device_address.addr,
case BT_GATT_READ_CHARACTERISTIC:
case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
bluetooth_gatt_client_char_prop_info_t *param = (bluetooth_gatt_client_char_prop_info_t*)data;
- BT_INFO("Request Sender [%s]", req_info->sender);
char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
_bt_convert_addr_type_to_string(addr, prop->device_address.addr);
if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_char_prop_info_t))) {
- BT_INFO("Gatt Char read or write request matched for address [%s]", addr);
+ BT_DBG("Gatt Char read or write request matched for address [%s]", addr);
out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_char_prop_info_t));
_bt_service_method_return(req_info->context, out_param, result);
case BT_GATT_READ_DESCRIPTOR_VALUE:
case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
bluetooth_gatt_client_desc_prop_info_t *param = (bluetooth_gatt_client_desc_prop_info_t*)data;
- BT_INFO("Request Sender [%s]", req_info->sender);
char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
bluetooth_gatt_client_desc_prop_info_t *prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
_bt_convert_addr_type_to_string(addr, prop->device_address.addr);
if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_desc_prop_info_t))) {
- BT_INFO("Descriptor read or write request matched for address [%s]", addr);
+ BT_DBG("Descriptor read or write request matched for address [%s]", addr);
out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_desc_prop_info_t));
_bt_service_method_return(req_info->context, out_param, result);
g_free(addr);
break;
}
+ case BT_REQ_ATT_MTU: {
+ char *addr = (char*)req_info->user_data;
+ bluetooth_device_address_t address;
+
+ if (!g_strcmp0(addr, (char*)data)) {
+ BT_DBG("GATT Client BT_REQ_ATT_MTU call pending for app [%s] addr [%s]",
+ req_info->sender, addr);
+ out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+ _bt_convert_addr_string_to_type(address.addr, addr);
+
+ g_array_append_vals(out_param, (bluetooth_device_address_t*)&address,
+ sizeof(bluetooth_device_address_t));
+ _bt_service_method_return(req_info->context, out_param, result);
+
+ g_free(req_info->user_data);
+ _bt_free_info_from_invocation_list(req_info);
+ g_array_free(out_param, TRUE);
+ }
+ }
#endif
default:
break;
}
}
- BT_DBG("-");
}
static void __bt_handle_server_instance_registered(event_gatts_register_t *data)
}
}
g_free(uuid_string);
- g_free(data);
}
static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
info = &numapps[k];
if (info->instance_id == event->gatt_srvc_stat.server_inst) {
- BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
+ BT_INFO("numapps[%d] Found GATT Server.. UUID [%s], sender [%s]", k, info->uuid, info->sender);
__bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_SERVICE,
(int*)&svc_handle, sizeof(int));
if (svc_handle > 0) {
handle = g_malloc0(sizeof(int));
*handle = svc_handle;
- numapps[event->gatt_srvc_stat.server_inst].service_handles = g_slist_append(numapps[event->gatt_srvc_stat.server_inst].service_handles, handle);
- count = g_slist_length(numapps[event->gatt_srvc_stat.server_inst].service_handles);
+ numapps[k].service_handles = g_slist_append(numapps[k].service_handles, handle);
+ count = g_slist_length(numapps[k].service_handles);
BT_INFO("Added Service handle [%d] to list..current count [%d]", svc_handle, count);
}
break;
}
}
- g_free(event);
g_free(uuid_str);
}
_bt_uuid_to_string(&(event->charctr_uuid), uuid_str);
BT_INFO("GATT Added Characteristic: UUID: [%s]", uuid_str);
- g_free(event);
g_free(uuid_str);
}
_bt_uuid_to_string(&(event->descrptr_uuid), uuid_str);
BT_INFO("GATT Added Descriptor: UUID: [%s]", uuid_str);
- g_free(event);
g_free(uuid_str);
}
break;
}
}
-
- g_free(event);
}
static void __bt_handle_gatt_server_service_stopped(event_gatts_srvc_t *event)
break;
}
}
-
- g_free(event);
}
static void __bt_handle_gatt_server_service_deleted(event_gatts_srvc_t *event)
break;
}
}
-
- g_free(event);
}
-static struct gatt_client_info_t *__bt_find_remote_gatt_client_info(char *address)
+struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address)
{
GSList *l;
struct gatt_client_info_t *info = NULL;
continue;
if (!g_strcmp0(info->addr, address)) {
- BT_INFO("Remote GATT client found addr[%s]", info->addr);
+ BT_DBG("Remote GATT client found addr[%s]", info->addr);
return info;
}
}
}
#ifdef TIZEN_GATT_CLIENT
-static struct gatt_server_info_t *__bt_find_remote_gatt_server_info(char *address)
+struct gatt_server_info_t *_bt_find_remote_gatt_server_info(char *address)
{
GSList *l;
struct gatt_server_info_t *info = NULL;
continue;
if (!g_strcmp0(info->addr, address)) {
- BT_INFO("Remote GATT Server found addr[%s]", info->addr);
+ BT_DBG("Remote GATT Server found addr[%s]", info->addr);
return info;
}
}
}
return NULL;
}
-
-static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_client_if(int client_if)
-{
- GSList *l;
- struct gatt_server_info_t *info = NULL;
-
- for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
- info = (struct gatt_server_info_t*)l->data;
- if (info == NULL)
- continue;
-
- if (info->client_id == client_if) {
- BT_INFO("Remote GATT server found addr[%s]", info->addr);
- return info;
- }
- }
- return NULL;
-}
#endif
-
-
-
#ifdef TIZEN_GATT_CLIENT
static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
{
int result = BLUETOOTH_ERROR_NONE;
- struct gatt_client_info_t *conn_info = NULL;
+ struct gatt_client_info_t *client_info = NULL;
+#ifndef __INTEGRATE_GATT_INFO__
+ struct gatt_server_info_t *server_info = NULL;
+#endif
bluetooth_device_address_t dev_addr;
+ GVariant *param = NULL;
+ int ret;
char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
in this event */
_bt_convert_addr_type_to_string(address,
(unsigned char *)dev_addr.addr);
+
+ if (event->status != OAL_STATUS_SUCCESS)
+ result = BLUETOOTH_ERROR_INTERNAL;
+
__bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
address, BT_ADDRESS_STRING_SIZE);
/* Check if device is already in connected list */
- conn_info = __bt_find_remote_gatt_client_info(address);
+ client_info = _bt_find_remote_gatt_client_info(address);
- if (!conn_info) {
+ if (!client_info) {
BT_INFO("Conn Info absent: But no need to Send Local GATT Server Connected event to apps");
-#if 0
+
param = g_variant_new("(is)", result, address);
/* Send event to application */
_bt_send_event(BT_DEVICE_EVENT,
BLUETOOTH_EVENT_GATT_SERVER_CONNECTED, /* Local device is GATT server */
param);
+
+ /* Save client connection info */
+ client_info = g_new0(struct gatt_client_info_t, 1);
+ client_info->addr = g_strdup(address);
+ BT_INFO("Added GATT client addr[%s]", client_info->addr);
+ client_info->connection_id = event->conn_id;
+#ifdef __INTEGRATE_GATT_INFO__
+ client_info->client_id = -1;
#endif
- /* Save Connection info */
- conn_info = g_new0(struct gatt_client_info_t, 1);
- conn_info->addr = g_strdup(address);
- BT_INFO("Added GATT client addr[%s]", conn_info->addr);
- conn_info->connection_id = event->conn_id;
- conn_info->instance_id = event->server_inst;
- gatt_client_info_list = g_slist_append(gatt_client_info_list, conn_info);
+ client_info->instance_id = event->server_inst;
+ gatt_client_info_list = g_slist_append(gatt_client_info_list, client_info);
BT_INFO("Total num of connected Remote GATT Clients [%d]", g_slist_length(gatt_client_info_list));
+
+#ifndef __INTEGRATE_GATT_INFO__
+ /* Save server connection info */
+ server_info = g_new0(struct gatt_server_info_t, 1);
+ server_info->addr = g_strdup(address);
+ server_info->client_id = -1;
+ BT_INFO("Added GATT server addr[%s]", server_info->addr);
+ server_info->connection_id = event->conn_id;
+ gatt_server_info_list = g_slist_append(gatt_server_info_list, server_info);
+ BT_INFO("Total num of connected Remote GATT Servers [%d]", g_slist_length(gatt_server_info_list));
+#endif
+
+ ret = gattc_add_connection_info((bt_address_t *)&dev_addr, event->conn_id, event->server_inst);
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("gattc register server instance failed");
+ }
}
+ __bt_add_mtu_gatt_device(address);
+
g_free(address);
}
static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *event)
{
int result = BLUETOOTH_ERROR_NONE;
- struct gatt_client_info_t *conn_info = NULL;
+ struct gatt_client_info_t *client_info = NULL;
+#ifndef __INTEGRATE_GATT_INFO__
+ struct gatt_server_info_t *server_info = NULL;
+#endif
bluetooth_device_address_t dev_addr;
-
- char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ GVariant *param = NULL;
+ char address[BT_ADDRESS_STRING_SIZE];
memcpy(dev_addr.addr, event->address.addr, 6);
_bt_convert_addr_type_to_string(address,
(unsigned char *)dev_addr.addr);
+ if (event->status != OAL_STATUS_SUCCESS)
+ result = BLUETOOTH_ERROR_INTERNAL;
+
if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
result = BLUETOOTH_ERROR_INTERNAL;
BT_INFO("Local GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
address, event->server_inst, event->conn_id);
/* Remove Connection info */
- conn_info = __bt_find_remote_gatt_client_info(address);
- if (conn_info) {
+ client_info = _bt_find_remote_gatt_client_info(address);
+ if (client_info) {
BT_INFO("No need to Send Local GATT Server Disconnected event to apps, just remove remote client info");
-#if 0
+
param = g_variant_new("(is)", result, address);
/* Send event to application */
_bt_send_event(BT_DEVICE_EVENT,
BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED, /* Local device is GATT server */
param);
+
+#ifndef __INTEGRATE_GATT_INFO__
+ /* Remove server info from list */
+ server_info = _bt_find_remote_gatt_server_info(address);
+ if (server_info)
+ gatt_server_info_list = g_slist_remove(gatt_server_info_list, server_info);
+ else
+ BT_INFO("Can not find conn info, already removed!");
+
+ /* Remove all services from info list_gatt_info */
+ __bt_cleanup_remote_services(server_info);
+#else
+ /* Remove all services from info list_gatt_info */
+ __bt_cleanup_remote_services(client_info);
#endif
- /* Remove info from List */
- gatt_client_info_list = g_slist_remove(gatt_client_info_list, conn_info);
+
+ /* Remove client info from List */
+ gatt_client_info_list = g_slist_remove(gatt_client_info_list, client_info);
BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
- g_free(conn_info->addr);
- g_free(conn_info);
+ g_free(client_info->addr);
+ g_free(client_info);
}
- g_free(address);
+ __bt_remove_mtu_gatt_device(address);
}
#else
/* Check if device is already in connected list */
- conn_info = __bt_find_remote_gatt_client_info(address);
+ conn_info = _bt_find_remote_gatt_client_info(address);
if (!conn_info) {
param = g_variant_new("(is)", result, address);
param);
/* Remove Connection info */
- conn_info = __bt_find_remote_gatt_client_info(address);
+ conn_info = _bt_find_remote_gatt_client_info(address);
if (conn_info) {
BT_INFO("Remove GATT client info from List..");
/* Remove info from List */
}
#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 address[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);
+
+ //address = 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(address,
+ (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, address);
+ BT_INFO("GATT Server ACQUIRE Write Req Attribute remote address : [%s]", address);
+
+ _bt_send_event(BT_GATT_SERVER_EVENT,
+ BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE,
+ param);
+
+}
+
+static void __bt_handle_gatt_server_acquire_notify_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 address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ BT_INFO("GATT Server ACQUIRE Notify Req Connection ID: [%d]", event->attr_trans.conn_id);
+ BT_INFO("GATT Server ACQUIRE Notify Req Transaction ID:[%d]", event->attr_trans.trans_id);
+ BT_INFO("GATT Server ACQUIRE Notify Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
+ BT_INFO("GATT Server ACQUIRE notify Req address : [%s]", address);
+
+ memcpy(dev_addr.addr, event->address.addr, 6);
+ _bt_convert_addr_type_to_string(address,
+ (unsigned char *)dev_addr.addr);
+ BT_INFO("GATT Server ACQUIRE notify Req remote address : [%s]", address);
+
+ 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_NOTIFY;
+ gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
+
+ 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,
+ address);
+
+ BT_INFO("GATT Server ACQUIRE Notify Req Attribute : ");
+
+ _bt_send_event(BT_GATT_SERVER_EVENT,
+ BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_NOTIFY,
+ param);
+}
+
static void __bt_handle_gatt_server_write_requested(event_gatts_srvc_write_attr_t *event)
{
char *address;
if (event->length <= 0) {
BT_INFO("GATT Server write requested, but length of attr value is 0");
- g_free(event);
return;
}
BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
param);
- g_free(event);
g_free(write_val);
}
_bt_send_event(BT_GATT_SERVER_EVENT,
BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
param);
-
- g_free(event);
}
static void __bt_handle_gatt_server_indicate_confirmed(event_gatts_ind_cnfrm_t *event)
param);
BT_INFO("Received Indication confirm for client number [%d]", recvd);
- g_free(event);
g_free(address);
}
BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
param);
- g_free(event);
g_free(address);
}
struct gatt_client_info_t *conn_info = NULL;
GVariant *param = NULL;
guint8 status = 0;
- BT_INFO("GATT Server MTU changed event");
conn_info = __bt_find_remote_gatt_client_info_from_conn_id(event->conn_id);
if (conn_info == NULL) {
BT_ERR("Cant find connection Information");
- g_free(event);
return;
}
BT_INFO("Got connection Info GATT client [%s] MTU Size [%d]",
conn_info->addr, event->mtu_size);
+ __bt_update_mtu_gatt_device(conn_info->addr, event->mtu_size);
+
param = g_variant_new("(isqy)",
result,
conn_info->addr,
_bt_send_event(BT_GATT_SERVER_EVENT,
BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
param);
- g_free(event);
}
static void __bt_gatt_event_handler(int event_type, gpointer event_data)
switch (event_type) {
case OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED: {
BT_INFO("OAL Event: Server Instance Registered");
- event_gatts_register_t* event = g_memdup(event_data, sizeof(event_gatts_register_t));
/* GATT Server Registered event is handled in MAIN thread context */
- __bt_handle_server_instance_registered(event);
+ __bt_handle_server_instance_registered((event_gatts_register_t *)event_data);
break;
}
case OAL_EVENT_GATTS_SERVICE_ADDED: {
BT_INFO("OAL Event: GATT Service added");
- event_gatts_srvc_prm_t *service_parm = g_memdup(event_data, sizeof(event_gatts_srvc_prm_t));
- __bt_handle_gatt_server_service_added(service_parm);
+ __bt_handle_gatt_server_service_added((event_gatts_srvc_prm_t *)event_data);
break;
}
case OAL_EVENT_GATTS_CHARACTERISTIC_ADDED: {
BT_INFO("OAL Event: GATT characteristic added");
- event_gatts_srvc_charctr_t *char_parm = g_memdup(event_data, sizeof(event_gatts_srvc_charctr_t));
- __bt_handle_gatt_server_characteristic_added(char_parm);
+ __bt_handle_gatt_server_characteristic_added((event_gatts_srvc_charctr_t *)event_data);
break;
}
case OAL_EVENT_GATTS_DESCRIPTOR_ADDED: {
BT_INFO("OAL Event: GATT descriptor added");
- event_gatts_srvc_descr_t *desc_parm = g_memdup(event_data, sizeof(event_gatts_srvc_descr_t));
- __bt_handle_gatt_server_descriptor_added(desc_parm);
+ __bt_handle_gatt_server_descriptor_added((event_gatts_srvc_descr_t *)event_data);
break;
}
case OAL_EVENT_GATTS_SERVICE_STARTED: {
BT_INFO("OAL Event: GATT Service started");
- event_gatts_srvc_t *svc_started = g_memdup(event_data, sizeof(event_gatts_srvc_t));
- __bt_handle_gatt_server_service_started(svc_started);
+ __bt_handle_gatt_server_service_started((event_gatts_srvc_t *)event_data);
break;
}
case OAL_EVENT_GATTS_SERVICE_STOPED: {
BT_INFO("OAL Event: GATT Service stopped");
- event_gatts_srvc_t *svc_stopped = g_memdup(event_data, sizeof(event_gatts_srvc_t));
- __bt_handle_gatt_server_service_stopped(svc_stopped);
+ __bt_handle_gatt_server_service_stopped((event_gatts_srvc_t *)event_data);
break;
}
case OAL_EVENT_GATTS_SERVICE_DELETED: {
BT_INFO("OAL Event: GATT Service deleted");
- event_gatts_srvc_t *svc_deleted = g_memdup(event_data, sizeof(event_gatts_srvc_t));
- __bt_handle_gatt_server_service_deleted(svc_deleted);
+ __bt_handle_gatt_server_service_deleted((event_gatts_srvc_t *) event_data);
break;
}
case OAL_EVENT_GATTS_CONNECTION_COMPLETED: {
BT_INFO("OAL Event: GATT Server Connected");
- event_gatts_conn_t* event = g_memdup(event_data, sizeof(event_gatts_conn_t));
- __bt_handle_gatt_server_connection_state(event);
+ __bt_handle_gatt_server_connection_state((event_gatts_conn_t *)event_data);
break;
}
case OAL_EVENT_GATTS_DISCONNECTION_COMPLETED: {
BT_INFO("OAL Event: GATT Server Disconnected");
- event_gatts_conn_t* event = g_memdup(event_data, sizeof(event_gatts_conn_t));
- __bt_handle_gatt_server_disconnection_state(event);
+ __bt_handle_gatt_server_disconnection_state((event_gatts_conn_t *)event_data);
break;
}
case OAL_EVENT_GATTS_REQUEST_READ: {
BT_INFO("OAL Event: GATT Server Read Request");
- event_gatts_srvc_read_attr_t *read_req = g_memdup(event_data, sizeof(event_gatts_srvc_read_attr_t));
- __bt_handle_gatt_server_read_requested(read_req);
+ __bt_handle_gatt_server_read_requested((event_gatts_srvc_read_attr_t *)event_data);
break;
}
case OAL_EVENT_GATTS_REQUEST_WRITE: {
BT_INFO("OAL Event: GATT Server Write Request");
- event_gatts_srvc_write_attr_t *write_req = g_memdup(event_data, sizeof(event_gatts_srvc_write_attr_t));
- __bt_handle_gatt_server_write_requested(write_req);
+ __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_REQUEST_ACQUIRE_NOTIFY: {
+ BT_INFO("OAL Event: GATT ServerAcquire Notify Request");
+ __bt_handle_gatt_server_acquire_notify_requested((event_gatts_srvc_acquire_attr_t*)event_data);
break;
}
case OAL_EVENT_GATTS_IND_CONFIRM: {
BT_INFO("OAL Event: GATT Server Indication confirmed");
- event_gatts_ind_cnfrm_t *parm = g_memdup(event_data, sizeof(event_gatts_ind_cnfrm_t));
- __bt_handle_gatt_server_indicate_confirmed(parm);
+ __bt_handle_gatt_server_indicate_confirmed((event_gatts_ind_cnfrm_t *)event_data);
break;
}
case OAL_EVENT_GATTS_NOTIFICATION: { /* Tizen Platform Specific */
BT_INFO("OAL Event: GATT Server DisConnected");
- event_gatts_notif_t* notif = g_memdup(event_data, sizeof(event_gatts_notif_t));
- __bt_handle_gatt_server_notification_changed(notif);
+ __bt_handle_gatt_server_notification_changed((event_gatts_notif_t *)event_data);
break;
}
case OAL_EVENT_GATTS_MTU_CHANGED: {
BT_INFO("OAL Event: GATT Server MTU changed event callback");
- event_gatts_mtu_changed_t *mtu_changed = g_memdup(event_data, sizeof(event_gatts_mtu_changed_t));
- __bt_handle_gatt_mtu_changed_event(mtu_changed);
+ __bt_handle_gatt_mtu_changed_event((event_gatts_mtu_changed_t *)event_data);
break;
}
#ifdef TIZEN_GATT_CLIENT
break;
}
case OAL_EVENT_GATTC_SERVICE_SEARCH_RESULT: {
- BT_INFO("OAL Event: GATT Client Service Search Result");
+ BT_DBG("OAL Event: GATT Client Service Search Result");
__bt_handle_client_service_search_result((event_gattc_service_result_t *) event_data);
break;
}
break;
}
case OAL_EVENT_GATTC_CHARAC_SERACH_RESULT: {
- BT_INFO("OAL Event: GATT Client Characteristic Search Result");
+ BT_DBG("OAL Event: GATT Client Characteristic Search Result");
__bt_handle_client_characteristic_search_result((event_gattc_characteristic_result_t *) event_data);
break;
}
case OAL_EVENT_GATTC_DESC_SERACH_RESULT: {
- BT_INFO("OAL Event: GATT Client Descriptor Search Result");
+ BT_DBG("OAL Event: GATT Client Descriptor Search Result");
__bt_handle_client_descriptor_search_result((event_gattc_descriptor_result_t *) event_data);
break;
}
case OAL_EVENT_GATTC_READ_CHARAC: {
- BT_INFO("OAL Event: GATT Client Characteristic Read Data");
+ BT_DBG("OAL Event: GATT Client Characteristic Read Data");
__bt_handle_client_characteristic_read_data((event_gattc_read_data *) event_data);
break;
}
case OAL_EVENT_GATTC_READ_DESCR: {
- BT_INFO("OAL Event: GATT Client Descriptor Read Data");
+ BT_DBG("OAL Event: GATT Client Descriptor Read Data");
__bt_handle_client_descriptor_read_data((event_gattc_read_data *) event_data);
break;
}
case OAL_EVENT_GATTC_WRITE_CHARAC: {
- BT_INFO("OAL Event: GATT Client Characteristic Write Data");
+ BT_DBG("OAL Event: GATT Client Characteristic Write Data");
__bt_handle_client_characteristic_write_data((event_gattc_write_data *) event_data);
break;
}
case OAL_EVENT_GATTC_WRITE_DESCR: {
- BT_INFO("OAL Event: GATT Client Descriptor Write Data");
+ BT_DBG("OAL Event: GATT Client Descriptor Write Data");
__bt_handle_client_descriptor_write_data((event_gattc_write_data *) event_data);
break;
}
__bt_handle_client_notification_registered((event_gattc_regdereg_notify_t *) event_data, FALSE);
break;
}
+ case OAL_EVENT_GATTC_NOTIFY_DATA: {
+ BT_DBG("OAL Event: GATT Client Notification Data");
+ __bt_handle_client_notification_data((event_gattc_notify_data *) event_data);
+ break;
+ }
+ case OAL_EVENT_GATTC_SERVICE_CHANGED_IND: {
+ BT_INFO("OAL Event: GATT Client service changed indication");
+ __bt_handle_client_service_changed_ind((event_gattc_service_changed_data *)event_data);
+ break;
+ }
+ case OAL_EVENT_GATTC_MTU_EXCHANGE_COMPLETED: {
+ BT_INFO("OAL Event: GATT Client MTU Exchange Complete");
+ __bt_handle_client_mtu_exchange_completed((event_gattc_mtu_configured_t *) event_data);
+ break;
+ }
#endif
default:
break;
}
- BT_DBG("-");
}
int _bt_gatt_server_add_service(char *sender, int service_type,
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_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(data, return);
BT_CHECK_PARAMETER(param, return);
- char *address;
- gboolean all_send = FALSE;
+ struct gatt_server_req_info *req_info = NULL;
int ret = OAL_STATUS_SUCCESS;
- struct gatt_client_info_t *conn;
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_addr_type_to_string(address, dev_addr->addr);
- if (memcmp(dev_addr->addr, BDADDR_ANY, 6) == 0) {
- BT_INFO("GATT Server: Send Indication to all connected GATT clients..");
- all_send = TRUE;
- } else {
- BT_INFO("GATT Server: Send Indication to connected GATT client addr [%s]", address);
- }
+ 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);
- /* Attempt to send Notification/Indication to all Connected GATT clients */
+ /* 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)
+{
+ BT_CHECK_PARAMETER(sender, return);
+ BT_CHECK_PARAMETER(data, return);
+ BT_CHECK_PARAMETER(param, return);
+ char *address;
+ gboolean all_send = FALSE;
+ int ret = OAL_STATUS_SUCCESS;
+ struct gatt_client_info_t *conn;
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_addr_type_to_string(address, dev_addr->addr);
+
+ if (memcmp(dev_addr->addr, BDADDR_ANY, 6) == 0) {
+ BT_INFO("GATT Server: Send Indication to all connected GATT clients..");
+ all_send = TRUE;
+ } else {
+ BT_INFO("GATT Server: Send Indication to connected GATT client addr [%s]", address);
+ }
+
+ /* Attempt to send Notification/Indication to all Connected GATT clients */
if (all_send) {
ret = __bt_gatt_send_indication_to_all_connected_clients(data, param);
if (ret != OAL_STATUS_SUCCESS) {
}
} else {
- conn = __bt_find_remote_gatt_client_info(address);
+ conn = _bt_find_remote_gatt_client_info(address);
if (conn) {
ret = gatts_send_indication(param->instance_id, param->atrribute_handle,
conn->connection_id, data->length,
return BLUETOOTH_ERROR_NONE;
}
+int _bt_request_att_mtu(bluetooth_device_address_t *device_address,
+ unsigned int mtu)
+{
+ struct gatt_server_info_t *conn_info = NULL;
+ char *addr = NULL;
+ int ret = OAL_STATUS_SUCCESS;
+
+ addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
+ _bt_convert_addr_type_to_string(addr, device_address->addr);
+
+ /* Check if remote GATT Server is connected or not */
+ conn_info = _bt_find_remote_gatt_server_info(addr);
+ if (conn_info) {
+ BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
+ conn_info->addr, conn_info->connection_id);
+ } else {
+ BT_ERR("GATT Server is not yet connected..");
+ g_free(addr);
+ return BLUETOOTH_ERROR_NOT_CONNECTED;
+ }
+
+ ret = gattc_configure_mtu(conn_info->connection_id, mtu);
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("ret: %d", ret);
+ g_free(addr);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_free(addr);
+ return BLUETOOTH_ERROR_NONE;
+}
+
int _bt_get_att_mtu(bluetooth_device_address_t *address,
unsigned int *mtu)
{
BT_INFO("Get current MTU size for the remote client:DevAddress:[%s]", addr);
- conn_info = __bt_find_remote_gatt_client_info(addr);
+ conn_info = _bt_find_remote_gatt_client_info(addr);
if (conn_info) {
BT_INFO("GATT Client [%s] is connected, conn Id [%d] Instance ID [%d]",
conn_info->addr, conn_info->connection_id, conn_info->instance_id);
} else {
- BT_ERR("GATT Client [%s] is not yet connected..");
+ BT_ERR("GATT Client [%s] is not yet connected..", addr);
return BLUETOOTH_ERROR_NOT_CONNECTED;
}
BT_ERR("ret: %d", ret);
return BLUETOOTH_ERROR_INTERNAL;
}
+
BT_INFO("ATT MTU received from OAL [%d]", stack_mtu);
*mtu = (unsigned int)stack_mtu;
- return BLUETOOTH_ERROR_NONE;
-}
-#ifdef TIZEN_GATT_CLIENT
-static void __bt_convert_byte_ordering(char *data, int data_len,
- char *converted_data)
-{
- int i, j;
- char temp[BLUETOOTH_UUID_HEX_MAX_LEN];
+ if (*mtu == 0) {
+ BT_ERR("MTU value is zero, GATT Client [%s] is not yet connected..", addr);
+ return BLUETOOTH_ERROR_NOT_CONNECTED;
+ }
- memcpy(&temp, data, data_len);
- for (i = 0, j = data_len - 1; i < data_len; i++, j--)
- converted_data[i] = temp[j];
+ return BLUETOOTH_ERROR_NONE;
}
+#ifdef TIZEN_GATT_CLIENT
/* GATT Client utility static functions */
-static bt_gatt_service_info_list_t * __bt_get_service_info_list(int conn_id)
+static bt_gatt_service_info_list_t *__bt_get_service_info_list(int conn_id)
{
GSList *l;
bt_gatt_service_info_list_t *info = NULL;
for (l = list_gatt_info; l != NULL; l = g_slist_next(l)) {
- info = (bt_gatt_service_info_list_t*)l->data;
+ info = (bt_gatt_service_info_list_t *)l->data;
if (info == NULL)
continue;
return NULL;
}
-static bt_gatt_service_info_t* __bt_find_matching_service(
+static bt_gatt_service_info_t *__bt_find_matching_service(
bt_gatt_service_info_list_t *svc_list, oal_gatt_srvc_id_t *svc)
{
GSList *l;
bt_gatt_service_info_t *info = NULL;
for (l = svc_list->services; l != NULL; l = g_slist_next(l)) {
- info = (bt_gatt_service_info_t*)l->data;
+ info = (bt_gatt_service_info_t *)l->data;
if (info == NULL)
continue;
return NULL;
}
-static bt_gatt_char_info_t* __bt_find_matching_charc(
+static bt_gatt_char_info_t *__bt_find_matching_charc(
bt_gatt_service_info_t *svc_info, oal_gatt_id_t *charc)
{
GSList *l;
bt_gatt_char_info_t *info = NULL;
for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
- info = (bt_gatt_char_info_t*)l->data;
+ info = (bt_gatt_char_info_t *)l->data;
if (info == NULL)
continue;
return NULL;
}
-static bt_gatt_descriptor_info_t* __bt_find_matching_desc(
+static bt_gatt_descriptor_info_t *__bt_find_matching_desc(
bt_gatt_char_info_t *char_info, oal_gatt_id_t *desc)
{
GSList *l;
bt_gatt_descriptor_info_t *info = NULL;
for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
- info = (bt_gatt_descriptor_info_t*)l->data;
+ info = (bt_gatt_descriptor_info_t *)l->data;
if (info == NULL)
continue;
struct gatt_server_info_t *conn_info = NULL;
int count = 0;
char uuid_string[BLUETOOTH_UUID_STRING_MAX];
- BT_INFO("+");
conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
_bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
svc_info_list = __bt_get_service_info_list(conn_id);
-
if (!svc_info_list)
return;
info->count = g_slist_length(svc_info_list->services);
- BT_INFO("Total services present in the svc info list for this conn id [%d] is [%d]",
+ BT_DBG("Total services present in the svc info list for this conn id [%d] is [%d]",
conn_id, info->count);
for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
memcpy(&uuid.uuid, &svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
_bt_uuid_to_string(&uuid, uuid_string);
- BT_INFO("Service UUID formed [%s] strlen [%d]", uuid_string, strlen(uuid_string));
+ BT_INFO("[%d] %s [%s]", count, uuid_string, _bt_convert_uuid_to_string(uuid_string));
/* Fill UUID of service */
g_strlcpy(info->uuids[count], uuid_string,
BLUETOOTH_UUID_STRING_MAX);
- BT_INFO("Service UUID formed TO be sent [%s] strlen [%d]",
- info->uuids[count], strlen(info->uuids[count]));
/* Fill instance ID of service */
info->inst_id[count] = svc_info->inst_id;
/* Increment count of services browsed */
count++;
}
-
- BT_INFO("Total services browsed [%d]", count);
}
static void __bt_build_char_browse_info(int conn_id,
int count = 0;
char uuid_string[BLUETOOTH_UUID_STRING_MAX];
- BT_INFO("+");
-
conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
if (!conn_info)
return;
}
info->count = g_slist_length(svc_info->chars);
- BT_INFO("Total count of Characteristics [%d]", info->count);
for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
char_info = (bt_gatt_char_info_t*)l->data;
/* Increment count of services browsed */
count++;
}
- BT_INFO("Total characteristics browsed [%d]", count);
+ BT_DBG("Total characteristics browsed [%d]", count);
}
static void __bt_build_descriptor_browse_info(int conn_id,
memcpy(&info->char_uuid, char_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
info->char_inst_id = char_info->inst_id;
+ /* Fill property of the parent characteristic of this descriptor */
+ info->char_props_map = char_info->props;
+
+ info->count = g_slist_length(char_info->descs);
+
if (!char_info->descs) {
BT_ERR("No Descriptors browsed for address [%s]", conn_info->addr);
return;
}
- info->count = g_slist_length(char_info->descs);
- BT_INFO("Total count of Descriptors [%d]", info->count);
-
for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
desc_info = (bt_gatt_descriptor_info_t*)l->data;
if (desc_info == NULL)
/* Fill instance ID of Descriptor */
info->inst_id[count] = desc_info->inst_id;
- /* Fill property of the parent characteristic of this descriptor */
- info->char_props_map = char_info->props;
/* Increment count of Descriptor browsed */
count++;
BT_INFO("Total descriptors browsed [%d]", count);
}
-
-static void __bt_cleanup_remote_services(struct gatt_server_info_t *conn_info)
+static void __bt_free_service_info(bt_gatt_service_info_t *svc)
{
- GSList *l;
- GSList *ll;
- GSList *lll;
- GSList *llll;
-
- bt_gatt_service_info_list_t * svc_info_list = NULL;
- bt_gatt_service_info_t *svc = NULL;
+ GSList *ll, *lll, *llll;
bt_gatt_char_info_t *chr = NULL;
bt_gatt_descriptor_info_t *desc = NULL;
bt_gatt_included_service_info_t *incl_svc = NULL;
- BT_INFO("Start Cleanup of all services");
+ BT_DBG("Service info Is Prim[%d] Inst ID [%d]", svc->is_primary, svc->inst_id);
+ /* Delete all chars and its descriptors */
+ for (ll = svc->chars; ll != NULL; ) {
+ chr = (bt_gatt_char_info_t *)ll->data;
+ ll = g_slist_next(ll);
+ if (chr == NULL)
+ continue;
+
+ for (lll = chr->descs; lll != NULL; ) {
+ desc = (bt_gatt_descriptor_info_t *)lll->data;
+ lll = g_slist_next(lll);
+ if (desc == NULL)
+ continue;
+ chr->descs = g_slist_remove(chr->descs, desc);
+ g_free(desc);
+ }
+ svc->chars = g_slist_remove(svc->chars, chr);
+ g_free(chr);
+ }
+
+ /* Delete all included services */
+ for (llll = svc->included_svcs; llll != NULL; ) {
+ incl_svc = (bt_gatt_included_service_info_t *)llll->data;
+ llll = g_slist_next(llll);
+ if (incl_svc == NULL)
+ continue;
+ svc->included_svcs = g_slist_remove(svc->included_svcs, incl_svc);
+ g_free(incl_svc);
+ }
+}
+
+static void __bt_cleanup_remote_services(struct gatt_server_info_t *conn_info)
+{
+ bt_gatt_service_info_list_t *svc_info_list = NULL;
+ bt_gatt_service_info_t *svc = NULL;
+ GSList *l;
svc_info_list = __bt_get_service_info_list(conn_info->connection_id);
if (!svc_info_list) {
return;
}
- BT_INFO("Num Services [%d]", g_slist_length(svc_info_list->services));
- for (l = svc_info_list->services; l;) {
- svc = (bt_gatt_service_info_t*)l->data;
+ BT_INFO("Start Cleanup of all services. Num Services [%d]", g_slist_length(svc_info_list->services));
+ for (l = svc_info_list->services; l != NULL; ) {
+ svc = (bt_gatt_service_info_t *)l->data;
l = g_slist_next(l);
if (svc == NULL)
continue;
- BT_INFO("Service info Is Prim[%d] Inst ID [%d]",
- svc->is_primary, svc->inst_id);
- BT_INFO("Num chars [%d]", g_slist_length(svc->chars));
- /* Delete all chars and its descriptors */
- for (ll = svc->chars; ll;) {
- chr = (bt_gatt_char_info_t*)ll->data;
- ll = g_slist_next(ll);
- if (chr == NULL)
- continue;
-
- BT_INFO("Num descs [%d]", g_slist_length(chr->descs));
- for (lll = chr->descs; lll;) {
- desc = (bt_gatt_descriptor_info_t *)lll->data;
- lll = g_slist_next(lll);
- if (desc == NULL)
- continue;
- chr->descs = g_slist_remove(chr->descs, desc);
- g_free(desc);
- }
- svc->chars = g_slist_remove(svc->chars, chr);
- g_free(chr);
- }
-
- BT_INFO("Num incl svcs [%d]", g_slist_length(svc->included_svcs));
- /* Delete all included services */
- for (llll = svc->included_svcs; llll;) {
- incl_svc = (bt_gatt_included_service_info_t*)llll->data;
- llll = g_slist_next(llll);
- if (incl_svc == NULL)
- continue;
-
- svc->included_svcs = g_slist_remove(svc->included_svcs, incl_svc);
- g_free(incl_svc);
- }
+ __bt_free_service_info(svc);
svc_info_list->services = g_slist_remove(svc_info_list->services, svc);
g_free(svc);
}
+
+ list_gatt_info = g_slist_remove(list_gatt_info, svc_info_list);
g_free(svc_info_list);
- BT_INFO("Cleanup of all services done");
}
int _bt_register_gatt_client_instance(const char *sender,
oal_uuid_t uuid;
/* App should ensure that it should not send */
- BT_INFO("###Check on which instance GATT Client instance can be initialized....");
+ BT_INFO("Check on which instance GATT Client instance can be initialized....");
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
if (numapps[k].is_initialized == 1) {
BT_INFO("Instance ID [%d] is already in use..Check next slot",
/* Platform GATT client framwork does not use Default GATT client instance
This GATT client instance is never deregistred in the lifetime of bt-service */
- BT_INFO("Default UUID [%s] current registered uuid [%s]",
- DEFAULT_GATT_CLIENT_UUID, uuid_string);
if (g_strcmp0(uuid_string, DEFAULT_GATT_CLIENT_UUID) == 0) {
- BT_INFO("Default client Instance Registered [%s] Client instance [%d]",
- uuid_string, data->client_if);
+ BT_INFO("Default client Instance Registered");
gatt_default_client = data->client_if;
g_free(uuid_string);
return;
info = &numapps[k];
if (g_strcmp0(info->uuid, uuid_string) == 0) {
- BT_INFO("Found GATT client.. UUID [%s], sender [%s]", info->uuid, info->sender);
- BT_INFO("Slot [%d] occupied", k);
+ BT_INFO("Found GATT client.. sender [%s] Slot [%d] occupied", info->sender, k);
info->is_initialized = TRUE;
info->client_id = data->client_if;
__bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_GATT_CLIENT_REGISTER,
if (result == BLUETOOTH_ERROR_NONE) {
/* Check if device is already in connected list */
- conn_info = __bt_find_remote_gatt_server_info(address);
+ conn_info = _bt_find_remote_gatt_server_info(address);
if (!conn_info) {
/* Send event to BT-API */
conn_info = g_new0(struct gatt_server_info_t, 1);
conn_info->addr = g_strdup(address);
conn_info->client_id = event_data->client_if;
- BT_INFO("Added GATT server addr[%s]", conn_info->addr);
+#ifdef __INTEGRATE_GATT_INFO__
+ conn_info->instance_id = -1;
+#endif
conn_info->connection_id = event_data->conn_id;
gatt_server_info_list = g_slist_append(gatt_server_info_list, conn_info);
- BT_INFO("Total num of connected Remote GATT server devices [%d]",
+ BT_DBG("Total num of connected Remote GATT server devices [%d]",
g_slist_length(gatt_server_info_list));
#if 0
#endif
} else
BT_ERR("Local GATT Client connected event for addr[%s], but device is in connected list already", address);
+
+ __bt_add_mtu_gatt_device(address);
} else
BT_ERR("GATT Client Connection failed!!");
__bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
address, BT_ADDRESS_STRING_SIZE);
BT_ERR("Failed to connect Local GATT Remote addr[%s]", address);
+ g_free(address);
return;
}
} else {
address, event_data->client_if, event_data->conn_id, event_data->status);
/* Remove Connection info */
- conn_info = __bt_find_remote_gatt_server_info(address);
+ conn_info = _bt_find_remote_gatt_server_info(address);
if (conn_info) {
param = g_variant_new("(is)", result, address);
} else
BT_INFO("Can not find conn info, already removed!");
+ __bt_remove_mtu_gatt_device(address);
+
/* If outgoing connection Info is present, then remove it */
out_conn_info = __bt_find_gatt_outgoing_conn_info(address);
if (out_conn_info) {
static void __bt_handle_client_service_search_result(
event_gattc_service_result_t *event_data)
{
- BT_INFO("+");
- BT_INFO("received the gatt service search result");
/* Pre: status is never fail from OAL */
/* Find service list from address */
bt_gatt_service_info_list_t *svc_info_list;
bt_gatt_service_info_t *svc_info;
- BT_INFO("Search Result: status [%d] conn_id [%d]",
- event_data->conn_status.status,
- event_data->conn_status.conn_id);
svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
if (!svc_info_list) {
- BT_INFO("Service info list not present for this connection ID, means first time browse");
+ BT_DBG("Service info list not present for connection ID %d, means first time browse", event_data->conn_status.conn_id);
/* Means for this conn_id, no services are ever browsed, first time,
create service info list for this conn_id */
svc_info_list = g_malloc0(sizeof(bt_gatt_service_info_list_t));
svc_info_list->conn_id = event_data->conn_status.conn_id;
list_gatt_info = g_slist_append(list_gatt_info, svc_info_list);
- } else {
- BT_INFO("Service info list Already present for this connection ID, means not first time browse for this conn ID ");
}
/* send list and current service's uuid and instance id to find it */
in remote GATT device, update uuid info in svc info list structure, to be used when
search is completed */
if (!svc_info) {
- BT_INFO("Service Not found in svc info list for this connection ID");
if (svc_info_list->info.is_changed) {
- BT_INFO("Service Changed indication already found for this connection ID");
+ BT_DBG("Service Changed indication already found for connection ID %d", event_data->conn_status.conn_id);
memcpy(svc_info_list->info.uuid, event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
}
/* Create and add new service in service list */
svc_info->inst_id = event_data->srvc_id.id.inst_id;
svc_info->is_primary = event_data->srvc_id.is_prmry;
svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
- BT_INFO("Service created and added in Svc info listf or this connection ID");
+ BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_status.conn_id);
} else {
- BT_INFO("Service Already found to be present inside the svc info list for this connection ID");
/* If returned matching service info, then just update service_rmeoved value inside it to 0 */
svc_info->is_removed = 0;
}
static void __bt_handle_client_service_search_completed(
event_gattc_conn_status_t *event_data)
{
- BT_INFO("+");
struct gatt_server_info_t *conn_info = NULL;
bt_gatt_service_info_list_t *svc_info_list;
bt_gatt_service_info_t *svc_info;
bt_gatt_char_info_t *char_info;
bt_char_browse_info_t browse_info;
- BT_INFO("Characteristic search result status [%d]",
- event_data->conn_status.status);
-
memset(&browse_info, 0x00, sizeof(bt_char_browse_info_t));
/* If success */
/* Find Matching char from service info in event */
char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
- if (char_info == NULL)
- BT_ERR("char_info is NULL");
/* If not found, then add new characteristic and return */
if (!char_info) {
- BT_INFO(" add new characteristic");
+ BT_DBG("Add new characteristic");
char_info = g_malloc0(sizeof(bt_gatt_char_info_t));
memcpy(char_info->uuid, event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
svc_info->chars = g_slist_append(svc_info->chars, char_info);
} else {
/* If found, then return */
- BT_INFO("Characteristic browsed is already presesnt");
+ BT_DBG("update char property as Characteristic browsed is already present");
+ char_info->props |= event_data->char_prop;
}
} else {
/* If Not success: Means Charc browse is completed */
/* Find char list from service in event */
/* Find service list from address */
svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
+ if (svc_info_list == NULL) {
+ BT_ERR("svc_info_list is NULL");
+ return;
+ }
/* Find service info from service in event */
svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
+ if (svc_info == NULL) {
+ BT_ERR("svc_info is NULL");
+ return;
+ }
/* Build char list from service in event */
__bt_build_char_browse_info(event_data->conn_status.conn_id,
bt_gatt_descriptor_info_t *desc_info;
bt_descriptor_browse_info_t browse_info;
- BT_INFO("descriptor search result status [%d]", event_data->conn_status.status);
+ BT_DBG("descriptor search result status [%d]", event_data->conn_status.status);
memset(&browse_info, 0x00, sizeof(bt_descriptor_browse_info_t));
if (event_data->conn_status.status == OAL_STATUS_SUCCESS) {
/* Find service list from address */
svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
+ if (svc_info_list == NULL) {
+ BT_ERR("svc_info_list is NULL");
+ return;
+ }
+
svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
+ if (svc_info == NULL) {
+ BT_ERR("svc_info is NULL");
+ return;
+ }
+
char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
- desc_info = __bt_find_matching_desc(char_info, &event_data->descr_id);
+ if (char_info == NULL) {
+ BT_ERR("char_info is NULL");
+ return;
+ }
+ desc_info = __bt_find_matching_desc(char_info, &event_data->descr_id);
/* If not found, add new descriptor and return */
if (!desc_info) {
desc_info = g_malloc0(sizeof(bt_gatt_descriptor_info_t));
/* Find included service list from service in event */
/* Create response and return by sending event*/
svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
+ if (svc_info_list == NULL) {
+ BT_ERR("svc_info_list is NULL");
+ return;
+ }
/* Find service info from service in event */
svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
+ if (svc_info == NULL) {
+ BT_ERR("svc_info is NULL");
+ return;
+ }
/* Find char info from char in event */
char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
+ if (char_info == NULL) {
+ BT_ERR("char_info is NULL");
+ return;
+ }
/* Build descriptor list from char in event */
__bt_build_descriptor_browse_info(event_data->conn_status.conn_id,
char *read_val = NULL;
char *svc_uuid = NULL;
char *char_uuid = NULL;
- int i;
int uuid_len = 16;
- BT_INFO("+");
-
//memset(&read_info, 0x00, sizeof(bt_gatt_handle_property_t));
memset(&read_info, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
else {
if (event_data->data_len > 0) {
/* DEBUG */
- for (i = 0; i < event_data->data_len; i++)
- BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
+ // for (i = 0; i < event_data->data_len; i++)
+ // BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
/* Read data */
read_val = g_memdup(&event_data->data[0], event_data->data_len);
read_val,
event_data->data_len,
TRUE, NULL, NULL);
- /* SVC uuid */
- svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
-
- data_svc_uuid = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- svc_uuid,
- 16,
- TRUE, NULL, NULL);
-
- /* Char uuid */
- char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
-
- data_char_uuid = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- char_uuid,
- 16,
- TRUE, NULL, NULL);
- param = g_variant_new("(isn@ayin@ayin@ay)", result,
- conn_info->addr,
- 16,
- data_svc_uuid,
- event_data->uuid_status.srvc_id.id.inst_id,
- 16,
- data_char_uuid,
- event_data->uuid_status.char_id.inst_id,
- event_data->data_len,
- data);
-
- /* Send Event */
- _bt_send_event(BT_GATT_CLIENT_EVENT,
- BLUETOOTH_EVENT_GATT_READ_CHAR,
- param);
} else {
BT_ERR("Characteristic Read success, but no data!!!");
- result = BLUETOOTH_ERROR_INTERNAL;
+
+ data = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ NULL,
+ 0,
+ FALSE, NULL, NULL);
}
+
+ /* SVC uuid */
+ svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
+
+ data_svc_uuid = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ svc_uuid,
+ 16,
+ TRUE, NULL, NULL);
+
+ /* Char uuid */
+ char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
+
+ data_char_uuid = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ char_uuid,
+ 16,
+ TRUE, NULL, NULL);
+
+ param = g_variant_new("(isn@ayin@ayin@ay)", result,
+ conn_info->addr,
+ 16,
+ data_svc_uuid,
+ event_data->uuid_status.srvc_id.id.inst_id,
+ 16,
+ data_char_uuid,
+ event_data->uuid_status.char_id.inst_id,
+ event_data->data_len,
+ data);
+
+ /* Send Event */
+ _bt_send_event(BT_GATT_CLIENT_EVENT,
+ BLUETOOTH_EVENT_GATT_READ_CHAR,
+ param);
}
/* Send DBUS return */
__bt_gatt_handle_pending_request_info(result,
if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
result = BLUETOOTH_ERROR_INTERNAL;
else {
+ BT_INFO("desc data len:%d", event_data->data_len);
if (event_data->data_len > 0) {
/* DEBUG */
for (i = 0; i < event_data->data_len; i++)
read_val,
event_data->data_len,
TRUE, NULL, NULL);
- /* SVC uuid */
- svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
-
- data_svc_uuid = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- svc_uuid,
- 16,
- TRUE, NULL, NULL);
-
- /* Char uuid */
- char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
-
- data_char_uuid = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- char_uuid,
- 16,
- TRUE, NULL, NULL);
-
- /* Desc uuid */
- desc_uuid = g_memdup(&event_data->uuid_status.descr_id.uuid.uuid[0], uuid_len);
+ } else {
+ BT_INFO("Descriptor Read success, but no data!!!");
- data_desc_uuid = g_variant_new_from_data(
+ data = g_variant_new_from_data(
G_VARIANT_TYPE_BYTESTRING,
- desc_uuid,
- 16,
- TRUE, NULL, NULL);
-
- param = g_variant_new("(isn@ayin@ayin@ayin@ay)", result,
- conn_info->addr,
- uuid_len,
- data_svc_uuid,
- event_data->uuid_status.srvc_id.id.inst_id,
- 16,
- data_char_uuid,
- event_data->uuid_status.char_id.inst_id,
- 16,
- data_desc_uuid,
- event_data->uuid_status.descr_id.inst_id,
- event_data->data_len,
- data);
-
- /* Send Event */
- _bt_send_event(BT_GATT_CLIENT_EVENT,
+ NULL,
+ 0,
+ FALSE, NULL, NULL);
+ }
+ /* SVC uuid */
+ svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
+
+ data_svc_uuid = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ svc_uuid,
+ 16,
+ TRUE, NULL, NULL);
+
+ /* Char uuid */
+ char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
+
+ data_char_uuid = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ char_uuid,
+ 16,
+ TRUE, NULL, NULL);
+
+ /* Desc uuid */
+ desc_uuid = g_memdup(&event_data->uuid_status.descr_id.uuid.uuid[0], uuid_len);
+
+ data_desc_uuid = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ desc_uuid,
+ 16,
+ TRUE, NULL, NULL);
+
+ param = g_variant_new("(isn@ayin@ayin@ayin@ay)", result,
+ conn_info->addr,
+ uuid_len,
+ data_svc_uuid,
+ event_data->uuid_status.srvc_id.id.inst_id,
+ 16,
+ data_char_uuid,
+ event_data->uuid_status.char_id.inst_id,
+ 16,
+ data_desc_uuid,
+ event_data->uuid_status.descr_id.inst_id,
+ event_data->data_len,
+ data);
+
+ /* Send Event */
+ _bt_send_event(BT_GATT_CLIENT_EVENT,
BLUETOOTH_EVENT_GATT_READ_DESC,
param);
- } else {
- BT_ERR("Descriptor Read success, but no data!!!");
- result = BLUETOOTH_ERROR_INTERNAL;
- }
}
BT_INFO("Send DBUS rpely for GATT Read Descriptor");
/* Send DBUS return */
__bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE, address,
BT_ADDRESS_STRING_SIZE);
+ g_free(address);
}
static void __bt_handle_client_notification_registered(
memset(¬if_info, 0x00, sizeof(bt_gatt_notif_reg_info_t));
BT_INFO("Client Interface [%d] status [%d]",
- event_data->client_if,
+ event_data->conn_id,
event_data->status);
/* Extract Address from conn_id of event data */
- conn_info = __bt_find_remote_gatt_server_info_from_client_if(
- event_data->client_if);
-
+ conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
if (!conn_info) {
BT_INFO("Connection Info is not present, return");
return;
}
- BT_INFO("Notification Registered for addr [%s]",
- conn_info->addr);
-
+ BT_INFO("Notification Registered for addr [%s]", conn_info->addr);
/* Fill svc informations in buffer */
memcpy(¬if_info.svc_uuid,
sizeof(bt_gatt_notif_reg_info_t));
}
-
-gboolean _bt_is_remote_gatt_device_connected(bluetooth_device_address_t *address)
+static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data)
{
- char *addr;
- struct gatt_server_info_t *conn_info = NULL;
- gboolean connected = FALSE;
- BT_INFO("+");
-
- addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_addr_type_to_string(addr,
- (unsigned char *)&(address->addr));
+ /* No status in this event from OAL */
+ int result = BLUETOOTH_ERROR_NONE;
- BT_INFO("Check Connected or not for [%s]", addr);
- /* Check if device is already in connected list */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ /* Read Information data structures */
+ GVariant *param = NULL;
+ GVariant *data = NULL;
+ GVariant *data_svc_uuid = NULL;
+ GVariant *data_char_uuid = NULL;
+ char *read_val = NULL;
+ char *svc_uuid = NULL;
+ char *char_uuid = NULL;
+ char *addr = NULL;
+ int i;
+ int uuid_len = 16;
+ BT_INFO("+");
- if (conn_info) {
- BT_INFO("Remote GATT Server device [%s] is Connected", conn_info->addr);
- connected = TRUE;
- } else
- BT_INFO("Remote GATT Server Device [%s] is not Connected", addr);
- g_free(addr);
- return connected;
+ BT_INFO("Notifcation of charc data changed");
+
+ if (event_data->data_len > 0) {
+ /* DEBUG */
+ for (i = 0; i < event_data->data_len; i++)
+ BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
+
+ /* Fill address */
+ addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_addr_type_to_string(addr,
+ (unsigned char *)&(event_data->address.addr));
+
+ /* Read data */
+ read_val = g_memdup(&event_data->data[0], event_data->data_len);
+
+ data = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ read_val,
+ event_data->data_len,
+ TRUE, NULL, NULL);
+ /* SVC uuid */
+ svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
+
+ data_svc_uuid = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ svc_uuid,
+ uuid_len,
+ TRUE, NULL, NULL);
+
+ /* Char uuid */
+ char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
+
+ data_char_uuid = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ char_uuid,
+ uuid_len,
+ TRUE, NULL, NULL);
+
+ /* Build Param */
+ param = g_variant_new("(isn@ayin@ayin@ay)", result,
+ addr,
+ 16,
+ data_svc_uuid,
+ event_data->srvc_id.id.inst_id,
+ 16,
+ data_char_uuid,
+ event_data->char_id.inst_id,
+ event_data->data_len,
+ data);
+
+ /* Send Event */
+ _bt_send_event(BT_GATT_CLIENT_EVENT,
+ BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
+ param);
+ } else {
+ BT_ERR("No Data!!");
+ }
+ /* Free data */
+ if (read_val)
+ g_free(read_val);
+ if (svc_uuid)
+ g_free(svc_uuid);
+ if (char_uuid)
+ g_free(char_uuid);
+ if (addr)
+ g_free(addr);
}
-
-int _bt_connect_le_device(bluetooth_device_address_t *address,
- int auto_connect, int client_id)
+static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data)
{
- struct gatt_server_info_t *conn_info = NULL;
- struct gatt_out_conn_info_t *out_conn_info = NULL;
-
- invocation_info_t *req_info = NULL;
- int ret = OAL_STATUS_SUCCESS;
+ bt_gatt_service_info_list_t *svc_info_list;
+ GSList *l;
+ bt_gatt_service_info_t *svc_info;
+ GVariant *param = NULL;
+ char *address_str = NULL;
+ char *uuid_str = NULL;
+
+ svc_info_list = __bt_get_service_info_list(event_data->conn_id);
+ if (svc_info_list == NULL) {
+ BT_ERR("svc_info_list is NULL");
+ return;
+ }
+
+ if (event_data->change_type) {
+ /* Add service UUID in list */
+ svc_info = g_malloc0(sizeof(bt_gatt_service_info_t));
+ memcpy(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+ svc_info->inst_id = event_data->inst_id;
+ svc_info->is_primary = 1; // TODO: Need to check is_primary is required or not
+ svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
+ BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_id);
+ } else {
+ /* Remove service UUID in list */
+ for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
+ svc_info = (bt_gatt_service_info_t *)l->data;
+ if (svc_info == NULL)
+ continue;
+
+ if (!memcmp(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
+ svc_info_list->services = g_slist_remove(svc_info_list->services, svc_info);
+ __bt_free_service_info(svc_info);
+ break;
+ }
+ }
+ }
+
+ address_str = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ uuid_str = g_malloc0(BT_UUID_STRING_MAX);
+ _bt_convert_addr_type_to_string(address_str, event_data->address.addr);
+ _bt_uuid_to_string(&event_data->uuid, uuid_str);
+
+ param = g_variant_new("(iiss)", event_data->inst_id, event_data->change_type, address_str, uuid_str);
+
+ _bt_send_event(BT_GATT_CLIENT_EVENT,
+ BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED,
+ param);
+ g_free(address_str);
+ g_free(uuid_str);
+}
+
+gboolean _bt_is_remote_gatt_device_connected(bluetooth_device_address_t *address)
+{
+ char *addr;
+ struct gatt_server_info_t *conn_info = NULL;
+ gboolean connected = FALSE;
+
+ addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_addr_type_to_string(addr,
+ (unsigned char *)&(address->addr));
+
+ BT_DBG("Check GATT connection status of [%s]", addr);
+ /* Check if device is already in connected list */
+ conn_info = _bt_find_remote_gatt_server_info(addr);
+
+ if (conn_info) {
+ BT_DBG("Remote GATT Server device [%s] is Connected", conn_info->addr);
+ connected = TRUE;
+ } else {
+ struct gatt_client_info_t *client_info = NULL;
+
+ BT_INFO("Remote GATT Server Device [%s] is not Connected", addr);
+
+ /* Check if device is already in connected list */
+ client_info = _bt_find_remote_gatt_client_info(addr);
+
+ if (client_info) {
+ BT_DBG("Remote Client device [%s] is Connected", client_info->addr);
+ connected = TRUE;
+ } else {
+ BT_INFO("Remote GATT Client Device [%s] is not Connected", addr);
+ }
+ }
+
+ g_free(addr);
+ return connected;
+}
+
+void _bt_handle_invocation_context(int function_name, void *data)
+{
+ switch (function_name) {
+ case BT_CONNECT_LE:
+ __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_CONNECT_LE,
+ (char *)data, BT_ADDRESS_STRING_SIZE);
+ break;
+ default:
+ break;
+ }
+}
+
+int _bt_connect_le_device(bluetooth_device_address_t *address,
+ int auto_connect, int client_id)
+{
+ struct gatt_server_info_t *conn_info = NULL;
+ struct gatt_out_conn_info_t *out_conn_info = NULL;
+
+ invocation_info_t *req_info = NULL;
+ int ret = OAL_STATUS_SUCCESS;
char *addr;
char *remote_address = NULL;
BT_CHECK_PARAMETER(address, return);
- BT_INFO("+");
-
addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
_bt_convert_addr_type_to_string(addr, address->addr);
- BT_INFO("GATT Client connect request for address [%s] client instance [%d]",
+ BT_DBG("GATT Client connect request for address [%s] client instance [%d]",
addr, client_id);
if (req_info) {
remote_address = (char*)req_info->user_data;
if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
- BT_INFO("Already Connection ongoing for same remote GATT Server address [%s]", remote_address);
+ BT_DBG("Already Connection ongoing for same remote GATT Server address [%s]", remote_address);
/* Return and wait for events to be sent to all apps */
g_free(addr);
return BLUETOOTH_ERROR_IN_PROGRESS;
}
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
BT_ERR("GATT Server is already connected..");
g_free(addr);
/* Check if app sent 0 client id for connection, in such case, use default gatt client ID */
if (client_id == 0) {
- BT_INFO("GATT CLient connect request sent by an app without any client instance [%d]",
- client_id);
- BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
+ /* GATT CLient connect request sent by an app without any client instance [0] */
+ BT_DBG("Assign default GATT client id [%d]", gatt_default_client);
client_id = gatt_default_client;
}
ret = gattc_connect(client_id, (bt_address_t*)(address), auto_connect);
if (ret != OAL_STATUS_SUCCESS) {
- BT_ERR("ret: %d", ret);
+ BT_ERR("gattc_connect is failed. ret: %d", ret);
g_free(addr);
return BLUETOOTH_ERROR_INTERNAL;
}
struct gatt_server_info_t *conn_info = NULL;
invocation_info_t *req_info = NULL;
int ret = OAL_STATUS_SUCCESS;
- BT_INFO("+");
+ BT_DBG("+");
/* Check if any app is already browsing primary services on the same remote GATT Server */
req_info = _bt_get_request_info_data(BT_GATT_GET_PRIMARY_SERVICES, address);
}
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(address);
+ conn_info = _bt_find_remote_gatt_server_info(address);
if (conn_info) {
BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
oal_gatt_srvc_id_t srvc_id;
int ret = OAL_STATUS_SUCCESS;
char *addr;
- BT_INFO("+");
/* Check if any app is already browsing characteristics of the same service on the same remote GATT Server */
req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_SERVICE_PROPERTIES);
if (req_info) {
prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
if (prop && !memcmp(svc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t))
- && memcmp(prop->svc.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
+ && !memcmp(prop->svc.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
&& prop->svc.instance_id == svc->svc.instance_id) {
BT_INFO("Already Properties browsing for Primary Service ongoing for same remote GATT Server");
/* Return and wait for events to be sent to all apps */
_bt_convert_addr_type_to_string(addr, svc->device_address.addr);
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
- BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
+ BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
} else {
BT_ERR("GATT Server is not yet connected..");
BT_CHECK_PARAMETER(chr, return);
- BT_INFO("+");
-
/* Check if any app is already browsing descriptors of the same char of
particular service on the same remote GATT Server */
req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_CHARACTERISTIC_PROPERTIES);
if (req_info) {
prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
- && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
+ && !memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
&& chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
- && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
+ && !memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
&& chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
BT_INFO("Already Properties browsing for Characteristic ongoing for same remote GATT Server");
/* Return and wait for events to be sent to all apps */
_bt_convert_addr_type_to_string(addr, chr->device_address.addr);
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
- BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
+ BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
} else {
BT_ERR("GATT Server is not yet connected..");
BT_CHECK_PARAMETER(chr, return);
- BT_INFO("+");
-
/* Check if any app is already Reading characteristic of the same char of
particular service on the same remote GATT Server */
req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_CHARACTERISTIC);
_bt_convert_addr_type_to_string(addr, chr->device_address.addr);
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
- BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
+ BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
} else {
BT_ERR("GATT Server is not yet connected..");
BT_CHECK_PARAMETER(desc, return);
- BT_INFO("+");
-
/* Check if any app is already Reading descriptors of the same char of
particular service on the same remote GATT Server */
req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_DESCRIPTOR_VALUE);
_bt_convert_addr_type_to_string(addr, desc->device_address.addr);
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
- BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
+ BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
} else {
BT_ERR("GATT Server is not yet connected..");
return BLUETOOTH_ERROR_NONE;
}
+/*acquire Notify*/
+int _bt_gatt_acquire_notify(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
+{
+ struct gatt_server_info_t *conn_info = NULL;
+ oal_gatt_srvc_id_t srvc_id;
+ oal_gatt_id_t char_id;
+ int ret = OAL_STATUS_SUCCESS;
+ char *addr;
+
+ BT_CHECK_PARAMETER(chr, return);
+
+ addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
+ _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
+
+ /* Check if remote GATT Server is connected or not */
+ conn_info = _bt_find_remote_gatt_server_info(addr);
+ if (conn_info) {
+ BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
+ conn_info->addr, conn_info->connection_id);
+ } else {
+ BT_ERR("GATT Server is not yet connected..");
+ g_free(addr);
+ return BLUETOOTH_ERROR_NOT_CONNECTED;
+ }
+
+ srvc_id.is_prmry = TRUE;
+ srvc_id.id.inst_id = chr->svc.instance_id;
+ memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+ char_id.inst_id = chr->characteristic.instance_id;
+ memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+ ret = gattc_acquire_notify(conn_info->connection_id, &srvc_id, &char_id, fd, mtu);
+
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("ret: %d", ret);
+ g_free(addr);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ BT_INFO("GATT characterstics FD [%d] mtu[%d]", *fd, *mtu);
+ g_free(addr);
+ return BLUETOOTH_ERROR_NONE;
+}
+
+/*acquire Write*/
+int _bt_gatt_acquire_write(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
+{
+
+ struct gatt_server_info_t *conn_info = NULL;
+ oal_gatt_srvc_id_t srvc_id;
+ oal_gatt_id_t char_id;
+ int ret = OAL_STATUS_SUCCESS;
+ char *addr;
+
+ BT_CHECK_PARAMETER(chr, return);
+
+ addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
+ _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
+
+ /* Check if remote GATT Server is connected or not */
+ conn_info = _bt_find_remote_gatt_server_info(addr);
+ if (conn_info) {
+ BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
+ conn_info->addr, conn_info->connection_id);
+ } else {
+ BT_ERR("GATT Server is not yet connected..");
+ g_free(addr);
+ return BLUETOOTH_ERROR_NOT_CONNECTED;
+ }
+
+ srvc_id.is_prmry = TRUE;
+ srvc_id.id.inst_id = chr->svc.instance_id;
+ memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+ char_id.inst_id = chr->characteristic.instance_id;
+ memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+ ret = gattc_acquire_write(conn_info->connection_id, &srvc_id, &char_id,
+ OAL_GATT_AUTH_REQ_NONE, fd, mtu);
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("ret: %d", ret);
+ g_free(addr);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ BT_INFO("GATT characterstics FD [%d] mtu [%d]", *fd, *mtu);
+ g_free(addr);
+ return BLUETOOTH_ERROR_NONE;
+
+}
+
/* Write Characteristic */
int _bt_gatt_write_characteristic_value_by_type(
_bt_convert_addr_type_to_string(addr, chr->device_address.addr);
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
_bt_convert_addr_type_to_string(addr, desc->device_address.addr);
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
_bt_convert_addr_type_to_string(addr, chr->device_address.addr);
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
+ conn_info = _bt_find_remote_gatt_server_info(addr);
if (conn_info) {
BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
conn_info->addr, conn_info->connection_id);
/* Register or unregister Notification characteristic */
if (is_notify)
- ret = gattc_register_for_notification(conn_info->client_id,
+ ret = gattc_register_for_notification(conn_info->connection_id,
(bt_address_t*)&(chr->device_address),
&srvc_id, &char_id);
else
- ret = gattc_deregister_for_notification(conn_info->client_id,
+ ret = gattc_deregister_for_notification(conn_info->connection_id,
(bt_address_t*)&(chr->device_address),
&srvc_id, &char_id);
int client_id)
{
struct gatt_server_info_t *conn_info = NULL;
+ struct gatt_client_info_t *rem_client_conn_info = NULL;
invocation_info_t *req_info = NULL;
int ret = OAL_STATUS_SUCCESS;
char *addr;
BT_CHECK_PARAMETER(address, return);
- BT_INFO("+");
-
addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
_bt_convert_addr_type_to_string(addr, address->addr);
BT_INFO("GATT Client Disconnect request for address [%s]", addr);
if (req_info) {
remote_address = (char*)req_info->user_data;
if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
- BT_INFO("Already DisConnection ongoing for same remote GATT Server address [%s]", remote_address);
+ BT_DBG("Already DisConnection ongoing for same remote GATT Server address [%s]", remote_address);
/* Return success and wait for events to be sent to all apps */
g_free(addr);
return BLUETOOTH_ERROR_IN_PROGRESS;
}
}
/* Check if remote GATT Server is connected or not */
- conn_info = __bt_find_remote_gatt_server_info(addr);
- if (!conn_info) {
- BT_ERR("GATT Server is not connected..");
- g_free(addr);
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
- }
+ conn_info = _bt_find_remote_gatt_server_info(addr);
+ if (conn_info) {
+ /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */
+ if (client_id == 0) {
+ BT_INFO("GATT CLient Disconnect request sent by an app without any client instance [%d]",
+ client_id);
+ BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
+ client_id = gatt_default_client;
+ }
- /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */
- if (client_id == 0) {
- BT_INFO("GATT CLient Disconnect request sent by an app without any client instance [%d]",
- client_id);
- BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
- client_id = gatt_default_client;
- }
+ BT_INFO("Disconnect remote gatt server using CLient ID [%d] Connection ID [%d]", client_id, conn_info->connection_id);
+ ret = gattc_disconnect(client_id, (bt_address_t*)(address),
+ conn_info->connection_id);
+ } else {
+ /* check if remote client is connected */
+ rem_client_conn_info = _bt_find_remote_gatt_client_info(addr);
- BT_INFO("Disconnect using CLient ID [%d] Connection ID [%d]", client_id, conn_info->connection_id);
- ret = gattc_disconnect(client_id, (bt_address_t*)(address),
- conn_info->connection_id);
+ if (!rem_client_conn_info || client_id != 0) {
+ BT_ERR("GATT device is not connected..");
+ g_free(addr);
+ return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+ }
+
+ BT_INFO("Disconnect remote gatt client ");
+
+ ret = gatts_disconnect(rem_client_conn_info->instance_id,
+ (bt_address_t*)(address), rem_client_conn_info->connection_id);
+ }
if (ret != OAL_STATUS_SUCCESS) {
BT_ERR("ret: %d", ret);
int k;
bt_service_app_info_t *info = NULL;
- BT_INFO("Enable Servic changed Indication watcher [%d] for app [%s]",
- is_enabled, sender);
+ BT_INFO("%s Servic changed Indication watcher for app [%s]",
+ is_enabled ? "Enable":"Disable", sender);
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
info = &numapps[k];
if (g_strcmp0(sender, info->sender) == 0 &&
memcmp(info->address.addr, address->addr,
sizeof(bluetooth_device_address_t)) == 0) {
- BT_INFO("Found GATT client App.. UUID [%s], sender [%s]", info->uuid, info->sender);
+ BT_DBG("Found GATT client App.. [%s], sender [%s]", info->uuid, info->sender);
info->is_watcher_enabled = is_enabled;
}
}
int _bt_unregister_gatt_client_instance(const char *sender, int client_id)
{
- BT_INFO("Unregister Allocated GATT CLient instance [%s] Client ID [%d]",
- sender, client_id);
- int result = BLUETOOTH_ERROR_NONE;
- int k;
+ bt_service_app_info_t *info = NULL;
+ int k, ret;
+
+ BT_DBG("Unregister Allocated GATT Client instance [%s] Client ID [%d]", sender, client_id);
/* Unregister CLient instance associated with address X. It is possible that another app still
has client_id valid for same remote address */
- bt_service_app_info_t *info = NULL;
-
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
info = &numapps[k];
/* Exact matching of sender */
if (!g_strcmp0(info->sender, sender) && info->client_id == client_id) { /* Check for only valid GATT client Instance */
- BT_INFO("Unregister GATT client instance [%d]", info->client_id);
- result = __bt_do_unregister_gatt_instance(info->client_id);
- if (result != BLUETOOTH_ERROR_NONE)
- BT_ERR("Error in unregistering GATT Client Interface");
+ numapps[k].client_id = -1;
+ numapps[k].is_initialized = FALSE;
+ memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
+ memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
+ memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
- break;
+ /* Its a GATT Client Instance */
+ ret = gattc_deregister(client_id);
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
+ return BLUETOOTH_ERROR_INTERNAL;
+ } else {
+ return BLUETOOTH_ERROR_NONE;
+ }
}
}
- return result;
+
+ return BLUETOOTH_ERROR_NOT_FOUND;
+}
+
+static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ struct gatt_server_info_t *conn_info = NULL;
+ GVariant *param = NULL;
+ guint16 mtu = 0;
+ guint8 status = 0;
+
+ conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
+ if (conn_info == NULL) {
+ BT_ERR("Cant find connection Information");
+ return;
+ }
+
+ BT_INFO("GATT Client: MTU Configured from addr [%s] status [%d] MTU size [%d]",
+ conn_info->addr, event_data->status, event_data->mtu);
+
+ if (event_data->status != OAL_STATUS_SUCCESS)
+ result = BLUETOOTH_ERROR_INTERNAL;
+
+ BT_INFO("reply BT_REQ_ATT_MTU ");
+
+ /* DBUS Return fo BT_REQ_ATT_MTU for all the apps */
+ __bt_gatt_handle_pending_request_info(result, BT_REQ_ATT_MTU, conn_info->addr,
+ BT_ADDRESS_STRING_SIZE);
+
+ if (result == BLUETOOTH_ERROR_NONE) {
+ BT_INFO("sending mtu event");
+
+ mtu = event_data->mtu;
+ param = g_variant_new("(isqy)",
+ result,
+ conn_info->addr,
+ mtu,
+ status);
+
+ /* Send event to BT-API */
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
+ param);
+
+ /* Update the MTU for current connection */
+ BT_INFO("Updating the MTU for current connection");
+ __bt_update_mtu_gatt_device(conn_info->addr, event_data->mtu);
+ }
+}
+
+static struct gatt_mtu_info_t *__bt_find_mtu_gatt_device(char *address)
+{
+ GSList *l = NULL;
+ struct gatt_mtu_info_t *info = NULL;
+
+ BT_INFO("+");
+
+ for (l = gatt_mtu_info_list; l != NULL; l = g_slist_next(l)) {
+ info = (struct gatt_mtu_info_t*)l->data;
+ if (info == NULL)
+ continue;
+
+ if (!g_strcmp0(info->addr, address)) {
+ BT_INFO("Remote GATT device found addr[%s]", info->addr);
+ return info;
+ }
+ }
+
+ BT_INFO("Not found Remote GATT device addr[%s]", address);
+ return NULL;
+}
+
+static void __bt_remove_mtu_gatt_device(char *address)
+{
+ struct gatt_mtu_info_t *dev_info = NULL;
+
+ BT_INFO("+");
+
+ dev_info = __bt_find_mtu_gatt_device(address);
+
+ if (dev_info) {
+ BT_INFO("removing the gatt device from mtu list");
+ gatt_mtu_info_list = g_slist_remove(gatt_mtu_info_list, dev_info);
+ g_free(dev_info->addr);
+ g_free(dev_info);
+ }
+}
+
+static void __bt_add_mtu_gatt_device(char *address)
+{
+ struct gatt_mtu_info_t *dev_info = NULL;
+
+ BT_INFO("+");
+
+ dev_info = __bt_find_mtu_gatt_device(address);
+
+ if (!dev_info) {
+ BT_INFO("adding the gatt device in mtu list");
+ dev_info = g_new0(struct gatt_mtu_info_t, 1);
+ dev_info->addr = g_strdup(address);
+ dev_info->att_mtu = BT_DEFAULT_ATT_MTU;
+ gatt_mtu_info_list = g_slist_append(gatt_mtu_info_list, dev_info);
+ }
+}
+
+static void __bt_update_mtu_gatt_device(char *address, int mtu)
+{
+ struct gatt_mtu_info_t *dev_info = NULL;
+
+ BT_INFO("+");
+
+ dev_info = __bt_find_mtu_gatt_device(address);
+
+ if (dev_info) {
+ BT_INFO("Udating the mtu");
+ dev_info->att_mtu = mtu;
+ }
+}
+
+int _bt_gatt_get_data_batching_available_packets(
+ guint *available_packets)
+{
+ int ret = OAL_STATUS_SUCCESS;
+
+ BT_CHECK_PARAMETER(available_packets, return);
+
+ ret = gatt_get_data_batching_available_packets(available_packets);
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("ret: %d", ret);
+ if (ret == OAL_STATUS_NOT_SUPPORT)
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_gatt_enable_data_batching(bluetooth_device_address_t *address,
+ int packet_threshold, int timeout)
+{
+ int ret = OAL_STATUS_SUCCESS;
+ char remote_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ BT_CHECK_PARAMETER(address, return);
+
+ _bt_convert_addr_type_to_string(remote_address, address->addr);
+ BT_INFO("Enable GATT data batching. address[%s] packet_threshold[%d] timeout[%d]",
+ remote_address, packet_threshold, timeout);
+
+ ret = gatt_enable_data_batching((bt_address_t*)(address), packet_threshold, timeout);
+
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("ret: %d", ret);
+ if (ret == OAL_STATUS_INVALID_PARAM)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ else if (ret == OAL_STATUS_NOT_SUPPORT)
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_gatt_disable_data_batching(bluetooth_device_address_t *address)
+{
+ int ret = OAL_STATUS_SUCCESS;
+ char remote_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ BT_CHECK_PARAMETER(address, return);
+
+ _bt_convert_addr_type_to_string(remote_address, address->addr);
+ BT_INFO("Disable GATT data batching. address[%s]", remote_address);
+
+ ret = gatt_disable_data_batching((bt_address_t*)(address));
+
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("ret: %d", ret);
+ if (ret == OAL_STATUS_NOT_SUPPORT)
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
}
#endif