蓝牙bluetooth

转自:http://blog.csdn.net/shichaog/article/details/51931898

参考:

https://www.cnblogs.com/yanghong-hnu/p/4713222.html

https://www.crifan.com/summary_bluetooth_specification_download/

http://blog.csdn.net/xlc2845321/article/details/58606676

http://blog.csdn.net/Innost/article/details/9187199

http://blog.csdn.net/androidstarjack/article/details/60468468

http://blog.csdn.net/xubin341719/article/details/38519555

http://www.cnblogs.com/zjutlitao/p/4742428.html


蓝牙profile的作用


蓝牙子系统应用程序的交互通过蓝牙profile实现。profile有些文献将其解释为子协议,似乎不是很准确,我依然以profile称呼它。蓝牙profile定义了蓝牙子系统分层结构中的每一层需要具有的功能和特性。
GAP(Generic Access Profile):基本的profile,每一个蓝牙设备都要实现该profile。对于BR/EDR,其定义了Radio,Baseband,Link Manager,L2CAP以及服务发现功能。对于LE,定义了Physical Layer,Link Layer,L2CAP,Security Manager,Attribute Protocol以及Generic Attribute Profile。
在BR/EDR中,GAP定义了设备发现,连接建立,安全,授权相关的模型和服务发现的行为和方法。

Physical channels, apart from the synchronization scan physical channel (which uses a set of fixed RF channels), are defined by a pseudo-random RF channel hopping sequence, the packet (slot) timing and an access code.

Five Bluetooth physical channels are defined. Each is optimized and used for a different purpose. Two of these physical channels (the basic piconet channel and adapted piconet channel) are used for communication between connected devices and are associated with a specific piconet. Other physical channels are used for discovering (the inquiry scan channel) and connecting (the page scan channel) Bluetooth devices. The synchronization scan physical channel is used by devices to obtain timing and frequency information about the Connectionless Slave Broadcast physical link or to recover the current piconet clock.

Whenever a Bluetooth device is synchronized to the timing, frequency and access code of a physical channel it is said to be 'connected' to this channel (whether or not it is actively involved in communications over the channel.)
A physical link represents a baseband connection between devices.


BT,核心规范


BT设备根据BT规范进行协议信息交换。系统核心规范是:radio(RF)协议,link(LC)控制协议,link(LM)管理协议以及 logical link control and adaptation protocol (L2CAP)。
最底下的三层是,RF,LC,LM,它们通常被放在一起组成蓝牙的(BT controller)控制子系统,蓝牙控制子系统通过(HCI,Host Controller Interface)接口和蓝牙系统(BT host)其它部分进行双向通信。
Primary controller可以是如下三种情况:
    BR/EDR:包括RF,基带,LM,也可能包括HCI
    LE:包括LE PHY,Link layer,也可能包括HCI
    BR/EDR和LE双模:LE PHY, Link layer,它们共享同一个设备地址。

Bluetooth Basic Rate/Enhanced Data Rate (BR/EDR)Bluetooth with low energy (LE)


蓝牙层次图

分为controller,host以及app三个层次。

Physical(PHY)层

控制蓝牙通信通道的2.4GHz RF信号的发送和接收,BR/EDR提供窄带更多通道,LE则使用宽带更少的通道,这是蓝牙芯片支持的功能。

Link Layer

定义了数据包结构/通道,发现/连接过程以及发送/接收数据

Direct Test Mode

可以让测试者指定PHY层发送或接收给定序列的数据包,通过HCI或者2线UART接口控制,认证测试会使用到这个模式。

Host to Controller Interface(HCI)

Logical Link Control and Adaptation Protocol(L2CAP) Layer

基于发送到HCI或者直接发送到LM的数据包协议,支持更高层协议复用,分包和组包以及将QoS信息发送到上层。

Attribute Protocol(ATT)

定义了当连接建立时客服端/服务端数据交互协议。属性将被GATT Profile打包,ATT使用在LE模式上,偶尔用在BR/EDR模式。

Security Manger

定义了设备间管理配对完整性/授权/加密的协议和行为。

Generic Attribute Profile(GATT)

主要用于寻找和配置服务端的属性,其实就是寻找、配置和读写servcice端的各种attribute,使其按需要的方式工作。

Generic Access Profile(GAP)

在LE模式下和GATT一起定义了发现和共享蓝牙设备信息的过程和角色。

OPP:对象存储规范(Object Push Profile),最为常见的,文件的传输都是使用此协议。

HID(Human Interface Device)人机接口设备。


中间协议层
L2CAP:Logical Link Control and Adaptation Protocol,数据的拆装,服务质量和协议复用等功能
SDP:(Service Discovery Protocol),提供一种机制来发现网络中可用的服务及其特性
GAP:(Generic Acess Profile),该profile保证不同的Bluetooth产品可以互相发现对方并建立连接。
EDR(Enhanced Data Rate)
HS(High Speed):是bt能够利用wifi作为传输方式进行数据传输。

