From 966703057d6424f89bdf1fce29dfc916a607a3cd Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Fri, 5 Feb 2021 16:09:24 +0100
Subject: [PATCH] synaptics: Fix lost messages when sequence counter overflows

The device will always use sequence number 0 for certain messages. We
use this knowledge to filter the messages and assume that it is one of
these special messages rather than a response to a command.

However, we could end up sending a command with a sequence counter of 0
which would result in the response being ignored. Fix this by ensuring
we correctly wrap from 255 to 1 instead of 0.

Fixes: #358
---
 libfprint/drivers/synaptics/synaptics.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libfprint/drivers/synaptics/synaptics.c b/libfprint/drivers/synaptics/synaptics.c
index b4711fa..b2db9bd 100644
--- a/libfprint/drivers/synaptics/synaptics.c
+++ b/libfprint/drivers/synaptics/synaptics.c
@@ -348,7 +348,7 @@ synaptics_sensor_cmd (FpiDeviceSynaptics *self,
    * may only be a cancellation currently). */
   if (seq_num <= 0)
     {
-      self->last_seq_num = MAX (1, self->last_seq_num + 1);
+      self->last_seq_num = MAX (1, (self->last_seq_num + 1) & 0xff);
       real_seq_num = self->last_seq_num;
       if (seq_num == 0)
         self->cmd_seq_num = self->last_seq_num;