[GATT Client] Delivery ATT error code to higher layer
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-otp.c
index 0c61c19..afe4232 100644 (file)
@@ -297,13 +297,31 @@ static void __bt_otp_remove_read_info(bt_otp_read_req_info *info)
        g_free(info);
 }
 
+static int __bluetooth_get_att_error_code(GError *error)
+{
+       int att_ecode = 0;
+       int len;
+       char *str = NULL;
+
+       BT_ERR("Error : %s", error->message);
+       str = g_strrstr(error->message, "ATT error: 0x");
+       if (str) {
+               len = strlen(str);
+               att_ecode =  g_ascii_xdigit_value(str[len-2]) << 4;
+               att_ecode += g_ascii_xdigit_value(str[len-1]);
+       } else
+               return BLUETOOTH_ATT_ERROR_INTERNAL;
+
+       return att_ecode;
+}
+
 static void __bt_otp_read_char_cb(GObject *source_object,
                        GAsyncResult *res, gpointer user_data)
 {
        bt_gatt_char_descriptor_property_t att_value =  { 0, };
        GDBusConnection *system_gconn = NULL;
        GVariant *var_data, *param = NULL;
-       int result = BLUETOOTH_ERROR_NONE;
+       int result = BLUETOOTH_ATT_ERROR_NONE;
        bt_otp_read_req_info *info = NULL;
        GByteArray *gp_byte_array = NULL;
        request_info_t *req_info = NULL;
@@ -312,7 +330,7 @@ static void __bt_otp_read_char_cb(GObject *source_object,
        char *otp_data = NULL;
        GVariant *out_param1;
        GError *error = NULL;
-       guint8 g_byte, att_error_code;
+       guint8 g_byte;
        char *handle;
 
        BT_DBG("+");
@@ -324,20 +342,12 @@ static void __bt_otp_read_char_cb(GObject *source_object,
        value = g_dbus_connection_call_finish(system_gconn, res, &error);
 
        if (error) {
-               BT_ERR("Error : %s \n", error->message);
+               result = __bluetooth_get_att_error_code(error);
                att_value.val_len = 0;
-               result = BLUETOOTH_ERROR_INTERNAL;
                goto dbus_return;
        }
 
-       g_variant_get(value, "(yay)", &att_error_code, &iter);
-
-       if (att_error_code != 0) {
-               BT_ERR("ATT err code : [%d]", att_error_code);
-               att_value.val_len = 0;
-               result = att_error_code;
-               goto dbus_return;
-       }
+       g_variant_get(value, "(ay)", &iter);
 
        gp_byte_array = g_byte_array_new();
 
@@ -431,7 +441,7 @@ int _bt_otp_read_characteristic_value(int request_id, char *sender, char *handle
                        GATT_CHAR_INTERFACE,
                        "ReadValue",
                        g_variant_new("(a{sv})", builder),
-                       G_VARIANT_TYPE("(yay)"),
+                       G_VARIANT_TYPE("(ay)"),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
@@ -626,27 +636,17 @@ static void __bt_otp_write_request_cb(GObject *source_object,
        GVariant *value = NULL;
        GVariant *param = NULL;
        GVariant *out_param1 = NULL;
-       int result = BLUETOOTH_ERROR_NONE;
+       int result = BLUETOOTH_ATT_ERROR_NONE;
        char *handle = NULL;
        bt_otp_notification_info *info = NULL;
        request_info_t *req_info = NULL;
-       guint8 att_ecode = 0;
        BT_DBG("+");
 
        system_gconn = _bt_gdbus_get_system_gconn();
        value = g_dbus_connection_call_finish(system_gconn, res, &error);
 
-       if (error) {
-               BT_ERR("Error : %s \n", error->message);
-               /* Process error->message to narrow down the att_ecode */
-               result = BLUETOOTH_ERROR_INTERNAL;
-       } else {
-               g_variant_get(value, "(y)", &att_ecode);
-               if (att_ecode) {
-                       result =  att_ecode;
-                       BT_ERR("ATT Error code: %d \n", att_ecode);
-               }
-       }
+       if (error)
+               result = __bluetooth_get_att_error_code(error);
 
        handle = (char *)user_data;
        info = __bt_otp_get_notification_info(handle);
@@ -654,7 +654,7 @@ static void __bt_otp_write_request_cb(GObject *source_object,
                req_info = _bt_get_request_info(info->req_id);
 
        /* Is Activation request failed for any reason, reset timer */
-       if (result != BLUETOOTH_ERROR_NONE && info != NULL) {
+       if (result != BLUETOOTH_ATT_ERROR_NONE && info != NULL) {
                BT_ERR("Activation Request failed");
                /* Remove Indication Info */
                __bt_otp_remove_notification_info(info);