File 05-fixed_bluetooth_support.patch of Package hidpp

Fixed bluetooth support

diff --git a/src/libhidpp/hidpp/Device.cpp b/src/libhidpp/hidpp/Device.cpp
index 1771ac4..862c060 100644
--- a/src/libhidpp/hidpp/Device.cpp
+++ b/src/libhidpp/hidpp/Device.cpp
@@ -47,6 +47,7 @@ const char *Device::InvalidProtocolVersion::what () const noexcept
 Device::Device (Dispatcher *dispatcher, DeviceIndex device_index):
 	_dispatcher (dispatcher), _device_index (device_index)
 {
+	force_long_reports = dispatcher->forceLongReports();
 	bool is_wireless = device_index >= WirelessDevice1 && device_index <= WirelessDevice6;
 	if (is_wireless) {
 		// Ask receiver for device info when wireless
@@ -79,6 +80,9 @@ Device::Device (Dispatcher *dispatcher, DeviceIndex device_index):
 	static constexpr unsigned int software_id = 1;
 	auto type = _dispatcher->reportInfo ().findReport ();
 	assert (type);
+	if (forceLongReports()) {
+		type = Report::Long;
+	}
 	Report request (*type, _device_index, HIDPP20::IRoot::index, HIDPP20::IRoot::Ping, software_id);
 	auto response = _dispatcher->sendCommand (std::move (request));
 	try {
diff --git a/src/libhidpp/hidpp/Device.h b/src/libhidpp/hidpp/Device.h
index 2599f6d..1469eb0 100644
--- a/src/libhidpp/hidpp/Device.h
+++ b/src/libhidpp/hidpp/Device.h
@@ -94,12 +94,18 @@ public:
 	 */
 	std::tuple<unsigned int, unsigned int> protocolVersion ();
 
+	const inline bool forceLongReports()
+	{
+		return force_long_reports;
+	}
+
 private:
 	Dispatcher *_dispatcher;
 	DeviceIndex _device_index;
 	uint16_t _product_id;
 	std::string _name;
 	std::tuple<unsigned int, unsigned int> _version;
+	bool force_long_reports = false;
 };
 
 }
diff --git a/src/libhidpp/hidpp/Dispatcher.h b/src/libhidpp/hidpp/Dispatcher.h
index 4d0d9d8..752e073 100644
--- a/src/libhidpp/hidpp/Dispatcher.h
+++ b/src/libhidpp/hidpp/Dispatcher.h
@@ -87,7 +87,7 @@ public:
 	/**
 	 * Sends the report without expecting any answer from the device.
 	 */
-	virtual void sendCommandWithoutResponse (const Report &report) = 0;
+	virtual void sendCommandWithoutResponse (Report &report) = 0;
 
 	/**
 	 * Sends the report expecting a matching (device index, sub ID and address)
@@ -120,6 +120,8 @@ public:
 	 */
 	virtual void unregisterEventHandler (listener_iterator it);
 
+	virtual bool forceLongReports () const = 0;
+
 	struct ReportInfo {
 		enum Flags { // flags are also the usage for collections and reports
 			HasShortReport = 1<<0,
@@ -148,6 +150,7 @@ public:
 
 protected:
 	void processEvent (const Report &);
+	bool force_long_reports = false;
 	void checkReportDescriptor (const HID::ReportDescriptor &report_desc);
 
 private:
diff --git a/src/libhidpp/hidpp/DispatcherThread.cpp b/src/libhidpp/hidpp/DispatcherThread.cpp
index 21712d9..4a45830 100644
--- a/src/libhidpp/hidpp/DispatcherThread.cpp
+++ b/src/libhidpp/hidpp/DispatcherThread.cpp
@@ -67,12 +67,18 @@ DispatcherThread::DispatcherThread (const char *path):
 	_stopped (false)
 {
 	checkReportDescriptor (_dev.getReportDescriptor ());
+	force_long_reports = true;
 }
 
 DispatcherThread::~DispatcherThread ()
 {
 }
 
+bool DispatcherThread::forceLongReports () const
+{
+	return force_long_reports;
+}
+
 const HID::RawDevice &DispatcherThread::hidraw () const
 {
 	return _dev;
@@ -93,13 +99,17 @@ std::string DispatcherThread::name () const
 	return _dev.name ();
 }
 
-void DispatcherThread::sendCommandWithoutResponse (const Report &report)
+void DispatcherThread::sendCommandWithoutResponse (Report &report)
 {
+	if (forceLongReports() && report.type() == Report::Short)
+	report.setType(Report::Long);
 	_dev.writeReport (report.rawReport ());
 }
 
 std::unique_ptr<Dispatcher::AsyncReport> DispatcherThread::sendCommand (Report &&report)
 {
+	if (forceLongReports() && report.type() == Report::Short)
+	report.setType(Report::Long);
 	std::unique_lock<std::mutex> lock (_command_mutex);
 	if (_stopped)
 		throw _exception;
diff --git a/src/libhidpp/hidpp/DispatcherThread.h b/src/libhidpp/hidpp/DispatcherThread.h
index 077b2bc..0d5d0ff 100644
--- a/src/libhidpp/hidpp/DispatcherThread.h
+++ b/src/libhidpp/hidpp/DispatcherThread.h
@@ -46,7 +46,7 @@ public:
 	virtual uint16_t vendorID () const;
 	virtual uint16_t productID () const;
 	virtual std::string name () const;
-	virtual void sendCommandWithoutResponse (const Report &report);
+	virtual void sendCommandWithoutResponse (Report &report);
 	virtual std::unique_ptr<Dispatcher::AsyncReport> sendCommand (Report &&report);
 	virtual std::unique_ptr<Dispatcher::AsyncReport> getNotification (DeviceIndex index, uint8_t sub_id);
 
@@ -54,6 +54,8 @@ public:
 	virtual listener_iterator registerEventHandler (DeviceIndex index, uint8_t sub_id, const event_handler &handler);
 	virtual void unregisterEventHandler (listener_iterator it);
 
+	virtual bool forceLongReports () const;
+
 	void run ();
 	void stop ();
 
diff --git a/src/libhidpp/hidpp/Report.cpp b/src/libhidpp/hidpp/Report.cpp
index 7946d6c..9463cde 100644
--- a/src/libhidpp/hidpp/Report.cpp
+++ b/src/libhidpp/hidpp/Report.cpp
@@ -302,3 +302,8 @@ bool Report::checkErrorMessage20 (uint8_t *feature_index,
 	return true;
 }
 
+void Report::setType(Report::Type type)
+{
+    _data[Offset::Type] = type;
+}
+
diff --git a/src/libhidpp/hidpp/Report.h b/src/libhidpp/hidpp/Report.h
index bae539c..d1655e3 100644
--- a/src/libhidpp/hidpp/Report.h
+++ b/src/libhidpp/hidpp/Report.h
@@ -297,6 +297,8 @@ public:
 	 */
 	const std::vector<uint8_t> &rawReport () const;
 
+	void setType(Report::Type type);
+
 private:
 	std::vector<uint8_t> _data;
 };
diff --git a/src/libhidpp/hidpp/SimpleDispatcher.cpp b/src/libhidpp/hidpp/SimpleDispatcher.cpp
index 687091e..20d551e 100644
--- a/src/libhidpp/hidpp/SimpleDispatcher.cpp
+++ b/src/libhidpp/hidpp/SimpleDispatcher.cpp
@@ -30,12 +30,18 @@ SimpleDispatcher::SimpleDispatcher (const char *path):
 	_dev (path)
 {
 	checkReportDescriptor (_dev.getReportDescriptor ());
+	force_long_reports = true;
 }
 
 SimpleDispatcher::~SimpleDispatcher ()
 {
 }
 
+bool SimpleDispatcher::forceLongReports() const
+{
+	return force_long_reports;
+}
+
 const HID::RawDevice &SimpleDispatcher::hidraw () const
 {
 	return _dev;
@@ -56,13 +62,17 @@ std::string SimpleDispatcher::name () const
 	return _dev.name ();
 }
 
-void SimpleDispatcher::sendCommandWithoutResponse (const Report &report)
+void SimpleDispatcher::sendCommandWithoutResponse (Report &report)
 {
+	if (forceLongReports() && report.type() == Report::Short)
+		report.setType(Report::Long);
 	_dev.writeReport (report.rawReport ());
 }
 
 std::unique_ptr<Dispatcher::AsyncReport> SimpleDispatcher::sendCommand (Report &&report)
 {
+	if (forceLongReports() && report.type() == Report::Short)
+		report.setType(Report::Long);
 	_dev.writeReport (report.rawReport ());
 	return std::make_unique<CommandResponse> (this, std::move (report));
 }
diff --git a/src/libhidpp/hidpp/SimpleDispatcher.h b/src/libhidpp/hidpp/SimpleDispatcher.h
index 3826991..f9f951a 100644
--- a/src/libhidpp/hidpp/SimpleDispatcher.h
+++ b/src/libhidpp/hidpp/SimpleDispatcher.h
@@ -49,12 +49,13 @@ public:
 	virtual uint16_t vendorID () const;
 	virtual uint16_t productID () const;
 	virtual std::string name () const;
-	virtual void sendCommandWithoutResponse (const Report &report);
+	virtual void sendCommandWithoutResponse (Report &report);
 	virtual std::unique_ptr<Dispatcher::AsyncReport> sendCommand (Report &&report);
 	virtual std::unique_ptr<Dispatcher::AsyncReport> getNotification (DeviceIndex index, uint8_t sub_id);
 
 	void listen ();
 	void stop ();
+	virtual bool forceLongReports () const;
 
 private:
 	Report getReport (int timeout = -1);
diff --git a/src/libhidpp/hidpp20/Device.cpp b/src/libhidpp/hidpp20/Device.cpp
index cf0874c..8eeaa90 100644
--- a/src/libhidpp/hidpp20/Device.cpp
+++ b/src/libhidpp/hidpp20/Device.cpp
@@ -54,6 +54,8 @@ std::vector<uint8_t> Device::callFunction (uint8_t feature_index,
 	auto type = dispatcher ()->reportInfo ().findReport (len);
 	if (!type)
 		throw std::logic_error ("Parameters too long");
+	if(forceLongReports())
+		type = HIDPP::Report::Long;
 	HIDPP::Report request (*type, deviceIndex (), feature_index, function, softwareID);
 	std::copy (param_begin, param_end, request.parameterBegin ());
 
diff --git a/src/tools/common/CommonOptions.cpp b/src/tools/common/CommonOptions.cpp
index 3fc5bb1..bcf1a3b 100644
--- a/src/tools/common/CommonOptions.cpp
+++ b/src/tools/common/CommonOptions.cpp
@@ -39,6 +39,8 @@ Option DeviceIndexOption (HIDPP::DeviceIndex &device_index)
 			case 6:
 				device_index = HIDPP::WirelessDevice6;
 				break;
+			case 255:
+				device_index = HIDPP::DefaultDevice;
 			default:
 				fprintf (stderr, "Invalid device index: %s\n", optarg);
 				return false;
openSUSE Build Service is sponsored by