make parallel port numbers permanent across program restarts
This commit is contained in:
parent
2b78cb9950
commit
0dca330e46
62
usb-driver.c
62
usb-driver.c
@ -48,8 +48,9 @@ static int windrvrfd = -1;
|
|||||||
static int parportfd = -1;
|
static int parportfd = -1;
|
||||||
static unsigned long ppbase = 0;
|
static unsigned long ppbase = 0;
|
||||||
static unsigned long ecpbase = 0;
|
static unsigned long ecpbase = 0;
|
||||||
static struct pports *pplist = NULL;
|
|
||||||
FILE *modulesfp = NULL;
|
FILE *modulesfp = NULL;
|
||||||
|
FILE *baseaddrfp = NULL;
|
||||||
|
int baseaddrnum = 0;
|
||||||
static int modules_read = 0;
|
static int modules_read = 0;
|
||||||
static struct usb_bus *busses = NULL;
|
static struct usb_bus *busses = NULL;
|
||||||
static struct usb_device *usbdevice;
|
static struct usb_device *usbdevice;
|
||||||
@ -354,7 +355,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
switch(request & ~(0xc0000000)) {
|
switch(request & ~(0xc0000000)) {
|
||||||
case VERSION:
|
case VERSION:
|
||||||
version = (struct version_struct*)(wdheader->data);
|
version = (struct version_struct*)(wdheader->data);
|
||||||
strcpy(version->version, "libusb-driver.so $Revision: 1.59 $");
|
strcpy(version->version, "libusb-driver.so $Revision: 1.60 $");
|
||||||
version->versionul = 802;
|
version->versionul = 802;
|
||||||
DPRINTF("VERSION\n");
|
DPRINTF("VERSION\n");
|
||||||
break;
|
break;
|
||||||
@ -385,36 +386,8 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
if (parportfd < 0) {
|
if (parportfd < 0) {
|
||||||
int max = -1;
|
snprintf(ppdev, sizeof(ppdev), "/dev/parport%lu",
|
||||||
struct pports **port = &pplist;
|
(unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
||||||
|
|
||||||
while (*port) {
|
|
||||||
DPRINTF("Looking up parallel port in linked list, entry: %d\n", (*port)->num);
|
|
||||||
if (max < (*port)->num)
|
|
||||||
max = (*port)->num;
|
|
||||||
|
|
||||||
if ((*port)->base == (unsigned long)cr->Card.Item[0].I.IO.dwAddr) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
port = &((*port)->next);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(*port)) { /* not found */
|
|
||||||
(*port) = malloc(sizeof(struct pports));
|
|
||||||
if (!(*port)) {
|
|
||||||
perror("malloc");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
(*port)->base = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
|
|
||||||
(*port)->num = max+1;
|
|
||||||
(*port)->next = NULL;
|
|
||||||
|
|
||||||
DPRINTF("parallel port not in linked list, new entry: %d\n", (*port)->num);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", (*port)->num);
|
|
||||||
DPRINTF("opening %s\n", ppdev);
|
DPRINTF("opening %s\n", ppdev);
|
||||||
parportfd = open(ppdev, O_RDWR|O_EXCL);
|
parportfd = open(ppdev, O_RDWR|O_EXCL);
|
||||||
|
|
||||||
@ -976,13 +949,15 @@ int close(int fd) {
|
|||||||
FILE *fopen(const char *path, const char *mode) {
|
FILE *fopen(const char *path, const char *mode) {
|
||||||
FILE *ret;
|
FILE *ret;
|
||||||
static FILE* (*func) (const char*, const char*) = NULL;
|
static FILE* (*func) (const char*, const char*) = NULL;
|
||||||
|
char buf[256];
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!func)
|
if (!func)
|
||||||
func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen");
|
func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen");
|
||||||
|
|
||||||
ret = (*func) (path, mode);
|
ret = (*func) (path, mode);
|
||||||
|
|
||||||
if (!strcmp (path, "/proc/modules")) {
|
if (!strcmp(path, "/proc/modules")) {
|
||||||
DPRINTF("opening /proc/modules\n");
|
DPRINTF("opening /proc/modules\n");
|
||||||
#ifdef NO_WINDRVR
|
#ifdef NO_WINDRVR
|
||||||
modulesfp = ret;
|
modulesfp = ret;
|
||||||
@ -990,12 +965,24 @@ FILE *fopen(const char *path, const char *mode) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
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);
|
||||||
|
baseaddrfp = ret;
|
||||||
|
baseaddrnum = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *fgets(char *s, int size, FILE *stream) {
|
char *fgets(char *s, int size, FILE *stream) {
|
||||||
static char* (*func) (char*, int, FILE*) = NULL;
|
static char* (*func) (char*, int, FILE*) = NULL;
|
||||||
const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
|
const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
|
||||||
|
char buf[256];
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
|
|
||||||
@ -1008,6 +995,11 @@ char *fgets(char *s, int size, FILE *stream) {
|
|||||||
ret = s;
|
ret = s;
|
||||||
modules_read++;
|
modules_read++;
|
||||||
}
|
}
|
||||||
|
} else if (baseaddrfp == stream) {
|
||||||
|
snprintf(s, sizeof(buf), "%d\t%d\n",
|
||||||
|
(baseaddrnum) * 0x10,
|
||||||
|
((baseaddrnum) * 0x10) + 0x400);
|
||||||
|
ret = s;
|
||||||
} else {
|
} else {
|
||||||
ret = (*func)(s,size,stream);
|
ret = (*func)(s,size,stream);
|
||||||
}
|
}
|
||||||
@ -1025,6 +1017,10 @@ int fclose(FILE *fp) {
|
|||||||
modulesfp = NULL;
|
modulesfp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fp == baseaddrfp) {
|
||||||
|
baseaddrfp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return (*func)(fp);
|
return (*func)(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,12 +33,6 @@
|
|||||||
|
|
||||||
#define WDU_GET_MAX_PACKET_SIZE(x) ((unsigned short) (((x) & 0x7ff) * (1 + (((x) & 0x1800) >> 11))))
|
#define WDU_GET_MAX_PACKET_SIZE(x) ((unsigned short) (((x) & 0x7ff) * (1 + (((x) & 0x1800) >> 11))))
|
||||||
|
|
||||||
struct pports {
|
|
||||||
unsigned long base;
|
|
||||||
int num;
|
|
||||||
struct pports *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* http://www.jungo.com/support/documentation/windriver/811/wdusb_man_mhtml/node78.html#SECTION001734000000000000000 */
|
/* http://www.jungo.com/support/documentation/windriver/811/wdusb_man_mhtml/node78.html#SECTION001734000000000000000 */
|
||||||
|
|
||||||
struct header_struct {
|
struct header_struct {
|
||||||
|
Reference in New Issue
Block a user