From: Gowtham Anandha Babu Date: Tue, 18 Jul 2017 13:35:50 +0000 (+0530) Subject: [GATT Client] Delivery ATT error code to higher layer X-Git-Tag: submit/tizen/20170721.013619^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9d24aa2f7722c30a7d8934e73c88e2d77648497;p=platform%2Fcore%2Fapi%2Fbluetooth.git [GATT Client] Delivery ATT error code to higher layer [Problem] ATT error code is not passed to application. [Cause & Measure] GATT application need to know ATT error code to handling error case. Specially application error code defined by a higher layer specification. [Checking Method] GATT error handling Change-Id: Ic7c8f14f107dd65bae925c2e424b3bd71e04f8b8 Signed-off-by: Gowtham Anandha Babu --- diff --git a/include/bluetooth_type_internal.h b/include/bluetooth_type_internal.h index 0748099..e01cedc 100644 --- a/include/bluetooth_type_internal.h +++ b/include/bluetooth_type_internal.h @@ -41,6 +41,47 @@ typedef enum { BT_ADAPTER_LE_ENABLED, /**< Bluetooth le is enabled */ } bt_adapter_le_state_e; +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the ATT error codes. + * @since_tizen 4.0 + */ +typedef enum { + BT_ATT_ERROR_INTERNAL = -1, + BT_ATT_ERROR_NONE = 0x00, + + /* Attribute error codes */ + BT_ATT_ERROR_INVALID_HANDLE = 0x01, + BT_ATT_ERROR_READ_NOT_PERMITTED = 0x02, + BT_ATT_ERROR_WRITE_NOT_PERMITTED = 0x03, + BT_ATT_ERROR_INVALID_PDU = 0x04, + BT_ATT_ERROR_AUTHENTICATION = 0x05, + BT_ATT_ERROR_REQUEST_NOT_SUPPORTED = 0x06, + BT_ATT_ERROR_INVALID_OFFSET = 0x07, + BT_ATT_ERROR_AUTHORIZATION = 0x08, + BT_ATT_ERROR_PREPARE_QUEUE_FULL = 0x09, + BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND = 0x0A, + BT_ATT_ERROR_ATTRIBUTE_NOT_LONG = 0x0B, + BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE = 0x0C, + BT_ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LEN = 0x0D, + BT_ATT_ERROR_UNLIKELY = 0x0E, + BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION = 0x0F, + BT_ATT_ERROR_UNSUPPORTED_GROUP_TYPE = 0x10, + BT_ATT_ERROR_INSUFFICIENT_RESOURCES = 0x11, + + /* Common profile error codes */ + BT_ATT_ERROR_WRITE_REQUEST_REJECTED = 0x80, + BT_ATT_ERROR_CCCD_IMPROPERLY_CONFIGURED = 0xFD, + BT_ATT_ERROR_PROCEDURE_ALREADY_IN_PROGRESS = 0xFE, + BT_ATT_ERROR_OUT_OF_RANGE = 0xFF, + + /* Bluetooth OTP error codes */ + BT_ATT_ERROR_OBJECT_NOT_SELECTED = 0x81, + BT_ATT_ERROR_CONCURRENCY_LIMIT_EXCEEDED = 0x82, + BT_ATT_ERROR_OBJECT_NAME_EXISTS = 0x83, + +} bt_att_error_e; + /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief Called when the Bluetooth adapter le state changes. diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index c9594f8..06e878b 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -451,10 +451,17 @@ int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_ (*dest_dev)->manufacturer_data_len = source_dev->manufacturer_data.data_len; if (source_dev->manufacturer_data.data_len > 0) { (*dest_dev)->manufacturer_data = (char *)malloc(source_dev->manufacturer_data.data_len); - memcpy((*dest_dev)->manufacturer_data, source_dev->manufacturer_data.data, source_dev->manufacturer_data.data_len); + if ((*dest_dev)->manufacturer_data) + memcpy((*dest_dev)->manufacturer_data, source_dev->manufacturer_data.data, + source_dev->manufacturer_data.data_len); + else + return BT_ERROR_OUT_OF_MEMORY; } else { (*dest_dev)->manufacturer_data = (char *)malloc(1); - (*dest_dev)->manufacturer_data[0] = 0; + if ((*dest_dev)->manufacturer_data) + (*dest_dev)->manufacturer_data[0] = 0; + else + return BT_ERROR_OUT_OF_MEMORY; } return BT_ERROR_NONE; @@ -2083,8 +2090,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us break; } _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC); - ret = _bt_get_error_code(param->result); - if (ret == BT_ERROR_NONE) { + ret = param->result; + if (ret == BT_ATT_ERROR_NONE) { char_val = (bt_gatt_char_value_t *)(param->param_data); bt_gatt_set_value(cb_data->gatt_handle, (char *)char_val->char_value, (int)char_val->val_len); @@ -2110,15 +2117,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us } _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC); - /* Send actual ATT error code to Application - * if param->result is not BLUETOOTH_ERROR_INTERNAL. - */ - if (param->result == BLUETOOTH_ERROR_INTERNAL) - ret = _bt_get_error_code(param->result); - else - ret = param->result; + ret = param->result; - if (ret != BT_ERROR_NONE) + if (ret != BT_ATT_ERROR_NONE) BT_ERR("BLUETOOTH_EVENT_GATT_WRITE_CHAR - ret [%d]", ret); cb(ret, cb_data->gatt_handle, cb_data->user_data); @@ -2135,8 +2136,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us BT_INFO("BLUETOOTH_EVENT_GATT_READ_DESC"); _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR); - ret = _bt_get_error_code(param->result); - if (ret == BT_ERROR_NONE) { + ret = param->result; + if (ret == BT_ATT_ERROR_NONE) { desc_val = (bt_gatt_char_property_t *)(param->param_data); bt_gatt_set_value(cb_data->gatt_handle, desc_val->description, (int)desc_val->val_len); @@ -2154,7 +2155,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_DESC"); _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR); - ret = _bt_get_error_code(param->result); + ret = param->result; cb(ret, cb_data->gatt_handle, cb_data->user_data); g_free(cb_data); @@ -2935,15 +2936,15 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bluetooth_otp_resp_info_t *info = NULL; char *handle = NULL; - if (_bt_get_error_code(param->result) == BT_ERROR_NONE) { + if (param->result == BT_ATT_ERROR_NONE) { info = (bluetooth_otp_resp_info_t *)(param->param_data); BT_ERR("Read Success Handle [%s]", info->handle); - _bt_otp_client_read_value_response(_bt_get_error_code(param->result), + _bt_otp_client_read_value_response(param->result, info->handle, info->data, info->data_length); } else { handle = (char *)(param->param_data); BT_ERR("Read Fail Handle [%s]", handle); - _bt_otp_client_read_value_response(_bt_get_error_code(param->result), + _bt_otp_client_read_value_response(param->result, handle, NULL, 0); } break; @@ -2952,7 +2953,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us BT_DBG("BLUETOOTH_EVENT_OTP_WRITE_CHAR_VAL"); /* LCOV_EXCL_LINE */ char *handle = (char *)(param->param_data); BT_ERR("Handle [%s]", handle); - _bt_otp_client_write_value_response(_bt_get_error_code(param->result), handle); + _bt_otp_client_write_value_response(param->result, handle); break; } case BLUETOOTH_EVENT_OTP_NOTIFICATION_ENABLED: { diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index f51e799..6d73ad3 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -2587,7 +2587,7 @@ int bt_gatt_server_send_response(int request_id, bt_gatt_att_request_type_e requ BT_CHECK_INIT_STATUS(); if (request_type == BT_GATT_REQUEST_TYPE_READ && - resp_status == BT_ERROR_NONE) { + resp_status == BT_ATT_ERROR_NONE) { BT_CHECK_INPUT_PARAMETER(value); if (value_length < 0) diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index c02f7bf..bfc2d7e 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -1729,7 +1729,7 @@ void __bt_gatt_server_read_value_requested_cb( int offset, void *user_data) { char char_value_1[3] = {0, 1, 2}; - int resp_status = BT_ERROR_NONE; + int resp_status = BT_ATT_ERROR_NONE; TC_PRT("__bt_gatt_server_read_value_requested_cb"); TC_PRT("remote_address %s", remote_address); @@ -2364,7 +2364,7 @@ void __bt_gatt_client_write_complete_cb(int result, bt_get_uuid_name(uuid, &str); TC_PRT("Write %s for %s (%s)", - result == BT_ERROR_NONE ? "Success" : "Fail", + result == BT_ATT_ERROR_NONE ? "Success" : "Fail", str ? str : "Unknown", uuid); g_free(str); @@ -2383,13 +2383,13 @@ void __bt_gatt_client_read_complete_cb(int result, bt_get_uuid_name(uuid, &str); TC_PRT("Read %s for %s (%s)", - result == BT_ERROR_NONE ? "Success" : "Fail", + result == BT_ATT_ERROR_NONE ? "Success" : "Fail", str ? str : "Unknown", uuid); g_free(str); g_free(uuid); - if (result != BT_ERROR_NONE) + if (result != BT_ATT_ERROR_NONE) return; __bt_gatt_client_print_value(gatt_handle); @@ -2694,7 +2694,7 @@ void __bt_gatt_server_write_value_requested_cb(const char *remote_address, bt_gatt_h gatt_handle, bool response_needed, int offset, const char *value, int len, void *user_data) { - int i, resp_status = BT_ERROR_NONE; + 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);