Assume max characteristic size when the client

This commit is contained in:
Scott Shawcroft 2021-04-13 15:37:47 -07:00
parent b1f4a9a9fd
commit b273f59c4e
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA

View File

@ -196,18 +196,23 @@ void common_hal_bleio_packet_buffer_construct(
bleio_characteristic_properties_t incoming = self->characteristic->props & (CHAR_PROP_WRITE_NO_RESPONSE | CHAR_PROP_WRITE); bleio_characteristic_properties_t incoming = self->characteristic->props & (CHAR_PROP_WRITE_NO_RESPONSE | CHAR_PROP_WRITE);
bleio_characteristic_properties_t outgoing = self->characteristic->props & (CHAR_PROP_NOTIFY | CHAR_PROP_INDICATE); bleio_characteristic_properties_t outgoing = self->characteristic->props & (CHAR_PROP_NOTIFY | CHAR_PROP_INDICATE);
uint16_t max_packet_size;
if (self->client) { if (self->client) {
// Swap if we're the client. // Swap if we're the client.
bleio_characteristic_properties_t temp = incoming; bleio_characteristic_properties_t temp = incoming;
incoming = outgoing; incoming = outgoing;
outgoing = temp; outgoing = temp;
self->conn_handle = bleio_connection_get_conn_handle(MP_OBJ_TO_PTR(self->characteristic->service->connection)); self->conn_handle = bleio_connection_get_conn_handle(MP_OBJ_TO_PTR(self->characteristic->service->connection));
// TODO: We may want to make this variable because our BLE connection may not be able to
// negotiate the higher MTU.
max_packet_size = BLE_GATTS_VAR_ATTR_LEN_MAX - 3; // 3 for ATT overhead
} else { } else {
self->conn_handle = BLE_CONN_HANDLE_INVALID; self->conn_handle = BLE_CONN_HANDLE_INVALID;
max_packet_size = characteristic->max_length;
} }
if (incoming) { if (incoming) {
if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + characteristic->max_length), false)) { if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + max_packet_size), false)) {
mp_raise_ValueError(translate("Buffer too large and unable to allocate")); mp_raise_ValueError(translate("Buffer too large and unable to allocate"));
} }
} }