#ifndef __LINUX_USBIF__H
#define __LINUX_USBIF__H

#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <err.h>

#if defined(__DragonFly__)
#include <bus/usb/usb.h>
#else
#include <dev/usb/usb.h>
#endif

#define USB_DIR_OUT			UT_WRITE
#define USB_DIR_IN			UT_READ
#define USB_TYPE_VENDOR			UT_VENDOR
#define USB_RECIP_DEVICE		UT_DEVICE
#define USB_RECIP_INTERFACE		UT_INTERFACE
#define USB_RECIP_ENDPOINT		UT_ENDPOINT
#define USB_RECIP_OTHER			UT_OTHER

#define	HZ	1000	/* dummy */

/* dummy */
#define usb_sndctrlpipe(a,b)		(b)
#define usb_rcvctrlpipe(a,b)		(b)

typedef	u_int8_t	u8;
typedef	u_int16_t	u16;
typedef u_int32_t	u32;
typedef	u_int8_t	__u8;
typedef	u_int16_t	__u16;
typedef int32_t		__s32;
typedef u_int32_t	__u32;

#define printk(fmt,args...) fprintf(stderr,fmt,##args)
#define kmalloc(siz,opt)	malloc(siz)
#define kfree(pt)		free(pt)

/* fake $kernel_source_top/include/linux/???.h */
/* I referenced 2.4.?? */
#define LINUX_VERSION_CODE 0x020400
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

struct devinfo{
	uint8_t		class;
	uint8_t		subclass;
	uint8_t		protocol;
	uint8_t		bNumConfigurations;
	uint16_t	idVendor;
	uint16_t	idProduct;
	uint16_t	bcdDevice;
};

struct usb_device {
    int fd;
    int efd;
    char epdevname[FILENAME_MAX];    
    struct devinfo descriptor;
    struct usb_config_desc configdesc;
    struct usb_config_desc *actconfig;
    struct usb_interface_desc interfacedesc;
    struct usb_endpoint_desc endpointdesc;
};

/* fake $kernel_source_top/include/linux/a.out.h */
/* original size = 0x400  too small!? */
#define PAGE_SIZE 0x800

/* fake $kernel_source_top/include/linux/usb.h */
int usb_control_msg(struct usb_device *dev, unsigned int pipe,
		    u_int8_t request, u_int8_t requesttype,
		    u_int16_t value, u_int16_t index, void *data, u_int16_t size, int timeout);

int usb_set_configuration(struct usb_device *dev, int configuration);
int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);

/* from $kernel_source_top/include/linux/kernel.h */
#define	KERN_EMERG	"<0>"	/* system is unusable			*/
#define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
#define	KERN_CRIT	"<2>"	/* critical conditions			*/
#define	KERN_ERR	"<3>"	/* error conditions			*/
#define	KERN_WARNING	"<4>"	/* warning conditions			*/
#define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
#define	KERN_INFO	"<6>"	/* informational			*/
#define	KERN_DEBUG	"<7>"	/* debug-level messages			*/

/* XXX */
#define MODULE_PARM(a,b)
#define MODULE_PARM_DESC(a,b)
#define MODULE_DESCRIPTION(a)
#define MODULE_AUTHOR(a)
#define MODULE_LICENSE(a)
#define MODULE_DEVICE_TABLE(a,b)


#endif /* __LINUX_USBIF__H */
