Permalink
Browse files

- Added support for CT-API

- Improved config file loading
- Implemented ATR parsing


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@396 c6295689-39f2-0310-b995-f0e70906c6a9
  • Loading branch information...
1 parent b2d2bc7 commit 59d4e9b7bee8de5fa321d86d2c3b65a4a7fdc75e jey committed Mar 26, 2002
@@ -38,7 +38,21 @@ app default {
#
# reader_drivers = pcsc, ctapi;
- # What reader drivers to load at start-up
+ reader_driver ctapi {
+ module /usr/local/towitoko/lib/libtowitoko.so {
+ # CT-API ports:
+ # 0..3 COM1..4
+ # 4 Printer
+ # 5 Modem
+ # 6..7 LPT1..2
+ ports = 0;
+ }
+ # module /usr/local/lib/ctapi/ctapi2.so {
+ # ports = 1, 6;
+ # }
+ }
+
+ # What card drivers to load at start-up
#
# A special value of 'internal' will load all
# statically linked drivers. If an unknown (ie. not
@@ -21,7 +21,7 @@ libopensc_la_SOURCES = sc.c ctx.c asn1.c base64.c sec.c log.c \
card.c iso7816.c dir.c \
pkcs15.c pkcs15-cert.c pkcs15-pin.c \
pkcs15-prkey.c pkcs15-pubkey.c pkcs15-sec.c \
- pkcs15-cache.c $(PCSC_SRC) \
+ pkcs15-cache.c $(PCSC_SRC) reader-ctapi.c \
card-setcos.c card-miocos.c card-flex.c card-gpk.c \
card-tcos.c card-emv.c card-default.c
libopensc_la_LDFLAGS = -version-info 0:6:0
View
@@ -0,0 +1,151 @@
+/*
+ CT-BCS commands, responses and parameters for terminals
+ without keypad and display.
+
+ This file is part of the Unix driver for Towitoko smartcard readers
+ Copyright (C) 1998 1999 2000 Carlos Prados <cprados@yahoo.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef _CTBCS_
+#define _CTBCS_
+
+/*
+ * Command and response size
+ */
+#define CTBCS_MIN_COMMAND_SIZE 2
+#define CTBCS_MIN_RESPONSE_SIZE 2
+
+/*
+ * Class byte of all CTBCS commands
+ */
+#define CTBCS_CLA 0x20
+
+/*
+ * Mandatory CT-BCS commands
+ */
+#define CTBCS_INS_RESET 0x11 /* Reset CT */
+#define CTBCS_INS_REQUEST 0x12 /* Request ICC */
+#define CTBCS_INS_STATUS 0x13 /* Get reader status */
+#define CTBCS_INS_EJECT 0x15 /* Eject ICC */
+
+/*
+ * P1 parameter: functional units
+ */
+
+#define CTBCS_P1_CT_KERNEL 0x00
+#define CTBCS_P1_INTERFACE1 0x01
+#define CTBCS_P1_INTERFACE2 0x02
+#define CTBCS_P1_INTERFACE3 0x03
+#define CTBCS_P1_INTERFACE4 0x04
+#define CTBCS_P1_INTERFACE5 0x05
+#define CTBCS_P1_INTERFACE6 0x06
+#define CTBCS_P1_INTERFACE7 0x07
+#define CTBCS_P1_INTERFACE8 0x08
+#define CTBCS_P1_INTERFACE9 0x09
+#define CTBCS_P1_INTERFACE10 0x0A
+#define CTBCS_P1_INTERFACE11 0x0B
+#define CTBCS_P1_INTERFACE12 0x0C
+#define CTBCS_P1_INTERFACE13 0x0D
+#define CTBCS_P1_INTERFACE14 0x0E
+#define CTBCS_P1_DISPLAY 0x40
+#define CTBCS_P1_KEYPAD 0x50
+
+/*
+ * P2 parameter for Reset CT: data to be returned
+ */
+#define CTBCS_P2_RESET_NO_RESP 0x00 /* Return no data */
+#define CTBCS_P2_RESET_GET_ATR 0x01 /* Return complete ATR */
+#define CTBCS_P2_RESET_GET_HIST 0x02 /* Return historical bytes */
+
+/*
+ * P2 parameter for Request ICC: data to be returned
+ */
+#define CTBCS_P2_REQUEST_NO_RESP 0x00 /* Return no data */
+#define CTBCS_P2_REQUEST_GET_ATR 0x01 /* Return complete ATR */
+#define CTBCS_P2_REQUEST_GET_HIST 0x02 /* Return historical bytes */
+
+/*
+ * P2 parameter for Get status: TAG of data object to return
+ */
+#define CTBCS_P2_STATUS_MANUFACTURER 0x46 /* Return manufacturer DO */
+#define CTBCS_P2_STATUS_ICC 0x80 /* Return ICC DO */
+
+/*
+ * General return codes
+ */
+#define CTBCS_SW1_OK 0x90 /* Command successful */
+#define CTBCS_SW2_OK 0x00
+#define CTBCS_SW1_WRONG_LENGTH 0x67 /* Wrong length */
+#define CTBCS_SW2_WRONG_LENGTH 0x00
+#define CTBCS_SW1_COMMAND_NOT_ALLOWED 0x69 /* Command not allowed */
+#define CTBCS_SW2_COMMAND_NOT_ALLOWED 0x00
+#define CTBCS_SW1_WRONG_PARAM 0x6A /* Wrong parameters P1, P2 */
+#define CTBCS_SW2_WRONG_PARAM 0x00
+#define CTBCS_SW1_WRONG_INS 0x6D /* Wrong Instruction */
+#define CTBCS_SW2_WRONG_INS 0x00
+#define CTBCS_SW1_WRONG_CLA 0x6E /* Class not supported */
+#define CTBCS_SW2_WRONG_CLA 0x00
+#define CTBCS_SW1_ICC_ERROR 0x6F /* ICC removed, defective or */
+#define CTBCS_SW2_ICC_ERROR 0x00 /* no longer reacts */
+
+/*
+ * Return codes for Reset CT
+ */
+#define CTBCS_SW1_RESET_CT_OK 0x90 /* Reset CT successful */
+#define CTBCS_SW2_RESET_CT_OK 0x00
+#define CTBCS_SW1_RESET_SYNC_OK 0x90 /* Synchoronous ICC, */
+#define CTBCS_SW2_RESET_SYNC_OK 0x00 /* reset successful */
+#define CTBCS_SW1_RESET_ASYNC_OK 0x90 /* Asynchoronous ICC, */
+#define CTBCS_SW2_RESET_ASYNC_OK 0x01 /* reset successful */
+#define CTBCS_SW1_RESET_ERROR 0x64 /* Reset not successful */
+#define CTBCS_SW2_RESET_ERROR 0x00
+
+/*
+ * Return codes for Request ICC
+ */
+#define CTBCS_SW1_REQUEST_SYNC_OK 0x90 /* Synchoronous ICC, */
+#define CTBCS_SW2_REQUEST_SYNC_OK 0x00 /* reset successful */
+#define CTBCS_SW1_REQUEST_ASYNC_OK 0x90 /* Asynchoronous ICC, */
+#define CTBCS_SW2_REQUEST_ASYNC_OK 0x01 /* reset successful */
+#define CTBCS_SW1_REQUEST_NO_CARD 0x62 /* No card present */
+#define CTBCS_SW2_REQUEST_NO_CARD 0x00
+#define CTBCS_SW1_REQUEST_CARD_PRESENT 0x62 /* Card already present */
+#define CTBCS_SW2_REQUEST_CARD_PRESENT 0x01
+#define CTBCS_SW1_REQUEST_ERROR 0x64 /* Reset not successful */
+#define CTBCS_SW2_REQUEST_ERROR 0x00
+#define CTBCS_SW1_REQUEST_TIMER_ERROR 0x69 /* Timer not supported */
+#define CTBCS_SW2_REQUEST_TIMER_ERROR 0x00
+
+/*
+ * Return codes for Eject ICC
+ */
+#define CTBCS_SW1_EJECT_OK 0x90 /* Command succesful, */
+#define CTBCS_SW2_EJECT_OK 0x00
+#define CTBCS_SW1_EJECT_REMOVED 0x90 /* Command succesful, */
+#define CTBCS_SW2_EJECT_REMOVED 0x01 /* Card removed */
+#define CTBCS_SW1_EJECT_NOT_REMOVED 0x62 /* Card not removed */
+#define CTBCS_SW2_EJECT_NOT_REMOVED 0x00
+
+/*
+ * Data returned on Get Status command
+ */
+#define CTBCS_DATA_STATUS_NOCARD 0x00 /* No card present */
+#define CTBCS_DATA_STATUS_CARD 0x01 /* Card present */
+#define CTBCS_DATA_STATUS_CARD_CONNECT 0x05 /* Card present */
+
+#endif /* _CTBCS_ */
+
View
@@ -65,6 +65,7 @@ static const struct _sc_driver_entry internal_reader_drivers[] = {
#ifdef HAVE_LIBPCSCLITE
{ "pcsc", sc_get_pcsc_driver },
#endif
+ { "ctapi", sc_get_ctapi_driver },
{ NULL }
};
@@ -144,75 +145,61 @@ static void add_internal_drvs(struct _sc_ctx_options *opts, int type)
}
}
-static int load_parameters(struct sc_context *ctx, const char *app,
+static int load_parameters(struct sc_context *ctx, scconf_block *block,
struct _sc_ctx_options *opts)
{
- scconf_block **blocks = NULL;
- int i, err = 0;
-
- blocks = scconf_find_blocks(ctx->conf, NULL, "app", NULL);
- for (i = 0; blocks[i]; i++) {
- const scconf_block *block = blocks[i];
- const scconf_list *list;
- const char *s_internal = "internal", *val;
-
- if (strcmp(block->name->data, app))
- continue;
- val = scconf_get_str(block, "debug", NULL);
- if (val)
- sscanf(val, "%d", &ctx->debug);
- val = scconf_get_str(block, "debug_file", NULL);
- if (val) {
- if (ctx->debug_file && ctx->debug_file != stdout)
- fclose(ctx->debug_file);
- if (strcmp(val, "stdout") == 0)
- ctx->debug_file = fopen(val, "a");
- else
- ctx->debug_file = stdout;
- }
- val = scconf_get_str(block, "error_file", NULL);
- if (val) {
- if (ctx->error_file && ctx->error_file != stderr)
- fclose(ctx->error_file);
- if (strcmp(val, "stderr") != 0)
- ctx->error_file = fopen(val, "a");
- else
- ctx->error_file = stderr;
- }
-
- list = scconf_find_list(block, "reader_drivers");
- if (list == NULL) {
- if (opts->rcount == 0) /* Add the internal drivers */
- add_internal_drvs(opts, 0);
- } else
- del_drvs(opts, 0);
- while (list != NULL) {
- if (strcmp(list->data, s_internal) == 0)
- add_internal_drvs(opts, 1);
- else
- add_drv(opts, 0, list->data);
- list = list->next;
- }
- if (err)
- break;
+ int err = 0;
+ const scconf_list *list;
+ const char *val;
+ const char *s_internal = "internal";
+
+ ctx->debug = scconf_get_int(block, "debug", ctx->debug);
+ val = scconf_get_str(block, "debug_file", NULL);
+ if (val) {
+ if (ctx->debug_file && ctx->debug_file != stdout)
+ fclose(ctx->debug_file);
+ if (strcmp(val, "stdout") == 0)
+ ctx->debug_file = fopen(val, "a");
+ else
+ ctx->debug_file = stdout;
+ }
+ val = scconf_get_str(block, "error_file", NULL);
+ if (val) {
+ if (ctx->error_file && ctx->error_file != stderr)
+ fclose(ctx->error_file);
+ if (strcmp(val, "stderr") != 0)
+ ctx->error_file = fopen(val, "a");
+ else
+ ctx->error_file = stderr;
+ }
+ list = scconf_find_list(block, "reader_drivers");
+ if (list == NULL) {
+ if (opts->rcount == 0) /* Add the internal drivers */
+ add_internal_drvs(opts, 0);
+ } else
+ del_drvs(opts, 0);
+ while (list != NULL) {
+ if (strcmp(list->data, s_internal) == 0)
+ add_internal_drvs(opts, 1);
+ else
+ add_drv(opts, 0, list->data);
+ list = list->next;
+ }
- list = scconf_find_list(block, "card_drivers");
- if (list == NULL) {
- if (opts->ccount == 0) /* Add the internal drivers */
- add_internal_drvs(opts, 1);
- } else
- del_drvs(opts, 1);
- while (list != NULL) {
- if (strcmp(list->data, s_internal) == 0)
- add_internal_drvs(opts, 1);
- else
- add_drv(opts, 1, list->data);
- list = list->next;
- }
- if (err)
- break;
+ list = scconf_find_list(block, "card_drivers");
+ if (list == NULL) {
+ if (opts->ccount == 0) /* Add the internal drivers */
+ add_internal_drvs(opts, 1);
+ } else
+ del_drvs(opts, 1);
+ while (list != NULL) {
+ if (strcmp(list->data, s_internal) == 0)
+ add_internal_drvs(opts, 1);
+ else
+ add_drv(opts, 1, list->data);
+ list = list->next;
}
- free(blocks);
+
return err;
}
@@ -281,12 +268,39 @@ static int load_card_drivers(struct sc_context *ctx,
return 0;
}
+void process_config_file(struct sc_context *ctx, struct _sc_ctx_options *opts)
+{
+ int i, r, count = 0;
+ scconf_block **blocks;
+
+ ctx->conf = scconf_init(OPENSC_CONF_PATH);
+ if (ctx->conf == NULL)
+ return;
+ r = scconf_parse(ctx->conf);
+ if (r < 1) {
+ scconf_deinit(ctx->conf);
+ ctx->conf = NULL;
+ return;
+ }
+ blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->app_name);
+ if (blocks[0])
+ ctx->conf_blocks[count++] = blocks[0];
+ free(blocks);
+ if (strcmp(ctx->app_name, "default") != 0) {
+ blocks = scconf_find_blocks(ctx->conf, NULL, "app", "default");
+ if (blocks[0])
+ ctx->conf_blocks[count++] = blocks[0];
+ free(blocks);
+ }
+ for (i = 0; i < count; i++)
+ load_parameters(ctx, ctx->conf_blocks[i], opts);
+}
+
int sc_establish_context(struct sc_context **ctx_out, const char *app_name)
{
const char *default_app = "default";
struct sc_context *ctx;
struct _sc_ctx_options opts;
- int r;
assert(ctx_out != NULL);
ctx = malloc(sizeof(struct sc_context));
@@ -296,19 +310,7 @@ int sc_establish_context(struct sc_context **ctx_out, const char *app_name)
memset(&opts, 0, sizeof(opts));
set_defaults(ctx, &opts);
ctx->app_name = app_name ? strdup(app_name) : strdup(default_app);
- ctx->conf = scconf_init(OPENSC_CONF_PATH);
- if (ctx->conf) {
- r = scconf_parse(ctx->conf);
- if (r < 1) {
- scconf_deinit(ctx->conf);
- ctx->conf = NULL;
- } else {
- load_parameters(ctx, default_app, &opts);
- if (strcmp(default_app, ctx->app_name)) {
- load_parameters(ctx, ctx->app_name, &opts);
- }
- }
- }
+ process_config_file(ctx, &opts);
#ifdef HAVE_PTHREAD
pthread_mutex_init(&ctx->mutex, NULL);
#endif
@@ -43,6 +43,7 @@ int sc_check_sw(struct sc_card *card, int sw1, int sw2);
size_t _sc_count_bit_string_size(const void * buf, size_t bufsize);
int _sc_add_reader(struct sc_context *ctx, struct sc_reader *reader);
+int _sc_parse_atr(struct sc_context *ctx, struct sc_slot_info *slot);
struct sc_slot_info * _sc_get_slot_info(struct sc_reader *reader, int slot_id);
/* Returns an index number if a match was found, -1 otherwise. table has to
Oops, something went wrong.

0 comments on commit 59d4e9b

Please sign in to comment.