11de7b4b8SPedro F. Giffuni /*-
21de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
31de7b4b8SPedro F. Giffuni *
40738c00eSWarner Losh * Copyright (c) 1995 Andrew McRae. All rights reserved.
50738c00eSWarner Losh *
60738c00eSWarner Losh * Redistribution and use in source and binary forms, with or without
70738c00eSWarner Losh * modification, are permitted provided that the following conditions
80738c00eSWarner Losh * are met:
90738c00eSWarner Losh * 1. Redistributions of source code must retain the above copyright
100738c00eSWarner Losh * notice, this list of conditions and the following disclaimer.
110738c00eSWarner Losh * 2. Redistributions in binary form must reproduce the above copyright
120738c00eSWarner Losh * notice, this list of conditions and the following disclaimer in the
130738c00eSWarner Losh * documentation and/or other materials provided with the distribution.
140738c00eSWarner Losh * 3. The name of the author may not be used to endorse or promote products
150738c00eSWarner Losh * derived from this software without specific prior written permission.
160738c00eSWarner Losh *
170738c00eSWarner Losh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
180738c00eSWarner Losh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
190738c00eSWarner Losh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
200738c00eSWarner Losh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
210738c00eSWarner Losh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
220738c00eSWarner Losh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
230738c00eSWarner Losh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
240738c00eSWarner Losh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
250738c00eSWarner Losh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
260738c00eSWarner Losh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
270738c00eSWarner Losh */
280738c00eSWarner Losh
29*5066eaebSWarner Losh #include <sys/cdefs.h>
300738c00eSWarner Losh /*
310738c00eSWarner Losh * Code cleanup, bug-fix and extension
320738c00eSWarner Losh * by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp>
330738c00eSWarner Losh */
340738c00eSWarner Losh
350738c00eSWarner Losh #include <err.h>
360738c00eSWarner Losh #include <stdio.h>
370738c00eSWarner Losh #include <stdlib.h>
380738c00eSWarner Losh #include <string.h>
390738c00eSWarner Losh #include <unistd.h>
400738c00eSWarner Losh #include <sys/ioctl.h>
410738c00eSWarner Losh
42f7911ae5SWarner Losh #include "cis.h"
430738c00eSWarner Losh #include "readcis.h"
440738c00eSWarner Losh
450738c00eSWarner Losh static void dump_config_map(struct tuple *tp);
460738c00eSWarner Losh static void dump_cis_config(struct tuple *tp);
470738c00eSWarner Losh static void dump_other_cond(u_char *p, int len);
48c1d393d2SWarner Losh static void dump_device_desc(u_char *p, int len, const char *type);
490738c00eSWarner Losh static void dump_info_v1(u_char *p, int len);
500738c00eSWarner Losh static void dump_longlink_mfc(u_char *p, int len);
510738c00eSWarner Losh static void dump_bar(u_char *p, int len);
520738c00eSWarner Losh static void dump_device_geo(u_char *p, int len);
530738c00eSWarner Losh static void dump_func_id(u_char *p);
540738c00eSWarner Losh static void dump_serial_ext(u_char *p, int len);
550738c00eSWarner Losh static void dump_disk_ext(u_char *p, int len);
560738c00eSWarner Losh static void dump_network_ext(u_char *p, int len);
570738c00eSWarner Losh static void dump_info_v2(u_char *p, int len);
580738c00eSWarner Losh static void dump_org(u_char *p, int len);
590738c00eSWarner Losh
600738c00eSWarner Losh void
dumpcis(struct tuple_list * tlist)612d134deaSWarner Losh dumpcis(struct tuple_list *tlist)
620738c00eSWarner Losh {
630738c00eSWarner Losh struct tuple *tp;
640738c00eSWarner Losh struct tuple_list *tl;
650738c00eSWarner Losh int count = 0, sz, ad, i;
660738c00eSWarner Losh u_char *p;
670738c00eSWarner Losh int func = 0;
680738c00eSWarner Losh
692d134deaSWarner Losh for (tl = tlist; tl; tl = tl->next)
700738c00eSWarner Losh for (tp = tl->tuples; tp; tp = tp->next) {
710738c00eSWarner Losh printf("Tuple #%d, code = 0x%x (%s), length = %d\n",
720738c00eSWarner Losh ++count, tp->code, tuple_name(tp->code), tp->length);
730738c00eSWarner Losh p = tp->data;
740738c00eSWarner Losh sz = tp->length;
750738c00eSWarner Losh ad = 0;
760738c00eSWarner Losh while (sz > 0) {
770738c00eSWarner Losh printf(" %03x: ", ad);
780738c00eSWarner Losh for (i = 0; i < ((sz < 16) ? sz : 16); i++)
790738c00eSWarner Losh printf(" %02x", p[i]);
800738c00eSWarner Losh printf("\n");
810738c00eSWarner Losh sz -= 16;
820738c00eSWarner Losh p += 16;
830738c00eSWarner Losh ad += 16;
840738c00eSWarner Losh }
850738c00eSWarner Losh switch (tp->code) {
860738c00eSWarner Losh default:
870738c00eSWarner Losh break;
880738c00eSWarner Losh case CIS_MEM_COMMON: /* 0x01 */
890738c00eSWarner Losh dump_device_desc(tp->data, tp->length, "Common");
900738c00eSWarner Losh break;
910738c00eSWarner Losh case CIS_CONF_MAP_CB: /* 0x04 */
920738c00eSWarner Losh dump_config_map(tp);
930738c00eSWarner Losh break;
940738c00eSWarner Losh case CIS_CONFIG_CB: /* 0x05 */
950738c00eSWarner Losh dump_cis_config(tp);
960738c00eSWarner Losh break;
970738c00eSWarner Losh case CIS_LONGLINK_MFC: /* 0x06 */
980738c00eSWarner Losh dump_longlink_mfc(tp->data, tp->length);
990738c00eSWarner Losh break;
1000738c00eSWarner Losh case CIS_BAR: /* 0x07 */
1010738c00eSWarner Losh dump_bar(tp->data, tp->length);
1020738c00eSWarner Losh break;
1030738c00eSWarner Losh case CIS_CHECKSUM: /* 0x10 */
1040738c00eSWarner Losh printf("\tChecksum from offset %d, length %d, value is 0x%x\n",
1050738c00eSWarner Losh tpl16(tp->data),
1060738c00eSWarner Losh tpl16(tp->data + 2),
1070738c00eSWarner Losh tp->data[4]);
1080738c00eSWarner Losh break;
1090738c00eSWarner Losh case CIS_LONGLINK_A: /* 0x11 */
1100738c00eSWarner Losh printf("\tLong link to attribute memory, address 0x%x\n",
1110738c00eSWarner Losh tpl32(tp->data));
1120738c00eSWarner Losh break;
1130738c00eSWarner Losh case CIS_LONGLINK_C: /* 0x12 */
1140738c00eSWarner Losh printf("\tLong link to common memory, address 0x%x\n",
1150738c00eSWarner Losh tpl32(tp->data));
1160738c00eSWarner Losh break;
1170738c00eSWarner Losh case CIS_INFO_V1: /* 0x15 */
1180738c00eSWarner Losh dump_info_v1(tp->data, tp->length);
1190738c00eSWarner Losh break;
1200738c00eSWarner Losh case CIS_ALTSTR: /* 0x16 */
1210738c00eSWarner Losh break;
1220738c00eSWarner Losh case CIS_MEM_ATTR: /* 0x17 */
1230738c00eSWarner Losh dump_device_desc(tp->data, tp->length, "Attribute");
1240738c00eSWarner Losh break;
1250738c00eSWarner Losh case CIS_JEDEC_C: /* 0x18 */
1260738c00eSWarner Losh case CIS_JEDEC_A: /* 0x19 */
1270738c00eSWarner Losh break;
1280738c00eSWarner Losh case CIS_CONF_MAP: /* 0x1A */
1290738c00eSWarner Losh dump_config_map(tp);
1300738c00eSWarner Losh break;
1310738c00eSWarner Losh case CIS_CONFIG: /* 0x1B */
1320738c00eSWarner Losh dump_cis_config(tp);
1330738c00eSWarner Losh break;
1340738c00eSWarner Losh case CIS_DEVICE_OC: /* 0x1C */
1350738c00eSWarner Losh case CIS_DEVICE_OA: /* 0x1D */
1360738c00eSWarner Losh dump_other_cond(tp->data, tp->length);
1370738c00eSWarner Losh break;
1380738c00eSWarner Losh case CIS_DEVICEGEO: /* 0x1E */
1390738c00eSWarner Losh case CIS_DEVICEGEO_A: /* 0x1F */
1400738c00eSWarner Losh dump_device_geo(tp->data, tp->length);
1410738c00eSWarner Losh break;
1420738c00eSWarner Losh case CIS_MANUF_ID: /* 0x20 */
1430738c00eSWarner Losh printf("\tPCMCIA ID = 0x%x, OEM ID = 0x%x\n",
1440738c00eSWarner Losh tpl16(tp->data),
1450738c00eSWarner Losh tpl16(tp->data + 2));
1460738c00eSWarner Losh break;
1470738c00eSWarner Losh case CIS_FUNC_ID: /* 0x21 */
1480738c00eSWarner Losh func = tp->data[0];
1490738c00eSWarner Losh dump_func_id(tp->data);
1500738c00eSWarner Losh break;
1510738c00eSWarner Losh case CIS_FUNC_EXT: /* 0x22 */
1520738c00eSWarner Losh switch (func) {
1530738c00eSWarner Losh case 2:
1540738c00eSWarner Losh dump_serial_ext(tp->data, tp->length);
1550738c00eSWarner Losh break;
1560738c00eSWarner Losh case 4:
1570738c00eSWarner Losh dump_disk_ext(tp->data, tp->length);
1580738c00eSWarner Losh break;
1590738c00eSWarner Losh case 6:
1600738c00eSWarner Losh dump_network_ext(tp->data, tp->length);
1610738c00eSWarner Losh break;
1620738c00eSWarner Losh }
1630738c00eSWarner Losh break;
1640738c00eSWarner Losh case CIS_VERS_2: /* 0x40 */
1650738c00eSWarner Losh dump_info_v2(tp->data, tp->length);
1660738c00eSWarner Losh break;
1670738c00eSWarner Losh case CIS_ORG: /* 0x46 */
1680738c00eSWarner Losh dump_org(tp->data, tp->length);
1690738c00eSWarner Losh break;
1700738c00eSWarner Losh }
1710738c00eSWarner Losh }
1720738c00eSWarner Losh }
1730738c00eSWarner Losh
1740738c00eSWarner Losh /*
1750738c00eSWarner Losh * CIS_CONF_MAP : Dump configuration map tuple.
1760738c00eSWarner Losh * CIS_CONF_MAP_CB: Dump configuration map for CardBus
1770738c00eSWarner Losh */
1780738c00eSWarner Losh static void
dump_config_map(struct tuple * tp)1790738c00eSWarner Losh dump_config_map(struct tuple *tp)
1800738c00eSWarner Losh {
1810738c00eSWarner Losh u_char *p = tp->data, x;
182*5066eaebSWarner Losh unsigned int rlen, mlen = 0, i;
1830738c00eSWarner Losh
1840738c00eSWarner Losh rlen = (p[0] & 3) + 1;
1850738c00eSWarner Losh if (tp->code == CIS_CONF_MAP)
1860738c00eSWarner Losh mlen = ((p[0] >> 2) & 3) + 1;
1870738c00eSWarner Losh if (tp->length < rlen + mlen + 2) {
1880738c00eSWarner Losh printf("\tWrong length for configuration map tuple\n");
1890738c00eSWarner Losh return;
1900738c00eSWarner Losh }
1910738c00eSWarner Losh printf("\tReg len = %d, config register addr = 0x%x, last config = 0x%x\n",
1920738c00eSWarner Losh rlen, parse_num(rlen | 0x10, p + 2, &p, 0), p[1]);
1930738c00eSWarner Losh if (mlen) {
1940738c00eSWarner Losh printf("\tRegisters: ");
1950738c00eSWarner Losh for (i = 0; i < mlen; i++, p++) {
1960738c00eSWarner Losh for (x = 0x1; x; x <<= 1)
1970738c00eSWarner Losh printf("%c", x & *p ? 'X' : '-');
1980738c00eSWarner Losh putchar(' ');
1990738c00eSWarner Losh }
2000738c00eSWarner Losh }
2010738c00eSWarner Losh i = tp->length - (rlen + mlen + 2);
2020738c00eSWarner Losh if (i) {
2030738c00eSWarner Losh if (!mlen)
2040738c00eSWarner Losh putchar('\t');
2050738c00eSWarner Losh printf("%d bytes in subtuples", i);
2060738c00eSWarner Losh }
2070738c00eSWarner Losh if (mlen || i)
2080738c00eSWarner Losh putchar('\n');
2090738c00eSWarner Losh }
2100738c00eSWarner Losh
2110738c00eSWarner Losh /*
2120738c00eSWarner Losh * Dump power descriptor.
2130738c00eSWarner Losh * call from dump_cis_config()
2140738c00eSWarner Losh */
2150738c00eSWarner Losh static int
print_pwr_desc(u_char * p)2160738c00eSWarner Losh print_pwr_desc(u_char *p)
2170738c00eSWarner Losh {
2180738c00eSWarner Losh int len = 1, i;
2190738c00eSWarner Losh u_char mask;
220c1d393d2SWarner Losh const char **expp;
221c1d393d2SWarner Losh static const char *pname[] =
2220738c00eSWarner Losh {"Nominal operating supply voltage",
2230738c00eSWarner Losh "Minimum operating supply voltage",
2240738c00eSWarner Losh "Maximum operating supply voltage",
2250738c00eSWarner Losh "Continuous supply current",
2260738c00eSWarner Losh "Max current average over 1 second",
2270738c00eSWarner Losh "Max current average over 10 ms",
2280738c00eSWarner Losh "Power down supply current",
2290738c00eSWarner Losh "Reserved"
2300738c00eSWarner Losh };
231c1d393d2SWarner Losh static const char *vexp[] =
2320738c00eSWarner Losh {"10uV", "100uV", "1mV", "10mV", "100mV", "1V", "10V", "100V"};
233c1d393d2SWarner Losh static const char *cexp[] =
2340738c00eSWarner Losh {"10nA", "1uA", "10uA", "100uA", "1mA", "10mA", "100mA", "1A"};
235c1d393d2SWarner Losh static const char *mant[] =
2360738c00eSWarner Losh {"1", "1.2", "1.3", "1.5", "2", "2.5", "3", "3.5", "4", "4.5",
2370738c00eSWarner Losh "5", "5.5", "6", "7", "8", "9"};
2380738c00eSWarner Losh
2390738c00eSWarner Losh mask = *p++;
2400738c00eSWarner Losh expp = vexp;
2410738c00eSWarner Losh for (i = 0; i < 8; i++)
2420738c00eSWarner Losh if (mask & (1 << i)) {
2430738c00eSWarner Losh len++;
2440738c00eSWarner Losh if (i >= 3)
2450738c00eSWarner Losh expp = cexp;
2460738c00eSWarner Losh printf("\t\t%s: ", pname[i]);
2470738c00eSWarner Losh printf("%s x %s",
2480738c00eSWarner Losh mant[(*p >> 3) & 0xF],
2490738c00eSWarner Losh expp[*p & 7]);
2500738c00eSWarner Losh while (*p & 0x80) {
2510738c00eSWarner Losh len++;
2520738c00eSWarner Losh p++;
2530738c00eSWarner Losh printf(", ext = 0x%x", *p);
2540738c00eSWarner Losh }
2550738c00eSWarner Losh printf("\n");
2560738c00eSWarner Losh p++;
2570738c00eSWarner Losh }
2580738c00eSWarner Losh return (len);
2590738c00eSWarner Losh }
2600738c00eSWarner Losh
2610738c00eSWarner Losh /*
2620738c00eSWarner Losh * print_ext_speed - Print extended speed.
2630738c00eSWarner Losh * call from dump_cis_config(), dump_device_desc()
2640738c00eSWarner Losh */
2650738c00eSWarner Losh static void
print_ext_speed(u_char x,int scale)2660738c00eSWarner Losh print_ext_speed(u_char x, int scale)
2670738c00eSWarner Losh {
268c1d393d2SWarner Losh static const char *mant[] =
2690738c00eSWarner Losh {"Reserved", "1.0", "1.2", "1.3", "1.5", "2.0", "2.5", "3.0",
2700738c00eSWarner Losh "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "7.0", "8.0"};
271c1d393d2SWarner Losh static const char *exp[] =
2720738c00eSWarner Losh {"1 ns", "10 ns", "100 ns", "1 us", "10 us", "100 us",
2730738c00eSWarner Losh "1 ms", "10 ms"};
274c1d393d2SWarner Losh static const char *scale_name[] =
2750738c00eSWarner Losh {"None", "10", "100", "1,000", "10,000", "100,000",
2760738c00eSWarner Losh "1,000,000", "10,000,000"};
2770738c00eSWarner Losh
2780738c00eSWarner Losh printf("Speed = %s x %s", mant[(x >> 3) & 0xF], exp[x & 7]);
2790738c00eSWarner Losh if (scale)
2800738c00eSWarner Losh printf(", scaled by %s", scale_name[scale & 7]);
2810738c00eSWarner Losh }
2820738c00eSWarner Losh
2830738c00eSWarner Losh /*
2840738c00eSWarner Losh * Print variable length value.
2850738c00eSWarner Losh * call from print_io_map(), print_mem_map()
2860738c00eSWarner Losh */
2870738c00eSWarner Losh static int
print_num(int sz,const char * fmt,u_char * p,int ofs)288c1d393d2SWarner Losh print_num(int sz, const char *fmt, u_char *p, int ofs)
2890738c00eSWarner Losh {
2900738c00eSWarner Losh switch (sz) {
2910738c00eSWarner Losh case 0:
2920738c00eSWarner Losh case 0x10:
2930738c00eSWarner Losh return 0;
2940738c00eSWarner Losh case 1:
2950738c00eSWarner Losh case 0x11:
2960738c00eSWarner Losh printf(fmt, *p + ofs);
2970738c00eSWarner Losh return 1;
2980738c00eSWarner Losh case 2:
2990738c00eSWarner Losh case 0x12:
3000738c00eSWarner Losh printf(fmt, tpl16(p) + ofs);
3010738c00eSWarner Losh return 2;
3020738c00eSWarner Losh case 0x13:
3030738c00eSWarner Losh printf(fmt, tpl24(p) + ofs);
3040738c00eSWarner Losh return 3;
3050738c00eSWarner Losh case 3:
3060738c00eSWarner Losh case 0x14:
3070738c00eSWarner Losh printf(fmt, tpl32(p) + ofs);
3080738c00eSWarner Losh return 4;
3090738c00eSWarner Losh }
3100738c00eSWarner Losh errx(1, "print_num(0x%x): Illegal arguments", sz);
3110738c00eSWarner Losh /*NOTREACHED*/
3120738c00eSWarner Losh }
3130738c00eSWarner Losh
3140738c00eSWarner Losh /*
3150738c00eSWarner Losh * Print I/O mapping sub-tuple.
3160738c00eSWarner Losh * call from dump_cis_config()
3170738c00eSWarner Losh */
3180738c00eSWarner Losh static u_char *
print_io_map(u_char * p,u_char * q)3190738c00eSWarner Losh print_io_map(u_char *p, u_char *q)
3200738c00eSWarner Losh {
3210738c00eSWarner Losh int i, j;
3220738c00eSWarner Losh u_char c;
3230738c00eSWarner Losh
3240738c00eSWarner Losh if (q <= p)
3250738c00eSWarner Losh goto err;
3260738c00eSWarner Losh if (CIS_IO_ADDR(*p)) /* I/O address line */
3270738c00eSWarner Losh printf("\tCard decodes %d address lines",
3280738c00eSWarner Losh CIS_IO_ADDR(*p));
3290738c00eSWarner Losh else
3300738c00eSWarner Losh printf("\tCard provides address decode");
3310738c00eSWarner Losh
3320738c00eSWarner Losh /* 8/16 bit I/O */
3330738c00eSWarner Losh switch (*p & (CIS_IO_8BIT | CIS_IO_16BIT)) {
3340738c00eSWarner Losh case CIS_IO_8BIT:
3350738c00eSWarner Losh printf(", 8 Bit I/O only");
3360738c00eSWarner Losh break;
3370738c00eSWarner Losh case CIS_IO_16BIT:
3380738c00eSWarner Losh printf(", limited 8/16 Bit I/O");
3390738c00eSWarner Losh break;
3400738c00eSWarner Losh case (CIS_IO_8BIT | CIS_IO_16BIT):
3410738c00eSWarner Losh printf(", full 8/16 Bit I/O");
3420738c00eSWarner Losh break;
3430738c00eSWarner Losh }
3440738c00eSWarner Losh putchar('\n');
3450738c00eSWarner Losh
3460738c00eSWarner Losh /* I/O block sub-tuple exist */
3470738c00eSWarner Losh if (*p++ & CIS_IO_RANGE) {
3480738c00eSWarner Losh if (q <= p)
3490738c00eSWarner Losh goto err;
3500738c00eSWarner Losh c = *p++;
3510738c00eSWarner Losh /* calculate byte length */
3520738c00eSWarner Losh j = CIS_IO_ADSZ(c) + CIS_IO_BLKSZ(c);
3530738c00eSWarner Losh if (CIS_IO_ADSZ(c) == 3)
3540738c00eSWarner Losh j++;
3550738c00eSWarner Losh if (CIS_IO_BLKSZ(c) == 3)
3560738c00eSWarner Losh j++;
3570738c00eSWarner Losh /* number of I/O block sub-tuples */
3580738c00eSWarner Losh for (i = 0; i <= CIS_IO_BLKS(c); i++) {
3590738c00eSWarner Losh if (q - p < j)
3600738c00eSWarner Losh goto err;
3610738c00eSWarner Losh printf("\t\tI/O address # %d: ", i + 1);
3620738c00eSWarner Losh /* start block address */
3630738c00eSWarner Losh p += print_num(CIS_IO_ADSZ(c),
3640738c00eSWarner Losh "block start = 0x%x", p, 0);
3650738c00eSWarner Losh /* block size */
3660738c00eSWarner Losh p += print_num(CIS_IO_BLKSZ(c),
3670738c00eSWarner Losh " block length = 0x%x", p, 1);
3680738c00eSWarner Losh putchar('\n');
3690738c00eSWarner Losh }
3700738c00eSWarner Losh }
3710738c00eSWarner Losh return p;
3720738c00eSWarner Losh
3730738c00eSWarner Losh err: /* warning */
3740738c00eSWarner Losh printf("\tWrong length for I/O mapping sub-tuple\n");
3750738c00eSWarner Losh return p;
3760738c00eSWarner Losh }
3770738c00eSWarner Losh
3780738c00eSWarner Losh /*
3790738c00eSWarner Losh * Print IRQ sub-tuple.
3800738c00eSWarner Losh * call from dump_cis_config()
3810738c00eSWarner Losh */
3820738c00eSWarner Losh static u_char *
print_irq_map(u_char * p,u_char * q)3830738c00eSWarner Losh print_irq_map(u_char *p, u_char *q)
3840738c00eSWarner Losh {
3850738c00eSWarner Losh int i, j;
3860738c00eSWarner Losh u_char c;
3870738c00eSWarner Losh
3880738c00eSWarner Losh if (q <= p)
3890738c00eSWarner Losh goto err;
3900738c00eSWarner Losh printf("\t\tIRQ modes:");
3910738c00eSWarner Losh c = ' ';
3920738c00eSWarner Losh if (*p & CIS_IRQ_LEVEL) { /* Level triggered interrupts */
3930738c00eSWarner Losh printf(" Level");
3940738c00eSWarner Losh c = ',';
3950738c00eSWarner Losh }
3960738c00eSWarner Losh if (*p & CIS_IRQ_PULSE) { /* Pulse triggered requests */
3970738c00eSWarner Losh printf("%c Pulse", c);
3980738c00eSWarner Losh c = ',';
3990738c00eSWarner Losh }
4000738c00eSWarner Losh if (*p & CIS_IRQ_SHARING) /* Interrupt sharing */
4010738c00eSWarner Losh printf("%c Shared", c);
4020738c00eSWarner Losh putchar('\n');
4030738c00eSWarner Losh
4040738c00eSWarner Losh /* IRQ mask values exist */
4050738c00eSWarner Losh if (*p & CIS_IRQ_MASK) {
4060738c00eSWarner Losh if (q - p < 3)
4070738c00eSWarner Losh goto err;
4080738c00eSWarner Losh i = tpl16(p + 1); /* IRQ mask */
4090738c00eSWarner Losh printf("\t\tIRQs: ");
4100738c00eSWarner Losh if (*p & 1)
4110738c00eSWarner Losh printf(" NMI");
4120738c00eSWarner Losh if (*p & 0x2)
4130738c00eSWarner Losh printf(" IOCK");
4140738c00eSWarner Losh if (*p & 0x4)
4150738c00eSWarner Losh printf(" BERR");
4160738c00eSWarner Losh if (*p & 0x8)
4170738c00eSWarner Losh printf(" VEND");
4180738c00eSWarner Losh for (j = 0; j < 16; j++)
4190738c00eSWarner Losh if (i & (1 << j))
4200738c00eSWarner Losh printf(" %d", j);
4210738c00eSWarner Losh putchar('\n');
4220738c00eSWarner Losh p += 3;
4230738c00eSWarner Losh } else {
4240738c00eSWarner Losh printf("\t\tIRQ level = %d\n", CIS_IRQ_IRQN(*p));
4250738c00eSWarner Losh p++;
4260738c00eSWarner Losh }
4270738c00eSWarner Losh return p;
4280738c00eSWarner Losh
4290738c00eSWarner Losh err: /* warning */
4300738c00eSWarner Losh printf("\tWrong length for IRQ sub-tuple\n");
4310738c00eSWarner Losh return p;
4320738c00eSWarner Losh }
4330738c00eSWarner Losh
4340738c00eSWarner Losh /*
4350738c00eSWarner Losh * Print memory map sub-tuple.
4360738c00eSWarner Losh * call from dump_cis_config()
4370738c00eSWarner Losh */
4380738c00eSWarner Losh static u_char *
print_mem_map(u_char feat,u_char * p,u_char * q)4390738c00eSWarner Losh print_mem_map(u_char feat, u_char *p, u_char *q)
4400738c00eSWarner Losh {
4410738c00eSWarner Losh int i, j;
4420738c00eSWarner Losh u_char c;
4430738c00eSWarner Losh
4440738c00eSWarner Losh switch (CIS_FEAT_MEMORY(feat)) {
4450738c00eSWarner Losh
4460738c00eSWarner Losh case CIS_FEAT_MEM_NONE: /* No memory block */
4470738c00eSWarner Losh break;
4480738c00eSWarner Losh case CIS_FEAT_MEM_LEN: /* Specify memory length */
4490738c00eSWarner Losh if (q - p < 2)
4500738c00eSWarner Losh goto err;
4510738c00eSWarner Losh printf("\tMemory space length = 0x%x\n", tpl16(p));
4520738c00eSWarner Losh p += 2;
4530738c00eSWarner Losh break;
4540738c00eSWarner Losh case CIS_FEAT_MEM_ADDR: /* Memory address and length */
4550738c00eSWarner Losh if (q - p < 4)
4560738c00eSWarner Losh goto err;
4570738c00eSWarner Losh printf("\tMemory space address = 0x%x, length = 0x%x\n",
4580738c00eSWarner Losh tpl16(p + 2), tpl16(p));
4590738c00eSWarner Losh p += 4;
4600738c00eSWarner Losh break;
4610738c00eSWarner Losh case CIS_FEAT_MEM_WIN: /* Memory descriptors. */
4620738c00eSWarner Losh if (q <= p)
4630738c00eSWarner Losh goto err;
4640738c00eSWarner Losh c = *p++;
4650738c00eSWarner Losh /* calculate byte length */
4660738c00eSWarner Losh j = CIS_MEM_LENSZ(c) + CIS_MEM_ADDRSZ(c);
4670738c00eSWarner Losh if (c & CIS_MEM_HOST)
4680738c00eSWarner Losh j += CIS_MEM_ADDRSZ(c);
4690738c00eSWarner Losh /* number of memory block */
4700738c00eSWarner Losh for (i = 0; i < CIS_MEM_WINS(c); i++) {
4710738c00eSWarner Losh if (q - p < j)
4720738c00eSWarner Losh goto err;
4730738c00eSWarner Losh printf("\tMemory descriptor %d\n\t\t", i + 1);
4740738c00eSWarner Losh /* memory length */
4750738c00eSWarner Losh p += print_num(CIS_MEM_LENSZ(c) | 0x10,
4760738c00eSWarner Losh " blk length = 0x%x00", p, 0);
4770738c00eSWarner Losh /* card address */
4780738c00eSWarner Losh p += print_num(CIS_MEM_ADDRSZ(c) | 0x10,
4790738c00eSWarner Losh " card addr = 0x%x00", p, 0);
4800738c00eSWarner Losh if (c & CIS_MEM_HOST) /* Host address value exist */
4810738c00eSWarner Losh p += print_num(CIS_MEM_ADDRSZ(c) | 0x10,
4820738c00eSWarner Losh " host addr = 0x%x00", p, 0);
4830738c00eSWarner Losh putchar('\n');
4840738c00eSWarner Losh }
4850738c00eSWarner Losh break;
4860738c00eSWarner Losh }
4870738c00eSWarner Losh return p;
4880738c00eSWarner Losh
4890738c00eSWarner Losh err: /* warning */
4900738c00eSWarner Losh printf("\tWrong length for memory mapping sub-tuple\n");
4910738c00eSWarner Losh return p;
4920738c00eSWarner Losh }
4930738c00eSWarner Losh
4940738c00eSWarner Losh /*
4950738c00eSWarner Losh * CIS_CONFIG : Dump a config entry.
4960738c00eSWarner Losh * CIS_CONFIG_CB: Dump a configuration entry for CardBus
4970738c00eSWarner Losh */
4980738c00eSWarner Losh static void
dump_cis_config(struct tuple * tp)4990738c00eSWarner Losh dump_cis_config(struct tuple *tp)
5000738c00eSWarner Losh {
5010738c00eSWarner Losh u_char *p, *q, feat;
5020738c00eSWarner Losh int i, j;
5030738c00eSWarner Losh char c;
5040738c00eSWarner Losh
5050738c00eSWarner Losh p = tp->data;
5060738c00eSWarner Losh q = p + tp->length;
5070738c00eSWarner Losh printf("\tConfig index = 0x%x%s\n", *p & 0x3F,
5080738c00eSWarner Losh *p & 0x40 ? "(default)" : "");
5090738c00eSWarner Losh
5100738c00eSWarner Losh /* Interface byte exists */
5110738c00eSWarner Losh if (tp->code == CIS_CONFIG && (*p & 0x80)) {
5120738c00eSWarner Losh p++;
5130738c00eSWarner Losh printf("\tInterface byte = 0x%x ", *p);
5140738c00eSWarner Losh switch (*p & 0xF) { /* Interface type */
5150738c00eSWarner Losh default:
5160738c00eSWarner Losh printf("(reserved)");
5170738c00eSWarner Losh break;
5180738c00eSWarner Losh case 0:
5190738c00eSWarner Losh printf("(memory)");
5200738c00eSWarner Losh break;
5210738c00eSWarner Losh case 1:
5220738c00eSWarner Losh printf("(I/O)");
5230738c00eSWarner Losh break;
5240738c00eSWarner Losh case 4:
5250738c00eSWarner Losh case 5:
5260738c00eSWarner Losh case 6:
5270738c00eSWarner Losh case 7:
5280738c00eSWarner Losh case 8:
5290738c00eSWarner Losh printf("(custom)");
5300738c00eSWarner Losh break;
5310738c00eSWarner Losh }
5320738c00eSWarner Losh c = ' ';
5330738c00eSWarner Losh if (*p & 0x10) { /* Battery voltage detect */
5340738c00eSWarner Losh printf(" BVD1/2 active");
5350738c00eSWarner Losh c = ',';
5360738c00eSWarner Losh }
5370738c00eSWarner Losh if (*p & 0x20) { /* Write protect active */
5380738c00eSWarner Losh printf("%c card WP active", c); /* Write protect */
5390738c00eSWarner Losh c = ',';
5400738c00eSWarner Losh }
5410738c00eSWarner Losh if (*p & 0x40) { /* RdyBsy active bit */
5420738c00eSWarner Losh printf("%c +RDY/-BSY active", c);
5430738c00eSWarner Losh c = ',';
5440738c00eSWarner Losh }
5450738c00eSWarner Losh if (*p & 0x80) /* Wait signal required */
5460738c00eSWarner Losh printf("%c wait signal supported", c);
5470738c00eSWarner Losh printf("\n");
5480738c00eSWarner Losh }
5490738c00eSWarner Losh
5500738c00eSWarner Losh /* features byte */
5510738c00eSWarner Losh p++;
5520738c00eSWarner Losh feat = *p++;
5530738c00eSWarner Losh
5540738c00eSWarner Losh /* Power structure sub-tuple */
5550738c00eSWarner Losh switch (CIS_FEAT_POWER(feat)) { /* Power sub-tuple(s) exists */
5560738c00eSWarner Losh case 0:
5570738c00eSWarner Losh break;
5580738c00eSWarner Losh case 1:
5590738c00eSWarner Losh printf("\tVcc pwr:\n");
5600738c00eSWarner Losh p += print_pwr_desc(p);
5610738c00eSWarner Losh break;
5620738c00eSWarner Losh case 2:
5630738c00eSWarner Losh printf("\tVcc pwr:\n");
5640738c00eSWarner Losh p += print_pwr_desc(p);
5650738c00eSWarner Losh printf("\tVpp pwr:\n");
5660738c00eSWarner Losh p += print_pwr_desc(p);
5670738c00eSWarner Losh break;
5680738c00eSWarner Losh case 3:
5690738c00eSWarner Losh printf("\tVcc pwr:\n");
5700738c00eSWarner Losh p += print_pwr_desc(p);
5710738c00eSWarner Losh printf("\tVpp1 pwr:\n");
5720738c00eSWarner Losh p += print_pwr_desc(p);
5730738c00eSWarner Losh printf("\tVpp2 pwr:\n");
5740738c00eSWarner Losh p += print_pwr_desc(p);
5750738c00eSWarner Losh break;
5760738c00eSWarner Losh }
5770738c00eSWarner Losh
5780738c00eSWarner Losh /* Timing sub-tuple */
5790738c00eSWarner Losh if (tp->code == CIS_CONFIG &&
5800738c00eSWarner Losh (feat & CIS_FEAT_TIMING)) { /* Timing sub-tuple exists */
5810738c00eSWarner Losh i = *p++;
5820738c00eSWarner Losh j = CIS_WAIT_SCALE(i);
5830738c00eSWarner Losh if (j != 3) {
5840738c00eSWarner Losh printf("\tWait scale ");
5850738c00eSWarner Losh print_ext_speed(*p++, j);
5860738c00eSWarner Losh printf("\n");
5870738c00eSWarner Losh }
5880738c00eSWarner Losh j = CIS_READY_SCALE(i);
5890738c00eSWarner Losh if (j != 7) {
5900738c00eSWarner Losh printf("\tRDY/BSY scale ");
5910738c00eSWarner Losh print_ext_speed(*p++, j);
5920738c00eSWarner Losh printf("\n");
5930738c00eSWarner Losh }
5940738c00eSWarner Losh j = CIS_RESERVED_SCALE(i);
5950738c00eSWarner Losh if (j != 7) {
5960738c00eSWarner Losh printf("\tExternal scale ");
5970738c00eSWarner Losh print_ext_speed(*p++, j);
5980738c00eSWarner Losh printf("\n");
5990738c00eSWarner Losh }
6000738c00eSWarner Losh }
6010738c00eSWarner Losh
6020738c00eSWarner Losh /* I/O mapping sub-tuple */
6030738c00eSWarner Losh if (feat & CIS_FEAT_I_O) { /* I/O space sub-tuple exists */
6040738c00eSWarner Losh if (tp->code == CIS_CONFIG)
6050738c00eSWarner Losh p = print_io_map(p, q);
6060738c00eSWarner Losh else { /* CIS_CONFIG_CB */
6070738c00eSWarner Losh printf("\tI/O base:");
6080738c00eSWarner Losh for (i = 0; i < 8; i++)
6090738c00eSWarner Losh if (*p & (1 << i))
6100738c00eSWarner Losh printf(" %d", i);
6110738c00eSWarner Losh putchar('\n');
6120738c00eSWarner Losh p++;
6130738c00eSWarner Losh }
6140738c00eSWarner Losh }
6150738c00eSWarner Losh
6160738c00eSWarner Losh /* IRQ descriptor sub-tuple */
6170738c00eSWarner Losh if (feat & CIS_FEAT_IRQ) /* IRQ sub-tuple exists */
6180738c00eSWarner Losh p = print_irq_map(p, q);
6190738c00eSWarner Losh
6200738c00eSWarner Losh /* Memory map sub-tuple */
6210738c00eSWarner Losh if (CIS_FEAT_MEMORY(feat)) { /* Memory space sub-tuple(s) exists */
6220738c00eSWarner Losh if (tp->code == CIS_CONFIG)
6230738c00eSWarner Losh p = print_mem_map(feat, p, q);
6240738c00eSWarner Losh else { /* CIS_CONFIG_CB */
6250738c00eSWarner Losh printf("\tMemory base:");
6260738c00eSWarner Losh for (i = 0; i < 8; i++)
6270738c00eSWarner Losh if (*p & (1 << i))
6280738c00eSWarner Losh printf(" %d", i);
6290738c00eSWarner Losh putchar('\n');
6300738c00eSWarner Losh p++;
6310738c00eSWarner Losh }
6320738c00eSWarner Losh }
6330738c00eSWarner Losh
6340738c00eSWarner Losh /* Misc sub-tuple */
6350738c00eSWarner Losh if (feat & CIS_FEAT_MISC) { /* Miscellaneous sub-tuple exists */
6360738c00eSWarner Losh if (tp->code == CIS_CONFIG) {
6370738c00eSWarner Losh printf("\tMax twin cards = %d\n", *p & 7);
6380738c00eSWarner Losh printf("\tMisc attr:%s%s%s",
6390738c00eSWarner Losh (*p & 8) ? " (Audio-BVD2)" : "",
6400738c00eSWarner Losh (*p & 0x10) ? " (Read-only)" : "",
6410738c00eSWarner Losh (*p & 0x20) ? " (Power down supported)" : "");
6420738c00eSWarner Losh if (*p++ & 0x80) {
6430738c00eSWarner Losh printf(" (Ext byte = 0x%x)", *p);
6440738c00eSWarner Losh p++;
6450738c00eSWarner Losh }
6460738c00eSWarner Losh putchar('\n');
6470738c00eSWarner Losh }
6480738c00eSWarner Losh else { /* CIS_CONFIG_CB */
6490738c00eSWarner Losh printf("\tMisc attr:");
6500738c00eSWarner Losh printf("%s%s%s%s%s%s%s",
6510738c00eSWarner Losh (*p & 1) ? " (Master)" : "",
6520738c00eSWarner Losh (*p & 2) ? " (Invalidate)" : "",
6530738c00eSWarner Losh (*p & 4) ? " (VGA palette)" : "",
6540738c00eSWarner Losh (*p & 8) ? " (Parity)" : "",
6550738c00eSWarner Losh (*p & 0x10) ? " (Wait)" : "",
6560738c00eSWarner Losh (*p & 0x20) ? " (Serr)" : "",
6570738c00eSWarner Losh (*p & 0x40) ? " (Fast back)" : "");
6580738c00eSWarner Losh if (*p++ & 0x80) {
6590738c00eSWarner Losh printf("%s%s",
6600738c00eSWarner Losh (*p & 1) ? " (Binary audio)" : "",
6610738c00eSWarner Losh (*p & 2) ? " (pwm audio)" : "");
6620738c00eSWarner Losh p++;
6630738c00eSWarner Losh }
6640738c00eSWarner Losh putchar('\n');
6650738c00eSWarner Losh }
6660738c00eSWarner Losh }
6670738c00eSWarner Losh }
6680738c00eSWarner Losh
6690738c00eSWarner Losh /*
6700738c00eSWarner Losh * CIS_DEVICE_OC, CIS_DEVICE_OA:
6710738c00eSWarner Losh * Dump other conditions for common/attribute memory
6720738c00eSWarner Losh */
6730738c00eSWarner Losh static void
dump_other_cond(u_char * p,int len)6740738c00eSWarner Losh dump_other_cond(u_char *p, int len)
6750738c00eSWarner Losh {
6760738c00eSWarner Losh if (p[0] && len > 0) {
6770738c00eSWarner Losh printf("\t");
6780738c00eSWarner Losh if (p[0] & 1)
6790738c00eSWarner Losh printf("(MWAIT)");
6800738c00eSWarner Losh if (p[0] & 2)
6810738c00eSWarner Losh printf(" (3V card)");
6820738c00eSWarner Losh if (p[0] & 0x80)
6830738c00eSWarner Losh printf(" (Extension bytes follow)");
6840738c00eSWarner Losh printf("\n");
6850738c00eSWarner Losh }
6860738c00eSWarner Losh }
6870738c00eSWarner Losh
6880738c00eSWarner Losh /*
6890738c00eSWarner Losh * CIS_MEM_COMMON, CIS_MEM_ATTR:
6900738c00eSWarner Losh * Common / Attribute memory descripter
6910738c00eSWarner Losh */
6920738c00eSWarner Losh static void
dump_device_desc(u_char * p,int len,const char * type)693c1d393d2SWarner Losh dump_device_desc(u_char *p, int len, const char *type)
6940738c00eSWarner Losh {
695c1d393d2SWarner Losh static const char *un_name[] =
6960738c00eSWarner Losh {"512b", "2Kb", "8Kb", "32Kb", "128Kb", "512Kb", "2Mb", "reserved"};
697c1d393d2SWarner Losh static const char *speed[] =
6980738c00eSWarner Losh {"No speed", "250nS", "200nS", "150nS",
6990738c00eSWarner Losh "100nS", "Reserved", "Reserved"};
700c1d393d2SWarner Losh static const char *dev[] =
7010738c00eSWarner Losh {"No device", "Mask ROM", "OTPROM", "UV EPROM",
7020738c00eSWarner Losh "EEPROM", "FLASH EEPROM", "SRAM", "DRAM",
7030738c00eSWarner Losh "Reserved", "Reserved", "Reserved", "Reserved",
7040738c00eSWarner Losh "Reserved", "Function specific", "Extended",
7050738c00eSWarner Losh "Reserved"};
7060738c00eSWarner Losh int count = 0;
7070738c00eSWarner Losh
7080738c00eSWarner Losh while (*p != 0xFF && len > 0) {
7090738c00eSWarner Losh u_char x;
7100738c00eSWarner Losh
7110738c00eSWarner Losh x = *p++;
7120738c00eSWarner Losh len -= 2;
7130738c00eSWarner Losh if (count++ == 0)
7140738c00eSWarner Losh printf("\t%s memory device information:\n", type);
7150738c00eSWarner Losh printf("\t\tDevice number %d, type %s, WPS = %s\n",
7160738c00eSWarner Losh count, dev[x >> 4], (x & 0x8) ? "ON" : "OFF");
7170738c00eSWarner Losh if ((x & 7) == 7) {
7180738c00eSWarner Losh len--;
7190738c00eSWarner Losh if (*p) {
7200738c00eSWarner Losh printf("\t\t");
7210738c00eSWarner Losh print_ext_speed(*p, 0);
7220738c00eSWarner Losh while (*p & 0x80) {
7230738c00eSWarner Losh p++;
7240738c00eSWarner Losh len--;
7250738c00eSWarner Losh }
7260738c00eSWarner Losh }
7270738c00eSWarner Losh p++;
7280738c00eSWarner Losh } else
7290738c00eSWarner Losh printf("\t\tSpeed = %s", speed[x & 7]);
7300738c00eSWarner Losh printf(", Memory block size = %s, %d units\n",
7310738c00eSWarner Losh un_name[*p & 7], (*p >> 3) + 1);
7320738c00eSWarner Losh p++;
7330738c00eSWarner Losh }
7340738c00eSWarner Losh }
7350738c00eSWarner Losh
7360738c00eSWarner Losh /*
7370738c00eSWarner Losh * CIS_INFO_V1: Print version-1 info
7380738c00eSWarner Losh */
7390738c00eSWarner Losh static void
dump_info_v1(u_char * p,int len)7400738c00eSWarner Losh dump_info_v1(u_char *p, int len)
7410738c00eSWarner Losh {
7420738c00eSWarner Losh if (len < 2) {
7430738c00eSWarner Losh printf("\tWrong length for version-1 info tuple\n");
7440738c00eSWarner Losh return;
7450738c00eSWarner Losh }
7460738c00eSWarner Losh printf("\tVersion = %d.%d", p[0], p[1]);
7470738c00eSWarner Losh p += 2;
7480738c00eSWarner Losh len -= 2;
7490738c00eSWarner Losh if (len > 1 && *p != 0xff) {
7500738c00eSWarner Losh printf(", Manuf = [%s]", p);
7510738c00eSWarner Losh while (*p++ && --len > 0);
7520738c00eSWarner Losh }
7530738c00eSWarner Losh if (len > 1 && *p != 0xff) {
7540738c00eSWarner Losh printf(", card vers = [%s]", p);
7550738c00eSWarner Losh while (*p++ && --len > 0);
7560738c00eSWarner Losh } else {
7570738c00eSWarner Losh printf("\n\tWrong length for version-1 info tuple\n");
7580738c00eSWarner Losh return;
7590738c00eSWarner Losh }
7600738c00eSWarner Losh putchar('\n');
7610738c00eSWarner Losh if (len > 1 && *p != 0xff) {
7620738c00eSWarner Losh printf("\tAddit. info = [%.*s]", len, p);
7630738c00eSWarner Losh while (*p++ && --len > 0);
7640738c00eSWarner Losh if (len > 1 && *p != 0xff)
7650738c00eSWarner Losh printf(",[%.*s]", len, p);
7660738c00eSWarner Losh putchar('\n');
7670738c00eSWarner Losh }
7680738c00eSWarner Losh }
7690738c00eSWarner Losh
7700738c00eSWarner Losh /*
7710738c00eSWarner Losh * CIS_FUNC_ID: Functional ID
7720738c00eSWarner Losh */
7730738c00eSWarner Losh static void
dump_func_id(u_char * p)7740738c00eSWarner Losh dump_func_id(u_char *p)
7750738c00eSWarner Losh {
776c1d393d2SWarner Losh static const char *id[] = {
7770738c00eSWarner Losh "Multifunction card",
7780738c00eSWarner Losh "Memory card",
7790738c00eSWarner Losh "Serial port/modem",
7800738c00eSWarner Losh "Parallel port",
7810738c00eSWarner Losh "Fixed disk card",
7820738c00eSWarner Losh "Video adapter",
7830738c00eSWarner Losh "Network/LAN adapter",
7840738c00eSWarner Losh "AIMS",
7850738c00eSWarner Losh "SCSI card",
7860738c00eSWarner Losh "Security"
7870738c00eSWarner Losh };
7880738c00eSWarner Losh
7890738c00eSWarner Losh printf("\t%s%s%s\n",
7900738c00eSWarner Losh (*p <= 9) ? id[*p] : "Unknown function",
7910738c00eSWarner Losh (p[1] & 1) ? " - POST initialize" : "",
7920738c00eSWarner Losh (p[1] & 2) ? " - Card has ROM" : "");
7930738c00eSWarner Losh }
7940738c00eSWarner Losh
7950738c00eSWarner Losh /*
7960738c00eSWarner Losh * CIS_FUNC_EXT: Dump functional extension tuple.
7970738c00eSWarner Losh * (Serial port/modem)
7980738c00eSWarner Losh */
7990738c00eSWarner Losh static void
dump_serial_ext(u_char * p,int len)8000738c00eSWarner Losh dump_serial_ext(u_char *p, int len)
8010738c00eSWarner Losh {
802c1d393d2SWarner Losh static const char *type[] = {
8030738c00eSWarner Losh "", "Modem", "Data", "Fax", "Voice", "Data modem",
8040738c00eSWarner Losh "Fax/modem", "Voice", " (Data)", " (Fax)", " (Voice)"
8050738c00eSWarner Losh };
8060738c00eSWarner Losh
8070738c00eSWarner Losh if (len < 1)
8080738c00eSWarner Losh return;
8090738c00eSWarner Losh switch (p[0]) {
8100738c00eSWarner Losh case 0: /* Serial */
8110738c00eSWarner Losh case 8: /* Data */
8120738c00eSWarner Losh case 9: /* Fax */
8130738c00eSWarner Losh case 10: /* Voice */
8140738c00eSWarner Losh printf("\tSerial interface extension:%s\n", type[*p]);
8150738c00eSWarner Losh if (len < 4)
8160738c00eSWarner Losh goto err;
8170738c00eSWarner Losh switch (p[1] & 0x1F) {
8180738c00eSWarner Losh default:
819c1d393d2SWarner Losh printf("\t\tUnknown device");
8200738c00eSWarner Losh break;
8210738c00eSWarner Losh case 0:
8220738c00eSWarner Losh printf("\t\t8250 UART");
8230738c00eSWarner Losh break;
8240738c00eSWarner Losh case 1:
8250738c00eSWarner Losh printf("\t\t16450 UART");
8260738c00eSWarner Losh break;
8270738c00eSWarner Losh case 2:
8280738c00eSWarner Losh printf("\t\t16550 UART");
8290738c00eSWarner Losh break;
8300738c00eSWarner Losh }
8310738c00eSWarner Losh printf(", Parity - %s%s%s%s\n",
8320738c00eSWarner Losh (p[2] & 1) ? "Space," : "",
8330738c00eSWarner Losh (p[2] & 2) ? "Mark," : "",
8340738c00eSWarner Losh (p[2] & 4) ? "Odd," : "",
8350738c00eSWarner Losh (p[2] & 8) ? "Even" : "");
8360738c00eSWarner Losh printf("\t\tData bit - %s%s%s%s Stop bit - %s%s%s\n",
8370738c00eSWarner Losh (p[3] & 1) ? "5bit," : "",
8380738c00eSWarner Losh (p[3] & 2) ? "6bit," : "",
8390738c00eSWarner Losh (p[3] & 4) ? "7bit," : "",
8400738c00eSWarner Losh (p[3] & 8) ? "8bit," : "",
8410738c00eSWarner Losh (p[3] & 0x10) ? "1bit," : "",
8420738c00eSWarner Losh (p[3] & 0x20) ? "1.5bit," : "",
8430738c00eSWarner Losh (p[3] & 0x40) ? "2bit" : "");
8440738c00eSWarner Losh break;
8450738c00eSWarner Losh case 1: /* Serial */
8460738c00eSWarner Losh case 5: /* Data */
8470738c00eSWarner Losh case 6: /* Fax */
8480738c00eSWarner Losh case 7: /* Voice */
8490738c00eSWarner Losh printf("\t%s interface capabilities:\n", type[*p]);
8500738c00eSWarner Losh if (len < 9)
8510738c00eSWarner Losh goto err;
8520738c00eSWarner Losh break;
8530738c00eSWarner Losh case 2: /* Data */
8540738c00eSWarner Losh printf("\tData modem services available:\n");
8550738c00eSWarner Losh break;
8560738c00eSWarner Losh case 0x13: /* Fax1 */
8570738c00eSWarner Losh case 0x23: /* Fax2 */
8580738c00eSWarner Losh case 0x33: /* Fax3 */
8590738c00eSWarner Losh printf("\tFax%d/modem services available:\n", *p >> 4);
8600738c00eSWarner Losh break;
8610738c00eSWarner Losh case 0x84: /* Voice */
8620738c00eSWarner Losh printf("\tVoice services available:\n");
8630738c00eSWarner Losh break;
8640738c00eSWarner Losh err: /* warning */
8650738c00eSWarner Losh printf("\tWrong length for serial extension tuple\n");
8660738c00eSWarner Losh return;
8670738c00eSWarner Losh }
8680738c00eSWarner Losh }
8690738c00eSWarner Losh
8700738c00eSWarner Losh /*
8710738c00eSWarner Losh * CIS_FUNC_EXT: Dump functional extension tuple.
8720738c00eSWarner Losh * (Fixed disk card)
8730738c00eSWarner Losh */
8740738c00eSWarner Losh static void
dump_disk_ext(u_char * p,int len)8750738c00eSWarner Losh dump_disk_ext(u_char *p, int len)
8760738c00eSWarner Losh {
8770738c00eSWarner Losh if (len < 1)
8780738c00eSWarner Losh return;
8790738c00eSWarner Losh switch (p[0]) {
8800738c00eSWarner Losh case 1: /* IDE interface */
8810738c00eSWarner Losh if (len < 2)
8820738c00eSWarner Losh goto err;
8830738c00eSWarner Losh printf("\tDisk interface: %s\n",
8840738c00eSWarner Losh (p[1] & 1) ? "IDE" : "Undefined");
8850738c00eSWarner Losh break;
8860738c00eSWarner Losh case 2: /* Master */
8870738c00eSWarner Losh case 3: /* Slave */
8880738c00eSWarner Losh if (len < 3)
8890738c00eSWarner Losh goto err;
8900738c00eSWarner Losh printf("\tDisk features: %s, %s%s\n",
8910738c00eSWarner Losh (p[1] & 0x04) ? "Silicon" : "Rotating",
8920738c00eSWarner Losh (p[1] & 0x08) ? "Unique, " : "",
8930738c00eSWarner Losh (p[1] & 0x10) ? "Dual" : "Single");
8940738c00eSWarner Losh if (p[2] & 0x7f)
8950738c00eSWarner Losh printf("\t\t%s%s%s%s%s%s%s\n",
8960738c00eSWarner Losh (p[2] & 0x01) ? "Sleep, " : "",
8970738c00eSWarner Losh (p[2] & 0x02) ? "Standby, " : "",
8980738c00eSWarner Losh (p[2] & 0x04) ? "Idle, " : "",
8990738c00eSWarner Losh (p[2] & 0x08) ? "Low power, " : "",
9000738c00eSWarner Losh (p[2] & 0x10) ? "Reg inhibit, " : "",
9010738c00eSWarner Losh (p[2] & 0x20) ? "Index, " : "",
9020738c00eSWarner Losh (p[2] & 0x40) ? "Iois16" : "");
9030738c00eSWarner Losh break;
9040738c00eSWarner Losh err: /* warning */
9050738c00eSWarner Losh printf("\tWrong length for fixed disk extension tuple\n");
9060738c00eSWarner Losh return;
9070738c00eSWarner Losh }
9080738c00eSWarner Losh }
9090738c00eSWarner Losh
9100738c00eSWarner Losh static void
print_speed(u_int i)9110738c00eSWarner Losh print_speed(u_int i)
9120738c00eSWarner Losh {
9130738c00eSWarner Losh if (i < 1000)
9140738c00eSWarner Losh printf("%u bits/sec", i);
9150738c00eSWarner Losh else if (i < 1000000)
9160738c00eSWarner Losh printf("%u kb/sec", i / 1000);
9170738c00eSWarner Losh else
9180738c00eSWarner Losh printf("%u Mb/sec", i / 1000000);
9190738c00eSWarner Losh }
9200738c00eSWarner Losh
9210738c00eSWarner Losh /*
9220738c00eSWarner Losh * CIS_FUNC_EXT: Dump functional extension tuple.
9230738c00eSWarner Losh * (Network/LAN adapter)
9240738c00eSWarner Losh */
9250738c00eSWarner Losh static void
dump_network_ext(u_char * p,int len)9260738c00eSWarner Losh dump_network_ext(u_char *p, int len)
9270738c00eSWarner Losh {
9280738c00eSWarner Losh static const char *tech[] = {
9290738c00eSWarner Losh "Undefined", "ARCnet", "Ethernet", "Token ring",
9300738c00eSWarner Losh "Localtalk", "FDDI/CDDI", "ATM", "Wireless"
9310738c00eSWarner Losh };
9320738c00eSWarner Losh static const char *media[] = {
9330738c00eSWarner Losh "Undefined", "UTP", "STP", "Thin coax",
9340738c00eSWarner Losh "THICK coax", "Fiber", "900 MHz", "2.4 GHz",
9350738c00eSWarner Losh "5.4 GHz", "Diffuse Infrared", "Point to point Infrared"
9360738c00eSWarner Losh };
9370738c00eSWarner Losh u_int i = 0;
9380738c00eSWarner Losh
9390738c00eSWarner Losh if (len < 1)
9400738c00eSWarner Losh return;
9410738c00eSWarner Losh switch (p[0]) {
9420738c00eSWarner Losh case 1: /* Network technology */
9430738c00eSWarner Losh if (len < 2)
9440738c00eSWarner Losh goto err;
9450738c00eSWarner Losh printf("\tNetwork technology: %s\n", tech[p[1] & 7]);
9460738c00eSWarner Losh break;
9470738c00eSWarner Losh case 2: /* Network speed */
9480738c00eSWarner Losh if (len < 5)
9490738c00eSWarner Losh goto err;
9500738c00eSWarner Losh printf("\tNetwork speed: ");
9510738c00eSWarner Losh print_speed(tpl32(p + 1));
9520738c00eSWarner Losh putchar('\n');
9530738c00eSWarner Losh break;
9540738c00eSWarner Losh case 3: /* Network media */
9550738c00eSWarner Losh if (len < 2)
9560738c00eSWarner Losh goto err;
9570738c00eSWarner Losh if (p[1] <= 10)
9580738c00eSWarner Losh i = p[1];
9590738c00eSWarner Losh printf("\tNetwork media: %s\n", media[i]);
9600738c00eSWarner Losh break;
9610738c00eSWarner Losh case 4: /* Node ID */
9620738c00eSWarner Losh if (len <= 2 || len < p[1] + 2)
9630738c00eSWarner Losh goto err;
9640738c00eSWarner Losh printf("\tNetwork node ID:");
9650738c00eSWarner Losh for (i = 0; i < p[1]; i++)
9660738c00eSWarner Losh printf(" %02x", p[i + 2]);
9670738c00eSWarner Losh putchar('\n');
9680738c00eSWarner Losh break;
9697a2b450fSEitan Adler case 5: /* Connector type */
9700738c00eSWarner Losh if (len < 2)
9710738c00eSWarner Losh goto err;
9720738c00eSWarner Losh printf("\tNetwork connector: %s connector standard\n",
9730738c00eSWarner Losh (p[1] == 0) ? "open" : "closed");
9740738c00eSWarner Losh break;
9750738c00eSWarner Losh err: /* warning */
9760738c00eSWarner Losh printf("\tWrong length for network extension tuple\n");
9770738c00eSWarner Losh return;
9780738c00eSWarner Losh }
9790738c00eSWarner Losh }
9800738c00eSWarner Losh
9810738c00eSWarner Losh /*
9820738c00eSWarner Losh * CIS_LONGLINK_MFC: Long link to next chain for Multi function card
9830738c00eSWarner Losh */
9840738c00eSWarner Losh static void
dump_longlink_mfc(u_char * p,int len)9850738c00eSWarner Losh dump_longlink_mfc(u_char *p, int len)
9860738c00eSWarner Losh {
9870738c00eSWarner Losh u_int i, n = *p++;
9880738c00eSWarner Losh
9890738c00eSWarner Losh --len;
9900738c00eSWarner Losh for (i = 0; i < n; i++) {
9910738c00eSWarner Losh if (len < 5) {
9920738c00eSWarner Losh printf("\tWrong length for long link MFC tuple\n");
9930738c00eSWarner Losh return;
9940738c00eSWarner Losh }
9950738c00eSWarner Losh printf("\tFunction %d: %s memory, address 0x%x\n",
9960738c00eSWarner Losh i, (*p ? "common" : "attribute"), tpl32(p + 1));
9970738c00eSWarner Losh p += 5;
9980738c00eSWarner Losh len -= 5;
9990738c00eSWarner Losh }
10000738c00eSWarner Losh }
10010738c00eSWarner Losh
10020738c00eSWarner Losh /*
10030738c00eSWarner Losh * CIS_DEVICEGEO, CIS_DEVICEGEO_A:
10040738c00eSWarner Losh * Geometry info for common/attribute memory
10050738c00eSWarner Losh */
10060738c00eSWarner Losh static void
dump_device_geo(u_char * p,int len)10070738c00eSWarner Losh dump_device_geo(u_char *p, int len)
10080738c00eSWarner Losh {
10090738c00eSWarner Losh while (len >= 6) {
10100738c00eSWarner Losh printf("\twidth = %d, erase = 0x%x, read = 0x%x, write = 0x%x\n"
10110738c00eSWarner Losh "\t\tpartition = 0x%x, interleave = 0x%x\n",
10120738c00eSWarner Losh p[0], 1 << (p[1] - 1),
10130738c00eSWarner Losh 1 << (p[2] - 1), 1 << (p[3] - 1),
10140738c00eSWarner Losh 1 << (p[4] - 1), 1 << (p[5] - 1));
10150738c00eSWarner Losh len -= 6;
10160738c00eSWarner Losh }
10170738c00eSWarner Losh }
10180738c00eSWarner Losh
10190738c00eSWarner Losh /*
10200738c00eSWarner Losh * CIS_INFO_V2: Print version-2 info
10210738c00eSWarner Losh */
10220738c00eSWarner Losh static void
dump_info_v2(u_char * p,int len)10230738c00eSWarner Losh dump_info_v2(u_char *p, int len)
10240738c00eSWarner Losh {
10250738c00eSWarner Losh if (len < 9) {
10260738c00eSWarner Losh printf("\tWrong length for version-2 info tuple\n");
10270738c00eSWarner Losh return;
10280738c00eSWarner Losh }
10290738c00eSWarner Losh printf("\tVersion = 0x%x, compliance = 0x%x, dindex = 0x%x\n",
10300738c00eSWarner Losh p[0], p[1], tpl16(p + 2));
10310738c00eSWarner Losh printf("\tVspec8 = 0x%x, vspec9 = 0x%x, nhdr = %d\n",
10320738c00eSWarner Losh p[6], p[7], p[8]);
10330738c00eSWarner Losh p += 9;
10340738c00eSWarner Losh len -= 9;
10350738c00eSWarner Losh if (len <= 1 || *p == 0xff)
10360738c00eSWarner Losh return;
10370738c00eSWarner Losh printf("\tVendor = [%.*s]", len, p);
10380738c00eSWarner Losh while (*p++ && --len > 0);
10390738c00eSWarner Losh if (len > 1 && *p != 0xff)
10400738c00eSWarner Losh printf(", info = [%.*s]", len, p);
10410738c00eSWarner Losh putchar('\n');
10420738c00eSWarner Losh }
10430738c00eSWarner Losh
10440738c00eSWarner Losh /*
10450738c00eSWarner Losh * CIS_ORG: Organization
10460738c00eSWarner Losh */
10470738c00eSWarner Losh static void
dump_org(u_char * p,int len)10480738c00eSWarner Losh dump_org(u_char *p, int len)
10490738c00eSWarner Losh {
10500738c00eSWarner Losh if (len < 1) {
10510738c00eSWarner Losh printf("\tWrong length for organization tuple\n");
10520738c00eSWarner Losh return;
10530738c00eSWarner Losh }
10540738c00eSWarner Losh switch (*p) {
10550738c00eSWarner Losh case 0:
10560738c00eSWarner Losh printf("\tFilesystem");
10570738c00eSWarner Losh break;
10580738c00eSWarner Losh case 1:
10590738c00eSWarner Losh printf("\tApp specific");
10600738c00eSWarner Losh break;
10610738c00eSWarner Losh case 2:
10620738c00eSWarner Losh printf("\tCode");
10630738c00eSWarner Losh break;
10640738c00eSWarner Losh default:
10650738c00eSWarner Losh if (*p < 0x80)
10660738c00eSWarner Losh printf("\tReserved");
10670738c00eSWarner Losh else
10680738c00eSWarner Losh printf("\tVendor specific");
10690738c00eSWarner Losh break;
10700738c00eSWarner Losh }
10710738c00eSWarner Losh printf(" [%.*s]\n", len - 1, p + 1);
10720738c00eSWarner Losh }
10730738c00eSWarner Losh
10740738c00eSWarner Losh static void
print_size(u_int i)10750738c00eSWarner Losh print_size(u_int i)
10760738c00eSWarner Losh {
10770738c00eSWarner Losh if (i < 1024)
10780738c00eSWarner Losh printf("%ubits", i);
10790738c00eSWarner Losh else if (i < 1024*1024)
10800738c00eSWarner Losh printf("%ukb", i / 1024);
10810738c00eSWarner Losh else
10820738c00eSWarner Losh printf("%uMb", i / (1024*1024));
10830738c00eSWarner Losh }
10840738c00eSWarner Losh
10850738c00eSWarner Losh /*
10860738c00eSWarner Losh * CIS_BAR: Base address register for CardBus
10870738c00eSWarner Losh */
10880738c00eSWarner Losh static void
dump_bar(u_char * p,int len)10890738c00eSWarner Losh dump_bar(u_char *p, int len)
10900738c00eSWarner Losh {
10910738c00eSWarner Losh if (len < 6) {
10920738c00eSWarner Losh printf("\tWrong length for BAR tuple\n");
10930738c00eSWarner Losh return;
10940738c00eSWarner Losh }
10950738c00eSWarner Losh printf("\tBAR %d: size = ", *p & 7);
10960738c00eSWarner Losh print_size(tpl32(p + 2));
10970738c00eSWarner Losh printf(", %s%s%s%s\n",
10980738c00eSWarner Losh (*p & 0x10) ? "I/O" : "Memory",
10990738c00eSWarner Losh (*p & 0x20) ? ", Prefetch" : "",
11000738c00eSWarner Losh (*p & 0x40) ? ", Cacheable" : "",
11010738c00eSWarner Losh (*p & 0x80) ? ", <1Mb" : "");
11020738c00eSWarner Losh }
1103