]>
cvs.zerfleddert.de Git - usb-driver/blob - usb-driver.c
1 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
6 #define REAL_LIBC RTLD_NEXT
8 #define REAL_LIBC ((void *) -1L)
17 #include <sys/types.h>
24 void hexdump(unsigned char *buf
, int len
);
26 struct header_struct
{
27 unsigned long dwHeader
;
32 struct version_struct
{
33 unsigned long versionul
;
37 struct license_struct
{
38 char cLicense
[128]; // Buffer with license string to put.
39 // If empty string then get current license setting
41 unsigned long dwLicense
; // Returns license settings: LICENSE_DEMO, LICENSE_WD
42 // etc..., or 0 for invalid license.
43 unsigned long dwLicense2
; // Returns additional license settings, if dwLicense
44 // could not hold all the information.
45 // Then dwLicense will return 0.
48 #define WD_IOCTL_HEADER_CODE 0xa410b413UL
50 void parse_wdioctlreq(unsigned char *wdioctl
, unsigned int request
) {
51 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
53 if (wdheader
->dwHeader
!= WD_IOCTL_HEADER_CODE
) {
54 fprintf(stderr
,"!!!ERROR: Header does not match!!!\n");
58 fprintf(stderr
, "Request: ");
61 fprintf(stderr
,"IOCTL_WD_VERSION");
62 //fprintf(stderr," %s(%d)", ((struct version_struct*)(wdheader->data))->version, ((struct version_struct*)(wdheader->data))->versionul);
65 fprintf(stderr
,"IOCTL_WD_LICENSE");
68 fprintf(stderr
,"IOCTL_WD_TRANSFER");
71 fprintf(stderr
,"IOCTL_WDU_TRANSFER");
74 fprintf(stderr
,"IOCTL_WD_EVENT_UNREGISTER");
77 fprintf(stderr
,"IOCTL_WD_INT_DISABLE");
80 fprintf(stderr
,"IOCTL_WD_INT_WAIT");
83 fprintf(stderr
,"IOCTL_WD_CARD_UNREGISTER");
86 fprintf(stderr
,"IOCTL_WDU_GET_DEVICE_DATA");
89 fprintf(stderr
,"IOCTL_WD_INT_ENABLE");
92 fprintf(stderr
,"IOCTL_WD_EVENT_PULL");
95 fprintf(stderr
,"IOCTL_WDU_SET_INTERFACE");
98 fprintf(stderr
,"Unknown(%x)",request
);
101 fprintf(stderr
, ", size: %d\n", wdheader
->dwSize
);
104 void parse_wdioctlans(unsigned char *wdioctl
, unsigned int request
, int result
) {
105 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
107 if (wdheader
->dwHeader
!= WD_IOCTL_HEADER_CODE
) {
108 fprintf(stderr
,"!!!ERROR: Header does not match!!!\n");
112 fprintf(stderr
, "Answer: %d ", result
);
115 fprintf(stderr
,"\"%s\" (%d)", ((struct version_struct
*)(wdheader
->data
))->version
, ((struct version_struct
*)(wdheader
->data
))->versionul
);
118 fprintf(stderr
,"\"%s\" (XX,XX)", ((struct license_struct
*)(wdheader
->data
))->cLicense
);
123 fprintf(stderr
, "\n");
127 typedef int (*open_funcptr_t
) (const char *, int, mode_t
);
129 static windrvrfd
= 0;
130 static void* mmapped
= NULL
;
131 static size_t mmapplen
= 0;
133 int open (const char *pathname
, int flags
, ...)
135 static open_funcptr_t func
= NULL
;
141 func
= (open_funcptr_t
) dlsym (REAL_LIBC
, "open");
143 if (flags
& O_CREAT
) {
144 va_start(args
, flags
);
145 mode
= va_arg(args
, mode_t
);
149 fd
= (*func
) (pathname
, flags
, mode
);
151 if (!strcmp (pathname
, "/dev/windrvr6")) {
152 fprintf(stderr
,"opening windrvr6\n");
159 void diff(unsigned char *buf1
, unsigned char *buf2
, int len
) {
162 for(i
=0; i
<len
; i
++) {
163 if (buf1
[i
] != buf2
[i
]) {
164 fprintf(stderr
,"Diff at %d: %02x(%c)->%02x(%c)\n", i
, buf1
[i
], ((buf1
[i
] >= 31 && buf1
[i
] <= 126)?buf1
[i
]:'.'), buf2
[i
], ((buf2
[i
] >= 31 && buf2
[i
] <= 126)?buf2
[i
]:'.'));
169 void hexdump(unsigned char *buf
, int len
) {
172 for(i
=0; i
<len
; i
++) {
173 fprintf(stderr
,"%02x ", buf
[i
]);
175 fprintf(stderr
,"\n");
179 int ioctl(int fd
, int request
, ...)
181 static int (*func
) (int, int, void *) = NULL
;
184 unsigned char prebuf
[SNIFFLEN
];
188 func
= (int (*) (int, int, void *)) dlsym (REAL_LIBC
, "ioctl");
190 va_start (args
, request
);
191 argp
= va_arg (args
, void *);
194 if (fd
== windrvrfd
) {
195 memcpy(prebuf
, argp
, SNIFFLEN
);
196 parse_wdioctlreq(argp
, request
);
199 ret
= (*func
) (fd
, request
, argp
);
201 if (fd
== windrvrfd
) {
202 parse_wdioctlans(argp
, request
, ret
);
207 void *mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
209 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
213 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap");
215 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
216 fprintf(stderr
,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
223 void *mmap64(void *start
, size_t length
, int prot
, int flags
, int fd
, off64_t offset
)
225 static void* (*func
) (void *, size_t, int, int, int, off64_t
) = NULL
;
229 func
= (void* (*) (void *, size_t, int, int, int, off64_t
)) dlsym (REAL_LIBC
, "mmap64");
231 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
232 fprintf(stderr
,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
239 void *mmap2(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t pgoffset
)
241 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
245 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap2");
247 ret
= (*func
) (start
, length
, prot
, flags
, fd
, pgoffset
);
248 fprintf(stderr
,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, pgoffset
, (unsigned int)ret
);
255 void *malloc(size_t size
)
257 static void* (*func
) (size_t) = NULL
;
261 func
= (void* (*) (size_t)) dlsym(REAL_LIBC
, "malloc");
263 ret
= (*func
) (size
);
265 //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret);