Add exception on small buffer and fix Connecion WRITE handling

crypto-aes
Scott Shawcroft 3 years ago
parent 3551b769a2
commit 8a5d3cd6c4
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E

@ -162,7 +162,8 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
self->do_bond_cccds = true;
self->do_bond_cccds_request_time = supervisor_ticks_ms64();
}
break;
// Return false so other handlers get this event as well.
return false;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0);

@ -148,6 +148,7 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
// A client wrote to this server characteristic.
ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write;
// Event handle must match the handle for my characteristic.
if (evt_write->handle == self->characteristic->handle) {
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
@ -261,8 +262,7 @@ int common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self, uin
sd_nvic_critical_region_enter(&is_nested_critical_region);
if (packet_length > len) {
// TODO: raise an exception.
packet_length = len;
return len - packet_length;
}
ringbuf_get_n(&self->ringbuf, data, packet_length);

@ -109,7 +109,12 @@ STATIC mp_obj_t bleio_packet_buffer_readinto(mp_obj_t self_in, mp_obj_t buffer_o
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buffer_obj, &bufinfo, MP_BUFFER_WRITE);
return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len));
int size = common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len);
if (size < 0) {
mp_raise_ValueError_varg(translate("Buffer too short by %d bytes"), size * -1);
}
return MP_OBJ_NEW_SMALL_INT(size);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_buffer_readinto);

Loading…
Cancel
Save