source: branches/monitor-improvement/csctapi/ifd_sci.c@ 1228

Last change on this file since 1228 was 1228, checked in by alno, 13 years ago

WebIf:

  • Command: Merging revisions 1212-1227 of trunk
File size: 2.6 KB
Line 
1/*
2 ifd_sci.c
3 This module provides IFD handling functions for SCI internal reader.
4*/
5
6#include "ifd_sci.h"
7
8#ifdef SCI_DEV
9
10#include <stdio.h>
11#include <time.h>
12#include <sys/ioctl.h>
13#include "sci_global.h"
14#include "sci_ioctl.h"
15#include "atr.h"
16#include "string.h"
17#ifdef SH4
18#include <fcntl.h>
19#endif
20
21#include "ifd_towitoko.h"
22#define IFD_TOWITOKO_ATR_TIMEOUT 800
23
24#define OK 1
25#define ERROR 0
26
27int Sci_Init ()
28{
29}
30
31int Sci_GetStatus (int handle, int * status)
32{
33 int in;
34 if (ioctl(handle, IOCTL_GET_IS_CARD_PRESENT, status)<0)
35 return ERROR;
36 return OK;
37}
38
39int Sci_Reset (IFD * ifd, ATR ** atr)
40{
41 unsigned char buf[SCI_MAX_ATR_SIZE];
42 int n = 0;
43 SCI_PARAMETERS params;
44#ifdef SH4
45 struct timeval tv, tv_spent;
46 int atr_size = 2, TDi_exists = 0;
47#endif
48
49 (*atr) = NULL;
50
51 memset(&params,0,sizeof(SCI_PARAMETERS));
52
53 params.ETU = 372;
54 params.EGT = 3; //not sure why this value is chosen
55#ifdef SH4
56 params.fs = 9; //not sure why this value is chosen
57#else
58 params.fs = 5;
59#endif
60 params.T = 0;
61
62 if(ioctl(ifd->io->fd, IOCTL_SET_PARAMETERS, &params)!=0)
63 return ERROR;
64
65 if(ioctl(ifd->io->fd, IOCTL_SET_RESET)<0)
66 return ERROR;
67
68#ifdef SH4
69 gettimeofday(&tv,0);
70 memcpy(&tv_spent,&tv,sizeof(struct timeval));
71
72 while(n<atr_size && (tv_spent.tv_sec-tv.tv_sec)<10)
73 {
74 if(IO_Serial_Read(IFD_TOWITOKO_ATR_TIMEOUT, 1, buf+n))
75 n++;
76 gettimeofday(&tv_spent,0);
77 if(n==2) // format character
78 {
79 // high nibble = TA1 , TB1 , TC1 , TD1
80 if(buf[n-1] & 0x10)
81 atr_size++;
82 if(buf[n-1] & 0x20)
83 atr_size++;
84 if(buf[n-1] & 0x40)
85 atr_size++;
86 if(buf[n-1] & 0x80)
87 {
88 atr_size++;
89 TDi_exists=atr_size;
90 }
91 atr_size+=(buf[n-1] & 0x0F); // historical bytes
92 }
93 if( (TDi_exists>0) && (n==TDi_exists) )
94 {
95 TDi_exists=0;
96 // high nibble = TA1 , TB1 , TC1 , TD1
97 if(buf[n-1] & 0x10)
98 atr_size++;
99 if(buf[n-1] & 0x20)
100 atr_size++;
101 if(buf[n-1] & 0x40)
102 atr_size++;
103 if(buf[n-1] & 0x80)
104 {
105 atr_size++;
106 TDi_exists=atr_size;
107 }
108 }
109 }
110#else
111 while(n<SCI_MAX_ATR_SIZE && IO_Serial_Read(IFD_TOWITOKO_ATR_TIMEOUT, 1, buf+n))
112 {
113 n++;
114 }
115
116 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
117 buf[0] = 0x3B;
118#endif
119
120 if(n==0)
121 return ERROR;
122
123
124 (*atr) = ATR_New ();
125 if(ATR_InitFromArray ((*atr), buf, n) == ATR_OK)
126 {
127 struct timespec req_ts;
128 req_ts.tv_sec = 0;
129 req_ts.tv_nsec = 50000000;
130 nanosleep (&req_ts, NULL);
131 if (ioctl(ifd->io->fd, IOCTL_SET_ATR_READY)<0)
132 return ERROR;
133 return OK;
134 }
135 else
136 {
137 ATR_Delete (*atr);
138 (*atr) = NULL;
139 return ERROR;
140 }
141}
142
143#endif
Note: See TracBrowser for help on using the repository browser.