tstTrekStorGo.c revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* Some simple inquiry test for the TrekStor USB-Stick GO, linux usbfs
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/usbdevice_fs.h>
/** @name USB Control message recipient codes (from spec)
* @{ */
#define VUSB_TO_DEVICE 0x0
#define VUSB_TO_INTERFACE 0x1
#define VUSB_TO_ENDPOINT 0x2
#define VUSB_TO_OTHER 0x3
#define VUSB_RECIP_MASK 0x1f
/** @} */
/** @name USB control pipe setup packet structure (from spec)
* @{ */
#define VUSB_REQ_SHIFT (5)
/** @} */
#define VUSB_DIR_TO_HOST 0x80
typedef struct vusb_setup
{
} VUSBSETUP, *PVUSBSETUP;
typedef const VUSBSETUP *PCVUSBSETUP;
int g_fd;
{
return 1;
}
{
int cch = 0;
int off = 0;
int cchPrecision = 16;
{
int i;
while (i++ < cchPrecision)
printf(" ");
printf(" ");
{
}
/* next */
pb += cchPrecision;
off += cchPrecision;
}
printf("\n");
}
{
int rc;
do
{
errno = 0;
if (rc)
else
return rc;
}
{
#if 0
struct usbdevfs_urb KUrb = {0};
{
return KUrb.actual_length;
}
return -1;
#else
struct usbdevfs_bulktransfer BulkMsg = {0};
// printf("rc=%d BulkMsg.len=%d cbBuf=%d\n", rc, BulkMsg.len, cbBuf);
if (rc >= 0)
return rc;
return -1;
#endif
}
{
}
{
if (cb > 0)
return cb;
}
int doctrl(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength,
{
#if 0
struct usbdevfs_urb KUrb = {0};
{
return KUrb.actual_length;
}
return -1;
#else
struct usbdevfs_ctrltransfer CtrlMsg = {0};
if (rc >= 0)
return rc;
return -1;
#endif
}
{
}
{
struct usbdevfs_ioctl io;
}
static int set_config(int iCfg)
{
}
{
struct usbdevfs_setinterface SetIf = {0};
}
/* can be exploited to check if there is an active config. */
{
}
static void msd()
{
#if 1
unsigned InEndPt = 1;
unsigned OutEndPt = 1;
#else
unsigned InEndPt = 1;
unsigned OutEndPt = 2;
#endif
unsigned char abBuf[512];
int i;
#if 0
/* Send an Get Max LUN request */
abBuf[0] = 0;
#endif
for (i = 0; i < 3; i++)
{
printf("i=%d\n", i);
/* Send an INQUIRY command to ep 2 */
//abBuf[8] = 0x08;
return;
//usleep(15000);
/* read result */
//printf("recv..\n");
/* sense? */
usleep(150000);
}
}
int reset(void)
{
int i = 0;
printf("resetting...\n");
}
{
if (g_fd < 0)
return bitch("open");
reset();
usb_set_connected(0, 1);
claim_if(0);
// set_config(1); - the culprit!
set_interface(0, 0);
msd();
return 0;
}