Skip to content

Commit 2bef6cb

Browse files
committed
drv/cplus_hub/bluetooth: Fix GATT read by type responses
The Control+ hub was causing macOS to fail to enumerate services on the device because we were sending the wrong responses in some cases (off by 1 error).
1 parent eeaacd4 commit 2bef6cb

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lib/pbio/drv/cplus_hub/bluetooth.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static void read_by_type_response_uuid16(uint16_t connection_handle,
314314
attReadByTypeRsp_t rsp;
315315
uint8_t buf[ATT_MTU_SIZE - 2];
316316

317-
buf[0] = ++attr_handle & 0xFF;
317+
buf[0] = attr_handle & 0xFF;
318318
buf[1] = (attr_handle >> 8) & 0xFF;
319319
buf[2] = property_flags;
320320
buf[3] = ++attr_handle & 0xFF;
@@ -332,7 +332,7 @@ static void read_by_type_response_uuid128(uint16_t connection_handle,
332332
attReadByTypeRsp_t rsp;
333333
uint8_t buf[ATT_MTU_SIZE - 2];
334334

335-
buf[0] = ++attr_handle & 0xFF;
335+
buf[0] = attr_handle & 0xFF;
336336
buf[1] = (attr_handle >> 8) & 0xFF;
337337
buf[2] = property_flags;
338338
buf[3] = ++attr_handle & 0xFF;
@@ -384,25 +384,25 @@ static void handle_event(uint8_t *packet) {
384384
DBG("s %04X t %04X", start_handle, type);
385385
switch (type) {
386386
case GATT_CHARACTER_UUID:
387-
if (start_handle <= gap_service_handle) {
388-
read_by_type_response_uuid16(connection_handle, gap_service_handle,
387+
if (start_handle <= gap_service_handle + 1) {
388+
read_by_type_response_uuid16(connection_handle, gap_service_handle + 1,
389389
GATT_PROP_READ, DEVICE_NAME_UUID);
390-
} else if (start_handle <= gap_service_handle + 2) {
391-
read_by_type_response_uuid16(connection_handle, gap_service_handle + 2,
390+
} else if (start_handle <= gap_service_handle + 3) {
391+
read_by_type_response_uuid16(connection_handle, gap_service_handle + 3,
392392
GATT_PROP_READ, APPEARANCE_UUID);
393-
} else if (start_handle <= gap_service_handle + 4) {
394-
read_by_type_response_uuid16(connection_handle, gap_service_handle + 4,
393+
} else if (start_handle <= gap_service_handle + 5) {
394+
read_by_type_response_uuid16(connection_handle, gap_service_handle + 5,
395395
GATT_PROP_READ, PERI_CONN_PARAM_UUID);
396-
} else if (start_handle <= pybricks_service_handle) {
397-
read_by_type_response_uuid128(connection_handle, pybricks_service_handle,
396+
} else if (start_handle <= pybricks_service_handle + 1) {
397+
read_by_type_response_uuid128(connection_handle, pybricks_service_handle + 1,
398398
GATT_PROP_READ | GATT_PROP_WRITE |
399399
GATT_PROP_WRITE_NO_RSP | GATT_PROP_NOTIFY,
400400
pybricks_char_uuid);
401-
} else if (start_handle <= uart_service_handle) {
402-
read_by_type_response_uuid128(connection_handle, uart_service_handle,
401+
} else if (start_handle <= uart_service_handle + 1) {
402+
read_by_type_response_uuid128(connection_handle, uart_service_handle + 1,
403403
GATT_PROP_WRITE_NO_RSP, nrf_uart_rx_char_uuid);
404-
} else if (start_handle <= uart_service_handle + 2) {
405-
read_by_type_response_uuid128(connection_handle, uart_service_handle + 2,
404+
} else if (start_handle <= uart_service_handle + 3) {
405+
read_by_type_response_uuid128(connection_handle, uart_service_handle + 3,
406406
GATT_PROP_NOTIFY, nrf_uart_tx_char_uuid);
407407
} else {
408408
attErrorRsp_t rsp;

0 commit comments

Comments
 (0)