Modify gatt-server interface as per bluez_5.37. 34/65034/3 accepted/tizen/common/20160414.142537 accepted/tizen/ivi/20160414.092026 accepted/tizen/mobile/20160414.092016 accepted/tizen/tv/20160414.092041 accepted/tizen/wearable/20160414.091938 submit/tizen/20160414.030922
authorh.sandeep <h.sandeep@samsung.com>
Thu, 7 Apr 2016 04:20:26 +0000 (09:50 +0530)
committerh.sandeep <h.sandeep@samsung.com>
Tue, 12 Apr 2016 08:14:14 +0000 (13:44 +0530)
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>
include/bluetooth_private.h
include/mobile/bluetooth_internal.h
include/tv/bluetooth_internal.h
include/wearable/bluetooth_internal.h
src/bluetooth-common.c
src/bluetooth-gatt.c
test/bt_unit_test.c
test/bt_unit_test.h

index 67b32cf5e0090c47ef2525030a5cb219fddb1cdf..8ef30a6f385f1fed749061d22a5d7805ec58d082 100644 (file)
@@ -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;
index 0dee35eba779ac73a264f27e8a82cbbe90f27c65..b8040eae54a43cb6373f5d53b7a368693f0ad816 100644 (file)
@@ -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);
@@ -2134,6 +2135,25 @@ int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service
  */
 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
index 8e4880782a17b75223fcc5aa7dce91444d287059..9e0072a9bd78e594f861d50e43556067aaa9498e 100644 (file)
@@ -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);
@@ -2134,6 +2135,25 @@ int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service
  */
 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
index 09a8e6d29edf66144182557ed7060889046cf4fd..772e75f46d829b8632100bd0cf7046ed7b3b75da 100644 (file)
@@ -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);
@@ -2780,6 +2781,25 @@ int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service
  */
 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
index 214cb1104a79820ef163c16815e5faf2819e7db8..eea0285dddf94072f2c15725756d0914a6a62409 100644 (file)
@@ -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;
 
index 1bb5bbc7e6dc4f38d3182fe02cb2c8a7b7c5deef..1cd0efd5c10fecf5d4227a3eae85d12c80f5f8b5 100644 (file)
@@ -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;
 }
index d7df18e62632c5c0373f84b19fa37817ba78f51e..eb0aa8bdf9d3eb278e0c1e12ed55bcd96007f9d6 100644 (file)
@@ -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,
index 29e1192f1b6c3a4d2bc4f81378d4fbd3a31ebc79..9f33e982875e514be00f0bc1e9a0388d5f3e511d 100644 (file)
@@ -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,