summaryrefslogtreecommitdiff
path: root/src/bluetooth-common.c
diff options
context:
space:
mode:
authorDoHyun Pyun <dh79.pyun@samsung.com>2017-09-20 18:25:13 +0900
committerPyun DoHyun <dh79.pyun@samsung.com>2017-09-21 07:36:36 +0000
commite2196b8a4b369aaf77c6ea7847cc2d138236776b (patch)
treee77ce92cb01c1abfa9eceb19e8fec8d127c2d792 /src/bluetooth-common.c
parentdce0f2e980f02e536cca4ef8585eb7fd6d849e83 (diff)
downloadbluetooth-e2196b8a4b369aaf77c6ea7847cc2d138236776b.tar.gz
bluetooth-e2196b8a4b369aaf77c6ea7847cc2d138236776b.tar.bz2
bluetooth-e2196b8a4b369aaf77c6ea7847cc2d138236776b.zip
Add the GATT Relay feature for the dual stack adaptation
Change-Id: I3b9d6efd865e8b72e91e6cbe86bb3a1817a5515a Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
Diffstat (limited to 'src/bluetooth-common.c')
-rw-r--r--src/bluetooth-common.c335
1 files changed, 332 insertions, 3 deletions
diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c
index 31ff603..6a5892d 100644
--- a/src/bluetooth-common.c
+++ b/src/bluetooth-common.c
@@ -635,6 +635,193 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de
return BT_ERROR_NONE;
}
+#ifdef TIZEN_FEATURE_GATT_RELAY
+/* Search for handle */
+static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(int att_handle, bt_gatt_server_h *server,
+ bt_gatt_h *gatt_handle, void **user_data)
+{
+ const GSList *gatt_server_list = NULL;
+ const GSList *l1, *l2, *l3, *l4;
+
+ gatt_server_list = _bt_gatt_get_server_list();
+
+ for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
+ bt_gatt_server_s *serv = l1->data;
+
+ if (!serv)
+ return NULL;
+
+ for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
+ bt_gatt_service_s *svc = l2->data;
+ for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
+ bt_gatt_characteristic_s *chr = l3->data;
+
+ if (chr) {
+ if (chr->handle == att_handle) {
+ if (chr->read_requested_cb) {
+ BT_INFO("GATT Server: Handle search match found! Its a characteristic: UUID [%s]", chr->uuid);
+ *user_data = chr->read_requested_user_data;
+ *gatt_handle = chr;
+ *server = serv;
+ return chr->read_requested_cb;
+ } else
+ return NULL;
+ } else {
+ for (l4 = chr->descriptors; l4 != NULL; l4 = l4->next) {
+ bt_gatt_descriptor_s *desc = l4->data;
+
+ if (desc && desc->handle == att_handle) {
+ if (desc->read_requested_cb) {
+ *user_data = desc->read_requested_user_data;
+ *gatt_handle = desc;
+ *server = serv;
+ BT_INFO("GATT Server: Handle search match found! Its a Desc UUID [%s]", desc->uuid);
+ return desc->read_requested_cb;
+ } else
+ return NULL;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_change_cb(int att_handle, bt_gatt_h *server,
+ bt_gatt_h *gatt_handle, void **user_data)
+{
+ const GSList *gatt_server_list = NULL;
+ const GSList *l1, *l2, *l3, *l4;
+
+ gatt_server_list = _bt_gatt_get_server_list();
+
+ for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
+ bt_gatt_server_s *serv = l1->data;
+
+ if (!serv)
+ return NULL;
+
+ for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
+ bt_gatt_service_s *svc = l2->data;
+ for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
+ bt_gatt_characteristic_s *chr = l3->data;
+
+ if (chr) {
+ if (chr->handle == att_handle) {
+ if (chr->write_value_requested_cb) {
+ BT_INFO("GATT Server: Handle search match found! Its a characteristic: UUID [%s]", chr->uuid);
+ *user_data = chr->write_value_requested_user_data;
+ *gatt_handle = chr;
+ *server = svc;
+ return chr->write_value_requested_cb;
+ } else
+ return NULL;
+ } else {
+ for (l4 = chr->descriptors; l4 != NULL; l4 = l4->next) {
+ bt_gatt_descriptor_s *desc = l4->data;
+
+ if (desc && desc->handle == att_handle) {
+ if (desc->write_value_requested_cb) {
+ *user_data = desc->write_value_requested_user_data;
+ *gatt_handle = desc;
+ *server = svc;
+ BT_INFO("GATT Server: Handle search match found! Its a Desc UUID [%s]", desc->uuid);
+ return desc->write_value_requested_cb;
+ } else
+ return NULL;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+static bt_gatt_server_characteristic_notification_state_changed_cb
+ __bt_gatt_attribute_get_notification_change_cb(
+ bt_gatt_server_h *server, int handle, bt_gatt_h *char_handle, void **user_data)
+{
+ const GSList *gatt_server_list = NULL;
+ const GSList *l1, *l2, *l3;
+
+ gatt_server_list = _bt_gatt_get_server_list();
+
+ for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
+ bt_gatt_server_s *serv = l1->data;
+
+ if (!serv)
+ return NULL;
+
+ for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
+ bt_gatt_service_s *svc = l2->data;
+
+ for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
+ bt_gatt_characteristic_s *chr = l3->data;
+
+ if (chr && chr->handle == handle) {
+ if (chr->notified_cb) {
+ *user_data = chr->notified_user_data;
+ *char_handle = (bt_gatt_h*) chr;
+ *server = serv;
+ return chr->notification_changed_cb;
+ } else
+ return NULL;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+static bt_gatt_server_notification_sent_cb __bt_gatt_attribute_get_notification_completed_cb(
+ bt_gatt_server_h *server, int handle, bt_gatt_h *char_handle, void **user_data)
+{
+ const GSList *gatt_server_list = NULL;
+ const GSList *l1, *l2, *l3;
+
+ gatt_server_list = _bt_gatt_get_server_list();
+
+ for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) {
+ bt_gatt_server_s *serv = l1->data;
+
+ if (!serv)
+ return NULL;
+
+ for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
+ bt_gatt_service_s *svc = l2->data;
+
+ for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
+ bt_gatt_characteristic_s *chr = l3->data;
+
+ if (chr && chr->handle == handle) {
+ if (chr->notified_cb) {
+ *user_data = chr->notified_user_data;
+ *char_handle = (bt_gatt_h*) chr;
+ *server = serv;
+ return chr->notified_cb;
+ } else
+ return NULL;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+void _bt_gatt_server_event_proxy(int event, gatt_server_event_param_t *param, void *user_data)
+{
+ bluetooth_event_param_t new_param;
+ new_param.event = param->event;
+ new_param.param_data = param->param_data;
+ new_param.result = param->result;
+ new_param.user_data = NULL;
+ __bt_event_proxy(event, &new_param, user_data);
+}
+#else
static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(
bt_gatt_h service, bt_gatt_h attribute, bt_gatt_h *gatt_handle, void **user_data)
{
@@ -691,6 +878,7 @@ static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(
return NULL;
}
+
static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_change_cb(
bt_gatt_h service, bt_gatt_h attribute, bt_gatt_h *gatt_handle, void **user_data)
{
@@ -822,6 +1010,7 @@ static bt_gatt_server_notification_sent_cb __bt_gatt_attribute_get_notification_
}
return NULL;
}
+#endif
static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info)
{
@@ -1064,7 +1253,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, &auth_information->device_address);
- BT_DBG("BUETOOTH_EVENT_PIN_REQUEST: name = %s address = %s", auth_information->device_name,
+ BT_DBG("BUETOOTH_EVENT_PIN_REQUEST: name = %s address = %s", auth_information->device_name.name,
device_addr);
((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
@@ -1078,7 +1267,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, &auth_information->device_address);
- BT_DBG("BLUETOOTH_EVENT_PASSKEY_REQUEST: name = %s address = %s", auth_information->device_name,
+ BT_DBG("BLUETOOTH_EVENT_PASSKEY_REQUEST: name = %s address = %s", auth_information->device_name.name,
device_addr);
((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
@@ -1970,10 +2159,48 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
param->param_data);
break;
case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED: {
+#ifdef TIZEN_FEATURE_GATT_RELAY
+ bluetooth_gatt_server_read_requested_info_t *read_req =
+ (bluetooth_gatt_server_read_requested_info_t *)(param->param_data);
+ bt_gatt_server_read_value_requested_cb cb_read;
+ void *user_data_read = NULL;
+ bt_gatt_h gatt_handle = NULL;
+ bt_gatt_server_h serv = NULL;
+
+ cb_read = __bt_gatt_attribute_get_read_cb(read_req->attribute_handle,
+ &serv, &gatt_handle, &user_data_read);
+
+ /* Copy data */
+ _bt_convert_address_to_string(&device_addr, &read_req->device_address);
+
+ BT_INFO("GATT Server Read Req: Addr [%s]", device_addr);
+ BT_INFO("GATT Server Read Req: Att handle[%d]", read_req->attribute_handle);
+ BT_INFO("GATT Server Read Req: Conn ID [%d]", read_req->connection_id);
+ BT_INFO("GATT Server Read Req: Trans ID [%d]", read_req->request_id);
+ BT_INFO("GATT Server Read Req: Offset [%d]", read_req->offset);
+ BT_INFO("GATT Server Read Req: Is Long [%d]", read_req->is_long);
+
+ if (cb_read == NULL) {
+ BT_INFO("GATT Server: App has not set the Read requested callback..for the current handle");
+
+ bt_gatt_server_send_response(read_req->request_id,
+ BT_GATT_REQUEST_TYPE_READ, 0,
+ BLUETOOTH_ERROR_INTERNAL, NULL, 0);
+
+ BT_INFO("GATT Server: Internal response sent for Read Request");
+ return;
+ }
+
+ cb_read(device_addr, read_req->request_id, serv, gatt_handle, read_req->offset, user_data_read);
+
+ if (device_addr != NULL)
+ free(device_addr);
+#else
bt_gatt_read_req_t *read_req = param->param_data;
bt_gatt_server_read_value_requested_cb cb;
void *user_data = NULL;
bt_gatt_h gatt_handle = NULL;
+
cb = __bt_gatt_attribute_get_read_cb(read_req->service_handle,
read_req->att_handle, &gatt_handle, &user_data);
@@ -1988,9 +2215,63 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
cb(read_req->address, read_req->req_id, read_req->service_handle,
gatt_handle, read_req->offset,
user_data);
+#endif
break;
}
case BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED: {
+#ifdef TIZEN_FEATURE_GATT_RELAY
+ BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_WRITE_REQUESTED");
+ bt_gatt_server_write_value_requested_cb cb_wr;
+ void *user_data_write = NULL;
+ bt_gatt_h gatt_handle = NULL;
+ bt_gatt_h server = NULL;
+ bluetooth_gatt_server_write_requested_info_t *write_req =
+ (bluetooth_gatt_server_write_requested_info_t *)(param->param_data);
+
+ char *val = g_malloc0(write_req->length);
+
+ memcpy(val, write_req->data.data, write_req->length);
+ cb_wr = __bt_gatt_attribute_get_value_change_cb(write_req->attribute_handle,
+ &server, &gatt_handle, &user_data_write);
+
+ /* Copy data */
+ _bt_convert_address_to_string(&device_addr, &write_req->device_address);
+
+ BT_INFO("GATT Server Write Req: Address [%s]", device_addr);
+ BT_INFO("GATT Server Write Req: Att handle [%d]", write_req->attribute_handle);
+ BT_INFO("GATT Server Write Req: Conn ID [%d]", write_req->connection_id);
+ BT_INFO("GATT Server Write Req: Trans ID [%d]", write_req->request_id);
+ BT_INFO("GATT Server Write Req: Offset [%d]", write_req->offset);
+ BT_INFO("GATT Server Write Req: Length [%d]", write_req->length);
+ BT_INFO("GATT Server Write Req: Need Resp [%d]", write_req->need_resp);
+
+ if (cb_wr == NULL) {
+ BT_INFO("GATT Server: App has not set the Write requested callback..for the current handle");
+
+ if (write_req->need_resp) {
+ BT_INFO("GATT Server: Send Response to Remote GATT client");
+
+ bt_gatt_server_send_response(write_req->request_id,
+ BT_GATT_REQUEST_TYPE_WRITE, 0,
+ BLUETOOTH_ERROR_INTERNAL, NULL, 0);
+
+ BT_INFO("GATT Server: Internal response sent for Write Request");
+ }
+
+ return;
+ }
+
+ cb_wr(device_addr, write_req->request_id, server, gatt_handle,
+ write_req->need_resp, write_req->offset,
+ val, write_req->length, user_data_write);
+
+ /* Free Data */
+ if (val != NULL)
+ g_free(val);
+
+ if (device_addr != NULL)
+ free(device_addr);
+#else
bt_gatt_value_change_t *value_change = param->param_data;
bt_gatt_server_write_value_requested_cb cb;
void *user_data = NULL;
@@ -2012,9 +2293,28 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
cb(value_change->address, value_change->req_id, value_change->service_handle,
gatt_handle, (bool)value_change->response_needed, value_change->offset,
(char *)value_change->att_value, value_change->val_len, user_data);
+#endif
break;
}
case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED: {
+ BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED");
+#ifdef TIZEN_FEATURE_GATT_RELAY
+ bluetooth_gatt_server_notification_changed_t *notif_info =
+ (bluetooth_gatt_server_notification_changed_t*)(param->param_data);
+
+ bt_gatt_server_characteristic_notification_state_changed_cb cb;
+ bt_gatt_server_h server_handle = NULL;
+ bt_gatt_h char_handle = NULL;
+ void *user_data_cfm = NULL;
+
+ cb = __bt_gatt_attribute_get_notification_change_cb(&server_handle,
+ notif_info->handle, &char_handle, &user_data_cfm);
+
+ if (cb == NULL)
+ return;
+
+ cb(notif_info->notification, server_handle, char_handle, user_data_cfm);
+#else
bt_gatt_char_notify_change_t *value_change = param->param_data;
bt_gatt_server_characteristic_notification_state_changed_cb cb;
void *user_data = NULL;
@@ -2028,9 +2328,38 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
cb(value_change->att_notify, value_change->service_handle,
gatt_handle, user_data);
+#endif
break;
}
case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED: {
+#ifdef TIZEN_FEATURE_GATT_RELAY
+ bluetooth_gatt_server_indicate_confirmed_info_t *cfm_info =
+ (bluetooth_gatt_server_indicate_confirmed_info_t*)(param->param_data);
+ bt_gatt_server_notification_sent_cb cb;
+ bt_gatt_server_h server_handle = NULL;
+ bt_gatt_h char_handle = NULL;
+
+ BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED");
+
+ void *user_data_cfm = NULL;
+
+ cb = __bt_gatt_attribute_get_notification_completed_cb(&server_handle,
+ cfm_info->handle, &char_handle, &user_data_cfm);
+
+ if (cb == NULL)
+ return;
+
+ /* Copy data */
+ _bt_convert_address_to_string(&device_addr, &cfm_info->device_address);
+
+ cb(_bt_get_error_code(param->result), device_addr,
+ server_handle, char_handle,
+ cfm_info->completed, user_data_cfm);
+
+ /* Free Data */
+ if (device_addr != NULL)
+ free(device_addr);
+#else
bt_gatt_indicate_confirm_t *confrim_status = param->param_data;
bt_gatt_server_notification_sent_cb cb;
void *user_data = NULL;
@@ -2044,7 +2373,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
cb(_bt_get_error_code(param->result), confrim_status->address,
confrim_status->service_handle,
confrim_status->att_handle, confrim_status->complete, user_data);
-
+#endif
break;
}
case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: