Fix weave bug for payloads that exceed the maximum write length

PiperOrigin-RevId: 563185164
This commit is contained in:
Nick Bourdakos
2023-09-06 12:39:47 -07:00
committed by Copybara-Service
parent 8725391822
commit 197d3f8476
2 changed files with 5 additions and 3 deletions
@@ -32,9 +32,7 @@ objc_library(
deps = [
":Shared",
"//third_party/apple_frameworks:CoreBluetooth",
"//third_party/apple_frameworks:CoreFoundation",
"//third_party/apple_frameworks:Foundation",
"//third_party/apple_frameworks:QuartzCore",
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
],
)
@@ -728,7 +728,11 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
packet.version);
[_connectionConfirmTimer invalidate];
_connectionConfirmTimer = nil;
_socket.packetSize = packet.packetSize;
// Weave is using `CBCharacteristicWriteWithResponse` for writes, so we must query max value since
// it can have a smaller value than the `GNSWeaveConnectionConfirmPacket` size.
NSUInteger maxWriteLength =
[_socket.peerAsPeripheral maximumWriteValueLengthForType:CBCharacteristicWriteWithResponse];
_socket.packetSize = MIN(packet.packetSize, maxWriteLength);
[_socket didConnect];
if (packet.data) {
// According to the Weave BLE protocol the data received during the connection handshake should