[GATT Client] Delivery ATT error code to higher layer 78/139378/5 accepted/tizen/unified/20170721.201850 submit/tizen/20170721.013619
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Tue, 18 Jul 2017 13:35:50 +0000 (19:05 +0530)
committerGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 19 Jul 2017 13:50:16 +0000 (19:20 +0530)
[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 <gowtham.ab@samsung.com>
include/bluetooth_type_internal.h
src/bluetooth-common.c
src/bluetooth-gatt.c
test/bt_unit_test.c

index 0748099bc497af009618b3d06b87aa47b7496df9..e01cedca025a4c2e5a535d11f8151323315a90c0 100644 (file)
@@ -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.
index c9594f8c86dff2fa6894acd57d2fc29d25459492..06e878b91364c4433c8ba35cfa4b8b14711e1ede 100644 (file)
@@ -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: {
index f51e799362775ccdb79ec2e617920577ea138a9e..6d73ad33b8122f2a77c7778369908e6eb38712c4 100644 (file)
@@ -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)
index c02f7bf242b6997738322b0c3e8cf832ce30db07..bfc2d7edd9c8c2d55483dbea89e8fee2b787be6b 100644 (file)
@@ -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);