Home | History | Annotate | Line # | Download | only in iopctl
iopctl.c revision 1.1
      1  1.1  ad /*	$NetBSD: iopctl.c,v 1.1 2000/12/11 13:48:53 ad Exp $	*/
      2  1.1  ad 
      3  1.1  ad /*-
      4  1.1  ad  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.1  ad  * All rights reserved.
      6  1.1  ad  *
      7  1.1  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  ad  * by Andrew Doran.
      9  1.1  ad  *
     10  1.1  ad  * Redistribution and use in source and binary forms, with or without
     11  1.1  ad  * modification, are permitted provided that the following conditions
     12  1.1  ad  * are met:
     13  1.1  ad  * 1. Redistributions of source code must retain the above copyright
     14  1.1  ad  *    notice, this list of conditions and the following disclaimer.
     15  1.1  ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  ad  *    documentation and/or other materials provided with the distribution.
     18  1.1  ad  * 3. All advertising materials mentioning features or use of this software
     19  1.1  ad  *    must display the following acknowledgement:
     20  1.1  ad  *	This product includes software developed by the NetBSD
     21  1.1  ad  *	Foundation, Inc. and its contributors.
     22  1.1  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  ad  *    contributors may be used to endorse or promote products derived
     24  1.1  ad  *    from this software without specific prior written permission.
     25  1.1  ad  *
     26  1.1  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  ad  */
     38  1.1  ad 
     39  1.1  ad #ifndef lint
     40  1.1  ad #include <sys/cdefs.h>
     41  1.1  ad __RCSID("$NetBSD: iopctl.c,v 1.1 2000/12/11 13:48:53 ad Exp $");
     42  1.1  ad #endif /* not lint */
     43  1.1  ad 
     44  1.1  ad #include <sys/param.h>
     45  1.1  ad #include <sys/ioctl.h>
     46  1.1  ad #include <sys/uio.h>
     47  1.1  ad 
     48  1.1  ad #include <err.h>
     49  1.1  ad #include <errno.h>
     50  1.1  ad #include <fcntl.h>
     51  1.1  ad #include <stdio.h>
     52  1.1  ad #include <stdlib.h>
     53  1.1  ad #include <stdarg.h>
     54  1.1  ad #include <string.h>
     55  1.1  ad #include <unistd.h>
     56  1.1  ad #include <util.h>
     57  1.1  ad #include <getopt.h>
     58  1.1  ad 
     59  1.1  ad #include <dev/i2o/i2o.h>
     60  1.1  ad #include <dev/i2o/iopvar.h>
     61  1.1  ad 
     62  1.1  ad const char	*class2str(int);
     63  1.1  ad int	main(int, char *[]);
     64  1.1  ad int	show(const char *, const char *, ...);
     65  1.1  ad void	i2ostrvis(const char *, int, char *, int);
     66  1.1  ad void	usage(void);
     67  1.1  ad 
     68  1.1  ad void	reconfig(char **);
     69  1.1  ad void	showdevid(char **);
     70  1.1  ad void	showddmid(char **);
     71  1.1  ad void	showlct(char **);
     72  1.1  ad void	showstatus(char **);
     73  1.1  ad 
     74  1.1  ad struct {
     75  1.1  ad 	int	class;
     76  1.1  ad 	const char	*caption;
     77  1.1  ad } const i2oclass[] = {
     78  1.1  ad 	{ I2O_CLASS_EXECUTIVE, "executive" },
     79  1.1  ad 	{ I2O_CLASS_DDM, "device driver module" },
     80  1.1  ad 	{ I2O_CLASS_RANDOM_BLOCK_STORAGE, "random block storage" },
     81  1.1  ad 	{ I2O_CLASS_SEQUENTIAL_STORAGE,	"sequential storage" },
     82  1.1  ad 	{ I2O_CLASS_LAN, "LAN port" },
     83  1.1  ad 	{ I2O_CLASS_WAN, "WAN port" },
     84  1.1  ad 	{ I2O_CLASS_FIBRE_CHANNEL_PORT,	"fibrechannel port" },
     85  1.1  ad 	{ I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL, "fibrechannel peripheral" },
     86  1.1  ad  	{ I2O_CLASS_SCSI_PERIPHERAL, "SCSI peripheral" },
     87  1.1  ad 	{ I2O_CLASS_ATE_PORT, "ATE port" },
     88  1.1  ad 	{ I2O_CLASS_ATE_PERIPHERAL, "ATE peripheral" },
     89  1.1  ad 	{ I2O_CLASS_FLOPPY_CONTROLLER, "floppy controller" },
     90  1.1  ad 	{ I2O_CLASS_FLOPPY_DEVICE, "floppy device" },
     91  1.1  ad 	{ I2O_CLASS_BUS_ADAPTER_PORT, "bus adapter port" },
     92  1.1  ad };
     93  1.1  ad 
     94  1.1  ad struct {
     95  1.1  ad 	const char	*label;
     96  1.1  ad 	int	takesargs;
     97  1.1  ad 	void	(*func)(char **);
     98  1.1  ad } const cmdtab[] = {
     99  1.1  ad 	{ "reconfig", 0, reconfig },
    100  1.1  ad 	{ "showddmid", 1, showddmid },
    101  1.1  ad 	{ "showdevid", 1, showdevid },
    102  1.1  ad 	{ "showlct", 0, showlct },
    103  1.1  ad 	{ "showstatus",	0, showstatus },
    104  1.1  ad };
    105  1.1  ad 
    106  1.1  ad int	fd;
    107  1.1  ad char	buf[32768];
    108  1.1  ad struct	i2o_status status;
    109  1.1  ad 
    110  1.1  ad int
    111  1.1  ad main(int argc, char **argv)
    112  1.1  ad {
    113  1.1  ad 	int ch, i;
    114  1.1  ad 	const char *dv;
    115  1.1  ad 	struct iovec iov;
    116  1.1  ad 
    117  1.1  ad 	dv = "/dev/iop0";
    118  1.1  ad 
    119  1.1  ad 	while ((ch = getopt(argc, argv, "f:")) != -1) {
    120  1.1  ad 		switch (ch) {
    121  1.1  ad 		case 'f':
    122  1.1  ad 			dv = optarg;
    123  1.1  ad 			break;
    124  1.1  ad 		default:
    125  1.1  ad 			usage();
    126  1.1  ad 			/* NOTREACHED */
    127  1.1  ad 		}
    128  1.1  ad 	}
    129  1.1  ad 
    130  1.1  ad 	if (argv[optind] == NULL)
    131  1.1  ad 		usage();
    132  1.1  ad 
    133  1.1  ad 	if ((fd = open(dv, O_RDWR)) < 0)
    134  1.1  ad 		err(EXIT_FAILURE, "%s", dv);
    135  1.1  ad 
    136  1.1  ad 	iov.iov_base = &status;
    137  1.1  ad 	iov.iov_len = sizeof(status);
    138  1.1  ad 	if (ioctl(fd, IOPIOCGSTATUS, &iov) < 0)
    139  1.1  ad 		err(EXIT_FAILURE, "IOPIOCGSTATUS");
    140  1.1  ad 
    141  1.1  ad 	for (i = 0; i < sizeof(cmdtab) / sizeof(cmdtab[0]); i++)
    142  1.1  ad 		if (strcmp(argv[optind], cmdtab[i].label) == 0) {
    143  1.1  ad 			if (cmdtab[i].takesargs == 0 &&
    144  1.1  ad 			    argv[optind + 1] != NULL)
    145  1.1  ad 			    	usage();
    146  1.1  ad 			(*cmdtab[i].func)(argv + optind + 1);
    147  1.1  ad 			break;
    148  1.1  ad 		}
    149  1.1  ad 
    150  1.1  ad 	if (i == sizeof(cmdtab) / sizeof(cmdtab[0]))
    151  1.1  ad 		usage();
    152  1.1  ad 
    153  1.1  ad 	close(fd);
    154  1.1  ad 	exit(EXIT_SUCCESS);
    155  1.1  ad 	/* NOTREACHED */
    156  1.1  ad }
    157  1.1  ad 
    158  1.1  ad void
    159  1.1  ad usage(void)
    160  1.1  ad {
    161  1.1  ad 	extern char *__progname;
    162  1.1  ad 
    163  1.1  ad 	(void)fprintf(stderr, "usage: %s [-f dev] <command> [target]\n",
    164  1.1  ad 	    __progname);
    165  1.1  ad 	exit(EXIT_FAILURE);
    166  1.1  ad 	/* NOTREACHED */
    167  1.1  ad }
    168  1.1  ad 
    169  1.1  ad int
    170  1.1  ad show(const char *hdr, const char *fmt, ...)
    171  1.1  ad {
    172  1.1  ad 	int i;
    173  1.1  ad 	va_list va;
    174  1.1  ad 
    175  1.1  ad 	for (i = printf("%s", hdr); i < 25; i++)
    176  1.1  ad 		putchar(' ');
    177  1.1  ad 	va_start(va, fmt);
    178  1.1  ad 	i += vprintf(fmt, va);
    179  1.1  ad 	va_end(va);
    180  1.1  ad 	putchar('\n');
    181  1.1  ad 	return (i);
    182  1.1  ad }
    183  1.1  ad 
    184  1.1  ad const char *
    185  1.1  ad class2str(int class)
    186  1.1  ad {
    187  1.1  ad 	int i;
    188  1.1  ad 
    189  1.1  ad 	for (i = 0; i < sizeof(i2oclass) / sizeof(i2oclass[0]); i++)
    190  1.1  ad 		if (class == i2oclass[i].class)
    191  1.1  ad 			return (i2oclass[i].caption);
    192  1.1  ad 
    193  1.1  ad 	return ("unknown");
    194  1.1  ad }
    195  1.1  ad 
    196  1.1  ad const char *
    197  1.1  ad bustype2str(bustype)
    198  1.1  ad 	int bustype;
    199  1.1  ad {
    200  1.1  ad 	static char buf[32];
    201  1.1  ad #ifdef notyet
    202  1.1  ad 	int i;
    203  1.1  ad #endif
    204  1.1  ad 
    205  1.1  ad 	strcpy(buf, "unknown");
    206  1.1  ad 
    207  1.1  ad #ifdef notyet
    208  1.1  ad 	for (i = 0; i < sizeof(i2obustype) / sizeof(i2obustype[0]); i++)
    209  1.1  ad 		if (bustype == i2obustype[i].bustype) {
    210  1.1  ad 			strcpy(buf, i2obustype[i].caption);
    211  1.1  ad 			break;
    212  1.1  ad 		}
    213  1.1  ad #endif
    214  1.1  ad 	return (strcat(buf, " bus"));
    215  1.1  ad }
    216  1.1  ad 
    217  1.1  ad void
    218  1.1  ad getparam(int tid, int group, void *pbuf, int pbufsize)
    219  1.1  ad {
    220  1.1  ad 	struct ioppt pt;
    221  1.1  ad 	struct i2o_util_params_op mb;
    222  1.1  ad 	struct {
    223  1.1  ad 		struct	i2o_param_op_list_header olh;
    224  1.1  ad 		struct	i2o_param_op_all_template oat;
    225  1.1  ad 	} req;
    226  1.1  ad 
    227  1.1  ad 	mb.msgflags = I2O_MSGFLAGS(i2o_util_params_op);
    228  1.1  ad 	mb.msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_GET);
    229  1.1  ad 	mb.flags = 0;
    230  1.1  ad 
    231  1.1  ad 	req.olh.count = htole16(1);
    232  1.1  ad 	req.olh.reserved = htole16(0);
    233  1.1  ad 	req.oat.operation = htole16(I2O_PARAMS_OP_FIELD_GET);
    234  1.1  ad 	req.oat.fieldcount = htole16(0xffff);
    235  1.1  ad 	req.oat.group = htole16(group);
    236  1.1  ad 
    237  1.1  ad 	printf("%d\n", sizeof(mb));
    238  1.1  ad 
    239  1.1  ad 	pt.pt_msg = &mb;
    240  1.1  ad 	pt.pt_msglen = sizeof(mb);
    241  1.1  ad 	pt.pt_reply = buf;
    242  1.1  ad 	pt.pt_replylen = sizeof(buf);
    243  1.1  ad 	pt.pt_timo = 10000;
    244  1.1  ad 	pt.pt_nbufs = 2;
    245  1.1  ad 
    246  1.1  ad 	pt.pt_bufs[0].ptb_data = &req;
    247  1.1  ad 	pt.pt_bufs[0].ptb_datalen = sizeof(req);
    248  1.1  ad 	pt.pt_bufs[0].ptb_out = 1;
    249  1.1  ad 
    250  1.1  ad 	pt.pt_bufs[1].ptb_data = pbuf;
    251  1.1  ad 	pt.pt_bufs[1].ptb_datalen = pbufsize;
    252  1.1  ad 	pt.pt_bufs[1].ptb_out = 0;
    253  1.1  ad 
    254  1.1  ad 	if (ioctl(fd, IOPIOCPT, &pt) < 0)
    255  1.1  ad 		err(EXIT_FAILURE, "IOPIOCPT");
    256  1.1  ad 
    257  1.1  ad 	if (((struct i2o_reply *)buf)->reqstatus != 0)
    258  1.1  ad 		errx(EXIT_FAILURE, "I2O_UTIL_PARAMS_GET failed (%d)",
    259  1.1  ad 		    ((struct i2o_reply *)buf)->reqstatus);
    260  1.1  ad }
    261  1.1  ad 
    262  1.1  ad void
    263  1.1  ad showlct(char **argv)
    264  1.1  ad {
    265  1.1  ad 	struct iovec iov;
    266  1.1  ad 	struct i2o_lct *lct;
    267  1.1  ad 	struct i2o_lct_entry *ent;
    268  1.1  ad 	u_int32_t classid, usertid;
    269  1.1  ad 	int i, nent;
    270  1.1  ad 	char ident[sizeof(ent->identitytag) * 4 + 1];
    271  1.1  ad 
    272  1.1  ad 	iov.iov_base = buf;
    273  1.1  ad 	iov.iov_len = sizeof(buf);
    274  1.1  ad 
    275  1.1  ad 	if (ioctl(fd, IOPIOCGLCT, &iov) < 0)
    276  1.1  ad 		err(EXIT_FAILURE, "IOPIOCGLCT");
    277  1.1  ad 
    278  1.1  ad 	lct = (struct i2o_lct *)buf;
    279  1.1  ad 	ent = lct->entry;
    280  1.1  ad 	nent = ((le16toh(lct->tablesize) << 2) -
    281  1.1  ad 	    sizeof(struct i2o_lct) + sizeof(struct i2o_lct_entry)) /
    282  1.1  ad 	    sizeof(struct i2o_lct_entry);
    283  1.1  ad 
    284  1.1  ad 	for (i = 0; i < nent; i++, ent++) {
    285  1.1  ad 		classid = le32toh(ent->classid);
    286  1.1  ad 		usertid = le32toh(ent->usertid);
    287  1.1  ad 
    288  1.1  ad 		show("lct entry", "%d", i);
    289  1.1  ad 		show("entry size", "%d bytes", le16toh(ent->entrysize) << 2);
    290  1.1  ad 		show("local tid", "%d", le16toh(ent->localtid) & 4095);
    291  1.1  ad 		show("change indicator", "%d", le32toh(ent->changeindicator));
    292  1.1  ad 		show("flags", "%x", le32toh(ent->deviceflags));
    293  1.1  ad 		show("class id", "%x (%s)", classid & 4095,
    294  1.1  ad 		    class2str(classid & 4095));
    295  1.1  ad 		show("version", "%x", (classid >> 12) & 15);
    296  1.1  ad 		show("organisation id", "%x", classid >> 16);
    297  1.1  ad 		show("subclass info", "%x", le32toh(ent->subclassinfo));
    298  1.1  ad 		show("user tid", "%d", usertid & 4095);
    299  1.1  ad 		show("parent tid", "%d", (usertid >> 12) & 4095);
    300  1.1  ad 		show("bios info", "%d", (usertid >> 24) & 255);
    301  1.1  ad 		i2ostrvis(ent->identitytag, sizeof(ent->identitytag), ident,
    302  1.1  ad 		    sizeof(ident));
    303  1.1  ad 		show("identity tag", "<%s>", ident);
    304  1.1  ad 		show("event caps", "%x", le32toh(ent->eventcaps));
    305  1.1  ad 
    306  1.1  ad 		if (i != nent - 1)
    307  1.1  ad 			printf("\n");
    308  1.1  ad 	}
    309  1.1  ad }
    310  1.1  ad 
    311  1.1  ad void
    312  1.1  ad showstatus(char **argv)
    313  1.1  ad {
    314  1.1  ad 	char ident[sizeof(status.productid) + 1];
    315  1.1  ad 	u_int32_t segnumber;
    316  1.1  ad 
    317  1.1  ad 	i2ostrvis(status.productid, sizeof(status.productid),
    318  1.1  ad 	    ident, sizeof(ident));
    319  1.1  ad 
    320  1.1  ad 	segnumber = le32toh(status.segnumber);
    321  1.1  ad 	show("organization id", "%d", le16toh(status.orgid));
    322  1.1  ad 	show("iop id", "%d", le32toh(status.iopid) & 4095);
    323  1.1  ad 	show("host unit id", "%d", (le32toh(status.iopid) >> 16));
    324  1.1  ad 	show("segment number", "%d", segnumber & 4095);
    325  1.1  ad 	show("i2o version", "%d", (segnumber >> 12) & 15);
    326  1.1  ad 	show("iop state", "%d", (segnumber >> 16) & 255);
    327  1.1  ad 	show("messenger type", "%d", segnumber >> 24);
    328  1.1  ad 	show("inbound frame sz", "%d", le32toh(status.inboundmframesize));
    329  1.1  ad 	show("init code", "%d", status.initcode);
    330  1.1  ad 	show("max inbound queue depth", "%d",
    331  1.1  ad 	    le32toh(status.maxinboundmframes));
    332  1.1  ad 	show("inbound queue depth", "%d",
    333  1.1  ad 	    le32toh(status.currentinboundmframes));
    334  1.1  ad 	show("max outbound queue depth", "%d",
    335  1.1  ad 	    le32toh(status.maxoutboundmframes));
    336  1.1  ad 	show("product id string", "<%s>", ident);
    337  1.1  ad 	show("expected lct size", "%d", le32toh(status.expectedlctsize));
    338  1.1  ad 	show("iop capabilities", "0x%08x", le32toh(status.iopcaps));
    339  1.1  ad 	show("desired priv mem sz", "0x%08x",
    340  1.1  ad 	    le32toh(status.desiredprivmemsize));
    341  1.1  ad 	show("current priv mem sz", "0x%08x",
    342  1.1  ad 	    le32toh(status.currentprivmemsize));
    343  1.1  ad 	show("current priv mem base", "0x%08x",
    344  1.1  ad 	    le32toh(status.currentprivmembase));
    345  1.1  ad 	show("desired priv io sz", "0x%08x",
    346  1.1  ad 	    le32toh(status.desiredpriviosize));
    347  1.1  ad 	show("current priv io sz", "0x%08x",
    348  1.1  ad 	    le32toh(status.currentpriviosize));
    349  1.1  ad 	show("current priv io base", "0x%08x",
    350  1.1  ad 	    le32toh(status.currentpriviobase));
    351  1.1  ad }
    352  1.1  ad 
    353  1.1  ad void
    354  1.1  ad showddmid(char **argv)
    355  1.1  ad {
    356  1.1  ad 	struct {
    357  1.1  ad 		struct	i2o_param_op_results pr;
    358  1.1  ad 		struct	i2o_param_read_results prr;
    359  1.1  ad 		struct	i2o_param_ddm_identity di;
    360  1.1  ad 	} __attribute__ ((__packed__)) p;
    361  1.1  ad 	char ident[128];
    362  1.1  ad 
    363  1.1  ad 	getparam(atoi(argv[0]), I2O_PARAM_DDM_IDENTITY, &p, sizeof(p));
    364  1.1  ad 
    365  1.1  ad 	show("ddm tid", "%d", le16toh(p.di.ddmtid) & 4095);
    366  1.1  ad 	i2ostrvis(p.di.name, sizeof(p.di.name), ident, sizeof(ident));
    367  1.1  ad 	show("module name", "%s", ident);
    368  1.1  ad 	i2ostrvis(p.di.revlevel, sizeof(p.di.revlevel), ident, sizeof(ident));
    369  1.1  ad 	show("module revision", "%s", ident);
    370  1.1  ad 	show("serial # format", "%d", p.di.snformat);
    371  1.1  ad 	show("serial #", "%08x%08x%08x", *(u_int32_t *)&p.di.serialnumber[0],
    372  1.1  ad 	    *(u_int32_t *)&p.di.serialnumber[4],
    373  1.1  ad 	    *(u_int32_t *)&p.di.serialnumber[8]);
    374  1.1  ad }
    375  1.1  ad 
    376  1.1  ad void
    377  1.1  ad showdevid(char **argv)
    378  1.1  ad {
    379  1.1  ad 	struct {
    380  1.1  ad 		struct	i2o_param_op_results pr;
    381  1.1  ad 		struct	i2o_param_read_results prr;
    382  1.1  ad 		struct	i2o_param_device_identity di;
    383  1.1  ad 	} __attribute__ ((__packed__)) p;
    384  1.1  ad 	char ident[128];
    385  1.1  ad 
    386  1.1  ad 	getparam(atoi(argv[0]), I2O_PARAM_DEVICE_IDENTITY, &p, sizeof(p));
    387  1.1  ad 
    388  1.1  ad 	show("class id", "%d (%s)", le32toh(p.di.classid) & 4095,
    389  1.1  ad 	    class2str(le32toh(p.di.classid) & 4095));
    390  1.1  ad 	show("owner tid", "%d", le32toh(p.di.ownertid) & 4095);
    391  1.1  ad 	show("parent tid", "%d", le32toh(p.di.parenttid) & 4095);
    392  1.1  ad 
    393  1.1  ad 	i2ostrvis(p.di.vendorinfo, sizeof(p.di.vendorinfo), ident,
    394  1.1  ad 	    sizeof(ident));
    395  1.1  ad 	show("vendor", "<%s>", ident);
    396  1.1  ad 
    397  1.1  ad 	i2ostrvis(p.di.productinfo, sizeof(p.di.productinfo), ident,
    398  1.1  ad 	    sizeof(ident));
    399  1.1  ad 	show("product", "<%s>", ident);
    400  1.1  ad 
    401  1.1  ad 	i2ostrvis(p.di.description, sizeof(p.di.description), ident,
    402  1.1  ad 	    sizeof(ident));
    403  1.1  ad 	show("description", "<%s>", ident);
    404  1.1  ad 
    405  1.1  ad 	i2ostrvis(p.di.revlevel, sizeof(p.di.revlevel), ident, sizeof(ident));
    406  1.1  ad 	show("revision level", "<%s>", ident);
    407  1.1  ad }
    408  1.1  ad 
    409  1.1  ad void
    410  1.1  ad reconfig(char **argv)
    411  1.1  ad {
    412  1.1  ad 
    413  1.1  ad 	if (ioctl(fd, IOPIOCRECONFIG))
    414  1.1  ad 		err(EXIT_FAILURE, "IOPIOCRECONFIG");
    415  1.1  ad }
    416  1.1  ad 
    417  1.1  ad void
    418  1.1  ad i2ostrvis(const char *src, int slen, char *dst, int dlen)
    419  1.1  ad {
    420  1.1  ad 	int hc, lc, i, nit;
    421  1.1  ad 
    422  1.1  ad 	dlen--;
    423  1.1  ad 	lc = 0;
    424  1.1  ad 	hc = 0;
    425  1.1  ad 	i = 0;
    426  1.1  ad 
    427  1.1  ad 	/*
    428  1.1  ad 	 * DPT use NUL as a space, whereas AMI use it as a terminator.  The
    429  1.1  ad 	 * spec has nothing to say about it.  Since AMI fields are usually
    430  1.1  ad 	 * filled with junk after the terminator, ...
    431  1.1  ad 	 */
    432  1.1  ad 	nit = (le16toh(status.orgid) != I2O_ORG_DPT);
    433  1.1  ad 
    434  1.1  ad 	while (slen-- != 0 && dlen-- != 0) {
    435  1.1  ad 		if (nit && *src == '\0')
    436  1.1  ad 			break;
    437  1.1  ad 		else if (*src <= 0x20 || *src >= 0x7f) {
    438  1.1  ad 			if (hc)
    439  1.1  ad 				dst[i++] = ' ';
    440  1.1  ad 		} else {
    441  1.1  ad 			hc = 1;
    442  1.1  ad 			dst[i++] = *src;
    443  1.1  ad 			lc = i;
    444  1.1  ad 		}
    445  1.1  ad 		src++;
    446  1.1  ad 	}
    447  1.1  ad 
    448  1.1  ad 	dst[lc] = '\0';
    449  1.1  ad }
    450