tstPalmOne.c revision d72aa6b0dab3e9b60aa78bfca99c767c48a406b0
/* $Id$ */
/** @file
* USB PalmOne testcase
*/
/*
* Copyright (C) 2006-2007 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;
// set_config(1); - the culprit
set_interface(0, 0);
#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);
}
}
void palm(void)
{
// set_config(1); //skip this
// reset_ep(6);
/* This seems to be some kind of 'identify device' request. */
/* read from ep 6. */
/* read from ep 6. */
#if 0
/* write to ep 6 */
abBuf[0] = 1;
return;
abBuf[0] = 0x12;
return;
return;
abBuf[0] = 0xff;
return;
/* read from ep 6 */
/* read from ep 6. */
#endif
}
int reset(void)
{
int i = 0;
printf("resetting...\n");
}
{
{
int i;
for (i = 0; i < 120; i++)
{
if (g_fd >= 0)
break;
usleep(500000);
}
printf("\n");
}
if (g_fd < 0)
return bitch("open");
// reset();
// set_config(0);
// set_config(1);
usb_set_connected(0, 1);
claim_if(0);
#if 0
msd();
#else
palm();
#endif
return 0;
}