summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorh.sandeep <h.sandeep@samsung.com>2016-04-07 09:50:26 +0530
committerh.sandeep <h.sandeep@samsung.com>2016-04-12 13:44:14 +0530
commitbdfd375a20da79f8c8351bf145f9e6be29d51aea (patch)
tree6c1d9abfdfa1894f0712fc36191ea6c83149d012
parent76b9b1330fcecffb52c65536f84d93818450e612 (diff)
downloadbluetooth-submit/tizen/20160414.030922.tar.gz
bluetooth-submit/tizen/20160414.030922.tar.bz2
bluetooth-submit/tizen/20160414.030922.zip
1. Added new API "bt_gatt_start_server" to register the Application. 2. Modified the API "bt_gatt_server_initialize". 3. Added new properties for characteristics/Descriptors. Change-Id: I20a6d948df166f114c9358522760199ec7917b92 Signed-off-by: h.sandeep <h.sandeep@samsung.com>
-rw-r--r--include/bluetooth_private.h4
-rw-r--r--include/mobile/bluetooth_internal.h20
-rw-r--r--include/tv/bluetooth_internal.h20
-rw-r--r--include/wearable/bluetooth_internal.h20
-rw-r--r--src/bluetooth-common.c16
-rw-r--r--src/bluetooth-gatt.c66
-rw-r--r--test/bt_unit_test.c11
-rw-r--r--test/bt_unit_test.h1
8 files changed, 136 insertions, 22 deletions
diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h
index 67b32cf..8ef30a6 100644
--- a/include/bluetooth_private.h
+++ b/include/bluetooth_private.h
@@ -297,8 +297,8 @@ typedef struct {
bt_gatt_server_read_value_requested_cb read_requested_cb;
void *read_requested_user_data;
- bt_gatt_server_notification_sent_cb indication_confirm_cb;
- void *indication_confirm_user_data;
+ bt_gatt_server_notification_sent_cb notified_cb;
+ void *notified_user_data;
bt_gatt_server_notification_state_change_cb notification_changed_cb;
void *notification_changed_user_data;
diff --git a/include/mobile/bluetooth_internal.h b/include/mobile/bluetooth_internal.h
index 0dee35e..b8040ea 100644
--- a/include/mobile/bluetooth_internal.h
+++ b/include/mobile/bluetooth_internal.h
@@ -2098,6 +2098,7 @@ int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle,
*
* @see bt_gatt_server_create()
* @see bt_gatt_service_create()
+ * @see bt_gatt_server_start()
* @see bt_gatt_server_unregister_service()
*/
int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service);
@@ -2136,6 +2137,25 @@ int bt_gatt_server_unregister_all_services(bt_gatt_server_h server);
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Registers the applciation along with the GATT services of the aplciation it is hosting
+ * @since_tizen 2.4
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_ALREADY_DONE Operation is already done
+ * @retval #BT_ERROR_PERMISSION_DENIED Permission denied
+ *
+ * @see bt_gatt_server_initialize()
+ * @see bt_gatt_server_create()
+ * @see bt_gatt_service_create()
+ * @see bt_gatt_server_unregister_service()
+ */
+int bt_gatt_server_start(void);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Sends a response to the remote device as a result of a read request
* @since_tizen 2.4
*
diff --git a/include/tv/bluetooth_internal.h b/include/tv/bluetooth_internal.h
index 8e48807..9e0072a 100644
--- a/include/tv/bluetooth_internal.h
+++ b/include/tv/bluetooth_internal.h
@@ -2098,6 +2098,7 @@ int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle,
*
* @see bt_gatt_server_create()
* @see bt_gatt_service_create()
+ * @see bt_gatt_server_start()
* @see bt_gatt_server_unregister_service()
*/
int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service);
@@ -2136,6 +2137,25 @@ int bt_gatt_server_unregister_all_services(bt_gatt_server_h server);
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Registers the applciation along with the GATT services of the aplciation it is hosting
+ * @since_tizen 2.4
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_ALREADY_DONE Operation is already done
+ * @retval #BT_ERROR_PERMISSION_DENIED Permission denied
+ *
+ * @see bt_gatt_server_initialize()
+ * @see bt_gatt_server_create()
+ * @see bt_gatt_service_create()
+ * @see bt_gatt_server_unregister_service()
+ */
+int bt_gatt_server_start(void);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Sends a response to the remote device as a result of a read request
* @since_tizen 2.4
*
diff --git a/include/wearable/bluetooth_internal.h b/include/wearable/bluetooth_internal.h
index 09a8e6d..772e75f 100644
--- a/include/wearable/bluetooth_internal.h
+++ b/include/wearable/bluetooth_internal.h
@@ -2744,6 +2744,7 @@ int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle,
*
* @see bt_gatt_server_create()
* @see bt_gatt_service_create()
+ * @see bt_gatt_server_start()
* @see bt_gatt_server_unregister_service()
*/
int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service);
@@ -2782,6 +2783,25 @@ int bt_gatt_server_unregister_all_services(bt_gatt_server_h server);
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Registers the applciation along with the GATT services of the aplciation it is hosting
+ * @since_tizen 2.4
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_ALREADY_DONE Operation is already done
+ * @retval #BT_ERROR_PERMISSION_DENIED Permission denied
+ *
+ * @see bt_gatt_server_initialize()
+ * @see bt_gatt_server_create()
+ * @see bt_gatt_service_create()
+ * @see bt_gatt_server_unregister_service()
+ */
+int bt_gatt_server_start(void);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Sends a response to the remote device as a result of a read request
* @since_tizen 2.4
*
diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c
index 214cb11..eea0285 100644
--- a/src/bluetooth-common.c
+++ b/src/bluetooth-common.c
@@ -613,7 +613,7 @@ static bt_gatt_server_notification_state_change_cb __bt_gatt_attribute_get_notif
return NULL;
}
-static bt_gatt_server_notification_sent_cb __bt_gatt_attribute_get_indication_confrim_cb(
+static bt_gatt_server_notification_sent_cb __bt_gatt_attribute_get_notification_completed_cb(
bt_gatt_h service, bt_gatt_h attribute, void **user_data)
{
gchar *svc_path = (gchar *)service;
@@ -637,9 +637,9 @@ static bt_gatt_server_notification_sent_cb __bt_gatt_attribute_get_indication_co
bt_gatt_characteristic_s *chr = l3->data;
if (chr && g_strcmp0(chr->path, att_path) == 0) {
- if (chr->indication_confirm_cb) {
- *user_data = chr->indication_confirm_user_data;
- return chr->indication_confirm_cb;
+ if (chr->notified_cb) {
+ *user_data = chr->notified_user_data;
+ return chr->notified_cb;
} else
return NULL;
}
@@ -782,7 +782,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
if (event == BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED || event == BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED ||
event == BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED || event == BLUETOOTH_EVENT_ADVERTISING_STARTED ||
- event == BLUETOOTH_EVENT_GATT_SERVER_INDICATE_CONFIRMED || event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
+ event == BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED || event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
BT_INFO("NOT use bt_event_slot_container");
else if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL)
return;
@@ -1703,14 +1703,14 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
value_change->att_handle, user_data);
break;
}
- case BLUETOOTH_EVENT_GATT_SERVER_INDICATE_CONFIRMED: {
+ case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED: {
bt_gatt_indicate_confirm_t *confrim_status = param->param_data;
bt_gatt_server_notification_sent_cb cb;
void *user_data = NULL;
- cb = __bt_gatt_attribute_get_indication_confrim_cb(confrim_status->service_handle,
+ cb = __bt_gatt_attribute_get_notification_completed_cb(confrim_status->service_handle,
confrim_status->att_handle, &user_data);
- BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_INDICATE_CONFIRMED");
+ BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED");
if (cb == NULL)
return;
diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c
index 1bb5bbc..1cd0efd 100644
--- a/src/bluetooth-gatt.c
+++ b/src/bluetooth-gatt.c
@@ -30,6 +30,7 @@ static GSList *gatt_client_list = NULL;
static GSList *gatt_server_list = NULL;
static bool is_gatt_server_initialized = false;
+static bool is_gatt_server_started = false;
#ifdef TIZEN_GATT_DISABLE
#define BT_CHECK_GATT_SUPPORT() \
@@ -1390,6 +1391,12 @@ int bt_gatt_service_create(const char *uuid, bt_gatt_service_type_e type,
return BT_ERROR_OUT_OF_MEMORY;
svc->type = BT_GATT_TYPE_SERVICE;
svc->role = BT_GATT_ROLE_SERVER;
+
+ if (is_gatt_server_started) {
+ BT_ERR("Already Server started");
+ return BT_ERROR_OPERATION_FAILED;
+ }
+
if (strlen(uuid) == 8)
svc->uuid = __convert_uuid_to_uuid128(uuid);
else
@@ -1917,6 +1924,11 @@ int bt_gatt_server_initialize(void)
int ret = BT_ERROR_NONE;
+ if (is_gatt_server_started) {
+ BT_ERR("Already Server started");
+ return BT_ERROR_OPERATION_FAILED;
+ }
+
if (!is_gatt_server_initialized) {
ret = _bt_get_error_code(bluetooth_gatt_init());
@@ -1961,6 +1973,7 @@ int bt_gatt_server_deinitialize(void)
}
is_gatt_server_initialized = false;
+ is_gatt_server_started = false;
return BT_ERROR_NONE;
}
@@ -1976,6 +1989,11 @@ int bt_gatt_server_create(bt_gatt_server_h *server)
BT_CHECK_INIT_STATUS();
BT_CHECK_INPUT_PARAMETER(server);
+ if (is_gatt_server_started) {
+ BT_ERR("Already Server started");
+ return BT_ERROR_OPERATION_FAILED;
+ }
+
serv = g_malloc0(sizeof(bt_gatt_server_s));
if (serv == NULL)
return BT_ERROR_OUT_OF_MEMORY;
@@ -2054,9 +2072,13 @@ int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service)
return BT_ERROR_ALREADY_DONE;
}
+ if (is_gatt_server_started) {
+ BT_ERR("Already Server started");
+ return BT_ERROR_OPERATION_FAILED;
+ }
+
ret = _bt_get_error_code(bluetooth_gatt_add_service(svc->uuid,
&svc->path));
-
if (ret != BT_ERROR_NONE) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
return ret;
@@ -2066,8 +2088,9 @@ int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service)
GSList *desc_l;
bt_gatt_characteristic_s *chr = char_l->data;
- ret = _bt_get_error_code(bluetooth_gatt_add_new_characteristic(svc->path,
- chr->uuid,
+ ret = _bt_get_error_code(bluetooth_gatt_add_new_characteristic(
+ svc->path, chr->uuid,
+ (bt_gatt_permission_t)chr->permissions,
(bt_gatt_characteristic_property_t)chr->properties,
&chr->path));
if (ret != BT_ERROR_NONE) {
@@ -2088,8 +2111,10 @@ int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service)
for (desc_l = chr->descriptors; desc_l; desc_l = g_slist_next(desc_l)) {
bt_gatt_descriptor_s *desc = desc_l->data;
- ret = _bt_get_error_code(bluetooth_gatt_add_descriptor(chr->path,
- desc->uuid, &desc->path));
+ ret = _bt_get_error_code(bluetooth_gatt_add_descriptor(
+ chr->path, desc->uuid,
+ (bt_gatt_permission_t)desc->permissions,
+ &desc->path));
if (ret != BT_ERROR_NONE) {
BT_ERR("%s(0x%08x)",
@@ -2150,6 +2175,7 @@ int bt_gatt_server_unregister_service(bt_gatt_server_h server,
int bt_gatt_server_unregister_all_services(bt_gatt_server_h server)
{
bt_gatt_server_s *serv = (bt_gatt_server_s *)server;
+ int ret = BT_ERROR_NONE;
BT_CHECK_INIT_STATUS();
BT_CHECK_GATT_SERVER_INIT_STATUS();
@@ -2158,7 +2184,29 @@ int bt_gatt_server_unregister_all_services(bt_gatt_server_h server)
g_slist_free_full(serv->services, __bt_gatt_free_service);
serv->services = NULL;
- return BT_ERROR_NONE;
+ ret = bluetooth_gatt_unregister_application();
+ is_gatt_server_started = false;
+
+ return ret;
+}
+
+int bt_gatt_server_start(void)
+{
+ int ret = BT_ERROR_NONE;
+
+ if (!is_gatt_server_started) {
+ ret = bluetooth_gatt_register_application();
+
+ if (ret != BT_ERROR_NONE) {
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+ }
+ is_gatt_server_started = true;
+ return ret;
+ }
+
+ BT_DBG("Gatt-service already Running");
+
+ return ret;
}
int bt_gatt_server_send_response(int request_id,
@@ -2223,10 +2271,8 @@ int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm,
}
}
- if (need_confirm) {
- chr->indication_confirm_cb = callback;
- chr->indication_confirm_user_data = user_data;
- }
+ chr->notified_cb = callback;
+ chr->notified_user_data = user_data;
return ret;
}
diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c
index d7df18e..eb0aa8b 100644
--- a/test/bt_unit_test.c
+++ b/test/bt_unit_test.c
@@ -577,6 +577,8 @@ tc_table_t tc_gatt[] = {
, BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_CUSTOM_SVC},
{"Change Custom Value"
, BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_CUSTOM_VAL},
+ {"Start Server"
+ , BT_UNIT_TEST_FUNCTION_GATT_START_SERVER},
{"ANCS (Pair)"
, BT_UNIT_TEST_FUNCTION_ANCS_PAIR},
{"ANCS (Watch notification)"
@@ -5795,7 +5797,7 @@ int test_input_callback(void *data)
char *char_uuid = "2a06"; /* Alert Level */
char char_value[1] = {2}; /* high alert */
int value_length = 1;
- int permissions = BT_GATT_PERMISSION_READ;
+ int permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE;
int properties = BT_GATT_PROPERTY_READ | BT_GATT_PROPERTY_WRITE;
ret = bt_gatt_server_initialize();
@@ -5841,7 +5843,7 @@ int test_input_callback(void *data)
char char_value[4] = {10, 20, 30, 40};
char desc_value[4] = {12, 34, 56, 78};
int value_length = 4;
- int permissions = BT_GATT_PERMISSION_READ;
+ int permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE;
int properties = BT_GATT_PROPERTY_BROADCAST | BT_GATT_PROPERTY_READ |
BT_GATT_PROPERTY_WRITE | BT_GATT_PROPERTY_NOTIFY;
@@ -5893,6 +5895,11 @@ int test_input_callback(void *data)
TC_PRT("returns %s\n", __bt_get_error_message(ret));
break;
}
+ case BT_UNIT_TEST_FUNCTION_GATT_START_SERVER: {
+ ret = bt_gatt_server_start();
+ TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret));
+ break;
+ }
case BT_UNIT_TEST_FUNCTION_GATT_SERVER_FOREACH_SERVICES: {
#ifdef ARCH64
ret = bt_gatt_server_foreach_services(server,
diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h
index 29e1192..9f33e98 100644
--- a/test/bt_unit_test.h
+++ b/test/bt_unit_test.h
@@ -241,6 +241,7 @@ typedef enum {
BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_LINK_LOSS_SVC,
BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_CUSTOM_SVC,
BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_CUSTOM_VAL,
+ BT_UNIT_TEST_FUNCTION_GATT_START_SERVER,
BT_UNIT_TEST_FUNCTION_ANCS_PAIR,
BT_UNIT_TEST_FUNCTION_ANCS_WATCH,
BT_UNIT_TEST_FUNCTION_ANCS_POSITIVE_ACTION,