Changeset 489 for branches/merlin/csctapi/ctapi.c
- Timestamp:
- 11/02/09 20:22:16 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/merlin/csctapi/ctapi.c
r346 r489 27 27 #include "ctapi.h" 28 28 #include "ctbcs.h" 29 #include "ct_list.h"30 29 #include "cardterminal.h" 31 30 #include "ct_slot.h" … … 41 40 42 41 /* 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 42 static CardTerminal *ct = NULL; 48 43 49 44 /* … … 51 46 */ 52 47 53 char CT_init( unsigned short ctn,char *device, unsigned long frequency, unsigned short reader_type)48 char CT_init(char *device, unsigned long frequency, unsigned short reader_type) 54 49 { 55 CardTerminal *ct;56 50 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) { 65 54 /* Create a new CardTerminal */ 66 55 ct = CardTerminal_New(); … … 71 60 72 61 /* 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) { 93 63 CardTerminal_Delete(ct); 94 64 } … … 100 70 } 101 71 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); 108 74 #endif 109 75 … … 111 77 } 112 78 113 char CT_close( unsigned short ctn)79 char CT_close() 114 80 { 115 CardTerminal *ct;116 81 char ret; 117 118 #ifdef HAVE_PTHREAD_H119 pthread_mutex_lock(&ct_list_mutex);120 #endif121 122 /* Get the card-terminal */123 ct = CT_List_GetCardTerminal(ct_list, ctn);124 82 125 83 if (ct != NULL) { 126 84 /* Close CardTerminal */ 127 85 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 }137 86 } else { 138 87 ret = ERR_CT; 139 88 } 140 89 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); 147 92 #endif 148 93 … … 150 95 } 151 96 152 char CT_data(unsigned short ctn, unsignedchar *dad, unsigned char *sad, unsigned short lc, unsigned char *cmd, unsigned short *lr, unsigned char *rsp)97 char CT_data(unsigned char *dad, unsigned char *sad, unsigned short lc, unsigned char *cmd, unsigned short *lr, unsigned char *rsp) 153 98 { 154 CardTerminal *ct;155 99 CT_Slot *slot; 156 100 APDU_Cmd *apdu_cmd; … … 163 107 int i; 164 108 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); 166 110 167 111 for (i = 0; i < lc; i++) … … 169 113 170 114 printf("}, *lr=%u, rsp=[])\n", *lr); 171 #endif172 173 #ifdef HAVE_PTHREAD_H174 pthread_mutex_lock(&ct_list_mutex);175 #endif176 177 /* Get card-terminal */178 ct = CT_List_GetCardTerminal(ct_list, ctn);179 180 #ifdef HAVE_PTHREAD_H181 pthread_mutex_unlock(&ct_list_mutex);182 115 #endif 183 116 … … 257 190 258 191 #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); 260 193 261 194 for (i = 0; i < *lr; i++)
Note:
See TracChangeset
for help on using the changeset viewer.