/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
#include <iostypes.h>
#include <ios.h>
#include <iop.h>
#include <ioslibc.h>

#ifndef ENABLE_TEST
#define STACK_SIZE 2048
const u8        _initStack[STACK_SIZE];
const u32       _initStackSize = sizeof(_initStack);
const u32       _initPriority = 20;
#endif /* ENABLE_TEST */

#include "iosusbtypes.h"
#include "iosusb.h"

#define BUF_SIZE (64)
static u8 *__buf;

extern IOSHeapId __ehcdHeapId;

static void
__print_buf(char *s, u32 size)
{
    int i;
    for (i = 2; i <= size && s[i] != '\0'; i += 2) {
        printf("%c ", s[i]);
    }
    printf("\n");
    return;
}
#include "usb11.h"

#ifdef ENABLE_TEST
void
ehci_test(u32 arg)
#else
void
main(u32 arg)
#endif
{
    IOSFd fd;
    struct USB_DevDescr *d;
    fd = IOS_Open("/dev/usb/ehc/0b95/7720", 0);
    if (fd < 0) {
        printf("Need device asix ethernet dongle (0b95, 7720) to run this test\n");
        goto done;
    }
   
    d = (struct USB_DevDescr *)IOS_Alloc(__ehcdHeapId, sizeof(struct USB_DevDescr));
    __buf = (u8 *) IOS_Alloc(__ehcdHeapId, BUF_SIZE);

    printf("Test transfers to DMA region (should succeed)\n");
    IUSB_GetDevDescr(fd, d);
    printf("Dst buffer address: 0x%08x\n", __buf);
    IUSB_WriteCtrlMsg(fd, USB_REQTYPE_GETDESC, USB_REQ_GET_DESCRIPTOR,
                             (USB_DT_STRING << 8) + d->iManufacturer,
                             USB_LANG_EN_US, BUF_SIZE, __buf);
    printf("String read: ");
    __print_buf(__buf, BUF_SIZE);
#ifdef EHC_ENABLE_FG
    printf("Doing secure memory access violation test\n");
    IUSB_SecTest(fd);
#else
    printf("Secure memory access violation test disabled\n");
#endif
done:
    return;
}
