Skip to content

Commit fe582c5

Browse files
committed
drv/bluetooth_stm32_cc2640: handle macOS 12 request
It looks like macOS 12 issues a new request we have't seen before: a Read By Type Request for the Device Name UUID. This was causing a connection failure in Pybricks Code. Since the hub never sent a response to this request, the OS would timeout and disconnect. This fixes the issue by handling the request. Plus an error response is now sent for unhandled UUIDs (as per the Bluetooth spec) to prevent similar problems in the future. Fixes: pybricks/support#489
1 parent af4a1d7 commit fe582c5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
user script ends ([support#456]).
1616
- Hub reset due to watchdog timer when writing data to UART I/O device
1717
([support#304]).
18+
- City/Technic hubs not connecting via Bluetooth on macOS 12 ([support#489]).
1819

1920
### Changed:
2021
- Updated to MicroPython v1.17.
@@ -23,6 +24,7 @@
2324
[support#439]: https://github.com/pybricks/support/issues/439
2425
[support#440]: https://github.com/pybricks/support/issues/440
2526
[support#456]: https://github.com/pybricks/support/issues/456
27+
[support#489]: https://github.com/pybricks/support/issues/489
2628

2729
## [3.1.0a4] - 2021-08-30
2830

lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,31 @@ static void handle_event(uint8_t *packet) {
872872
ATT_ErrorRsp(connection_handle, &rsp);
873873
}
874874
break;
875-
default:
875+
876+
case DEVICE_NAME_UUID: {
877+
attReadByTypeRsp_t rsp;
878+
uint8_t buf[ATT_MTU_SIZE - 2];
879+
uint8_t hub_name_len = strlen(pbdrv_bluetooth_hub_name);
880+
881+
pbio_set_uint16_le(&buf[0], gap_service_handle + 2);
882+
memcpy(&buf[2], pbdrv_bluetooth_hub_name, hub_name_len);
883+
rsp.pDataList = buf;
884+
rsp.dataLen = hub_name_len + 2;
885+
ATT_ReadByTypeRsp(connection_handle, &rsp);
886+
}
887+
break;
888+
889+
default: {
890+
attErrorRsp_t rsp;
891+
892+
rsp.reqOpcode = ATT_READ_BY_TYPE_REQ;
893+
rsp.handle = start_handle;
894+
rsp.errCode = ATT_ERR_ATTR_NOT_FOUND;
895+
ATT_ErrorRsp(connection_handle, &rsp);
896+
876897
DBG("unhandled read by type req: %04X", type);
877-
break;
898+
}
899+
break;
878900
}
879901
}
880902
break;

0 commit comments

Comments
 (0)