Android蓝牙开发常见问题

1 Pairing 
1.1 配对种类
PIN Code Pairing:需要双方蓝牙设备输入4位配对密码
Secure Simple Pairing:SSP,只需要双方确认屏幕上的6位随机数相同即可
- BLE选择何种配对方式,是跟双方的IO_Capability有关
- 蓝牙耳机使用SSP的Just Works - BT_SSP_VARIANT_CONSENT
- BluetoothDevice.ACTION_BOND_STATE_CHANGED

1.2 IO Capability
- BTM_LOCAL_IO_CAPS
- DisplayYesNo - 设置只有输入YES和NO的能力,能够显示

1.3 Android SSP Just Works代码流程
typedef struct {
    [...]
    /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
     * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
     * BT_SSP_VARIANT_CONSENT
     * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
     * shall be zero */
    int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
                     uint8_t accept, uint32_t passkey);
    [...]
};


/* Structure associated with BTA_DM_SP_CFM_REQ_EVT */
typedef struct
{
    [...]
    tBTA_IO_CAP     loc_io_caps;    /* IO Capabilities of local device */
    tBTA_AUTH_REQ   rmt_io_caps;    /* IO Capabilities of remote device */
} tBTA_DM_SP_CFM_REQ;

1.4 CC2564 SSP Just Works
IO_Capability = icNoInputNoOutput
BLE模式免配对用的就是Just Works(密码是000000)
MITM:Man in The Middle

2 bluedroid
2.1 MSM NVM
NV项是被存储在EFS文件系统(efs.img)中的 /nvm/num/ 或者 /nvm/context%d/ 子目录下。

2.2 HAL
@ hardware/qcom/bt/libbt-vendor/
NV_BD_ADDR_I: 447
ro.hardware.bluetooth
@ device/qcom/common/bdroid_buildcfg.h
#define BTM_DEF_LOCAL_NAME "QCOM-BTD"

2.3 HCI dump
@ /system/etc/bluetooth/bt_stack.conf
BtSnoopLogOutput=true
BtSnoopFileName=/sdcard/btsnoop_hci.log
TRC_HCI=5

Settings/Developer options/Enable Bluetooth HCI snoop log
btsnoop_hci.log

2.4 判断/dev/ttyS1是否被蓝牙进程打开?
lsof | grep /dev/ttyS1

2.5 Bond
@ system/bt/btif/src/bluetooth.c
static int create_bond(const bt_bdaddr_t *bd_addr, int transport);

// For NFC Touch Pairing
static int create_bond_out_of_band(const bt_bdaddr_t *bd_addr, int transport, const bt_out_of_band_data_t *oob_data);

2.6 Wireshark
Keywords: Sent Inquiry, Sent Create Connection, Sent Authentication Request

3 CSR bluecore
3.1 SDK
xIDE for ADK:Audio or Application Development Kit
xIDE for Bluelab
USB-SPI

3.2 CSR芯片版本差异
- rom版本一般是固定功能的,比较常见的是用于dongle和耳机的rom版本芯片,可以修改参数,但基本功能是固定的。
- flash版本可以自己开发固件,相对来说灵活性高一些;开发环境里面自带HCI以下协议。

3.3 URLs
CS-212778-AN-1.pdf

4 蓝牙抓包工具
- BEX400,Bluetooth Explorer 400;瑞士Ellisys
- FTS,FrontLine Sniffer;USA LeCroy公司

5  蓝牙转串口无线透传transparent
5.1 协议
使用蓝牙的RFCOMM协议

5.2 最常见透传模块
HC-06
HC-USB-P
HC助手

6 Abbreviations
ADK:Audio or Application Development Kit
BCSP:BlueCore Serial Protocol
COD:Class of Device
CSR:Cambridge Silicon Radio
H2:USB ,H2 means corresponding section of the Bluetooth specification
H3:RS232 ,H3 means corresponding section of the Bluetooth specification
H4:UART ,H4 means corresponding section of the Bluetooth specification
pass-through:设备的透传
PSKey:BlueCore Persistent Store Key
transparent:数据的透传
xIDE:CSR's Integrated Development Environment

你可能感兴趣的:(Wireless)