From: injun.yang Date: Tue, 20 Feb 2018 08:10:19 +0000 (+0900) Subject: Fix : GATT service is not registered X-Git-Tag: submit/tizen_4.0/20180328.084945~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=22492e7e0498a918d6b8d6e11a65aaeceb2e67d6;p=platform%2Fcore%2Fapi%2Fbluetooth.git Fix : GATT service is not registered Change-Id: I8fa782c830f96f84d9032ffd65883c43dec26a88 --- diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index 3baa268..08f26fe 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -2771,9 +2771,25 @@ int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service) _bt_convert_error_to_string(ret), ret); goto fail; } + + ret = _bt_get_error_code(bluetooth_gatt_set_descriptor_value(desc->path, + desc->value, desc->value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", + _bt_convert_error_to_string(ret), ret); + goto fail; + } } } + ret = _bt_get_error_code(bluetooth_gatt_register_service(svc->path)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + serv->services = g_slist_append(serv->services, svc); svc->parent = (void *)server; @@ -2781,6 +2797,7 @@ int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service) fail: BT_ERR("Registering Service failed!!!!!"); + bluetooth_gatt_unregister_service(svc->path); return ret; } diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 1dca483..667a6b2 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -1764,6 +1764,40 @@ static void __bt_adapter_le_scan_result_cb( } } +static void __print_gatt_handler(bt_gatt_h gatt_handle) +{ + if (!gatt_handle) { + TC_PRT("Invalid handler"); + return; + } + + char *type; + char *role; + bt_gatt_common_s *handle = (bt_gatt_common_s *)gatt_handle; + + if (handle->type == BT_GATT_TYPE_SERVICE) + type = g_strdup("Service"); + else if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) + type = g_strdup("Characteristic"); + else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) + type = g_strdup("Descriptor"); + else + type = g_strdup("Unknown"); + + if (handle->role == BT_GATT_ROLE_SERVER) + role = g_strdup("Server"); + else if (handle->role == BT_GATT_ROLE_CLIENT) + role = g_strdup("Client"); + else + role = g_strdup("Unknown"); + + TC_PRT("GATT %s [%s]", type, role); + TC_PRT("%s [%s]", handle->path, handle->uuid); + + g_free(type); + g_free(role); +} + void __bt_gatt_server_read_value_requested_cb( const char *remote_address, int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, @@ -1772,12 +1806,10 @@ void __bt_gatt_server_read_value_requested_cb( char char_value_1[3] = {0, 1, 2}; int resp_status = BT_ATT_ERROR_NONE; - TC_PRT("__bt_gatt_server_read_value_requested_cb"); - TC_PRT("remote_address %s", remote_address); - TC_PRT("req_id %d", request_id); - TC_PRT("server %s", (char *)server); - TC_PRT("gatt_handle %s", (char *)gatt_handle); - TC_PRT("Offset %d", offset); + __print_gatt_handler(gatt_handle); + TC_PRT("[%s] req_id %d, offset %d", remote_address, request_id, offset); + printf("\n"); + /* Get the attribute new values here */ bt_gatt_server_send_response(request_id, BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ, offset, @@ -1788,10 +1820,11 @@ void __bt_gatt_server_notification_state_change_cb(bool notify, bt_gatt_server_h server, bt_gatt_h gatt_handle, void *user_data) { - TC_PRT("__bt_gatt_server_notification_state_change_cb"); - TC_PRT("notify %d", notify); + __print_gatt_handler(gatt_handle); + TC_PRT("Notification %s [%d]", notify ? "enabled" : "disabled", notify); TC_PRT("server %s", (char *)server); - TC_PRT("gatt_handle %s", (char *)gatt_handle); + printf("\n\n"); + } @@ -2769,10 +2802,11 @@ void __bt_gatt_server_write_value_requested_cb(const char *remote_address, const char *value, int len, void *user_data) { int i, resp_status = BT_ATT_ERROR_NONE; - TC_PRT("remote_address : %s", remote_address); - TC_PRT("Response needed : %d", response_needed); - TC_PRT("offset : %d", offset); - TC_PRT("len [%d] : ", len); + + __print_gatt_handler(gatt_handle); + TC_PRT("[%s] req_id %d, response_needed %d, offset %d, len %d", + remote_address, request_id, response_needed, offset, len); + for (i = 0; i < len; i++) printf("%d ", value[i]); @@ -8090,9 +8124,9 @@ int test_input_callback(void *data) bt_gatt_h descriptor = NULL; char *service_uuid = "000018f2-0000-1000-8000-00805f9b34fb"; char *char_uuid = "00002af6-0000-1000-8000-00805f9b34fb"; - char *desc_uuid = "00002a56-0000-1000-8000-00805f9b34fb"; + char *desc_uuid = "2902"; // CCCD char char_value[4] = {10, 20, 30, 40}; - char desc_value[4] = {12, 34, 56, 78}; + char desc_value[2] = {0, 0}; // Notification disabled int value_length = 4; int permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; int properties = BT_GATT_PROPERTY_BROADCAST | BT_GATT_PROPERTY_READ | @@ -8111,6 +8145,7 @@ int test_input_callback(void *data) &service); TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret)); + /* Read & Write & Notify characteristics UUID */ ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, char_value, value_length, &characteristic); @@ -8118,20 +8153,21 @@ int test_input_callback(void *data) bt_gatt_server_set_read_value_requested_cb(characteristic, __bt_gatt_server_read_value_requested_cb, NULL); + + 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_service_add_characteristic(service, characteristic); TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + /* CCCD for Notify characteristics */ ret = bt_gatt_descriptor_create(desc_uuid, permissions, desc_value, value_length, &descriptor); TC_PRT("bt_gatt_descriptor_create : %s\n", __bt_get_error_message(ret)); - bt_gatt_server_set_read_value_requested_cb(descriptor, - __bt_gatt_server_read_value_requested_cb, NULL); - - ret = bt_gatt_server_set_write_value_requested_cb(descriptor, - __bt_gatt_server_write_value_requested_cb, - NULL); - ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor); TC_PRT("bt_gatt_characteristic_add_descriptor : %s\n", __bt_get_error_message(ret));