LDLIBS += $(shell pkg-config --libs libpcsclite)
test_cr: test_cr.o pcsc_cr.o ykneo.o
+
+test_cr.o: pcsc_cr.h
+pcsc_cr.o: pcsc_cr.h token.h
+ykneo.o: token.h
+#include <stdio.h>
#include <string.h>
+#include <alloca.h>
#include "token.h"
#include <reader.h>
char *pcsc_errstr(long err) {
return pcsc_stringify_error(err);
}
+
+int pcsc_option(char *option)
+{
+ char *name, *key, *val;
+ int i, rc = -1;
+ struct token_interface *type;
+
+ name=(char *)alloca(strlen(option)+1);
+ strcpy(name, option);
+ if ((key = strchr(name, ':'))) *(key++) = '\0';
+ else return -1;
+ if ((val = strchr(key, '='))) *(val++) = '\0';
+ else return -1;
+ if (*val == '\0') return -1;
+ for (i = 0; types[i]; i++) {
+ type = types[i];
+ if (!strcmp(type->name,name)) {
+ rc = type->parse_option(key, val);
+ break;
+ }
+ }
+ return rc;
+}
#ifndef _PCSC_CR_H
#define _PCSC_CR_H
+int pcsc_option(char *option);
long pcsc_cr(unsigned char *chal, int csize, unsigned char *resp, int *rsize);
char *pcsc_errstr(long err);
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
#include "pcsc_cr.h"
char chal[] = {
0x0f,0x65,0xd1,0x3a,0xfe,0xcb,0xc4,0xb9,0x52,0xb1,0x60,0xcf,0xe8,0x55,0x6a,0xdd,0xfb,0xef,0xf6,0x55,0x83,0x4c,0x8d,0xea,0x38,0xea,0x3b,0x26,0xf7,0x0a,0xe8,0x0d,0x31,0x38,0xee,0x16,0x5d,0xab,0x8b,0x7f,0xf0,0x1b,0xe3,0xbe,0xd8,0x4b,0x6e,0x44,0x42,0x8d,0x0f,0xc1,0x3b,0x23,0xea,0xfe,0xc0,0x68,0xc1,0x0f,0x60,0x6c,0xf4};
+static void usage(const char const *cmd)
+{
+ fprintf(stderr, "usage: %s [-o backend:name=value] ...\n", cmd);
+}
+
int main(int argc, char *argv[])
{
unsigned char rbuf[20];
int rsize = sizeof(rbuf);
int i;
long rc;
+ int c;
+
+ while ((c = getopt(argc, argv, "ho:")) != -1) switch (c) {
+ case 'h':
+ usage(argv[0]);
+ exit(0);
+ case 'o':
+ if (pcsc_option(optarg)) {
+ fprintf(stderr, "Option \"%s\" bad\n", optarg);
+ exit(1);
+ }
+ break;
+ default:
+ usage(argv[0]);
+ exit(1);
+ }
memset(rbuf, 0xFE, sizeof(rbuf));
rc = pcsc_cr(chal, sizeof(chal), rbuf, &rsize);
extern SCARD_IO_REQUEST pioSendPci;
struct token_interface {
+ char *name;
+ int (*parse_option)(char *key, char *val);
DWORD (*check_atr_hb)(LPTSTR str, DWORD size);
DWORD (*prologue)(SCARDHANDLE hCard,LPTSTR envp[]);
DWORD (*trancieve)(SCARDHANDLE hCard,LPTSTR envp[],
+#include <stdlib.h>
#include <string.h>
#include <alloca.h>
static const BYTE selcmd[] = {0x00, 0xA4, 0x04, 0x00, 0x07, 0xA0,
0x00, 0x00, 0x05, 0x27, 0x20, 0x01, 0x00};
-static const BYTE cr_cmd[] = {0x00, 0x01, 0x38, 0x00};
+static const BYTE cr_cmd[] = {0x00, 0x01, 0xff, 0x00};
+
+static BYTE cr_for_slot[3] = {0xff, 0x30, 0x38};
+
+static int slot;
+
+static int ykn_parse_option(char *key, char *val)
+{
+ if (!strcmp(key, "slot")) {
+ if (!strcmp(val, "1")) {
+ slot = 1;
+ } else if (!strcmp(val, "2")) {
+ slot = 2;
+ } else {
+ return -1;
+ }
+ } else {
+ return -1;
+ }
+ return 0;
+}
static DWORD ykn_check_atr_hb(LPTSTR str, DWORD size)
{
BYTE *rbuf = alloca(rsize);
BYTE *sbuf = alloca(sendsize + 6);
memcpy(sbuf, cr_cmd, sizeof(cr_cmd));
+ sbuf[2] = cr_for_slot[slot];
sbuf[sizeof(cr_cmd)] = sendsize;
memcpy(sbuf + sizeof(cr_cmd) + 1, send, sendsize);
sbuf[sendsize + 5] = rsize;
}
struct token_interface ykneo_interface = {
+ .name = "ykneo",
+ .parse_option = ykn_parse_option,
.check_atr_hb = ykn_check_atr_hb,
.prologue = ykn_prologue,
.trancieve = ykn_trancieve,