summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-03-25 13:31:18 -0700
committerScott Shawcroft <scott@tannewt.org>2020-03-25 13:31:18 -0700
commit3551b769a27c442780e978ea7a58cc56170cdfc8 (patch)
tree46f17e1e5d3bade199daf19a66cef4c55aa80714
parent59eb35da30c0141ce0b2eb5b9718d2a655f988ba (diff)
Fix connection handle tracking in PacketBuffer when a server.
-rw-r--r--ports/nrf/common-hal/_bleio/PacketBuffer.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.c b/ports/nrf/common-hal/_bleio/PacketBuffer.c
index 27dacb493..8382a0970 100644
--- a/ports/nrf/common-hal/_bleio/PacketBuffer.c
+++ b/ports/nrf/common-hal/_bleio/PacketBuffer.c
@@ -156,8 +156,7 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
return false;
}
write_to_ringbuf(self, evt_write->data, evt_write->len);
- } else if (evt_write->handle == self->characteristic->cccd_handle &&
- self->conn_handle == BLE_CONN_HANDLE_INVALID) {
+ } else if (evt_write->handle == self->characteristic->cccd_handle) {
uint16_t cccd = *((uint16_t*) evt_write->data);
if (cccd & BLE_GATT_HVX_NOTIFICATION) {
self->conn_handle = conn_handle;
@@ -167,6 +166,11 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
}
break;
}
+ case BLE_GAP_EVT_DISCONNECTED: {
+ if (self->conn_handle == conn_handle) {
+ self->conn_handle = BLE_CONN_HANDLE_INVALID;
+ }
+ }
case BLE_GATTS_EVT_HVN_TX_COMPLETE: {
queue_next_write(self);
}
@@ -192,6 +196,8 @@ void common_hal_bleio_packet_buffer_construct(
incoming = outgoing;
outgoing = temp;
self->conn_handle = bleio_connection_get_conn_handle(MP_OBJ_TO_PTR(self->characteristic->service->connection));
+ } else {
+ self->conn_handle = BLE_CONN_HANDLE_INVALID;
}
if (incoming) {