蓝牙协议概述


认识蓝牙协议

到目前为止,蓝牙协议已经发展到了4.x版本,各版本的基本信息如下:

Term Introduced Means
BR 1.1(2002) Basic Rate(1M/s)
EDR 2.0(2014) Enhanced Data Rate(2 ~ 3M/s)
HS 3.0(2009) Hight Speed (Alternate MAC/PHY)
LE 4.0(2010) Low Energy (1M/s, ultra low power)
Bluetooth Smart 4.0 Single mode, LE-only radio
Bluetooth Samrt Ready 4.0 Dual mode, BR/EDR and LE dual raio

各版本蓝牙层次结构图如下:
蓝牙层次图

其中Bluetooth LE的架构图如下: Bluetooth Architecture

链路层的拓扑图如下: Bluetooth Topology

蓝牙协议基本特征

Bluetooth is target at short-range communication. Every bluetooth device should have a unique physical address. The address is used in all layers of the Bluetooth communication process, from the low-level radio protocols to the higher level application protocols. Bluetooth devices will almost always have a userfriendly name. But it is the Bluetooth address that is used in actual communication.

All Bluetooth devices operate in the 2.4-GHz frequency band. The same radio frequencies as:

  • microwaves,
  • 802.11
  • Some cordless phones it divides the 2.4-GHz band into 79 channels and employs channel-hopping techniques

An actively communicating Bluetooth device changes channels every 625 μs (1600 times per second). two Bluetooth devices that are communicating with each other must hop channels together so that they’re always transmitting and receiving on the same frequencies

蓝牙网络

两个或以上的正在通信的蓝牙设备组成一个Piconet网,这些设备使用相同的跳频配置。 每个Piconet网内有一个蓝牙设备被指定为Master的角色,其他的设备则为Slave的角色。Slave依照Master指定的频率进行通信。 每个蓝牙设备理论上可以参与多个Piconet网,如果这是可能的,则这样的多个Piconet网形成的网络称为scatternet。

两个处于同一个Piconet网的蓝牙设备能够进行通信,而处于同一个Scatternet网,但不处于同一个Piconet网的蓝牙设备则不能进行通信。 不过,所有这些细节都由硬件或驱动自动处理,上层应用开发人员不需要关注。

蓝牙Profile

Bluetooth programming defines transport protocols and methods of communicating, but it also goes one step further to specify methods of using Bluetooth to accomplish higher level tasks. These methods and specifications are collectively called the Bluetooth Profiles

it define standardized ways to perform tasks such as transferring files, playing music, using nearby printers, and so on。 Some of the more well-known and widely used Bluetooth Profiles include:

  • OBEX Object Push:“Here, take this file,”
  • File Transfer:“Let me look at all of your files and do stuff (upload/download/rename/copy/etc.)”
  • Dial-Up Networking
  • Hands-Free Audio
  • Advanced Audio Distribution:L2CAP connections
  • Personal Area Network
  • Human Interface Device
  • Serial Port Profile:RFCOMM

蓝牙协议不能做的事情

  • Announce the presence of a device

    It is not possible for a Bluetooth device to do the equivalent of shouting, “Hello! Here I am!” It is only possible to inquire for nearby devices – similar to saying “Hello? Who’s there?”

  • Detect when a remote device is inquiring for nearby devices

    The Bluetooth adapter can detect this event, of course, but it just doesn’t pass that information on to the host computer.

  • Determine the Bluetooth address of an inquiring device

    A Bluetooth device conducting a device inquiry never transmits information identifying itself.

  • Distance to a remote Bluetooth device

  • Broadcast messages

    It is not possible for a Bluetooth device to broadcast a message to all nearby devices.

蓝牙总体架构

蓝牙构架分为Host端和Controller端,如下图所示: 蓝牙总体框架

  • Link Manager, Link Controller and BR/EDR Radio blocks comprise a BR/EDR Controller.
  • An AMP PAL, AMP MAC, and AMP PHY comprise an AMP Controller.
  • Link Manager, Link Controller and LE Radio blocks comprise an LE Controller.
  • L2CAP, SDP and GAP blocks comprise a BR/EDR Host.
  • L2CAP, SMP, Attribute protocol, GAP and Generic Attribute Profile (GATT) blocks comprise an LE Host.

蓝牙核心系统协议

The Bluetooth core system protocols are

  • the Radio (PHY) protocol,
  • Link Control (LC)
  • Link Manager (LM) protocol or Link Layer (LL) protocol
  • AMP PAL, Logical Link Control and Adaptation protocol (L2CAP)
  • AMP Manager Protocol,

Host Architectural Blocks

  • Channel Manager

    The channel manager is responsible for creating, managing and closing L2CAP channels for the transport of service protocols and application data streams.

  • L2CAP Resource Manager

    The L2CAP resource manager block is responsible for managing the ordering of submission of PDU fragments to the baseband and some relative scheduling between channels

  • Security Manager Protocol

    The Security Manager Protocol (SMP) is the peer-to-peer protocol used to generate encryption keys and identity keys.

  • Attribute Protocol

    The Attribute Protocol (ATT) block implements the peer-to-peer protocol between an attribute server and an attribute client.

  • AMP Manager Protocol

    The AMP manager is a layer that uses L2CAP to communicate with a peer AMP Manager on a remote device.

  • Generic Attribute Profile

    The Generic Attribute Profile (GATT) block represents the functionality of the attribute server and, optionally, the attribute client. GATT is used on LE devices for LE profile service discovery.

  • Generic Access Profile

    The Generic Access Profile (GAP) block represents the base functionality common to all Bluetooth devices GAP services include device discovery, connection modes, security, authentication, association models and service discovery.

Controller Architectural Blocks

  • Device Manager

    The device manager is the functional block in the baseband that controls the general behavior of the Bluetooth device.

  • Link Manager

    The link manager is responsible for the creation, modification and release of logical links (and, if required, their associated logical transports), as well as the update of parameters related to physical links between devices.

  • Baseband Resource Manager

    The baseband resource manager is responsible for all access to the radio medium.

  • Link Controller

    The link controller is responsible for the encoding and decoding of Bluetooth packets from the data payload and parameters related to the physical channel, logical transport and logical link.

  • PHY

    The PHY block is responsible for transmitting and receiving packets of information on the physical channel.

Bluetooth传输层协议

RFCOMM

  • The Radio Frequency Communications (RFCOMM) protocol is a reliable streams-based protocol
  • general-purpose transport protocol that happens to work well for emulating serial ports.
  • Like TCP, a reliable protocol
  • RFCOMM allows only 30 port number.

L2CAP

  • The Logical Link Control and Adaption Protocol (L2CAP) is a packet-based protocol that can be configured with varying levels of reliability
  • Package size: 672(default)~65,535 bytes
  • Like UDP, is a best-effort packet-based protocol, enforces delivery order.
  • can be configured for varying levels of reliability
  • serves as the transport protocol for RFCOMM.
  • every RFCOMM connection is actually encapsulated within an L2CAP connection.
  • Applications transmitting data, regardless of whether they require reliably delivered packets, should almost always use L2CAP connections

ACL

  • The Asynchronous Connection-oriented Logical (ACL) transport protocol.
  • All L2CAP connections are encapsulated within ACL connections.
  • Two Bluetooth devices can have at most a single ACL connection between them, which is used to transport all L2CAP and RFCOMM traffic.
  • ACL is similar to IP in that it is a fundamental protocol that is rarely used to directly transport data.
  • Instead, it is almost always used to encapsulate higher level protocol packets.

SCO

  • the Synchronous Connection-Oriented (SCO) logical transport.
  • a best-effort packet based protocol that is exclusively used to transmit voice-quality audio – not just any audio, but voice-quality audio, at exactly 64 kb/s.
  • SCO packets are not reliable and never retransmitted, but there is a separate quality of service guarantee.
  • An SCO connection is always guaranteed to have a 64 kb/s transmission rate.
  • no Bluetooth device is allowed to have more than three active SCO connections.
  • two Bluetooth devices can have at most one SCO connection between them.

Transport Protocol Summary

  • RFCOMM is often the best choice, and sometimes the only choice.
  • L2CAP is also a widely used transport protocol that is used when the streaming nature of RFCOMM isn’t needed.
  • ACL is used to carry only L2CAP and RFCOMM-related traffic, and you probably will never end up using it directly.
  • SCO is a highly specialized transport protocol designed specifically for voice-quality audio

BLUETOOTH APPLICATION ARCHITECTURE

BLUETOOTH PROFILES

Application interoperability in the Bluetooth system is accomplished by Bluetooth profiles. Bluetooth profiles define the required functions and features of each layer in the Bluetooth system from the PHY to L2CAP and any other protocols outside of the Core specification.

基于蓝牙的应用程序都是通过Profile来提供或获得彼此的服务的,从而实现设备间的互操作性。蓝牙Profile定义了蓝牙系统中从PHY到L2CAP各层间所需的功能和特性,也包括一些非核心规范之外的协议定义的功能和特性。

蓝牙Profile结构

另外,Profile也定义了应用程序的行为和数据格式。只有当两个设备同时符合一个Profile的要求,它们之间才能进行互操作。 GAP即Generic Access Profile,是所有蓝牙设备必须实现的一个Profile,它定义了一个蓝牙设备的基本要求。GAP也描述了设备发现,连接建立,安全,认证,关联模型和服务发现的行为和方法。 任何新实现的Profile都会基于GAP,提供的功能也是GAP所能提供的功能的超集。 处于最上层的Profile描述了应用程序之间的互操作,称为应用程序Profile。

Profile之间的依赖关系

对于BR/BER类型的蓝牙设备,它也定义一个单一的角色,这个角色决定了一个蓝牙设备的功能(设备怎样发现对方,连接怎样建立,怎样使用安全认证模型) 对于LE类型的蓝牙设备,定义了4种特别的角色:Broadcaster,Observer,Peripheral和Central。一个LE设备可能支持所有的角色,只要底层的FW支持。但是,任何时刻只能充当一种角色。

角色 描述
Broadcaster The Broadcaster role is optimized for transmitter only applications. Devices supporting the broadcaster role use advertising to broadcast data. The broadcaster role does not support connections.
Observer The Observer role is optimized for receiver only applications. Devices supporting the observer role are the complementary device for a broadcaster and receives broadcast data contained in advertisements. The observer role does not support connections.
Peripheral The Peripheral role is optimized for devices that support a single connection and are less complex than central devices. Devices supporting the peripheral role only require Controllers that support the Controller’s slave role.
Central The Central role supports multiple connections and is the initiator for all connections with devices in the peripheral role. Devices supporting the central role require a Controller that support the Controller’s master role and generally supports more complex functions compared to the other LE GAP roles.