bt-bredr-profile is a command-line front-end for the BR/EDR profile API (fuchsia.bluetooth.bredr/Profile). The tool supports establishing both L2CAP and RFCOMM channels, and provides an interface for sending data over these channels.
Include bt-bredr-profile in your fx set:
--with //src/connectivity/bluetooth/tools/bt-bredr-profile
Include the tests target in your fx set:
--with //src/connectivity/bluetooth/tools/bt-bredr-profile:tests
Then run fx run-test bt-bredr-profile-tests.
Registers an example RFCOMM-requesting SPP service. Adds a service advertisement and search.
setup-rfcomm
Targets Profile.Connect.
Issuing this command does not automatically connect non-connected peers, and will fail for such peers. bt-cli may be used in conjunction with this tool to control peer connections.
connect-l2cap <peer-id> <psm> <channel-mode> <max-rx-sdu-size> <security-requirements>
peer-id maps to the peer_id field of Connectpsm maps to the psm field of Connectchannel-mode can be one of {basic, ertm}, and maps to the parameters.channel_mode field of Connectmax-rx-sdu-size maps to the parameters.max_rx_sdu_size field of Connectsecurity-requirements can be one of {none, auth, sc, auth-sc}, and maps to the parameters.security_requirements field of Connect.profile> connect-l2cap 75870b2c86d9e801 1 basic 672 none Channel: Id: 0 Mode: Basic Max Tx Sdu Size: 672
Attempts to make an outgoing RFCOMM connection to the service advertised by server-channel on the peer indicated by peer-id.
Issuing this command does not guarantee a successful RFCOMM connection. Users should only attempt to make a connection to a peer whose services have been discovered - the server-channel for any such service will be printed in the REPL.
connect-rfcomm <peer-id> <server-channel>
peer-id maps to the PeerId of the peer.server-channel maps to the Server Channel number of the peer's advertised RFCOMM service.profile> connect-rfcomm 75870b2c86d9e801 1
Drops the socket corresponding to channel-id, which will disconnect the l2cap channel.
disconnect-l2cap <channel-id>
channel-id is an integer assigned to this channel by the REPL. It must correspond to a connected channel listed by the channels command.Drops the socket corresponding to server-channel, which will disconnect the rfcomm channel.
disconnect-rfcomm <server-channel>
server-channel is the Server Channel number assigned to the RFCOMM channel.Prints the assigned Ids of connected L2CAP channels. These Ids are local to the REPL and are only used for indicating which channel to perform operations on in other commands.
channels
profile> channels Channel: Id: 0 Mode: Basic Max Tx Sdu Size: 672
Write data on an L2CAP socket/channel.
write-l2cap <channel-id> <data>
channel-id is an integer assigned to a channel by the REPL. It must correspond to a connected channel listed by the channels command.data is a string of characters that will be written on the channel.Write data on the RFCOMM channel identified by server-channel.
write-rfcomm <server-channel> <data>
server-channel is the integer Server Channel identifying the RFCOMM channel. For channels that were established by the peer, use the identifier printed in the REPL. For channels that were initiated by the tool, use the same identifier as used in the connect-rfcomm command.data is a string of characters that will be written on the channel.Targets Profile.Advertise.
Advertises an L2CAP service with the SDP server. After advertising, a notification will be printed when a peer connects to that service.
advertise <psm> <channel-mode> <max-rx-sdu-size>
For convenience, a valid Audio Sink service definition (with 1 UUID and 1 L2CAP protocol descriptor) is created from just the psm argument.
psm maps to the PSM included in the L2CAP protocol descriptor of the service definition.channel-mode maps to parameters.channel_mode and is {basic|ertm} (which may be abbreviated to their first letter).max-rx-sdu-size maps to parameters.max_rx_sdu_size and is an integer in the range 0 - 65535.profile> advertise 25 ertm 672 Service: Id: 0
Unregisters an L2CAP service from the SDP server, using the id returned by advertise
remove-service <service-id>
service-id is the identifier assigned to the registration after executing the advertise command.Lists services registered with the advertise command.
services
profile> services Service: Id: 0 Mode: Basic Max Rx Sdu Size: 48
Removes all services, closes all open channels, and exits the REPL.