Usb box is not recognize

Post Reply
insa_hc
Posts: 2
Joined: Wed May 06, 2009 2:43 pm

Usb box is not recognize

Post by insa_hc » Wed May 06, 2009 3:28 pm

Hello,
I'm trying to understand why my 8g kingstone usb dongle works and why all my 3 external 2.5 usb box don't (with every wii homebrew, for example mplayer). The only one "application" which works with my usb external box is geexbox but I think is because it uses linux's kernel usb stack.
First of all I've used the template to write a small code to debug it. That's it:

Code: Select all

#include <sys/types.h>
#include <sys/dir.h>
#include <sys/param.h>

#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <ogcsys.h>
#include <ogc/usbstorage.h>
#include <ogc/usb.h>

#define UMS_BASE			(('U'<<24)|('M'<<16)|('S'<<8))
#define USB_IOCTL_UMS_INIT	        (UMS_BASE+0x1)
#define USB_HEAPSIZE					8192
#define USB_IOCTL_UMS_GET_CAPACITY      (UMS_BASE+0x2)
#define UMS_HEAPSIZE			0x8000

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

#define DEVLIST_MAXSIZE    8
#define	TAG_START			0x0BADC0DE

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

    s32 ret;
    s32 hId = -1;
    s32 fd = -1;
    u32 sector_size;

    ret = IOS_ReloadIOS(249);

	// Initialise the video system
	VIDEO_Init();
	
	// This function initialises the attached controllers
	WPAD_Init();
	
	// Obtain the preferred video mode from the system
	// This will correspond to the settings in the Wii menu
	rmode = VIDEO_GetPreferredMode(NULL);

	// Allocate memory for the display in the uncached region
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	// Initialise the console, required for printf
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	
	// Set up the video registers with the chosen mode
	VIDEO_Configure(rmode);
	
	// Tell the video hardware where our display memory is
	VIDEO_SetNextFramebuffer(xfb);
	
	// Make the display visible
	VIDEO_SetBlack(FALSE);

	// Flush the video register changes to the hardware
	VIDEO_Flush();

	// Wait for Video setup to complete
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	// The console understands VT terminal escape codes
	// This positions the cursor on row 2, column 0
	// we can use variables for this with format codes too
	// e.g. printf ("\x1b[%d;%dH", row, column );
	printf("\x1b[2;0H");  

    printf("IOS_Reload: %d\n", ret);

    ret = USB_Initialize();
    printf("USB_Initialize: %d\n", ret);
    ret = USBStorage_Initialize();
    printf("USBStorage_Initialize: %d\n", ret);	       

    hId = iosCreateHeap(UMS_HEAPSIZE);

    char *path = "/dev/usb/ehc";
    
    fd = IOS_Open(path,IPC_OPEN_NONE);

    ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_INIT, ":");
    printf("IOS_IoctlvFormat: %d\n", ret);

    printf("hId: %d\n", hId);
    printf("fd: %d\n", fd);

    ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", &sector_size);
    printf("IOS_IoctlvFormat (long args): %d\n", ret);

    printf("hId: %d\n", hId);
    printf("fd: %d\n", fd);
    printf("sector_size: %d\n", sector_size);

    ret = USB_Deinitialize();
    printf("USB_Deinitialize: %d\n", ret);    
	while(1) {

		// Call WPAD_ScanPads each loop, this reads the latest controller states
		WPAD_ScanPads();

		// WPAD_ButtonsDown tells us which buttons were pressed in this loop
		// this is a "one shot" state which will not fire again until the button has been released
		u32 pressed = WPAD_ButtonsDown(0);

		// We return to the launcher application via exit
		if ( pressed & WPAD_BUTTON_HOME ) exit(0);

		// Wait for the next frame
		VIDEO_WaitVSync();
	}

	return 0;
}
This is a "lsusb -v" on a linux machine for the working dongle:

Code: Select all

Bus 001 Device 009: ID 0951:1603 Kingston Technology Data Traveler 1GB/2GB Pen Drive
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0951 Kingston Technology
  idProduct          0x1603 Data Traveler 1GB/2GB Pen Drive
  bcdDevice            1.00
  iManufacturer           1 Kingston
  iProduct                2 DataTraveler 2.0
  iSerial                 3 0019E000B4B05B8B1C10009D
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk (Zip)
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0000
And that's one of the not working box:

Code: Select all

Bus 001 Device 010: ID 04cf:8818 Myson Century, Inc. USB2.0 to ATAPI Bridge Controller
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x04cf Myson Century, Inc.
  idProduct          0x8818 USB2.0 to ATAPI Bridge Controller
  bcdDevice           b0.08
  iManufacturer           1 Myson Century, Inc.
  iProduct                2 USB Mass Storage Device
  iSerial                 3 100
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 USB Mass Storage
    bmAttributes         0xc0
      Self Powered
    MaxPower               10mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      5 SFF-8070i
      bInterfaceProtocol     80 
      iInterface              5 Mass Storage Class
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0001
  Self Powered
