client/btpclient: Add GAP extended advertising support
cover client/btpclient: Add GAP extended advertising support
The BTP_OP_GAP_SET_EXTENDED_ADVERTISING command is used by at least the BAP/USR/DISC/BV-01-C test.
Since this opcode is defined as 0x21 (33), it does not fit into the current fixed-size command bitmap. This series refactors the way btpclient reports supported auto-PTS commands so it can grow the bitmap dynamically as needed.
The series also switches GAP advertising data handling to the advertising type definitions already provided by src/shared/ad.h.
Frédéric Danis (3):
client/btpclient: refactor read-commands bitmap building client/btpclient: Replace advertising defines by shared ones client/btpclient: Add BTP_OP_GAP_SET_EXTENDED_ADVERTISING support
client/btpclient/bap.c | 27 ++++-- client/btpclient/btpclient.c | 25 +++++ client/btpclient/btpclient.h | 5 + client/btpclient/core.c | 29 ++++-- client/btpclient/gap.c | 171 +++++++++++++++++++++++++---------- client/btpclient/gatt.c | 39 +++++--- src/shared/btp.h | 7 ++ 7 files changed, 229 insertions(+), 74 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 client/btpclient: refactor read-commands bitmap building
Add add_supported_command() and use it across all btp_*_read_commands handlers.
This replaces fixed-size bitmask assembly with a dynamically growing command bitmap based on opcode index, avoiding shift-width issues with higher opcodes.
This will allow to add opcodes like GAP_SET_EXTENDED_ADVERTISING (0x21).
Refactor core, gap, gatt and bap read-commands paths to build response bitmaps through the shared helper and preserve existing error handling for allocation failures.
--- client/btpclient/bap.c | 27 +++++++++++++---- client/btpclient/btpclient.c | 25 +++++++++++++++ client/btpclient/btpclient.h | 5 +++ client/btpclient/core.c | 29 ++++++++++++++---- client/btpclient/gap.c | 59 +++++++++++++++++++++++------------- client/btpclient/gatt.c | 39 ++++++++++++++++-------- 6 files changed, 139 insertions(+), 45 deletions(-)
client/btpclient/bap.c +21 -6
@@ -27,7 +27,13 @@ static bool bap_service_registered;static void btp_bap_read_commands (uint8_t index,const void *param,uint16_t length,void *user_data) { -uint16_t commands =0 ; +const uint8_t supported_commands[] = { +BTP_OP_BAP_READ_SUPPORTED_COMMANDS , +BTP_OP_BAP_DISCOVER , + }; +uint8_t *commands =NULL ; +size_t commands_len =0 ; +size_t i;if (index !=BTP_INDEX_NON_CONTROLLER ) { btp_send_error(btp, BTP_BAP_SERVICE, index,
@@ -35,13 +41,22 @@ static void btp_bap_read_commands(uint8_t index, const void *param,return ; } - commands |= (1 <<BTP_OP_BAP_READ_SUPPORTED_COMMANDS ); - commands |= (1 <<BTP_OP_BAP_DISCOVER ); - - commands =L_CPU_TO_LE16 (commands); +for (i =0 ; i <L_ARRAY_SIZE (supported_commands); i++) { +if (!add_supported_command (&commands, &commands_len, + supported_commands[i])) + goto failed; + }btp_send (btp,BTP_BAP_SERVICE ,BTP_OP_BAP_READ_SUPPORTED_COMMANDS , -BTP_INDEX_NON_CONTROLLER ,sizeof (commands), &commands); +BTP_INDEX_NON_CONTROLLER , commands_len, commands); + +l_free (commands); + +return ; + +failed: +l_free (commands); +btp_send_error (btp,BTP_BAP_SERVICE , index,BTP_ERROR_FAIL ); } static void btp_bap_discover(uint8_t index, const void *param, uint16_t length,
client/btpclient/btpclient.c +25 -0
@@ -38,6 +38,31 @@ static struct btp *btp;static struct btp_agent ag; +bool add_supported_command (uint8_t **commands,size_t *commands_len, +uint8_t command) +{ +size_t cmd_byte = command /8 ; + +if (cmd_byte >= *commands_len) { +size_t old_len = *commands_len; +size_t new_len = cmd_byte +1 ; +uint8_t *tmp; + + tmp =l_realloc (*commands, new_len); +if (!tmp) +return false; + +memset (tmp + old_len,0 , new_len - old_len); + + *commands = tmp; + *commands_len = new_len; + } + + (*commands)[cmd_byte] |= (1U << (command %8 )); + +return true; +} +struct l_queue *get_adapters_list (void ) {return adapters;
client/btpclient/btpclient.h +5 -0
@@ -7,6 +7,8 @@* */ +#include <stddef.h> +struct btp_adapter {struct l_dbus_proxy *proxy;struct l_dbus_proxy *ad_proxy;
@@ -54,3 +56,6 @@ struct btp_agent *get_agent(void);bool request_default_agent (l_dbus_client_proxy_result_func_t reply,void *user_data,l_dbus_destroy_func_t destroy); + +bool add_supported_command (uint8_t **commands,size_t *commands_len, +uint8_t command);
client/btpclient/core.c +23 -6
@@ -24,7 +24,15 @@ static struct l_dbus *dbus;static void btp_core_read_commands (uint8_t index,const void *param,uint16_t length,void *user_data) { -uint8_t commands =0 ; +const uint8_t supported_commands[] = { +BTP_OP_CORE_READ_SUPPORTED_COMMANDS , +BTP_OP_CORE_READ_SUPPORTED_SERVICES , +BTP_OP_CORE_REGISTER , +BTP_OP_CORE_UNREGISTER , + }; +uint8_t *commands =NULL ; +size_t commands_len =0 ; +size_t i;if (index !=BTP_INDEX_NON_CONTROLLER ) { btp_send_error(btp, BTP_CORE_SERVICE, index,
@@ -32,13 +40,22 @@ static void btp_core_read_commands(uint8_t index, const void *param,return ; } - commands |= (1 <<BTP_OP_CORE_READ_SUPPORTED_COMMANDS ); - commands |= (1 <<BTP_OP_CORE_READ_SUPPORTED_SERVICES ); - commands |= (1 <<BTP_OP_CORE_REGISTER ); - commands |= (1 <<BTP_OP_CORE_UNREGISTER ); +for (i =0 ; i <L_ARRAY_SIZE (supported_commands); i++) { +if (!add_supported_command (&commands, &commands_len, + supported_commands[i])) + goto failed; + }btp_send (btp,BTP_CORE_SERVICE ,BTP_OP_CORE_READ_SUPPORTED_COMMANDS , -BTP_INDEX_NON_CONTROLLER ,sizeof (commands), &commands); +BTP_INDEX_NON_CONTROLLER , commands_len, commands); + +l_free (commands); + +return ; + +failed: +l_free (commands); +btp_send_error (btp,BTP_CORE_SERVICE , index,BTP_ERROR_FAIL ); } static void btp_core_read_services(uint8_t index, const void *param,
client/btpclient/gap.c +38 -21
73 lines not on this page · raw message
client/btpclient/gatt.c +27 -12
@@ -44,7 +44,19 @@ static int create_uuid(bt_uuid_t *btuuid, uint8_t len, const uint8_t *data)static void btp_gatt_read_commands (uint8_t index,const void *param,uint16_t length,void *user_data) { -uint16_t commands =0 ; +const uint8_t supported_commands[] = { +BTP_OP_GATT_READ_SUPPORTED_COMMANDS , +BTP_OP_GATT_DISC_PRIM_UUID , +BTP_OP_GATT_DISC_CHRC_UUID , +BTP_OP_GATT_DISC_ALL_DESC , +BTP_OP_GATT_READ , +BTP_OP_GATT_READ_UUID , +BTP_OP_GATT_WRITE_WITHOUT_RSP , +BTP_OP_GATT_WRITE , + }; +uint8_t *commands =NULL ; +size_t commands_len =0 ; +size_t i;if (index !=BTP_INDEX_NON_CONTROLLER ) { btp_send_error(btp, BTP_GATT_SERVICE, index,
@@ -52,19 +64,22 @@ static void btp_gatt_read_commands(uint8_t index, const void *param,return ; } - commands |= (1 <<BTP_OP_GATT_READ_SUPPORTED_COMMANDS ); - commands |= (1 <<BTP_OP_GATT_DISC_PRIM_UUID ); - commands |= (1 <<BTP_OP_GATT_DISC_CHRC_UUID ); - commands |= (1 <<BTP_OP_GATT_DISC_ALL_DESC ); - commands |= (1 <<BTP_OP_GATT_READ ); - commands |= (1 <<BTP_OP_GATT_READ_UUID ); - commands |= (1 <<BTP_OP_GATT_WRITE_WITHOUT_RSP ); - commands |= (1 <<BTP_OP_GATT_WRITE ); - - commands =L_CPU_TO_LE16 (commands); +for (i =0 ; i <L_ARRAY_SIZE (supported_commands); i++) { +if (!add_supported_command (&commands, &commands_len, + supported_commands[i])) + goto failed; + }btp_send (btp,BTP_GATT_SERVICE ,BTP_OP_GATT_READ_SUPPORTED_COMMANDS , -BTP_INDEX_NON_CONTROLLER ,sizeof (commands), &commands); +BTP_INDEX_NON_CONTROLLER , commands_len, commands); + +l_free (commands); + +return ; + +failed: +l_free (commands); +btp_send_error (btp,BTP_GATT_SERVICE , index,BTP_ERROR_FAIL ); }static bool match_attribute_uuid (const void *attr,const void *uuid)
Signature · 1 line
2.43.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=1097304
---Test result---
Test Summary:
CheckPatch FAIL 1.19 seconds GitLint PASS 0.75 seconds BuildEll PASS 21.12 seconds BluezMake PASS 625.35 seconds CheckSmatch WARNING 326.82 seconds bluezmakeextell PASS 164.98 seconds IncrementalBuild PASS 636.73 seconds ScanBuild PASS 930.69 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,1/3] client/btpclient: refactor read-commands bitmap building WARNING:BAD_SIGN_OFF: Non-standard signature: Assisted-by:
#84:
ERROR:BAD_SIGN_OFF: Unrecognized email address: 'GPT:GPT-5.3-Codex' #84:
/github/workspace/src/patch/14581674.patch total: 1 errors, 1 warnings, 255 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/patch/14581674.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:client/btpclient/gatt.c: note: in included file:./src/shared/btp.h:335:41: warning: array of flexible structures./src/shared/btp.h:340:55: warning: array of flexible structures./src/shared/btp.h:363:47: warning: array of flexible structures./src/shared/btp.h:392:42: warning: array of flexible structures
https://github.com/bluez/bluez/pull/2137
---
Regards,
Linux Bluetooth
PATCH 2/3 client/btpclient: Replace advertising defines by shared ones
In reply to Frédéric DanisThe advertisement types are already defined in src/shared/ad.h
--- client/btpclient/gap.c | 44 ++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 27 deletions(-)
client/btpclient/gap.c +17 -27
@@ -17,6 +17,7 @@#include "bluetooth/bluetooth.h" #include "bluetooth/uuid.h" +#include "src/shared/ad.h" #include "src/shared/btp.h" #include "btpclient.h" #include "core.h"
@@ -27,17 +28,6 @@#define AD_IFACE "org.bluez.LEAdvertisement1"#define AG_IFACE "org.bluez.Agent1" -/* List of assigned numbers for advertising data and scan response */ -#define AD_TYPE_FLAGS 0x01 -#define AD_TYPE_INCOMPLETE_UUID16_SERVICE_LIST 0x02 -#define AD_TYPE_SHORT_NAME 0x08 -#define AD_TYPE_COMPLETE_NAME 0x09 -#define AD_TYPE_TX_POWER 0x0a -#define AD_TYPE_SOLICIT_UUID16_SERVICE_LIST 0x14 -#define AD_TYPE_SERVICE_DATA_UUID16 0x16 -#define AD_TYPE_APPEARANCE 0x19 -#define AD_TYPE_MANUFACTURER_DATA 0xff -static void register_gap_service (void );static struct l_dbus *dbus;
@@ -899,7 +889,7 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data) ad_data = &data[adv_data_len - remaining_data_len +2 ];switch (ad_type) { -case AD_TYPE_INCOMPLETE_UUID16_SERVICE_LIST : +case BT_AD_UUID16_SOME : {char *uuid =dupuuid2str (ad_data,16 );
@@ -907,20 +897,28 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data)break ; } -case AD_TYPE_SHORT_NAME : -case AD_TYPE_COMPLETE_NAME : +case BT_AD_NAME_SHORT : +case BT_AD_NAME_COMPLETE : ad.local_name =malloc (ad_len +1 );memcpy (ad.local_name, ad_data, ad_len); ad.local_name[ad_len] ='\0' ;break ; -case AD_TYPE_TX_POWER : +case BT_AD_TX_POWER : ad.tx_power = true;/* XXX Value is omitted cause, stack fills it */ break ; -case AD_TYPE_SERVICE_DATA_UUID16 : +case BT_AD_SOLICIT16 : + { +char *uuid =dupuuid2str (ad_data,16 ); + +l_queue_push_tail (ad.solicits, uuid); + +break ; + } +case BT_AD_SERVICE_DATA16 : {struct service_data *sd;
@@ -933,11 +931,11 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data)break ; } -case AD_TYPE_APPEARANCE : +case BT_AD_GAP_APPEARANCE :memcpy (&ad.local_appearance, ad_data, ad_len);break ; -case AD_TYPE_MANUFACTURER_DATA : +case BT_AD_MANUFACTURER_DATA : {struct manufacturer_data *md;
@@ -954,14 +952,6 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data)break ; } -case AD_TYPE_SOLICIT_UUID16_SERVICE_LIST : - { -char *uuid =dupuuid2str (ad_data,16 ); - -l_queue_push_tail (ad.solicits, uuid); - -break ; - }default :l_info ("Unsupported advertising data type" );
@@ -2455,7 +2445,7 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy) ev->eir_len); eir = &ev->eir[ev->eir_len - n -4 ]; eir[0 ] = n +3 ; - eir[1 ] =AD_TYPE_MANUFACTURER_DATA ; + eir[1 ] =BT_AD_MANUFACTURER_DATA ; eir[2 ] = key >>8 ; eir[3 ] = key &0xFF ;memcpy (&eir[4 ], data, n);
Signature · 1 line
2.43.0
PATCH 3/3 client/btpclient: Add BTP_OP_GAP_SET_EXTENDED_ADVERTISING support
In reply to Frédéric DanisThis set LEAdvertisement1's SecondaryChannel property to "2M" to force Extended advertisement type.
--- client/btpclient/gap.c | 68 ++++++++++++++++++++++++++++++++++++++++-- src/shared/btp.h | 7 +++++ 2 files changed, 73 insertions(+), 2 deletions(-)
client/btpclient/gap.c +66 -2
@@ -73,7 +73,7 @@ static char *dupuuid2str(const uint8_t *uuid, uint8_t len) {switch (len) {case 16 : -return l_strdup_printf ("%hhx%hhx" , uuid[0 ], uuid[1 ]); +return l_strdup_printf ("%hhx%hhx" , uuid[1 ], uuid[0 ]);case 128 : return l_strdup_printf("%hhx%hhx%hhx%hhx%hhx%hhx%hhx%hhx%hhx" "%hhx%hhx%hhx%hhx%hhx%hhx%hhx", uuid[0],
@@ -109,6 +109,7 @@ static void btp_gap_read_commands(uint8_t index, const void *param,BTP_OP_GAP_UNPAIR ,BTP_OP_GAP_PASSKEY_ENTRY_RSP ,BTP_OP_GAP_PASSKEY_CONFIRM_RSP , + BTP_OP_GAP_SET_EXTENDED_ADVERTISING, };uint8_t *commands =NULL ;size_t commands_len =0 ;
@@ -813,6 +814,22 @@ static bool ad_timeout_getter(struct l_dbus *dbus,return true; } +static bool ad_secondarychannel_getter (struct l_dbus *dbus, +struct l_dbus_message *message, +struct l_dbus_message_builder *builder, +void *user_data) +{ +struct btp_adapter *adapter = user_data; +uint32_t settings = adapter->current_settings; + +if (!(settings &BTP_GAP_SETTINGS_EXTENDED_ADVERTISING )) +return false; + +l_dbus_message_builder_append_basic (builder,'s' ,"2M" ); + +return true; +} +static void setup_ad_interface (struct l_dbus_interface *interface) { l_dbus_interface_method(interface, "Release",
@@ -839,6 +856,8 @@ static void setup_ad_interface(struct l_dbus_interface *interface) ad_duration_getter, NULL);l_dbus_interface_property (interface,"Timeout" ,0 ,"q" , ad_timeout_getter,NULL ); +l_dbus_interface_property (interface,"SecondaryChannel" ,0 ,"s" , + ad_secondarychannel_getter,NULL ); } static void start_advertising_reply(struct l_dbus_proxy *proxy,
@@ -889,6 +908,9 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data) ad_data = &data[adv_data_len - remaining_data_len +2 ];switch (ad_type) { +case BT_AD_FLAGS : +/* Advertisement flags are set by bluetoothd */ +break ;case BT_AD_UUID16_SOME : {char *uuid =dupuuid2str (ad_data,16 );
@@ -897,6 +919,14 @@ static void create_advertising_data(uint8_t adv_data_len, const uint8_t *data)break ; } +case BT_AD_UUID16_ALL : + { +char *uuid =dupuuid2str (ad_data,16 ); + +l_queue_push_tail (ad.uuids, uuid); + +break ; + }case BT_AD_NAME_SHORT :case BT_AD_NAME_COMPLETE : ad.local_name =malloc (ad_len +1 );
@@ -1008,7 +1038,7 @@ static void btp_gap_start_advertising(uint8_t index, const void *param, goto failed; } -if (!l_dbus_object_add_interface (dbus,AD_PATH ,AD_IFACE ,NULL )) { +if (!l_dbus_object_add_interface (dbus,AD_PATH ,AD_IFACE , adapter)) {l_info ("Unable to instantiate ad interface" );if (!l_dbus_unregister_interface (dbus,AD_IFACE ))
@@ -2380,6 +2410,36 @@ failed:btp_send_error (btp,BTP_GAP_SERVICE , index, status); } + +static void btp_gap_set_extended_advertising (uint8_t index,const void *param, +uint16_t length,void *user_data) +{ +struct btp_adapter *adapter =find_adapter_by_index (index); +const struct btp_gap_set_extended_advertising_cp *cp = param; +uint32_t new_settings; +uint8_t status =BTP_ERROR_FAIL ; + +if (!adapter) { + status =BTP_ERROR_INVALID_INDEX ; + goto failed; + } + + new_settings = adapter->current_settings; +if (cp->settings) + new_settings |=BTP_GAP_SETTINGS_EXTENDED_ADVERTISING ; +else + new_settings &= ~BTP_GAP_SETTINGS_EXTENDED_ADVERTISING ; +update_current_settings (adapter, new_settings); + +btp_send (btp,BTP_GAP_SERVICE ,BTP_OP_GAP_SET_EXTENDED_ADVERTISING , + adapter->index,sizeof (new_settings), + &new_settings); + +return ; +failed: +btp_send_error (btp,BTP_GAP_SERVICE , index, status); +} +static void btp_gap_device_found_ev (struct l_dbus_proxy *proxy) {struct btp_device *device =find_device_by_proxy (proxy);
@@ -2632,6 +2692,10 @@ static void register_gap_service(void)btp_register (btp,BTP_GAP_SERVICE ,BTP_OP_GAP_PASSKEY_CONFIRM_RSP , btp_gap_confirm_entry_rsp,NULL ,NULL ); + +btp_register (btp,BTP_GAP_SERVICE ,BTP_OP_GAP_SET_EXTENDED_ADVERTISING , + btp_gap_set_extended_advertising, +NULL ,NULL ); }void gap_proxy_added (struct l_dbus_proxy *proxy,void *user_data)
src/shared/btp.h +7 -0
@@ -82,6 +82,8 @@ struct btp_gap_read_index_rp {#define BTP_GAP_SETTING_PRIVACY 0x00002000#define BTP_GAP_SETTING_CONTROLLER_CONF 0x00004000#define BTP_GAP_SETTING_STATIC_ADDRESS 0x00008000 +#define BTP_GAP_SETTINGS_SC_ONLY 0x00010000 +#define BTP_GAP_SETTINGS_EXTENDED_ADVERTISING 0x00020000#define BTP_OP_GAP_READ_CONTROLLER_INFO 0x03struct btp_gap_read_info_rp {
@@ -224,6 +226,11 @@ struct btp_gap_passkey_confirm_rsp_cp {uint8_t match; } __packed; +#define BTP_OP_GAP_SET_EXTENDED_ADVERTISING 0x21 +struct btp_gap_set_extended_advertising_cp { +uint8_t settings; +} __packed; +#define BTP_EV_GAP_NEW_SETTINGS 0x80struct btp_new_settings_ev {uint32_t current_settings;
Signature · 1 line
2.43.0
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 9 lines · On Tue, 19 May 2026 12:55:16 +0200 you wrote:
The
BTP_OP_GAP_SET_EXTENDED_ADVERTISINGcommand is used by at least the BAP/USR/DISC/BV-01-C test.Since this opcode is defined as
0x21(33), it does not fit into the current fixed-size command bitmap. This series refactors the way btpclient reports supported auto-PTS commands so it can grow the bitmap dynamically as needed.[...]
Here is the summary with links:
- [BlueZ,1/3] client/btpclient: refactor read-commands bitmap building
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=0e55974d713b - [BlueZ,2/3] client/btpclient: Replace advertising defines by shared ones https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9074d38c5fed - [BlueZ,3/3] client/btpclient: Add BTP_OP_GAP_SET_EXTENDED_ADVERTISING support https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=588a0267d8fa
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html