VirtualBox

source: vbox/trunk/src/VBox/Devices/USB/VUSBSnifferVmx.cpp

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
RevLine 
[53014]1/* $Id: VUSBSnifferVmx.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
[59633]3 * Virtual USB Sniffer facility - VMX USBIO format.
[53014]4 */
5
6/*
[98103]7 * Copyright (C) 2016-2023 Oracle and/or its affiliates.
[53014]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
[53014]26 */
27
[57358]28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
[53014]32#define LOG_GROUP LOG_GROUP_DRV_VUSB
33#include <VBox/log.h>
34#include <iprt/mem.h>
35#include <iprt/buildconfig.h>
36#include <iprt/string.h>
37#include <iprt/system.h>
[53072]38#include <iprt/time.h>
[53014]39
[59615]40#include "VUSBSnifferInternal.h"
[53014]41
42
[57358]43/*********************************************************************************************************************************
44* Defined Constants And Macros *
45*********************************************************************************************************************************/
46
[62463]47
[57358]48/*********************************************************************************************************************************
49* Structures and Typedefs *
50*********************************************************************************************************************************/
51
[53014]52/**
53 * The internal VUSB sniffer state.
54 */
[59615]55typedef struct VUSBSNIFFERFMTINT
[53014]56{
[59615]57 /** Stream handle. */
58 PVUSBSNIFFERSTRM pStrm;
59} VUSBSNIFFERFMTINT;
[53014]60
[59615]61
62/*********************************************************************************************************************************
63* Static Variables *
64*********************************************************************************************************************************/
65
[53014]66/**
[59615]67 * Supported file extensions.
68 */
69static const char *s_apszFileExts[] =
70{
[59633]71 "vmx",
72 "vmware",
73 "usbio",
[59615]74 NULL
75};
76
77
78/**
[59633]79 * Month strings.
[53014]80 */
[59633]81static const char *s_apszMonths[] =
[53014]82{
[59633]83 "Jan",
84 "Feb",
85 "Mar",
86 "Apr",
87 "May",
88 "Jun",
89 "Jul",
90 "Aug",
91 "Sep",
92 "Oct",
93 "Nov",
94 "Dec"
95};
[53014]96
[62463]97
[59633]98/*********************************************************************************************************************************
99* Internal Functions *
100*********************************************************************************************************************************/
[53014]101
102
[59633]103static int vusbSnifferFmtVmxLogData(PVUSBSNIFFERFMTINT pThis, PRTTIME pTime, uint8_t *pbBuf, size_t cbBuf)
[53060]104{
[62960]105 int rc;
106 char szLineBuf[256];
107 size_t off = 0;
[53060]108
[59633]109 do
110 {
[62960]111 size_t cch = RTStrPrintf(&szLineBuf[0], sizeof(szLineBuf),
112 "%s %02u %02u:%02u:%02u.%3.*u: vmx| USBIO: %03zx: %16.*Rhxs\n",
113 s_apszMonths[pTime->u8Month - 1], pTime->u8MonthDay,
114 pTime->u8Hour, pTime->u8Minute, pTime->u8Second, 3, pTime->u32Nanosecond,
[59633]115 off, RT_MIN(cbBuf - off, 16), pbBuf);
[62960]116 rc = pThis->pStrm->pfnWrite(pThis->pStrm, &szLineBuf[0], cch);
[59633]117 off += RT_MIN(cbBuf, 16);
118 pbBuf += RT_MIN(cbBuf, 16);
119 } while (RT_SUCCESS(rc) && off < cbBuf);
[53060]120
121 return rc;
122}
123
[62956]124/** @interface_method_impl{VUSBSNIFFERFMT,pfnInit} */
[59633]125static DECLCALLBACK(int) vusbSnifferFmtVmxInit(PVUSBSNIFFERFMTINT pThis, PVUSBSNIFFERSTRM pStrm)
[53014]126{
[59633]127 pThis->pStrm = pStrm;
128 return VINF_SUCCESS;
[53072]129}
130
131
[62956]132/** @interface_method_impl{VUSBSNIFFERFMT,pfnDestroy} */
[59633]133static DECLCALLBACK(void) vusbSnifferFmtVmxDestroy(PVUSBSNIFFERFMTINT pThis)
[53014]134{
[59633]135 NOREF(pThis);
[53014]136}
137
138
[62956]139/** @interface_method_impl{VUSBSNIFFERFMT,pfnRecordEvent} */
[59633]140static DECLCALLBACK(int) vusbSnifferFmtVmxRecordEvent(PVUSBSNIFFERFMTINT pThis, PVUSBURB pUrb, VUSBSNIFFEREVENT enmEvent)
[53014]141{
[59633]142 RTTIMESPEC TimeNow;
143 RTTIME Time;
[62960]144 char szLineBuf[256];
[59633]145 const char *pszEvt = enmEvent == VUSBSNIFFEREVENT_SUBMIT ? "Down" : "Up";
146 uint8_t cIsocPkts = pUrb->enmType == VUSBXFERTYPE_ISOC ? pUrb->cIsocPkts : 0;
[53014]147
[59633]148 if (pUrb->enmType == VUSBXFERTYPE_MSG)
149 return VINF_SUCCESS;
[53014]150
[62960]151 RT_ZERO(szLineBuf);
[53014]152
[59633]153 RTTimeNow(&TimeNow);
154 RTTimeExplode(&Time, &TimeNow);
[53014]155
[62960]156 size_t cch = RTStrPrintf(&szLineBuf[0], sizeof(szLineBuf),
[59633]157 "%s %02u %02u:%02u:%02u.%3.*u: vmx| USBIO: %s dev=%u endpt=%x datalen=%u numPackets=%u status=%u 0\n",
158 s_apszMonths[Time.u8Month - 1], Time.u8MonthDay, Time.u8Hour, Time.u8Minute, Time.u8Second, 3, Time.u32Nanosecond,
159 pszEvt, pUrb->DstAddress, pUrb->EndPt | (pUrb->enmDir == VUSBDIRECTION_IN ? 0x80 : 0x00),
160 pUrb->cbData, cIsocPkts, pUrb->enmStatus);
[62960]161 int rc = pThis->pStrm->pfnWrite(pThis->pStrm, &szLineBuf[0], cch);
[59615]162 if (RT_SUCCESS(rc))
163 {
[59633]164 /* Log the data in the appropriate stage. */
165 if ( pUrb->enmType == VUSBXFERTYPE_CTRL
166 || pUrb->enmType == VUSBXFERTYPE_MSG)
[59615]167 {
[59633]168 if (enmEvent == VUSBSNIFFEREVENT_SUBMIT)
169 rc = vusbSnifferFmtVmxLogData(pThis, &Time, &pUrb->abData[0], sizeof(VUSBSETUP));
170 else if (enmEvent == VUSBSNIFFEREVENT_COMPLETE)
[59615]171 {
[59633]172 rc = vusbSnifferFmtVmxLogData(pThis, &Time, &pUrb->abData[0], sizeof(VUSBSETUP));
173 if ( RT_SUCCESS(rc)
174 && pUrb->cbData > sizeof(VUSBSETUP))
175 rc = vusbSnifferFmtVmxLogData(pThis, &Time, &pUrb->abData[sizeof(VUSBSETUP)], pUrb->cbData - sizeof(VUSBSETUP));
[59615]176 }
177 }
178 else
179 {
[59633]180 if ( enmEvent == VUSBSNIFFEREVENT_SUBMIT
181 && pUrb->enmDir == VUSBDIRECTION_OUT)
182 rc = vusbSnifferFmtVmxLogData(pThis, &Time, &pUrb->abData[0], pUrb->cbData);
183 else if ( enmEvent == VUSBSNIFFEREVENT_COMPLETE
184 && pUrb->enmDir == VUSBDIRECTION_IN)
185 rc = vusbSnifferFmtVmxLogData(pThis, &Time, &pUrb->abData[0], pUrb->cbData);
[53014]186 }
187 }
188
189 return rc;
190}
191
[59615]192/**
193 * VUSB sniffer format writer.
194 */
[59633]195const VUSBSNIFFERFMT g_VUsbSnifferFmtVmx =
[59615]196{
197 /** szName */
[59633]198 "VMX",
[59615]199 /** pszDesc */
[59633]200 "VMX log format writer supported by vusb-analyzer: http://vusb-analyzer.sourceforge.net",
[59615]201 /** papszFileExts */
202 &s_apszFileExts[0],
203 /** cbFmt */
204 sizeof(VUSBSNIFFERFMTINT),
205 /** pfnInit */
[59633]206 vusbSnifferFmtVmxInit,
[59615]207 /** pfnDestroy */
[59633]208 vusbSnifferFmtVmxDestroy,
[59615]209 /** pfnRecordEvent */
[59633]210 vusbSnifferFmtVmxRecordEvent
[59615]211};
212
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use