diff mbox

[3/6] Input: elantech - packet checking for v2 hardware

Message ID 1313632629-23603-4-git-send-email-jj_ding@emc.com.tw (mailing list archive)
State New, archived
Headers show

Commit Message

JJ Ding Aug. 18, 2011, 1:57 a.m. UTC
For v2 hardware, there is no real parity check, but we can still check
some constant bits for data integrity.

Signed-off-by: JJ Ding <jj_ding@emc.com.tw>
---
 drivers/input/mouse/elantech.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

Comments

Daniel Kurtz Aug. 18, 2011, 2:49 a.m. UTC | #1
On Thu, Aug 18, 2011 at 9:57 AM, JJ Ding <jj_ding@emc.com.tw> wrote:
> For v2 hardware, there is no real parity check, but we can still check
> some constant bits for data integrity.
>
> Signed-off-by: JJ Ding <jj_ding@emc.com.tw>
> ---
>  drivers/input/mouse/elantech.c |   26 +++++++++++++++++++++++---
>  1 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> index cf41f23..032181c 100644
> --- a/drivers/input/mouse/elantech.c
> +++ b/drivers/input/mouse/elantech.c
> @@ -376,6 +376,25 @@ static int elantech_check_parity_v1(struct psmouse *psmouse)
>               etd->parity[packet[3]] == p3;
>  }
>
> +static int packet_simple_check_v2(struct psmouse *psmouse)
> +{
> +       struct elantech_data *etd = psmouse->private;
> +       unsigned char *packet = psmouse->packet;
> +
> +       if (etd->reports_pressure)
> +               return (packet[0] & 0x0c) == 0x04 &&
> +                      (packet[3] & 0x0f) == 0x02;
> +
> +       if ((packet[0] & 0xc0) == 0x80)
> +               return (packet[0] & 0x0c) == 0x0c &&
> +                      (packet[3] & 0x0e) == 0x08;
> +
> +       return (packet[0] & 0x3c) == 0x3c &&
> +              (packet[1] & 0xf0) == 0x00 &&
> +              (packet[3] & 0x3e) == 0x38 &&
> +              (packet[4] & 0xf0) == 0x00;
> +}
> +
>  /*
>  * Process byte stream from mouse and handle complete packets
>  */
> @@ -398,7 +417,9 @@ static psmouse_ret_t elantech_process_byte(struct psmouse *psmouse)
>                break;
>
>        case 2:
> -               /* We don't know how to check parity in protocol v2 */
> +               if (etd->paritycheck && !packet_simple_check_v2(psmouse))
> +                       return PSMOUSE_BAD_DATA;
> +
>                elantech_report_absolute_v2(psmouse);
>                break;
>        }
> @@ -799,8 +820,7 @@ int elantech_init(struct psmouse *psmouse)
>                etd->hw_version = 2;
>                /* For now show extra debug information */
>                etd->debug = 1;
> -               /* Don't know how to do parity checking for version 2 */
> -               etd->paritycheck = 0;
> +               etd->paritycheck = 1;

If we always do some sort of check, can we just remove etd->paritycheck now?

