1 | #ifdef COOL
|
---|
2 | /*
|
---|
3 | ifd_cool.c
|
---|
4 | This module provides IFD handling functions for Coolstream internal reader.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <stdio.h>
|
---|
8 | #include <time.h>
|
---|
9 | #include <string.h>
|
---|
10 | #include"ifd_cool.h"
|
---|
11 | #include"../globals.h"
|
---|
12 | #include"icc_async.h"
|
---|
13 |
|
---|
14 | void * handle;
|
---|
15 |
|
---|
16 | unsigned char cardbuffer[256];
|
---|
17 | int cardbuflen = 0;
|
---|
18 |
|
---|
19 | int Cool_Init (char *device)
|
---|
20 | {
|
---|
21 | int reader_nb = 0;
|
---|
22 | if (cnxt_kal_initialize ())
|
---|
23 | return FALSE;
|
---|
24 |
|
---|
25 | if (cnxt_drv_init ())
|
---|
26 | return FALSE;
|
---|
27 |
|
---|
28 | if (cnxt_smc_init (NULL) != 1)
|
---|
29 | return FALSE;
|
---|
30 |
|
---|
31 | // this is to stay compatible with olfer config.
|
---|
32 | if(!strlen(device))
|
---|
33 | reader_nb=0;
|
---|
34 | else
|
---|
35 | reader_nb=atoi((const char *)device);
|
---|
36 | if(reader_nb>1) {
|
---|
37 | // there are only 2 readers in the coolstream : 0 or 1
|
---|
38 | cs_log("Coolstream reader device can only be 0 or 1");
|
---|
39 | return FALSE;
|
---|
40 | }
|
---|
41 | if (cnxt_smc_open (&handle, &reader_nb))
|
---|
42 | return FALSE;
|
---|
43 |
|
---|
44 | return OK;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | int Cool_GetStatus (int * in)
|
---|
49 | {
|
---|
50 | int state;
|
---|
51 | call (cnxt_smc_get_state(handle, &state));
|
---|
52 | //state = 0 no card, 1 = not ready, 2 = ready
|
---|
53 | if (state)
|
---|
54 | *in = 1; //CARD, even if not ready report card is in, or it will never get activated
|
---|
55 | else
|
---|
56 | *in = 0; //NOCARD
|
---|
57 | return OK;
|
---|
58 | }
|
---|
59 |
|
---|
60 | int Cool_Reset (ATR * atr)
|
---|
61 | {
|
---|
62 | call (Cool_SetClockrate(357));
|
---|
63 |
|
---|
64 | //reset card
|
---|
65 | int timeout = 5000; // Timout in ms?
|
---|
66 | call (cnxt_smc_reset_card (handle, ATR_TIMEOUT, NULL, NULL));
|
---|
67 |
|
---|
68 | cs_sleepms(50);
|
---|
69 |
|
---|
70 | int n = 40;
|
---|
71 | unsigned char buf[40];
|
---|
72 | call (cnxt_smc_get_atr (handle, buf, &n));
|
---|
73 |
|
---|
74 | call (!ATR_InitFromArray (atr, buf, n) == ATR_OK);
|
---|
75 | {
|
---|
76 | cs_sleepms(50);
|
---|
77 | return OK;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | int Cool_Transmit (BYTE * sent, unsigned size)
|
---|
82 | {
|
---|
83 | cardbuflen = 256;//it needs to know max buffer size to respond?
|
---|
84 | call (cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, 50, 0));
|
---|
85 | //call (cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, read_timeout, 0));
|
---|
86 | cs_ddump(sent, size, "COOL IO: Transmit: ");
|
---|
87 | return OK;
|
---|
88 | }
|
---|
89 |
|
---|
90 | int Cool_Receive (BYTE * data, unsigned size)
|
---|
91 | {
|
---|
92 | if (size > cardbuflen)
|
---|
93 | size = cardbuflen; //never read past end of buffer
|
---|
94 | memcpy(data,cardbuffer,size);
|
---|
95 | cardbuflen -= size;
|
---|
96 | memmove(cardbuffer,cardbuffer+size,cardbuflen);
|
---|
97 | cs_ddump(data, size, "COOL IO: Receive: ");
|
---|
98 | return OK;
|
---|
99 | }
|
---|
100 |
|
---|
101 | int Cool_SetClockrate (int mhz)
|
---|
102 | {
|
---|
103 | typedef unsigned long u_int32;
|
---|
104 | u_int32 clk;
|
---|
105 | clk = mhz * 10000;
|
---|
106 | call (cnxt_smc_set_clock_freq (handle, clk));
|
---|
107 | cs_debug("COOL: Clock succesfully set to %i0 kHz", mhz);
|
---|
108 | return OK;
|
---|
109 | }
|
---|
110 |
|
---|
111 | int Cool_WriteSettings (unsigned long BWT, unsigned long CWT, unsigned long EGT, unsigned long BGT)
|
---|
112 | {
|
---|
113 | //this code worked with old cnxt_lnx.ko, but prevented nagra cards from working with new cnxt_lnx.ko
|
---|
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 |
|
---|
134 | int 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
|
---|