Fix GATT over BR/EDR
cover Fix GATT over BR/EDR
We need GATT over BR/EDR to pass PTS qualification of a dual-mode device, and bluetoothd only handled it when the remote opened ATT and both L2CAP MTUs matched:
- the ATT_MTU was our incoming MTU instead of the smaller of the two, so a remote with a smaller MTU never finished discovery (2-3)
- GATT discovery marked the BR/EDR services resolved before SDP had finished (4)
- EATT was connected to the LE address next to a BR/EDR bearer (5)
- LE only profiles (BAP, VCP, MCP, BASS, RAP, ...) attached over BR/EDR (6-7)
- bluetoothd couldn't open ATT over BR/EDR itself (8): it now does on ConnectProfile with the GATT UUID, Connect() is unchanged
btgatt-client gets BR/EDR support (1) to reproduce the MTU case. Tested between two BlueZ boards (Intel BE200 and Broadcom BCM4359) over BR/EDR, next to A2DP.
Simon Mikuda (8):
tools/btgatt-client: Add BR/EDR support shared/att: Use the smaller L2CAP MTU as ATT MTU
device: Don't override the ATT MTU over BR/EDR
device: Don't resolve services on GATT over BR/EDR
gatt-client: Don't connect EATT on an ATT bearer over BR/EDR
profiles: Set the LE bearer for TMAP, GMAP and RAP
device: Don't accept LE profiles over ATT on BR/EDR
device: Connect GATT over BR/EDR with ConnectProfile
profiles/audio/gmap.c | 1 + profiles/audio/tmap.c | 1 + profiles/ranging/rap.c | 1 + src/device.c | 154 ++++++++++++++++++++++++++++++++++++----- src/gatt-client.c | 4 ++ src/shared/att.c | 43 ++++++++++-- tools/btgatt-client.c | 53 +++++++++++--- 7 files changed, 223 insertions(+), 34 deletions(-)
base-commit: 1608f836188610aabeff5a3164169ebe0360e443
Signature · 1 line
2.43.0
PATCH 1/8 tools/btgatt-client: Add BR/EDR support
Add the bredr address type: btgatt-client then connects ATT over the BR/EDR ATT PSM, and -m sets the L2CAP MTU, which is the ATT MTU there.
btgatt-client -t bredr -d 00:11:22:33:44:55 -m 48
--- tools/btgatt-client.c | 53 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-)
tools/btgatt-client.c +42 -11
@@ -1631,8 +1631,8 @@ static void signal_cb(int signum, void *user_data) } } -static int l2cap_le_att_connect (bdaddr_t *src,bdaddr_t *dst,uint8_t dst_type, -int sec) +static int l2cap_att_connect (bdaddr_t *src,bdaddr_t *dst,uint8_t dst_type, +int sec,uint16_t mtu) {int sock;struct sockaddr_l2 srcaddr, dstaddr;
@@ -1644,9 +1644,10 @@ static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,ba2str (src, srcaddr_str);ba2str (dst, dstaddr_str); -printf ("btgatt-client: Opening L2CAP LE connection on ATT " -"channel:\n\t src: %s\n\tdest: %s\n" , - srcaddr_str, dstaddr_str); +printf ("btgatt-client: Opening L2CAP %s connection on ATT " +"channel:\n\t src: %s\n\tdest: %s\n" , + dst_type ==BDADDR_BREDR ?"BR/EDR" :"LE" , + srcaddr_str, dstaddr_str); } sock =socket (PF_BLUETOOTH ,SOCK_SEQPACKET ,BTPROTO_L2CAP );
@@ -1658,7 +1659,8 @@ 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 (BT_ATT_CID ); +if (dst_type !=BDADDR_BREDR ) + srcaddr.l2_cid =htobs (BT_ATT_CID ); srcaddr.l2_bdaddr_type =0 ;bacpy (&srcaddr.l2_bdaddr, src);
@@ -1678,10 +1680,35 @@ static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,return -1 ; } +/* On BR/EDR the ATT MTU is the L2CAP MTU */ +if (dst_type ==BDADDR_BREDR && mtu) { +struct l2cap_options l2o; +socklen_t len =sizeof (l2o); + +memset (&l2o,0 ,sizeof (l2o)); +if (getsockopt (sock,SOL_L2CAP ,L2CAP_OPTIONS , &l2o, + &len) <0 ) { +perror ("Failed to get L2CAP options" ); +close (sock); +return -1 ; + } + + l2o.imtu = mtu; +if (setsockopt (sock,SOL_L2CAP ,L2CAP_OPTIONS , &l2o, + len) <0 ) { +perror ("Failed to set L2CAP MTU" ); +close (sock); +return -1 ; + } + } +/* Set up destination address */ memset (&dstaddr,0 ,sizeof (dstaddr)); dstaddr.l2_family =AF_BLUETOOTH ; - dstaddr.l2_cid =htobs (BT_ATT_CID ); +if (dst_type ==BDADDR_BREDR ) + dstaddr.l2_psm =htobs (BT_ATT_PSM ); +else + dstaddr.l2_cid =htobs (BT_ATT_CID ); dstaddr.l2_bdaddr_type = dst_type;bacpy (&dstaddr.l2_bdaddr, dst);
@@ -1707,8 +1734,10 @@ static void usage(void)printf ("Options:\n" "\t-i, --index <id>\t\tSpecify adapter index, e.g. hci0\n" "\t-d, --dest <addr>\t\tSpecify the destination address\n" -"\t-t, --type [random|public] \tSpecify the LE address type\n" -"\t-m, --mtu <mtu> \t\tThe ATT MTU to use\n" +"\t-t, --type [random|public|bredr] \tSpecify the address " +"type\n" +"\t-m, --mtu <mtu> \t\tThe ATT MTU to use (BR/EDR: the " +"L2CAP MTU)\n" "\t-s, --security-level <sec> \tSet security level (low|medium|" "high|fips)\n" "\t-v, --verbose\t\t\tEnable extra logging\n"
@@ -1783,9 +1812,11 @@ int main(int argc, char *argv[]) dst_type =BDADDR_LE_RANDOM ; else if (strcmp(optarg, "public") == 0) dst_type =BDADDR_LE_PUBLIC ; + else if (strcmp(optarg, "bredr") == 0) + dst_type =BDADDR_BREDR ; else {fprintf (stderr, -"Allowed types: random, public\n" ); +"Allowed types: random, public, bredr\n" );return EXIT_FAILURE ; }break ;
@@ -1841,7 +1872,7 @@ int main(int argc, char *argv[])mainloop_init (); - fd =l2cap_le_att_connect (&src_addr, &dst_addr, dst_type, sec); + fd =l2cap_att_connect (&src_addr, &dst_addr, dst_type, sec, mtu);if (fd <0 )return EXIT_FAILURE ;
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/series/1220975/
---Test result---
Test Summary:
CheckPatch PASS 2.82 seconds GitLint PASS 1.97 seconds BuildEll PASS 14.31 seconds BluezMake PASS 183.27 seconds MakeCheck PASS 3.22 seconds MakeDistcheck PASS 105.60 seconds CheckValgrind PASS 103.84 seconds CheckSmatch PASS 191.69 seconds bluezmakeextell PASS 67.26 seconds TestFunctional PASS 938.33 seconds IncrementalBuild PASS 223.50 seconds ScanBuild PASS 659.07 seconds
https://github.com/bluez/bluez/pull/2907
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi Simon,
Quoted 27 lines · On Tue, Nov 24, 2026 at 3:44 PM <[email protected]> wrote:
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/series/1220975/---Test result---
Test Summary:
CheckPatch PASS 2.82 seconds GitLint PASS 1.97 seconds BuildEll PASS 14.31 seconds BluezMake PASS 183.27 seconds MakeCheck PASS 3.22 seconds MakeDistcheck PASS 105.60 seconds CheckValgrind PASS 103.84 seconds CheckSmatch PASS 191.69 seconds bluezmakeextell PASS 67.26 seconds TestFunctional PASS 938.33 seconds IncrementalBuild PASS 223.50 seconds ScanBuild PASS 659.07 seconds
Quoted 1 line
Copilot flagged 1 issue:
https://github.com/bluez/bluez/pull/2907#pullrequestreview-6046550224
Quoted 4 lines
---
Regards,
Linux Bluetooth
Signature · 1 line
Luiz Augusto von Dentz
PATCH 2/8 shared/att: Use the smaller L2CAP MTU as ATT MTU
In reply to Simon MikudaOn an L2CAP channel with a dynamic CID (BR/EDR, EATT) bt_att uses the outgoing MTU as ATT_MTU and reads into a buffer of that size. The ATT_MTU is the smaller of the two MTUs of the channel (Core Vol 3, Part G, 5.1.1 for BR/EDR and 5.3.1 for EATT), and a PDU the remote sends up to our incoming MTU is cut short.
Use the smaller MTU as ATT_MTU, and read up to the incoming MTU.
--- src/shared/att.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-)
src/shared/att.c +36 -7
@@ -53,6 +53,7 @@ struct bt_att_chan {bool in_req;/* There's a pending incoming request */ uint8_t *buf; +uint16_t buf_len;uint16_t mtu; };
@@ -1104,7 +1105,7 @@ static bool can_read_data(struct io *io, void *user_data)uint8_t *pdu;ssize_t bytes_read; - bytes_read =read (chan->fd, chan->buf, chan->mtu); + bytes_read =read (chan->fd, chan->buf, chan->buf_len);if (bytes_read <0 )return false;
@@ -1237,6 +1238,21 @@ static uint16_t io_get_mtu(int fd)return 0 ; } +static uint16_t io_get_imtu (int fd) +{ +socklen_t len; +struct l2cap_options l2o; + + len =sizeof (l2o); +if (!getsockopt (fd,SOL_L2CAP ,L2CAP_OPTIONS , &l2o, &len)) +return l2o.imtu; + +if (!getsockopt (fd,SOL_BLUETOOTH ,BT_RCVMTU , &l2o.imtu, &len)) +return l2o.imtu; + +return 0 ; +} +static uint8_t io_get_type (int fd) {struct sockaddr_l2 src;
@@ -1259,6 +1275,7 @@ static uint8_t io_get_type(int fd)static struct bt_att_chan *bt_att_chan_new (int fd,uint8_t type) {struct bt_att_chan *chan; +uint16_t imtu;if (fd <0 )return NULL ;
@@ -1283,15 +1300,24 @@ static struct bt_att_chan *bt_att_chan_new(int fd, uint8_t type)/* fall through */ case BT_ATT_LE : chan->mtu =BT_ATT_DEFAULT_LE_MTU ; + chan->buf_len = chan->mtu;break ;default : +/* The ATT_MTU of an L2CAP channel is the smaller of its two +* MTUs (Core Vol 3, Part G, 5.1.1 and 5.3.1). Read up to the +* incoming one, as L2CAP lets the remote send that much. +*/ chan->mtu =io_get_mtu (chan->fd); + imtu =io_get_imtu (chan->fd); +if (imtu) + chan->mtu =MIN (chan->mtu, imtu); + chan->buf_len =MAX (chan->mtu, imtu); }if (chan->mtu <BT_ATT_DEFAULT_LE_MTU ) goto fail; - chan->buf =malloc (chan->mtu); + chan->buf =malloc (chan->buf_len);if (!chan->buf) goto fail;
@@ -1487,14 +1513,17 @@ bool bt_att_set_mtu(struct bt_att *att, uint16_t mtu)if (!chan)return -ENOTCONN ; - buf =malloc (mtu); -if (!buf) -return false; +if (mtu > chan->buf_len) { + buf =malloc (mtu); +if (!buf) +return false; -free (chan->buf); +free (chan->buf); + chan->buf = buf; + chan->buf_len = mtu; + } chan->mtu = mtu; - chan->buf = buf;if (chan->mtu > att->mtu) { att->mtu = chan->mtu;
Signature · 1 line
2.43.0
PATCH 3/8 device: Don't override the ATT MTU over BR/EDR
In reply to Simon Mikudadevice_attach_att() sets the ATT_MTU of a BR/EDR channel to our incoming L2CAP MTU, as g_attrib_new() did before commit 9d09a446ace8 ("device:
Use bt_att instead of GAttrib"). The ATT_MTU is the smaller of the two MTUs of the channel (Core Vol 3, Part G, 5.1.1), so when the remote's incoming MTU is smaller, bluetoothd sends PDUs it can't take.
On the remote, paired over BR/EDR:
btgatt-client -t bredr -d <address> -m 48
[GATT client]# services
The discovery never completes, and bluetoothd logs:
bt_att_chan_write() (chan 0x...) write failed: Message too long
bt_att already uses the smaller MTU: leave it.
--- src/device.c | 9 --------- 1 file changed, 9 deletions(-)
src/device.c +0 -9
@@ -6670,14 +6670,12 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)struct bt_att *att;BtIOSecLevel sec_level;uint16_t mtu; -uint16_t cid;struct btd_gatt_database *database;const bdaddr_t *dst;char dstaddr[18 ];bt_io_get (io, &gerr,BT_IO_OPT_SEC_LEVEL , &sec_level,BT_IO_OPT_IMTU , &mtu, -BT_IO_OPT_CID , &cid,BT_IO_OPT_INVALID );if (gerr) {
@@ -6724,13 +6722,6 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)return false; } -if (!bt_att_set_mtu (att, cid ==BT_ATT_CID ?BT_ATT_DEFAULT_LE_MTU : - dev->att_mtu)) { -error ("Unable to set ATT MTU" ); -bt_att_unref (att); -return false; - } -/* The fd is closed once the ATT instance is freed */ g_io_channel_set_close_on_unref (io, FALSE);
Signature · 1 line
2.43.0
PATCH 4/8 device: Don't resolve services on GATT over BR/EDR
In reply to Simon MikudaWhen GATT discovery over BR/EDR completes, gatt_client_ready_cb() calls device_svc_resolved() for device->bdaddr_type. For a BR/EDR device this marks the bearer resolved and runs the device_wait_for_svc_complete() callbacks while SDP may still be running, so they find none of the device's profiles. For a device with an LE address type it resolves the LE bearer instead. iOS opens ATT over BR/EDR right after pairing.
Over BR/EDR, leave resolving the services to SDP.
--- src/device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
src/device.c +8 -3
@@ -6423,12 +6423,15 @@ static void gatt_client_ready_cb(bool success, uint8_t att_ecode, void *user_data) {struct btd_device *device = user_data; +bool bredr =bt_att_get_link_type (device->att) ==BT_ATT_BREDR ;DBG ("status: %s, error: %u" , success ?"success" :"failed" , att_ecode); +/* Over BR/EDR, SDP resolves the services of the bearer */ if (!success) { -device_svc_resolved (device,BROWSE_GATT , device->bdaddr_type, - -EIO ); +if (!bredr) +device_svc_resolved (device,BROWSE_GATT , + device->bdaddr_type, -EIO );return ; }
@@ -6436,7 +6439,9 @@ static void gatt_client_ready_cb(bool success, uint8_t att_ecode,btd_gatt_client_ready (device->client_dbus); -device_svc_resolved (device,BROWSE_GATT , device->bdaddr_type,0 ); +if (!bredr) +device_svc_resolved (device,BROWSE_GATT , device->bdaddr_type, +0 );store_gatt_db (device); }
Signature · 1 line
2.43.0
PATCH 5/8 gatt-client: Don't connect EATT on an ATT bearer over BR/EDR
In reply to Simon MikudaWith Channels set above 1, btd_gatt_client_eatt_connect() connects the EATT channels to the device's LE address also when ATT runs over BR/EDR:
EATT bt_io_connect(<addr>): connect to <addr>: Invalid argument (22)
Only connect EATT channels next to an ATT bearer over LE.
--- src/gatt-client.c | 4 ++++ 1 file changed, 4 insertions(+)
src/gatt-client.c +4 -0
@@ -2361,6 +2361,10 @@ void btd_gatt_client_eatt_connect(struct btd_gatt_client *client)if (bt_att_get_channels (att) == btd_opts.gatt_channels)return ; +/* EATT channels are connected over LE only */ +if (bt_att_get_link_type (att) ==BT_ATT_BREDR ) +return ; +ba2str (device_get_address (dev), addr);for (i =bt_att_get_channels (att); i < btd_opts.gatt_channels; i++) {
Signature · 1 line
2.43.0
PATCH 6/8 profiles: Set the LE bearer for TMAP, GMAP and RAP
In reply to Simon MikudaTMAP and GMAP are LE Audio roles and RAP uses Channel Sounding, which all run over LE only, but unlike the other LE Audio profiles they don't set the bearer.
--- profiles/audio/gmap.c | 1 + profiles/audio/tmap.c | 1 + profiles/ranging/rap.c | 1 + 3 files changed, 3 insertions(+)
profiles/audio/gmap.c +1 -0
@@ -169,6 +169,7 @@ static void gmap_adapter_remove(struct btd_profile *p,static struct btd_profile gmap_profile = { .name ="gmap" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =GMAS_UUID_STR , .device_probe = gmap_probe,
profiles/audio/tmap.c +1 -0
@@ -172,6 +172,7 @@ static void tmap_adapter_remove(struct btd_profile *p,static struct btd_profile tmap_profile = { .name ="tmap" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =TMAS_UUID_STR , .device_probe = tmap_probe,
profiles/ranging/rap.c +1 -0
@@ -1216,6 +1216,7 @@ static void rap_server_remove(struct btd_profile *p,static struct btd_profile rap_profile = { .name ="rap" , .priority =BTD_PROFILE_PRIORITY_MEDIUM , + .bearer =BTD_PROFILE_BEARER_LE , .remote_uuid =RAS_UUID , .local_uuid =RAS_UUID ,
Signature · 1 line
2.43.0
PATCH 7/8 device: Don't accept LE profiles over ATT on BR/EDR
In reply to Simon MikudaWhen ATT runs over BR/EDR, every profile accepts the GATT services found on it, LE only ones included: BAP reads the PACs, VCP, MCP and BASS attach, MCP creates a player and RAP a ChannelSounding1 interface for a device without an LE link.
Skip the profiles of the LE bearer when ATT runs over BR/EDR.
--- src/device.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
src/device.c +16 -4
@@ -4806,6 +4806,19 @@ static bool device_match_profile(struct btd_device *device,return true; } +static void device_accept_gatt_service (struct btd_device *device, +struct btd_service *service) +{ +struct btd_profile *profile =btd_service_get_profile (service); + +/* A profile of the LE bearer doesn't run over ATT on BR/EDR */ +if (profile->bearer ==BTD_PROFILE_BEARER_LE && +bt_att_get_link_type (device->att) ==BT_ATT_BREDR ) +return ; + +service_accept (service,btd_device_is_initiator (device)); +} +static void add_gatt_service (struct gatt_db_attribute *attr,void *user_data) {struct btd_device *device = user_data;
@@ -4845,7 +4858,7 @@ done: }/* Notify driver about the new connection */ -service_accept (service,btd_device_is_initiator (device)); +device_accept_gatt_service (device, service); }
@@ -4907,17 +4920,16 @@ static void device_add_gatt_services(struct btd_device *device)static void device_accept_gatt_profiles (struct btd_device *device) {GSList *l; -bool initiator =btd_device_is_initiator (device);GSList *services; -DBG ("initiator %s" , initiator ?"true" :"false" ); +DBG ("initiator %s" ,btd_device_is_initiator (device) ?"true" :"false" );/* Accept in profile priority order */ services =g_slist_copy (device->services); services =btd_profile_sort_list (services, get_service_profile,NULL );for (l = services; l !=NULL ; l =g_slist_next (l)) -service_accept (l->data, initiator); +device_accept_gatt_service (device, l->data);g_slist_free (services); }
Signature · 1 line
2.43.0
PATCH 8/8 device: Connect GATT over BR/EDR with ConnectProfile
In reply to Simon Mikudabluetoothd runs GATT over BR/EDR only when the remote opens the ATT channel, so the GATT services a BR/EDR device lists in SDP can't be discovered from our side, as the TODO in search_cb() says.
Add a gatt-bredr profile for a device whose SDP has the GATT service:
ConnectProfile and DisconnectProfile with the GATT UUID open and close ATT over BR/EDR, and its state follows an ATT channel the remote opens. It isn't connected automatically, so Connect() works as before.
bluetoothctl connect <address> 00001801-0000-1000-8000-00805f9b34fb
--- src/device.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)
src/device.c +114 -0
@@ -394,6 +394,14 @@ static GSList *find_service_with_uuid(GSList *list, char *uuid)return NULL ; } +/* The GATT service of a BR/EDR device, connected while ATT runs over BR/EDR */ +static struct btd_service *gatt_bredr_service (struct btd_device *dev) +{ +GSList *l =find_service_with_uuid (dev->services,GATT_UUID ); + +return l ? l->data :NULL ; +} +static const char *device_prefer_bearer_str (struct btd_device *device) {/* Check if both BR/EDR and LE bearer are supported */
@@ -6373,6 +6381,7 @@ static void disconnect_gatt_service(gpointer data, gpointer user_data)static void att_disconnected_cb (int err,void *user_data) {struct btd_device *device = user_data; +struct btd_service *service;DBG ("" );
@@ -6399,6 +6408,10 @@ static void att_disconnected_cb(int err, void *user_data)adapter_connect_list_add (device->adapter, device); done: + service =gatt_bredr_service (device); +if (service) +btd_service_disconnecting_complete (service,0 ); +attio_cleanup (device); }
@@ -6774,6 +6787,14 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)gatt_client_init (dev);gatt_server_init (dev, database); +/* ATT over BR/EDR, opened by either side, is the GATT service */ +if (bt_att_get_link_type (dev->att) ==BT_ATT_BREDR ) { +struct btd_service *service =gatt_bredr_service (dev); + +if (service) +btd_service_connecting_complete (service,0 ); + } +/* * Remove the device from the connect_list and give the passive * scanning another chance to be restarted in case there are
@@ -6861,6 +6882,95 @@ done: } } +static void gatt_bredr_connect_cb (GIOChannel *io,GError *gerr, +gpointer user_data) +{ +struct btd_device *dev = user_data; +struct btd_service *service =gatt_bredr_service (dev); + +g_io_channel_unref (dev->att_io); + dev->att_io =NULL ; + +if (gerr) { +DBG ("%s" , gerr->message); +if (service) +btd_service_connecting_complete (service, -EIO ); +return ; + } + +if (!device_attach_att (dev, io) && service) +btd_service_connecting_complete (service, -EIO ); +} + +static int gatt_bredr_probe (struct btd_service *service) +{ +struct btd_device *dev =btd_service_get_device (service); + +/* Only a device that lists the GATT service in SDP */ +if (!btd_device_get_record (dev,GATT_UUID )) +return -ENOTSUP ; + +return 0 ; +} + +static void gatt_bredr_remove (struct btd_service *service) +{ +} + +static int gatt_bredr_connect (struct btd_service *service) +{ +struct btd_device *dev =btd_service_get_device (service); +GError *gerr =NULL ; +char addr[18 ]; + +/* A device has one ATT bearer, over LE or BR/EDR */ +if (dev->att || dev->att_io) +return -EALREADY ; + +ba2str (&dev->bdaddr, addr); +DBG ("Connection attempt to: %s" , addr); + + dev->att_io =bt_io_connect (gatt_bredr_connect_cb, dev,NULL , &gerr, +BT_IO_OPT_SOURCE_BDADDR , +btd_adapter_get_address (dev->adapter), +BT_IO_OPT_DEST_BDADDR , &dev->bdaddr, +BT_IO_OPT_PSM ,BT_ATT_PSM , +BT_IO_OPT_SEC_LEVEL ,BT_IO_SEC_MEDIUM , +BT_IO_OPT_MTU , btd_opts.gatt_mtu, +BT_IO_OPT_INVALID ); +if (!dev->att_io) { +error ("ATT bt_io_connect(%s): %s" , addr, gerr->message); +g_error_free (gerr); +return -EIO ; + } + +return 0 ; +} + +static int gatt_bredr_disconnect (struct btd_service *service) +{ +struct btd_device *dev =btd_service_get_device (service); + +if (!dev->att ||bt_att_get_link_type (dev->att) !=BT_ATT_BREDR ) +return -ENOTCONN ; + +/* Clean up as on a remote disconnection, which closes the channel */ +att_disconnected_cb (0 , dev); + +return 0 ; +} + +/* GATT over BR/EDR is only connected on request, with ConnectProfile */ +static struct btd_profile gatt_bredr_profile = { + .name ="gatt-bredr" , + .bearer =BTD_PROFILE_BEARER_BREDR , + .remote_uuid =GATT_UUID , + .device_probe = gatt_bredr_probe, + .device_remove = gatt_bredr_remove, + .connect = gatt_bredr_connect, + .disconnect = gatt_bredr_disconnect, +}; +int device_connect_le (struct btd_device *dev) {struct btd_adapter *adapter = dev->adapter;
@@ -8504,11 +8614,15 @@ void btd_device_init(void) dbus_conn =btd_get_dbus_connection (); service_state_cb_id =btd_service_add_state_cb ( service_state_changed,NULL ); + +btd_profile_register (&gatt_bredr_profile); }void btd_device_cleanup (void ) {btd_service_remove_state_cb (service_state_cb_id); + +btd_profile_unregister (&gatt_bredr_profile); }void btd_device_set_volume (struct btd_device *device,int8_t volume)
Signature · 1 line
2.43.0