[PATCH BlueZ 12/12] client/mgmt: align implementation cmd_io_cap with its documentation
From: Christian Eggers <ceggers@arri.de>
Date: 2026-02-25 16:20:33
Subsystem:
the rest · Maintainer:
Linus Torvalds
Documentation of io-cap in doc/bluetootctl-mgmt.rst states that the IO capability has to passed as string instead of an integer. Additionally improve error checking after calling strtol(). --- client/mgmt.c | 18 +++++++++++++++--- src/shared/mgmt.c | 20 ++++++++++++++++++++ src/shared/mgmt.h | 1 + 3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/client/mgmt.c b/client/mgmt.c
index 1d3a842afd55..430a96a9e4b7 100644
--- a/client/mgmt.c
+++ b/client/mgmt.c@@ -4226,14 +4226,25 @@ static void io_cap_rsp(uint8_t status, uint16_t len, const void *param, static void cmd_io_cap(int argc, char **argv) { struct mgmt_cp_set_io_capability cp; - uint8_t cap; + long cap; uint16_t index; index = mgmt_index; if (index == MGMT_INDEX_NONE) index = 0; - cap = strtol(argv[1], NULL, 0); + cap = mgmt_parse_io_capability(argv[1]); + if (cap == MGMT_IO_CAPABILITY_INVALID) { + char *endptr; + + errno = 0; + cap = strtol(argv[1], &endptr, 0); + if (errno || (cap < 0) || (cap > UINT8_MAX) || *endptr) { + bt_shell_printf("Invalid argument %s\n", argv[1]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + } + memset(&cp, 0, sizeof(cp)); cp.io_capability = cap;
@@ -6149,7 +6160,8 @@ static const struct bt_shell_menu mgmt_menu = { { "conn-info", "[-t type] <remote address>", cmd_conn_info, "Get connection information" }, { "io-cap", "<cap>", - cmd_io_cap, "Set IO Capability" }, + cmd_io_cap, "Set IO Capability", + mgmt_iocap_generator }, { "scan-params", "<interval> <window>", cmd_scan_params, "Set Scan Parameters" }, { "get-clock", "[address]",
diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 300abbae1c50..618bd349fa1c 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c@@ -1054,6 +1054,26 @@ uint16_t mgmt_get_mtu(struct mgmt *mgmt) return mgmt->mtu; } +char *mgmt_iocap_generator(const char *text, int state) +{ + static int index, len; + const char *arg; + + if (!state) { + index = 0; + len = strlen(text); + } + + while ((arg = iocap_arguments[index].name)) { + index++; + + if (!strncmp(arg, text, len)) + return strdup(arg); + } + + return NULL; +} + uint8_t mgmt_parse_io_capability(const char *capability) { const char *arg;
diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h
index a4c30075f7b7..58db09308c51 100644
--- a/src/shared/mgmt.h
+++ b/src/shared/mgmt.h@@ -98,4 +98,5 @@ bool mgmt_unregister_all(struct mgmt *mgmt); uint16_t mgmt_get_mtu(struct mgmt *mgmt); +char *mgmt_iocap_generator(const char *text, int state); uint8_t mgmt_parse_io_capability(const char *capability);
--
2.51.0