Skip to content

Commit 6dbb17e

Browse files
committed
drv/bluetooth/cc2640: fix Read by Group Type Response
When services are enumerated, the connecting device usually starts with a Read by Group Type Request for handles 0x0001 to 0xffff. However, the first handle, gatt_service_handle, seems to be 0x0009, so this would result in an application error response since no if case matched 0x0001. This fixes the problem by using inequalities instead of strict equals. Also, when all groups have been enumerated, it is supposed to send an attribute not found error, not an application error, so this is fixed too.
1 parent ff4909f commit 6dbb17e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ static void handle_event(uint8_t *packet) {
628628
DBG("s %04X g %04X", start_handle, group_type);
629629
switch (group_type) {
630630
case GATT_PRIMARY_SERVICE_UUID:
631-
if (start_handle == gatt_service_handle) {
631+
if (start_handle <= gatt_service_handle) {
632632
attReadByGrpTypeRsp_t rsp;
633633
uint8_t buf[ATT_MTU_SIZE - 2];
634634

@@ -642,7 +642,7 @@ static void handle_event(uint8_t *packet) {
642642
rsp.pDataList = buf;
643643
rsp.dataLen = 6;
644644
ATT_ReadByGrpTypeRsp(connection_handle, &rsp);
645-
} else if (start_handle == gap_service_handle) {
645+
} else if (start_handle <= gap_service_handle) {
646646
attReadByGrpTypeRsp_t rsp;
647647
uint8_t buf[ATT_MTU_SIZE - 2];
648648

@@ -656,7 +656,7 @@ static void handle_event(uint8_t *packet) {
656656
rsp.pDataList = buf;
657657
rsp.dataLen = 6;
658658
ATT_ReadByGrpTypeRsp(connection_handle, &rsp);
659-
} else if (start_handle == pybricks_service_handle) {
659+
} else if (start_handle <= pybricks_service_handle) {
660660
attReadByGrpTypeRsp_t rsp;
661661
uint8_t buf[ATT_MTU_SIZE - 2];
662662

@@ -669,7 +669,7 @@ static void handle_event(uint8_t *packet) {
669669
rsp.pDataList = buf;
670670
rsp.dataLen = 20;
671671
ATT_ReadByGrpTypeRsp(connection_handle, &rsp);
672-
} else if (start_handle == uart_service_handle) {
672+
} else if (start_handle <= uart_service_handle) {
673673
attReadByGrpTypeRsp_t rsp;
674674
uint8_t buf[ATT_MTU_SIZE - 2];
675675

@@ -687,13 +687,21 @@ static void handle_event(uint8_t *packet) {
687687

688688
rsp.reqOpcode = ATT_READ_BY_GRP_TYPE_REQ;
689689
rsp.handle = start_handle;
690-
rsp.errCode = ATT_ERR_INVALID_VALUE;
690+
rsp.errCode = ATT_ERR_ATTR_NOT_FOUND;
691691
ATT_ErrorRsp(connection_handle, &rsp);
692692
}
693693
break;
694-
default:
694+
default: {
695+
attErrorRsp_t rsp;
696+
697+
rsp.reqOpcode = ATT_READ_BY_GRP_TYPE_REQ;
698+
rsp.handle = start_handle;
699+
rsp.errCode = ATT_ERR_INVALID_VALUE;
700+
ATT_ErrorRsp(connection_handle, &rsp);
701+
695702
DBG("unhandled read by grp type req: %05X", group_type);
696-
break;
703+
}
704+
break;
697705
}
698706
}
699707
break;

0 commit comments

Comments
 (0)