Received: by 10.223.185.116 with SMTP id b49csp3540799wrg; Tue, 13 Feb 2018 04:04:44 -0800 (PST) X-Google-Smtp-Source: AH8x226+a9Irewn3q+5P5Cm1hZ1uZUR2kx+Ygz3mfJEMeU0FDQi3Q2RH4Xjk697zqSGwPk1XsB8u X-Received: by 10.101.66.129 with SMTP id j1mr824071pgp.56.1518523484742; Tue, 13 Feb 2018 04:04:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518523484; cv=none; d=google.com; s=arc-20160816; b=UvmIUoXJAM/W3qGhqNfMnz5JnclnZK0RRur7XSEyrL5GhFhlpox9/ynLKZqfj1KO8S LbnPeeJGXeoZuY2esPMrOFl+RlrEyhYSLqWwUMCWDaZWAdtLGawMIAtlUNFemQWYCLSV siorvd0NfeCqiNfGjkkOvzlUXNeWholsAF5GBXOCo6K9nLFo0CenklKZouvBoPpvbHKp lR3EfUFKcTOqLL8RefN21t7FBsLBBjsG9xWyOAAIwwOJNWOSZrTaIRYAJECICTkPexoR zeQ104l266sRmJ6myZwJ2zY1/tIyqPeUcEedkq+AMOzUlly2oJMiMxVfx1AxTPmbJZP8 m1ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LWji5FeUPBryqp6aAwFSE/QlvWB+LBCCtqwXDzim0Sk=; b=EuyvabLXdQ91P3F1Pp/NdCgf2q5uDrPs60blmYW0O9gSdalN7aUfBasMmXJ9jf3JDf J9IvhP8QuLt+Z85o56Ivz3PbAh1oYwtz3LSEn1lGA7Hl8W3jD+J1GovaN6VAwPAbalcg uNZny85tMczzJPfX4dlZNu4Off2owPd8vinnYaWd5HBK7X8s9Mq607Zr3UXodNZaRZuq BQvjLnW8CuxXTPSIRVJ0zQqMRh7Nv7Irn6V+Mik7tsa/j2JaGgmZ9bht+fYaYRd7zwPW Y2x/yLNaBc/dpkoehcz52Qs/sX8Ri0okLghGeYW0zRFNR2+25O5A8bO96JTgyq5tT3Pv Tc2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ml2qauXt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 133si204304pfy.347.2018.02.13.04.04.29; Tue, 13 Feb 2018 04:04:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ml2qauXt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934978AbeBMMDq (ORCPT + 99 others); Tue, 13 Feb 2018 07:03:46 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46341 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934835AbeBMMDk (ORCPT ); Tue, 13 Feb 2018 07:03:40 -0500 Received: by mail-wr0-f193.google.com with SMTP id 34so8114125wre.13; Tue, 13 Feb 2018 04:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LWji5FeUPBryqp6aAwFSE/QlvWB+LBCCtqwXDzim0Sk=; b=ml2qauXt/BLboohdLd3QnTVknMgLqj2qBXGo8OTDA/QRKgRjfosibvGIb43HmZzvD9 pElerZxPG4p/8v7O6muAm0P7FJzNE780PiROKWqju5D9Rye+UchiaOEb/yT0sgcOQaud XTyqzv+K8qgG4kjnyEyizaKBqM/MDVsHdLEzHaOXiVwZxph6WpzAzVZvt+MRApwC1vWy PakrHLmpSJ8VVq3rQdhBOXDLy4VKr6NTxKAEh7k+OAfADVS/yBDv/emHO7AsVkMOZdHc LdEIlPlcg/1xFU7ErAWrmkWFONz5YI9JR6nOYW/Eys1WBTS1sj+HT+HSfOnghlfNoyIx t1+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LWji5FeUPBryqp6aAwFSE/QlvWB+LBCCtqwXDzim0Sk=; b=qpB2VV7g4QZtGcsPvziT7McqOFqVFeWrSxW+aVXZjhy4bX2LCU8waOaGJCmcJQfhE+ hhARb+YrxKq7ogQbZ1Wu/+7EuKd7t5qIDK7OsoLkTIrpltwwBkXxlDmzZ7AhtxOCLxDA hGUyZs/2PlxA8f2eyOktq8Xu7xtq6B+em8i2sUubCTPg6lLbW2X5uIEbsKM0RIAsiQwR O7WaKJK7rr40xRM/elLvgMje1pkoWd5YaU8fBm2SLSBeUyunDw33o+L3+FkQZqUCFCQ2 g2s9EQT0rK0fa2beqqtI+4lJKVXNFg4zQK4Y30AGRD9SNhKNiyHiNwAuVAS4NIz9gFF3 XORw== X-Gm-Message-State: APf1xPDVKKQitKv9CYy3UO5cmhvJPsRYZWm289szBoL5FY0ifP37xg66 JP3mg2vNWtF/zvL837gYvxg= X-Received: by 10.223.163.16 with SMTP id c16mr192013wrb.18.1518523419101; Tue, 13 Feb 2018 04:03:39 -0800 (PST) Received: from localhost.localdomain ([2a01:c50e:5126:7a00:bca6:624f:b432:9029]) by smtp.gmail.com with ESMTPSA id 62sm11641550wrg.81.2018.02.13.04.03.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 04:03:38 -0800 (PST) From: Rodrigo Rivas Costa To: Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Cc: Rodrigo Rivas Costa Subject: [PATCH 2/3] HID: steam: add serial number information. Date: Tue, 13 Feb 2018 13:03:07 +0100 Message-Id: <20180213120308.23879-2-rodrigorivascosta@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180213120308.23879-1-rodrigorivascosta@gmail.com> References: <20180213120308.23879-1-rodrigorivascosta@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This device has a feature report to send and receive commands. Use it to get the serial number and set the device's uniq value. Signed-off-by: Rodrigo Rivas Costa --- drivers/hid/hid-steam.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index 03f912ab5484..f269a986e2be 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -34,12 +34,17 @@ struct steam_device { unsigned long quirks; struct work_struct work_connect; bool connected; + char serial_no[11]; }; static int steam_register(struct steam_device *steam); static void steam_unregister(struct steam_device *steam); static void steam_do_connect_event(struct steam_device *steam, bool connected); static void steam_do_input_event(struct steam_device *steam, u8 *data); +static int steam_send_report(struct steam_device *steam, + u8 *cmd, int size); +static int steam_recv_report(struct steam_device *steam, + u8 *data, int size); static int steam_input_open(struct input_dev *dev) { @@ -55,6 +60,78 @@ static void steam_input_close(struct input_dev *dev) hid_hw_close(steam->hid_dev); } +#define STEAM_FEATURE_REPORT_SIZE 65 + +static int steam_send_report(struct steam_device *steam, + u8 *cmd, int size) +{ + int retry; + int ret; + u8 *buf = kzalloc(STEAM_FEATURE_REPORT_SIZE, GFP_KERNEL); + + if (!buf) + return -ENOMEM; + + /* The report ID is always 0 */ + memcpy(buf + 1, cmd, size); + + /* Sometimes the wireless controller fails with EPIPE + * when sending a feature report. + * Doing a HID_REQ_GET_REPORT and waiting for a while + * seems to fix that. + */ + for (retry = 0; retry < 10; ++retry) { + ret = hid_hw_raw_request(steam->hid_dev, 0, + buf, size + 1, + HID_FEATURE_REPORT, HID_REQ_SET_REPORT); + if (ret != -EPIPE) + break; + dbg_hid("%s: failed, retrying (%d times)\n", __func__, retry+1); + steam_recv_report(steam, NULL, 0); + msleep(50); + } + kfree(buf); + return ret; +} + +static int steam_recv_report(struct steam_device *steam, + u8 *data, int size) +{ + int ret; + u8 *buf = kzalloc(STEAM_FEATURE_REPORT_SIZE, GFP_KERNEL); + + if (!buf) + return -ENOMEM; + + /* The report ID is always 0 */ + ret = hid_hw_raw_request(steam->hid_dev, 0x00, + buf, STEAM_FEATURE_REPORT_SIZE, + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); + memcpy(data, buf + 1, size); + kfree(buf); + return ret; +} + +static int steam_get_serial(struct steam_device *steam) +{ + /* Send: 0xae 0x15 0x01 + * Recv: 0xae 0x15 0x01 serialnumber (10 chars) + */ + int ret; + u8 cmd[] = {0xae, 0x15, 0x01}; + u8 reply[14]; + + ret = steam_send_report(steam, cmd, sizeof(cmd)); + if (ret < 0) + return ret; + ret = steam_recv_report(steam, reply, sizeof(reply)); + if (ret < 0) + return ret; + reply[13] = 0; + strcpy(steam->serial_no, reply + 3); + return 0; +} + static void steam_work_connect_cb(struct work_struct *work) { struct steam_device *steam = container_of(work, struct steam_device, @@ -385,7 +462,12 @@ static int steam_register(struct steam_device *steam) dbg_hid("%s\n", __func__); - hid_info(hdev, "Steam Controller connected"); + ret = steam_get_serial(steam); + if (ret) + return ret; + + hid_info(hdev, "Steam Controller SN: '%s' connected", + steam->serial_no); input = input_allocate_device(); if (!input) @@ -398,7 +480,7 @@ static int steam_register(struct steam_device *steam) input->name = "Steam Controller"; input->phys = hdev->phys; - input->uniq = hdev->uniq; + input->uniq = steam->serial_no; input->id.bustype = hdev->bus; input->id.vendor = hdev->vendor; input->id.product = hdev->product; @@ -447,7 +529,8 @@ static void steam_unregister(struct steam_device *steam) dbg_hid("%s\n", __func__); if (steam->input_dev) { - hid_info(steam->hid_dev, "Steam Controller disconnected"); + hid_info(steam->hid_dev, "Steam Controller SN: '%s' disconnected", + steam->serial_no); input_unregister_device(steam->input_dev); steam->input_dev = NULL; } -- 2.16.1