int bt_gatt_client_write_value(bt_gatt_h gatt_handle,
bt_gatt_client_request_completed_cb callback, void *user_data);
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Requests a change of the ATT MTU value.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/bluetooth
+ *
+ * @param[in] client The created GATT client's handle
+ * @param[in] mtu The new MTU value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED Not enabled
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #BT_ERROR_NOT_SUPPORTED Not supported
+ * @see bt_gatt_client_set_att_mtu_changed_cb()
+ */
+int bt_gatt_client_request_att_mtu_change(bt_gatt_client_h client, unsigned int mtu);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Gets the ATT MTU value set for a connection.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/bluetooth
+ *
+ * @param[in] client The created GATT client's handle
+ * @param[ot] mtu The MTU value set for a connection
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED Not enabled
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #BT_ERROR_NOT_SUPPORTED Not supported
+ */
+int bt_gatt_client_get_att_mtu(bt_gatt_client_h client, unsigned int *mtu);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Registers a callback function to be invoked when the ATT MTU is changed.
+ * @since_tizen 4.0
+ * @param[in] client The created GATT client's handle
+ * @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
+ *
+ * @pre The Bluetooth service must be initialized with bt_initialize().
+ * @post bt_device_connection_state_changed_cb() will be invoked.
+ * @see bt_initialize()
+ * @see bt_gatt_client_request_att_mtu_change()
+ * @see bt_gatt_client_unset_att_mtu_changed_cb()
+ */
+int bt_gatt_client_set_att_mtu_changed_cb(bt_gatt_client_h client, bt_gatt_client_att_mtu_changed_cb callback, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Unregisters the callback function to be invoked when the ATT MTU is changed.
+ * @since_tizen 4.0
+ * @param[in] client The created GATT client's handle
+ * @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
+ *
+ * @pre The Bluetooth service must be initialized with bt_initialize().
+ * @see bt_initialize()
+ * @see bt_gatt_client_request_att_mtu_change()
+ * @see bt_gatt_client_set_att_mtu_changed_cb()
+ */
+int bt_gatt_client_unset_att_mtu_changed_cb(bt_gatt_client_h client);
+
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Registers a callback function to be invoked when the characteristic value is changed on the remote device.
int bt_device_unset_trusted_profile_cb(void);
/**
+ * @deprecated Deprecated since 4.0. Use bt_gatt_client_request_att_mtu_change instead.
* @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
* @brief Request to change ATT MTU value
* @since_tizen 3.0
* @retval #BT_ERROR_PERMISSION_DENIED Permission denied
* @retval #BT_ERROR_NOT_SUPPORTED Not supported
*/
-int bt_device_request_att_mtu(const char *remote_address, unsigned int mtu);
+int bt_device_request_att_mtu(const char *remote_address, unsigned int mtu) TIZEN_DEPRECATED_API;
/**
+ * @deprecated Deprecated since 4.0. Use bt_gatt_client_get_att_mtu instead.
* @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
* @brief Gets the ATT MTU value set for a connection
* @since_tizen 3.0
* @retval #BT_ERROR_PERMISSION_DENIED Permission denied
* @retval #BT_ERROR_NOT_SUPPORTED Not supported
*/
-int bt_device_get_att_mtu(const char *remote_address, unsigned int *mtu);
+int bt_device_get_att_mtu(const char *remote_address, unsigned int *mtu) TIZEN_DEPRECATED_API;
/**
+ * @deprecated Deprecated since 4.0. Use bt_gatt_client_set_att_mtu_changed_cb instead.
* @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
* @brief Registers a callback function to be invoked when the ATT MTU is changed.
* @since_tizen 3.0
* @see bt_initialize()
* @see bt_device_unset_att_mtu_changed_cb()
*/
-int bt_device_set_att_mtu_changed_cb(bt_device_att_mtu_changed_cb callback, void *user_data);
+int bt_device_set_att_mtu_changed_cb(bt_device_att_mtu_changed_cb callback, void *user_data) TIZEN_DEPRECATED_API;
/**
+ * @deprecated Deprecated since 4.0. Use bt_gatt_client_unset_att_mtu_changed_cb instead.
* @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
* @brief Unregisters the callback function to be invoked when the ATT MTU is changed.
* @since_tizen 3.0
* @see bt_initialize()
* @see bt_device_set_att_mtu_changed_cb()
*/
-int bt_device_unset_att_mtu_changed_cb(void);
+int bt_device_unset_att_mtu_changed_cb(void) TIZEN_DEPRECATED_API;
/**
* @internal
bool services_discovered;
bool connected;
+ bt_gatt_client_att_mtu_changed_cb att_mtu_changed_cb;
bt_gatt_client_service_changed_cb service_changed_cb;
void *service_changed_user_data;
+ void *att_mtu_changed_user_data;
} bt_gatt_client_s;
typedef struct {
typedef bool (*bt_gatt_foreach_cb) (int total, int index, bt_gatt_h gatt_handle,
void *user_data);
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Attribute protocol MTU change information structure.
+ * @since_tizen 4.0
+ *
+ * @see bt_gatt_client_att_mtu_changed_cb()
+ */
+typedef struct {
+ char *remote_address; /**< The address of remote device */
+ unsigned int mtu; /**< MTU value */
+ unsigned int status; /**< Request status*/
+} bt_gatt_client_att_mtu_info_s;
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
+ * @brief Called when the ATT MTU value is changed.
+ * @since_tizen 4.0
+ *
+ * @remarks The @a mtu_info must not be freed by application.
+ * @a mtu_info can be used only inside the callback.
+ * If it's needed outside, make a copy.
+ *
+ * @param[in] client The handle of a GATT client which is associated with a remote device
+ * @param[in] mtu_info The MTU information
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see bt_gatt_client_set_connection_state_changed_cb()
+ * @see bt_gatt_client_unset_connection_state_changed_cb()
+ */
+typedef void (*bt_gatt_client_att_mtu_changed_cb)(bt_gatt_client_h client,
+ const bt_gatt_client_att_mtu_info_s *mtu_info,
+ void *user_data);
+
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Called when the client request(e.g. read / write) has been completed
(int result, char *remote_address, int trusted_profile, bool supported, bool trusted, void *user_data);
/**
+ * @deprecated Deprecated since 4.0. Use bt_gatt_client_att_mtu_info_s instead.
* @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
* @brief Attribute protocol MTU change information structure.
* @since_tizen 3.0
} bt_device_att_mtu_info_s;
/**
+ * @deprecated Deprecated since 4.0. Use bt_gatt_client_att_mtu_changed_cb instead.
* @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
* @brief Called when the connection state is changed.
* @since_tizen 3.0
sdp_info = NULL;
}
-static int __bt_get_bt_device_att_mtu_info_s(bt_device_att_mtu_info_s **dest, bluetooth_le_att_mtu_info_t *source)
+static int __bt_get_bt_gatt_client_att_mtu_info_s(bt_gatt_client_att_mtu_info_s **dest, bluetooth_le_att_mtu_info_t *source)
{
- *dest = (bt_device_att_mtu_info_s *)g_malloc0(sizeof(bt_device_att_mtu_info_s));
+ *dest = (bt_gatt_client_att_mtu_info_s *)g_malloc0(sizeof(bt_gatt_client_att_mtu_info_s));
if (*dest == NULL)
return BT_ERROR_OUT_OF_MEMORY;
case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED:
case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED:
case BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED:
+ case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED:
case BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED:
case BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT:
case BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED:
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED: {
- bt_device_att_mtu_info_s *mtu_info = NULL;
+ bt_gatt_client_att_mtu_info_s *mtu_info = NULL;
+ bt_gatt_client_s *client = NULL;
BT_INFO("BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED");
- __bt_get_bt_device_att_mtu_info_s(&mtu_info, (bluetooth_le_att_mtu_info_t *)(param->param_data));
- ((bt_device_att_mtu_changed_cb)bt_event_slot_container[event_index].callback)
- (_bt_get_error_code(param->result), mtu_info, bt_event_slot_container[event_index].user_data);
+ __bt_get_bt_gatt_client_att_mtu_info_s(&mtu_info, (bluetooth_le_att_mtu_info_t *)(param->param_data));
+
+ client = _bt_gatt_get_client(mtu_info->remote_address);
+
+ if (client && client->connected && client->att_mtu_changed_cb)
+ client->att_mtu_changed_cb(client,
+ (const bt_gatt_client_att_mtu_info_s *)mtu_info,
+ client->att_mtu_changed_user_data);
+
+ if (bt_event_slot_container[event_index].callback)
+ ((bt_device_att_mtu_changed_cb)bt_event_slot_container[event_index].callback)
+ (_bt_get_error_code(param->result), (bt_device_att_mtu_info_s *)mtu_info,
+ bt_event_slot_container[event_index].user_data);
+
break;
}
case BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED:
{
BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
BT_CHECK_INIT_STATUS();
- _bt_unset_cb(BT_EVENT_DEVICE_CONNECTION_STATUS);
+ _bt_unset_cb(BT_EVENT_GATT_ATT_MTU_CHANGE_STATUS);
return BT_ERROR_NONE;
}
return BT_ERROR_NONE;
}
+
+int bt_gatt_client_request_att_mtu_change(bt_gatt_client_h client, unsigned int mtu)
+{
+ int ret;
+ bluetooth_device_address_t addr_hex = { {0,} };
+ bt_gatt_client_s *client_s = (bt_gatt_client_s *)client;
+
+ BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(client);
+
+ _bt_convert_address_to_hex(&addr_hex, client_s->remote_address);
+
+ ret = _bt_get_error_code(bluetooth_request_att_mtu(&addr_hex, mtu));
+ if (BT_ERROR_NONE != ret)
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+
+ return ret;
+}
+
+int bt_gatt_client_get_att_mtu(bt_gatt_client_h client, unsigned int *mtu)
+{
+ bluetooth_device_address_t addr_hex = { {0,} };
+ int ret;
+ unsigned int mtu_value = 0;
+ bt_gatt_client_s *client_s = (bt_gatt_client_s *)client;
+
+ BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(client);
+
+ _bt_convert_address_to_hex(&addr_hex, client_s->remote_address);
+
+ ret = _bt_get_error_code(bluetooth_get_att_mtu(&addr_hex, &mtu_value));
+
+ if (ret != BT_ERROR_NONE) {
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+ return ret;
+ }
+
+ *mtu = mtu_value;
+
+ return ret;
+
+}
+
+int bt_gatt_client_set_att_mtu_changed_cb(bt_gatt_client_h client, bt_gatt_client_att_mtu_changed_cb callback, void *user_data)
+{
+ bt_gatt_client_s *client_s = (bt_gatt_client_s *)client;
+
+ BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(callback);
+ BT_CHECK_INPUT_PARAMETER(client);
+
+ if (client_s->att_mtu_changed_cb) {
+ BT_INFO("Already registered");
+ client_s->att_mtu_changed_cb = callback;
+ client_s->att_mtu_changed_user_data = user_data;
+ return BT_ERROR_NONE;
+ }
+
+ BT_INFO("MTU Changed callback registered");
+ client_s->att_mtu_changed_cb = callback;
+ client_s->att_mtu_changed_user_data = user_data;
+
+ return BT_ERROR_NONE;
+}
+
+int bt_gatt_client_unset_att_mtu_changed_cb(bt_gatt_client_h client)
+{
+ bt_gatt_client_s *client_s = (bt_gatt_client_s *)client;
+
+ BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(client);
+
+ BT_INFO("MTU Changed callback unregistered [%s]", client_s->remote_address);
+ client_s->service_changed_cb = NULL;
+ client_s->service_changed_user_data = NULL;
+
+ return BT_ERROR_NONE;
+}
, BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_CHAR_VALUE_CHANGED_CB},
{"bt_gatt_client_foreach_services"
, BT_UNIT_TEST_FUNCTION_GATT_CLIENT_FOREACH_SERVICES},
+ {"bt_gatt_client_request_att_mtu_change"
+ , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_REQUEST_ATT_MTU},
+ {"bt_gatt_client_get_att_mtu"
+ , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_GET_ATT_MTU},
{"bt_gatt_client_set_service_changed_cb"
, BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_SERVICE_CHANGED_CB},
{"bt_gatt_client_unset_service_changed_cb"
, BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_SERVICE_CHANGED_CB},
+ {"bt_gatt_client_set_att_mtu_changed_cb"
+ , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_ATT_MTU_CHANGED_CB},
+ {"bt_gatt_client_unset_att_mtu_changed_cb"
+ , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_ATT_MTU_CHANGED_CB},
{"bt_gatt_server_initialize"
, BT_UNIT_TEST_FUNCTION_GATT_SERVER_INITIALIZE},
{"bt_gatt_server_deinitilaize"
g_free(addr);
}
+void __bt_gatt_client_att_mtu_changed_cb(bt_gatt_client_h c, const bt_gatt_client_att_mtu_info_s *mtu_info, void *user_data)
+{
+ char *addr = NULL;
+ int ret;
+
+ TC_PRT("__bt_gatt_client_att_mtu_changed_cb");
+
+ ret = bt_gatt_client_get_remote_address(client, &addr);
+ if (ret != BT_ERROR_NONE) {
+ TC_PRT("Cannot get remote address");
+ return;
+ }
+
+ if (mtu_info) {
+ TC_PRT("status [%d]", mtu_info->status);
+ TC_PRT("address [%s]", mtu_info->remote_address);
+ TC_PRT("MTU [%d]", mtu_info->mtu);
+ }
+
+ g_free(addr);
+}
+
int __bt_gatt_client_set_value(char *type, char *value, bt_gatt_h h)
{
int ret;
break;
}
+ case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_REQUEST_ATT_MTU: {
+ if (param_index == 0) {
+ g_test_param.param_count = 1;
+ g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count);
+ param_type = "int(1, 2, 10, ...., 512)";
+ }
+
+ if (param_index > 0) {
+ g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1);
+ strncpy(g_test_param.params[param_index - 1], param, strlen(param));
+ }
+
+ if (param_index == g_test_param.param_count) {
+ need_to_set_params = false;
+#ifdef ARCH64
+ test_input_callback((void *)(uintptr_t)test_id);
+#else
+ test_input_callback((void *)test_id);
+#endif
+ param_index = 0;
+ return 0;
+ }
+
+ TC_PRT("Input param(%d) : %s", param_index + 1, param_type);
+ param_index++;
+
+ break;
+ }
case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_CHAR_VALUE_CHANGED_CB: {
if (param_index == 0) {
g_test_param.param_count = 2;
TC_PRT("bt_gatt_client_foreach_services_by_uuid is failed");
break;
}
+ case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_REQUEST_ATT_MTU: {
+ unsigned int mtu = 512; /* MAX MTU Value */
+
+ if (g_test_param.param_count > 0) {
+ mtu = atoi(g_test_param.params[0]);
+
+ __bt_free_test_param(&g_test_param);
+ }
+
+ ret = bt_gatt_client_request_att_mtu_change(client, mtu);
+ TC_PRT("returns %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_GET_ATT_MTU: {
+ unsigned int mtu = 0;
+ ret = bt_gatt_client_get_att_mtu(client, &mtu);
+ TC_PRT("returns %s, MTU %d\n", __bt_get_error_message(ret), mtu);
+ break;
+ }
case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_SERVICE_CHANGED_CB: {
ret = bt_gatt_client_set_service_changed_cb(client,
__bt_gatt_client_service_changed_cb, NULL);
TC_PRT("bt_gatt_client_unset_service_changed_cb is failed");
break;
}
+ case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_ATT_MTU_CHANGED_CB: {
+ ret = bt_gatt_client_set_att_mtu_changed_cb(client, __bt_gatt_client_att_mtu_changed_cb, NULL);
+ TC_PRT("returns %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_ATT_MTU_CHANGED_CB: {
+ ret = bt_gatt_client_unset_att_mtu_changed_cb(client);
+ TC_PRT("returns %s\n", __bt_get_error_message(ret));
+ break;
+ }
case BT_UNIT_TEST_FUNCTION_GATT_SERVER_INITIALIZE: {
ret = bt_gatt_server_initialize();
BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_CHAR_VALUE_CHANGED_CB,
BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_CHAR_VALUE_CHANGED_CB,
BT_UNIT_TEST_FUNCTION_GATT_CLIENT_FOREACH_SERVICES,
+ BT_UNIT_TEST_FUNCTION_GATT_CLIENT_REQUEST_ATT_MTU,
+ BT_UNIT_TEST_FUNCTION_GATT_CLIENT_GET_ATT_MTU,
BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_SERVICE_CHANGED_CB,
BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_SERVICE_CHANGED_CB,
+ BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_ATT_MTU_CHANGED_CB,
+ BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_ATT_MTU_CHANGED_CB,
BT_UNIT_TEST_FUNCTION_GATT_SERVER_INITIALIZE,
BT_UNIT_TEST_FUNCTION_GATT_SERVER_DEINITIALIZE,
BT_UNIT_TEST_FUNCTION_GATT_SERVER_UNREGISTER_ALL_SERVICES,