1 介绍
本文章在瑞芯微RV1103芯片移植了RTL8723BS模块的蓝牙驱动部分,成功完成通讯连接。经过研究,RTL其他SDIO接口的蓝牙WIFI芯片的接口与RTL8923BS基本相似,引脚和功能也基本相同,所以通过更换固件库即可实现其他型号的驱动移植,操作逻辑是完全相同的。
包含蓝牙、WIFI驱动移植以及启动脚本的程序在github中,在最后一章节给出,可以直接按照github的readme进行操作。
平台介绍: 主控芯片为RV1103。
SDK: 幸狐Luckfox的SDK V1.3
WIFI模块: RTL8723BS是一个集成了蓝牙和WIFI的模块。
2 电路介绍
关于硬件电路方案在文章RTL8723BSWIFI模块驱动移植中。唯一不同的是,为了方便蓝牙的使用,后续将芯片的BT_EN即蓝牙使能引脚引到了空闲的引脚gpio1 PC0上。
3 移植流程
移植蓝牙驱动的大致流程分为几个部分。
- 下载驱动程序并编译
- 添加固件
- 配置内核
- 修改设备树
- 添加buildroot软件包
- 测试并撰写启动脚本
4 驱动程序编译
可以从该驱动程序链接中下载驱动,具体包含了HCI_URAT驱动、rtk_hciattach工具,其中makefile已经配置好了,可以直接使用。
hci_uart的makefile
MODULE_NAME = hci_uart
ifneq ($(KERNELRELEASE),)
obj-m :=$(MODULE_NAME).o
$(MODULE_NAME)-y := hci_ldisc.o hci_h4.o hci_rtk_h5.o rtk_coex.o
#cc1: all warnings being treated as errors解决办法
CFLAGS = -Wall -Wpointer-arith -Wno-unused
KBUILD_CFLAGS += -w
else
PWD := $(shell pwd)
KDIR := ../../../source/kernel #linux内核路径自行修改
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
#$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL_DIR) M=$(shell pwd) modules -j16
clean:
rm -rf *.o *.mod *.mod.c *.mod.o *.ko *.symvers *.order *.a
endif
编译目标为hci_uart.ko意味着会编译成一个驱动,可以通过外部加载,编译过程依赖于hci_ldisc.c hci_h4.c hci_rtk_h5.c rtk_coex.c等文件。
在使用的时候,主要是要注意到内核的路径和编译器不要错了。
编译解释
5 kernel配置
可以参考github仓库中的配置文件,应该在官方的默认位置下,也可以直接找到复制即可。
如果想要自己配置,请按照如下流程
./build.sh kernelconfig
5.1 蓝牙子系统支持
设置CONFIG_BT_HCIUART=n,即关闭HCI UART driver。
5.2 用户层驱动支持
5.3 HID驱动
6 buildroot配置
这里可以直接复制仓库根目录luckfox_pico_defconfig到自己对应的配置文件中。
如果想要自己手动配置,可以按照如下流程
./build.sh buildrootconfig
6.1 Target options
6.2 设置外部工具链
6.3 bluez工具
6.4 DBUS
6.5 expat
6.6 添加bluez依赖
还需要添加以下两个包,不然会报错Checking for function “ngettext” : NO
Run-time dependency libffi found: YES 3.4.4
Run-time dependency zlib found: YES 1.2.13
Checking for function "ngettext" : NO
Library intl found: NO
output/build/libglib2-2.72.3/meson.build:2102:4: ERROR: Automatic wrap-based subproject downloading is disabled
7 设备树配置
配置好的dts可以参考仓库中的luckforv1103g-luckfox-pico-plus.dts
具体流程如下
7.1 添加蓝牙节点
wireless_bluetooth: wireless-bluetooth {
compatible = "bluetooth-platdata";
uart_rts_gpios = <&gpio1 RK_PC6 GPIO_ACTIVE_LOW>;//对应RTS
pinctrl-names = "default","rts_gpio";
pinctrl-0 = <&uart4m1_rtsn>;
pinctrl-1 = <&uart4_rts_gpio>; /* 定义gpio1 RK_PD0 为蓝牙引脚 */
BT,power_gpio = <&gpio1 RK_PC0 GPIO_ACTIVE_LOW>;//蓝牙使能引脚
//keep_bt_power_on;
/* BT,power_gpio = <&gpio* *** GPIO_ACTIVE_HIGH>; *///这些引脚都没有
/*BT,power_gpio = <&gpio0 RK_PA2 GPIO_ACTIVE_LOW>;*/
/*BT,wake_gpio = <&gpio1 RK_PA4 GPIO_ACTIVE_HIGH>;*/
/*BT,wake_host_irq = <&gpio1 RK_PA4 GPIO_ACTIVE_HIGH>;*/
status = "okay";
};
7.2 配置串口4
追加uart4节点的属性,注意这里是ctsn,而不是rtsn。
/* UART4_M1 */
&uart4 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&uart4m1_xfer &uart4m1_ctsn>;
}
7.3 配置引脚
pincrtl 节点下配置引脚
wireless-bluetooth {
uart4_rts_gpio: uart4-rts-gpio {
rockchip,pins = <1 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>;
};
8 调试
8.1 加载驱动
到对应的目录下,insmod加载已经编译好的驱动文件。
cd /oem/usr/ko
insmod hci_uart.ko
输出结果为
[ 60.331033] hci_uart: loading out-of-tree module taints kernel.
[ 60.337344] Bluetooth: HCI UART driver ver 2.2.74e8f89.20210423-153941
[ 60.337372] Bluetooth: HCI H4 protocol i[root@luckfox ko]$ nitialized
[ 60.337382] Bluetooth: HCI Realtek H5 protocol initialized
[ 60.337390] rtk_btcoex: rtk_btcoex_init: version: 1.2
[ 60.337395] rtk_btcoex: create workqueue
[ 60.339424] rtk_btcoex: alloc buffers 1408, 2240 for ev and l2
8.2 重新启动dbus守护进程
先杀死所有的dbus进程,再重新启动一个
killall dbus-daemon
rm /run/messagebus.pid
dbus-daemon --system --print-pid --print-address
输出
unix:path=/run/dbus/system_bus_socket,guid=32f2adedb64adb6c24e4bcbd0000012f
324
8.3 配置串口连接蓝牙
还是再之前的文件夹下,rtk_hciattach是我们编译的配置串口的可执行文件。
配置串口为115200,以h5协议连接串口4。
./rtk_hciattach -n -s 115200 /dev/ttyS4 rtk_h5 &
输出为
[ 334.328603] of_dma_request_slave_channel: dma-names property of node Realtek Bluetoot'/serial@altek Bluetooth init uart with init speed:115200, type:HCI UART H5
ff4e0000Realtek Bluetooth :Realtek hciattach version 3.1.dced3af.20210423-153942
Realtek Bluetooth :Use epoll
' missing or empty
[ 334.328757] dw-apb-uart Realtek Bluetooth :[SYNC] Get SYNC Resp Pkt
Realtek Bluetooth :[CONFIG] Get SYNC pkt
ff4e0000.serial: failed to request DRealtek Bluetooth :[CONFIG] Get CONFG pkt
Realtek Bluetooth :[CONFIG] Get CONFG resp pkt
Realtek Bluetooth :dic is 1, cfg field 0x14
Realtek Bluetooth :H5 init finished
Realtek Bluetooth :Realtek H5 IC
MA, use interrupt mode
Realtek Bluetooth :Receive cmd complete event of command: 1001
Realtek Bluetooth :HCI Version 0x06
Realtek Bluetooth :HCI Revision 0x000b
Realtek Bluetooth :LMP Subversion 0x8723
Realtek Bluetooth :Receive cmd complete event of command: fc6d
Realtek Bluetooth :Read ROM version 01
Realtek Bluetooth :LMP Subversion 0x8723
Realtek Bluetooth :EVersion 1
Realtek Bluetooth :IC: RTL8723BS
Realtek Bluetooth :Firmware/config: rtl8723b_fw, rtl8723b_config
Realtek Bluetooth :Couldnt open extra config /opt/rtk_btconfig.txt, No such file or directory
Realtek Bluetooth :Couldnt access customer BT MAC file /opt/bdaddr
Realtek Bluetooth :Origin cfg len 55
Realtek Bluetooth :55 ab 23 87 31 00 f4 00 08 01 00 00 00 05 50 00
Realtek Bluetooth :00 0c 00 10 02 80 92 04 50 c5 ea 19 e1 1b f1 af
Realtek Bluetooth :5f 01 a4 0b 27 00 01 63 fe 00 01 01 5b 01 04 0b
Realtek Bluetooth :0b 0b 0a e3 01 01 00
Realtek Bluetooth :Config baudrate: 04928002
Realtek Bluetooth :uart flow ctrl: 1
Realtek Bluetooth :Vendor baud from Config file: 04928002
Realtek Bluetooth :New cfg len 55
Realtek Bluetooth :55 ab 23 87 31 00 f4 00 08 01 00 00 00 05 50 00
Realtek Bluetooth :00 0c 00 10 02 80 92 04 50 c5 ea 19 e1 1b f1 af
Realtek Bluetooth :5f 01 a4 0b 27 00 01 63 fe 00 01 01 5b 01 04 0b
Realtek Bluetooth :0b 0b 0a e3 01 01 00
Realtek Bluetooth :Load FW /lib/firmware/rtlbt/rtl8723b_fw OK, size 51364
Realtek Bluetooth :rtb_get_fw_project_id: opcode 0, len 1, data 1
Realtek Bluetooth :FW version 0x373e6962, Patch num 3
Realtek Bluetooth :Chip id 0x0000
Realtek Bluetooth :Chip id 0x0001
Realtek Bluetooth :Chip id 0x0002
Realtek Bluetooth :Patch length 0x5c5c
Realtek Bluetooth :Start offset 0x00006c00
Realtek Bluetooth :Svn version: 13226
Realtek Bluetooth :Coexistence: BTCOEX_20140708-5240
Realtek Bluetooth :FW exists, Config file exists
Realtek Bluetooth :Total len 23699 for fwc
Realtek Bluetooth :baudrate in change speed command: 0x02 0x80 0x92 0x04
Realtek Bluetooth :Receive cmd complete event of command: fc17
Realtek Bluetooth :Received cc of vendor change baud
Realtek Bluetooth :Final speed 1500000
Realtek Bluetooth :end_idx: 94, lp_len: 11, additional pkts: 5
Realtek Bluetooth :Start downloading...
Realtek Bluetooth :Send additional packet 95
Realtek Bluetooth :Send additional packet 96
Realtek Bluetooth :Send additional packet 97
Realtek Bluetooth :Send additional packet 98
Realtek Bluetooth :Last packet 227
Realtek Bluetooth :Send last pkt
Realtek Bluetooth :Enable host hw flow control
Realtek Bluetooth :h5_hci_reset: Issue hci reset cmd
Realtek Bluetooth :Receive cmd complete event of command: 0c03
Realtek Bluetooth :Received cc of hci reset cmd
Realtek Bluetooth :Init Process finished
[ 335.567505] Bluetooth: h5_open
[ 335.567555] Bluetooth: hci_uart_register_dev
Realtek Bluetooth :Realtek Bluetooth post process
Realtek Bluetooth :Device setup complete
[ 335.580628] rtk_btcoex: Open BTCOEX
[ 335.584465] rtk_btcoex: BTCOEX hci_rev 0x373e
[ 335.584485] rtk_btcoex: BTCOEX lmp_subver 0x6962
[ 335.614205] Bluetooth: __hci_uart_flush: hdev 04a67e7b tty d657431c
[ 335.674083] Bluetooth: hci_uart_close: hdev 04a67e7b
[ 335.674128] Bluetooth: __hci_uart_flush: hdev 04a67e7b tty d657431c
[ 335.674149] rtk_btcoex: Close BTCOEX
[ 335.674165] rtk_btcoex: -x
8.4 启动rfkill
先查看一下rfkill文件夹下对应的设备文件,我对应的是rfkill1。
cat /sys/class/rfkill/rfkill1/uevent
可以看到在文件uevent中,包含了蓝牙的状态。hci0对应的是蓝牙设备,但是此时的state是0,即天线还没有打开。
RFKILL_NAME=hci0
RFKILL_TYPE=bluetooth
RFKILL_STATE=0
启动一下天线,即向state文件中写入1。
echo 1 > /sys/class/rfkill/rfkill1/state
8.5 蓝牙启动
先查看一下蓝牙
hciconfig -a
终端会输出如下内容:
hci0: Type: Primary Bus: UART
BD Address: AC:35:EE:C7:C8:9F ACL MTU: 820:8 SCO MTU: 255:16
DOWN
RX bytes:1079 acl:0 sco:0 events:31 errors:0
TX bytes:678 acl:0 sco:0 commands:31 errors:0
Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: PERIPHERAL ACCEPT
可以看到发现蓝牙为hci0了,但是此时是down状态,我们给它启动一下。
hciconfig hci0 up
如果正常情况,蓝牙会输出结果如下。
[root@luckfox ko]$ hciconfig hci0 up
[ 548.466521] rtk_btcoex: Open BTCOEX
[ 548.720428] Bluetooth: hu 5770f882 retransmitting 1 pkts
[ 548.722538] rtk_btcoex: BTCOEX hci_rev 0x373e
[ 548.722549] rtk_btcoex: BTCOEX lmp_subver 0x6962
但是如果像下面报错的话,就是蓝牙的天线没有打开,请回到8.4重新配置。请注意一定是要配置的是蓝牙的rfkill文件,因为wifi也有rfkill。
Can't init device hci0: Unknown error 132 (22)
此时再查看一下hci0的状态,已经是UP RUNNING了。
hci0: Type: Primary Bus: UART
BD Address: AC:35:EE:C7:C8:9F ACL MTU: 820:8 SCO MTU: 255:16
UP RUNNING
RX bytes:2135 acl:0 sco:0 events:61 errors:0
TX bytes:1337 acl:0 sco:0 commands:62 errors:0
如果要自己的设备蓝牙可以被搜索到的话,可以用指令
hciconfig hci0 piscan
8.6 启动bluetoothd服务
跳转到对应的目录,并启动
cd /usr/libexec/bluetooth/
./bluetoothd -n -d &
输出的结果是下面的这些
[root@luckfox bluetooth]$ bluetoothd[352]: Bluetooth daemon 5.65
bluetoothd[352]: src/adapter.c:adapter_init() sending read version command
bluetoothd[352]: Starting SDP server
bluetoothd[352]: src/sdpd-service.c:register_device_id() Adding device id record for 0002:1d6b:0246:0541
bluetoothd[352]: src/plugin.c:plugin_init() Loading builtin plugins
bluetoothd[352]: src/plugin.c:add_plugin() Loading hostname plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading wiimote plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading autopair plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading policy plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading network plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading gap plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading scanparam plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading deviceinfo plugin
bluetoothd[352]: src/plugin.c:add_plugin() Loading battery plugin
bluetoothd[352]: src/plugin.c:plugin_init() Loading plugins /usr/lib/bluetooth/plugins
bluetoothd[352]: profiles/network/manager.c:read_config() Config options: Security=true
bluetoothd[352]: src/main.c:main() Entering main loop
bluetoothd[352]: src/shared/mgmt.c:send_request() [0xffff] command 0x0001
bluetoothd[352]: src/rfkill.c:rfkill_event() RFKILL event idx 0 type 2 op 0 soft 1 hard 0
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0xffff] command 0x0001 complete: 0x00
bluetoothd[352]: Bluetooth management interface 1.18 initialized
bluetoothd[352]: src/adapter.c:read_version_complete() sending read supported commands command
bluetoothd[352]: src/adapter.c:read_version_complete() sending read index list command
bluetoothd[352]: src/rfkill.c:rfkill_event() RFKILL event idx 1 type 2 op 0 soft 0 hard 0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0xffff] command 0x0002
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0xffff] command 0x0002 complete: 0x00
bluetoothd[352]: src/adapter.c:read_commands_complete() Number of commands: 79
bluetoothd[352]: src/adapter.c:read_commands_complete() Number of events: 40
bluetoothd[352]: src/adapter.c:read_commands_complete() enabling kernel-side connection control
bluetoothd[352]: src/adapter.c:read_commands_complete() kernel supports the set_blocked_keys op
bluetoothd[352]: src/adapter.c:read_commands_complete() kernel supports controller cap command
bluetoothd[352]: src/adapter.c:read_commands_complete() kernel supports exp features
bluetoothd[352]: src/adapter.c:read_commands_complete() kernel supports set system confic
bluetoothd[352]: src/adapter.c:read_commands_complete() kernel supports suspend/resume events
bluetoothd[352]: src/shared/mgmt.c:send_request() [0xffff] command 0x0003
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0xffff] command 0x0003 complete: 0x00
bluetoothd[352]: src/adapter.c:read_index_list_complete() Number of controllers: 1
bluetoothd[352]: src/adapter.c:read_index_list_complete() Found index 0
bluetoothd[352]: src/adapter.c:index_added() index 0
bluetoothd[352]: src/adapter.c:reset_adv_monitors() sending remove Adv Monitor command with handle 0
bluetoothd[352]: src/adapter.c:btd_adapter_new() System name: BlueZ 5.65
bluetoothd[352]: src/adapter.c:btd_adapter_new() Major class: 0
bluetoothd[352]: src/adapter.c:btd_adapter_new() Minor class: 0
bluetoothd[352]: src/adapter.c:btd_adapter_new() Modalias: usb:v1D6Bp0246d0541
bluetoothd[352]: src/adapter.c:btd_adapter_new() Discoverable timeout: 180 seconds
bluetoothd[352]: src/adapter.c:btd_adapter_new() Pairable timeout: 0 seconds
bluetoothd[352]: src/adapter.c:index_added() sending read info command for index 0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0053
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0053 complete: 0x00
bluetoothd[352]: src/adapter.c:reset_adv_monitors_complete() Removed all Adv Monitors
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0049
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0049 complete: 0x00
bluetoothd[352]: src/adapter.c:read_exp_features_complete() index 0 status 0x00
bluetoothd[352]: src/adapter.c:read_exp_features_complete() 671b10b5-42c0-4696-9227-eb28d1b049d6 flags 0 action 0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0004
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0004 complete: 0x00
bluetoothd[352]: src/adapter.c:read_info_complete() index 0 status 0x00
bluetoothd[352]: src/adapter.c:clear_uuids() sending clear uuids command for index 0
bluetoothd[352]: src/adapter.c:clear_devices() sending clear devices command for index 0
bluetoothd[352]: src/adapter.c:set_mode() sending set mode command for index 0
bluetoothd[352]: src/adapter.c:set_mode() sending set mode command for index 0
bluetoothd[352]: src/adapter.c:set_mode() sending set mode command for index 0
bluetoothd[352]: src/adapter.c:set_privacy() sending set privacy command for index 0
bluetoothd[352]: src/adapter.c:set_privacy() setting privacy mode 0x00 for index 0
bluetoothd[352]: src/gatt-database.c:btd_gatt_database_new() GATT Manager registered for adapter: /org/bluez/hci0
bluetoothd[352]: src/adapter.c:adapter_service_add() /org/bluez/hci0
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10001
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001800-0000-1000-8000-00805f9
bluetoothd[352]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
bluetoothd[352]: src/adapter.c:add_uuid() sending add uuid command for index 0
bluetoothd[352]: src/adapter.c:adapter_service_add() /org/bluez/hci0
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10002
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001801-0000-1000-8000-00805f9
bluetoothd[352]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
bluetoothd[352]: src/adapter.c:add_uuid() sending add uuid command for index 0
bluetoothd[352]: src/adapter.c:adapter_service_add() /org/bluez/hci0
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10003
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9
bluetoothd[352]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000180a-0000-1000-8000-00805f9
bluetoothd[352]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
bluetoothd[352]: src/adapter.c:add_uuid() sending add uuid command for index 0
bluetoothd[352]: src/advertising.c:btd_adv_manager_new() LE Advertising Manager created for adapter: /org/bluez/hci0
bluetoothd[352]: plugins/policy.c:policy_adapter_probe()
bluetoothd[352]: plugins/hostname.c:hostname_probe()
bluetoothd[352]: profiles/network/manager.c:panu_server_probe() path /org/bluez/hci0
bluetoothd[352]: profiles/network/server.c:server_register() Registered interface org.bluez.NetworkServer1 on path /org/bluez/hci0
bluetoothd[352]: profiles/network/manager.c:gn_server_probe() path /org/bluez/hci0
bluetoothd[352]: profiles/network/manager.c:nap_server_probe() path /org/bluez/hci0
bluetoothd[352]: src/adapter.c:btd_adapter_unblock_address() hci0 00:00:00:00:00:00
bluetoothd[352]: src/adapter.c:load_link_keys() hci0 keys 0 debug_keys 0
bluetoothd[352]: src/adapter.c:load_ltks() hci0 keys 0
bluetoothd[352]: src/adapter.c:load_irks() hci0 irks 0
bluetoothd[352]: src/adapter.c:load_conn_params() hci0 conn params 0
bluetoothd[352]: src/adapter.c:load_connections() sending get connections command for index 0
bluetoothd[352]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
bluetoothd[352]: src/adapter.c:add_uuid() sending add uuid command for index 0
bluetoothd[352]: src/adapter.c:set_did() hci0 source 2 vendor 1d6b product 246 version 541
bluetoothd[352]: src/adapter.c:adapter_register() Adapter /org/bluez/hci0 registered
bluetoothd[352]: src/adapter.c:set_dev_class() sending set device class command for index 0
bluetoothd[352]: src/adapter.c:set_name() sending set local name command for index 0
bluetoothd[352]: src/adapter.c:adapter_start() adapter /org/bluez/hci0 has been enabled
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0011
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0011 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0034
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0034 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x000b
[ 784.480375] Bluetooth: hu 5770f882 retransmitting 1 pkts
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x000b complete: 0x00
bluetoothd[352]: src/adapter.c:new_settings_callback() Settings: 0x000000c1
bluetoothd[352]: src/adapter.c:settings_changed() Changed settings: 0x00000040
bluetoothd[352]: src/adapter.c:settings_changed() Pending settings: 0x00000000
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x000d
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x000d complete: 0x00
bluetoothd[352]: src/adapter.c:new_settings_callback() Settings: 0x000002c1
bluetoothd[352]: src/adapter.c:settings_changed() Changed settings: 0x00000200
bluetoothd[352]: src/adapter.c:settings_changed() Pending settings: 0x00000000
bluetoothd[352]: src/adapter.c:trigger_passive_scanning()
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x002d
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x002d complete: 0x00
bluetoothd[352]: src/adapter.c:new_settings_callback() Settings: 0x00000ac1
bluetoothd[352]: src/adapter.c:settings_changed() Changed settings: 0x00000800
bluetoothd[352]: src/adapter.c:settings_changed() Pending settings: 0x00000000
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x002f
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x2f status: 0x0b
bluetoothd[352]: Failed to set privacy: Rejected (0x0b)
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0010
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0010 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0010
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0010 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0010
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0010 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x003d
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x003d complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0027
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0027 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0012
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0012 complete: 0x00
bluetoothd[352]: src/adapter.c:load_link_keys_complete() link keys loaded for hci0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0013
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0013 complete: 0x00
bluetoothd[352]: src/adapter.c:load_ltks_complete() LTKs loaded for hci0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0030
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0030 complete: 0x00
bluetoothd[352]: src/adapter.c:load_irks_complete() IRKs loaded for hci0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0035
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0035 complete: 0x00
bluetoothd[352]: src/adapter.c:load_conn_params_complete() Connection Parameters loaded for hci0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0015
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0015 complete: 0x00
bluetoothd[352]: src/adapter.c:get_connections_complete() Connection count: 0
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0010
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0010 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0028
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0028 complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x000e
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x000e complete: 0x00
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x000f
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x000f complete: 0x00
bluetoothd[352]: src/adapter.c:local_name_changed_callback() Name: BlueZ 5.65
bluetoothd[352]: src/adapter.c:local_name_changed_callback() Short name:
bluetoothd[352]: src/adapter.c:local_name_changed_callback() Current alias: BlueZ 5.65
bluetoothd[352]: src/shared/mgmt.c:send_request() [0x0000] command 0x0046
bluetoothd[352]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0046 complete: 0x00
bluetoothd[352]: src/adapter.c:set_blocked_keys_complete() Successfully set blocked keys for index 0
9 蓝牙连接
蓝牙的连接可以用buletoothctl或者hcitool,但是我的buletoothctl交互没有任何反应,所以我改成了使用hcitool。
hcitool 也是一样的,可以用hcitool查看一下,hcitool指令详解可以看链接hcitool命令详解和蓝牙工具hcitool和gatttool的使用
9.1 查看蓝牙地址
hcitool dev
蓝牙地址为 AC:35:EE:C7:C8:9F
9.2 开启广播
在蓝牙的使用中,如果我们的蓝牙作为从机,需要它进入到广播状态
hciconfig hci0 leadv
9.3 发现并连接
这时候,手机就可以发现蓝牙并连接了。连接之后可以获取其特征和服务等。
我这里的TEST即为我的蓝牙,我的名称为TEST是因为对它重新改名字了,如果是默认名字应该为bluez 5.65。