其分层对应的框图

这张图显示了哪里是firmware,哪里是hardware,哪里是sofware实现的,基带控制器是硬件实现的,HCI firmware,Link Manager以及physical bus是蓝牙芯片厂商实现的,并在其提供的firmware中。

软件层需要实现的包括接口驱动,hci驱动以及其它更高层次的驱动。

蓝牙协议栈

蓝牙在安卓中的代码


蓝牙profile


顶层应用框架(Profiles)
SPP(Serial prot profile):串行端口服务配置文件,通过蓝牙技术将手机与PC连接。
OPP(object push profile):对象操作配置文件。主要是手机与手机,或是手机与电脑之间通过蓝牙进行文件操作。(如,名片交换/便签/日历/书签等。)
FTP(File Transfer Profile):文档传输配置文件。其同OPP操作时的文件不同。在进行FTP操作时,还可以建立新的复制/删除等操作,并且在文件传输过程中可以进行接受/拒绝或者中断等操作。而OPP操作时则不能进行此类动作。
A2DP(Anvanced Audio Distribution Profile)蓝牙音频传输模型配置文件。无线传输立体声。
A2DP采样率44.1KHz,采样位数:16位。
HFP:采样率是8KHz,采样位数8位。
只在音乐播放器播放音乐或者电影播放器中播放电影使用A2DP,其余情况使用HFP协议。
AVRCP(Audio/Video Remote Control Profile),音频/视频远程控制配置文件,比如用户通过蓝牙耳机远程遥控手机,包括:暂停/停止/播放/切歌/音频控制。
HSP(Headset profile),耳机配置文件。
HFP(Hands free profile),免提配置文件。蓝牙耳机,蓝牙音箱等设备,HFP相关的配置文件有HSP,PBAP。
PBAP(Phonebook Acess profile),电话本访问配置文件。主要用于读取手机中通信录。
SAP(SIM Access Profile),可访问手机内的SIM卡。
HRP(Heart Rate Profile),心率配置文件。使用与和医疗/健康相关的应用场景中,它使得蓝牙设备能与心率传感器交互。
BPP(Basic Printing Profile),基本 打印配置文件,可将文件/电子邮件传至打印机打印。
CTP(Cordless Telephony Profile),无线电话规范,蓝牙无线电话之间沟通的规范。
HID()人性化接口设备
BT4.1支持Multi-Link,其类似于Zigbee技术。
HDP (Health Device Profile) 蓝牙医疗设备模式 可以创建支持蓝牙的医疗设备,使用蓝牙通信的应用程序,例如心率监视器,血液,温度计和秤。

Generic Attribute Profile (GATT) 通过BLE连接,读写属性类小数据的Profile通用规范。
MAP:message access profile。
PAN个人区域网用户 (PANU) 设备、小组临时网络 (GN) 设备或网络访问点 (NAP) 设备。

传输速率

Basic Rate system offers synchronous and aysnchronous connections.
721.2kb/s for Basic Rate.
2.1Mb/s for Enhanced Data Rate
54Mb/s for high speed with 802.11 AMP.Alternate MAC/PHY (AMP).

接入模式和跳频

LE employs two multiple access schemes: Frequency division multiple access (FDMA) and time division multiple access (TDMA). Forty (40) physical channels, separated by 2 MHz, are used in the FDMA scheme. Three (3) are used as advertising channels and 37 are used as data channels.

The basic hopping pattern is a pseudo-random ordering of the 79 frequencies, separated by 1 MHz, in the ISM band.

FHSS,跳频技术 (Frequency-Hopping Spread Spectrum)在同步、且同时的情况下,接受两端以特定型式的窄频载波来传送讯号,对于一个非特定的接受器,FHSS所产生的跳动讯号对它而言,也只算是脉冲噪声。FHSS所展开的讯号可依特别设计来规避噪声或One-to-Many的非重复的频道,并且这些跳频讯号必须遵守FCC的要求,使用75个以上的跳频讯号、且跳频至下一个频率的最大时间间隔(Dwell Time)为400ms。

在主从设备的物理通道(channel)之间会建立物理链路(link)。但是在查询扫描(inquiry scan)和页扫描(page scan)物理通道并没有关联物理链路。物理链路提供了主从设备之间的双向packet(命令和数据)的传输,一个特例是没有和主建立链接的从设备广播自己的物理链路(Physical link)。

蓝牙4.0


BT协议栈在整个蓝牙使用架构中的位置

Bluedroid下的蓝牙开发具体流程

模拟串口RFCOMM协议如下:

RFcomm是串口模拟协议,



HFP涉及的profile如下:


猜你喜欢

转载自blog.csdn.net/fchyang/article/details/79259687