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

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

WebIf:

  • Merging with 1171 of trunk
  • Property svn:executable set to *
File size: 3.9 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"ifd_cool.h"
10/*
11#include "io_serial.h"
12#include "sci_global.h"
13#include "sci_ioctl.h"
14*/
15
16// these should be called from icc, t0, cardterminal etc. like this:
17// switch (reader[ridx].type) {
18// case INTERN:
19// #ifdef COOL
20// Cool_Init();
21// break;
22// #endif
23// #ifdef SCI_DEV
24// //still in towitoko shit
25// #endif
26// case SMART:
27// case MOUSE:
28// IFD_Towitoko_Init(ifd, io, slot);
29// break;
30// default:
31// return ERROR;
32// }
33// all other IFD_Towitoko functions should be
34// -eliminated (like SetLed or administrative jobs)
35// -rewritten eg. setparity should become a call to getproperties, setproperties
36// ActivateICC should call ResetICC automagically
37// DeactivateICC for symmetry and cleanup
38//
39
40#define OK 1
41#define ERROR 0
42
43void * handle;
44
45unsigned char cardbuffer[256];
46int cardbuflen = 0;
47
48int Cool_Init ()
49{
50 //initialize properties(input_bitrate, output_bitrate, bits, stopbits, parity,dtr, rts) of device to default values
51 //initialize ifd settings
52 //and get reader info
53 if (cnxt_kal_initialize ())
54 return FALSE;
55
56 if (cnxt_drv_init ())
57 return FALSE;
58
59 if (cnxt_smc_init (NULL) != 1)
60 return FALSE;
61
62 int reader = 0;
63 if (cnxt_smc_open (&handle, &reader))
64 return FALSE;
65/*
66 if (Cool_SetBaudrate(mhz) != OK)
67 return ERROR;*/
68
69 return OK;
70}
71
72/*
73int Cool_GetStatus (BYTE * result)
74{
75// return status : 0 -start, 1 - card, 2- no card
76
77 //extern int cnxt_smc_get_state();
78 return OK;
79}
80*/
81int Cool_Reset (ATR ** atr)
82{
83printf("Entering coolreset");
84fflush(stdout);
85 //reset needs clock to be reset by hand
86 typedef unsigned long u_int32;
87 u_int32 clk;
88 clk = 357*10000; // MHZ
89 if (cnxt_smc_set_clock_freq(handle, clk))
90 return ERROR;
91
92 //reset card
93 int timeout = 5000; // Timout in ms?
94 if (cnxt_smc_reset_card (handle, timeout, NULL, NULL))
95 return ERROR;
96
97 int n = 40;
98 //int atr_len = 40;
99 unsigned char buf[40];
100 if (cnxt_smc_get_atr (handle, buf, &n))
101 return ERROR;
102 //atr_len = n;
103// atr = buf;
104 /////////////
105 (*atr) = ATR_New ();
106 if(ATR_InitFromArray ((*atr), buf, n) == ATR_OK)
107 {
108 struct timespec req_ts;
109 req_ts.tv_sec = 0;
110 req_ts.tv_nsec = 50000000;
111 nanosleep (&req_ts, NULL);
112#ifdef SCI_DEV
113 if (ioctl(ifd->io->fd, IOCTL_SET_ATR_READY)<0)
114 return ERROR;
115#endif
116 return OK;
117 }
118 else
119 {
120 ATR_Delete (*atr);
121 (*atr) = NULL;
122 return ERROR;
123 }
124 ///////////
125}
126/*
127int Cool_DeactivateICC ()
128{
129#ifdef DEBUG_IFD
130 printf ("IFD: Deactivating card\n");
131#endif
132/*
133 int in;
134
135#if defined(TUXBOX) && (defined(MIPSEL) || defined(PPC) || defined(SH4))
136 if(ioctl(ifd->io->fd, IOCTL_GET_IS_CARD_PRESENT, &in)<0)
137#else
138 if(ioctl(ifd->io->fd, IOCTL_GET_IS_CARD_ACTIVATED, &in)<0)
139#endif
140 return IFD_TOWITOKO_IO_ERROR;
141
142 if(in)
143 {
144 if(ioctl(ifd->io->fd, IOCTL_SET_DEACTIVATE)<0)
145 return IFD_TOWITOKO_IO_ERROR;
146 }
147*/
148/*
149 return OK;
150}
151*/
152
153int Cool_Transmit (BYTE * sent, unsigned size)
154{
155#define TIMEOUT 4000 //max 4294
156 cardbuflen = 256;//it needs to know max buffer size to respond?
157 int rc = cnxt_smc_read_write(handle, FALSE, sent, size, cardbuffer, &cardbuflen, TIMEOUT, 0);
158
159#ifdef DEBUG_IFD
160 //usually done in IFD_Towitoko, for COOL do it here
161 printf ("COOLIFD: Transmit: ");
162 int i;
163 for (i = 0; i < size; i++)
164 printf ("%X ", sent[i]);
165 printf ("\n");
166#endif
167
168 //FIXME implement rc
169}
170
171int Cool_Receive (BYTE * buffer, unsigned size)
172{ //receive buffer to SC
173 //memcpy(buffer,cardbuffer,cardbuflen);
174 //size = cardbuflen;
175
176#ifdef DEBUG_IFD
177 int i;
178 printf ("IFD: Receive: "); //I think
179 for (i = 0; i < size; i++)
180 printf ("%X ", buffer[i]);
181 printf ("\n");
182#endif
183
184 return OK;
185}
186
187int Cool_SetBaudrate (int mhz)
188{
189 typedef unsigned long u_int32;
190 u_int32 clk;
191 //clk = 357 * 10000; // MHZ
192 clk = mhz * 10000; // MHZ
193 if (cnxt_smc_set_clock_freq (handle, clk))
194 return ERROR;
195 return OK;
196}
197#endif
Note: See TracBrowser for help on using the repository browser.