8000 Port changes to ble_hci code · jun2sak/circuitpython@68d5839 · GitHub
[go: up one dir, main page]

Skip to content

Commit 68d5839

Browse files
committed
Port changes to ble_hci code
1 parent 81e11ae commit 68d5839

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

devices/ble_hci/common-hal/_bleio/Characteristic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_character
7878
return self->service;
7979
}
8080

81+
size_t common_hal_bleio_characteristic_get_max_length(bleio_characteristic_obj_t *self) {
82+
return self->max_length;
83+
}
84+
8185
size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t *buf, size_t len) {
8286
// Do GATT operations only if this characteristic has been added to a registered service.
8387
if (self->handle != BLE_GATT_HANDLE_INVALID) {

devices/ble_hci/common-hal/_bleio/PacketBuffer.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void bleio_packet_buffer_update(bleio_packet_buffer_obj_t *self, mp_buffer_info_
8181

8282
void common_hal_bleio_packet_buffer_construct(
8383
bleio_packet_buffer_obj_t *self, bleio_characteristic_obj_t *characteristic,
84-
size_t buffer_size) {
84+
size_t buffer_size, size_t max_packet_size) {
8585

8686
self->characteristic = characteristic;
8787
self->client = self->characteristic->service->is_remote;
@@ -101,7 +101,7 @@ void common_hal_bleio_packet_buffer_construct(
101101
}
102102

103103
if (incoming) {
104-
if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + characteristic->max_length), false)) {
104+
if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + max_packet_size), false)) {
105105
mp_raise_ValueError(translate("Buffer too large and unable to allocate"));
106106
}
107107
}
@@ -110,12 +110,13 @@ void common_hal_bleio_packet_buffer_construct(
110110
self->packet_queued = false;
111111
self->pending_index = 0;
112112
self->pending_size = 0;
113-
self->outgoing[0] = m_malloc(characteristic->max_length, false);
114-
self->outgoing[1] = m_malloc(characteristic->max_length, false);
113+
self->outgoing[0] = m_malloc(max_packet_size, false);
114+
self->outgoing[1] = m_malloc(max_packet_size, false);
115115
} else {
116116
self->outgoing[0] = NULL;
117117
self->outgoing[1] = NULL;
118118
}
119+
self->max_packet_size = max_packet_size;
119120

120121
bleio_characteristic_set_observer(self->characteristic, self);
121122
}
@@ -243,15 +244,16 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_
243244
if (self->conn_handle != BLE_CONN_HANDLE_INVALID) {
244245
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
245246
if (connection) {
246-
return MIN(common_hal_bleio_connection_get_max_packet_length(connection),
247-
self->characteristic->max_length);
247+
return MIN(MIN(common_hal_bleio_connection_get_max_packet_length(connection),
248+
self->max_packet_size),
249+
self->characteristic->max_length);
248250
}
249251
}
250252
// There's no current connection, so we don't know the MTU, and
251253
// we can't tell what the largest outgoing packet length would be.
252254
return -1;
253255
}
254-
return self->characteristic->max_length;
256+
return MIN(self->characteristic->max_length, self->max_packet_size);
255257
}
256258

257259
bool common_hal_bleio_packet_buffer_deinited(bleio_packet_buffer_obj_t *self) {

devices/ble_hci/common-hal/_bleio/PacketBuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct {
4242
// We remember the conn_handle so we can do a NOTIFY/INDICATE to a client.
4343
// We can find out the conn_handle on a Characteristic write or a CCCD write (but not a read).
4444
volatile uint16_t conn_handle;
45+
uint16_t max_packet_size;
4546
uint8_t pending_index;
4647
uint8_t write_type;
4748
bool client;

0 commit comments

Comments
 (0)
0