Tuya Ble BlueZ5
2020-02-28 11:31:05 10 举报
AI智能生成
bluez5
作者其他创作
大纲/内容
bluez协议栈介绍及分层理解
介绍
BlueZ 是官方 Linux Bluetooth 栈,由主机控制接口(Host Control Interface ,HCI)层、Bluetooth 协议核心、<br>逻辑链路控制和适配协议(Logical Link Control and Adaptation Protocol,L2CAP)、<br>SCO 音频层、其他 Bluetooth 服务、用户空间后台进程以及配置工具组成<br>
蓝牙协议
1)Classic Bluetooth (BR/EDR)<br>2)Bluetooth Smart (Low Energy)
划分
linux
(1)Debian GNU / Linux<br>(2)Ubuntu Linux<br>(3)Fedora Core / Red Hat Linux<br>(4)OpenSuSE / SuSE Linux<br>(5)Mandrake Linux<br>(6)Gentoo Linux<br>(7)Chrome操作系统
处理器
(1)英特尔和AMD x86<br>(2)AMD64和EM64T(x86-64)<br>(3)SUN SPARC 32 / 64bit<br>(4)PowerPC 32 / 64bit<br>(5)英特尔StrongARM和XScale<br>(6)日立/瑞萨SH处理器<br>(7)摩托罗拉 DragonBall
守护进程
bluetoothd
BlueZ的中央守护进程
obexd<br>
是OBEX协议的守护进程
工具使用及源码分析
命令行测试工具<br>
bluetoothctl
可直接命令行测试以及信息show
bluetoothd测试工具
obexctl
可直接命令行测试以及信息show
信息跟踪
btmon【建议使用】
信息直接解析
工具使用及源码分析
hciconfig *
eg: hciconfig hci0 leadv 0
hcitool *
eg: hcitool -i hci0 cmd 0x08 0x0008 1F 02 01 06 1a ff 4c 00 02 15<br> e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 00<br>
btmgmt *
btmgmt info/io-cap/power..
gatt-service *
gatt-service example
hcidump<target-group-name></target-group-name>
hcidump -i hci0 -wt test.cfa
ciptool
cip disconnect
...
平台验证及功能验证
平台验证
1)Ubuntu Linux 16.04 × cannot disconnect<br>2) Ubuntu Linux 18.04 × cannot disconnect<br>3) Raspberry Pi × cannot disconnect<br>4) RK3308 with RTL wifi+bt modules √ 20s disconnect *
功能验证
特定广播
eg: hcitool -i hci0 cmd 0x08 0x0008 1F 02 01 06 1a ff 4c 00 02 15 <br>e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 00 √<br><br>hciconfig hci0 leadv 0<br>
1) 广播包 correct √<br>2) 响应包 correct √
添加服务
1) 添加Tuya BLE 服务 √ *<br>2) 测试RX TX通信 √ *<br>
安卓 IOS平台
1) 链接Gatt 服务,通信ok √
1) 连接,断连测试,测试于LightBlue 工具<br>2) 【问题】测试于IOS 平台,无法正确断连。
问题总结梳理
【问题描述】
【问题】:当前在PC Linux环境下,我们发送固定广播,让IOS设备端用Lightblue去连接,无法正确断开!<br>1,在pairable&bondable的情况下,连接后会保持系统连接,推出app无法断连。不可取于我们当前BLE架构。<br>2,在非pairbale和bondable的情况下,我们连接可以在退出app后断开连接,同时,退出app后,连接也会断开<br>经过抓包发现,虽然建立了连接并且可以通信,但是一直会有pairing request,该方案受限于目前无法知道PC <br>Linux kernel是否有这一层设计,暂定!<br>3,在板载Linux芯片RK3308上,我们发现经过定制的hci uart driver上有pairing request cancel这一层机制,但是目前<br>需要经过20-30秒后才可断开,目前该kernel开源,便于今后了解其机制。
测试方案
1,取消ssp,取消bondable<br>2,使用btmgmt 取消io-cap设定<br>3,通过btmgmt主动关闭bredr设定<br>4,通过hciconfig主动去关闭ssp设定<br>5,通过取消event mask部分request<br>6,通过设定main.conf dual-> LE<br>7,通过bluetoothctl主动关闭bondable以及配合固定广播<br>8,通过hcitool去设定noauth和no encrypt模式<br>9,多平台验证固定广播,不一样的现象<br>10,重新配置bluez->bluetoothd<br>11, disable bluez5.51部分功能,并重新注册agent<br>12,抓取每次power off/on设定,抓取连接断开的数据并解析,<br>可使用hcidump,btmon, 上位机,wireshark,comprobe protocol<br>13,以及更多bluez工具,不再详述
测试结论
1,PC Linux受限kernel driver,目前无法正确断连。后期会继续同步<br>2,板载linux后期可优化20s断开问题(kernel开源),可以断开连接
Tuya Ble BlueZ 私有库设计
设计思想
抽离BlueZ5,建立与Bluez5无关的私有库
前提条件
1)PC端需要安装BlueZ,确定安装Bluetoothd,具体版本有内核最新版本确定。例如Unbuntu16.04最新版本bluetoothd 5.37<br>
apt-get install bluez
2) PC端有安装对应版本BlueZ5,例如:bluez5.51
安装对应库:sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev <br>automake libudev-dev libical-dev libreadline-dev<br>
配置所需信息:./configure --prefix=/usr --mandir=/usr/share/man <br>--sysconfdir=/etc --localstatedir=/var<br>
编译器:GCC(利用Makefile.guess去猜)
编译安装: make-->make install
3)裸机环境(具体指:RK3308),以及内核移植,环境搭建(待定)
工具熟悉以及源码提取
hciconfig
hcitool
btmgmt
gatt-service, client
蓝牙接口设计并适配tuya ble sdk与tuya ble os
裸机平台到Linux 设计
timer
普通timer,alarm,用于事件
精确timer,用于timestamp
线程池
链式线程池,便于event控制
文件io操作,类于读写flash
同时配合kv组件操作,便于管理数据
接口设计
框架设计
Makefile编写
Tuya Ble SDK 移植规划
移植easylogger,mbedTLS,micro-ECC<br>
移植单点加密SDK<br>
移植并测试配网部分
移植蓝牙单点模块
功能验证
1) PC linux 方向
2) 裸板Linux方向
0 条评论
下一页
为你推荐
查看更多