Running the code posted before with the working one:

Code: Select all

IOS_Reload: 0
USB_Initialize: 0
USBStorage_Initialize:0
IOS_IoctlvFormat: 0
hId: 4
fd: 4
IOS_IoctlvFormat (long args): 15874047
hId: 4
fd: 4
sector_size: 512
USB_Deinitialize: 0
Running the code posted before with the not working one:

Code: Select all

IOS_Reload: 0
USB_Initialize: 0
USBStorage_Initialize:0
IOS_IoctlvFormat: 0
hId: 4
fd: 4
IOS_IoctlvFormat (long args): 0
hId: 4
fd: 4
sector_size: -2146790336
USB_Deinitialize: 0
Uncommenting "#define DEBUG_IPC" in ipc.c with the working one prints this:

Code: Select all

__ipc_ackhandler()
__ipc_sendrequest()
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_ackhandler()
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_replyhandler()
IPC res:cmd 00000008 rcmd 00000001 res 00000004
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_ackhandler()
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_replyhandler()
IPC res:cmd 00000008 rcmd 00000007 res 00000000
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_replyhandler()
IPC res:cmd 00000008 rcmd 00000007 res 00f237ff
__ipc_ackhandler()
__ipc_sendrequest()
The not working one:

Code: Select all

__ipc_ackhandler()
__ipc_sendrequest()
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_replyhandler()
IPC res:cmd 00000008 rcmd 00000001 res 00000004
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_replyhandler()
IPC res:cmd 00000008 rcmd 00000007 res 00000000
__ipc_ackhandler()
__ipc_sendrequest()
__ipc_sendrequest()
__ipc_interrupthandler(27)
__ipc_replyhandler()
IPC res:cmd 00000008 rcmd 00000007 res 00000000
__ipc_ackhandler()
__ipc_sendrequest()
Could someone please help me to find out where the bug is? :)
Thank you and bye.
InSa

Ps: sorry for the (very) long post, but I've tried to give more information as possible.

dontwantanick
Posts: 19
Joined: Tue Dec 30, 2008 5:44 pm

Re: Usb box is not recognize

Post by dontwantanick » Fri May 08, 2009 9:16 pm

I know it's a stupid question, but i have to ask. Are your HDDs fat formatted? You seem to know what you are doing, but most people have ntfs formatted drives and wonder why they don't work.

insa_hc
Posts: 2
Joined: Wed May 06, 2009 2:43 pm

Re: Usb box is not recognize

Post by insa_hc » Sat May 09, 2009 12:35 am

dontwantanick wrote:I know it's a stupid question, but i have to ask. Are your HDDs fat formatted? You seem to know what you are doing, but most people have ntfs formatted drives and wonder why they don't work.
First of all thank you for your reply. :)
No problem for the question, I know very well that often the simplest things are what you do not catch.
Unfortunately that's not the case, I've already tried fat filesystem but the problem is on a "lower" level. Infact the problem appears before the filesystem layer is "called" and AFAIK my little "tester" code should not invoke the filesystem part, which explains why my working dongle returns "consistent" results (with my code) even when it's ntfs formatted. The not working boxes do not care about filesystem, they always return crap results.

Continue debugging this I've discovered that my box has the "bInterfaceSubClass" setted to the not standard value "5" which should be (from usb mass storage standard) setted to "6" as the working dongle. Unfortunately it seems that matters only if using usbstorage.c as it's defined there in line 69 and used in line 466 in "USBStorage_Open" function. Considering that from usbstorage.c I'm only calling "USBStorage_Initialize" which don't call "USBStorage_Open" it should be irrelevant.
The other place where "0x06" appears is in ipc.c as "#define IOS_IOCTL 0x06" but that should be irrelevant too.

If my assumptions are wrong or if you have some advice please post it, as I'm trying to solve it as a c++ newbie coder with no experience with C... ;)

Thank you and bye.
InSa

dontwantanick
Posts: 19
Joined: Tue Dec 30, 2008 5:44 pm

Re: Usb box is not recognize

Post by dontwantanick » Sat May 09, 2009 9:32 am

Hmm, that's the whole code i use for usb storage:
#include <ogc/usbstorage.h>

__io_usbstorage.startup();
fatMountSimple("usb", &__io_usbstorage);

fatUnmount("usb");
__io_usbstorage.shutdown();


Which works for all my usb storage devices until an IOS reload. (because __io_usbstorage.shutdown does nothing)


The startup calls __usbstorage_IsInserted and that calls USBStorage_Open. Maybe you should try what happens with this, and what happens if you integrate your value "5" into usbstorage.c code.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest