Add implementation of bearer connect/disconnect
v6 cover Add implementation of bearer connect/disconnect
---
Changes in v6:
- Fix coding style warnings.
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- Split adding bearer field to btd_profile into a standalone patch.
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Add a bearer field to btd_profile to indicate which bearer type the profile
- belongs to, thus we can distinct the services per bearer.
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Move the modification logic from the device to bearer, and add
- some helper functions to the device.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Fix build error & warning.
- Link to v1: https://patch.msgid.link/[email protected]
---
Ye He (3):
profiles: Add bearer field to btd_profile
bearer: Implement Connect/Disconnect methods
client: Add shell cmd for bearer connect/disconnect
client/bluetoothctl.rst | 34 ++++++++ client/main.c | 141 +++++++++++++++++++++++++++++++++ profiles/audio/a2dp.c | 5 +- profiles/audio/asha.c | 1 + profiles/audio/avrcp.c | 2 + profiles/audio/bap.c | 2 + profiles/audio/bass.c | 1 + profiles/audio/ccp.c | 1 + profiles/audio/csip.c | 2 + profiles/audio/mcp.c | 1 + profiles/audio/micp.c | 1 + profiles/audio/vcp.c | 1 + profiles/battery/battery.c | 1 + profiles/deviceinfo/deviceinfo.c | 1 + profiles/gap/gas.c | 1 + profiles/health/hdp_manager.c | 2 + profiles/input/hog.c | 1 + profiles/input/manager.c | 1 + profiles/midi/midi.c | 1 + profiles/network/manager.c | 3 + profiles/scanparam/scan.c | 1 + src/bearer.c | 167 ++++++++++++++++++++++++++++++++++++++- src/device.c | 129 +++++++++++++++++++++++++----- src/device.h | 17 ++++ src/profile.h | 10 +++ 25 files changed, 503 insertions(+), 24 deletions(-)
---
base-commit: 5e41d1e1d361e7288964e4c2c5ed90736025662f
change-id: 20251111-bearer-impl-5f7e396174aa
Best regards,
Signature · 1 line
Ye He <[email protected]>
PATCH v6 1/3 profiles: Add bearer field to btd_profile
Add bearer filed into btd_profile to indicates which bearer type this profile belongs to. Thus we can distinct the services per bearer.
--- profiles/audio/a2dp.c | 5 +++-- profiles/audio/asha.c | 1 + profiles/audio/avrcp.c | 2 ++ profiles/audio/bap.c | 2 ++ profiles/audio/bass.c | 1 + profiles/audio/ccp.c | 1 + profiles/audio/csip.c | 2 ++ profiles/audio/mcp.c | 1 + profiles/audio/micp.c | 1 + profiles/audio/vcp.c | 1 + profiles/battery/battery.c | 1 + profiles/deviceinfo/deviceinfo.c | 1 + profiles/gap/gas.c | 1 + profiles/health/hdp_manager.c | 2 ++ profiles/input/hog.c | 1 + profiles/input/manager.c | 1 + profiles/midi/midi.c | 1 + profiles/network/manager.c | 3 +++ profiles/scanparam/scan.c | 1 + src/profile.h | 10 ++++++++++ 20 files changed, 37 insertions(+), 2 deletions(-)
profiles/audio/a2dp.c +3 -2
@@ -3757,8 +3757,9 @@ static void media_server_remove(struct btd_adapter *adapter)static struct btd_profile a2dp_source_profile = { .name ="a2dp-source" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , - + .bearer =BTD_PROFILE_BEARER_BREDR , .remote_uuid =A2DP_SOURCE_UUID , + .device_probe = a2dp_source_probe, .device_remove = a2dp_source_remove,
@@ -3773,7 +3774,7 @@ static struct btd_profile a2dp_source_profile = {static struct btd_profile a2dp_sink_profile = { .name ="a2dp-sink" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , - + .bearer =BTD_PROFILE_BEARER_BREDR , .remote_uuid =A2DP_SINK_UUID , .device_probe = a2dp_sink_probe, .device_remove = a2dp_sink_remove,
profiles/audio/asha.c +1 -0
@@ -499,6 +499,7 @@ static int asha_source_disconnect(struct btd_service *service)static struct btd_profile asha_source_profile = { .name ="asha-source" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =ASHA_PROFILE_UUID , .experimental = true,
profiles/audio/avrcp.c +2 -0
@@ -4868,6 +4868,7 @@ done:static struct btd_profile avrcp_target_profile = { .name ="audio-avrcp-target" , + .bearer =BTD_PROFILE_BEARER_BREDR , .remote_uuid =AVRCP_TARGET_UUID , .device_probe = avrcp_target_probe,
@@ -4951,6 +4952,7 @@ done:static struct btd_profile avrcp_controller_profile = { .name ="avrcp-controller" , + .bearer =BTD_PROFILE_BEARER_BREDR , .remote_uuid =AVRCP_REMOTE_UUID , .device_probe = avrcp_controller_probe,
profiles/audio/bap.c +2 -0
@@ -3865,6 +3865,7 @@ static void bap_adapter_remove(struct btd_profile *p,static struct btd_profile bap_profile = { .name ="bap" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =PACS_UUID_STR , .device_probe = bap_probe, .device_remove = bap_remove,
@@ -3879,6 +3880,7 @@ static struct btd_profile bap_profile = {static struct btd_profile bap_bcast_profile = { .name ="bcaa" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =BCAAS_UUID_STR , .device_probe = bap_bcast_probe, .device_remove = bap_bcast_remove,
profiles/audio/bass.c +1 -0
@@ -2172,6 +2172,7 @@ static void bass_server_remove(struct btd_profile *p,static struct btd_profile bass_service = { .name ="bass" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =BASS_UUID_STR , .device_probe = bass_probe, .device_remove = bass_remove,
profiles/audio/ccp.c +1 -0
@@ -208,6 +208,7 @@ ccp_server_remove(struct btd_profile *p,static struct btd_profile ccp_profile = { .name ="ccp" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =GTBS_UUID_STR , .device_probe = ccp_probe, .device_remove = ccp_remove,
profiles/audio/csip.c +2 -0
@@ -303,6 +303,7 @@ static void csip_remove(struct btd_service *service)static struct btd_profile csip_profile = { .name ="csip" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =CSIS_UUID_STR , .device_probe = csip_probe,
@@ -442,6 +443,7 @@ static void csis_server_remove(struct btd_profile *p,static struct btd_profile csis_profile = { .name ="csis" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .local_uuid =CSIS_UUID_STR , .adapter_probe = csis_server_probe,
profiles/audio/mcp.c +1 -0
@@ -383,6 +383,7 @@ static void media_control_server_remove(struct btd_profile *p,static struct btd_profile mcp_profile = { .name ="mcp" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =GMCS_UUID_STR , .device_probe = mcp_probe, .device_remove = mcp_remove,
profiles/audio/micp.c +1 -0
@@ -300,6 +300,7 @@ static void micp_server_remove(struct btd_profile *p,static struct btd_profile micp_profile = { .name ="micp" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =MICS_UUID_STR , .device_probe = micp_probe,
profiles/audio/vcp.c +1 -0
@@ -328,6 +328,7 @@ static void vcp_server_remove(struct btd_profile *p,static struct btd_profile vcp_profile = { .name ="vcp" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =VCS_UUID_STR , .device_probe = vcp_probe,
profiles/battery/battery.c +1 -0
@@ -327,6 +327,7 @@ static int batt_disconnect(struct btd_service *service)static struct btd_profile batt_profile = { .name ="batt-profile" , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =BATTERY_UUID , .device_probe = batt_probe, .device_remove = batt_remove,
profiles/deviceinfo/deviceinfo.c +1 -0
@@ -137,6 +137,7 @@ static int deviceinfo_disconnect(struct btd_service *service)static struct btd_profile deviceinfo_profile = { .name ="deviceinfo" , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =DEVICE_INFORMATION_UUID , .device_probe = deviceinfo_probe, .device_remove = deviceinfo_remove,
profiles/gap/gas.c +1 -0
@@ -366,6 +366,7 @@ static int gap_disconnect(struct btd_service *service)static struct btd_profile gap_profile = { .name ="gap-profile" , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =GAP_UUID , .device_probe = gap_probe, .device_remove = gap_remove,
profiles/health/hdp_manager.c +2 -0
@@ -57,6 +57,7 @@ static void hdp_driver_remove(struct btd_service *service)static struct btd_profile hdp_source_profile = { .name ="hdp-source" , + .bearer =BTD_PROFILE_BEARER_BREDR , .remote_uuid =HDP_SOURCE_UUID , .device_probe = hdp_driver_probe,
@@ -68,6 +69,7 @@ static struct btd_profile hdp_source_profile = {static struct btd_profile hdp_sink_profile = { .name ="hdp-sink" , + .bearer =BTD_PROFILE_BEARER_BREDR , .remote_uuid =HDP_SINK_UUID , .device_probe = hdp_driver_probe,
profiles/input/hog.c +1 -0
@@ -215,6 +215,7 @@ static int hog_disconnect(struct btd_service *service)static struct btd_profile hog_profile = { .name ="input-hog" , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =HOG_UUID , .device_probe = hog_probe, .device_remove = hog_remove,
profiles/input/manager.c +1 -0
@@ -45,6 +45,7 @@ static void hid_server_remove(struct btd_profile *p,static struct btd_profile input_profile = { .name ="input-hid" , + .bearer =BTD_PROFILE_BEARER_BREDR , .local_uuid =HID_UUID , .remote_uuid =HID_UUID ,
profiles/midi/midi.c +1 -0
@@ -458,6 +458,7 @@ static int midi_disconnect(struct btd_service *service)static struct btd_profile midi_profile = { .name ="MIDI GATT Driver" , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =MIDI_UUID , .priority =BTD_PROFILE_PRIORITY_HIGH , .auto_connect = true,
profiles/network/manager.c +3 -0
@@ -120,6 +120,7 @@ static void nap_server_remove(struct btd_profile *p,static struct btd_profile panu_profile = { .name ="network-panu" , + .bearer =BTD_PROFILE_BEARER_BREDR , .local_uuid =NAP_UUID , .remote_uuid =PANU_UUID , .device_probe = connection_register,
@@ -132,6 +133,7 @@ static struct btd_profile panu_profile = {static struct btd_profile gn_profile = { .name ="network-gn" , + .bearer =BTD_PROFILE_BEARER_BREDR , .local_uuid =PANU_UUID , .remote_uuid =GN_UUID , .device_probe = connection_register,
@@ -144,6 +146,7 @@ static struct btd_profile gn_profile = {static struct btd_profile nap_profile = { .name ="network-nap" , + .bearer =BTD_PROFILE_BEARER_BREDR , .local_uuid =PANU_UUID , .remote_uuid =NAP_UUID , .device_probe = connection_register,
profiles/scanparam/scan.c +1 -0
@@ -259,6 +259,7 @@ static int scan_param_probe(struct btd_service *service)static struct btd_profile scan_profile = { .name ="Scan Parameters Client Driver" , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =SCAN_PARAMETERS_UUID , .device_probe = scan_param_probe, .device_remove = scan_param_remove,
src/profile.h +10 -0
@@ -12,12 +12,22 @@#define BTD_PROFILE_PRIORITY_MEDIUM 1#define BTD_PROFILE_PRIORITY_HIGH 2 +#define BTD_PROFILE_BEARER_ANY 0 +#define BTD_PROFILE_BEARER_LE 1 +#define BTD_PROFILE_BEARER_BREDR 2 +struct btd_service ;struct btd_profile {const char *name;int priority; +/* Indicates which bearer type this profile belongs to. Some profiles +* may exist in both BR/EDR and LE, in which case they should be +* registered with BTD_PROFILE_BEARER_ANY. +*/ +int bearer; +const char *local_uuid;const char *remote_uuid;
Signature · 1 line
2.42.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=1027639
---Test result---
Test Summary:
CheckPatch PENDING 0.31 seconds GitLint PENDING 0.27 seconds BuildEll PASS 20.76 seconds BluezMake PASS 696.10 seconds MakeCheck PASS 22.46 seconds MakeDistcheck PASS 253.51 seconds CheckValgrind PASS 309.82 seconds CheckSmatch PASS 351.91 seconds bluezmakeextell PASS 185.91 seconds IncrementalBuild PENDING 0.37 seconds ScanBuild PASS 1038.47 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
PATCH v6 2/3 bearer: Implement Connect/Disconnect methods
In reply to Ye HeThis patch provides implementations for the Connect and Disconnect methods of the org.bluez.Bearer.LE1 and org.bluez.Bearer.BREDR1 interfaces.
--- src/bearer.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/device.c | 129 ++++++++++++++++++++++++++++++++++++++------- src/device.h | 17 ++++++ 3 files changed, 291 insertions(+), 22 deletions(-)
src/bearer.c +165 -2
@@ -25,23 +25,43 @@#include "bluetooth/bluetooth.h" #include "bluetooth/mgmt.h" +#include "bluetooth/uuid.h" #include "gdbus/gdbus.h" #include "src/shared/util.h" +#include "src/shared/queue.h" +#include "src/shared/timeout.h" #include "log.h" #include "error.h" #include "adapter.h" #include "device.h" +#include "profile.h" +#include "service.h" #include "dbus-common.h" #include "bearer.h" +#define DISCONNECT_TIMER 2 +struct btd_bearer {struct btd_device *device;uint8_t type;const char *path; +unsigned int disconn_timer; +struct queue *disconnects;/* disconnects message */ + +/* Connect() is defined as a single in-flight operation. To preserve +* the API semantics of org.bluez.Device1.Connect(), we do not queue +* additional connect messages. +*/ +DBusMessage *connect;/* connect message */ }; +static void bearer_free_dbus_message (void *data) +{ +dbus_message_unref ((DBusMessage *)data); +} +static void bearer_free (void *data) {struct btd_bearer *bearer = data;
@@ -49,17 +69,128 @@ static void bearer_free(void *data)free (bearer); } +static void bearer_disconnect_service (struct btd_service *service, +void *user_data) +{ +uint8_t bdaddr_type = *(uint8_t *)user_data; +struct btd_profile *profile =btd_service_get_profile (service); +struct btd_device *device =btd_service_get_device (service); + +if (!profile || !device) +return ; + +if (bdaddr_type ==BDADDR_BREDR ) { +if (profile->bearer ==BTD_PROFILE_BEARER_LE ) +return ; + }else { +if (profile->bearer ==BTD_PROFILE_BEARER_BREDR ) +return ; + } + +DBG ("Disconnecting profile %s for bearer addr type %u" , + profile->name ?:"(unknown)" , bdaddr_type); + +btd_service_disconnect (service); +} + + +static bool bearer_disconnect_link (gpointer user_data) +{ +struct btd_bearer *bearer = user_data; +struct btd_device *device = bearer->device; + + bearer->disconn_timer =0 ; + +if (btd_device_bdaddr_type_connected (device, bearer->type)) +btd_adapter_disconnect_device (device_get_adapter (device), +device_get_address (device), + bearer->type); +return FALSE; +} +static DBusMessage *bearer_connect (DBusConnection *conn,DBusMessage *msg,void *user_data) { -/* TODO */ +struct btd_bearer *bearer = user_data; +struct btd_device *device = bearer->device; +int err; + +if (btd_device_bdaddr_type_connected (device, bearer->type)) { +if (msg) +return btd_error_already_connected (msg); +return NULL ; + } + +if (device_is_bonding (device,NULL )) { +if (msg) +return btd_error_in_progress (msg); +return NULL ; + } + +if (device_is_connecting (device) || + bearer->connect) { +if (msg) +return btd_error_in_progress (msg); +return NULL ; + } + +if (msg) + bearer->connect =dbus_message_ref (msg); + +if (bearer->type ==BDADDR_BREDR ) +return device_connect_profiles (device,BDADDR_BREDR , + msg,NULL ); +else { +btd_device_set_temporary (device, false); + err =device_connect_le (device); +if (err <0 ) +return btd_error_failed (msg,strerror (-err)); + } +return NULL ; }static DBusMessage *bearer_disconnect (DBusConnection *conn,DBusMessage *msg,void *user_data) { -/* TODO */ +struct btd_bearer *bearer = user_data; +struct btd_device *device = bearer->device; + +if (!btd_device_bdaddr_type_connected (device, bearer->type)) { +if (msg) +return btd_error_not_connected (msg); +return NULL ; + } + +/* org.bluez.Device1.Disconnect() is in progress. Since it tears down +* both LE and BR/EDR bearers, it takes precedence over bearer-level +* disconnects. Ignore any bearer-specific disconnect requests here. +*/ +if (device_is_disconnecting (device)) { +if (msg) +return btd_error_in_progress (msg); +return NULL ; + } + +if (msg) +queue_push_tail (bearer->disconnects,dbus_message_ref (msg)); + +device_cancel_bonding (device,MGMT_STATUS_DISCONNECTED ); + +device_cancel_browse (device, bearer->type); + +btd_device_foreach_service (device, bearer_disconnect_service, + &bearer->type); + +device_remove_pending_services (device, bearer->type); + +if (bearer->disconn_timer) +return NULL ; + + bearer->disconn_timer =timeout_add_seconds (DISCONNECT_TIMER , + bearer_disconnect_link, + bearer,NULL ); +return NULL ; }
@@ -151,6 +282,7 @@ struct btd_bearer *btd_bearer_new(struct btd_device *device, uint8_t type) bearer->device = device; bearer->type = type; bearer->path =device_get_path (device); + bearer->disconnects =queue_new (); if (!g_dbus_register_interface(btd_get_dbus_connection(), bearer->path, bearer_interface(type),
@@ -174,6 +306,16 @@ void btd_bearer_destroy(struct btd_bearer *bearer)return ; } +if (bearer->disconnects) { +queue_destroy (bearer->disconnects, bearer_free_dbus_message); + bearer->disconnects =NULL ; + } + +if (bearer->connect) { +dbus_message_unref (bearer->connect); + bearer->connect =NULL ; + } +g_dbus_unregister_interface (btd_get_dbus_connection (), bearer->path,bearer_interface (bearer->type)); }
@@ -203,6 +345,13 @@ void btd_bearer_connected(struct btd_bearer *bearer)if (!bearer || !bearer->path)return ; +if (bearer->connect) { +g_dbus_send_reply (btd_get_dbus_connection (), bearer->connect, +DBUS_TYPE_INVALID ); +dbus_message_unref (bearer->connect); + bearer->connect =NULL ; + } +g_dbus_emit_property_changed (btd_get_dbus_connection (), bearer->path,bearer_interface (bearer->type),"Connected" );
@@ -212,10 +361,24 @@ void btd_bearer_disconnected(struct btd_bearer *bearer, uint8_t reason) {const char *name;const char *message; +DBusMessage *msg; +const struct queue_entry *entry;if (!bearer || !bearer->path)return ; +if (!btd_device_is_connected (bearer->device)) +device_disconnect_watches_callback (bearer->device); + +while (!queue_isempty (bearer->disconnects)) { + entry =queue_get_entries (bearer->disconnects); + msg = entry->data; +g_dbus_send_reply (btd_get_dbus_connection (), msg, +DBUS_TYPE_INVALID ); +queue_remove (bearer->disconnects, msg); +dbus_message_unref (msg); + } +g_dbus_emit_property_changed (btd_get_dbus_connection (), bearer->path,bearer_interface (bearer->type),"Connected" );
src/device.c +109 -20
180 lines not on this page · raw message
src/device.h +17 -0
@@ -120,6 +120,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type,gboolean device_is_bonding (struct btd_device *device,const char *sender);void device_bonding_attempt_failed (struct btd_device *device,uint8_t status);void device_bonding_failed (struct btd_device *device,uint8_t status); +void device_cancel_bonding (struct btd_device *device,uint8_t status);struct btd_adapter_pin_cb_iter *device_bonding_iter (struct btd_device *device);int device_bonding_attempt_retry (struct btd_device *device);long device_bonding_last_duration (struct btd_device *device);
@@ -134,6 +135,9 @@ int device_notify_pincode(struct btd_device *device, gboolean secure, const char *pincode);void device_cancel_authentication (struct btd_device *device,gboolean aborted);gboolean device_is_authenticating (struct btd_device *device); + +void device_cancel_browse (struct btd_device *device,uint8_t bdaddr_type); +void device_add_connection (struct btd_device *dev,uint8_t bdaddr_type,uint32_t flags); void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type,
@@ -141,6 +145,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type, uint8_t reason);void device_request_disconnect (struct btd_device *device,DBusMessage *msg);bool device_is_disconnecting (struct btd_device *device); +bool device_is_connecting (struct btd_device *device);void device_set_ltk (struct btd_device *device,const uint8_t val[16 ],bool central,uint8_t enc_size); bool btd_device_get_ltk(struct btd_device *device, uint8_t val[16],
@@ -170,6 +175,7 @@ guint device_add_disconnect_watch(struct btd_device *device, disconnect_watch watch, void *user_data, GDestroyNotify destroy);void device_remove_disconnect_watch (struct btd_device *device,guint id); +void device_disconnect_watches_callback (struct btd_device *device);int device_get_appearance (struct btd_device *device,uint16_t *value);void device_set_appearance (struct btd_device *device,uint16_t value);
@@ -184,6 +190,9 @@ void btd_device_set_pnpid(struct btd_device *device, uint16_t source,int device_connect_le (struct btd_device *dev); +DBusMessage *device_connect_profiles (struct btd_device *dev, +uint8_t bdaddr_type,DBusMessage *msg,const char *uuid); +typedef void (*device_svc_cb_t ) (struct btd_device *dev,int err,void *user_data);
@@ -225,3 +234,11 @@ void btd_device_set_conn_param(struct btd_device *device, uint16_t min_interval,void btd_device_foreach_service_data (struct btd_device *dev,bt_device_ad_func_t func,void *data); + +typedef void (*btd_device_service_func_t )(struct btd_service *service, +void *user_data); +void btd_device_foreach_service (struct btd_device *dev, +btd_device_service_func_t func, +void *user_data); +void device_remove_pending_services (struct btd_device *dev, +uint8_t bdaddr_type);
Signature · 1 line
2.42.0
PATCH v6 3/3 client: Add shell cmd for bearer connect/disconnect
In reply to Ye HeThis patch adds shell command for bearer connect/disconnect.
--- client/bluetoothctl.rst | 34 ++++++++++++ client/main.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+)
client/bluetoothctl.rst +34 -0
@@ -296,6 +296,40 @@ needed. :Usage: **> disconnect <dev> [uuid]** +connect-bearer +-------------- + +Connect device with specified bearer. + +This command initiates a bearer-level connection to a remote device. + +By default this command connects the specified bearer (LE or BREDR) +and all profiles that are associated with that bearer and marked as +auto-connectable. Only the profiles bound to the selected bearer +will be considered, profiles on the other bearer are not affected. + +For LE connections an active scan report is required before the connection +can be established. If no advertising report is received before the timeout, +a le-connection-abort-by-local error will be issued. + +:Usage: > connect-bearer <dev> <le/bredr> +:Example: > connect-bearer 1C:48:F9:9D:81:5C le +:Example: > connect-bearer 1C:48:F9:9D:81:5C bredr + +disconnect-bearer +----------------- + +Disconnect device with specified bearer. + +By default this command disconnects all profiles associated with the specified +bearer (LE or BREDR) and then terminates that bearer's link. Only profiles +bound to the selected bearer are affected, profiles on the other bearer remain +connected. + +:Usage: > disconnect-bearer <dev> <le/bredr> +:Example: > disconnect-bearer 1C:48:F9:9D:81:5C le +:Example: > disconnect-bearer 1C:48:F9:9D:81:5C bredr + info ----
client/main.c +141 -0
153 lines not on this page · raw message
Signature · 1 line
2.42.0
Luiz Augusto von Dentz
maintainerRe: [PATCH bluez v6 3/3] client: Add shell cmd for bearer connect/disconnect
Hi,
Quoted 42 lines · On Wed, Nov 26, 2025 at 12:21 AM Ye He via B4 Relay…
From: Ye He <[email protected]>
This patch adds shell command for bearer connect/disconnect.
Signed-off-by Ye He <[email protected]>--- client/bluetoothctl.rst | 34 ++++++++++++ client/main.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+)client/bluetoothctl.rst +23
-0@@ -296,6 +296,40 @@ needed. :Usage: **> disconnect <dev> [uuid]** +connect-bearer +-------------- + +Connect device with specified bearer. + +This command initiates a bearer-level connection to a remote device. + +By default this command connects the specified bearer (LE or BREDR) +and all profiles that are associated with that bearer and marked as +auto-connectable. Only the profiles bound to the selected bearer +will be considered, profiles on the other bearer are not affected. + +For LE connections an active scan report is required before the connection +can be established. If no advertising report is received before the timeout, +a le-connection-abort-by-local error will be issued. + +:Usage: > connect-bearer <dev> <le/bredr> +:Example: > connect-bearer 1C:48:F9:9D:81:5C le +:Example: > connect-bearer 1C:48:F9:9D:81:5C bredr + +disconnect-bearer +----------------- +
client/bluetoothctl.rst needed. · line 331
Quoted 10 lines
client/bluetoothctl.rst +10
-0+Disconnect device with specified bearer. + +By default this command disconnects all profiles associated with the specified +bearer (LE or BREDR) and then terminates that bearer's link. Only profiles +bound to the selected bearer are affected, profiles on the other bearer remain +connected. + +:Usage: > disconnect-bearer <dev> <le/bredr> +:Example: > disconnect-bearer 1C:48:F9:9D:81:5C le +:Example: > disconnect-bearer 1C:48:F9:9D:81:5C bredr
I think it would be better if we do something like le.connect/bredr.connect instead of having to pass the bearer as parameter, this should also help with tab completion since in that case we can make it list just the devices that support the given bearer.
Quoted 168 lines
client/bluetoothctl.rst +0
-0info ----client/main.c +141
-1@@ -2303,6 +2303,141 @@ static void cmd_disconn(int argc, char *argv[]) proxy_address(proxy)); } +static void bearer_connect_reply (DBusMessage *message,void *user_data) +{ +DBusError error; + +dbus_error_init (&error); + +if (dbus_set_error_from_message (&error, message) == TRUE) { +bt_shell_printf ("Failed to connect: %s %s\n" , error.name, + error.message); +dbus_error_free (&error); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Connection successful\n" ); + +return bt_shell_noninteractive_quit (EXIT_SUCCESS ); +} + +static void bearer_disconn_reply (DBusMessage *message,void *user_data) +{ +DBusError error; + +dbus_error_init (&error); + +if (dbus_set_error_from_message (&error, message) == TRUE) { +bt_shell_printf ("Failed to disconnect: %s %s\n" , error.name, + error.message); +dbus_error_free (&error); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Disconnection successful\n" ); + +return bt_shell_noninteractive_quit (EXIT_SUCCESS ); +} + +static void cmd_connect_bearer (int argc,char *argv[]) +{ +const char *type; +GDBusProxy *device; +GDBusProxy *bearer =NULL ; + +if (argc <3 ) { +bt_shell_printf ("Usage: connect-bearer <dev> <le/bredr>\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + device =find_device (argc, argv); +if (!device) { +bt_shell_printf ("Device %s not available\n" , argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + type = argv[2 ]; + +if (strcmp (type,"le" ) !=0 &&strcmp (type,"bredr" ) !=0 ) { +bt_shell_printf ("Invalid bearer type: %s, " +"Usage: connect-bearer <dev> <le/bredr>\n" , type); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (!strcmp (type,"bredr" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.BREDR1" ); +else if (!strcmp (type,"le" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.LE1" ); + +if (!bearer) { +bt_shell_printf ("No bearer(%s) on device %s\n" , type, argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (g_dbus_proxy_method_call (bearer,"Connect" ,NULL , + bearer_connect_reply,NULL ,NULL ) == FALSE) { +bt_shell_printf ("Failed to call bearer Connect\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Attempting to connect bearer(%s) to %s\n" , + type, argv[1 ]); +} + +static void cmd_disconnect_bearer (int argc,char *argv[]) +{ +const char *type; +GDBusProxy *device; +GDBusProxy *bearer =NULL ; + +if (argc <3 ) { +bt_shell_printf ("Usage: disconnect-bearer <dev> <le/bredr>\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + device =find_device (argc, argv); +if (!device) { +bt_shell_printf ("Device %s not available\n" , argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + type = argv[2 ]; + +if (strcmp (type,"le" ) !=0 &&strcmp (type,"bredr" ) !=0 ) { +bt_shell_printf ("Invalid bearer type: %s, " +"Usage: disconnect-bearer <dev> <le/bredr>\n" , type); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (!strcmp (type,"bredr" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.BREDR1" ); +else if (!strcmp (type,"le" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.LE1" ); + +if (!bearer) { +bt_shell_printf ("No bearer(%s) on device %s\n" , type, argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (g_dbus_proxy_method_call (bearer,"Disconnect" ,NULL , + bearer_disconn_reply,NULL ,NULL ) == FALSE) { +bt_shell_printf ("Failed to call bearer Disconnect\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Attempting to disconnect bearer(%s) from %s\n" , + type, + argv[1 ]); +} +static void cmd_wake (int argc,char *argv[]) {GDBusProxy *proxy;@@ -3528,6 +3663,12 @@ static const struct bt_shell_menu main_menu = { {"disconnect" ,"[dev] [uuid]" , cmd_disconn,"Disconnect a device or optionally disconnect " "a single profile only", dev_generator }, + { "connect-bearer", "<dev> <le/bredr>", cmd_connect_bearer, +"Connect a specific bearer on a device" , + dev_generator }, + { "disconnect-bearer", "<dev> <le/bredr>", cmd_disconnect_bearer, +"Disconnect a specific bearer on a device" , + dev_generator }, { "wake", "[dev] [on/off]", cmd_wake, "Get/Set wake support", dev_generator }, { "bearer", "<dev> [last-seen/bredr/le]", cmd_bearer, --2.42.0
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH bluez v6 3/3] client: Add shell cmd for bearer connect/disconnect
Hi Luiz,
Quoted 55 lines
[ EXTERNAL EMAIL ]
Hi,
Quoted 49 lines · On Wed, Nov 26, 2025 at 12:21 AM Ye He via B4 Relay…
From: Ye He <[email protected]>
This patch adds shell command for bearer connect/disconnect.
Signed-off-by Ye He <[email protected]>--- client/bluetoothctl.rst | 34 ++++++++++++ client/main.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+)client/bluetoothctl.rst +31
-0@@ -296,6 +296,40 @@ needed. :Usage: **> disconnect <dev> [uuid]** +connect-bearer +-------------- + +Connect device with specified bearer. + +This command initiates a bearer-level connection to a remote device. + +By default this command connects the specified bearer (LE or BREDR) +and all profiles that are associated with that bearer and marked as +auto-connectable. Only the profiles bound to the selected bearer +will be considered, profiles on the other bearer are not affected. + +For LE connections an active scan report is required before the connection +can be established. If no advertising report is received before the timeout, +a le-connection-abort-by-local error will be issued. + +:Usage: > connect-bearer <dev> <le/bredr> +:Example: > connect-bearer 1C:48:F9:9D:81:5C le +:Example: > connect-bearer 1C:48:F9:9D:81:5C bredr + +disconnect-bearer +----------------- + +Disconnect device with specified bearer. + +By default this command disconnects all profiles associated with the specified +bearer (LE or BREDR) and then terminates that bearer's link. Only profiles +bound to the selected bearer are affected, profiles on the other bearer remain +connected. + +:Usage: > disconnect-bearer <dev> <le/bredr>
Quoted 8 lines
client/bluetoothctl.rst needed. · line 331
Quoted 2 lines
client/bluetoothctl.rst +2
-0+:Example: > disconnect-bearer 1C:48:F9:9D:81:5C le +:Example: > disconnect-bearer 1C:48:F9:9D:81:5C bredrI think it would be better if we do something like le.connect/bredr.connect instead of having to pass the bearer as parameter, this should also help with tab completion since in that case we can make it list just the devices that support the given bearer.
That's fine, thanks for your suggestion. I will rework it in V7.
Quoted 171 lines
Quoted 164 lines
client/bluetoothctl.rst +0
-0info ----client/main.c +141
-1@@ -2303,6 +2303,141 @@ static void cmd_disconn(int argc, char *argv[]) proxy_address(proxy)); } +static void bearer_connect_reply (DBusMessage *message,void *user_data) +{ +DBusError error; + +dbus_error_init (&error); + +if (dbus_set_error_from_message (&error, message) == TRUE) { +bt_shell_printf ("Failed to connect: %s %s\n" , error.name, + error.message); +dbus_error_free (&error); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Connection successful\n" ); + +return bt_shell_noninteractive_quit (EXIT_SUCCESS ); +} + +static void bearer_disconn_reply (DBusMessage *message,void *user_data) +{ +DBusError error; + +dbus_error_init (&error); + +if (dbus_set_error_from_message (&error, message) == TRUE) { +bt_shell_printf ("Failed to disconnect: %s %s\n" , error.name, + error.message); +dbus_error_free (&error); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Disconnection successful\n" ); + +return bt_shell_noninteractive_quit (EXIT_SUCCESS ); +} + +static void cmd_connect_bearer (int argc,char *argv[]) +{ +const char *type; +GDBusProxy *device; +GDBusProxy *bearer =NULL ; + +if (argc <3 ) { +bt_shell_printf ("Usage: connect-bearer <dev> <le/bredr>\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + device =find_device (argc, argv); +if (!device) { +bt_shell_printf ("Device %s not available\n" , argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + type = argv[2 ]; + +if (strcmp (type,"le" ) !=0 &&strcmp (type,"bredr" ) !=0 ) { +bt_shell_printf ("Invalid bearer type: %s, " +"Usage: connect-bearer <dev> <le/bredr>\n" , type); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (!strcmp (type,"bredr" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.BREDR1" ); +else if (!strcmp (type,"le" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.LE1" ); + +if (!bearer) { +bt_shell_printf ("No bearer(%s) on device %s\n" , type, argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (g_dbus_proxy_method_call (bearer,"Connect" ,NULL , + bearer_connect_reply,NULL ,NULL ) == FALSE) { +bt_shell_printf ("Failed to call bearer Connect\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Attempting to connect bearer(%s) to %s\n" , + type, argv[1 ]); +} + +static void cmd_disconnect_bearer (int argc,char *argv[]) +{ +const char *type; +GDBusProxy *device; +GDBusProxy *bearer =NULL ; + +if (argc <3 ) { +bt_shell_printf ("Usage: disconnect-bearer <dev> <le/bredr>\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + device =find_device (argc, argv); +if (!device) { +bt_shell_printf ("Device %s not available\n" , argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + + type = argv[2 ]; + +if (strcmp (type,"le" ) !=0 &&strcmp (type,"bredr" ) !=0 ) { +bt_shell_printf ("Invalid bearer type: %s, " +"Usage: disconnect-bearer <dev> <le/bredr>\n" , type); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (!strcmp (type,"bredr" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.BREDR1" ); +else if (!strcmp (type,"le" )) + bearer =find_proxies_by_iface (default_ctrl->bearers, +g_dbus_proxy_get_path (device), +"org.bluez.Bearer.LE1" ); + +if (!bearer) { +bt_shell_printf ("No bearer(%s) on device %s\n" , type, argv[1 ]); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +if (g_dbus_proxy_method_call (bearer,"Disconnect" ,NULL , + bearer_disconn_reply,NULL ,NULL ) == FALSE) { +bt_shell_printf ("Failed to call bearer Disconnect\n" ); +return bt_shell_noninteractive_quit (EXIT_FAILURE ); + } + +bt_shell_printf ("Attempting to disconnect bearer(%s) from %s\n" , + type, + argv[1 ]); +} +static void cmd_wake (int argc,char *argv[]) {GDBusProxy *proxy;@@ -3528,6 +3663,12 @@ static const struct bt_shell_menu main_menu = { {"disconnect" ,"[dev] [uuid]" , cmd_disconn,"Disconnect a device or optionally disconnect " "a single profile only", dev_generator }, + { "connect-bearer", "<dev> <le/bredr>", cmd_connect_bearer, +"Connect a specific bearer on a device" , + dev_generator }, + { "disconnect-bearer", "<dev> <le/bredr>", cmd_disconnect_bearer, +"Disconnect a specific bearer on a device" , + dev_generator }, { "wake", "[dev] [on/off]", cmd_wake, "Get/Set wake support", dev_generator }, { "bearer", "<dev> [last-seen/bredr/le]", cmd_bearer, --Quoted 4 lines
2.42.0
--
Luiz Augusto von Dentz