source: trunk/csctapi/ifd_cool.c@ 3181

Last change on this file since 3181 was 3181, checked in by dingo35, 10 years ago

Adding threadsafety FIXMEs, feel free to join checking..

File size: 3.3 KB
Line 
1//FIXME Not checked on threadsafety yet; after checking please remove this line
2#ifdef COOL
3/*
4 ifd_cool.c
5 This module provides IFD handling functions for Coolstream internal reader.
6*/
7
8#include <stdio.h>
9#include <time.h>
10#include <string.h>
11#include"ifd_cool.h"
12#include"../globals.h"
13#include"icc_async.h"
14
15void * handle;
16
17unsigned char cardbuffer[256];
18int cardbuflen = 0;
19
20int Cool_Init (char *device)
21{
22 int reader_nb = 0;
23 if (cnxt_kal_initialize ())
24 return FALSE;
25
26 if (cnxt_drv_init ())
27 return FALSE;
28
29 if (cnxt_smc_init (NULL) != 1)
30 return FALSE;
31
32 // this is to stay compatible with olfer config.
33 if(!strlen(device))
34 reader_nb=0;
35 else
36 reader_nb=atoi((const char *)device);
37 if(reader_nb>1) {
38 // there are only 2 readers in the coolstream : 0 or 1
39 cs_log("Coolstream reader device can only be 0 or 1");
40 return FALSE;
41 }
42 if (cnxt_smc_open (&handle, &reader_nb))
43 return FALSE;
44
45 return OK;
46}
47
48
49int Cool_GetStatus (int * in)
50{
51 int state;
52 call (cnxt_smc_get_state(handle, &state));
53 //state = 0 no card, 1 = not ready, 2 = ready
54 if (state)
55 *in = 1; //CARD, even if not ready report card is in, or it will never get activated
56 else
57 *in = 0; //NOCARD
58 return OK;
59}
60
61int Cool_Reset (ATR * atr)
62{
63 call (Cool_SetClockrate(357));
64
65 //reset card
66 int timeout = 5000; // Timout in ms?
67 call (cnxt_smc_reset_card (handle, ATR_TIMEOUT, NULL, NULL));
68
69 cs_sleepms(50);
70
71 int n = 40;
72 unsigned char buf[40];
73 call (cnxt_smc_get_atr (handle, buf, &n));
74
75 call (!ATR_InitFromArray (atr, buf, n) == ATR_OK);
76 {
77 cs_sleepms(50);
78 return OK;
79 }
80}
81
82int Cool_Transmit (BYTE * sent, unsigned size)
83{
84 cardbuflen = 256;//it needs to know max buffer size to respond?
85 call (cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, 50, 0));
86 //call (cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, read_timeout, 0));
87 cs_ddump(sent, size, "COOL IO: Transmit: ");
88 return OK;
89}
90
91int Cool_Receive (BYTE * data, unsigned size)
92{
93 if (size > cardbuflen)
94 size = cardbuflen; //never read past end of buffer
95 memcpy(data,cardbuffer,size);
96 cardbuflen -= size;
97 memmove(cardbuffer,cardbuffer+size,cardbuflen);
98 cs_ddump(data, size, "COOL IO: Receive: ");
99 return OK;
100}
101
102int Cool_SetClockrate (int mhz)
103{
104 typedef unsigned long u_int32;
105 u_int32 clk;
106 clk = mhz * 10000;
107 call (cnxt_smc_set_clock_freq (handle, clk));
108 cs_debug("COOL: Clock succesfully set to %i0 kHz", mhz);
109 return OK;
110}
111
112int Cool_WriteSettings (unsigned long BWT, unsigned long CWT, unsigned long EGT, unsigned long BGT)
113{
114 struct
115 {
116 unsigned short CardActTime; //card activation time (in clock cycles = 1/54Mhz)
117 unsigned short CardDeactTime; //card deactivation time (in clock cycles = 1/54Mhz)
118 unsigned short ATRSTime; //ATR first char timeout in clock cycles (1/f)
119 unsigned short ATRDTime; //ATR duration in ETU
120 unsigned long BWT;
121 unsigned long CWT;
122 unsigned char EGT;
123 unsigned char BGT;
124 } params;
125 params.BWT = BWT;
126 params.CWT = CWT;
127 params.EGT = EGT;
128 params.BGT = BGT;
129 call (cnxt_smc_set_config_timeout(handle, params));
130 cs_debug("COOL WriteSettings OK");
131 return OK;
132}
133
134int Cool_FastReset ()
135{
136 int n = 40;
137 unsigned char buf[40];
138
139 //reset card
140 call (cnxt_smc_reset_card (handle, ATR_TIMEOUT, NULL, NULL));
141
142 cs_sleepms(50);
143
144 call (cnxt_smc_get_atr (handle, buf, &n));
145
146 return 0;
147}
148
149#endif
Note: See TracBrowser for help on using the repository browser.