client/mgmt: fix compiler error
PATCH 1/12 client/mgmt: fix compiler error
client/mgmt.c: In function ‘str2bytearray’:client/mgmt.c:2385:23: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘long int’ [-Werror=sign-compare]
2385 | if (i >= *val_len) {
| ^~
--- client/mgmt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
client/mgmt.c +2 -2
@@ -2373,7 +2373,7 @@ static void cmd_set_flags(int argc, char **argv)static uint8_t *str2bytearray (char *arg,uint8_t *val,long *val_len) {char *entry; -unsigned int i; +long i;for (i =0 ; (entry =strsep (&arg," \t" )) !=NULL ; i++) {long v;
@@ -2389,7 +2389,7 @@ static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len) v =strtol (entry, &endptr,0 );if (!endptr || *endptr !='\0' || v >UINT8_MAX ) { -bt_shell_printf ("Invalid value at index %d\n" , i); +bt_shell_printf ("Invalid value at index %ld\n" , i);return NULL ; }
Signature · 1 line
2.51.0
PATCH 2/12 tools: btgatt-client/-server: replace ATT_CID with 'shared' BT_ATT_CID
Avoid multiple definitions of the same value.
--- tools/btgatt-client.c | 6 ++---- tools/btgatt-server.c | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-)
tools/btgatt-client.c +2 -4
@@ -35,8 +35,6 @@#include "src/shared/gatt-client.h" #include "src/shared/gatt-helpers.h" -#define ATT_CID 4 -#define PRLOG (...) \ printf(__VA_ARGS__); print_prompt();
@@ -1660,7 +1658,7 @@ static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,/* Set up source address */ memset (&srcaddr,0 ,sizeof (srcaddr)); srcaddr.l2_family =AF_BLUETOOTH ; - srcaddr.l2_cid =htobs (ATT_CID ); + srcaddr.l2_cid =htobs (BT_ATT_CID ); srcaddr.l2_bdaddr_type =0 ;bacpy (&srcaddr.l2_bdaddr, src);
@@ -1683,7 +1681,7 @@ static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,/* Set up destination address */ memset (&dstaddr,0 ,sizeof (dstaddr)); dstaddr.l2_family =AF_BLUETOOTH ; - dstaddr.l2_cid =htobs (ATT_CID ); + dstaddr.l2_cid =htobs (BT_ATT_CID ); dstaddr.l2_bdaddr_type = dst_type;bacpy (&dstaddr.l2_bdaddr, dst);
tools/btgatt-server.c +1 -3
@@ -42,8 +42,6 @@#define UUID_HEART_RATE_BODY 0x2a38#define UUID_HEART_RATE_CTRL 0x2a39 -#define ATT_CID 4 -#define PRLOG (...) \ do { \ printf(__VA_ARGS__); \
@@ -663,7 +661,7 @@ static int l2cap_le_att_listen_and_accept(bdaddr_t *src, int sec,/* Set up source address */ memset (&srcaddr,0 ,sizeof (srcaddr)); srcaddr.l2_family =AF_BLUETOOTH ; - srcaddr.l2_cid =htobs (ATT_CID ); + srcaddr.l2_cid =htobs (BT_ATT_CID ); srcaddr.l2_bdaddr_type = src_type;bacpy (&srcaddr.l2_bdaddr, src);
Signature · 1 line
2.51.0
PATCH 3/12 src: replace ATT_CID with 'shared' BT_ATT_CID
In reply to Christian EggersAvoid multiple definitions of the same value.
--- src/adapter.c | 2 +- src/device.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
src/adapter.c +1 -1
@@ -3768,7 +3768,7 @@ static void device_connect(struct btd_adapter *adapter, const bdaddr_t *dst,BT_IO_OPT_SOURCE_TYPE , adapter->bdaddr_type,BT_IO_OPT_DEST_BDADDR , dst,BT_IO_OPT_DEST_TYPE , dst_type, -BT_IO_OPT_CID ,ATT_CID , +BT_IO_OPT_CID ,BT_ATT_CID ,BT_IO_OPT_SEC_LEVEL ,BT_IO_SEC_LOW , BT_IO_OPT_INVALID);
src/device.c +3 -3
@@ -6453,7 +6453,7 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io) dev->att_mtu =MIN (mtu, btd_opts.gatt_mtu); attrib =g_attrib_new (io, - cid ==ATT_CID ?BT_ATT_DEFAULT_LE_MTU : dev->att_mtu, + cid ==BT_ATT_CID ?BT_ATT_DEFAULT_LE_MTU : dev->att_mtu, false);if (!attrib) {error ("Unable to create new GAttrib instance" );
@@ -6610,7 +6610,7 @@ int device_connect_le(struct btd_device *dev)btd_adapter_get_address_type (adapter),BT_IO_OPT_DEST_BDADDR , &dev->bdaddr,BT_IO_OPT_DEST_TYPE , dev->bdaddr_type, -BT_IO_OPT_CID ,ATT_CID , +BT_IO_OPT_CID ,BT_ATT_CID ,BT_IO_OPT_SEC_LEVEL , sec_level, BT_IO_OPT_INVALID);
@@ -6705,7 +6705,7 @@ static int device_browse_gatt(struct btd_device *device, DBusMessage *msg)btd_adapter_get_address_type (adapter),BT_IO_OPT_DEST_BDADDR , &device->bdaddr,BT_IO_OPT_DEST_TYPE , device->bdaddr_type, -BT_IO_OPT_CID ,ATT_CID , +BT_IO_OPT_CID ,BT_ATT_CID ,BT_IO_OPT_SEC_LEVEL ,BT_IO_SEC_LOW , BT_IO_OPT_INVALID);
Signature · 1 line
2.51.0
PATCH 4/12 peripheral: replace ATT_CID with shared BT_ATT_CID
In reply to Christian EggersAvoid multiple definitions of the same value.
--- peripheral/gatt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
peripheral/gatt.c +1 -3
@@ -30,8 +30,6 @@#include "src/shared/gatt-client.h" #include "peripheral/gatt.h" -#define ATT_CID 4 -#define UUID_GAP 0x1800struct gatt_conn {
@@ -243,7 +241,7 @@ void gatt_server_start(void)memset (&addr,0 ,sizeof (addr)); addr.l2_family =AF_BLUETOOTH ; - addr.l2_cid =htobs (ATT_CID ); + addr.l2_cid =htobs (BT_ATT_CID );memcpy (&addr.l2_bdaddr, static_addr,6 ); addr.l2_bdaddr_type =BDADDR_LE_RANDOM ;
Signature · 1 line
2.51.0
PATCH 5/12 attrib: replace ATT_CID with 'shared' BT_ATT_CID
In reply to Christian EggersAvoid multiple definitions of the same value.
--- attrib/att.h | 1 - attrib/gatttool.c | 3 ++- attrib/interactive.c | 3 ++- attrib/utils.c | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-)
attrib/att.h +0 -1
@@ -71,7 +71,6 @@#define ATT_DEFAULT_L2CAP_MTU 48#define ATT_DEFAULT_LE_MTU 23 -#define ATT_CID 4#define ATT_PSM 31/* Flags for Execute Write Request Operation */
attrib/gatttool.c +2 -1
@@ -25,6 +25,7 @@#include "bluetooth/sdp.h" #include "bluetooth/uuid.h" +#include "src/shared/att-types.h" #include "src/shared/util.h" #include "att.h" #include "btio/btio.h"
@@ -132,7 +133,7 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) mtu =ATT_DEFAULT_LE_MTU ; } -if (cid ==ATT_CID ) +if (cid ==BT_ATT_CID ) mtu =ATT_DEFAULT_LE_MTU ; attrib =g_attrib_new (io, mtu, false);
attrib/interactive.c +2 -1
@@ -30,6 +30,7 @@#include "bluetooth/sdp.h" #include "bluetooth/uuid.h" +#include "src/shared/att-types.h" #include "src/shared/util.h" #include "btio/btio.h" #include "att.h"
@@ -159,7 +160,7 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) mtu =ATT_DEFAULT_LE_MTU ; } -if (cid ==ATT_CID ) +if (cid ==BT_ATT_CID ) mtu =ATT_DEFAULT_LE_MTU ; attrib =g_attrib_new (iochannel, mtu, false);
attrib/utils.c +2 -1
@@ -22,6 +22,7 @@#include "bluetooth/sdp.h" #include "bluetooth/uuid.h" +#include "src/shared/att-types.h" #include "btio/btio.h" #include "att.h" #include "gattrib.h"
@@ -69,7 +70,7 @@ GIOChannel *gatt_connect(const char *src, const char *dst,BT_IO_OPT_SOURCE_TYPE ,BDADDR_LE_PUBLIC ,BT_IO_OPT_DEST_BDADDR , &dba,BT_IO_OPT_DEST_TYPE , dest_type, -BT_IO_OPT_CID ,ATT_CID , +BT_IO_OPT_CID ,BT_ATT_CID ,BT_IO_OPT_SEC_LEVEL , sec, BT_IO_OPT_INVALID); else
Signature · 1 line
2.51.0
PATCH 6/12 src: replace ATT_PSM with 'shared' BT_ATT_PSM
In reply to Christian EggersAvoid multiple definitions of the same value.
--- attrib/att.h | 2 -- src/device.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-)
attrib/att.h +0 -2
@@ -71,8 +71,6 @@#define ATT_DEFAULT_L2CAP_MTU 48#define ATT_DEFAULT_LE_MTU 23 -#define ATT_PSM 31 -/* Flags for Execute Write Request Operation */ #define ATT_CANCEL_ALL_PREP_WRITES 0x00#define ATT_WRITE_ALL_PREP_WRITES 0x01
src/device.c +1 -1
@@ -6097,7 +6097,7 @@ static void search_cb(sdp_list_t *recs, int err, gpointer user_data) primaries =device_services_from_record (device, req->profiles_added);if (primaries) -device_register_primaries (device, primaries,ATT_PSM ); +device_register_primaries (device, primaries,BT_ATT_PSM );/* * TODO: The btd_service instances for GATT services need to be
Signature · 1 line
2.51.0
PATCH 7/12 tools: btgatt-server: remove unused member 'fd'
In reply to Christian Eggers--- tools/btgatt-server.c | 2 -- 1 file changed, 2 deletions(-)
tools/btgatt-server.c +0 -2
@@ -66,7 +66,6 @@ static const char test_device_name[] = "Very Long Test Device Name For Testing "static bool verbose = false;struct server { -int fd;struct bt_att *att;struct gatt_db *db;struct bt_gatt_server *gatt;
@@ -570,7 +569,6 @@ static struct server *server_create(int fd, uint16_t mtu, bool hr_visible)memcpy (server->device_name, test_device_name, name_len); server->device_name[name_len] ='\0' ; - server->fd = fd; server->db =gatt_db_new ();if (!server->db) {fprintf (stderr,"Failed to create GATT database\n" );
Signature · 1 line
2.51.0
PATCH 8/12 l2test: add comment to -F <fcs> option
In reply to Christian EggersClarify that this option has affect for BR/EDR sockets only. Use defines instead of magic numbers.
--- lib/bluetooth/l2cap.h | 3 +++ tools/l2test.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-)
lib/bluetooth/l2cap.h +3 -0
@@ -187,6 +187,9 @@ typedef struct {#define L2CAP_MODE_LE_FLOWCTL 0x80#define L2CAP_MODE_ECRED 0x81 +#define L2CAP_FCS_NONE 0x00 +#define L2CAP_FCS_CRC16 0x01 +#define L2CAP_SERVTYPE_NOTRAFFIC 0x00#define L2CAP_SERVTYPE_BESTEFFORT 0x01#define L2CAP_SERVTYPE_GUARANTEED 0x02
tools/l2test.c +2 -2
@@ -72,7 +72,7 @@ static int imtu = 672;static int omtu =0 ;/* Default FCS option */ -static int fcs =0x01 ; +static int fcs =L2CAP_FCS_CRC16 ;/* Default Transmission Window */ static int txwin_size =63 ;
@@ -1349,7 +1349,7 @@ static void usage(void)"\t[-g milliseconds] delay before disconnecting (default = 0)\n" "\t[-X mode] l2cap mode (help for list, default = basic)\n" "\t[-a policy] chan policy (help for list, default = bredr)\n" -"\t[-F fcs] use CRC16 check (default = 1)\n" +"\t[-F fcs] use CRC16 check (default = 1, affects BR/EDR only)\n" "\t[-Q num] Max Transmit value (default = 3)\n" "\t[-Z size] Transmission Window size (default = 63)\n" "\t[-Y priority] socket priority\n"
Signature · 1 line
2.51.0
PATCH 9/12 l2test: add comment to -O <omtu> option
In reply to Christian EggersClarify that this option has affect for BR/EDR sockets only.
--- tools/l2test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/l2test.c +2 -1
@@ -1338,7 +1338,8 @@ static void usage(void)printf ("Options:\n" "\t[-b bytes] [-i device] [-P psm] [-J cid]\n" -"\t[-I imtu] [-O omtu]\n" +"\t[-I imtu]\n" +"\t[-O omtu] (affects BR/EDR sockets only)\n" "\t[-L seconds] enable SO_LINGER\n" "\t[-W seconds] enable deferred setup\n" "\t[-B filename] use data packets from file\n"
Signature · 1 line
2.51.0
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 09/12] l2test: add comment to -O <omtu> option
Hi Christian,
Quoted 11 lines · Christian Eggers
Clarify that this option has affect for BR/EDR sockets only.
--- tools/l2test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/l2test.c +0
-0
tools/l2test.c static void usage(void) · line 1342
Quoted 6 lines
tools/l2test.c +2
-1@@ -1338,7 +1338,8 @@ static void usage(void)printf ("Options:\n" "\t[-b bytes] [-i device] [-P psm] [-J cid]\n" - "\t[-I imtu] [-O omtu]\n" +"\t[-I imtu]\n" + "\t[-O omtu] (affects BR/EDR sockets only)\n"
Actually this is no longer the case since:
https://github.com/bluez/bluez/commit/290f9973c9069f293367284e95fd338a221ab90d
Quoted 7 lines
tools/l2test.c +0
-1"\t[-L seconds] enable SO_LINGER\n" "\t[-W seconds] enable deferred setup\n" "\t[-B filename] use data packets from file\n" --2.51.0
Signature · 1 line
Luiz Augusto von Dentz
PATCH 10/12 l2test: small improvements for deferred setup
In reply to Christian Eggers- don't pass arbitrary option values to the kernel (the kernel only checks for zero / non-zero)
- centralize authorization of new connections in listen()
- improve documentation of command line option
--- tools/l2test.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
tools/l2test.c +13 -19
@@ -658,7 +658,7 @@ static void do_listen(void (*handler)(int sk)) }/* Enable deferred setup */ - opt = defer_setup; + opt = !!defer_setup;if (opt &&setsockopt (sk,SOL_BLUETOOTH ,BT_DEFER_SETUP , &opt,sizeof (opt)) <0 ) {
@@ -768,6 +768,8 @@ static void do_listen(void (*handler)(int sk))/* Handle deferred setup */ if (defer_setup) { +int len; +syslog (LOG_INFO ,"Waiting for %d seconds" ,abs (defer_setup) -1 );sleep (abs (defer_setup) -1 );
@@ -776,6 +778,13 @@ static void do_listen(void (*handler)(int sk))close (nsk); goto error; } + + len =read (sk, buf, buffer_size); +if (len <0 ) +syslog (LOG_ERR ,"Initial read error: %s (%d)" , +strerror (errno), errno); +else +syslog (LOG_INFO ,"Initial bytes %d" , len); }handler (nsk);
@@ -798,15 +807,6 @@ static void dump_mode(int sk)if (data_size <0 ) data_size = imtu; -if (defer_setup) { - len =read (sk, buf, data_size); -if (len <0 ) -syslog (LOG_ERR ,"Initial read error: %s (%d)" , -strerror (errno), errno); -else -syslog (LOG_INFO ,"Initial bytes %d" , len); - } -syslog (LOG_INFO ,"Receiving ..." );while (1 ) {fd_set rset;
@@ -858,15 +858,6 @@ static void recv_mode(int sk)if (data_size <0 ) data_size = imtu; -if (defer_setup) { - len =read (sk, buf, data_size); -if (len <0 ) -syslog (LOG_ERR ,"Initial read error: %s (%d)" , -strerror (errno), errno); -else -syslog (LOG_INFO ,"Initial bytes %d" , len); - } -if (recv_delay)usleep (recv_delay);
@@ -1342,6 +1333,9 @@ static void usage(void)"\t[-O omtu] (affects BR/EDR sockets only)\n" "\t[-L seconds] enable SO_LINGER\n" "\t[-W seconds] enable deferred setup\n" +"\t 0: don't enable (default)\n" +"\t >0: authorize after <seconds>\n" +"\t <0: deny after abs(<seconds>)\n" "\t[-B filename] use data packets from file\n" "\t[-N num] send num frames (default = infinite)\n" "\t[-C num] send num frames before delay (default = 1)\n"
Signature · 1 line
2.51.0
PATCH 11/12 agent: move defines and parsing for I/O capability to shared/mgnt
In reply to Christian EggersAllow reusing in client/mgmt.c (next commit)
--- src/adapter.c | 6 +++--- src/agent.c | 24 ++++-------------------- src/agent.h | 7 ------- src/device.c | 7 ++++--- src/shared/mgmt.c | 32 ++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 10 ++++++++++ 6 files changed, 53 insertions(+), 33 deletions(-)
src/adapter.c +3 -3
@@ -9156,7 +9156,7 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)struct mgmt_cp_set_io_capability cp;if (!btd_opts.pairable) { -if (io_cap ==IO_CAPABILITY_INVALID ) { +if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) {if (adapter->current_settings &MGMT_SETTING_BONDABLE )set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x00 );
@@ -9165,8 +9165,8 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)if (!(adapter->current_settings &MGMT_SETTING_BONDABLE ))set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x01 ); - }else if (io_cap ==IO_CAPABILITY_INVALID ) - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + }else if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ;memset (&cp,0 ,sizeof (cp)); cp.io_capability = io_cap;
src/agent.c +4 -20
@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "agent.h" +#include "shared/mgmt.h" #include "shared/queue.h" #define REQUEST_TIMEOUT (60 * 1000)/* 60 seconds */
@@ -131,7 +132,7 @@ static void set_io_cap(struct btd_adapter *adapter, gpointer user_data)if (agent) io_cap = agent->capability;else - io_cap =IO_CAPABILITY_INVALID ; + io_cap =MGMT_IO_CAPABILITY_INVALID ;adapter_set_io_capability (adapter, io_cap); }
@@ -944,23 +945,6 @@ static void agent_destroy(gpointer data)agent_unref (agent); } -static uint8_t parse_io_capability (const char *capability) -{ -if (g_str_equal (capability,"" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -if (g_str_equal (capability,"DisplayOnly" )) -return IO_CAPABILITY_DISPLAYONLY ; -if (g_str_equal (capability,"DisplayYesNo" )) -return IO_CAPABILITY_DISPLAYYESNO ; -if (g_str_equal (capability,"KeyboardOnly" )) -return IO_CAPABILITY_KEYBOARDONLY ; -if (g_str_equal (capability,"NoInputNoOutput" )) -return IO_CAPABILITY_NOINPUTNOOUTPUT ; -if (g_str_equal (capability,"KeyboardDisplay" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -return IO_CAPABILITY_INVALID ; -} -static DBusMessage *register_agent (DBusConnection *conn,DBusMessage *msg,void *user_data) {
@@ -979,8 +963,8 @@ static DBusMessage *register_agent(DBusConnection *conn, DBUS_TYPE_INVALID) == FALSE)return btd_error_invalid_args (msg); - cap =parse_io_capability (capability); -if (cap ==IO_CAPABILITY_INVALID ) + cap =mgmt_parse_io_capability (capability); +if (cap ==MGMT_IO_CAPABILITY_INVALID )return btd_error_invalid_args (msg); agent =agent_create (sender, path, cap);
src/agent.h +0 -7
@@ -9,13 +9,6 @@* */ -#define IO_CAPABILITY_DISPLAYONLY 0x00 -#define IO_CAPABILITY_DISPLAYYESNO 0x01 -#define IO_CAPABILITY_KEYBOARDONLY 0x02 -#define IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 -#define IO_CAPABILITY_KEYBOARDDISPLAY 0x04 -#define IO_CAPABILITY_INVALID 0xFF -struct agent ; typedef void (*agent_cb) (struct agent *agent, DBusError *err,
src/device.c +4 -3
@@ -43,6 +43,7 @@#include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" #include "src/shared/ad.h" +#include "src/shared/mgmt.h" #include "src/shared/timeout.h" #include "btio/btio.h" #include "bluetooth/mgmt.h"
@@ -3375,7 +3376,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,if (agent) io_cap =agent_get_io_capability (agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; bonding =bonding_request_new (msg, device, bdaddr_type, agent);
@@ -6544,7 +6545,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)if (device->bonding->agent) io_cap =agent_get_io_capability (device->bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_create_bonding (device->adapter, &device->bdaddr, device->bdaddr_type, io_cap);
@@ -7452,7 +7453,7 @@ static gboolean device_bonding_retry(gpointer data)if (bonding->agent) io_cap =agent_get_io_capability (bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_bonding_attempt (adapter, &device->bdaddr, device->bdaddr_type, io_cap);
src/shared/mgmt.c +32 -0
@@ -81,6 +81,20 @@ struct mgmt_tlv_list {uint16_t size; }; +struct arg_table { +const char *name; +unsigned value; +}; + +static const struct arg_table iocap_arguments[] = { + {"DisplayOnly" ,MGMT_IO_CAPABILITY_DISPLAYONLY }, + {"DisplayYesNo" ,MGMT_IO_CAPABILITY_DISPLAYYESNO }, + {"KeyboardOnly" ,MGMT_IO_CAPABILITY_KEYBOARDONLY }, + {"NoInputNoOutput" ,MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT }, + {"KeyboardDisplay" ,MGMT_IO_CAPABILITY_KEYBOARDDISPLAY }, + {NULL ,0 } +}; +static void destroy_request (void *data) {struct mgmt_request *request = data;
@@ -1039,3 +1053,21 @@ uint16_t mgmt_get_mtu(struct mgmt *mgmt)return mgmt->mtu; } + +uint8_t mgmt_parse_io_capability (const char *capability) +{ +const char *arg; +int index =0 ; + +if (!strcmp (capability,"" )) +return MGMT_IO_CAPABILITY_KEYBOARDDISPLAY ; + +while ((arg = iocap_arguments[index].name)) { +if (!strncmp (arg, capability,strlen (capability))) +return iocap_arguments[index].value; + + index++; + } + +return MGMT_IO_CAPABILITY_INVALID ; +}
src/shared/mgmt.h +10 -0
@@ -13,6 +13,14 @@#define MGMT_VERSION (v, r) (((v) << 16) + (r)) +#define MGMT_IO_CAPABILITY_DISPLAYONLY 0x00 +#define MGMT_IO_CAPABILITY_DISPLAYYESNO 0x01 +#define MGMT_IO_CAPABILITY_KEYBOARDONLY 0x02 +#define MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 +#define MGMT_IO_CAPABILITY_KEYBOARDDISPLAY 0x04 +#define MGMT_IO_CAPABILITY_INVALID 0xFF + +typedef void (*mgmt_destroy_func_t )(void *user_data);struct mgmt ;
@@ -89,3 +97,5 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index);bool mgmt_unregister_all (struct mgmt *mgmt);uint16_t mgmt_get_mtu (struct mgmt *mgmt); + +uint8_t mgmt_parse_io_capability (const char *capability);
Signature · 1 line
2.51.0
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 11/12] agent: move defines and parsing for I/O capability to shared/mgnt
Hi Christian,
Quoted 7 lines · Christian Eggers
Allow reusing in
client/mgmt.c(next commit)--- src/adapter.c | 6 +++--- src/agent.c | 24 ++++-------------------- src/agent.h | 7 ------- src/device.c | 7 ++++---
Shared changed should be sent separately since its license (LGPL) is different than the daemon (GPL).
Quoted 193 lines
src/shared/mgmt.c | 32 ++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 10 ++++++++++ 6 files changed, 53 insertions(+), 33 deletions(-)src/adapter.c +3
-3@@ -9156,7 +9156,7 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)struct mgmt_cp_set_io_capability cp;if (!btd_opts.pairable) { -if (io_cap ==IO_CAPABILITY_INVALID ) { +if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) {if (adapter->current_settings &MGMT_SETTING_BONDABLE )set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x00 );@@ -9165,8 +9165,8 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)if (!(adapter->current_settings &MGMT_SETTING_BONDABLE ))set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x01 ); - }else if (io_cap ==IO_CAPABILITY_INVALID ) - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + }else if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ;memset (&cp,0 ,sizeof (cp)); cp.io_capability = io_cap;src/agent.c +4
-20@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "agent.h" +#include "shared/mgmt.h" #include "shared/queue.h" #define REQUEST_TIMEOUT (60 * 1000)/* 60 seconds */ @@ -131,7 +132,7 @@ static void set_io_cap(struct btd_adapter *adapter, gpointer user_data)if (agent) io_cap = agent->capability;else - io_cap =IO_CAPABILITY_INVALID ; + io_cap =MGMT_IO_CAPABILITY_INVALID ;adapter_set_io_capability (adapter, io_cap); }@@ -944,23 +945,6 @@ static void agent_destroy(gpointer data)agent_unref (agent); } -static uint8_t parse_io_capability (const char *capability) -{ -if (g_str_equal (capability,"" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -if (g_str_equal (capability,"DisplayOnly" )) -return IO_CAPABILITY_DISPLAYONLY ; -if (g_str_equal (capability,"DisplayYesNo" )) -return IO_CAPABILITY_DISPLAYYESNO ; -if (g_str_equal (capability,"KeyboardOnly" )) -return IO_CAPABILITY_KEYBOARDONLY ; -if (g_str_equal (capability,"NoInputNoOutput" )) -return IO_CAPABILITY_NOINPUTNOOUTPUT ; -if (g_str_equal (capability,"KeyboardDisplay" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -return IO_CAPABILITY_INVALID ; -} -static DBusMessage *register_agent (DBusConnection *conn,DBusMessage *msg,void *user_data) {@@ -979,8 +963,8 @@ static DBusMessage *register_agent(DBusConnection *conn, DBUS_TYPE_INVALID) == FALSE)return btd_error_invalid_args (msg); - cap =parse_io_capability (capability); -if (cap ==IO_CAPABILITY_INVALID ) + cap =mgmt_parse_io_capability (capability); +if (cap ==MGMT_IO_CAPABILITY_INVALID )return btd_error_invalid_args (msg); agent =agent_create (sender, path, cap);src/agent.h +0
-7@@ -9,13 +9,6 @@* */ -#define IO_CAPABILITY_DISPLAYONLY 0x00 -#define IO_CAPABILITY_DISPLAYYESNO 0x01 -#define IO_CAPABILITY_KEYBOARDONLY 0x02 -#define IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 -#define IO_CAPABILITY_KEYBOARDDISPLAY 0x04 -#define IO_CAPABILITY_INVALID 0xFF -struct agent ; typedef void (*agent_cb) (struct agent *agent, DBusError *err,src/device.c +4
-3@@ -43,6 +43,7 @@#include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" #include "src/shared/ad.h" +#include "src/shared/mgmt.h" #include "src/shared/timeout.h" #include "btio/btio.h" #include "bluetooth/mgmt.h" @@ -3375,7 +3376,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,if (agent) io_cap =agent_get_io_capability (agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; bonding =bonding_request_new (msg, device, bdaddr_type, agent);@@ -6544,7 +6545,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)if (device->bonding->agent) io_cap =agent_get_io_capability (device->bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_create_bonding (device->adapter, &device->bdaddr, device->bdaddr_type, io_cap);@@ -7452,7 +7453,7 @@ static gboolean device_bonding_retry(gpointer data)if (bonding->agent) io_cap =agent_get_io_capability (bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_bonding_attempt (adapter, &device->bdaddr, device->bdaddr_type, io_cap);src/shared/mgmt.c +32
-0@@ -81,6 +81,20 @@ struct mgmt_tlv_list {uint16_t size; }; +struct arg_table { +const char *name; +unsigned value; +}; + +static const struct arg_table iocap_arguments[] = { + {"DisplayOnly" ,MGMT_IO_CAPABILITY_DISPLAYONLY }, + {"DisplayYesNo" ,MGMT_IO_CAPABILITY_DISPLAYYESNO }, + {"KeyboardOnly" ,MGMT_IO_CAPABILITY_KEYBOARDONLY }, + {"NoInputNoOutput" ,MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT }, + {"KeyboardDisplay" ,MGMT_IO_CAPABILITY_KEYBOARDDISPLAY }, + {NULL ,0 } +}; +static void destroy_request (void *data) {struct mgmt_request *request = data;@@ -1039,3 +1053,21 @@ uint16_t mgmt_get_mtu(struct mgmt *mgmt)return mgmt->mtu; } + +uint8_t mgmt_parse_io_capability (const char *capability) +{ +const char *arg; +int index =0 ; + +if (!strcmp (capability,"" )) +return MGMT_IO_CAPABILITY_KEYBOARDDISPLAY ; + +while ((arg = iocap_arguments[index].name)) { +if (!strncmp (arg, capability,strlen (capability))) +return iocap_arguments[index].value; + + index++; + } + +return MGMT_IO_CAPABILITY_INVALID ; +}src/shared/mgmt.h +0
-0
src/shared/mgmt.h line 21
Quoted 9 lines
src/shared/mgmt.h +6
-0@@ -13,6 +13,14 @@#define MGMT_VERSION (v, r) (((v) << 16) + (r)) +#define MGMT_IO_CAPABILITY_DISPLAYONLY 0x00 +#define MGMT_IO_CAPABILITY_DISPLAYYESNO 0x01 +#define MGMT_IO_CAPABILITY_KEYBOARDONLY 0x02 +#define MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 +#define MGMT_IO_CAPABILITY_KEYBOARDDISPLAY 0x04 +#define MGMT_IO_CAPABILITY_INVALID 0xFF
Perhaps this should be an enum to ensure things like switch statements do check for unhandled values.
Quoted 15 lines
src/shared/mgmt.h +4
-1+ +typedef void (*mgmt_destroy_func_t )(void *user_data);struct mgmt ;@@ -89,3 +97,5 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index);bool mgmt_unregister_all (struct mgmt *mgmt);uint16_t mgmt_get_mtu (struct mgmt *mgmt); + +uint8_t mgmt_parse_io_capability (const char *capability); --2.51.0
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH BlueZ 11/12] agent: move defines and parsing for I/O capability to shared/mgnt
Hi Luiz,
Quoted 11 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 7 lines · Christian Eggers
Allow reusing in
client/mgmt.c(next commit)--- src/adapter.c | 6 +++--- src/agent.c | 24 ++++-------------------- src/agent.h | 7 ------- src/device.c | 7 ++++---
Quoted 2 lines
Shared changed should be sent separately since its license (LGPL) is different than the daemon (GPL).
done
Quoted 197 lines
Quoted 197 lines
src/shared/mgmt.c | 32 ++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 10 ++++++++++ 6 files changed, 53 insertions(+), 33 deletions(-)src/adapter.c +3
-3@@ -9156,7 +9156,7 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)struct mgmt_cp_set_io_capability cp;if (!btd_opts.pairable) { -if (io_cap ==IO_CAPABILITY_INVALID ) { +if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) {if (adapter->current_settings &MGMT_SETTING_BONDABLE )set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x00 );@@ -9165,8 +9165,8 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)if (!(adapter->current_settings &MGMT_SETTING_BONDABLE ))set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x01 ); - }else if (io_cap ==IO_CAPABILITY_INVALID ) - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + }else if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ;memset (&cp,0 ,sizeof (cp)); cp.io_capability = io_cap;src/agent.c +4
-20@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "agent.h" +#include "shared/mgmt.h" #include "shared/queue.h" #define REQUEST_TIMEOUT (60 * 1000)/* 60 seconds */ @@ -131,7 +132,7 @@ static void set_io_cap(struct btd_adapter *adapter, gpointer user_data)if (agent) io_cap = agent->capability;else - io_cap =IO_CAPABILITY_INVALID ; + io_cap =MGMT_IO_CAPABILITY_INVALID ;adapter_set_io_capability (adapter, io_cap); }@@ -944,23 +945,6 @@ static void agent_destroy(gpointer data)agent_unref (agent); } -static uint8_t parse_io_capability (const char *capability) -{ -if (g_str_equal (capability,"" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -if (g_str_equal (capability,"DisplayOnly" )) -return IO_CAPABILITY_DISPLAYONLY ; -if (g_str_equal (capability,"DisplayYesNo" )) -return IO_CAPABILITY_DISPLAYYESNO ; -if (g_str_equal (capability,"KeyboardOnly" )) -return IO_CAPABILITY_KEYBOARDONLY ; -if (g_str_equal (capability,"NoInputNoOutput" )) -return IO_CAPABILITY_NOINPUTNOOUTPUT ; -if (g_str_equal (capability,"KeyboardDisplay" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -return IO_CAPABILITY_INVALID ; -} -static DBusMessage *register_agent (DBusConnection *conn,DBusMessage *msg,void *user_data) {@@ -979,8 +963,8 @@ static DBusMessage *register_agent(DBusConnection *conn, DBUS_TYPE_INVALID) == FALSE)return btd_error_invalid_args (msg); - cap =parse_io_capability (capability); -if (cap ==IO_CAPABILITY_INVALID ) + cap =mgmt_parse_io_capability (capability); +if (cap ==MGMT_IO_CAPABILITY_INVALID )return btd_error_invalid_args (msg); agent =agent_create (sender, path, cap);src/agent.h +0
-7@@ -9,13 +9,6 @@* */ -#define IO_CAPABILITY_DISPLAYONLY 0x00 -#define IO_CAPABILITY_DISPLAYYESNO 0x01 -#define IO_CAPABILITY_KEYBOARDONLY 0x02 -#define IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 -#define IO_CAPABILITY_KEYBOARDDISPLAY 0x04 -#define IO_CAPABILITY_INVALID 0xFF -struct agent ; typedef void (*agent_cb) (struct agent *agent, DBusError *err,src/device.c +4
-3@@ -43,6 +43,7 @@#include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" #include "src/shared/ad.h" +#include "src/shared/mgmt.h" #include "src/shared/timeout.h" #include "btio/btio.h" #include "bluetooth/mgmt.h" @@ -3375,7 +3376,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,if (agent) io_cap =agent_get_io_capability (agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; bonding =bonding_request_new (msg, device, bdaddr_type, agent);@@ -6544,7 +6545,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)if (device->bonding->agent) io_cap =agent_get_io_capability (device->bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_create_bonding (device->adapter, &device->bdaddr, device->bdaddr_type, io_cap);@@ -7452,7 +7453,7 @@ static gboolean device_bonding_retry(gpointer data)if (bonding->agent) io_cap =agent_get_io_capability (bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_bonding_attempt (adapter, &device->bdaddr, device->bdaddr_type, io_cap);src/shared/mgmt.c +32
-0@@ -81,6 +81,20 @@ struct mgmt_tlv_list {uint16_t size; }; +struct arg_table { +const char *name; +unsigned value; +}; + +static const struct arg_table iocap_arguments[] = { + {"DisplayOnly" ,MGMT_IO_CAPABILITY_DISPLAYONLY }, + {"DisplayYesNo" ,MGMT_IO_CAPABILITY_DISPLAYYESNO }, + {"KeyboardOnly" ,MGMT_IO_CAPABILITY_KEYBOARDONLY }, + {"NoInputNoOutput" ,MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT }, + {"KeyboardDisplay" ,MGMT_IO_CAPABILITY_KEYBOARDDISPLAY }, + {NULL ,0 } +}; +static void destroy_request (void *data) {struct mgmt_request *request = data;@@ -1039,3 +1053,21 @@ uint16_t mgmt_get_mtu(struct mgmt *mgmt)return mgmt->mtu; } + +uint8_t mgmt_parse_io_capability (const char *capability) +{ +const char *arg; +int index =0 ; + +if (!strcmp (capability,"" )) +return MGMT_IO_CAPABILITY_KEYBOARDDISPLAY ; + +while ((arg = iocap_arguments[index].name)) { +if (!strncmp (arg, capability,strlen (capability))) +return iocap_arguments[index].value; + + index++; + } + +return MGMT_IO_CAPABILITY_INVALID ; +}src/shared/mgmt.h +0
-0@@ -13,6 +13,14 @@#define MGMT_VERSION (v, r) (((v) << 16) + (r))
Quoted 9 lines
src/shared/mgmt.h line 21
Quoted 6 lines
src/shared/mgmt.h +6
-0+#define MGMT_IO_CAPABILITY_DISPLAYONLY 0x00 +#define MGMT_IO_CAPABILITY_DISPLAYYESNO 0x01 +#define MGMT_IO_CAPABILITY_KEYBOARDONLY 0x02 +#define MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 +#define MGMT_IO_CAPABILITY_KEYBOARDDISPLAY 0x04 +#define MGMT_IO_CAPABILITY_INVALID 0xFFPerhaps this should be an enum to ensure things like switch statements do check for unhandled values.
also done. But now using an enum in src/adapter.h requires also including "src/shared/mgmt.h" in every file where src/adapter.h is used. I've made all these changes, but maybe we should really think about include guards.
Shall I resubmit the whole series or do you want to pick the fine commits first?
regards,
Christian
Quoted 19 lines
Quoted 16 lines
src/shared/mgmt.h +4
-1+ +typedef void (*mgmt_destroy_func_t )(void *user_data);struct mgmt ;@@ -89,3 +97,5 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index);bool mgmt_unregister_all (struct mgmt *mgmt);uint16_t mgmt_get_mtu (struct mgmt *mgmt); + +uint8_t mgmt_parse_io_capability (const char *capability); --2.51.0
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 11/12] agent: move defines and parsing for I/O capability to shared/mgnt
Hi Christian,
Quoted 227 lines · Christian Eggers
Hi Luiz,
Quoted 11 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 7 lines · Christian Eggers
Allow reusing in
client/mgmt.c(next commit)--- src/adapter.c | 6 +++--- src/agent.c | 24 ++++-------------------- src/agent.h | 7 ------- src/device.c | 7 ++++---Quoted 2 lines
Shared changed should be sent separately since its license (LGPL) is different than the daemon (GPL).
done
Quoted 197 lines
Quoted 197 lines
src/shared/mgmt.c | 32 ++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 10 ++++++++++ 6 files changed, 53 insertions(+), 33 deletions(-)src/adapter.c +3
-3@@ -9156,7 +9156,7 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)struct mgmt_cp_set_io_capability cp;if (!btd_opts.pairable) { -if (io_cap ==IO_CAPABILITY_INVALID ) { +if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) {if (adapter->current_settings &MGMT_SETTING_BONDABLE )set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x00 );@@ -9165,8 +9165,8 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)if (!(adapter->current_settings &MGMT_SETTING_BONDABLE ))set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x01 ); - }else if (io_cap ==IO_CAPABILITY_INVALID ) - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + }else if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ;memset (&cp,0 ,sizeof (cp)); cp.io_capability = io_cap;src/agent.c +4
-20@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "agent.h" +#include "shared/mgmt.h" #include "shared/queue.h" #define REQUEST_TIMEOUT (60 * 1000)/* 60 seconds */ @@ -131,7 +132,7 @@ static void set_io_cap(struct btd_adapter *adapter, gpointer user_data)if (agent) io_cap = agent->capability;else - io_cap =IO_CAPABILITY_INVALID ; + io_cap =MGMT_IO_CAPABILITY_INVALID ;adapter_set_io_capability (adapter, io_cap); }@@ -944,23 +945,6 @@ static void agent_destroy(gpointer data)agent_unref (agent); } -static uint8_t parse_io_capability (const char *capability) -{ -if (g_str_equal (capability,"" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -if (g_str_equal (capability,"DisplayOnly" )) -return IO_CAPABILITY_DISPLAYONLY ; -if (g_str_equal (capability,"DisplayYesNo" )) -return IO_CAPABILITY_DISPLAYYESNO ; -if (g_str_equal (capability,"KeyboardOnly" )) -return IO_CAPABILITY_KEYBOARDONLY ; -if (g_str_equal (capability,"NoInputNoOutput" )) -return IO_CAPABILITY_NOINPUTNOOUTPUT ; -if (g_str_equal (capability,"KeyboardDisplay" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -return IO_CAPABILITY_INVALID ; -} -static DBusMessage *register_agent (DBusConnection *conn,DBusMessage *msg,void *user_data) {@@ -979,8 +963,8 @@ static DBusMessage *register_agent(DBusConnection *conn, DBUS_TYPE_INVALID) == FALSE)return btd_error_invalid_args (msg); - cap =parse_io_capability (capability); -if (cap ==IO_CAPABILITY_INVALID ) + cap =mgmt_parse_io_capability (capability); +if (cap ==MGMT_IO_CAPABILITY_INVALID )return btd_error_invalid_args (msg); agent =agent_create (sender, path, cap);src/agent.h +0
-7@@ -9,13 +9,6 @@* */ -#define IO_CAPABILITY_DISPLAYONLY 0x00 -#define IO_CAPABILITY_DISPLAYYESNO 0x01 -#define IO_CAPABILITY_KEYBOARDONLY 0x02 -#define IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 -#define IO_CAPABILITY_KEYBOARDDISPLAY 0x04 -#define IO_CAPABILITY_INVALID 0xFF -struct agent ; typedef void (*agent_cb) (struct agent *agent, DBusError *err,src/device.c +4
-3@@ -43,6 +43,7 @@#include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" #include "src/shared/ad.h" +#include "src/shared/mgmt.h" #include "src/shared/timeout.h" #include "btio/btio.h" #include "bluetooth/mgmt.h" @@ -3375,7 +3376,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,if (agent) io_cap =agent_get_io_capability (agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; bonding =bonding_request_new (msg, device, bdaddr_type, agent);@@ -6544,7 +6545,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)if (device->bonding->agent) io_cap =agent_get_io_capability (device->bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_create_bonding (device->adapter, &device->bdaddr, device->bdaddr_type, io_cap);@@ -7452,7 +7453,7 @@ static gboolean device_bonding_retry(gpointer data)if (bonding->agent) io_cap =agent_get_io_capability (bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_bonding_attempt (adapter, &device->bdaddr, device->bdaddr_type, io_cap);src/shared/mgmt.c +32
-0@@ -81,6 +81,20 @@ struct mgmt_tlv_list {uint16_t size; }; +struct arg_table { +const char *name; +unsigned value; +}; + +static const struct arg_table iocap_arguments[] = { + {"DisplayOnly" ,MGMT_IO_CAPABILITY_DISPLAYONLY }, + {"DisplayYesNo" ,MGMT_IO_CAPABILITY_DISPLAYYESNO }, + {"KeyboardOnly" ,MGMT_IO_CAPABILITY_KEYBOARDONLY }, + {"NoInputNoOutput" ,MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT }, + {"KeyboardDisplay" ,MGMT_IO_CAPABILITY_KEYBOARDDISPLAY }, + {NULL ,0 } +}; +static void destroy_request (void *data) {struct mgmt_request *request = data;@@ -1039,3 +1053,21 @@ uint16_t mgmt_get_mtu(struct mgmt *mgmt)return mgmt->mtu; } + +uint8_t mgmt_parse_io_capability (const char *capability) +{ +const char *arg; +int index =0 ; + +if (!strcmp (capability,"" )) +return MGMT_IO_CAPABILITY_KEYBOARDDISPLAY ; + +while ((arg = iocap_arguments[index].name)) { +if (!strncmp (arg, capability,strlen (capability))) +return iocap_arguments[index].value; + + index++; + } + +return MGMT_IO_CAPABILITY_INVALID ; +}src/shared/mgmt.h +0
-0@@ -13,6 +13,14 @@#define MGMT_VERSION (v, r) (((v) << 16) + (r))Quoted 9 lines
src/shared/mgmt.h line 21
Quoted 6 lines
src/shared/mgmt.h +6
-0+#define MGMT_IO_CAPABILITY_DISPLAYONLY 0x00 +#define MGMT_IO_CAPABILITY_DISPLAYYESNO 0x01 +#define MGMT_IO_CAPABILITY_KEYBOARDONLY 0x02 +#define MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 +#define MGMT_IO_CAPABILITY_KEYBOARDDISPLAY 0x04 +#define MGMT_IO_CAPABILITY_INVALID 0xFFPerhaps this should be an enum to ensure things like switch statements do check for unhandled values.
Quoted 3 lines
also done. But now using an enum in
src/adapter.hrequires also including "src/shared/mgmt.h" in every file wheresrc/adapter.his used. I've made all these changes, but maybe we should really think about include guards.
Not following why would adapter.h requires it? Is adapter.h returning the enum?
Quoted 2 lines
Shall I resubmit the whole series or do you want to pick the fine commits first?
Ive already applied the changes that I didn't have any comments, so please rebase and send as a new set.
Quoted 26 lines
regards,
ChristianQuoted 19 lines
Quoted 16 lines
src/shared/mgmt.h +4
-1+ +typedef void (*mgmt_destroy_func_t )(void *user_data);struct mgmt ;@@ -89,3 +97,5 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index);bool mgmt_unregister_all (struct mgmt *mgmt);uint16_t mgmt_get_mtu (struct mgmt *mgmt); + +uint8_t mgmt_parse_io_capability (const char *capability); --2.51.0
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH BlueZ 11/12] agent: move defines and parsing for I/O capability to shared/mgnt
Hi Luiz,
Quoted 230 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 227 lines · Christian Eggers
Hi Luiz,
Quoted 11 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 7 lines · Christian Eggers
Allow reusing in
client/mgmt.c(next commit)--- src/adapter.c | 6 +++--- src/agent.c | 24 ++++-------------------- src/agent.h | 7 ------- src/device.c | 7 ++++---Quoted 2 lines
Shared changed should be sent separately since its license (LGPL) is different than the daemon (GPL).
done
Quoted 206 lines
Quoted 194 lines
src/shared/mgmt.c | 32 ++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 10 ++++++++++ 6 files changed, 53 insertions(+), 33 deletions(-)src/adapter.c +3
-3@@ -9156,7 +9156,7 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)struct mgmt_cp_set_io_capability cp;if (!btd_opts.pairable) { -if (io_cap ==IO_CAPABILITY_INVALID ) { +if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) {if (adapter->current_settings &MGMT_SETTING_BONDABLE )set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x00 );@@ -9165,8 +9165,8 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)if (!(adapter->current_settings &MGMT_SETTING_BONDABLE ))set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x01 ); - }else if (io_cap ==IO_CAPABILITY_INVALID ) - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + }else if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ;memset (&cp,0 ,sizeof (cp)); cp.io_capability = io_cap;src/agent.c +4
-20@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "agent.h" +#include "shared/mgmt.h" #include "shared/queue.h" #define REQUEST_TIMEOUT (60 * 1000)/* 60 seconds */ @@ -131,7 +132,7 @@ static void set_io_cap(struct btd_adapter *adapter, gpointer user_data)if (agent) io_cap = agent->capability;else - io_cap =IO_CAPABILITY_INVALID ; + io_cap =MGMT_IO_CAPABILITY_INVALID ;adapter_set_io_capability (adapter, io_cap); }@@ -944,23 +945,6 @@ static void agent_destroy(gpointer data)agent_unref (agent); } -static uint8_t parse_io_capability (const char *capability) -{ -if (g_str_equal (capability,"" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -if (g_str_equal (capability,"DisplayOnly" )) -return IO_CAPABILITY_DISPLAYONLY ; -if (g_str_equal (capability,"DisplayYesNo" )) -return IO_CAPABILITY_DISPLAYYESNO ; -if (g_str_equal (capability,"KeyboardOnly" )) -return IO_CAPABILITY_KEYBOARDONLY ; -if (g_str_equal (capability,"NoInputNoOutput" )) -return IO_CAPABILITY_NOINPUTNOOUTPUT ; -if (g_str_equal (capability,"KeyboardDisplay" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -return IO_CAPABILITY_INVALID ; -} -static DBusMessage *register_agent (DBusConnection *conn,DBusMessage *msg,void *user_data) {@@ -979,8 +963,8 @@ static DBusMessage *register_agent(DBusConnection *conn, DBUS_TYPE_INVALID) == FALSE)return btd_error_invalid_args (msg); - cap =parse_io_capability (capability); -if (cap ==IO_CAPABILITY_INVALID ) + cap =mgmt_parse_io_capability (capability); +if (cap ==MGMT_IO_CAPABILITY_INVALID )return btd_error_invalid_args (msg); agent =agent_create (sender, path, cap);src/agent.h +0
-7@@ -9,13 +9,6 @@* */ -#define IO_CAPABILITY_DISPLAYONLY 0x00 -#define IO_CAPABILITY_DISPLAYYESNO 0x01 -#define IO_CAPABILITY_KEYBOARDONLY 0x02 -#define IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 -#define IO_CAPABILITY_KEYBOARDDISPLAY 0x04 -#define IO_CAPABILITY_INVALID 0xFF -struct agent ; typedef void (*agent_cb) (struct agent *agent, DBusError *err,src/device.c +4
-3@@ -43,6 +43,7 @@#include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" #include "src/shared/ad.h" +#include "src/shared/mgmt.h" #include "src/shared/timeout.h" #include "btio/btio.h" #include "bluetooth/mgmt.h" @@ -3375,7 +3376,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,if (agent) io_cap =agent_get_io_capability (agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; bonding =bonding_request_new (msg, device, bdaddr_type, agent);@@ -6544,7 +6545,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)if (device->bonding->agent) io_cap =agent_get_io_capability (device->bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_create_bonding (device->adapter, &device->bdaddr, device->bdaddr_type, io_cap);@@ -7452,7 +7453,7 @@ static gboolean device_bonding_retry(gpointer data)if (bonding->agent) io_cap =agent_get_io_capability (bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_bonding_attempt (adapter, &device->bdaddr, device->bdaddr_type, io_cap);src/shared/mgmt.c +32
-0@@ -81,6 +81,20 @@ struct mgmt_tlv_list {uint16_t size; }; +struct arg_table { +const char *name; +unsigned value; +}; + +static const struct arg_table iocap_arguments[] = { + {"DisplayOnly" ,MGMT_IO_CAPABILITY_DISPLAYONLY }, + {"DisplayYesNo" ,MGMT_IO_CAPABILITY_DISPLAYYESNO }, + {"KeyboardOnly" ,MGMT_IO_CAPABILITY_KEYBOARDONLY }, + {"NoInputNoOutput" ,MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT }, + {"KeyboardDisplay" ,MGMT_IO_CAPABILITY_KEYBOARDDISPLAY }, + {NULL ,0 } +}; +static void destroy_request (void *data) {struct mgmt_request *request = data;@@ -1039,3 +1053,21 @@ uint16_t mgmt_get_mtu(struct mgmt *mgmt)return mgmt->mtu; } + +uint8_t mgmt_parse_io_capability (const char *capability) +{ +const char *arg; +int index =0 ; + +if (!strcmp (capability,"" )) +return MGMT_IO_CAPABILITY_KEYBOARDDISPLAY ; + +while ((arg = iocap_arguments[index].name)) { +if (!strncmp (arg, capability,strlen (capability))) +return iocap_arguments[index].value; + + index++; + } + +return MGMT_IO_CAPABILITY_INVALID ; +}src/shared/mgmt.h +0
-0src/shared/mgmt.h line 21
Quoted 9 lines
src/shared/mgmt.h +6
-0@@ -13,6 +13,14 @@#define MGMT_VERSION (v, r) (((v) << 16) + (r)) +#define MGMT_IO_CAPABILITY_DISPLAYONLY 0x00 +#define MGMT_IO_CAPABILITY_DISPLAYYESNO 0x01 +#define MGMT_IO_CAPABILITY_KEYBOARDONLY 0x02 +#define MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 +#define MGMT_IO_CAPABILITY_KEYBOARDDISPLAY 0x04 +#define MGMT_IO_CAPABILITY_INVALID 0xFFPerhaps this should be an enum to ensure things like switch statements do check for unhandled values.
Quoted 5 lines
Quoted 3 lines
also done. But now using an enum in
src/adapter.hrequires also including "src/shared/mgmt.h" in every file wheresrc/adapter.his used. I've made all these changes, but maybe we should really think about include guards.Not following why would
adapter.hrequires it? Isadapter.hreturning the enum?
src/adapter.h +6 -3
@@ -207,15 +207,18 @@ int btd_adapter_passkey_reply(struct btd_adapter *adapter, uint32_t passkey);int adapter_create_bonding (struct btd_adapter *adapter,const bdaddr_t *bdaddr, -uint8_t addr_type,uint8_t io_cap); +uint8_t addr_type, +enum mgmt_io_capability io_cap);int adapter_bonding_attempt (struct btd_adapter *adapter,const bdaddr_t *bdaddr, -uint8_t addr_type,uint8_t io_cap); +uint8_t addr_type, +enum mgmt_io_capability io_cap);int adapter_cancel_bonding (struct btd_adapter *adapter,const bdaddr_t *bdaddr,uint8_t addr_type); -int adapter_set_io_capability (struct btd_adapter *adapter,uint8_t io_cap); +int adapter_set_io_capability (struct btd_adapter *adapter, +enum mgmt_io_capability io_cap);int btd_adapter_read_local_oob_data (struct btd_adapter *adapter);
Compiler output:
In file included from plugins/autopair.c:28:./src/adapter.h:211:54: warning: ‘enum mgmt_io_capability’ declared inside parameter list will not be visible outside of this definition or declaration
211 | enum mgmt_io_capability io_cap);
| ^~~~~~~~~~~~~~~~~~
./src/adapter.h:215:54: warning: ‘enum mgmt_io_capability’ declared inside parameter list will not be visible outside of this definition or declaration
215 | enum mgmt_io_capability io_cap);
| ^~~~~~~~~~~~~~~~~~
./src/adapter.h:221:54: warning: ‘enum mgmt_io_capability’ declared inside parameter list will not be visible outside of this definition or declaration
221 | enum mgmt_io_capability io_cap);
| ^~~~~~~~~~~~~~~~~~So, enum mgmt_io_capability is not used as a return value, but also using it as function argument requires prior declaration.
AFAIK, forward declaration of C-style enum is not possible. So if enum mgmt_io_capability is declared in shared/mgmt.h, this header must be included prior src/adapter.h
Currently, src/adapter.h is included by 56 files. In nearly all of them, I had to add inclusion of src/shared/mgmt.h.
regards,
Christian
Quoted 36 lines
Quoted 3 lines
Shall I resubmit the whole series or do you want to pick the fine commits first?
Ive already applied the changes that I didn't have any comments, so please rebase and send as a new set.
Quoted 26 lines
regards,
ChristianQuoted 19 lines
Quoted 16 lines
src/shared/mgmt.h +4
-1+ +typedef void (*mgmt_destroy_func_t )(void *user_data);struct mgmt ;@@ -89,3 +97,5 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index);bool mgmt_unregister_all (struct mgmt *mgmt);uint16_t mgmt_get_mtu (struct mgmt *mgmt); + +uint8_t mgmt_parse_io_capability (const char *capability); --2.51.0
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 11/12] agent: move defines and parsing for I/O capability to shared/mgnt
Hi Christian,
Quoted 253 lines · Christian Eggers
Hi Luiz,
Quoted 235 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 227 lines · Christian Eggers
Hi Luiz,
Quoted 11 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 7 lines · Christian Eggers
Allow reusing in
client/mgmt.c(next commit)--- src/adapter.c | 6 +++--- src/agent.c | 24 ++++-------------------- src/agent.h | 7 ------- src/device.c | 7 ++++---Quoted 2 lines
Shared changed should be sent separately since its license (LGPL) is different than the daemon (GPL).
done
Quoted 197 lines
Quoted 197 lines
src/shared/mgmt.c | 32 ++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 10 ++++++++++ 6 files changed, 53 insertions(+), 33 deletions(-)src/adapter.c +3
-3@@ -9156,7 +9156,7 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)struct mgmt_cp_set_io_capability cp;if (!btd_opts.pairable) { -if (io_cap ==IO_CAPABILITY_INVALID ) { +if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) {if (adapter->current_settings &MGMT_SETTING_BONDABLE )set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x00 );@@ -9165,8 +9165,8 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)if (!(adapter->current_settings &MGMT_SETTING_BONDABLE ))set_mode (adapter,MGMT_OP_SET_BONDABLE ,0x01 ); - }else if (io_cap ==IO_CAPABILITY_INVALID ) - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + }else if (io_cap ==MGMT_IO_CAPABILITY_INVALID ) + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ;memset (&cp,0 ,sizeof (cp)); cp.io_capability = io_cap;src/agent.c +4
-20@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "agent.h" +#include "shared/mgmt.h" #include "shared/queue.h" #define REQUEST_TIMEOUT (60 * 1000)/* 60 seconds */ @@ -131,7 +132,7 @@ static void set_io_cap(struct btd_adapter *adapter, gpointer user_data)if (agent) io_cap = agent->capability;else - io_cap =IO_CAPABILITY_INVALID ; + io_cap =MGMT_IO_CAPABILITY_INVALID ;adapter_set_io_capability (adapter, io_cap); }@@ -944,23 +945,6 @@ static void agent_destroy(gpointer data)agent_unref (agent); } -static uint8_t parse_io_capability (const char *capability) -{ -if (g_str_equal (capability,"" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -if (g_str_equal (capability,"DisplayOnly" )) -return IO_CAPABILITY_DISPLAYONLY ; -if (g_str_equal (capability,"DisplayYesNo" )) -return IO_CAPABILITY_DISPLAYYESNO ; -if (g_str_equal (capability,"KeyboardOnly" )) -return IO_CAPABILITY_KEYBOARDONLY ; -if (g_str_equal (capability,"NoInputNoOutput" )) -return IO_CAPABILITY_NOINPUTNOOUTPUT ; -if (g_str_equal (capability,"KeyboardDisplay" )) -return IO_CAPABILITY_KEYBOARDDISPLAY ; -return IO_CAPABILITY_INVALID ; -} -static DBusMessage *register_agent (DBusConnection *conn,DBusMessage *msg,void *user_data) {@@ -979,8 +963,8 @@ static DBusMessage *register_agent(DBusConnection *conn, DBUS_TYPE_INVALID) == FALSE)return btd_error_invalid_args (msg); - cap =parse_io_capability (capability); -if (cap ==IO_CAPABILITY_INVALID ) + cap =mgmt_parse_io_capability (capability); +if (cap ==MGMT_IO_CAPABILITY_INVALID )return btd_error_invalid_args (msg); agent =agent_create (sender, path, cap);src/agent.h +0
-7@@ -9,13 +9,6 @@* */ -#define IO_CAPABILITY_DISPLAYONLY 0x00 -#define IO_CAPABILITY_DISPLAYYESNO 0x01 -#define IO_CAPABILITY_KEYBOARDONLY 0x02 -#define IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 -#define IO_CAPABILITY_KEYBOARDDISPLAY 0x04 -#define IO_CAPABILITY_INVALID 0xFF -struct agent ; typedef void (*agent_cb) (struct agent *agent, DBusError *err,src/device.c +4
-3@@ -43,6 +43,7 @@#include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" #include "src/shared/ad.h" +#include "src/shared/mgmt.h" #include "src/shared/timeout.h" #include "btio/btio.h" #include "bluetooth/mgmt.h" @@ -3375,7 +3376,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,if (agent) io_cap =agent_get_io_capability (agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; bonding =bonding_request_new (msg, device, bdaddr_type, agent);@@ -6544,7 +6545,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)if (device->bonding->agent) io_cap =agent_get_io_capability (device->bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_create_bonding (device->adapter, &device->bdaddr, device->bdaddr_type, io_cap);@@ -7452,7 +7453,7 @@ static gboolean device_bonding_retry(gpointer data)if (bonding->agent) io_cap =agent_get_io_capability (bonding->agent);else - io_cap =IO_CAPABILITY_NOINPUTNOOUTPUT ; + io_cap =MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT ; err =adapter_bonding_attempt (adapter, &device->bdaddr, device->bdaddr_type, io_cap);src/shared/mgmt.c +32
-0@@ -81,6 +81,20 @@ struct mgmt_tlv_list {uint16_t size; }; +struct arg_table { +const char *name; +unsigned value; +}; + +static const struct arg_table iocap_arguments[] = { + {"DisplayOnly" ,MGMT_IO_CAPABILITY_DISPLAYONLY }, + {"DisplayYesNo" ,MGMT_IO_CAPABILITY_DISPLAYYESNO }, + {"KeyboardOnly" ,MGMT_IO_CAPABILITY_KEYBOARDONLY }, + {"NoInputNoOutput" ,MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT }, + {"KeyboardDisplay" ,MGMT_IO_CAPABILITY_KEYBOARDDISPLAY }, + {NULL ,0 } +}; +static void destroy_request (void *data) {struct mgmt_request *request = data;@@ -1039,3 +1053,21 @@ uint16_t mgmt_get_mtu(struct mgmt *mgmt)return mgmt->mtu; } + +uint8_t mgmt_parse_io_capability (const char *capability) +{ +const char *arg; +int index =0 ; + +if (!strcmp (capability,"" )) +return MGMT_IO_CAPABILITY_KEYBOARDDISPLAY ; + +while ((arg = iocap_arguments[index].name)) { +if (!strncmp (arg, capability,strlen (capability))) +return iocap_arguments[index].value; + + index++; + } + +return MGMT_IO_CAPABILITY_INVALID ; +}src/shared/mgmt.h +0
-0@@ -13,6 +13,14 @@#define MGMT_VERSION (v, r) (((v) << 16) + (r))Quoted 9 lines
src/shared/mgmt.h line 21
Quoted 6 lines
src/shared/mgmt.h +6
-0+#define MGMT_IO_CAPABILITY_DISPLAYONLY 0x00 +#define MGMT_IO_CAPABILITY_DISPLAYYESNO 0x01 +#define MGMT_IO_CAPABILITY_KEYBOARDONLY 0x02 +#define MGMT_IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 +#define MGMT_IO_CAPABILITY_KEYBOARDDISPLAY 0x04 +#define MGMT_IO_CAPABILITY_INVALID 0xFFPerhaps this should be an enum to ensure things like switch statements do check for unhandled values.
Quoted 3 lines
also done. But now using an enum in
src/adapter.hrequires also including "src/shared/mgmt.h" in every file wheresrc/adapter.his used. I've made all these changes, but maybe we should really think about include guards.Not following why would
adapter.hrequires it? Isadapter.hreturning the enum?src/adapter.h +2
-1@@ -207,15 +207,18 @@ int btd_adapter_passkey_reply(struct btd_adapter *adapter, uint32_t passkey);int adapter_create_bonding (struct btd_adapter *adapter,const bdaddr_t *bdaddr, -uint8_t addr_type,uint8_t io_cap); +uint8_t addr_type, +enum mgmt_io_capability io_cap); int adapter_bonding_attempt(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
src/adapter.h int btd_adapter_passkey_reply(struct btd_adapter *adapter, · line 221
Quoted 10 lines
src/adapter.h +4
-2- uint8_t addr_type, uint8_t io_cap); +uint8_t addr_type, + enum mgmt_io_capability io_cap);int adapter_cancel_bonding (struct btd_adapter *adapter,const bdaddr_t *bdaddr,uint8_t addr_type); -int adapter_set_io_capability (struct btd_adapter *adapter,uint8_t io_cap); +int adapter_set_io_capability (struct btd_adapter *adapter, +enum mgmt_io_capability io_cap);
I'd keep these as uint8_t to limit the necessary changes, as the objective here is fixing the bluetoothctl mgmt command. We can attempt cleanup in a different set.
Quoted 68 lines
src/adapter.h +0
-0int btd_adapter_read_local_oob_data (struct btd_adapter *adapter);Compiler output:
In file included fromplugins/autopair.c:28:./src/adapter.h:211:54: warning: ‘enum mgmt_io_capability’ declared inside parameter list will not be visible outside of this definition or declaration211 | enum mgmt_io_capability io_cap); | ^~~~~~~~~~~~~~~~~~ ./src/adapter.h:215:54: warning: ‘enum mgmt_io_capability’ declared inside parameter list will not be visible outside of this definition or declaration 215 | enum mgmt_io_capability io_cap); | ^~~~~~~~~~~~~~~~~~ ./src/adapter.h:221:54: warning: ‘enum mgmt_io_capability’ declared inside parameter list will not be visible outside of this definition or declaration 221 | enum mgmt_io_capability io_cap); | ^~~~~~~~~~~~~~~~~~So,
enum mgmt_io_capabilityis not used as a return value, but also using it as function argument requires prior declaration.AFAIK, forward declaration of C-style enum is not possible. So if
enum mgmt_io_capabilityis declared inshared/mgmt.h, this header must be included priorsrc/adapter.hCurrently,
src/adapter.his included by 56 files. In nearly all of them, I had to add inclusion ofsrc/shared/mgmt.h.regards,
ChristianQuoted 36 lines
Quoted 3 lines
Shall I resubmit the whole series or do you want to pick the fine commits first?
Ive already applied the changes that I didn't have any comments, so please rebase and send as a new set.
Quoted 26 lines
regards,
ChristianQuoted 19 lines
Quoted 16 lines
src/shared/mgmt.h +4
-1+ +typedef void (*mgmt_destroy_func_t )(void *user_data);struct mgmt ;@@ -89,3 +97,5 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index);bool mgmt_unregister_all (struct mgmt *mgmt);uint16_t mgmt_get_mtu (struct mgmt *mgmt); + +uint8_t mgmt_parse_io_capability (const char *capability); --2.51.0
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH BlueZ 11/12] agent: move defines and parsing for I/O capability to shared/mgnt
In reply to Christian EggersQuoted 10 lines · Christian Eggers
Quoted 3 lines
Perhaps this should be an enum to ensure things like switch statements
do check for unhandled values.also done. But now using an enum in
src/adapter.hrequires also including
"src/shared/mgmt.h" in every file wheresrc/adapter.his used. I've made
all these changes, but maybe we should really think about include guards.
#pragma once
should be all that's needed, at the top of the header in question. IMO, there's really no need to start adding it everywhere, but it's a good time to set an example on how it can be done when needed.
Quoted 3 lines
Shall I resubmit the whole series or do you want to pick the fine commits
first?
PATCH 12/12 client/mgmt: align implementation cmd_io_cap with its documentation
In reply to Christian EggersDocumentation 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(-)
client/mgmt.c +15 -3
@@ -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]",
src/shared/mgmt.c +20 -0
@@ -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;
src/shared/mgmt.h +1 -0
@@ -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);
Signature · 1 line
2.51.0
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=1057897
---Test result---
Test Summary:
CheckPatch PENDING 0.54 seconds GitLint PENDING 0.35 seconds BuildEll PASS 21.40 seconds BluezMake PASS 682.28 seconds MakeCheck PASS 19.42 seconds MakeDistcheck PASS 255.54 seconds CheckValgrind PASS 304.40 seconds CheckSmatch WARNING 371.58 seconds bluezmakeextell PASS 185.95 seconds IncrementalBuild PENDING 0.36 seconds ScanBuild PASS 1058.84 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:attrib/gatttool.c:236:23: warning: Variable length array is used.attrib/interactive.c: note: in included file (through /usr/include/readline/readline.h):attrib/interactive.c:175:27: warning: non-ANSI function declaration of function 'disconnect_io'attrib/interactive.c:300:23: warning: Variable length array is used.
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 8 lines · On Wed, 25 Feb 2026 17:17:04 +0100 you wrote:
client/mgmt.c: In function ‘str2bytearray’:client/mgmt.c:2385:23: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘long int’ [-Werror=sign-compare]
2385 | if (i >=*val_len) {
| ^~[...]
Here is the summary with links:
- [BlueZ,01/12] client/mgmt: fix compiler error
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=451fff520c8a - [BlueZ,02/12] tools: btgatt-client/-server: replace ATT_CID with 'shared' BT_ATT_CID https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9648dbaa8d01 - [BlueZ,03/12] src: replace ATT_CID with 'shared' BT_ATT_CID (no matching commit) - [BlueZ,04/12] peripheral: replace ATT_CID with shared BT_ATT_CID https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5767a7dded4f - [BlueZ,05/12] attrib: replace ATT_CID with 'shared' BT_ATT_CID https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=cd6a809f7b43 - [BlueZ,06/12] src: replace ATT_PSM with 'shared' BT_ATT_PSM https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=776f9062c845 - [BlueZ,07/12] tools: btgatt-server: remove unused member 'fd' https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d5c85b052eea - [BlueZ,08/12] l2test: add comment to -F <fcs> option https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c8a7462f3490
- [BlueZ,09/12] l2test: add comment to -O <omtu> option
(no matching commit)
- [BlueZ,10/12] l2test: small improvements for deferred setup
(no matching commit)
- [BlueZ,11/12] agent: move defines and parsing for I/O capability to shared/mgnt (no matching commit)
- [BlueZ,12/12] client/mgmt: align implementation cmd_io_cap with its documentation (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html