[GATT Server] Delivery the specific error code to central device 14/140614/3 accepted/tizen/4.0/unified/20170816.013218 accepted/tizen/unified/20170727.190503 submit/tizen/20170725.234514 submit/tizen_4.0/20170811.094300
authorinjun.yang <injun.yang@samsung.com>
Tue, 25 Jul 2017 14:36:47 +0000 (20:06 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Tue, 25 Jul 2017 23:39:17 +0000 (23:39 +0000)
[Problem] Unalbe to pass application error code to central device
[Cause & Measure] Pass the specific error code to central device
[Checking Method] Reponse with the specific error to central device

Change-Id: Icb9eb38e0f7759d5aeb898eef92d1327233e9a48
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
src/gatt-database.c

index 37b8b9b..79d9a9b 100755 (executable)
@@ -1859,47 +1859,23 @@ static bool parse_primary(GDBusProxy *proxy, bool *primary)
 }
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-static bool is_otp_operation(bt_uuid_t *uuid)
+static uint8_t dbus_error_to_att_ecode(const char *error_message)
 {
-       bt_uuid_t u1, u2;
-       uint16_t start = 0x2ABD;
-       uint16_t end = 0x2AC8;
+       uint8_t att_ecode = 0;
+       int len;
+       char *str = NULL;
 
-       bt_uuid16_create(&u1, start);
-       bt_uuid16_create(&u2, end);
-
-       /* check whether the given uuid is in
-        * OTP characteristics range or not.
-        */
-       if ((bt_uuid_cmp(uuid, &u1) >= 0) &&
-                       (bt_uuid_cmp(uuid, &u2) <= 0))
-               return true;
-
-       return false;
-}
-
-static uint8_t dbus_error_to_otp_ecode(const char *error_msg)
-{
-       /* OTP error codes */
-       if (strcmp(error_msg, "Write Request Rejected") == 0)
-               return BT_ATT_ERROR_WRITE_REQUEST_REJECTED;
-
-       if (strcmp(error_msg, "Object Not Selected") == 0)
-               return BT_ATT_ERROR_OBJECT_NOT_SELECTED;
-
-       if (strcmp(error_msg, "Concurrency Limit Exceeded") == 0)
-               return BT_ATT_ERROR_CONCURRENCY_LIMIT_EXCEEDED;
-
-       if (strcmp(error_msg, "Object Name Already Exists") == 0)
-               return BT_ATT_ERROR_OBJECT_NAME_EXISTS;
-
-       if (strcmp(error_msg, "CCC Improperly Configured") == 0)
-               return BT_ERROR_CCC_IMPROPERLY_CONFIGURED;
+       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
+               att_ecode = BT_ATT_ERROR_UNLIKELY;
 
-       return 0x80; /* Default application error code */
+       return att_ecode;
 }
-#endif
-
+#else
 static uint8_t dbus_error_to_att_ecode(const char *error_name)
 {
        if (strcmp(error_name, "org.bluez.Error.Failed") == 0)
@@ -1919,6 +1895,7 @@ static uint8_t dbus_error_to_att_ecode(const char *error_name)
 
        return 0;
 }
+#endif
 
 static void read_reply_cb(DBusMessage *message, void *user_data)
 {
@@ -1942,12 +1919,12 @@ static void read_reply_cb(DBusMessage *message, void *user_data)
 
        if (dbus_set_error_from_message(&err, message) == TRUE) {
                DBG("Failed to read value: %s: %s", err.name, err.message);
-               ecode = dbus_error_to_att_ecode(err.name);
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-               if (is_otp_operation(uuid) && ecode == 0x80)
-                       ecode = dbus_error_to_otp_ecode(err.message);
-#endif
+               ecode = dbus_error_to_att_ecode(err.message);
+#else
+               ecode = dbus_error_to_att_ecode(err.name);
                ecode = ecode ? ecode : BT_ATT_ERROR_READ_NOT_PERMITTED;
+#endif
                dbus_error_free(&err);
                goto done;
        }
@@ -2129,12 +2106,12 @@ static void write_reply_cb(DBusMessage *message, void *user_data)
 
        if (dbus_set_error_from_message(&err, message) == TRUE) {
                DBG("Failed to write value: %s: %s", err.name, err.message);
-               ecode = dbus_error_to_att_ecode(err.name);
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-               if (is_otp_operation(uuid) && ecode == 0x80)
-                       ecode = dbus_error_to_otp_ecode(err.message);
-#endif
+               ecode = dbus_error_to_att_ecode(err.message);
+#else
+               ecode = dbus_error_to_att_ecode(err.name);
                ecode = ecode ? ecode : BT_ATT_ERROR_WRITE_NOT_PERMITTED;
+#endif
                dbus_error_free(&err);
                goto done;
        }