Date: Fri, 2 Aug 1996 18:40:43 -0600 (MDT) From: Nate Williams <nate@mt.sri.com> To: mobile@freebsd.org Cc: hosokawa@mt.cs.keio.ac.jp Subject: Pccardd partial diffs Message-ID: <199608030040.SAA13976@rocky.mt.sri.com> In-Reply-To: <199608011928.NAA08134@rocky.mt.sri.com> References: <199608011928.NAA08134@rocky.mt.sri.com>
next in thread | previous in thread | raw e-mail | index | archive | help
OK, I spent some time merging in all of the changes I've made recently to the pccardd stuff, so what follows is *most* of the functional changes that are between the Nomad's PAO release and the FreeBSD release. I've merged in recent changes I and others have made in the FreeBSD sources, so this 'diff' and accompanying files are against -current as of 8/2/96. However, I've not yet merged the file 'cardd.c', which is quite large and a bit more complex. Some of the merge may be slightly incomplete, but I'd like folks to test them. Also, some of the changes I've made in these diffs to help out the Nomad SYSINSTALL changes are going to go into the FreeBSD sources, so I'll send out a new 'cdif' shar file again when I make those changes, since I suspect it won't be totally straightforward. You should be able to take the *STOCK* FreeBSD sources and apply the sharfile for pccardc (which includes diffs and new files supplied by the Nomads) and the shar file I'm appending below which contains similar files + the Nomad version of pccardd/cardd.c, and with minor tweaking get 'fully Nomad compliant' user-land code. As before, the work I'm doing does not mean that I've tested the changes, nor that I in any way agree that they are bug free, but it's an attempt to synchronize the Nomad and FreeBSD source trees, as I believe we can better minimze the 'SYSINSTALL' changes to one file, which would be acceptable to me where the current scheme of '#ifdef SYSINSTALL' all over the place is not. I'm not going to work on this stuff over the weekend, so if anyone feels like it feel free to convert 'pccard/cardd.c'. There is *ONE* change that will cause the PAO version of cardd.c to break, and that is the function 'readfile()' returns "void" in the FreeBSD sources, and "int" in the Nomad sources. I believe cardd.c calls readfile and expects and arguement back from it in sysinstall mode, but it should be an easy change. Finally, these changes aren't really applicable to a non-PAO release due to kernel changes they've made. So, if you've got a non-PAO system, stick with -current until I start merging in the 'tested' changes into the FreeBSD-current tree. Nate ps. Is this stuff helpful to the rest of the folks, or should I skip posting it to the list and only send it to the Nomads? I'd *really* like to get our source trees 'merged' and I need help from folks who are running the PAO release to help *me* do it by testing this stuff. --------- # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # cdif # pccardd.c # server.c # echo x - cdif sed 's/^X//' >cdif << 'END-of-cdif' XIndex: Makefile X=================================================================== XRCS file: /home/CVS/src/usr.sbin/pccard/pccardd/Makefile,v Xretrieving revision 1.3 Xdiff -c -r1.3 Makefile X*** Makefile 1996/06/18 22:54:25 1.3 X--- Makefile 1996/08/02 22:06:16 X*************** X*** 1,12 **** X # Makefile for pccardd X X PROG= pccardd X! SRCS= cardd.c file.c util.c readcis.c printcis.c X MAN8= pccardd.8 X MAN5= pccard.conf.5 X DPADD= ${LIBUTIL} X LDADD= -lutil X! CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../pccardc X X .include <bsd.prog.mk> X .PATH: ${.CURDIR}/../pccardc X--- 1,15 ---- X # Makefile for pccardd X X PROG= pccardd X! SRCS= pccardd.c cardd.c file.c util.c readcis.c printcis.c server.c X MAN8= pccardd.8 X MAN5= pccard.conf.5 X DPADD= ${LIBUTIL} X LDADD= -lutil X! CFLAGS= -I${.CURDIR} -I${.CURDIR}/../pccardc -DSERVER X! X! # if you want to AT&T GIS WaveLAN or Digital RoamAbout/DS, uncomment this line. X! #CFLAGS+= -DWAVELAN X X .include <bsd.prog.mk> X .PATH: ${.CURDIR}/../pccardc XIndex: cardd.h X=================================================================== XRCS file: /home/CVS/src/usr.sbin/pccard/pccardd/cardd.h,v Xretrieving revision 1.5 Xdiff -c -r1.5 cardd.h X*** cardd.h 1996/06/18 19:52:29 1.5 X--- cardd.h 1996/08/03 00:17:09 X*************** X*** 27,60 **** X * X * Common include file for PCMCIA daemon X */ X #include <bitstring.h> X X #include <pccard/card.h> X #include <pccard/cis.h> X X #include "readcis.h" X X struct cmd { X struct cmd *next; X char *line; /* Command line */ X int macro; /* Contains macros */ X }; X X struct card_config { X struct card_config *next; X unsigned char index; X struct driver *driver; X int irq; X int flags; X char inuse; X }; X X struct card { X struct card *next; X char *manuf; X char *version; X! int ether; /* For net cards, ether at offset */ X int reset_time; /* Reset time */ X struct card_config *config; /* List of configs */ X struct cmd *insert; /* Insert commands */ X struct cmd *remove; /* Remove commands */ X--- 27,106 ---- X * X * Common include file for PCMCIA daemon X */ X+ X+ /* X+ * Code cleanup, bug-fix and extension X+ * by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp> X+ */ X+ X #include <bitstring.h> X X #include <pccard/card.h> X #include <pccard/cis.h> X+ #ifdef WAVELAN X+ #include <machine/wavelan.h> X+ #endif X X #include "readcis.h" X X+ #ifndef EXTERN X+ #define EXTERN extern X+ #endif X+ X struct cmd { X struct cmd *next; X char *line; /* Command line */ X int macro; /* Contains macros */ X }; X X+ struct card_io { X+ struct card_io *next; X+ int addr; X+ int size; X+ }; X+ X+ struct card_mem { X+ struct card_mem *next; X+ int addr; X+ int cardaddr; X+ int size; X+ }; X+ X struct card_config { X struct card_config *next; X unsigned char index; X struct driver *driver; X+ struct card_io *card_io; X+ struct card_mem *card_mem; X int irq; X int flags; X char inuse; X }; X X+ /* ethernet MAC address check */ X+ struct ether_mac { X+ struct ether_mac *next; X+ u_char addr[3]; X+ }; X+ X+ struct ether { X+ struct ether *next; X+ int type; X+ int attr; X+ struct ether_mac *ether_mac; X+ }; X+ #define ETHTYPE_GENERIC 0 X+ #define ETHTYPE_MEGAHERTZ 1 X+ #define ETHTYPE_WAVELAN 2 X+ X struct card { X struct card *next; X char *manuf; X char *version; X! u_char func_id; X! int deftype; X int reset_time; /* Reset time */ X+ struct ether *ether; /* For net cards, ether at offset */ X struct card_config *config; /* List of configs */ X struct cmd *insert; /* Insert commands */ X struct cmd *remove; /* Remove commands */ X*************** X*** 86,91 **** X--- 132,138 ---- X int flags; /* Flags for block */ X int cardaddr; /* Card address */ X }; X+ X /* X * Slot structure - data held for each slot. X */ X*************** X*** 102,131 **** X struct cis_config *card_config; X char devname[16]; X unsigned char eaddr[6]; /* If any */ X struct allocblk io; /* I/O block spec */ X struct allocblk mem; /* Memory block spec */ X int irq; /* Irq value */ X }; X X! struct slot *slots, *current_slot; X X! struct allocblk *pool_ioblks; /* I/O blocks in the pool */ X! struct allocblk *pool_mem; /* Memory in the pool */ X! int pool_irq[16]; /* IRQ allocations */ X! struct driver *drivers; /* List of drivers */ X! struct card *cards; X! bitstr_t *mem_avail; X! bitstr_t *io_avail; X X! int verbose, do_log; X X char *newstr(); X void die(char *); X void *xmalloc(int); X! void log_1s(char *, char *); X void logerr(char *); X void reset_slot(struct slot *); X void execute(struct cmd *); X void readfile(char *); X int bit_fns(bitstr_t *, int, int); X unsigned long alloc_memory(int); X--- 149,192 ---- X struct cis_config *card_config; X char devname[16]; X unsigned char eaddr[6]; /* If any */ X+ int eaddr_conf; X struct allocblk io; /* I/O block spec */ X struct allocblk mem; /* Memory block spec */ X+ #ifdef WAVELAN X+ struct wavelan_conf wl; X+ int wl_conf; X+ #endif X int irq; /* Irq value */ X+ int use_irqpool; X+ int io_assigned; X }; X X! EXTERN struct slot *slots, *current_slot; X X! EXTERN struct allocblk *pool_ioblks; /* I/O blocks in the pool */ X! EXTERN struct allocblk *pool_mem; /* Memory in the pool */ X! EXTERN int pool_irq[16]; /* IRQ allocations */ X! EXTERN struct driver *drivers; /* List of drivers */ X! EXTERN struct card *cards; X! EXTERN struct card *last_card; X! EXTERN bitstr_t *mem_avail; X! EXTERN bitstr_t *io_avail; X X! EXTERN int verbose; X X char *newstr(); X void die(char *); X void *xmalloc(int); X! void log_setup(void); X! void log_1s(const char *, ...); X void logerr(char *); X void reset_slot(struct slot *); X void execute(struct cmd *); X+ void readslots(void); X+ void slot_change(struct slot *); X+ void set_socket(int); X+ void stat_changed(struct slot *); X+ void process_client(void); X void readfile(char *); X int bit_fns(bitstr_t *, int, int); X unsigned long alloc_memory(int); X*************** X*** 137,139 **** X--- 198,203 ---- X #define MEMBLKS ((MEMEND-MEMSTART)/MEMUNIT) X #define MEM2BIT(x) (((x)-MEMSTART)/MEMUNIT) X #define BIT2MEM(x) (((x)*MEMUNIT)+MEMSTART) X+ X+ #define DT_VERS 0 X+ #define DT_FUNC 1 XIndex: file.c X=================================================================== XRCS file: /home/CVS/src/usr.sbin/pccard/pccardd/file.c,v Xretrieving revision 1.8 Xdiff -c -r1.8 file.c X*** file.c 1996/07/11 15:04:43 1.8 X--- file.c 1996/08/03 00:19:55 X*************** X*** 25,33 **** X--- 25,40 ---- X * X * $Id: file.c,v 1.8 1996/07/11 15:04:43 nate Exp $ X */ X+ X+ /* X+ * Code cleanup, bug-fix and extension X+ * by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp> X+ */ X+ X #include <stdio.h> X #include <stdlib.h> X #include <string.h> X+ #include <ctype.h> X #include <sys/types.h> X #include "cardd.h" X X*************** X*** 50,55 **** X--- 57,65 ---- X "remove", /* 11 */ X "iosize", /* 12 */ X "memsize", /* 13 */ X+ "function", /* 14 */ X+ "cardio", /* 15 */ X+ "cardmem", /* 16 */ X 0 X }; X X*************** X*** 65,76 **** X static void error(char *); X static int keyword(char *); X static int irq_tok(int); X static struct allocblk *ioblk_tok(int); X static struct allocblk *memblk_tok(int); X static struct driver *new_driver(char *); X X! static void addcmd(struct cmd **cp); X! static void parse_card(void); X X /* X * Read a file and parse the pcmcia configuration data. X--- 75,89 ---- X static void error(char *); X static int keyword(char *); X static int irq_tok(int); X+ static int config_tok(void); X+ static int func_tok(void); X+ static int ether_mac_tok(struct ether_mac *); X static struct allocblk *ioblk_tok(int); X static struct allocblk *memblk_tok(int); X static struct driver *new_driver(char *); X X! static void addcmd(struct cmd **); X! static void parse_card(int); X X /* X * Read a file and parse the pcmcia configuration data. X*************** X*** 83,97 **** X X in = fopen(name, "r"); X if (in == 0) { X! perror(name); X! exit(1); X } X parsefile(); X for (cp = cards; cp; cp = cp->next) { X if (cp->config == 0) X! fprintf(stderr, X! "warning: card %s(%s) has no valid configuration\n", X! cp->manuf, cp->version); X } X } X X--- 96,109 ---- X X in = fopen(name, "r"); X if (in == 0) { X! logerr(name); X! die("readfile"); X } X parsefile(); X for (cp = cards; cp; cp = cp->next) { X if (cp->config == 0) X! log_1s("warning: card %s(%s) has no valid configuration\n", X! cp->manuf, cp->version); X } X } X X*************** X*** 144,151 **** X break; X case 5: X /* Card definition. */ X! parse_card(); X break; X default: X error("Syntax error"); X pusht = 0; X--- 156,167 ---- X break; X case 5: X /* Card definition. */ X! parse_card(DT_VERS); X break; X+ case 14: X+ /* Function definition. */ X+ parse_card(DT_FUNC); X+ break; X default: X error("Syntax error"); X pusht = 0; X*************** X*** 157,182 **** X * Parse a card definition. X */ X static void X! parse_card(void) X { X char *man, *vers; X struct card *cp; X int i; X struct card_config *confp, *lastp; X X! man = newstr(next_tok()); X! vers = newstr(next_tok()); X cp = xmalloc(sizeof(*cp)); X! cp->manuf = man; X! cp->version = vers; X! cp->reset_time = 50; X cp->next = cards; X cards = cp; X for (;;) { X switch (keyword(next_tok())) { X case 7: X /* config */ X! i = num_tok(); X if (i == -1) { X error("Illegal card config index"); X break; X--- 173,228 ---- X * Parse a card definition. X */ X static void X! parse_card(int deftype) X { X char *man, *vers; X struct card *cp; X int i; X struct card_config *confp, *lastp; X+ struct ether_mac ether_mac; X+ struct ether *ether; X+ struct card_io *card_io; X+ struct card_mem *card_mem; X X! confp = lastp = 0; X cp = xmalloc(sizeof(*cp)); X! cp->deftype = deftype; X! cp->ether = 0; X! switch (deftype) { X! case DT_VERS: X! man = newstr(next_tok()); X! vers = newstr(next_tok()); X! cp->manuf = man; X! cp->version = vers; X! cp->func_id = 0; X! break; X! case DT_FUNC: X! cp->manuf = ""; X! cp->version = ""; X! cp->func_id = (u_char) func_tok(); X! break; X! default: X! fprintf(stderr, "parse_card: unknown deftype %d\n", deftype); X! exit(1); X! } X! cp->reset_time = 100; X! #if 1 X! cp->next = 0; X! if (!last_card) X! cards = last_card = cp; X! else { X! last_card->next = cp; X! last_card = cp; X! } X! #else X cp->next = cards; X cards = cp; X+ #endif X for (;;) { X switch (keyword(next_tok())) { X case 7: X /* config */ X! i = config_tok(); X if (i == -1) { X error("Illegal card config index"); X break; X*************** X*** 190,196 **** X pusht = 1; X confp->flags = 0; X } X! if (confp->irq < 0 || confp->irq > 15) { X error("Illegal card IRQ value"); X break; X } X--- 236,248 ---- X pusht = 1; X confp->flags = 0; X } X! #if 0 X! if (confp->irq < 0 || confp->irq > 15) X! #else X! /* quick hack: irq == 16 means PIO mode (hosokawa) */ X! if (confp->irq < 0 || confp->irq > 16) X! #endif X! { X error("Illegal card IRQ value"); X break; X } X*************** X*** 222,232 **** X--- 274,316 ---- X break; X case 9: X /* ether */ X+ #ifdef orig X cp->ether = num_tok(); X if (cp->ether == -1) { X error("Illegal ether address offset"); X cp->ether = 0; X } X+ #else X+ ether = xmalloc(sizeof(*ether)); X+ ether->type = ETHTYPE_GENERIC; X+ if (strcmp("megahertz", next_tok()) == 0) X+ ether->type = ETHTYPE_MEGAHERTZ; X+ else { X+ pusht = 1; X+ if (strcmp("wavelan", next_tok()) == 0) X+ ether->type = ETHTYPE_WAVELAN; X+ else X+ pusht = 1; X+ } X+ if (ether->type == ETHTYPE_GENERIC) { X+ ether->attr = num_tok(); X+ if (ether->attr == -1) { X+ error("Illegal ether address offset"); X+ free(ether); X+ break; X+ } X+ } X+ while (ether_mac_tok(ðer_mac) == 0) { X+ struct ether_mac *em = xmalloc(sizeof(*em)); X+ for (i = 0; i < 3; i++) X+ em->addr[i] = ether_mac.addr[i]; X+ em->next = ether->ether_mac; X+ ether->ether_mac = em; X+ } X+ pusht = 1; X+ ether->next = cp->ether; X+ cp->ether = ether; X+ #endif X break; X case 10: X /* insert */ X*************** X*** 236,241 **** X--- 320,367 ---- X /* remove */ X addcmd(&cp->remove); X break; X+ case 15: X+ /* cardio */ X+ card_io = xmalloc(sizeof(*card_io)); X+ card_io->addr = num_tok(); X+ card_io->size = num_tok(); X+ #ifdef DEBUG X+ if (verbose) X+ printf("cardio:addr=%x size=%x\n", X+ card_io->addr, card_io->size); X+ #endif X+ if (!confp) { X+ error("No valid config index for cardio"); X+ free(card_io); X+ break; X+ } X+ #if 0 X+ card_io = confp->card_io; X+ #endif X+ confp->card_io = card_io; X+ break; X+ case 16: X+ /* cardmem */ X+ card_mem = xmalloc(sizeof(*card_mem)); X+ card_mem->addr = num_tok(); X+ card_mem->cardaddr = num_tok(); X+ card_mem->size = num_tok(); X+ #ifdef DEBUG X+ if (verbose) X+ printf("cardmem:addr=%x cardaddr=%x size=%x\n", X+ card_mem->addr, card_mem->cardaddr, X+ card_mem->size); X+ #endif X+ if (!confp) { X+ error("No valid config index for cardio"); X+ free(card_mem); X+ break; X+ } X+ #if 0 X+ card_mem = confp->card_mem; X+ #endif X+ confp->card_mem = card_mem; X+ break; X default: X pusht = 1; X return; X*************** X*** 351,356 **** X--- 477,488 ---- X if (strcmp("?", next_tok()) == 0 && force) X return (0); X pusht = 1; X+ if (strcmp("any", next_tok()) == 0 && force) X+ return (0); X+ pusht = 1; X+ if (strcmp("pio", next_tok()) == 0 && force) X+ return (16); X+ pusht = 1; X i = num_tok(); X if (i > 0 && i < 16) X return (i); X*************** X*** 360,365 **** X--- 492,547 ---- X } X X /* X+ * Config index token X+ */ X+ static int X+ config_tok(void) X+ { X+ if (strcmp("default", next_tok()) == 0) X+ return 0; X+ pusht = 1; X+ return num_tok(); X+ } X+ X+ /* X+ * Function ID token X+ */ X+ static int X+ func_tok(void) X+ { X+ if (strcmp("serial", next_tok()) == 0) X+ return 2; X+ pusht = 1; X+ if (strcmp("fixed_disk", next_tok()) == 0) X+ return 4; X+ pusht = 1; X+ return num_tok(); X+ } X+ X+ /* X+ * Ethernet address token X+ */ X+ static int X+ ether_mac_tok(struct ether_mac *ether_mac) X+ { X+ unsigned char *t; X+ int i, x; X+ static int hex[] = {1, 1, 0, 1, 1, 0, 1, 1}; X+ X+ t = next_tok(); X+ if (strlen(t) != 8) X+ return -1; X+ for (i = 0; i < 8; i++) X+ if (!(hex[i] ? isxdigit(t[i]) : (t[i] == ':'))) X+ return -1; X+ for (i = 0; i < 3; i++) { X+ sscanf(t + i * 3, "%x", &x); X+ ether_mac->addr[i] = x; X+ } X+ return 0; X+ } X+ X+ /* X * search the table for a match. X */ X static int X*************** X*** 398,405 **** X error(char *msg) X { X pusht = 1; X! fprintf(stderr, "%s: %s at line %d, near %s\n", X! filename, msg, lineno, next_tok()); X pusht = 1; X } X X--- 580,587 ---- X error(char *msg) X { X pusht = 1; X! log_1s("%s: %s at line %d, near %s\n", X! filename, msg, lineno, next_tok()); X pusht = 1; X } X XIndex: readcis.c X=================================================================== XRCS file: /home/CVS/src/usr.sbin/pccard/pccardd/readcis.c,v Xretrieving revision 1.6 Xdiff -c -r1.6 readcis.c X*** readcis.c 1996/06/18 21:58:51 1.6 X--- readcis.c 1996/08/02 23:15:11 X*************** X*** 25,35 **** X--- 25,44 ---- X * X * $Id: readcis.c,v 1.6 1996/06/18 21:58:51 nate Exp $ X */ X+ X+ /* X+ * Code cleanup, bug-fix and extension X+ * by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp> X+ */ X+ X #include <stdio.h> X #include <unistd.h> X #include <stdlib.h> X #include <string.h> X #include <sys/ioctl.h> X+ #ifdef SYSINSTALL X+ #include <dialog.h> X+ #endif X X #include <pccard/card.h> X #include <pccard/cis.h> X*************** X*** 42,47 **** X--- 51,57 ---- X static void device_desc(unsigned char *, int, struct dev_mem *); X static void config_map(struct cis *, unsigned char *, int); X static void cis_config(struct cis *, unsigned char *, int); X+ static void cis_func_id(struct cis *, unsigned char *, int); X static struct tuple_list *read_one_tuplelist(int, int, off_t); X static struct tuple_list *read_tuples(int); X static struct tuple *find_tuple_in_list(struct tuple_list *, unsigned char); X*************** X*** 98,104 **** X X for (tl = cp->tlist; tl; tl = tl->next) X for (tp = tl->tuples; tp; tp = tp->next) { X! #if 0 X printf("tuple code = 0x%02x, data is\n", tp->code); X dump(tp->data, tp->length); X #endif X--- 108,114 ---- X X for (tl = cp->tlist; tl; tl = tl->next) X for (tp = tl->tuples; tp; tp = tp->next) { X! #if DEBUG X printf("tuple code = 0x%02x, data is\n", tp->code); X dump(tp->data, tp->length); X #endif X*************** X*** 118,123 **** X--- 128,136 ---- X case CIS_CONFIG: /* 0x1B */ X cis_config(cp, tp->data, tp->length); X break; X+ case CIS_FUNC_ID: /* 0x21 */ X+ cis_func_id(cp, tp->data, tp->length); X+ break; X } X } X return (cp); X*************** X*** 177,182 **** X--- 190,225 ---- X } X X /* X+ * Fills in CIS function ID. X+ */ X+ static void X+ cis_func_id(struct cis *cp, unsigned char *p, int len) X+ { X+ cp->func_id1 = *p++; X+ cp->func_id2 = *p++; X+ } X+ X+ /* X+ * "FUJITSU LAN Card (FMV-J182)" has broken CIS X+ */ X+ static int X+ fmvj182_check(unsigned char *p) X+ { X+ char manuf[BUFSIZ], vers[BUFSIZ]; X+ X+ p++; /* major version */ X+ p++; /* minor version */ X+ strncpy(manuf, p, CIS_MAXSTR - 1); X+ while (*p++); X+ strncpy(vers, p, CIS_MAXSTR - 1); X+ while (*p++); X+ if (!strcmp(manuf, "FUJITSU") && !strcmp(vers, "LAN Card(FMV-J182)")) X+ return 1; X+ else X+ return 0; X+ } X+ X+ /* X * device_desc - decode device descriptor. X */ X static void X*************** X*** 437,443 **** X last_tl->next = tl; X last_tl = tl; X } X! } X } while (tl); X X /* X--- 480,487 ---- X last_tl->next = tl; X last_tl = tl; X } X! } else X! tl = 0; X } while (tl); X X /* X*************** X*** 466,471 **** X--- 510,516 ---- X struct tuple_info *tinfo; X int total = 0; X unsigned char code, length; X+ int fmvj182 = 0; X X /* Check to see if this memory has already been scanned. */ X for (tl = tlist; tl; tl = tl->next) X*************** X*** 491,500 **** X break; X } X total++; X tp->length = length; X #ifdef DEBUG X! fprintf(stderr, "Tuple code = 0x%x, len = %d\n", X! code, length); X #endif X if (length == 0xFF) { X length = tp->length = 0; X--- 536,546 ---- X break; X } X total++; X+ if (fmvj182 && (code == 0x1b) && (length == 25)) X+ length = 31; X tp->length = length; X #ifdef DEBUG X! printf("Tuple code = 0x%x, len = %d\n", code, length); X #endif X if (length == 0xFF) { X length = tp->length = 0; X*************** X*** 514,519 **** X--- 560,568 ---- X * or the length is illegal. X */ X tinfo = get_tuple_info(code); X+ if (code == 0x15) X+ /* Hack for broken CIS of FMV-J182 Ethernet card */ X+ fmvj182 = fmvj182_check(tp->data); X if (tinfo == 0 || (tinfo->length != 255 && tinfo->length != length)) { X printf("code %s ignored\n", tuple_name(code)); X tp->code = CIS_NULL; XIndex: readcis.h X=================================================================== XRCS file: /home/CVS/src/usr.sbin/pccard/pccardd/readcis.h,v Xretrieving revision 1.6 Xdiff -c -r1.6 readcis.h X*** readcis.h 1996/06/18 21:58:55 1.6 X--- readcis.h 1996/08/02 22:18:15 X*************** X*** 119,124 **** X--- 119,125 ---- X unsigned char last_config; X unsigned char ccrs; X unsigned long reg_addr; X+ unsigned char func_id1, func_id2; X struct dev_mem attr_mem; X struct dev_mem common_mem; X struct cis_config *def_config; XIndex: util.c X=================================================================== XRCS file: /home/CVS/src/usr.sbin/pccard/pccardd/util.c,v Xretrieving revision 1.6 Xdiff -c -r1.6 util.c X*** util.c 1996/06/20 21:06:53 1.6 X--- util.c 1996/08/02 23:09:35 X*************** X*** 25,50 **** X * X * $Id: util.c,v 1.6 1996/06/20 21:06:53 nate Exp $ X */ X #include <stdio.h> X #include <stdlib.h> X #include <string.h> X #include <unistd.h> X #include <fcntl.h> X #include <sys/types.h> X #include <sys/ioctl.h> X #include <syslog.h> X #include "cardd.h" X X X void X! log_1s(char *msg, char *arg) X { X if (do_log) X! syslog(LOG_ERR, msg, arg); X else { X! fprintf(stderr, "cardd: "); X! fprintf(stderr, msg, arg); X! fprintf(stderr, "\n"); X } X } X X--- 25,81 ---- X * X * $Id: util.c,v 1.6 1996/06/20 21:06:53 nate Exp $ X */ X+ X+ /* X+ * Code cleanup, bug-fix and extension X+ * by: X+ * Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp> X+ * Nate Williams <nate@FreeBSD.org> X+ */ X+ X #include <stdio.h> X #include <stdlib.h> X #include <string.h> X #include <unistd.h> X #include <fcntl.h> X+ #include <stdarg.h> X #include <sys/types.h> X #include <sys/ioctl.h> X #include <syslog.h> X+ #ifdef SYSINSTALL X+ #include <dialog.h> X+ #endif X #include "cardd.h" X X+ static int do_log = 0; X+ X+ void X+ log_setup(void) X+ { X+ #ifndef SYSINSTALL X+ do_log = 1; X+ openlog("pccardd", LOG_PID, LOG_DAEMON); X+ #endif X+ } X X void X! log_1s(const char *fmt, ...) X { X+ va_list ap; X+ char s[100]; X+ X+ va_start(ap, fmt); X+ vsprintf(s, fmt, ap); X+ X if (do_log) X! syslog(LOG_ERR, s); X else { X! #ifdef SYSINSTALL X! dialog_clear(); X! msgConfirm(s); X! #else X! fprintf(stderr, "cardd: %s\n", s); X! #endif X } X } X X*************** X*** 53,60 **** X { X if (do_log) X syslog(LOG_ERR, "%s: %m", msg); X! else X perror(msg); X } X X /* X--- 84,97 ---- X { X if (do_log) X syslog(LOG_ERR, "%s: %m", msg); X! else { X! #ifdef SYSINSTALL X! dialog_clear(); X! msgConfirm(msg); X! #else X perror(msg); X+ #endif X+ } X } X X /* X*************** X*** 65,72 **** X { X if (do_log) X syslog(LOG_CRIT, "fatal error: %s", msg); X! else X fprintf(stderr, "cardd fatal error: %s\n", msg); X closelog(); X exit(1); X } X--- 102,118 ---- X { X if (do_log) X syslog(LOG_CRIT, "fatal error: %s", msg); X! else { X! #ifdef SYSINSTALL X! char s[100]; X! X! sprintf(s, "cardd fatal error: %s\n", msg); X! dialog_clear(); X! msgConfirm(s); X! #else X fprintf(stderr, "cardd fatal error: %s\n", msg); X+ #endif X+ } X closelog(); X exit(1); X } X*************** X*** 122,131 **** X { X int i; X X! i = bit_fns(mem_avail, MEMBLKS, size / MEMUNIT); X if (i < 0) X return (0); X! bit_nclear(mem_avail, i, size / MEMUNIT); X return (BIT2MEM(i)); X } X X--- 168,177 ---- X { X int i; X X! i = bit_fns(mem_avail, MEMBLKS, size / MEMUNIT + (size % MEMUNIT != 0)); X if (i < 0) X return (0); X! bit_nclear(mem_avail, i, i + size / MEMUNIT + (size % MEMUNIT != 0) - 1); X return (BIT2MEM(i)); X } X X*************** X*** 216,222 **** X continue; X #ifdef DEBUG X fprintf(stderr, "Executing [%s]\n", cmd); X! #endif /* DEBUG */ X system(cmd); X } X } X--- 262,268 ---- X continue; X #ifdef DEBUG X fprintf(stderr, "Executing [%s]\n", cmd); X! #endif X system(cmd); X } X } END-of-cdif echo x - pccardd.c sed 's/^X//' >pccardd.c << 'END-of-pccardd.c' X/* X * Copyright (c) 1995 Andrew McRae. All rights reserved. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. The name of the author may not be used to endorse or promote products X * derived from this software without specific prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. X */ X X/* X * Code cleanup, bug-fix and extension X * by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp> X */ X X#ifndef SYSINSTALL X#define DEBUG 1 X#endif /* SYSINSTALL */ X X/* X * pccardd X */ X#include <stdio.h> X#include <stdlib.h> X#include <unistd.h> X#include <string.h> X#include <fcntl.h> X#include <sys/ioctl.h> X#include <sys/types.h> X#include <sys/stat.h> X#include <sys/time.h> X#include <sys/socket.h> X#include <sys/un.h> X#include <stdarg.h> X#define EXTERN X#include "cardd.h" X Xchar *config_file = "/etc/pccard.conf"; Xchar *stand_config_file = "/stand/etc/pccard.conf"; X X/* X * pathname of UNIX-domain socket X */ Xchar *socket_name = "/tmp/.pccardd"; X Xvoid dump_config_file(void); Xvoid readslots(void); Xvoid slot_change(struct slot *); X X/* X * mainline code for pccardd X */ Xint Xmain(int argc, char *argv[]) X{ X struct slot *sp; X int count, debug = 0; X int verbose = 0; X char *conf = 0; X FILE *fp; X int s, slen; X struct sockaddr_un sun; X extern char *optarg; X extern int optind, optopt; X#define COM_OPTS ":dvf:" X X cards = last_card = 0; X X while ((count = getopt(argc, argv, COM_OPTS)) != -1) { X switch (count) { X case 'd': X setbuf(stdout, 0); X setbuf(stderr, 0); X debug = 1; X break; X case 'v': X verbose = 1; X break; X case 'f': X conf = optarg; X break; X case ':': X die("No config file argument"); X break; X case '?': X die("Illegal option"); X break; X } X } X#ifdef DEBUG X debug = 1; X#endif X io_avail = bit_alloc(IOPORTS); /* Only supports ISA ports */ X X /* Mem allocation done in MEMUNIT units. */ X mem_avail = bit_alloc(MEMBLKS); X if (!conf) { X if ((fp = fopen(config_file, "r"))) { X conf = config_file; X fclose(fp); X } else if ((fp = fopen(stand_config_file, "r"))) { X conf = stand_config_file; X fclose(fp); X } X } X if (!conf) X die("can't open default config file"); X readfile(conf); X if (verbose) X dump_config_file(); X log_setup(); X if (!debug) X if (daemon(0, 0)) X die("fork failed"); X readslots(); X if (slots == 0) X die("No PC-CARD slots"); X log_1s("pccardd started", NULL); X#ifdef SERVER X if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) X die("socket failed"); X bzero(&sun, sizeof(sun)); X sun.sun_family = AF_UNIX; X strcpy(sun.sun_path, socket_name); X slen = SUN_LEN(&sun); X unlink(socket_name); X if (bind(s, (struct sockaddr *) & sun, slen) < 0) X die("bind failed"); X chown(socket_name, 0, 5); /* XXX - root.operator */ X chmod(socket_name, 0660); X set_socket(s); X#endif /* SERVER */ X X for (;;) { X fd_set rmask, emask; X FD_ZERO(&emask); X#ifdef SERVER X FD_ZERO(&rmask); X#endif /* SERVER */ X for (sp = slots; sp; sp = sp->next) X FD_SET(sp->fd, &emask); X#ifdef SERVER X FD_SET(s, &rmask); X count = select(32, &rmask, 0, &emask, 0); X#else /* SERVER */ X count = select(32, 0, 0, &emask, 0); X#endif /* SERVER */ X if (count == -1) { X perror("Select"); X continue; X } X if (count) { X for (sp = slots; sp; sp = sp->next) X if (FD_ISSET(sp->fd, &emask)) X slot_change(sp); X#ifdef SERVER X if (FD_ISSET(s, &rmask)) X process_client(); X#endif /* SERVER */ X } X } X} END-of-pccardd.c echo x - server.c sed 's/^X//' >server.c << 'END-of-server.c' X/* X * pccardd UNIX-domain socket interface X * Copyright (C) 1996 by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp> X */ X#include <stdio.h> X#include <unistd.h> X#include <sys/types.h> X#include <sys/ioctl.h> X#include <sys/socket.h> X#include <sys/un.h> X#include <signal.h> X#include <setjmp.h> X X#include "cardd.h" X Xstatic void Xcardnum(char *buf) X{ X int i = 0; X struct slot *sp; X X for (sp = slots; sp; sp = sp->next) X i++; X if (i > MAXSLOT) X i = MAXSLOT; X sprintf(buf, "%2d", i); X} X Xstatic struct slot * Xfind_slot(int slot) X{ X struct slot *sp; X X /* Search the list until we find the slot or get to the end */ X for (sp = slots; sp && sp->slot != slot; sp = sp->next) X continue; X X return ( sp ); X} X Xstatic void Xcardname(char *buf, int slot) X{ X struct slot *sp; X char *manuf, *vers, *drv, *stat; X X /* Look for the slot */ X if ( (sp = find_slot(slot)) == NULL) X return; X X /* Fill in the information in the buff */ X if (sp->cis) { X X manuf = sp->cis->manuf; X vers = sp->cis->vers; X if (sp->config && sp->config->driver && X sp->config->driver->name) X drv = sp->config->driver->name; X else X drv = ""; X } else X manuf = vers = drv = ""; X X switch (sp->state) { X case empty: X stat = "0"; X break; X case filled: X stat = "1"; X break; X#if 0 X case inactive: X stat = "2"; X break; X#endif X default: X stat = "9"; X } X sprintf(buf, "%d~%s~%s~%s~%s", slot, manuf, vers, drv, stat); X} X Xstatic void Xcardpwr(int slot, int pwon) X{ X struct slot *sp; X X /* Look for the slot */ X if ( (sp = find_slot(slot)) == NULL) X return; X X#if 0 X if (ioctl(sp->fd, PIOCSVIR, &pwon) < 0) X logerr("invaild arguments for cardpwr"); X#endif X} X Xstatic int sock = 0; Xstatic int slen = 0; Xstatic struct sockaddr_un sun; X Xvoid Xset_socket(int s) X{ X sock = s; X} X Xvoid Xstat_changed(struct slot *sp) X{ X int len; X char buf[512]; X X if (!slen) X return; X X cardname(buf, sp->slot); X len = strlen(buf); X if (sendto(sock, buf, len, 0, (struct sockaddr *) & sun, slen) != len) { X logerr("sendto failed"); X slen = 0; X } X} X Xvoid Xprocess_client(void) X{ X char buf[512], obuf[512]; X int len; X int snum; X X if (!sock) X return; X slen = sizeof(sun); X len = recvfrom(sock, buf, sizeof(buf), X 0, (struct sockaddr *)&sun, &slen); X if (len < 0) X logerr("recvfrom failed"); X obuf[0] = '\0'; X switch (buf[0]) { X case 'S': X cardnum(obuf); X break; X case 'N': X sscanf(buf + 1, "%d", &snum); X if (snum >= 0 && snum <= MAXSLOT) X cardname(obuf, snum); X else X logerr("Illegal slot requests for N command"); X break; X case 'P': X sscanf(buf + 1, "%d", &snum); X if (snum >= 0 && snum <= MAXSLOT) { X log_1s("slot %d: spring has come", snum); X cardpwr(snum, 1); X } else X logerr("Illegal slot requests for P command"); X break; X case 'Q': X sscanf(buf + 1, "%d", &snum); X if (snum >= 0 && snum <= MAXSLOT) { X log_1s("slot %d: hybernation", snum); X cardpwr(snum, 0); X } else X logerr("Illegal slot requests for Q command"); X break; X default: X logerr("Unknown control message from socket"); X break; X } X len = strlen(obuf); X if (len) { X if (sendto(sock, obuf, len, 0, (struct sockaddr *)&sun, slen) X != len) { X logerr("sendto failed"); X slen = 0; X } X } else if (sendto(sock, 0, 0, 0, (struct sockaddr *)&sun, slen) X != len) { X logerr("sendto failed"); X slen = 0; X } X} END-of-server.c exit
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608030040.SAA13976>