Skip to content

nimble/bttester: Subrating support #2077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/bttester/src/btp/btp_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ struct gap_periodic_adv_sync_transfer_recv_cmd {
uint16_t sync_timeout;
uint8_t flags;
} __packed;

#define GAP_SUBRATE_REQUEST 0x2b
struct gap_subrate_request_cmd {
ble_addr_t address;
uint16_t subrate_min;
uint16_t subrate_max;
uint16_t max_latency;
uint16_t cont_num;
uint16_t supervision_timeout;
} __packed;

/* events */
#define BTP_GAP_EV_NEW_SETTINGS 0x80
struct btp_gap_new_settings_ev {
Expand Down Expand Up @@ -444,3 +455,14 @@ struct gap_periodic_transfer_recieved_ev {
uint8_t status;
ble_addr_t peer_addr;
} __packed;

#define GAP_EV_SUBRATE_CHANGE 0x92
struct gap_subrate_change_ev {
ble_addr_t addr;
uint8_t status;
uint16_t conn_handle;
uint16_t subrate_factor;
uint16_t periph_latency;
uint16_t cont_num;
uint16_t supervision_tmo;
} __packed;
67 changes: 67 additions & 0 deletions apps/bttester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,30 @@ periodic_transfer_received(struct ble_gap_event *event)
}
#endif

#if MYNEWT_VAL(BLE_CONN_SUBRATING)
static void
subrate_change_received(struct ble_gap_event *event)
{
int rc;
struct ble_gap_conn_desc desc;
struct gap_subrate_change_ev ev;

rc = ble_gap_conn_find(event->subrate_change.conn_handle, &desc);
assert(rc == 0);

ev.addr = desc.peer_ota_addr;
ev.status = event->subrate_change.status;
ev.conn_handle = event->subrate_change.conn_handle;
ev.subrate_factor = event->subrate_change.subrate_factor;
ev.periph_latency = event->subrate_change.periph_latency;
ev.cont_num = event->subrate_change.cont_num;
ev.supervision_tmo = event->subrate_change.supervision_tmo;

tester_event(BTP_SERVICE_ID_GAP, GAP_EV_SUBRATE_CHANGE, (uint8_t *)&ev,
sizeof(ev));
}
#endif

static void
print_bytes(const uint8_t *bytes, int len)
{
Expand Down Expand Up @@ -1563,6 +1587,19 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
event->periodic_transfer.adv_clk_accuracy);
periodic_transfer_received(event);
break;
#endif
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
case BLE_GAP_EVENT_SUBRATE_CHANGE:
console_printf(
"Subrate change received:"
"status=%d, conn_handle=%d, subrate_factor=%d, perpih_latency=%d,"
"cont_num=%d supervision_tmo=%d",
event->subrate_change.status, event->subrate_change.conn_handle,
event->subrate_change.subrate_factor,
event->subrate_change.periph_latency, event->subrate_change.cont_num,
event->subrate_change.supervision_tmo);
subrate_change_received(event);
break;
#endif
default:
break;
Expand Down Expand Up @@ -2210,6 +2247,29 @@ periodic_adv_sync_transfer_set_info(const void *cmd, uint16_t cmd_len,
}
#endif

#if MYNEWT_VAL(BLE_CONN_SUBRATING)
static uint8_t
subrate_request(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
{
const struct gap_subrate_request_cmd *cp = cmd;
struct ble_gap_conn_desc desc;
int rc;

rc = gap_conn_find_by_addr(&cp->address, &desc);
if (rc) {
return BTP_STATUS_FAILED;
}

rc = ble_gap_subrate_req(desc.conn_handle, cp->subrate_min, cp->subrate_max,
cp->max_latency, cp->cont_num, cp->supervision_timeout);
if (rc) {
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}
#endif

static const struct btp_handler handlers[] = {
{
.opcode = BTP_GAP_READ_SUPPORTED_COMMANDS,
Expand Down Expand Up @@ -2380,6 +2440,13 @@ static const struct btp_handler handlers[] = {
.func = periodic_adv_sync_transfer_recv,
},
#endif
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
{
.opcode = GAP_SUBRATE_REQUEST,
.expect_len = sizeof(struct gap_subrate_request_cmd),
.func = subrate_request,
},
#endif
};

static void
Expand Down
1 change: 1 addition & 0 deletions apps/bttester/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,4 @@ syscfg.vals.!BTTESTER_NODEFAULT:
BLE_MESH_RX_SEG_MAX: 13
BLE_MESH_TX_SEG_MSG_COUNT: 2
BLE_MAX_CONNECTIONS: 8
BLE_CONN_SUBRATING: 1
1 change: 1 addition & 0 deletions nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,7 @@ ble_gap_rx_subrate_change(const struct ble_hci_ev_le_subev_subrate_change *ev)
event.subrate_change.supervision_tmo = le16toh(ev->supervision_tmo);

ble_gap_event_listener_call(&event);
ble_gap_call_conn_event_cb(&event, ev->conn_handle);
}
#endif

Expand Down
Loading