How Bluetooth LE works? -- Host stack

How Bluetooth LE works? – Host stack


Table of Contents

  • 1 Bluetooth LE hosts stack architecture
  • 2 L2CAP
  • 3 Attribute
  • 4 The Attribute Protocol and The Generic Attribute Profile

1 Bluetooth LE hosts stack architecture

                                      
          +----------------------------------+
          |                                  |
          |  Generic Attribute Profile       |
          +----------------------------------+
          |                                  |
          |           Attribute Protocol     |
          +----------------------------------+
          |                                  |
          |             L2CAP                |
          +----------------------------------+
                                      

Bluetooth LE's host stack is built under the Host Control interface, which is used to connect with controller part. As showing in the above figures, there are at least three layers which need to introduce in this article, GATT, ATT, L2CAP.

2 L2CAP

L2CAP provided a layer just like TCP on The Internet, you can open an L2CAP type socket and bind a port number into it, then build your communication program based on it. In Bluetooth LE, only fixed ports are used to build upper protocol(Attribute Protocol).

Channel IdentifierUse
0x0000Reserved: cannot be used
0x0001Bluetooth Classic signaling channel
0x0002"Connectionless" channel
0x0003AMP manager protocol
0x0004Attribute Protocol
0x0005LE signaling Protocol
0x0006Security Manager Protocol
0x0007 to 0x003EReserved: maybe used in the future
0x003FAMP test protocol
0x0040 to 0xFFFFConnection-oriented channels

In this section, I mentioned port and channel, never minded, they are actually the same meaning. Another thing should be pointed is that L2CAP is not only used for Bluetooth LE, but also for Bluetooth classic, and according to the above table, there are only three L2CAP's channels used to implemented the Bluetooth LE.

Channel 0x0004 is used for Attribute Protocol, Channel 0x0005 is used for LE signaling protocol, Channel 0x0006 is used for the security manager.

3 Attribute

To understand Attribute is to understand Bluetooth LE. So the first question is what the attribute is?
                                      
    +-----------------+-----------------------+----------------------+
    |   handle(2 oct) | type(2 or 16 octets)  | value(0 to 512 oct)  |
    +-----------------+-----------------------+----------------------+


An Attribute is a piece of labeled and addressable data. The above table shows that an attribute composed of three segments: handle, type, and value. The attribute handles' valid value are from 0x0001 to 0xFFFF, 0x0000 is an invalid handle. I consider the attribute handle is the address of an attribute in a device.

The attribute type is used to identify the type of attribute, this identity is also called UUID, which is huge and has 128-bit length. In order to short the attribute size, a simpler and short 16-bit number is used to replace the large UUID.

A collection of attributes is called a database. A database defines how those attributes are used in services and profiles. There is only one attribute server on each device, there is only one attribute database on each device.

A service is a grouping of one or more characteristics; a characteristic is a grouping of one or more attributes.

4 The Attribute Protocol and The Generic Attribute Profile

The Attribute Protocol defines how a client and server can send standard messages between one another. The GATT procedures define standard way that services, characteristics, and their descriptors can be discovered and then used.

The Attribute protocol defines six basic operations to manipulate the attributes, which is Request, Response, Command, Indication, Confirmation, Notification. Those operations are annoying, I couldn't illustrate them all in details, they can only be understood by reading the real code.

The GATT procedures can be considered to split into three basic types: Discovery procedures, client-initiated procedures, and server-initiated procedures.

So, That's all of them, about the Attribute protocol and GATT profile still need more words to figure them out, and there is still some part of them which I didn't understand without reading some codes. Next, I should write some applications in order to understand them.

Comments

Popular posts from this blog

Bluedroid stack in android

How to setup a NAT server?

Network programming in elisp