Changeset 489


Ignore:
Timestamp:
Nov 2, 2009, 8:22:16 PM (10 years ago)
Author:
Merlin
Message:

Removed CT_list, only 1 cardterminal is needed

Location:
branches/merlin
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • branches/merlin/csctapi/ctapi.c

    r346 r489  
    2727#include "ctapi.h"
    2828#include "ctbcs.h"
    29 #include "ct_list.h"
    3029#include "cardterminal.h"
    3130#include "ct_slot.h"
     
    4140
    4241/* Linked list of card-terminals */
    43 static CT_List *ct_list = NULL;
    44 
    45 #ifdef HAVE_PTHREAD_H
    46 static pthread_mutex_t ct_list_mutex = PTHREAD_MUTEX_INITIALIZER;
    47 #endif
     42static CardTerminal *ct = NULL;
    4843
    4944/*
     
    5146 */
    5247
    53 char CT_init(unsigned short ctn, char *device, unsigned long frequency, unsigned short reader_type)
     48char CT_init(char *device, unsigned long frequency, unsigned short reader_type)
    5449{
    55     CardTerminal *ct;
    5650    char ret;
    57     bool ct_list_empty;
    58 
    59 #ifdef HAVE_PTHREAD_H
    60     pthread_mutex_lock(&ct_list_mutex);
    61 #endif
    62 
    63     /* Check that ctn is not in use */
    64     if (CT_List_GetCardTerminal(ct_list, ctn) == NULL) {
     51
     52    /* Check if card terminal is initialized */
     53    if (ct == NULL) {
    6554        /* Create a new CardTerminal */
    6655        ct = CardTerminal_New();
     
    7160
    7261            /* Add CardTerminal to list */
    73             if (ret == OK) {
    74                 /* See if list is initialised */
    75                 ct_list_empty = (ct_list == NULL);
    76 
    77                 if (ct_list_empty)
    78                     ct_list = CT_List_New();
    79 
    80                 /* Add the CardTerminal to the list */
    81                 if (!CT_List_AddCardTerminal(ct_list, ct, ctn)) {
    82                     CardTerminal_Close(ct);
    83                     CardTerminal_Delete(ct);
    84 
    85                     if (ct_list_empty) {
    86                         CT_List_Delete(ct_list);
    87                         ct_list = NULL;
    88                     }
    89 
    90                     ret = ERR_MEMORY;
    91                 }
    92             } else {
     62            if (ret != OK) {
    9363                CardTerminal_Delete(ct);
    9464            }
     
    10070    }
    10171
    102 #ifdef HAVE_PTHREAD_H
    103     pthread_mutex_unlock(&ct_list_mutex);
    104 #endif
    105 
    106 #ifdef DEBUG_CTAPI
    107     printf("CTAPI: CT_init(ctn=%u, device=%s)=%d\n", ctn, device, ret);
     72#ifdef DEBUG_CTAPI
     73    printf("CTAPI: CT_init(device=%s)=%d\n", device, ret);
    10874#endif
    10975
     
    11177}
    11278
    113 char CT_close(unsigned short ctn)
     79char CT_close()
    11480{
    115     CardTerminal *ct;
    11681    char ret;
    117 
    118 #ifdef HAVE_PTHREAD_H
    119     pthread_mutex_lock(&ct_list_mutex);
    120 #endif
    121 
    122     /* Get the card-terminal */
    123     ct = CT_List_GetCardTerminal(ct_list, ctn);
    12482
    12583    if (ct != NULL) {
    12684        /* Close CardTerminal */
    12785        ret = CardTerminal_Close(ct);
    128 
    129         /* Remove card-terminal from list */
    130         CT_List_RemoveCardTerminal(ct_list, ctn);
    131 
    132         /* Delete the list if there are no more card-terminals */
    133         if (CT_List_GetNumberOfElements(ct_list) == 0) {
    134             CT_List_Delete(ct_list);
    135             ct_list = NULL;
    136         }
    13786    } else {
    13887        ret = ERR_CT;
    13988    }
    14089
    141 #ifdef HAVE_PTHREAD_H
    142     pthread_mutex_unlock(&ct_list_mutex);
    143 #endif
    144 
    145 #ifdef DEBUG_CTAPI
    146     printf("CTAPI: CT_close(ctn=%d)=%u\n", ctn, ret);
     90#ifdef DEBUG_CTAPI
     91    printf("CTAPI: CT_close()=%u\n", ret);
    14792#endif
    14893
     
    15095}
    15196
    152 char CT_data(unsigned short ctn, unsigned char *dad, unsigned char *sad, unsigned short lc, unsigned char *cmd, unsigned short *lr, unsigned char *rsp)
     97char CT_data(unsigned char *dad, unsigned char *sad, unsigned short lc, unsigned char *cmd, unsigned short *lr, unsigned char *rsp)
    15398{
    154     CardTerminal *ct;
    15599    CT_Slot *slot;
    156100    APDU_Cmd *apdu_cmd;
     
    163107    int i;
    164108
    165     printf("CTAPI: CT_data(ctn=%u, *dad=0x%02X, *sad=0x%02X, lc=%u, *cmd={", ctn, *dad, *sad, lc);
     109    printf("CTAPI: CT_data(*dad=0x%02X, *sad=0x%02X, lc=%u, *cmd={", *dad, *sad, lc);
    166110
    167111    for (i = 0; i < lc; i++)
     
    169113
    170114    printf("}, *lr=%u, rsp=[])\n", *lr);
    171 #endif
    172 
    173 #ifdef HAVE_PTHREAD_H
    174     pthread_mutex_lock(&ct_list_mutex);
    175 #endif
    176 
    177     /* Get card-terminal */
    178     ct = CT_List_GetCardTerminal(ct_list, ctn);
    179 
    180 #ifdef HAVE_PTHREAD_H
    181     pthread_mutex_unlock(&ct_list_mutex);
    182115#endif
    183116
     
    257190
    258191#ifdef DEBUG_CTAPI
    259     printf("CTAPI: CT_data(ctn=%u, *dad=0x%02X, *sad=0x%02X, lc=%u, *cmd={}, *lr=%u, rsp={", ctn, *dad, *sad, lc, *lr);
     192    printf("CTAPI: CT_data(*dad=0x%02X, *sad=0x%02X, lc=%u, *cmd={}, *lr=%u, rsp={", *dad, *sad, lc, *lr);
    260193
    261194    for (i = 0; i < *lr; i++)
  • branches/merlin/src/reader/serial.c

    r395 r489  
    1313#include "ctbcs.h"
    1414#include "defines.h"
    15 
    16 #define CTAPI_CTN 1
    1715
    1816int reader_serial_card_detect;      // UGLY : to be removed
     
    8482    /* Call CT-API */
    8583    ret = CT_data(
    86         CTAPI_CTN,  /* Terminal Number */
    8784        &dad,       /* Destination */
    8885        &sad,       /* Source */
     
    123120
    124121    /* Initialize CardTerminal */
    125     if ((ret = CT_init(CTAPI_CTN, reader->device, reader->frequency, reader_type)) != OK) {
     122    if ((ret = CT_init(reader->device, reader->frequency, reader_type)) != OK) {
    126123        log_normal("Reader: Cannot open device \"%s\" (%d) !", reader->device, ret);
    127124    }
Note: See TracChangeset for help on using the changeset viewer.