Adafruit Feather 32u4 Bluefruit LE: BLE GAP

From UNamur InfoSec
Revision as of 12:41, 15 December 2017 by Mkuy (talk | contribs) (→‎AT Commands)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

BLE GAP

GAP, which stands for the Generic Access Profile, governs advertising and connections with Bluetooth Low Energy devices.

The following commands can be used to configure the GAP settings on the BLE module.

You can use these commands to modify the advertising data (for ex. the device name that appears during the advertising process), to retrieve information about the connection that has been established between two devices, or the disconnect if you no longer wish to maintain a connection.

AT Commands

The Bluefruit LE modules use a Hayes AT-style command set to configure the device.

The advantage of an AT style command set is that it's easy to use in machine to machine communication, while still being somewhat user friendly for humans.

Test Command Mode '=?'

'Test' mode is used to check whether or not the specified command exists on the system or not.

Certain firmware versions or configurations may or may not include a specific command, and you can determine if the command is present by taking the command name and appending '=?' to it, as shown below

AT+BLESTARTADV=?

Write Command Mode '=xxx'

'Write' mode is used to assign specific value(s) to the command, such as changing the radio's transmit power level using the command we used above.

To write a value to the command, simple append an '=' sign to the command followed by any paramater(s) you wish to write (other than a lone '?' character which will be interpretted as tet mode):

AT+BLEPOWERLEVEL=-8

Execute Mode

'Execute' mode will cause the specific command to 'run', if possible, and will be used when the command name is entered with no additional parameters.

AT+FACTORYRESET

Read Command Mode '?'

'Read' mode is used to read the current value of a command.

Not every command supports read mode, but you generally use this to retrieve information like the current transmit power level for the radio by appending a '?' to the command, as shown below:

AT+BLEPOWERLEVEL?

AT+GAPSETADVDATA

Sets the raw advertising data payload to the specified byte array (overriding the normal advertising data), following the guidelines in the Bluetooth 4.0 or 4.1 Core Specification.

In particular, Core Specification Supplement (CSS) v4 contains the details on common advertising data fields like 'Flags' (Part A, Section 1.3) and the various Service UUID lists (Part A, Section 1.1). A list of all possible GAP Data Types is available on the Bluetooth SIG's Generic Access Profile page.

The Advertising Data payload consists of Generic Access Profile data that is inserted into the advertising packet in the following format: [U8:LEN] [U8:Data Type Value] [n:Value]

For example, to insert the 'Flags' Data Type (Data Type Value 0x01), and set the value to 0x06/0b00000110 (BR/EDR Not Supported and LE General Discoverable Mode) we would use the following byte array:

02-01-06
  • 0x02 indicates the number of bytes in the entry
  • 0x01 is the 'Data Type Value' and indicates that this is a 'Flag'
  • 0x06 (0b00000110) is the Flag value, and asserts the following fields (see Core Specification 4.0, Volume 3, Part C, 18.1):
    • LE General Discoverable Mode (i.e. anyone can discover this device)
    • BR/EDR Not Supported (i.e. this is a Bluetooth Low Energy only device)

If we also want to include two 16-bit service UUIDs in the advertising data (so that listening devices know that we support these services) we could append the following data to the byte array:

05-02-0D-18-0A-18
  • 0x05 indicates that the number of bytes in the entry (5)
  • 0x02 is the 'Data Type Value' and indicates that this is an 'Incomplete List of 16-bit Service Class UUIDs'
  • 0x0D 0x18 is the first 16-bit UUID (which translates to 0x180D, corresponding to the Heart Rate Service).
  • 0x0A 0x18 is another 16-bit UUID (which translates to 0x180A, corresponding to the Device Information Service).

The Example AT Command:

AT+GAPSETADVDATA=02-01-06-05-02-0d-18-0a-18

The results of this command can be seen in the screenshot below, taken from a sniffer analyzing the advertising packets in Wireshark. The advertising data payload is higlighted in blue in the raw byte array at the bottom of the image, and the packet analysis is in the upper section:

Adafruit screenshot gap adv.png

Reference

Adafruit Learn BLE GAP https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/ble-gap

Adafruit Learn AT Commands https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/at-commands

BLE Core Specification Supplement (CSS) V7 https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=421047