Skip to content

Commit 3551b76

Browse files
committed
Fix connection handle tracking in PacketBuffer when a server.
1 parent 59eb35d commit 3551b76

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ports/nrf/common-hal/_bleio/PacketBuffer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
156156
return false;
157157
}
158158
write_to_ringbuf(self, evt_write->data, evt_write->len);
159-
} else if (evt_write->handle == self->characteristic->cccd_handle &&
160-
self->conn_handle == BLE_CONN_HANDLE_INVALID) {
159+
} else if (evt_write->handle == self->characteristic->cccd_handle) {
161160
uint16_t cccd = *((uint16_t*) evt_write->data);
162161
if (cccd & BLE_GATT_HVX_NOTIFICATION) {
163162
self->conn_handle = conn_handle;
@@ -167,6 +166,11 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
167166
}
168167
break;
169168
}
169+
case BLE_GAP_EVT_DISCONNECTED: {
170+
if (self->conn_handle == conn_handle) {
171+
self->conn_handle = BLE_CONN_HANDLE_INVALID;
172+
}
173+
}
170174
case BLE_GATTS_EVT_HVN_TX_COMPLETE: {
171175
queue_next_write(self);
172176
}
@@ -192,6 +196,8 @@ void common_hal_bleio_packet_buffer_construct(
192196
incoming = outgoing;
193197
outgoing = temp;
194198
self->conn_handle = bleio_connection_get_conn_handle(MP_OBJ_TO_PTR(self->characteristic->service->connection));
199+
} else {
200+
self->conn_handle = BLE_CONN_HANDLE_INVALID;
195201
}
196202

197203
if (incoming) {

0 commit comments

Comments
 (0)