linux bluetooth

一 、底层kernel的配置情况
[*] Networking support —>
/Unix socket配置/
Networking options —>
<*> Unix domain sockets
/* Bluetooth子系统配置 */
<*> Bluetooth subsystem support —>
<*> L2CAP protocol suppor
<*> SCO links support
<*> RFCOMM protocol support
[*] RFCOMM TTY support
<*> BNEP protocol support
[*] Multicast filter support
[*] Protocol filter support
<*> HIDP protocol support
Bluetooth device drivers —>
<*> HCI UART driver
[*] UART (H4) protocol support
[ ] BCSP protocol support
[ ] Atheros AR300x serial support
[*] HCILL protocol support
< > HCI VHCI (Virtual HCI device) driver
< > Marvell Bluetooth driver support
/* RF switch 子系统配置 */
<*> RF switch subsystem support —>
[*] Power off on suspend
[*] RF switch input support
/蓝牙misc设备配置/
Device Drivers —>
[*] Misc devices —>
<*> Bluetooth power control driver
<*> BCM module power control core driver
/UART0配置/
Character devices —>
Serial drivers —>
[*] enable uart0
[ ] enable uart0 dma mode

二、启动蓝牙的脚本
#!/bin/sh

echo 1 > /sys/class/rfkill/rfkill0/state (setting中开关状态)
brcm_patchram_plus –patchram /usr/etc/bluetooth/bcm43341.hcd –baudrate 3000000 –enable_hci –bd_addr 11:11:11:11:11:11 – tosleep=5000 –no2bytes /dev/ttyS0
( brcm_patchram_plus 命令是蓝牙芯片厂商博通提供的,将固件加载到芯片中,初始化芯片用,后面配波特率,接着配串口(uart),通过uart加载到蓝牙芯片中,这个段程序在android中的external//bluetooth/bluedroid 再到 hardware/broadcom/libbt/src/hardware.c,也就是上层通过层层调用最后执行到这里)
hciattach -s 3000000 /dev/ttyS0 any 3000000
(ttyS0走哪个串口由kernel来配置)
rfkill unblock all (解锁)
hciconfig hci0 up (激活蓝牙,上电,hci0是套接字,底层走pmu供电,蓝牙打不开问题跟底层串口配置有关)
bluetoothd –udev (bluez协议栈) 启动协议栈守护进程
sleep 2
hciconfig hci0 reset

hcitool cmd 0x03 0x001A 0x03 (使蓝牙设备可见,执行这步时会走bluez,蓝牙搜索不到问题有关)

#close bluetooth
# hciconfig hci0 down

(1)其中hcittach 命令的源码在bluez/tools/hciconfig.c
蓝牙设备(IC)与CPU之间,它们之间的接口称为 HCI

(2)L2CAP Logical Link Control and Adaptation Protocol 实现蓝牙数据包分割和重组,信息传递服务质量,可以理解为是蓝牙的网络层协议,主要在Linux主要由驱动来实现。

(3)HCI只是提出一个抽象的逻辑接口,具体蓝牙设备与CPU互联还是需要特定的硬件方式.
最常见的是USB联接,市面常见USB蓝牙棒即是此类接口。
还有UART串口形式的蓝牙设备。

三、M200芯片内部原理图:
这里写图片描述

bt芯片的驱动是bcm43341.hcd,
蓝牙通过uart和CPU通信。上层是bluez协议栈。

四、android蓝牙结构图
这里写图片描述

发布了35 篇原创文章 · 获赞 8 · 访问量 10万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章