From: Gowtham Anandha Babu Date: Tue, 28 Mar 2017 12:39:09 +0000 (+0530) Subject: [Bluetooth][OTP] Handle OTP specific ATT error codes X-Git-Tag: accepted/tizen/unified/20170410.155737^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F11%2F121711%2F3;p=platform%2Fupstream%2Fbluez.git [Bluetooth][OTP] Handle OTP specific ATT error codes Refer OTS specification, section 1.10 Application Error Codes. Change-Id: Id91b4788ccd9ac22885412e4808040e4c1ab343c Signed-off-by: Gowtham Anandha Babu --- diff --git a/src/gatt-database.c b/src/gatt-database.c index 9fa059b..255583b 100755 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -1858,9 +1858,47 @@ static bool parse_primary(GDBusProxy *proxy, bool *primary) return true; } -static uint8_t dbus_error_to_att_ecode(const char *error_name) +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +static bool is_otp_operation(bt_uuid_t *uuid) +{ + bt_uuid_t u1, u2; + uint16_t start = 0x2ABD; + uint16_t end = 0x2AC8; + + 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; + return 0x80; /* Default application error code */ +} +#endif + +static uint8_t dbus_error_to_att_ecode(const char *error_name) +{ if (strcmp(error_name, "org.bluez.Error.Failed") == 0) return 0x80; /* For now return this "application error" */ @@ -1882,6 +1920,10 @@ static uint8_t dbus_error_to_att_ecode(const char *error_name) static void read_reply_cb(DBusMessage *message, void *user_data) { struct pending_op *op = user_data; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + struct gatt_db_attribute *attrib = op->attrib; + bt_uuid_t *uuid = gatt_db_attribute_get_type(attrib); +#endif DBusError err; DBusMessageIter iter, array; uint8_t ecode = 0; @@ -1898,6 +1940,10 @@ 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 = ecode ? ecode : BT_ATT_ERROR_READ_NOT_PERMITTED; dbus_error_free(&err); goto done; @@ -2063,6 +2109,10 @@ static void write_setup_cb(DBusMessageIter *iter, void *user_data) static void write_reply_cb(DBusMessage *message, void *user_data) { struct pending_op *op = user_data; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + struct gatt_db_attribute *attrib = op->attrib; + bt_uuid_t *uuid = gatt_db_attribute_get_type(attrib); +#endif DBusError err; DBusMessageIter iter; uint8_t ecode = 0; @@ -2077,6 +2127,10 @@ 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 = ecode ? ecode : BT_ATT_ERROR_WRITE_NOT_PERMITTED; dbus_error_free(&err); goto done; diff --git a/src/shared/att-types.h b/src/shared/att-types.h index 51922d1..4f763d7 100755 --- a/src/shared/att-types.h +++ b/src/shared/att-types.h @@ -101,6 +101,17 @@ struct bt_att_pdu_error_rsp { #define BT_ATT_ERROR_UNSUPPORTED_GROUP_TYPE 0x10 #define BT_ATT_ERROR_INSUFFICIENT_RESOURCES 0x11 +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +/* + * OTP ATT error codes. Refer OTS specification, + * section 1.10 Application Error Codes + */ +#define BT_ATT_ERROR_WRITE_REQUEST_REJECTED 0x80 +#define BT_ATT_ERROR_OBJECT_NOT_SELECTED 0x81 +#define BT_ATT_ERROR_CONCURRENCY_LIMIT_EXCEEDED 0x82 +#define BT_ATT_ERROR_OBJECT_NAME_EXISTS 0x83 +#endif + /* * Common Profile and Service Error Code descriptions (see Supplement to the * Bluetooth Core Specification, sections 1.2 and 2). The error codes within