Skip to content

Peripheral BLE_GAP_EVENT_CONNECT arrives late causing GATT operations to occur before connection event #117

@h2zero

Description

@h2zero

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

always

Expected behavior

The peripheral should know about a connected central before any other connection oriented event occurs.

Actual behavior (suspected bug)

When acting as a peripheral the central starts requesting reads/writes etc. before the peripheral knows about the connection.

Error logs or terminal output

Steps to reproduce the behavior

The cause is here:

ble_gap_rd_rem_ver_tx(evt->connection_handle);

Instead of calling ble_gap_event_connect_call(evt->connection_handle, evt->status);, as it should in the slave roll since the connection has already been established, it waits for the result of ble_gap_rd_rem_ver_tx(evt->connection_handle); before sending the connection event.

During this time the central could, and in my tests does, start performing GATT operations before the application knows about the connection.

Project release version

latest

System architecture

Intel/AMD 64-bit (modern PC, older Mac)

Operating system

Linux

Operating system version

all

Shell

Bash

Additional context

The fix is simple, at:

ble_gap_rd_rem_ver_tx(evt->connection_handle);

Change it to:

    if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) {
        ble_gap_event_connect_call(evt->connection_handle, evt->status);
        ble_gap_rd_rem_ver_tx(evt->connection_handle);
    } else {
        ble_gap_rd_rem_sup_feat_tx(evt->connection_handle);
    }

And at :

Remove the else block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions