From patchwork Fri Aug 5 07:05:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suniel Mahesh X-Patchwork-Id: 2295 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C24793F047 for ; Fri, 5 Aug 2022 09:05:31 +0200 (CEST) Received: by mail-pj1-f71.google.com with SMTP id r14-20020a17090a1bce00b001f53b234980sf721505pjr.5 for ; Fri, 05 Aug 2022 00:05:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659683130; cv=pass; d=google.com; s=arc-20160816; b=im8qQrWXkgwyVfuPgidYzbp6k4SRY8nGrbBO/0//yVe44O1TrRo1ZokR66V3GAFDTt gE+uhwFn3YShPAGhhEvn7P9bmBzRzX81m+CZqAvis2BX7NL5gkOpK7Rs7whNx0SvgWcN 6y85fdOfXfysedZFvHcIRFbzJvVW8b+kyMdkmJTALXphVIn8NVzmsqxjb0OpMEsXRTfq y26Ay91NTNfSjCrw8Zoshv6xA8nRMppcBAbjTKPGGbhpz3lo59px/oowvfJhIWq90nIT QM8MNKCjghmsEL6Oy5kjpLH2UYQ+OmrBlYpABo5zPycAHNc1Vvdn4ZWmT7X8Lo/VuCaT 8rjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=KtGXdeOzqMj0YSwmlIA9lfVgp1gwYzwTTAdOkTfvhfs=; b=HkqU8qFF7wkC4rkaPDB/F2j/AyAaP24jrQHZwHHiXB92H0mXwWW/xVfnDr56S/O8zm UwElNrVG10DhSXh6rbLF2PVMVUWrjYPfBd2wNZGyF1f3Y4ToJC4vKICsJJZdz+wjFawC KYjjXohd8Zw0R5K6mlu46iXT5XqX9/w7XwXmJv9VMuRiNvo8+jnncZl67hawqjxw+zO8 49S4e6lBsYgrPzukiVWqjLxSkac/Jg6/9Rs9ULE7K2dxfbKuB3ZIRgNkOVLA5siL2qR+ 6XDEamgsiSlZX0XH7kmcy7OvfVqcHrn6EZQyUzQJ7DQ4QK+y6LJRU5HXiruIsbzUQP24 Bk3g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NbfxvjgW; spf=pass (google.com: domain of sunil@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=sunil@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc; bh=KtGXdeOzqMj0YSwmlIA9lfVgp1gwYzwTTAdOkTfvhfs=; b=rdLN1Hzb3z2lOK9BX8/nvNiZhn1G5rkPMnBv5g9CUIM58Hpr1DXdoTBZODxCdYDtPT ST+ePMFrUUfrKp/scxxeeHYOONyJo4clYSBQIoeH4DwKaav4F+GD8fU0vQiYk1GZ68R1 YJGSua7/NzPyY/QQNH8GUnxTCgsmdRaFvAx3U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc; bh=KtGXdeOzqMj0YSwmlIA9lfVgp1gwYzwTTAdOkTfvhfs=; b=HqQBFkwcjIw9JtiLGr5tyI6QJjtReOsF0+H1cMWH5QeMN4WE8aEP/9b1pgtpzH6+Lo W9mDnlkwIff/SvCP+mNB4sHbnhnbxcTXBXB7kvPBJz4iwCjuI95Gm3/VQe/uj+BWdg3r DlCyQwoyLQCAYUdcDBZCSakfkLxlA0zt9DDIT0iBtN40ZcjA65NpN9OjsG9v/EgwFX51 2PWttSDlrfmwPh+CA0yJQsoZc+64MvPPsBQ7hr4Ej5qUvt7IM+732Zs6d/G6d+uvmJy8 lw1Hvi5tnO4Ph2nqF7d/vcQK33jzup1uKzrNiDcWr2iHU6z0ZPuou1KwZdXKkEFpSLHC Piaw== X-Gm-Message-State: ACgBeo0mJ5y4EYg/SMCr3HfmtMLeSdgY8YCxgob07DgYCOer/iKkSX5X B6EAYmyow9B+Vpa2m2hhiqhGFarV X-Google-Smtp-Source: AA6agR6cM0xd2xNYlN95qmw/k3GsX+Y04m4Zuk2HcGMkjXo3B/onJTBksD+j03hVkZX3ubJphv3H1w== X-Received: by 2002:a17:902:d4c1:b0:16f:8311:54bc with SMTP id o1-20020a170902d4c100b0016f831154bcmr4902731plg.25.1659683130437; Fri, 05 Aug 2022 00:05:30 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90b:d96:b0:1f5:81e:89e1 with SMTP id bg22-20020a17090b0d9600b001f5081e89e1ls2997930pjb.1.-pod-prod-gmail; Fri, 05 Aug 2022 00:05:29 -0700 (PDT) X-Received: by 2002:a17:903:2286:b0:16f:8f52:c952 with SMTP id b6-20020a170903228600b0016f8f52c952mr2431862plh.126.1659683129587; Fri, 05 Aug 2022 00:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659683129; cv=none; d=google.com; s=arc-20160816; b=VSDj5dYHZfY5gM5G7Sxr6qgt/UFuRHkijICiW67x219d/lFzvVuGTG23WE6BcUr15O Q5qV8Gx0KUmQMd233q9um9Q3ngMAAMUmb4+g4Gdc4xyGQdxDi/S3JEIP5pSJkXmwLbW4 KeuTzSERarnJrc3dye0Hxr4ZTpZHd7VdttO9kiS6dsNy4JfXeb4W53NT0/sATzfJj/v2 4PT8se+jN3R1u/P20797GbZZrFL805eRAElody00wWz/Mp8IVE9DCLgFxNejPNYziw3g Q7Q8k3wV+9qeS1ZBwykV4NwJEm2eJaAMTG/UDzVGRctdYfbm0k80ph3i4cbtI6CDlm+x a0hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=J2MAC1RRxVe+1E8IQ0U0gCK1zi4qNZSQc9yqeL3gN+4=; b=JDnS2MV5AfXGuzcDWM7FiOoSCd8+xXPb5QZb6Iu4Y4SO36cFU18J1/qPuP8GlNnooJ SiExVOGDPRQKEvgrkrLsGnaJnANK6JT6olWFOxzHPGPUiufvqpNDllzXabv3lcimzxyz 2CQ0kllKpwsGAjt5URj/Mi+xAA7DGo7FbdxEu3/ofqvoY4I53hHnENkq8v9vST/RwdaE tGwPc9QjCr6jmdfhrTo94ctVNNwnQIDu/1QVma7vjnihcKw2lYoA7dCJcykQZ5haNXP9 IWpFZlHmhSb4XrLu3BN993EVEVUhPwfhDnlvLf63FeMXcWv6llHeN+Ur1J90TzDO+8Vn goew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NbfxvjgW; spf=pass (google.com: domain of sunil@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=sunil@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id p2-20020a170902ebc200b0016372444a47sor1604704plg.82.2022.08.05.00.05.29 for (Google Transport Security); Fri, 05 Aug 2022 00:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of sunil@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:902:8b87:b0:16f:1bb7:984a with SMTP id ay7-20020a1709028b8700b0016f1bb7984amr5454865plb.113.1659683129239; Fri, 05 Aug 2022 00:05:29 -0700 (PDT) Received: from localhost.localdomain ([183.83.136.224]) by smtp.gmail.com with ESMTPSA id e60-20020a17090a6fc200b001f262f6f717sm4877484pjk.3.2022.08.05.00.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:05:29 -0700 (PDT) From: Suniel Mahesh To: Felipe Balbi , Greg Kroah-Hartman , Michael Trimarchi , Jagan Teki , Zachary Holland , Daniel McLean , Rene Samson Ambrose , David Sands Cc: linux-kernel@vger.kernel.org, linux-amarula@amarulasolutions.com, USB list Subject: [RFC v3 2/2] HID: ghid: add example program for GET_REPORT Date: Fri, 5 Aug 2022 12:35:07 +0530 Message-Id: <20220805070507.123151-3-sunil@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805070507.123151-1-sunil@amarulasolutions.com> References: <20220805070507.123151-1-sunil@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: sunil@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NbfxvjgW; spf=pass (google.com: domain of sunil@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=sunil@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This adds a user-space ghid sample get report program at gadget side. This program sends reports from userspace(gadget side) which are saved in the kernel in a list. When a host requests a particular report based on report number and type, corresponding report can be send to host, instead of a zero filled in report. This program can add, delete reports and modify an existing report. Signed-off-by: Suniel Mahesh --- Changes for v3: - no changes Changes for v2: - no changes --- samples/Kconfig | 10 +++ samples/Makefile | 1 + samples/ghid/Makefile | 4 ++ samples/ghid/test-hid.c | 134 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 samples/ghid/Makefile create mode 100644 samples/ghid/test-hid.c diff --git a/samples/Kconfig b/samples/Kconfig index 470ee3baf2e1..f3d7873bb966 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -86,6 +86,16 @@ config SAMPLE_FPROBE This builds a fprobe example module. This module has an option 'symbol'. You can specify a probed symbol or symbols separated with ','. +config SAMPLE_GHID_GET_REPORT + bool "GHID sample get report" + depends on CC_CAN_LINK && HEADERS_INSTALL + help + Build GHID sample get report program. This program can send reports from + userspace(gadget side) which are saved in the kernel in a linked list. + When a host requests a particular report based on report number and type, + corresponding report can be send to host, instead of a zero filled in report. + This program can add, delete reports and modify an existing report. + config SAMPLE_KFIFO tristate "Build kfifo examples -- loadable modules only" depends on m diff --git a/samples/Makefile b/samples/Makefile index 701e912ab5af..1d58f7a0381e 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -6,6 +6,7 @@ subdir-$(CONFIG_SAMPLE_ANDROID_BINDERFS) += binderfs obj-$(CONFIG_SAMPLE_CONFIGFS) += configfs/ obj-$(CONFIG_SAMPLE_CONNECTOR) += connector/ obj-$(CONFIG_SAMPLE_FANOTIFY_ERROR) += fanotify/ +subdir-$(SAMPLE_GHID_GET_REPORT) += ghid subdir-$(CONFIG_SAMPLE_HIDRAW) += hidraw obj-$(CONFIG_SAMPLE_HW_BREAKPOINT) += hw_breakpoint/ obj-$(CONFIG_SAMPLE_KDB) += kdb/ diff --git a/samples/ghid/Makefile b/samples/ghid/Makefile new file mode 100644 index 000000000000..8c93ded625c1 --- /dev/null +++ b/samples/ghid/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +userprogs-always-y += test-hid + +userccflags += -I usr/include diff --git a/samples/ghid/test-hid.c b/samples/ghid/test-hid.c new file mode 100644 index 000000000000..f76786509047 --- /dev/null +++ b/samples/ghid/test-hid.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * usb hidg GET_REPORT example, device/gadget side + * This program tests the newly implemented GET_REPORT feature + * + * Copyright (c) 2022 Amarula Solutions India PVT LTD + * + * Authors: + * Copyright (c) 2022 Suniel Mahesh + * + */ + +#include +/* Linux */ +#include +#include +#include +#include +#include + +/* Unix */ +#include +#include +#include +#include +#include + +/* C */ +#include +#include +#include +#include +#include + +/* + * fix for failing compilation on systems that don't + * yet populate new version of uapi/linux/usb/g_hid.h + * to userspace. + */ +#define GADGET_ADD_REPORT_STATUS _IOWR('g', 0x41, struct uhid_set_report_req) +#define GADGET_REMOVE_REPORT_STATUS _IOWR('g', 0x42, struct uhid_get_report_req) +#define GADGET_UPDATE_REPORT_STATUS _IOWR('g', 0x43, struct uhid_set_report_req) + +struct uhid_set_report_req *create_report(void) +{ + struct uhid_set_report_req *rep; + int i; + + rep = (struct uhid_set_report_req *)calloc(1, sizeof(struct uhid_set_report_req)); + if (rep == NULL) { + perror("calloc() failed"); + exit(EXIT_FAILURE); + } + + printf("enter report id:\n"); + scanf("%u", &rep->id); + printf("enter report number:\n"); + scanf("%hhu", &rep->rnum); + printf("enter report type:\n"); + scanf("%hhu", &rep->rtype); + printf("enter report size:\n"); + scanf("%hu", &rep->size); + printf("enter report data:\n"); + + for (i = 0; i < rep->size; i++) + scanf("%hhu", &rep->data[i]); + + return rep; +} + +int main(int argc, char **argv) +{ + const char *filename = NULL; + struct uhid_set_report_req *report; + int fd = 0, res = 0, i, reports; + + if (argc < 1) { + fprintf(stderr, "Usage: %s /dev/hidg0\n", argv[0]); + return -1; + } + + filename = argv[1]; + fd = open(filename, O_RDWR, 0666); + + if (fd == -1) { + perror(filename); + return -2; + } + + printf("enter no of reports to send from userspace:\n"); + scanf("%d", &reports); + + if (reports == 0) + goto out; + + for (i = 0; i < reports; i++) { + report = create_report(); +/* send reports to device */ + res = ioctl(fd, GADGET_ADD_REPORT_STATUS, report); + if (res < 0) { + perror("GADGET_ADD_REPORT_STATUS"); + res = -3; + goto test_end; + } + free(report); + } + +/* delete report with report number specified */ + printf("deleting report w.r.t rtype and rnum:\n"); + report = create_report(); + res = ioctl(fd, GADGET_REMOVE_REPORT_STATUS, report); + if (res < 0) { + perror("GADGET_REMOVE_REPORT_STATUS"); + res = -4; + goto test_end; + } + free(report); + +/* modify an existing report identified by report number */ + printf("modify report w.r.t rtype and rnum:\n"); + report = create_report(); + res = ioctl(fd, GADGET_UPDATE_REPORT_STATUS, report); + if (res < 0) { + perror("GADGET_UPDATE_REPORT_STATUS"); + res = -5; + } + +test_end: + free(report); + report = NULL; +out: + close(fd); + return res; +}