From 0b87d3c6647835614ca63c97c1df595c5d7d1b2f Mon Sep 17 00:00:00 2001 From: pixl Date: Fri, 3 Jul 2020 22:59:34 -0400 Subject: [PATCH] Fixed bug: odd devices would fail Root GetFeature Some devices throw an hidpp20::Error InvalidFeatureIndex when Root GetFeature is called with some features (e.g. 0x1b04) as the parameter. Since Root is a required feature in the HID++ 2.0 protocol, this error can safely be ignored and treated as an UnsupportedFeature. Fixes bug in #20 where the Logitech PRO headset would not work. --- src/logid/backend/hidpp/Device.cpp | 2 +- src/logid/backend/hidpp20/Device.cpp | 2 ++ .../backend/hidpp20/EssentialFeature.cpp | 14 +++++++++++-- src/logid/backend/hidpp20/Feature.cpp | 13 ++++++++++-- src/logid/backend/hidpp20/features/Root.cpp | 21 +++++++++++++++---- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/logid/backend/hidpp/Device.cpp b/src/logid/backend/hidpp/Device.cpp index 680ed3f..d6d5a64 100644 --- a/src/logid/backend/hidpp/Device.cpp +++ b/src/logid/backend/hidpp/Device.cpp @@ -174,7 +174,7 @@ Report Device::sendReport(Report& report) Report::Hidpp20Error hidpp20_error{}; if(response.isError20(&hidpp20_error)) - throw hidpp10::Error(hidpp20_error.error_code); + throw hidpp20::Error(hidpp20_error.error_code); return response; } diff --git a/src/logid/backend/hidpp20/Device.cpp b/src/logid/backend/hidpp20/Device.cpp index 2e71ae7..691cc34 100644 --- a/src/logid/backend/hidpp20/Device.cpp +++ b/src/logid/backend/hidpp20/Device.cpp @@ -45,6 +45,8 @@ std::vector Device::callFunction(uint8_t feature_index, type = hidpp::Report::Type::Short; else if(params.size() <= hidpp::LongParamLength) type = hidpp::Report::Type::Long; + else + throw hidpp::Report::InvalidReportID(); hidpp::Report request(type, deviceIndex(), feature_index, function, LOGID_HIDPP_SOFTWARE_ID); diff --git a/src/logid/backend/hidpp20/EssentialFeature.cpp b/src/logid/backend/hidpp20/EssentialFeature.cpp index bbca19f..11b9751 100644 --- a/src/logid/backend/hidpp20/EssentialFeature.cpp +++ b/src/logid/backend/hidpp20/EssentialFeature.cpp @@ -20,6 +20,7 @@ #include "EssentialFeature.h" #include "feature_defs.h" #include "features/Root.h" +#include "Error.h" using namespace logid::backend::hidpp20; @@ -33,6 +34,8 @@ std::vector EssentialFeature::callFunction(uint8_t function_id, type = hidpp::Report::Type::Short; else if(params.size() <= hidpp::LongParamLength) type = hidpp::Report::Type::Long; + else + throw hidpp::Report::InvalidReportID(); hidpp::Report request(type, _device->deviceIndex(), _index, function_id, LOGID_HIDPP_SOFTWARE_ID); @@ -52,8 +55,15 @@ EssentialFeature::EssentialFeature(hidpp::Device* dev, uint16_t _id) : std::vector getFunc_req(2); getFunc_req[0] = (_id >> 8) & 0xff; getFunc_req[1] = _id & 0xff; - auto getFunc_resp = this->callFunction(Root::GetFeature, getFunc_req); - _index = getFunc_resp[0]; + try { + auto getFunc_resp = this->callFunction(Root::GetFeature, + getFunc_req); + _index = getFunc_resp[0]; + } catch(Error& e) { + if(e.code() == Error::InvalidFeatureIndex) + throw UnsupportedFeature(_id); + throw e; + } // 0 if not found if(!_index) diff --git a/src/logid/backend/hidpp20/Feature.cpp b/src/logid/backend/hidpp20/Feature.cpp index 5f32bbb..6f64db5 100644 --- a/src/logid/backend/hidpp20/Feature.cpp +++ b/src/logid/backend/hidpp20/Feature.cpp @@ -16,6 +16,7 @@ * */ +#include "Error.h" #include "Feature.h" #include "feature_defs.h" #include "features/Root.h" @@ -46,8 +47,16 @@ Feature::Feature(Device* dev, uint16_t _id) : _device (dev) std::vector getFunc_req(2); getFunc_req[0] = (_id >> 8) & 0xff; getFunc_req[1] = _id & 0xff; - auto getFunc_resp = this->callFunction(Root::GetFeature, getFunc_req); - _index = getFunc_resp[0]; + + try { + auto getFunc_resp = this->callFunction(Root::GetFeature, + getFunc_req); + _index = getFunc_resp[0]; + } catch(Error& e) { + if(e.code() == Error::InvalidFeatureIndex) + throw UnsupportedFeature(_id); + throw e; + } // 0 if not found if(!_index) diff --git a/src/logid/backend/hidpp20/features/Root.cpp b/src/logid/backend/hidpp20/features/Root.cpp index ba5e91a..f1aa724 100644 --- a/src/logid/backend/hidpp20/features/Root.cpp +++ b/src/logid/backend/hidpp20/features/Root.cpp @@ -17,6 +17,7 @@ */ #include "Root.h" +#include "../Error.h" using namespace logid::backend::hidpp20; @@ -51,8 +52,14 @@ feature_info _genGetFeatureInfo(uint16_t feature_id, feature_info Root::getFeature(uint16_t feature_id) { auto params = _genGetFeatureParams(feature_id); - auto response = this->callFunction(Function::GetFeature, params); - return _genGetFeatureInfo(feature_id, response); + try { + auto response = this->callFunction(Root::Function::GetFeature, params); + return _genGetFeatureInfo(feature_id, response); + } catch(Error& e) { + if(e.code() == Error::InvalidFeatureIndex) + throw UnsupportedFeature(feature_id); + throw e; + } } std::tuple Root::getVersion() @@ -70,8 +77,14 @@ EssentialRoot::EssentialRoot(hidpp::Device* dev) : EssentialFeature(dev, ID) feature_info EssentialRoot::getFeature(uint16_t feature_id) { auto params = _genGetFeatureParams(feature_id); - auto response = this->callFunction(Root::Function::GetFeature, params); - return _genGetFeatureInfo(feature_id, response); + try { + auto response = this->callFunction(Root::Function::GetFeature, params); + return _genGetFeatureInfo(feature_id, response); + } catch(Error& e) { + if(e.code() == Error::InvalidFeatureIndex) + throw UnsupportedFeature(feature_id); + throw e; + } } std::tuple EssentialRoot::getVersion()