Blame |
Last modification |
View Log
| RSS feed
/************************************************************************\
## ##
## Creation Date: 18 Mar 2007 ##
## Last Update: 18 Mar 2007 ##
## Author: EviLove ##
## ##
\************************************************************************/
#include "usmcpkt.h"
#include <linux/usb.h>
#include <linux/usbdevice_fs.h>
#include <linux/usb/ch9.h>
#include <linux/module.h> // kzalloc (), kfree ()
#include <asm/uaccess.h>
#include <linux/slab.h>
#define BYTE_I(i) (*(((__u8 * )pPacketData)+i))
#define FIRST_BYTE(pPacketData) (*((__u8 * )pPacketData))
#define SECOND_BYTE(pPacketData) (*(((__u8 * )pPacketData)+1))
#define THIRD_BYTE(pPacketData) (*(((__u8 * )pPacketData)+2))
#define FOURTH_BYTE(pPacketData) (*(((__u8 * )pPacketData)+3))
#define FIRST_WORD(pPacketData) (*((__u16 * )pPacketData))
#define SECOND_WORD(pPacketData) (*(((__u16 * )pPacketData)+1))
#define FIRST_WORD_SWAPPED(pPacketData) ((FIRST_BYTE(pPacketData)<<8)|SECOND_BYTE(pPacketData))
#define SECOND_WORD_SWAPPED(pPacketData) ((THIRD_BYTE(pPacketData)<<8)|FOURTH_BYTE(pPacketData))
#define PACK_WORD(w) (HIBYTE(w)|(LOBYTE(w)<<8))
#define REST_DATA(pPacketData) ((void *)(((__u16 * )pPacketData)+2))
char * user_to_kernel ( const char * user_buf, int len )
{
char * kern_buf;
int i;
kern_buf = ( char * ) kzalloc ( ( ssize_t ) len, GFP_KERNEL );
for ( i = 0 ; i < len ; i++ )
get_user ( kern_buf [i], user_buf + i );
return kern_buf;
}
void bsp_GetDescriptor ( int descriptorType,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequestType = USB_DIR_IN |
USB_RECIP_DEVICE |
USB_TYPE_STANDARD;
*bRequest = 0x06;
switch ( descriptorType )
{
case GET_DESCRIPTOR_CONFIGURATION:
*wValue = 0x0200;
*wIndex = 0x0000;
*wLength = 0x0009;
break;
case GET_DESCRIPTOR_DEVICE:
*wValue = 0x0100;
*wIndex = 0x0000;
*wLength = 0x0012;
break;
case GET_DESCRIPTOR_STRING:
*wValue = 0x0300;
*wIndex = 0x0409;
*wLength = 0x0002;
break;
}
}
void bsp_GetStatus ( int statusType,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequest = 0x00;
*wValue = 0x0000;
*wIndex = 0x0000;
*wLength = 0x0002;
switch ( statusType )
{
case GET_STATUS_DEVICE:
*bRequestType = USB_DIR_IN |
USB_RECIP_DEVICE |
USB_TYPE_STANDARD;
break;
case GET_STATUS_ENDPOINT:
*bRequestType = USB_DIR_IN |
USB_RECIP_ENDPOINT |
USB_TYPE_STANDARD;
break;
case GET_STATUS_INTERFACE:
*bRequestType = USB_DIR_IN |
USB_RECIP_INTERFACE |
USB_TYPE_STANDARD;
break;
}
}
void bsp_GetVersion ( __u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequestType = USB_DIR_IN |
USB_RECIP_DEVICE |
USB_TYPE_STANDARD;
*bRequest = 0x06;
*wValue = 0x0304;
*wIndex = 0x0409;
*wLength = 0x0006;
}
void bsp_GetSerial ( __u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequestType = USB_DIR_IN |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0xC9; // Dec: 201
*wValue = 0x0000;
*wIndex = 0x0000;
*wLength = 0x0010; // Dec: 16
}
void bsp_GetEncoderState ( __u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequestType = USB_DIR_IN |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x85; // Dec: 133
*wValue = 0x0000;
*wIndex = 0x0000;
*wLength = 0x0008;
}
void bsp_GetState ( __u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequestType = USB_DIR_IN |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x82; // Dec: 130
*wValue = 0x0000;
*wIndex = 0x0000;
*wLength = 0x000B; // Dec: 11
}
char * bsp_GoTo ( const char * user_buf,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
char * kern_buf;
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x80; // Dec: 128
*wLength = 0x0003;
kern_buf = user_to_kernel ( user_buf, *wLength + 4 );
*wIndex = FIRST_WORD ( kern_buf );
*wValue = SECOND_WORD ( kern_buf );
return kern_buf;
}
char * bsp_SetMode ( const char * user_buf,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
char * kern_buf;
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x81; // Dec: 129
*wLength = 0x0003;
kern_buf = user_to_kernel ( user_buf, *wLength + 4 );
*wValue = FIRST_WORD_SWAPPED ( kern_buf );
*wIndex = SECOND_WORD_SWAPPED ( kern_buf );
return kern_buf;
}
char * bsp_SetParameters ( const char * user_buf,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
char * kern_buf;
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x83; // Dec: 131
*wLength = 0x0035; // Dec: 53
kern_buf = user_to_kernel ( user_buf, *wLength + 4 );
*wValue = FIRST_WORD_SWAPPED ( kern_buf );
*wIndex = SECOND_WORD ( kern_buf );
return kern_buf;
}
char * bsp_Download ( const char * user_buf,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
char * kern_buf;
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0xC8; // Dec: 200
*wLength = 0x003D; // Dec: 61
kern_buf = user_to_kernel ( user_buf, *wLength + 4 );
*wValue = FIRST_WORD_SWAPPED ( kern_buf );
*wIndex = SECOND_WORD_SWAPPED ( kern_buf );
return kern_buf;
}
char * bsp_SetSerial ( const char * user_buf,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
char * kern_buf;
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0xCA; // Dec: 202
*wLength = 0x001C; // Dec: 28
kern_buf = user_to_kernel ( user_buf, *wLength + 4 );
*wValue = FIRST_WORD_SWAPPED ( kern_buf );
*wIndex = SECOND_WORD_SWAPPED ( kern_buf );
return kern_buf;
}
void bsp_SetCurrentPosition ( const char * user_buf,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
char * kern_buf;
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x01;
*wLength = 0x0000;
kern_buf = user_to_kernel ( user_buf, *wLength + 4 );
*wValue = SECOND_WORD ( kern_buf );
*wIndex = FIRST_WORD ( kern_buf );
}
void bsp_StopStepMotor ( __u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x07;
*wLength = 0x0000;
*wValue = 0x0000;
*wIndex = 0x0000;
}
void bsp_EmulateButtons ( const char * user_buf,
__u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
char * kern_buf;
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x0D; // Dec: 13
*wLength = 0x0000;
kern_buf = user_to_kernel ( user_buf, *wLength + 1 );
*wValue = FIRST_BYTE ( kern_buf );
*wIndex = 0x0000;
}
void bsp_SaveParameters ( __u8 * bRequestType,
__u8 * bRequest,
__u16 * wValue,
__u16 * wIndex,
__u16 * wLength )
{
*bRequestType = USB_DIR_OUT |
USB_RECIP_DEVICE |
USB_TYPE_VENDOR;
*bRequest = 0x84; // Dec: 132
*wLength = 0x0000;
*wValue = 0x0000;
*wIndex = 0x0000;
}