pax-pwn/utils/linux/Driver/ttyPos.h

138 lines
3.7 KiB
C
Raw Normal View History

#ifndef _TTY_POS_H_
#define _TTY_POS_H_
#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/kref.h>
#include <linux/uaccess.h>
#include <linux/usb.h>
#include <linux/mutex.h>
#include <linux/time.h>
#include <linux/sched.h>
#ifdef LINUX_VERSION_CODE
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
#include <linux/err.h>
#include <linux/kthread.h>
#endif
#endif
#define USB_VENDOR_ID 0x1234
#define USB_PRODUCT_ID 0x0101
static struct usb_device_id pos_usb_table[] = {
{ USB_DEVICE(USB_VENDOR_ID, USB_PRODUCT_ID) },
{},
};
MODULE_DEVICE_TABLE(usb,pos_usb_table);
//#define POS_TTY_MAJOR 192 /* experimental range */
#define POS_TTY_MINORS 20 /* only have 20 devices */
#define THREAD_INIT 0x00
#define THREAD_STOPPED 0x01
#define THREAD_CREATED 0x82
#define THREAD_CLOSE 0x83
#define THREAD_IS_RUNNING(ThreadState) (ThreadState & 0x80)
#define WRITE_COMMAND 0 /* write to usb device command */
#define READ_COMMAND 1 /* read from to usb device command */
#define STATUS_COMMAND 2 /* get device buffer status command */
#define POOL_SIZE 10241
typedef struct _POOL {
unsigned int ReadPos;
unsigned int WritePos;
unsigned char Buffer[POOL_SIZE];
} __attribute__((packed)) POOL, *PPOOL;
typedef struct {
unsigned char SeqNo;
unsigned char ReqType; /* 0:OUT, 1:IN, 2:STAT, 3:RESET */
unsigned short Len;
unsigned char Data[508];
} __attribute__((packed)) ST_BULK_IO;
typedef struct {
unsigned int TxBufSize;
unsigned int RxBufSize;
unsigned int TxLeft;
unsigned int RxLeft;
} __attribute__((packed)) ST_BIO_STATE;
struct tty_pos {
struct tty_struct *tty;
unsigned char devIndex;
/* for tiocmget and tiocmset functions */
int msr; /* MSR shadow */
int mcr; /* MCR shadow */
struct file *filp;
struct usb_device *udev;
struct usb_interface *interface;
struct urb *urb;
wait_queue_head_t urb_wait;
atomic_t urb_done;
int timeout_jiffies;
atomic_t urb_busy;
wait_queue_head_t write_wait;
atomic_t write_flag;
__u8 bulk_in_epAddr;
__u8 bulk_out_epAddr;
struct kref kref;
struct mutex io_mutex; /* synchronize I/O with disconnect */
volatile u8 ThreadState;
struct completion ThreadExit_completion;
unsigned char SeqCount;
ST_BULK_IO *BioPack; /* for IO access */
ST_BIO_STATE BioDevState;
POOL TxPool;
};
#define to_pos_dev(d) container_of(d, struct tty_pos, kref)
#define INIT_POOL_BUFFER(pool) pool.ReadPos = pool.WritePos = 0
#define IS_POOL_EMPTY(pool) (pool.ReadPos == pool.WritePos)
#define GET_USING_POOL(pool) \
((pool.WritePos + POOL_SIZE - pool.ReadPos) % POOL_SIZE)
#define GET_SPACE_POOL(pool) (POOL_SIZE - 1 - GET_USING_POOL(pool))
#if 0
#define ERR(stuff...)
#define INFO(stuff...)
#else
#define ERR(stuff...) printk(KERN_ERR "ttyPos: " stuff)
#define INFO(stuff...) printk(KERN_INFO "ttyPos: " stuff)
#endif
//--error code define of API call
#define USB_ERR_NOT_OPEN (-3403)//ͨ<><CDA8>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
#define USB_ERR_BUF (-3404)//<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define USB_ERR_NOT_FREE (-3405)//<2F>޿<EFBFBD><DEBF>õĶ˿<C4B6>
#define USB_ERR_NO_CONF (-3411)//<2F>豸δ<E8B1B8><CEB4><EFBFBD><EFBFBD>ö<EFBFBD>ٺ<EFBFBD><D9BA><EFBFBD><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>
#define USB_ERR_DISCONN (-3412)//<2F><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>
#define USB_ERR_MEM_SYSTEM (-3413)//ϵͳ<CFB5>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define USB_ERR_BUSY (-3414)//USBϵͳæµ
#define USB_ERR_RC_SYSTEM (-3415)//ϵͳ<CFB5><CDB3>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
#define USB_ERR_DEV_ABSENT (-3416)//USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>λ
#define USB_ERR_INVALID (-3417)//USBͨѶ״̬<D7B4><CCAC>Ч
#endif