From patchwork Fri Oct 7 19:39:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roderick Colenbrander X-Patchwork-Id: 9367433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF8DB600C8 for ; Fri, 7 Oct 2016 19:40:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE5ED297EE for ; Fri, 7 Oct 2016 19:40:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2EE429832; Fri, 7 Oct 2016 19:40:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5620A297EE for ; Fri, 7 Oct 2016 19:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755351AbcJGTkP (ORCPT ); Fri, 7 Oct 2016 15:40:15 -0400 Received: from mail-io0-f177.google.com ([209.85.223.177]:36230 "EHLO mail-io0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752666AbcJGTkP (ORCPT ); Fri, 7 Oct 2016 15:40:15 -0400 Received: by mail-io0-f177.google.com with SMTP id j37so57472363ioo.3 for ; Fri, 07 Oct 2016 12:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaikai-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qn9K7rSjwQ9IdGcYsxyADR99GOcYr5IH9qWnW4vI1QM=; b=CZpUsSxd2cTKIVfahk+QTMksv2tNDhoCHazYqHlxNV/6UMQKR7M7Ek5v5dbKSKX/jp ys23Kb2jKxGedguJ94aHXXv6JvRcIGh49N08BuTKh7a4Ap85Ym0InZhi9lVJ2EcC3q41 FNJpBJX2JLO63yhDETNCQMqUW2G2K4CV2Za9eG0lFRxwaynPOQq1m1Qsf8Ro0WvLDqcB PqeCQNj9yCRPuG8skf1KtEnMKylHvtrF0WFnpHcADMN0Fj+vid4uJg2YIq7/SG337mqg /Np4wp/U2sdnxiin9ZJ3D59NldK5HJXjk2ejol4t6sNqnPB2mwntsC5IXvfaA9eOFHUp jovw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Qn9K7rSjwQ9IdGcYsxyADR99GOcYr5IH9qWnW4vI1QM=; b=hfPImpMC6SSz4S95Z/me6lfKer4Rb9dtsyJxyePig8TvwuF8hYxy0ikzQyQwjx5Rs+ Zkz6XDGIHYsbtVHpEr96CxytSDSJJLow7ff47n/fq9C7F0vJEhOxEV38miiKPLa9eAtm SMI7mwnODqWyZyO8TLGaPREJ3jCc9Kh9lNtesgBJk2sGKv2yEJztfpDhvOtAH6uL5XoT +xnQ53sJlSv+MV4P4VWaNkIAF4wvlvJdOaltqMGluuYzATbmvEc0ipJPDkccYOGodMut GK5nY+CRznOT8QgsiPQZGVs98fhQbXFk2ti6JhMIbJHyTmARd9AwDfsrs8QYRXNQWni4 ByLg== X-Gm-Message-State: AA6/9RlQqtzbUBMDYQUR7GhblxDgZrKu16wypfKh6A0xO3ZfaqKuKwKdtPzTz1e13x8+4PZc X-Received: by 10.107.205.65 with SMTP id d62mr21587861iog.221.1475869214213; Fri, 07 Oct 2016 12:40:14 -0700 (PDT) Received: from konan1.dev.biz ([100.42.98.197]) by smtp.gmail.com with ESMTPSA id v7sm1735481itd.6.2016.10.07.12.40.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Oct 2016 12:40:13 -0700 (PDT) From: Roderick Colenbrander To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jiri Kosina , Tim Bird , Roderick Colenbrander Subject: [PATCH 3/7] HID: sony: Perform CRC check on bluetooth input packets Date: Fri, 7 Oct 2016 12:39:36 -0700 Message-Id: <1475869180-26757-4-git-send-email-roderick@gaikai.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475869180-26757-1-git-send-email-roderick@gaikai.com> References: <1475869180-26757-1-git-send-email-roderick@gaikai.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Roderick Colenbrander Signed-off-by: Roderick Colenbrander --- drivers/hid/hid-sony.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 43bb24c..34988ce 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "hid-ids.h" @@ -1021,6 +1023,7 @@ struct motion_output_report_02 { #define DS4_FEATURE_REPORT_0x02_SIZE 37 #define DS4_FEATURE_REPORT_0x81_SIZE 7 +#define DS4_INPUT_REPORT_0x11_SIZE 78 #define DS4_OUTPUT_REPORT_0x05_SIZE 32 #define DS4_OUTPUT_REPORT_0x11_SIZE 78 #define SIXAXIS_REPORT_0xF2_SIZE 17 @@ -1324,6 +1327,21 @@ static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && size == 64) || ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && rd[0] == 0x11 && size == 78)) { + if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) { + /* CRC check */ + u8 bthdr = 0xA1; + u32 crc; + u32 report_crc; + + crc = crc32_le(0xFFFFFFFF, &bthdr, 1); + crc = ~crc32_le(crc, rd, DS4_INPUT_REPORT_0x11_SIZE-4); + report_crc = get_unaligned_le32(&rd[DS4_INPUT_REPORT_0x11_SIZE-4]); + if (crc != report_crc) { + hid_dbg(sc->hdev, "DualShock 4 input report's CRC check failed, received crc 0x%0x != 0x%0x\n", + report_crc, crc); + return -EILSEQ; + } + } dualshock4_parse_report(sc, rd, size); }