From fd0e79deaca0f4eadd5bca6993ebcbc671466bd7 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Wed, 27 Apr 2016 23:12:48 -0500 Subject: [PATCH] fixed Read Response --- Sources/BluetoothLinux/GATTServer.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/BluetoothLinux/GATTServer.swift b/Sources/BluetoothLinux/GATTServer.swift index 2baa5a7..d1e6a43 100644 --- a/Sources/BluetoothLinux/GATTServer.swift +++ b/Sources/BluetoothLinux/GATTServer.swift @@ -234,7 +234,7 @@ public final class GATTServer { guard offset <= UInt16(attribute.value.byteValue.count) else { errorResponse(opcode, .InvalidOffset, handle); return nil } - let value: [UInt8] + var value: [UInt8] // Guard against invalid access if offset equals to value length if offset == UInt16(attribute.value.byteValue.count) { @@ -250,6 +250,9 @@ public final class GATTServer { value = attribute.value.byteValue } + // adjust value for MTU + value = Array(value.prefix(connection.maximumTransmissionUnit - 1)) + // validate application errors with read callback if let error = willRead?(UUID: attribute.UUID, value: Data(byteValue: value), offset: Int(offset)) {