Bluetooth: Classic: L2CAP Shell
This document describes how to run the Bluetooth Classic L2CAP functionality.
The br l2cap command exposes the Bluetooth Classic L2CAP Shell commands.
Commands
The br l2cap commands:
uart:~$ br l2cap
l2cap - [none]
Subcommands:
register : <psm> <mode: none, ret, fc, eret, stream> [hold_credit]
[mode_optional] [extended_control]
connect : <psm> <mode: none, ret, fc, eret, stream> [hold_credit]
[mode_optional] [extended_control]
disconnect : [none]
send : [number of packets] [length of packet(s)]
credits : [none]
echo : L2CAP BR ECHO commands
connless : L2CAP connectionless commands
The br l2cap echo commands:
uart:~$ br l2cap echo
echo - L2CAP BR ECHO commands
Subcommands:
register : [none]
unregister : [none]
req : <length of data>
rsp : <identifier> <length of data>
The br l2cap connless commands:
uart:~$ br l2cap connless
connless - L2CAP connectionless commands
Subcommands:
register : <psm> [sec level]
unregister : [none]
send : <psm> <length of data>
Connection-oriented L2CAP
[Server] Register L2CAP Server:
When the Bluetooth stack has been initialized (bt init), the L2CAP server can be registered
by calling br l2cap register.
uart:~$ br l2cap register 1001 none
L2CAP psm 4097 registered
[Client] Create L2CAP connection:
The command can only be used after the ACL connection has been established.
uart:~$ br l2cap connect 1001 none
L2CAP connection pending
L2CAP connection is established:
uart:~$
Security changed: XX:XX:XX:XX:XX:XX level 2
Incoming BR/EDR conn 0x20004848
Channel 0x20000b18 connected
It is basic mode
Send L2CAP data to remote:
uart:~$ br l2cap send
Rem 0
L2CAP data is received:
uart:~$
Incoming data channel 0x20000b18 len 200
00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
000000A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
000000B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........|
000000C0: 00 00 00 00 00 00 00 00 |........ |
Disconnect L2CAP connection:
uart:~$ br l2cap disconnect
L2CAP connection is broken:
Channel 0x20000b18 disconnected
L2CAP echo
The echo subcommand provides functionality for L2CAP echo requests and responses in Bluetooth Classic.
The subcommand is controlled by CONFIG_BT_TESTING.
The commands can only be used after the ACL connection has been established.
Listen for L2CAP echo request an L2CAP echo response:
uart:~$ br l2cap echo register
Stop listening for L2CAP echo request an L2CAP echo response:
uart:~$ br l2cap echo unregister
Send L2CAP echo request:
uart:~$ br l2cap echo req 1
Echo request is received:
Incoming ECHO REQ data identifier 4 len 1
00000000: 00 |. |
Send L2CAP echo response:
uart:~$ br l2cap echo rsp 4 1
Echo response is received:
uart:~$
Incoming ECHO RSP data len 1
00000000: 00 |. |
Connectionless L2CAP
The connless subcommand provides functionality for connectionless L2CAP communication in Bluetooth Classic, allowing packet transmission without establishing a L2CAP connection.
The subcommand is controlled by CONFIG_BT_L2CAP_CONNLESS.
The commands can only be used after the ACL connection has been established.
Listen for connectionless L2CAP packets:
uart:~$ br l2cap connless register 1001
Register connectionless callbacks with PSM 0x1001
Send data
uart:~$ br l2cap connless send 1001 1
Sending connectionless data with PSM 0x1001
Connectionless data is received:
Incoming connectionless data psm 0x1001 len 1
00000000: 00 |. |