summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/nrf/common-hal/_bleio/PacketBuffer.c4
-rw-r--r--shared-bindings/_bleio/PacketBuffer.c10
2 files changed, 6 insertions, 8 deletions
diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.c b/ports/nrf/common-hal/_bleio/PacketBuffer.c
index 37f584664..a8773f961 100644
--- a/ports/nrf/common-hal/_bleio/PacketBuffer.c
+++ b/ports/nrf/common-hal/_bleio/PacketBuffer.c
@@ -267,6 +267,10 @@ mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self
if (packet_length > len) {
// Packet is longer than requested. Return negative of overrun value.
ret = len - packet_length;
+ // Discard the packet if it's too large. Don't fill data.
+ while (packet_length--) {
+ (void) ringbuf_get(&self->ringbuf);
+ }
} else {
// Read as much as possible, but might be shorter than len.
ringbuf_get_n(&self->ringbuf, data, packet_length);
diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c
index 1520c8b5c..e087cf22d 100644
--- a/shared-bindings/_bleio/PacketBuffer.c
+++ b/shared-bindings/_bleio/PacketBuffer.c
@@ -190,16 +190,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_packet_buffer_deinit_obj, bleio_packet_bu
//| .. attribute:: incoming_packet_length
//|
//| Maximum length in bytes of a packet we are reading.
-//| If the packet is arriving from a remote service via notify or indicate,
-//| the maximum length is `Connection.max_packet_length`.
-//| Otherwise it is the ``max_length`` of the :py:class:`~_bleio.Characteristic`.
//|
STATIC mp_obj_t bleio_packet_buffer_get_incoming_packet_length(mp_obj_t self_in) {
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t size = common_hal_bleio_packet_buffer_get_incoming_packet_length(self);
if (size < 0) {
- mp_raise_ValueError(translate("No connection: size cannot be determined"));
+ mp_raise_ValueError(translate("No connection: length cannot be determined"));
}
return MP_OBJ_NEW_SMALL_INT(size);
}
@@ -215,16 +212,13 @@ const mp_obj_property_t bleio_packet_buffer_incoming_packet_length_obj = {
//| .. attribute:: outgoing_packet_length
//|
//| Maximum length in bytes of a packet we are writing.
-//| If the packet is being sent via notify or indicate,
-//| the maximum length is `Connection.max_packet_length`.
-//| Otherwise it is the ``max_length`` of the :py:class:`~_bleio.Characteristic`.
//|
STATIC mp_obj_t bleio_packet_buffer_get_outgoing_packet_length(mp_obj_t self_in) {
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t size = common_hal_bleio_packet_buffer_get_outgoing_packet_length(self);
if (size < 0) {
- mp_raise_ValueError(translate("No connection: size cannot be determined"));
+ mp_raise_ValueError(translate("No connection: length cannot be determined"));
}
return MP_OBJ_NEW_SMALL_INT(size);
}