蓝牙连通性l2ping和L2ACP层传输速率稳定性测试l2test

内容分享2周前发布
0 0 0

l2ping:

l2ping 是一个用于测试蓝牙设备连接状态的命令行工具类似ping工具。它通过发送一个L2CAP(逻辑链路控制和适配协议)请求到指定的蓝牙设备,并等待设备的响应来判断设备是否在线和可连接。这个工具在Linux系统中比较常见,特别是在需要调试或验证蓝牙设备连接时超级有用。

以下是l2ping的一些基本用法和参数:

l2ping - L2CAP ping
Usage:
        l2ping [-i device] [-s size] [-c count] [-t timeout] [-d delay] [-f] [-r] [-v] <bdaddr>
        -f  Flood ping (delay = 0)
        -r  Reverse ping
        -v  Verify request and response payload

  • -i:指定hci接口,例如-i 0是指定hci0,默认就是hci0
  • -s:指定ping包大小,默认是44字节
  • -c:指定ping包个数
  • -t:指定最大超时时间,单位是秒
  • -d:指定两个ping包之间的间隔,单位是秒
  • -f:相当于-d 0,ping包之间没有间隔,只要收到应答就发送下一个ping包
  • -r:接收ping包
  • -v:校验发送与接收到的ping包内容
  • :指定目标设备的蓝牙地址,格式为xx:xx:xx:xx:xx:xx

执行这个命令后,l2ping会显示每次ping请求的结果,包括发送时间、接收时间和往返时间(RTT),以及丢包率等信息。

# 实例
root@TinaLinux:/# l2ping -f -s 512 -c 10 -t 1 5C:8A:AE:19:07:69
Ping: 5C:8A:AE:19:07:69 from 5C:8A:AE:19:07:EF (data size 512) ...
512 bytes from 5C:8A:AE:19:07:69 id 0 time 41.07ms
512 bytes from 5C:8A:AE:19:07:69 id 1 time 28.53ms
512 bytes from 5C:8A:AE:19:07:69 id 2 time 28.71ms
512 bytes from 5C:8A:AE:19:07:69 id 3 time 28.80ms
512 bytes from 5C:8A:AE:19:07:69 id 4 time 28.62ms
512 bytes from 5C:8A:AE:19:07:69 id 5 time 28.74ms
512 bytes from 5C:8A:AE:19:07:69 id 6 time 28.64ms
512 bytes from 5C:8A:AE:19:07:69 id 7 time 28.75ms
512 bytes from 5C:8A:AE:19:07:69 id 8 time 28.76ms
512 bytes from 5C:8A:AE:19:07:69 id 9 time 28.58ms
10 sent, 10 received, 0% loss

通过l2ping,你可以快速检查蓝牙设备是否在线、响应是否正常,以及连接的稳定性,是蓝牙设备调试和维护中超级有用的工具。

l2test:

l2test工具用于测试蓝牙L2CAP层的性能,有点类似于iperf工具。(不了解iperf的可以移步)

l2test工具使用的是服务器-客户端模型,基于L2CAP层建立socket连接。测试时,一台设备需作为server,另一台作为client。
下面是测试命令示例,其中-r表明接收模式,-b表明接收多少数据,-s表明发送模式,xx:xx:xx:xx:xx:xx是接收端的地址。

# 服务端
./l2test -r -b 100000 
# 发送端
./l2test -s xx:xx:xx:xx:xx:xx

l2test工具较为灵活,这个例子是服务器接收、客户端连接并发送,也可以改成服务器发送、客户端连接并接收,只需要将-r改为-w,-s改为-u
执行实例:

蓝牙连通性l2ping和L2ACP层传输速率稳定性测试l2test

协助信息如下:

l2test: invalid option --  h 
l2test - L2CAP testing
Usage:
        l2test <mode> [options] [bdaddr]
Modes:
        -r listen and receive
        -w listen and send
        -d listen and dump incoming data
        -x listen, then send, then dump incoming data
        -t listen, then send and receive at the same time
        -q connect, then send and receive at the same time
        -s connect and send
        -u connect and receive
        -n connect and be silent
        -y connect, then send, then dump incoming data
        -c connect, disconnect, connect, ...
        -m multiple connects
        -p trigger dedicated bonding
        -z information request
Options:
        [-b bytes] [-i device] [-P psm] [-J cid]
        [-I imtu] [-O omtu]
        [-L seconds] enable SO_LINGER
        [-W seconds] enable deferred setup
        [-B filename] use data packets from file
        [-N num] send num frames (default = infinite)
        [-C num] send num frames before delay (default = 1)
        [-D milliseconds] delay after sending num frames (default = 0)
        [-K milliseconds] delay before receiving (default = 0)
        [-g milliseconds] delay before disconnecting (default = 0)
        [-X mode] l2cap mode (help for list, default = basic)
        [-a policy] chan policy (help for list, default = bredr)
        [-F fcs] use CRC16 check (default = 1)
        [-Q num] Max Transmit value (default = 3)
        [-Z size] Transmission Window size (default = 63)
        [-Y priority] socket priority
        [-H size] Maximum receive buffer size
        [-R] reliable mode
        [-G] use connectionless channel (datagram)
        [-U] use sock stream
        [-A] request authentication
        [-E] request encryption
        [-S] secure connection
        [-M] become master
        [-T] enable timestamps
        [-V type] address type (help for list, default = bredr)
        [-e seq] initial sequence value (default = 0)

常用命令以及描述:

1.接收数据(-r 模式)

l2test -r -i hci0 -P 1 -I 672 -O 672 5C:8A:AE:19:07:69

  • -i hci0:指定使用的蓝牙设备。

  • -P 1:指定PSM(Protocol/Service Multiplexer)。

  • -I 672-O 672:设置输入和输出MTU(Maximum Transmission Unit)。

  • 5C:8A:AE:19:07:69:远程设备的MAC地址。

2.发送数据(-s 模式)

l2test -s -i hci0 -P 1 -I 672 -O 672 5C:8A:AE:19:07:69 "Hello, Bluetooth!"

  • -s:发送数据模式。

  • "Hello, Bluetooth!":要发送的数据

3.同时发送和接收数据(-q 模式)

l2test -q -i hci0 -P 1 -I 672 -O 672 5C:8A:AE:19:07:69

  • -q:连接后同时发送和接收数据。

高级选项:

  1. 连接、断开、再连接(-c 模式)

    l2test -c -i hci0 -P 1 -I 672 -O 672 5C:8A:AE:19:07:69
    

    • -c:连接、断开、再连接模式。
  1. 多重连接(-m 模式)

    l2test -m -i hci0 -P 1 -I 672 -O 672 5C:8A:AE:19:07:69
    

    • -m:多重连接模式。
  1. 触发专用绑定(-p 模式)

    l2test -p -i hci0 -P 1 -I 672 -O 672 5C:8A:AE:19:07:69
    

    • -p:触发专用绑定模式。

通过这些示例和选项,你可以根据具体需求使用l2test进行各种L2CAP连接测试。

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...