📄 dump_cis.c
字号:
}}/*====================================================================*/static void print_vers_1(cistpl_vers_1_t *v1){ int i, n; char s[32]; sprintf(s, "%svers_1 %d.%d", indent, v1->major, v1->minor); printf("%s", s); n = strlen(s); for (i = 0; i < v1->ns; i++) { if (n + strlen(v1->str + v1->ofs[i]) + 4 > 72) { n = strlen(indent) + 2; printf(",\n%s ", indent); } else { printf(", "); n += 2; } printf("\"%s\"", v1->str + v1->ofs[i]); n += strlen(v1->str + v1->ofs[i]) + 2; } putchar('\n');}/*====================================================================*/static void print_vers_2(cistpl_vers_2_t *v2){ printf("%sversion 0x%2.2x, compliance 0x%2.2x, dindex 0x%4.4x\n", indent, v2->vers, v2->comply, v2->dindex); printf("%s vspec8 0x%2.2x, vspec9 0x%2.2x, nhdr %d\n", indent, v2->vspec8, v2->vspec9, v2->nhdr); printf("%s vendor \"%s\"\n", indent, v2->str+v2->vendor); printf("%s info \"%s\"\n", indent, v2->str+v2->info);}/*====================================================================*/#ifdef CISTPL_FORMAT_DISKstatic void print_format(cistpl_format_t *fmt){ if (fmt->type == CISTPL_FORMAT_DISK) printf("%s [disk]", indent); else if (fmt->type == CISTPL_FORMAT_MEM) printf("%s [memory]", indent); else printf("%s [type 0x%02x]\n", indent, fmt->type); if (fmt->edc == CISTPL_EDC_NONE) printf(" [no edc]"); else if (fmt->edc == CISTPL_EDC_CKSUM) printf(" [cksum]"); else if (fmt->edc == CISTPL_EDC_CRC) printf(" [crc]"); else if (fmt->edc == CISTPL_EDC_PCC) printf(" [pcc]"); else printf(" [edc 0x%02x]", fmt->edc); printf(" offset 0x%04x length ", fmt->offset); print_size(fmt->length); putchar('\n');}#endif/*====================================================================*/static void print_config(int code, cistpl_config_t *cfg){ printf("%sconfig%s base 0x%4.4x", indent, (code == CISTPL_CONFIG_CB) ? "_cb" : "", cfg->base); if (code == CISTPL_CONFIG) printf(" mask 0x%4.4x", cfg->rmask[0]); printf(" last_index 0x%2.2x\n", cfg->last_idx); if (verbose && cfg->subtuples) printf("%s %d bytes in subtuples\n", indent, cfg->subtuples);}/*====================================================================*/static int nfn = 0, cur = 0;static void print_parse(tuple_parse_t *tup){ static int func = 0; int i; switch (tup->tuple.TupleCode) { case CISTPL_DEVICE: case CISTPL_DEVICE_A: if (tup->tuple.TupleCode == CISTPL_DEVICE) printf("%sdev_info\n", indent); else printf("%sattr_dev_info\n", indent); print_device(&tup->parse.device); break; case CISTPL_CHECKSUM: printf("%schecksum 0x%04x-0x%04x = 0x%02x\n", indent, tup->parse.checksum.addr, tup->parse.checksum.addr+tup->parse.checksum.len-1, tup->parse.checksum.sum); break; case CISTPL_LONGLINK_A: if (verbose) printf("%slong_link_attr 0x%04x\n", indent, tup->parse.longlink.addr); break; case CISTPL_LONGLINK_C: if (verbose) printf("%slong_link 0x%04x\n", indent, tup->parse.longlink.addr); break; case CISTPL_LONGLINK_MFC: if (verbose) { printf("%smfc_long_link\n", indent); for (i = 0; i < tup->parse.longlink_mfc.nfn; i++) printf("%s function %d: %s 0x%04x\n", indent, i, tup->parse.longlink_mfc.fn[i].space ? "common" : "attr", tup->parse.longlink_mfc.fn[i].addr); } else { printf("%smfc {\n", indent); nfn = tup->parse.longlink_mfc.nfn; cur = 0; strcat(indent, " "); } break; case CISTPL_NO_LINK: if (verbose) printf("%sno_long_link\n", indent); break;#ifdef CISTPL_INDIRECT case CISTPL_INDIRECT: if (verbose) printf("%sindirect_access\n", indent); break;#endif case CISTPL_LINKTARGET: if (verbose) printf("%slink_target\n", indent); else { if (cur++) printf("%s}, {\n", indent+2); } break; case CISTPL_VERS_1: print_vers_1(&tup->parse.version_1); break; case CISTPL_ALTSTR: break; case CISTPL_JEDEC_A: case CISTPL_JEDEC_C: if (tup->tuple.TupleCode == CISTPL_JEDEC_C) printf("%scommon_jedec", indent); else printf("%sattr_jedec", indent); print_jedec(&tup->parse.jedec); break; case CISTPL_DEVICE_GEO: case CISTPL_DEVICE_GEO_A: if (tup->tuple.TupleCode == CISTPL_DEVICE_GEO) printf("%scommon_geometry\n", indent); else printf("%sattr_geometry\n", indent); print_device_geo(&tup->parse.device_geo); break; case CISTPL_MANFID: printf("%smanfid 0x%4.4x, 0x%4.4x\n", indent, tup->parse.manfid.manf, tup->parse.manfid.card); break; case CISTPL_FUNCID: print_funcid(&tup->parse.funcid); func = tup->parse.funcid.func; break; case CISTPL_FUNCE: switch (func) { case CISTPL_FUNCID_SERIAL: print_serial(&tup->parse.funce); break; case CISTPL_FUNCID_FIXED: print_fixed(&tup->parse.funce); break; case CISTPL_FUNCID_NETWORK: print_network(&tup->parse.funce); break; } break; case CISTPL_BAR: printf("%sBAR %d size ", indent, tup->parse.bar.attr & CISTPL_BAR_SPACE); print_size(tup->parse.bar.size); if (tup->parse.bar.attr & CISTPL_BAR_SPACE_IO) printf(" [io]"); else printf(" [mem]"); if (tup->parse.bar.attr & CISTPL_BAR_PREFETCH) printf(" [prefetch]"); if (tup->parse.bar.attr & CISTPL_BAR_CACHEABLE) printf(" [cacheable]"); if (tup->parse.bar.attr & CISTPL_BAR_1MEG_MAP) printf(" [<1mb]"); putchar('\n'); break; case CISTPL_CONFIG: case CISTPL_CONFIG_CB: print_config(tup->tuple.TupleCode, &tup->parse.config); break; case CISTPL_CFTABLE_ENTRY: print_cftable_entry(&tup->parse.cftable_entry); break; case CISTPL_CFTABLE_ENTRY_CB: print_cftable_entry_cb(&tup->parse.cftable_entry_cb); break; case CISTPL_VERS_2: print_vers_2(&tup->parse.vers_2); break; case CISTPL_ORG: print_org(&tup->parse.org); break;#ifdef CISTPL_FORMAT_DISK case CISTPL_FORMAT: case CISTPL_FORMAT_A: if (tup->tuple.TupleCode == CISTPL_FORMAT) printf("%scommon_format\n", indent); else printf("%sattr_format\n", indent); print_format(&tup->parse.format);#endif }}/*====================================================================*/static int get_tuple_buf(int fd, ds_ioctl_arg_t *arg, int first){ u_int ofs; static int nb = 0; static u_char buf[1024]; if (first) { nb = read(fd, buf, sizeof(buf)); arg->tuple.TupleLink = arg->tuple.CISOffset = 0; } ofs = arg->tuple.CISOffset + arg->tuple.TupleLink; if (ofs >= nb) return -1; arg->tuple.TupleCode = buf[ofs++]; arg->tuple.TupleDataLen = arg->tuple.TupleLink = buf[ofs++]; arg->tuple.CISOffset = ofs; memcpy(arg->tuple_parse.data, buf+ofs, arg->tuple.TupleLink); return 0;}static int get_tuple(int fd, ds_ioctl_arg_t *arg, int first){ int cmd = (first) ? DS_GET_FIRST_TUPLE : DS_GET_NEXT_TUPLE; if (ioctl(fd, cmd, arg) != 0) { if (errno == ENODEV) printf("%sno card\n", indent); else if (errno != ENODATA) printf("%sget tuple: %s\n", indent, strerror(errno)); return -1; } if (ioctl(fd, DS_GET_TUPLE_DATA, arg) != 0) { printf("%sget tuple data: %s\n", indent, strerror(errno)); return -1; } return 0;}/*====================================================================*/#define MAX_SOCKS 8int main(int argc, char *argv[]){ int i, fd, pfd = -1; ds_ioctl_arg_t arg; int optch, errflg, first; int force = 0; char *infile = NULL; errflg = 0; while ((optch = getopt(argc, argv, "fvi:")) != -1) { switch (optch) { case 'f': force = 1; break; case 'v': verbose = 1; break; case 'i': infile = strdup(optarg); break; default: errflg = 1; break; } } if (errflg || (optind < argc)) { fprintf(stderr, "usage: %s [-v] [-f] [-i infile]\n", argv[0]); exit(EXIT_FAILURE); } major = lookup_dev("pcmcia"); if (major < 0) { fprintf(stderr, "no pcmcia driver in /proc/devices\n"); exit(EXIT_FAILURE); } for (i = 0; (i < MAX_SOCKS) && !(i && infile); i++) { nfn = cur = 0; if (infile) { indent[0] = '\0'; fd = open(infile, O_RDONLY); if (fd < 0) { perror("open()"); return -1; } pfd = open_sock(0); } else { strcpy(indent, " "); fd = pfd = open_sock(i); } if (pfd < 0) break; if (!verbose && (i > 0)) putchar('\n'); if (!infile) printf("Socket %d:\n", i); if (!force && !infile) { if (ioctl(fd, DS_VALIDATE_CIS, &arg) != 0) { printf("%svalidate CIS: %s\n", indent, strerror(errno)); continue; } if (arg.cisinfo.Chains == 0) { printf("%sno CIS present\n", indent); continue; } } arg.tuple.TupleDataMax = sizeof(arg.tuple_parse.data); arg.tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; arg.tuple.DesiredTuple = RETURN_FIRST_TUPLE; arg.tuple.TupleOffset = 0; for (first = 1; ; first = 0) { if (infile) { if (get_tuple_buf(fd, &arg, first) != 0) break; } else { if (get_tuple(fd, &arg, first) != 0) break; } if (verbose) print_tuple(&arg.tuple_parse); if (ioctl(pfd, DS_PARSE_TUPLE, &arg) == 0) print_parse(&arg.tuple_parse); else if (errno != ENOSYS) printf("%sparse error: %s\n", indent, strerror(errno)); if (verbose) putchar('\n'); if (arg.tuple.TupleCode == CISTPL_END) break; } if (!verbose && (nfn > 0)) printf("%s}\n", indent+2); } if ((i == 0) && (pfd < 0)) { perror("open()"); return -1; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -