> For the complete documentation index, see [llms.txt](https://davidjosearaujo.gitbook.io/notes-miect/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://davidjosearaujo.gitbook.io/notes-miect/comunicacoes-moveis/bluetooth-wireless-sensor-networks-zigbee/bluetooth/802.15.x/bluetooth-4.0-low-energy/ble-and-gap.md).

# BLE and GAP

## Generic Access Profile (GAP).

* GAP defines a base profile which all Bluetooth devices implement, which ties all the various layers together to form the basic requirements for a Bluetooth device.
* GAP also defines generic procedures for connection-related services:
  * Device Discovery.
  * Link Establishment.
  * Link Management.
  * Link Termination.
  * Initiation of security features.

The GAP layer works in one of **four** profile roles:

* **Broadcaster**: an advertiser that is non-connectable.
* **Observer**: scans for advertisements, but cannot initiate connections.
* **Peripheral**: an advertiser that is connectable and can operate as a slave in a single link layer connection.
* **Central**: scans for advertisements and initiates connections; operates as a master in a single or multiple link layer connections.

<figure><img src="https://2294401029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1IGi5yHjBBVlQOff5FyI%2Fuploads%2FqbKW9AquiABIIiSpYADr%2Fa.png?alt=media&amp;token=0fdb61d7-ddf6-40c0-926b-a99147558811" alt=""><figcaption></figcaption></figure>

### Discoverable Modes

GAP supports **three** different discoverable modes:

* **Non-discoverable Mode**: No advertisements.
* **Limited Discoverable Mode**: Device advertises for a limited amount of time before returning to the standby state.
* **General Discoverable Mode**: Devices Advertises continuously.

GAP manages the data that is sent out in advertisement and scan response packets.

### Pairing

Pairing can be **initiated by either the central or peripheral device**.

The two devices generate and **exchange short-term keys** (STK) which can be used to decrypt data packets.

Either device can request to enable “bonding” to create a long- term relationship between the two devices.

* A long-term key (LTK) is generated, exchanged, and stored allowing device to re-encrypt the link quickly upon re-connection, **without going through the complete pairing process once again**.
* Profile / Service configuration data is remembered, so that the user does not need to re-configure the device every time they re- connect.

Each device also states its input/output capabilities from among these options:

* **DisplayOnly** – no way user can input anything into device, but it can output data.
* **DisplayYesNo** – user can input “yes” or “no” but nothing else; can also display data.
* **KeyboardOnly** – user can input a password or PIN, but no display.
* **NoInputNoOutput** – device has no means for user input, and has no display.
* **KeyboardDisplay** – device has a means for display as well as for input.
