diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2009-04-19 18:33:54 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2009-04-19 18:33:54 +0000 |
commit | 20e2f4466606d1095baf3b5cbfeefefd06ee6b47 (patch) | |
tree | fe4660a895a88e5c9242bcc4028b03ea0ae91171 | |
parent | 0c4a2dbb18b1d5de0843e0e04ed970771aa6632b (diff) |
Parse and display the part number and the serial number, instead of falsely
printing the part number as the serial number.
-rw-r--r-- | sys/arch/sgi/dev/owserial.c | 57 | ||||
-rw-r--r-- | sys/arch/sgi/dev/owserialvar.h | 8 |
2 files changed, 47 insertions, 18 deletions
diff --git a/sys/arch/sgi/dev/owserial.c b/sys/arch/sgi/dev/owserial.c index 9fc26f9c6f1..333e6073d02 100644 --- a/sys/arch/sgi/dev/owserial.c +++ b/sys/arch/sgi/dev/owserial.c @@ -1,4 +1,4 @@ -/* $OpenBSD: owserial.c,v 1.1 2008/04/07 22:55:57 miod Exp $ */ +/* $OpenBSD: owserial.c,v 1.2 2009/04/19 18:33:53 miod Exp $ */ /* * Copyright (c) 2008 Miodrag Vallat. @@ -176,8 +176,10 @@ void owserial_read_serial(struct owserial_softc *sc) { uint8_t buf[EEPROM_PAGE_SIZE * 2]; - char serial[1 + OWSERIAL_NAME_LEN]; - char descr[1 + OWSERIAL_SERIAL_LEN], *dptr; + char name[1 + OWSERIAL_NAME_LEN]; + char product[1 + OWSERIAL_PRODUCT_LEN]; + char serial[1 + OWSERIAL_SERIAL_LEN]; + char *s, *e; int pg; int i; @@ -196,22 +198,47 @@ owserial_read_serial(struct owserial_softc *sc) if (buf[i] != 0xff) return; - bcopy(buf + 21, serial, 9); - bcopy(buf + EEPROM_PAGE_SIZE + 3, serial + 9, 3); - serial[OWSERIAL_NAME_LEN] = '\0'; - for (i = 0; i < OWSERIAL_NAME_LEN; i++) - if (serial[i] != '-' && (serial[i] < '0' || serial[i] > '9')) + bcopy(buf + 21, product, 9); + bcopy(buf + EEPROM_PAGE_SIZE + 3, product + 9, 3); + product[OWSERIAL_PRODUCT_LEN] = '\0'; + for (i = 0; i < OWSERIAL_PRODUCT_LEN; i++) + if (product[i] != '-' && (product[i] < '0' || product[i] > '9')) return; - bcopy(buf + EEPROM_PAGE_SIZE + 16, descr, OWSERIAL_SERIAL_LEN); - descr[OWSERIAL_SERIAL_LEN] = '\0'; + bcopy(buf + EEPROM_PAGE_SIZE + 16, name, OWSERIAL_NAME_LEN); + name[OWSERIAL_NAME_LEN] = '\0'; + for (i = 0; i < OWSERIAL_NAME_LEN; i++) + if (name[i] < ' ' || name[i] > '~') + return; + + bcopy(buf + 1, serial, OWSERIAL_SERIAL_LEN); + serial[OWSERIAL_SERIAL_LEN] = '\0'; for (i = 0; i < OWSERIAL_SERIAL_LEN; i++) - if (descr[i] < ' ' || descr[i] > '~') + if (serial[i] < ' ' || serial[i] > '~') return; - for (dptr = descr; *dptr == ' '; dptr++); - strlcpy(sc->sc_name, dptr, sizeof sc->sc_name); - strlcpy(sc->sc_serial, serial, sizeof sc->sc_serial); + /* + * Trim leading and trailing spaces from name and serial # + */ - printf("%s: \"%s\" serial %s\n", sc->sc_dev.dv_xname, dptr, serial); + strlcpy(sc->sc_product, product, sizeof sc->sc_product); + + s = name; + while (*s == ' ') + s++; + e = name + OWSERIAL_NAME_LEN - 1; + while (*e == ' ' && e >= s) + *e-- = '\0'; + strlcpy(sc->sc_name, s, sizeof sc->sc_name); + + s = serial; + while (*s == ' ') + s++; + e = serial + OWSERIAL_SERIAL_LEN - 1; + while (*e == ' ' && e >= s) + *e-- = '\0'; + strlcpy(sc->sc_serial, s, sizeof sc->sc_serial); + + printf("%s: \"%s\" p/n %s, serial %s\n", + sc->sc_dev.dv_xname, sc->sc_name, sc->sc_product, sc->sc_serial); } diff --git a/sys/arch/sgi/dev/owserialvar.h b/sys/arch/sgi/dev/owserialvar.h index acdfde41fe6..41002b5c808 100644 --- a/sys/arch/sgi/dev/owserialvar.h +++ b/sys/arch/sgi/dev/owserialvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: owserialvar.h,v 1.1 2008/04/07 22:55:57 miod Exp $ */ +/* $OpenBSD: owserialvar.h,v 1.2 2009/04/19 18:33:53 miod Exp $ */ /* * Copyright (c) 2008 Miodrag Vallat. @@ -22,8 +22,9 @@ * SGI seems to use DS2505 (or compatibles) to store serial numbers. */ -#define OWSERIAL_NAME_LEN 12 -#define OWSERIAL_SERIAL_LEN 14 +#define OWSERIAL_NAME_LEN 14 +#define OWSERIAL_PRODUCT_LEN 12 +#define OWSERIAL_SERIAL_LEN 20 struct owserial_softc { struct device sc_dev; @@ -35,5 +36,6 @@ struct owserial_softc { uint8_t sc_redir[256]; /* redirection table */ char sc_name[1 + OWSERIAL_NAME_LEN]; + char sc_product[1 + OWSERIAL_PRODUCT_LEN]; char sc_serial[1 + OWSERIAL_SERIAL_LEN]; }; |