GATT : New GATT connect APIs 10/282310/2
authorAnuj Jain <anuj01.jain@samsung.com>
Thu, 29 Sep 2022 16:33:57 +0000 (22:03 +0530)
committerDohyun Pyun <dh79.pyun@samsung.com>
Wed, 5 Oct 2022 08:48:23 +0000 (17:48 +0900)
This patch saperate the connection state change callbacks for GATT
client and server.
This patch add the following:
-New callback APIs for GATT client and server connection state change
-New GATT client connect API.

Change-Id: Ida1d672db2b41f9a7ea6b210c30dac1e83d929ba
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
include/bluetooth_internal.h
include/bluetooth_private.h
include/bluetooth_type_internal.h
src/bluetooth-common.c
src/bluetooth-gatt.c
tests/test/bt_unit_test.c
tests/test/bt_unit_test.h

index de47431..a8f1c9c 100644 (file)
@@ -2197,6 +2197,64 @@ int bt_avrcp_control_send_player_command_to(bt_avrcp_player_command_e cmd, char
 int bt_gatt_get_uuid_specification_name(const char *uuid, char **name);
 
 /**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_CLIENT_MODULE
+ * @brief Connects to a specific LE based service on a remote bluetooth device address, asynchronously.
+ * @since_tizen 7.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/bluetooth
+ *
+ * @remarks A connection can be disconnected by bt_gatt_disconnect().
+ *
+ * @param[in] address The address of the remote Bluetooth device.
+ * @param[in] auto_connect The flag of the auto connection.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED Not enabled
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_PERMISSION_DENIED  Permission denied
+ * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
+ *
+ * @pre The Bluetooth service must be initialized with bt_initialize().
+ * @pre The remote device must support le connection.
+ * @post This function invokes bt_gatt_connection_state_changed_cb().
+ *
+ * @see bt_initialize()
+ * @see bt_gatt_client_disconnect()
+ * @see bt_gatt_client_connection_state_changed_cb()
+ */
+int bt_gatt_client_connect(bt_gatt_client_h client, bt_gatt_client_connection_state_changed_cb callback,
+               bool auto_connect, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_CLIENT_MODULE
+ * @brief Disconnects to LE connection with the given remote Bluetooth device address, asynchronously or cancels a LE connection attempt currently in progress.
+ * @since_tizen 7.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/bluetooth
+ *
+ * @param[in] address The address of the remote Bluetooth device
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED Not enabled
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_PERMISSION_DENIED  Permission denied
+ * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
+ *
+ * @post This function invokes bt_gatt_connection_state_changed_cb().
+ *
+ * @see bt_initialize()
+ * @see bt_gatt_client_connect()
+ * @see bt_gatt_connection_state_changed_cb()
+ */
+int bt_gatt_client_disconnect(bt_gatt_client_h client);
+
+/**
  * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_SERVER_MODULE
  * @brief  Updates the permissions which a characteristic or descriptor's GATT handle has.
  * @since_tizen 3.0
@@ -2305,6 +2363,42 @@ int bt_gatt_server_set_att_mtu_changed_cb(bt_gatt_server_h server, bt_gatt_serve
 int bt_gatt_server_unset_att_mtu_changed_cb(bt_gatt_server_h server);
 
 /**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Registers a callback function that will be invoked when the connection state is changed.
+ * @since_tizen 7.0
+ *
+ * @param[in] callback The callback function to register.
+ * @param[in] user_data The user data to be passed  to the callback function.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
+ *
+ * @see bt_gatt_server_connection_state_changed_cb()
+ * @see bt_gatt_server_unset_connection_state_changed_cb()
+ */
+int bt_gatt_server_set_connection_state_changed_cb(bt_gatt_server_h server,
+                bt_gatt_server_connection_state_changed_cb callback, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Unregisters a callback function that will be invoked when the connection state is changed.
+ * @since_tizen 7.0
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
+ *
+ * @see bt_gatt_server_connection_state_changed_cb()
+ * @see bt_gatt_server_set_connection_state_changed_cb()
+ */
+
+int bt_gatt_server_unset_connection_state_changed_cb(bt_gatt_server_h server);
+
+/**
  * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE
  * @brief  Registers a callback function that will be invoked when the A2DP Source connection state is changed.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
index d1b07cc..156c59c 100644 (file)
@@ -357,6 +357,8 @@ typedef struct bt_event_sig_event_slot_s {
 typedef struct {
        GSList *services;
        bt_gatt_server_att_mtu_changed_cb att_mtu_changed_cb;
+       bt_gatt_server_connection_state_changed_cb server_connection_change_cb;
+       void *connection_change_user_data;
        void *att_mtu_changed_user_data;
 } bt_gatt_server_s;
 
@@ -368,6 +370,9 @@ typedef struct {
 
        bt_gatt_client_att_mtu_changed_cb att_mtu_changed_cb;
        bt_gatt_client_service_changed_cb service_changed_cb;
+       bt_gatt_client_connection_state_changed_cb client_connection_change_cb;
+       void *connection_change_user_data;
+
        void *service_changed_user_data;
        void *att_mtu_changed_user_data;
 #ifdef TIZEN_GATT_CLIENT
index d55a748..37224fb 100644 (file)
@@ -705,6 +705,44 @@ typedef void (*bt_gatt_server_att_mtu_changed_cb)(bt_gatt_server_h server,
                void *user_data);
 
 /**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Called when the connection state is changed.
+ *
+ * @details This callback is called when the connection state is changed.
+ * When you called bt_gatt_client_connect() or bt_gatt_client_disconnect(), this callback is also called with error result even though these functions fail.
+ *
+ * @since_tizen 7.0
+ * @param[in] result The result of changing the connection state.
+ * @param[in] connected The state to be changed, true means connected state, Otherwise, false.
+ * @param[in] remote_address The remote_address
+ * @param[in] user_data The user data passed from the callback registration function.
+ *
+ * @see bt_gatt_client_connect()
+ * @see bt_gatt_client_disconnect()
+ */
+typedef void (*bt_gatt_client_connection_state_changed_cb)(int result, bool connected, const char *remote_address, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Called when the connection state is changed.
+ *
+ * @details This callback is called when the connection state is changed.
+ * When you called bt_gatt_client_connect() or bt_gatt_client_disconnect(), this callback is also called with error result even though these functions fail.
+ *
+ * @since_tizen 7.0
+ * @param[in] result The result of changing the connection state.
+ * @param[in] connected The state to be changed, true means connected state, Otherwise, false.
+ * @param[in] remote_address The remote_address
+ * @param[in] user_data The user data passed from the callback registration function.
+ *
+ * @see bt_gatt_client_connect()
+ * @see bt_gatt_client_disconnect()
+ * @see bt_gatt_server_set_connection_state_changed_cb()
+ * @see bt_gatt_server_unset_connection_state_changed_cb()
+ */
+typedef void(*bt_gatt_server_connection_state_changed_cb)(int result, bool connected, const char *remote_address, void *user_data);
+
+/**
  * @ingroup CAPI_NETWORK_BLUETOOTH_PROXIMITY_MODULE
  * @brief The handle of a Proximity Monitor client handle which is associated with a remote device.
  * @since_tizen 4.0
index a420351..60af564 100644 (file)
@@ -2543,31 +2543,63 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
 #ifdef TIZEN_GATT_CLIENT
        /* Local is GATT server */
        case BLUETOOTH_EVENT_GATT_SERVER_CONNECTED: {
+               const GSList *server_list = NULL;
+               bt_gatt_server_s *server = NULL;
+
                bt_gatt_connection_state_changed_cb cb = NULL;
+
+               server_list = _bt_gatt_get_server_list();
+               if (!server_list)
+                       break;
+
+               server = (bt_gatt_server_s *)server_list->data;
+
                BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_CONNECTED");
                _bt_convert_address_to_string(&device_addr,
                                (bluetooth_device_address_t *)(param->param_data));
 
-               if (event_index >= 0)
-                       cb = bt_event_slot_container[event_index].callback;
-               if (cb)
-                       cb(_bt_get_error_code(param->result), TRUE, device_addr,
-                               bt_event_slot_container[event_index].user_data);
+               if (server && server->server_connection_change_cb)
+                       server->server_connection_change_cb(_bt_get_error_code(param->result), TRUE, device_addr,
+                                       server->connection_change_user_data);
+
+               else {
+                       if (event_index >= 0)
+                               cb = bt_event_slot_container[event_index].callback;
+                       if (cb)
+                               cb(_bt_get_error_code(param->result), TRUE, device_addr,
+                                       bt_event_slot_container[event_index].user_data);
+               }
 
                g_free(device_addr);
                device_addr = NULL;
                break;
        }
        case BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED: {
+               const GSList *server_list = NULL;
+               bt_gatt_server_s *server = NULL;
+
                bt_gatt_connection_state_changed_cb cb = NULL;
+
+               server_list = _bt_gatt_get_server_list();
+               if (!server_list)
+                       break;
+
+               server = (bt_gatt_server_s *)server_list->data;
+
                BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED");
                _bt_convert_address_to_string(&device_addr,
                                (bluetooth_device_address_t *)(param->param_data));
-               if (event_index >= 0)
-                       cb = bt_event_slot_container[event_index].callback;
-               if (cb)
-                       cb(_bt_get_error_code(param->result), FALSE, device_addr,
-                               bt_event_slot_container[event_index].user_data);
+
+               if (server && server->server_connection_change_cb)
+                       server->server_connection_change_cb(_bt_get_error_code(param->result), FALSE, device_addr,
+                                       server->connection_change_user_data);
+               else {
+                       if (event_index >= 0)
+                               cb = bt_event_slot_container[event_index].callback;
+                       if (cb)
+                               cb(_bt_get_error_code(param->result), FALSE, device_addr,
+                                       bt_event_slot_container[event_index].user_data);
+               }
 
                g_free(device_addr);
                device_addr = NULL;
@@ -2600,11 +2632,16 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                /* TDS Seeker */
                _bt_tds_update_seeker_connection_state_changed(param->result, device_addr, TRUE);
 
-               if (event_index >= 0)
-                       cb = bt_event_slot_container[event_index].callback;
-               if (cb)
-                       cb(_bt_get_error_code(param->result), TRUE, device_addr,
-                               bt_event_slot_container[event_index].user_data);
+               if (client_s && client_s->client_connection_change_cb)
+                       client_s->client_connection_change_cb(_bt_get_error_code(param->result), TRUE, device_addr,
+                                       client_s->connection_change_user_data);
+               else {
+                       if (event_index >= 0)
+                               cb = bt_event_slot_container[event_index].callback;
+                       if (cb)
+                               cb(_bt_get_error_code(param->result), TRUE, device_addr,
+                                       bt_event_slot_container[event_index].user_data);
+               }
                g_free(device_addr);
                device_addr = NULL;
                break;
@@ -2633,11 +2670,17 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                /* TDS Seeker */
                _bt_tds_update_seeker_connection_state_changed(param->result, device_addr, FALSE);
 
-               if (event_index >= 0)
-                       cb = bt_event_slot_container[event_index].callback;
-               if (cb)
-                       cb(_bt_get_error_code(param->result), FALSE, device_addr,
-                               bt_event_slot_container[event_index].user_data);
+               if (client_s && client_s->client_connection_change_cb)
+                       client_s->client_connection_change_cb(_bt_get_error_code(param->result), FALSE, device_addr,
+                                       client_s->connection_change_user_data);
+               else {
+                       if (event_index >= 0)
+                               cb = bt_event_slot_container[event_index].callback;
+                       if (cb)
+                               cb(_bt_get_error_code(param->result), FALSE, device_addr,
+                                       bt_event_slot_container[event_index].user_data);
+               }
+
                g_free(device_addr);
                device_addr = NULL;
                break;
index 3c190a0..5643b29 100644 (file)
@@ -818,6 +818,49 @@ next:
 #endif
 
 #ifdef TIZEN_GATT_CLIENT
+
+int bt_gatt_client_connect(bt_gatt_client_h client,
+               bt_gatt_client_connection_state_changed_cb callback, bool auto_connect, void *user_data)
+{
+       int ret;
+       bluetooth_device_address_t bd_addr = { {0,} };
+
+       bt_gatt_client_s *client_h = (bt_gatt_client_s *)client;
+
+       bt_gatt_client_s *client_s;
+
+       BT_INFO("Address [%s] Auto Connect [%d]",
+                       client_h->remote_address, auto_connect);
+
+       BT_CHECK_GATT_CLIENT_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(client_h->remote_address);
+       _bt_convert_address_to_hex(&bd_addr, client_h->remote_address);
+
+       client_h->client_connection_change_cb = callback;
+       client_h->connection_change_user_data = user_data;
+
+       /* Find any client attached with remote address or not */
+       client_s = _bt_gatt_get_client(client_h->remote_address);
+       if (client_s) {
+               BT_INFO("GATT client instance is already present for the rmeote addr [%s] client_id[%d]",
+                       client_h->remote_address, client_s->client_id);
+               ret = _bt_get_error_code(bluetooth_connect_le(&bd_addr,
+                       auto_connect, client_s->client_id));
+       } else {
+               BT_INFO("GATT client instance is NOT present for the remote addr [%s]",
+                       client_h->remote_address);
+
+               ret = _bt_get_error_code(bluetooth_connect_le(&bd_addr,
+                                       auto_connect, 0/* Default Client ID */));
+       }
+
+       if (ret != BT_ERROR_NONE)
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+
+       return ret;
+}
+
 int bt_gatt_connect(const char *address, bool auto_connect)
 {
        int ret;
@@ -874,6 +917,42 @@ int bt_gatt_connect(const char *address, bool auto_connect)
        return ret;
 }
 #endif
+int bt_gatt_client_disconnect(bt_gatt_client_h client)
+{
+       int ret;
+       bluetooth_device_address_t bd_addr = { {0,} };
+#ifdef TIZEN_GATT_CLIENT
+       bt_gatt_client_s *client_h = (bt_gatt_client_s *)client;
+       bt_gatt_client_s *client_s;
+#endif
+
+       BT_CHECK_GATT_CLIENT_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(client_h->remote_address);
+       _bt_convert_address_to_hex(&bd_addr, client_h->remote_address);
+
+#ifdef TIZEN_GATT_CLIENT
+
+       /* Find any client attached with remote address or not */
+       client_s = _bt_gatt_get_client(client_h->remote_address);
+       if (client_s) {
+               BT_INFO("GATT client instance is already present for the remote addr [%s] client interface [%d]",
+                       client_h->remote_address, client_s->client_id);
+               ret = _bt_get_error_code(bluetooth_disconnect_le(&bd_addr, client_s->client_id));
+       } else {
+               BT_INFO("GATT client instance is NOT present for the remote addr [%s]",
+                       client_h->remote_address);
+               ret = _bt_get_error_code(bluetooth_disconnect_le(&bd_addr, 0 /* Default CLient ID */));
+       }
+#else
+       ret = _bt_get_error_code(bluetooth_disconnect_le(&bd_addr));
+#endif
+
+       if (ret != BT_ERROR_NONE)
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+
+       return ret;
+}
 
 int bt_gatt_disconnect(const char *address)
 {
@@ -907,9 +986,39 @@ int bt_gatt_disconnect(const char *address)
        if (ret != BT_ERROR_NONE)
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
 
+       _bt_unset_cb(BT_EVENT_GATT_CONNECTION_STATUS);
        return ret;
 }
 /* LCOV_EXCL_STOP */
+int bt_gatt_server_set_connection_state_changed_cb(bt_gatt_server_h server,
+               bt_gatt_server_connection_state_changed_cb callback, void *user_data)
+{
+       bt_gatt_server_s *server_s = (bt_gatt_server_s *)server;
+
+       BT_CHECK_GATT_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(callback);
+       BT_INFO("Connection Change callback registered");
+
+       server_s->server_connection_change_cb = callback;
+       server_s->connection_change_user_data = user_data;
+
+       return BT_ERROR_NONE;
+}
+
+int bt_gatt_server_unset_connection_state_changed_cb(bt_gatt_server_h server)
+{
+       bt_gatt_server_s *server_s = (bt_gatt_server_s *)server;
+
+       BT_CHECK_GATT_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       BT_INFO("Connection Changed callback unregistered");
+
+       server_s->server_connection_change_cb = NULL;
+       server_s->connection_change_user_data = NULL;
+
+       return BT_ERROR_NONE;
+}
 
 int bt_gatt_set_connection_state_changed_cb(bt_gatt_connection_state_changed_cb callback,
                                                        void *user_data)
index 0e9a21f..d800fc4 100644 (file)
@@ -658,14 +658,14 @@ tc_table_t tc_gatt[] = {
        /* Gatt functions */
        {"BACK"
                , BT_UNIT_TEST_FUNCTION_BACK},
-       {"bt_gatt_connect"
-               , BT_UNIT_TEST_FUNCTION_GATT_CONNECT},
-       {"bt_gatt_disconnect"
-               , BT_UNIT_TEST_FUNCTION_GATT_DISCONNECT},
-       {"bt_gatt_set_connection_state_changed_cb"
-               , BT_UNIT_TEST_FUNCTION_SET_GATT_CONNECTION_STATE_CHANGED_CB},
-       {"bt_gatt_unset_connection_state_changed_cb"
-               , BT_UNIT_TEST_FUNCTION_UNSET_GATT_CONNECTION_STATE_CHANGED_CB},
+       {"bt_gatt_client_connect"
+               , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CONNECT},
+       {"bt_gatt_client_disconnect"
+               , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_DISCONNECT},
+       {"bt_gatt_server_set_connection_state_changed_cb"
+               , BT_UNIT_TEST_FUNCTION_SET_GATT_SERVER_CONNECTION_STATE_CHANGED_CB},
+       {"bt_gatt_server_unset_connection_state_changed_cb"
+               , BT_UNIT_TEST_FUNCTION_UNSET_GATT_SERVER_CONNECTION_STATE_CHANGED_CB},
        {"bt_gatt_client_create"
                , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CREATE},
        {"bt_gatt_client_destroy"
@@ -2426,6 +2426,50 @@ void __bt_gatt_connection_state_changed_cb(int result,
        }
 }
 
+void __bt_gatt_server_connection_state_changed_cb(int result,
+       bool connected, const char *remote_address, void *user_data)
+{
+       if (result != BT_ERROR_NONE)
+               TC_PRT("result: %s", __bt_get_error_message(result));
+
+       if (connected) {
+               TC_PRT("GATT server connected [%s]", remote_address);
+               strncpy(remote_addr, remote_address, strlen(remote_addr));
+
+               bt_le_conn_update_s param;
+
+               param.interval_min = 90;
+               param.interval_max = 90;
+               param.latency = 0;
+               param.time_out = 2000;
+               bt_device_le_conn_update(remote_addr, &param);
+       } else {
+               TC_PRT("GATT server DISconnected [%s]", remote_address);
+       }
+}
+
+void __bt_gatt_client_connection_state_changed_cb(int result,
+       bool connected, const char *remote_address, void *user_data)
+{
+       if (result != BT_ERROR_NONE)
+               TC_PRT("result: %s", __bt_get_error_message(result));
+
+       if (connected) {
+               TC_PRT("GATT client connected [%s]", remote_address);
+               strncpy(remote_addr, remote_address, strlen(remote_addr));
+
+               bt_le_conn_update_s param;
+
+               param.interval_min = 90;
+               param.interval_max = 90;
+               param.latency = 0;
+               param.time_out = 2000;
+               bt_device_le_conn_update(remote_addr, &param);
+       } else {
+               TC_PRT("GATT client DISconnected [%s]", remote_address);
+       }
+}
+
 void __bt_hps_connection_state_changed_cb(int result,
        bool connected, const char *remote_address, void *user_data)
 {
@@ -3922,7 +3966,7 @@ int test_set_params(int test_id, char *param)
 
        case BT_UNIT_TEST_TABLE_GATT: {
                switch (test_id) {
-               case BT_UNIT_TEST_FUNCTION_GATT_CONNECT:
+               case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CONNECT:
                        param_count = 1;
                        param_type = BT_UNIT_TEST_PARAM_TYPE_BOOL;
                        TC_PRT("Input param(%d) type:%s", param_index + 1, param_type);
@@ -6790,7 +6834,7 @@ int test_input_callback(void *data)
        }
        case BT_UNIT_TEST_TABLE_GATT: {
                switch (test_id) {
-               case BT_UNIT_TEST_FUNCTION_GATT_CONNECT: {
+               case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CONNECT: {
                        bool auto_connect = false;
 
                        if (g_test_param.param_count > 0) {
@@ -6802,23 +6846,24 @@ int test_input_callback(void *data)
                                __bt_free_test_param(&g_test_param);
                        }
 
-                       ret = bt_gatt_connect(remote_addr, auto_connect);
+                       ret = bt_gatt_client_connect(client,
+                                       __bt_gatt_client_connection_state_changed_cb, auto_connect, NULL);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
-               case BT_UNIT_TEST_FUNCTION_GATT_DISCONNECT: {
-                       ret = bt_gatt_disconnect(remote_addr);
+               case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_DISCONNECT: {
+                       ret = bt_gatt_client_disconnect(client);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
-               case BT_UNIT_TEST_FUNCTION_SET_GATT_CONNECTION_STATE_CHANGED_CB: {
-                       ret = bt_gatt_set_connection_state_changed_cb(
-                               __bt_gatt_connection_state_changed_cb, NULL);
+               case BT_UNIT_TEST_FUNCTION_SET_GATT_SERVER_CONNECTION_STATE_CHANGED_CB: {
+                       ret = bt_gatt_server_set_connection_state_changed_cb(server,
+                               __bt_gatt_server_connection_state_changed_cb, NULL);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
-               case BT_UNIT_TEST_FUNCTION_UNSET_GATT_CONNECTION_STATE_CHANGED_CB: {
-                       ret = bt_gatt_unset_connection_state_changed_cb();
+               case BT_UNIT_TEST_FUNCTION_UNSET_GATT_SERVER_CONNECTION_STATE_CHANGED_CB: {
+                       ret = bt_gatt_server_unset_connection_state_changed_cb(server);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
@@ -8013,11 +8058,8 @@ int test_input_callback(void *data)
                                __bt_free_test_param(&g_test_param);
                        }
 
-                       ret = bt_gatt_connect(remote_addr, auto_connect);
-                       TC_PRT("returns %s\n", __bt_get_error_message(ret));
-                       ret = bt_gatt_set_connection_state_changed_cb(
-                                       __bt_hps_connection_state_changed_cb,
-                                       NULL);
+                       ret = bt_gatt_client_connect(hps_client,
+                               __bt_gatt_client_connection_state_changed_cb, auto_connect, NULL);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
@@ -8028,7 +8070,7 @@ int test_input_callback(void *data)
                        ret = bt_gatt_client_destroy(hps_client);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        hps_client = NULL;
-                       ret = bt_gatt_disconnect(remote_addr);
+                       ret = bt_gatt_disconnect(hps_client);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
index e490bca..34f936a 100644 (file)
@@ -274,10 +274,10 @@ typedef enum {
        BT_UNIT_TEST_FUNCTION_NAP_DISCONNECT,
        BT_UNIT_TEST_FUNCTION_PANU_SET_CONNECTION_STATE_CHANGED_CB,
        BT_UNIT_TEST_FUNCTION_PANU_CONNECT,
-       BT_UNIT_TEST_FUNCTION_GATT_CONNECT = 1,
-       BT_UNIT_TEST_FUNCTION_GATT_DISCONNECT,
-       BT_UNIT_TEST_FUNCTION_SET_GATT_CONNECTION_STATE_CHANGED_CB,
-       BT_UNIT_TEST_FUNCTION_UNSET_GATT_CONNECTION_STATE_CHANGED_CB,
+       BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CONNECT = 1,
+       BT_UNIT_TEST_FUNCTION_GATT_CLIENT_DISCONNECT,
+       BT_UNIT_TEST_FUNCTION_SET_GATT_SERVER_CONNECTION_STATE_CHANGED_CB,
+       BT_UNIT_TEST_FUNCTION_UNSET_GATT_SERVER_CONNECTION_STATE_CHANGED_CB,
        BT_UNIT_TEST_FUNCTION_GATT_SET_WRITE_TYPE,
        BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CREATE,
        BT_UNIT_TEST_FUNCTION_GATT_CLIENT_DESTROY,