>
>                if (etd->fw_version >= 0x020800)
>                        etd->reports_pressure = true;
> --
> 1.7.4.1
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov Aug. 18, 2011, 6:38 a.m. UTC | #2
On Thu, Aug 18, 2011 at 09:57:06AM +0800, JJ Ding wrote:
> For v2 hardware, there is no real parity check, but we can still check
> some constant bits for data integrity.
> 
> Signed-off-by: JJ Ding <jj_ding@emc.com.tw>
> ---
>  drivers/input/mouse/elantech.c |   26 +++++++++++++++++++++++---
>  1 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> index cf41f23..032181c 100644
> --- a/drivers/input/mouse/elantech.c
> +++ b/drivers/input/mouse/elantech.c
> @@ -376,6 +376,25 @@ static int elantech_check_parity_v1(struct psmouse *psmouse)
>  	       etd->parity[packet[3]] == p3;
>  }
>  
> +static int packet_simple_check_v2(struct psmouse *psmouse)
> +{
> +	struct elantech_data *etd = psmouse->private;
> +	unsigned char *packet = psmouse->packet;
> +
> +	if (etd->reports_pressure)
> +		return (packet[0] & 0x0c) == 0x04 &&
> +		       (packet[3] & 0x0f) == 0x02;
> +
> +	if ((packet[0] & 0xc0) == 0x80)
> +		return (packet[0] & 0x0c) == 0x0c &&
> +		       (packet[3] & 0x0e) == 0x08;
> +
> +	return (packet[0] & 0x3c) == 0x3c &&
> +	       (packet[1] & 0xf0) == 0x00 &&
> +	       (packet[3] & 0x3e) == 0x38 &&
> +	       (packet[4] & 0xf0) == 0x00;

Can we please spell out the assumptions under which we decide that
packet is invalid?

Thanks.
JJ Ding Aug. 18, 2011, 7:31 a.m. UTC | #3
Hi Dmitry,

On Wed, 17 Aug 2011 23:38:18 -0700, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> On Thu, Aug 18, 2011 at 09:57:06AM +0800, JJ Ding wrote:
> > For v2 hardware, there is no real parity check, but we can still check
> > some constant bits for data integrity.
> > 
> > Signed-off-by: JJ Ding <jj_ding@emc.com.tw>
> > ---
> >  drivers/input/mouse/elantech.c |   26 +++++++++++++++++++++++---
> >  1 files changed, 23 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> > index cf41f23..032181c 100644
> > --- a/drivers/input/mouse/elantech.c
> > +++ b/drivers/input/mouse/elantech.c
> > @@ -376,6 +376,25 @@ static int elantech_check_parity_v1(struct psmouse *psmouse)
> >  	       etd->parity[packet[3]] == p3;
> >  }
> >  
> > +static int packet_simple_check_v2(struct psmouse *psmouse)
> > +{
> > +	struct elantech_data *etd = psmouse->private;
> > +	unsigned char *packet = psmouse->packet;
> > +
> > +	if (etd->reports_pressure)
> > +		return (packet[0] & 0x0c) == 0x04 &&
> > +		       (packet[3] & 0x0f) == 0x02;
        this is for newer v2 hardware

> > +
> > +	if ((packet[0] & 0xc0) == 0x80)
> > +		return (packet[0] & 0x0c) == 0x0c &&
> > +		       (packet[3] & 0x0e) == 0x08;
        this is for older v2, two finger touch 

> > +
> > +	return (packet[0] & 0x3c) == 0x3c &&
> > +	       (packet[1] & 0xf0) == 0x00 &&
> > +	       (packet[3] & 0x3e) == 0x38 &&
> > +	       (packet[4] & 0xf0) == 0x00;
        this is for older v2, 1/3 finger touch
      
> 
> Can we please spell out the assumptions under which we decide that
> packet is invalid?
> 
> Thanks.
> 
> -- 
> Dmitry
V2 hardware has two flavors. Older ones that do not report pressure,
and newer ones that reports pressure and width.

With newer ones, all packets (1, 2, 3 finger touch) have the same
constant bits.

With older ones, 1/3 finger touch packets and 2 finger touch packets have
different constant bits.

With all three cases, if the constant bits are not exactly what I
expected, I consider them invalid.

Dmitry, how do you want me to improve this? not enough comments?

Thanks
jj
> --
> To unsubscribe from this list: send the line "unsubscribe linux-input" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov Aug. 18, 2011, 7:52 a.m. UTC | #4
On Thu, Aug 18, 2011 at 03:31:27PM +0800, JJ Ding wrote:
> Hi Dmitry,
> 
> On Wed, 17 Aug 2011 23:38:18 -0700, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> > On Thu, Aug 18, 2011 at 09:57:06AM +0800, JJ Ding wrote:
> > > For v2 hardware, there is no real parity check, but we can still check
> > > some constant bits for data integrity.
> > > 
> > > Signed-off-by: JJ Ding <jj_ding@emc.com.tw>
> > > ---
> > >  drivers/input/mouse/elantech.c |   26 +++++++++++++++++++++++---
> > >  1 files changed, 23 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> > > index cf41f23..032181c 100644
> > > --- a/drivers/input/mouse/elantech.c
> > > +++ b/drivers/input/mouse/elantech.c
> > > @@ -376,6 +376,25 @@ static int elantech_check_parity_v1(struct psmouse *psmouse)
> > >  	       etd->parity[packet[3]] == p3;
> > >  }
> > >  
> > > +static int packet_simple_check_v2(struct psmouse *psmouse)
> > > +{
> > > +	struct elantech_data *etd = psmouse->private;
> > > +	unsigned char *packet = psmouse->packet;
> > > +
> > > +	if (etd->reports_pressure)
> > > +		return (packet[0] & 0x0c) == 0x04 &&
> > > +		       (packet[3] & 0x0f) == 0x02;
>         this is for newer v2 hardware
> 
> > > +
> > > +	if ((packet[0] & 0xc0) == 0x80)
> > > +		return (packet[0] & 0x0c) == 0x0c &&
> > > +		       (packet[3] & 0x0e) == 0x08;
>         this is for older v2, two finger touch 
> 
> > > +
> > > +	return (packet[0] & 0x3c) == 0x3c &&
> > > +	       (packet[1] & 0xf0) == 0x00 &&
> > > +	       (packet[3] & 0x3e) == 0x38 &&
> > > +	       (packet[4] & 0xf0) == 0x00;
>         this is for older v2, 1/3 finger touch
>       
> > 
> > Can we please spell out the assumptions under which we decide that
> > packet is invalid?
> > 
> > Thanks.
> > 
> > -- 
> > Dmitry
> V2 hardware has two flavors. Older ones that do not report pressure,
> and newer ones that reports pressure and width.
> 
> With newer ones, all packets (1, 2, 3 finger touch) have the same
> constant bits.
> 
> With older ones, 1/3 finger touch packets and 2 finger touch packets have
> different constant bits.
> 
> With all three cases, if the constant bits are not exactly what I
> expected, I consider them invalid.
> 
> Dmitry, how do you want me to improve this? not enough comments?

Right, if you could put the above into comments right in the
packet_simple_check_v2() that woudl be great.

Thanks.
JJ Ding Aug. 18, 2011, 8:06 a.m. UTC | #5
Hi Dmitry,

On Thu, 18 Aug 2011 00:52:26 -0700, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> On Thu, Aug 18, 2011 at 03:31:27PM +0800, JJ Ding wrote:
> > Hi Dmitry,
> > 
> > On Wed, 17 Aug 2011 23:38:18 -0700, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> > > On Thu, Aug 18, 2011 at 09:57:06AM +0800, JJ Ding wrote:
> > > > For v2 hardware, there is no real parity check, but we can still check
> > > > some constant bits for data integrity.
> > > > 
> > > > Signed-off-by: JJ Ding <jj_ding@emc.com.tw>
> > > > ---
> > > >  drivers/input/mouse/elantech.c |   26 +++++++++++++++++++++++---
> > > >  1 files changed, 23 insertions(+), 3 deletions(-)
> > > > 
> > > > diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> > > > index cf41f23..032181c 100644
> > > > --- a/drivers/input/mouse/elantech.c
> > > > +++ b/drivers/input/mouse/elantech.c
> > > > @@ -376,6 +376,25 @@ static int elantech_check_parity_v1(struct psmouse *psmouse)
> > > >  	       etd->parity[packet[3]] == p3;
> > > >  }
> > > >  
> > > > +static int packet_simple_check_v2(struct psmouse *psmouse)
> > > > +{
> > > > +	struct elantech_data *etd = psmouse->private;
> > > > +	unsigned char *packet = psmouse->packet;
> > > > +
> > > > +	if (etd->reports_pressure)
> > > > +		return (packet[0] & 0x0c) == 0x04 &&
> > > > +		       (packet[3] & 0x0f) == 0x02;
> >         this is for newer v2 hardware
> > 
> > > > +
> > > > +	if ((packet[0] & 0xc0) == 0x80)
> > > > +		return (packet[0] & 0x0c) == 0x0c &&
> > > > +		       (packet[3] & 0x0e) == 0x08;
> >         this is for older v2, two finger touch 
> > 
> > > > +
> > > > +	return (packet[0] & 0x3c) == 0x3c &&
> > > > +	       (packet[1] & 0xf0) == 0x00 &&
> > > > +	       (packet[3] & 0x3e) == 0x38 &&
> > > > +	       (packet[4] & 0xf0) == 0x00;
> >         this is for older v2, 1/3 finger touch
> >       
> > > 
> > > Can we please spell out the assumptions under which we decide that
> > > packet is invalid?
> > > 
> > > Thanks.
> > > 
> > > -- 
> > > Dmitry
> > V2 hardware has two flavors. Older ones that do not report pressure,
> > and newer ones that reports pressure and width.
> > 
> > With newer ones, all packets (1, 2, 3 finger touch) have the same
> > constant bits.
> > 
> > With older ones, 1/3 finger touch packets and 2 finger touch packets have
> > different constant bits.
> > 
> > With all three cases, if the constant bits are not exactly what I
> > expected, I consider them invalid.
> > 
> > Dmitry, how do you want me to improve this? not enough comments?
> 
> Right, if you could put the above into comments right in the
> packet_simple_check_v2() that woudl be great.
> 
> Thanks.
No problem. I will do that. 
> -- 
> Dmitry
> --
> To unsubscribe from this list: send the line "unsubscribe linux-input" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Éric Piel Aug. 19, 2011, 12:22 p.m. UTC | #6
Op 18-08-11 03:57, JJ Ding schreef:
> For v2 hardware, there is no real parity check, but we can still check
> some constant bits for data integrity.
>
> Signed-off-by: JJ Ding<jj_ding@emc.com.tw>
If you add some comments, as suggest by Dmitry, it looks perfect :-)

