int bt_gatt_characteristic_set_properties(bt_gatt_h characteristic, int properties);
/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_SERVER_MODULE
+ * @brief Registers a callback function to be invoked when the remote device enables or disables the Notification/Indication for particular characteristics.
+ * @since_tizen 6.5
+ *
+ * @param[in] gatt_handle The GATT handle of a characteristic
+ * @param[in] callback The callback to be invoked
+ * @param[in] user_data The user data to be passed to @a callback function
+ * @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_SUPPORTED Not supported
+ *
+ * @see bt_gatt_server_characteristic_notif_state_changed_cb()
+ */
+int bt_gatt_server_set_characteristic_notif_state_change_cb(bt_gatt_h gatt_handle,
+ bt_gatt_server_characteristic_notif_state_changed_cb callback,
+ void *user_data);
+
+/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Destroys the GATT handle
* @since_tizen 2.4
void *notified_user_data;
bt_gatt_server_characteristic_notification_state_changed_cb notification_changed_cb;
+ bt_gatt_server_characteristic_notif_state_changed_cb notif_changed_cb;
void *notification_changed_user_data;
+ void *notif_changed_user_data;
int value_length;
char *value;
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_SERVER_MODULE
+ * @brief Called when the remote device enables or disables the Notification/Indication for particular characteristics.
+ *
+ * @details By using this callback function, server can know notification state.
+ *
+ * @since_tizen 6.5
+ * @remarks The @a server must not be freed by application.
+ * @remarks The @a gatt_handle must not be freed by application.
+ *
+ * @param[in] remote_address The client device address
+ * @param[in] notify Indicates whether the Notification/Indication is enabled or not
+ * @param[in] server The GATT server handle
+ * @param[in] gatt_handle The characteristic's GATT handle to be read
+ * @param[in] user_data The user data passed from the registration function
+ *
+ * @see bt_gatt_server_set_read_value_requested_cb()
+ */
+typedef void (*bt_gatt_server_characteristic_notif_state_changed_cb) (const char *remote_address, bool notify,
+ bt_gatt_server_h server, bt_gatt_h gatt_handle, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_SERVER_MODULE
* @brief Attribute protocol MTU change information structure.
* @since_tizen 5.5
*
return NULL;
}
+static bt_gatt_server_characteristic_notif_state_changed_cb
+ __bt_gatt_attribute_get_notif_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->notif_changed_cb) {
+ *user_data = chr->notif_changed_user_data;
+ *char_handle = (bt_gatt_h*) chr;
+ *server = serv;
+ return chr->notif_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)
{
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_characteristic_notification_state_changed_cb cb1;
+ bt_gatt_server_characteristic_notif_state_changed_cb cb2;
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,
+ cb1 = __bt_gatt_attribute_get_notification_change_cb(&server_handle,
+ notif_info->handle, &char_handle, &user_data_cfm);
+ cb2 = __bt_gatt_attribute_get_notif_change_cb(&server_handle,
notif_info->handle, &char_handle, &user_data_cfm);
- if (cb == NULL) {
+ if (cb1 == NULL && cb2 == NULL) {
BT_INFO("cb is NULL");
return;
}
- BT_INFO("CCCD Noticfication ENABLED [%d]", notif_info->notification);
- cb(notif_info->notification, server_handle, char_handle, user_data_cfm);
+ if (cb1 != NULL) {
+ BT_INFO("CCCD Notification ENABLED [%d]", notif_info->notification);
+ cb1(notif_info->notification, server_handle, char_handle, user_data_cfm);
+ }
+
+ if (cb2 != NULL) {
+ _bt_convert_address_to_string(&device_addr, ¬if_info->device_address);
+ BT_INFO("CCCD Notification ENABLED [%d]", notif_info->notification);
+ cb2(device_addr, notif_info->notification, server_handle, char_handle, user_data_cfm);
+ if (device_addr != NULL)
+ free(device_addr);
+ }
#else
bt_gatt_char_notify_change_t *value_change = param->param_data;
bt_gatt_server_characteristic_notification_state_changed_cb cb;
return BT_ERROR_NONE;
} /* LCOV_EXCL_STOP */
+int bt_gatt_server_set_characteristic_notif_state_change_cb(bt_gatt_h gatt_handle,
+ bt_gatt_server_characteristic_notif_state_changed_cb callback,
+ void *user_data)
+{
+ bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)gatt_handle;
+
+ BT_CHECK_GATT_SERVER_SUPPORT();
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_GATT_SERVER_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(gatt_handle);
+ BT_CHECK_INPUT_PARAMETER(callback);
+
+ BT_VALIDATE_GATT_HANDLE(gatt_handle);
+
+ chr->notif_changed_cb = callback; /* LCOV_EXCL_START */
+ chr->notif_changed_user_data = user_data;
+
+ return BT_ERROR_NONE;
+} /* LCOV_EXCL_STOP */
+
#ifdef TIZEN_FEATURE_GATT_RELAY
/* LCOV_EXCL_START */
static int __gatt_service_add_num_handle(bt_gatt_service_s *service)
return FALSE;
}
-static void __bt_hrp_gatt_server_set_char_notification_state_change_cb(bool notify,
+static void __bt_hrp_gatt_server_set_char_notif_state_change_cb(const char *remote_address, bool notify,
bt_gatt_server_h server, bt_gatt_h gatt_handle,
void *user_data)
{
- BT_INFO("[HR]__bt_gatt_server_notification_state_change_cb");
+ BT_INFO("[HR]__bt_gatt_server_notif_state_change_cb");
BT_INFO("[HR]notify %d", notify);
BT_INFO("[HR]server %s", (char *)server);
BT_INFO("[HR]gatt_handle %s", (char *)gatt_handle);
-
+ BT_INFO("[HR]remote address %s", remote_address);
}
static void __bt_hrp_fast_interval_adv_state_changed_cb(int result,
return error_code;
}
- error_code = bt_gatt_server_set_characteristic_notification_state_change_cb
+ error_code = bt_gatt_server_set_characteristic_notif_state_change_cb
(hrp_server_info_s.hrs_characteristic,
- __bt_hrp_gatt_server_set_char_notification_state_change_cb, NULL);
+ __bt_hrp_gatt_server_set_char_notif_state_change_cb, NULL);
if (error_code != BT_ERROR_NONE)
- BT_ERR("[HR]bt_gatt_server_set_characteristic_notification_state_change_cb : %s\n", _bt_convert_error_to_string(error_code));
+ BT_ERR("[HR]bt_gatt_server_set_characteristic_notif_state_change_cb : %s\n", _bt_convert_error_to_string(error_code));
error_code = bt_gatt_server_register_service(hrp_server_info_s.hrp_sensor, hrp_server_info_s.dis_service);
if (error_code != BT_ERROR_NONE) {
}
-static void __bt_gatt_notification_state_change_cb(bool notify,
+static void __bt_gatt_notif_state_change_cb(const char *remote_address, bool notify,
bt_gatt_server_h server, bt_gatt_h gatt_handle,
void *user_data)
{
BLE_PRT("Notification %s [%d]", notify ? "enabled" : "disabled", notify);
BLE_PRT("server %s\n", (char *)server);
+ BLE_PRT("Remote Address %s", remote_address);
}
ret = bt_gatt_server_set_read_value_requested_cb(characteristic1_3,
__bt_gatt_read_value1_req_cb, NULL);
- ret = bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic1_3,
- __bt_gatt_notification_state_change_cb, NULL);
+ ret = bt_gatt_server_set_characteristic_notif_state_change_cb(characteristic1_3,
+ __bt_gatt_notif_state_change_cb, NULL);
ret = bt_gatt_service_add_characteristic(service1, characteristic1_3);
BLE_PRT("bt_gatt_service_add_characteristic : %s", __bt_get_error_message(ret));
ret = bt_gatt_server_set_read_value_requested_cb(characteristic1_4,
__bt_gatt_read_value1_req_cb, NULL);
- ret = bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic1_4,
- __bt_gatt_notification_state_change_cb, NULL);
+ ret = bt_gatt_server_set_characteristic_notif_state_change_cb(characteristic1_4,
+ __bt_gatt_notif_state_change_cb, NULL);
ret = bt_gatt_service_add_characteristic(service1, characteristic1_4);
BLE_PRT("bt_gatt_service_add_characteristic : %s", __bt_get_error_message(ret));
ret = bt_gatt_server_set_read_value_requested_cb(characteristic2_1,
__bt_gatt_read_value_req_cb, NULL);
- ret = bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic2_1,
- __bt_gatt_notification_state_change_cb, NULL);
+ ret = bt_gatt_server_set_characteristic_notif_state_change_cb(characteristic2_1,
+ __bt_gatt_notif_state_change_cb, NULL);
ret = bt_gatt_service_add_characteristic(service2, characteristic2_1);
BLE_PRT("bt_gatt_service_add_characteristic : %s", __bt_get_error_message(ret));
g_free(new_value);
}
-void __bt_gatt_server_notification_state_change_cb(bool notify,
+void __bt_gatt_server_notif_state_change_cb(const char *remote_address, bool notify,
bt_gatt_server_h server, bt_gatt_h gatt_handle,
void *user_data)
{
__print_gatt_handler(gatt_handle);
TC_PRT("Notification %s [%d]", notify ? "enabled" : "disabled", notify);
TC_PRT("server %s", (char *)server);
+ TC_PRT("Remote address [%s]", remote_address);
printf("\n\n");
}
bt_gatt_server_set_read_value_requested_cb(characteristic,
__bt_gatt_server_read_value_requested_cb, NULL);
- bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic,
- __bt_gatt_server_notification_state_change_cb, NULL);
+ bt_gatt_server_set_characteristic_notif_state_change_cb(characteristic,
+ __bt_gatt_server_notif_state_change_cb, NULL);
ret = bt_gatt_service_add_characteristic(service, characteristic);
TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret));
bt_gatt_server_set_read_value_requested_cb(characteristic,
__bt_gatt_server_read_value_requested_cb, NULL);
- bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic,
- __bt_gatt_server_notification_state_change_cb, NULL);
+ bt_gatt_server_set_characteristic_notif_state_change_cb(characteristic,
+ __bt_gatt_server_notif_state_change_cb, NULL);
ret = bt_gatt_service_add_characteristic(service, characteristic);
TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret));
bt_gatt_server_set_read_value_requested_cb(characteristic,
__bt_gatt_server_read_value_requested_cb, NULL);
- bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic,
- __bt_gatt_server_notification_state_change_cb, NULL);
+ bt_gatt_server_set_characteristic_notif_state_change_cb(characteristic,
+ __bt_gatt_server_notif_state_change_cb, NULL);
ret = bt_gatt_service_add_characteristic(service, characteristic);
TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret));
ret = bt_gatt_server_set_write_value_requested_cb(characteristic,
__bt_gatt_server_write_value_requested_cb, NULL);
- ret = bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic,
- __bt_gatt_server_notification_state_change_cb, NULL);
+ ret = bt_gatt_server_set_characteristic_notif_state_change_cb(characteristic,
+ __bt_gatt_server_notif_state_change_cb, NULL);
ret = bt_gatt_service_add_characteristic(service, characteristic);
TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret));