summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-20 05:44:37 +0200
committerSven Gothel <[email protected]>2020-10-20 05:44:37 +0200
commit1f6e924fe05ed45bfa4d0d901af2c4df6c1abab5 (patch)
tree3e7bb612dcf35b5ef3cff10b46f4fbc95236ad6f /src
parent2e40a6fbb84ef21bb9551c653199964e55d7954b (diff)
Normalize: Use size_t where appropriate; timestamp is uint64_t
timestamp is uint64_t - AttPDUMsg Use size_t where appropriate - OctetTypes.hpp: TROOctets* - ATTPDUTypes.hpp: AttPDUMsg* - HCITypes.hpp: HCIPacket* - HCIComm.hpp: HCIComm - L2CAPComm.hpp: L2CAPComm - MgmtTypes.hpp: MgmtCommand*, MgmtEvent* - UUID.hpp: uuid_t - DBTManager, GATTHandler, HCIHandler - HCIComm.hpp: HCIComm - BTTypes.hpp - DBTTypes.hpp
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/ATTPDUTypes.cpp2
-rw-r--r--src/direct_bt/BTTypes.cpp16
-rw-r--r--src/direct_bt/DBTManager.cpp13
-rw-r--r--src/direct_bt/GATTHandler.cpp16
-rw-r--r--src/direct_bt/GATTNumbers.cpp10
-rw-r--r--src/direct_bt/HCIComm.cpp12
-rw-r--r--src/direct_bt/HCIHandler.cpp15
-rw-r--r--src/direct_bt/HCITypes.cpp2
-rw-r--r--src/direct_bt/L2CAPComm.cpp16
-rw-r--r--src/direct_bt/MgmtTypes.cpp6
10 files changed, 55 insertions, 53 deletions
diff --git a/src/direct_bt/ATTPDUTypes.cpp b/src/direct_bt/ATTPDUTypes.cpp
index 675089dd..97f33bfd 100644
--- a/src/direct_bt/ATTPDUTypes.cpp
+++ b/src/direct_bt/ATTPDUTypes.cpp
@@ -115,7 +115,7 @@ std::string AttErrorRsp::getPlainErrorString(const ErrorCode errorCode) noexcept
return "Error Reserved for future use";
}
-std::shared_ptr<const AttPDUMsg> AttPDUMsg::getSpecialized(const uint8_t * buffer, int const buffer_size) noexcept {
+std::shared_ptr<const AttPDUMsg> AttPDUMsg::getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept {
const uint8_t opc = *buffer;
const AttPDUMsg * res;
switch( opc ) {
diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp
index f4a200be..0b91d261 100644
--- a/src/direct_bt/BTTypes.cpp
+++ b/src/direct_bt/BTTypes.cpp
@@ -696,20 +696,20 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex
return count;
}
-std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t const * data, uint8_t const data_length) noexcept {
- int const num_reports = (int) data[0];
+std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t const * data, size_t const data_length) noexcept {
+ size_t const num_reports = (size_t) data[0];
std::vector<std::shared_ptr<EInfoReport>> ad_reports;
- if( 0 >= num_reports || num_reports > 0x19 ) {
+ if( 0 == num_reports || num_reports > 0x19 ) {
DBG_PRINT("AD-Reports: Invalid reports count: %d", num_reports);
return ad_reports;
}
uint8_t const *limes = data + data_length;
uint8_t const *i_octets = data + 1;
uint8_t ad_data_len[0x19];
- const int segment_count = 6;
- int read_segments = 0;
- int i;
+ const size_t segment_count = 6;
+ size_t read_segments = 0;
+ size_t i;
const uint64_t timestamp = jau::getCurrentMilliseconds();
for(i = 0; i < num_reports && i_octets < limes; i++) {
@@ -742,10 +742,10 @@ std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t c
i_octets++;
read_segments++;
}
- const int bytes_left = limes - i_octets;
+ const size_t bytes_left = static_cast<size_t>(limes - i_octets);
if( segment_count != read_segments ) {
- WARN_PRINT("AD-Reports: Incomplete %d reports within %d bytes: Segment read %d < %d, data-ptr %d bytes to limes\n",
+ WARN_PRINT("AD-Reports: Incomplete %zu reports within %zu bytes: Segment read %zu < %zu, data-ptr %zu bytes to limes\n",
num_reports, data_length, read_segments, segment_count, bytes_left);
}
return ad_reports;
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index 8cf6a31e..54600070 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -89,7 +89,7 @@ void DBTManager::mgmtReaderThreadImpl() noexcept {
}
while( !mgmtReaderShallStop ) {
- int len;
+ ssize_t len;
if( !comm.isOpen() ) {
// not open
ERR_PRINT("DBTManager::reader: Not connected");
@@ -99,12 +99,13 @@ void DBTManager::mgmtReaderThreadImpl() noexcept {
len = comm.read(rbuffer.get_wptr(), rbuffer.getSize(), env.MGMT_READER_THREAD_POLL_TIMEOUT);
if( 0 < len ) {
- const uint16_t paramSize = len >= MGMT_HEADER_SIZE ? rbuffer.get_uint16_nc(4) : 0;
- if( len < MGMT_HEADER_SIZE + paramSize ) {
- WARN_PRINT("DBTManager::reader: length mismatch %d < MGMT_HEADER_SIZE(%d) + %d", len, MGMT_HEADER_SIZE, paramSize);
+ const size_t len2 = static_cast<size_t>(len);
+ const size_t paramSize = len2 >= MGMT_HEADER_SIZE ? rbuffer.get_uint16_nc(4) : 0;
+ if( len2 < MGMT_HEADER_SIZE + paramSize ) {
+ WARN_PRINT("DBTManager::reader: length mismatch %zu < MGMT_HEADER_SIZE(%zu) + %zu", len2, MGMT_HEADER_SIZE, paramSize);
continue; // discard data
}
- std::shared_ptr<MgmtEvent> event = MgmtEvent::getSpecialized(rbuffer.get_ptr(), len);
+ std::shared_ptr<MgmtEvent> event = MgmtEvent::getSpecialized(rbuffer.get_ptr(), len2);
const MgmtEvent::Opcode opc = event->getOpcode();
if( MgmtEvent::Opcode::CMD_COMPLETE == opc || MgmtEvent::Opcode::CMD_STATUS == opc ) {
COND_PRINT(env.DEBUG_EVENT, "DBTManager-IO RECV (CMD) %s", event->toString().c_str());
@@ -410,7 +411,7 @@ next1:
const uint16_t num_adapter = jau::get_uint16(data, 0, true /* littleEndian */);
WORDY_PRINT("Bluetooth %d adapter", num_adapter);
- const int expDataSize = 2 + num_adapter * 2;
+ const size_t expDataSize = 2 + num_adapter * 2;
if( res->getDataSize() < expDataSize ) {
ERR_PRINT("Insufficient data for %d adapter indices: res %s", num_adapter, res->toString().c_str());
goto fail;
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index 087814c6..d881ca9f 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -198,7 +198,7 @@ void GATTHandler::l2capReaderThreadImpl() {
}
while( !l2capReaderShallStop ) {
- int len;
+ ssize_t len;
if( !validateConnected() ) {
ERR_PRINT("GATTHandler::reader: Invalid IO state -> Stop");
l2capReaderShallStop = true;
@@ -207,7 +207,7 @@ void GATTHandler::l2capReaderThreadImpl() {
len = l2cap.read(rbuffer.get_wptr(), rbuffer.getSize());
if( 0 < len ) {
- std::shared_ptr<const AttPDUMsg> attPDU = AttPDUMsg::getSpecialized(rbuffer.get_ptr(), len);
+ std::shared_ptr<const AttPDUMsg> attPDU = AttPDUMsg::getSpecialized(rbuffer.get_ptr(), static_cast<size_t>(len));
const AttPDUMsg::Opcode opc = attPDU->getOpcode();
if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_NTF == opc ) {
@@ -262,7 +262,7 @@ void GATTHandler::l2capReaderThreadImpl() {
attPDURing.putBlocking( attPDU );
}
} else if( ETIMEDOUT != errno && !l2capReaderShallStop ) { // expected exits
- IRQ_PRINT("GATTHandler::reader: l2cap read error -> Stop; l2cap.read %d", len);
+ IRQ_PRINT("GATTHandler::reader: l2cap read error -> Stop; l2cap.read %zd", len);
l2capReaderShallStop = true;
has_ioerror = true;
}
@@ -414,15 +414,15 @@ void GATTHandler::send(const AttPDUMsg & msg) {
}
// Thread safe l2cap.write(..) operation..
- const int res = l2cap.write(msg.pdu.get_ptr(), msg.pdu.getSize());
+ const ssize_t res = l2cap.write(msg.pdu.get_ptr(), msg.pdu.getSize());
if( 0 > res ) {
IRQ_PRINT("GATTHandler::send: l2cap write error -> disconnect: %s to %s", msg.toString().c_str(), deviceString.c_str());
has_ioerror = true;
disconnect(true /* disconnectDevice */, true /* ioErrorCause */); // state -> Disconnected
throw BluetoothException("GATTHandler::send: l2cap write error: req "+msg.toString()+" to "+deviceString, E_FILE_LINE);
}
- if( res != msg.pdu.getSize() ) {
- ERR_PRINT("GATTHandler::send: l2cap write count error, %d != %d: %s -> disconnect: %s",
+ if( static_cast<size_t>(res) != msg.pdu.getSize() ) {
+ ERR_PRINT("GATTHandler::send: l2cap write count error, %zd != %zu: %s -> disconnect: %s",
res, msg.pdu.getSize(), msg.toString().c_str(), deviceString.c_str());
has_ioerror = true;
disconnect(true /* disconnectDevice */, true /* ioErrorCause */); // state -> Disconnected
@@ -982,8 +982,8 @@ bool GATTHandler::ping() {
std::vector<GATTCharacteristicRef> & genericAccessCharDeclList = services.at(i)->characteristicList;
POctets value(32, 0);
- for(size_t i=0; isOK && i<genericAccessCharDeclList.size(); i++) {
- const GATTCharacteristic & charDecl = *genericAccessCharDeclList.at(i);
+ for(size_t j=0; isOK && j<genericAccessCharDeclList.size(); j++) {
+ const GATTCharacteristic & charDecl = *genericAccessCharDeclList.at(j);
std::shared_ptr<GATTService> service = charDecl.getServiceUnchecked();
if( nullptr == service || _GENERIC_ACCESS != *(service->type) ) {
continue;
diff --git a/src/direct_bt/GATTNumbers.cpp b/src/direct_bt/GATTNumbers.cpp
index 17448320..6fec1bd9 100644
--- a/src/direct_bt/GATTNumbers.cpp
+++ b/src/direct_bt/GATTNumbers.cpp
@@ -347,7 +347,7 @@ const GattCharacteristicSpec * direct_bt::findGattCharSpec(const uint16_t uuid16
/********************************************************/
std::string direct_bt::GattNameToString(const TROOctets &v) noexcept {
- const int str_len = v.getSize();
+ const size_t str_len = v.getSize();
if( 0 == str_len ) {
return std::string(); // empty
}
@@ -364,7 +364,7 @@ GattPeriphalPreferredConnectionParameters::GattPeriphalPreferredConnectionParame
}
std::shared_ptr<GattPeriphalPreferredConnectionParameters> GattPeriphalPreferredConnectionParameters::get(const TROOctets &source) noexcept {
- const int reqSize = 8;
+ const size_t reqSize = 8;
if( source.getSize() < reqSize ) {
ERR_PRINT("GattPeriphalPreferredConnectionParameters: Insufficient data, less than %d bytes in %s", reqSize, source.toString().c_str());
return nullptr;
@@ -389,7 +389,7 @@ GattPnP_ID::GattPnP_ID(const TROOctets &source) noexcept
product_id(source.get_uint16(3)), product_version(source.get_uint16(5)) {}
std::shared_ptr<GattPnP_ID> GattPnP_ID::get(const TROOctets &source) noexcept {
- const int reqSize = 7;
+ const size_t reqSize = 7;
if( source.getSize() < reqSize ) {
ERR_PRINT("GattPnP_ID: Insufficient data, less than %d bytes in %s", reqSize, source.toString().c_str());
return nullptr;
@@ -412,8 +412,8 @@ std::string GattDeviceInformationSvc::toString() const noexcept {
}
std::shared_ptr<GattTemperatureMeasurement> GattTemperatureMeasurement::get(const TROOctets &source) noexcept {
- const int size = source.getSize();
- int reqSize = 1 + 4; // max size = 13
+ const size_t size = source.getSize();
+ size_t reqSize = 1 + 4; // max size = 13
if( reqSize > size ) {
// min size: flags + temperatureValue
ERR_PRINT("GattTemperatureMeasurement: Insufficient data, less than %d bytes in %s", reqSize, source.toString().c_str());
diff --git a/src/direct_bt/HCIComm.cpp b/src/direct_bt/HCIComm.cpp
index 9810fa1a..a99125e9 100644
--- a/src/direct_bt/HCIComm.cpp
+++ b/src/direct_bt/HCIComm.cpp
@@ -138,9 +138,9 @@ void HCIComm::close() noexcept {
DBG_PRINT("HCIComm::close: End: dd %d", socket_descriptor.load());
}
-int HCIComm::read(uint8_t* buffer, const int capacity, const int32_t timeoutMS) noexcept {
- int len = 0;
- if( 0 > socket_descriptor || 0 > capacity ) {
+ssize_t HCIComm::read(uint8_t* buffer, const size_t capacity, const int32_t timeoutMS) noexcept {
+ ssize_t len = 0;
+ if( 0 > socket_descriptor ) {
goto errout;
}
if( 0 == capacity ) {
@@ -180,10 +180,10 @@ errout:
return -1;
}
-int HCIComm::write(const uint8_t* buffer, const int size) noexcept {
+ssize_t HCIComm::write(const uint8_t* buffer, const size_t size) noexcept {
const std::lock_guard<std::recursive_mutex> lock(mtx_write); // RAII-style acquire and relinquish via destructor
- int len = 0;
- if( 0 > socket_descriptor || 0 > size ) {
+ ssize_t len = 0;
+ if( 0 > socket_descriptor ) {
goto errout;
}
if( 0 == size ) {
diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp
index 750386d4..9bdae951 100644
--- a/src/direct_bt/HCIHandler.cpp
+++ b/src/direct_bt/HCIHandler.cpp
@@ -260,7 +260,7 @@ void HCIHandler::hciReaderThreadImpl() noexcept {
}
while( !hciReaderShallStop ) {
- int len;
+ ssize_t len;
if( !comm.isOpen() ) {
// not open
ERR_PRINT("HCIHandler::reader: Not connected");
@@ -270,16 +270,17 @@ void HCIHandler::hciReaderThreadImpl() noexcept {
len = comm.read(rbuffer.get_wptr(), rbuffer.getSize(), env.HCI_READER_THREAD_POLL_TIMEOUT);
if( 0 < len ) {
- const uint16_t paramSize = len >= number(HCIConstU8::EVENT_HDR_SIZE) ? rbuffer.get_uint8_nc(2) : 0;
- if( len < number(HCIConstU8::EVENT_HDR_SIZE) + paramSize ) {
- WARN_PRINT("HCIHandler::reader: length mismatch %d < EVENT_HDR_SIZE(%d) + %d",
- len, number(HCIConstU8::EVENT_HDR_SIZE), paramSize);
+ const size_t len2 = static_cast<size_t>(len);
+ const size_t paramSize = len2 >= number(HCIConstSizeT::EVENT_HDR_SIZE) ? rbuffer.get_uint8_nc(2) : 0;
+ if( len2 < number(HCIConstSizeT::EVENT_HDR_SIZE) + paramSize ) {
+ WARN_PRINT("HCIHandler::reader: length mismatch %zu < EVENT_HDR_SIZE(%zu) + %zu",
+ len2, number(HCIConstSizeT::EVENT_HDR_SIZE), paramSize);
continue; // discard data
}
- std::shared_ptr<HCIEvent> event = HCIEvent::getSpecialized(rbuffer.get_ptr(), len);
+ std::shared_ptr<HCIEvent> event = HCIEvent::getSpecialized(rbuffer.get_ptr(), len2);
if( nullptr == event ) {
// not an event ...
- ERR_PRINT("HCIHandler-IO RECV Drop (non-event) %s", jau::bytesHexString(rbuffer.get_ptr(), 0, len, true /* lsbFirst*/).c_str());
+ ERR_PRINT("HCIHandler-IO RECV Drop (non-event) %s", jau::bytesHexString(rbuffer.get_ptr(), 0, len2, true /* lsbFirst*/).c_str());
continue;
}
diff --git a/src/direct_bt/HCITypes.cpp b/src/direct_bt/HCITypes.cpp
index 7bbd1b9f..ce334788 100644
--- a/src/direct_bt/HCITypes.cpp
+++ b/src/direct_bt/HCITypes.cpp
@@ -272,7 +272,7 @@ std::string getHCIMetaEventTypeString(const HCIMetaEventType op) noexcept {
return "Unknown HCIMetaType";
}
-std::shared_ptr<HCIEvent> HCIEvent::getSpecialized(const uint8_t * buffer, int const buffer_size) noexcept {
+std::shared_ptr<HCIEvent> HCIEvent::getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept {
const HCIPacketType pc = static_cast<HCIPacketType>( jau::get_uint8(buffer, 0) );
if( HCIPacketType::EVENT != pc ) {
return nullptr;
diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp
index a20d8911..6e2514d1 100644
--- a/src/direct_bt/L2CAPComm.cpp
+++ b/src/direct_bt/L2CAPComm.cpp
@@ -215,14 +215,14 @@ bool L2CAPComm::disconnect() noexcept {
return true;
}
-int L2CAPComm::read(uint8_t* buffer, const int capacity) {
+ssize_t L2CAPComm::read(uint8_t* buffer, const size_t capacity) {
const int32_t timeoutMS = env.L2CAP_READER_POLL_TIMEOUT;
- int len = 0;
- int err_res = 0;
+ ssize_t len = 0;
+ ssize_t err_res = 0;
tid_read = pthread_self(); // temporary safe tid to allow interruption
- if( 0 > socket_descriptor || 0 > capacity ) {
+ if( 0 > socket_descriptor ) {
err_res = -1; // invalid socket_descriptor or capacity
goto errout;
}
@@ -280,12 +280,12 @@ errout:
return err_res;
}
-int L2CAPComm::write(const uint8_t * buffer, const int length) {
+ssize_t L2CAPComm::write(const uint8_t * buffer, const size_t length) {
const std::lock_guard<std::recursive_mutex> lock(mtx_write); // RAII-style acquire and relinquish via destructor
- int len = 0;
- int err_res = 0;
+ ssize_t len = 0;
+ ssize_t err_res = 0;
- if( 0 > socket_descriptor || 0 > length ) {
+ if( 0 > socket_descriptor ) {
err_res = -1; // invalid socket_descriptor or capacity
goto errout;
}
diff --git a/src/direct_bt/MgmtTypes.cpp b/src/direct_bt/MgmtTypes.cpp
index ace0b7b4..ee4e15fe 100644
--- a/src/direct_bt/MgmtTypes.cpp
+++ b/src/direct_bt/MgmtTypes.cpp
@@ -230,7 +230,7 @@ std::string MgmtEvent::getOpcodeString(const Opcode opc) noexcept {
return "Unknown Opcode";
}
-std::shared_ptr<MgmtEvent> MgmtEvent::getSpecialized(const uint8_t * buffer, int const buffer_size) noexcept {
+std::shared_ptr<MgmtEvent> MgmtEvent::getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept {
const MgmtEvent::Opcode opc = static_cast<MgmtEvent::Opcode>( jau::get_uint16(buffer, 0, true /* littleEndian */) );
MgmtEvent * res;
switch( opc ) {
@@ -287,7 +287,7 @@ std::shared_ptr<ConnectionInfo> MgmtEvtCmdComplete::toConnectionInfo() const noe
ERR_PRINT("No Success: %s", toString().c_str());
return nullptr;
}
- const int min_size = ConnectionInfo::minimumDataSize();
+ const size_t min_size = ConnectionInfo::minimumDataSize();
if( getDataSize() < min_size ) {
ERR_PRINT("Data size < %d: %s", min_size, toString().c_str());
return nullptr;
@@ -311,7 +311,7 @@ std::shared_ptr<NameAndShortName> MgmtEvtCmdComplete::toNameAndShortName() const
ERR_PRINT("No Success: %s", toString().c_str());
return nullptr;
}
- const int min_size = MgmtEvtLocalNameChanged::namesDataSize();
+ const size_t min_size = MgmtEvtLocalNameChanged::namesDataSize();
if( getDataSize() < min_size ) {
ERR_PRINT("Data size < %d: %s", min_size, toString().c_str());
return nullptr;