Bluetooth LE discovery module

Use the Bluetooth® LE discovery module to discover GATT Services and read GATT Attribute Values from an nRF Desktop peripheral. The module is mandatory for the nRF Desktop central.

Module events

Source Module

Input Event

This Module

Output Event

Sink Module

Bluetooth LE advertising module

ble_peer_event

ble_discovery

Bluetooth LE state module

Source modules for module_state_event

module_state_event

Bluetooth LE discovery module

ble_discovery_complete_event

ble_discovery_complete_event

HID forward module

Bluetooth LE connection parameters module

Bluetooth LE scanning module

Bluetooth LE discovery module

module_state_event

Sink modules for module_state_event

Note

See the Application overview for more information about the event-based communication in the nRF Desktop application and about how to read this table.

Configuration

Complete the following steps to configure the module:

  1. Complete the basic Bluetooth configuration, as described in nRF Desktop: Bluetooth. Make sure that both CONFIG_DESKTOP_ROLE_HID_DONGLE and CONFIG_DESKTOP_BT_CENTRAL options are enabled. The Bluetooth LE discovery module is enabled by the CONFIG_DESKTOP_BLE_DISCOVERY_ENABLE Kconfig option which is implied by the CONFIG_DESKTOP_BT_CENTRAL Kconfig option together with other application modules. These modules are required for HID dongle that forwards the data from HID peripherals connected over Bluetooth.

  2. Make sure that the CONFIG_BT_GATT_CLIENT Kconfig option is enabled to support the GATT Client role. The GATT Client role is enabled by default by the CONFIG_DESKTOP_BT_CENTRAL Kconfig option.

  3. The Bluetooth LE discovery module module uses the GATT Discovery Manager and selects the CONFIG_BT_GATT_DM Kconfig option to enable the library.

  4. Define the module configuration in the ble_discovery_def.h file, located in the board-specific directory in the application configuration directory. You must define the following parameters for every nRF Desktop peripheral that connects with the given nRF Desktop central:

    • Parameters common for all the peripherals:

      • Vendor ID (VID)

    • Parameters defined separately for every peripheral:

      • Product ID (PID)

      • Peer type (PEER_TYPE_MOUSE or PEER_TYPE_KEYBOARD)

    For an example of the module configuration, see configuration/nrf52840dongle_nrf52840/ble_discovery_def.h.

    Note

    The module configuration example uses 0x1915 as Nordic Semiconductor’s VID. Make sure to change this value to the VID of your company.

    The assigned PIDs should be unique for devices with the same VID.

Implementation details

The Bluetooth LE discovery module implementation is tasked with peripheral discovery and verification.

Peripheral discovery

The module starts the peripheral device discovery when it receives ble_peer_event with ble_peer_event.state set to PEER_STATE_CONNECTED.

The peripheral discovery consists of the following steps:

  1. Reading device description. The central checks if the connected peripheral supports the LLPM (Low Latency Packet Mode). The device description is a GATT Characteristic that is specific for nRF Desktop peripherals and is implemented by Device description module.

  2. Reading Hardware ID (HW ID). The HW ID is unique per device and it is used to identify the device while forwarding the Configuration channel data. The HW ID is a read from a GATT Characteristic that is specific for nRF Desktop peripherals and is implemented by Device description module.

  3. Reading DIS (Device Information Service). The central reads VID and PID of the connected peripheral.

  4. HIDS (Human Interface Device Service) discovery. The central discovers HIDS and forwards the information to other application modules using ble_discovery_complete event. The HID forward module uses the event to register a new subscriber.

Note

Only one peripheral can be discovered at a time. The nRF Desktop central will not scan for new peripherals if a peripheral discovery is in progress.

Peripheral verification

If the connected peripheral does not provide one of the required GATT Characteristics, the central disconnects. The same actions are taken if the peripheral’s VID and PID value combination is unknown to the central.

The nRF Desktop central works only with predefined subset of peripherals. The mentioned peripherals must be described in the ble_discovery_def.h file.