* [PATCH BlueZ 1/2] gatt-api: Add error code ReadValue/WriteValue
@ 2022-08-25 20:07 Luiz Augusto von Dentz
2022-08-25 20:07 ` [PATCH BlueZ 2/2] gatt: Parse error message Luiz Augusto von Dentz
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-08-25 20:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This allows application to return error codes in the range allowed by
the spec:
'GATT - Section 4.9.5:
Application Error 0x80 – 0x9F Application error code defined by a
higher layer specification.'
---
doc/gatt-api.txt | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
index af0aa761d0a2..5042c54704e4 100644
--- a/doc/gatt-api.txt
+++ b/doc/gatt-api.txt
@@ -79,13 +79,15 @@ Methods array{byte} ReadValue(dict options)
"mtu": Exchanged MTU (Server only)
"device": Object Device (Server only)
- Possible Errors: org.bluez.Error.Failed
+ Possible Errors: org.bluez.Error.Failed(string ecode)
org.bluez.Error.InProgress
org.bluez.Error.NotPermitted
org.bluez.Error.NotAuthorized
org.bluez.Error.InvalidOffset
org.bluez.Error.NotSupported
+ Possible Error Code: string 0x80 - 0x9f
+
void WriteValue(array{byte} value, dict options)
Issues a request to write the value of the
@@ -105,13 +107,15 @@ Methods array{byte} ReadValue(dict options)
authorization
request
- Possible Errors: org.bluez.Error.Failed
+ Possible Errors: org.bluez.Error.Failed(string ecode)
org.bluez.Error.InProgress
org.bluez.Error.NotPermitted
org.bluez.Error.InvalidValueLength
org.bluez.Error.NotAuthorized
org.bluez.Error.NotSupported
+ Possible Error Code: string 0x80 - 0x9f
+
fd, uint16 AcquireWrite(dict options) [optional]
Acquire file descriptor and MTU for writing. Only
--
2.37.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH BlueZ 2/2] gatt: Parse error message 2022-08-25 20:07 [PATCH BlueZ 1/2] gatt-api: Add error code ReadValue/WriteValue Luiz Augusto von Dentz @ 2022-08-25 20:07 ` Luiz Augusto von Dentz 2022-08-25 21:09 ` [BlueZ,1/2] gatt-api: Add error code ReadValue/WriteValue bluez.test.bot 2022-08-29 19:50 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth 2 siblings, 0 replies; 4+ messages in thread From: Luiz Augusto von Dentz @ 2022-08-25 20:07 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Application can now encode an error code into the D-Bus reply error message (0x80-0x9f). Fixes: https://github.com/bluez/bluez/issues/380 --- src/gatt-database.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/gatt-database.c b/src/gatt-database.c index db8432c6bf77..89a3dc47560b 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -2192,27 +2192,43 @@ static bool parse_handle(GDBusProxy *proxy, uint16_t *handle) return true; } -static uint8_t dbus_error_to_att_ecode(const char *error_name, uint8_t perm_err) +static uint8_t dbus_error_to_att_ecode(const char *name, const char *msg, + uint8_t perm_err) { - if (strcmp(error_name, ERROR_INTERFACE ".Failed") == 0) - return 0x80; /* For now return this "application error" */ + if (strcmp(name, ERROR_INTERFACE ".Failed") == 0) { + char *endptr = NULL; + uint32_t ecode; - if (strcmp(error_name, ERROR_INTERFACE ".NotSupported") == 0) + ecode = strtol(msg, &endptr, 0); + + /* If message doesn't set an error code just use 0x80 */ + if (!endptr || *endptr != '\0') + return 0x80; + + if (ecode < 0x80 || ecode > 0x9f) { + error("Invalid error code: %s", msg); + return BT_ATT_ERROR_UNLIKELY; + } + + return ecode; + } + + if (strcmp(name, ERROR_INTERFACE ".NotSupported") == 0) return BT_ATT_ERROR_REQUEST_NOT_SUPPORTED; - if (strcmp(error_name, ERROR_INTERFACE ".NotAuthorized") == 0) + if (strcmp(name, ERROR_INTERFACE ".NotAuthorized") == 0) return BT_ATT_ERROR_AUTHORIZATION; - if (strcmp(error_name, ERROR_INTERFACE ".InvalidValueLength") == 0) + if (strcmp(name, ERROR_INTERFACE ".InvalidValueLength") == 0) return BT_ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LEN; - if (strcmp(error_name, ERROR_INTERFACE ".InvalidOffset") == 0) + if (strcmp(name, ERROR_INTERFACE ".InvalidOffset") == 0) return BT_ATT_ERROR_INVALID_OFFSET; - if (strcmp(error_name, ERROR_INTERFACE ".InProgress") == 0) + if (strcmp(name, ERROR_INTERFACE ".InProgress") == 0) return BT_ERROR_ALREADY_IN_PROGRESS; - if (strcmp(error_name, ERROR_INTERFACE ".NotPermitted") == 0) + if (strcmp(name, ERROR_INTERFACE ".NotPermitted") == 0) return perm_err; return BT_ATT_ERROR_UNLIKELY; @@ -2236,7 +2252,7 @@ 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, + ecode = dbus_error_to_att_ecode(err.name, err.message, BT_ATT_ERROR_READ_NOT_PERMITTED); dbus_error_free(&err); goto done; @@ -2415,7 +2431,7 @@ 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, + ecode = dbus_error_to_att_ecode(err.name, err.message, BT_ATT_ERROR_WRITE_NOT_PERMITTED); dbus_error_free(&err); goto done; @@ -2610,7 +2626,7 @@ static void acquire_write_reply(DBusMessage *message, void *user_data) error("Failed to acquire write: %s\n", err.name); - ecode = dbus_error_to_att_ecode(err.name, + ecode = dbus_error_to_att_ecode(err.name, err.message, BT_ATT_ERROR_WRITE_NOT_PERMITTED); dbus_error_free(&err); -- 2.37.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [BlueZ,1/2] gatt-api: Add error code ReadValue/WriteValue 2022-08-25 20:07 [PATCH BlueZ 1/2] gatt-api: Add error code ReadValue/WriteValue Luiz Augusto von Dentz 2022-08-25 20:07 ` [PATCH BlueZ 2/2] gatt: Parse error message Luiz Augusto von Dentz @ 2022-08-25 21:09 ` bluez.test.bot 2022-08-29 19:50 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth 2 siblings, 0 replies; 4+ messages in thread From: bluez.test.bot @ 2022-08-25 21:09 UTC (permalink / raw) To: linux-bluetooth, luiz.dentz [-- Attachment #1: Type: text/plain, Size: 2160 bytes --] This is automated email and please do not reply to this email! Dear submitter, Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series: PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=671211 ---Test result--- Test Summary: CheckPatch PASS 2.27 seconds GitLint PASS 1.61 seconds Prep - Setup ELL PASS 26.73 seconds Build - Prep PASS 0.73 seconds Build - Configure PASS 8.39 seconds Build - Make PASS 969.49 seconds Make Check PASS 11.87 seconds Make Check w/Valgrind PASS 286.82 seconds Make Distcheck PASS 235.16 seconds Build w/ext ELL - Configure PASS 8.64 seconds Build w/ext ELL - Make PASS 82.00 seconds Incremental Build w/ patches PASS 194.44 seconds Scan Build WARNING 491.96 seconds Details ############################## Test: Scan Build - WARNING Desc: Run Scan Build with patches Output: ***************************************************************************** The bugs reported by the scan-build may or may not be caused by your patches. Please check the list and fix the bugs if they are caused by your patch. ***************************************************************************** src/gatt-database.c:1138:10: warning: Value stored to 'bits' during its initialization is never read uint8_t bits[] = { BT_GATT_CHRC_CLI_FEAT_ROBUST_CACHING, ^~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/gatt-database.c:3535:14: warning: Value stored to 'iface' during its initialization is never read const char *iface = g_dbus_proxy_get_interface(proxy); ^~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/gatt-database.c:3536:14: warning: Value stored to 'path' during its initialization is never read const char *path = g_dbus_proxy_get_path(proxy); ^~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 warnings generated. --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH BlueZ 1/2] gatt-api: Add error code ReadValue/WriteValue 2022-08-25 20:07 [PATCH BlueZ 1/2] gatt-api: Add error code ReadValue/WriteValue Luiz Augusto von Dentz 2022-08-25 20:07 ` [PATCH BlueZ 2/2] gatt: Parse error message Luiz Augusto von Dentz 2022-08-25 21:09 ` [BlueZ,1/2] gatt-api: Add error code ReadValue/WriteValue bluez.test.bot @ 2022-08-29 19:50 ` patchwork-bot+bluetooth 2 siblings, 0 replies; 4+ messages in thread From: patchwork-bot+bluetooth @ 2022-08-29 19:50 UTC (permalink / raw) To: Luiz Augusto von Dentz; +Cc: linux-bluetooth Hello: This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>: On Thu, 25 Aug 2022 13:07:57 -0700 you wrote: > From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> > > This allows application to return error codes in the range allowed by > the spec: > > 'GATT - Section 4.9.5: > > [...] Here is the summary with links: - [BlueZ,1/2] gatt-api: Add error code ReadValue/WriteValue https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ea903d120680 - [BlueZ,2/2] gatt: Parse error message https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6b8f9fbd5bb8 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-29 19:50 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-08-25 20:07 [PATCH BlueZ 1/2] gatt-api: Add error code ReadValue/WriteValue Luiz Augusto von Dentz 2022-08-25 20:07 ` [PATCH BlueZ 2/2] gatt: Parse error message Luiz Augusto von Dentz 2022-08-25 21:09 ` [BlueZ,1/2] gatt-api: Add error code ReadValue/WriteValue bluez.test.bot 2022-08-29 19:50 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox