source: trunk/csctapi/ifd_sci.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.5 KB
Line 
1//FIXME Not checked on threadsafety yet; after checking please remove this line
2/*
3 ifd_sci.c
4 This module provides IFD handling functions for SCI internal reader.
5*/
6
7#include "ifd_sci.h"
8
9#ifdef SCI_DEV
10
11#include <stdio.h>
12#include <time.h>
13#include <sys/ioctl.h>
14#include "sci_global.h"
15#include "sci_ioctl.h"
16#include "string.h"
17#ifdef SH4
18#include <fcntl.h>
19#endif
20
21#define ATR_TIMEOUT 800
22
23#define OK 0
24#define ERROR 1
25
26int Sci_GetStatus (struct s_reader * reader, int * status)
27{
28 call (ioctl(reader->handle, IOCTL_GET_IS_CARD_PRESENT, status)<0);
29 return OK;
30}
31
32int Sci_Reset (struct s_reader * reader, ATR * atr)
33{
34 unsigned char buf[SCI_MAX_ATR_SIZE];
35 int n = 0;
36 SCI_PARAMETERS params;
37
38 memset(&params,0,sizeof(SCI_PARAMETERS));
39
40 params.ETU = 372;
41 params.EGT = 3; //not sure why this value is chosen
42 params.fs = 5;
43 params.T = 0;
44
45 call (ioctl(reader->handle, IOCTL_SET_PARAMETERS, &params)!=0);
46 call (ioctl(reader->handle, IOCTL_SET_RESET)<0);
47
48 while(n<SCI_MAX_ATR_SIZE && !IO_Serial_Read(reader, ATR_TIMEOUT, 1, buf+n))
49 {
50 n++;
51 }
52
53 if ((buf[0] !=0x3B) && (buf[0] != 0x3F) && (n>9 && !memcmp(buf+4, "IRDETO", 6))) //irdeto S02 reports FD as first byte on dreambox SCI, not sure about SH4 or phoenix
54 buf[0] = 0x3B;
55
56 if(n==0) {
57 cs_log("ERROR: 0 characters found in ATR");
58 return ERROR;
59 }
60 call(!ATR_InitFromArray (atr, buf, n) == ATR_OK);
61 {
62 cs_sleepms(50);
63 call (ioctl(reader->handle, IOCTL_SET_ATR_READY)<0);
64 return OK;
65 }
66}
67
68int Sci_WriteSettings (struct s_reader * reader, BYTE T, unsigned long fs, unsigned long ETU, unsigned long WWT, unsigned long BWT, unsigned long CWT, unsigned long EGT, unsigned char P, unsigned char I)
69{
70 //int n;
71 SCI_PARAMETERS params;
72 //memset(&params,0,sizeof(SCI_PARAMETERS));
73 call (ioctl(reader->handle, IOCTL_GET_PARAMETERS, &params) < 0 );
74
75 params.T = T;
76 params.fs = fs;
77
78 //for Irdeto T14 cards, do not set ETU
79 if (ETU)
80 params.ETU = ETU;
81 params.EGT = EGT;
82 params.WWT = WWT;
83 params.BWT = BWT;
84 params.CWT = CWT;
85 if (P)
86 params.P = P;
87 if (I)
88 params.I = I;
89
90 cs_debug("Setting T=%d fs=%lu mhz ETU=%d WWT=%d CWT=%d BWT=%d EGT=%d clock=%d check=%d P=%d I=%d U=%d", (int)params.T, params.fs, (int)params.ETU, (int)params.WWT, (int)params.CWT, (int)params.BWT, (int)params.EGT, (int)params.clock_stop_polarity, (int)params.check, (int)params.P, (int)params.I, (int)params.U);
91
92 call (ioctl(reader->handle, IOCTL_SET_PARAMETERS, &params)!=0);
93 return OK;
94}
95
96int Sci_Activate (struct s_reader * reader)
97{
98 cs_debug_mask(D_IFD, "IFD: Activating card");
99 int in;
100
101#if defined(TUXBOX) && (defined(MIPSEL) || defined(PPC) || defined(SH4))
102 call (ioctl(reader->handle, IOCTL_GET_IS_CARD_PRESENT, &in)<0);
103#else
104 call (ioctl(reader->handle, IOCTL_GET_IS_CARD_ACTIVATED, &in)<0);
105#endif
106
107 if(in)
108 cs_sleepms(50);
109 else
110 return ERROR;
111 return OK;
112}
113
114int Sci_Deactivate (struct s_reader * reader)
115{
116 cs_debug_mask(D_IFD, "IFD: Deactivating card");
117 int in;
118
119#if defined(TUXBOX) && (defined(MIPSEL) || defined(PPC) || defined(SH4))
120 call (ioctl(reader->handle, IOCTL_GET_IS_CARD_PRESENT, &in)<0);
121#else
122 call (ioctl(reader->handle, IOCTL_GET_IS_CARD_ACTIVATED, &in)<0);
123#endif
124
125 if(in)
126 call (ioctl(reader->handle, IOCTL_SET_DEACTIVATE)<0);
127 return OK;
128}
129
130
131int Sci_FastReset (struct s_reader *reader)
132{
133 unsigned char buf[SCI_MAX_ATR_SIZE];
134 int n = 0;
135
136 call (ioctl(reader->handle, IOCTL_SET_RESET)<0);
137
138 cs_sleepms(50);
139 // flush atr from buffer
140 while(n<SCI_MAX_ATR_SIZE && !IO_Serial_Read(reader, ATR_TIMEOUT, 1, buf+n))
141 {
142 n++;
143 }
144
145
146 call (ioctl(reader->handle, IOCTL_SET_ATR_READY)<0);
147
148 return 0;
149}
150
151#endif
Note: See TracBrowser for help on using the repository browser.