source: branches/monitor-improvement/csctapi/ifd_cool.c@ 1189

Last change on this file since 1189 was 1189, checked in by alno, 12 years ago

WebIf:

  • Merging revisions 1180-1185 of trunk
  • Property svn:executable set to *
File size: 2.4 KB
Line 
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
12#define OK 1
13#define ERROR 0
14
15void * handle;
16
17unsigned char cardbuffer[256];
18int cardbuflen = 0;
19
20int Cool_Init ()
21{
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 int reader = 0;
32 if (cnxt_smc_open (&handle, &reader))
33 return FALSE;
34/*
35 if (Cool_SetBaudrate(mhz) != OK)
36 return ERROR;*/
37
38 return OK;
39}
40
41
42int Cool_GetStatus (int * in)
43{
44 int state;
45 if (cnxt_smc_get_state(handle, &state))
46 return ERROR;
47 //state = 0 no card, 1 = not ready, 2 = ready
48 if (state)
49 *in = 1; //CARD, even if not ready report card is in, or it will never get activated
50 else
51 *in = 0; //NOCARD
52 return OK;
53}
54
55int Cool_Reset (ATR ** atr)
56{
57 if (!Cool_SetBaudrate(357))
58 return ERROR;
59
60 //reset card
61 int timeout = 5000; // Timout in ms?
62 if (cnxt_smc_reset_card (handle, timeout, NULL, NULL))
63 return ERROR;
64
65 int n = 40;
66 unsigned char buf[40];
67 if (cnxt_smc_get_atr (handle, buf, &n))
68 return ERROR;
69
70 (*atr) = ATR_New ();
71 if(ATR_InitFromArray ((*atr), buf, n) == ATR_OK)
72 {
73 struct timespec req_ts;
74 req_ts.tv_sec = 0;
75 req_ts.tv_nsec = 50000000;
76 nanosleep (&req_ts, NULL);
77 return OK;
78 }
79 else
80 {
81 ATR_Delete (*atr);
82 (*atr) = NULL;
83 return ERROR;
84 }
85}
86
87int Cool_Transmit (BYTE * sent, unsigned size)
88{
89#define TIMEOUT 4000 //max 4294
90 cardbuflen = 256;//it needs to know max buffer size to respond?
91 if (cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, TIMEOUT, 0))
92 return ERROR;
93
94#ifdef DEBUG_IFD
95 //usually done in IFD_Towitoko, for COOL do it here
96 printf ("COOLIFD: Transmit: ");
97 int i;
98 for (i = 0; i < size; i++)
99 printf ("%X ", sent[i]);
100 printf ("\n");
101#endif
102 return OK;
103}
104
105int Cool_Receive (BYTE * data, unsigned size)
106{
107 if (size > cardbuflen)
108 size = cardbuflen; //never read past end of buffer
109 memcpy(data,cardbuffer,size);
110 cardbuflen -= size;
111 memmove(cardbuffer,cardbuffer+size,cardbuflen);
112
113#ifdef DEBUG_IFD
114 int i;
115 printf ("COOLIFD: Receive: "); //I think
116 for (i = 0; i < size; i++)
117 printf ("%X ", data[i]);
118 printf ("\n");
119 fflush(stdout);
120#endif
121 return OK;
122}
123
124int Cool_SetBaudrate (int mhz)
125{
126 typedef unsigned long u_int32;
127 u_int32 clk;
128 clk = mhz * 10000;
129 if (cnxt_smc_set_clock_freq (handle, clk))
130 return ERROR;
131 return OK;
132}
133#endif
Note: See TracBrowser for help on using the repository browser.