diff options
-rw-r--r-- | lib/libsectok/Makefile | 4 | ||||
-rw-r--r-- | lib/libsectok/atr.c | 47 | ||||
-rw-r--r-- | lib/libsectok/cmdtab.c | 22 | ||||
-rw-r--r-- | lib/libsectok/sc7816.h | 11 | ||||
-rw-r--r-- | lib/libsectok/scT1.c | 3 | ||||
-rw-r--r-- | lib/libsectok/scio.c | 3 | ||||
-rw-r--r-- | lib/libsectok/scrw.c | 3 | ||||
-rw-r--r-- | lib/libsectok/sectok.h | 8 | ||||
-rw-r--r-- | lib/libsectok/shlib_version | 2 | ||||
-rw-r--r-- | lib/libsectok/todos_atr.c | 29 |
10 files changed, 61 insertions, 71 deletions
diff --git a/lib/libsectok/Makefile b/lib/libsectok/Makefile index 46b0d44151a..4db64de97e9 100644 --- a/lib/libsectok/Makefile +++ b/lib/libsectok/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 2001/07/02 22:08:29 markus Exp $ +# $OpenBSD: Makefile,v 1.6 2001/07/20 15:51:45 rees Exp $ LIB= sectok SRCS= atr.c cmdtab.c cyberflex.c input.c r1r2.c sc7816.c sectok.c todos_atr.c \ ifdhandler.c scT1.c scio.c scrw.c -HDRS= sectok.h sc7816.h +HDRS= sectok.h CFLAGS+=-Wall diff --git a/lib/libsectok/atr.c b/lib/libsectok/atr.c index 10f8c59f442..bd8d559f221 100644 --- a/lib/libsectok/atr.c +++ b/lib/libsectok/atr.c @@ -1,4 +1,4 @@ -/* $Id: atr.c,v 1.6 2001/07/02 20:07:07 rees Exp $ */ +/* $Id: atr.c,v 1.7 2001/07/20 15:51:45 rees Exp $ */ /* copyright 1997, 1999, 2000, 2001 @@ -50,7 +50,7 @@ typedef long int32_t; #include <sys/types.h> #endif -#include "sc7816.h" +#include "sectok.h" /* Global interface bytes */ #define TA1 (tpb[0][0]) @@ -145,7 +145,7 @@ static struct bps { int -parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *param) +sectok_parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *param) { int i, c, t, ts, t0, tck, nhb, pbn; int F, D, Fi, Di, N, etu, WI; @@ -156,7 +156,7 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para ap = atr; if (atr[0] == 0x3) { - if (flags & SCRV) + if (flags & STRV) printf("inverse conversion\n"); for (i = 0; i < len; i++) atr[i] = scinvert[atr[i]]; @@ -164,14 +164,14 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para ts = *ap++; - if (flags & SCRV) { + if (flags & STRV) { for (i = 0; i < len; i++) printf("%d:%x ", i + 1, atr[i]); printf("\n"); } if (ts != 0x3b && ts != 0x3f) { - if (flags & SCRV) + if (flags & STRV) printf("TS=%02x (not default timing)\n", ts); param->t = -1; return len; @@ -202,7 +202,7 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para if (t > hiproto) hiproto = t; - if (flags & SCRV) { + if (flags & STRV) { printf("proto %d T=%d", i + 1, t); for (pbn = 0; pbn < 4; pbn++) if (t0 & (1 << (4 + pbn))) @@ -220,7 +220,7 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para ap += nhb; } - if (nhb && (flags & SCRV)) { + if (nhb && (flags & STRV)) { printf("%d historical bytes:", nhb); for (i = 0; i < nhb; i++) { c = hb[i]; @@ -235,23 +235,23 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para if (hiproto > 0) ap++; - if (ap - atr < len && (flags & SCRLEN)) + if (ap - atr < len && (flags & STRLEN)) len = ap - atr; if (hiproto > 0) { tck = 0; for (i = 1; i < len; i++) tck ^= atr[i]; - if (tck != 0 && (flags & SCRV)) + if (tck != 0 && (flags & STRV)) printf("Checksum failed, TCK=%x sum=%x\n", atr[len-1], tck); } /* got enough bytes? */ - if (ap - atr != len && (flags & SCRV)) + if (ap - atr != len && (flags & STRV)) printf("expected %d proto bytes + %d historical bytes, got %d\n", (int) (ap - atr) - nhb, nhb, len); if (ap - atr > len) { - if (flags & SCRV) + if (flags & STRV) printf("atr underrun\n"); param->t = -1; return len; @@ -267,16 +267,13 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para else t = TD1 & 0xf; - /* Todos reader won't do higher speeds */ - if (!(flags & SCRTODOS)) { - for (i = 0; bps[i].bps; i++) { - if (((TA1 >> 4) & 0xf) >= bps[i].Fi && (TA1 & 0xf) >= bps[i].Di) { - if (flags & SCRV) - printf("speed %ld\n", (long) bps[i].bps); - Fi = bps[i].Fi; - Di = bps[i].Di; - break; - } + for (i = 0; bps[i].bps; i++) { + if (((TA1 >> 4) & 0xf) >= bps[i].Fi && (TA1 & 0xf) >= bps[i].Di) { + if (flags & STRV) + printf("speed %ld\n", (long) bps[i].bps); + Fi = bps[i].Fi; + Di = bps[i].Di; + break; } } @@ -288,7 +285,7 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para param->etu = etu = (F * 50L) / (D * 179L); param->n = (N < 255) ? N : 0; - if (flags & SCRV) { + if (flags & STRV) { printf("%d etu = %d F / %d D * 3.58 f\n", etu, F, D); if (N) printf("%d N\n", N); @@ -299,14 +296,14 @@ parse_atr(int ttyn, int flags, unsigned char *atr, int len, struct scparam *para /* cwt is in milliseconds */ param->cwt = (960L * WI * F) / 3580L; - if ((flags & SCRV) && WI != 10) + if ((flags & STRV) && WI != 10) printf("%d cwt = (960 * %d WI * %d F) / 3.58 f / 1000\n", param->cwt, WI, F); } else if (t == 1) { /* add 100 to each for engineering safety margin */ param->cwt = (11L + (1 << (TB1 & 0xf))) * etu / 1000 + 100; param->bwt = (11L * etu / 1000L) + ((1 << ((TB1 >> 4) & 0xf)) * 100) + 100; - if (flags & SCRV) + if (flags & STRV) printf("%d cwt, %d bwt\n", param->cwt, param->bwt); } param->t = t; diff --git a/lib/libsectok/cmdtab.c b/lib/libsectok/cmdtab.c index ca89dd40c67..ab0f0e9febe 100644 --- a/lib/libsectok/cmdtab.c +++ b/lib/libsectok/cmdtab.c @@ -1,4 +1,4 @@ -/* $Id: cmdtab.c,v 1.3 2001/06/08 15:04:02 rees Exp $ */ +/* $Id: cmdtab.c,v 1.4 2001/07/20 15:51:45 rees Exp $ */ /* copyright 1999 @@ -47,7 +47,7 @@ such damages. #include <stdio.h> #endif -struct cmd { +static struct cmd { int ins, inout; char *name; } cmdtab[] = { @@ -115,11 +115,10 @@ struct cmd { {0, 0, NULL} }; -struct cmd * -lookup_cmd(int ins) +char * +sectok_get_ins(int ins) { struct cmd *p; - static struct cmd dummy; static char name[32]; for (p = &cmdtab[0]; p->name; p++) @@ -127,18 +126,9 @@ lookup_cmd(int ins) break; if (!p->name) { - dummy.ins = ins; - dummy.inout = 2; sprintf(name, "unknown ins %02x", ins); - dummy.name = name; - p = &dummy; + return name; } - return p; -} - -char * -lookup_cmdname(int ins) -{ - return lookup_cmd(ins)->name; + return p->name; } diff --git a/lib/libsectok/sc7816.h b/lib/libsectok/sc7816.h index 962eab89bc6..5bf71d93911 100644 --- a/lib/libsectok/sc7816.h +++ b/lib/libsectok/sc7816.h @@ -1,4 +1,4 @@ -/* $Id: sc7816.h,v 1.1 2001/07/02 20:11:25 rees Exp $ */ +/* $Id: sc7816.h,v 1.2 2001/07/20 15:51:45 rees Exp $ */ /* copyright 1997, 2000 @@ -69,12 +69,7 @@ such damages. #define SCEUNKNOWN 13 extern char *scerrtab[]; - -extern struct scparam { - int t, etu, cwt, bwt, n; -} scparam[]; - -extern unsigned char root_fid[]; +extern struct scparam scparam[]; /* forward declarations */ @@ -100,7 +95,6 @@ void scdrain(int fd); int scioT1(int fd, int cla, int ins, int p1, int p2, int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *sw1p, int *sw2p); int scioT1Iblk(int fd, int ilen, unsigned char *ibuf, unsigned char *obuf); int scioT1pkt(int fd, unsigned char *ibuf, unsigned char *obuf); -int parse_atr(int fd, int flags, unsigned char *atr, int len, struct scparam *param); int parse_input(char *ibuf, unsigned char *obuf, int olen); #ifndef __palmos__ int get_input(FILE *f, unsigned char *obuf, int omin, int olen); @@ -109,7 +103,6 @@ int dump_reply(unsigned char *p, int n, int r1, int r2); #endif void print_r1r2(int r1, int r2); char *get_r1r2s(int r1, int r2); -char *lookup_cmdname(int ins); /* SCPERF - performance evaluation */ #ifdef SCPERF diff --git a/lib/libsectok/scT1.c b/lib/libsectok/scT1.c index 62b1a13602e..3a1ecf3f215 100644 --- a/lib/libsectok/scT1.c +++ b/lib/libsectok/scT1.c @@ -1,4 +1,4 @@ -/* $Id: scT1.c,v 1.4 2001/07/02 20:07:08 rees Exp $ */ +/* $Id: scT1.c,v 1.5 2001/07/20 15:51:45 rees Exp $ */ /* copyright 1997, 1999, 2000 @@ -50,6 +50,7 @@ such damages. #include <sys/time.h> #endif +#include "sectok.h" #include "sc7816.h" #ifdef __palmos__ diff --git a/lib/libsectok/scio.c b/lib/libsectok/scio.c index b6c7731e74e..d681568c3c9 100644 --- a/lib/libsectok/scio.c +++ b/lib/libsectok/scio.c @@ -1,4 +1,4 @@ -/* $Id: scio.c,v 1.7 2001/07/16 22:03:38 rees Exp $ */ +/* $Id: scio.c,v 1.8 2001/07/20 15:51:45 rees Exp $ */ /* copyright 1997 @@ -52,6 +52,7 @@ such damages. #include <fcntl.h> #include <errno.h> +#include "sectok.h" #include "sc7816.h" #include "todos_scrw.h" diff --git a/lib/libsectok/scrw.c b/lib/libsectok/scrw.c index fb248356ae4..d0d85d2e12c 100644 --- a/lib/libsectok/scrw.c +++ b/lib/libsectok/scrw.c @@ -1,4 +1,4 @@ -/* $Id: scrw.c,v 1.5 2001/07/02 20:07:09 rees Exp $ */ +/* $Id: scrw.c,v 1.6 2001/07/20 15:51:45 rees Exp $ */ /* copyright 1997, 1999, 2000 @@ -51,6 +51,7 @@ such damages. #ifdef SCPERF #define SCPERF_FIRST_APPEARANCE #endif /* SCPERF */ +#include "sectok.h" #include "sc7816.h" #include "todos_scrw.h" diff --git a/lib/libsectok/sectok.h b/lib/libsectok/sectok.h index f112c1d265d..6c269b28511 100644 --- a/lib/libsectok/sectok.h +++ b/lib/libsectok/sectok.h @@ -1,4 +1,4 @@ -/* $Id: sectok.h,v 1.11 2001/07/02 20:07:09 rees Exp $ */ +/* $Id: sectok.h,v 1.12 2001/07/20 15:51:45 rees Exp $ */ /* copyright 2001 @@ -35,6 +35,7 @@ such damages. #define STOHUP 0x4 /* send signal on card removal */ /* Reset flags */ +#define STRV 0x1 /* be verbose */ #define STRLEN 0x2 /* determine length by examing atr */ #define STRFORCE 0x8 /* Talk to card even if atr is bad */ @@ -61,6 +62,10 @@ such damages. #define sectok_mksw(r1, r2) (((r1) << 8) | (r2)) #define sectok_swOK(sw) (sectok_r1(sw) == 0x90 || sectok_r1(sw) == 0x61) +struct scparam { + int t, etu, cwt, bwt, n; +}; + extern unsigned char root_fid[]; /* Common card functions */ @@ -75,6 +80,7 @@ int sectok_selectfile(int fd, int cla, unsigned char *fid, int *swp); /* Convenience functions */ void sectok_fmt_fid(char *fname, int f0, int f1); +int sectok_parse_atr(int fd, int flags, unsigned char *atr, int len, struct scparam *param); void sectok_parse_fname(char *buf, unsigned char *fid); int sectok_parse_input(char *ibuf, unsigned char *obuf, int olen); #ifndef __palmos__ diff --git a/lib/libsectok/shlib_version b/lib/libsectok/shlib_version index 1edea46de91..b52599a164f 100644 --- a/lib/libsectok/shlib_version +++ b/lib/libsectok/shlib_version @@ -1,2 +1,2 @@ -major=1 +major=2 minor=0 diff --git a/lib/libsectok/todos_atr.c b/lib/libsectok/todos_atr.c index b012388e7f6..18417e25696 100644 --- a/lib/libsectok/todos_atr.c +++ b/lib/libsectok/todos_atr.c @@ -1,4 +1,4 @@ -/* $Id: todos_atr.c,v 1.7 2001/07/17 16:57:41 rees Exp $ */ +/* $Id: todos_atr.c,v 1.8 2001/07/20 15:51:45 rees Exp $ */ /* copyright 1997, 1999, 2000 @@ -51,6 +51,7 @@ typedef long int32_t; #include <sys/types.h> #endif +#include "sectok.h" #include "sc7816.h" #include "todos_scrw.h" @@ -170,7 +171,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) unsigned char tpb[8][4]; int hiproto = 0; - if (flags & SCRFORCE) { + if (flags & STRFORCE) { /* drain and ignore any atr bytes returned by the card */ while (scgetc(ttyn, atr, BYTETIME) == SCEOK) ; @@ -184,7 +185,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) } #ifndef DEBUG - flags &= ~SCRV; + flags &= ~STRV; #endif ap = atr; @@ -194,13 +195,13 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) SCGETC; ts = *ap++; if (ts == 0x3) { - if (flags & SCRV) + if (flags & STRV) printf("inverse conversion\n"); todos_scsetflags(ttyn, SCOINVRT, SCOINVRT); ts = todos_scinvert[ts]; } if (ts != 0x3b && ts != 0x3f) { - if (flags & SCRV) + if (flags & STRV) printf("TS=%02x (not default timing)\n", ts); param->t = -1; return 0; @@ -236,7 +237,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) if (t > hiproto) hiproto = t; - if (flags & SCRV) { + if (flags & STRV) { printf("proto %d T=%d", i + 1, t); for (pbn = 0; pbn < 4; pbn++) if (t0 & (1 << (4 + pbn))) @@ -255,7 +256,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) SCGETC; ap++; } - if ((flags & SCRV)) + if ((flags & STRV)) printf("%d historical bytes\n", nhb); } @@ -266,7 +267,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) tck = 0; for (i = 1; i < len; i++) tck ^= atr[i]; - if (tck != 0 && (flags & SCRV)) + if (tck != 0 && (flags & STRV)) printf("Checksum failed, TCK=%x sum=%x\n", atr[len-1], tck); } @@ -291,7 +292,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) pps[2] = (bps[i].Fi << 4) | bps[i].Di; pps[3] = 0; - if (flags & SCRV) + if (flags & STRV) printf("speed %ld\n", (long) bps[i].bps); #ifdef SCPPS @@ -308,7 +309,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) continue; if (todos_scsetspeed(ttyn, bps[i].bps) < 0) { /* We already sent the pps, can't back out now, so fail. */ - if (flags & SCRV) + if (flags & STRV) printf("scsetspeed %ld failed\n", (long) bps[i].bps); param->t = -1; return len; @@ -329,7 +330,7 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) param->etu = etu = (F * 50L) / (D * 179L); param->n = (N < 255) ? N : 0; - if (flags & SCRV) { + if (flags & STRV) { printf("%d etu = %d F / %d D * 3.58 f\n", etu, F, D); if (N) printf("%d N\n", N); @@ -340,21 +341,21 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param) /* cwt is in milliseconds */ param->cwt = (960L * WI * F) / 3580L; - if ((flags & SCRV) && WI != 10) + if ((flags & STRV) && WI != 10) printf("%d cwt = (960 * %d WI * %d F) / 3.58 f / 1000\n", param->cwt, WI, F); } else if (t == 1) { /* add 100 to each for engineering safety margin */ param->cwt = (11L + (1 << (TB1 & 0xf))) * etu / 1000 + 100; param->bwt = (11L * etu / 1000L) + ((1 << ((TB1 >> 4) & 0xf)) * 100) + 100; - if (flags & SCRV) + if (flags & STRV) printf("%d cwt, %d bwt\n", param->cwt, param->bwt); } param->t = t; return len; timedout: - if (flags & SCRV) + if (flags & STRV) printf("timed out after %d atr bytes\n", len); param->t = -1; return 0; |