Signed-off-by: Éric Piel <eric.piel@tremplin-utc.net>

Éric

> ---
>   drivers/input/mouse/elantech.c |   26 +++++++++++++++++++++++---
>   1 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> index cf41f23..032181c 100644
> --- a/drivers/input/mouse/elantech.c
> +++ b/drivers/input/mouse/elantech.c
> @@ -376,6 +376,25 @@ static int elantech_check_parity_v1(struct psmouse *psmouse)
>   	       etd->parity[packet[3]] == p3;
>   }
>
> +static int packet_simple_check_v2(struct psmouse *psmouse)
> +{
> +	struct elantech_data *etd = psmouse->private;
> +	unsigned char *packet = psmouse->packet;
> +
> +	if (etd->reports_pressure)
> +		return (packet[0]&  0x0c) == 0x04&&
> +		       (packet[3]&  0x0f) == 0x02;
> +
> +	if ((packet[0]&  0xc0) == 0x80)
> +		return (packet[0]&  0x0c) == 0x0c&&
> +		       (packet[3]&  0x0e) == 0x08;
> +
> +	return (packet[0]&  0x3c) == 0x3c&&
> +	       (packet[1]&  0xf0) == 0x00&&
> +	       (packet[3]&  0x3e) == 0x38&&
> +	       (packet[4]&  0xf0) == 0x00;
> +}
> +
>   /*
>    * Process byte stream from mouse and handle complete packets
>    */
> @@ -398,7 +417,9 @@ static psmouse_ret_t elantech_process_byte(struct psmouse *psmouse)
>   		break;
>
>   	case 2:
> -		/* We don't know how to check parity in protocol v2 */
> +		if (etd->paritycheck&&  !packet_simple_check_v2(psmouse))
> +			return PSMOUSE_BAD_DATA;
> +
>   		elantech_report_absolute_v2(psmouse);
>   		break;
>   	}
> @@ -799,8 +820,7 @@ int elantech_init(struct psmouse *psmouse)
>   		etd->hw_version = 2;
>   		/* For now show extra debug information */
>   		etd->debug = 1;
> -		/* Don't know how to do parity checking for version 2 */
> -		etd->paritycheck = 0;
> +		etd->paritycheck = 1;
>
>   		if (etd->fw_version>= 0x020800)
>   			etd->reports_pressure = true;

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index cf41f23..032181c 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -376,6 +376,25 @@  static int elantech_check_parity_v1(struct psmouse *psmouse)
 	       etd->parity[packet[3]] == p3;
 }
 
+static int packet_simple_check_v2(struct psmouse *psmouse)
+{
+	struct elantech_data *etd = psmouse->private;
+	unsigned char *packet = psmouse->packet;
+
+	if (etd->reports_pressure)
+		return (packet[0] & 0x0c) == 0x04 &&
+		       (packet[3] & 0x0f) == 0x02;
+
+	if ((packet[0] & 0xc0) == 0x80)
+		return (packet[0] & 0x0c) == 0x0c &&
+		       (packet[3] & 0x0e) == 0x08;
+
+	return (packet[0] & 0x3c) == 0x3c &&
+	       (packet[1] & 0xf0) == 0x00 &&
+	       (packet[3] & 0x3e) == 0x38 &&
+	       (packet[4] & 0xf0) == 0x00;
+}
+
 /*
  * Process byte stream from mouse and handle complete packets
  */
@@ -398,7 +417,9 @@  static psmouse_ret_t elantech_process_byte(struct psmouse *psmouse)
 		break;
 
 	case 2:
-		/* We don't know how to check parity in protocol v2 */
+		if (etd->paritycheck && !packet_simple_check_v2(psmouse))
+			return PSMOUSE_BAD_DATA;
+
 		elantech_report_absolute_v2(psmouse);
 		break;
 	}
@@ -799,8 +820,7 @@  int elantech_init(struct psmouse *psmouse)
 		etd->hw_version = 2;
 		/* For now show extra debug information */
 		etd->debug = 1;
-		/* Don't know how to do parity checking for version 2 */
-		etd->paritycheck = 0;
+		etd->paritycheck = 1;
 
 		if (etd->fw_version >= 0x020800)
 			etd->reports_pressure = true;