飞凌 OK113i-C 全志T113-i开发板 rtl8723du WIFI 功能测试及蓝牙驱动移植
-
飞凌 OK113i-C 全志T113-i开发板板载一个RTL8723du wifi/蓝牙二合一模块,板子出厂已经移植好了WIFI驱动但是蓝牙驱动没有,所以这篇文章我们主要做蓝牙驱动的移植和功能验证。
./build.sh menuconfig
在
Device Drivers > Network device support > Wireless LAN
下找到Realtek 8723D USB WiFi
选项。
默认是开启的。默认wifi驱动联网尝试
wpa_supplicant -Dnl80211 -iwlan0 -c /etc/wpa_supplicant.conf -B udhcpc -i wlan0 udhcpc: started, v1.29.3 udhcpc: sending discover udhcpc: sending select for 192.168.0.111 udhcpc: lease of 192.168.0.111 obtained, lease time 7200 deleting routers adding dns 192.168.1.1 adding dns 192.168.0.1
wpa_supplicant.conf 文件
network={ ssid="TP-LINK_142C" psk="123445678" } update_config=1 ctrl_interface=DIR=/var/run/wpa_supplicant
打印网卡信息:
ifconfig eth0 Link encap:Ethernet HWaddr BA:E9:F2:1C:9D:87 inet addr:192.168.0.232 Bcast:0.0.0.0 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:39 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:41 errors:0 dropped:0 overruns:0 frame:0 TX packets:41 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3936 (3.8 KiB) TX bytes:3936 (3.8 KiB) wlan0 Link encap:Ethernet HWaddr 2C:C3:E6:67:4D:3B inet addr:192.168.0.111 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::2ec3:e6ff:fe67:4d3b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:86 errors:0 dropped:0 overruns:0 frame:0 TX packets:19 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17189 (16.7 KiB) TX bytes:3763 (3.6 KiB)
至此,wifi连接路由器成功,可以ping 百度验证是否联网成功。
蓝牙功能
首先打印设备上的蓝牙设备
hciconfig -a
输出为空,应该是没有蓝牙驱动。看来出厂并没有带蓝牙驱动,下一步自行移植蓝牙驱动,板上的无线芯片模组使用的是rtl8723du是一款bt4.2和 wifi 2.4G芯片。
蓝牙驱动移植
- 修改kernel config
修改OK113i-linux-sdk/kernel/linux-5.4/arch/arm/configs/OK113I_linux_defconfig
文件添加如下一行
CONFIG_BT_HCIBTUSB_RTLBTUSB=m
- 修改Kconfig
添加如下:
config BT_HCIBTUSB_RTLBTUSB tristate "Realtek HCI USB driver support" depends on USB help Realtek Bluetooth HCI USB driver. This driver is required if you want to use Realtek Bluetooth device with USB interface. Say Y here to compile support for Bluetooth USB devices into the kernel or say M to compile it as module (rtk_btusb).
- 修改Makefile
在文档最后添加:
obj-$(CONFIG_BT_HCIBTUSB_RTLBTUSB) := rtk_btusb.o rtk_btusb-objs := rtk_bt.o rtk_misc.o rtk_coex.o
- 将驱动文件中如下文件复制到内核目录
OK113i-linux-sdk/kernel/linux-5.4/drivers/bluetooth
下:
rtk_bt.c rtk_bt.h rtk_coex.c rtk_coex.h rtk_misc.c rtk_misc.h
- 编译内核驱动
./build.sh kernel
编译完成后会在
OK113i-linux-sdk/out/t113_i/ok113i/longan/dist
目录下生成rtk_btusb.ko
驱动文件,将该驱动文件和驱动文件对应的固件文件(rtl8723du_fw.bin和rtl8723du_config.bin)放在板子/lib/firmware/
下为了方便查看驱动加载过程报错信息,打开内核打印信息:
echo 8 4 1 7 > /proc/sys/kernel/printk
将编译好的驱动文件和固件文件上传到板卡上,并将估计文件存放在板卡
/lib/firmware
目录下。scp out/t113_i/ok113i/longan/dist/rtk_btusb.ko root@192.168.0.105:/home/forlinx/ scp /home/luoyang/Documents/Dev/Bluetooth/V4-8761蓝牙_Linux驱动/20210819_LINUX_BT_DRIVER/rtkbt-firmware/lib/firmware/rtl8723du* root@192.168.0.105:/home/forlinx/ cp rtl8723du_config /lib/firmware/rtl8723du_config.bin cp rtl8723du_fw /lib/firmware/rtl8723du_fw.bin
加载驱动试试,报错:
insmod rtk_btusb.ko [ 4832.222554] rtk_btusb: module uses symbol (kernel_read) from namespace VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver, but does not import it. [ 4832.238042] rtk_btusb: Unknown symbol kernel_read (err -22) [ 4832.298908] rtk_btusb: module uses symbol (kernel_read) from namespace VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver, but does not import it. [ 4832.314387] rtk_btusb: Unknown symbol kernel_read (err -22) insmod: can't insert 'rtk_btusb.ko': Invalid argument
在rtk_bt.c文件最后一行添加:
MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
重新编译驱动,然后上传并加载试试。
root@ok113i:/home/forlinx# insmod rtk_btusb.ko [ 7964.303169] rtk_btusb: Realtek Bluetooth USB driver ver 3.1.32e1d0b.20210819-170430 [ 7964.311850] rtk_btcoex: rtk_btcoex_init: version: 1.2 [ 7964.317513] rtk_btcoex: create workqueue [ 7964.322343] rtk_btcoex: alloc buffers 1408, 2240 for ev and l2 [ 7964.329075] rtk_btusb: btusb_probe intf->cur_altsetting->desc.bInterfaceNumber 0 [ 7964.337365] rtk_btusb: btusb_probe can_wakeup 1, may wakeup 0 [ 7964.343827] rtk_btusb: patch_add [ 7964.347451] rtk_btusb: auto suspend is disabled [ 7964.352568] rtk_btusb: pid = 0xd723 [ 7964.356478] rtk_btusb: patch_add: Reset gEVersion to 0xff [ 7964.362590] rtk_btusb: set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); [ 7964.370965] rtk_btusb: btusb_probe: done [ 7964.375679] usbcore: registered new interface driver rtk_btusb [ 7964.377514] rtk_btusb: btusb_open start [ 7964.386578] rtk_btusb: btusb_open hdev->promisc ==0 [ 7964.392129] rtk_btusb: download_patch start root@ok113i:/home/forlinx# [ 7964.396839] rtk_btusb: chip type value: 0x71 [ 7964.403997] rtk_btusb: HCI reset. [ 7964.416814] rtk_btusb: read_ver_rsp->lmp_subver = 0x8723 [ 7964.423054] rtk_btusb: read_ver_rsp->hci_rev = 0xd [ 7964.428449] rtk_btusb: patch_entry->lmp_sub = 0x8723 [ 7964.434017] rtk_btusb: load_firmware start [ 7964.438638] rtk_btusb: lmp_version = 0x8723 [ 7964.443325] rtk_btusb: config filename rtl8723du_config [ 7964.449952] rtk_btusb: no bdaddr file /opt/bdaddr [ 7964.455252] rtk_btusb: Origin cfg len 22 [ 7964.459688] rtk_btusb: 55 ab 23 87 10 00 d9 00 01 0f e4 00 01 08 8d 00 [ 7964.467005] rtk_btusb: 01 fa 8f 00 01 bf [ 7964.471497] rtk_btusb: New cfg len 22 [ 7964.475600] rtk_btusb: 55 ab 23 87 10 00 d9 00 01 0f e4 00 01 08 8d 00 [ 7964.482969] rtk_btusb: 01 fa 8f 00 01 bf [ 7964.487399] rtk_btusb: fw name is rtl8723du_fw [ 7964.492801] rtk_btusb: This is not 8723a, use new patch style! [ 7964.499374] rtk_btusb: rtk_get_eversion: gEVersion 255 [ 7964.505815] rtk_btusb: eversion->status = 0x0, eversion->version = 0x2 [ 7964.513566] rtk_btusb: load_firmware: New gEVersion 2 [ 7964.519331] rtk_btusb: rtk_get_fw_project_id: opcode 0, len 1, data 9 [ 7964.526565] rtk_btusb: lmp_version is 8723, project_id is 8723, match! [ 7964.533909] rtk_btusb: fw_version = 0x82a8a133 [ 7964.538921] rtk_btusb: number_of_total_patch = 3 [ 7964.544092] rtk_btusb: chipID 3 [ 7964.547606] rtk_btusb: patch_length 0x889c [ 7964.552220] rtk_btusb: start_offset 0x00004940 [ 7964.557198] rtk_btusb: Svn version: -1433992835 [ 7964.562301] rtk_btusb: Coexistence: BTCOEX_20210106-3b3b [ 7964.568274] rtk_btusb: buf_len = 0x88b2 [ 7964.572647] rtk_btusb: fw: exists, config file: exists [ 7964.578430] rtk_btusb: load_firmware done [ 7964.582960] rtk_btusb: download_data start [ 7964.855824] rtk_btusb: download_data done [ 7964.860346] rtk_btusb: HCI reset. [ 7964.873812] rtk_btusb: read_ver_rsp->lmp_subver = 0xa133 [ 7964.880054] rtk_btusb: read_ver_rsp->hci_rev = 0x82a8 [ 7964.885730] rtk_btusb: patch_entry->lmp_sub = 0x8723 [ 7964.891337] rtk_btusb: Rtk patch end 0 [ 7964.895538] rtk_btusb: btusb_open set HCI_RUNNING [ 7964.900945] rtk_btcoex: Open BTCOEX [ 7964.904856] rtk_btusb: btusb_open end [ 7964.911832] rtk_btcoex: BTCOEX hci_rev 0x82a8 [ 7964.916883] rtk_btcoex: BTCOEX lmp_subver 0xa133 [ 7964.943829] rtk_btusb: btusb_notify: hci0 evt 3 [ 7967.007992] rtk_btusb: btusb_flush add delay [ 7967.022915] rtk_btusb: btusb_close [ 7967.045574] rtk_btcoex: Close BTCOEX [ 7967.049615] rtk_btcoex: -x
以上信息说明蓝牙驱动加载成功。
此时,再一次查看系统的蓝牙设备信息会打印如下:root@ok113i:/home/forlinx# hciconfig -a hci0: Type: Primary Bus: USB BD Address: 2C:C3:E6:67:4D:3C ACL MTU: 1021:8 SCO MTU: 255:12 DOWN RX bytes:584 acl:0 sco:0 events:30 errors:0 TX bytes:369 acl:0 sco:0 commands:30 errors:0 Features: 0xff 0xff 0xff 0xfa 0xdb 0xbd 0x7b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH HOLD SNIFF PARK Link mode: SLAVE ACCEPT
蓝牙工具软件使用
蓝牙驱动安装成功后就可以对蓝牙设备进行配对连接并进行播放音频操作了,此处我们选择通过蓝牙连接家里的智能音箱天猫精灵作为蓝牙音频输出设备,涉及的蓝牙工具软件开发板上出厂移植好了,所以此处省去了移植这些工具软件的步骤。
- 启动系统蓝牙服务
bluetoothd
,使其在后台运行
bluetoothd -d -n & root@ok113i:/# bluetoothd[1516]: Bluetooth daemon 5.50 bluetoothd[1516]: src/adapter.c:adapter_init() sending read version command bluetoothd[1516]: Starting SDP server bluetoothd[1516]: src/sdpd-service.c:register_device_id() Adding device id record for 0002:1d6b:0246:0532 bluetoothd[1516]: src/plugin.c:plugin_init() Loading builtin plugins bluetoothd[1516]: src/plugin.c:add_plugin() Loading hostname plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading wiimote plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading autopair plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading policy plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading neard plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading sap plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading a2dp plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading avrcp plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading network plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading input plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading hog plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading health plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading gap plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading scanparam plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading deviceinfo plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading midi plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading battery plugin bluetoothd[1516]: src/plugin.c:plugin_init() Loading plugins /usr/lib/bluetooth/plugins bluetoothd[1516]: src/plugin.c:add_plugin() Loading sixaxis plugin bluetoothd[1516]: profiles/health/hdp.c:hdp_manager_start() Starting Health manager bluetoothd[1516]: profiles/input/suspend-none.c:suspend_init() bluetoothd[1516]: profiles/network/manager.c:read_config() Config options: Security=true bluetoothd[1516]: kernel lacks bnep-protocol support bluetoothd[1516]: System does not support network plugin bluetoothd[1516]: plugins/neard.c:neard_init() Setup neard plugin bluetoothd[1516]: plugins/sixaxis.c:sixaxis_init() bluetoothd[1516]: src/main.c:main() Entering main loop bluetoothd[1516]: src/rfkill.c:rfkill_event() RFKILL event idx 0 type 1 op 0 soft 0 hard 0 bluetoothd[1516]: Bluetooth management interface 1.14 initialized bluetoothd[1516]: src/adapter.c:read_version_complete() sending read supported commands command bluetoothd[1516]: src/adapter.c:read_version_complete() sending read index list command bluetoothd[1516]: src/adapter.c:read_commands_complete() Number of commands: 65 bluetoothd[1516]: src/adapter.c:read_commands_complete() Number of events: 35 bluetoothd[1516]: src/adapter.c:read_commands_complete() enabling kernel-side connection control bluetoothd[1516]: src/adapter.c:read_index_list_complete() Number of controllers: 0 root@ok113i:/#
- 通过
bluetoothctl
对蓝牙设备操作,主要包括:蓝牙设备信息打印查看,蓝牙设备开启和关闭、蓝牙外设扫描、查看扫描到的蓝牙外设设备、配对连接等,下面实例命令行中##
开头的行是注释
## 进入bluetoothctl root@ok113i:/# bluetoothctl bluetoothd[1516]: src/agent.c:agent_ref() 0x8c9338: ref=1 bluetoothd[1516]: src/agent.c:register_agent() agent :1.1 Agent registered ## 蓝牙设备信息打印查看 [bluetooth]#show Controller 2C:C3:E6:67:4D:3C (public) Name: BlueZ 5.50 Alias: BlueZ 5.50 Class: 0x00000000 Powered: no Discoverable: no Pairable: yes UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb) UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb) Modalias: usb:v1D6Bp0246d0532 Discovering: no ## 蓝牙设备开启和关闭 [bluetooth]#power on [bluetooth]# [ 417.686414] rtk_btusb: btusb_open start bluetoothd[1516]: src/adapter.c:[ 417.691880] rtk_btusb: btusb_open hdev->promisc ==0 property_set_mode() sending Set [ 417.700202] rtk_btusb: download_patch start Powered command for index 0 [ 417.707637] rtk_btusb: chip type value: 0x71 [ 417.714939] rtk_btusb: HCI reset. [ 417.727699] rtk_btusb: read_ver_rsp->lmp_subver = 0xa133 [ 417.733654] rtk_btusb: read_ver_rsp->hci_rev = 0x82a8 [ 417.739344] rtk_btusb: patch_entry->lmp_sub = 0x8723 [ 417.744905] rtk_btusb: Firmware already exists [ 417.749914] rtk_btusb: Rtk patch end 1 [ 417.754125] rtk_btusb: btusb_open set HCI_RUNNING [ 417.759504] rtk_btcoex: Open BTCOEX [ 417.763412] rtk_btusb: btusb_open end [ 417.769720] rtk_btcoex: BTCOEX hci_rev 0x82a8 [ 417.774656] rtk_btcoex: BTCOEX lmp_subver 0xa133 bluetoothd[1516]: src/adapter.c:property_set_mode_complete() Success (0x00) bluetoothd[1516]: src/adapter.c:new_settings_callback() Settings: 0x00000ad1 bluetoothd[1516]: src/adapter.c:settings_changed() Changed settings: 0x00000001 bluetoothd[1516]: src/adapter.c:adapter_start() adapter /org/bluez/hci0 has been enabled bluetoothd[1516]: src/adapter.c:trigger_passive_scanning() Changing power on succeeded [CHG] Controller 2C:C3:E6:67:4D:3C Powered: yes ## 蓝牙设备开启和关闭 [bluetooth]#scan on [bluetooth]#scan off ## 查看扫描到的蓝牙外设设备 [bluetooth]#devices Device F1:22:33:1A:48:9B F1-22-33-1A-48-9B Device C4:DE:E2:DF:E8:22 Keep_CC_50200973 Device 34:29:EF:5B:D2:D3 34-29-EF-5B-D2-D3 Device E8:F5:63:87:03:9D Mi Band 3 Device B8:8C:29:87:72:C9 midea Device 04:7F:0E:40:4A:BD BEIJING-EU5 Device CC:B5:D1:FB:45:3A SMI-M14 Device 45:B8:CC:87:53:F8 45-B8-CC-87-53-F8 Device 84:7C:9B:6D:FF:11 midea_db_2943 Device 10:9E:3A:92:2E:DA �方�糖(80:7A) ## 配对连接 [bluetooth]#connect 10:9E:3A:92:2E:DA Attempting to connect to 10:9E:3A:92:2E:DA bluetoothd[1516]: src/device.c:connect_profiles() /org/bluez/hci0/dev_10_9E_3A_92_2E_DA (all), client :1.2 bluetoothd[1516]: profiles/audio/a2dp.c:a2dp_sink_connect() path /org/bluez/hci0/dev_10_9E_3A_92_2E_DA bluetoothd[1516]: a2dp-sink profile connect failed for 10:9E:3A:92:2E:DA: Protocol not available Failed to connect: org.bluez.Error.Failed
报错了,因为没有提前运行
bluealsa
这个程序,运行如下:bluealsa -p a2dp-source & [2] 1537 root@ok113i:/home/forlinx# bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_register_sep() SEP 0x8cc378 registered: type:0 codec:2 seid:1 bluetoothd[1516]: src/adapter.c:adapter_service_add() /org/bluez/hci0 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10003 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000019-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000110a-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000110d-0000-1000-8000-00805f9 bluetoothd[1516]: src/adapter.c:adapter_service_insert() /org/bluez/hci0 bluetoothd[1516]: src/adapter.c:add_uuid() sending add uuid command for index 0 bluetoothd[1516]: Endpoint registered: sender=:1.3 path=/A2DP/MPEG24/Source/1 bluetoothd[1516]: src/adapter.c:dev_class_changed_callback() Class: 0x080000 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_register_sep() SEP 0x8c63f0 registered: type:0 codec:0 seid:2 bluetoothd[1516]: Endpoint registered: sender=:1.3 path=/A2DP/SBC/Source/1
至此,再进入bluetoothctl 连接天猫精灵试试,首先输入
devices
命令打印出扫描到的设备信息,然后使用connect xx:xx:xx:xx:xx:xx
连接上想要连接的蓝牙设备,连接成功后提示符会变成[连接的设备]
样式,具体如下:[bluetooth]#devices Device F1:22:33:1A:48:9B F1-22-33-1A-48-9B Device C4:DE:E2:DF:E8:22 Keep_CC_50200973 Device 34:29:EF:5B:D2:D3 34-29-EF-5B-D2-D3 Device E8:F5:63:87:03:9D Mi Band 3 Device B8:8C:29:87:72:C9 midea Device 04:7F:0E:40:4A:BD BEIJING-EU5 Device CC:B5:D1:FB:45:3A SMI-M14 Device 45:B8:CC:87:53:F8 45-B8-CC-87-53-F8 Device 84:7C:9B:6D:FF:11 midea_db_2943 Device 10:9E:3A:92:2E:DA �方�糖(80:7A) [bluetooth]#connect 10:9E:3A:92:2E:DA ... [�方�糖(80:7A)]# list Controller 2C:C3:E6:67:4D:3C BlueZ 5.50 [default] ## 退出bluetoothctl程序 [�方�糖(80:7A)]# exit
- 蓝牙音频播放
因为此处我们使用alsa-utils
工具集中的 aplay 进行音频播放测试,所以仅仅支持PCM
和WAV
等音频格式,要是想直接播放 mp3 或者 mp4 等格式音频文件需要借助MPD
或者FFmpeg
等软件。
上一步我们在bluetoothctl中打印扫描并连接了蓝牙音箱,蓝牙音箱的设备地址如下:
[bluetooth]#devices Device F1:22:33:1A:48:9B F1-22-33-1A-48-9B Device C4:DE:E2:DF:E8:22 Keep_CC_50200973 Device 34:29:EF:5B:D2:D3 34-29-EF-5B-D2-D3 Device E8:F5:63:87:03:9D Mi Band 3 Device B8:8C:29:87:72:C9 midea Device 04:7F:0E:40:4A:BD BEIJING-EU5 Device CC:B5:D1:FB:45:3A SMI-M14 Device 45:B8:CC:87:53:F8 45-B8-CC-87-53-F8 Device 84:7C:9B:6D:FF:11 midea_db_2943 Device 10:9E:3A:92:2E:DA �方�糖(80:7A)
根据上面信息我们可以看到天猫精灵方糖的蓝牙设备地址是
10:9E:3A:92:2E:DA
,所以我们可以使用如下命令进行音频播放测试:root@ok113i:/# aplay -D bluealsa:DEV=10:9E:3A:92:2E:DA ./wishforyou.wav Playing WAVE './wishforyou.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo bluetoothd[1516]: profiles/audio/transport.c:media_owner_create() Owner created: sender=:1.3 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_ref() 0x8cf3c0: ref=2 bluetoothd[1516]: profiles/audio/a2dp.c:a2dp_sep_lock() SEP 0x8c63f0 locked bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_ref() 0x8cf3c0: ref=3 bluetoothd[1516]: profiles/audio/a2dp.c:setup_ref() 0x8ccad0: ref=1 bluetoothd[1516]: profiles/audio/transport.c:transport_set_state() State changed /org/bluez/hci0/dev_10_9E_3A_92_2E_DA/fd0: TRANSPORT_STATE_IDLE -> TRANSPORT_STATE_REQUESTING bluetoothd[1516]: profiles/audio/transport.c:media_request_create() Request created: method=Acquire id=4 bluetoothd[1516]: profiles/audio/transport.c:media_owner_add() Owner :1.3 Request Acquire bluetoothd[1516]: profiles/audio/transport.c:media_transport_set_owner() Transport /org/bluez/hci0/dev_10_9E_3A[ 1901.267056] rtk_btcoex: update_profile_state: btrtl_coex.prof4 _92_2E_DA/fd0 Owner :1.3 blueto[ 1901.276315] rtk_btcoex: update_profile_state: btrtl_coex.profile_status = 4 othd[1516]: profiles/audio/avdtp[ 1901.287222] rtk_btcoex: rtk_notify_profileinfo_to_fw: BufferSize 5 .c:session_cb() bluetoothd[151[ 1901.296656] rtk_btcoex: rtk_notify_profileinfo_to_fw: NumberOfHandles 1 6]: profiles/audio/avdtp.c:avdtp[ 1901.307101] rtk_btcoex: rtk_notify_profileinfo_to_fw: handle 0x0003 _parse_resp() START request succ[ 1901.316801] rtk_btcoex: rtk_notify_profileinfo_to_fw: profile_bitmap 0x04 eeded bluetoothd[1516]: profile[ 1901.327316] rtk_btcoex: rtk_notify_profileinfo_to_fw: profile_status 0x04 s/audio/a2dp.c:start_cfm() Sourc[ 1901.337472] rtk_btcoex: rtk_vendor_cmd_to_fw: opcode 0xfc19 e 0x8c63f0: Start_Cfm bluetooth[ 1901.346663] rtk_btcoex: Length 629 d[1516]: /org/bluez/hci0/dev_10_[ 1901.353083] rtk_btcoex: rtp: v 2, cc 0, pt 96 9E_3A_92_2E_DA/fd0: fd(20) ready[ 1901.360767] rtk_btcoex: syncword: 9c bluetoothd[1516]: profiles/aud[ 1901.367663] rtk_btcoex: freq 48kHz io/transport.c:media_owner_remov[ 1901.374144] rtk_btcoex: blocks 16 e() Owner :1.3 Request Acquire [ 1901.380646] rtk_btcoex: channel mode JOINT_STEREO bluetoothd[1516]: profiles/audio[ 1901.388829] rtk_btcoex: allocation method LOUDNESS /transport.c:transport_set_state[ 1901.396877] rtk_btcoex: subbands 8 () State changed /org/bluez/hci0[ 1901.403488] rtk_btcoex: bitpool 32 /dev_10_9E_3A_92_2E_DA/fd0: TRAN[ 1901.410192] rtk_btcoex: rtk_vendor_cmd_to_fw: opcode 0xfc51 SPORT_STATE_REQUESTING -> TRANSPORT_STATE_ACTIVE bluetoothd[1516]: profiles/audio/a2dp.c:setup_unref() 0x8ccad0: ref=0 bluetoothd[1516]: profiles/audio/a2dp.c:setup_free() 0x8ccad0 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_unref() 0x8cf3c0: ref=2 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_sep_set_state() stream state changed: OPEN -> STREAMING bluetoothd[1516]: profiles/audio/sink.c:sink_set_state() State changed /org/bluez/hci0/dev_10_9E_3A_92_2E_DA: SINK_STATE_CONNECTED -> SINK_STATE_PLAYING bluetoothd[1516]: profiles/audio/transport.c:transport_update_playing() /org/bluez/hci0/dev_10_9E_3A_92_2E_DA/fd0 State=TRANSPORT_STATE_ACTIVE Playing=1 [ 1902.124926] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1903.164933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 22 [ 1904.204932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1905.244932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 14 [ 1906.284931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 26 [ 1907.324939] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 18 [ 1908.364936] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 18 [ 1909.404933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1910.444937] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 13 [ 1911.484925] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 16 [ 1912.524927] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 14 [ 1913.564933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 13 [ 1914.604934] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 10 [ 1915.644932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 7 [ 1916.684940] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 8 [ 1917.724923] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 9 [ 1918.764925] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 15 [ 1919.804933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1920.844937] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1921.884941] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 27 [ 1922.924932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1923.964933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 16 [ 1925.004927] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 19 [ 1926.044934] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 31 [ 1927.084937] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 22 [ 1928.124936] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 31 [ 1929.164931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 32 [ 1930.204929] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 18 [ 1931.244931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 36 [ 1932.284931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 24 [ 1933.324936] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1934.364932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1935.404930] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 11 [ 1936.444934] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 15 [ 1937.484928] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 17 [ 1938.524946] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1939.564928] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 13 [ 1940.604935] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 19 [ 1941.644929] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 16 [ 1942.684932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 28
不出意外的话可以听到播放的歌曲声音了。
参考
- 修改kernel config
-
编译好的驱动文件及固件打包
ok-t113-i-rtl8723du-bt.zip -
@lyphotoes 在 飞凌 OK113i-C 全志T113-i开发板 rtl8723du WIFI 功能测试及蓝牙驱动移植 中说:
飞凌 OK113i-C 全志T113-i开发板板载一个RTL8723du wifi/蓝牙二合一模块,板子出厂已经移植好了WIFI驱动但是蓝牙驱动没有,所以这篇文章我们主要做蓝牙驱动的移植和功能验证。
./build.sh menuconfig
在
Device Drivers > Network device support > Wireless LAN
下找到Realtek 8723D USB WiFi
选项。
默认是开启的。默认wifi驱动联网尝试
wpa_supplicant -Dnl80211 -iwlan0 -c /etc/wpa_supplicant.conf -B udhcpc -i wlan0 udhcpc: started, v1.29.3 udhcpc: sending discover udhcpc: sending select for 192.168.0.111 udhcpc: lease of 192.168.0.111 obtained, lease time 7200 deleting routers adding dns 192.168.1.1 adding dns 192.168.0.1
wpa_supplicant.conf 文件
network={ ssid="TP-LINK_142C" psk="123445678" } update_config=1 ctrl_interface=DIR=/var/run/wpa_supplicant
打印网卡信息:
ifconfig eth0 Link encap:Ethernet HWaddr BA:E9:F2:1C:9D:87 inet addr:192.168.0.232 Bcast:0.0.0.0 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:39 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:41 errors:0 dropped:0 overruns:0 frame:0 TX packets:41 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3936 (3.8 KiB) TX bytes:3936 (3.8 KiB) wlan0 Link encap:Ethernet HWaddr 2C:C3:E6:67:4D:3B inet addr:192.168.0.111 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::2ec3:e6ff:fe67:4d3b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:86 errors:0 dropped:0 overruns:0 frame:0 TX packets:19 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17189 (16.7 KiB) TX bytes:3763 (3.6 KiB)
至此,wifi连接路由器成功,可以ping 百度验证是否联网成功。
蓝牙功能
首先打印设备上的蓝牙设备
hciconfig -a
输出为空,应该是没有蓝牙驱动。看来出厂并没有带蓝牙驱动,下一步自行移植蓝牙驱动,板上的无线芯片模组使用的是rtl8723du是一款bt4.2和 wifi 2.4G芯片。
蓝牙驱动移植
- 修改kernel config
修改OK113i-linux-sdk/kernel/linux-5.4/arch/arm/configs/OK113I_linux_defconfig
文件添加如下一行
CONFIG_BT_HCIBTUSB_RTLBTUSB=m
- 修改Kconfig
添加如下:
config BT_HCIBTUSB_RTLBTUSB tristate "Realtek HCI USB driver support" depends on USB help Realtek Bluetooth HCI USB driver. This driver is required if you want to use Realtek Bluetooth device with USB interface. Say Y here to compile support for Bluetooth USB devices into the kernel or say M to compile it as module (rtk_btusb).
- 修改Makefile
在文档最后添加:
obj-$(CONFIG_BT_HCIBTUSB_RTLBTUSB) := rtk_btusb.o rtk_btusb-objs := rtk_bt.o rtk_misc.o rtk_coex.o
- 将驱动文件中如下文件复制到内核目录
OK113i-linux-sdk/kernel/linux-5.4/drivers/bluetooth
下:
rtk_bt.c rtk_bt.h rtk_coex.c rtk_coex.h rtk_misc.c rtk_misc.h
- 编译内核驱动
./build.sh kernel
编译完成后会在
OK113i-linux-sdk/out/t113_i/ok113i/longan/dist
目录下生成rtk_btusb.ko
驱动文件,将该驱动文件和驱动文件对应的固件文件(rtl8723du_fw.bin和rtl8723du_config.bin)放在板子/lib/firmware/
下为了方便查看驱动加载过程报错信息,打开内核打印信息:
echo 8 4 1 7 > /proc/sys/kernel/printk
将编译好的驱动文件和固件文件上传到板卡上,并将估计文件存放在板卡
/lib/firmware
目录下。scp out/t113_i/ok113i/longan/dist/rtk_btusb.ko root@192.168.0.105:/home/forlinx/ scp /home/luoyang/Documents/Dev/Bluetooth/V4-8761蓝牙_Linux驱动/20210819_LINUX_BT_DRIVER/rtkbt-firmware/lib/firmware/rtl8723du* root@192.168.0.105:/home/forlinx/ cp rtl8723du_config /lib/firmware/rtl8723du_config.bin cp rtl8723du_fw /lib/firmware/rtl8723du_fw.bin
加载驱动试试,报错:
insmod rtk_btusb.ko [ 4832.222554] rtk_btusb: module uses symbol (kernel_read) from namespace VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver, but does not import it. [ 4832.238042] rtk_btusb: Unknown symbol kernel_read (err -22) [ 4832.298908] rtk_btusb: module uses symbol (kernel_read) from namespace VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver, but does not import it. [ 4832.314387] rtk_btusb: Unknown symbol kernel_read (err -22) insmod: can't insert 'rtk_btusb.ko': Invalid argument
在rtk_bt.c文件最后一行添加:
MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
重新编译驱动,然后上传并加载试试。
root@ok113i:/home/forlinx# insmod rtk_btusb.ko [ 7964.303169] rtk_btusb: Realtek Bluetooth USB driver ver 3.1.32e1d0b.20210819-170430 [ 7964.311850] rtk_btcoex: rtk_btcoex_init: version: 1.2 [ 7964.317513] rtk_btcoex: create workqueue [ 7964.322343] rtk_btcoex: alloc buffers 1408, 2240 for ev and l2 [ 7964.329075] rtk_btusb: btusb_probe intf->cur_altsetting->desc.bInterfaceNumber 0 [ 7964.337365] rtk_btusb: btusb_probe can_wakeup 1, may wakeup 0 [ 7964.343827] rtk_btusb: patch_add [ 7964.347451] rtk_btusb: auto suspend is disabled [ 7964.352568] rtk_btusb: pid = 0xd723 [ 7964.356478] rtk_btusb: patch_add: Reset gEVersion to 0xff [ 7964.362590] rtk_btusb: set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); [ 7964.370965] rtk_btusb: btusb_probe: done [ 7964.375679] usbcore: registered new interface driver rtk_btusb [ 7964.377514] rtk_btusb: btusb_open start [ 7964.386578] rtk_btusb: btusb_open hdev->promisc ==0 [ 7964.392129] rtk_btusb: download_patch start root@ok113i:/home/forlinx# [ 7964.396839] rtk_btusb: chip type value: 0x71 [ 7964.403997] rtk_btusb: HCI reset. [ 7964.416814] rtk_btusb: read_ver_rsp->lmp_subver = 0x8723 [ 7964.423054] rtk_btusb: read_ver_rsp->hci_rev = 0xd [ 7964.428449] rtk_btusb: patch_entry->lmp_sub = 0x8723 [ 7964.434017] rtk_btusb: load_firmware start [ 7964.438638] rtk_btusb: lmp_version = 0x8723 [ 7964.443325] rtk_btusb: config filename rtl8723du_config [ 7964.449952] rtk_btusb: no bdaddr file /opt/bdaddr [ 7964.455252] rtk_btusb: Origin cfg len 22 [ 7964.459688] rtk_btusb: 55 ab 23 87 10 00 d9 00 01 0f e4 00 01 08 8d 00 [ 7964.467005] rtk_btusb: 01 fa 8f 00 01 bf [ 7964.471497] rtk_btusb: New cfg len 22 [ 7964.475600] rtk_btusb: 55 ab 23 87 10 00 d9 00 01 0f e4 00 01 08 8d 00 [ 7964.482969] rtk_btusb: 01 fa 8f 00 01 bf [ 7964.487399] rtk_btusb: fw name is rtl8723du_fw [ 7964.492801] rtk_btusb: This is not 8723a, use new patch style! [ 7964.499374] rtk_btusb: rtk_get_eversion: gEVersion 255 [ 7964.505815] rtk_btusb: eversion->status = 0x0, eversion->version = 0x2 [ 7964.513566] rtk_btusb: load_firmware: New gEVersion 2 [ 7964.519331] rtk_btusb: rtk_get_fw_project_id: opcode 0, len 1, data 9 [ 7964.526565] rtk_btusb: lmp_version is 8723, project_id is 8723, match! [ 7964.533909] rtk_btusb: fw_version = 0x82a8a133 [ 7964.538921] rtk_btusb: number_of_total_patch = 3 [ 7964.544092] rtk_btusb: chipID 3 [ 7964.547606] rtk_btusb: patch_length 0x889c [ 7964.552220] rtk_btusb: start_offset 0x00004940 [ 7964.557198] rtk_btusb: Svn version: -1433992835 [ 7964.562301] rtk_btusb: Coexistence: BTCOEX_20210106-3b3b [ 7964.568274] rtk_btusb: buf_len = 0x88b2 [ 7964.572647] rtk_btusb: fw: exists, config file: exists [ 7964.578430] rtk_btusb: load_firmware done [ 7964.582960] rtk_btusb: download_data start [ 7964.855824] rtk_btusb: download_data done [ 7964.860346] rtk_btusb: HCI reset. [ 7964.873812] rtk_btusb: read_ver_rsp->lmp_subver = 0xa133 [ 7964.880054] rtk_btusb: read_ver_rsp->hci_rev = 0x82a8 [ 7964.885730] rtk_btusb: patch_entry->lmp_sub = 0x8723 [ 7964.891337] rtk_btusb: Rtk patch end 0 [ 7964.895538] rtk_btusb: btusb_open set HCI_RUNNING [ 7964.900945] rtk_btcoex: Open BTCOEX [ 7964.904856] rtk_btusb: btusb_open end [ 7964.911832] rtk_btcoex: BTCOEX hci_rev 0x82a8 [ 7964.916883] rtk_btcoex: BTCOEX lmp_subver 0xa133 [ 7964.943829] rtk_btusb: btusb_notify: hci0 evt 3 [ 7967.007992] rtk_btusb: btusb_flush add delay [ 7967.022915] rtk_btusb: btusb_close [ 7967.045574] rtk_btcoex: Close BTCOEX [ 7967.049615] rtk_btcoex: -x
以上信息说明蓝牙驱动加载成功。
此时,再一次查看系统的蓝牙设备信息会打印如下:root@ok113i:/home/forlinx# hciconfig -a hci0: Type: Primary Bus: USB BD Address: 2C:C3:E6:67:4D:3C ACL MTU: 1021:8 SCO MTU: 255:12 DOWN RX bytes:584 acl:0 sco:0 events:30 errors:0 TX bytes:369 acl:0 sco:0 commands:30 errors:0 Features: 0xff 0xff 0xff 0xfa 0xdb 0xbd 0x7b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH HOLD SNIFF PARK Link mode: SLAVE ACCEPT
蓝牙工具软件使用
蓝牙驱动安装成功后就可以对蓝牙设备进行配对连接并进行播放音频操作了,此处我们选择通过蓝牙连接家里的智能音箱天猫精灵作为蓝牙音频输出设备,涉及的蓝牙工具软件开发板上出厂移植好了,所以此处省去了移植这些工具软件的步骤。
- 启动系统蓝牙服务
bluetoothd
,使其在后台运行
bluetoothd -d -n & root@ok113i:/# bluetoothd[1516]: Bluetooth daemon 5.50 bluetoothd[1516]: src/adapter.c:adapter_init() sending read version command bluetoothd[1516]: Starting SDP server bluetoothd[1516]: src/sdpd-service.c:register_device_id() Adding device id record for 0002:1d6b:0246:0532 bluetoothd[1516]: src/plugin.c:plugin_init() Loading builtin plugins bluetoothd[1516]: src/plugin.c:add_plugin() Loading hostname plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading wiimote plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading autopair plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading policy plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading neard plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading sap plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading a2dp plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading avrcp plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading network plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading input plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading hog plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading health plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading gap plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading scanparam plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading deviceinfo plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading midi plugin bluetoothd[1516]: src/plugin.c:add_plugin() Loading battery plugin bluetoothd[1516]: src/plugin.c:plugin_init() Loading plugins /usr/lib/bluetooth/plugins bluetoothd[1516]: src/plugin.c:add_plugin() Loading sixaxis plugin bluetoothd[1516]: profiles/health/hdp.c:hdp_manager_start() Starting Health manager bluetoothd[1516]: profiles/input/suspend-none.c:suspend_init() bluetoothd[1516]: profiles/network/manager.c:read_config() Config options: Security=true bluetoothd[1516]: kernel lacks bnep-protocol support bluetoothd[1516]: System does not support network plugin bluetoothd[1516]: plugins/neard.c:neard_init() Setup neard plugin bluetoothd[1516]: plugins/sixaxis.c:sixaxis_init() bluetoothd[1516]: src/main.c:main() Entering main loop bluetoothd[1516]: src/rfkill.c:rfkill_event() RFKILL event idx 0 type 1 op 0 soft 0 hard 0 bluetoothd[1516]: Bluetooth management interface 1.14 initialized bluetoothd[1516]: src/adapter.c:read_version_complete() sending read supported commands command bluetoothd[1516]: src/adapter.c:read_version_complete() sending read index list command bluetoothd[1516]: src/adapter.c:read_commands_complete() Number of commands: 65 bluetoothd[1516]: src/adapter.c:read_commands_complete() Number of events: 35 bluetoothd[1516]: src/adapter.c:read_commands_complete() enabling kernel-side connection control bluetoothd[1516]: src/adapter.c:read_index_list_complete() Number of controllers: 0 root@ok113i:/#
- 通过
bluetoothctl
对蓝牙设备操作,主要包括:蓝牙设备信息打印查看,蓝牙设备开启和关闭、蓝牙外设扫描、查看扫描到的蓝牙外设设备、配对连接等,下面实例命令行中##
开头的行是注释
## 进入bluetoothctl root@ok113i:/# bluetoothctl bluetoothd[1516]: src/agent.c:agent_ref() 0x8c9338: ref=1 bluetoothd[1516]: src/agent.c:register_agent() agent :1.1 Agent registered ## 蓝牙设备信息打印查看 [bluetooth]#show Controller 2C:C3:E6:67:4D:3C (public) Name: BlueZ 5.50 Alias: BlueZ 5.50 Class: 0x00000000 Powered: no Discoverable: no Pairable: yes UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb) UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb) Modalias: usb:v1D6Bp0246d0532 Discovering: no ## 蓝牙设备开启和关闭 [bluetooth]#power on [bluetooth]# [ 417.686414] rtk_btusb: btusb_open start bluetoothd[1516]: src/adapter.c:[ 417.691880] rtk_btusb: btusb_open hdev->promisc ==0 property_set_mode() sending Set [ 417.700202] rtk_btusb: download_patch start Powered command for index 0 [ 417.707637] rtk_btusb: chip type value: 0x71 [ 417.714939] rtk_btusb: HCI reset. [ 417.727699] rtk_btusb: read_ver_rsp->lmp_subver = 0xa133 [ 417.733654] rtk_btusb: read_ver_rsp->hci_rev = 0x82a8 [ 417.739344] rtk_btusb: patch_entry->lmp_sub = 0x8723 [ 417.744905] rtk_btusb: Firmware already exists [ 417.749914] rtk_btusb: Rtk patch end 1 [ 417.754125] rtk_btusb: btusb_open set HCI_RUNNING [ 417.759504] rtk_btcoex: Open BTCOEX [ 417.763412] rtk_btusb: btusb_open end [ 417.769720] rtk_btcoex: BTCOEX hci_rev 0x82a8 [ 417.774656] rtk_btcoex: BTCOEX lmp_subver 0xa133 bluetoothd[1516]: src/adapter.c:property_set_mode_complete() Success (0x00) bluetoothd[1516]: src/adapter.c:new_settings_callback() Settings: 0x00000ad1 bluetoothd[1516]: src/adapter.c:settings_changed() Changed settings: 0x00000001 bluetoothd[1516]: src/adapter.c:adapter_start() adapter /org/bluez/hci0 has been enabled bluetoothd[1516]: src/adapter.c:trigger_passive_scanning() Changing power on succeeded [CHG] Controller 2C:C3:E6:67:4D:3C Powered: yes ## 蓝牙设备开启和关闭 [bluetooth]#scan on [bluetooth]#scan off ## 查看扫描到的蓝牙外设设备 [bluetooth]#devices Device F1:22:33:1A:48:9B F1-22-33-1A-48-9B Device C4:DE:E2:DF:E8:22 Keep_CC_50200973 Device 34:29:EF:5B:D2:D3 34-29-EF-5B-D2-D3 Device E8:F5:63:87:03:9D Mi Band 3 Device B8:8C:29:87:72:C9 midea Device 04:7F:0E:40:4A:BD BEIJING-EU5 Device CC:B5:D1:FB:45:3A SMI-M14 Device 45:B8:CC:87:53:F8 45-B8-CC-87-53-F8 Device 84:7C:9B:6D:FF:11 midea_db_2943 Device 10:9E:3A:92:2E:DA �方�糖(80:7A) ## 配对连接 [bluetooth]#connect 10:9E:3A:92:2E:DA Attempting to connect to 10:9E:3A:92:2E:DA bluetoothd[1516]: src/device.c:connect_profiles() /org/bluez/hci0/dev_10_9E_3A_92_2E_DA (all), client :1.2 bluetoothd[1516]: profiles/audio/a2dp.c:a2dp_sink_connect() path /org/bluez/hci0/dev_10_9E_3A_92_2E_DA bluetoothd[1516]: a2dp-sink profile connect failed for 10:9E:3A:92:2E:DA: Protocol not available Failed to connect: org.bluez.Error.Failed
报错了,因为没有提前运行
bluealsa
这个程序,运行如下:bluealsa -p a2dp-source & [2] 1537 root@ok113i:/home/forlinx# bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_register_sep() SEP 0x8cc378 registered: type:0 codec:2 seid:1 bluetoothd[1516]: src/adapter.c:adapter_service_add() /org/bluez/hci0 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10003 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000019-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000110a-0000-1000-8000-00805f9 bluetoothd[1516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000110d-0000-1000-8000-00805f9 bluetoothd[1516]: src/adapter.c:adapter_service_insert() /org/bluez/hci0 bluetoothd[1516]: src/adapter.c:add_uuid() sending add uuid command for index 0 bluetoothd[1516]: Endpoint registered: sender=:1.3 path=/A2DP/MPEG24/Source/1 bluetoothd[1516]: src/adapter.c:dev_class_changed_callback() Class: 0x080000 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_register_sep() SEP 0x8c63f0 registered: type:0 codec:0 seid:2 bluetoothd[1516]: Endpoint registered: sender=:1.3 path=/A2DP/SBC/Source/1
至此,再进入bluetoothctl 连接天猫精灵试试,首先输入
devices
命令打印出扫描到的设备信息,然后使用connect xx:xx:xx:xx:xx:xx
连接上想要连接的蓝牙设备,连接成功后提示符会变成[连接的设备]
样式,具体如下:[bluetooth]#devices Device F1:22:33:1A:48:9B F1-22-33-1A-48-9B Device C4:DE:E2:DF:E8:22 Keep_CC_50200973 Device 34:29:EF:5B:D2:D3 34-29-EF-5B-D2-D3 Device E8:F5:63:87:03:9D Mi Band 3 Device B8:8C:29:87:72:C9 midea Device 04:7F:0E:40:4A:BD BEIJING-EU5 Device CC:B5:D1:FB:45:3A SMI-M14 Device 45:B8:CC:87:53:F8 45-B8-CC-87-53-F8 Device 84:7C:9B:6D:FF:11 midea_db_2943 Device 10:9E:3A:92:2E:DA �方�糖(80:7A) [bluetooth]#connect 10:9E:3A:92:2E:DA ... [�方�糖(80:7A)]# list Controller 2C:C3:E6:67:4D:3C BlueZ 5.50 [default] ## 退出bluetoothctl程序 [�方�糖(80:7A)]# exit
- 蓝牙音频播放
因为此处我们使用alsa-utils
工具集中的 aplay 进行音频播放测试,所以仅仅支持PCM
和WAV
等音频格式,要是想直接播放 mp3 或者 mp4 等格式音频文件需要借助MPD
或者FFmpeg
等软件。
上一步我们在bluetoothctl中打印扫描并连接了蓝牙音箱,蓝牙音箱的设备地址如下:
[bluetooth]#devices Device F1:22:33:1A:48:9B F1-22-33-1A-48-9B Device C4:DE:E2:DF:E8:22 Keep_CC_50200973 Device 34:29:EF:5B:D2:D3 34-29-EF-5B-D2-D3 Device E8:F5:63:87:03:9D Mi Band 3 Device B8:8C:29:87:72:C9 midea Device 04:7F:0E:40:4A:BD BEIJING-EU5 Device CC:B5:D1:FB:45:3A SMI-M14 Device 45:B8:CC:87:53:F8 45-B8-CC-87-53-F8 Device 84:7C:9B:6D:FF:11 midea_db_2943 Device 10:9E:3A:92:2E:DA �方�糖(80:7A)
根据上面信息我们可以看到天猫精灵方糖的蓝牙设备地址是
10:9E:3A:92:2E:DA
,所以我们可以使用如下命令进行音频播放测试:root@ok113i:/# aplay -D bluealsa:DEV=10:9E:3A:92:2E:DA ./wishforyou.wav Playing WAVE './wishforyou.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo bluetoothd[1516]: profiles/audio/transport.c:media_owner_create() Owner created: sender=:1.3 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_ref() 0x8cf3c0: ref=2 bluetoothd[1516]: profiles/audio/a2dp.c:a2dp_sep_lock() SEP 0x8c63f0 locked bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_ref() 0x8cf3c0: ref=3 bluetoothd[1516]: profiles/audio/a2dp.c:setup_ref() 0x8ccad0: ref=1 bluetoothd[1516]: profiles/audio/transport.c:transport_set_state() State changed /org/bluez/hci0/dev_10_9E_3A_92_2E_DA/fd0: TRANSPORT_STATE_IDLE -> TRANSPORT_STATE_REQUESTING bluetoothd[1516]: profiles/audio/transport.c:media_request_create() Request created: method=Acquire id=4 bluetoothd[1516]: profiles/audio/transport.c:media_owner_add() Owner :1.3 Request Acquire bluetoothd[1516]: profiles/audio/transport.c:media_transport_set_owner() Transport /org/bluez/hci0/dev_10_9E_3A[ 1901.267056] rtk_btcoex: update_profile_state: btrtl_coex.prof4 _92_2E_DA/fd0 Owner :1.3 blueto[ 1901.276315] rtk_btcoex: update_profile_state: btrtl_coex.profile_status = 4 othd[1516]: profiles/audio/avdtp[ 1901.287222] rtk_btcoex: rtk_notify_profileinfo_to_fw: BufferSize 5 .c:session_cb() bluetoothd[151[ 1901.296656] rtk_btcoex: rtk_notify_profileinfo_to_fw: NumberOfHandles 1 6]: profiles/audio/avdtp.c:avdtp[ 1901.307101] rtk_btcoex: rtk_notify_profileinfo_to_fw: handle 0x0003 _parse_resp() START request succ[ 1901.316801] rtk_btcoex: rtk_notify_profileinfo_to_fw: profile_bitmap 0x04 eeded bluetoothd[1516]: profile[ 1901.327316] rtk_btcoex: rtk_notify_profileinfo_to_fw: profile_status 0x04 s/audio/a2dp.c:start_cfm() Sourc[ 1901.337472] rtk_btcoex: rtk_vendor_cmd_to_fw: opcode 0xfc19 e 0x8c63f0: Start_Cfm bluetooth[ 1901.346663] rtk_btcoex: Length 629 d[1516]: /org/bluez/hci0/dev_10_[ 1901.353083] rtk_btcoex: rtp: v 2, cc 0, pt 96 9E_3A_92_2E_DA/fd0: fd(20) ready[ 1901.360767] rtk_btcoex: syncword: 9c bluetoothd[1516]: profiles/aud[ 1901.367663] rtk_btcoex: freq 48kHz io/transport.c:media_owner_remov[ 1901.374144] rtk_btcoex: blocks 16 e() Owner :1.3 Request Acquire [ 1901.380646] rtk_btcoex: channel mode JOINT_STEREO bluetoothd[1516]: profiles/audio[ 1901.388829] rtk_btcoex: allocation method LOUDNESS /transport.c:transport_set_state[ 1901.396877] rtk_btcoex: subbands 8 () State changed /org/bluez/hci0[ 1901.403488] rtk_btcoex: bitpool 32 /dev_10_9E_3A_92_2E_DA/fd0: TRAN[ 1901.410192] rtk_btcoex: rtk_vendor_cmd_to_fw: opcode 0xfc51 SPORT_STATE_REQUESTING -> TRANSPORT_STATE_ACTIVE bluetoothd[1516]: profiles/audio/a2dp.c:setup_unref() 0x8ccad0: ref=0 bluetoothd[1516]: profiles/audio/a2dp.c:setup_free() 0x8ccad0 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_unref() 0x8cf3c0: ref=2 bluetoothd[1516]: profiles/audio/avdtp.c:avdtp_sep_set_state() stream state changed: OPEN -> STREAMING bluetoothd[1516]: profiles/audio/sink.c:sink_set_state() State changed /org/bluez/hci0/dev_10_9E_3A_92_2E_DA: SINK_STATE_CONNECTED -> SINK_STATE_PLAYING bluetoothd[1516]: profiles/audio/transport.c:transport_update_playing() /org/bluez/hci0/dev_10_9E_3A_92_2E_DA/fd0 State=TRANSPORT_STATE_ACTIVE Playing=1 [ 1902.124926] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1903.164933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 22 [ 1904.204932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1905.244932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 14 [ 1906.284931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 26 [ 1907.324939] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 18 [ 1908.364936] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 18 [ 1909.404933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1910.444937] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 13 [ 1911.484925] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 16 [ 1912.524927] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 14 [ 1913.564933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 13 [ 1914.604934] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 10 [ 1915.644932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 7 [ 1916.684940] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 8 [ 1917.724923] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 9 [ 1918.764925] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 15 [ 1919.804933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1920.844937] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1921.884941] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 27 [ 1922.924932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1923.964933] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 16 [ 1925.004927] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 19 [ 1926.044934] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 31 [ 1927.084937] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 22 [ 1928.124936] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 31 [ 1929.164931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 32 [ 1930.204929] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 18 [ 1931.244931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 36 [ 1932.284931] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 24 [ 1933.324936] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 21 [ 1934.364932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1935.404930] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 11 [ 1936.444934] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 15 [ 1937.484928] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 17 [ 1938.524946] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 20 [ 1939.564928] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 13 [ 1940.604935] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 19 [ 1941.644929] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 16 [ 1942.684932] rtk_btcoex: count_a2dp_packet_timeout: a2dp_packet_count 28
不出意外的话可以听到播放的歌曲声音了。
参考
博主,我按这样的步骤去移植RTL8733BU蓝牙 一样USB模组的 我这扫不到设备是什么原因啊
- 修改kernel config
-
学习到了,谢谢大佬
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号