summaryrefslogtreecommitdiff
path: root/lib/libsectok
diff options
context:
space:
mode:
authorJim Rees <rees@cvs.openbsd.org>2001-06-07 20:19:44 +0000
committerJim Rees <rees@cvs.openbsd.org>2001-06-07 20:19:44 +0000
commite9d8e8141890250cad627810ff1b0d3c8906647f (patch)
tree2b7bd2e8c85cf9c58cca894d5627fdf4cb647227 /lib/libsectok
parentb83201a2b2dce8e73b5132d45d30e1c2104e439d (diff)
import latest from CITI with Palm support
Diffstat (limited to 'lib/libsectok')
-rw-r--r--lib/libsectok/ifdhandler.c2
-rw-r--r--lib/libsectok/scT1.c29
-rw-r--r--lib/libsectok/scio.c19
-rw-r--r--lib/libsectok/scrw.c85
-rw-r--r--lib/libsectok/sectok.h2
-rw-r--r--lib/libsectok/todos_atr.c8
-rw-r--r--lib/libsectok/todos_scrw.h17
7 files changed, 78 insertions, 84 deletions
diff --git a/lib/libsectok/ifdhandler.c b/lib/libsectok/ifdhandler.c
index 11e8901bafe..b09bfa65722 100644
--- a/lib/libsectok/ifdhandler.c
+++ b/lib/libsectok/ifdhandler.c
@@ -5,7 +5,7 @@
*
* Jim Rees, University of Michigan CITI, August 2000
*/
-static char *rcsid = "$Id: ifdhandler.c,v 1.2 2001/06/07 16:09:59 rees Exp $";
+static char *rcsid = "$Id: ifdhandler.c,v 1.3 2001/06/07 20:19:42 rees Exp $";
#include <sys/types.h>
#include <stdio.h>
diff --git a/lib/libsectok/scT1.c b/lib/libsectok/scT1.c
index 7398a3ef110..5441cf5415f 100644
--- a/lib/libsectok/scT1.c
+++ b/lib/libsectok/scT1.c
@@ -1,11 +1,9 @@
/*
* T=1 protocol engine
*
- * See copyright notice at end of file
- *
* Jim Rees, University of Michigan, October 1997
*/
-static char *rcsid = "$Id: scT1.c,v 1.1 2001/06/07 15:17:33 rees Exp $";
+static char *rcsid = "$Id: scT1.c,v 1.2 2001/06/07 20:19:43 rees Exp $";
#ifdef __palmos__
#include <Common.h>
@@ -22,10 +20,15 @@ static char *rcsid = "$Id: scT1.c,v 1.1 2001/06/07 15:17:33 rees Exp $";
#endif
#include "sectok.h"
-#include "todos_scrw.h"
+
+#ifdef __palmos__
+#undef printf
+#undef sprintf
+#define printf palmprintf
+#endif
int
-todos_scioT1(int ttyn, int cla, int ins, int p1, int p2, int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *sw1p, int *sw2p)
+scioT1(int ttyn, int cla, int ins, int p1, int p2, int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *sw1p, int *sw2p)
{
int i, len, n;
unsigned char *bp, *obp, tbuf[256];
@@ -57,7 +60,7 @@ todos_scioT1(int ttyn, int cla, int ins, int p1, int p2, int ilen, unsigned char
obp = obuf ? obuf : tbuf;
- n = todos_scioT1Iblk(ttyn, len, tbuf, obp);
+ n = scioT1Iblk(ttyn, len, tbuf, obp);
if (n >= 2) {
*sw1p = obp[n-2];
@@ -68,7 +71,7 @@ todos_scioT1(int ttyn, int cla, int ins, int p1, int p2, int ilen, unsigned char
}
int
-todos_scioT1Iblk(int ttyn, int ilen, unsigned char *ibuf, unsigned char *obuf)
+scioT1Iblk(int ttyn, int ilen, unsigned char *ibuf, unsigned char *obuf)
{
int n;
unsigned char tbuf[256];
@@ -79,7 +82,7 @@ todos_scioT1Iblk(int ttyn, int ilen, unsigned char *ibuf, unsigned char *obuf)
ssn ^= 0x40;
tbuf[2] = ilen;
memcpy(&tbuf[3], ibuf, ilen);
- n = todos_scioT1pkt(ttyn, tbuf, tbuf);
+ n = scioT1pkt(ttyn, tbuf, tbuf);
if (n < 0)
return n;
memcpy(obuf, &tbuf[3], tbuf[2]);
@@ -87,7 +90,7 @@ todos_scioT1Iblk(int ttyn, int ilen, unsigned char *ibuf, unsigned char *obuf)
}
int
-todos_scioT1pkt(int ttyn, unsigned char *ibuf, unsigned char *obuf)
+scioT1pkt(int ttyn, unsigned char *ibuf, unsigned char *obuf)
{
int i, len;
unsigned char edc, *bp;
@@ -102,11 +105,11 @@ todos_scioT1pkt(int ttyn, unsigned char *ibuf, unsigned char *obuf)
/* Wait BGT = 22 etu */
- todos_scsleep(scparam[ttyn].etu * 22 / 1000 + 1);
+ scsleep(scparam[ttyn].etu * 22 / 1000 + 1);
/* Send the packet */
- todos_scputblk(ttyn, ibuf, len);
+ scputblk(ttyn, ibuf, len);
/* Read return packet */
@@ -114,7 +117,7 @@ todos_scioT1pkt(int ttyn, unsigned char *ibuf, unsigned char *obuf)
/* Read three byte header */
for (i = 0; i < 3; i++) {
- if (todos_scgetc(ttyn, bp++, (i == 0) ? scparam[ttyn].bwt : scparam[ttyn].cwt) != SCEOK) {
+ if (scgetc(ttyn, bp++, (i == 0) ? scparam[ttyn].bwt : scparam[ttyn].cwt) != SCEOK) {
#ifdef DEBUG
printf("T=1 header read timeout\n");
#endif
@@ -125,7 +128,7 @@ todos_scioT1pkt(int ttyn, unsigned char *ibuf, unsigned char *obuf)
/* Read data and edc */
for (i = 0; i < len + 1; i++) {
- if (todos_scgetc(ttyn, bp++, scparam[ttyn].cwt) != SCEOK) {
+ if (scgetc(ttyn, bp++, scparam[ttyn].cwt) != SCEOK) {
#ifdef DEBUG
printf("T=1 data read timeout\n");
#endif
diff --git a/lib/libsectok/scio.c b/lib/libsectok/scio.c
index 682eafff8b0..91a3153835c 100644
--- a/lib/libsectok/scio.c
+++ b/lib/libsectok/scio.c
@@ -5,7 +5,7 @@
*
* Jim Rees, University of Michigan, October 1997
*/
-static char *rcsid = "$Id: scio.c,v 1.2 2001/06/07 16:10:00 rees Exp $";
+static char *rcsid = "$Id: scio.c,v 1.3 2001/06/07 20:19:43 rees Exp $";
#include <sys/ioctl.h>
#include <sys/file.h>
@@ -101,7 +101,7 @@ todos_scopen(int ttyn, int flags, int *ep)
#endif
if (i & TIOCM_RI) {
/* Todos reader */
- todos_scsleep(20);
+ scsleep(20);
sc[ttyn].flags |= (SCOXCTS | SCOXDTR);
}
@@ -245,7 +245,7 @@ todos_scfdopen(int ttyn, int fd, int flags, int *ep)
/* The open may or may not have reset the card. Wait a while then flush
anything that came in on the port. */
- todos_scsleep(250);
+ scsleep(250);
todos_scdrain(ttyn);
return ttyn;
@@ -335,7 +335,7 @@ todos_scclose(int ttyn)
*/
int
-todos_scgetc(int ttyn, unsigned char *cp, int ms)
+scgetc(int ttyn, unsigned char *cp, int ms)
{
int fd = sc[ttyn].fd;
fd_set fdset;
@@ -371,7 +371,7 @@ todos_scgetc(int ttyn, unsigned char *cp, int ms)
/* write one byte to the card */
int
-todos_scputc(int ttyn, int ic)
+scputc(int ttyn, int ic)
{
int fd = sc[ttyn].fd;
unsigned char c0, c1;
@@ -385,7 +385,7 @@ todos_scputc(int ttyn, int ic)
write(fd, &c0, 1);
/* gobble up the echo */
- code = todos_scgetc(ttyn, &c1, 200);
+ code = scgetc(ttyn, &c1, 200);
#ifdef GOBBLEDEBUG
if (sc[ttyn].flags & SCOINVRT)
c1 = todos_scinvert[c1];
@@ -399,20 +399,21 @@ todos_scputc(int ttyn, int ic)
return code;
}
-int todos_scputblk(int ttyn, unsigned char *bp, int n)
+int
+scputblk(int ttyn, unsigned char *bp, int n)
{
int fd = sc[ttyn].fd;
unsigned char c;
write(fd, bp, n);
while (n--)
- todos_scgetc(ttyn, &c, 30);
+ scgetc(ttyn, &c, 30);
return SCEOK;
}
void
-todos_scsleep(int ms)
+scsleep(int ms)
{
struct timeval tv;
diff --git a/lib/libsectok/scrw.c b/lib/libsectok/scrw.c
index b71b329b218..21a5093109a 100644
--- a/lib/libsectok/scrw.c
+++ b/lib/libsectok/scrw.c
@@ -5,7 +5,7 @@
*
* Jim Rees, University of Michigan, October 1997
*/
-static char *rcsid = "$Id: scrw.c,v 1.2 2001/06/07 16:10:00 rees Exp $";
+static char *rcsid = "$Id: scrw.c,v 1.3 2001/06/07 20:19:43 rees Exp $";
#ifdef __palmos__
#include <Common.h>
@@ -19,20 +19,12 @@ static char *rcsid = "$Id: scrw.c,v 1.2 2001/06/07 16:10:00 rees Exp $";
#include <stdio.h>
#include <string.h>
#endif
-#ifdef SCPERF
+#ifdef SCPERF
#define SCPERF_FIRST_APPEARANCE
#endif /* SCPERF */
#include "sectok.h"
#include "todos_scrw.h"
-/* Global interface bytes */
-#define TA1 (tpb[0][0])
-#define TB1 (tpb[0][1])
-#define TC1 (tpb[0][2])
-#define TD1 (tpb[0][3])
-#define TC2 (tpb[1][2])
-#define TA2 (tpb[1][0])
-
/* external variable */
#ifdef BYTECOUNT
extern int num_getc, num_putc;
@@ -40,10 +32,6 @@ extern int num_getc, num_putc;
struct scparam scparam[4];
-#ifndef NO_T_EQ_1
-int todos_scioT1(int ttyn, int cla, int ins, int p1, int p2, int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *sw1p, int *sw2p);
-#endif
-
/* reset the card, and return answer to reset (atr) */
int
@@ -77,7 +65,7 @@ todos_scxreset(int ttyn, int flags, unsigned char *atr, int *ep)
}
/* 7816-3 sec 5.2 says >= 40000 clock cycles, ~=12 msec */
- todos_scsleep(20);
+ scsleep(20);
todos_scdtr(ttyn, !(flags & SCRTODOS));
@@ -97,9 +85,9 @@ todos_scioproc(int ttyn, int io, unsigned char *cp)
/* Wait extra guard time if needed */
if (!io && scparam[ttyn].n)
- todos_scsleep(((scparam[ttyn].n * scparam[ttyn].etu) + 999) / 1000);
+ scsleep(((scparam[ttyn].n * scparam[ttyn].etu) + 999) / 1000);
- code = (!io ? todos_scputc(ttyn, *cp) : todos_scgetc(ttyn, cp, scparam[ttyn].cwt));
+ code = (!io ? scputc(ttyn, *cp) : scgetc(ttyn, cp, scparam[ttyn].cwt));
return code;
}
@@ -111,7 +99,7 @@ static int
todos_scioT0(int ttyn, int io, int cla, int ins, int p1, int p2, int p3, unsigned char *buf, int *sw1p, int *sw2p)
{
int n = 0, ack, ackxins;
- unsigned char *bp = buf, c;
+ unsigned char *bp = buf, c, apdu[5];
#ifdef BYTECOUNT
int tmp_num_getc, tmp_num_putc;
#endif /* BYTECOUNT */
@@ -128,12 +116,13 @@ todos_scioT0(int ttyn, int io, int cla, int ins, int p1, int p2, int p3, unsigne
#ifdef DEBUG
printf("scioT0 %3s %02x %02x %02x %02x %02x\n", io ? "out" : "in", cla, ins, p1, p2, p3);
#endif
-
- c = cla; todos_scioproc(ttyn, 0, &c);
- c = ins; todos_scioproc(ttyn, 0, &c);
- c = p1; todos_scioproc(ttyn, 0, &c);
- c = p2; todos_scioproc(ttyn, 0, &c);
- c = p3; todos_scioproc(ttyn, 0, &c);
+
+ apdu[0] = cla;
+ apdu[1] = ins;
+ apdu[2] = p1;
+ apdu[3] = p2;
+ apdu[4] = p3;
+ scputblk(ttyn, apdu, 5);
#ifdef SCPERF
SetTime("Finish sending APDU");
@@ -141,7 +130,7 @@ todos_scioT0(int ttyn, int io, int cla, int ins, int p1, int p2, int p3, unsigne
while (1) {
/* read ack byte; see 7816-3 8.2.2 */
- if (todos_scgetc(ttyn, &c, scparam[ttyn].cwt) != SCEOK) {
+ if (scgetc(ttyn, &c, scparam[ttyn].cwt) != SCEOK) {
#ifdef DEBUG
printf("%d ms timeout reading ack\n", scparam[ttyn].cwt);
#endif
@@ -160,7 +149,7 @@ todos_scioT0(int ttyn, int io, int cla, int ins, int p1, int p2, int p3, unsigne
if ((ack & 0xf0) == 0x60 || (ack & 0xf0) == 0x90) {
/* SW1; get SW2 and return */
*sw1p = ack;
- if (todos_scgetc(ttyn, &c, scparam[ttyn].cwt) != SCEOK) {
+ if (scgetc(ttyn, &c, scparam[ttyn].cwt) != SCEOK) {
#ifdef DEBUG
printf("%d ms timeout reading sw2\n", scparam[ttyn].cwt);
#endif
@@ -215,7 +204,7 @@ todos_scioT0(int ttyn, int io, int cla, int ins, int p1, int p2, int p3, unsigne
#ifdef BYTECOUNT
tmp_num_putc = num_putc - tmp_num_putc;
tmp_num_getc = num_getc - tmp_num_getc - tmp_num_putc;
- MESSAGE3("#getc=%d, #putc=%d\n", tmp_num_getc, tmp_num_putc);
+ MESSAGE3("#getc=%d, #putc=%d\n", tmp_num_getc, tmp_num_putc);
#endif /* BYTECOUNT */
return n;
@@ -240,7 +229,7 @@ todos_scrw(int ttyn, int cla, int ins, int p1, int p2, int ilen, unsigned char *
}
#ifndef NO_T_EQ_1
} else if (scparam[ttyn].t == 1) {
- r = todos_scioT1(ttyn, cla, ins, p1, p2, ilen, ibuf, olen, obuf, sw1p, sw2p);
+ r = scioT1(ttyn, cla, ins, p1, p2, ilen, ibuf, olen, obuf, sw1p, sw2p);
#endif
} else
r = -1;
@@ -253,27 +242,27 @@ copyright 1997, 1999, 2000
the regents of the university of michigan
all rights reserved
-permission is granted to use, copy, create derivative works
-and redistribute this software and such derivative works
-for any purpose, so long as the name of the university of
-michigan is not used in any advertising or publicity
-pertaining to the use or distribution of this software
-without specific, written prior authorization. if the
-above copyright notice or any other identification of the
-university of michigan is included in any copy of any
-portion of this software, then the disclaimer below must
+permission is granted to use, copy, create derivative works
+and redistribute this software and such derivative works
+for any purpose, so long as the name of the university of
+michigan is not used in any advertising or publicity
+pertaining to the use or distribution of this software
+without specific, written prior authorization. if the
+above copyright notice or any other identification of the
+university of michigan is included in any copy of any
+portion of this software, then the disclaimer below must
also be included.
-this software is provided as is, without representation
-from the university of michigan as to its fitness for any
-purpose, and without warranty by the university of
-michigan of any kind, either express or implied, including
-without limitation the implied warranties of
-merchantability and fitness for a particular purpose. the
-regents of the university of michigan shall not be liable
-for any damages, including special, indirect, incidental, or
-consequential damages, with respect to any claim arising
-out of or in connection with the use of the software, even
-if it has been or is hereafter advised of the possibility of
+this software is provided as is, without representation
+from the university of michigan as to its fitness for any
+purpose, and without warranty by the university of
+michigan of any kind, either express or implied, including
+without limitation the implied warranties of
+merchantability and fitness for a particular purpose. the
+regents of the university of michigan shall not be liable
+for any damages, including special, indirect, incidental, or
+consequential damages, with respect to any claim arising
+out of or in connection with the use of the software, even
+if it has been or is hereafter advised of the possibility of
such damages.
*/
diff --git a/lib/libsectok/sectok.h b/lib/libsectok/sectok.h
index b1e487a73b6..6e8e8aaeb71 100644
--- a/lib/libsectok/sectok.h
+++ b/lib/libsectok/sectok.h
@@ -1,7 +1,7 @@
/*
* See copyright notice at end of file
*
- * $Id: sectok.h,v 1.1 2001/06/07 15:17:33 rees Exp $
+ * $Id: sectok.h,v 1.2 2001/06/07 20:19:43 rees Exp $
*/
/* SCPERF - performance evaluation */
diff --git a/lib/libsectok/todos_atr.c b/lib/libsectok/todos_atr.c
index 1619da0548b..70dbdae3dcd 100644
--- a/lib/libsectok/todos_atr.c
+++ b/lib/libsectok/todos_atr.c
@@ -5,7 +5,7 @@
*
* Jim Rees, University of Michigan CITI
*/
-static char *rcsid = "$Id: todos_atr.c,v 1.2 2001/06/07 16:10:00 rees Exp $";
+static char *rcsid = "$Id: todos_atr.c,v 1.3 2001/06/07 20:19:43 rees Exp $";
#ifdef __palmos__
#include <Common.h>
@@ -128,7 +128,7 @@ static struct bps {
};
-#define SCGETC if (todos_scgetc(ttyn, ap, (len ? BYTETIME : ATRTIME)) != SCEOK) goto timedout; else len++
+#define SCGETC if (scgetc(ttyn, ap, (len ? BYTETIME : ATRTIME)) != SCEOK) goto timedout; else len++
int
todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param)
@@ -266,9 +266,9 @@ todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param)
pps[3] ^= pps[j];
for (j = 0; j < 4; j++)
- todos_scputc(ttyn, pps[j]);
+ scputc(ttyn, pps[j]);
for (j = 0; j < 4; j++)
- if (todos_scgetc(ttyn, &c, 100) != SCEOK || c != pps[j])
+ if (scgetc(ttyn, &c, 100) != SCEOK || c != pps[j])
break;
if (j != 4)
continue;
diff --git a/lib/libsectok/todos_scrw.h b/lib/libsectok/todos_scrw.h
index ccc3b0e0a00..80882168413 100644
--- a/lib/libsectok/todos_scrw.h
+++ b/lib/libsectok/todos_scrw.h
@@ -1,13 +1,21 @@
/*
* See copyright notice at end of file
*
- * $Id: todos_scrw.h,v 1.2 2001/06/07 16:10:01 rees Exp $
+ * $Id: todos_scrw.h,v 1.3 2001/06/07 20:19:43 rees Exp $
*/
extern unsigned char todos_scinvert[];
/* forward declarations */
+int scgetc(int ttyn, unsigned char *cp, int ms);
+int scputc(int ttyn, int ic);
+int scputblk(int ttyn, unsigned char *bp, int n);
+void scsleep(int ms);
+int scioT1(int ttyn, 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 ttyn, int ilen, unsigned char *ibuf, unsigned char *obuf);
+int scioT1pkt(int ttyn, unsigned char *ibuf, unsigned char *obuf);
+
int todos_scopen(int ttyn, int flags, int *ep);
int todos_scsetflags(int ttyn, int flags, int mask);
int todos_scsetspeed(int ttyn, int speed);
@@ -17,14 +25,7 @@ int todos_scdsr(int ttyn);
int todos_scclose(int ttyn);
int todos_scxreset(int ttyn, int flags, unsigned char *atr, int *ep);
int todos_scdtr(int ttyn, int cmd);
-int todos_scgetc(int ttyn, unsigned char *cp, int ms);
-int todos_scputc(int ttyn, int ic);
-int todos_scputblk(int ttyn, unsigned char *bp, int n);
-void todos_scsleep(int ms);
void todos_scdrain(int ttyn);
-int todos_scioT1(int ttyn, int cla, int ins, int p1, int p2, int ilen, unsigned char *ibuf, int olen, unsigned char *obuf, int *sw1p, int *sw2p);
-int todos_scioT1Iblk(int ttyn, int ilen, unsigned char *ibuf, unsigned char *obuf);
-int todos_scioT1pkt(int ttyn, unsigned char *ibuf, unsigned char *obuf);
int todos_get_atr(int ttyn, int flags, unsigned char *atr, struct scparam *param);
/*