diff options
author | Sven Gothel <[email protected]> | 2022-01-02 21:35:41 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-01-02 21:35:41 +0100 |
commit | 6765a919a9b37fad6fbacdfd6b8db4190aaf8dd5 (patch) | |
tree | 1d9834c2080e456098f6adcb146528a8437c511a | |
parent | 243fc0775bb54070b225aa69e3a77cafee75837e (diff) |
AttHandleValueRcv, sendNotification/Indication: Limit by mtu to avoid exception
-rw-r--r-- | api/direct_bt/ATTPDUTypes.hpp | 6 | ||||
-rw-r--r-- | src/direct_bt/BTGattHandler.cpp | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/api/direct_bt/ATTPDUTypes.hpp b/api/direct_bt/ATTPDUTypes.hpp index 01879828..aab9e91a 100644 --- a/api/direct_bt/ATTPDUTypes.hpp +++ b/api/direct_bt/ATTPDUTypes.hpp @@ -1189,12 +1189,12 @@ namespace direct_bt { checkOpcode(Opcode::HANDLE_VALUE_NTF, Opcode::HANDLE_VALUE_IND); } - AttHandleValueRcv(const bool isNotify, const uint16_t handle, const jau::TROOctets & value) - : AttPDUMsg(isNotify ? Opcode::HANDLE_VALUE_NTF : Opcode::HANDLE_VALUE_IND, getPDUValueOffset()+value.size()), + AttHandleValueRcv(const bool isNotify, const uint16_t handle, const jau::TROOctets & value, const jau::nsize_t mtu) + : AttPDUMsg(isNotify ? Opcode::HANDLE_VALUE_NTF : Opcode::HANDLE_VALUE_IND, getPDUValueOffset()+std::min(mtu-pdu_value_offset, value.size())), view(pdu, getPDUValueOffset(), getPDUValueSize()) { pdu.put_uint16_nc(1, handle); - pdu.put_bytes_nc(getPDUValueOffset(), value.get_ptr(), value.size()); + pdu.put_bytes_nc(getPDUValueOffset(), value.get_ptr(), std::min(mtu-pdu_value_offset, value.size())); } /** opcode + handle */ diff --git a/src/direct_bt/BTGattHandler.cpp b/src/direct_bt/BTGattHandler.cpp index 7d2e7f95..96855cbe 100644 --- a/src/direct_bt/BTGattHandler.cpp +++ b/src/direct_bt/BTGattHandler.cpp @@ -1331,7 +1331,7 @@ bool BTGattHandler::sendNotification(const uint16_t char_value_handle, const jau COND_PRINT(env.DEBUG_DATA, "GATT SEND NTF: Zero size, skipped sending to %s", toString().c_str()); return true; } - AttHandleValueRcv data(true /* isNotify */, char_value_handle, value); + AttHandleValueRcv data(true /* isNotify */, char_value_handle, value, usedMTU); COND_PRINT(env.DEBUG_DATA, "GATT SEND NTF: %s to %s", data.toString().c_str(), toString().c_str()); send(data); return true; @@ -1351,7 +1351,7 @@ bool BTGattHandler::sendIndication(const uint16_t char_value_handle, const jau:: return true; } const std::lock_guard<std::recursive_mutex> lock(mtx_command); // RAII-style acquire and relinquish via destructor - AttHandleValueRcv req(false /* isNotify */, char_value_handle, value); + AttHandleValueRcv req(false /* isNotify */, char_value_handle, value, usedMTU); std::unique_ptr<const AttPDUMsg> pdu = sendWithReply(req, write_cmd_reply_timeout); // valid reply or exception if( pdu->getOpcode() == AttPDUMsg::Opcode::HANDLE_VALUE_CFM ) { COND_PRINT(env.DEBUG_DATA, "GATT SENT IND: %s -> %s to/from %s", |