return result;
}
+BT_EXPORT_API int bluetooth_gatt_server_set_service_persistence(const char *svc_uuid)
+{
+ BT_CHECK_ENABLED(return);
+ int result;
+ char uuid[BT_GATT_ATT_UUID_LEN_MAX + 1];
+
+ g_strlcpy(uuid, svc_uuid, sizeof(uuid));
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ g_array_append_vals(in_param1, uuid, BT_GATT_ATT_UUID_LEN_MAX + 1);
+
+ result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_SET_SERVICE_PERSISTENCE,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ if (result != BLUETOOTH_ERROR_NONE)
+ BT_INFO("GATT Server Set service persistence failed result [%d]", result);
+ else
+ BT_INFO("GATT Server Set service persistence successful");
+
+ BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+ return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_unset_service_persistence(const char *svc_uuid)
+{
+ BT_CHECK_ENABLED(return);
+ int result;
+ char uuid[BT_GATT_ATT_UUID_LEN_MAX + 1];
+
+ g_strlcpy(uuid, svc_uuid, sizeof(uuid));
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ g_array_append_vals(in_param1, uuid, BT_GATT_ATT_UUID_LEN_MAX + 1);
+
+ result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ if (result != BLUETOOTH_ERROR_NONE)
+ BT_INFO("GATT Server Unset service persistence failed result [%d]", result);
+ else
+ BT_INFO("GATT Server Unset service persistence successful");
+
+ BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+ return result;
+}
static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
GIOCondition cond, gpointer data)
}
break;
}
+ case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE: {
+ char *uuid;
+ uuid = (char *)g_variant_get_data(in_param1);
+ result = _bt_gatt_server_set_service_persistence(uuid);
+ break;
+ }
+ case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE: {
+ char *uuid;
+ uuid = (char *)g_variant_get_data(in_param1);
+ result = _bt_gatt_server_unset_service_persistence(uuid);
+ break;
+ }
case BT_GATT_SERVER_SEND_RESPONSE: {
bluetooth_gatt_server_response_params_t param;
bluetooth_gatt_att_data_t data;
case BT_GATT_SERVER_START_SERVICE:
case BT_GATT_SERVER_STOP_SERVICE:
case BT_GATT_SERVER_DELETE_SERVICE:
+ case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE:
+ case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE:
case BT_GATT_SERVER_SEND_RESPONSE:
case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
int completed; /* 1 if last event, otheriwse 0 */
};
+static char service_persistence[BT_UUID_STRING_SIZE + 1];
+
/* Request Search Utility method */
static struct gatt_server_req_info *__bt_gatt_server_find_request_info(int request_id,
bluetooth_gatt_att_request_type_e req_type);
return BLUETOOTH_ERROR_NONE;
}
+int _bt_gatt_server_set_service_persistence(const char *uuid)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ BT_DBG("+");
+
+ retv_if(uuid == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+ if (!strncasecmp(service_persistence, uuid, BT_UUID_STRING_SIZE)) {
+ result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
+ } else {
+ g_strlcpy(service_persistence, uuid, sizeof(service_persistence));
+ BT_DBG("Set service(%s) to be persisted not removed", uuid);
+ }
+
+ return result;
+}
+
+int _bt_gatt_server_unset_service_persistence(const char *uuid)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ BT_DBG("+");
+
+ retv_if(uuid == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+ if (!strncasecmp(service_persistence, uuid, BT_UUID_STRING_SIZE)) {
+ memset(service_persistence, 0, sizeof(service_persistence));
+ BT_DBG("Unset service persistence: %s", uuid);
+ } else {
+ result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
+ }
+
+ return result;
+}
+
+char *_bt_gatt_server_get_service_persistence()
+{
+ return service_persistence;
+}
+
+static gboolean __bt_gatt_server_is_service_persistence(int service_handle)
+{
+ GSList *l;
+ bt_service_app_info_t *info = NULL;
+ bt_service_handle_uuid_info_t *uuid_info = NULL;
+
+ for (int k = 1; k < MAX_APPS_SUPPORTED; k++) {
+ info = &numapps[k];
+ for (l = info->service_handle_uuids; l != NULL;) {
+ uuid_info = l->data;
+ l = g_slist_next(l);
+ if (!uuid_info)
+ continue;
+ if (uuid_info->service_handle == service_handle) {
+ char *uuid = _bt_gatt_server_get_service_persistence();
+ if (!strcasecmp(uuid_info->service_uuid, uuid)) {
+ BT_DBG("service(%s) persisted by user. can't be removed", uuid);
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
{
GSList *l;
l = g_slist_next(l);
if (handle) {
+ if (__bt_gatt_server_is_service_persistence(*handle))
+ return;
+
BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, app_info->instance_id);
if (_bt_gatt_server_stop_service(app_info->sender, *handle, app_info->instance_id) != BLUETOOTH_ERROR_NONE)
continue;
int k;
bt_service_app_info_t *info = NULL;
+ if (__bt_gatt_server_is_service_persistence(service_handle))
+ return BLUETOOTH_ERROR_INTERNAL;
+
ret = gatts_delete_service(instance_id, service_handle);
if (ret != OAL_STATUS_SUCCESS) {
BT_ERR("ret: %d", ret);
int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param, void *);
+int _bt_gatt_server_set_service_persistence(const char *uuid);
+
+int _bt_gatt_server_unset_service_persistence(const char *uuid);
+
//#define __INTEGRATE_GATT_INFO__ // TODO: this feature can be used if easy setup scenario is fully supported
#ifndef __INTEGRATE_GATT_INFO__
struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address);
int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
+int bluetooth_gatt_server_set_service_persistence(const char *svc_uuid);
+
+int bluetooth_gatt_server_unset_service_persistence(const char *svc_uuid);
+
#ifdef __cplusplus
}
#endif
BT_GATT_SERVER_START_SERVICE,
BT_GATT_SERVER_STOP_SERVICE,
BT_GATT_SERVER_DELETE_SERVICE,
+ BT_GATT_SERVER_SET_SERVICE_PERSISTENCE,
+ BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE,
BT_GATT_SERVER_SEND_RESPONSE,
BT_GATT_SERVER_ACQURE_WRITE_RESPONSE,
BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE,