VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/usb/UsbTestServiceGadgetClassTest.cpp@ 60376

Last change on this file since 60376 was 60376, checked in by vboxsync, 9 years ago

build fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: UsbTestServiceGadgetClassTest.cpp 60376 2016-04-07 14:46:28Z vboxsync $ */
2/** @file
3 * UsbTestServ - Remote USB test configuration and execution server, USB gadget class
4 * for the test device.
5 */
6
7/*
8 * Copyright (C) 2016 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.215389.xyz. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19
20/*********************************************************************************************************************************
21* Header Files *
22*********************************************************************************************************************************/
23
24#include <iprt/asm.h>
25#include <iprt/cdefs.h>
26#include <iprt/ctype.h>
27#include <iprt/dir.h>
28#include <iprt/env.h>
29#include <iprt/mem.h>
30#include <iprt/path.h>
31#include <iprt/process.h>
32#include <iprt/string.h>
33#include <iprt/types.h>
34
35#include <iprt/linux/sysfs.h>
36
37#include "UsbTestServiceGadgetInternal.h"
38
39/*********************************************************************************************************************************
40* Constants And Macros, Structures and Typedefs *
41*********************************************************************************************************************************/
42
43/** Default configfs mount point. */
44#define UTS_GADGET_CLASS_CONFIGFS_MNT_DEF "/sys/kernel/config/usb_gadget"
45/** Gadget template name */
46#define UTS_GADGET_TEMPLATE_NAME "gadget_test"
47
48#define UTS_GADGET_TEST_VENDOR_ID_DEF UINT16_C(0x0525)
49#define UTS_GADGET_TEST_PRODUCT_ID_DEF UINT16_C(0xa4a0)
50#define UTS_GADGET_TEST_DEVICE_CLASS_DEF UINT8_C(0xff)
51
52
53/**
54 * Internal UTS gadget host instance data.
55 */
56typedef struct UTSGADGETCLASSINT
57{
58 /** Gadget template path. */
59 char *pszGadgetPath;
60 /** The UDC this gadget is connected to. */
61 char *pszUdc;
62 /** Bus identifier for the used UDC. */
63 uint32_t uBusId;
64 /** Device identifier. */
65 uint32_t uDevId;
66} UTSGADGETCLASSINT;
67
68
69/*********************************************************************************************************************************
70* Internal Functions *
71*********************************************************************************************************************************/
72
73
74/**
75 * @interface_method_impl{UTSGADGETCLASS,pfnInit}
76 */
77static DECLCALLBACK(int) utsGadgetClassTestInit(PUTSGADGETCLASSINT pClass, PCUTSGADGETCFGITEM paCfg)
78{
79 int rc = VINF_SUCCESS;
80
81 if (RTLinuxSysFsExists(UTS_GADGET_CLASS_CONFIGFS_MNT_DEF))
82 {
83 /* Create the gadget template */
84 unsigned idx = 0;
85 char aszPath[RTPATH_MAX];
86
87 do
88 {
89 RTStrPrintf(&aszPath[0], RT_ELEMENTS(aszPath), "%s/%s%u",
90 UTS_GADGET_CLASS_CONFIGFS_MNT_DEF, UTS_GADGET_TEMPLATE_NAME,
91 idx);
92 rc = RTDirCreateFullPath(aszPath, 0700);
93 if (RT_SUCCESS(rc))
94 break;
95 idx++;
96 } while (idx < 100);
97
98 if (RT_SUCCESS(rc))
99 {
100 pClass->pszGadgetPath = RTStrDup(aszPath);
101
102 uint16_t idVendor = 0;
103 uint16_t idProduct = 0;
104 uint8_t bDeviceClass = 0;
105 rc = utsGadgetCfgQueryU16Def(paCfg, "Gadget/idVendor", &idVendor, UTS_GADGET_TEST_VENDOR_ID_DEF);
106 if (RT_SUCCESS(rc))
107 rc = utsGadgetCfgQueryU16Def(paCfg, "Gadget/idProduct", &idProduct, UTS_GADGET_TEST_PRODUCT_ID_DEF);
108 if (RT_SUCCESS(rc))
109 rc = utsGadgetCfgQueryU8Def(paCfg, "Gadget/bDeviceClass", &bDeviceClass, UTS_GADGET_TEST_DEVICE_CLASS_DEF);
110 }
111 }
112 else
113 rc = VERR_NOT_FOUND;
114
115 return rc;
116}
117
118
119/**
120 * @interface_method_impl{UTSGADGETCLASS,pfnTerm}
121 */
122static DECLCALLBACK(void) utsGadgetClassTestTerm(PUTSGADGETCLASSINT pClass)
123{
124
125}
126
127
128
129/**
130 * The gadget host interface callback table.
131 */
132const UTSGADGETCLASSIF g_UtsGadgetClassTest =
133{
134 /** enmType */
135 UTSGADGETCLASS_TEST,
136 /** pszDesc */
137 "UTS test device gadget class",
138 /** cbIf */
139 sizeof(UTSGADGETCLASSINT),
140 /** pfnInit */
141 utsGadgetClassTestInit,
142 /** pfnTerm */
143 utsGadgetClassTestTerm
144};
145
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette