From patchwork Mon Aug 1 12:30:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suniel Mahesh X-Patchwork-Id: 2289 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C47563F3A4 for ; Mon, 1 Aug 2022 14:30:30 +0200 (CEST) Received: by mail-pl1-f200.google.com with SMTP id m5-20020a170902f64500b0016d313f3ce7sf7379040plg.23 for ; Mon, 01 Aug 2022 05:30:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659357029; cv=pass; d=google.com; s=arc-20160816; b=T2H2GQDBHo5GkbtDkgG5iimxrbO0pSQig8lJzRAbD/YN56MnpeBKdKbypI2zpekxR0 cpR6wGxhw6nXQ6HWlr0aJKUyeDqqib9O+UznHrNhgV/J/Y/perTDIKnWLRGJRKpENzWr /zmoZdrbvCHuTAD99zmKwazh/cbAUCzG2XFkMNP7OiBHkDIPQQwHm6qxU+GzJawswUgi 5oX8/F6aGaEVHX+A7e3AUPr6HV1Dyy+8Vi7Yv+SvsBV7bjILdOY0vd9KB10XgsJEoouf 1PNiUb2aU8HHgmMRRBc0weC3WjjaGF3mnr+DLxgINDPd97sqhnTMNj6uP0lybgjmbfR5 un9Q== 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=GSpON0EqMLd3J3nq2xpuoVHaNDKj7GySI5u/JxufX5E=; b=r2uEgvSx0630c06OouoQG9VLTn/y3Ug2YDLP5BqJu5OnOlfXchXUhT5AMVa5qAUv+e 3NlI/dxvi9v1NknE20wYU5oCg8ZicLAQx7e+oIhNoNOcFj4ib1BT7TXQa4YT8Eb+p7LJ NUpHf/z5yWQv8fgGcCtO5AoewZfnQ0c1EHxB57WMiHzKVIvvcOGgKLoki0fqTizFHlqA ZKizwCKFydmkIPlcdKh8/1girzAjFh2fTwS2G+TI2GY7xwwxm9Xq10vCKtylOYWkbj9J 2ocW8iAIYwyl2jDAgw71La9hbmJ12CtQ2ZQeyN/PffatHz6MINqRGe4jfPjHNWjuwi78 HyHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jTNNzOOm; 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=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=GSpON0EqMLd3J3nq2xpuoVHaNDKj7GySI5u/JxufX5E=; b=R/m/Gh3w1+Ho1Lv0U3jguRCweMMNh3XIB0fJmev/+4ZOu9xRUU5lMSm7ex1QHQvKDC 64mrfIyAyziuNAxQlkqmxmSLJ62kZw0udjqS/VdO4vawS33KJ2pVACJQfLzlPcPulboo igZX69Orkr2C2mdFoHqfkj4EmZBUHYTnjJ98g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=GSpON0EqMLd3J3nq2xpuoVHaNDKj7GySI5u/JxufX5E=; b=w0VsJPhtOwi4QU2nvOcG2/LJybBr28mvnyoaeity9boV5h/wxdTNzDYBUQJxv3lZxg LtjIlgT5ZJmIMzauxIY0NjQUJRDh2ElPaao5meLsLFdNdx3iCdhkaud3pVBeM9iVa2S8 e1skJyasXsEbX8PsA4aaZA2y2CB82v2eub9SgZXDiNlAdtHrp2gGhxZ05cikZ78NyhtE HKLwBbTKTm8nGtfSDhA4wMvsA2ubbkjh0+KoAKSC25qIh/RA2Etsi2Xnjh+gtO2XxaJa IOa7TCpJJiS79Xou+1TJHcB/6OcC100E14Wb2xsL+u6o146Dz4BPY3/My9NM5GXVsOmB Op0w== X-Gm-Message-State: AJIora+2to2T4URC5fHPY4rLcyYEpnTN+h3+h+WrW2uinXh+E55/vMXk IoRl81dsVCQDuvJnGDIQFMGvRBtt X-Google-Smtp-Source: AGRyM1v32ESsjtZZ6E5HKmXvRw3A/+vePO7UYBCrf6DqhTHt1sO5i6ou0o3ioe75Lrc/u3ZoULPWgQ== X-Received: by 2002:a63:fc1b:0:b0:41b:93c4:136a with SMTP id j27-20020a63fc1b000000b0041b93c4136amr11647622pgi.163.1659357029391; Mon, 01 Aug 2022 05:30:29 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:1d8:0:b0:412:9ace:9fdf with SMTP id 207-20020a6301d8000000b004129ace9fdfls5534250pgb.8.-pod-prod-gmail; Mon, 01 Aug 2022 05:30:28 -0700 (PDT) X-Received: by 2002:a05:6a00:1d26:b0:52b:f8ab:6265 with SMTP id a38-20020a056a001d2600b0052bf8ab6265mr16042423pfx.54.1659357028521; Mon, 01 Aug 2022 05:30:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659357028; cv=none; d=google.com; s=arc-20160816; b=GJF4HFLZq3B4m/cCLJxaQJP95iuq2kCnqJTTDk9awiwMwfkuhcgEY/sxXomNSHiA2F q2yKm/UiQ/hABSP936zqO4DkmDu/+zT65/CCJ7u0h4IweLIKjw1upuJmfSgECCo7MOXV OIPg+tGCBSiMzJflQ8lQ9CbsC+eaTaMuomvBNTPt3wAj60FySqAh56HOeRudtlWdZcSD FJ8RZ8x14eG326rxsbGsG7I29wKwlZGAl7flVpKcuvlk1ie2ZLJpbmyZM9r0dlN/KE+x C/L2ma7pp876lj1GrgOIr9cxaLVgMCjGIgeTd+zeOxGiSUsFLY2RcDq876i+EgvQFSqI Cihw== 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=79wsiIuqmJHlDnyKBpsU0dcqa0Z1I6VJ8b46FtTPbYM=; b=Ylr4ZevPJs5Q8Zch0g1XcG/nIgaMTMnqTzNOhe3qs/fLDvxjXGGXMV508C/7+kpZoe NJnYp2Yn5XAJQAV9IQYcKscKaj4yJvtRvlmOMI5IDI+Cvm/xTn9NPLOc21qL5aonnL8f +9xFsEXfvxfgkGGFWEQO7AVy7NnC25MbgV5s3te1JTCO9/FSAO8PAIxaYUhpVhI1UHvl Ld6w/MBspbSt1QyBJSjk5rrQgyj/A4D6/LgKKqNFsT6ESNhu740YuSRPLyLJQHYx3GIT hvogIDrXt0xTxNaMnlLU7sd0ednWX1OgZgk46jMyW65K/Z59qUOud86JAMHxN3/lG/TM 7Iwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jTNNzOOm; 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 e4-20020a621e04000000b0052d91859d3bsor1014991pfe.92.2022.08.01.05.30.28 for (Google Transport Security); Mon, 01 Aug 2022 05:30:28 -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:a05:6a00:190b:b0:52c:eb0e:e1b6 with SMTP id y11-20020a056a00190b00b0052ceb0ee1b6mr12456249pfi.54.1659357028121; Mon, 01 Aug 2022 05:30:28 -0700 (PDT) Received: from localhost.localdomain ([183.83.136.224]) by smtp.gmail.com with ESMTPSA id a14-20020a1709027e4e00b0015e8d4eb219sm3473230pln.99.2022.08.01.05.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 05:30:27 -0700 (PDT) From: Suniel Mahesh To: Felipe Balbi , Greg Kroah-Hartman , Michael Trimarchi , Jagan Teki Cc: linux-kernel@vger.kernel.org, linux-amarula@amarulasolutions.com, USB list Subject: [RFC 2/2] HID: ghid: add example program for GET_REPORT Date: Mon, 1 Aug 2022 18:00:10 +0530 Message-Id: <20220801123010.2984864-3-sunil@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801123010.2984864-1-sunil@amarulasolutions.com> References: <20220801123010.2984864-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=jTNNzOOm; 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 --- 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; +}