⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb-driver.c

📁 Xilinx USB下载线 Linux驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
			}			break;		case INT_WAIT:			DPRINTF("INT_WAIT\n");			{				struct interrupt *it = (struct interrupt*)(wdheader->data);				DPRINTF("-> Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",				it->hInterrupt, it->dwOptions,				it->dwCmds, it->fEnableOk, it->dwCounter,				it->dwLost, it->fStopped);#ifndef NO_WINDRVR				ret = (*ioctl_func) (fd, request, wdioctl);#else				ret = xpcu_int_wait(it);#endif				DPRINTF("<- INT_WAIT_RETURN: Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",				it->hInterrupt, it->dwOptions, it->dwCmds,				it->fEnableOk, it->dwCounter, it->dwLost,				it->fStopped);			}			break;		case CARD_UNREGISTER:			DPRINTF("CARD_UNREGISTER\n");			{				struct card_register* cr = (struct card_register*)(wdheader->data);				DPRINTF("-> Addr: 0x%lx, bytes: %lu, bar: %lu\n",				(unsigned long)cr->Card.Item[0].I.IO.dwAddr,				cr->Card.Item[0].I.IO.dwBytes,				cr->Card.Item[0].I.IO.dwBar);				DPRINTF("-> hCard: %lu\n", cr->hCard);#ifndef NO_WINDRVR				ret = (*ioctl_func) (fd, request, wdioctl);#else				if (pport)					pport->close(cr->hCard);				pport = NULL;#endif			}			break;		case EVENT_PULL:			DPRINTF("EVENT_PULL\n");			{				struct event *e = (struct event*)(wdheader->data);#ifdef DEBUG				int i;				DPRINTF("-> handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",				e->handle, e->dwAction, e->dwStatus,				e->dwEventId, e->dwCardType, e->hKernelPlugIn,				e->dwOptions, e->u.Usb.deviceId.dwVendorId,				e->u.Usb.deviceId.dwProductId,				e->u.Usb.dwUniqueID, e->dwEventVer,				e->dwNumMatchTables);				for (i = 0; i < e->dwNumMatchTables; i++)					DPRINTF("-> match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",					e->matchTables[i].VendorId,					e->matchTables[i].ProductId,					e->matchTables[i].bDeviceClass,					e->matchTables[i].bDeviceSubClass,					e->matchTables[i].bInterfaceClass,					e->matchTables[i].bInterfaceSubClass,					e->matchTables[i].bInterfaceProtocol);#endif#ifndef NO_WINDRVR				ret = (*ioctl_func) (fd, request, wdioctl);#else				ret = xpcu_found(e);#endif#ifdef DEBUG				DPRINTF("<- handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",				e->handle, e->dwAction, e->dwStatus,				e->dwEventId, e->dwCardType, e->hKernelPlugIn,				e->dwOptions, e->u.Usb.deviceId.dwVendorId,				e->u.Usb.deviceId.dwProductId,				e->u.Usb.dwUniqueID, e->dwEventVer,				e->dwNumMatchTables);				for (i = 0; i < e->dwNumMatchTables; i++)					DPRINTF("<- match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",					e->matchTables[i].VendorId,					e->matchTables[i].ProductId,					e->matchTables[i].bDeviceClass,					e->matchTables[i].bDeviceSubClass,					e->matchTables[i].bInterfaceClass,					e->matchTables[i].bInterfaceSubClass,					e->matchTables[i].bInterfaceProtocol);#endif			}			break;		default:			fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request);#ifndef NO_WINDRVR			ret = (*ioctl_func) (fd, request, wdioctl);#endif			break;	}	return ret;}int ioctl(int fd, unsigned long int request, ...) {	va_list args;	void *argp;	int i;	if (!ioctl_func)                                                                    		ioctl_func = (int (*) (int, int, void *)) dlsym (RTLD_NEXT, "ioctl");             	va_start (args, request);	argp = va_arg (args, void *);	va_end (args);	for (i = 0; i < windrvrfds_count; i++) {		if (fd == windrvrfds[i])			return do_wdioctl(fd, request, argp);	}	return (*ioctl_func) (fd, request, argp);}int open (const char *pathname, int flags, ...) {	static int (*func) (const char *, int, mode_t) = NULL;	mode_t mode = 0;	va_list args;	int fd;	if (!func)		func = (int (*) (const char *, int, mode_t)) dlsym (RTLD_NEXT, "open");	if (flags & O_CREAT) {		va_start(args, flags);		mode = va_arg(args, mode_t);		va_end(args);	}	if (!strcmp (pathname, "/dev/windrvr6")) {		DPRINTF("opening windrvr6 (%d)\n", windrvrfds_count);		windrvrfds = realloc(windrvrfds, sizeof(int) * (++windrvrfds_count));		if (!windrvrfds)			return -ENOMEM;#ifdef NO_WINDRVR		windrvrfds[windrvrfds_count-1] = fd = (*func) ("/dev/null", flags, mode);#else		windrvrfds[windrvrfds_count-1] = fd = (*func) (pathname, flags, mode);#endif		return fd;	}	return (*func) (pathname, flags, mode);}int close(int fd) {	static int (*func) (int) = NULL;	int i;	if (!func)		func = (int (*) (int)) dlsym(RTLD_NEXT, "close");		for (i = 0; i < windrvrfds_count; i++) {		if (fd == windrvrfds[i] && windrvrfds[i] >= 0) {			int remaining = windrvrfds_count - (i + 1);			DPRINTF("close windrvr6 (%d)\n", i);			if (remaining)				memmove(&(windrvrfds[i]), &(windrvrfds[i+1]), remaining * sizeof(int));			windrvrfds = realloc(windrvrfds, sizeof(int) * --windrvrfds_count);			if (!windrvrfds_count)				windrvrfds = NULL;			break;		}	}	return (*func) (fd);}FILE *fopen(const char *path, const char *mode) {	FILE *ret;	static FILE* (*func) (const char*, const char*) = NULL;	char buf[256];	int i;	if (!func)		func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen");	for (i = 0; i < 4; i++) {		snprintf(buf, sizeof(buf), "/proc/sys/dev/parport/parport%d/base-addr", i);		if (!strcmp(path, buf)) {			DPRINTF("open base-addr of parport%d\n", i);			if (config_is_real_pport(i)) {				ret = (*func) (path, mode);			} else {				ret = (*func) ("/dev/null", mode);			}			if (ret) {				baseaddrfp = ret;				baseaddrnum = i;			}			return ret;		}	}	ret = (*func) (path, mode);	if (!strcmp(path, "/proc/modules")) {		DPRINTF("opening /proc/modules\n");		if (!ret && errno == ENOENT) {			/* Hmm.. there appears to be no /proc/modules file			 * fake it then */			ret = (*func)("/dev/null", mode);			DPRINTF("No /proc/modules -- faking\n");		}#ifdef NO_WINDRVR		modulesfp = ret;		modules_read = 0;#endif	}	return ret;}char *fgets(char *s, int size, FILE *stream) {        static char* (*func) (char*, int, FILE*) = NULL;	const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};	char buf[256];	char *ret = NULL;	if (!func)		func = (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT, "fgets");		if (modulesfp == stream) {		if (modules_read < sizeof(modules) / sizeof(modules[0])) {			strcpy(s, modules[modules_read]);			ret = s;			modules_read++;		}	} else if (baseaddrfp == stream) {		snprintf(s, sizeof(buf), "%d\t%d\n",			(baseaddrnum) * 0x10,			((baseaddrnum) * 0x10) + 0x400);		ret = s;	} else {		ret = (*func)(s,size,stream);	}	return ret;}int fclose(FILE *fp) {	static int (*func) (FILE*) = NULL;	if (!func)		func = (int (*) (FILE*)) dlsym(RTLD_NEXT, "fclose");	if (fp == modulesfp) {		modulesfp = NULL;	}	if (fp == baseaddrfp) {		baseaddrfp = NULL;	}		return (*func)(fp);}int access(const char *pathname, int mode) {	static int (*func) (const char*, int);	if (!func)		func = (int (*) (const char*, int)) dlsym(RTLD_NEXT, "access");	if (pathname && !strcmp(pathname, "/dev/windrvr6")) {		return 0;	} else {		return (*func)(pathname, mode);	}}#if 0/* USB cable sharing needs to overload semop, TODO! */int semop (int __semid, struct sembuf *__sops, size_t __nsops) {	static int (*func) (int, struct sembuf*, size_t) = NULL;	int i;	if (!func)		func = (int (*) (int, struct sembuf*, size_t)) dlsym(RTLD_NEXT, "semop");		fprintf(stderr,"semop: semid: 0x%X, elements: %d\n", __semid, __nsops);	for (i = 0; i < __nsops; i++) {		fprintf(stderr, " num: %u, op: %d, flg: %d\n", __sops[i].sem_num, __sops[i].sem_op, __sops[i].sem_flg);		if (__sops[i].sem_op < 0) {			fprintf(stderr, "SEMAPHORE LOCK\n");		} else {			fprintf(stderr, "SEMAPHORE UNLOCK\n");		}	}	return (*func)(__semid, __sops, __nsops);}#endif#if __WORDSIZE == 32int uname (struct utsname *__name) {	static int (*func) (struct utsname*);	int ret;	if (!func)		func = (int (*) (struct utsname*)) dlsym(RTLD_NEXT, "uname");		ret = (*func)(__name);	if (ret == 0 && (!strcmp(__name->machine, "x86_64"))) {		strcpy(__name->machine, "i686");	}		return ret;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -